From 42395c30a8cbe15f69843b609e07574e1fa64ac8 Mon Sep 17 00:00:00 2001 From: Zeck Date: Tue, 7 Jun 2022 22:40:39 -0500 Subject: [PATCH] discord presence --- .gitignore | 3 ++- .vscode/settings.json | 21 ++++++++++++++++++++- patch.cpp | 36 ++++++++++++++++++++++++++++++++++++ readme.md | 14 +++++++++----- 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 64e4a08..157e2a3 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *.lib *.exp *.exe -*.obj \ No newline at end of file +*.obj +/discord \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 39773e6..845ed1e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -51,6 +51,25 @@ "xutility": "cpp", "codecvt": "cpp", "cctype": "cpp", - "string": "cpp" + "string": "cpp", + "thread": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "compare": "cpp", + "csignal": "cpp", + "format": "cpp", + "forward_list": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "optional": "cpp", + "sstream": "cpp", + "stop_token": "cpp", + "unordered_map": "cpp", + "xhash": "cpp", + "xtree": "cpp" } } \ No newline at end of file diff --git a/patch.cpp b/patch.cpp index 8906971..ee994de 100644 --- a/patch.cpp +++ b/patch.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include "discord/cpp/discord.h" constexpr unsigned int patchOneStart = 0x4C14E0; constexpr unsigned char patchOne[] = { @@ -61,11 +63,16 @@ int selectedIndex = 0; std::filesystem::path configFilePath; +discord::Core* core{}; + LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void OpenAdapterSelectDialog(HINSTANCE hInstDll); bool LoadPrior(); void LoadAdapters(); void Patch(PIP_ADAPTER_UNICAST_ADDRESS_LH addr); +void Discord(); + +auto exiting = false; extern __declspec(dllexport) INT APIENTRY DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpvReserved) { @@ -82,12 +89,41 @@ extern __declspec(dllexport) INT APIENTRY DllMain(HINSTANCE hInstDll, DWORD fdwR if(!LoadPrior()) OpenAdapterSelectDialog(hInstDll); delete(pAddresses); + + auto hThread = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Discord, 0, 0, 0); + break; } + case DLL_PROCESS_DETACH: + exiting = true; + break; } return TRUE; } +void Discord() +{ + discord::ClientId CLIENT_ID(983113098980364359); + auto result = discord::Core::Create(CLIENT_ID, DiscordCreateFlags_Default, &core); + + discord::Activity activity{}; + activity.SetType(discord::ActivityType::Playing); + activity.GetAssets().SetLargeImage("raymanmarena"); + activity.GetAssets().SetLargeText("Join the community: https://discord.gg/qp5S83ZhgW"); + activity.GetAssets().SetSmallText("Join the community: https://discord.gg/qp5S83ZhgW"); + activity.GetTimestamps().SetStart(std::time(nullptr)); + core->ActivityManager().UpdateActivity(activity, [](discord::Result result) { + + }); + + while (!exiting) + { + core->RunCallbacks(); + const auto delay = 5000; + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); + } +} + bool LoadPrior() { std::wifstream settings(configFilePath); diff --git a/readme.md b/readme.md index 5304386..39f4baa 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,16 @@ +This patch allows you to choose a network adapter at startup, like hamachi, for Rayman Arena to use in LAN mode. +The LAN init code in the game is not very good, which is why it has problems with multiple adapters, or adapters with adaper IP addresses in ranges it doesn't expect. +The patch NOPs out most of a couple of routines, and hardcodes into them the network adapter information selected. + +It also adds basic discord rich presence support, showing you are playing rayman m/arena. + +Copy the discord sdk into a directory named discord in the root of this repo. + In the visual studio native tools command prompt (or similar environment): -cl.exe /std:c++17 /Zi /LD patch.cpp /link /OUT:arenapatch.asi user32.lib IPHLPAPI.lib Ws2_32.lib +cl.exe /std:c++17 /Zi /LD discord/cpp/*.cpp patch.cpp /I\discord\cpp\ /link /OUT:arenapatch.asi user32.lib IPHLPAPI.lib Ws2_32.lib discord/lib/x86/discord_game_sdk.dll.lib Use [Ultimate Asi Loader](https://github.com/ThirteenAG/Ultimate-ASI-Loader), with rayman arena and put arenapatch.asi into the plugins directory. You may want to rename dinput8.dll from the asi loader to one of the other supported dll names. The controller patch for arena on the pcwiki replaces dinput8.dll - -This patch allows you to choose a network adapter at startup, like hamachi, for Rayman Arena to use in LAN mode. -The LAN init code in the game is not very good, which is why it has problems with multiple adapters, or adapters with adaper IP addresses in ranges it doesn't expect. -The patch NOPs out most of a couple of routines, and hardcodes into them the network adapter information selected.