Skip to content

Commit

Permalink
add 'Blood II' support
Browse files Browse the repository at this point in the history
  • Loading branch information
anzz1 committed Oct 5, 2023
1 parent 0316ffd commit 7603347
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Please note that the GameSpy protocol is old and does not meet modern password e
| --- | :-: | :-: | :-: | --- |
| Act of War: High Treason | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/act_of_war_gold_edition"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/9760/Act_of_War_High_Treason/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `version.dll` | n/a | |
| Battlefield Vietnam | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture> | `dinput8.dll` | n/a | |
| Blood II | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/blood_2_the_chosen_expansion"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a>&nbsp;<a href="https://store.steampowered.com/app/299050/Blood_II_The_Chosen__Expansion/"><img src="./.github/img/steam.png" title="Steam" alt="(Steam)" /></a> | `winmm.dll` | n/a | |
| Civilization III | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/sid_meiers_civilization_iii_complete"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a> | `version.dll` | n/a | |
| Civilization IV | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/sid_meiers_civilization_iv_the_complete_edition"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a> | `dsound.dll` | n/a | |
| Colin McRae Rally 2005 | <picture><img src="./.github/img/disc.png" title="Retail" alt="(Retail)" /></picture>&nbsp;<a href="https://www.gog.com/en/game/colin_mcrae_rally_2005"><img src="./.github/img/gog.png" title="GOG" alt="(GOG)" /></a> | `dinput8.dll` | n/a | |
Expand Down
3 changes: 3 additions & 0 deletions dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "include/game_hd2.h"
#include "include/game_stbc.h"
#include "include/game_bfme2.h"
#include "include/game_blood2.h"
#endif // !_WIN64

#include "include/picoupnp.h"
Expand Down Expand Up @@ -262,6 +263,8 @@ int __stdcall DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved) {
patch_hd2();
} else if (!__stricmp(p, "stbc.exe")) { // Star Trek - Bridge Commander
patch_stbc();
} else if (!__stricmp(p, "blood2.exe") || !__stricmp(p, "blood2sv.exe") || !__stricmp(p, "b2nmsrv.exe")) { // Blood II - The Chosen
patch_blood2();
} else if (!__stricmp(p, "game.dat") && p2 && !__strcmp(p2, "RTS.exe")) { // Battle for Middle-earth II
patch_bfme2();
} else if (!__stricmp(p, "serioussam.exe") || !__stricmp(p, "sam2.exe") || !__stricmp(p, "dedicatedserver.exe")) { // Serious Sam 1 & 2
Expand Down
49 changes: 49 additions & 0 deletions include/game_blood2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// game_blood2.h

#ifndef __GAME_BLOOD2_H
#define __GAME_BLOOD2_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 blood2_hook_mod(HMODULE mod) {
HOOK_FUNC(mod, gethostbyname, hk_gethostbyname, "ws2_32.dll", 52, TRUE);
HOOK_FUNC(mod, gethostbyname, hk_gethostbyname, "wsock32.dll", 52, TRUE);
HOOK_FUNC(mod, bind, hk_bind, "ws2_32.dll", 2, TRUE);
HOOK_FUNC(mod, bind, hk_bind, "wsock32.dll", 2, TRUE);
}

HMODULE __stdcall blood2_hk_LoadLibraryA(LPCSTR lpLibFileName) {
HMODULE mod = 0;
const char* name = __strrchr(lpLibFileName, '\\');
if (name)
name++;
else
name = lpLibFileName;

mod = oLoadLibraryA(lpLibFileName);
if (mod && (!__stricmp(name, "server.dll")))
blood2_hook_mod(mod);

return mod;
}

__forceinline static void blood2_hook_gs() {
HMODULE mod;

blood2_hook_mod(0);
HOOK_FUNC(0, LoadLibraryA, blood2_hk_LoadLibraryA, "kernel32.dll", 0, FALSE);

mod = GetModuleHandleA("server.dll");
if (mod)
blood2_hook_mod(mod);
}

__noinline static void patch_blood2() {
blood2_hook_gs();
}

#endif // __GAME_BLOOD2_H

0 comments on commit 7603347

Please sign in to comment.