Skip to content

Commit

Permalink
discord presence
Browse files Browse the repository at this point in the history
  • Loading branch information
zZeck committed Jun 8, 2022
1 parent 87a5871 commit 42395c3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*.lib
*.exp
*.exe
*.obj
*.obj
/discord
21 changes: 20 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
36 changes: 36 additions & 0 deletions patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <codecvt>
#include <string>
#include <vector>
#include <thread>
#include "discord/cpp/discord.h"

constexpr unsigned int patchOneStart = 0x4C14E0;
constexpr unsigned char patchOne[] = {
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
14 changes: 9 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 42395c3

Please sign in to comment.