2020-12-02 16:19:16 -05:00
|
|
|
#include "pch.h"
|
2021-09-20 08:41:40 -04:00
|
|
|
#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
|
2021-01-09 15:06:53 -05:00
|
|
|
// FlA
|
2021-06-18 12:49:11 -04:00
|
|
|
tRadarTrace* CRadar::ms_RadarTrace = reinterpret_cast<tRadarTrace*>(patch::GetPointer(0x5838B0 + 2));
|
2021-01-09 15:06:53 -05:00
|
|
|
|
2020-12-09 08:15:50 -05:00
|
|
|
void Teleport::FetchRadarSpriteData()
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
2020-12-09 08:15:50 -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)
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2020-12-09 08:15:50 -05:00
|
|
|
return;
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
2020-12-09 08:15:50 -05:00
|
|
|
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->m_Data.erase("Radar");
|
2020-12-09 08:15:50 -05:00
|
|
|
|
|
|
|
// 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)
|
2020-12-09 08:15:50 -05:00
|
|
|
{
|
|
|
|
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>();
|
2020-12-09 08:15:50 -05:00
|
|
|
std::string key_name = sprite_name + ", " + Util::GetLocationName(&pos);
|
|
|
|
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.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);
|
2020-12-09 08:15:50 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
"Radar" : {
|
|
|
|
"key_name" : "0, x, y, z",
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2021-08-01 21:41:48 -04:00
|
|
|
#endif
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2020-12-09 08:15:50 -05:00
|
|
|
Teleport::Teleport()
|
|
|
|
{
|
2021-09-20 08:41:40 -04:00
|
|
|
m_bQuickTeleport = gConfig.GetValue("quick_teleport", false);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
Events::processScriptsEvent += []
|
|
|
|
{
|
2021-06-19 09:00:13 -04:00
|
|
|
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);
|
2021-06-19 09:00:13 -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, &player_entity) + 1.0f;
|
2021-10-21 19:07:30 -04:00
|
|
|
#else // GTA3 & 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-10-21 19:07:30 -04:00
|
|
|
if (pVeh && BY_GAME(player->m_nPedFlags.bInVehicle, player->m_pVehicle, player->m_pVehicle))
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2021-08-01 21:41:48 -04:00
|
|
|
BY_GAME(pVeh->Teleport(m_Teleport::m_fPos, false), pVeh->Teleport(m_Teleport::m_fPos));
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
2020-12-02 16:19:16 -05:00
|
|
|
else
|
2021-08-12 23:28:19 -04:00
|
|
|
{
|
2021-08-01 21:41:48 -04:00
|
|
|
BY_GAME(player->Teleport(m_Teleport::m_fPos, false), player->Teleport(m_Teleport::m_fPos));
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2021-06-19 09:00:13 -04: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
|
|
|
{
|
2021-09-20 08:41:40 -04:00
|
|
|
if (quickTeleport.Pressed()
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-08-12 23:28:19 -04:00
|
|
|
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;
|
|
|
|
|
2021-06-19 09:00:13 -04:00
|
|
|
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-10-21 19:07:30 -04:00
|
|
|
#ifdef GTA3
|
|
|
|
CStreaming::LoadScene(pos);
|
|
|
|
#else
|
2021-02-21 18:09:28 -05:00
|
|
|
CStreaming::LoadScene(&pos);
|
|
|
|
CStreaming::LoadSceneCollision(&pos);
|
2021-10-21 19:07:30 -04:00
|
|
|
#endif
|
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
|
|
|
|
2020-12-24 14:31:26 -05: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-10-21 19:07:30 -04:00
|
|
|
#else // GTA3 & GTAVC
|
2021-08-01 21:41:48 -04:00
|
|
|
if (pVeh && pPlayer->m_pVehicle)
|
|
|
|
{
|
2021-10-21 19:07:30 -04:00
|
|
|
#ifndef GTA3
|
|
|
|
BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior, NULL) = interior_id;
|
|
|
|
#endif
|
2021-08-01 21:41:48 -04:00
|
|
|
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-10-21 19:07:30 -04:00
|
|
|
#ifndef GTA3
|
|
|
|
BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior, NULL) = interior_id;
|
|
|
|
#endif
|
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
|
|
|
|
{
|
2021-08-12 23:28:19 -04:00
|
|
|
int dimension = 0;
|
2020-12-02 16:19:16 -05:00
|
|
|
CVector pos;
|
2021-08-12 23:28:19 -04:00
|
|
|
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")
|
|
|
|
{
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->m_Data["Custom"].erase(key);
|
2021-08-01 21:41:48 -04:00
|
|
|
SetHelpMessage("Location removed", false, false, false);
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->WriteToDisk();
|
2021-08-12 23:28:19 -04:00
|
|
|
}
|
|
|
|
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,
|
2021-09-20 08:41:40 -04:00
|
|
|
std::string(std::string("Teleport to the location of your radar\ntarget blip using ")
|
|
|
|
+ quickTeleport.GetNameString()).c_str()))
|
2020-12-21 15:24:07 -05:00
|
|
|
{
|
2021-09-20 08:41:40 -04:00
|
|
|
gConfig.SetValue("quick_teleport", m_bQuickTeleport);
|
2020-12-21 15:24:07 -05:00
|
|
|
}
|
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
|
|
|
{
|
2021-09-16 09:35:02 -04:00
|
|
|
CVector pos{0, 0, 10};
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
try
|
|
|
|
{
|
2021-08-12 23:28:19 -04:00
|
|
|
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
|
2020-12-09 08:15:50 -05:00
|
|
|
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-09-18 14:42:22 -04:00
|
|
|
Ui::DrawJSON(m_tpData, 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()))
|
|
|
|
{
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->m_Data["Custom"][m_nLocationBuffer] = ("0, " + std::string(m_nInputBuffer));
|
2020-12-21 15:24:07 -05:00
|
|
|
|
2021-08-14 20:36:11 -04:00
|
|
|
#ifdef GTASA
|
2020-12-21 15:24:07 -05:00
|
|
|
// Clear the Radar coordinates
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->m_Data.erase("Radar");
|
|
|
|
m_tpData.m_pJson->m_Data["Radar"] = {};
|
2021-08-14 20:36:11 -04:00
|
|
|
#endif
|
2020-12-21 15:24:07 -05:00
|
|
|
|
2021-09-18 14:42:22 -04:00
|
|
|
m_tpData.m_pJson->WriteToDisk();
|
2020-12-02 16:19:16 -05:00
|
|
|
}
|
|
|
|
ImGui::EndTabItem();
|
|
|
|
}
|
|
|
|
ImGui::EndTabBar();
|
|
|
|
}
|
2021-06-18 12:49:11 -04:00
|
|
|
}
|