| 16 | #include <windows.h> |
| 17 | |
| 18 | void ApplyCodePatches() |
| 19 | { |
| 20 | #ifndef SHADOW_BROODWAR |
| 21 | // ---------------------------------- VERSION DEPENDENT ---------------------------------------------------- |
| 22 | // Only apply if version is correct |
| 23 | if ( isCorrectVersion ) |
| 24 | { |
| 25 | // Create function-level hooks |
| 26 | HackUtil::CallPatch(BW::BWFXN_P_IsGamePaused, &_nextFrameHook); |
| 27 | HackUtil::CallPatch(BW::BWFXN_ExecuteGameTrigsCallPatch, &ExecuteGameTriggers); |
| 28 | HackUtil::WriteNops(BW::BWFXN_SpendRepair, 7); |
| 29 | HackUtil::JmpPatch(BW::BWFXN_SpendRepair, &_repairHook); |
| 30 | HackUtil::JmpPatch(BW::BWFXN_RefundMinerals, &_refundMineralsHook); |
| 31 | HackUtil::JmpPatch(BW::BWFXN_RefundGas, &_refundGasHook); |
| 32 | HackUtil::JmpPatch(BW::BWFXN_RefundMinAndGas2, &_refundMinAndGas2Hook); |
| 33 | HackUtil::JmpPatch(BW::BWFXN_RefundMin3, &_refundMin3Hook); |
| 34 | HackUtil::JmpPatch(BW::BWFXN_RefundGas3, &_refundGas3Hook); |
| 35 | HackUtil::JmpPatch(BW::BWFXN_RefundMin4, &_refundMin4Hook); |
| 36 | HackUtil::JmpPatch(BW::BWFXN_RefundGas4, &_refundGas4Hook); |
| 37 | HackUtil::JmpPatch(BW::BWFXN_RefundMinAndGas5, &_refundMinAndGas5Hook); |
| 38 | HackUtil::JmpPatch(BW::BWDATA::BWFXN_QueueCommand, &CommandFilter); |
| 39 | HackUtil::JmpPatch(BW::BWDATA::BWFXN_DDrawDestroy, &DDrawDestroy); |
| 40 | HackUtil::CallPatch(BW::BWFXN_RandomizeRacePatch, &_RandomizePlayerRaces); |
| 41 | HackUtil::CallPatch(BW::BWFXN_InitPlayerConsolePatch, &_InitializePlayerConsole); |
| 42 | |
| 43 | // Perform code patches |
| 44 | char zero = 0; |
| 45 | HackUtil::WriteMem(BW::BWDATA::ServerMenuIn, &zero, 1); // BNET Server menu in speed |
| 46 | HackUtil::WriteMem(BW::BWDATA::ServerMenuOut, &zero, 1); // BNET Server menu out speed |
| 47 | HackUtil::WriteMem(BW::BWDATA::OpponentStartHack, &zero, 1); // Start without an opponent |
| 48 | HackUtil::WriteNops(BW::BWDATA::SingleSpeedHack, 11); // Use multiplayer speed setting instead |
| 49 | // of always setting speed to "Normal" in |
| 50 | // single player |
| 51 | // Write menu animation speed hack |
| 52 | for (auto &it : BW::BWDATA::commonSwishControllers) it.wType = 4; |
| 53 | for (auto &it : BW::BWDATA::gluCustmSwishController) it.wType = 4; |
| 54 | for (auto &it : BW::BWDATA::gluCmpgnSwishController) it.wType = 4; |
| 55 | for (auto &it : BW::BWDATA::gluScoreSwishController) it.wType = 4; |
| 56 | for (auto &it : BW::BWDATA::gluChatSwishController) it.wType = 4; |
| 57 | } |
| 58 | // ---------------------------------- VERSION INDEPENDENT -------------------------------------------------- |
| 59 | // Storm detours |
| 60 | _SNetLeaveGameOld = HackUtil::PatchImport("storm.dll", 119, &_SNetLeaveGame); |
| 61 | _SNetReceiveMessageOld = HackUtil::PatchImport("storm.dll", 121, &_SNetReceiveMessage); |
| 62 | _SNetSendTurnOld = HackUtil::PatchImport("storm.dll", 128, &_SNetSendTurn); |
| 63 | _SFileOpenFileOld = HackUtil::PatchImport("storm.dll", 267, &_SFileOpenFile); |
| 64 | _SFileOpenFileExOld = HackUtil::PatchImport("storm.dll", 268, &_SFileOpenFileEx); |
| 65 | _SDrawCaptureScreenOld = HackUtil::PatchImport("storm.dll", 342, &_SDrawCaptureScreen); |
| 66 | _SMemAllocOld = HackUtil::PatchImport("storm.dll", 401, &_SMemAlloc); |
| 67 | _SStrCopyOld = HackUtil::PatchImport("storm.dll", 501, &_SStrCopy); |
| 68 | |
| 69 | // wmode/drawing detours |
| 70 | _GetCursorPosOld = HackUtil::PatchImport("user32.dll", "GetCursorPos", &_GetCursorPos); |
| 71 | _SetCursorPosOld = HackUtil::PatchImport("user32.dll", "SetCursorPos", &_SetCursorPos); |
| 72 | _ClipCursorOld = HackUtil::PatchImport("user32.dll", "ClipCursor", &_ClipCursor); |
| 73 | _SDrawLockSurfaceOld = HackUtil::PatchImport("storm.dll", 350, &_SDrawLockSurface); |
| 74 | _SDrawUnlockSurfaceOld = HackUtil::PatchImport("storm.dll", 356, &_SDrawUnlockSurface); |
| 75 | _SDrawUpdatePaletteOld = HackUtil::PatchImport("storm.dll", 357, &_SDrawUpdatePalette); |