From fe67e21eeb6118a2d4e2bd47371b54ba22e2d303 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Mon, 8 Aug 2022 07:16:35 +0600 Subject: [PATCH] Refactor freecam, neon & randomcheats --- resource/common/locale/English.toml | 1 - src/custom/freecam.cpp | 191 ++++++++++++++++ src/custom/freecam.h | 34 +++ src/custom/neon.cpp | 90 ++++---- src/custom/neon.h | 33 ++- src/custom/randomcheats.cpp | 80 +++++++ src/custom/randomcheats.h | 32 +++ src/interface/icheat.hpp | 59 +++++ src/pages/game.cpp | 334 +++------------------------- src/pages/game.h | 37 --- src/pages/vehicle.cpp | 17 +- src/utils/log.cpp | 1 - tools/premake5.lua | 2 - 13 files changed, 499 insertions(+), 412 deletions(-) create mode 100644 src/custom/freecam.cpp create mode 100644 src/custom/freecam.h create mode 100644 src/custom/randomcheats.cpp create mode 100644 src/custom/randomcheats.h create mode 100644 src/interface/icheat.hpp diff --git a/resource/common/locale/English.toml b/resource/common/locale/English.toml index a116628..26ac767 100644 --- a/resource/common/locale/English.toml +++ b/resource/common/locale/English.toml @@ -359,7 +359,6 @@ LungCapacity = "Lung capacity" MaxAppeal = "Max sex appeal" MaxArmour = "Max armour" MaxHealth = "Max health" -MeeleProof = "Meele proof" MegaJump = "Mega jump" MegaPunch = "Mega punch" Money = "Money" diff --git a/src/custom/freecam.cpp b/src/custom/freecam.cpp new file mode 100644 index 0000000..eb45250 --- /dev/null +++ b/src/custom/freecam.cpp @@ -0,0 +1,191 @@ +#include "pch.h" +#ifdef GTASA +#include "freecam.h" + +static CVector gTotalMouse; +FreecamMgr& Freecam = *FreecamMgr::Get(); + +void FreecamMgr::Enable() +{ + CPlayerPed* player = FindPlayerPed(); + Command(0, true); + + // set hud & radar states + m_bHudState = patch::Get(BY_GAME(0xBA6769, 0x86963A, NULL)); // hud + m_bRadarState = patch::Get(BY_GAME(0xBA676C, 0xA10AB6, NULL)); // radar + patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), 0); // disable hud + patch::Set(0xBA676C, 2); // disable radar + + // create our dummy character + CVector pos = player->GetPosition(); + Command(pos.x, pos.y, pos.z, &m_nPed); + m_pPed = CPools::GetPed(m_nPed); + m_pPed->m_bIsVisible = false; + + gTotalMouse.x = player->GetHeading() + 89.6f; + gTotalMouse.y = 0; + pos.z -= 20; + m_pPed->SetPosn(pos); + + Command(m_nPed, true); + Command(m_nPed, false); + Command(m_nPed, false); + + // set camera fov + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 1000, true); + Command(true); +} + +void FreecamMgr::Process() +{ + int delta = (CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds); + int ratio = 1 / (1 + (delta * m_nMul)); + int speed = m_nMul + m_nMul * ratio * delta; + CVector pos = m_pPed->GetPosition(); + + gTotalMouse.x -= CPad::NewMouseControllerState.x / 250; + gTotalMouse.y += CPad::NewMouseControllerState.y / 3; + + gTotalMouse.x = gTotalMouse.x > 150 ? 150 : gTotalMouse.x; + gTotalMouse.x = gTotalMouse.x < -150 ? -150 : gTotalMouse.x; + + 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; + Util::SetMessage(TEXT("Game.PlayerTeleported")); + } + + if (KeyPressed(VK_MENU) && m_nMul > 1) + { + speed /= 2; + } + + if (KeyPressed(VK_SHIFT)) + { + speed *= 2; + } + + if (freeCamForward.PressedRealtime() || freeCamBackward.PressedRealtime()) + { + if (freeCamBackward.PressedRealtime()) + { + speed *= -1; + } + + float angle; + Command(m_nPed, &angle); + + if (KeyPressed(VK_CONTROL)) + { + pos.z += speed * sin(90.0f / 3 * 3.14159f / 180.0f); + } + else + { + pos.x += speed * cos(angle * 3.14159f / 180.0f); + pos.y += speed * sin(angle * 3.14159f / 180.0f); + + if (!KeyPressed(VK_SPACE)) + { + pos.z += speed * 2 * sin(gTotalMouse.y / 3 * 3.14159f / 180.0f); + } + } + } + + if (freeCamLeft.PressedRealtime() || freeCamRight.PressedRealtime()) + { + if (freeCamLeft.PressedRealtime()) + { + 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 (KeyPressed(VK_CONTROL)) + { + if (m_fFOV > 10.0f) + { + m_fFOV -= 2.0f * speed; + } + + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); + Command(true); + } + else + { + if (m_nMul < 10) + { + ++m_nMul; + Util::SetMessage(std::format("Speed: {}", m_nMul).c_str()); + } + } + } + + if (CPad::NewMouseControllerState.wheelDown) + { + if (KeyPressed(VK_CONTROL)) + { + if (m_fFOV < 115.0f) + { + m_fFOV += 2.0f * speed; + } + + TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); + Command(true); + } + else + { + if (m_nMul > 1) + { + --m_nMul; + Util::SetMessage(std::to_string(m_nMul).c_str()); + Util::SetMessage(std::format("Speed: {}", m_nMul).c_str()); + } + } + } + + m_pPed->SetHeading(gTotalMouse.x); + Command(m_nPed, 0.0, 0.0, 20.0, 90.0, 180, gTotalMouse.y, 0.0, 2); + m_pPed->SetPosn(pos); + plugin::Call<0x4045B0>(&pos); // CIPLStore::AddIplsNeededAtPosn(CVector) +} + +void FreecamMgr::Disable() +{ + Command(0, false); + patch::Set(BY_GAME(0xBA6769, 0x86963A, NULL), m_bHudState); // hud + patch::Set(BY_GAME(0xBA676C, 0xA10AB6, NULL), m_bRadarState); // radar + + Command(m_nPed); + m_pPed = nullptr; + + Command(); +} + +FreecamMgr::FreecamMgr() +{ + Events::processScriptsEvent += [this]() + { + if (m_bEnabled) + { + Process(); + } + }; +} +#endif \ No newline at end of file diff --git a/src/custom/freecam.h b/src/custom/freecam.h new file mode 100644 index 0000000..63813dd --- /dev/null +++ b/src/custom/freecam.h @@ -0,0 +1,34 @@ +#pragma once +#ifdef GTASA +#include "interface/icheat.hpp" + +/* + Freeroam Camera Mode for SA + Similar to how airbreaks work + But more flexible +*/ +class FreecamMgr : public ICheat +{ +private: + CPed* m_pPed; // pointer to the dummy ped + int m_nPed = -1; // handle to the dummy ped + bool m_bHudState; // backup of the prev game hud state + bool m_bRadarState; // backup of the prev game radar state + + friend ICheat; + FreecamMgr(); + FreecamMgr(const FreecamMgr&); + + // Process freecam mode each frame + void Process(); + +public: + int m_nMul = 1; // speed multiplier + float m_fFOV = 60.0f; // freecam field of view + + void Enable(); + void Disable(); +}; + +extern FreecamMgr& Freecam; +#endif \ No newline at end of file diff --git a/src/custom/neon.cpp b/src/custom/neon.cpp index 6846d8e..61132a2 100644 --- a/src/custom/neon.cpp +++ b/src/custom/neon.cpp @@ -3,6 +3,8 @@ #ifdef GTASA #include "neon.h" +NeonMgr& Neon = *NeonMgr::Get(); + // Neon sprite const unsigned char neon_mask[1689] = { @@ -180,64 +182,56 @@ static RwTexture* LoadTextureFromMemory(char* data, unsigned int size) return RwTextureCreate(raster); } -void Neon::Init() +NeonMgr::NeonMgr() { - static bool init; - if (init) + Events::vehicleRenderEvent += [this](CVehicle* pVeh) { - return; - } - - Events::processScriptsEvent += [] - { - if (!m_pNeonTexture) + if (m_bEnabled) { - m_pNeonTexture = LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask)); - } - }; - - Events::vehicleRenderEvent += [](CVehicle* pVeh) - { - NeonData* data = &m_VehNeon.Get(pVeh); - if (data->m_bNeonInstalled && !pVeh->IsUpsideDown()) - { - CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin; - CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); - CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->m_fVal, 0.0f)) - center; - CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->m_fVal, 0.0f, 0.0f)) - center; - CShadows::StoreShadowToBeRendered(5, m_pNeonTexture, ¢er, up.x, up.y, right.x, right.y, 180, data->m_Color.r, - data->m_Color.g, data->m_Color.b, 2.0f, false, 1.0f, 0, true); - - if (data->m_bPulsing) + NeonData* data = &m_VehNeon.Get(pVeh); + if (data->m_bNeonInstalled && !pVeh->IsUpsideDown()) { - size_t delta = CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds; - - if (data->m_fVal < 0.0f) + if (!m_pNeonTexture) { - data->m_bIncrement = true; + m_pNeonTexture = LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask)); } - if (data->m_fVal > 0.3f) - { - data->m_bIncrement = false; - } + CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin; + CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f)); + CVector up = pVeh->TransformFromObjectSpace(CVector(0.0f, -Pos.y - data->m_fVal, 0.0f)) - center; + CVector right = pVeh->TransformFromObjectSpace(CVector(Pos.x + data->m_fVal, 0.0f, 0.0f)) - center; + CShadows::StoreShadowToBeRendered(5, m_pNeonTexture, ¢er, up.x, up.y, right.x, right.y, 180, data->m_Color.r, + data->m_Color.g, data->m_Color.b, 2.0f, false, 1.0f, 0, true); - if (data->m_bIncrement) + if (data->m_bPulsing) { - data->m_fVal += 0.0003f * delta; - } - else - { - data->m_fVal -= 0.0003f * delta; + size_t delta = CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds; + + if (data->m_fVal < 0.0f) + { + data->m_bIncrement = true; + } + + if (data->m_fVal > 0.3f) + { + data->m_bIncrement = false; + } + + if (data->m_bIncrement) + { + data->m_fVal += 0.0003f * delta; + } + else + { + data->m_fVal -= 0.0003f * delta; + } } } } }; - - init = true; } -void Neon::Shutdown() +NeonMgr::~NeonMgr() { if (m_pNeonTexture) { @@ -246,22 +240,22 @@ void Neon::Shutdown() } } -bool Neon::IsInstalled(CVehicle* pVeh) +bool NeonMgr::IsInstalled(CVehicle* pVeh) { return m_VehNeon.Get(pVeh).m_bNeonInstalled; } -bool Neon::IsPulsingEnabled(CVehicle* pVeh) +bool NeonMgr::IsPulsingEnabled(CVehicle* pVeh) { return m_VehNeon.Get(pVeh).m_bPulsing; } -void Neon::SetPulsing(CVehicle* pVeh, bool state) +void NeonMgr::SetPulsing(CVehicle* pVeh, bool state) { m_VehNeon.Get(pVeh).m_bPulsing = state; } -void Neon::Install(CVehicle* pVeh, int r, int g, int b) +void NeonMgr::Install(CVehicle* pVeh, int r, int g, int b) { CRGBA& color = m_VehNeon.Get(pVeh).m_Color; @@ -273,7 +267,7 @@ void Neon::Install(CVehicle* pVeh, int r, int g, int b) m_VehNeon.Get(pVeh).m_bNeonInstalled = true; } -void Neon::Remove(CVehicle* pVeh) +void NeonMgr::Remove(CVehicle* pVeh) { m_VehNeon.Get(pVeh).m_bNeonInstalled = false; } diff --git a/src/custom/neon.h b/src/custom/neon.h index 4543aac..870b28a 100644 --- a/src/custom/neon.h +++ b/src/custom/neon.h @@ -1,7 +1,7 @@ #pragma once #ifdef GTASA #include - +#include "interface/icheat.hpp" /* Vehicle Neon implementation class for GTA: San Andreas Handles neon colors and neon color changing @@ -9,7 +9,7 @@ TODO: Implement for VC & 3 too (maybe) Dunno how it'd work with the d3d8to9 wrapper */ -class Neon +class NeonMgr : public ICheat { private: class NeonData @@ -29,32 +29,31 @@ private: } }; - static inline RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture - static inline VehicleExtendedData m_VehNeon; + RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture + VehicleExtendedData m_VehNeon; + + friend ICheat; + NeonMgr(); + NeonMgr(NeonMgr&); + ~NeonMgr(); public: - Neon() = delete; - Neon(Neon&) = delete; - - // Injects necessary hooks into the game - static void Init(); // Installs neons with color - static void Install(CVehicle* veh, int r, int g, int b); + void Install(CVehicle* veh, int r, int g, int b); // Is neon installer for particular vehicle - static bool IsInstalled(CVehicle* veh); + bool IsInstalled(CVehicle* veh); // Is neon pulsing enabled for vehicle - static bool IsPulsingEnabled(CVehicle* veh); + bool IsPulsingEnabled(CVehicle* veh); // Set neon pulsing state - static void SetPulsing(CVehicle* veh, bool state); - - // Removes the neon game hooks - static void Shutdown(); + void SetPulsing(CVehicle* veh, bool state); // Removes neon from vehicle - static void Remove(CVehicle* veh); + void Remove(CVehicle* veh); }; + +extern NeonMgr& Neon; #endif \ No newline at end of file diff --git a/src/custom/randomcheats.cpp b/src/custom/randomcheats.cpp new file mode 100644 index 0000000..bd7d9c5 --- /dev/null +++ b/src/custom/randomcheats.cpp @@ -0,0 +1,80 @@ +#include "pch.h" +#include "randomcheats.h" + +#ifdef GTASA +RandomCheatsMgr& RandomCheats = *RandomCheatsMgr::Get(); + +void RandomCheatsMgr::Process() +{ + uint timer = CTimer::m_snTimeInMilliseconds; + static uint m_nTimer = 0; + + 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) + Call<0x69F0B0>((char*)m_EnabledCheats[i][0].c_str(), 2000, 0, false); // CMessages::AddMessage + m_nTimer = timer; + } + break; + } + } + } + + if (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 RandomCheatsMgr::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"; + } + } +} + +RandomCheatsMgr::RandomCheatsMgr() +{ + // Generate enabled cheats vector + for (auto [k, v] : m_pData.Items()) + { + std::string key { k.str() }; + m_EnabledCheats[std::stoi(key)][0] = v.value_or("Unknown"); + m_EnabledCheats[std::stoi(key)][1] = "true"; + } + + Events::drawingEvent += [this]() + { + if (m_bEnabled) + { + Process(); + } + }; +} +#endif \ No newline at end of file diff --git a/src/custom/randomcheats.h b/src/custom/randomcheats.h new file mode 100644 index 0000000..bf48012 --- /dev/null +++ b/src/custom/randomcheats.h @@ -0,0 +1,32 @@ +#pragma once +#ifdef GTASA +#include "interface/icheat.hpp" +#include "pch.h" + +/* + RandomCheats for SA + Activates/Disactivates cheats randomly +*/ +class RandomCheatsMgr : public ICheat +{ +private: + std::string m_EnabledCheats[92][2]; + DataStore m_pData {"cheats"}; + + friend ICheat; + RandomCheatsMgr(); + RandomCheatsMgr(const RandomCheatsMgr&); + + // Process the RandomCheat each frame & draw progress bar + void Process(); + +public: + bool m_bProgressBar = true; + int m_nInterval = 10; // interval between cheat activation/deactivation + + // Draws a list of cheats for ui + void DrawList(); +}; + +extern RandomCheatsMgr& RandomCheats; +#endif \ No newline at end of file diff --git a/src/interface/icheat.hpp b/src/interface/icheat.hpp new file mode 100644 index 0000000..240f57c --- /dev/null +++ b/src/interface/icheat.hpp @@ -0,0 +1,59 @@ +#pragma once + +template +class ICheat +{ +protected: + bool m_bEnabled = false; + +public: + + // Deactivates the cheat + virtual void Disable() + { + m_bEnabled = false; + } + + // Activates the cheat + virtual void Enable() + { + m_bEnabled = true; + } + + static T *Get() + { + static T _instance; + return &_instance; + } + + // Returns the current stae of the cheat + virtual const bool GetState() final + { + return m_bEnabled; + } + + // Sets the cheat state + virtual void SetState(const bool state) final + { + if (m_bEnabled != state) + { + Toggle(); + } + } + + // Toggles the cheat & returns it's toggled state + virtual bool Toggle() final + { + m_bEnabled = !m_bEnabled; + if (m_bEnabled) + { + Enable(); + } + else + { + Disable(); + } + + return m_bEnabled; + } +}; \ No newline at end of file diff --git a/src/pages/game.cpp b/src/pages/game.cpp index debefc5..eb205bd 100644 --- a/src/pages/game.cpp +++ b/src/pages/game.cpp @@ -5,7 +5,8 @@ #include "utils/util.h" #ifdef GTASA -#include +#include "custom/freecam.h" +#include "custom/randomcheats.h" #include #include #include @@ -13,275 +14,6 @@ #ifdef GTASA static bool bSaveGameFlag = false; -void Freecam::Process() -{ - static CVector m_fTotalMouse; - - 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(); - 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; - Util::SetMessage(TEXT("Game.PlayerTeleported")); - } - - if (KeyPressed(VK_MENU) && m_nMul > 1) - { - speed /= 2; - } - - if (KeyPressed(VK_SHIFT)) - { - speed *= 2; - } - - if (freeCamForward.PressedRealtime() || freeCamBackward.PressedRealtime()) - { - if (freeCamBackward.PressedRealtime()) - { - speed *= -1; - } - - float angle; - Command(m_nPed, &angle); - - if (KeyPressed(VK_CONTROL)) - { - pos.z += speed * sin(90.0f / 3 * 3.14159f / 180.0f); - } - else - { - pos.x += speed * cos(angle * 3.14159f / 180.0f); - pos.y += speed * sin(angle * 3.14159f / 180.0f); - - if (!KeyPressed(VK_SPACE)) - { - pos.z += speed * 2 * sin(m_fTotalMouse.y / 3 * 3.14159f / 180.0f); - } - } - } - - if (freeCamLeft.PressedRealtime() || freeCamRight.PressedRealtime()) - { - if (freeCamLeft.PressedRealtime()) - { - 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 (KeyPressed(VK_CONTROL)) - { - if (m_fFOV > 10.0f) - { - m_fFOV -= 2.0f * speed; - } - - TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); - Command(true); - } - else - { - if (m_nMul < 10) - { - ++m_nMul; - Util::SetMessage(std::format("Speed: {}", m_nMul).c_str()); - } - } - } - - if (CPad::NewMouseControllerState.wheelDown) - { - if (KeyPressed(VK_CONTROL)) - { - if (m_fFOV < 115.0f) - { - m_fFOV += 2.0f * speed; - } - - TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 250, true); - Command(true); - } - else - { - if (m_nMul > 1) - { - --m_nMul; - Util::SetMessage(std::to_string(m_nMul).c_str()); - Util::SetMessage(std::format("Speed: {}", m_nMul).c_str()); - } - } - } - - 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 - - Command(m_nPed); - m_pPed = nullptr; - - // restore lock camera zoom here - if (Game::m_bLockCameraZoom) - { - TheCamera.LerpFOV(TheCamera.FindCamFOV(), Game::m_nCameraZoom, 250, true); - } - else - { - Command(false); - } - Command(); -} - -void RandomCheats::Process() -{ - 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; - } - - if (m_bEnabled) - { - 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() @@ -319,8 +51,6 @@ void Game::Init() bSaveGameFlag = false; } }; - - Events::drawingEvent.Add(RandomCheats::DrawBar); #endif Events::processScriptsEvent += [] @@ -388,24 +118,20 @@ void Game::Init() } } - RandomCheats::Process(); - if (freeCam.Pressed()) { - if (Freecam::m_bEnabled) + if (Freecam.Toggle()) { - Freecam::m_bEnabled = false; - Freecam::Clear(); + // restore lock camera zoom here + if (Game::m_bLockCameraZoom) + { + TheCamera.LerpFOV(TheCamera.FindCamFOV(), Game::m_nCameraZoom, 250, true); + } + else + { + Command(false); + } } - else - { - Freecam::m_bEnabled = true; - } - } - - if (Freecam::m_bEnabled) - { - Freecam::Process(); } #endif @@ -657,7 +383,7 @@ void Game::ShowPage() if (ImGui::CollapsingHeader(TEXT("Game.CameraZoom"))) { ImGui::Spacing(); - if (Freecam::m_bEnabled) + if (Freecam.GetState()) { ImGui::TextWrapped(TEXT("Game.CameraZoomLockFreecam")); } @@ -872,20 +598,29 @@ void Game::ShowPage() if (ImGui::BeginTabItem(TEXT("Game.Freecam"))) { ImGui::Spacing(); - if (Widget::Checkbox(TEXT("Game.Enable"), &Freecam::m_bEnabled)) + bool state = Freecam.GetState(); + if (Widget::Checkbox(TEXT("Game.Enable"), &state)) { - if (!Freecam::m_bEnabled) + if (Freecam.Toggle()) { - Freecam::Clear(); + // restore lock camera zoom here + if (Game::m_bLockCameraZoom) + { + TheCamera.LerpFOV(TheCamera.FindCamFOV(), Game::m_nCameraZoom, 250, true); + } + else + { + Command(false); + } } } ImGui::Spacing(); - if (ImGui::SliderFloat(TEXT("Game.FieldOfView"), &Freecam::m_fFOV, 5.0f, 120.0f) && Freecam::m_bEnabled) + if (ImGui::SliderFloat(TEXT("Game.FieldOfView"), &Freecam.m_fFOV, 5.0f, 120.0f) && Freecam.GetState()) { - TheCamera.LerpFOV(TheCamera.FindCamFOV(), Freecam::m_fFOV, 250, true); + TheCamera.LerpFOV(TheCamera.FindCamFOV(), Freecam.m_fFOV, 250, true); } - ImGui::SliderInt(TEXT("Game.MovementSpeed"), &Freecam::m_nMul, 1, 10); + ImGui::SliderInt(TEXT("Game.MovementSpeed"), &Freecam.m_nMul, 1, 10); ImGui::Dummy(ImVec2(0.0f, 20.0f)); ImGui::BeginChild("Conrtls"); @@ -1054,15 +789,20 @@ void Game::ShowPage() { ImGui::Spacing(); ImGui::Columns(2, NULL, false); - ImGui::Checkbox(TEXT("Game.Enable"), &RandomCheats::m_bEnabled); + + bool state = RandomCheats.GetState(); + if (ImGui::Checkbox(TEXT("Game.Enable"), &state)) + { + RandomCheats.Toggle(); + } ImGui::NextColumn(); - ImGui::Checkbox(TEXT("Game.ProgressBar"), &RandomCheats::m_bProgressBar); + ImGui::Checkbox(TEXT("Game.ProgressBar"), &RandomCheats.m_bProgressBar); ImGui::Columns(1); ImGui::Spacing(); ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2); - ImGui::SliderInt(TEXT("Game.ActivateTimer"), &RandomCheats::m_nInterval, 5, 60); + ImGui::SliderInt(TEXT("Game.ActivateTimer"), &RandomCheats.m_nInterval, 5, 60); Widget::Tooltip(TEXT("Game.ActivateTimerText")); ImGui::PopItemWidth(); @@ -1071,7 +811,7 @@ void Game::ShowPage() ImGui::Separator(); if (ImGui::BeginChild("Cheats list")) { - RandomCheats::DrawList(); + RandomCheats.DrawList(); ImGui::EndChild(); } ImGui::EndTabItem(); diff --git a/src/pages/game.h b/src/pages/game.h index 9b078ee..f15cc06 100644 --- a/src/pages/game.h +++ b/src/pages/game.h @@ -1,43 +1,6 @@ #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: diff --git a/src/pages/vehicle.cpp b/src/pages/vehicle.cpp index d357a49..5fc15f0 100644 --- a/src/pages/vehicle.cpp +++ b/src/pages/vehicle.cpp @@ -18,7 +18,6 @@ void Vehicle::Init() { #ifdef GTASA FileHandler::FetchHandlingID(m_VehicleIDE); - Neon::Init(); Paint::InjectHooks(); #endif @@ -144,7 +143,7 @@ void Vehicle::Init() int red, green, blue; Util::RainbowValues(red, green, blue, 0.25); - Neon::Install(pVeh, red, green, blue); + Neon.Install(pVeh, red, green, blue); NeonData::m_nRainbowTimer = timer; } #endif @@ -173,9 +172,9 @@ void Vehicle::Init() chance = Random(1, 3); } - if (chance == 1 && !Neon::IsInstalled(veh) && veh->m_pDriver != pPlayer) + if (chance == 1 && !Neon.IsInstalled(veh) && veh->m_pDriver != pPlayer) { - Neon::Install(veh, Random(0, 255), Random(0, 255), Random(0, 255)); + Neon.Install(veh, Random(0, 255), Random(0, 255), Random(0, 255)); } } NeonData::m_bTrafficTimer = timer; @@ -1314,17 +1313,17 @@ void Vehicle::ShowPage() ImGui::Spacing(); if (ImGui::Button(TEXT("Vehicle.RemoveNeon"), ImVec2(Widget::CalcSize()))) { - Neon::Remove(veh); + Neon.Remove(veh); Util::SetMessage(TEXT("Vehicle.RemoveNeonMSG")); } ImGui::Spacing(); ImGui::Columns(2, NULL, false); - bool pulsing = Neon::IsPulsingEnabled(veh); + bool pulsing = Neon.IsPulsingEnabled(veh); if (Widget::Checkbox(TEXT("Vehicle.PulsingNeon"), &pulsing)) { - Neon::SetPulsing(veh, pulsing); + Neon.SetPulsing(veh, pulsing); } Widget::Checkbox(TEXT("Vehicle.RainbowNeon"), &NeonData::m_bRainbowEffect, TEXT("Vehicle.RainbowNeonMSG")); @@ -1340,7 +1339,7 @@ void Vehicle::ShowPage() int g = static_cast(NeonData::m_fColorPicker[1] * 255); int b = static_cast(NeonData::m_fColorPicker[2] * 255); - Neon::Install(veh, r, g, b); + Neon.Install(veh, r, g, b); } @@ -1364,7 +1363,7 @@ void Vehicle::ShowPage() int g = static_cast(color[1] * 255); int b = static_cast(color[2] * 255); - Neon::Install(veh, r, g, b); + Neon.Install(veh, r, g, b); } if ((color_id + 1) % btnsInRow != 0) diff --git a/src/utils/log.cpp b/src/utils/log.cpp index e1fb343..c59dc34 100644 --- a/src/utils/log.cpp +++ b/src/utils/log.cpp @@ -1,6 +1,5 @@ #include "log.h" #include "pch.h" -#include void Log::AppendLogLevel(std::string& text) noexcept { diff --git a/tools/premake5.lua b/tools/premake5.lua index 7e1724d..5db8d93 100644 --- a/tools/premake5.lua +++ b/tools/premake5.lua @@ -63,8 +63,6 @@ function createProject(projectID) pchheader "pch.h" pchsource "../src/pch.cpp" - filter "files:..src/utils/**.cpp" - flags {"NoPCH"} filter "configurations:Debug" symbols "On"