Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix status command and add UID to status output #189

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions NorthstarDedicatedTest/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,95 @@ bool CClientState_ProcessPrint_Hook(__int64 thisptr, __int64 msg)
return true;
}


typedef double(__fastcall* GetTimeConnectedType)(__int64 thisptr);
GetTimeConnectedType GetTimeConnected;

typedef char*(__fastcall* GetAddressType)(__int64 thisptr);
GetAddressType GetAddress;

const char* COM_FormatSeconds(int seconds)
{
static char string[64];

int hours = 0;
int minutes = seconds / 60;

if (minutes > 0)
{
seconds -= (minutes * 60);
hours = minutes / 60;

if (hours > 0)
{
minutes -= (hours * 60);
}
}

if (hours > 0)
{
snprintf(string, sizeof(string), "%2i:%02i:%02i", hours, minutes, seconds);
}
else
{
snprintf(string, sizeof(string), "%02i:%02i", minutes, seconds);
}

return string;
}

void __fastcall Host_Status_PrintClient_Hook(__int64 client, char addresses, void (*print)(const char*, ...))
{
__int64 nci;
int state;
const char* active;
int rate;
int loss;
int ping;
__int64 playerUid;
const char* connected;
char* address;
DWORD playerSlot;
nci = *(unsigned __int64*)(client + 656);
state = *(DWORD*)(client + 672);

if (state == 8)
{
active = "active";
}
else if (state < 3)
{
active = "connecting";
if (state < 2)
active = "challenging";
}
else
{
active = "spawning";
}
playerUid = *(unsigned __int64*)(client + 185928);
if (nci)
{
playerSlot = *(DWORD*)(client + 16);
rate = *(unsigned int*)(nci + 232);
loss = (int)(float)((*(float*)(6712 * 1 + nci + 500)) * 100.0);
ping = (int)(float)((*(float*)(6712 * 0 + nci + 508)) * 1000.0);
connected = COM_FormatSeconds(GetTimeConnected(nci));
print(
"# %i \"%s\" %lld %s %i %i %s %d", (unsigned int)(playerSlot + 1), client + 22, playerUid, connected, ping, loss, active, rate);
if (addresses)
{
address = GetAddress(nci);
print(" %s", address);
}
}
else
{
print("#%2i \"%s\" %lld %s", (unsigned int)(*(DWORD*)(client + 16) + 1), client + 22, playerUid, active);
}
print("\n");
}

void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
{
HookEnabler hook;
Expand All @@ -423,6 +512,11 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
CClientState_ProcessPrint_Hook,
reinterpret_cast<LPVOID*>(&CClientState_ProcessPrint_Original));

ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15B7F0, Host_Status_PrintClient_Hook, NULL);

GetTimeConnected = (GetTimeConnectedType)((char*)baseAddress + 0x210530);
GetAddress = (GetAddressType)((char*)baseAddress + 0x2101A0);

Cvar_spewlog_enable = new ConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged");
}

Expand Down
7 changes: 6 additions & 1 deletion NorthstarDedicatedTest/serverauthentication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ void CBaseClient__DisconnectHook(void* self, uint32_t unknownButAlways1, const c
typedef bool (*CCommand__TokenizeType)(CCommand& self, const char* pCommandString, cmd_source_t commandSource);
CCommand__TokenizeType CCommand__Tokenize;

// thisptr isn't used
typedef bool (*CGameClient__IsEngineClientCommandType)(__int64 a1, const CCommand& args);
CGameClient__IsEngineClientCommandType CGameClient__IsEngineClientCommand;

char CGameClient__ExecuteStringCommandHook(void* self, uint32_t unknown, const char* pCommandString)
{
if (CVar_sv_quota_stringcmdspersecond->GetInt() != -1)
Expand Down Expand Up @@ -511,7 +515,7 @@ char CGameClient__ExecuteStringCommandHook(void* self, uint32_t unknown, const c
ConCommand* command = g_pCVar->FindCommand(tempCommand.Arg(0));

// if the command doesn't exist pass it on to ExecuteStringCommand for script clientcommands and stuff
if (command && !command->IsFlagSet(FCVAR_CLIENTCMD_CAN_EXECUTE))
if (command && !command->IsFlagSet(FCVAR_CLIENTCMD_CAN_EXECUTE) && !CGameClient__IsEngineClientCommand(NULL, tempCommand))
GeckoEidechse marked this conversation as resolved.
Show resolved Hide resolved
{
// ensure FCVAR_GAMEDLL concommands without FCVAR_CLIENTCMD_CAN_EXECUTE can't be executed by remote clients
if (IsDedicated())
Expand Down Expand Up @@ -700,6 +704,7 @@ void InitialiseServerAuthentication(HMODULE baseAddress)
hook, (char*)baseAddress + 0x117800, &ProcessConnectionlessPacketHook, reinterpret_cast<LPVOID*>(&ProcessConnectionlessPacket));

CCommand__Tokenize = (CCommand__TokenizeType)((char*)baseAddress + 0x418380);
CGameClient__IsEngineClientCommand = (CGameClient__IsEngineClientCommandType)((char*)baseAddress + 0x103590);

uintptr_t ba = (uintptr_t)baseAddress;

Expand Down