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

Refactor cleanup (some formatting fixes) #257

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion NorthstarDLL/bansystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void ServerBanSystem::UnbanUID(uint64_t uid)
return;

m_vBannedUids.erase(findResult);

std::vector<std::string> banlistText;
std::ifstream fs_readBanlist(GetNorthstarPrefix() + "/banlist.txt");

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/clientruihooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bool,, (void* a1, float* a2))
{
if (!Cvar_rui_drawEnable->GetBool())
return 0;

return DrawRUIFunc(a1, a2);
}

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/convar.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const std::multimap<int, const char*> g_PrintCommandFlags = {
{FCVAR_ARCHIVE_PLAYERPROFILE, "ARCHIVE_PLAYERPROFILE"},
{FCVAR_SERVER_CAN_EXECUTE, "SERVER_CAN_EXECUTE"},
{FCVAR_SERVER_CANNOT_QUERY, "SERVER_CANNOT_QUERY"},
{FCVAR_CLIENTCMD_CAN_EXECUTE, "UNKNOWN"},
{FCVAR_CLIENTCMD_CAN_EXECUTE, "UNKNOWN"},
{FCVAR_ACCESSIBLE_FROM_THREADS, "ACCESSIBLE_FROM_THREADS"}
};

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CCvar
};

// use the R2 namespace for game funcs
namespace R2
namespace R2
{
extern SourceInterface<CCvar>* g_pCVarInterface;
extern CCvar* g_pCVar;
Expand Down
5 changes: 1 addition & 4 deletions NorthstarDLL/dedicated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ ON_DLL_LOAD_DEDI_RELIESON("engine.dll", DedicatedServer, ServerPresence, (CModul
// 00 => 01
base.Offset(7).Patch("01");
}


// Some init that i'm not sure of that crashes
// nop the call to it
Expand Down Expand Up @@ -198,7 +197,6 @@ ON_DLL_LOAD_DEDI_RELIESON("engine.dll", DedicatedServer, ServerPresence, (CModul
// nop call to ShowWindow
module.Offset(0x1CD146).NOP(5);


CDedicatedExports* dedicatedExports = new CDedicatedExports;
dedicatedExports->vtable = dedicatedExports;
dedicatedExports->Sys_Printf = Sys_Printf;
Expand All @@ -222,7 +220,7 @@ ON_DLL_LOAD_DEDI_RELIESON("engine.dll", DedicatedServer, ServerPresence, (CModul
Tier0::CommandLine()->AppendParm("-nomessagebox", 0);
Tier0::CommandLine()->AppendParm("+host_preload_shaders", "0");
Tier0::CommandLine()->AppendParm("+net_usesocketsforloopback", "1");

// use presence reporter for console title
DedicatedConsoleServerPresence* presenceReporter = new DedicatedConsoleServerPresence;
g_pServerPresence->AddPresenceReporter(presenceReporter);
Expand Down Expand Up @@ -285,6 +283,5 @@ ON_DLL_LOAD_DEDI("server.dll", DedicatedServerGameDLL, (CModule module))
module.Offset(0x6BA300).Patch(
"B8 C8 00 00 00 C3"); // return 200 as the number of skins from server.dll + 6BA300, this is the normal value read from
// skins.rson and should be updated when we need it more modular

}
}
2 changes: 1 addition & 1 deletion NorthstarDLL/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <filesystem>
namespace fs = std::filesystem;

typedef void (*initPluginFuncPtr)(void* (*getPluginObject)(PluginObject));
typedef void (*initPluginFuncPtr)(void* (*getPluginObject)(PluginObject));

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/exploitfixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ ON_DLL_LOAD("engine.dll", EngineExploitFixes, (CModule module))
{
AUTOHOOK_DISPATCH_MODULE(engine.dll)

CCommand__Tokenize = module.Offset(0x418380).As<bool(*)(CCommand&, const char*, R2::cmd_source_t)>();
CCommand__Tokenize = module.Offset(0x418380).As<bool (*)(CCommand&, const char*, R2::cmd_source_t)>();

// allow client/ui to run clientcommands despite restricting servercommands
module.Offset(0x4FB65).Patch("EB 11");
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/exploitfixes_lzss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ unsigned int,, (void* self, const unsigned char* pInput, unsigned char* pOutput,
{
if (!getCmdByte)
cmdByte = *pInput++;

getCmdByte = (getCmdByte + 1) & 0x07;

if (cmdByte & 0x01)
Expand Down
1 change: 0 additions & 1 deletion NorthstarDLL/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ void CallLoadLibraryACallbacks(LPCSTR lpLibFileName, HMODULE moduleAddress)
}
}


if (bShouldContinue)
continue;

Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ void,, (bool bDedicated))
}

ON_DLL_LOAD("engine.dll", Host_Init, (CModule module))
{
{
AUTOHOOK_DISPATCH()
}
2 changes: 1 addition & 1 deletion NorthstarDLL/hoststate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace R2

ConVar* Cvar_hostport;

void ServerStartingOrChangingMap()
void ServerStartingOrChangingMap()
{
// net_data_block_enabled is required for sp, force it if we're on an sp map
// sucks for security but just how it be
Expand Down
4 changes: 1 addition & 3 deletions NorthstarDLL/localchatwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class vgui_BaseRichText_vtable
void(__fastcall* InsertIndentChange)(vgui_BaseRichText* self, int pixelsIndent);
void(__fastcall* InsertClickableTextStart)(vgui_BaseRichText* self, const char* pchClickAction);
void(__fastcall* InsertClickableTextEnd)(vgui_BaseRichText* self);
void(__fastcall* InsertPossibleURLString)(
vgui_BaseRichText* self, const char* text, Color URLTextColor, Color normalTextColor);
void(__fastcall* InsertPossibleURLString)(vgui_BaseRichText* self, const char* text, Color URLTextColor, Color normalTextColor);
void(__fastcall* InsertFade)(vgui_BaseRichText* self, float flSustain, float flLength);
void(__fastcall* ResetAllFades)(vgui_BaseRichText* self, bool bHold, bool bOnlyExpired, float flNewSustain);
void(__fastcall* SetToFullHeight)(vgui_BaseRichText* self);
Expand Down Expand Up @@ -374,7 +373,6 @@ static Color GetHudSwatchColor(CHudChat* hud, LocalChatWriter::SwatchColor swatc

case LocalChatWriter::NetworkNameColor:
return hud->m_networkNameColor;

}

return Color(0, 0, 0, 0);
Expand Down
8 changes: 4 additions & 4 deletions NorthstarDLL/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ RemoteServerInfo::RemoteServerInfo(

description = std::string(newDescription);

strncpy_s((char*)map, sizeof(map) , newMap, sizeof(map) - 1);
strncpy_s((char*)playlist, sizeof(playlist) , newPlaylist, sizeof(playlist) - 1);
strncpy_s((char*)map, sizeof(map), newMap, sizeof(map) - 1);
strncpy_s((char*)playlist, sizeof(playlist), newPlaylist, sizeof(playlist) - 1);

playerCount = newPlayerCount;
maxPlayers = newMaxPlayers;
Expand Down Expand Up @@ -755,7 +755,7 @@ class MasterServerPresenceReporter : public ServerPresenceReporter
double m_bShouldTryRegisterServer;
int m_nNumRegistrationAttempts;

void CreatePresence(const ServerPresence* pServerPresence) override
void CreatePresence(const ServerPresence* pServerPresence) override
{
m_bShouldTryRegisterServer = true;
m_nNumRegistrationAttempts = 0;
Expand All @@ -764,7 +764,7 @@ class MasterServerPresenceReporter : public ServerPresenceReporter
void ReportPresence(const ServerPresence* pServerPresence) override
{
// make a copy of presence for multithreading purposes

ServerPresence threadedPresence(pServerPresence);

if (!*g_pMasterServerManager->m_sOwnServerId || m_bShouldTryRegisterServer)
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/maxplayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ bool MaxPlayersIncreaseEnabled()
// should we use R2 for this? not sure
namespace R2 // use R2 namespace for game funcs
{
int GetMaxPlayers()
int GetMaxPlayers()
{
if (MaxPlayersIncreaseEnabled())
return NEW_MAX_PLAYERS;
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/maxplayers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

// should we use R2 for this? not sure
// should we use R2 for this? not sure
namespace R2 // use R2 namespace for game funcs
{
int GetMaxPlayers();
Expand Down
16 changes: 7 additions & 9 deletions NorthstarDLL/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MemoryAddress::operator uintptr_t() const
return m_nAddress;
}

MemoryAddress::operator void* () const
MemoryAddress::operator void*() const
{
return reinterpret_cast<void*>(m_nAddress);
}
Expand Down Expand Up @@ -41,12 +41,12 @@ bool MemoryAddress::operator!=(const uintptr_t& addr) const
return m_nAddress != addr;
}

MemoryAddress MemoryAddress::operator+(const MemoryAddress& other) const
MemoryAddress MemoryAddress::operator+(const MemoryAddress& other) const
{
return Offset(other.m_nAddress);
}

MemoryAddress MemoryAddress::operator-(const MemoryAddress& other) const
MemoryAddress MemoryAddress::operator-(const MemoryAddress& other) const
{
return MemoryAddress(m_nAddress - other.m_nAddress);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ inline std::vector<uint8_t> HexBytesToString(const char* pHexString)
// If this is a space character, ignore it
if (isspace(pHexString[i]))
continue;

if (i < size - 1)
{
BYTE result = 0;
Expand Down Expand Up @@ -159,7 +159,7 @@ void MemoryAddress::NOP(const size_t nSize)

memset(pBytes, 0x90, nSize);
Patch(pBytes, nSize);

delete[] pBytes;
}

Expand All @@ -176,9 +176,7 @@ bool MemoryAddress::IsMemoryReadable(const size_t nSize)
return memInfo.RegionSize >= nSize && memInfo.State & MEM_COMMIT && !(memInfo.Protect & PAGE_NOACCESS);
}



CModule::CModule(const HMODULE pModule)
CModule::CModule(const HMODULE pModule)
{
MODULEINFO mInfo {0};

Expand Down Expand Up @@ -343,7 +341,7 @@ inline std::pair<std::vector<uint8_t>, std::string> MaskedBytesFromPattern(const
return std::make_pair(vRet, sMask);
}

MemoryAddress CModule::FindPattern(const char* pPattern)
MemoryAddress CModule::FindPattern(const char* pPattern)
{
const auto pattern = MaskedBytesFromPattern(pPattern);
return FindPattern(pattern.first.data(), pattern.second.c_str());
Expand Down
9 changes: 6 additions & 3 deletions NorthstarDLL/memory.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
#pragma once

class MemoryAddress
{
Expand All @@ -10,7 +10,7 @@ class MemoryAddress
MemoryAddress(const uintptr_t nAddress);
MemoryAddress(const void* pAddress);

//operators
// operators
operator uintptr_t() const;
operator void*() const;
operator bool() const;
Expand All @@ -26,7 +26,10 @@ class MemoryAddress
MemoryAddress operator-(const uintptr_t& other) const;
MemoryAddress operator*() const;

template <typename T> T As() { return reinterpret_cast<T>(m_nAddress); }
template <typename T> T As()
{
return reinterpret_cast<T>(m_nAddress);
}

// traversal
MemoryAddress Offset(const uintptr_t nOffset) const;
Expand Down
6 changes: 3 additions & 3 deletions NorthstarDLL/misccommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "serverauthentication.h"
#include "squirrel.h"

void ConCommand_force_newgame(const CCommand& arg)
void ConCommand_force_newgame(const CCommand& arg)
{
if (arg.ArgC() < 2)
return;
Expand All @@ -18,14 +18,14 @@ void ConCommand_force_newgame(const CCommand& arg)
strncpy(R2::g_pHostState->m_levelName, arg.Arg(1), sizeof(R2::g_pHostState->m_levelName));
}

void ConCommand_ns_start_reauth_and_leave_to_lobby(const CCommand& arg)
void ConCommand_ns_start_reauth_and_leave_to_lobby(const CCommand& arg)
{
// hack for special case where we're on a local server, so we erase our own newly created auth data on disconnect
g_pMasterServerManager->m_bNewgameAfterSelfAuth = true;
g_pMasterServerManager->AuthenticateWithOwnServer(R2::g_pLocalPlayerUserID, g_pMasterServerManager->m_sOwnClientAuthToken);
}

void ConCommand_ns_end_reauth_and_leave_to_lobby(const CCommand& arg)
void ConCommand_ns_end_reauth_and_leave_to_lobby(const CCommand& arg)
{
R2::Cbuf_AddText(
R2::Cbuf_GetCurrentPlayer(),
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/miscserverscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "squirrel.h"
#include "masterserver.h"
#include "serverauthentication.h"
#include "dedicated.h"
#include "dedicated.h"
#include "r2client.h"
#include "r2server.h"

Expand Down
3 changes: 1 addition & 2 deletions NorthstarDLL/modmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ void ModManager::LoadMods()

Mod mod(modDir, (char*)jsonStringStream.str().c_str());


for (auto& pair : mod.DependencyConstants)
{
if (m_DependencyConstants.find(pair.first) != m_DependencyConstants.end() && m_DependencyConstants[pair.first] != pair.second)
Expand Down Expand Up @@ -366,7 +365,7 @@ void ModManager::LoadMods()
// causes us to leak memory on reload, but not much, potentially find a way to not do this at some point
for (ModConVar* convar : mod.ConVars)
if (!R2::g_pCVar->FindVar(convar->Name.c_str())) // make sure convar isn't registered yet, unsure if necessary but idk what
// behaviour is for defining same convar multiple times
// behaviour is for defining same convar multiple times
new ConVar(convar->Name.c_str(), convar->DefaultValue.c_str(), convar->Flags, convar->HelpString.c_str());

// read vpk paths
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/modmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Mod
std::unordered_map<std::string, std::string>
RpakAliases; // paks we alias to other rpaks, e.g. to load sp_crashsite paks on the map mp_crashsite

std::unordered_map<std::string, std::string> DependencyConstants;
std::unordered_map<std::string, std::string> DependencyConstants;

public:
Mod(fs::path modPath, char* jsonBuf);
Expand Down
11 changes: 5 additions & 6 deletions NorthstarDLL/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AUTOHOOK(SetCurrentPlaylist, engine.dll + 0x18EB20,
bool, __fastcall, (const char* pPlaylistName))
{
bool bSuccess = SetCurrentPlaylist(pPlaylistName);

if (bSuccess)
{
spdlog::info("Set playlist to {}", R2::GetCurrentPlaylistName());
Expand Down Expand Up @@ -72,7 +72,6 @@ int,, ())
return iMaxPlayers;
}


void ConCommand_playlist(const CCommand& args)
{
if (args.ArgC() < 2)
Expand All @@ -94,10 +93,10 @@ ON_DLL_LOAD_RELIESON("engine.dll", PlaylistHooks, (ConCommand, ConVar), (CModule
{
AUTOHOOK_DISPATCH()

R2::GetCurrentPlaylistName = module.Offset(0x18C640).As<const char*(*)()>();
R2::SetCurrentPlaylist = module.Offset(0x18EB20).As <void(*)(const char*)>();
R2::SetPlaylistVarOverride = module.Offset(0x18ED00).As<void(*)(const char*, const char*)>();
R2::GetCurrentPlaylistVar = module.Offset(0x18C680).As<const char*(*)(const char*, bool)>();
R2::GetCurrentPlaylistName = module.Offset(0x18C640).As<const char* (*)()>();
R2::SetCurrentPlaylist = module.Offset(0x18EB20).As<void (*)(const char*)>();
R2::SetPlaylistVarOverride = module.Offset(0x18ED00).As<void (*)(const char*, const char*)>();
R2::GetCurrentPlaylistVar = module.Offset(0x18C680).As<const char* (*)(const char*, bool)>();

// playlist is the name of the command on respawn servers, but we already use setplaylist so can't get rid of it
RegisterConCommand("playlist", ConCommand_playlist, "Sets the current playlist", FCVAR_NONE);
Expand Down
2 changes: 1 addition & 1 deletion NorthstarDLL/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ SQRESULT SQ_UpdateListenServer(HSquirrelVM* sqvm)
{
AcquireSRWLockExclusive(&serverInfoLock);
serverInfo.id = g_pMasterServerManager->m_sOwnServerId;
serverInfo.password = "";// g_pServerPresence->Cvar_ns_server_password->GetString(); todo this fr
serverInfo.password = ""; // g_pServerPresence->Cvar_ns_server_password->GetString(); todo this fr
ReleaseSRWLockExclusive(&serverInfoLock);
return SQRESULT_NOTNULL;
}
Expand Down
Loading