diff --git a/CHANGELOG.md b/CHANGELOG.md index b70e057..7c2cd42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] +### Fixed +- Fix startup crash of Warhead launcher when Logitech G15 keyboard is connected +([#39](https://github.com/ccomrade/c1-launcher/issues/39)). + ## [v6] - 2024-02-15 ### Added - Crysis Editor (Sandbox 2) support. diff --git a/Code/Launcher/Game/GameLauncher.cpp b/Code/Launcher/Game/GameLauncher.cpp index a41ca87..53c594b 100644 --- a/Code/Launcher/Game/GameLauncher.cpp +++ b/Code/Launcher/Game/GameLauncher.cpp @@ -90,6 +90,8 @@ void GameLauncher::PatchEngine() } MemoryPatch::CryAction::AllowDX9ImmersiveMultiplayer(m_dlls.pEXE, m_dlls.gameBuild); + + MemoryPatch::WarheadEXE::FixHInstance(m_dlls.pEXE, m_dlls.gameBuild); } if (m_dlls.pCryGame) diff --git a/Code/Launcher/MemoryPatch.cpp b/Code/Launcher/MemoryPatch.cpp index 10d8acd..ef24f3c 100644 --- a/Code/Launcher/MemoryPatch.cpp +++ b/Code/Launcher/MemoryPatch.cpp @@ -3240,6 +3240,41 @@ void MemoryPatch::CryRenderNULL::DisableDebugRenderer(void* pCryRenderNULL, int } } +//////////////////////////////////////////////////////////////////////////////// +// WarheadEXE +//////////////////////////////////////////////////////////////////////////////// + +/** + * Initializes the global hInstance pointer in the Warhead EXE. + * + * Normally, WinMain initializes it, but we load Warhead EXE as a DLL without executing its WinMain function. + * Only the Logitech G15 display interface uses it to obtain its bitmap resources from the EXE. + * + * Only game launcher needs this. + */ +void MemoryPatch::WarheadEXE::FixHInstance(void* pEXE, int gameBuild) +{ + switch (gameBuild) + { +#ifdef BUILD_64BIT + case 710: + case 711: + { + *static_cast(ByteOffset(pEXE, 0x80BBE8)) = pEXE; + break; + } +#else + case 687: + case 710: + case 711: + { + // TODO: 32-bit Crysis Warhead + break; + } +#endif + } +} + //////////////////////////////////////////////////////////////////////////////// // Editor //////////////////////////////////////////////////////////////////////////////// diff --git a/Code/Launcher/MemoryPatch.h b/Code/Launcher/MemoryPatch.h index bed477e..3c2f668 100644 --- a/Code/Launcher/MemoryPatch.h +++ b/Code/Launcher/MemoryPatch.h @@ -70,6 +70,11 @@ namespace MemoryPatch void DisableDebugRenderer(void* pCryRenderNULL, int gameBuild); } + namespace WarheadEXE + { + void FixHInstance(void* pEXE, int gameBuild); + } + namespace Editor { struct Version