CheatMenuSA/src/pages/teleport.cpp

379 lines
13 KiB
C++
Raw Normal View History

2021-10-25 10:03:27 -04:00
#include "pch.h"
2021-09-20 08:41:40 -04:00
#include "teleport.h"
#include "menu.h"
#include "utils/widget.h"
#include "utils/util.h"
2020-12-02 16:19:16 -05:00
2021-08-01 21:41:48 -04:00
#ifdef GTASA
// FLA
tRadarTrace* ms_RadarTrace = reinterpret_cast<tRadarTrace*>(patch::GetPointer(0x5838B0 + 2));
static int maxSprites = *(uint*)0x5D5870;
2022-08-17 21:12:21 -04:00
void TeleportPage::FetchRadarSpriteData()
2020-12-02 16:19:16 -05:00
{
2022-06-16 06:51:22 -04:00
uint timer = CTimer::m_snTimeInMilliseconds;
static uint lastUpdated = timer;
2022-01-07 03:18:00 -05:00
// Update the radar list each 5 seconds
2022-06-16 06:51:22 -04:00
if (timer - lastUpdated < 5000)
2022-01-07 03:18:00 -05:00
{
return;
}
2022-07-17 18:07:30 -04:00
m_locData.m_pData->RemoveTable("Radar");
for (int i = 0; i != maxSprites; ++i)
2022-01-07 03:18:00 -05:00
{
CVector pos = ms_RadarTrace[i].m_vecPos;
std::string sprite = std::to_string(ms_RadarTrace[i].m_nRadarSprite);
2022-06-15 06:45:43 -04:00
std::string keyName = m_SpriteData.Get<std::string>(sprite.c_str(), "Unknown");
keyName += ", " + Util::GetLocationName(&pos);
std::string key = "Radar." + keyName;
2022-07-17 18:07:30 -04:00
m_locData.m_pData->Set(key.c_str(), std::format("0, {}, {}, {}", pos.x, pos.y, pos.z));
2022-01-07 03:18:00 -05:00
}
2022-06-16 06:51:22 -04:00
lastUpdated = timer;
}
2021-08-01 21:41:48 -04:00
#endif
2020-12-02 16:19:16 -05:00
2022-08-17 21:12:21 -04:00
bool TeleportPage::IsQuickTeleportActive()
2022-07-31 21:03:25 -04:00
{
return m_bQuickTeleport;
}
2022-08-17 21:12:21 -04:00
TeleportPage& teleportPage = TeleportPage::Get();
2022-08-17 21:12:21 -04:00
TeleportPage::TeleportPage()
: IPage<TeleportPage>(ePageID::Teleport, "Window.TeleportPage", true)
{
2022-07-06 15:11:53 -04:00
m_bTeleportMarker = gConfig.Get("Features.TeleportMarker", false);
2022-06-16 06:51:22 -04:00
m_bQuickTeleport = gConfig.Get("Features.QuickTeleport", false);
m_fMapSize.x = gConfig.Get("Game.MapSizeX", 6000.0f);
m_fMapSize.y = gConfig.Get("Game.MapSizeY", 6000.0f);
2020-12-02 16:19:16 -05:00
2022-08-17 21:12:21 -04:00
Events::drawingEvent += [this]
2022-01-07 03:18:00 -05:00
{
2022-07-06 15:11:53 -04:00
if (m_bTeleportMarker && teleportMarker.Pressed())
2022-01-07 03:18:00 -05:00
{
2022-07-29 16:12:34 -04:00
WarpPlayer<eTeleportType::Marker>();
2022-07-06 15:11:53 -04:00
}
#ifdef GTASA
if (m_bQuickTeleport && quickTeleport.PressedRealtime())
{
static CSprite2d map;
if (!map.m_pTexture)
{
map.m_pTexture = gTextureList.FindRwTextureByName("map");
2022-07-06 15:11:53 -04:00
}
ImVec2 screenSz = ImVec2(screen::GetScreenWidth(), screen::GetScreenHeight());
float size = screenSz.x * screenSz.y / screenSz.x; // keep aspect ratio
float left = (screenSz.x-size) / 2;
2022-07-06 15:11:53 -04:00
float right = left+size;
map.Draw(CRect(left, 0.0f, right, screenSz.y), CRGBA(255, 255, 255, 200));
// draw sprites on map
static float sz = SCREEN_MULTIPLIER(12.5f);
for (int i = 0; i != maxSprites; ++i)
{
tRadarTrace &trace = ms_RadarTrace[i];
if (trace.m_nRadarSprite != RADAR_SPRITE_NONE)
{
CSprite2d &sprite = CRadar::RadarBlipSprites[LOWORD(trace.m_nRadarSprite)];
ImVec2 pos = ImVec2(trace.m_vecPos.x, trace.m_vecPos.y);
pos = Util::ConvertMapToScreen(pos, m_fMapSize, screenSz);
sprite.Draw(CRect(pos.x-sz, pos.y-sz, pos.x+sz, pos.y+sz), CRGBA(255, 255, 255, 200));
}
}
// create player sprite
CSprite2d &sprite = CRadar::RadarBlipSprites[RADAR_SPRITE_CENTRE];
CPlayerPed *pPlayer = FindPlayerPed();
CVector coord = pPlayer->GetPosition();
ImVec2 pos = Util::ConvertMapToScreen(ImVec2(coord.x, coord.y), m_fMapSize, screenSz);
sprite.Draw(CRect(pos.x-sz, pos.y-sz, pos.x+sz, pos.y+sz), CRGBA(255, 255, 255, 200));
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left))
2022-01-07 03:18:00 -05:00
{
2022-07-06 15:11:53 -04:00
ImVec2 pos = ImGui::GetMousePos();
2022-07-06 22:28:09 -04:00
if (pos.x > left && pos.x < right)
{
pos = Util::ConvertScreenToMap(pos, m_fMapSize, screenSz);
2022-07-29 16:12:34 -04:00
WarpPlayer<eTeleportType::MapPosition>(CVector(pos.x, pos.y, 0.0f));
2022-07-06 22:28:09 -04:00
}
2022-01-07 03:18:00 -05:00
}
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
{
ImVec2 pos = ImGui::GetMousePos();
if (pos.x > left && pos.x < right)
{
pos = Util::ConvertScreenToMap(pos, m_fMapSize, screenSz);
tRadarTrace *trace = &ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)];
trace->m_vecPos = CVector(pos.x, pos.y, 0.0f);
// trace->m_nRadarSprite = RADAR_SPRITE_WAYPOINT;
}
}
2022-01-07 03:18:00 -05:00
}
2022-07-06 15:11:53 -04:00
#endif
2022-07-31 21:03:25 -04:00
};
2020-12-02 16:19:16 -05:00
}
2022-07-31 21:03:25 -04:00
#ifdef GTASA
2022-07-29 16:12:34 -04:00
template<eTeleportType Type>
2022-08-17 21:12:21 -04:00
void TeleportPage::WarpPlayer(CVector pos, int interiorID)
2020-12-02 16:19:16 -05:00
{
2022-01-07 03:18:00 -05:00
CPlayerPed* pPlayer = FindPlayerPed();
CVehicle* pVeh = pPlayer->m_pVehicle;
2022-07-06 16:23:32 -04:00
int hplayer = CPools::GetPedRef(pPlayer);
2022-07-31 21:03:25 -04:00
bool jetpack = Command<Commands::IS_PLAYER_USING_JETPACK>(0);
2022-01-07 03:18:00 -05:00
2022-07-31 21:03:25 -04:00
if (Type == eTeleportType::Marker)
{
tRadarTrace targetBlip = ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)];
2022-07-31 21:03:25 -04:00
if (targetBlip.m_nRadarSprite != RADAR_SPRITE_WAYPOINT)
2022-01-07 03:18:00 -05:00
{
2022-07-31 21:03:25 -04:00
Util::SetMessage(TEXT("Teleport.TargetBlipText"));
return;
}
pos = targetBlip.m_vecPos;
}
2020-12-02 16:19:16 -05:00
2022-01-07 03:18:00 -05:00
CStreaming::LoadScene(&pos);
CStreaming::LoadSceneCollision(&pos);
CStreaming::LoadAllRequestedModels(false);
2021-06-18 12:49:11 -04:00
2022-07-31 21:03:25 -04:00
if (Type == eTeleportType::Marker || Type == eTeleportType::MapPosition)
{
CEntity* pPlayerEntity = FindPlayerEntity(-1);
pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &pPlayerEntity) + 1.0f;
}
2022-01-07 03:18:00 -05:00
if (pVeh && pPlayer->m_nPedFlags.bInVehicle)
{
if (CModelInfo::IsTrainModel(pVeh->m_nModelIndex))
{
CVector vehPos = pVeh->GetPosition();
Command<Commands::WARP_CHAR_FROM_CAR_TO_COORD>(CPools::GetPedRef(pPlayer), vehPos.x, vehPos.y, vehPos.z + 2.0f);
if (DistanceBetweenPoints(pos, vehPos) > 100.0f)
{
Command<Commands::DELETE_ALL_TRAINS>();
}
2022-01-07 03:18:00 -05:00
pPlayer->Teleport(pos, false);
}
else
{
pVeh->Teleport(pos, false);
if (pVeh->m_nVehicleClass == VEHICLE_BIKE)
{
reinterpret_cast<CBike*>(pVeh)->PlaceOnRoadProperly();
}
else if (pVeh->m_nVehicleClass != VEHICLE_BOAT)
{
reinterpret_cast<CAutomobile*>(pVeh)->PlaceOnRoadProperly();
}
2022-07-29 16:12:34 -04:00
pVeh->m_nAreaCode = interiorID;
}
2022-01-07 03:18:00 -05:00
}
else
{
pPlayer->Teleport(pos, false);
}
2022-07-06 16:23:32 -04:00
2022-07-31 21:03:25 -04:00
if (jetpack)
2022-07-06 16:23:32 -04:00
{
Command<Commands::TASK_JETPACK>(hplayer);
}
2022-07-31 21:03:25 -04:00
pPlayer->m_nAreaCode = interiorID;
Command<Commands::SET_AREA_VISIBLE>(interiorID);
}
2022-01-07 03:18:00 -05:00
#else
2022-07-31 21:03:25 -04:00
template<eTeleportType Type>
2022-08-17 21:12:21 -04:00
void TeleportPage::WarpPlayer(CVector pos, int interiorID)
2022-07-31 21:03:25 -04:00
{
CPlayerPed* pPlayer = FindPlayerPed();
CVehicle* pVeh = pPlayer->m_pVehicle;
#ifdef GTAVC
CStreaming::LoadScene(&pos);
CStreaming::LoadSceneCollision(&pos);
#else
CStreaming::LoadScene(pos);
#endif
CStreaming::LoadAllRequestedModels(false);
2022-01-07 03:18:00 -05:00
if (pVeh && pPlayer->m_pVehicle)
{
#ifdef GTAVC
2022-07-31 21:03:25 -04:00
pVeh->m_nAreaCode = interiorID;
2021-10-21 19:07:30 -04:00
#endif
2022-01-07 03:18:00 -05:00
pVeh->Teleport(pos);
}
else
{
pPlayer->Teleport(pos);
}
2020-12-25 12:44:41 -05:00
2022-07-31 21:03:25 -04:00
#ifdef GTAVC
2022-07-29 16:12:34 -04:00
pPlayer->m_nAreaCode = interiorID;
Command<Commands::SET_AREA_VISIBLE>(interiorID);
#endif
2020-12-02 16:19:16 -05:00
}
2022-07-31 21:03:25 -04:00
#endif
2020-12-02 16:19:16 -05:00
2022-08-17 21:12:21 -04:00
void TeleportPage::LocationAddNew()
{
ImGui::InputTextWithHint(TEXT("Teleport.Location"), TEXT("Teleport.LocationHint"), m_LocBuf, INPUT_BUFFER_SIZE);
ImGui::InputTextWithHint(TEXT("Teleport.Coordinates"), "x, y, z", m_InBuf, INPUT_BUFFER_SIZE);
ImGui::Spacing();
if (ImGui::Button(TEXT("Window.AddEntry"), Widget::CalcSize()))
{
std::string key = std::string("Custom.") + m_LocBuf;
m_locData.m_pData->Set(key.c_str(), ("0, " + std::string(m_InBuf)));
#ifdef GTASA
// Clear the Radar coordinates
m_locData.m_pData->RemoveTable("Radar");
#endif
m_locData.m_pData->Save();
Util::SetMessage(TEXT("Window.AddEntryMSG"));
}
}
void TeleportPage::LocationClick(str& unk1, str& unk2, str& loc)
{
int dim = 0;
CVector pos;
if (sscanf(loc.c_str(), "%d,%f,%f,%f", &dim, &pos.x, &pos.y, &pos.z) == 4)
{
WarpPlayer<eTeleportType::Coordinate>(pos, dim);
}
else
{
Util::SetMessage(TEXT("Teleport.InvalidLocation"));
}
}
void TeleportPage::Draw()
2020-12-02 16:19:16 -05:00
{
2022-01-07 03:18:00 -05:00
if (ImGui::BeginTabBar("Teleport", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll))
{
ImGui::Spacing();
if (ImGui::BeginTabItem(TEXT("Window.TeleportPage")))
2022-01-07 03:18:00 -05:00
{
ImGui::Spacing();
if (ImGui::BeginChild("Teleport Child"))
{
2022-07-31 21:03:25 -04:00
#ifdef GTASA
2022-01-07 03:18:00 -05:00
ImGui::Columns(2, nullptr, false);
ImGui::Checkbox(TEXT("Teleport.InsertCoord"), &m_bInsertCoord);
2022-07-31 21:03:25 -04:00
2022-07-01 04:06:34 -04:00
if (Widget::Checkbox(TEXT("Teleport.QuickTeleport"), &m_bQuickTeleport,
std::string(TEXT_S("Teleport.QuickTeleportHint")
+ quickTeleport.GetNameString()).c_str()))
2022-01-07 03:18:00 -05:00
{
2022-06-16 06:51:22 -04:00
gConfig.Set("Features.QuickTeleport", m_bQuickTeleport);
2022-01-07 03:18:00 -05:00
}
2022-07-06 15:11:53 -04:00
ImGui::NextColumn();
if (Widget::Checkbox(TEXT("Teleport.TeleportMarker"), &m_bTeleportMarker,
std::string(TEXT_S("Teleport.TeleportMarkerHint")
+ teleportMarker.GetNameString()).c_str()))
{
gConfig.Set("Features.TeleportMarker", m_bTeleportMarker);
}
2022-01-07 03:18:00 -05:00
ImGui::Columns(1);
2022-07-31 21:03:25 -04:00
#else
ImGui::Spacing();
ImGui::SameLine();
2022-07-31 21:03:25 -04:00
ImGui::Checkbox(TEXT("Teleport.InsertCoord"), &m_bInsertCoord);
#endif
2022-01-07 03:18:00 -05:00
ImGui::Spacing();
if (m_bInsertCoord)
{
CVector pos = FindPlayerPed()->GetPosition();
2022-08-17 21:12:21 -04:00
strcpy(m_InBuf,
2022-01-07 03:18:00 -05:00
(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());
}
2022-08-17 21:12:21 -04:00
ImGui::InputTextWithHint(TEXT("Teleport.Coordinates"), "x, y, z", m_InBuf, INPUT_BUFFER_SIZE);
2022-01-07 03:18:00 -05:00
ImGui::Spacing();
2022-06-29 19:56:53 -04:00
if (ImGui::Button(TEXT("Teleport.TeleportToCoord"), Widget::CalcSize(2)))
2022-01-07 03:18:00 -05:00
{
CVector pos{0, 0, 10};
2022-08-17 21:12:21 -04:00
if (sscanf(m_InBuf,"%f,%f,%f", &pos.x, &pos.y, &pos.z) == 3)
2022-01-07 03:18:00 -05:00
{
pos.z += 1.0f;
2022-07-29 16:12:34 -04:00
WarpPlayer(pos);
2022-01-07 03:18:00 -05:00
}
2022-07-31 21:03:25 -04:00
else
2022-01-07 03:18:00 -05:00
{
Util::SetMessage(TEXT("Teleport.InvalidCoord"));
2022-01-07 03:18:00 -05:00
}
}
ImGui::SameLine();
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2022-07-07 03:32:37 -04:00
if (ImGui::Button((TEXT_S("Teleport.TeleportMarker") + "##Btn").c_str(), Widget::CalcSize(2)))
2022-01-07 03:18:00 -05:00
{
2022-07-29 16:12:34 -04:00
WarpPlayer<eTeleportType::Marker>();
2022-01-07 03:18:00 -05:00
}
2021-08-14 20:36:11 -04:00
#else
2022-06-29 19:56:53 -04:00
if (ImGui::Button(TEXT("Teleport.TeleportCenter"), Widget::CalcSize(2)))
2022-01-07 03:18:00 -05:00
{
WarpPlayer<eTeleportType::Coordinate>(CVector(0, 0, 23));
2022-01-07 03:18:00 -05:00
}
#endif
ImGui::Dummy(ImVec2(0, 20));
if (m_bQuickTeleport)
{
if (ImGui::CollapsingHeader(TEXT("Teleport.CustomMapSize")))
{
ImGui::TextWrapped(TEXT("Teleport.CustomMapSizeHint"));
ImGui::Spacing();
if (Widget::InputFloat(TEXT("Teleport.Width"), &m_fMapSize.x, 1.0f, 0.0f, 9999999))
{
gConfig.Set("Game.MapSizeX", m_fMapSize.x);
}
if (Widget::InputFloat(TEXT("Teleport.Height"), &m_fMapSize.y, 1.0f, 0.0f, 9999999))
{
gConfig.Set("Game.MapSizeY", m_fMapSize.y);
}
ImGui::Spacing();
if (ImGui::Button(TEXT("Game.ResetDefault"), Widget::CalcSize()))
{
m_fMapSize = {6000.0f, 6000.0f};
gConfig.Set("Game.MapSizeX", m_fMapSize.x);
gConfig.Set("Game.MapSizeY", m_fMapSize.y);
}
ImGui::Spacing();
ImGui::Separator();
}
}
2022-01-07 03:18:00 -05:00
ImGui::EndChild();
}
ImGui::EndTabItem();
}
2020-12-02 16:19:16 -05:00
2022-06-29 19:56:53 -04:00
if (ImGui::BeginTabItem(TEXT("Window.LocationsTab")))
2022-01-07 03:18:00 -05:00
{
2021-08-14 20:36:11 -04:00
#ifdef GTASA
2022-01-07 03:18:00 -05:00
FetchRadarSpriteData();
2022-02-07 03:46:55 -05:00
#endif
ImGui::Spacing();
2022-08-17 21:12:21 -04:00
Widget::DataList(m_locData, fArg3Wrapper(teleportPage.LocationClick),
fArgNoneWrapper(teleportPage.LocationAddNew));
2022-01-07 03:18:00 -05:00
ImGui::EndTabItem();
}
ImGui::EndTabBar();
}
2021-06-18 12:49:11 -04:00
}