Skip to content

Commit f6c9a31

Browse files
authored
add 'Star Trek: Legacy' support
1 parent 9daf756 commit f6c9a31

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Please note that the GameSpy protocol is old and does not meet modern password e
9595
| 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 | |
9696
| 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 | |
9797
| 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 | |
98+
| 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> |
9899
| 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 | |
99100
| 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> |
100101
| 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> |

dllmain.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "include/game_sacrifice.h"
4949
#include "include/game_nolf.h"
5050
#include "include/game_bf2142.h"
51+
#include "include/game_stlegacy.h"
5152
#endif // !_WIN64
5253

5354
#include "include/picoupnp.h"
@@ -284,6 +285,8 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
284285
patch_nolf_srv();
285286
} else if (!__stricmp(p, "bf2142.exe")) { // Battlefield 2142
286287
patch_bf2142();
288+
} else if (!__stricmp(p, "legacy.exe")) { // Star Trek: Legacy
289+
patch_stlegacy();
287290
} else if (!__stricmp(p, "serioussam.exe") || !__stricmp(p, "sam2.exe") || !__stricmp(p, "dedicatedserver.exe")) { // Serious Sam 1 & 2
288291
force_bind_ip = 0;
289292
patch_sam();

include/game_stlegacy.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// game_stlegacy.h
2+
3+
#ifndef __GAME_STLEGACY_H
4+
#define __GAME_STLEGACY_H
5+
6+
#include "include/global.h"
7+
#include "iathook/iathook.h"
8+
9+
int __stdcall hk_bind(SOCKET s, struct sockaddr* addr, int namelen);
10+
LPHOSTENT __stdcall hk_gethostbyname(const char* name);
11+
12+
__forceinline static void stlegacy_hook_gs(HMODULE mod) {
13+
HOOK_FUNC(0, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
14+
HOOK_FUNC(mod, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
15+
HOOK_FUNC(mod, bind, hk_bind, "ws2_32.dll", 2, TRUE);
16+
}
17+
18+
// net voice init crashes game - disable it
19+
__forceinline static void stlegacy_disable_net_voice(HMODULE mod) {
20+
BYTE search1[] = {0x83,0xC4,0x04,0x8B,0x46,0x08,0x05,0xD4,0x00,0x00,0x00,0x50};
21+
BYTE patch1[] = {0xE9,0xBE,0x00,0x00,0x00,0x90,0x90,0x90};
22+
WORD search2[] = {0x64,0x89,0x25,0x00,0x00,0x00,0x00,0x51,0xA1,_ANY,_ANY,_ANY,_ANY,0x85,0xC0,0x75,0x47,0x56,0x6A,0x44};
23+
BYTE patch2[] = {0xEB,0x3F};
24+
WORD search3[] = {0x83,0xC4,0x10,0xC3,0x33,0xC0,0xA3,_ANY,_ANY,_ANY,_ANY,0x5E,0x8B,0x4C,0x24,0x04};
25+
26+
BYTE* ptr = find_pattern_mem((ULONG_PTR)mod, search1, search1 + 11, TRUE);
27+
if (ptr)
28+
write_mem(ptr+3, patch1, 8);
29+
30+
ptr = find_pattern_mem_wildcard((ULONG_PTR)mod, search2, search2 + 19, TRUE);
31+
if (ptr) {
32+
write_mem(ptr+15, patch2, 2);
33+
ptr = find_pattern_mem_wildcard((ULONG_PTR)mod, search3, search3 + 15, TRUE);
34+
if (ptr)
35+
nop_mem(ptr+11, 1);
36+
}
37+
}
38+
39+
__noinline static void patch_stlegacy() {
40+
HMODULE mod = GetModuleHandleA("NetworkManager.dll");
41+
if (mod) {
42+
stlegacy_hook_gs(mod);
43+
stlegacy_disable_net_voice(mod);
44+
}
45+
}
46+
47+
#endif // __GAME_STLEGACY_H

0 commit comments

Comments
 (0)