From 2816ed42f09524cf59b5d5d69224f4d5de8d18dd Mon Sep 17 00:00:00 2001 From: kelson8 Date: Fri, 14 Jun 2024 15:54:39 -0400 Subject: [PATCH] Add test page to the menu in a working state. Blow up all cars, show coods, blow something up, close car doors and more features to come. --- build/test.cpp | 447 ++++++++++++++++++++++++++++++++++++++ build/test.h | 25 +++ src/cheatmenu.cpp | 4 + src/custom/vehcustmzr.cpp | 2 + src/interface/ipage.h | 2 +- src/pages/player.cpp | 103 +++++---- 6 files changed, 543 insertions(+), 40 deletions(-) create mode 100644 build/test.cpp create mode 100644 build/test.h diff --git a/build/test.cpp b/build/test.cpp new file mode 100644 index 0000000..c974a41 --- /dev/null +++ b/build/test.cpp @@ -0,0 +1,447 @@ +#include "pch.h" +#include "test.h" +//#include +//#include +//#include "pages/menu.h" +//#include "pages/teleport.h" +//#include "utils/widget.h" +//#include "utils/util.h" +//#include "custom/filehandler.h" +//#include "custom/vehcustmzr.h" +//#include "custom/autodrive.h" +//#include + +/* + This file has been created by kelson8, thanks to Grinch for the GPLV3 license to mess around with the code. + If you like my work, please check out the original author and the page for this code from the link below: + I have been using this project to learn more C++. + https://github.com/user-grinch/Cheat-Menu +*/ + +#ifdef GTASA +#include "CExplosion.h" +// New +#include "C3dMarker.h" +#include "C3dMarkers.h" +#include "CWorld.h" + +// Vehicle +#include "CCarAI.h" +#include "CCarCtrl.h" +#include "CCarEnterExit.h" + +//Misc +#include "CCheat.h" + +#endif + +#define _TEST +// I wonder how to get this test menu to show up. +// This breaks the menu. +#ifdef _TEST + +#include +#include +#include "pages/vehicle.h" +#include "utils/widget.h" +#include "utils/util.h" +#include "pages/ped.h" + +// Well I had this working but then broke it 6-14-2024 @ 3:51PM... +// I fixed it 3:53PM. + +TestPage& testPage = TestPage::Get(); +TestPage::TestPage() + : IPage(ePageID::Test, "Window.TestPage", true) { + +} + +//void TestPage::VehicleTest() { +// // These are neat, the BY_GAME defines seem to have everything in this order: SA, VC, 3. +// // This is under defines.h +// CVehicle* pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); +// int hVeh = CPools::GetVehicleRef(pVeh); +// +// // If the player is in a vehicle. +// if (pVeh) +// { +// +// } +// +// // There is a lot of these on the sanny builder website. +// // +// // Car, TireId (int) +// // https://library.sannybuilder.com/#/sa/default/04FE +// //Command(hVeh, 1); +// +// // Get car speed +// // https://library.sannybuilder.com/#/sa/default/02E3 +// // +// // Car +// //Command(hVeh); +// +// // Lock car doors +// // https://library.sannybuilder.com/#/sa/default/020A +// // Will this work? +// //Command(hVeh); +// +// // Explode +// // https://library.sannybuilder.com/#/sa/default/020B +// // +// //Command(hVeh); +// +// +//} + +//void TestPage::PlayerTest() { +// CPlayerPed* player = FindPlayerPed(); +// int hplayer = CPools::GetPedRef(player); +// bool isInAir = Command(hplayer); +//} + + +void PlayerTestFeatures() +{ + CPlayerPed* player = FindPlayerPed(); + int hplayer = CPools::GetPedRef(player); + CVehicle* pVeh = nullptr; + CVector pos = player->GetPosition(); +} + + +void TestPage::Draw() +{ + CPlayerPed* player = FindPlayerPed(); + //ImGui::BeginChild("Test"); + if (ImGui::BeginTabBar("Test", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) + { + if (ImGui::BeginTabItem(TEXT("Test.TestVehicle"))) + { + ImGui::Text("Vehicle Tab"); + //static int selected = Locale::GetCurrentLocaleIndex(); + //static std::vector& vec = Locale::GetLocaleList(); + + ImGui::Text("Hello from KCNet"); + if (ImGui::Button("Blow up Car")) + { +#ifdef GTASA + //CPlayerPed* player = FindPlayerPed(); + int hplayer = CPools::GetPedRef(player); + CVehicle* pVeh = nullptr; + + // This actually does work. + bool bInVehicle = Command(hplayer); + if (bInVehicle) + { + CVehicle* pVeh = player->m_pVehicle; + int hVeh = CPools::GetVehicleRef(pVeh); + Command(hVeh); + } +#endif + } + + if (ImGui::Button("Close doors")) + { +#ifdef GTASA + + int hplayer = CPools::GetPedRef(player); + CVehicle* pVeh = nullptr; + + bool bInVehicle = Command(hplayer); + if (bInVehicle) + { + CVehicle* pVeh = player->m_pVehicle; + int hVeh = CPools::GetVehicleRef(pVeh); + Command(hVeh); + } +#endif + } + + // This works for locking the car doors. + if (ImGui::Button("Lock doors")) + { +#ifdef GTASA + + int hplayer = CPools::GetPedRef(player); + CVehicle* pVeh = nullptr; + + bool bInVehicle = Command(hplayer); + if (bInVehicle) + { + CVehicle* pVeh = player->m_pVehicle; + int hVeh = CPools::GetVehicleRef(pVeh); + bool isCarLocked = Command(hVeh); + //bool isCarLocked = player->m_pVehicle->m_eDoorLock; + + // https://library.sannybuilder.com/#/sa/default/020A + // https://library.sannybuilder.com/#/sa/enums/CarLock + if (!isCarLocked) + { + // 2 - Locked + Command(hVeh, 2); + Util::SetMessage("Car has been locked!"); + } + else + { + // 1 - Unlocked + Command(hVeh, 1); + Util::SetMessage("Car has been unlocked!"); + } + } + else + { + // I wonder how to get the last vehicle the player was in to unlock it. + } +#endif + } + //} + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem(TEXT("Test.TestFeatures"))) + { + if (ImGui::Button("Suicide")) + { + //CPlayerPed* player = FindPlayerPed(); + int hplayer = CPools::GetPedRef(player); + Command(hplayer); + } + + if (ImGui::Button("Bomb")) { + CPlayerPed* player = FindPlayerPed(); + int hplayer = CPools::GetPedRef(player); + + CVector playerPos = player->GetPosition(); + + // https://library.sannybuilder.com/#/sa/default/020C + // x, y, z, EXPLOSION_CAR + Command(playerPos.x, playerPos.y, playerPos.z, EXPLOSION_CAR); + } + + if (ImGui::Button("Show coords")) + { + CVector playerCoords = player->GetPosition(); + //std::string text = std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " + std::to_string(pos.z); + //int playerX = playerCoords.x; + //int playerY = playerCoords.y; + //int playerZ = playerCoords.z; + + std::string playerX = std::to_string(playerCoords.x); + std::string playerY = std::to_string(playerCoords.y); + std::string playerZ = std::to_string(playerCoords.z); + + + + // This works for showing just the X coord, I cannot concatenate these values though + //Util::SetMessage(playerXChar); + // Taken idea from freecam_sa.cpp on line 156 + // This works!! + // 6-14-2024 @ 2:34PM + Util::SetMessage(std::format("X: {} Y: {} Z: {}", playerX, playerY, playerZ).c_str()); + //Util::SetMessage("X: " + playerXChar + " Y: " + playerYChar + " Z: " + playerZChar); + } + + //if (ImGui::Button("Show Marker Coords")) + //{ + + // if (Command()) + // { + // // Check if the target marker blip exists and print the coords if so, looks like this function is only available in cleo. + // // GET_TARGET_BLIP_COORDS + // //if() + // } + // //Command(playerPos.x, playerPos.y, playerPos.z, EXPLOSION_CAR); + + //} + + if (ImGui::Button("Blow up all cars")) { +#ifdef GTASA + CCheat::BlowUpCarsCheat(); + Util::SetMessage("All cars have been exterminated!"); +#else + Util::SetMessage("Only works for SA!"); +#endif + } + + //if (ImGui::Button("Spawn ped to attack vehicle")) + //{ + // Util::SetMessage("Not setup!"); + //} + + /* + if (ImGui::CollapsingHeader("Spawner")) + { + // PedPage::AddNewPed + // This doesn't work yet. +//#define _DISABLED_CODE +#ifdef _DISABLED_CODE + static char name[8]; + static int model = 0; + ImGui::InputTextWithHint(TEXT("Menu.Name"), "PEDNAME", name, 7); + Widget::InputInt(TEXT("Ped.Model"), &model, 0, 999999); + ImGui::Spacing(); + ImVec2 sz = Widget::CalcSize(2); + if (ImGui::Button(TEXT("Ped.AddPed"), sz)) + { + Command(model); + Command(); + if (Command(model)) + { + std::string key = std::format("Custom.{} (Added)", name); + // This part doesn't want to work. + //m_PedData.m_pData->Set(key.c_str(), std::to_string(model)); + pedPage.m_PedData.m_pData->Set(key.c_str(), std::to_string(model)); + pedPage.m_PedData.m_pData->Save(); + // + Util::SetMessage(TEXT("Ped.AddPedMSG")); + Command(model); + } + else + { + Util::SetMessage(TEXT("Vehicle.InvalidID")); + } + } + ImGui::SameLine(); + if (ImGui::Button(TEXT("Ped.GetPlayerModel"), sz)) + { + model = FindPlayerPed()->m_nModelIndex; + } +#endif //_DISABLED_CODE + // + + // https://library.sannybuilder.com/#/sa/default/0672 + //Command(pPed); + + } //End + //ImGui::EndChild(); + + * + } + + + // This seems to work for printing text, idea came from imgui_demo.cpp line 5819 + static char text[64] = "text"; + static int bufTest[2]; + + if(ImGui::InputText("Test", text, IM_ARRAYSIZE(text))) + + // Not sure how to get this to work + //if (ImGui::InputInt("Clock", bufTest, IM_ARRAYSIZE(bufTest))) + { + //CClock::ms_nGameClockHours = hours; + //CClock::SetGameClock(hours) + } + + if (ImGui::Button("Print Text")) + { + Util::SetMessage(text); + } + + ImGui::Text("Test Items"); + //CWorld:: + ImGui::EndTabItem(); + ImGui::EndTabItem(); + */ + } + + //ImGui::EndChild(); + + ImGui::EndTabBar(); + } + +} + + + +// This doesn't do anything yet, I would like to add a custom tab to the Cheat menu +#endif //_TEST + + +#ifdef _DISABLED_CODE +// These weren't needed, leaving here for future reference. +// ////////////// +// https://www.geeksforgeeks.org/convert-string-char-array-cpp/ +//const char* playerXChar = playerX.c_str(); +//const char* playerYChar = playerY.c_str(); +//const char* playerZChar = playerZ.c_str(); +//const char* playerXTest = static_cast(char_array); + +//https://www.tutorialspoint.com/How-to-convert-an-std-string-to-const-char-or-char-in-Cplusplus +//const char* test = new char[playerCoords.x]; +// + +//https://cplusplus.com/forum/general/268793/ +//const char* s = new[std::strlen(playerXChar) + std::strlen(playerYChar) + 1]; + +//https://stackoverflow.com/questions/347949/how-to-convert-a-stdstring-to-const-char-or-char +// +//const char* playerMessage = std::to_string(playerCoords.x) + ", " + std::to_string(playerCoords.y) + ", " + std::to_string(playerCoords.z); +//const char* playerMessage = std::to_string(playerXChar) + ", " + std::to_string(playerCoords.y) + ", " + std::to_string(playerCoords.z); +//const char* playerMessage(test); + + +//Util::SetMessage("X: " + *playerXChar); +//Util::SetMessage(std::to_string(playerCoords.x)); +//Util::SetMessage(playerMessage); +////////////////// + + + +// Old +/* + if (ImGui::BeginTabBar("Test", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) + { + if (ImGui::BeginTabItem(TEXT("Test.TestVehicle"))) + { + ImGui::Text("Vehicle Tab"); + //static int selected = Locale::GetCurrentLocaleIndex(); + //static std::vector& vec = Locale::GetLocaleList(); + + ImGui::Text("Hello from KCNet"); + //} + ImGui::EndTabItem(); + } + + if (ImGui::BeginTabItem(TEXT("Test.TestFeatures"))) + { + ImGui::Text("Test Features"); + // ImGui::Text("Test Features"); + // //if (ImGui::BeginChild("CommandsChild")) + // //{ + // // ImGui::Text("Hello from KCNet"); + // // // + // // //if (ImGui::CollapsingHeader(TEXT("Menu.QuickVehSpawnerCMD"))) + // // //{ + // // // ImGui::Spacing(); + // // // ImGui::TextWrapped(TEXT("Menu.QuickVehSpawnerCMDText")); + // // // ImGui::Spacing(); + // // // ImGui::Separator(); + // // //} + // // //if (ImGui::CollapsingHeader(TEXT("Menu.QuickWepSpawnerCMD"))) + // // //{ + // // // ImGui::Spacing(); + // // // ImGui::TextWrapped(TEXT("Menu.QuickWepSpawnerCMDText")); + // // // ImGui::Spacing(); + // // // ImGui::Separator(); + //} + // // // + + + ImGui::EndChild(); + ImGui::EndTabItem(); + ImGui::EndTabBar(); + } + + */ + //} + + +// Get config data +/* +Events::initGameEvent += [this]() + { + }; + +*/ + +#endif //_DISABLED_CODE \ No newline at end of file diff --git a/build/test.h b/build/test.h new file mode 100644 index 0000000..704b602 --- /dev/null +++ b/build/test.h @@ -0,0 +1,25 @@ +#pragma once +//#include "pch.h" +#include "interface/ipage.h" + +class TestPage : public IPage +{ +public: + //bool m_test; + +// This is just going to be a blank toggle. +//#ifdef GTASA +// bool m_saToggle; +//#endif + + TestPage(); + TestPage(const TestPage&); + void Draw(); + void VehicleTest(); + void PlayerTest(); + +}; + +extern TestPage& testPage; + +// This doesn't do anything yet, I would like to add a custom tab to the Cheat menu \ No newline at end of file diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index f123808..000b2c6 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -9,6 +9,10 @@ #include "pages/teleport.h" #include "pages/menu.h" +// 6-14-2024 @ 11:34AM - kelson8 +// I setup this for building the asi: +// https://stackoverflow.com/questions/1776060/how-to-make-visual-studio-copy-a-dll-file-to-the-output-directory + static bool DrawTitleBar() { bool hovered, held; diff --git a/src/custom/vehcustmzr.cpp b/src/custom/vehcustmzr.cpp index 62168a0..37d59ca 100644 --- a/src/custom/vehcustmzr.cpp +++ b/src/custom/vehcustmzr.cpp @@ -102,6 +102,8 @@ bool VehCustmzrMgr::IsSideskirtComponent(unsigned int compID) void VehCustmzrMgr::ApplyCustomizations(std::string& cat, std::string& key, std::string& val) { + // These are neat, the BY_GAME defines seem to have everything in this order: SA, VC, 3. + // This is under defines.h CVehicle *pVeh = BY_GAME(FindPlayerVehicle(-1, false), FindPlayerVehicle(), FindPlayerVehicle()); if (pVeh) { diff --git a/src/interface/ipage.h b/src/interface/ipage.h index e8d3432..27e10a7 100644 --- a/src/interface/ipage.h +++ b/src/interface/ipage.h @@ -15,7 +15,7 @@ enum class ePageID Menu, // Added by kelson8 - //Test, + Test, // Pages without headers Anniversary, diff --git a/src/pages/player.cpp b/src/pages/player.cpp index 608740c..062b1fd 100644 --- a/src/pages/player.cpp +++ b/src/pages/player.cpp @@ -789,23 +789,46 @@ void PlayerPage::Draw() ImGui::Spacing(); ImGui::Separator(); + } + // Why doesn't the below menu show up? + // Oops I had this setup under the watned level menu, no wonder it didn't show up. #ifdef CUSTOM_CODE - if (ImGui::CollapsingHeader(TEXT("Player.TestFeatures"))) { - if (ImGui::Button(TEXT("Player.Explosion"), Widget::CalcSize(3))) { - //CExplosion* explosion = new CExplosion(); - //CPlayerPed playerPed = FindPlayerPed(); - CVector playerCoords = FindPlayerCoors(-1); - - CExplosion::AddExplosion(FindPlayerPed(), FindPlayerPed(), EXPLOSION_CAR, playerCoords, 1000, true, 1.0f, true); - } - } + if (ImGui::CollapsingHeader(TEXT("Player.TestFeatures"))) { +#ifdef GTASA + if (ImGui::Button(TEXT("Player.Explosion"), Widget::CalcSize(3))) { + //CExplosion* explosion = new CExplosion(); + //CPlayerPed playerPed = FindPlayerPed(); + CVector playerCoords = FindPlayerCoors(-1); + CExplosion::AddExplosion(FindPlayerPed(), FindPlayerPed(), EXPLOSION_CAR, playerCoords, 1000, true, 1.0f, true); + } ImGui::Spacing(); ImGui::Separator(); -#endif //CUSTOM_CODE +#endif //GTASA + ImGui::Text("Flying: "); + if (ImGui::Button(TEXT("Player.IsFlying"))) + { + // I've never used these much in C++ + // Ternary operators: https://cplusplus.com/forum/articles/14631/ + bool isFlying = Command(hplayer); + // Will this work? + //std::string flyingCheck = isFlying ? "Yes" : "No"; + // This doesn't show up properly + const char* flyingCheck = isFlying ? "Yes" : "No"; + + Util::SetMessage("In a flying vehicle: " + *flyingCheck); + + ImGui::Spacing(); + ImGui::Separator(); + + } } + ImGui::Spacing(); + ImGui::Separator(); +#endif //CUSTOM_CODE + ImGui::EndChild(); ImGui::EndTabItem(); } @@ -885,43 +908,45 @@ void PlayerPage::Draw() #endif ImGui::EndTabBar(); - - } - #ifdef CUSTOM_CODE - - ImGui::Spacing(); - if (ImGui::BeginTabBar("TestTab", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { - if (ImGui::BeginTabItem(TEXT("TestTab.TestTab"))) { - ImGui::Text("Hello from KCNet"); + ImGui::Spacing(); + if (ImGui::BeginTabBar("TestTab", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { + if (ImGui::BeginTabItem(TEXT("TestTab.TestingTab"))) { - ImGui::Spacing(); - ImGui::Separator(); + ImGui::Text("Hello from KCNet"); - // I never did get this working yet. - if (ImGui::CollapsingHeader(TEXT("Player.TestFeatures"))) { - if (ImGui::Button(TEXT("Player.Explosion"), Widget::CalcSize(3))) { - //CExplosion* explosion = new CExplosion(); - //CPlayerPed playerPed = FindPlayerPed(); - - // This somewhat works but has no sound - CVector testCoords = CVector(2494.666016, -1672.507080, 13.335972); - // From teleport.cpp - // Couldn't get this working properly. - CPlayerPed* pPlayer = FindPlayerPed(); + ImGui::Spacing(); + ImGui::Separator(); - CVector playerCoords = pPlayer->GetPosition(); - // + // I never did get this working yet. + if (ImGui::CollapsingHeader(TEXT("Player.TestFeatures"))) { +#ifdef GTASA + if (ImGui::Button(TEXT("Player.Explosion"), Widget::CalcSize(3))) { + //CExplosion* explosion = new CExplosion(); + //CPlayerPed playerPed = FindPlayerPed(); - CExplosion::AddExplosion(FindPlayerPed(), FindPlayerPed(), EXPLOSION_CAR, testCoords, 1000, true, 1.0f, true); + // This somewhat works but has no sound + CVector testCoords = CVector(2494.666016, -1672.507080, 13.335972); + // From teleport.cpp + // Couldn't get this working properly. + CPlayerPed* pPlayer = FindPlayerPed(); + + CVector playerCoords = pPlayer->GetPosition(); + // + + //CExplosion::AddExplosion(FindPlayerPed(), FindPlayerPed(), EXPLOSION_CAR, testCoords, 1000, true, 1.0f, true); + CExplosion::AddExplosion(NULL, NULL, EXPLOSION_CAR, testCoords, 1000, true, 1.0f, true); + } +#endif //GTASA } + + ImGui::EndTabItem(); + } - - ImGui::EndTabItem(); - + ImGui::EndTabBar(); } - ImGui::EndTabBar(); - } #endif //CUSTOM_CODE + } + }