-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Windows patches to 0.4.29, rewrite a bunch of code
Closes #13 PS: fuck msvc
- Loading branch information
Showing
26 changed files
with
350 additions
and
330 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1 @@ | ||
.vs/* | ||
*.exe | ||
patcher | ||
*.filters | ||
*.user | ||
*.obj | ||
patcher.vcxproj | ||
patcher.log | ||
patcher.sln | ||
build/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@echo off | ||
|
||
setlocal | ||
|
||
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 | ||
|
||
set application_name=patcher | ||
set compiler=cl.exe | ||
|
||
set build_options= /DBUILD_WIN32=1 /D_DEBUG /D_CRT_SECURE_NO_WARNINGS | ||
set compile_flags= -nologo /W4 /permissive- /std:c17 /FC /TC /FS /Zi /I ../source/ | ||
set link_flags= -opt:ref -incremental:no /Debug:full | ||
|
||
if not exist build mkdir build | ||
pushd build | ||
%compiler% %build_options% %compile_flags% ../source/build.c /link %link_flags% /out:%application_name%.exe | ||
popd | ||
|
||
endlocal |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@echo off | ||
|
||
setlocal | ||
|
||
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 | ||
|
||
set application_name=patcher | ||
set compiler=cl.exe | ||
|
||
set build_options= /DBUILD_WIN32=1 /D_CRT_SECURE_NO_WARNINGS | ||
set compile_flags= -nologo /W4 /permissive- /std:c17 /FC /TC /O2 /I ../source/ | ||
set link_flags= -opt:ref -incremental:no /Debug:none | ||
|
||
if not exist build mkdir build | ||
pushd build | ||
%compiler% %build_options% %compile_flags% ../source/build.c /link %link_flags% /out:%application_name%.exe | ||
popd | ||
|
||
endlocal |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#include "options.h" | ||
#include "language_layer.h" | ||
|
||
#include "strings.h" | ||
#include "pattern.h" | ||
#include "patches.h" | ||
|
||
#include "strings.c" | ||
#include "patches.c" | ||
#include "checks.c" | ||
|
||
#include "main.c" |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
typedef Patch Check; | ||
|
||
#if BUILD_WIN32 | ||
#define CHECKS_INCLUDE_PATH "win32/checks.inc" | ||
#elif BUILD_LINUX | ||
#define CHECKS_INCLUDE_PATH "linux/checks.inc" | ||
#endif | ||
|
||
#define CHECK(check_name, check_offset, ...) \ | ||
global const Check check_name = { \ | ||
.name = S8LitComp(#check_name), \ | ||
.offset = check_offset, \ | ||
.pattern = PatternFromStringLitComp(__VA_ARGS__), \ | ||
}; | ||
#include CHECKS_INCLUDE_PATH | ||
#undef CHECK | ||
|
||
#define CHECK(checkname, ...) &checkname, | ||
global const Check* checks[] = { | ||
#include CHECKS_INCLUDE_PATH | ||
}; | ||
#undef CHECK | ||
|
||
global const u32 checks_count = ArraySize(checks); | ||
|
||
#undef CHECKS_INCLUDE_PATH |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#define global static | ||
#define internal static | ||
#define local_persist static | ||
#define ArraySize(a) (sizeof(a) / sizeof((a)[0])) | ||
|
||
typedef uint8_t u8; | ||
typedef uint16_t u16; | ||
typedef uint32_t u32; | ||
typedef uint64_t u64; | ||
|
||
typedef int8_t i8; | ||
typedef int16_t i16; | ||
typedef int32_t i32; | ||
typedef int64_t i64; | ||
|
||
typedef i32 b32; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
CHECK(version_check, 0x4C92AD, "0.4.27") |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
PATCH(deleted_message_details, 0x163FA0, {0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3}) | ||
PATCH(deleted_message_append, 0x209DE3, {0xE9, 0x83, 0x00, 0x00}) | ||
PATCH(cooldown, 0x169CD0, {0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3}) |
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
i32 main(i32 argc, char** argv) { | ||
// TODO(geni): Rewrite this whole thing | ||
// TODO(geni): Memory-mapped files | ||
|
||
if (argc == 2) { | ||
if (CStringCompareToS8(argv[1], S8Lit("-h"))) { | ||
String8 base_name = S8PathToBaseName(S8FromCString(argv[0])); | ||
printf("Usage: %.*s [-h] [-l] [original (" DEFAULT_FILENAME ") [patched (" DEFAULT_PATCH_FILENAME ") [disabled patches]]]", S8Expand(base_name)); | ||
} else if (CStringCompareToS8(argv[1], S8Lit("-l"))) { | ||
puts("Available patches:"); | ||
for (u32 i = 0; i < patches_count; ++i) { | ||
printf("Patch \"%.*s\"\n", S8Expand(patches[i]->name)); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
// NOTE(geni): User wants to disable specific patches | ||
if (argc > 3) { | ||
for (i32 i = 3; i < argc; ++i) { | ||
for (u32 p = 0; p < patches_count; ++p) { | ||
if (!patches[p]) { | ||
continue; | ||
} | ||
|
||
if (S8CompareToCString(patches[p]->name, argv[i])) { | ||
patches[p] = NULL; | ||
} | ||
} | ||
} | ||
} | ||
|
||
FILE* fp = NULL; | ||
if (argc == 1) { | ||
fputs("No arguments passed, attempting to use " DEFAULT_FILENAME " as original binary...\n", stderr); | ||
fp = fopen(DEFAULT_FILENAME, "rb"); | ||
} else { | ||
fp = fopen(argv[1], "rb"); | ||
} | ||
|
||
if (!fp) { | ||
fputs("Failed to open original binary!\n", stderr); | ||
return 1; | ||
} | ||
|
||
fseek(fp, 0, SEEK_END); | ||
const u64 size = ftell(fp); | ||
rewind(fp); | ||
|
||
u8* buf = malloc(size); | ||
if (!buf) { | ||
fprintf(stderr, "Failed to allocate buffer (size %zu), not enough memory?", size); | ||
fclose(fp); | ||
return 1; | ||
} | ||
fread(buf, size, sizeof(u8), fp); | ||
fclose(fp); | ||
|
||
b32 failed_checks = 0; | ||
for (u32 i = 0; i < checks_count; ++i) { | ||
const Check* c = checks[i]; | ||
|
||
if (memcmp(buf + c->offset, PatternExpand(c->pattern)) != 0) { | ||
fprintf(stderr, "Check \"%.*s\" failed!\n", S8Expand(c->name)); | ||
failed_checks = 1; | ||
} | ||
} | ||
if (failed_checks) { | ||
return 1; | ||
} | ||
|
||
for (u32 i = 0; i < patches_count; ++i) { | ||
const Patch* p = patches[i]; | ||
|
||
// NOTE(geni): Patch is (hopefully) disabled | ||
if (!p) { | ||
continue; | ||
} | ||
|
||
memcpy(buf + p->offset, PatternExpand(p->pattern)); | ||
printf("Patch \"%.*s\" done\n", S8Expand(p->name)); | ||
} | ||
|
||
if (argc < 2) { | ||
fputs("No patched filename passed, attempting to use " DEFAULT_PATCH_FILENAME " as patched binary...\n", stderr); | ||
fp = fopen(DEFAULT_PATCH_FILENAME, "wb"); | ||
} else { | ||
fp = fopen(argv[2], "wb"); | ||
} | ||
|
||
if (!fp) { | ||
fputs("Failed to create patched binary!\n", stderr); | ||
return 1; | ||
} | ||
const u64 written = fwrite(buf, sizeof(buf[0]), size, fp); | ||
if (written != size) { | ||
fputs("Number of bytes written differs from original size\n", stderr); | ||
return 1; | ||
} | ||
|
||
fclose(fp); | ||
free(buf); | ||
} |
Oops, something went wrong.