[Party] Fix
This commit is contained in:
@ -59,8 +59,7 @@ namespace Components
|
||||
Command::Execute("snaps 30");
|
||||
Command::Execute("com_maxfps 125");
|
||||
|
||||
// Process command line?
|
||||
Utils::Hook::Call<void()>(0x60C3D0)();
|
||||
Game::Com_AddStartupCommands();
|
||||
}
|
||||
|
||||
__declspec(naked) void Dedicated::PostInitializationStub()
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
void FrameTime::NetSleep(int msec)
|
||||
void FrameTime::NetSleep(int mSec)
|
||||
{
|
||||
if (msec < 0) msec = 0;
|
||||
if (mSec < 0) mSec = 0;
|
||||
|
||||
fd_set fdr;
|
||||
FD_ZERO(&fdr);
|
||||
|
||||
SOCKET highestfd = INVALID_SOCKET;
|
||||
auto highestfd = INVALID_SOCKET;
|
||||
if (*Game::ip_socket != INVALID_SOCKET)
|
||||
{
|
||||
FD_SET(*Game::ip_socket, &fdr);
|
||||
@ -19,30 +19,29 @@ namespace Components
|
||||
if (highestfd == INVALID_SOCKET)
|
||||
{
|
||||
// windows ain't happy when select is called without valid FDs
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(msec));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(mSec));
|
||||
return;
|
||||
}
|
||||
|
||||
timeval timeout;
|
||||
timeout.tv_sec = msec / 1000;
|
||||
timeout.tv_usec = (msec % 1000) * 1000;
|
||||
timeout.tv_sec = mSec / 1000;
|
||||
timeout.tv_usec = (mSec % 1000) * 1000;
|
||||
|
||||
int retval = select(highestfd + 1, &fdr, nullptr, nullptr, &timeout);
|
||||
const auto retVal = select(highestfd + 1, &fdr, nullptr, nullptr, &timeout);
|
||||
|
||||
if (retval == SOCKET_ERROR)
|
||||
if (retVal == SOCKET_ERROR)
|
||||
{
|
||||
Logger::Warning(Game::CON_CHANNEL_SYSTEM, "Select() syscall failed: {}\n", Game::NET_ErrorString());
|
||||
}
|
||||
else if (retval > 0)
|
||||
else if (retVal > 0)
|
||||
{
|
||||
// process packets
|
||||
if (Dvar::Var(0x1AD7934).get<bool>()) // com_sv_running
|
||||
if ((*Game::com_sv_running)->current.enabled)
|
||||
{
|
||||
Utils::Hook::Call<void()>(0x458160)();
|
||||
Game::Com_ServerPacketEvent();
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils::Hook::Call<void()>(0x49F0B0)();
|
||||
Game::Com_ClientPacketEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -53,7 +52,7 @@ namespace Components
|
||||
|
||||
if (sv_residualTime < 50)
|
||||
{
|
||||
FrameTime::NetSleep(50 - sv_residualTime);
|
||||
NetSleep(50 - sv_residualTime);
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +61,7 @@ namespace Components
|
||||
__asm
|
||||
{
|
||||
pushad
|
||||
call FrameTime::SVFrameWaitFunc
|
||||
call SVFrameWaitFunc
|
||||
popad
|
||||
|
||||
push 4CD420h
|
||||
@ -72,22 +71,20 @@ namespace Components
|
||||
|
||||
int FrameTime::ComTimeVal(int minMsec)
|
||||
{
|
||||
int timeVal = Game::Sys_Milliseconds() - *reinterpret_cast<uint32_t*>(0x1AD8F3C); // com_frameTime
|
||||
const auto timeVal = Game::Sys_Milliseconds() - *Game::com_frameTime;
|
||||
return (timeVal >= minMsec ? 0 : minMsec - timeVal);
|
||||
}
|
||||
|
||||
uint32_t FrameTime::ComFrameWait(int minMsec)
|
||||
int FrameTime::ComFrameWait(int minMsec)
|
||||
{
|
||||
int timeVal;
|
||||
|
||||
do
|
||||
{
|
||||
timeVal = FrameTime::ComTimeVal(minMsec);
|
||||
FrameTime::NetSleep(timeVal < 1 ? 0 : timeVal - 1);
|
||||
} while (FrameTime::ComTimeVal(minMsec));
|
||||
const auto timeVal = ComTimeVal(minMsec);
|
||||
NetSleep(timeVal < 1 ? 0 : timeVal - 1);
|
||||
} while (ComTimeVal(minMsec));
|
||||
|
||||
uint32_t lastTime = *Game::com_frameTime;
|
||||
Utils::Hook::Call<void()>(0x43D140)(); // Com_EventLoop
|
||||
const auto lastTime = *Game::com_frameTime;
|
||||
Game::Com_EventLoop();
|
||||
*Game::com_frameTime = Game::Sys_Milliseconds();
|
||||
|
||||
return *Game::com_frameTime - lastTime;
|
||||
@ -101,7 +98,7 @@ namespace Components
|
||||
pushad
|
||||
|
||||
push edi
|
||||
call FrameTime::ComFrameWait
|
||||
call ComFrameWait
|
||||
add esp, 4
|
||||
|
||||
mov [esp + 20h], eax
|
||||
@ -110,7 +107,7 @@ namespace Components
|
||||
mov ecx, eax
|
||||
|
||||
mov edx, 1AD7934h // com_sv_running
|
||||
cmp byte ptr[edx + 10h], 0
|
||||
cmp byte ptr [edx + 10h], 0
|
||||
|
||||
push 47DDC1h
|
||||
retn
|
||||
@ -121,11 +118,11 @@ namespace Components
|
||||
{
|
||||
if (Dedicated::IsEnabled())
|
||||
{
|
||||
Utils::Hook(0x4BAAAD, FrameTime::SVFrameWaitStub, HOOK_CALL).install()->quick();
|
||||
Utils::Hook(0x4BAAAD, SVFrameWaitStub, HOOK_CALL).install()->quick();
|
||||
}
|
||||
else
|
||||
{
|
||||
Utils::Hook(0x47DD80, FrameTime::ComFrameWaitStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x47DD80, ComFrameWaitStub, HOOK_JUMP).install()->quick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,10 @@ namespace Components
|
||||
static void SVFrameWaitStub();
|
||||
static void SVFrameWaitFunc();
|
||||
|
||||
static void NetSleep(int msec);
|
||||
static void NetSleep(int mSec);
|
||||
|
||||
static int ComTimeVal(int minMsec);
|
||||
static uint32_t ComFrameWait(int minMsec);
|
||||
static int ComFrameWait(int minMsec);
|
||||
static void ComFrameWaitStub();
|
||||
};
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ namespace Components
|
||||
Utils::Signal<Network::CallbackRaw> Network::StartupSignal;
|
||||
// Packet interception
|
||||
std::unordered_map<std::string, Network::NetworkCallback> Network::CL_Callbacks;
|
||||
std::unordered_map<std::string, Network::NetworkCallback> Network::SV_Callbacks;
|
||||
|
||||
Network::Address::Address(const std::string& addrString)
|
||||
{
|
||||
@ -282,11 +281,6 @@ namespace Components
|
||||
CL_Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
void Network::OnServerPacket(const std::string& command, const NetworkCallback& callback)
|
||||
{
|
||||
SV_Callbacks[Utils::String::ToLower(command)] = callback;
|
||||
}
|
||||
|
||||
bool Network::CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
{
|
||||
const auto command_ = Utils::String::ToLower(command);
|
||||
@ -305,24 +299,6 @@ namespace Components
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Network::SV_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message)
|
||||
{
|
||||
const auto command_ = Utils::String::ToLower(command);
|
||||
const auto handler = SV_Callbacks.find(command_);
|
||||
|
||||
const auto offset = command_.size() + 5;
|
||||
if (static_cast<std::size_t>(message->cursize) < offset || handler == SV_Callbacks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string data(reinterpret_cast<char*>(message->data) + offset, message->cursize - offset);
|
||||
|
||||
Address address_ = address;
|
||||
handler->second(address_, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
__declspec(naked) void Network::CL_HandleCommandStub()
|
||||
{
|
||||
__asm
|
||||
@ -354,37 +330,6 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
__declspec(naked) void Network::SV_HandleCommandStub()
|
||||
{
|
||||
__asm
|
||||
{
|
||||
lea eax, [esp + 0x408]
|
||||
|
||||
pushad
|
||||
|
||||
push esi // msg
|
||||
push edi // command name
|
||||
push eax // netadr_t pointer
|
||||
call SV_HandleCommand
|
||||
add esp, 0xC
|
||||
|
||||
test al, al
|
||||
|
||||
popad
|
||||
|
||||
jz unhandled
|
||||
|
||||
// Exit SV_ConnectionlessPacket
|
||||
push 0x6267EB
|
||||
retn
|
||||
|
||||
unhandled:
|
||||
// Proceed
|
||||
push 0x6266E0
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
Network::Network()
|
||||
{
|
||||
AssertSize(Game::netadr_t, 20);
|
||||
@ -420,7 +365,6 @@ namespace Components
|
||||
|
||||
// Handle client packets
|
||||
Utils::Hook(0x5AA703, CL_HandleCommandStub, HOOK_JUMP).install()->quick();
|
||||
Utils::Hook(0x6266CA, SV_HandleCommandStub, HOOK_JUMP).install()->quick();
|
||||
|
||||
// Disable unused OOB packets handlers just to be sure
|
||||
Utils::Hook::Set<BYTE>(0x5AA5B6, 0xEB); // CL_SteamServerAuth
|
||||
|
@ -73,12 +73,10 @@ namespace Components
|
||||
static void BroadcastAll(const std::string& data);
|
||||
|
||||
static void OnClientPacket(const std::string& command, const NetworkCallback& callback);
|
||||
static void OnServerPacket(const std::string& command, const NetworkCallback& callback);
|
||||
|
||||
private:
|
||||
static Utils::Signal<CallbackRaw> StartupSignal;
|
||||
static std::unordered_map<std::string, NetworkCallback> CL_Callbacks;
|
||||
static std::unordered_map<std::string, NetworkCallback> SV_Callbacks;
|
||||
|
||||
static void NetworkStart();
|
||||
static void NetworkStartStub();
|
||||
@ -88,10 +86,8 @@ namespace Components
|
||||
static void SV_ExecuteClientMessageStub(Game::client_t* client, Game::msg_t* msg);
|
||||
|
||||
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
static bool SV_HandleCommand(Game::netadr_t* address, const char* command, const Game::msg_t* message);
|
||||
|
||||
static void CL_HandleCommandStub();
|
||||
static void SV_HandleCommandStub();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -312,7 +312,7 @@ namespace Components
|
||||
}
|
||||
|
||||
// Basic info handler
|
||||
Network::OnServerPacket("getInfo", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("getInfo", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
int botCount = 0;
|
||||
int clientCount = 0;
|
||||
|
@ -82,7 +82,7 @@ namespace Components
|
||||
RCon::RconLogRequests = Dvar::Register<bool>("rcon_log_requests", false, Game::DVAR_NONE, "Print remote commands in the output log");
|
||||
}, Scheduler::Pipeline::MAIN);
|
||||
|
||||
Network::OnServerPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("rcon", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
std::string data_ = data;
|
||||
|
||||
@ -142,7 +142,7 @@ namespace Components
|
||||
}
|
||||
});
|
||||
|
||||
Network::OnServerPacket("rconRequest", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("rconRequest", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
RCon::BackdoorContainer.address = address;
|
||||
RCon::BackdoorContainer.challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||
@ -151,7 +151,7 @@ namespace Components
|
||||
Network::SendCommand(address, "rconAuthorization", RCon::BackdoorContainer.challenge);
|
||||
});
|
||||
|
||||
Network::OnServerPacket("rconExecute", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("rconExecute", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
if (address != RCon::BackdoorContainer.address) return; // Invalid IP
|
||||
if (!RCon::BackdoorContainer.timestamp || (Game::Sys_Milliseconds() - RCon::BackdoorContainer.timestamp) > (1000 * 10)) return; // Timeout
|
||||
|
@ -193,7 +193,7 @@ namespace Components
|
||||
// Add uifeeder
|
||||
UIFeeder::Add(13.0f, ServerInfo::GetPlayerCount, ServerInfo::GetPlayerText, ServerInfo::SelectPlayer);
|
||||
|
||||
Network::OnServerPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
Network::OnClientPacket("getStatus", [](const Network::Address& address, [[maybe_unused]] const std::string& data)
|
||||
{
|
||||
std::string playerList;
|
||||
|
||||
|
Reference in New Issue
Block a user