Skip to content

Commit

Permalink
Cleanup, porting (mostly untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchv committed Feb 17, 2024
1 parent 7c64e20 commit 08d1a07
Show file tree
Hide file tree
Showing 15 changed files with 495 additions and 362 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ OBJS := \
obj/dll/rugburn/main.o \
obj/hooks/kernel32/inject.o \
obj/hooks/msvcr100/msvcr100.o \
obj/hooks/projectg/us852/ranking.o \
obj/hooks/user32/window.o \
obj/hooks/ws2_32/redir.o \
obj/hooks/wininet/netredir.o \
Expand All @@ -38,6 +39,7 @@ OBJS := \
obj/bootstrap.o \
obj/common.o \
obj/config.o \
obj/hex.o \
obj/ijlfwd.o \
obj/json.o \
obj/patch.o \
Expand Down
7 changes: 3 additions & 4 deletions rugburn.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
<BufferSecurityCheck>false</BufferSecurityCheck>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
<LanguageStandard>stdcpp17</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -150,7 +149,7 @@
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>exportvs.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;libvcruntime.lib;libcmt.lib;libucrt.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand Down Expand Up @@ -193,7 +192,7 @@
<ClCompile Include="src\regex.c" />
<ClCompile Include="src\third_party\lend\ld32.c" />
<ClCompile Include="src\hooks\msvcr100\msvcr100.c" />
<ClCompile Include="src\patch_usa_852.c" />
<ClCompile Include="src\hooks\projectg\us852\ranking.c" />
</ItemGroup>
<ItemGroup>
<None Include="exportvs.def" />
Expand All @@ -204,4 +203,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
2 changes: 1 addition & 1 deletion scripts/setup-clangd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ cp ".tmp/h/sdkddkve.h" ".tmp/h/sdkddkver.h"
echo "-I$PWD/.tmp/h" > compile_flags.txt
echo "-D__va_list=__builtin_va_list" >> compile_flags.txt
echo "-D_exception_code=__exception_code" >> compile_flags.txt
echo "-D__stdcall=" >> compile_flags.txt
echo "-fms-extensions" >> compile_flags.txt

2 changes: 1 addition & 1 deletion src/bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef struct _TEB {
#else // x86
PTEB tebPtr = (PTEB)__readfsdword(OFFSETOF(NT_TIB, Self));
#endif
return tebPtr;
return tebPtr;
}
#endif

Expand Down
28 changes: 15 additions & 13 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ void ReadJsonPatchAddressMap(LPSTR *json, LPCSTR key) {
FatalError("Reached maximum number of Patch address!");
}

Config.PatchAddress[Config.NumPatchAddress].addr = ReadDword(key);
TranslateHexInText(value, Config.PatchAddress[Config.NumPatchAddress].patch, sizeof(Config.PatchAddress[Config.NumPatchAddress].patch), &Config.PatchAddress[Config.NumPatchAddress].patch_len);
Config.PatchAddress[Config.NumPatchAddress].addr = ParseAddress(key);
ParsePatch(value, &Config.PatchAddress[Config.NumPatchAddress].patch, &Config.PatchAddress[Config.NumPatchAddress].patchLen);
Config.NumPatchAddress++;
}

Expand Down Expand Up @@ -141,15 +141,17 @@ BOOL RewriteAddr(LPSOCKADDR_IN addr) {
}

void PatchAddress() {
int i;

for (i = 0; i < Config.NumPatchAddress; i++) {

if (Config.PatchAddress[i].addr != 0 && Config.PatchAddress[i].patch_len > 0 && Config.PatchAddress[i].patch[0] != '\0') {

Patch((LPVOID)Config.PatchAddress[i].addr, Config.PatchAddress[i].patch, Config.PatchAddress[i].patch_len);

Log("PatchAddress: 0x%08lX, Len: %d, Value: %s\r\n", Config.PatchAddress[i].addr, Config.PatchAddress[i].patch_len, Config.PatchAddress[i].patch);
}
}
int i;
for (i = 0; i < Config.NumPatchAddress; i++) {
if (Config.PatchAddress[i].addr == 0) {
Warning("Patch %d at address 0 will be ignored.", i);
continue;
}
if (Config.PatchAddress[i].patchLen == 0) {
Warning("Patch %d is empty.", i);
continue;
}
Patch((LPVOID)Config.PatchAddress[i].addr, Config.PatchAddress[i].patch, Config.PatchAddress[i].patchLen);
Log("PatchAddress: 0x%08lX, Len: %d, Value: %s\r\n", Config.PatchAddress[i].addr, Config.PatchAddress[i].patchLen, Config.PatchAddress[i].patch);
}
}
4 changes: 2 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ typedef struct _PORTREWRITERULE {

typedef struct _PATCHADDRESS {
DWORD addr;
CHAR patch[1024];
int patch_len;
LPSTR patch;
DWORD patchLen;
} PATCHADDRESS, *LPPATCHADDRESS;

typedef struct _RUGBURNCONFIG {
Expand Down
97 changes: 50 additions & 47 deletions src/dll/rugburn/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include "../../bootstrap.h"
#include "../../common.h"
#include "../../config.h"
#include "../../hooks/hooks.h"
#include "../../ijlfwd.h"
#include "../../patch.h"
#include "../../hooks/hooks.h"
#include "../../patch_usa_852.h"
#include "../../hooks/projectg/us852/ranking.h"

/**
* InitEnvironment configures the PANGYA_ARG environment to avoid needing to
Expand All @@ -44,9 +44,9 @@ static VOID InitEnvironment() {
* Implements the GameGuard patches for Pangya US 852.00.
*/
static DWORD STDCALL PatchGG_US852(PVOID unused) {
while(1) {
while (1) {
// TODO(john): Remove hardcoded addresses.
if (*(DWORD*)0x00A495E0 == 0x8F143D83) {
if (*(DWORD *)0x00A495E0 == 0x8F143D83) {
Patch((LPVOID)0x00A495E0, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A49670, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A49690, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Expand All @@ -56,35 +56,36 @@ static DWORD STDCALL PatchGG_US852(PVOID unused) {
Log("Patched GG check routines (US 852)\r\n");

Patch((LPVOID)0x00A6ECC9, "\x30\xC0", 2);
Log("Patched Cookie Point Item (US 852)\r\n");

Patch((LPVOID)0x005FB990, "\x80\xB9\x40\x02\x00\x00\x00\x0F\x85\x0D\x00\x00\x00\x8B\x89\x8C\x01\x00\x00\x8B\x01\x8B\x50\x4C\xFF\xD2\xC2\x04\x00", 29);
Log("Patched Cookie Btn in onCallback that's disabled (US 852)\r\n");

Patch((LPVOID)0x005FB9AD, "\xB3\x01\x31\xFF\x90\x53\xBA\xB4\x6A\xCE\x00\xE9\xC9\x31\x00\x00", 16);
Patch((LPVOID)0x005FEB7E, "\xE9\x2A\xCE\xFF\xFF", 5);
Patch((LPVOID)0x005FEB8D, "\x53", 1);
Patch((LPVOID)0x005FEB9A, "\x53", 1);
Patch((LPVOID)0x005FB9BD, "\x6A\x01\xBA\xB4\x6A\xCE\x00\x8B\xCE\xE8\xF5\x2C\x00\x00\x6A\x01\xBA\xB0\x69\xCE\x00\xE9\x29\x32\x00\x00", 26);
Patch((LPVOID)0x005FEBF9, "\xE9\xBF\xCD\xFF\xFF", 5);
Log("Patched Btn Cookie, Gacha and Scratch disabled (US 852)\r\n");

Patch((LPVOID)0x008BC729, "\x01", 1);
Patch((LPVOID)0x008C1495, "\xEB\x0C", 2);
Patch((LPVOID)0x008C14A3, "\xE8\xF8\xB2\xFF\xFF\x88\x86\xE4\x00\x00\x00\x5E\xC3", 13);
Log("Patched Btn Change Nickname disabled (US 852)\r\n");

unsigned char jmp_to_patch_ranking[5] = { 0xE9u, 0u, 0u, 0u, 0u };

DWORD relAddr = (DWORD)OnUnderBar_RankingUp - 0x00655630u - 5u;

memcpy(&jmp_to_patch_ranking[1], &relAddr, 4u);

Patch((LPVOID)0x00655630, jmp_to_patch_ranking, sizeof(jmp_to_patch_ranking));
Log("Patched Ranking System disabled (US 852)\r\n");
Log("Patched Cookie Point Item (US 852)\r\n");

Patch((LPVOID)0x005FB990,
"\x80\xB9\x40\x02\x00\x00\x00\x0F\x85\x0D\x00\x00\x00\x8B\x89\x8C\x01\x00\x00\x8B"
"\x01\x8B\x50\x4C\xFF\xD2\xC2\x04\x00",
29);
Log("Patched Cookie Btn in onCallback that's disabled (US 852)\r\n");

Patch((LPVOID)0x005FB9AD,
"\xB3\x01\x31\xFF\x90\x53\xBA\xB4\x6A\xCE\x00\xE9\xC9\x31\x00\x00", 16);
Patch((LPVOID)0x005FEB7E, "\xE9\x2A\xCE\xFF\xFF", 5);
Patch((LPVOID)0x005FEB8D, "\x53", 1);
Patch((LPVOID)0x005FEB9A, "\x53", 1);
Patch((LPVOID)0x005FB9BD,
"\x6A\x01\xBA\xB4\x6A\xCE\x00\x8B\xCE\xE8\xF5\x2C\x00\x00\x6A\x01\xBA\xB0\x69\xCE"
"\x00\xE9\x29\x32\x00\x00",
26);
Patch((LPVOID)0x005FEBF9, "\xE9\xBF\xCD\xFF\xFF", 5);
Log("Patched Btn Cookie, Gacha and Scratch disabled (US 852)\r\n");

Patch((LPVOID)0x008BC729, "\x01", 1);
Patch((LPVOID)0x008C1495, "\xEB\x0C", 2);
Patch((LPVOID)0x008C14A3, "\xE8\xF8\xB2\xFF\xFF\x88\x86\xE4\x00\x00\x00\x5E\xC3", 13);
Log("Patched Btn Change Nickname disabled (US 852)\r\n");

InitUS852RankingHook();
Log("Patched Ranking System disabled (US 852)\r\n");
return TRUE;
}
if (*(DWORD*)0x00A49580 == 0x8F143D83) {
if (*(DWORD *)0x00A49580 == 0x8F143D83) {
Patch((LPVOID)0x00A49580, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A49670, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A49690, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Expand All @@ -94,18 +95,18 @@ static DWORD STDCALL PatchGG_US852(PVOID unused) {
Log("Patched GG check routines (US 824)\r\n");
return TRUE;
}
Delay(5);
Delay(5);
}
return FALSE;
return FALSE;
}

/**
* Implements the GameGuard patches for Pangya JP 972.00.
*/
static DWORD STDCALL PatchGG_JP972(PVOID unused) {
while(1) {
while (1) {
// TODO(john): Remove hardcoded addresses.
if (*(DWORD*)0x00A5CD10 == 0x1BA43D83) {
if (*(DWORD *)0x00A5CD10 == 0x1BA43D83) {
Patch((LPVOID)0x00A5CD10, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5CDA0, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5CDC0, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Expand All @@ -115,7 +116,7 @@ static DWORD STDCALL PatchGG_JP972(PVOID unused) {
Log("Patched GG check routines (JP 972)\r\n");
return TRUE;
}
if (*(DWORD*)0x00A5CF80 == 0x1BA43D83) {
if (*(DWORD *)0x00A5CF80 == 0x1BA43D83) {
Patch((LPVOID)0x00A5CF80, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5C010, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5C030, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Expand All @@ -125,7 +126,7 @@ static DWORD STDCALL PatchGG_JP972(PVOID unused) {
Log("Patched GG check routines (JP 974)\r\n");
return TRUE;
}
if (*(DWORD*)0x00A5CF80 == 0x1C143D83) {
if (*(DWORD *)0x00A5CF80 == 0x1C143D83) {
Patch((LPVOID)0x00A5CF80, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5C010, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Patch((LPVOID)0x00A5C030, "\xC3\x90\x90\x90\x90\x90\x90", 7);
Expand All @@ -135,20 +136,22 @@ static DWORD STDCALL PatchGG_JP972(PVOID unused) {
Log("Patched GG check routines (JP 983)\r\n");
return TRUE;
}
Delay(5);
Delay(5);
}
return FALSE;
return FALSE;
}

static VOID STDCALL PatchDynamicAndGG(LPTHREAD_START_ROUTINE patchThread) {

if (!patchThread) {
Warning("It looks like no patch exists for this version of PangYa™.\nThe game will likely exit a couple minutes after detecting GameGuard is not present.");
PatchAddress();
}else {
if (patchThread(NULL) == TRUE)
PatchAddress();
}
if (!patchThread) {
Warning("It looks like no patch exists for this version of PangYa™.\nThe game will likely "
"exit a couple minutes after detecting GameGuard is not present.");
PatchAddress();
} else {
if (patchThread(NULL) == TRUE) {
PatchAddress();
}
}
}

/**
Expand Down Expand Up @@ -202,7 +205,7 @@ extern BOOL STDCALL SlipstrmDllMain(HANDLE hInstance, DWORD dwReason, LPVOID res
PFNDLLMAINPROC pSlipstreamOep;
BOOL bOepResult;

pSlipstreamOep = (PFNDLLMAINPROC)((*(DWORD*)((DWORD)hInstance + 0x40))+(DWORD)hInstance);
pSlipstreamOep = (PFNDLLMAINPROC)((*(DWORD *)((DWORD)hInstance + 0x40)) + (DWORD)hInstance);

// Call OEP; return failure if it fails.
bOepResult = pSlipstreamOep(hInstance, dwReason, reserved);
Expand Down
Loading

0 comments on commit 08d1a07

Please sign in to comment.