r5sdk/r5dev/client/cdll_engine_int.cpp
Amos d5b2e58dae Code base refactor + major performance and readability improvement. Read description for details.
* Codebase restructured to SourceSDK codebase style and .cpp/.h assertion paths in the game executable.
* Document most functions with valve style 'Purpose' blocks.
* Rename variables to match the rest of the codebase and Valve's naming convention.
* Dedicated DLL and the SDKLauncher now share the same codebase as the DevSDK.

* Obtain globals or pointers directly instead of waiting for runtime initialized data.
* Dynamically search for all functions and globals (this doesn't count for dedicated yet!).
* Initialize most in-SDK variables.

* Move certain prints and other utilities under ConVars to reduce verbosity and increase performance.
* Print all pattern scan results through a virtual function to make it easier to add and debug new patterns in the future.
* Type global var pointers appropriately if class or type is known and implemented.
* Forward declare 'CClient' class to avoid having 2 'g_pClient' copies.
* Add IDA's pseudo definitions for easier prototyping with decompiled assembly code.

* RPAK decompress Command callback implementation.
* Load decompressed RPaks from 'paks\Win32\' overriding the ones in 'paks\Win64\' (the decompress callback will automatically fix the header and write it to 'paks\Win32\').

* VPK decompress Command callback implementation.
* Move CRC32 ands Adler32 to implementation files.

* Server will print out more details about the connecting client.

* Upgrade ImGui lib to v1.86.
* Don't compile id3dx.h for dedicated.
* Don't compile id3dx.cpp for dedicated
* Implement DevMsg print function allowing to print information to the in-game VGUI/RUI console overlay, ImGui console overlay and the external windows console

* Fixed bug where the Error function would not properly terminate the process when an error is called. This caused access violations for critical/non-recoverable errors.
* Fixed bug where the game would crash if the console or server browser was enabled while the game was still starting up.
* Several bug fixes for the dedicated server (warning: dedicated is still considered work-in-progress!).
2021-12-25 22:36:38 +01:00

134 lines
3.8 KiB
C++

#include "core/stdafx.h"
/*****************************************************************************/
#include "tier0/basetypes.h"
#include "tier0/IConVar.h"
#include "tier0/cvar.h"
#include "client/IVEngineClient.h"
#include "client/client.h"
#include "client/cdll_engine_int.h"
#include "public/include/bansystem.h"
#include "engine/net_chan.h"
#include "vpc/keyvalues.h"
/*****************************************************************************/
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void __fastcall HFrameStageNotify(CHLClient* rcx, ClientFrameStage_t frameStage)
{
switch (frameStage)
{
case ClientFrameStage_t::FRAME_START: // FrameStageNotify gets called every frame by CEngine::Frame with the stage being FRAME_START. We can use this to check/set global variables.
{
static bool bInitialized = false;
if (!bInitialized)
{
IConVar_ClearHostNames();
ConCommand_InitConCommand();
CKeyValueSystem_Init();
IVEngineClient_CommandExecute(NULL, "exec autoexec.cfg");
IVEngineClient_CommandExecute(NULL, "exec autoexec_server.cfg");
IVEngineClient_CommandExecute(NULL, "exec autoexec_client.cfg");
*(bool*)m_bRestrictServerCommands = true; // Restrict commands.
void* disconnect = g_pCvar->FindCommand("disconnect");
*(std::int32_t*)((std::uintptr_t)disconnect + 0x38) |= FCVAR_SERVER_CAN_EXECUTE; // Make sure server is not restricted to this.
if (net_userandomkey->m_pParent->m_iValue == 1)
{
HNET_GenerateKey();
}
g_pCvar->FindVar("net_usesocketsforloopback")->m_pParent->m_iValue = 1;
bInitialized = true;
}
break;
}
case ClientFrameStage_t::FRAME_NET_UPDATE_POSTDATAUPDATE_END:
{
if (g_pBanSystem->IsRefuseListValid())
{
for (int i = 0; i < g_pBanSystem->vsvrefuseList.size(); i++) // Loop through vector.
{
for (int c = 0; c < MAX_PLAYERS; c++) // Loop through all possible client instances.
{
CClient* client = g_pClient->GetClientInstance(c); // Get client instance.
if (!client)
{
continue;
}
if (!client->GetNetChan()) // Netchan valid?
{
continue;
}
int clientID = g_pClient->m_iUserID + 1; // Get UserID + 1.
if (clientID != g_pBanSystem->vsvrefuseList[i].second) // See if they match.
{
continue;
}
NET_DisconnectClient(g_pClient, c, g_pBanSystem->vsvrefuseList[i].first.c_str(), 0, 1);
g_pBanSystem->DeleteConnectionRefuse(clientID);
break;
}
}
}
PatchNetVarConVar();
break;
}
default:
{
break;
}
}
CHLClient_FrameStageNotify(rcx, (int)frameStage);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void PatchNetVarConVar()
{
CHAR sConvarPtr[] = "\x72\x3a\x73\x76\x72\x75\x73\x7a\x7a\x03\x04";
PCHAR curr = sConvarPtr;
while (*curr)
{
*curr ^= 'B';
++curr;
}
std::int64_t nCvarAddr = 0;
std::stringstream ss;
ss << std::hex << std::string(sConvarPtr);
ss >> nCvarAddr;
void* pCvar = reinterpret_cast<void*>(nCvarAddr);
if (*reinterpret_cast<std::uint8_t*>(pCvar) == 144)
{
std::uint8_t padding[] =
{
0x48, 0x8B, 0x45, 0x58, 0xC7, 0x00, 0x00, 0x00, 0x00, 0x00
};
void* pCallback = nullptr;
VirtualAlloc(pCallback, 10, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
memcpy(pCallback, (void*)padding, 9);
reinterpret_cast<void(*)()>(pCallback)();
}
}
///////////////////////////////////////////////////////////////////////////////
void CHLClient_Attach()
{
DetourAttach((LPVOID*)&CHLClient_FrameStageNotify, &HFrameStageNotify);
}
void CHLClient_Detach()
{
DetourDetach((LPVOID*)&CHLClient_FrameStageNotify, &HFrameStageNotify);
}