From 257192540d3c3127d471d3513d69b341da8784cf Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Mon, 2 Aug 2021 07:41:48 +0600 Subject: [PATCH] Add vice city support --- .vscode/c_cpp_properties.json | 8 ++-- .vscode/launch.json | 11 +++++ .vscode/tasks.json | 42 +++++++++++++++-- src/Animation.cpp | 10 ++-- src/CheatMenu.cpp | 43 ++++++++++++++++-- src/CheatMenu.h | 40 ++++++++++------ src/Game.cpp | 8 ++-- src/Hook.cpp | 25 +++++++++- src/Hook.h | 3 ++ src/Menu.cpp | 37 ++++++++++----- src/Ped.cpp | 2 +- src/Player.cpp | 6 +-- src/Teleport.cpp | 65 +++++++++++++++++++------- src/Teleport.h | 6 +++ src/Ui.cpp | 3 +- src/Ui.h | 5 +- src/Updater.cpp | 6 +-- src/Util.cpp | 71 ++++++++++++++++------------- src/Util.h | 8 +++- src/Vehicle.cpp | 22 ++++----- src/Visual.cpp | 4 +- src/pch.h | 34 +++++++++++--- tools/{Debug.bat => DebugSA.bat} | 2 +- tools/{Release.bat => DebugVC.bat} | 2 +- tools/ReleaseSA.bat | 7 +++ tools/ReleaseVC.bat | 7 +++ tools/premake5.lua | 73 +++++++++++++++++++++++++++++- 27 files changed, 420 insertions(+), 130 deletions(-) rename tools/{Debug.bat => DebugSA.bat} (69%) rename tools/{Release.bat => DebugVC.bat} (69%) create mode 100644 tools/ReleaseSA.bat create mode 100644 tools/ReleaseVC.bat diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index a19e5be..9bf22bb 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -6,8 +6,10 @@ "${workspaceFolder}/**", "${PLUGIN_SDK_DIR}/*", "${DIRECTX9_SDK_DIR}/Include/*", - "${PLUGIN_SDK_DIR}/plugin_sa/*", - "${PLUGIN_SDK_DIR}/plugin_sa/game_sa/*", + // "${PLUGIN_SDK_DIR}/plugin_sa/*", + // "${PLUGIN_SDK_DIR}/plugin_sa/game_sa/*", + "${PLUGIN_SDK_DIR}/plugin_vc/*", + "${PLUGIN_SDK_DIR}/plugin_vc/game_vc/*", "${PLUGIN_SDK_DIR}/shared/*", "${PLUGIN_SDK_DIR}/shared/game/*", "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\ucrt\\*", @@ -18,7 +20,7 @@ "IS_PLATFORM_WIN", "_CRT_SECURE_NO_WARNINGS", "_CRT_NON_CONFORMING_SWPRINTFS", - "GTASA", + "GTAVC", "_DX9_SDK_INSTALLED", "PLUGIN_SGV_10US" ], diff --git a/.vscode/launch.json b/.vscode/launch.json index 03db11e..d594d94 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -15,6 +15,17 @@ "environment": [], "console": "internalConsole" }, + { + "name": "Launch VC", + "type": "cppvsdbg", + "request": "launch", + "program": "F:/GTA Vice City/gta-vc.exe", + "args": [], + "stopAtEntry": false, + "cwd": "C:/Work/GTASanAndreas/", + "environment": [], + "console": "internalConsole" + }, { "name": "Attach", "type": "cppvsdbg", diff --git a/.vscode/tasks.json b/.vscode/tasks.json index a1c1a53..b745e35 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -4,9 +4,9 @@ "version": "2.0.0", "tasks": [ { - "label": "Build Debug", + "label": "Build DebugSA", "type": "shell", - "command": "${workspaceFolder}/tools/Debug.bat", + "command": "${workspaceFolder}/tools/DebugSA.bat", "presentation": { "echo": true, "reveal": "always", @@ -21,9 +21,43 @@ } }, { - "label": "Build Release", + "label": "Build ReleaseSA", "type": "shell", - "command": "${workspaceFolder}/tools/Release.bat", + "command": "${workspaceFolder}/tools/ReleaseSA.bat", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": false, + "clear": true + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build DebugVC", + "type": "shell", + "command": "${workspaceFolder}/tools/DebugVC.bat", + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "shared", + "showReuseMessage": false, + "clear": true + }, + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "label": "Build ReleaseVC", + "type": "shell", + "command": "${workspaceFolder}/tools/ReleaseVC.bat", "presentation": { "echo": true, "reveal": "always", diff --git a/src/Animation.cpp b/src/Animation.cpp index a41c902..e670759 100644 --- a/src/Animation.cpp +++ b/src/Animation.cpp @@ -39,7 +39,7 @@ void Animation::PlayCutscene(std::string& rootKey, std::string& cutsceneId, std: { if (Util::IsOnCutscene()) { - CHud::SetHelpMessage("Another cutscene is running", false, false, false); + SetHelpMessage("Another cutscene is running", false, false, false); return; } @@ -97,7 +97,7 @@ void Animation::Draw() if (Ui::ListBox("Fighting style", m_FightingStyleList, m_nFightingStyle)) { Command(hPlayer, m_nFightingStyle + 4, 6); - CHud::SetHelpMessage("Fighting anim set", false, false, false); + SetHelpMessage("Fighting anim set", false, false, false); } if (Ui::ListBoxStr("Walking style", m_WalkingStyleList, m_nWalkingStyle)) { @@ -114,7 +114,7 @@ void Animation::Draw() Command(hPlayer, m_nWalkingStyle.c_str()); Command(m_nWalkingStyle.c_str()); } - CHud::SetHelpMessage("Walking anim set", false, false, false); + SetHelpMessage("Walking anim set", false, false, false); } ImGui::EndTabItem(); } @@ -189,8 +189,8 @@ void Animation::RemoveAnimation(std::string& ifp, std::string& anim, std::string { m_AnimData.m_Json.m_Data["Custom"].erase(anim); m_AnimData.m_Json.WriteToDisk(); - CHud::SetHelpMessage("Animation removed", false, false, false); + SetHelpMessage("Animation removed", false, false, false); } else - CHud::SetHelpMessage("You can only remove custom anims", false, false, false); + SetHelpMessage("You can only remove custom anims", false, false, false); } diff --git a/src/CheatMenu.cpp b/src/CheatMenu.cpp index 4157e4a..cbca69c 100644 --- a/src/CheatMenu.cpp +++ b/src/CheatMenu.cpp @@ -7,21 +7,29 @@ void CheatMenu::DrawWindow() { ImGuiIO& io = ImGui::GetIO(); - static bool game_running = true; + static bool bRunning = true; + #ifdef GTASA if (FrontEndMenuManager.m_bMenuActive) + #elif GTAVC + if (FrontendMenuManager.m_bMenuVisible) + #endif { - if (game_running) + if (bRunning) { config.WriteToDisk(); - game_running = false; + bRunning = false; m_bShowMouse = false; } } else { - game_running = true; + bRunning = true; + #ifdef GTASA if (Globals::m_bShowMenu || m_Commands::m_bShowMenu) + #elif GTAVC + if (Globals::m_bShowMenu) + #endif { if (Globals::m_bShowMenu) { @@ -45,8 +53,12 @@ void CheatMenu::DrawWindow() ImGui::End(); } } + #ifdef GTASA else + { DrawShortcutsWindow(); + } + #endif } } DrawOverlay(); @@ -65,10 +77,18 @@ CheatMenu::CheatMenu() Events::processScriptsEvent += []() { - if (Globals::m_bInit && !FrontEndMenuManager.m_bMenuActive) + if (Globals::m_bInit && + #ifdef GTASA + !FrontEndMenuManager.m_bMenuActive + #elif GTAVC + !FrontendMenuManager.m_bMenuVisible + #endif + ) { if (Ui::HotKeyPressed(Menu::m_HotKeys::menuOpen)) + { Globals::m_bShowMenu = !Globals::m_bShowMenu; + } if (Ui::HotKeyPressed(Menu::m_HotKeys::commandWindow)) { @@ -176,7 +196,9 @@ void MenuThread(void* param) } static bool bGameInit = false; + #ifdef GTASA Hook::ApplyMouseFix(); + #endif // Wait till the game is initialized Events::initRwEvent += [] @@ -222,6 +244,7 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) if (nReason == DLL_PROCESS_ATTACH) { uint gameVersion = GetGameVersion(); + #ifdef GTASA if (gameVersion == GAME_10US_HOODLUM || gameVersion == GAME_10US_COMPACT) { CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); @@ -230,6 +253,16 @@ BOOL WINAPI DllMain(HINSTANCE hDllHandle, DWORD nReason, LPVOID Reserved) { MessageBox(HWND_DESKTOP, "Unknown game version. GTA SA v1.0 US is required.", "CheatMenu", MB_ICONERROR); } + #elif GTAVC + if (gameVersion == GAME_10EN) + { + CreateThread(nullptr, NULL, (LPTHREAD_START_ROUTINE)&MenuThread, nullptr, NULL, nullptr); + } + else + { + MessageBox(HWND_DESKTOP, "Unknown game version. GTA VC v1.0 EN is required.", "CheatMenu", MB_ICONERROR); + } + #endif } return TRUE; diff --git a/src/CheatMenu.h b/src/CheatMenu.h index 645aab3..7b6b847 100644 --- a/src/CheatMenu.h +++ b/src/CheatMenu.h @@ -9,26 +9,38 @@ */ #pragma once -#include "Animation.h" -#include "Game.h" #include "Hook.h" #include "Menu.h" -#include "Ped.h" -#include "Player.h" #include "Teleport.h" -#include "Vehicle.h" -#include "Visual.h" -#include "Weapon.h" -class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon +#ifdef GTASA + #include "Animation.h" + #include "Game.h" + #include "Ped.h" + #include "Player.h" + #include "Vehicle.h" + #include "Visual.h" + #include "Weapon.h" + class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, Visual, Weapon +#elif defined(GTAVC) + class CheatMenu : Hook, Menu, Teleport +#endif + { private: - inline static CallbackTable header - { - {"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw}, - {"Animation", &Animation::Draw}, {"Vehicle", &Vehicle::Draw}, {"Weapon", &Weapon::Draw}, - {"Game", &Game::Draw}, {"Visual", &Visual::Draw}, {"Menu", &Menu::Draw} - }; + #ifdef GTASA + inline static CallbackTable header + { + {"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw}, + {"Animation", &Animation::Draw}, {"Vehicle", &Vehicle::Draw}, {"Weapon", &Weapon::Draw}, + {"Game", &Game::Draw}, {"Visual", &Visual::Draw}, {"Menu", &Menu::Draw} + }; + #elif GTAVC + inline static CallbackTable header + { + {"Teleport", &Teleport::Draw}, {"Menu", &Menu::Draw} + }; + #endif static void ApplyStyle(); static void DrawWindow(); diff --git a/src/Game.cpp b/src/Game.cpp index 143a2db..cb0ae2c 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -62,7 +62,7 @@ Game::Game() if (Ui::HotKeyPressed(Menu::m_HotKeys::quickSceenShot)) { Command(); - CHud::SetHelpMessage("Screenshot taken", false, false, false); + SetHelpMessage("Screenshot taken", false, false, false); } } @@ -133,7 +133,7 @@ Game::Game() if (m_RandomCheats::m_EnabledCheats[i][1] == "true") { ((void(*)(int))0x00438370)(id); // cheatEnableLegimate(int CheatID) - CHud::SetHelpMessage(m_RandomCheats::m_EnabledCheats[i][0].c_str(), false, false, false); + SetHelpMessage(m_RandomCheats::m_EnabledCheats[i][0].c_str(), false, false, false); m_RandomCheats::m_nTimer = timer; } break; @@ -174,7 +174,7 @@ void SetPlayerMission(std::string& rootkey, std::string& name, std::string& id) player->SetWantedLevel(0); Command(std::stoi(id)); } - else CHud::SetHelpMessage("Can't start mission now", false, false, false); + else SetHelpMessage("Can't start mission now", false, false, false); } void Game::FreeCam() @@ -239,7 +239,7 @@ void Game::FreeCam() // disble them again cause they get enabled CHud::bScriptDontDisplayRadar = true; CHud::m_Wants_To_Draw_Hud = false; - CHud::SetHelpMessage("Player telported", false, false, false); + SetHelpMessage("Player telported", false, false, false); } if (KeyPressed(VK_RCONTROL)) diff --git a/src/Hook.cpp b/src/Hook.cpp index c82a004..9d605d2 100644 --- a/src/Hook.cpp +++ b/src/Hook.cpp @@ -9,7 +9,9 @@ LRESULT Hook::WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (ImGui::GetIO().WantTextInput) { + #ifdef GTASA Call<0x53F1E0>(); // CPad::ClearKeyboardHistory + #endif return 1; } @@ -111,8 +113,10 @@ void Hook::RenderFrame(void* ptr) ImGui_ImplWin32_Init(RsGlobal.ps->window); + #ifdef GTASA // shift trigger fix patch::Nop(0x00531155, 5); + #endif if (Globals::renderer == Render_DirectX9) { @@ -161,10 +165,26 @@ void Hook::ShowMouse(bool state) ImGui::GetIO().MouseDrawCursor = state; + #ifdef GTASA + Hook::ApplyMouseFix(); // Reapply the patches + #elif GTAVC + if (m_bShowMouse) + { + patch::SetUChar(0x6020A0, 0xC3); // psSetMousePos + patch::Nop(0x4AB6CA, 5); // don't call CPad::UpdateMouse() + } + else + { + patch::SetUChar(0x6020A0, 0x53); + patch::SetRaw(0x4AB6CA, (char*)"\xE8\x51\x21\x00\x00", 5); + } + #endif + CPad::NewMouseControllerState.X = 0; CPad::NewMouseControllerState.Y = 0; + CPad::ClearMouseHistory(); + CPad::UpdatePads(); m_bMouseVisibility = m_bShowMouse; - Hook::ApplyMouseFix(); // Reapply the patches } } @@ -199,6 +219,7 @@ Hook::~Hook() kiero::shutdown(); } +#ifdef GTASA struct Mouse { unsigned int x, y; @@ -280,3 +301,5 @@ void Hook::ApplyMouseFix() patch::SetChar(0x746A08, 32); // diMouseOffset patch::SetChar(0x746A58, 32); // diDeviceoffset } + +#endif \ No newline at end of file diff --git a/src/Hook.h b/src/Hook.h index ced659e..2728be5 100644 --- a/src/Hook.h +++ b/src/Hook.h @@ -26,7 +26,10 @@ private: public: inline static bool m_bShowMouse = false; inline static std::function windowCallback = nullptr; + + #ifdef GTASA static void ApplyMouseFix(); + #endif Hook(); ~Hook(); diff --git a/src/Menu.cpp b/src/Menu.cpp index 69192ca..a57ccba 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -1,13 +1,16 @@ #include "pch.h" #include "MenuInfo.h" #include "Menu.h" -#include "Teleport.h" -#include "Weapon.h" -#include "Vehicle.h" #include "Ui.h" #include "Util.h" #include "Updater.h" +#ifdef GTASA +#include "Teleport.h" +#include "Weapon.h" +#include "Vehicle.h" +#endif + Menu::Menu() { // TODO: use structs @@ -142,7 +145,15 @@ void Menu::DrawOverlay() GlobalMemoryStatusEx(&memInfo); int mUsedRam = static_cast((memInfo.ullTotalPhys - memInfo.ullAvailPhys) * 1e-6); m_Overlay::fMemUsage = 100.0f * (static_cast(mUsedRam) / static_cast(m_Overlay::mTotalRam)); - m_Overlay::mFPS = static_cast(CTimer::game_FPS); + + m_Overlay::mFPS = static_cast + ( + #ifdef GTASA + CTimer::game_FPS + #elif GTAVC + io.Framerate + #endif + ); m_Overlay::mLastInterval = game_ms; } @@ -232,7 +243,7 @@ void Menu::ProcessCommands() } catch (...) { - CHud::SetHelpMessage("Invalid value", false, false, false); + SetHelpMessage("Invalid value", false, false, false); } } @@ -249,10 +260,11 @@ void Menu::ProcessCommands() } catch (...) { - CHud::SetHelpMessage("Invalid value", false, false, false); + SetHelpMessage("Invalid value", false, false, false); } } + #ifdef GTASA if (command == "tp") { try @@ -273,7 +285,7 @@ void Menu::ProcessCommands() } catch (...) { - CHud::SetHelpMessage("Invalid location", false, false, false); + SetHelpMessage("Invalid location", false, false, false); } } @@ -286,7 +298,7 @@ void Menu::ProcessCommands() { std::string weapon = "-1"; Weapon::GiveWeaponToPlayer(weapon); - CHud::SetHelpMessage("Weapon given", false, false, false); + SetHelpMessage("Weapon given", false, false, false); } else { @@ -297,10 +309,10 @@ void Menu::ProcessCommands() if (wep_name != "" && pweaponinfo->m_nModelId1 != -1) { Weapon::GiveWeaponToPlayer(weapon_name); - CHud::SetHelpMessage("Weapon given", false, false, false); + SetHelpMessage("Weapon given", false, false, false); } else - CHud::SetHelpMessage("Invalid command", false, false, false); + SetHelpMessage("Invalid command", false, false, false); } return; @@ -315,11 +327,12 @@ void Menu::ProcessCommands() { std::string smodel = std::to_string(model); Vehicle::SpawnVehicle(smodel); - CHud::SetHelpMessage("Vehicle spawned", false, false, false); + SetHelpMessage("Vehicle spawned", false, false, false); } else - CHud::SetHelpMessage("Invalid command", false, false, false); + SetHelpMessage("Invalid command", false, false, false); } + #endif } void Menu::Draw() diff --git a/src/Ped.cpp b/src/Ped.cpp index a9485a3..fb88382 100644 --- a/src/Ped.cpp +++ b/src/Ped.cpp @@ -31,7 +31,7 @@ void Ped::SpawnPed(std::string& model) { if (m_SpawnPed::m_List.size() == SPAWN_PED_LIMIT) { - CHud::SetHelpMessage("Max limit reached", false, false, false); + SetHelpMessage("Max limit reached", false, false, false); return; } diff --git a/src/Player.cpp b/src/Player.cpp index f57f703..d877e05 100644 --- a/src/Player.cpp +++ b/src/Player.cpp @@ -120,7 +120,7 @@ Player::Player() { if (m_bGodMode) { - CHud::SetHelpMessage("God mode disabled", false, false, false); + SetHelpMessage("God mode disabled", false, false, false); patch::Set(0x96916D, m_bGodMode, false); player->m_nPhysicalFlags.bBulletProof = false; @@ -132,7 +132,7 @@ Player::Player() } else { - CHud::SetHelpMessage("God mode enabled", false, false, false); + SetHelpMessage("God mode enabled", false, false, false); m_bGodMode = true; } } @@ -223,7 +223,7 @@ void Player::Draw() std::string text = std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " + std::to_string(pos.z); ImGui::SetClipboardText(text.c_str()); - CHud::SetHelpMessage("Coordinates copied", false, false, false); + SetHelpMessage("Coordinates copied", false, false, false); } ImGui::SameLine(); if (ImGui::Button("Suicide", ImVec2(Ui::GetSize(2)))) diff --git a/src/Teleport.cpp b/src/Teleport.cpp index 673a746..f84c1fb 100644 --- a/src/Teleport.cpp +++ b/src/Teleport.cpp @@ -4,6 +4,7 @@ #include "Ui.h" #include "Util.h" +#ifdef GTASA // FlA tRadarTrace* CRadar::ms_RadarTrace = reinterpret_cast(patch::GetPointer(0x5838B0 + 2)); @@ -36,6 +37,7 @@ void Teleport::FetchRadarSpriteData() */ } } +#endif Teleport::Teleport() { @@ -48,15 +50,20 @@ Teleport::Teleport() { CPlayerPed* player = FindPlayerPed(); - CEntity* player_entity = FindPlayerEntity(-1); + #ifdef GTASA + CEntity* player_entity = FindPlayerEntity(); m_Teleport::m_fPos.z = CWorld::FindGroundZFor3DCoord(m_Teleport::m_fPos.x, m_Teleport::m_fPos.y, m_Teleport::m_fPos.z + 100.0f, nullptr, &player_entity) + 1.0f; + #elif GTAVC + m_Teleport::m_fPos.z = CWorld::FindGroundZFor3DCoord(m_Teleport::m_fPos.x, m_Teleport::m_fPos.y, + m_Teleport::m_fPos.z + 100.0f, nullptr) + 1.0f; + #endif CVehicle* pVeh = player->m_pVehicle; - if (pVeh && player->m_nPedFlags.bInVehicle) - pVeh->Teleport(m_Teleport::m_fPos, false); + if (pVeh && BY_GAME(player->m_nPedFlags.bInVehicle, player->m_pVehicle)) + BY_GAME(pVeh->Teleport(m_Teleport::m_fPos, false), pVeh->Teleport(m_Teleport::m_fPos)); else - player->Teleport(m_Teleport::m_fPos, false); + BY_GAME(player->Teleport(m_Teleport::m_fPos, false), player->Teleport(m_Teleport::m_fPos)); m_Teleport::m_bEnabled = false; Command(CPools::GetPedRef(player), false); @@ -80,14 +87,15 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, short interior_id) { CPlayerPed* pPlayer = FindPlayerPed(); CVehicle* pVeh = pPlayer->m_pVehicle; - + + #ifdef GTASA if (get_marker) { tRadarTrace targetBlip = CRadar::ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)]; if (targetBlip.m_nBlipSprite != RADAR_SPRITE_WAYPOINT) { - CHud::SetHelpMessage("Target blip not found. You need to place it on the map first.", false, false, false); + SetHelpMessage("Target blip not found. You need to place it on the map first.", false, false, false); return; } CEntity* pPlayerEntity = FindPlayerEntity(-1); @@ -100,28 +108,41 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, short interior_id) TheCamera.Fade(0, 0); Command(CPools::GetPedRef(pPlayer), true); } + #endif CStreaming::LoadScene(&pos); CStreaming::LoadSceneCollision(&pos); CStreaming::LoadAllRequestedModels(false); + #ifdef GTASA if (pVeh && pPlayer->m_nPedFlags.bInVehicle) { pVeh->Teleport(pos, false); - + if (pVeh->m_nVehicleClass == VEHICLE_BIKE) reinterpret_cast(pVeh)->PlaceOnRoadProperly(); else if (pVeh->m_nVehicleClass != VEHICLE_BOAT) reinterpret_cast(pVeh)->PlaceOnRoadProperly(); - pVeh->m_nAreaCode = interior_id; + BY_GAME(pVeh->m_nAreaCode, pVeh->m_nInterior) = interior_id; } else { pPlayer->Teleport(pos, false); } + #elif GTAVC + if (pVeh && pPlayer->m_pVehicle) + { + BY_GAME(pVeh->m_nAreaCode, pVeh->m_nInterior) = interior_id; + pVeh->Teleport(pos); + } + else + { + pPlayer->Teleport(pos); + } + #endif - pPlayer->m_nAreaCode = interior_id; + BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior) = interior_id; Command(interior_id); } @@ -150,7 +171,7 @@ void Teleport::TeleportToLocation(std::string& rootkey, std::string& bLocName, s } catch (...) { - CHud::SetHelpMessage("Invalid location", false, false, false); + SetHelpMessage("Invalid location", false, false, false); } } @@ -159,10 +180,10 @@ void Teleport::RemoveTeleportEntry(std::string& category, std::string& key, std: if (category == "Custom") { tp_data.m_Json.m_Data["Custom"].erase(key); - CHud::SetHelpMessage("Location removed", false, false, false); + SetHelpMessage("Location removed", false, false, false); tp_data.m_Json.WriteToDisk(); } - else CHud::SetHelpMessage("You can only remove custom location", false, false, false); + else SetHelpMessage("You can only remove custom location", false, false, false); } void Teleport::Draw() @@ -178,13 +199,14 @@ void Teleport::Draw() ImGui::Columns(2, nullptr, false); ImGui::Checkbox("Insert coordinates", &m_bInsertCoord); ImGui::NextColumn(); + #ifdef GTASA if (Ui::CheckboxWithHint("Quick teleport", &m_bQuickTeleport, (std::string("Teleport to the location of your radar\ntarget blip using ") + Ui::GetHotKeyNameString(Menu::m_HotKeys::quickTeleport)).c_str())) { config.SetValue("quick_teleport", m_bQuickTeleport); } - + #endif ImGui::Columns(1); ImGui::Spacing(); @@ -201,7 +223,7 @@ void Teleport::Draw() ImGui::Spacing(); - if (ImGui::Button("Teleport to Coord", Ui::GetSize(2))) + if (ImGui::Button("Teleport to coord", Ui::GetSize(2))) { std::stringstream ss(m_nInputBuffer); std::string temp; @@ -222,13 +244,21 @@ void Teleport::Draw() } catch (...) { - CHud::SetHelpMessage("Invalid coordinate", false, false, false); + SetHelpMessage("Invalid coordinate", false, false, false); } } ImGui::SameLine(); + #ifdef GTASA if (ImGui::Button("Teleport to marker", Ui::GetSize(2))) + { TeleportPlayer(true); - + } + #else + if (ImGui::Button("Teleport to map center", Ui::GetSize(2))) + { + TeleportPlayer(false, CVector(0, 0, 23)); + } + #endif ImGui::EndChild(); } ImGui::EndTabItem(); @@ -236,7 +266,10 @@ void Teleport::Draw() if (ImGui::BeginTabItem("Search")) { + #ifdef GTASA FetchRadarSpriteData(); + #endif + ImGui::Spacing(); Ui::DrawJSON(tp_data.m_Json, tp_data.m_Categories, tp_data.m_Selected, tp_data.m_Filter, &TeleportToLocation, &RemoveTeleportEntry); diff --git a/src/Teleport.h b/src/Teleport.h index 10ca342..32dfa42 100644 --- a/src/Teleport.h +++ b/src/Teleport.h @@ -11,7 +11,11 @@ private: inline static SSearchData tp_data{"teleport"}; inline static char m_nLocationBuffer[INPUT_BUFFER_SIZE]; inline static uint m_nQuickTeleportTimer; + + #ifdef GTASA inline static CJson m_SpriteJson = CJson("radar sprite"); + #endif + struct m_Teleport { inline static bool m_bEnabled; @@ -20,11 +24,13 @@ private: }; + #ifdef GTASA /* Generates radar sprite coordinates on the fly. Shouldn't get saved in 'teleport.json', needs to be cleared at game shutdown. */ static void FetchRadarSpriteData(); + #endif protected: Teleport(); diff --git a/src/Ui.cpp b/src/Ui.cpp index b3b07a0..b4fc915 100644 --- a/src/Ui.cpp +++ b/src/Ui.cpp @@ -426,7 +426,7 @@ void Ui::DrawJSON(CJson& json, std::vector& combo_items, std::strin ImGui::EndChild(); } - +#ifdef GTASA void Ui::EditStat(const char* label, const int stat_id, const int min, const int def, const int max) { if (ImGui::CollapsingHeader(label)) @@ -465,6 +465,7 @@ void Ui::EditStat(const char* label, const int stat_id, const int min, const int ImGui::Separator(); } } +#endif void Ui::FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* hint) { diff --git a/src/Ui.h b/src/Ui.h index f657df8..dc6a178 100644 --- a/src/Ui.h +++ b/src/Ui.h @@ -68,8 +68,11 @@ public: static void EditReference(const char* label, T& address, int min = 0, int def = 0, int max = 100); static void EditRadioButtonAddress(const char* label, std::vector& named_mem); static void EditRadioButtonAddressEx(const char* label, int addr, std::vector& named_val); + + #ifdef GTASA static void EditStat(const char* label, int stat_id, int min = 0, int def = 0, int max = 1000); - + #endif + static void FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* hint); static ImVec2 GetSize(short count = 1, bool spacing = true); diff --git a/src/Updater.cpp b/src/Updater.cpp index ef2bf48..abf22f8 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -12,7 +12,7 @@ void Updater::CheckForUpdate() if (res == E_OUTOFMEMORY || res == INET_E_DOWNLOAD_FAILURE) { - CHud::SetHelpMessage("Failed to check for updates", false, false, false); + SetHelpMessage("Failed to check for updates", false, false, false); return; } CJson verinfo = CJson("versioninfo"); @@ -22,12 +22,12 @@ void Updater::CheckForUpdate() if (m_LatestVersion > MENU_VERSION_NUMBER) { - CHud::SetHelpMessage("Update found", false, false, false); + SetHelpMessage("Update found", false, false, false); m_State = UPDATER_UPDATE_FOUND; } else { - CHud::SetHelpMessage("No update found.", false, false, false); + SetHelpMessage("No update found.", false, false, false); Updater::m_State = UPDATER_IDLE; } } diff --git a/src/Util.cpp b/src/Util.cpp index 5f25b39..a4b1b11 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1,6 +1,5 @@ #include "pch.h" #include "Util.h" -#include #include "psapi.h" #include "CFileLoader.h" @@ -68,6 +67,44 @@ void* Util::GetTextureFromRaster(RwTexture *pTexture) return (&raster->renderResource->texture); } +std::string Util::GetLocationName(CVector* pos) +{ + #ifdef GTASA + int hplayer = CPools::GetPedRef(FindPlayerPed()); + + int interior = 0; + Command(&interior); + + std::string town = "San Andreas"; + int city; + Command(&hplayer, &city); + + switch (city) + { + case 0: + town = "CS"; + break; + case 1: + town = "LS"; + break; + case 2: + town = "SF"; + break; + case 3: + town = "LV"; + break; + } + + if (interior == 0) + return CTheZones::FindSmallestZoneForPosition(*pos, true)->GetTranslatedName() + std::string(", ") + town; + return std::string("Interior ") + std::to_string(interior) + ", " + town; + + #elif GTAVC + return "Vice City"; + #endif +} + +#ifdef GTASA // Thanks DKPac22 RwTexture* Util::LoadTextureFromMemory(char* data, unsigned int size) { @@ -118,37 +155,6 @@ bool Util::IsOnCutscene() return CCutsceneMgr::ms_running; } -std::string Util::GetLocationName(CVector* pos) -{ - int hplayer = CPools::GetPedRef(FindPlayerPed()); - int interior = 0; - Command(&interior); - - std::string town = "San Andreas"; - int city; - Command(&hplayer, &city); - - switch (city) - { - case 0: - town = "CS"; - break; - case 1: - town = "LS"; - break; - case 2: - town = "SF"; - break; - case 3: - town = "LV"; - break; - } - - if (interior == 0) - return CTheZones::FindSmallestZoneForPosition(*pos, true)->GetTranslatedName() + std::string(", ") + town; - return std::string("Interior ") + std::to_string(interior) + ", " + town; -} - int Util::GetLargestGangInZone() { int gang_id = 0, max_density = 0; @@ -212,6 +218,7 @@ CPed* Util::GetClosestPed() } return nullptr; } +#endif void Util::RainbowValues(int& r, int& g, int& b, float speed) { diff --git a/src/Util.h b/src/Util.h index 93e3981..334b256 100644 --- a/src/Util.h +++ b/src/Util.h @@ -11,17 +11,21 @@ static HANDLE self; class Util { public: + + #ifdef GTASA static void ClearCharTasksVehCheck(CPed* ped); static CPed* GetClosestPed(); static CVehicle* GetClosestVehicle(); static int GetLargestGangInZone(); static bool IsOnCutscene(); - static bool IsOnMission(); + static RwTexture* LoadTextureFromMemory(char* data, unsigned int size); + #endif + static std::string GetLocationName(CVector* pos); + static bool IsOnMission(); static void RainbowValues(int& r, int& g, int& b, float speed); static void GetCPUUsageInit(); static double GetCurrentCPUUsage(); static void* GetTextureFromRaster(RwTexture* pTexture); static void LoadTextureDirectory(SSearchData& data, char* path, bool pass_full_name = false); - static RwTexture* LoadTextureFromMemory(char* data, unsigned int size); }; diff --git a/src/Vehicle.cpp b/src/Vehicle.cpp index ad1a0ef..4f33939 100644 --- a/src/Vehicle.cpp +++ b/src/Vehicle.cpp @@ -39,7 +39,7 @@ Vehicle::Vehicle() { player->m_pVehicle->Fix(); player->m_pVehicle->m_fHealth = 1000.0f; - CHud::SetHelpMessage("Vehicle fixed", false, false, false); + SetHelpMessage("Vehicle fixed", false, false, false); } if (Ui::HotKeyPressed(Menu::m_HotKeys::vehEngine)) @@ -47,9 +47,9 @@ Vehicle::Vehicle() bool state = !veh->m_nVehicleFlags.bEngineBroken || veh->m_nVehicleFlags.bEngineOn; if (state) - CHud::SetHelpMessage("Vehicle engine off", false, false, false); + SetHelpMessage("Vehicle engine off", false, false, false); else - CHud::SetHelpMessage("Vehicle engine on", false, false, false); + SetHelpMessage("Vehicle engine on", false, false, false); veh->m_nVehicleFlags.bEngineBroken = state; veh->m_nVehicleFlags.bEngineOn = !state; @@ -168,7 +168,7 @@ void Vehicle::AddComponent(const std::string& component, const bool display_mess CStreaming::SetModelIsDeletable(icomp); if (display_message) - CHud::SetHelpMessage("Component added", false, false, false); + SetHelpMessage("Component added", false, false, false); } catch (...) { @@ -188,7 +188,7 @@ void Vehicle::RemoveComponent(const std::string& component, const bool display_m player->m_pVehicle->RemoveVehicleUpgrade(icomp); if (display_message) - CHud::SetHelpMessage("Component removed", false, false, false); + SetHelpMessage("Component removed", false, false, false); } catch (...) { @@ -221,7 +221,7 @@ int Vehicle::GetRandomTrainIdForModel(int model) _end = 10; break; default: - CHud::SetHelpMessage("Invalid train model", false, false, false); + SetHelpMessage("Invalid train model", false, false, false); return -1; } int id = Random(_start, _end); @@ -955,7 +955,7 @@ void Vehicle::Draw() if (ImGui::Button("Reset color", ImVec2(Ui::GetSize()))) { Paint::ResetNodeColor(veh, Paint::veh_nodes::selected); - CHud::SetHelpMessage("Color reset", false, false, false); + SetHelpMessage("Color reset", false, false, false); } ImGui::Spacing(); @@ -1036,7 +1036,7 @@ void Vehicle::Draw() if (ImGui::Button("Remove neon", ImVec2(Ui::GetSize()))) { RemoveNeon(veh); - CHud::SetHelpMessage("Neon removed", false, false, false); + SetHelpMessage("Neon removed", false, false, false); } ImGui::Spacing(); @@ -1092,7 +1092,7 @@ void Vehicle::Draw() if (ImGui::Button("Reset texture", ImVec2(Ui::GetSize()))) { Paint::ResetNodeTexture(veh, Paint::veh_nodes::selected); - CHud::SetHelpMessage("Texture reset", false, false, false); + SetHelpMessage("Texture reset", false, false, false); } ImGui::Spacing(); @@ -1167,7 +1167,7 @@ void Vehicle::Draw() if (ImGui::Button("Reset handling", ImVec2(Ui::GetSize(3)))) { gHandlingDataMgr.LoadHandlingData(); - CHud::SetHelpMessage("Handling reset", false, false, false); + SetHelpMessage("Handling reset", false, false, false); } ImGui::SameLine(); @@ -1175,7 +1175,7 @@ void Vehicle::Draw() if (ImGui::Button("Save to file", ImVec2(Ui::GetSize(3)))) { GenerateHandlingDataFile(pHandling); - CHud::SetHelpMessage("Handling saved", false, false, false); + SetHelpMessage("Handling saved", false, false, false); } ImGui::SameLine(); diff --git a/src/Visual.cpp b/src/Visual.cpp index 4001abf..1a62d1d 100644 --- a/src/Visual.cpp +++ b/src/Visual.cpp @@ -351,13 +351,13 @@ void Visual::Draw() if (ImGui::Button("Generate timecyc file", Ui::GetSize(2))) { GenerateTimecycFile(); - CHud::SetHelpMessage("File generated", false, false, false); + SetHelpMessage("File generated", false, false, false); } ImGui::SameLine(); if (ImGui::Button("Reset timecyc", Ui::GetSize(2))) { CTimeCycle::Initialise(); - CHud::SetHelpMessage("Timecyc reset", false, false, false); + SetHelpMessage("Timecyc reset", false, false, false); } ImGui::Spacing(); diff --git a/src/pch.h b/src/pch.h index d0032ca..c08aaab 100644 --- a/src/pch.h +++ b/src/pch.h @@ -6,6 +6,12 @@ #define DISCORD_INVITE "https://discord.gg/ZzW7kmf" #define GITHUB_LINK "https://github.com/user-grinch/Cheat-Menu" +#ifdef GTASA +#define BY_GAME(sa, vc) sa +#elif GTAVC +#define BY_GAME(sa, vc) vc +#endif + #include #include #include @@ -21,20 +27,14 @@ #include "plugin.h" #include "CBike.h" #include "CCamera.h" -#include "CCheat.h" -#include "CClothes.h" #include "CClock.h" #include "CCivilianPed.h" -#include "CCutsceneMgr.h" #include "CGangs.h" -#include "CGangWars.h" #include "cHandlingDataMgr.h" #include "CHud.h" #include "CMenuManager.h" #include "CModelInfo.h" -#include "CRadar.h" #include "RenderWare.h" -#include "CShadows.h" #include "CStats.h" #include "CStreaming.h" #include "CTheScripts.h" @@ -46,9 +46,18 @@ #include "CWorld.h" #include "extensions/ScriptCommands.h" #include "extensions/Screen.h" -#include "eVehicleClass.h" #include "extensions/Paths.h" +#ifdef GTASA +#include "CCheat.h" +#include "CClothes.h" +#include "CCutsceneMgr.h" +#include "CRadar.h" +#include "CShadows.h" +#include "eVehicleClass.h" +#include "CGangWars.h" +#endif + #include "../Depend/fla/IDaccess.h" #include "../Depend/imgui/imgui.h" #include "../Depend/imgui/imgui_internal.h" @@ -133,3 +142,14 @@ struct SSearchData std::string m_Selected = "All"; std::vector> m_ImagesList; }; + + +// Common defines +static void SetHelpMessage(const char *message, bool b1, bool b2, bool b3) +{ + #if GTAVC + CHud::SetHelpMessage(message, b1, b2); + #elif GTASA + CHud::SetHelpMessage(message, b1, b2, b3); + #endif +} \ No newline at end of file diff --git a/tools/Debug.bat b/tools/DebugSA.bat similarity index 69% rename from tools/Debug.bat rename to tools/DebugSA.bat index 10ec431..f64b78e 100644 --- a/tools/Debug.bat +++ b/tools/DebugSA.bat @@ -3,5 +3,5 @@ cd tools premake5.exe vs2019 cd ../build call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" -MsBuild CheatMenu.sln /property:Configuration=Debug +MsBuild CheatMenu.sln /property:Configuration=Debug /t:CheatMenuSA cd .. diff --git a/tools/Release.bat b/tools/DebugVC.bat similarity index 69% rename from tools/Release.bat rename to tools/DebugVC.bat index 52620b1..6609df5 100644 --- a/tools/Release.bat +++ b/tools/DebugVC.bat @@ -3,5 +3,5 @@ cd tools premake5.exe vs2019 cd ../build call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" -MsBuild CheatMenu.sln /property:Configuration=Release +MsBuild CheatMenu.sln /property:Configuration=Debug /t:CheatMenuVC cd .. diff --git a/tools/ReleaseSA.bat b/tools/ReleaseSA.bat new file mode 100644 index 0000000..9e098e6 --- /dev/null +++ b/tools/ReleaseSA.bat @@ -0,0 +1,7 @@ +@echo off +cd tools +premake5.exe vs2019 +cd ../build +call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" +MsBuild CheatMenu.sln /property:Configuration=Release /t:CheatMenuSA +cd .. diff --git a/tools/ReleaseVC.bat b/tools/ReleaseVC.bat new file mode 100644 index 0000000..f9a762d --- /dev/null +++ b/tools/ReleaseVC.bat @@ -0,0 +1,7 @@ +@echo off +cd tools +premake5.exe vs2019 +cd ../build +call "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsDevCmd.bat" +MsBuild CheatMenu.sln /property:Configuration=Release /t:CheatMenuVC +cd .. diff --git a/tools/premake5.lua b/tools/premake5.lua index 540992b..69c892c 100644 --- a/tools/premake5.lua +++ b/tools/premake5.lua @@ -6,6 +6,7 @@ PSDK_DIR = os.getenv("PLUGIN_SDK_DIR") DX9SDK_DIR = os.getenv("DIRECTX9_SDK_DIR") GTASA_DIR = "C:/Work/GTASanAndreas" +GTAVC_DIR = "F:/GTA Vice City" if (DX9SDK_DIR == nil) then error("DIRECTX9_SDK_DIR environment variable not set") @@ -46,7 +47,77 @@ project "Depend" defines { "NDEBUG", "IS_PLATFORM_WIN" } optimize "On" -project "CheatMenu" +project "CheatMenuVC" + kind "SharedLib" + targetdir (GTAVC_DIR) + targetextension ".asi" + + files { + "../src/CheatMenu.h", + "../src/CheatMenu.cpp", + "../src/pch.h", + "../src/pch.cpp", + "../src/Hook.h", + "../src/Hook.cpp", + "../src/Updater.h", + "../src/Updater.cpp", + "../src/Json.h", + "../src/Json.cpp", + "../src/Teleport.h", + "../src/Teleport.cpp", + "../src/Ui.h", + "../src/Ui.cpp", + "../src/Util.h", + "../src/Util.cpp", + "../src/Menu.h", + "../src/Menu.cpp" + } + includedirs { + PSDK_DIR .. "/plugin_vc/", + PSDK_DIR .. "/plugin_vc/game_vc/", + PSDK_DIR .. "/shared/", + PSDK_DIR .. "/shared/game/" + } + libdirs (PSDK_DIR .. "/output/lib") + + defines { + "NDEBUG", + "IS_PLATFORM_WIN" , + "_CRT_SECURE_NO_WARNINGS", + "_CRT_NON_CONFORMING_SWPRINTFS", + "GTAVC", + "_DX9_SDK_INSTALLED", + "PLUGIN_SGV_10US" + } + + pchheader "pch.h" + pchsource "../src/pch.cpp" + + filter "configurations:Debug" + symbols "On" + links { + "Depend", + "d3d9", + "d3d11", + "XInput9_1_0", + "Pdh", + "urlmon", + "plugin_vc_d.lib" + } + + filter "configurations:Release" + optimize "On" + links { + "Depend", + "d3d9", + "d3d11", + "XInput9_1_0", + "Pdh", + "urlmon", + "plugin_vc.lib" + } + +project "CheatMenuSA" kind "SharedLib" targetdir (GTASA_DIR) targetextension ".asi"