Add weapon tab

This commit is contained in:
Grinch_ 2021-10-24 14:15:06 +06:00
parent 4c5ec9d48e
commit 18be8aea42
6 changed files with 83 additions and 24 deletions

View File

@ -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"
}
}

View File

@ -11,7 +11,6 @@
#pragma once #pragma once
#ifndef GTA3 #ifndef GTA3
#include "animation.h" #include "animation.h"
#include "weapon.h"
#include "game.h" #include "game.h"
#include "visual.h" #include "visual.h"
#endif #endif
@ -20,12 +19,13 @@
#include "teleport.h" #include "teleport.h"
#include "menu.h" #include "menu.h"
#include "hook.h" #include "hook.h"
#include "weapon.h"
#include "vehicle.h" #include "vehicle.h"
#ifndef GTA3 #ifndef GTA3
class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon
#else #else
class CheatMenu : Hook, Menu, Player, Teleport, Vehicle class CheatMenu : Hook, Menu, Player, Teleport, Vehicle, Weapon
#endif #endif
{ {
private: private:
@ -36,7 +36,8 @@ private:
static inline CallbackTable header static inline CallbackTable header
{ {
{"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw}, {"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 #else
static inline CallbackTable header static inline CallbackTable header

View File

@ -384,7 +384,7 @@ void Ped::Draw()
}, },
[](std::string str) { return str != "-1"; /*Jetpack*/ } [](std::string str) { return str != "-1"; /*Jetpack*/ }
); );
#elif GTAVC #else // GTA3 & GTAVC
Ui::DrawJSON(Weapon::m_WeaponData, Ui::DrawJSON(Weapon::m_WeaponData,
[](std::string& root, std::string& key, std::string& id) [](std::string& root, std::string& key, std::string& id)
{ {

View File

@ -28,13 +28,20 @@ Weapon::Weapon()
} }
#endif #endif
uchar slot = player->m_nActiveWeaponSlot;
uchar slot = BY_GAME(player->m_nActiveWeaponSlot, player->m_nActiveWeaponSlot, player->m_nCurrentWeapon);
if (m_nCurrentWeaponSlot != slot) if (m_nCurrentWeaponSlot != slot)
{ {
#ifdef GTA3
eWeaponType weaponType = player->m_aWeapons[slot].m_eWeaponType;
#else
eWeaponType weaponType = player->m_aWeapons[slot].m_nType; eWeaponType weaponType = player->m_aWeapons[slot].m_nType;
#endif
#ifdef GTASA #ifdef GTASA
CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType, player->GetWeaponSkill(weaponType)); CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType, player->GetWeaponSkill(weaponType));
#elif GTAVC #else // GTA3 & GTAVC
CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType); CWeaponInfo* pWeaponInfo = CWeaponInfo::GetWeaponInfo(weaponType);
if(m_bInfiniteAmmo) if(m_bInfiniteAmmo)
@ -55,7 +62,7 @@ Weapon::Weapon()
pWeaponInfo->m_fWeaponRange = 1000.0f; pWeaponInfo->m_fWeaponRange = 1000.0f;
pWeaponInfo->m_fAccuracy = 1.0f; pWeaponInfo->m_fAccuracy = 1.0f;
pWeaponInfo->m_nFlags.bReload2Start = true; pWeaponInfo->m_nFlags.bReload2Start = true;
#elif GTAVC #else // GTA3 & GTAVC
pWeaponInfo->m_fRange = 1000.0f; pWeaponInfo->m_fRange = 1000.0f;
#endif #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], CGangs::SetGangWeapons(m_nSelectedGang, m_nGangWeaponList[m_nSelectedGang][0], m_nGangWeaponList[m_nSelectedGang][1],
m_nGangWeaponList[m_nSelectedGang][2]); m_nGangWeaponList[m_nSelectedGang][2]);
} }
#elif GTAVC #else // GTA3 & GTAVC
// Implementation of SA opcode 0x555 // Implementation of SA opcode 0x555
static void ClearPlayerWeapon(eWeaponType weaponType) static void ClearPlayerWeapon(eWeaponType weaponType)
{ {
int weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_WeaponSlot;
CPlayerPed *pPlayer = FindPlayerPed(); CPlayerPed *pPlayer = FindPlayerPed();
#ifdef GTA3
int weaponSlot = pPlayer->GetWeaponSlot(weaponType);
#else
int weaponSlot = CWeaponInfo::GetWeaponInfo(weaponType)->m_WeaponSlot;
#endif
if ( weaponSlot != -1 ) if ( weaponSlot != -1 )
{ {
CWeapon *pWeapon = &pPlayer->m_aWeapons[weaponSlot]; 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<Commands::SET_CURRENT_PLAYER_WEAPON>(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); CWeaponInfo *pWeaponInfo = CWeaponInfo::GetWeaponInfo(WEAPONTYPE_UNARMED);
pPlayer->SetCurrentWeapon(pWeaponInfo->m_WeaponSlot); pPlayer->SetCurrentWeapon(pWeaponInfo->m_WeaponSlot);
} }
pWeapon->Shutdown(); pWeapon->Shutdown();
} }
#endif
} }
} }
@ -124,7 +151,8 @@ static eWeaponType GetWeaponTypeFromModel(int model)
for (size_t i = 0; i < 37; i++) for (size_t i = 0; i < 37; i++)
{ {
int temp = CallAndReturn<int,0x4418B0>(i); // int __cdecl CPickups::ModelForWeapon(int a1)
int temp = CallAndReturn<int, BY_GAME(NULL, 0x4418B0, 0x430690)>(i); // int __cdecl CPickups::ModelForWeapon(int a1)
if (temp == model) if (temp == model)
{ {
@ -181,7 +209,7 @@ void Weapon::GiveWeaponToPlayer(std::string& weapon_type)
Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(model); Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(model);
} }
} }
#elif GTAVC #else // GTA3 & GTAVC
void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::string& model) void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::string& model)
{ {
CPlayerPed* player = FindPlayerPed(); CPlayerPed* player = FindPlayerPed();
@ -193,6 +221,9 @@ void Weapon::GiveWeaponToPlayer(std::string& rootkey, std::string& name, std::st
eWeaponType weaponType = GetWeaponTypeFromModel(iModel); eWeaponType weaponType = GetWeaponTypeFromModel(iModel);
Command<Commands::GIVE_WEAPON_TO_CHAR>(hplayer, weaponType, m_nAmmoCount); Command<Commands::GIVE_WEAPON_TO_CHAR>(hplayer, weaponType, m_nAmmoCount);
Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(iModel); Command<Commands::MARK_MODEL_AS_NO_LONGER_NEEDED>(iModel);
#ifdef GTA3
Command<Commands::SET_CURRENT_PLAYER_WEAPON>(0, weaponType);
#endif
} }
#endif #endif
@ -206,21 +237,26 @@ void Weapon::Draw()
{ {
float x, y, z; float x, y, z;
Command<Commands::GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS>(hplayer, 0.0, 3.0, 0.0, &x, &y, &z); Command<Commands::GET_OFFSET_FROM_CHAR_IN_WORLD_COORDS>(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; eWeaponType weaponType = pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType;
#endif
if (weaponType) if (weaponType)
{ {
int model = 0, pickup = 0; int model = 0, pickup = 0;
#ifdef GTASA #ifdef GTASA
Command<Commands::GET_WEAPONTYPE_MODEL>(weaponType, &model); Command<Commands::GET_WEAPONTYPE_MODEL>(weaponType, &model);
#elif GTAVC #else // GTA3 & GTAVC
model = CallAndReturn<int,0x4418B0>(weaponType); // int __cdecl CPickups::ModelForWeapon(int a1) model = CallAndReturn<int, BY_GAME(NULL, 0x4418B0, 0x430690)>(weaponType); // int __cdecl CPickups::ModelForWeapon(int a1)
#endif #endif
Command<Commands::CREATE_PICKUP_WITH_AMMO>(model, 3, 999, x, y, z, &pickup); Command<Commands::CREATE_PICKUP_WITH_AMMO>(model, 3, 999, x, y, z, &pickup);
#ifdef GTASA #ifdef GTASA
Command<Commands::REMOVE_WEAPON_FROM_CHAR>(hplayer, weaponType); Command<Commands::REMOVE_WEAPON_FROM_CHAR>(hplayer, weaponType);
#elif GTAVC #else // GTA3 & GTAVC
ClearPlayerWeapon(weaponType); ClearPlayerWeapon(weaponType);
#endif #endif
} }
@ -228,16 +264,18 @@ void Weapon::Draw()
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Remove all", Ui::GetSize(3))) if (ImGui::Button("Remove all", Ui::GetSize(3)))
{ {
Command<Commands::REMOVE_ALL_CHAR_WEAPONS>(hplayer); pPlayer->ClearWeapons();
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Remove current", Ui::GetSize(3))) if (ImGui::Button("Remove current", Ui::GetSize(3)))
{ {
#ifdef GTASA #ifdef GTASA
Command<Commands::REMOVE_WEAPON_FROM_CHAR>(hplayer, pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType); Command<Commands::REMOVE_WEAPON_FROM_CHAR>(hplayer, pPlayer->m_aWeapons[pPlayer->m_nActiveWeaponSlot].m_nType);
#elif GTAVC #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 #endif
} }
ImGui::Spacing(); ImGui::Spacing();
@ -278,9 +316,9 @@ void Weapon::Draw()
#ifdef GTASA #ifdef GTASA
Ui::CheckboxAddress("Infinite ammo", 0x969178); Ui::CheckboxAddress("Infinite ammo", 0x969178);
#endif
ImGui::NextColumn(); ImGui::NextColumn();
#ifdef GTAVC #else
ImGui::NextColumn();
Ui::CheckboxWithHint("Infinite ammo", &m_bInfiniteAmmo); Ui::CheckboxWithHint("Infinite ammo", &m_bInfiniteAmmo);
#endif #endif
if (Ui::CheckboxWithHint("Long range", &m_bLongRange)) 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>(); }, [](std::string str) { return m_WeaponData.m_pJson->m_Data[str].get<std::string>(); },
[](std::string str) { return str != "0"; /*Unarmed*/ } [](std::string str) { return str != "0"; /*Unarmed*/ }
); );
#elif GTAVC #else // GTA3 & GTAVC
Ui::DrawJSON(m_WeaponData, GiveWeaponToPlayer, nullptr); Ui::DrawJSON(m_WeaponData, GiveWeaponToPlayer, nullptr);
#endif #endif
ImGui::EndTabItem(); ImGui::EndTabItem();

View File

@ -13,7 +13,7 @@ public:
static inline bool m_bMoveAim; static inline bool m_bMoveAim;
static inline bool m_bMoveFire; static inline bool m_bMoveFire;
static inline int m_nSelectedGang; static inline int m_nSelectedGang;
#elif GTAVC #else // GTA3 & GTAVC
static inline ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT }; static inline ResourceStore m_WeaponData{ "weapon", eResourceType::TYPE_TEXT };
static inline bool m_bInfiniteAmmo; static inline bool m_bInfiniteAmmo;
#endif #endif
@ -46,7 +46,7 @@ public:
#ifdef GTASA #ifdef GTASA
static void GiveWeaponToPlayer(std::string& weapon_type); static void GiveWeaponToPlayer(std::string& weapon_type);
#elif GTAVC #else // GTA3 & GTAVC
static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name);
#endif #endif

View File

@ -84,6 +84,8 @@ project "CheatMenuIII"
"../src/hotkeys.cpp", "../src/hotkeys.cpp",
"../src/vehicle.h", "../src/vehicle.h",
"../src/vehicle.cpp", "../src/vehicle.cpp",
"../src/weapon.h",
"../src/weapon.cpp",
"../src/filehandler.h", "../src/filehandler.h",
"../src/filehandler.cpp", "../src/filehandler.cpp",
"../src/dllmain.cpp" "../src/dllmain.cpp"