[Events]: Cleanup (#1016)
This commit is contained in:
parent
9526c7aa74
commit
54f6162a7a
@ -697,7 +697,7 @@ namespace Components
|
|||||||
|
|
||||||
mg_mgr_init(&Mgr);
|
mg_mgr_init(&Mgr);
|
||||||
|
|
||||||
Network::OnStart([]
|
Events::OnNetworkInit([]() -> void
|
||||||
{
|
{
|
||||||
const auto* nc = mg_http_listen(&Mgr, Utils::String::VA(":%hu", Network::GetPort()), &EventHandler, &Mgr);
|
const auto* nc = mg_http_listen(&Mgr, Utils::String::VA(":%hu", Network::GetPort()), &EventHandler, &Mgr);
|
||||||
if (!nc)
|
if (!nc)
|
||||||
@ -709,7 +709,7 @@ namespace Components
|
|||||||
|
|
||||||
ServerRunning = true;
|
ServerRunning = true;
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
ServerThread = Utils::Thread::CreateNamedThread("Mongoose", []
|
ServerThread = Utils::Thread::CreateNamedThread("Mongoose", []() -> void
|
||||||
{
|
{
|
||||||
Com_InitThreadData();
|
Com_InitThreadData();
|
||||||
|
|
||||||
@ -722,7 +722,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Events::OnDvarInit([]
|
Events::OnDvarInit([]() -> void
|
||||||
{
|
{
|
||||||
UIDlTimeLeft = Dvar::Register<const char*>("ui_dl_timeLeft", "", Game::DVAR_NONE, "");
|
UIDlTimeLeft = Dvar::Register<const char*>("ui_dl_timeLeft", "", Game::DVAR_NONE, "");
|
||||||
UIDlProgress = Dvar::Register<const char*>("ui_dl_progress", "", Game::DVAR_NONE, "");
|
UIDlProgress = Dvar::Register<const char*>("ui_dl_progress", "", Game::DVAR_NONE, "");
|
||||||
|
@ -9,6 +9,7 @@ namespace Components
|
|||||||
Utils::Signal<Events::Callback> Events::ClientInitSignal;
|
Utils::Signal<Events::Callback> Events::ClientInitSignal;
|
||||||
Utils::Signal<Events::Callback> Events::ServerInitSignal;
|
Utils::Signal<Events::Callback> Events::ServerInitSignal;
|
||||||
Utils::Signal<Events::Callback> Events::DvarInitSignal;
|
Utils::Signal<Events::Callback> Events::DvarInitSignal;
|
||||||
|
Utils::Signal<Events::Callback> Events::NetworkInitSignal;
|
||||||
|
|
||||||
void Events::OnClientDisconnect(const Utils::Slot<ClientCallback>& callback)
|
void Events::OnClientDisconnect(const Utils::Slot<ClientCallback>& callback)
|
||||||
{
|
{
|
||||||
@ -45,6 +46,11 @@ namespace Components
|
|||||||
DvarInitSignal.connect(callback);
|
DvarInitSignal.connect(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Events::OnNetworkInit(const Utils::Slot<Callback>& callback)
|
||||||
|
{
|
||||||
|
NetworkInitSignal.connect(callback);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Should be called when a client drops from the server
|
* Should be called when a client drops from the server
|
||||||
* but not "between levels" (Quake-III-Arena)
|
* but not "between levels" (Quake-III-Arena)
|
||||||
@ -101,6 +107,22 @@ namespace Components
|
|||||||
Utils::Hook::Call<void()>(0x60AD10)(); // Com_InitDvars
|
Utils::Hook::Call<void()>(0x60AD10)(); // Com_InitDvars
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Events::NetworkStart()
|
||||||
|
{
|
||||||
|
NetworkInitSignal();
|
||||||
|
NetworkInitSignal.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
__declspec(naked) void Events::NET_OpenSocks_Hk()
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
mov eax, 64D900h
|
||||||
|
call eax
|
||||||
|
jmp NetworkStart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Events::Events()
|
Events::Events()
|
||||||
{
|
{
|
||||||
Utils::Hook(0x625235, ClientDisconnect_Hk, HOOK_CALL).install()->quick(); // SV_FreeClient
|
Utils::Hook(0x625235, ClientDisconnect_Hk, HOOK_CALL).install()->quick(); // SV_FreeClient
|
||||||
@ -117,5 +139,7 @@ namespace Components
|
|||||||
Utils::Hook(0x60BB3A, Com_InitDvars_Hk, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
Utils::Hook(0x60BB3A, Com_InitDvars_Hk, HOOK_CALL).install()->quick(); // Com_Init_Try_Block_Function
|
||||||
|
|
||||||
Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init
|
Utils::Hook(0x4D3665, SV_Init_Hk, HOOK_CALL).install()->quick(); // SV_Init
|
||||||
|
|
||||||
|
Utils::Hook(0x4FD4D4, NET_OpenSocks_Hk, HOOK_JUMP).install()->quick(); // NET_OpenIP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@ namespace Components
|
|||||||
// Client & Server (triggered once)
|
// Client & Server (triggered once)
|
||||||
static void OnDvarInit(const Utils::Slot<Callback>& callback);
|
static void OnDvarInit(const Utils::Slot<Callback>& callback);
|
||||||
|
|
||||||
|
static void OnNetworkInit(const Utils::Slot<Callback>& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Utils::Signal<ClientCallback> ClientDisconnectSignal;
|
static Utils::Signal<ClientCallback> ClientDisconnectSignal;
|
||||||
static Utils::Signal<ClientConnectCallback> ClientConnectSignal;
|
static Utils::Signal<ClientConnectCallback> ClientConnectSignal;
|
||||||
@ -38,6 +40,7 @@ namespace Components
|
|||||||
static Utils::Signal<Callback> ClientInitSignal;
|
static Utils::Signal<Callback> ClientInitSignal;
|
||||||
static Utils::Signal<Callback> ServerInitSignal;
|
static Utils::Signal<Callback> ServerInitSignal;
|
||||||
static Utils::Signal<Callback> DvarInitSignal;
|
static Utils::Signal<Callback> DvarInitSignal;
|
||||||
|
static Utils::Signal<Callback> NetworkInitSignal;
|
||||||
|
|
||||||
static void ClientDisconnect_Hk(int clientNum);
|
static void ClientDisconnect_Hk(int clientNum);
|
||||||
static void SV_UserinfoChanged_Hk(Game::client_s* cl);
|
static void SV_UserinfoChanged_Hk(Game::client_s* cl);
|
||||||
@ -46,5 +49,8 @@ namespace Components
|
|||||||
static void CL_InitOnceForAllClients_HK();
|
static void CL_InitOnceForAllClients_HK();
|
||||||
static void SV_Init_Hk();
|
static void SV_Init_Hk();
|
||||||
static void Com_InitDvars_Hk();
|
static void Com_InitDvars_Hk();
|
||||||
|
|
||||||
|
static void NetworkStart();
|
||||||
|
static void NET_OpenSocks_Hk();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
Utils::Signal<Network::CallbackRaw> Network::StartupSignal;
|
|
||||||
// Packet interception
|
// Packet interception
|
||||||
std::unordered_map<std::string, Network::networkCallback> Network::CL_Callbacks;
|
std::unordered_map<std::string, Network::networkCallback> Network::CL_Callbacks;
|
||||||
std::unordered_map<std::string, Network::networkRawCallback> Network::CL_RawCallbacks;
|
std::unordered_map<std::string, Network::networkRawCallback> Network::CL_RawCallbacks;
|
||||||
@ -152,11 +151,6 @@ namespace Components
|
|||||||
return (this->getType() != Game::NA_BAD && this->getType() >= Game::NA_BOT && this->getType() <= Game::NA_IP);
|
return (this->getType() != Game::NA_BAD && this->getType() >= Game::NA_BOT && this->getType() <= Game::NA_IP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::OnStart(const Utils::Slot<CallbackRaw>& callback)
|
|
||||||
{
|
|
||||||
StartupSignal.connect(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Network::Send(Game::netsrc_t type, const Address& target, const std::string& data)
|
void Network::Send(Game::netsrc_t type, const Address& target, const std::string& data)
|
||||||
{
|
{
|
||||||
// Do not use NET_OutOfBandPrint. It only supports non-binary data!
|
// Do not use NET_OutOfBandPrint. It only supports non-binary data!
|
||||||
@ -228,12 +222,6 @@ namespace Components
|
|||||||
BroadcastRange(100, 65536, data);
|
BroadcastRange(100, 65536, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::NetworkStart()
|
|
||||||
{
|
|
||||||
StartupSignal();
|
|
||||||
StartupSignal.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint16_t Network::GetPort()
|
std::uint16_t Network::GetPort()
|
||||||
{
|
{
|
||||||
assert((*Game::port));
|
assert((*Game::port));
|
||||||
@ -241,16 +229,6 @@ namespace Components
|
|||||||
return static_cast<std::uint16_t>((*Game::port)->current.unsignedInt);
|
return static_cast<std::uint16_t>((*Game::port)->current.unsignedInt);
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(naked) void Network::NetworkStartStub()
|
|
||||||
{
|
|
||||||
__asm
|
|
||||||
{
|
|
||||||
mov eax, 64D900h
|
|
||||||
call eax
|
|
||||||
jmp NetworkStart
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__declspec(naked) void Network::PacketErrorCheck()
|
__declspec(naked) void Network::PacketErrorCheck()
|
||||||
{
|
{
|
||||||
__asm
|
__asm
|
||||||
@ -392,9 +370,6 @@ namespace Components
|
|||||||
// Parse port as short in Net_AddrToString
|
// Parse port as short in Net_AddrToString
|
||||||
Utils::Hook::Set<const char*>(0x4698E3, "%u.%u.%u.%u:%hu");
|
Utils::Hook::Set<const char*>(0x4698E3, "%u.%u.%u.%u:%hu");
|
||||||
|
|
||||||
// Install startup handler
|
|
||||||
Utils::Hook(0x4FD4D4, NetworkStartStub, HOOK_JUMP).install()->quick();
|
|
||||||
|
|
||||||
// Prevent recvfrom error spam
|
// Prevent recvfrom error spam
|
||||||
Utils::Hook(0x46531A, PacketErrorCheck, HOOK_JUMP).install()->quick();
|
Utils::Hook(0x46531A, PacketErrorCheck, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
|
@ -46,16 +46,12 @@ namespace Components
|
|||||||
Game::netadr_t address;
|
Game::netadr_t address;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void(CallbackRaw)();
|
|
||||||
|
|
||||||
using networkCallback = std::function<void(Address&, const std::string&)>;
|
using networkCallback = std::function<void(Address&, const std::string&)>;
|
||||||
using networkRawCallback = std::function<void(Game::netadr_t*, Game::msg_t* msg)>;
|
using networkRawCallback = std::function<void(Game::netadr_t*, Game::msg_t* msg)>;
|
||||||
|
|
||||||
Network();
|
Network();
|
||||||
|
|
||||||
static std::uint16_t GetPort();
|
static std::uint16_t GetPort();
|
||||||
|
|
||||||
static void OnStart(const Utils::Slot<CallbackRaw>& callback);
|
|
||||||
|
|
||||||
// Send quake-styled binary data
|
// Send quake-styled binary data
|
||||||
static void Send(const Address& target, const std::string& data);
|
static void Send(const Address& target, const std::string& data);
|
||||||
@ -77,13 +73,9 @@ namespace Components
|
|||||||
static void OnClientPacketRaw(const std::string& command, const networkRawCallback& callback);
|
static void OnClientPacketRaw(const std::string& command, const networkRawCallback& callback);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Utils::Signal<CallbackRaw> StartupSignal;
|
|
||||||
static std::unordered_map<std::string, networkCallback> CL_Callbacks;
|
static std::unordered_map<std::string, networkCallback> CL_Callbacks;
|
||||||
static std::unordered_map<std::string, networkRawCallback> CL_RawCallbacks;
|
static std::unordered_map<std::string, networkRawCallback> CL_RawCallbacks;
|
||||||
|
|
||||||
static void NetworkStart();
|
|
||||||
static void NetworkStartStub();
|
|
||||||
|
|
||||||
static void PacketErrorCheck();
|
static void PacketErrorCheck();
|
||||||
|
|
||||||
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message);
|
static bool CL_HandleCommand(Game::netadr_t* address, const char* command, Game::msg_t* message);
|
||||||
|
@ -22,7 +22,7 @@ namespace Game
|
|||||||
assert((size >= 0));
|
assert((size >= 0));
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable: 6250)
|
#pragma warning(disable: 6250)
|
||||||
[[maybe_unused]] const auto result = VirtualFree(ptr, size, MEM_DECOMMIT);
|
VirtualFree(ptr, size, MEM_DECOMMIT);
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user