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")))
{
static std::string channels[] = {
"Playback FM", "KRose", "KDST", "Bounce FM", "SFUR", "Radio Los Santos", "Radio X",
"CSR ", "KJah West", "Master Sounds", "WCTR", "User Tracks", "None"
};
static const char* channels =
"Playback FM\0KRose\0KDST\0Bounce FM\0SFUR\0Radio Los Santos\0Radio X\0CSR\0KJah West\0"
"Master Sounds\0WCTR\0User Tracks\0None\0";
int channelIndex = 0;
Command<Commands::GET_RADIO_CHANNEL>(&channelIndex);
if (ImGui::ArrowButton("Left", ImGuiDir_Left))
int curStation = Command<Commands::GET_RADIO_CHANNEL>();
if (ImGui::Combo(TEXT("Game.CurrentStation"), &curStation, channels))
{
if (channelIndex == 0)
{
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);
Command<Commands::SET_RADIO_CHANNEL>(curStation);
}
ImGui::Spacing();
ImGui::Separator();

View File

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

View File

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

View File

@ -1,6 +1,13 @@
#pragma once
#include "pch.h"
enum class eTeleportType
{
Marker,
MapPosition,
Coordinate,
};
class Teleport
{
private:
@ -37,6 +44,7 @@ public:
static inline bool m_bQuickTeleport;
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();
};