1
mirror of https://github.com/R2Northstar/NorthstarLauncher synced 2024-10-30 11:26:40 +01:00

implement svc_Print, copy NS hostname to source cvar

This commit is contained in:
HappyDOGE 2021-12-28 12:18:58 +03:00
parent bea776a8f6
commit e49f026c92
2 changed files with 29 additions and 1 deletions

View File

@ -331,6 +331,21 @@ void Status_ConMsg_Hook(const char* text, ...)
spdlog::info(formatted);
}
typedef bool(*CClientState_ProcessPrint_Type)(__int64 thisptr, __int64 msg);
CClientState_ProcessPrint_Type CClientState_ProcessPrint_Original;
bool CClientState_ProcessPrint_Hook(__int64 thisptr, __int64 msg)
{
char* text = *(char**)(msg + 0x20);
auto endpos = strlen(text);
if (text[endpos - 1] == '\n')
text[endpos - 1] = '\0'; // cut off repeated newline
spdlog::info(text);
return true;
}
void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
{
HookEnabler hook;
@ -339,4 +354,7 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
// Hook print function that status concmd uses to actually print data
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15ABD0, Status_ConMsg_Hook, reinterpret_cast<LPVOID*>(&Status_ConMsg_Original));
// Hook CClientState::ProcessPrint
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1A1530, CClientState_ProcessPrint_Hook, reinterpret_cast<LPVOID*>(&CClientState_ProcessPrint_Original));
}

View File

@ -21,6 +21,9 @@ ConVar* Cvar_ns_server_name;
ConVar* Cvar_ns_server_desc;
ConVar* Cvar_ns_server_password;
// Source ConVar
ConVar* Cvar_hostname;
MasterServerManager* g_MasterServerManager;
typedef void(*CHostState__State_NewGameType)(CHostState* hostState);
@ -127,7 +130,7 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(char* uid, char* or
if (originAuthInfo.HasParseError())
{
spdlog::error("Failed reading origin auth info response: encountered parse error \{}\"", rapidjson::GetParseError_En(originAuthInfo.GetParseError()));
spdlog::error("Failed reading origin auth info response: encountered parse error \"{}\"", rapidjson::GetParseError_En(originAuthInfo.GetParseError()));
goto REQUEST_END_CLEANUP;
}
@ -852,6 +855,10 @@ void CHostState__State_NewGameHook(CHostState* hostState)
if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this
maxPlayers = std::stoi(maxPlayersVar);
// Copy new server name cvar to source
Cvar_hostname->m_pszString = Cvar_ns_server_name->m_pszString;
Cvar_hostname->m_StringLength = Cvar_ns_server_name->m_StringLength;
g_MasterServerManager->AddSelfToServerList(Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString, hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers, Cvar_ns_server_password->m_pszString);
g_ServerAuthenticationManager->StartPlayerAuthServer();
g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false;
@ -898,6 +905,9 @@ void InitialiseSharedMasterServer(HMODULE baseAddress)
Cvar_ns_server_password = RegisterConVar("ns_server_password", "", FCVAR_GAMEDLL, "");
Cvar_ns_report_server_to_masterserver = RegisterConVar("ns_report_server_to_masterserver", "1", FCVAR_GAMEDLL, "");
Cvar_ns_report_sp_server_to_masterserver = RegisterConVar("ns_report_sp_server_to_masterserver", "0", FCVAR_GAMEDLL, "");
Cvar_hostname = *(ConVar**)((char*)baseAddress + 0x1315bae8);
g_MasterServerManager = new MasterServerManager;
RegisterConCommand("ns_fetchservers", ConCommand_ns_fetchservers, "", FCVAR_CLIENTDLL);