Skip to content

Commit

Permalink
Server Messages (#153)
Browse files Browse the repository at this point in the history
* initial

* Sigs for Serializer and Receiver

* Optimize SendNetInfoToLobby Hook

* Remove Fixed Comment

* use rdr-classes

* last minute change
  • Loading branch information
Rxann authored Jun 25, 2024
1 parent a1bb94a commit 8025d4f
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmake/rdr-classes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include(FetchContent)
FetchContent_Declare(
rdr_classes
GIT_REPOSITORY https://github.com/YimMenu/RDR-Classes.git
GIT_TAG 79b0389bcfc7a616290ec3ec97ce4fa6a574d0ed
GIT_TAG 70091e27d2e0e515f0e34cb1983ab965421dab0e
GIT_PROGRESS TRUE
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
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 @@ -42,6 +42,8 @@ namespace YimMenu
BaseHook::Add<Hooks::Protections::ResetSyncNodes>(new DetourHook("ResetSyncNodes", Pointers.ResetSyncNodes, Hooks::Protections::ResetSyncNodes));
BaseHook::Add<Hooks::Protections::HandleScriptedGameEvent>(new DetourHook("HandleScriptedGameEvent", Pointers.HandleScriptedGameEvent, Hooks::Protections::HandleScriptedGameEvent));
BaseHook::Add<Hooks::Protections::AddObjectToCreationQueue>(new DetourHook("AddObjectToCreationQueue", Pointers.AddObjectToCreationQueue, Hooks::Protections::AddObjectToCreationQueue));
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::Voice::EnumerateAudioDevices>(new DetourHook("EnumerateAudioDevices", Pointers.EnumerateAudioDevices, Hooks::Voice::EnumerateAudioDevices));
BaseHook::Add<Hooks::Voice::DirectSoundCaptureCreate>(new DetourHook("DirectSoundCaptureCreate", Pointers.DirectSoundCaptureCreate, Hooks::Voice::DirectSoundCaptureCreate));
Expand Down
1 change: 0 additions & 1 deletion src/game/frontend/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ namespace YimMenu
UIManager::AddSubmenu(std::make_shared<Submenus::Players>());
UIManager::AddSubmenu(std::make_shared<Submenus::World>());
UIManager::AddSubmenu(std::make_shared<Submenus::Settings>());
// Wierd glitch causes menu to crash when clicking debug
UIManager::AddSubmenu(std::make_shared<Submenus::Debug>());

Renderer::AddRendererCallBack(
Expand Down
1 change: 1 addition & 0 deletions src/game/frontend/submenus/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ namespace YimMenu::Submenus
debug->AddItem(std::make_shared<BoolCommandItem>("logevents"_J));
debug->AddItem(std::make_shared<BoolCommandItem>("logtses"_J));
debug->AddItem(std::make_shared<BoolCommandItem>("logmetrics"_J));
debug->AddItem(std::make_shared<BoolCommandItem>("logservermessages"_J));
AddCategory(std::move(debug));
}
}
1 change: 1 addition & 0 deletions src/game/frontend/submenus/Self.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace YimMenu::Submenus
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("autotp"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("superjump"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("superpunch"_J));
globalsGroup->AddItem(std::make_shared<BoolCommandItem>("unlimiteditems"_J));


toolsGroup->AddItem(std::make_shared<CommandItem>("suicide"_J));
Expand Down
5 changes: 5 additions & 0 deletions src/game/hooks/Hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ namespace rage
class netObject;
class netSyncTree;
class rlGamerInfo;
class ServerMsg;
class ServerMsgData;
class ServerRPCSerializer;
}
class CNetGamePlayer;
enum class NetEventType;
Expand Down Expand Up @@ -70,6 +73,8 @@ namespace YimMenu::Hooks
extern void ResetSyncNodes();
extern bool HandleScriptedGameEvent(CScriptedGameEvent* event, CNetGamePlayer* src, CNetGamePlayer* dst);
extern int AddObjectToCreationQueue(void* mgr, eNetObjType objectType, CNetGamePlayer* src, CNetGamePlayer* dst);
extern bool SerializeServerRPC(rage::ServerRPCSerializer* ser, void* a2, const char* message, void* def, void* structure, const char* rpc_guid, void* a7);
extern bool ReceiveServerMessage(void* a1, rage::ServerMsg* a2); // doesn't receive all messages
}

namespace Voice
Expand Down
44 changes: 44 additions & 0 deletions src/game/hooks/Protections/ServerMessages.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "core/commands/BoolCommand.hpp"
#include "core/hooking/DetourHook.hpp"
#include "game/hooks/Hooks.hpp"
#include "util/Joaat.hpp"
#include "util/StrToHex.hpp"

#include <network/netServerMessages.hpp>


namespace YimMenu::Features
{
BoolCommand _UnlimitedItems{"unlimiteditems", "Unlimited Items", "Never run out of items in your inventory!"};
BoolCommand _LogServerMessages{"logservermessages", "Log Server Messages", "Log Server Messages"};
}

namespace YimMenu::Hooks
{
bool Protections::ReceiveServerMessage(void* a1, rage::ServerMsg* a2)
{
if (Features::_LogServerMessages.GetState())
{
LOG(INFO) << __FUNCTION__ << ": " << a2->GetName() << ": "
<< hexStr((unsigned char*)a2->GetMsgData()->data, a2->GetMsgData()->size);
}
return BaseHook::Get<ReceiveServerMessage, DetourHook<decltype(&ReceiveServerMessage)>>()->Original()(a1, a2);
}

bool Protections::SerializeServerRPC(rage::ServerRPCSerializer* ser, void* a2, const char* message, void* def, void* structure, const char* rpc_guid, void* a7)
{
// TODO: remove ret variable and just return original instead of storing it
bool ret = BaseHook::Get<SerializeServerRPC, DetourHook<decltype(&SerializeServerRPC)>>()->Original()(ser, a2, message, def, structure, rpc_guid, a7);
if (Features::_LogServerMessages.GetState())
{
LOG(INFO) << __FUNCTION__ << ": " << message << ": " << hexStr((unsigned char*)ser->GetData(), ser->GetSize());
if (rpc_guid)
LOG(INFO) << "RPC Guid"
" = "
<< rpc_guid;
}
if (Joaat(message) == "UseItems"_J && Features::_UnlimitedItems.GetState())
return false;
return ret;
}
}
4 changes: 1 addition & 3 deletions src/game/hooks/Spoofing/SendNetInfoToLobby.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "core/commands/BoolCommand.hpp"
#include "core/commands/Commands.hpp"
#include "core/hooking/DetourHook.hpp"
#include "game/hooks/Hooks.hpp"
#include "game/rdr/Natives.hpp"
Expand All @@ -12,7 +10,7 @@ namespace YimMenu::Hooks
{
bool Spoofing::SendNetInfoToLobby(rage::rlGamerInfo* local_player, int64_t a2, int64_t a3, DWORD* a4)
{
if (!g_SpoofingStorage.spoofed_name.empty())
if (!g_SpoofingStorage.spoofed_name.empty() && !SCRIPTS::IS_LOADING_SCREEN_VISIBLE())
memcpy(local_player->m_Name, g_SpoofingStorage.spoofed_name.c_str(), sizeof(local_player->m_Name));

return BaseHook::Get<Spoofing::SendNetInfoToLobby, DetourHook<decltype(&Spoofing::SendNetInfoToLobby)>>()->Original()(local_player, a2, a3, a4);
Expand Down
10 changes: 10 additions & 0 deletions src/game/pointers/Pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,16 @@ namespace YimMenu
FwScriptGuidCreateGuid = ptr.Sub(141).As<uint32_t (*)(void*)>();
});

constexpr auto receiveServerMessagePtrn = Pattern<"48 89 5C 24 08 57 48 83 EC 20 48 8B 02 48 8B F9 48 8B CA 48 8B DA FF 50 ?? 48 8B C8">("ReceiveServerMessage");
scanner.Add(receiveServerMessagePtrn, [this](PointerCalculator ptr) {
ReceiveServerMessage = ptr.As<PVOID>();
});

constexpr auto serializeServerRPCPtrn = Pattern<"48 89 5C 24 08 57 48 83 EC 30 48 8B 44 24 70">("SerializeServerRPC");
scanner.Add(serializeServerRPCPtrn, [this](PointerCalculator ptr) {
SerializeServerRPC = ptr.As<PVOID>();
});

if (!scanner.Scan())
{
LOG(FATAL) << "Some patterns could not be found, unloading.";
Expand Down
5 changes: 4 additions & 1 deletion src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once
#include "game/rdr/GraphicsOptions.hpp"
#include "game/rdr/RenderingInfo.hpp"
#include <rage/pools.hpp>

#include <d3d12.h>
#include <dxgi1_4.h>
#include <rage/atArray.hpp>
#include <rage/pools.hpp>
#include <script/scrNativeHandler.hpp>
#include <vulkan/vulkan.h>
#include <windows.h>


class CNetGamePlayer;
class CVehicle;
class CPed;
Expand Down Expand Up @@ -80,6 +81,8 @@ namespace YimMenu
PVOID ResetSyncNodes;
PVOID HandleScriptedGameEvent;
PVOID AddObjectToCreationQueue;
PVOID ReceiveServerMessage;
PVOID SerializeServerRPC;

// Player Stuff
PVOID PlayerHasJoined;
Expand Down
9 changes: 9 additions & 0 deletions src/util/StrToHex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ namespace YimMenu

return ch - 'a' + 10;
}

inline std::string hexStr(unsigned char* data, int len)
{
std::stringstream ss;
ss << std::hex;
for (int i = 0; i < len; ++i)
ss << std::setw(2) << std::setfill('0') << (int)data[i];
return ss.str();
}
}

0 comments on commit 8025d4f

Please sign in to comment.