Merge pull request #197 from mjkzy/sv-motd-fix

Proper sv_motd fix
This commit is contained in:
Maurice Heumann 2021-08-11 12:00:22 +02:00 committed by GitHub
commit c537c33992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View File

@ -122,6 +122,7 @@ namespace exception
{
recovery_data.last_recovery = std::chrono::high_resolution_clock::now();
++recovery_data.recovery_counts;
game::Com_Error(game::ERR_DROP, "Fatal error (0x%08X) at 0x%p.\nA minidump has been written.\n\n"
"S1x has tried to recover your game, but it might not run stable anymore.\n\n"
"Make sure to update your graphics card drivers and install operating system updates!\n"

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "party.hpp"
#include "game/game.hpp"
#include "console.hpp"
@ -55,6 +56,8 @@ namespace logger
console::error("Error: %s\n", buffer);
}
party::clear_sv_motd(); // clear sv_motd on error if it exists
com_error_hook.invoke<void>(error, "%s", buffer);
}

View File

@ -120,7 +120,6 @@ namespace party
// This function either does Dvar_SetString or Dvar_RegisterString for the given dvar
reinterpret_cast<void(*)(const char*, const char*)>(0x1404C39B0)(dvar_name, string);
party::sv_motd.clear();
}
void disconnect_stub()
@ -139,6 +138,14 @@ namespace party
}
}
utils::hook::detour cldisconnect_hook;
void cldisconnect_stub(int a1)
{
clear_sv_motd();
cldisconnect_hook.invoke<void>(a1);
}
const auto drop_reason_stub = utils::hook::assemble([](utils::hook::assembler& a)
{
a.mov(rdx, rdi);
@ -147,6 +154,12 @@ namespace party
});
}
void clear_sv_motd()
{
party::sv_motd.clear();
return;
}
int get_client_num_by_name(const std::string& name)
{
for (auto i = 0; !name.empty() && i < *game::mp::svs_numclients; ++i)
@ -292,6 +305,9 @@ namespace party
// hook disconnect command function
utils::hook::jump(0x14020A010, disconnect_stub);
// detour CL_Disconnect to clear motd
cldisconnect_hook.create(0x140209EC0, cldisconnect_stub);
if (game::environment::is_mp())
{
// show custom drop reason

View File

@ -8,6 +8,7 @@ namespace party
void connect(const game::netadr_s& target);
void start_map(const std::string& mapname);
void clear_sv_motd();
int server_client_count();
int get_client_num_by_name(const std::string& name);