From ba389f1ab7173de5ed3441bd9702a7ded86d6211 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 23 Jan 2022 18:30:28 +0600 Subject: [PATCH] Refactor code, radarBlips fla compatible, new credits ui --- src/game.cpp | 3 +- src/menu.cpp | 31 ++++++++++++++++++-- src/teleport.cpp | 5 ++-- src/util.cpp | 71 +++++++++++++++++++++++++++++++++++++++++----- src/util.h | 15 ++++++++-- src/vehicle.cpp | 74 +++++------------------------------------------- src/vehicle.h | 3 +- 7 files changed, 116 insertions(+), 86 deletions(-) diff --git a/src/game.cpp b/src/game.cpp index ddc9f13..2040851 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -11,7 +11,6 @@ static bool bSaveGameFlag = false; -// Thanks to aap void Game::RealTimeClock() { time_t tmp = time(nullptr); @@ -22,9 +21,9 @@ void Game::RealTimeClock() if (now->tm_yday != lastday) { 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_nGameClockDays = now->tm_mday; CClock::CurrentDay = now->tm_wday + 1; diff --git a/src/menu.cpp b/src/menu.cpp index 256923f..083c1ce 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -606,10 +606,37 @@ void Menu::ShowPage() ImGui::Dummy(ImVec2(0, 10)); ImGui::TextWrapped("If you find bugs or have suggestions, let me know on discord."); 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"); + 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(); } diff --git a/src/teleport.cpp b/src/teleport.cpp index dee69f6..76b5696 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -12,6 +12,7 @@ void Teleport::FetchRadarSpriteData() { uint cur_timer = CTimer::m_snTimeInMilliseconds; static uint timer = cur_timer; + static int maxSprites = *(uint*)0x5D5870; // Update the radar list each 5 seconds if (cur_timer - timer < 5000) @@ -20,9 +21,7 @@ void Teleport::FetchRadarSpriteData() } m_tpData.m_pJson->m_Data.erase("Radar"); - - // 175 is the max number of sprites, FLA can increase this limit, might need to update this - for (int i = 0; i != 175; ++i) + for (int i = 0; i != maxSprites; ++i) { CVector pos = CRadar::ms_RadarTrace[i].m_vPosition; uchar sprite = CRadar::ms_RadarTrace[i].m_nBlipSprite; diff --git a/src/util.cpp b/src/util.cpp index 3a6d69d..76b30c4 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -2,6 +2,63 @@ #include "util.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(pVeh)->Fix(); + break; + } +#ifdef GTAVC + case VEHICLE_BIKE: + { + reinterpret_cast(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(hveh, &roll); + roll += 180; + Command(hveh, roll); + Command(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) { #ifdef GTA3 @@ -58,18 +115,18 @@ std::string Util::GetLocationName(CVector* pos) } #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; bool veh_engine = true; float speed; - if (ped->m_nPedFlags.bInVehicle) + if (IsInVehicle(pPed)) { - hveh = CPools::GetVehicleRef(ped->m_pVehicle); - veh_engine = ped->m_pVehicle->m_nVehicleFlags.bEngineOn; - speed = ped->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f; + hveh = CPools::GetVehicleRef(pPed->m_pVehicle); + veh_engine = pPed->m_pVehicle->m_nVehicleFlags.bEngineOn; + speed = pPed->m_pVehicle->m_vecMoveSpeed.Magnitude() * 50.0f; } Command(hped); @@ -77,7 +134,7 @@ void Util::ClearCharTasksVehCheck(CPed* ped) if (hveh) { Command(hped, hveh); - ped->m_pVehicle->m_nVehicleFlags.bEngineOn = veh_engine; + pPed->m_pVehicle->m_nVehicleFlags.bEngineOn = veh_engine; Command(hveh, speed); } } diff --git a/src/util.h b/src/util.h index 6e62f76..8213a29 100644 --- a/src/util.h +++ b/src/util.h @@ -2,6 +2,11 @@ #include "tchar.h" #include "pdh.h" + +/* +* Contains utility functions +* for all 3 games +*/ class Util { private: @@ -16,16 +21,20 @@ public: Util(Util&) = delete; #ifdef GTASA - static void ClearCharTasksVehCheck(CPed* ped); static int GetLargestGangInZone(); + static void ClearCharTasksVehCheck(CPed* ped); + static bool IsOnMission(); #endif - static void SetCarForwardSpeed(CVehicle *pVeh, float speed); + + static void FlipVehicle(CVehicle *pVeh); + static void FixVehicle(CVehicle *pVeh); static CPed* GetClosestPed(); static CVehicle* GetClosestVehicle(); static void GetCPUUsageInit(); static double GetCurrentCPUUsage(); static std::string GetLocationName(CVector* pos); 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 SetCarForwardSpeed(CVehicle *pVeh, float speed); }; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index ee73361..ff49dcb 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -12,63 +12,6 @@ #include "paint.h" #endif -void Vehicle::FixVehicle(CVehicle *pVeh) -{ -#ifdef GTASA - pVeh->Fix(); -#else - switch (pVeh->m_nVehicleClass) - { - case VEHICLE_AUTOMOBILE: - { - reinterpret_cast(pVeh)->Fix(); - break; - } -#ifdef GTAVC - case VEHICLE_BIKE: - { - reinterpret_cast(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(hveh, &roll); - roll += 180; - Command(hveh, roll); - Command(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() { #ifdef GTASA @@ -85,18 +28,18 @@ Vehicle::Vehicle() CPlayerPed* pPlayer = FindPlayerPed(); CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); - if (pPlayer && pVeh) + if (pPlayer && Util::IsInVehicle()) { int hveh = CPools::GetVehicleRef(pVeh); if (flipVeh.Pressed()) { - FlipVehicle(); + Util::FlipVehicle(pVeh); } if (fixVeh.Pressed()) { - FixVehicle(pVeh); + Util::FixVehicle(pVeh); SetHelpMessage("Vehicle fixed", false, false, false); } @@ -575,19 +518,16 @@ void Vehicle::ShowPage() 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) - { - FixVehicle(pVeh); - } + Util::FixVehicle(pVeh); } 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(); diff --git a/src/vehicle.h b/src/vehicle.h index af0d65b..46c52ec 100644 --- a/src/vehicle.h +++ b/src/vehicle.h @@ -82,12 +82,11 @@ private: #endif private: - static void FixVehicle(CVehicle *pVeh); + #ifdef GTASA static void AddComponent(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 void GenerateHandlingDataFile(int phandling); #endif public: