CheatMenuSA/src/Teleport.cpp

286 lines
7.7 KiB
C++
Raw Normal View History

2020-12-02 16:19:16 -05:00
#include "pch.h"
#include "Teleport.h"
#include "Menu.h"
#include "Ui.h"
#include "Util.h"
2020-12-02 16:19:16 -05:00
2021-08-01 21:41:48 -04:00
#ifdef GTASA
// FlA
2021-06-18 12:49:11 -04:00
tRadarTrace* CRadar::ms_RadarTrace = reinterpret_cast<tRadarTrace*>(patch::GetPointer(0x5838B0 + 2));
void Teleport::FetchRadarSpriteData()
2020-12-02 16:19:16 -05:00
{
uint cur_timer = CTimer::m_snTimeInMilliseconds;
static uint timer = cur_timer;
// Update the radar list each 5 seconds
if (cur_timer - timer < 5000)
{
return;
}
tp_data.m_pJson->m_Data.erase("Radar");
// 175 is the max number of sprites, FLA can increase this limit, might need to update this
2021-06-18 12:49:11 -04:00
for (int i = 0; i != 175; ++i)
{
CVector pos = CRadar::ms_RadarTrace[i].m_vPosition;
uchar sprite = CRadar::ms_RadarTrace[i].m_nBlipSprite;
2021-06-18 12:49:11 -04:00
auto sprite_name = m_SpriteJson.m_Data[std::to_string(sprite)].get<std::string>();
std::string key_name = sprite_name + ", " + Util::GetLocationName(&pos);
tp_data.m_pJson->m_Data["Radar"][key_name] = "0, " + std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " +
2021-06-18 12:49:11 -04:00
std::to_string(pos.z);
/*
"Radar" : {
"key_name" : "0, x, y, z",
}
*/
}
}
2021-08-01 21:41:48 -04:00
#endif
2020-12-02 16:19:16 -05:00
Teleport::Teleport()
{
2021-06-18 12:49:11 -04:00
m_bQuickTeleport = config.GetValue("quick_teleport", false);
2020-12-02 16:19:16 -05:00
Events::processScriptsEvent += []
{
if ((m_Teleport::m_bEnabled == true) && ((CTimer::m_snTimeInMilliseconds - m_Teleport::m_nTimer) > 500))
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
CPlayerPed* player = FindPlayerPed();
2020-12-02 16:19:16 -05:00
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2021-08-06 11:53:18 -04:00
CEntity* player_entity = FindPlayerEntity(-1);
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;
2021-08-14 20:36:11 -04:00
#elif GTAVC
2021-08-01 21:41:48 -04:00
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;
2021-08-14 20:36:11 -04:00
#endif
2021-06-18 12:49:11 -04:00
CVehicle* pVeh = player->m_pVehicle;
2020-12-02 16:19:16 -05:00
2021-08-01 21:41:48 -04:00
if (pVeh && BY_GAME(player->m_nPedFlags.bInVehicle, player->m_pVehicle))
{
2021-08-01 21:41:48 -04:00
BY_GAME(pVeh->Teleport(m_Teleport::m_fPos, false), pVeh->Teleport(m_Teleport::m_fPos));
}
2020-12-02 16:19:16 -05:00
else
{
2021-08-01 21:41:48 -04:00
BY_GAME(player->Teleport(m_Teleport::m_fPos, false), player->Teleport(m_Teleport::m_fPos));
}
2020-12-02 16:19:16 -05:00
m_Teleport::m_bEnabled = false;
2020-12-02 16:19:16 -05:00
Command<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(CPools::GetPedRef(player), false);
2021-02-15 03:49:01 -05:00
Command<Commands::RESTORE_CAMERA_JUMPCUT>();
2021-06-18 12:49:11 -04:00
TheCamera.Fade(0, 1);
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
if (m_bQuickTeleport)
2020-12-02 16:19:16 -05:00
{
if (Ui::HotKeyPressed(Menu::m_HotKeys::quickTeleport)
2021-06-18 12:49:11 -04:00
&& ((CTimer::m_snTimeInMilliseconds - m_nQuickTeleportTimer) > 500))
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
m_nQuickTeleportTimer = CTimer::m_snTimeInMilliseconds;
2020-12-02 16:19:16 -05:00
TeleportPlayer(true);
}
}
};
}
void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
CPlayerPed* pPlayer = FindPlayerPed();
CVehicle* pVeh = pPlayer->m_pVehicle;
2021-08-01 21:41:48 -04:00
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
if (get_marker)
{
2021-06-18 12:49:11 -04:00
tRadarTrace targetBlip = CRadar::ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)];
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
if (targetBlip.m_nBlipSprite != RADAR_SPRITE_WAYPOINT)
2020-12-02 16:19:16 -05:00
{
2021-08-01 21:41:48 -04:00
SetHelpMessage("Target blip not found. You need to place it on the map first.", false, false, false);
2020-12-02 16:19:16 -05:00
return;
}
2021-06-18 12:49:11 -04:00
CEntity* pPlayerEntity = FindPlayerEntity(-1);
pos = targetBlip.m_vPosition;
pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &pPlayerEntity) + 50.f;
m_Teleport::m_fPos = pos;
m_Teleport::m_nTimer = CTimer::m_snTimeInMilliseconds;
m_Teleport::m_bEnabled = true;
2021-06-18 12:49:11 -04:00
TheCamera.Fade(0, 0);
Command<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(CPools::GetPedRef(pPlayer), true);
2020-12-02 16:19:16 -05:00
}
2021-08-14 20:36:11 -04:00
#endif
2020-12-02 16:19:16 -05:00
2021-02-21 18:09:28 -05:00
CStreaming::LoadScene(&pos);
CStreaming::LoadSceneCollision(&pos);
2020-12-02 16:19:16 -05:00
CStreaming::LoadAllRequestedModels(false);
2021-06-18 12:49:11 -04:00
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2021-06-18 12:49:11 -04:00
if (pVeh && pPlayer->m_nPedFlags.bInVehicle)
2020-12-02 16:19:16 -05:00
{
2021-02-21 18:09:28 -05:00
pVeh->Teleport(pos, false);
2021-08-01 21:41:48 -04:00
if (pVeh->m_nVehicleClass == VEHICLE_BIKE)
reinterpret_cast<CBike*>(pVeh)->PlaceOnRoadProperly();
else if (pVeh->m_nVehicleClass != VEHICLE_BOAT)
reinterpret_cast<CAutomobile*>(pVeh)->PlaceOnRoadProperly();
2021-06-18 12:49:11 -04:00
2021-08-01 21:41:48 -04:00
BY_GAME(pVeh->m_nAreaCode, pVeh->m_nInterior) = interior_id;
2020-12-02 16:19:16 -05:00
}
else
2021-07-22 18:35:20 -04:00
{
2021-06-18 12:49:11 -04:00
pPlayer->Teleport(pos, false);
2021-07-22 18:35:20 -04:00
}
2021-08-14 20:36:11 -04:00
#elif GTAVC
2021-08-01 21:41:48 -04:00
if (pVeh && pPlayer->m_pVehicle)
{
BY_GAME(pVeh->m_nAreaCode, pVeh->m_nInterior) = interior_id;
pVeh->Teleport(pos);
}
else
{
pPlayer->Teleport(pos);
}
2021-08-14 20:36:11 -04:00
#endif
2020-12-25 12:44:41 -05:00
2021-08-01 21:41:48 -04:00
BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior) = interior_id;
2020-12-02 16:19:16 -05:00
Command<Commands::SET_AREA_VISIBLE>(interior_id);
}
2021-06-18 12:49:11 -04:00
void Teleport::TeleportToLocation(std::string& rootkey, std::string& bLocName, std::string& loc)
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
try
{
int dimension = 0;
2020-12-02 16:19:16 -05:00
CVector pos;
sscanf(loc.c_str(), "%d,%f,%f,%f", &dimension, &pos.x, &pos.y, &pos.z);
TeleportPlayer(false, pos, dimension);
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
catch (...)
{
2021-08-01 21:41:48 -04:00
SetHelpMessage("Invalid location", false, false, false);
2020-12-02 16:19:16 -05:00
}
}
void Teleport::RemoveTeleportEntry(std::string& category, std::string& key, std::string& val)
{
if (category == "Custom")
{
tp_data.m_pJson->m_Data["Custom"].erase(key);
2021-08-01 21:41:48 -04:00
SetHelpMessage("Location removed", false, false, false);
tp_data.m_pJson->WriteToDisk();
}
else
{
SetHelpMessage("You can only remove custom location", false, false, false);
2020-12-02 16:19:16 -05:00
}
}
2021-02-24 16:54:45 -05:00
void Teleport::Draw()
2020-12-02 16:19:16 -05:00
{
2021-06-18 12:49:11 -04:00
if (ImGui::BeginTabBar("Teleport", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll))
2020-12-02 16:19:16 -05:00
{
ImGui::Spacing();
if (ImGui::BeginTabItem("Teleport"))
{
ImGui::Spacing();
if (ImGui::BeginChild("Teleport Child"))
{
2021-06-18 12:49:11 -04:00
ImGui::Columns(2, nullptr, false);
ImGui::Checkbox("Insert coordinates", &m_bInsertCoord);
2020-12-02 16:19:16 -05:00
ImGui::NextColumn();
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2021-06-18 12:49:11 -04:00
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()))
{
2021-06-18 12:49:11 -04:00
config.SetValue("quick_teleport", m_bQuickTeleport);
}
2021-08-14 20:36:11 -04:00
#endif
2020-12-02 16:19:16 -05:00
ImGui::Columns(1);
ImGui::Spacing();
2021-06-18 12:49:11 -04:00
if (m_bInsertCoord)
2020-12-02 16:19:16 -05:00
{
CVector pos = FindPlayerPed()->GetPosition();
2021-06-18 12:49:11 -04:00
strcpy(m_nInputBuffer,
(std::to_string(static_cast<int>(pos.x)) + ", " + std::to_string(static_cast<int>(pos.y)) +
", " + std::to_string(static_cast<int>(pos.z))).c_str());
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
ImGui::InputTextWithHint("Coordinates", "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer));
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
2021-06-18 12:49:11 -04:00
2021-08-01 21:41:48 -04:00
if (ImGui::Button("Teleport to coord", Ui::GetSize(2)))
2020-12-02 16:19:16 -05:00
{
CVector pos;
2020-12-02 16:19:16 -05:00
2021-06-18 12:49:11 -04:00
try
{
sscanf(m_nInputBuffer,"%f,%f,%f", &pos.x, &pos.y, &pos.z);
pos.z += 1.0f;
2021-06-18 12:49:11 -04:00
TeleportPlayer(false, pos);
2020-12-02 16:19:16 -05:00
}
2021-06-18 12:49:11 -04:00
catch (...)
{
2021-08-01 21:41:48 -04:00
SetHelpMessage("Invalid coordinate", false, false, false);
2020-12-02 16:19:16 -05:00
}
}
ImGui::SameLine();
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2020-12-02 16:19:16 -05:00
if (ImGui::Button("Teleport to marker", Ui::GetSize(2)))
2021-08-01 21:41:48 -04:00
{
2021-06-18 12:49:11 -04:00
TeleportPlayer(true);
2021-08-01 21:41:48 -04:00
}
2021-08-14 20:36:11 -04:00
#else
2021-08-01 21:41:48 -04:00
if (ImGui::Button("Teleport to map center", Ui::GetSize(2)))
{
TeleportPlayer(false, CVector(0, 0, 23));
}
2021-08-14 20:36:11 -04:00
#endif
2020-12-02 16:19:16 -05:00
ImGui::EndChild();
}
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Search"))
{
2021-08-14 20:36:11 -04:00
#ifdef GTASA
FetchRadarSpriteData();
2021-08-14 20:36:11 -04:00
#endif
2021-08-01 21:41:48 -04:00
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
2021-08-07 12:01:44 -04:00
Ui::DrawJSON(tp_data, TeleportToLocation,RemoveTeleportEntry);
2020-12-02 16:19:16 -05:00
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Custom"))
{
ImGui::Spacing();
2021-06-18 12:49:11 -04:00
ImGui::InputTextWithHint("Location", "Groove Street", m_nLocationBuffer, IM_ARRAYSIZE(m_nInputBuffer));
ImGui::InputTextWithHint("Coordinates", "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer));
2020-12-02 16:19:16 -05:00
ImGui::Spacing();
if (ImGui::Button("Add location", Ui::GetSize()))
{
tp_data.m_pJson->m_Data["Custom"][m_nLocationBuffer] = ("0, " + std::string(m_nInputBuffer));
2021-08-14 20:36:11 -04:00
#ifdef GTASA
// Clear the Radar coordinates
tp_data.m_pJson->m_Data.erase("Radar");
tp_data.m_pJson->m_Data["Radar"] = {};
2021-08-14 20:36:11 -04:00
#endif
tp_data.m_pJson->WriteToDisk();
2020-12-02 16:19:16 -05:00
}
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
2021-06-18 12:49:11 -04:00
}