Skip to content

Commit

Permalink
Remote Teleport, Script Functions, and More (#170)
Browse files Browse the repository at this point in the history
Vehicle Spawner
Chat Clearing
Script Functions
Remote TPs
Various Code Cleanups and Refactors
  • Loading branch information
Rxann authored Jul 22, 2024
1 parent 9062a74 commit 094174a
Show file tree
Hide file tree
Showing 68 changed files with 1,118 additions and 239 deletions.
2 changes: 1 addition & 1 deletion src/core/frontend/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace YimMenu

auto depletionProgress = 1.0f - (timeElapsed / (float)notification.m_Duration);

ImGui::ProgressBar(depletionProgress, ImVec2(-1, 1), "");
ImGui::ProgressBar(depletionProgress, ImVec2(-1, 3.5f), "");

auto style = ImGui::GetStyle();
// TODO: Add icon for type instead of colored text
Expand Down
2 changes: 2 additions & 0 deletions src/core/hooking/Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ namespace YimMenu
BaseHook::Add<Hooks::Protections::SerializeServerRPC>(new DetourHook("SerializeServerRPC", Pointers.SerializeServerRPC, Hooks::Protections::SerializeServerRPC));
BaseHook::Add<Hooks::Protections::ReceiveServerMessage>(new DetourHook("ReceiveServerMessage", Pointers.ReceiveServerMessage, Hooks::Protections::ReceiveServerMessage));
BaseHook::Add<Hooks::Protections::ReceiveArrayUpdate>(new DetourHook("ReceiveArrayUpdate", Pointers.ReceiveArrayUpdate, Hooks::Protections::ReceiveArrayUpdate));

BaseHook::Add<Hooks::Protections::CreatePoolItem>(new DetourHook("CreatePoolItem", Pointers.CreatePoolItem, Hooks::Protections::CreatePoolItem));

BaseHook::Add<Hooks::Voice::EnumerateAudioDevices>(new DetourHook("EnumerateAudioDevices", Pointers.EnumerateAudioDevices, Hooks::Voice::EnumerateAudioDevices));
Expand All @@ -65,6 +66,7 @@ namespace YimMenu

BaseHook::Add<Hooks::Spoofing::WritePlayerHealthData>(new DetourHook("WritePlayerHealthData", Pointers.WritePlayerHealthData, Hooks::Spoofing::WritePlayerHealthData));
BaseHook::Add<Hooks::Spoofing::SendNetInfoToLobby>(new DetourHook("SendNetInfoToLobby", Pointers.SendNetInfoToLobby, Hooks::Spoofing::SendNetInfoToLobby));
BaseHook::Add<Hooks::Spoofing::WriteVPMData>(new DetourHook("WriteVehicleProximityMigrationData", Pointers.WriteVPMData, Hooks::Spoofing::WriteVPMData));

BaseHook::Add<Hooks::Toxic::BroadcastNetArray>(new DetourHook("BroadcastNetArray", Pointers.BroadcastNetArray, Hooks::Toxic::BroadcastNetArray));
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace YimMenu
for (auto& serializer : m_StateSerializers)
LoadComponentImpl(serializer);

LOG(VERBOSE) << "Initial Settings Load Completed";
LOG(VERBOSE) << "All settings loaded";
m_InitialLoadDone = true;
}

Expand Down
1 change: 0 additions & 1 deletion src/game/backend/NativeHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace YimMenu
{
if (scp->m_NameHash == script || script == ALL_SCRIPTS)
{
LOG(VERBOSE) << "Applying native hook on existing script";
program->Apply(Hook(index, hook));
}
}
Expand Down
23 changes: 15 additions & 8 deletions src/game/backend/Players.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,36 @@

namespace YimMenu
{
void Players::TickImpl()
Players::Players()
{
const auto& playerMgr = Pointers.NetworkPlayerMgr;
if (!playerMgr || !g_Running)
if (!playerMgr)
return;

for (uint8_t idx = 0; idx < 32u; idx++)
{
if (const auto& netPlayer = playerMgr->m_PlayerList[idx];
netPlayer && (Pointers.GetNetPlayerFromPid(idx) == netPlayer /*game also does this*/) && netPlayer->IsValid())
netPlayer && (Pointers.GetNetPlayerFromPid(idx) == netPlayer) && netPlayer->IsValid())
{
m_Players[idx] = Player(idx);
if (!m_PlayerDatas.contains(idx))
m_PlayerDatas[idx] = PlayerData();
}
else
{
m_Players.erase(idx);
m_PlayerDatas.erase(idx);
}
}
}

void Players::OnPlayerJoinImpl(CNetGamePlayer* player)
{
m_Players[player->m_PlayerIndex] = Player(player);
m_PlayerDatas[player->m_PlayerIndex] = PlayerData();
}

void Players::OnPlayerLeaveImpl(CNetGamePlayer* player)
{
m_Players.erase(player->m_PlayerIndex);
m_PlayerDatas.erase(player->m_PlayerIndex);
}

Player Players::GetByRIDImpl(uint64_t rid)
{
for (auto& [idx, player] : Players::GetPlayers())
Expand Down
14 changes: 11 additions & 3 deletions src/game/backend/Players.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ namespace YimMenu
Player m_SelectedPlayer = Player((uint8_t)0);

public:
static void Tick()
static void OnPlayerJoin(CNetGamePlayer* player)
{
GetInstance().TickImpl();
GetInstance().OnPlayerJoinImpl(player);
}

static void OnPlayerLeave(CNetGamePlayer* player)
{
GetInstance().OnPlayerLeaveImpl(player);
}

static Player GetSelected()
Expand Down Expand Up @@ -61,13 +66,16 @@ namespace YimMenu
}

private:
Players();

static Players& GetInstance()
{
static Players Instance;
return Instance;
}

void TickImpl();
void OnPlayerJoinImpl(CNetGamePlayer* player);
void OnPlayerLeaveImpl(CNetGamePlayer* player);
Player GetByRIDImpl(uint64_t rid);
Player GetByHostTokenImpl(uint64_t token);
};
Expand Down
7 changes: 4 additions & 3 deletions src/game/backend/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ namespace YimMenu
m_ChildFiber = CreateFiber(
0,
[](void* param) {
auto this_script = static_cast<Script*>(param);
this_script->m_Done = true;
auto this_script = static_cast<Script*>(param);
this_script->m_Callback();
this_script->m_Done = true;
SwitchToFiber(this_script->m_MainFiber);
},
this);
}
Expand All @@ -29,7 +30,7 @@ namespace YimMenu
void Script::Tick()
{
m_MainFiber = GetCurrentFiber();
if (!m_WakeTime.has_value() || m_WakeTime.value() <= std::chrono::high_resolution_clock::now())
if ((!m_WakeTime.has_value() || m_WakeTime.value() <= std::chrono::high_resolution_clock::now()) && !m_Done)
{
SwitchToFiber(m_ChildFiber);
}
Expand Down
67 changes: 33 additions & 34 deletions src/game/features/Features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ namespace YimMenu
}
}

void BlockAllControls()
{
FiberPool::Push([] {
PAD::DISABLE_ALL_CONTROL_ACTIONS(0);
});
}

void TryFirstLoad()
{
if (!Features::_IsFirstLoadComplete.GetState())
Expand All @@ -90,13 +83,12 @@ namespace YimMenu
*Pointers.RageSecurityInitialized = false;
if (g_Running)
{
Players::Tick();
*Pointers.ExplosionBypass = true;
Commands::RunLoopedCommands();
g_HotkeySystem.FeatureCommandsHotkeyLoop();
Self::Update();
ScriptMgr::Yield();
}
ScriptMgr::Yield();
}
}

Expand All @@ -106,31 +98,38 @@ namespace YimMenu
{
if (GUI::IsOpen())
{
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_LOOK_LR, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_LOOK_UD, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_MELEE_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_DRIVE_LOOK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_GUN_LR, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_GUN_UD, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_DRIVE_LOOK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_NEXT_WEAPON, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_PREV_WEAPON, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_ATTACK2, 1);
if (GUI::IsUsingKeyboard())
{
PAD::DISABLE_ALL_CONTROL_ACTIONS(0);
}
else
{
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_LOOK_LR, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_LOOK_UD, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_MELEE_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_DRIVE_LOOK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_GUN_LR, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_HORSE_GUN_UD, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_DRIVE_LOOK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_NEXT_WEAPON, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_PREV_WEAPON, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_CAR_ATTACK2, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_AIM, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_ATTACK, 1);
PAD::DISABLE_CONTROL_ACTION(0, (Hash)NativeInputs::INPUT_VEH_BOAT_ATTACK2, 1);
}
}

ScriptMgr::Yield();
Expand Down
2 changes: 0 additions & 2 deletions src/game/features/Features.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ namespace YimMenu

void FeatureLoop();
void BlockControlsForUI();
void BlockAllControls();
void SpectateTick();
void ContextMenuTick();
void RegisterScriptPatches();
}
23 changes: 23 additions & 0 deletions src/game/features/network/teleport/BringAllPlayers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "core/commands/Command.hpp"
#include "game/backend/Players.hpp"
#include "game/backend/Self.hpp"
#include "game/rdr/Natives.hpp"
#include "util/teleport.hpp"

namespace YimMenu::Features
{
class BringAllPlayers : public Command
{
using Command::Command;

virtual void OnCall() override
{
for (auto& [idx, player] : Players::GetPlayers())
{
Teleport::TeleportPlayerToCoords(player, Self::GetPed().GetPosition());
}
}
};

static BringAllPlayers _BringAllPlayers{"bringall", "Bring", "Teleport all players to you"};
}
31 changes: 31 additions & 0 deletions src/game/features/network/teleport/TpAllToJail.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "core/commands/Command.hpp"
#include "game/backend/Self.hpp"
#include "game/rdr/Natives.hpp"
#include "game/backend/Players.hpp"
#include "util/teleport.hpp"
#include "game/rdr/data/JailTeleports.hpp"

namespace YimMenu::Features
{
class TpAllToJail : public Command
{
using Command::Command;

virtual void OnCall() override
{
for (auto& [idx, player] : Players::GetPlayers())
{
std::srand(static_cast<unsigned int>(std::time(nullptr)));
int randomIndex = std::rand() % Data::g_JailCells.size();

auto it = Data::g_JailCells.begin();
std::advance(it, randomIndex);

rage::fvector3 cell = it->second;
Teleport::TeleportPlayerToCoords(player, cell);
}
}
};

static TpAllToJail _TpAllToJail{"tpalltojail", "Teleport To Jail", "Teleport all players to a random Saint Denis jail cell"};
}
23 changes: 23 additions & 0 deletions src/game/features/network/teleport/TpAllToWaypoint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "core/commands/Command.hpp"
#include "game/backend/Self.hpp"
#include "game/rdr/Natives.hpp"
#include "game/backend/Players.hpp"
#include "util/teleport.hpp"

namespace YimMenu::Features
{
class TpAllToWaypoint : public Command
{
using Command::Command;

virtual void OnCall() override
{
for (auto& [idx, player] : Players::GetPlayers())
{
Teleport::TeleportPlayerToCoords(player, Teleport::GetWaypointCoords());
}
}
};

static TpAllToWaypoint _TpAllToWaypoint{"tpalltowaypoint", "Teleport To Waypoint", "Teleport all players to your active waypoint"};
}
20 changes: 20 additions & 0 deletions src/game/features/players/teleport/BringPlayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "game/backend/Self.hpp"
#include "game/backend/Players.hpp"
#include "game/commands/PlayerCommand.hpp"
#include "game/rdr/Natives.hpp"
#include "util/teleport.hpp"

namespace YimMenu::Features
{
class BringPlayer : public PlayerCommand
{
using PlayerCommand::PlayerCommand;

virtual void OnCall(Player player) override
{
Teleport::TeleportPlayerToCoords(player, Self::GetPed().GetPosition());
}
};

static BringPlayer _BringPlayer{"bring", "Bring Player", "Teleport the player to you"};
}
26 changes: 26 additions & 0 deletions src/game/features/players/teleport/TpBehindPlayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "game/backend/Self.hpp"
#include "game/commands/PlayerCommand.hpp"
#include "game/rdr/Natives.hpp"
#include "game/features/Features.hpp"
#include "util/teleport.hpp"

namespace YimMenu::Features
{
class TpBehindPlayer : public PlayerCommand
{
using PlayerCommand::PlayerCommand;

virtual void OnCall(Player player) override
{
auto pos = player.GetPed().GetPosition();
auto forward = ENTITY::GET_ENTITY_FORWARD_VECTOR(player.GetPed().GetHandle());
float distance = -7.5f;
rage::fvector3 coords{pos.x + (forward.x * distance), pos.y + (forward.y * distance), pos.z + .75f};

if (Teleport::TeleportEntity(Self::GetPed().GetHandle(), {coords.x, coords.y, coords.z}, false))
g_Spectating = false;
}
};

static TpBehindPlayer _TpBehindPlayer{"tpbehindplayer", "Teleport Behind Player", "Teleport behind the player"};
}
Loading

0 comments on commit 094174a

Please sign in to comment.