-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
768 additions
and
704 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,75 @@ | ||
#include "features/discord_rpc.h" | ||
|
||
DWORD discord_rich_presence_code_start = 0; | ||
DWORD discord_rich_presence_jump_back = 0; | ||
DWORD discord_rich_presence_state_string_ptr = NULL; | ||
DWORD discord_rich_presence_large_text_string_ptr = NULL; | ||
DWORD discord_rich_presence_small_text_string_ptr = NULL; | ||
intptr_t drpc_code_start = 0; | ||
intptr_t drpc_jump_back = 0; | ||
intptr_t drpc_state_string_ptr = NULL; | ||
intptr_t drpc_state_string_gc_handle = NULL; | ||
intptr_t drpc_large_text_string_ptr = NULL; | ||
intptr_t drpc_large_text_string_gc_handle = NULL; | ||
intptr_t drpc_small_text_string_ptr = NULL; | ||
intptr_t drpc_small_text_string_gc_handle = NULL; | ||
|
||
Hook<Detour32> DiscordRichPresenceHook; | ||
|
||
void init_discord_rpc() | ||
{ | ||
VARIANT v = invoke_csharp_method(L"Freedom.Utils", L"GetSetPresencePtr"); | ||
if (variant_ok(v)) | ||
drpc_code_start = get_set_presence_ptr(); | ||
if (drpc_code_start) | ||
{ | ||
discord_rich_presence_code_start = v.intVal; | ||
discord_rich_presence_jump_back = discord_rich_presence_code_start + 0x5; | ||
} | ||
if (discord_rich_presence_code_start) | ||
{ | ||
DiscordRichPresenceHook = Hook<Detour32>(discord_rich_presence_code_start, (BYTE *)set_discord_rich_presence, 5); | ||
if (cfg_discord_rich_presence_enabled) | ||
drpc_jump_back = drpc_code_start + 0x5; | ||
DiscordRichPresenceHook = Hook<Detour32>(drpc_code_start, (BYTE *)set_drpc, 5); | ||
if (cfg_drpc_enabled) | ||
{ | ||
enable_discord_rich_presence_hooks(); | ||
enable_drpc_hooks(); | ||
|
||
if (cfg_discord_rich_presence_state[0] != '\0') | ||
set_discord_rpc_str(discord_rich_presence_state_wchar, cfg_discord_rich_presence_state, &discord_rich_presence_state_string_ptr); | ||
if (cfg_drpc_state[0] != '\0') | ||
set_discord_rpc_str(drpc_state_wchar, cfg_drpc_state, &drpc_state_string_ptr, &drpc_state_string_gc_handle); | ||
|
||
if (cfg_discord_rich_presence_large_text[0] != '\0') | ||
set_discord_rpc_str(discord_rich_presence_large_text_wchar, cfg_discord_rich_presence_large_text, &discord_rich_presence_large_text_string_ptr); | ||
if (cfg_drpc_large_text[0] != '\0') | ||
set_discord_rpc_str(drpc_large_text_wchar, cfg_drpc_large_text, &drpc_large_text_string_ptr, &drpc_large_text_string_gc_handle); | ||
|
||
if (cfg_discord_rich_presence_small_text[0] != '\0') | ||
set_discord_rpc_str(discord_rich_presence_small_text_wchar, cfg_discord_rich_presence_small_text, &discord_rich_presence_small_text_string_ptr); | ||
if (cfg_drpc_small_text[0] != '\0') | ||
set_discord_rpc_str(drpc_small_text_wchar, cfg_drpc_small_text, &drpc_small_text_string_ptr, &drpc_small_text_string_gc_handle); | ||
} | ||
} | ||
} | ||
|
||
void set_discord_rpc_str(wchar_t *w_str, char *c_str, DWORD *output_str_ptr) | ||
void set_discord_rpc_str(wchar_t *w_str, char *c_str, intptr_t *output_str_ptr, intptr_t *output_str_gc_handle) | ||
{ | ||
invoke_csharp_method(L"Freedom.Utils", L"FreeCSharpString", w_str); | ||
if (*output_str_gc_handle) | ||
free_managed_string(*output_str_gc_handle); | ||
int wchars_count = MultiByteToWideChar(CP_UTF8, 0, c_str, -1, NULL, 0); | ||
int bytes_written = MultiByteToWideChar(CP_UTF8, 0, c_str, -1, w_str, wchars_count); | ||
w_str[bytes_written] = '\0'; | ||
VARIANT v = invoke_csharp_method(L"Freedom.Utils", L"GetCSharpStringPtr", w_str); | ||
if (variant_ok(v)) | ||
*output_str_ptr = v.intVal; | ||
*output_str_ptr = allocate_managed_string(w_str, output_str_gc_handle); | ||
} | ||
|
||
void enable_discord_rich_presence_hooks() | ||
void enable_drpc_hooks() | ||
{ | ||
DiscordRichPresenceHook.Enable(); | ||
} | ||
|
||
void disable_discord_rich_presence_hooks() | ||
void disable_drpc_hooks() | ||
{ | ||
DiscordRichPresenceHook.Disable(); | ||
} | ||
|
||
__declspec(naked) void set_discord_rich_presence() | ||
__declspec(naked) void set_drpc() | ||
{ | ||
__asm { | ||
push esi | ||
mov eax, discord_rich_presence_state_string_ptr | ||
mov eax, drpc_state_string_ptr | ||
mov dword ptr [edx+0x4], eax | ||
mov esi, discord_rich_presence_large_text_string_ptr | ||
mov esi, drpc_large_text_string_ptr | ||
mov eax, [edx+0x10] | ||
mov dword ptr [eax+0x8], esi | ||
mov esi, discord_rich_presence_small_text_string_ptr | ||
mov esi, drpc_small_text_string_ptr | ||
mov dword ptr [eax+0x10], esi | ||
pop esi | ||
push ebp | ||
mov ebp,esp | ||
push edi | ||
push esi | ||
jmp [discord_rich_presence_jump_back] | ||
jmp [drpc_jump_back] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.