Skip to content

Commit

Permalink
add 'Star Trek: Legacy' support
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 committed Dec 10, 2023
1 parent 9daf756 commit f6c9a31
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Please note that the GameSpy protocol is old and does not meet modern password e
| Sniper Elite | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/sniper_elite_berlin_1945"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/3700/Sniper_Elite/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `dinput8.dll` | n/a | |
| Startopia | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/game/startopia"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/243040/Startopia/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `dsound.dll` | n/a | |
| Star Trek: Bridge Commander | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/star_trek_bridge_commander"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a> | `dinput.dll` | n/a | |
| Star Trek: Legacy | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture> | `dinput8.dll` | n/a | <sub><sup>[1]</sup> Latest [v1.2 update](https://taco.cab/files/games/stlegacy/STLegacyv1.2.zip) is recommended</sub> |
| Star Wars: Republic Commando | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/star_wars_republic_commando"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/6000/STAR_WARS_Republic_Commando/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `version.dll` | n/a | |
| Terminator 3: War of the Machines | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture> | `dinput8.dll` | n/a | <sub><sup>[1]</sup> Requires latest [v1.16 update](https://taco.cab/files/games/t3wotm/t3wotm_us_retail-116.zip)<br><sup>[2]</sup> Requires [No-CD patch](https://taco.cab/files/games/t3wotm/T3.WOTM.NoCD.zip) to remove SecuROM (V5) protection</sub> |
| TimeShift | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/game/timeshift"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/10130/TimeShift/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `dinput8.dll` | n/a | <sub><sup>[1]</sup> Requires latest [v1.02 update](https://taco.cab/files/games/timeshift/timeshiftpatch12.zip)&nbsp;&nbsp;<sup>**RETAIL&nbsp;&nbsp;STEAM**</sup></sub> |
Expand Down
3 changes: 3 additions & 0 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "include/game_sacrifice.h"
#include "include/game_nolf.h"
#include "include/game_bf2142.h"
#include "include/game_stlegacy.h"
#endif // !_WIN64

#include "include/picoupnp.h"
Expand Down Expand Up @@ -284,6 +285,8 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
patch_nolf_srv();
} else if (!__stricmp(p, "bf2142.exe")) { // Battlefield 2142
patch_bf2142();
} else if (!__stricmp(p, "legacy.exe")) { // Star Trek: Legacy
patch_stlegacy();
} else if (!__stricmp(p, "serioussam.exe") || !__stricmp(p, "sam2.exe") || !__stricmp(p, "dedicatedserver.exe")) { // Serious Sam 1 & 2
force_bind_ip = 0;
patch_sam();
Expand Down
47 changes: 47 additions & 0 deletions include/game_stlegacy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// game_stlegacy.h

#ifndef __GAME_STLEGACY_H
#define __GAME_STLEGACY_H

#include "include/global.h"
#include "iathook/iathook.h"

int __stdcall hk_bind(SOCKET s, struct sockaddr* addr, int namelen);
LPHOSTENT __stdcall hk_gethostbyname(const char* name);

__forceinline static void stlegacy_hook_gs(HMODULE mod) {
HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(mod, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(mod, bind, hk_bind, "ws2_32.dll", 2, TRUE);
}

// net voice init crashes game - disable it
__forceinline static void stlegacy_disable_net_voice(HMODULE mod) {
BYTE search1[] = {0x83,0xC4,0x04,0x8B,0x46,0x08,0x05,0xD4,0x00,0x00,0x00,0x50};
BYTE patch1[] = {0xE9,0xBE,0x00,0x00,0x00,0x90,0x90,0x90};
WORD search2[] = {0x64,0x89,0x25,0x00,0x00,0x00,0x00,0x51,0xA1,_ANY,_ANY,_ANY,_ANY,0x85,0xC0,0x75,0x47,0x56,0x6A,0x44};
BYTE patch2[] = {0xEB,0x3F};
WORD search3[] = {0x83,0xC4,0x10,0xC3,0x33,0xC0,0xA3,_ANY,_ANY,_ANY,_ANY,0x5E,0x8B,0x4C,0x24,0x04};

BYTE* ptr = find_pattern_mem((ULONG_PTR)mod, search1, search1 + 11, TRUE);
if (ptr)
write_mem(ptr+3, patch1, 8);

ptr = find_pattern_mem_wildcard((ULONG_PTR)mod, search2, search2 + 19, TRUE);
if (ptr) {
write_mem(ptr+15, patch2, 2);
ptr = find_pattern_mem_wildcard((ULONG_PTR)mod, search3, search3 + 15, TRUE);
if (ptr)
nop_mem(ptr+11, 1);
}
}

__noinline static void patch_stlegacy() {
HMODULE mod = GetModuleHandleA("NetworkManager.dll");
if (mod) {
stlegacy_hook_gs(mod);
stlegacy_disable_net_voice(mod);
}
}

#endif // __GAME_STLEGACY_H

0 comments on commit f6c9a31

Please sign in to comment.