Skip to content

Commit

Permalink
Replace assign physical index. (#67)
Browse files Browse the repository at this point in the history
Replaces assign physical index with individual hooks since assign physical index will not get called on player leaves.
  • Loading branch information
MarkEcza authored Dec 8, 2023
1 parent 7990cda commit a4145a2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 21 deletions.
4 changes: 3 additions & 1 deletion src/core/hooking/Hooking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ namespace YimMenu
BaseHook::Add<Hooks::Misc::ThrowFatalError>(new DetourHook("ThrowFatalError", Pointers.ThrowFatalError, Hooks::Misc::ThrowFatalError));

BaseHook::Add<Hooks::Info::NetworkRequest>(new DetourHook("NetworkReqeust", Pointers.NetworkRequest, Hooks::Info::NetworkRequest));
BaseHook::Add<Hooks::Info::AssignPhysicalIndex>(new DetourHook("AssignPhysicalIndex", Pointers.AssignPhysicalIndex, Hooks::Info::AssignPhysicalIndex));

BaseHook::Add<Hooks::Info::PlayerHasJoined>(new DetourHook("PlayerHasJoined", Pointers.PlayerHasJoined, Hooks::Info::PlayerHasJoined));
BaseHook::Add<Hooks::Info::PlayerHasLeft>(new DetourHook("PlayerHasLeft", Pointers.PlayerHasLeft, Hooks::Info::PlayerHasLeft));

BaseHook::Add<Hooks::Spoofing::WritePlayerHealthData>(new DetourHook("WritePlayerHealthData", Pointers.WritePlayerHealthData, Hooks::Spoofing::WritePlayerHealthData));
}
Expand Down
4 changes: 3 additions & 1 deletion src/game/hooks/Hooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ namespace YimMenu::Hooks
namespace Info
{
extern uint8_t* NetworkRequest(HttpRequest* Request, uint8_t* a2, uint32_t a3);
extern void AssignPhysicalIndex(void* mgr, CNetGamePlayer* player, uint8_t newIndex);

extern void PlayerHasJoined(CNetGamePlayer* player);
extern void PlayerHasLeft(CNetGamePlayer* player);
}

namespace Spoofing
Expand Down
15 changes: 0 additions & 15 deletions src/game/hooks/Info/AssignPhysicalIndex.cpp

This file was deleted.

22 changes: 22 additions & 0 deletions src/game/hooks/Info/PlayerJoinLeave.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "core/hooking/DetourHook.hpp"
#include "game/hooks/Hooks.hpp"
#include "core/frontend/Notifications.hpp"
#include "game/rdr/Natives.hpp"
#include "network/CNetGamePlayer.hpp"

namespace YimMenu::Hooks
{
void Info::PlayerHasJoined(CNetGamePlayer* player)
{
BaseHook::Get<Info::PlayerHasJoined, DetourHook<decltype(&Info::PlayerHasJoined)>>()->Original()(player);

LOG(INFO) << player->GetName() << " is joining your session.";
}

void Info::PlayerHasLeft(CNetGamePlayer* player)
{
BaseHook::Get<Info::PlayerHasLeft, DetourHook<decltype(&Info::PlayerHasLeft)>>()->Original()(player);

LOG(INFO) << player->GetName() << " has left your session.";
}
}
4 changes: 4 additions & 0 deletions src/game/hooks/Misc/ThrowFatalError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ namespace YimMenu::Hooks
// This is *not* noreturn
void Misc::ThrowFatalError(int code, int fileHash, int fileLine)
{
//Make an exception to log the stack.
int* nullPointer = 0;
*nullPointer = 69;

//Spams the log with no actual information, eventually crashes the game
//LOG(FATAL) << "RECEIVED FATAL ERROR | Code = " << HEX((uint32_t)code) << " | FileHash = " << HEX((uint32_t)fileHash) << " | FileLine = " << (uint32_t)fileLine << " | ReturnAddress = " << HEX((__int64)_ReturnAddress() - (__int64)GetModuleHandle(0));
}
Expand Down
11 changes: 8 additions & 3 deletions src/game/pointers/Pointers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ namespace YimMenu
AddObjectToCreationQueue = ptr.As<PVOID>();
});

constexpr auto assignPhysicalIndexPtrn = Pattern<"48 8B C4 48 89 58 08 48 89 68 10 48 89 70 18 48 89 78 20 41 54 41 56 41 57 48 83 EC 30 41 8A C0">("AssignPhysicalIndex");
scanner.Add(assignPhysicalIndexPtrn, [this](PointerCalculator ptr) {
AssignPhysicalIndex = ptr.As<PVOID>();
constexpr auto playerHasJoinedPtrn = Pattern<"E8 ? ? ? ? 8A 4B 19 48 8B 45 38">("PlayerHasJoined");
scanner.Add(playerHasJoinedPtrn, [this](PointerCalculator ptr) {
PlayerHasJoined = ptr.Add(1).Rip().As<PVOID>();
});

constexpr auto playerHasLeftPtrn = Pattern<"E8 ? ? ? ? 48 8B 0D ? ? ? ? 48 8B 57 08">("PlayerHasLeft");
scanner.Add(playerHasLeftPtrn, [this](PointerCalculator ptr) {
PlayerHasLeft = ptr.Add(1).Rip().As<PVOID>();
});

constexpr auto networkPlayerMgrPtrn = Pattern<"48 89 5C 24 08 57 48 83 EC 30 48 8B ? ? ? ? 01 8A D9 80 F9 20">("NetworkPlayerMgr");
Expand Down
3 changes: 2 additions & 1 deletion src/game/pointers/Pointers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ namespace YimMenu
PVOID AddObjectToCreationQueue;

// Player Stuff
PVOID AssignPhysicalIndex;
PVOID PlayerHasJoined;
PVOID PlayerHasLeft;
Functions::GetNetworkPlayerFromPid GetNetPlayerFromPid;

// Voice
Expand Down

0 comments on commit a4145a2

Please sign in to comment.