Skip to content

Commit

Permalink
tweak(net/five): shared method to get net object from entity
Browse files Browse the repository at this point in the history
Should decrease hard-to-read code duplication and ensure consistency.
  • Loading branch information
Disquse committed Oct 7, 2023
1 parent 1e5c861 commit 9bac936
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
26 changes: 15 additions & 11 deletions code/components/gta-net-five/src/CloneExperiments.cpp
Expand Up @@ -437,20 +437,24 @@ static hook::cdecl_stub<void* (CNetGamePlayer*)> getPlayerPedForNetPlayer([]()
});

#ifdef GTA_FIVE
static const uint32_t g_entityNetObjOffset = 208;
static constexpr uint32_t g_entityNetObjOffset = 208;
#elif IS_RDR3
static const uint32_t g_entityNetObjOffset = 224;
static constexpr uint32_t g_entityNetObjOffset = 224;
#endif

rage::netObject* GetNetObjectFromEntity(void* entity)
{
// technically must be at least CDynamicEntity
return *(rage::netObject**)((char*)entity + g_entityNetObjOffset);
}

rage::netObject* GetLocalPlayerPedNetObject()
{
auto ped = getPlayerPedForNetPlayer(GetLocalPlayer());

if (ped)
{
auto netObj = *(rage::netObject**)((char*)ped + g_entityNetObjOffset);

return netObj;
return GetNetObjectFromEntity(ped);
}

return nullptr;
Expand Down Expand Up @@ -489,7 +493,7 @@ void HandleClientDrop(const NetLibraryClientInfo& info)

if (ped)
{
auto netObj = *(rage::netObject**)((char*)ped + g_entityNetObjOffset);
auto netObj = GetNetObjectFromEntity(ped);

if (netObj)
{
Expand Down Expand Up @@ -4702,7 +4706,7 @@ static InitFunction initFunction([]()
return;
}

auto netObj = *(rage::netObject**)(entity + g_entityNetObjOffset);
auto netObj = GetNetObjectFromEntity(entity);

static char blah[90000];

Expand Down Expand Up @@ -4743,7 +4747,7 @@ static InitFunction initFunction([]()
return;
}

auto netObj = *(rage::netObject**)(entity + g_entityNetObjOffset);
auto netObj = GetNetObjectFromEntity(entity);

static char blah[90000];

Expand Down Expand Up @@ -4931,7 +4935,7 @@ static InitFunction initFunction([]()
return;
}

auto obj = *(rage::netObject**)(entity + g_entityNetObjOffset);
auto obj = GetNetObjectFromEntity(entity);

auto data = context.GetArgument<const char*>(1);

Expand Down Expand Up @@ -5003,15 +5007,15 @@ static InitFunction initFunction([]()
return;
}

auto obj = *(rage::netObject**)(entity + g_entityNetObjOffset);
auto obj = GetNetObjectFromEntity(entity);
//obj->GetBlender()->m_30();
obj->GetBlender()->m_58();
});

static ConsoleCommand saveCloneCmd("save_clone", [](const std::string& address)
{
uintptr_t addressPtr = _strtoui64(address.c_str(), nullptr, 16);
auto netObj = *(rage::netObject**)(addressPtr + g_entityNetObjOffset);
auto netObj = GetNetObjectFromEntity((void*)addressPtr);

static char blah[90000];

Expand Down
8 changes: 3 additions & 5 deletions code/components/gta-net-five/src/MumbleVoice.cpp
Expand Up @@ -701,6 +701,8 @@ static bool(*g_origIsPlayerTalking)(void*, void*);

extern CNetGamePlayer* netObject__GetPlayerOwner(rage::netObject* object);

extern rage::netObject* GetNetObjectFromEntity(void* entity);

static bool _isPlayerTalking(void* mgr, char* playerData)
{
if (g_origIsPlayerTalking(mgr, playerData))
Expand Down Expand Up @@ -730,11 +732,7 @@ static bool _isPlayerTalking(void* mgr, char* playerData)

if (ped)
{
#ifdef GTA_FIVE
auto netObj = *(rage::netObject**)(ped + 208);
#elif IS_RDR3
auto netObj = *(rage::netObject**)(ped + 224);
#endif
auto netObj = GetNetObjectFromEntity(ped);

if (netObj)
{
Expand Down

0 comments on commit 9bac936

Please sign in to comment.