From d6e9eb5f802bb07c5e2cba76b78de0cd506c7fb6 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Wed, 29 Jun 2022 02:23:03 +0600 Subject: [PATCH] Refactor --- README.md | 42 +-- resource/common/locale/English.toml | 5 +- src/animation.cpp | 182 +++++----- src/animation.h | 70 ++-- src/cheatmenu.cpp | 74 +--- src/game.cpp | 500 ++++++++++++++-------------- src/game.h | 69 ++-- src/menu.cpp | 2 +- src/menu.h | 2 +- src/ped.cpp | 200 +++++------ src/ped.h | 27 +- src/player.cpp | 21 +- src/player.h | 18 +- src/teleport.h | 7 +- src/weapon.cpp | 20 +- src/weapon.h | 37 +- 16 files changed, 598 insertions(+), 678 deletions(-) diff --git a/README.md b/README.md index 973fa8b..473b8e4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- +

Press Left Ctrl + M to open the menu. Doesn't work in multiplayer @@ -56,25 +56,25 @@ You can either open a issue here or directly contact me on discord (Recommended) ## Images

Show Images - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + +
## Submit Translations @@ -82,7 +82,7 @@ You can either open a issue here or directly contact me on discord (Recommended) The translations are loaded from `CheatMenuXX/locale/*.toml` files. Make a copy of the `English.toml` file and translate the texts there to your language. Rename the file to `your_language.toml` and make a pull request. -If you're language isn't supported ( Appears `???` in the menu. Check [here](https://github.com/user-grinch/Cheat-Menu/tree/rewrite/tools/subset/in.txt) for supported languages), open a [issue](https://github.com/user-grinch/Cheat-Menu/issues) asking for support. +If you're language isn't supported ( Appears `???` in the menu. Check [here](https://github.com/user-grinch/Cheat-Menu/tree/master/tools/subset/in.txt) for supported languages), open a [issue](https://github.com/user-grinch/Cheat-Menu/issues) asking for support. ## Required to build diff --git a/resource/common/locale/English.toml b/resource/common/locale/English.toml index bc6ec9d..8d89003 100644 --- a/resource/common/locale/English.toml +++ b/resource/common/locale/English.toml @@ -109,6 +109,7 @@ RandomCheats = "Random cheats" Sandstorm = "Sandstorm" SaveGame = "Save game (might cause game bugs)" Screenshot = "Screenshot shortcut" +ScreenshotTip = "Take screenshot using" ScreenshotTaken = "Screenshot taken" SelectCheats = "Select cheats" SelectDay = "Select day" @@ -249,7 +250,7 @@ EveryoneAtk = "Everyone attacks players" ExGangWarsTip = "You'll need ExGangWars plugin to display some turf colors" GangsControl = "Gangs control streets" GangsEverywhere = "Gangs everywhere" -GangWars = "Gang wars" +GangWars = "Gangs" Health = "Health" MaxLimit = "Max limit reached" NastyLimbs = "Nasty limbs" @@ -273,7 +274,7 @@ SpawnerTab = "Spawner" StartWar = "Start gang war" ThinBody = "Thin body effect" WeaponAll = "Weapons for all" -ZoneDensity = "Gang zone density:" +ZoneDensity = "Gang zone density (0-127):" [Player] AimSkinChanger = "Aim skin changer" diff --git a/src/animation.cpp b/src/animation.cpp index a6cb449..d5465e3 100644 --- a/src/animation.cpp +++ b/src/animation.cpp @@ -3,23 +3,24 @@ #include "ui.h" #include "util.h" -#ifndef GTASA +#ifdef GTA3 +#include +#include +#include +#include "eAnimations.h" +#include + +#elif GTAVC + +#include "../depend/kiero/minhook/MinHook.h" #include #include #include "eAnimations.h" #include #endif -#ifdef GTA3 -#include -#endif - -#ifdef GTAVC -#include "../depend/kiero/minhook/MinHook.h" -#endif - #ifdef GTASA -void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std::string& interior) +void Cutscene::Play(std::string& rootKey, std::string& cutsceneId, std::string& interior) { if (Util::IsOnCutscene()) { @@ -30,15 +31,15 @@ void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std: CPlayerPed* pPlayer = FindPlayerPed(); if (pPlayer) { - Cutscene::m_SceneName = cutsceneId; + m_SceneName = cutsceneId; Command(cutsceneId.c_str()); - Cutscene::m_nInterior = pPlayer->m_nAreaCode; + m_nInterior = pPlayer->m_nAreaCode; pPlayer->m_nAreaCode = std::stoi(interior); Command(pPlayer->m_nAreaCode); } } -void Animation::PlayParticle(std::string& rootKey, std::string& particle, std::string& dummy) +void Particle::Play(std::string& rootKey, std::string& particle, std::string& dummy) { CPlayerPed* pPlayer = FindPlayerPed(); if (pPlayer) @@ -47,12 +48,12 @@ void Animation::PlayParticle(std::string& rootKey, std::string& particle, std::s int handle; Command(particle.c_str(), pos.x, pos.y, pos.z, 1, &handle); Command(handle); - Particle::m_nParticleList.push_back(handle); + m_nParticleList.push_back(handle); } } -void Animation::RemoveParticle(std::string& ifp, std::string& particle, std::string& dummy) +void Particle::Remove(std::string& ifp, std::string& particle, std::string& dummy) { if (ifp == "Custom") { @@ -67,8 +68,8 @@ void Animation::RemoveParticle(std::string& ifp, std::string& particle, std::str } #elif GTAVC -// Thanks to codenulls(https://github.com/codenulls/) +// Thanks to codenulls(https://github.com/codenulls/) static auto OLD_CStreaming_RemoveModel = (bool(__cdecl*)(int))0x40D6E0; static bool NEW_CStreaming_RemoveModel(int modelID) { @@ -81,7 +82,30 @@ static bool NEW_CStreaming_RemoveModel(int modelID) return OLD_CStreaming_RemoveModel(modelID); } -void Animation::_PlayAnimation(RpClump* pClump, int animGroup, int animID, float blend) +bool _LoadAnimationBlock(const char* szBlockName) +{ + CAnimBlock* pAnimBlock = CAnimManager::GetAnimationBlock(szBlockName); + if (pAnimBlock) + { + if (!pAnimBlock->bLoaded) + { + int animIndex = ((unsigned char*)pAnimBlock - (unsigned char*)CAnimManager::ms_aAnimBlocks) / 32; + CStreaming::RequestModel(7916 + animIndex, 0x20 | MISSION_REQUIRED | PRIORITY_REQUEST); + CStreaming::LoadAllRequestedModels(true); + if (pAnimBlock->bLoaded) + { + return true; + } + } + else + { + return true; + } + } + return false; +} + +void _PlayAnim(RpClump* pClump, int animGroup, int animID, float blend, bool loop, bool secondary) { if (animGroup < CAnimManager::ms_numAnimAssocDefinitions) { @@ -109,42 +133,20 @@ void Animation::_PlayAnimation(RpClump* pClump, int animGroup, int animID, float pAnimAssoc = CAnimManager::BlendAnimation(pClump, animGroup, animID, blend); pAnimAssoc->m_nFlags = ANIMATION_STARTED | ANIMATION_MOVEMENT; - if (m_Loop) + if (loop) { pAnimAssoc->m_nFlags |= ANIMATION_LOOPED; } - if (m_bSecondary) + if (secondary) { pAnimAssoc->m_nFlags |= ANIMATION_PARTIAL; } } -bool Animation::_LoadAnimationBlock(const char* szBlockName) -{ - CAnimBlock* pAnimBlock = CAnimManager::GetAnimationBlock(szBlockName); - if (pAnimBlock) - { - if (!pAnimBlock->bLoaded) - { - int animIndex = ((unsigned char*)pAnimBlock - (unsigned char*)CAnimManager::ms_aAnimBlocks) / 32; - CStreaming::RequestModel(7916 + animIndex, 0x20 | MISSION_REQUIRED | PRIORITY_REQUEST); - CStreaming::LoadAllRequestedModels(true); - if (pAnimBlock->bLoaded) - { - return true; - } - } - else - { - return true; - } - } - return false; -} #else -void Animation::_PlayAnimation(RpClump* pClump, int animGroup, int animID, float blend) +void _PlayAnim(RpClump* pClump, int animGroup, int animID, float blend, bool loop, bool secondary) { CAnimBlendAssociation* pAnimStaticAssoc = CAnimManager::GetAnimAssociation(animGroup, animID); CAnimBlendAssociation* pAnimAssoc = RpAnimBlendClumpGetFirstAssociation(pClump); @@ -161,23 +163,21 @@ void Animation::_PlayAnimation(RpClump* pClump, int animGroup, int animID, float pAnimAssoc = CAnimManager::BlendAnimation(pClump, animGroup, animID, blend); pAnimAssoc->m_nFlags = 0x1 | 0x20; - if (m_Loop) + if (loop) { pAnimAssoc->m_nFlags |= 0x2; } - if (m_bSecondary) + if (secondary) { pAnimAssoc->m_nFlags |= 0x10; } } #endif - -void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& _) +void Animation::Play(std::string& ifp, std::string& anim, std::string& _) { CPed *pPed = m_PedAnim ? m_pTarget : FindPlayerPed(); - if (!pPed) { return; @@ -208,15 +208,26 @@ void Animation::PlayAnimation(std::string& ifp, std::string& anim, std::string& } #else - if (pPed) - { - int groupID, animID; - sscanf(ifp.c_str(), "%d$%d,", &groupID, &animID); - _PlayAnimation(pPed->m_pRwClump, groupID, animID, 4.0f); - } + int groupID, animID; + sscanf(ifp.c_str(), "%d$%d,", &groupID, &animID); + _PlayAnim(pPed->m_pRwClump, groupID, animID, 4.0f, m_Loop, m_bSecondary); #endif } +void Animation::Remove(std::string& ifp, std::string& anim, std::string& ifpRepeat) +{ + if (ifp == "Custom") + { + m_AnimData.m_pData->RemoveKey("Custom", anim.c_str()); + m_AnimData.m_pData->Save(); + SetHelpMessage(TEXT("Animation.AnimationRemoved")); + } + else + { + SetHelpMessage(TEXT("Animation.CustomAnimsOnly")); + } +} + void Animation::Init() { #ifdef GTASA @@ -291,7 +302,7 @@ void Animation::ShowPage() #ifdef GTASA Command(hPlayer); #else - _PlayAnimation(pPlayer->m_pRwClump, ANIM_GROUP_MAN, ANIM_MAN_IDLE_STANCE, 4.0f); + _PlayAnim(pPlayer->m_pRwClump, ANIM_GROUP_MAN, ANIM_MAN_IDLE_STANCE, 4.0f, m_Loop, m_bSecondary); #endif } } @@ -315,13 +326,16 @@ void Animation::ShowPage() { if (ImGui::CollapsingHeader(TEXT("Window.AddNew"))) { - ImGui::InputTextWithHint(TEXT("Animation.IFPName"), "ped", m_nIfpBuffer, INPUT_BUFFER_SIZE); - ImGui::InputTextWithHint(TEXT("Animation.AnimName"), "cower", m_nAnimBuffer, INPUT_BUFFER_SIZE); + static char animBuf[INPUT_BUFFER_SIZE]; + static char ifpBuf[INPUT_BUFFER_SIZE]; + + ImGui::InputTextWithHint(TEXT("Animation.IFPName"), "ped", ifpBuf, INPUT_BUFFER_SIZE); + ImGui::InputTextWithHint(TEXT("Animation.AnimName"), "cower", animBuf, INPUT_BUFFER_SIZE); ImGui::Spacing(); if (ImGui::Button(TEXT("Animation.AddAnimation"), Ui::GetSize())) { - std::string key = std::string("Custom.") + m_nAnimBuffer; - m_AnimData.m_pData->Set(key.c_str(), std::string(m_nIfpBuffer)); + std::string key = std::string("Custom.") + animBuf; + m_AnimData.m_pData->Set(key.c_str(), std::string(ifpBuf)); m_AnimData.m_pData->Save(); } } @@ -330,7 +344,7 @@ void Animation::ShowPage() if (ImGui::BeginChild("Anims Child")) { ImGui::Spacing(); - Ui::DrawList(m_AnimData, PlayAnimation, RemoveAnimation); + Ui::DrawList(m_AnimData, Play, Remove); ImGui::EndChild(); } } @@ -359,7 +373,7 @@ void Animation::ShowPage() if (ImGui::BeginChild("Cutscene Child")) { ImGui::Spacing(); - Ui::DrawList(Cutscene::m_Data, PlayCutscene, nullptr); + Ui::DrawList(Cutscene::m_Data, Cutscene::Play, nullptr); ImGui::EndChild(); } ImGui::EndTabItem(); @@ -389,11 +403,12 @@ void Animation::ShowPage() ImGui::Spacing(); if (ImGui::CollapsingHeader(TEXT("Window.AddNew"))) { - ImGui::InputTextWithHint(TEXT("Animation.ParticleName"), "kkjj_on_fire", Particle::m_NameBuffer, INPUT_BUFFER_SIZE); + static char buf[INPUT_BUFFER_SIZE]; + ImGui::InputTextWithHint(TEXT("Animation.ParticleName"), "kkjj_on_fire", buf, INPUT_BUFFER_SIZE); ImGui::Spacing(); if (ImGui::Button(TEXT("Animation.AddParticle"), Ui::GetSize())) { - std::string key = std::string("Custom.") + Particle::m_NameBuffer; + std::string key = std::string("Custom.") + buf; m_AnimData.m_pData->Set(key.c_str(), std::string("Dummy")); Particle::m_Data.m_pData->Save(); } @@ -402,22 +417,33 @@ void Animation::ShowPage() if (ImGui::BeginChild("Anims Child")) { ImGui::Spacing(); - Ui::DrawList(Particle::m_Data, PlayParticle, RemoveParticle); + Ui::DrawList(Particle::m_Data, Particle::Play, Particle::Remove); ImGui::EndChild(); } ImGui::EndTabItem(); } if (ImGui::BeginTabItem(TEXT("Animation.Styles"))) { - ImGui::Spacing(); - if (Ui::ListBox(TEXT("Animation.FightingStyle"), m_FightingStyleList, m_nFightingStyle)) + ImGui::Spacing(); + + static int fightStyle; + static const char* fightStyles = "Default\0Boxing\0Kung Fu\0Kick Boxing\0Punch Kick\0"; + static std::string walkStyle = "default"; + static std::vector walkStyles = { - Command(hPlayer, m_nFightingStyle + 4, 6); + "default", "man", "shuffle", "oldman", "gang1", "gang2", "oldfatman", + "fatman", "jogger", "drunkman", "blindman", "swat", "woman", "shopping", "busywoman", + "sexywoman", "pro", "oldwoman", "fatwoman", "jogwoman", "oldfatwoman", "skate" + }; + + if (ImGui::Combo(TEXT("Animation.FightingStyle"), &fightStyle, fightStyles)) + { + Command(hPlayer, fightStyle + 4, 6); SetHelpMessage(TEXT("Animation.FightingStyleSet")); } - if (Ui::ListBoxStr(TEXT("Animation.WalkingStyle"), m_WalkingStyleList, m_nWalkingStyle)) + if (Ui::ListBoxStr(TEXT("Animation.WalkingStyle"), walkStyles, walkStyle)) { - if (m_nWalkingStyle == "default") + if (walkStyle == "default") { patch::Set(0x609A4E, 0x4D48689); patch::Set(0x609A52, 0); @@ -425,10 +451,10 @@ void Animation::ShowPage() else { patch::Nop(0x609A4E, 6); - Command(m_nWalkingStyle.c_str()); + Command(walkStyle.c_str()); Command(); - Command(hPlayer, m_nWalkingStyle.c_str()); - Command(m_nWalkingStyle.c_str()); + Command(hPlayer, walkStyle.c_str()); + Command(walkStyle.c_str()); } SetHelpMessage(TEXT("Animation.WalkingStyleSet")); } @@ -437,18 +463,4 @@ void Animation::ShowPage() #endif ImGui::EndTabBar(); } -} - -void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string& ifpRepeat) -{ - if (ifp == "Custom") - { - m_AnimData.m_pData->RemoveKey("Custom", anim.c_str()); - m_AnimData.m_pData->Save(); - SetHelpMessage(TEXT("Animation.AnimationRemoved")); - } - else - { - SetHelpMessage(TEXT("Animation.CustomAnimsOnly")); - } } \ No newline at end of file diff --git a/src/animation.h b/src/animation.h index f115d16..521feb4 100644 --- a/src/animation.h +++ b/src/animation.h @@ -1,60 +1,40 @@ #pragma once #include "pch.h" +#ifdef GTASA +class Cutscene +{ +public: + static inline ResourceStore m_Data{ "cutscenes", eResourceType::TYPE_TEXT }; + static inline std::string m_SceneName; + static inline int m_nInterior; // player interior backup + static inline bool m_bRunning; + + static void Play(std::string& rootKey, std::string& cutsceneId, std::string& interior); +}; + +class Particle +{ +public: + static inline ResourceStore m_Data{ "particles", eResourceType::TYPE_TEXT }; + static inline std::vector m_nParticleList; + + static void Play(std::string& rootKey, std::string& particle, std::string& dummy); + static void Remove(std::string& ifp, std::string& anim, std::string& ifpRepeat); +}; +#endif + class Animation { private: - // Animation player static inline ResourceStore m_AnimData{ "animations", eResourceType::TYPE_TEXT }; - static inline char m_nAnimBuffer[INPUT_BUFFER_SIZE]; - static inline char m_nIfpBuffer[INPUT_BUFFER_SIZE]; static inline bool m_Loop; // loop animation static inline bool m_bSecondary; // play animation as secondary static inline bool m_PedAnim; static inline CPed *m_pTarget = nullptr; -#ifdef GTASA - // Cutscene player - struct Cutscene - { - static inline ResourceStore m_Data{ "cutscenes", eResourceType::TYPE_TEXT }; - static inline std::string m_SceneName; - static inline int m_nInterior; // player interior backup - static inline bool m_bRunning; - }; - - static inline int m_nFightingStyle; - static inline std::string m_nWalkingStyle = "default"; - static inline std::vector m_FightingStyleList = - { "Default", "Boxing", "Kung fu", "Kick Boxing", "Punch Kick" }; - static inline std::vector m_WalkingStyleList = - { - "default", "man", "shuffle", "oldman", "gang1", "gang2", "oldfatman", - "fatman", "jogger", "drunkman", "blindman", "swat", "woman", "shopping", "busywoman", - "sexywoman", "pro", "oldwoman", "fatwoman", "jogwoman", "oldfatwoman", "skate" - }; - - // Particle player - struct Particle - { - static inline ResourceStore m_Data{ "particles", eResourceType::TYPE_TEXT }; - static inline char m_NameBuffer[INPUT_BUFFER_SIZE]; - static inline std::vector m_nParticleList; - }; -#endif - - static void PlayAnimation(std::string& rootKey, std::string& anim, std::string& ifp); - static void RemoveAnimation(std::string& rootKey, std::string& anim, std::string& ifp); - static void RemoveParticle(std::string& ifp, std::string& anim, std::string& ifpRepeat); -#ifdef GTASA - static void PlayParticle(std::string& rootKey, std::string& particle, std::string& dummy); - static void PlayCutscene(std::string& rootKey, std::string& cutsceneId, std::string& interior); -#elif GTAVC - static bool _LoadAnimationBlock(const char* szBlockName); -#endif -#ifndef GTASA - static void _PlayAnimation(RpClump* pClump, int animGroup, int animID, float blend); -#endif + static void Play(std::string& rootKey, std::string& anim, std::string& ifp); + static void Remove(std::string& rootKey, std::string& anim, std::string& ifp); public: Animation() = delete; diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index 8c3ab8e..c0d7ddd 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -63,7 +63,7 @@ void CheatMenu::DrawWindow() #ifdef GTASA else { - Menu::DrawShortcutsWindow(); + Menu::DrawCommandWindow(); } #endif } @@ -261,75 +261,27 @@ void CheatMenu::Init() }; } -/* -* YIKES YOU AREN"T SUPPOSED TO FIND THIS!!! -* Probably a good easter egg for the upcoming anniversary ;) -*/ void CheatMenu::ShowAnniversaryPage() { Ui::CenterdText("Happy Anniversary!"); ImGui::NewLine(); - static bool showHistory; - if (showHistory) - { - ImGui::Checkbox("Show backstory", &showHistory); - ImGui::BeginChild("BACKSTORY"); - ImGui::TextWrapped("I wanted to share the backstory behind the initial idea or planning behind the menu." -" This is gonna be long so feel free to skip it if you're not interested."); - ImGui::NewLine(); - - ImGui::TextWrapped("The original idea of the menu comes way back from 2016! The inspiration for the menu" -" is from the 'CLEO CheatMenu by UNRATED69'. I wanted something that had more features and worked with SAxVCxLC." -" But there wasn't any other CheatMenu's back then. So, I wanted to create one myself but lacked the knowledge to do so."); - ImGui::NewLine(); - - ImGui::TextWrapped("In 2018, I finally got an opportunity to learn CLEO or GTA3Script after Junior-Djjr released" -" his tutorial. I started from basics but it soon became apparent that due to the limitations of CLEO, creating menus were" -" really tedious."); - - ImGui::NewLine(); - ImGui::TextWrapped("Later that year I found Moonloader, which had ImGui support. Meaning I could make menus" -" without brain fucking myself (kudos to everyone who writes 100s of lines in CLEO). I recall starting working on" -" the menu in October/November that same year."); - - ImGui::NewLine(); - ImGui::TextWrapped("I had high hopes the mod would succeed and the menu was nowhere near the state I wanted" -" it to be. But over a hot conversation with KKJJ, I finally decided to add the absolute bare minimum of features and" -" see what happens. And to my surprise, it even surpassed all of my expectations and became my most popular mod to this day."); - - ImGui::NewLine(); - ImGui::TextWrapped("A part of me is already cringing telling the story but it is what it is. I've learned" -" a lot working on this mod and I'm grateful. If you made it through all this way, kudos, you're awesome."); - - ImGui::NewLine(); - ImGui::TextWrapped("Again, thanks to you and everyone who used or helped me along the way. Enjoy ;)"); - - ImGui::EndChild(); - } - else - { - ImGui::TextWrapped("On this day, in 2019, the first public version of menu was released in MixMods Forum." + ImGui::TextWrapped("On this day, in 2019, the first public version of menu was released in MixMods Forum." " It's been a blast working on it and I've learned a lot in the process.\n\nThanks to you and everyone who used or" " contributed to the modification in any form or shape."); - ImGui::NewLine(); - ImGui::TextWrapped("Feel free to star the GitHub repo or join the discord server and provide feedback, ideas, or suggestions."); - ImGui::NewLine(); + ImGui::NewLine(); + ImGui::TextWrapped("Feel free to star the GitHub repo or join the discord server and provide feedback, ideas, or suggestions."); + ImGui::NewLine(); - if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Ui::GetSize(3)))) - { - ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL); - } - ImGui::SameLine(); - if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Ui::GetSize(3)))) - { - ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL); - } - - ImGui::NewLine(); - - ImGui::Checkbox("Show backstory", &showHistory); + if (ImGui::Button(TEXT("Menu.DiscordServer"), ImVec2(Ui::GetSize(3)))) + { + ShellExecute(nullptr, "open", DISCORD_INVITE, nullptr, nullptr, SW_SHOWNORMAL); + } + ImGui::SameLine(); + if (ImGui::Button(TEXT("Menu.GitHubRepo"), ImVec2(Ui::GetSize(3)))) + { + ShellExecute(nullptr, "open", GITHUB_LINK, nullptr, nullptr, SW_SHOWNORMAL); } } diff --git a/src/game.cpp b/src/game.cpp index 12d1110..e97b2b1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -9,9 +9,241 @@ #include #endif +#ifdef GTASA static bool bSaveGameFlag = false; +void Freecam::Process() +{ + static CVector m_fTotalMouse; -void Game::RealTimeClock() + int delta = (CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds); + + int ratio = 1 / (1 + (delta * m_nMul)); + int speed = m_nMul + m_nMul * ratio * delta; + + if (!m_bInitDone) + { + CPlayerPed* player = FindPlayerPed(); + Command(0, true); + + m_bHudState = patch::Get(BY_GAME(0xBA6769, 0x86963A, NULL)); // hud + patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), 0); // hud + m_bRadarState = patch::Get(BY_GAME(0xBA676C, 0xA10AB6, NULL)); // radar + + CVector playerPos = player->GetPosition(); + CPad::GetPad(0)->DisablePlayerControls = true; + + Command(playerPos.x, playerPos.y, playerPos.z, &m_nPed); + m_pPed = CPools::GetPed(m_nPed); + + m_fTotalMouse.x = player->GetHeading() + 89.6f; + m_fTotalMouse.y = 0; + playerPos.z -= 20; + + Command(m_nPed, true); + Command(m_nPed, false); + + m_pPed->m_bIsVisible = false; + Command(m_nPed, false); + m_pPed->SetPosn(playerPos); + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 1000, true); + Command(true); + patch::Set(0xBA676C, 2); // disable radar + m_bInitDone = true; + } + + CVector pos = m_pPed->GetPosition(); + + m_fTotalMouse.x = m_fTotalMouse.x - CPad::NewMouseControllerState.x / 250; + m_fTotalMouse.y = m_fTotalMouse.y + CPad::NewMouseControllerState.y / 3; + + if (m_fTotalMouse.x > 150) + { + m_fTotalMouse.y = 150; + } + + if (m_fTotalMouse.y < -150) + { + m_fTotalMouse.y = -150; + } + + if (freeCamTeleport.Pressed()) + { + CPlayerPed* player = FindPlayerPed(); + CVector pos = m_pPed->GetPosition(); + + CEntity* playerEntity = FindPlayerEntity(-1); + pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &playerEntity) + 0.5f; + Command(CPools::GetPedRef(player), pos.x, pos.y, pos.z); + + // disble them again cause they get enabled + CHud::bScriptDontDisplayRadar = true; + CHud::m_Wants_To_Draw_Hud = false; + SetHelpMessage(TEXT("Game.PlayerTeleported")); + } + + if (KeyPressed(VK_RCONTROL)) + { + speed /= 2; + } + + if (KeyPressed(VK_RSHIFT)) + { + speed *= 2; + } + + if (freeCamForward.PressedBasic() || freeCamBackward.PressedBasic()) + { + if (freeCamBackward.PressedBasic()) + { + speed *= -1; + } + + float angle; + Command(m_nPed, &angle); + pos.x += speed * cos(angle * 3.14159f / 180.0f); + pos.y += speed * sin(angle * 3.14159f / 180.0f); + pos.z += speed * 2 * sin(m_fTotalMouse.y / 3 * 3.14159f / 180.0f); + } + + if (freeCamLeft.PressedBasic() || freeCamRight.PressedBasic()) + { + if (freeCamLeft.PressedBasic()) + { + speed *= -1; + } + + float angle; + Command(m_nPed, &angle); + angle -= 90; + + pos.x += speed * cos(angle * 3.14159f / 180.0f); + pos.y += speed * sin(angle * 3.14159f / 180.0f); + } + + if (CPad::NewMouseControllerState.wheelUp) + { + if (m_fFOV > 10.0f) + { + m_fFOV -= 2.0f * speed; + } + + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); + Command(true); + } + + if (CPad::NewMouseControllerState.wheelDown) + { + if (m_fFOV < 115.0f) + { + m_fFOV += 2.0f * speed; + } + + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); + Command(true); + } + + m_pPed->SetHeading(m_fTotalMouse.x); + Command(m_nPed, 0.0, 0.0, 20.0, 90.0, 180, m_fTotalMouse.y, 0.0, 2); + m_pPed->SetPosn(pos); + CIplStore::AddIplsNeededAtPosn(pos); +} + +void Freecam::Clear() +{ + m_bInitDone = false; + Command(0, false); + patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), m_bHudState); // hud + patch::Set(BY_GAME(0xBA676C, 0xA10AB6, NULL), m_bRadarState); // radar + + CPad::GetPad(0)->DisablePlayerControls = false; + + Command(m_nPed); + m_pPed = nullptr; + + Command(false); + Command(); +} + +void RandomCheats::Process() +{ + if (m_bEnabled) + { + static bool genCheats = false; + if (!genCheats) + { + // Generate enabled cheats vector + for (auto [k, v] : m_pData.Items()) + { + /* + [ + cheat_id = [ cheat_name, state (true/false) ] + ] + */ + std::string key { k.str() }; + m_EnabledCheats[std::stoi(key)][0] = v.value_or("Unknown"); + m_EnabledCheats[std::stoi(key)][1] = "true"; + } + genCheats = true; + } + + uint timer = CTimer::m_snTimeInMilliseconds; + if ((timer - m_nTimer) > (static_cast(m_nInterval) * 1000)) + { + int id = Random(0, 91); + + for (int i = 0; i < 92; i++) + { + if (i == id) + { + if (m_EnabledCheats[i][1] == "true") + { + Call<0x438370>(id); // cheatEnableLegimate(int CheatID) + CMessages::AddMessage((char*)m_EnabledCheats[i][0].c_str(), 2000, 0, false); + m_nTimer = timer; + } + break; + } + } + } + } +} + +void RandomCheats::DrawBar() +{ + if (m_bEnabled && m_bProgressBar) + { + // Next cheat timer bar + uint screenWidth = screen::GetScreenWidth(); + uint screenHeight = screen::GetScreenHeight(); + uint timer = CTimer::m_snTimeInMilliseconds; + uint totalTime = m_nInterval; + float progress = (totalTime - (timer - m_nTimer) / 1000.0f) / totalTime; + + CRect sizeBox = CRect(0,0, screenWidth, screenHeight/50); + CRect sizeProgress = CRect(0,0, screenWidth*progress, screenHeight/50); + CRGBA colorBG = CRGBA(24, 99, 44, 255); + CRGBA colorProgress = CRGBA(33, 145, 63, 255); + + CSprite2d::DrawRect(sizeBox, colorBG); + CSprite2d::DrawRect(sizeProgress, colorProgress); + } +} + +void RandomCheats::DrawList() +{ + for (std::string* element : m_EnabledCheats) + { + bool selected = (element[1] == "true") ? true : false; + + if (ImGui::MenuItem(element[0].c_str(), nullptr, selected)) + { + element[1] = selected ? "false" : "true"; + } + } +} +#endif + +static void RealTimeClock() { time_t tmp = time(nullptr); struct tm* now = localtime(&tmp); @@ -37,19 +269,6 @@ void Game::RealTimeClock() void Game::Init() { #ifdef GTASA - // Generate enabled cheats vector - for (auto [k, v] : RandomCheats::m_pData.Items()) - { - /* - [ - cheat_id = [ cheat_name, state (true/false) ] - ] - */ - std::string key { k.str() }; - RandomCheats::m_EnabledCheats[std::stoi(key)][0] = v.value_or("Unknown"); - RandomCheats::m_EnabledCheats[std::stoi(key)][1] = "true"; - } - Events::drawMenuBackgroundEvent += []() { if (bSaveGameFlag) @@ -59,26 +278,7 @@ void Game::Init() } }; - Events::drawingEvent += []() - { - if (RandomCheats::m_bEnabled && RandomCheats::m_bProgressBar) - { - // Next cheat timer bar - uint screenWidth = screen::GetScreenWidth(); - uint screenHeight = screen::GetScreenHeight(); - uint timer = CTimer::m_snTimeInMilliseconds; - uint totalTime = RandomCheats::m_nInterval; - float progress = (totalTime - (timer - RandomCheats::m_nTimer) / 1000.0f) / totalTime; - - CRect sizeBox = CRect(0,0, screenWidth, screenHeight/50); - CRect sizeProgress = CRect(0,0, screenWidth*progress, screenHeight/50); - CRGBA colorBG = CRGBA(24, 99, 44, 255); - CRGBA colorProgress = CRGBA(33, 145, 63, 255); - - CSprite2d::DrawRect(sizeBox, colorBG); - CSprite2d::DrawRect(sizeProgress, colorProgress); - } - }; + Events::drawingEvent.Add(RandomCheats::DrawBar); #endif Events::processScriptsEvent += [] @@ -90,7 +290,9 @@ void Game::Init() if (HardMode::m_bEnabled) { if (pPlayer->m_fHealth > 50.0f) + { pPlayer->m_fHealth = 50.0f; + } pPlayer->m_fArmour = 0.0f; @@ -144,6 +346,7 @@ void Game::Init() } } + RandomCheats::Process(); #endif if (freeCam.Pressed()) @@ -151,7 +354,7 @@ void Game::Init() if (Freecam::m_bEnabled) { Freecam::m_bEnabled = false; - ClearFreecamStuff(); + Freecam::Clear(); } else { @@ -161,7 +364,7 @@ void Game::Init() if (Freecam::m_bEnabled) { - FreeCam(); + Freecam::Process(); } // improve this later @@ -176,30 +379,6 @@ void Game::Init() syncTimer = timer; } - -#ifdef GTASA - if (RandomCheats::m_bEnabled) - { - if ((timer - RandomCheats::m_nTimer) > (static_cast(RandomCheats::m_nInterval) * 1000)) - { - int id = Random(0, 91); - - for (int i = 0; i < 92; i++) - { - if (i == id) - { - if (RandomCheats::m_EnabledCheats[i][1] == "true") - { - Call<0x00438370>(id); // cheatEnableLegimate(int CheatID) - CMessages::AddMessage((char*)RandomCheats::m_EnabledCheats[i][0].c_str(), 2000, 0, false); - RandomCheats::m_nTimer = timer; - } - break; - } - } - } - } -#endif }; } @@ -224,187 +403,6 @@ void SetPlayerMission(std::string& rootkey, std::string& name, std::string& id) } } -void Game::FreeCam() -{ - int delta = (CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds); - - int ratio = 1 / (1 + (delta * Freecam::m_nMul)); - int speed = Freecam::m_nMul + Freecam::m_nMul * ratio * delta; - - if (!Freecam::m_bInitDone) - { - CPlayerPed* player = FindPlayerPed(); - Command(0, true); - - Freecam::m_bHudState = patch::Get(BY_GAME(0xBA6769, 0x86963A, NULL)); // hud - patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), 0); // hud - Freecam::m_bRadarState = patch::Get(BY_GAME(0xBA676C, 0xA10AB6, NULL)); // radar - - CVector playerPos = player->GetPosition(); - CPad::GetPad(0)->DisablePlayerControls = true; - - Command(playerPos.x, playerPos.y, playerPos.z, &Freecam::m_nPed); - Freecam::m_pPed = CPools::GetPed(Freecam::m_nPed); - - Freecam::m_fTotalMouse.x = player->GetHeading() + 89.6f; - Freecam::m_fTotalMouse.y = 0; - playerPos.z -= 20; - - Command(Freecam::m_nPed, true); - Command(Freecam::m_nPed, false); - -#ifdef GTASA - Freecam::m_pPed->m_bIsVisible = false; - Command(Freecam::m_nPed, false); - Freecam::m_pPed->SetPosn(playerPos); - TheCamera.LerpFOV(TheCamera.FindCamFOV(), Freecam::m_fFOV, 1000, true); - Command(true); - patch::Set(0xBA676C, 2); // disable radar -#elif GTAVC - Freecam::m_pPed->m_nFlags.bIsVisible = false; - Freecam::m_pPed->m_nFlags.bUseCollision = false; - Freecam::m_pPed->SetPosition(playerPos); - patch::Set(0xA10AB6, 1); // disable radar -#else - Freecam::m_pPed->m_nFlags.bIsVisible = false; - Freecam::m_pPed->m_nFlags.bUsesCollision = false; - Freecam::m_pPed->SetPosition(playerPos.x, playerPos.y, playerPos.z); -#endif - - Freecam::m_bInitDone = true; - } - - CVector pos = Freecam::m_pPed->GetPosition(); - - Freecam::m_fMouse.x = CPad::NewMouseControllerState.x; - Freecam::m_fMouse.y = CPad::NewMouseControllerState.y; - Freecam::m_fTotalMouse.x = Freecam::m_fTotalMouse.x - Freecam::m_fMouse.x / 250; - Freecam::m_fTotalMouse.y = Freecam::m_fTotalMouse.y + Freecam::m_fMouse.y / 3; - - if (Freecam::m_fTotalMouse.x > 150) - { - Freecam::m_fTotalMouse.y = 150; - } - - if (Freecam::m_fTotalMouse.y < -150) - { - Freecam::m_fTotalMouse.y = -150; - } - - if (freeCamTeleport.Pressed()) - { - CPlayerPed* player = FindPlayerPed(); - CVector pos = Freecam::m_pPed->GetPosition(); - -#ifdef GTASA - CEntity* playerEntity = FindPlayerEntity(-1); - pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &playerEntity) + 0.5f; -#else - pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr) + 0.5f; -#endif - Command(CPools::GetPedRef(player), pos.x, pos.y, pos.z); - - // disble them again cause they get enabled -#ifndef GTA3 - CHud::bScriptDontDisplayRadar = true; -#endif - CHud::m_Wants_To_Draw_Hud = false; - SetHelpMessage(TEXT("Game.PlayerTeleported")); - } - - if (KeyPressed(VK_RCONTROL)) - { - speed /= 2; - } - - if (KeyPressed(VK_RSHIFT)) - { - speed *= 2; - } - - if (freeCamForward.PressedBasic() || freeCamBackward.PressedBasic()) - { - if (freeCamBackward.PressedBasic()) - { - speed *= -1; - } - - float angle; - Command(Freecam::m_nPed, &angle); - pos.x += speed * cos(angle * 3.14159f / 180.0f); - pos.y += speed * sin(angle * 3.14159f / 180.0f); - pos.z += speed * 2 * sin(Freecam::m_fTotalMouse.y / 3 * 3.14159f / 180.0f); - } - - if (freeCamLeft.PressedBasic() || freeCamRight.PressedBasic()) - { - if (freeCamLeft.PressedBasic()) - { - speed *= -1; - } - - float angle; - Command(Freecam::m_nPed, &angle); - angle -= 90; - - pos.x += speed * cos(angle * 3.14159f / 180.0f); - pos.y += speed * sin(angle * 3.14159f / 180.0f); - } - -#ifdef GTASA - if (CPad::NewMouseControllerState.wheelUp) - { - if (Freecam::m_fFOV > 10.0f) - { - Freecam::m_fFOV -= 2.0f * speed; - } - - TheCamera.LerpFOV(TheCamera.FindCamFOV(), Freecam::m_fFOV, 250, true); - Command(true); - } - - if (CPad::NewMouseControllerState.wheelDown) - { - if (Freecam::m_fFOV < 115.0f) - { - Freecam::m_fFOV += 2.0f * speed; - } - - TheCamera.LerpFOV(TheCamera.FindCamFOV(), Freecam::m_fFOV, 250, true); - Command(true); - } - - Freecam::m_pPed->SetHeading(Freecam::m_fTotalMouse.x); - Command(Freecam::m_nPed, 0.0, 0.0, 20.0, 90.0, 180, Freecam::m_fTotalMouse.y, 0.0, 2); - Freecam::m_pPed->SetPosn(pos); - CIplStore::AddIplsNeededAtPosn(pos); -#elif GTAVC - Freecam::m_pPed->m_placement.SetHeading(Freecam::m_fTotalMouse.x); - Freecam::m_pPed->SetPosition(pos); -#else - Freecam::m_pPed->SetHeading(Freecam::m_fTotalMouse.x); - Freecam::m_pPed->SetPosition(pos.x, pos.y, pos.z); -#endif -} - -void Game::ClearFreecamStuff() -{ - Freecam::m_bInitDone = false; - Command(0, false); - patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), Freecam::m_bHudState); // hud - patch::Set(BY_GAME(0xBA676C, 0xA10AB6, NULL), Freecam::m_bRadarState); // radar - - CPad::GetPad(0)->DisablePlayerControls = false; - - Command(Freecam::m_nPed); - Freecam::m_pPed = nullptr; - -#ifdef GTASA - Command(false); -#endif - Command(); -} - void Game::ShowPage() { ImGui::Spacing(); @@ -548,9 +546,9 @@ void Game::ShowPage() Command(m_bKeepStuff); Command(m_bKeepStuff); } - Ui::CheckboxWithHint(TEXT("Game.Screenshot"), &m_bScreenShot, - (("Take screenshot using ") + quickSceenShot.GetNameString() - + "\nSaved inside 'GTA San Andreas User Files\\Gallery'").c_str()); + Ui::CheckboxWithHint(TEXT("Game.Screenshot"), &m_bScreenShot, + std::format("{} {}", TEXT("Game.ScreenshotTip"), + quickSceenShot.GetNameString()).c_str()); Ui::CheckboxWithHint(TEXT("Game.SolidWater"), &m_bSolidWater, TEXT("Game.SolidWaterText")); #endif if (ImGui::Checkbox(TEXT("Game.SyncSystemTime"), &m_bSyncTime)) @@ -574,7 +572,7 @@ void Game::ShowPage() if (ImGui::CollapsingHeader(TEXT("Game.CurrentDay"))) { int day = CClock::CurrentDay - 1; - if (Ui::ListBox(TEXT("Game.SelectDay"), m_DayNames, day)) + if (ImGui::Combo(TEXT("Game.SelectDay"), &day, "Sunday\0Monday\0Tuesday\0Wednesday\0Thursday\0Friday\0Saturday\0")) { CClock::CurrentDay = day + 1; } @@ -592,7 +590,7 @@ void Game::ShowPage() { if (!Freecam::m_bEnabled) { - ClearFreecamStuff(); + Freecam::Clear(); } } ImGui::Spacing(); @@ -851,15 +849,7 @@ void Game::ShowPage() ImGui::Separator(); if (ImGui::BeginChild("Cheats list")) { - for (std::string* element : RandomCheats::m_EnabledCheats) - { - bool selected = (element[1] == "true") ? true : false; - - if (ImGui::MenuItem(element[0].c_str(), nullptr, selected)) - { - element[1] = selected ? "false" : "true"; - } - } + RandomCheats::DrawList(); ImGui::EndChild(); } ImGui::EndTabItem(); diff --git a/src/game.h b/src/game.h index e8f015e..2021deb 100644 --- a/src/game.h +++ b/src/game.h @@ -1,6 +1,43 @@ #pragma once #include "pch.h" +#ifdef GTASA +class Freecam +{ +private: + static inline bool m_bInitDone; + static inline CPed* m_pPed; + static inline int m_nPed = -1; + static inline BYTE m_bHudState; + static inline BYTE m_bRadarState; + +public: + static inline bool m_bEnabled; + static inline int m_nMul = 1; + static inline float m_fFOV = 60.0f; + + static void Clear(); + static void Process(); +}; + +class RandomCheats +{ +private: + static inline std::string m_EnabledCheats[92][2]; + static inline DataStore m_pData {"cheats"}; + static inline uint m_nTimer; + +public: + static inline bool m_bEnabled; + static inline bool m_bProgressBar = true; + static inline int m_nInterval = 10; + + static void DrawBar(); + static void DrawList(); + static void Process(); +}; +#endif + class Game { private: @@ -9,19 +46,6 @@ private: static inline bool m_bDisableReplay; static inline bool m_bMissionTimer; - struct Freecam - { - static inline bool m_bEnabled; - static inline int m_nMul = 1; - static inline float m_fFOV = 60.0f; - static inline bool m_bInitDone; - static inline CPed* m_pPed; - static inline int m_nPed = -1; - static inline CVector m_fMouse; - static inline CVector m_fTotalMouse; - static inline BYTE m_bHudState; - static inline BYTE m_bRadarState; - }; struct HardMode { static inline bool m_bEnabled; @@ -38,27 +62,8 @@ private: static inline bool m_bScreenShot; static inline bool m_bKeepStuff; static inline ResourceStore m_StatData{ "stats", eResourceType::TYPE_TEXT }; - - static inline std::vector m_DayNames = - { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" - }; - - struct RandomCheats - { - static inline bool m_bEnabled; - static inline bool m_bProgressBar = true; - static inline std::string m_EnabledCheats[92][2]; - static inline int m_nInterval = 10; - static inline DataStore m_pData {"cheats"}; - static inline uint m_nTimer; - }; #endif - static void RealTimeClock(); - static void FreeCam(); - static void ClearFreecamStuff(); - public: static inline bool m_bFreezeTime; static inline bool m_bSyncTime; diff --git a/src/menu.cpp b/src/menu.cpp index 93926a0..fa9358d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -173,7 +173,7 @@ void Menu::DrawOverlay() } } -void Menu::DrawShortcutsWindow() +void Menu::DrawCommandWindow() { int resX = static_cast(screen::GetScreenWidth()); int resY = static_cast(screen::GetScreenHeight()); diff --git a/src/menu.h b/src/menu.h index fb7cbc1..81be981 100644 --- a/src/menu.h +++ b/src/menu.h @@ -53,6 +53,6 @@ public: static void Init(); static void ShowPage(); static void DrawOverlay(); - static void DrawShortcutsWindow(); + static void DrawCommandWindow(); static void ProcessCommands(); }; diff --git a/src/ped.cpp b/src/ped.cpp index 0f82083..36750d3 100644 --- a/src/ped.cpp +++ b/src/ped.cpp @@ -7,17 +7,24 @@ #ifdef GTASA #include + +static const char* pedTypeList = "Civ Male\0Civ Female\0Cop\0Ballas\0Grove Street Families" +"\0Los Santos Vagos\0San Fierro Rifa\0Da Nang Boys\0Mafia\0Mountain Cloud Triads" +"\0Varrio Los Aztecas\0Gang 9\0Medic\0Dealer\0Criminal\0Fireman\0Prostitute\0"; + +#elif GTAVC +static const char* pedTypeList = "Civ Male\0Civ Female\0Cop (crash)\0Cubans\0Haitians\0Streetwannabe's" +"\0Diaz' Gang\0Security Guards\0Biker Gang\0Vercetti Gang\0Golfers\0Gang 9\0Emergency\0Fireman" +"\0Criminal\0Unused\0Prostitute\0Special\0"; + +#else +static const char* pedTypeList = L"Civ Male\0Civ Female\0Cop\0Leones\0Triads\0Diablos\0Yakuza\0Yardies\0Colombians\0" +L"Hoods\0unused\0unused\0Emergency\0Fireman\0Criminal\0unused\0Prostitute\0Special\0"; + #endif void Ped::Init() { -#ifdef GTASA - if (GetModuleHandle("ExGangWars.asi")) - { - m_bExGangWarsInstalled = true; - } -#endif - /* Taken from gta chaos mod by Lordmau5 & _AG TODO: Implement in VC too @@ -85,7 +92,7 @@ void Ped::SpawnPed(std::string& model) void Ped::SpawnPed(std::string& cat, std::string& name, std::string& model) #endif { - if (SpawnPed::m_List.size() == SPAWN_PED_LIMIT) + if (Spawner::m_List.size() == SPAWN_PED_LIMIT) { SetHelpMessage(TEXT("Ped.MaxLimit")); return; @@ -117,7 +124,7 @@ void Ped::SpawnPed(std::string& cat, std::string& name, std::string& model) CStreaming::RequestSpecialChar(currentSlot, name.c_str(), PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(true); - Command(SpawnPed::m_nSelectedPedType + 4, 290 + currentSlot, pos.x, pos.y, pos.z + 1, &hplayer); + Command(Spawner::m_nSelectedPedType + 4, 290 + currentSlot, pos.x, pos.y, pos.z + 1, &hplayer); CStreaming::SetSpecialCharIsDeletable(290 + currentSlot); // SA has 10 slots @@ -154,31 +161,31 @@ void Ped::SpawnPed(std::string& cat, std::string& name, std::string& model) CStreaming::RequestModel(iModel, eStreamingFlags::PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); - Command(SpawnPed::m_nSelectedPedType + 4, iModel, pos.x, pos.y, pos.z + 1, &hplayer); + Command(Spawner::m_nSelectedPedType + 4, iModel, pos.x, pos.y, pos.z + 1, &hplayer); CStreaming::SetModelIsDeletable(iModel); } ped = CPools::GetPed(hplayer); - if (SpawnPed::m_bPedMove) + if (Spawner::m_bPedMove) { - SpawnPed::m_List.push_back(ped); + Spawner::m_List.push_back(ped); } else { Command(hplayer); } - ped->m_nPedFlags.bPedIsBleeding = SpawnPed::m_bPedBleed; - ped->m_nWeaponAccuracy = SpawnPed::m_nAccuracy; - ped->m_fHealth = SpawnPed::m_nPedHealth; + ped->m_nPedFlags.bPedIsBleeding = Spawner::m_bPedBleed; + ped->m_nWeaponAccuracy = Spawner::m_nAccuracy; + ped->m_fHealth = Spawner::m_nPedHealth; #ifdef GTASA - if (SpawnPed::m_nWeaponId != 0) + if (Spawner::m_nWeaponId != 0) { int model = 0; - Command(SpawnPed::m_nWeaponId, &model); + Command(Spawner::m_nWeaponId, &model); CStreaming::RequestModel(model, PRIORITY_REQUEST); CStreaming::LoadAllRequestedModels(false); - Command(hplayer, SpawnPed::m_nWeaponId, 999); + Command(hplayer, Spawner::m_nWeaponId, 999); } #endif } @@ -240,67 +247,6 @@ void Ped::ShowPage() { ImGui::Spacing(); ImGui::BeginChild("MenusChild"); - -#ifdef GTASA - if (ImGui::CollapsingHeader(TEXT("Ped.GangWars"))) - { - if (ImGui::Button(TEXT("Ped.StartWar"), ImVec2(Ui::GetSize(2)))) - { - if (Util::GetLargestGangInZone() == 1) - { - CGangWars::StartDefensiveGangWar(); - } - else - { - CGangWars::StartOffensiveGangWar(); - } - CGangWars::bGangWarsActive = true; - } - ImGui::SameLine(); - if (ImGui::Button(TEXT("Ped.EndWar"), ImVec2(Ui::GetSize(2)))) - { - CGangWars::EndGangWar(true); - } - - ImGui::Dummy(ImVec2(0, 20)); - ImGui::TextWrapped(TEXT("Ped.ZoneDensity")); - ImGui::Spacing(); - - ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2); - for (int i = 0; i != 10; ++i) - { - CVector pos = FindPlayerPed()->GetPosition(); - CZone szone = CZone(); - CZone* pZone = &szone; - - CZoneInfo* zoneInfo = CTheZones::GetZoneInfo(&pos, &pZone); - int density = zoneInfo->m_nGangDensity[i]; - - if (ImGui::SliderInt(m_GangList[i].c_str(), &density, 0, 127)) - { - zoneInfo->m_nGangDensity[i] = static_cast(density); - Command(); - CGangWars::bGangWarsActive = true; - } - } - ImGui::PopItemWidth(); - ImGui::Spacing(); - - if (!m_bExGangWarsInstalled) - { - ImGui::TextWrapped(TEXT("Ped.ExGangWarsTip")); - ImGui::Spacing(); - if (ImGui::Button(TEXT("Ped.DownloadExGangWars"), Ui::GetSize(1))) - { - ShellExecute(NULL, "open", "https://gtaforums.com/topic/682194-extended-gang-wars/", NULL, NULL, - SW_SHOWNORMAL); - } - } - - ImGui::Spacing(); - ImGui::Separator(); - } -#endif Ui::EditReference(TEXT("Ped.PedDensityMul"), CPopulation::PedDensityMultiplier, 0, 1, 10); #ifdef GTASA if (ImGui::CollapsingHeader(TEXT("Ped.RecruitAnyone"))) @@ -343,12 +289,12 @@ void Ped::ShowPage() ImGui::Spacing(); if (ImGui::Button(TEXT("Ped.RemoveFrozen"), Ui::GetSize(1))) { - for (CPed* ped : SpawnPed::m_List) + for (CPed* ped : Spawner::m_List) { CWorld::Remove(ped); ped->Remove(); } - SpawnPed::m_List.clear(); + Spawner::m_List.clear(); } ImGui::Spacing(); if (ImGui::BeginTabBar("SpawnPedBar")) @@ -374,41 +320,42 @@ void Ped::ShowPage() ImGui::Spacing(); ImGui::BeginChild("PedCOnfig"); ImGui::Columns(2, 0, false); - Ui::CheckboxWithHint(TEXT("Ped.NoMove"), &SpawnPed::m_bPedMove); + Ui::CheckboxWithHint(TEXT("Ped.NoMove"), &Spawner::m_bPedMove); ImGui::NextColumn(); - Ui::CheckboxWithHint(TEXT("Ped.PedBleed"), &SpawnPed::m_bPedBleed); + Ui::CheckboxWithHint(TEXT("Ped.PedBleed"), &Spawner::m_bPedBleed); ImGui::Columns(1); ImGui::Spacing(); - ImGui::SliderInt(TEXT("Ped.Accuracy"), &SpawnPed::m_nAccuracy, 0.0, 100.0); - if (ImGui::InputInt(TEXT("Ped.Health"), &SpawnPed::m_nPedHealth)) + ImGui::SliderInt(TEXT("Ped.Accuracy"), &Spawner::m_nAccuracy, 0.0, 100.0); + if (ImGui::InputInt(TEXT("Ped.Health"), &Spawner::m_nPedHealth)) { - if (SpawnPed::m_nPedHealth > 1000) + if (Spawner::m_nPedHealth > 1000) { - SpawnPed::m_nPedHealth = 1000; + Spawner::m_nPedHealth = 1000; } - if (SpawnPed::m_nPedHealth < 0) + if (Spawner::m_nPedHealth < 0) { - SpawnPed::m_nPedHealth = 0; + Spawner::m_nPedHealth = 0; } } - Ui::ListBox(TEXT("Ped.PedType"), SpawnPed::m_PedTypeList, SpawnPed::m_nSelectedPedType); + ImGui::Combo(TEXT("Ped.PedType"), &Spawner::m_nSelectedPedType, pedTypeList); + static std::string weaponName = "None"; ImGui::Spacing(); - ImGui::Text(TEXT("Ped.SelectedWeapon"), SpawnPed::m_nWeaponName.c_str()); + ImGui::Text(TEXT("Ped.SelectedWeapon"), weaponName.c_str()); ImGui::Spacing(); #ifdef GTASA Ui::DrawImages(Weapon::m_WeaponData, [](std::string str) { - SpawnPed::m_nWeaponId = std::stoi(str); + Spawner::m_nWeaponId = std::stoi(str); }, nullptr, [](std::string str) { - SpawnPed::m_nWeaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); - return SpawnPed::m_nWeaponName; + weaponName = Weapon::m_WeaponData.m_pData->Get(str.c_str(), "Unknown"); + return weaponName; }, [](std::string str) { @@ -417,10 +364,10 @@ void Ped::ShowPage() ); #else Ui::DrawList(Weapon::m_WeaponData, - [](std::string& root, std::string& key, std::string& id) + [](std::string& root, std::string& key, std::string& id) { SpawnPed::m_nWeaponId = std::stoi(id); - SpawnPed::m_nWeaponName = key; + weaponName = key; }, nullptr); #endif @@ -432,6 +379,67 @@ void Ped::ShowPage() } ImGui::EndTabItem(); } +#ifdef GTASA + if (ImGui::BeginTabItem(TEXT("Ped.GangWars"))) + { + ImGui::Spacing(); + if (ImGui::Button(TEXT("Ped.StartWar"), ImVec2(Ui::GetSize(2)))) + { + if (Util::GetLargestGangInZone() == 1) + { + CGangWars::StartDefensiveGangWar(); + } + else + { + CGangWars::StartOffensiveGangWar(); + } + CGangWars::bGangWarsActive = true; + } + ImGui::SameLine(); + if (ImGui::Button(TEXT("Ped.EndWar"), ImVec2(Ui::GetSize(2)))) + { + CGangWars::EndGangWar(true); + } + + ImGui::Dummy(ImVec2(0, 20)); + ImGui::TextWrapped(TEXT("Ped.ZoneDensity")); + ImGui::Spacing(); + + static const char* m_GangList[] = + { + "Ballas", "Grove street families", "Los santos vagos", "San fierro rifa", + "Da nang boys", "Mafia", "Mountain cloud triad", "Varrio los aztecas", "Gang9", "Gang10" + }; + ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2); + for (int i = 0; i != 10; ++i) + { + CVector pos = FindPlayerPed()->GetPosition(); + CZoneInfo* info = CTheZones::GetZoneInfo(&pos, nullptr); + int density = info->m_nGangDensity[i]; + if (ImGui::SliderInt(m_GangList[i], &density, 0, 127)) + { + info->m_nGangDensity[i] = static_cast(density); + Command(); + CGangWars::bGangWarsActive = true; + } + } + ImGui::PopItemWidth(); + static bool pluginRequired = (GetModuleHandle("ExGangWars.asi") == 0); + if (pluginRequired) + { + ImGui::Spacing(); + ImGui::TextWrapped(TEXT("Ped.ExGangWarsTip")); + ImGui::Spacing(); + if (ImGui::Button(TEXT("Ped.DownloadExGangWars"), Ui::GetSize(1))) + { + ShellExecute(NULL, "open", "https://gtaforums.com/topic/682194-extended-gang-wars/", NULL, NULL, + SW_SHOWNORMAL); + } + } + + ImGui::EndTabItem(); + } +#endif ImGui::EndTabBar(); } } diff --git a/src/ped.h b/src/ped.h index 5b0c3cb..db56218 100644 --- a/src/ped.h +++ b/src/ped.h @@ -5,17 +5,9 @@ class Ped { private: static inline bool m_bBigHead; -#ifdef GTASA - static inline bool m_bExGangWarsInstalled; static inline bool m_bThinBody; - static inline std::vector m_GangList = - { - "Ballas", "Grove street families", "Los santos vagos", "San fierro rifa", - "Da nang boys", "Mafia", "Mountain cloud triad", "Varrio los aztecas", "Gang9", "Gang10" - }; -#endif - struct SpawnPed + struct Spawner { static inline std::vector m_List; static inline int m_nAccuracy = 50; @@ -24,27 +16,10 @@ private: static inline bool m_bPedBleed; static inline int m_nSelectedPedType; static inline int m_nWeaponId; - static inline std::string m_nWeaponName = "None"; - static inline std::vector m_PedTypeList = - { -#ifdef GTASA - "Civ Male", "Civ Female", "Cop", "Ballas", "Grove Street Families", "Los Santos Vagos", - "San Fierro Rifa", "Da Nang Boys", "Mafia", "Mountain Cloud Triads", "Varrio Los Aztecas", - "Gang 9", "Medic", "Dealer", "Criminal", "Fireman", "Prostitute" -#elif GTAVC - "Civ Male", "Civ Female", "Cop (crash)", "Cubans", "Haitians", "Streetwannabe's", "Diaz' Gang", - "Security Guards", "Biker Gang", "Vercetti Gang", "Golfers", "Gang 9", "Emergency", - "Fireman", "Criminal", "Unused", "Prostitute", "Special" -#else - "Civ Male", "Civ Female", "Cop", "Leones", "Triads", "Diablos", "Yakuza", "Yardies", "Colombians", - "Hoods", "unused", "unused", "Emergency", "Fireman", "Criminal", "unused", "Prostitute", "Special" -#endif - }; }; #ifdef GTASA static void SpawnPed(std::string& model); - static void BigHeadEffect(CPed *ped); #else static void SpawnPed(std::string& cat, std::string& name, std::string& model); #endif diff --git a/src/player.cpp b/src/player.cpp index 21e770d..80b0ce8 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -7,6 +7,14 @@ #ifdef GTASA #include "ped.h" +static inline const char* clothNameList[18] = +{ + "Shirts", "Heads", "Trousers", "Shoes", "Tattoos left lower arm", "Tattoos left upper arm", + "Tattoos right upper arm", "Tattoos right lower arm", "Tattoos back", "Tattoos left chest", + "Tattoos right chest", "Tattoos stomach", "Tattoos lower back", "Necklaces", "Watches", + "Glasses", "Hats", "Extras" +}; + static inline void PlayerModelBrokenFix() { CPlayerPed* pPlayer = FindPlayerPed(); @@ -21,11 +29,11 @@ static inline void PlayerModelBrokenFix() Taken from gta chaos mod by Lordmau5 https://github.com/gta-chaos-mod/Trilogy-ASI-Script */ -void Player::TopDownCameraView() +void Player::TopDownCamera::Process() { CPlayerPed *player = FindPlayerPed (); CVector pos = player->GetPosition (); - float curOffset = TopDownCamera::m_fOffset; + float curOffset = m_fOffset; // drunk effect causes issues Command (0, 0); @@ -207,7 +215,7 @@ void Player::Init() if (TopDownCamera::m_bEnabled) { - TopDownCameraView(); + TopDownCamera::Process(); } if (m_bAimSkinChanger && aimSkinChanger.Pressed()) @@ -612,21 +620,22 @@ void Player::ShowPage() if (pPlayer->m_nModelIndex == 0) { ImGui::Columns(3, 0, false); - if (ImGui::RadioButton(TEXT("Player.Fat"), &m_nUiBodyState, 2)) + static int bodyState = 0; + if (ImGui::RadioButton(TEXT("Player.Fat"), &bodyState, 2)) { CCheat::FatCheat(); } ImGui::NextColumn(); - if (ImGui::RadioButton(TEXT("Player.Muscle"), &m_nUiBodyState, 1)) + if (ImGui::RadioButton(TEXT("Player.Muscle"), &bodyState, 1)) { CCheat::MuscleCheat(); } ImGui::NextColumn(); - if (ImGui::RadioButton(TEXT("Player.Skinny"), &m_nUiBodyState, 0)) + if (ImGui::RadioButton(TEXT("Player.Skinny"), &bodyState, 0)) { CCheat::SkinnyCheat(); } diff --git a/src/player.h b/src/player.h index ddb162d..884119a 100644 --- a/src/player.h +++ b/src/player.h @@ -18,7 +18,6 @@ private: static inline bool m_bAimSkinChanger; static inline bool m_bDrunkEffect; static inline bool m_bFastSprint; - static inline int m_nUiBodyState; static inline ResourceStore m_ClothData { "clothes", eResourceType::TYPE_IMAGE, ImVec2(70, 100)}; struct CustomSkins { @@ -28,26 +27,17 @@ private: struct TopDownCamera { + public: static inline bool m_bEnabled = false; static inline float m_fOffset = 40.0f; + + static void Process(); }; - static inline const char* clothNameList[18] = - { - "Shirts", "Heads", "Trousers", "Shoes", "Tattoos left lower arm", "Tattoos left upper arm", - "Tattoos right upper arm", "Tattoos right lower arm", "Tattoos back", "Tattoos left chest", - "Tattoos right chest", "Tattoos stomach", "Tattoos lower back", "Necklaces", "Watches", - "Glasses", "Hats", "Extras" - }; -#else - static inline ResourceStore skinData { BY_GAME(NULL, "skins", "peds"), eResourceType::TYPE_TEXT }; -#endif - -#ifdef GTASA static void ChangePlayerModel(std::string& model); static void ChangePlayerCloth(std::string& model); - static void TopDownCameraView(); #else + static inline ResourceStore skinData { BY_GAME(NULL, "skins", "peds"), eResourceType::TYPE_TEXT }; static void ChangePlayerModel(std::string& cat, std::string& name, std::string& id); #endif diff --git a/src/teleport.h b/src/teleport.h index 8dd7cd4..3292749 100644 --- a/src/teleport.h +++ b/src/teleport.h @@ -11,10 +11,6 @@ private: static inline char m_nLocationBuffer[INPUT_BUFFER_SIZE]; static inline uint m_nQuickTeleportTimer; -#ifdef GTASA - static inline DataStore m_SpriteData {"sprites"}; -#endif - struct QuickTP { static inline bool m_bEnabled; @@ -22,8 +18,9 @@ private: static inline uint m_nTimer; }; - #ifdef GTASA + static inline DataStore m_SpriteData {"sprites"}; + /* Generates radar sprite coordinates on the fly. Shouldn't get saved in 'teleport.json', needs to be cleared at game shutdown. diff --git a/src/weapon.cpp b/src/weapon.cpp index d683381..6e15217 100644 --- a/src/weapon.cpp +++ b/src/weapon.cpp @@ -27,9 +27,9 @@ void Weapon::Init() } #endif - - uchar slot = BY_GAME(player->m_nActiveWeaponSlot, player->m_nSelectedWepSlot, player->m_nSelectedWepSlot); - if (m_nCurrentWeaponSlot != slot) + static uint8_t curWeaponSlot; + uint8_t slot = BY_GAME(player->m_nActiveWeaponSlot, player->m_nSelectedWepSlot, player->m_nSelectedWepSlot); + if (curWeaponSlot != slot) { eWeaponType weaponType = player->m_aWeapons[slot].m_eWeaponType; @@ -83,7 +83,7 @@ void Weapon::Init() pWeaponInfo->m_nFlags.bMoveFire = true; } #endif - m_nCurrentWeaponSlot = slot; + curWeaponSlot = slot; } }; } @@ -366,9 +366,15 @@ void Weapon::ShowPage() if (ImGui::BeginTabItem(TEXT("Weapon.GangWeaponEditor"))) { ImGui::Spacing(); - Ui::ListBox(TEXT("Weapon.SelectGang"), m_GangList, m_nSelectedGang); - std::vector vec = {TEXT("Weapon.Weapon1"), TEXT("Weapon.Weapon2"), TEXT("Weapon.Weapon3")}; - Ui::ListBox(TEXT("Ped.SelectWeapon"), vec, m_nSelectedWeapon); + static const char* gangList = + { + "Ballas\0Grove street families\0Los santos vagos\0San fierro rifa\0Da nang boys\0" + "Mafia\0Mountain cloud triad\0Varrio los aztecas\0Gang9\0Gang10\0" + }; + std::string str = std::format("{}\0{}\0{}\0", TEXT("Weapon.Weapon1"), TEXT("Weapon.Weapon2"), + TEXT("Weapon.Weapon3")); + ImGui::Combo(TEXT("Weapon.SelectGang"), &m_nSelectedGang, gangList); + ImGui::Combo(TEXT("Ped.SelectWeapon"), &m_nSelectedWeapon, str.c_str()); ImGui::Spacing(); std::string key = std::to_string(m_nGangWeaponList[m_nSelectedGang][m_nSelectedWeapon]); diff --git a/src/weapon.h b/src/weapon.h index d6f4175..dbf3dba 100644 --- a/src/weapon.h +++ b/src/weapon.h @@ -4,6 +4,12 @@ class Weapon { private: + static inline bool m_bFastReload; + static inline bool m_bHugeDamage; + static inline bool m_bLongRange; + static inline int m_nAmmoCount = 99999; + static inline int m_nSelectedWeapon; + #ifdef GTASA static inline bool m_bAutoAim; static inline bool m_bRapidFire; @@ -24,37 +30,26 @@ private: {WEAPON_UNARMED, WEAPON_UNARMED, WEAPON_UNARMED}, // Gang 9 {WEAPON_UNARMED, WEAPON_UNARMED, WEAPON_UNARMED}, // Gang 10 }; - - static inline std::vector m_GangList = - { - "Ballas", "Grove street families", "Los santos vagos", "San fierro rifa", - "Da nang boys", "Mafia", "Mountain cloud triad", "Varrio los aztecas", "Gang9", "Gang10" - }; -#else - static inline bool m_bInfiniteAmmo; -#endif - static inline bool m_bFastReload; - static inline bool m_bHugeDamage; - static inline bool m_bLongRange; - static inline int m_nAmmoCount = 99999; - static inline uchar m_nCurrentWeaponSlot = -1; - static inline int m_nSelectedWeapon; - -public: -#ifdef GTASA static inline ResourceStore m_WeaponData { "weapons", eResourceType::TYPE_BOTH, ImVec2(65, 65) }; - static void GiveWeaponToPlayer(std::string& weapon_type); - static void SetGangWeapon(std::string& weapon_type); #else + static inline bool m_bInfiniteAmmo; static inline ResourceStore m_WeaponData { "weapons", eResourceType::TYPE_TEXT }; - static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); #endif +public: Weapon() = delete; Weapon(const Weapon&) = delete; static void Init(); static void ShowPage(); + +#ifdef GTASA + static void GiveWeaponToPlayer(std::string& weapon_type); + static void SetGangWeapon(std::string& weapon_type); +#else + static void GiveWeaponToPlayer(std::string& rootkey, std::string& model, std::string& name); +#endif }; +