Skip to content

Commit

Permalink
Update Discord Hero to new Core SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-k0 committed Feb 24, 2024
1 parent 42d5dd3 commit 3e52e44
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 17 deletions.
3 changes: 1 addition & 2 deletions LoopHero_DiscordPresence/DiscordPresence.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@
<ClCompile Include="SDK\Structures\Documented\CDynamicArray\CDynamicArray.cpp" />
<ClCompile Include="SDK\Structures\Documented\RefThing\RefThing.cpp" />
<ClCompile Include="SDK\Structures\Documented\YYRValue\YYRValue.cpp" />
<ClCompile Include="TKEventManager.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="LHCore.h" />
<ClInclude Include="MyHelper.h" />
<ClInclude Include="SDK\Enums\Enums.hpp" />
<ClInclude Include="SDK\FwdDecls\FwdDecls.hpp" />
Expand All @@ -194,7 +194,6 @@
<ClInclude Include="SDK\Structures\Undocumented\YYGMLFuncs\YYGMLFuncs.hpp" />
<ClInclude Include="SDK\Structures\Undocumented\YYObjectBase\YYObjectBase.hpp" />
<ClInclude Include="SDK\Structures\Undocumented\YYVAR\YYVAR.hpp" />
<ClInclude Include="TKEventManager.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
3 changes: 1 addition & 2 deletions LoopHero_DiscordPresence/DiscordPresence.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="dllmain.cpp" />
<ClCompile Include="TKEventManager.cpp" />
<ClCompile Include="SDK\Plugins\API Definitions\APIDefs.cpp">
<Filter>YYTK</Filter>
</ClCompile>
Expand All @@ -21,7 +20,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="MyHelper.h" />
<ClInclude Include="TKEventManager.h" />
<ClInclude Include="SDK\Plugins\API Definitions\APIDefs.hpp">
<Filter>YYTK</Filter>
</ClInclude>
Expand Down Expand Up @@ -85,6 +83,7 @@
<ClInclude Include="SDK\Structures\Undocumented\YYVAR\YYVAR.hpp">
<Filter>YYTK</Filter>
</ClInclude>
<ClInclude Include="LHCore.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="YYTK">
Expand Down
79 changes: 79 additions & 0 deletions LoopHero_DiscordPresence/LHCore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once
#include <Windows.h>
#include "MyHelper.h"

namespace LHCore {

// Ready-check function
typedef bool (*CoreReady)();
CoreReady pCoreReady = nullptr;
bool isCoreReady = false;

// Saying hello to the core function
typedef bool (*RegisterModule)(std::string, YYTKPlugin*);
RegisterModule pRegisterModule = nullptr;

// unregistering from the core function
typedef bool (*UnregisterModule)(std::string);
UnregisterModule pUnregisterModule = nullptr;

typedef bool (*CoreFoundCallback_t)();

typedef struct ResolveCoreParams_t {
YYTKPlugin* plugin;
CoreFoundCallback_t callback;
} ResolveCoreParams_t;

DWORD WINAPI ResolveCore(LPVOID lpParam)
{
ResolveCoreParams_t* params = static_cast<ResolveCoreParams_t*>(lpParam);
YYTKPlugin* plugin = params->plugin;
CoreFoundCallback_t callback = params->callback;
#ifdef DEBUG
Misc::Print("Importing Core function");
#endif
void* rawCoreReady;
void* rawRegisterModule;
void* rawUnregisterModule;
while (true)
{
Sleep(10);
// Loading ready function
if (PmGetExported("CoreReady", rawCoreReady) == YYTK_OK)
{
pCoreReady = reinterpret_cast<CoreReady>(rawCoreReady);
if (pCoreReady() == true)
{
#ifdef DEBUG
Misc::Print("Core is present", CLR_GREEN);
#endif
isCoreReady = true;

// Loading register function
if (PmGetExported("RegisterModule", rawRegisterModule) == YYTK_OK)
{
pRegisterModule = reinterpret_cast<RegisterModule>(rawRegisterModule);
pRegisterModule(gPluginName, gThisPlugin);
#ifdef DEBUG
Misc::Print("Registered to Core", CLR_GREEN);
#endif
if (callback != NULL)
{
callback();
}
}

// Loading unregister function
if (PmGetExported("UnregisterModule", rawUnregisterModule) == YYTK_OK)
{
pUnregisterModule = reinterpret_cast<UnregisterModule>(rawUnregisterModule);
}

return TRUE;
}
}
Misc::Print("Waiting for Core. Did you install LoopHeroCallbackCore.dll?", CLR_RED);
}
}

}
4 changes: 2 additions & 2 deletions LoopHero_DiscordPresence/MyHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

HINSTANCE DllHandle; // Self modhandle

std::string gPluginName = "Discord Hero";
std::string gVer = "2023.11.10";
std::string gPluginName = "sam-k0.DiscordHero.yytk";
std::string gVer = "2024.02.24";
YYTKPlugin* gThisPlugin = nullptr;
CallbackAttributes_t* callbackAttr = nullptr;

Expand Down
36 changes: 25 additions & 11 deletions LoopHero_DiscordPresence/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

// YYTK is in this now
#include "MyHelper.h"
#include "LHCore.h"

// Plugin functionality
#include <fstream>
Expand Down Expand Up @@ -117,18 +118,9 @@ YYTKStatus CodeExecuteCallback(YYTKCodeEvent* codeEvent, void*)
return YYTK_OK;
}


// Entry
DllExport YYTKStatus PluginEntry(
YYTKPlugin* PluginObject // A pointer to the dedicated plugin object
)
bool CoreFoundCallback() // set hooks
{
Misc::Print("Loading RPC - ver " + gVer);

gThisPlugin = PluginObject;
gThisPlugin->PluginUnload = PluginUnload;

PluginAttributes_t* pluginAttributes = nullptr;
PluginAttributes_t* pluginAttributes = nullptr;
if (PmGetPluginAttributes(gThisPlugin, pluginAttributes) == YYTK_OK)
{
PmCreateCallback(pluginAttributes, callbackAttr, reinterpret_cast<FNEventHandler>(CodeExecuteCallback), EVT_CODE_EXECUTE, nullptr);
Expand All @@ -150,6 +142,28 @@ DllExport YYTKStatus PluginEntry(
presence.largeImageKey = "loop-hero-new-key-art-logo";
presence.largeImageText = "Loop Hero modded";
Discord_UpdatePresence(&presence);

return true;
}

// Entry
DllExport YYTKStatus PluginEntry(
YYTKPlugin* PluginObject // A pointer to the dedicated plugin object
)
{


Misc::Print("Loading RPC - ver " + gVer);

gThisPlugin = PluginObject;
gThisPlugin->PluginUnload = PluginUnload;

// Get info
LHCore::ResolveCoreParams_t params;
params.plugin = gThisPlugin;
params.callback = CoreFoundCallback;

CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)LHCore::ResolveCore, (LPVOID)&params, 0, NULL); // Check if the Callback Core Module is loaded, and wait for it to load

return YYTK_OK; // Successful PluginEntry.
}
Expand Down

0 comments on commit 3e52e44

Please sign in to comment.