Refactor freecam, neon & randomcheats

This commit is contained in:
Grinch_ 2022-08-08 07:16:35 +06:00
parent 6e9c3c43cb
commit fe67e21eeb
13 changed files with 499 additions and 412 deletions

View File

@ -359,7 +359,6 @@ LungCapacity = "Lung capacity"
MaxAppeal = "Max sex appeal" MaxAppeal = "Max sex appeal"
MaxArmour = "Max armour" MaxArmour = "Max armour"
MaxHealth = "Max health" MaxHealth = "Max health"
MeeleProof = "Meele proof"
MegaJump = "Mega jump" MegaJump = "Mega jump"
MegaPunch = "Mega punch" MegaPunch = "Mega punch"
Money = "Money" Money = "Money"

191
src/custom/freecam.cpp Normal file
View File

@ -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<Commands::SET_EVERYONE_IGNORE_PLAYER>(0, true);
// set hud & radar states
m_bHudState = patch::Get<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL)); // hud
m_bRadarState = patch::Get<BYTE>(BY_GAME(0xBA676C, 0xA10AB6, NULL)); // radar
patch::Set<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL), 0); // disable hud
patch::Set<BYTE>(0xBA676C, 2); // disable radar
// create our dummy character
CVector pos = player->GetPosition();
Command<Commands::CREATE_RANDOM_CHAR>(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<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(m_nPed, true);
Command<Commands::SET_LOAD_COLLISION_FOR_CHAR_FLAG>(m_nPed, false);
Command<Commands::SET_CHAR_COLLISION>(m_nPed, false);
// set camera fov
TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 1000, true);
Command<Commands::CAMERA_PERSIST_FOV>(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<Commands::SET_CHAR_COORDINATES>(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<Commands::GET_CHAR_HEADING>(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<Commands::GET_CHAR_HEADING>(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<Commands::CAMERA_PERSIST_FOV>(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<Commands::CAMERA_PERSIST_FOV>(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<Commands::ATTACH_CAMERA_TO_CHAR>(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<Commands::SET_EVERYONE_IGNORE_PLAYER>(0, false);
patch::Set<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL), m_bHudState); // hud
patch::Set<BYTE>(BY_GAME(0xBA676C, 0xA10AB6, NULL), m_bRadarState); // radar
Command<Commands::DELETE_CHAR>(m_nPed);
m_pPed = nullptr;
Command<Commands::RESTORE_CAMERA_JUMPCUT>();
}
FreecamMgr::FreecamMgr()
{
Events::processScriptsEvent += [this]()
{
if (m_bEnabled)
{
Process();
}
};
}
#endif

34
src/custom/freecam.h Normal file
View File

@ -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<FreecamMgr>
{
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

View File

@ -3,6 +3,8 @@
#ifdef GTASA #ifdef GTASA
#include "neon.h" #include "neon.h"
NeonMgr& Neon = *NeonMgr::Get();
// Neon sprite // Neon sprite
const unsigned char neon_mask[1689] = const unsigned char neon_mask[1689] =
{ {
@ -180,64 +182,56 @@ static RwTexture* LoadTextureFromMemory(char* data, unsigned int size)
return RwTextureCreate(raster); return RwTextureCreate(raster);
} }
void Neon::Init() NeonMgr::NeonMgr()
{ {
static bool init; Events::vehicleRenderEvent += [this](CVehicle* pVeh)
if (init)
{ {
return; if (m_bEnabled)
}
Events::processScriptsEvent += []
{
if (!m_pNeonTexture)
{ {
m_pNeonTexture = LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask)); NeonData* data = &m_VehNeon.Get(pVeh);
} if (data->m_bNeonInstalled && !pVeh->IsUpsideDown())
};
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, &center, 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)
{ {
size_t delta = CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds; if (!m_pNeonTexture)
if (data->m_fVal < 0.0f)
{ {
data->m_bIncrement = true; m_pNeonTexture = LoadTextureFromMemory((char*)neon_mask, sizeof(neon_mask));
} }
if (data->m_fVal > 0.3f) CVector Pos = CModelInfo::GetModelInfo(pVeh->m_nModelIndex)->m_pColModel->m_boundBox.m_vecMin;
{ CVector center = pVeh->TransformFromObjectSpace(CVector(0.0f, 0.0f, 0.0f));
data->m_bIncrement = false; 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, &center, 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; size_t delta = CTimer::m_snTimeInMilliseconds - CTimer::m_snPreviousTimeInMilliseconds;
}
else if (data->m_fVal < 0.0f)
{ {
data->m_fVal -= 0.0003f * delta; 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) 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; return m_VehNeon.Get(pVeh).m_bNeonInstalled;
} }
bool Neon::IsPulsingEnabled(CVehicle* pVeh) bool NeonMgr::IsPulsingEnabled(CVehicle* pVeh)
{ {
return m_VehNeon.Get(pVeh).m_bPulsing; 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; 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; 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; m_VehNeon.Get(pVeh).m_bNeonInstalled = true;
} }
void Neon::Remove(CVehicle* pVeh) void NeonMgr::Remove(CVehicle* pVeh)
{ {
m_VehNeon.Get(pVeh).m_bNeonInstalled = false; m_VehNeon.Get(pVeh).m_bNeonInstalled = false;
} }

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#ifdef GTASA #ifdef GTASA
#include <extender/VehicleExtender.h> #include <extender/VehicleExtender.h>
#include "interface/icheat.hpp"
/* /*
Vehicle Neon implementation class for GTA: San Andreas Vehicle Neon implementation class for GTA: San Andreas
Handles neon colors and neon color changing Handles neon colors and neon color changing
@ -9,7 +9,7 @@
TODO: Implement for VC & 3 too (maybe) TODO: Implement for VC & 3 too (maybe)
Dunno how it'd work with the d3d8to9 wrapper Dunno how it'd work with the d3d8to9 wrapper
*/ */
class Neon class NeonMgr : public ICheat<NeonMgr>
{ {
private: private:
class NeonData class NeonData
@ -29,32 +29,31 @@ private:
} }
}; };
static inline RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture RwTexture* m_pNeonTexture = nullptr; // pointer to the neon mask texture
static inline VehicleExtendedData<NeonData> m_VehNeon; VehicleExtendedData<NeonData> m_VehNeon;
friend ICheat;
NeonMgr();
NeonMgr(NeonMgr&);
~NeonMgr();
public: public:
Neon() = delete;
Neon(Neon&) = delete;
// Injects necessary hooks into the game
static void Init();
// Installs neons with color // 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 // Is neon installer for particular vehicle
static bool IsInstalled(CVehicle* veh); bool IsInstalled(CVehicle* veh);
// Is neon pulsing enabled for vehicle // Is neon pulsing enabled for vehicle
static bool IsPulsingEnabled(CVehicle* veh); bool IsPulsingEnabled(CVehicle* veh);
// Set neon pulsing state // Set neon pulsing state
static void SetPulsing(CVehicle* veh, bool state); void SetPulsing(CVehicle* veh, bool state);
// Removes the neon game hooks
static void Shutdown();
// Removes neon from vehicle // Removes neon from vehicle
static void Remove(CVehicle* veh); void Remove(CVehicle* veh);
}; };
extern NeonMgr& Neon;
#endif #endif

View File

@ -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<uint>(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<std::string>("Unknown");
m_EnabledCheats[std::stoi(key)][1] = "true";
}
Events::drawingEvent += [this]()
{
if (m_bEnabled)
{
Process();
}
};
}
#endif

32
src/custom/randomcheats.h Normal file
View File

@ -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<RandomCheatsMgr>
{
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

59
src/interface/icheat.hpp Normal file
View File

@ -0,0 +1,59 @@
#pragma once
template<typename T>
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;
}
};

View File

@ -5,7 +5,8 @@
#include "utils/util.h" #include "utils/util.h"
#ifdef GTASA #ifdef GTASA
#include <CIplStore.h> #include "custom/freecam.h"
#include "custom/randomcheats.h"
#include <CMessages.h> #include <CMessages.h>
#include <CSprite2d.h> #include <CSprite2d.h>
#include <CAERadioTrackManager.h> #include <CAERadioTrackManager.h>
@ -13,275 +14,6 @@
#ifdef GTASA #ifdef GTASA
static bool bSaveGameFlag = false; 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<Commands::SET_EVERYONE_IGNORE_PLAYER>(0, true);
m_bHudState = patch::Get<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL)); // hud
patch::Set<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL), 0); // hud
m_bRadarState = patch::Get<BYTE>(BY_GAME(0xBA676C, 0xA10AB6, NULL)); // radar
CVector playerPos = player->GetPosition();
Command<Commands::CREATE_RANDOM_CHAR>(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<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(m_nPed, true);
Command<Commands::SET_LOAD_COLLISION_FOR_CHAR_FLAG>(m_nPed, false);
m_pPed->m_bIsVisible = false;
Command<Commands::SET_CHAR_COLLISION>(m_nPed, false);
m_pPed->SetPosn(playerPos);
TheCamera.LerpFOV(TheCamera.FindCamFOV(), m_fFOV, 1000, true);
Command<Commands::CAMERA_PERSIST_FOV>(true);
patch::Set<BYTE>(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<Commands::SET_CHAR_COORDINATES>(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<Commands::GET_CHAR_HEADING>(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<Commands::GET_CHAR_HEADING>(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<Commands::CAMERA_PERSIST_FOV>(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<Commands::CAMERA_PERSIST_FOV>(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<Commands::ATTACH_CAMERA_TO_CHAR>(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<Commands::SET_EVERYONE_IGNORE_PLAYER>(0, false);
patch::Set<BYTE>(BY_GAME(0xBA6769, 0x86963A, NULL), m_bHudState); // hud
patch::Set<BYTE>(BY_GAME(0xBA676C, 0xA10AB6, NULL), m_bRadarState); // radar
Command<Commands::DELETE_CHAR>(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<Commands::CAMERA_PERSIST_FOV>(false);
}
Command<Commands::RESTORE_CAMERA_JUMPCUT>();
}
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<std::string>("Unknown");
m_EnabledCheats[std::stoi(key)][1] = "true";
}
genCheats = true;
}
if (m_bEnabled)
{
uint timer = CTimer::m_snTimeInMilliseconds;
if ((timer - m_nTimer) > (static_cast<uint>(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 #endif
static void RealTimeClock() static void RealTimeClock()
@ -319,8 +51,6 @@ void Game::Init()
bSaveGameFlag = false; bSaveGameFlag = false;
} }
}; };
Events::drawingEvent.Add(RandomCheats::DrawBar);
#endif #endif
Events::processScriptsEvent += [] Events::processScriptsEvent += []
@ -388,24 +118,20 @@ void Game::Init()
} }
} }
RandomCheats::Process();
if (freeCam.Pressed()) if (freeCam.Pressed())
{ {
if (Freecam::m_bEnabled) if (Freecam.Toggle())
{ {
Freecam::m_bEnabled = false; // restore lock camera zoom here
Freecam::Clear(); if (Game::m_bLockCameraZoom)
{
TheCamera.LerpFOV(TheCamera.FindCamFOV(), Game::m_nCameraZoom, 250, true);
}
else
{
Command<Commands::CAMERA_PERSIST_FOV>(false);
}
} }
else
{
Freecam::m_bEnabled = true;
}
}
if (Freecam::m_bEnabled)
{
Freecam::Process();
} }
#endif #endif
@ -657,7 +383,7 @@ void Game::ShowPage()
if (ImGui::CollapsingHeader(TEXT("Game.CameraZoom"))) if (ImGui::CollapsingHeader(TEXT("Game.CameraZoom")))
{ {
ImGui::Spacing(); ImGui::Spacing();
if (Freecam::m_bEnabled) if (Freecam.GetState())
{ {
ImGui::TextWrapped(TEXT("Game.CameraZoomLockFreecam")); ImGui::TextWrapped(TEXT("Game.CameraZoomLockFreecam"));
} }
@ -872,20 +598,29 @@ void Game::ShowPage()
if (ImGui::BeginTabItem(TEXT("Game.Freecam"))) if (ImGui::BeginTabItem(TEXT("Game.Freecam")))
{ {
ImGui::Spacing(); 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<Commands::CAMERA_PERSIST_FOV>(false);
}
} }
} }
ImGui::Spacing(); 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::Dummy(ImVec2(0.0f, 20.0f));
ImGui::BeginChild("Conrtls"); ImGui::BeginChild("Conrtls");
@ -1054,15 +789,20 @@ void Game::ShowPage()
{ {
ImGui::Spacing(); ImGui::Spacing();
ImGui::Columns(2, NULL, false); 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::NextColumn();
ImGui::Checkbox(TEXT("Game.ProgressBar"), &RandomCheats::m_bProgressBar); ImGui::Checkbox(TEXT("Game.ProgressBar"), &RandomCheats.m_bProgressBar);
ImGui::Columns(1); ImGui::Columns(1);
ImGui::Spacing(); ImGui::Spacing();
ImGui::PushItemWidth(ImGui::GetWindowContentRegionWidth() / 2); 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")); Widget::Tooltip(TEXT("Game.ActivateTimerText"));
ImGui::PopItemWidth(); ImGui::PopItemWidth();
@ -1071,7 +811,7 @@ void Game::ShowPage()
ImGui::Separator(); ImGui::Separator();
if (ImGui::BeginChild("Cheats list")) if (ImGui::BeginChild("Cheats list"))
{ {
RandomCheats::DrawList(); RandomCheats.DrawList();
ImGui::EndChild(); ImGui::EndChild();
} }
ImGui::EndTabItem(); ImGui::EndTabItem();

View File

@ -1,43 +1,6 @@
#pragma once #pragma once
#include "pch.h" #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 class Game
{ {
private: private:

View File

@ -18,7 +18,6 @@ void Vehicle::Init()
{ {
#ifdef GTASA #ifdef GTASA
FileHandler::FetchHandlingID(m_VehicleIDE); FileHandler::FetchHandlingID(m_VehicleIDE);
Neon::Init();
Paint::InjectHooks(); Paint::InjectHooks();
#endif #endif
@ -144,7 +143,7 @@ void Vehicle::Init()
int red, green, blue; int red, green, blue;
Util::RainbowValues(red, green, blue, 0.25); Util::RainbowValues(red, green, blue, 0.25);
Neon::Install(pVeh, red, green, blue); Neon.Install(pVeh, red, green, blue);
NeonData::m_nRainbowTimer = timer; NeonData::m_nRainbowTimer = timer;
} }
#endif #endif
@ -173,9 +172,9 @@ void Vehicle::Init()
chance = Random(1, 3); 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; NeonData::m_bTrafficTimer = timer;
@ -1314,17 +1313,17 @@ void Vehicle::ShowPage()
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::Button(TEXT("Vehicle.RemoveNeon"), ImVec2(Widget::CalcSize()))) if (ImGui::Button(TEXT("Vehicle.RemoveNeon"), ImVec2(Widget::CalcSize())))
{ {
Neon::Remove(veh); Neon.Remove(veh);
Util::SetMessage(TEXT("Vehicle.RemoveNeonMSG")); Util::SetMessage(TEXT("Vehicle.RemoveNeonMSG"));
} }
ImGui::Spacing(); ImGui::Spacing();
ImGui::Columns(2, NULL, false); ImGui::Columns(2, NULL, false);
bool pulsing = Neon::IsPulsingEnabled(veh); bool pulsing = Neon.IsPulsingEnabled(veh);
if (Widget::Checkbox(TEXT("Vehicle.PulsingNeon"), &pulsing)) 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")); Widget::Checkbox(TEXT("Vehicle.RainbowNeon"), &NeonData::m_bRainbowEffect, TEXT("Vehicle.RainbowNeonMSG"));
@ -1340,7 +1339,7 @@ void Vehicle::ShowPage()
int g = static_cast<int>(NeonData::m_fColorPicker[1] * 255); int g = static_cast<int>(NeonData::m_fColorPicker[1] * 255);
int b = static_cast<int>(NeonData::m_fColorPicker[2] * 255); int b = static_cast<int>(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<int>(color[1] * 255); int g = static_cast<int>(color[1] * 255);
int b = static_cast<int>(color[2] * 255); int b = static_cast<int>(color[2] * 255);
Neon::Install(veh, r, g, b); Neon.Install(veh, r, g, b);
} }
if ((color_id + 1) % btnsInRow != 0) if ((color_id + 1) % btnsInRow != 0)

View File

@ -1,6 +1,5 @@
#include "log.h" #include "log.h"
#include "pch.h" #include "pch.h"
#include <stdarg.h>
void Log::AppendLogLevel(std::string& text) noexcept void Log::AppendLogLevel(std::string& text) noexcept
{ {

View File

@ -63,8 +63,6 @@ function createProject(projectID)
pchheader "pch.h" pchheader "pch.h"
pchsource "../src/pch.cpp" pchsource "../src/pch.cpp"
filter "files:..src/utils/**.cpp"
flags {"NoPCH"}
filter "configurations:Debug" filter "configurations:Debug"
symbols "On" symbols "On"