CheatMenuSA/src/Ped.cpp

331 lines
9.1 KiB
C++
Raw Normal View History

2020-12-02 16:19:16 -05:00
#include "pch.h"
#include "Ped.h"
#include "Ui.h"
#include "Util.h"
2021-08-07 12:01:44 -04:00
#include <CPopulation.h>
2020-12-02 16:19:16 -05:00
Ped::Ped()
{
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2021-02-24 16:54:45 -05:00
if (GetModuleHandle("ExGangWars.asi"))
2021-08-07 12:01:44 -04:00
{
2021-06-18 12:49:11 -04:00
m_bExGangWarsInstalled = true;
2021-08-07 12:01:44 -04:00
}
2020-12-02 16:19:16 -05:00
2021-02-24 16:54:45 -05:00
Events::processScriptsEvent += []
{
2021-06-18 12:49:11 -04:00
if (!m_bImagesLoaded)
2021-02-24 16:54:45 -05:00
{
2021-07-17 03:51:02 -04:00
Util::LoadTextureDirectory(m_PedData, PLUGIN_PATH((char*)"CheatMenu\\peds.txd"));
2021-06-18 12:49:11 -04:00
m_bImagesLoaded = true;
2021-02-24 16:54:45 -05:00
}
2020-12-02 16:19:16 -05:00
};
2021-08-07 12:01:44 -04:00
#elif GTAVC
m_PedData.m_Json.LoadData(m_PedData.m_Categories, m_PedData.m_Selected);
#endif
2020-12-02 16:19:16 -05:00
}
Ped::~Ped()
{
for (CPed* ped : m_SpawnPed::m_List)
2020-12-02 16:19:16 -05:00
{
CWorld::Remove(ped);
ped->Remove();
}
}
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
void Ped::SpawnPed(std::string& model)
2021-08-07 12:01:44 -04:00
#elif GTAVC
void Ped::SpawnPed(std::string& cat, std::string& name, std::string& model)
#endif
2020-12-02 16:19:16 -05:00
{
if (m_SpawnPed::m_List.size() == SPAWN_PED_LIMIT)
2020-12-02 16:19:16 -05:00
{
2021-08-01 21:41:48 -04:00
SetHelpMessage("Max limit reached", false, false, false);
2020-12-02 16:19:16 -05:00
return;
}
2021-08-07 12:01:44 -04:00
if (BY_GAME(m_PedData.m_Json.m_Data.contains(model), true))
2020-12-02 16:19:16 -05:00
{
2021-02-24 16:54:45 -05:00
CPlayerPed* player = FindPlayerPed();
2020-12-02 16:19:16 -05:00
CVector pos = player->GetPosition();
pos.y += 1;
2021-02-24 16:54:45 -05:00
CPed* ped;
2020-12-02 16:19:16 -05:00
int hplayer;
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2021-06-18 12:49:11 -04:00
if (m_SpecialPedJson.m_Data.contains(model))
2020-12-02 16:19:16 -05:00
{
std::string name;
2021-06-18 12:49:11 -04:00
if (m_SpecialPedJson.m_Data.contains(model))
name = m_SpecialPedJson.m_Data[model].get<std::string>().c_str();
2020-12-02 16:19:16 -05:00
else
name = model;
CStreaming::RequestSpecialChar(1, name.c_str(), PRIORITY_REQUEST);
CStreaming::LoadAllRequestedModels(true);
Command<Commands::CREATE_CHAR>(m_SpawnPed::m_nSelectedPedType + 4, 291, pos.x, pos.y, pos.z + 1, &hplayer);
2020-12-02 16:19:16 -05:00
CStreaming::SetSpecialCharIsDeletable(291);
}
2021-08-07 12:01:44 -04:00
#elif GTAVC
if (cat == "Special") // Special model
2021-02-24 16:54:45 -05:00
{
2021-08-07 12:01:44 -04:00
static size_t currentSlot = 1;
Command<Commands::LOAD_SPECIAL_CHARACTER>(currentSlot, model.c_str());
Command<Commands::LOAD_ALL_MODELS_NOW>();
2021-08-09 14:26:49 -04:00
Command<Commands::CREATE_CHAR>(m_SpawnPed::m_nSelectedPedType + 4, 108+currentSlot, pos.x, pos.y, pos.z + 1, &hplayer);
2021-08-07 12:01:44 -04:00
Command<Commands::UNLOAD_SPECIAL_CHARACTER>(currentSlot);
++currentSlot;
if (currentSlot > 21)
{
currentSlot = 1;
}
}
#endif
else
{
2021-06-18 12:49:11 -04:00
int iModel = std::stoi(model);
CStreaming::RequestModel(iModel, eStreamingFlags::PRIORITY_REQUEST);
2020-12-02 16:19:16 -05:00
CStreaming::LoadAllRequestedModels(false);
Command<Commands::CREATE_CHAR>(m_SpawnPed::m_nSelectedPedType + 4, iModel, pos.x, pos.y, pos.z + 1, &hplayer);
2021-06-18 12:49:11 -04:00
CStreaming::SetModelIsDeletable(iModel);
2020-12-02 16:19:16 -05:00
}
ped = CPools::GetPed(hplayer);
if (m_SpawnPed::m_bPedMove)
m_SpawnPed::m_List.push_back(ped);
2020-12-02 16:19:16 -05:00
else
{
Command<Commands::MARK_CHAR_AS_NO_LONGER_NEEDED>(hplayer);
}
ped->m_nPedFlags.bPedIsBleeding = m_SpawnPed::m_bPedBleed;
ped->m_nWeaponAccuracy = m_SpawnPed::m_nAccuracy;
ped->m_fHealth = m_SpawnPed::m_nPedHealth;
2021-02-24 16:54:45 -05:00
2021-08-07 12:01:44 -04:00
#ifdef GTASA
if (m_SpawnPed::m_nWeaponId != 0)
2020-12-02 16:19:16 -05:00
{
int model = 0;
Command<Commands::GET_WEAPONTYPE_MODEL>(m_SpawnPed::m_nWeaponId, &model);
2020-12-02 16:19:16 -05:00
CStreaming::RequestModel(model, PRIORITY_REQUEST);
CStreaming::LoadAllRequestedModels(false);
Command<Commands::GIVE_WEAPON_TO_CHAR>(hplayer, m_SpawnPed::m_nWeaponId, 999);
2020-12-02 16:19:16 -05:00
}
2021-08-07 12:01:44 -04:00
#endif
2020-12-02 16:19:16 -05:00
}
}
2021-08-07 12:01:44 -04:00
2021-02-24 16:54:45 -05:00
void Ped::Draw()
2020-12-02 16:19:16 -05:00
{
if (ImGui::BeginTabBar("Ped", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll))
{
if (ImGui::BeginTabItem("Checkboxes"))
{
ImGui::Spacing();
ImGui::BeginChild("CheckboxesChild");
ImGui::Columns(2, 0, false);
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
Ui::CheckboxAddress("Elvis everywhere", 0x969157);
Ui::CheckboxAddress("Everyone is armed", 0x969140);
Ui::CheckboxAddress("Gangs control streets", 0x96915B);
Ui::CheckboxAddress("Gangs everywhere", 0x96915A);
Ui::CheckboxWithHint("Gang wars", &CGangWars::bGangWarsActive);
ImGui::NextColumn();
Ui::CheckboxAddress("Peds mayhem", 0x96913E);
Ui::CheckboxAddress("Peds attack with rockets", 0x969158);
Ui::CheckboxAddress("Peds riot", 0x969175);
Ui::CheckboxAddress("Slut magnet", 0x96915D);
2021-08-09 14:26:49 -04:00
#elif GTAVC
Ui::CheckboxAddress("Slut magnet", 0xA10B5F);
ImGui::NextColumn();
Ui::CheckboxAddress("Weapons for all", 0xA10AB3);
2021-08-07 12:01:44 -04:00
#endif
2020-12-02 16:19:16 -05:00
ImGui::Columns(1);
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Menus"))
{
ImGui::Spacing();
ImGui::BeginChild("MenusChild");
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
if (ImGui::CollapsingHeader("Gang wars"))
{
if (ImGui::Button("Start gang war", ImVec2(Ui::GetSize(2))))
{
if (Util::GetLargestGangInZone() == 1)
CGangWars::StartDefensiveGangWar();
else
CGangWars::StartOffensiveGangWar();
2021-02-24 16:54:45 -05:00
2020-12-02 16:19:16 -05:00
CGangWars::bGangWarsActive = true;
2021-02-24 16:54:45 -05:00
}
2020-12-02 16:19:16 -05:00
ImGui::SameLine();
if (ImGui::Button("End gang war", ImVec2(Ui::GetSize(2))))
CGangWars::EndGangWar(true);
ImGui::Dummy(ImVec2(0, 20));
ImGui::TextWrapped("Gang zone density:");
ImGui::Spacing();
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2);
for (int i = 0; i != 10; ++i)
{
CVector pos = FindPlayerPed()->GetPosition();
CZone szone = CZone();
2021-02-24 16:54:45 -05:00
CZone* pZone = &szone;
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
CZoneExtraInfo* zoneInfo = CTheZones::GetZoneInfo(&pos, &pZone);
int density = zoneInfo->m_nGangDensity[i];
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if (ImGui::SliderInt(m_GangNames[i].c_str(), &density, 0, 127))
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
zoneInfo->m_nGangDensity[i] = static_cast<char>(density);
2020-12-02 16:19:16 -05:00
Command<Commands::CLEAR_SPECIFIC_ZONES_TO_TRIGGER_GANG_WAR>();
CGangWars::bGangWarsActive = true;
}
}
ImGui::PopItemWidth();
ImGui::Spacing();
2021-06-18 12:49:11 -04:00
if (!m_bExGangWarsInstalled)
2020-12-02 16:19:16 -05:00
{
ImGui::TextWrapped("You'll need ExGangWars plugin to display some turf colors");
ImGui::Spacing();
if (ImGui::Button("Download ExGangWars", Ui::GetSize(1)))
2021-06-18 12:49:11 -04:00
ShellExecute(NULL, "open", "https://gtaforums.com/topic/682194-extended-gang-wars/", NULL, NULL,
SW_SHOWNORMAL);
2020-12-02 16:19:16 -05:00
}
ImGui::Spacing();
ImGui::Separator();
}
2021-08-07 12:01:44 -04:00
#endif
Ui::EditReference<float>("Pedestrian density multiplier", CPopulation::PedDensityMultiplier, 0, 1, 10);
#ifdef GTASA
2020-12-02 16:19:16 -05:00
if (ImGui::CollapsingHeader("Recruit anyone"))
{
2021-06-18 12:49:11 -04:00
static std::vector<Ui::NamedMemory> selectWeapon{
{"9mm", 0x96917C}, {"AK47", 0x96917D}, {"Rockets", 0x96917E}
};
Ui::RadioButtonAddress("Select weapon", selectWeapon);
ImGui::Spacing();
ImGui::Separator();
}
2021-08-07 12:01:44 -04:00
#endif
if (ImGui::CollapsingHeader("Remove peds in radius"))
{
2021-06-18 12:49:11 -04:00
ImGui::InputInt("Radius", &m_nPedRemoveRadius);
ImGui::Spacing();
2021-02-24 16:54:45 -05:00
if (ImGui::Button("Remove peds", Ui::GetSize(1)))
{
2021-02-24 16:54:45 -05:00
CPlayerPed* player = FindPlayerPed();
for (CPed* ped : CPools::ms_pPedPool)
{
2021-06-18 12:49:11 -04:00
if (DistanceBetweenPoints(ped->GetPosition(), player->GetPosition()) < m_nPedRemoveRadius
&& ped->m_pVehicle == nullptr && ped != player)
2021-08-07 12:01:44 -04:00
{
Command<Commands::DELETE_CHAR>(CPools::GetPedRef(ped));
2021-08-07 12:01:44 -04:00
}
}
}
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
ImGui::Separator();
}
ImGui::EndChild();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Spawn"))
{
ImGui::Spacing();
if (ImGui::Button("Remove frozen peds", Ui::GetSize(1)))
{
for (CPed* ped : m_SpawnPed::m_List)
2020-12-02 16:19:16 -05:00
{
CWorld::Remove(ped);
ped->Remove();
}
m_SpawnPed::m_List.clear();
2020-12-02 16:19:16 -05:00
}
ImGui::Spacing();
if (ImGui::BeginTabBar("SpawnPedBar"))
{
ImGui::Spacing();
if (ImGui::BeginTabItem("Spawner"))
{
ImGui::Spacing();
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2021-06-18 12:49:11 -04:00
Ui::DrawImages(m_PedData.m_ImagesList, ImVec2(65, 110), m_PedData.m_Categories, m_PedData.m_Selected,
m_PedData.m_Filter, SpawnPed, nullptr,
[](std::string str) { return m_PedData.m_Json.m_Data[str].get<std::string>(); });
2021-08-07 12:01:44 -04:00
#elif GTAVC
Ui::DrawJSON(m_PedData, SpawnPed, nullptr);
#endif
2020-12-02 16:19:16 -05:00
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Config"))
{
ImGui::Spacing();
ImGui::BeginChild("PedCOnfig");
ImGui::Columns(2, 0, false);
Ui::CheckboxWithHint("Don't move", &m_SpawnPed::m_bPedMove);
2020-12-02 16:19:16 -05:00
ImGui::NextColumn();
Ui::CheckboxWithHint("Ped bleed", &m_SpawnPed::m_bPedBleed);
2020-12-02 16:19:16 -05:00
ImGui::Columns(1);
ImGui::Spacing();
ImGui::SliderInt("Accuracy", &m_SpawnPed::m_nAccuracy, 0.0, 100.0);
if (ImGui::InputInt("Health", &m_SpawnPed::m_nPedHealth))
2020-12-02 16:19:16 -05:00
{
if (m_SpawnPed::m_nPedHealth > 1000)
m_SpawnPed::m_nPedHealth = 1000;
2020-12-02 16:19:16 -05:00
if (m_SpawnPed::m_nPedHealth < 0)
m_SpawnPed::m_nPedHealth = 0;
2020-12-02 16:19:16 -05:00
}
Ui::ListBox("Ped type", m_SpawnPed::m_PedTypeList, m_SpawnPed::m_nSelectedPedType);
2021-08-07 12:01:44 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
2021-06-18 12:49:11 -04:00
ImGui::Text("Selected weapon: %s",
2021-07-05 13:05:46 -04:00
Weapon::m_WeaponData.m_Json.m_Data[std::to_string(m_SpawnPed::m_nWeaponId)].get<std::string>().c_str());
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
2021-08-07 12:01:44 -04:00
2021-06-18 12:49:11 -04:00
Ui::DrawImages(Weapon::m_WeaponData.m_ImagesList, ImVec2(65, 65), Weapon::m_WeaponData.m_Categories,
Weapon::m_WeaponData.m_Selected, Weapon::m_WeaponData.m_Filter,
[](std::string str) { m_SpawnPed::m_nWeaponId = std::stoi(str); },
2021-06-18 12:49:11 -04:00
nullptr,
[](std::string str)
{
return Weapon::m_WeaponData.m_Json.m_Data[str].get<std::string>();
},
[](std::string str) { return str != "-1"; /*Jetpack*/ }
2020-12-02 16:19:16 -05:00
);
2021-08-07 12:01:44 -04:00
#endif
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
ImGui::EndChild();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
}