Some fixes
This commit is contained in:
@ -95,7 +95,7 @@ namespace bots
|
||||
num_bots = atoi(params.get(1));
|
||||
}
|
||||
|
||||
num_bots = std::min(num_bots, *game::mp::svs_numclients);;
|
||||
num_bots = std::min(num_bots, *game::mp::svs_numclients);
|
||||
|
||||
for (auto i = 0; i < num_bots; i++)
|
||||
{
|
||||
|
@ -126,12 +126,16 @@ namespace dedicated
|
||||
|
||||
void kill_server()
|
||||
{
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients != nullptr)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 3)
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
game::SV_GameSendServerCommand(i, game::SV_CMD_CAN_IGNORE,
|
||||
utils::string::va("r \"%s\"", "EXE_ENDOFGAME"));
|
||||
if (svs_clients[i].header.state >= 3)
|
||||
{
|
||||
game::SV_GameSendServerCommand(i, game::SV_CMD_CAN_IGNORE,
|
||||
utils::string::va("r \"%s\"", "EXE_ENDOFGAME"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,6 +160,34 @@ namespace dedicated
|
||||
|
||||
game::Com_Error(game::ERR_DROP, "%s", buffer);
|
||||
}
|
||||
|
||||
utils::hook::detour ui_set_active_menu_hook;
|
||||
void ui_set_active_menu_stub(void* a1, int a2)
|
||||
{
|
||||
static auto done = false;
|
||||
if (done && (a2 == 6 || a2 == 7))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (a2 == 6 || a2 == 7)
|
||||
{
|
||||
done = true;
|
||||
}
|
||||
|
||||
ui_set_active_menu_hook.invoke<void>(a1, a2);
|
||||
}
|
||||
|
||||
utils::hook::detour sub_552830_hook;
|
||||
void* sub_552830_stub()
|
||||
{
|
||||
// sub_554D00 svs_clients along with other svs stuff
|
||||
// Upon loading a 2nd map (ex. doing map mp_bog; map mp_crash) sub_552830 is called instead of sub_554D00
|
||||
// But svs stuff is already deallocated so it will read bad memory -> crash
|
||||
// Calling sub_554D00 makes sure it reallocates that stuff first
|
||||
utils::hook::invoke<void>(0x554D00_b);
|
||||
return sub_552830_hook.invoke<void*>();
|
||||
}
|
||||
}
|
||||
|
||||
void initialize()
|
||||
@ -292,6 +324,11 @@ namespace dedicated
|
||||
utils::hook::set<uint8_t>(0x1D48B0_b, 0xC3); // related to shader caching / techsets / fastfilesc
|
||||
utils::hook::set<uint8_t>(0x3A1940_b, 0xC3); // DB_ReadPackedLoadedSounds
|
||||
|
||||
// Workaround for server spamming 'exec default_xboxlive.cfg' when not running
|
||||
ui_set_active_menu_hook.create(0x1E4D80_b, ui_set_active_menu_stub);
|
||||
|
||||
sub_552830_hook.create(0x552830_b, sub_552830_stub);
|
||||
|
||||
// initialize the game after onlinedataflags is 32 (workaround)
|
||||
scheduler::schedule([=]()
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ namespace dedicated_info
|
||||
scheduler::loop([]()
|
||||
{
|
||||
auto* sv_running = game::Dvar_FindVar("sv_running");
|
||||
if (!sv_running || !sv_running->current.enabled)
|
||||
if (!sv_running || !sv_running->current.enabled || (*game::mp::svs_clients) == nullptr)
|
||||
{
|
||||
SetConsoleTitle("H1-Mod Dedicated Server");
|
||||
return;
|
||||
@ -32,12 +32,14 @@ namespace dedicated_info
|
||||
auto bot_count = 0;
|
||||
auto client_count = 0;
|
||||
|
||||
for (auto i = 0; i < sv_maxclients->current.integer; i++)
|
||||
const auto svs_clients = *game::mp::svs_clients;
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; i++)
|
||||
{
|
||||
auto* client = &game::mp::svs_clients[i];
|
||||
const auto client = svs_clients[i];
|
||||
auto* self = &game::mp::g_entities[i];
|
||||
|
||||
if (client->header.state >= 1 && self && self->client)
|
||||
if (client.header.state >= 1 && self && self->client)
|
||||
{
|
||||
client_count++;
|
||||
if (game::SV_BotIsBot(i))
|
||||
@ -54,8 +56,9 @@ namespace dedicated_info
|
||||
static_cast<int>(strlen(sv_hostname->current.string)) + 1);
|
||||
|
||||
SetConsoleTitle(utils::string::va("%s on %s [%d/%d] (%d)", cleaned_hostname.data(),
|
||||
mapname->current.string, client_count,
|
||||
sv_maxclients->current.integer, bot_count));
|
||||
mapname->current.string, client_count,
|
||||
sv_maxclients->current.integer, bot_count)
|
||||
);
|
||||
}, scheduler::pipeline::main, 1s);
|
||||
}
|
||||
};
|
||||
|
@ -122,28 +122,28 @@ namespace party
|
||||
utils::hook::invoke<void>(0x1404FB210, dvar_name, string);
|
||||
}
|
||||
|
||||
void disconnect_stub()
|
||||
void disconnect()
|
||||
{
|
||||
if (!game::VirtualLobby_Loaded())
|
||||
{
|
||||
if (game::CL_IsCgameInitialized())
|
||||
{
|
||||
// CL_ForwardCommandToServer
|
||||
// utils::hook::invoke<void>(0x140253480, 0, "disconnect");
|
||||
// CL_AddReliableCommand
|
||||
utils::hook::invoke<void>(0x12B810_b, 0, "disconnect");
|
||||
// CL_WritePacket
|
||||
// utils::hook::invoke<void>(0x14024DB10, 0);
|
||||
utils::hook::invoke<void>(0x13D490_b, 0);
|
||||
}
|
||||
// CL_Disconnect
|
||||
// utils::hook::invoke<void>(0x140252060, 0);
|
||||
utils::hook::invoke<void>(0x12F080_b, 0);
|
||||
}
|
||||
}
|
||||
|
||||
utils::hook::detour cldisconnect_hook;
|
||||
utils::hook::detour cl_disconnect_hook;
|
||||
|
||||
void cl_disconnect_stub(int a1)
|
||||
{
|
||||
party::clear_sv_motd();
|
||||
cldisconnect_hook.invoke<void>(a1);
|
||||
cl_disconnect_hook.invoke<void>(a1);
|
||||
}
|
||||
|
||||
const auto drop_reason_stub = utils::hook::assemble([](utils::hook::assembler& a)
|
||||
@ -192,9 +192,15 @@ namespace party
|
||||
int get_client_count()
|
||||
{
|
||||
auto count = 0;
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 1)
|
||||
if (svs_clients[i].header.state >= 1)
|
||||
{
|
||||
++count;
|
||||
}
|
||||
@ -206,9 +212,15 @@ namespace party
|
||||
int get_bot_count()
|
||||
{
|
||||
auto count = 0;
|
||||
const auto* svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
for (auto i = 0; i < *game::mp::svs_numclients; ++i)
|
||||
{
|
||||
if (game::mp::svs_clients[i].header.state >= 1 &&
|
||||
if (svs_clients[i].header.state >= 1 &&
|
||||
game::SV_BotIsBot(i))
|
||||
{
|
||||
++count;
|
||||
@ -316,21 +328,20 @@ namespace party
|
||||
return;
|
||||
}
|
||||
|
||||
// hook disconnect command function
|
||||
// utils::hook::jump(0x1402521C7, disconnect_stub);
|
||||
|
||||
// detour CL_Disconnect to clear motd
|
||||
// cldisconnect_hook.create(0x140252060, cl_disconnect_stub);
|
||||
cl_disconnect_hook.create(0x12F080_b, cl_disconnect_stub);
|
||||
|
||||
if (game::environment::is_mp())
|
||||
{
|
||||
// show custom drop reason
|
||||
// utils::hook::nop(0x12EF4E_b, 13);
|
||||
// utils::hook::jump(0x12EF4E_b, drop_reason_stub, true);
|
||||
|
||||
command::add("disconnect", disconnect);
|
||||
}
|
||||
|
||||
// enable custom kick reason in GScr_KickPlayer
|
||||
// utils::hook::set<uint8_t>(0xE423D_b, 0xEB);
|
||||
utils::hook::set<uint8_t>(0xE423D_b, 0xEB);
|
||||
|
||||
command::add("map", [](const command::params& argument)
|
||||
{
|
||||
|
@ -115,12 +115,19 @@ namespace patches
|
||||
utils::hook::detour cmd_lui_notify_server_hook;
|
||||
void cmd_lui_notify_server_stub(game::mp::gentity_s* ent)
|
||||
{
|
||||
const auto svs_clients = *game::mp::svs_clients;
|
||||
if (svs_clients == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
command::params_sv params{};
|
||||
const auto menu_id = atoi(params.get(1));
|
||||
const auto client = &game::mp::svs_clients[ent->s.entityNum];
|
||||
const auto client = svs_clients[ent->s.entityNum];
|
||||
|
||||
// 22 => "end_game"
|
||||
if (menu_id == 22 && client->header.remoteAddress.type != game::NA_LOOPBACK)
|
||||
if (menu_id == 22 && client.header.remoteAddress.type != game::NA_LOOPBACK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -217,10 +224,10 @@ namespace patches
|
||||
dvars::override::register_int("data_validation_allow_drop", 0, 0, 0, game::DVAR_FLAG_NONE);
|
||||
|
||||
// Patch SV_KickClientNum
|
||||
/*sv_kick_client_num_hook.create(0x14047ED00, &sv_kick_client_num);
|
||||
sv_kick_client_num_hook.create(game::SV_KickClientNum, &sv_kick_client_num);
|
||||
|
||||
// block changing name in-game
|
||||
utils::hook::set<uint8_t>(0x14047FC90, 0xC3);
|
||||
/*utils::hook::set<uint8_t>(0x14047FC90, 0xC3);
|
||||
|
||||
// patch "Couldn't find the bsp for this map." error to not be fatal in mp
|
||||
utils::hook::call(0x1402BA26B, bsp_sys_error_stub);
|
||||
|
Reference in New Issue
Block a user