Refactor code, radarBlips fla compatible, new credits ui

This commit is contained in:
Grinch_ 2022-01-23 18:30:28 +06:00
parent 5eb7bc0f41
commit ba389f1ab7
7 changed files with 116 additions and 86 deletions

View File

@ -11,7 +11,6 @@
static bool bSaveGameFlag = false; static bool bSaveGameFlag = false;
// Thanks to aap
void Game::RealTimeClock() void Game::RealTimeClock()
{ {
time_t tmp = time(nullptr); time_t tmp = time(nullptr);
@ -22,9 +21,9 @@ void Game::RealTimeClock()
if (now->tm_yday != lastday) if (now->tm_yday != lastday)
{ {
CStats::SetStatValue(0x86, CStats::GetStatValue(0x86) + 1.0f); CStats::SetStatValue(0x86, CStats::GetStatValue(0x86) + 1.0f);
lastday = now->tm_yday;
} }
lastday = now->tm_yday;
CClock::ms_nGameClockMonth = now->tm_mon + 1; CClock::ms_nGameClockMonth = now->tm_mon + 1;
CClock::ms_nGameClockDays = now->tm_mday; CClock::ms_nGameClockDays = now->tm_mday;
CClock::CurrentDay = now->tm_wday + 1; CClock::CurrentDay = now->tm_wday + 1;

View File

@ -606,10 +606,37 @@ void Menu::ShowPage()
ImGui::Dummy(ImVec2(0, 10)); ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("If you find bugs or have suggestions, let me know on discord."); ImGui::TextWrapped("If you find bugs or have suggestions, let me know on discord.");
ImGui::Dummy(ImVec2(0, 10)); ImGui::Dummy(ImVec2(0, 10));
ImGui::TextWrapped("Thanks to Junior-Djjr");
ImGui::Dummy(ImVec2(0, 30));
Ui::CenterdText("Copyright Grinch_ 2019-2022. All rights reserved"); Ui::CenterdText("Copyright Grinch_ 2019-2022. All rights reserved");
ImGui::Dummy(ImVec2(0, 30));
static ImGuiTableFlags flags = ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY;
if (ImGui::BeginTable("Hall of Fame", 2, flags))
{
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, 100);
ImGui::TableSetupColumn("Credits");
ImGui::TableHeadersRow();
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Codenulls");
ImGui::TableNextColumn();
ImGui::Text("III & VC animation code");
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("DKPac22");
ImGui::TableNextColumn();
ImGui::Text("Vehicle texturing code");
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Junior-Djjr");
ImGui::TableNextColumn();
ImGui::Text("Code & suggestions");
ImGui::EndTable();
}
ImGui::EndChild(); ImGui::EndChild();
} }

View File

@ -12,6 +12,7 @@ void Teleport::FetchRadarSpriteData()
{ {
uint cur_timer = CTimer::m_snTimeInMilliseconds; uint cur_timer = CTimer::m_snTimeInMilliseconds;
static uint timer = cur_timer; static uint timer = cur_timer;
static int maxSprites = *(uint*)0x5D5870;
// Update the radar list each 5 seconds // Update the radar list each 5 seconds
if (cur_timer - timer < 5000) if (cur_timer - timer < 5000)
@ -20,9 +21,7 @@ void Teleport::FetchRadarSpriteData()
} }
m_tpData.m_pJson->m_Data.erase("Radar"); m_tpData.m_pJson->m_Data.erase("Radar");
for (int i = 0; i != maxSprites; ++i)
// 175 is the max number of sprites, FLA can increase this limit, might need to update this
for (int i = 0; i != 175; ++i)
{ {
CVector pos = CRadar::ms_RadarTrace[i].m_vPosition; CVector pos = CRadar::ms_RadarTrace[i].m_vPosition;
uchar sprite = CRadar::ms_RadarTrace[i].m_nBlipSprite; uchar sprite = CRadar::ms_RadarTrace[i].m_nBlipSprite;

View File

@ -2,6 +2,63 @@
#include "util.h" #include "util.h"
#include "psapi.h" #include "psapi.h"
bool Util::IsInVehicle(CPed *pPed)
{
if (!pPed)
{
return false;
}
return BY_GAME(pPed->m_nPedFlags.bInVehicle, pPed->m_bInVehicle, pPed->m_bInVehicle);
}
void Util::FixVehicle(CVehicle *pVeh)
{
#ifdef GTASA
pVeh->Fix();
#else
switch (pVeh->m_nVehicleClass)
{
case VEHICLE_AUTOMOBILE:
{
reinterpret_cast<CAutomobile*>(pVeh)->Fix();
break;
}
#ifdef GTAVC
case VEHICLE_BIKE:
{
reinterpret_cast<CBike *>(pVeh)->Fix();
break;
}
#endif
}
#endif
pVeh->m_fHealth = 1000.0f;
}
void Util::FlipVehicle(CVehicle *pVeh)
{
#ifdef GTASA
int hveh = CPools::GetVehicleRef(pVeh);
float roll;
Command<Commands::GET_CAR_ROLL>(hveh, &roll);
roll += 180;
Command<Commands::SET_CAR_ROLL>(hveh, roll);
Command<Commands::SET_CAR_ROLL>(hveh, roll); // z rot fix
#elif GTAVC
float x,y,z;
pVeh->m_placement.GetOrientation(x, y, z);
y += 135.0f;
pVeh->m_placement.SetOrientation(x, y, z);
#else
float x,y,z;
pVeh->GetOrientation(x, y, z);
y += 135.0f;
pVeh->SetOrientation(x, y, z);
#endif
}
void Util::SetCarForwardSpeed(CVehicle *pVeh, float speed) void Util::SetCarForwardSpeed(CVehicle *pVeh, float speed)
{ {
#ifdef GTA3 #ifdef GTA3
@ -58,18 +115,18 @@ std::string Util::GetLocationName(CVector* pos)
} }
#ifdef GTASA #ifdef GTASA
void Util::ClearCharTasksVehCheck(CPed* ped) void Util::ClearCharTasksVehCheck(CPed* pPed)
{ {
uint hped = CPools::GetPedRef(ped); uint hped = CPools::GetPedRef(pPed);
uint hveh = NULL; uint hveh = NULL;
bool veh_engine = true; bool veh_engine = true;
float speed; float speed;
if (ped->m_nPedFlags.bInVehicle) if (IsInVehicle(pPed))
{ {
hveh = CPools::GetVehicleRef(ped->m_pVehicle); hveh = CPools::GetVehicleRef(pPed->m_pVehicle);
veh_engine = ped->m_pVehicle->m_nVehicleFlags.bEngineOn; veh_engine = pPed->m_pVehicle->m_nVehicleFlags.bEngineOn;
speed = ped->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f; speed = pPed->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f;
} }
Command<Commands::CLEAR_CHAR_TASKS_IMMEDIATELY>(hped); Command<Commands::CLEAR_CHAR_TASKS_IMMEDIATELY>(hped);
@ -77,7 +134,7 @@ void Util::ClearCharTasksVehCheck(CPed* ped)
if (hveh) if (hveh)
{ {
Command<Commands::TASK_WARP_CHAR_INTO_CAR_AS_DRIVER>(hped, hveh); Command<Commands::TASK_WARP_CHAR_INTO_CAR_AS_DRIVER>(hped, hveh);
ped->m_pVehicle->m_nVehicleFlags.bEngineOn = veh_engine; pPed->m_pVehicle->m_nVehicleFlags.bEngineOn = veh_engine;
Command<Commands::SET_CAR_FORWARD_SPEED>(hveh, speed); Command<Commands::SET_CAR_FORWARD_SPEED>(hveh, speed);
} }
} }

View File

@ -2,6 +2,11 @@
#include "tchar.h" #include "tchar.h"
#include "pdh.h" #include "pdh.h"
/*
* Contains utility functions
* for all 3 games
*/
class Util class Util
{ {
private: private:
@ -16,16 +21,20 @@ public:
Util(Util&) = delete; Util(Util&) = delete;
#ifdef GTASA #ifdef GTASA
static void ClearCharTasksVehCheck(CPed* ped);
static int GetLargestGangInZone(); static int GetLargestGangInZone();
static void ClearCharTasksVehCheck(CPed* ped);
static bool IsOnMission();
#endif #endif
static void SetCarForwardSpeed(CVehicle *pVeh, float speed);
static void FlipVehicle(CVehicle *pVeh);
static void FixVehicle(CVehicle *pVeh);
static CPed* GetClosestPed(); static CPed* GetClosestPed();
static CVehicle* GetClosestVehicle(); static CVehicle* GetClosestVehicle();
static void GetCPUUsageInit(); static void GetCPUUsageInit();
static double GetCurrentCPUUsage(); static double GetCurrentCPUUsage();
static std::string GetLocationName(CVector* pos); static std::string GetLocationName(CVector* pos);
static bool IsOnCutscene(); static bool IsOnCutscene();
static bool IsOnMission(); static bool IsInVehicle(CPed *pPed = FindPlayerPed());
static void RainbowValues(int& r, int& g, int& b, float speed); static void RainbowValues(int& r, int& g, int& b, float speed);
static void SetCarForwardSpeed(CVehicle *pVeh, float speed);
}; };

View File

@ -12,63 +12,6 @@
#include "paint.h" #include "paint.h"
#endif #endif
void Vehicle::FixVehicle(CVehicle *pVeh)
{
#ifdef GTASA
pVeh->Fix();
#else
switch (pVeh->m_nVehicleClass)
{
case VEHICLE_AUTOMOBILE:
{
reinterpret_cast<CAutomobile *>(pVeh)->Fix();
break;
}
#ifdef GTAVC
case VEHICLE_BIKE:
{
reinterpret_cast<CBike *>(pVeh)->Fix();
break;
}
#endif
}
#endif
pVeh->m_fHealth = 1000.0f;
}
void FlipVehicle()
{
CPlayerPed* pPlayer = FindPlayerPed();
#ifdef GTASA
if (pPlayer->m_nPedFlags.bInVehicle)
{
int hveh = CPools::GetVehicleRef(pPlayer->m_pVehicle);
float roll;
Command<Commands::GET_CAR_ROLL>(hveh, &roll);
roll += 180;
Command<Commands::SET_CAR_ROLL>(hveh, roll);
Command<Commands::SET_CAR_ROLL>(hveh, roll); // z rot fix
}
#elif GTAVC
if (pPlayer->m_bInVehicle)
{
float x,y,z;
pPlayer->m_pVehicle->m_placement.GetOrientation(x, y, z);
y += 135.0f;
pPlayer->m_pVehicle->m_placement.SetOrientation(x, y, z);
}
#else
if (pPlayer->m_bInVehicle)
{
float x,y,z;
pPlayer->m_pVehicle->GetOrientation(x, y, z);
y += 135.0f;
pPlayer->m_pVehicle->SetOrientation(x, y, z);
}
#endif
}
Vehicle::Vehicle() Vehicle::Vehicle()
{ {
#ifdef GTASA #ifdef GTASA
@ -85,18 +28,18 @@ Vehicle::Vehicle()
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle());
if (pPlayer && pVeh) if (pPlayer && Util::IsInVehicle())
{ {
int hveh = CPools::GetVehicleRef(pVeh); int hveh = CPools::GetVehicleRef(pVeh);
if (flipVeh.Pressed()) if (flipVeh.Pressed())
{ {
FlipVehicle(); Util::FlipVehicle(pVeh);
} }
if (fixVeh.Pressed()) if (fixVeh.Pressed())
{ {
FixVehicle(pVeh); Util::FixVehicle(pVeh);
SetHelpMessage("Vehicle fixed", false, false, false); SetHelpMessage("Vehicle fixed", false, false, false);
} }
@ -575,19 +518,16 @@ void Vehicle::ShowPage()
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(3)))) if (ImGui::Button("Fix vehicle", ImVec2(Ui::GetSize(3))) && Util::IsInVehicle())
{ {
if (pPlayer && pVeh) Util::FixVehicle(pVeh);
{
FixVehicle(pVeh);
}
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Flip vehicle", ImVec2(Ui::GetSize(3)))) if (ImGui::Button("Flip vehicle", ImVec2(Ui::GetSize(3))) && Util::IsInVehicle())
{ {
FlipVehicle(); Util::FlipVehicle(pVeh);
} }
ImGui::Spacing(); ImGui::Spacing();

View File

@ -82,12 +82,11 @@ private:
#endif #endif
private: private:
static void FixVehicle(CVehicle *pVeh);
#ifdef GTASA #ifdef GTASA
static void AddComponent(const std::string& component, bool display_message = true); static void AddComponent(const std::string& component, bool display_message = true);
static void RemoveComponent(const std::string& component, bool display_message = true); static void RemoveComponent(const std::string& component, bool display_message = true);
static int GetRandomTrainIdForModel(int model); static int GetRandomTrainIdForModel(int model);
static void GenerateHandlingDataFile(int phandling);
#endif #endif
public: public: