From 1606869430dee33492af103a43a802a8ff777348 Mon Sep 17 00:00:00 2001 From: Grinch_ Date: Sun, 13 Feb 2022 11:29:58 +0600 Subject: [PATCH] Add translation support to teleport tab, Fix a game crash when teleporting from inside a train/tram --- resource/common/locale/English.json | 36 ++++++++++++- src/cheatmenu.cpp | 17 ++++++ src/cheatmenu.h | 17 +----- src/locale.h | 5 ++ src/pch.h | 4 +- src/teleport.cpp | 82 +++++++++++++++++++---------- 6 files changed, 114 insertions(+), 47 deletions(-) diff --git a/resource/common/locale/English.json b/resource/common/locale/English.json index 6dac159..3c83b17 100644 --- a/resource/common/locale/English.json +++ b/resource/common/locale/English.json @@ -1,7 +1,41 @@ { "Main" : { - "TranslatorName" : "Grinch_" + "TranslatorName" : "Grinch_", + "TranslationLanguage" : "English", + "TranslationLanguageDisclaimer" : "Translated to English by Grinch_" + }, + "Teleport" : + { + "TargetBlipText" : "Target blip not found. You need to place it on the map first", + "InvalidLocation" : "Invalid location", + "LocationRemoved" : "Location removed", + "CustomLocationRemoveOnly" : "You can only remove custom location", + "InsertCoord" : "Insert coordinates", + "QuickTeleport" : "Quick teleport", + "QuickTeleportHint" : "Teleport to the location of your radar\ntarget blip using ", + "Coordinates" : "Coordinates", + "TeleportToCoord" : "Teleport to coordinates", + "InvalidCoord" : "Invalid coordinates", + "TeleportMarker" : "Teleport to marker", + "TeleportCenter" : "Teleport to center", + "Location" : "Location", + "LocationHint" : "Groove Street", + "AddLocation" : "Add location" + }, + "Window" : + { + "TeleportPage" : "Teleport", + "PlayerPage" : "Player", + "PedPage" : "Ped", + "VehiclePage" : "Vehicle", + "WeaponPage" : "Weapon", + "AnimationPage" : "Animation", + "GamePage" : "Game", + "VisualPage" : "Visual", + "MenuPage" : "Menu", + "Search" : "Search", + "AddNew" : "Add new" }, "Menu" : { diff --git a/src/cheatmenu.cpp b/src/cheatmenu.cpp index 5300a0c..d823ef5 100644 --- a/src/cheatmenu.cpp +++ b/src/cheatmenu.cpp @@ -180,6 +180,23 @@ CheatMenu::CheatMenu() srand(CTimer::m_snTimeInMilliseconds); Locale::Init("CheatMenu/locale/"); + + CheatMenu::m_headerList = + { + {TEXT_S("Window.TeleportPage"), &Teleport::ShowPage, eMenuPages::TELEPORT}, + {TEXT_S("Window.PlayerPage"), &Player::ShowPage, eMenuPages::PLAYER}, + {TEXT_S("Window.PedPage"), &Ped::ShowPage, eMenuPages::PED}, + {TEXT_S("Window.AnimationPage"), &Animation::ShowPage, eMenuPages::ANIMATION}, + {TEXT_S("Window.VehiclePage"), &Vehicle::ShowPage, eMenuPages::VEHICLE}, + {TEXT_S("Window.WeaponPage"), &Weapon::ShowPage, eMenuPages::WEAPON}, + {TEXT_S("Window.GamePage"), &Game::ShowPage, eMenuPages::GAME}, + {TEXT_S("Window.VisualPage"), &Visual::ShowPage, eMenuPages::VISUAL}, + {TEXT_S("Window.MenuPage"), &Menu::ShowPage, eMenuPages::MENU}, + {"Welcome", &ShowWelcomePage, eMenuPages::WELCOME, true}, + {"Update", &ShowUpdatePage, eMenuPages::UPDATE, true}, + {"Anniversary", &ShowAnniversaryPage, eMenuPages::ANNIVERSARY, true} + }; + Events::processScriptsEvent += []() { if (!BY_GAME(FrontEndMenuManager.m_bMenuActive, FrontendMenuManager.m_bMenuVisible, FrontEndMenuManager.m_bMenuActive)) diff --git a/src/cheatmenu.h b/src/cheatmenu.h index f281633..46efa00 100644 --- a/src/cheatmenu.h +++ b/src/cheatmenu.h @@ -38,6 +38,7 @@ private: static inline bool m_bShowMenu = false; static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2); static inline bool m_bSizeChangedExternal = false; + static inline std::vector m_headerList; static void ApplyStyle(); static void DrawWindow(); @@ -46,22 +47,6 @@ private: static void ShowWelcomePage(); static void ProcessPages(); - static inline std::vector m_headerList - { - {"Teleport", &Teleport::ShowPage, eMenuPages::TELEPORT}, - {"Player", &Player::ShowPage, eMenuPages::PLAYER}, - {"Ped", &Ped::ShowPage, eMenuPages::PED}, - {"Animation", &Animation::ShowPage, eMenuPages::ANIMATION}, - {"Vehicle", &Vehicle::ShowPage, eMenuPages::VEHICLE}, - {"Weapon", &Weapon::ShowPage, eMenuPages::WEAPON}, - {"Game", &Game::ShowPage, eMenuPages::GAME}, - {"Visual", &Visual::ShowPage, eMenuPages::VISUAL}, - {"Menu", &Menu::ShowPage, eMenuPages::MENU}, - {"Welcome", &ShowWelcomePage, eMenuPages::WELCOME, true}, - {"Update", &ShowUpdatePage, eMenuPages::UPDATE, true}, - {"Anniversary", &ShowAnniversaryPage, eMenuPages::ANNIVERSARY, true} - }; - public: CheatMenu(); ~CheatMenu(); diff --git a/src/locale.h b/src/locale.h index bc2a9fe..36c9323 100644 --- a/src/locale.h +++ b/src/locale.h @@ -55,6 +55,11 @@ public: return defaultValue; } +#ifdef _GTA_ + // Wanted to do this in the macro TEXT/ TEXT_S + // But VS Code complains about it so.. + defaultValue += "##" + key; +#endif return m_pJson->GetValueStr(key, defaultValue); } diff --git a/src/pch.h b/src/pch.h index f723a8a..4310265 100644 --- a/src/pch.h +++ b/src/pch.h @@ -76,8 +76,8 @@ #include "fontmgr.h" #include "locale.h" -#define TEXT(x) Locale::GetText(x, "Unknown##"x).c_str() -#define TEXT_S(x) Locale::GetText(x,"Unknown##"x).c_str() +#define TEXT(x) Locale::GetText(x, "Unknown").c_str() +#define TEXT_S(x) Locale::GetText(x,"Unknown") using namespace plugin; diff --git a/src/teleport.cpp b/src/teleport.cpp index 061a3ab..073d9fb 100644 --- a/src/teleport.cpp +++ b/src/teleport.cpp @@ -99,7 +99,7 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id) if (targetBlip.m_nBlipSprite != RADAR_SPRITE_WAYPOINT) { - SetHelpMessage("Target blip not found. You need to place it on the map first.", false, false, false); + SetHelpMessage(TEXT("Teleport.TargetBlipText")); return; } CEntity* pPlayerEntity = FindPlayerEntity(-1); @@ -123,16 +123,42 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id) CStreaming::LoadAllRequestedModels(false); #ifdef GTASA + + if (CModelInfo::IsTrainModel(pVeh->m_nModelIndex)) + { + + } + if (pVeh && pPlayer->m_nPedFlags.bInVehicle) { - pVeh->Teleport(pos, false); - if (pVeh->m_nVehicleClass == VEHICLE_BIKE) - reinterpret_cast(pVeh)->PlaceOnRoadProperly(); - else if (pVeh->m_nVehicleClass != VEHICLE_BOAT) - reinterpret_cast(pVeh)->PlaceOnRoadProperly(); + if (CModelInfo::IsTrainModel(pVeh->m_nModelIndex)) + { + CVector vehPos = pVeh->GetPosition(); + Command(CPools::GetPedRef(pPlayer), vehPos.x, vehPos.y, vehPos.z + 2.0f); - BY_GAME(pVeh->m_nAreaCode, pVeh->m_nInterior, NULL) = interior_id; + if (DistanceBetweenPoints(pos, vehPos) > 100.0f) + { + Command(); + } + + pPlayer->Teleport(pos, false); + } + else + { + pVeh->Teleport(pos, false); + + if (pVeh->m_nVehicleClass == VEHICLE_BIKE) + { + reinterpret_cast(pVeh)->PlaceOnRoadProperly(); + } + else if (pVeh->m_nVehicleClass != VEHICLE_BOAT) + { + reinterpret_cast(pVeh)->PlaceOnRoadProperly(); + } + + pVeh->m_nAreaCode = interior_id; + } } else { @@ -141,8 +167,8 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id) #else if (pVeh && pPlayer->m_pVehicle) { -#ifndef GTA3 - BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior, NULL) = interior_id; +#ifdef GTAVC + pPlayer->m_nInterior = interior_id; #endif pVeh->Teleport(pos); } @@ -152,7 +178,7 @@ void Teleport::TeleportPlayer(bool get_marker, CVector pos, int interior_id) } #endif -#ifndef GTA3 +#if defined GTASA || defined GTAVC BY_GAME(pPlayer->m_nAreaCode, pPlayer->m_nInterior, NULL) = interior_id; Command(interior_id); #endif @@ -169,7 +195,7 @@ void Teleport::TeleportToLocation(std::string& rootkey, std::string& bLocName, s } catch (...) { - SetHelpMessage("Invalid location", false, false, false); + SetHelpMessage(TEXT("Teleport.InvalidLocation")); } } @@ -178,12 +204,12 @@ void Teleport::RemoveTeleportEntry(std::string& category, std::string& key, std: if (category == "Custom") { m_tpData.m_pJson->m_Data["Custom"].erase(key); - SetHelpMessage("Location removed", false, false, false); + SetHelpMessage(TEXT("Teleport.LocationRemoved")); m_tpData.m_pJson->WriteToDisk(); } else { - SetHelpMessage("You can only remove custom location", false, false, false); + SetHelpMessage(TEXT("Teleport.CustomLocationRemoveOnly")); } } @@ -192,18 +218,18 @@ void Teleport::ShowPage() if (ImGui::BeginTabBar("Teleport", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll)) { ImGui::Spacing(); - if (ImGui::BeginTabItem("Teleport")) + if (ImGui::BeginTabItem(TEXT("Window.TeleportPage"))) { ImGui::Spacing(); if (ImGui::BeginChild("Teleport Child")) { ImGui::Columns(2, nullptr, false); - ImGui::Checkbox("Insert coordinates", &m_bInsertCoord); + ImGui::Checkbox(TEXT("Teleport.InsertCoord"), &m_bInsertCoord); ImGui::NextColumn(); #ifdef GTASA - if (Ui::CheckboxWithHint("Quick teleport", &m_bQuickTeleport, - std::string(std::string("Teleport to the location of your radar\ntarget blip using ") - + quickTeleport.GetNameString()).c_str())) + if (Ui::CheckboxWithHint(TEXT("Teleport.QuickTeleport"), &m_bQuickTeleport, + std::string(TEXT_S("Teleport.QuickTeleportHint") + + quickTeleport.GetNameString()).c_str())) { gConfig.SetValue("quick_teleport", m_bQuickTeleport); } @@ -220,11 +246,11 @@ void Teleport::ShowPage() ", " + std::to_string(static_cast(pos.z))).c_str()); } - ImGui::InputTextWithHint("Coordinates", "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer)); + ImGui::InputTextWithHint(TEXT("Teleport.Coordinates"), "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer)); ImGui::Spacing(); - if (ImGui::Button("Teleport to coord", Ui::GetSize(2))) + if (ImGui::Button(TEXT("Teleport.TeleportToCoord"), Ui::GetSize(2))) { CVector pos{0, 0, 10}; @@ -236,17 +262,17 @@ void Teleport::ShowPage() } catch (...) { - SetHelpMessage("Invalid coordinate", false, false, false); + SetHelpMessage(TEXT("Teleport.InvalidCoord")); } } ImGui::SameLine(); #ifdef GTASA - if (ImGui::Button("Teleport to marker", Ui::GetSize(2))) + if (ImGui::Button(TEXT("Teleport.TeleportMarker"), Ui::GetSize(2))) { TeleportPlayer(true); } #else - if (ImGui::Button("Teleport to map center", Ui::GetSize(2))) + if (ImGui::Button(TEXT("Teleport.TeleportCenter"), Ui::GetSize(2))) { TeleportPlayer(false, CVector(0, 0, 23)); } @@ -256,19 +282,19 @@ void Teleport::ShowPage() ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("Search")) + if (ImGui::BeginTabItem(TEXT("Window.Search"))) { #ifdef GTASA FetchRadarSpriteData(); #endif ImGui::Spacing(); - if (ImGui::CollapsingHeader("Add new")) + if (ImGui::CollapsingHeader(TEXT("Window.AddNew"))) { ImGui::Spacing(); - ImGui::InputTextWithHint("Location", "Groove Street", m_nLocationBuffer, IM_ARRAYSIZE(m_nInputBuffer)); - ImGui::InputTextWithHint("Coordinates", "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer)); + ImGui::InputTextWithHint(TEXT("Teleport.Location"), TEXT("Teleport.LocationHint"), m_nLocationBuffer, IM_ARRAYSIZE(m_nInputBuffer)); + ImGui::InputTextWithHint(TEXT("Teleport.Coordinates"), "x, y, z", m_nInputBuffer, IM_ARRAYSIZE(m_nInputBuffer)); ImGui::Spacing(); - if (ImGui::Button("Add location", Ui::GetSize())) + if (ImGui::Button(TEXT("Teleport.AddLocation"), Ui::GetSize())) { m_tpData.m_pJson->m_Data["Custom"][m_nLocationBuffer] = ("0, " + std::string(m_nInputBuffer));