From 18be8aea4296ed1c5dcf567ca8c028657453a445 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 24 Oct 2021 14:15:06 +0600 Subject: [PATCH] Add weapon tab --- resource/III/CheatMenu/json/weapon.json | 18 ++++++ src/cheatmenu.h | 7 ++- src/ped.cpp | 2 +- src/weapon.cpp | 74 +++++++++++++++++++------ src/weapon.h | 4 +- tools/premake5.lua | 2 + 6 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 resource/III/CheatMenu/json/weapon.json diff --git a/resource/III/CheatMenu/json/weapon.json b/resource/III/CheatMenu/json/weapon.json new file mode 100644 index 0000000..c2951b5 --- /dev/null +++ b/resource/III/CheatMenu/json/weapon.json @@ -0,0 +1,18 @@ +{ + "All": { + "Grenade": "170", + "Ak47": "171", + "Bat": "172", + "Colt45": "173", + "Molotov": "174", + "Rocket": "175", + "Shotgun": "176", + "Sniper": "177", + "Uzi": "178", + "Missile": "179", + "M16": "180", + "Flame": "181", + "Bomb": "182", + "Fingers": "183" + } +} \ No newline at end of file diff --git a/src/cheatmenu.h b/src/cheatmenu.h index ae95f39..ef8eece 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -11,7 +11,6 @@ #pragma once #ifndef GTA3 #include "animation.h" -#include "weapon.h" #include "game.h" #include "visual.h" #endif @@ -20,12 +19,13 @@ #include "teleport.h" #include "menu.h" #include "hook.h" +#include "weapon.h" #include "vehicle.h" #ifndef GTA3 class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon #else -class CheatMenu : Hook, Menu, Player, Teleport, Vehicle +class CheatMenu : Hook, Menu, Player, Teleport, Vehicle, Weapon #endif { private: @@ -36,7 +36,8 @@ private: static inline CallbackTable header { {"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw}, - {"Dummy", nullptr}, {"Vehicle", &Vehicle::Draw}, {"Menu", &Menu::Draw}, + {"Dummy", nullptr}, {"Vehicle", &Vehicle::Draw}, {"Weapon", &Weapon::Draw}, + {"Menu", &Menu::Draw}, }; #else static inline CallbackTable header diff --git a/src/ped.cpp b/src/ped.cpp index c2dac5e..4cf20a8 100644 --- a/src/ped.cpp +++ b/src/ped.cpp @@ -384,7 +384,7 @@ void Ped::Draw() }, [](std::string str) { return str != "-1"; /*Jetpack*/ } ); -#elif GTAVC +#else // GTA3 & GTAVC Ui::DrawJSON(Weapon::m_WeaponData, [](std::string& root, std::string& key, std::string& id) { diff --git a/src/weapon.cpp b/src/weapon.cpp index 5484bc6..15ea924 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -28,13 +28,20 @@ Weapon::Weapon() } #endif - uchar slot = player->m_nActiveWeaponSlot; + + uchar slot = BY_GAME(player->m_nActiveWeaponSlot, player->m_nActiveWeaponSlot, player->m_nCurrentWeapon); if (m_nCurrentWeaponSlot != slot) { + +#ifdef GTA3 + eWeaponType weaponType = player->m_aWeapons[slot].m_eWeaponType; +#else eWeaponType weaponType = player->m_aWeapons[slot].m_nType; +#endif + #ifdef GTASA CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType, player->GetWeaponSkill(weaponType)); -#elif GTAVC +#else // GTA3 & GTAVC CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType); if(m_bInfiniteAmmo) @@ -55,7 +62,7 @@ Weapon::Weapon() pWeaponInfo->m_fWeaponRange = 1000.0f; pWeaponInfo->m_fAccuracy = 1.0f; pWeaponInfo->m_nFlags.bReload2Start = true; -#elif GTAVC +#else // GTA3 & GTAVC pWeaponInfo->m_fRange = 1000.0f; #endif } @@ -95,25 +102,45 @@ void Weapon::SetGangWeapon(std::string& weapon_type) CGangs::SetGangWeapons(m_nSelectedGang, m_nGangWeaponList[m_nSelectedGang][0], m_nGangWeaponList[m_nSelectedGang][1], m_nGangWeaponList[m_nSelectedGang][2]); } -#elif GTAVC +#else // GTA3 & GTAVC // Implementation of SA opcode 0x555 static void ClearPlayerWeapon(eWeaponType weaponType) { - int weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_WeaponSlot; CPlayerPed *pPlayer = FindPlayerPed(); +#ifdef GTA3 + int weaponSlot = pPlayer->GetWeaponSlot(weaponType); +#else + int weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_WeaponSlot; +#endif + if ( weaponSlot != -1 ) { CWeapon *pWeapon = &pPlayer->m_aWeapons[weaponSlot]; - if ( pWeapon->m_nType == weaponType ) + +#ifdef GTA3 + if (pWeapon->m_eWeaponType == weaponType) { - if ( pPlayer->m_nActiveWeaponSlot == weaponSlot ) + if (pPlayer->m_nCurrentWeapon == weaponSlot) + { + Command(0, WEAPONTYPE_UNARMED); + } + // This doesn't work for melee weapons aka bats, chainsaw etc + pWeapon->m_eWeaponState = WEAPONSTATE_OUT_OF_AMMO; + pWeapon->m_nAmmoTotal = 0; + pWeapon->m_nAmmoInClip = 0; + } +#else + if (pWeapon->m_nType == weaponType) + { + if (pPlayer->m_nActiveWeaponSlot == weaponSlot) { CWeaponInfo *pWeaponInfo = CWeaponInfo::GetWeaponInfo(WEAPONTYPE_UNARMED); pPlayer->SetCurrentWeapon(pWeaponInfo->m_WeaponSlot); } pWeapon->Shutdown(); } +#endif } } @@ -124,7 +151,8 @@ static eWeaponType GetWeaponTypeFromModel(int model) for (size_t i = 0; i < 37; i++) { - int temp = CallAndReturn(i); // int __cdecl CPickups::ModelForWeapon(int a1) + + int temp = CallAndReturn(i); // int __cdecl CPickups::ModelForWeapon(int a1) if (temp == model) { @@ -181,7 +209,7 @@ void Weapon::GiveWeaponToPlayer(std::string& weapon_type) Command(model); } } -#elif GTAVC +#else // GTA3 & GTAVC void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::string& model) { CPlayerPed* player = FindPlayerPed(); @@ -193,6 +221,9 @@ void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::st eWeaponType weaponType = GetWeaponTypeFromModel(iModel); Command(hplayer, weaponType, m_nAmmoCount); Command(iModel); +#ifdef GTA3 + Command(0, weaponType); +#endif } #endif @@ -206,21 +237,26 @@ void Weapon::Draw() { float x, y, z; Command(hplayer, 0.0, 3.0, 0.0, &x, &y, &z); + +#ifdef GTA3 + eWeaponType weaponType = pPlayer->m_aWeapons[pPlayer->m_nCurrentWeapon].m_eWeaponType; +#else eWeaponType weaponType = pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType; +#endif if (weaponType) { int model = 0, pickup = 0; #ifdef GTASA Command(weaponType, &model); -#elif GTAVC - model = CallAndReturn(weaponType); // int __cdecl CPickups::ModelForWeapon(int a1) +#else // GTA3 & GTAVC + model = CallAndReturn(weaponType); // int __cdecl CPickups::ModelForWeapon(int a1) #endif Command(model, 3, 999, x, y, z, &pickup); #ifdef GTASA Command(hplayer, weaponType); -#elif GTAVC +#else // GTA3 & GTAVC ClearPlayerWeapon(weaponType); #endif } @@ -228,16 +264,18 @@ void Weapon::Draw() ImGui::SameLine(); if (ImGui::Button("Remove all", Ui::GetSize(3))) { - Command(hplayer); + pPlayer->ClearWeapons(); } ImGui::SameLine(); if (ImGui::Button("Remove current", Ui::GetSize(3))) { #ifdef GTASA - Command(hplayer, pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType); + Command(hplayer, pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType); #elif GTAVC - ClearPlayerWeapon(pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType); + ClearPlayerWeapon(pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType); +#else // GTA3 + ClearPlayerWeapon(pPlayer->m_aWeapons[pPlayer->m_nCurrentWeapon].m_eWeaponType); #endif } ImGui::Spacing(); @@ -278,9 +316,9 @@ void Weapon::Draw() #ifdef GTASA Ui::CheckboxAddress("Infinite ammo", 0x969178); -#endif ImGui::NextColumn(); -#ifdef GTAVC +#else + ImGui::NextColumn(); Ui::CheckboxWithHint("Infinite ammo", &m_bInfiniteAmmo); #endif if (Ui::CheckboxWithHint("Long range", &m_bLongRange)) @@ -330,7 +368,7 @@ void Weapon::Draw() [](std::string str) { return m_WeaponData.m_pJson->m_Data[str].get(); }, [](std::string str) { return str != "0"; /*Unarmed*/ } ); -#elif GTAVC +#else // GTA3 & GTAVC Ui::DrawJSON(m_WeaponData, GiveWeaponToPlayer, nullptr); #endif ImGui::EndTabItem(); diff --git a/src/weapon.h b/src/weapon.h index 296e892..d33c69e 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -13,7 +13,7 @@ public: static inline bool m_bMoveAim; static inline bool m_bMoveFire; static inline int m_nSelectedGang; -#elif GTAVC +#else // GTA3 & GTAVC static inline ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT }; static inline bool m_bInfiniteAmmo; #endif @@ -46,7 +46,7 @@ public: #ifdef GTASA static void GiveWeaponToPlayer(std::string& weapon_type); -#elif GTAVC +#else // GTA3 & GTAVC static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); #endif diff --git a/tools/premake5.lua b/tools/premake5.lua index 63fe276..a53e554 100644 --- a/tools/premake5.lua +++ b/tools/premake5.lua @@ -84,6 +84,8 @@ project "CheatMenuIII" "../src/hotkeys.cpp", "../src/vehicle.h", "../src/vehicle.cpp", + "../src/weapon.h", + "../src/weapon.cpp", "../src/filehandler.h", "../src/filehandler.cpp", "../src/dllmain.cpp"