diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index cb6664f5..bf25e9a5 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -17,6 +17,7 @@ namespace Components Loader::Register(new Colors()); Loader::Register(new D3D9Ex()); Loader::Register(new Logger()); + Loader::Register(new Weapon()); Loader::Register(new Window()); Loader::Register(new Command()); Loader::Register(new Console()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 46151646..9d01410e 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -28,6 +28,7 @@ namespace Components #include "Modules\Colors.hpp" #include "Modules\D3D9Ex.hpp" #include "Modules\Logger.hpp" +#include "Modules\Weapon.hpp" #include "Modules\Window.hpp" #include "Modules\Command.hpp" #include "Modules\Console.hpp" diff --git a/src/Components/Modules/Weapon.cpp b/src/Components/Modules/Weapon.cpp new file mode 100644 index 00000000..2876e96e --- /dev/null +++ b/src/Components/Modules/Weapon.cpp @@ -0,0 +1,28 @@ +#include "STDInclude.hpp" + +namespace Components +{ + Game::XAssetHeader Weapon::WeaponFileLoad(Game::XAssetType type, const char* filename) + { + Game::XAssetHeader header = { nullptr }; + + // Try loading raw weapon + if (FileSystem::File(Utils::VA("weapons/mp/%s", filename)).Exists()) + { + header.data = Game::BG_LoadWeaponDef_LoadObj(filename); + } + + return header; + } + + Weapon::Weapon() + { + // Intercept weapon loading + AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_WEAPON, Weapon::WeaponFileLoad); + + // weapon asset existence check + Utils::Hook::Nop(0x408228, 5); // find asset header + Utils::Hook::Nop(0x408230, 5); // is asset default + Utils::Hook::Nop(0x40823A, 2); // jump + } +} diff --git a/src/Components/Modules/Weapon.hpp b/src/Components/Modules/Weapon.hpp new file mode 100644 index 00000000..30710ff6 --- /dev/null +++ b/src/Components/Modules/Weapon.hpp @@ -0,0 +1,12 @@ +namespace Components +{ + class Weapon : public Component + { + public: + Weapon(); + const char* GetName() { return "Weapon"; }; + + private: + static Game::XAssetHeader WeaponFileLoad(Game::XAssetType type, const char* filename); + }; +} diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index 63a77894..59d2aa3b 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -2,6 +2,8 @@ namespace Game { + BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj = (BG_LoadWeaponDef_LoadObj_t)0x57B5F0; + Cbuf_AddText_t Cbuf_AddText = (Cbuf_AddText_t)0x404B20; CL_GetClientName_t CL_GetClientName = (CL_GetClientName_t)0x4563D0; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 49e0ef53..44b2c624 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1,6 +1,9 @@ namespace Game { - typedef void(__cdecl * Cbuf_AddText_t)(int a1, const char* cmd); + typedef void*(__cdecl * BG_LoadWeaponDef_LoadObj_t)(const char* filename); + extern BG_LoadWeaponDef_LoadObj_t BG_LoadWeaponDef_LoadObj; + + typedef void(__cdecl * Cbuf_AddText_t)(int localClientNum, const char *text); extern Cbuf_AddText_t Cbuf_AddText; typedef char*(__cdecl * CL_GetClientName_t)(int localClientNum, int index, char *buf, size_t size); diff --git a/src/Utils/Hooking.hpp b/src/Utils/Hooking.hpp index 08983163..1882de71 100644 --- a/src/Utils/Hooking.hpp +++ b/src/Utils/Hooking.hpp @@ -11,6 +11,7 @@ namespace Utils Hook() : Place(nullptr), Stub(nullptr), Initialized(false), Installed(false), UseJump(false), Protection(0) { ZeroMemory(Hook::Buffer, sizeof(Hook::Buffer)); } Hook(void* place, void* stub, bool useJump = true) : Hook() { Hook::Initialize(place, stub, useJump); } Hook(DWORD place, void* stub, bool useJump = true) : Hook((void*)place, stub, useJump) {} + Hook(DWORD place, DWORD stub, bool useJump = true) : Hook((void*)place, (void*)stub, useJump) {} ~Hook();