Fix crash with quick teleport

This commit is contained in:
Grinch_ 2022-07-30 02:12:34 +06:00
parent 28f21de664
commit 4d4e3b28f6
4 changed files with 39 additions and 61 deletions

View File

@ -705,39 +705,14 @@ void Game::ShowPage()
} }
if (ImGui::CollapsingHeader(TEXT("Game.ChangeRadioStaion"))) if (ImGui::CollapsingHeader(TEXT("Game.ChangeRadioStaion")))
{ {
static std::string channels[] = { static const char* channels =
"Playback FM", "KRose", "KDST", "Bounce FM", "SFUR", "Radio Los Santos", "Radio X", "Playback FM\0KRose\0KDST\0Bounce FM\0SFUR\0Radio Los Santos\0Radio X\0CSR\0KJah West\0"
"CSR ", "KJah West", "Master Sounds", "WCTR", "User Tracks", "None" "Master Sounds\0WCTR\0User Tracks\0None\0";
};
int channelIndex = 0; int curStation = Command<Commands::GET_RADIO_CHANNEL>();
Command<Commands::GET_RADIO_CHANNEL>(&channelIndex); if (ImGui::Combo(TEXT("Game.CurrentStation"), &curStation, channels))
if (ImGui::ArrowButton("Left", ImGuiDir_Left))
{ {
if (channelIndex == 0) Command<Commands::SET_RADIO_CHANNEL>(curStation);
{
channelIndex = 12;
}
else
{
--channelIndex;
}
Command<Commands::SET_RADIO_CHANNEL>(channelIndex);
}
ImGui::SameLine();
ImGui::Text("%s: %s",TEXT("Game.CurrentStation"), channels[channelIndex].c_str());
ImGui::SameLine();
if (ImGui::ArrowButton("Right", ImGuiDir_Right))
{
if (channelIndex == 12)
{
channelIndex = 0;
}
else
{
++channelIndex;
}
Command<Commands::SET_RADIO_CHANNEL>(channelIndex);
} }
ImGui::Spacing(); ImGui::Spacing();
ImGui::Separator(); ImGui::Separator();

View File

@ -278,7 +278,7 @@ void Menu::ProcessCommands()
ss >> temp; ss >> temp;
pos.z = std::stof(temp); pos.z = std::stof(temp);
Teleport::TeleportPlayer(false, pos, 0); Teleport::WarpPlayer(pos);
} }
catch (...) catch (...)
{ {

View File

@ -78,7 +78,7 @@ void Teleport::Init()
if (m_bTeleportMarker && teleportMarker.Pressed()) if (m_bTeleportMarker && teleportMarker.Pressed())
{ {
TeleportPlayer(true); WarpPlayer<eTeleportType::Marker>();
} }
}; };
@ -114,14 +114,7 @@ void Teleport::Init()
pos.y = pos.y / size * 6000; pos.y = pos.y / size * 6000;
pos.y *= -1; pos.y *= -1;
tRadarTrace &target = CRadar::ms_RadarTrace[FrontEndMenuManager.m_nTargetBlipIndex]; WarpPlayer<eTeleportType::MapPosition>(CVector(pos.x, pos.y, 0.0f));
CVector temp = target.m_vecPos;
unsigned char sprite = target.m_nRadarSprite;
target.m_nRadarSprite = RADAR_SPRITE_WAYPOINT;
target.m_vecPos = {pos.x, pos.y, 0.0f};
TeleportPlayer(true);
target.m_vecPos = temp;
target.m_nRadarSprite = sprite;
} }
} }
} }
@ -129,7 +122,8 @@ void Teleport::Init()
#endif #endif
} }
void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id) template<eTeleportType Type>
void Teleport::WarpPlayer(CVector pos, int interiorID)
{ {
CPlayerPed* pPlayer = FindPlayerPed(); CPlayerPed* pPlayer = FindPlayerPed();
CVehicle* pVeh = pPlayer->m_pVehicle; CVehicle* pVeh = pPlayer->m_pVehicle;
@ -137,17 +131,20 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id)
#ifdef GTASA #ifdef GTASA
TPMarker::m_bJetpack = Command<Commands::IS_PLAYER_USING_JETPACK>(0); TPMarker::m_bJetpack = Command<Commands::IS_PLAYER_USING_JETPACK>(0);
if (get_marker) if (Type == eTeleportType::Marker || Type == eTeleportType::MapPosition)
{ {
tRadarTrace targetBlip = CRadar::ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)]; if (Type == eTeleportType::Marker)
if (targetBlip.m_nRadarSprite != RADAR_SPRITE_WAYPOINT)
{ {
SetHelpMessage(TEXT("Teleport.TargetBlipText")); tRadarTrace targetBlip = CRadar::ms_RadarTrace[LOWORD(FrontEndMenuManager.m_nTargetBlipIndex)];
return; if (targetBlip.m_nRadarSprite != RADAR_SPRITE_WAYPOINT)
} {
SetHelpMessage(TEXT("Teleport.TargetBlipText"));
return;
}
pos = targetBlip.m_vecPos;
}
CEntity* pPlayerEntity = FindPlayerEntity(-1); CEntity* pPlayerEntity = FindPlayerEntity(-1);
pos = targetBlip.m_vecPos;
pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &pPlayerEntity) + 500.f; pos.z = CWorld::FindGroundZFor3DCoord(pos.x, pos.y, 1000, nullptr, &pPlayerEntity) + 500.f;
TPMarker::m_fPos = pos; TPMarker::m_fPos = pos;
@ -156,8 +153,6 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id)
TheCamera.Fade(0, 0); TheCamera.Fade(0, 0);
Command<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(CPools::GetPedRef(pPlayer), true); Command<Commands::FREEZE_CHAR_POSITION_AND_DONT_LOAD_COLLISION>(CPools::GetPedRef(pPlayer), true);
} }
#endif #endif
#ifdef GTA3 #ifdef GTA3
@ -198,7 +193,7 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id)
reinterpret_cast<CAutomobile*>(pVeh)->PlaceOnRoadProperly(); reinterpret_cast<CAutomobile*>(pVeh)->PlaceOnRoadProperly();
} }
pVeh->m_nAreaCode = interior_id; pVeh->m_nAreaCode = interiorID;
} }
} }
else else
@ -225,8 +220,8 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id)
#endif #endif
#if defined GTASA || defined GTAVC #if defined GTASA || defined GTAVC
pPlayer->m_nAreaCode = interior_id; pPlayer->m_nAreaCode = interiorID;
Command<Commands::SET_AREA_VISIBLE>(interior_id); Command<Commands::SET_AREA_VISIBLE>(interiorID);
#endif #endif
} }
@ -237,7 +232,7 @@ void Teleport::TeleportToLocation(std::string& rootkey, std::string& bLocName, s
int dimension = 0; int dimension = 0;
CVector pos; CVector pos;
sscanf(loc.c_str(), "%d,%f,%f,%f", &dimension, &pos.x, &pos.y, &pos.z); sscanf(loc.c_str(), "%d,%f,%f,%f", &dimension, &pos.x, &pos.y, &pos.z);
TeleportPlayer(false, pos, dimension); WarpPlayer<eTeleportType::Coordinate>(pos, dimension);
} }
catch (...) catch (...)
{ {
@ -312,7 +307,7 @@ void Teleport::ShowPage()
{ {
sscanf(m_nInputBuffer,"%f,%f,%f", &pos.x, &pos.y, &pos.z); sscanf(m_nInputBuffer,"%f,%f,%f", &pos.x, &pos.y, &pos.z);
pos.z += 1.0f; pos.z += 1.0f;
TeleportPlayer(false, pos); WarpPlayer(pos);
} }
catch (...) catch (...)
{ {
@ -323,12 +318,12 @@ void Teleport::ShowPage()
#ifdef GTASA #ifdef GTASA
if (ImGui::Button((TEXT_S("Teleport.TeleportMarker") + "##Btn").c_str(), Widget::CalcSize(2))) if (ImGui::Button((TEXT_S("Teleport.TeleportMarker") + "##Btn").c_str(), Widget::CalcSize(2)))
{ {
TeleportPlayer(true); WarpPlayer<eTeleportType::Marker>();
} }
#else #else
if (ImGui::Button(TEXT("Teleport.TeleportCenter"), Widget::CalcSize(2))) if (ImGui::Button(TEXT("Teleport.TeleportCenter"), Widget::CalcSize(2)))
{ {
TeleportPlayer(false, CVector(0, 0, 23)); TeleportPlayer(CVector(0, 0, 23), eTeleportType::Coordinate);
} }
#endif #endif
ImGui::EndChild(); ImGui::EndChild();

View File

@ -1,6 +1,13 @@
#pragma once #pragma once
#include "pch.h" #include "pch.h"
enum class eTeleportType
{
Marker,
MapPosition,
Coordinate,
};
class Teleport class Teleport
{ {
private: private:
@ -37,6 +44,7 @@ public:
static inline bool m_bQuickTeleport; static inline bool m_bQuickTeleport;
static void Init(); static void Init();
static void TeleportPlayer(bool get_marker = false, CVector pos = CVector(0, 0, 0), int interior_id = 0); template<eTeleportType Type = eTeleportType::Coordinate>
static void WarpPlayer(CVector pos = CVector(0, 0, 0), int interiorID = 0);
static void ShowPage(); static void ShowPage();
}; };