[Auth]: Improve sv_privateClients patch (#928)

This commit is contained in:
Edo 2023-04-16 10:47:02 +02:00 committed by GitHub
parent 9160436b05
commit e945652dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 28 deletions

View File

@ -273,33 +273,16 @@ namespace Components
return value;
}
__declspec(naked) void Auth::DirectConnectPrivateClientStub()
int Auth::NET_IsLocalAddressStub(Game::netadr_t adr)
{
__asm
if (HasAccessToReservedSlot)
{
push eax
mov al, HasAccessToReservedSlot
test al, al
pop eax
je noAccess
// Set the number of private clients to 0 if the client has the right password
xor eax, eax
jmp safeContinue
noAccess:
mov eax, dword ptr [edx + 0x10]
safeContinue:
// Game code skipped by hook
add esp, 0xC
push 0x460FB3
ret
// Bypass sv_privateClients if client has the password
return 1;
}
// Only bypass if address is local. Original behaviour
return Utils::Hook::Call<int(Game::netadr_t)>(0x402BD0)(adr);
}
unsigned __int64 Auth::GetKeyHash(const std::string& key)
@ -484,8 +467,7 @@ namespace Components
// Install registration hook
Utils::Hook(0x6265F9, DirectConnectStub, HOOK_JUMP).install()->quick();
Utils::Hook(0x460EF5, Info_ValueForKeyStub, HOOK_CALL).install()->quick();
Utils::Hook(0x460FAD, DirectConnectPrivateClientStub, HOOK_JUMP).install()->quick();
Utils::Hook::Nop(0x460FAD + 5, 1);
Utils::Hook(0x460F89, NET_IsLocalAddressStub, HOOK_CALL).install()->quick();
Utils::Hook(0x41D3E3, SendConnectDataStub, HOOK_CALL).install()->quick();

View File

@ -51,7 +51,7 @@ namespace Components
static void ParseConnectData(Game::msg_t* msg, Game::netadr_t* addr);
static void DirectConnectStub();
static char* Info_ValueForKeyStub(const char* s, const char* key);
static void DirectConnectPrivateClientStub();
static int NET_IsLocalAddressStub(Game::netadr_t adr);
static void Frame();
};

View File

@ -168,7 +168,7 @@ namespace Components
Scheduler::Once([ent]
{
Game::Scr_AddString(Utils::String::VA("class%u", Utils::Cryptography::Rand::GenerateInt() % 5u));
Game::Scr_AddString(Utils::String::Format("class{}", std::rand() % 5));
Game::Scr_AddString("changeclass");
Game::Scr_Notify(ent, static_cast<std::uint16_t>(Game::SL_GetString("menuresponse", 0)), 2);
}, Scheduler::Pipeline::SERVER, 1s);