Update: worked on it today, and i managed to do it.
the following snipet will get the PlayerId(i think its constant over instances) from the AgentId(volatile):
PHP Code:
unsigned long* GetPlayerIdByAgentId(unsigned long ulAgentId)
{
unsigned long pAgent = GetAgentById(ulAgentId);
if (!pAgent)
return NULL;
unsigned long pCharacter = ((unsigned long (__thiscall *)(unsigned long))VIRTUAL_FUNCTION(pAgent, 0x84))(pAgent) - 0x18;
if (!pCharacter)
return NULL;
unsigned long pPlayer = ((unsigned long (__thiscall *)(unsigned long))VIRTUAL_FUNCTION(pCharacter, 0xf4))(pCharacter);
if (!pPlayer)
return NULL;
return ((unsigned long* (__thiscall *)(unsigned long))VIRTUAL_FUNCTION(pPlayer, 0x40))(pPlayer);
}
unsigned long GetAgentById(unsigned long ulAgentId)
{
return ((unsigned long(__fastcall *)(unsigned long))GetAgentById_Address)(ulAgentId);
}
GetAgentById_Address change from build to build, so you would need to add this to your signature engine:
PHP Code:
NEW_SIG_NORMAL(GetAgentById, "56578BF1E8????????8BF83B774473108B473C8B04B085C074068B4004")
after you got the PlayerId you can either use your own STS client,
or use gw2 built in one to query for UserIds, perhaps next week i will work on that.
Update: one last thing i forgot to mention GetAgentById will not work and probably cause crash without some preparations before.
the reason is GetAgentById calls PropGetContext which uses TLS.
the way i made it "multi thread compatible" is like this:
(all my threads are being managed by a class i made and are registered there)
PHP Code:
MyDetour* GetContext_Detour;
unsigned long __cdecl GetContext_Hook()
{
unsigned long ulCallingThreadId = GetCurrentThreadId();
for (std::vector<ThreadManager*>::iterator i = g_pThreadList.begin(); i != g_pThreadList.end(); i++)
{
if (ulCallingThreadId == (*i)->GetThreadId())
{
while (!g_ulContext)
Sleep(10);
return g_ulContext;
}
}
unsigned long ulContext = ((unsigned long (__cdecl *)())GetContext_Detour->GetTrampoline())();
g_ulContext = ulContext;
return ulContext;
}
PHP Code:
NEW_SIG_NORMAL(GetContext, "8B0D????????64A12C0000008B04888B8004000000C3")
i know its not thread safe, but with the current gw2 design there wasn't a need to make it like that.