From d191e90e1fa0ce41c6a549db5deb0925fa4f3e8b Mon Sep 17 00:00:00 2001 From: Diavolo Date: Thu, 30 Jun 2022 22:24:40 +0200 Subject: [PATCH] [Weapon] Fix null pointer (Prank gone wrong) --- src/Components/Modules/Weapon.cpp | 45 +++++++++++++++++++++++++++++++ src/Components/Modules/Weapon.hpp | 3 +++ 2 files changed, 48 insertions(+) diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp index 82e2db4d..58a90e46 100644 --- a/src/Components/Modules/Weapon.cpp +++ b/src/Components/Modules/Weapon.cpp @@ -448,6 +448,48 @@ namespace Components } } + void __declspec(naked) Weapon::CG_UpdatePrimaryForAltModeWeapon_Stub() + { + __asm + { + mov eax, 0x440EB0 // BG_GetWeaponDef + call eax + add esp, 0x4 + + test eax, eax + jz null + + // Game code + push 0x59E349 + retn + + null: + mov al, 1 + ret + } + } + + void __declspec(naked) Weapon::CG_SelectWeaponIndex_Stub() + { + __asm + { + mov eax, 0x440EB0 // BG_GetWeaponDef + call eax + add esp, 0x4 + + test eax, eax + jz null + + // Game code + push 0x48BB2D + retn + + null: + push 0x48BB1F // Exit function + ret + } + } + void __declspec(naked) Weapon::WeaponEntCanBeGrabbed_Stub() { using namespace Game; @@ -525,6 +567,9 @@ namespace Components //Utils::Hook::Nop(0x452C1D, 2); //Utils::Hook::Nop(0x452C24, 5); + Utils::Hook(0x59E341, CG_UpdatePrimaryForAltModeWeapon_Stub, HOOK_JUMP).install()->quick(); + Utils::Hook(0x48BB25, CG_SelectWeaponIndex_Stub, HOOK_JUMP).install()->quick(); + AddScriptMethods(); AssertOffset(Game::playerState_s, Game::playerState_s::weapCommon.weapFlags, 0x2BC); diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp index 12dd99a2..7599c772 100644 --- a/src/Components/Modules/Weapon.hpp +++ b/src/Components/Modules/Weapon.hpp @@ -26,6 +26,9 @@ namespace Components static int ParseWeaponConfigStrings(); static int ClearConfigStrings(void* dest, int value, int size); + static void CG_UpdatePrimaryForAltModeWeapon_Stub(); + static void CG_SelectWeaponIndex_Stub(); + static void WeaponEntCanBeGrabbed_Stub(); static void AddScriptMethods(); };