Skip to content

Commit

Permalink
minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 committed Aug 24, 2023
1 parent e62a002 commit a6b4efc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
5 changes: 4 additions & 1 deletion include/game_thug2.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

__forceinline static void thug2_hook_gs() {
BYTE* ptr = 0;
ULONG_PTR addr = (ULONG_PTR)GetModuleHandleA(0);
BYTE search[] = "www.thug2online.com/";
while (ptr = find_pattern_mem(0, search, search + 19, FALSE))
while (ptr = find_pattern_mem(addr, search, search + 19, FALSE)) {
write_mem(ptr, "thmods.com/motd.dat", 20);
addr = (ULONG_PTR)ptr+20;
}
}

__noinline static void patch_thug2() {
Expand Down
40 changes: 28 additions & 12 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,39 @@ __forceinline static void gs_replace_pubkey(ULONG_PTR addr) {
}

__forceinline static int gs_copy_string(char* dst, const char* src) {
if (__stristr(src, "gamespy.com") || __stristr(src, "gamespy.net")) {
char* p;
char* p = 0;
const char* s = src;
while (p = __stristr(s, "gamespy.")) {
if (((p[8] == 'c' || p[8] == 'C') &&
(p[9] == 'o' || p[9] == 'O') &&
(p[10] == 'm' || p[10] == 'M')) ||
((p[8] == 'n' || p[8] == 'N') &&
(p[9] == 'e' || p[9] == 'E') &&
(p[10] == 't' || p[10] == 'T')))
break;
s = p+8;
}
if (p) {
__strncpy(dst, src, 511);
while (p = __stristr(dst, "gamespy.com")) {
p[0] = 'o';
p[1] = 'p';
p[2] = 'e';
p[3] = 'n';
p[8] = 'n';
p[9] = 'e';
p[10] = 't';
}
while (p = __stristr(dst, "gamespy.net")) {
s = dst+(p-src);
while (p = __stristr(s, "gamespy.")) {
if ((p[8] == 'c' || p[8] == 'C') &&
(p[9] == 'o' || p[9] == 'O') &&
(p[10] == 'm' || p[10] == 'M')) {
p[8] = 'n';
p[9] = 'e';
p[10] = 't';
} else if ((p[8] != 'n' && p[8] != 'N') ||
(p[9] != 'e' && p[9] != 'E') ||
(p[10] != 't' && p[10] != 'T')) {
s = p+8;
continue;
}
p[0] = 'o';
p[1] = 'p';
p[2] = 'e';
p[3] = 'n';
s = p+11;
}
return 1;
}
Expand Down

0 comments on commit a6b4efc

Please sign in to comment.