Merge pull request #125 from xerxes-at/develop

Small QOL changes mostly for dedicated server owners.
This commit is contained in:
Maurice Heumann 2021-04-28 16:53:49 +02:00 committed by GitHub
commit bdacfd926f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 2 deletions

View File

@ -9,6 +9,7 @@
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include <utils/memory.hpp>
#include "utils/io.hpp"
namespace command
{
@ -287,14 +288,33 @@ namespace command
console::info("Total %i matches\n", matches.size());
});
add("dvarDump", []()
add("dvarDump", [](const params& argument)
{
console::info("================================ DVAR DUMP ========================================\n");
std::string filename;
if (argument.size() == 2)
{
filename = "s1x/";
filename.append(argument[1]);
if (!filename.ends_with(".txt"))
{
filename.append(".txt");
}
}
for (auto i = 0; i < *game::dvarCount; i++)
{
const auto dvar = game::sortedDvars[i];
if (dvar)
{
if (!filename.empty())
{
//It's 10.2020 and still no std:format in vs :<
std::string line = dvar->name;
line.append("\"");
line.append(game::Dvar_ValueToString(dvar, dvar->current));
line.append("\"\r\n");
utils::io::write_file(filename, line, i != 0);
}
console::info("%s \"%s\"\n", dvar->name,
game::Dvar_ValueToString(dvar, dvar->current));
}
@ -303,15 +323,32 @@ namespace command
console::info("================================ END DVAR DUMP ====================================\n");
});
add("commandDump", []()
add("commandDump", [](const params& argument)
{
console::info("================================ COMMAND DUMP =====================================\n");
game::cmd_function_s* cmd = (*game::cmd_functions);
std::string filename;
if (argument.size() == 2)
{
filename = "s1x/";
filename.append(argument[1]);
if (!filename.ends_with(".txt"))
{
filename.append(".txt");
}
}
int i = 0;
while (cmd)
{
if (cmd->name)
{
if (!filename.empty())
{
//It's 10.2020 and still no std:format in vs :<
std::string line = cmd->name;
line.append("\r\n");
utils::io::write_file(filename, line, i != 0);
}
console::info("%s\n", cmd->name);
i++;
}

View File

@ -8,6 +8,7 @@
namespace map_rotation
{
DWORD previousPriority;
namespace
{
void set_dvar(const std::string& dvar, const std::string& value)
@ -81,6 +82,23 @@ namespace map_rotation
set_dvar("sv_mapRotationCurrent", value);
}
void change_process_priority()
{
auto* const dvar = game::Dvar_FindVar("sv_autoPriority");
if (dvar && dvar->current.enabled)
{
scheduler::on_game_initialized([]()
{
//printf("=======================setting OLD priority=======================\n");
SetPriorityClass(GetCurrentProcess(), previousPriority);
}, scheduler::pipeline::main, 1s);
previousPriority = GetPriorityClass(GetCurrentProcess());
//printf("=======================setting NEW priority=======================\n");
SetPriorityClass(GetCurrentProcess(), NORMAL_PRIORITY_CLASS);
}
}
void perform_map_rotation()
{
if (game::Live_SyncOnlineDataFlags(0) != 0)
@ -103,6 +121,7 @@ namespace map_rotation
else if (key == "map")
{
store_new_rotation(rotation, i + 2);
change_process_priority();
if (!game::SV_MapExists(value.data()))
{
printf("map_rotation: '%s' map doesn't exist!\n", value.data());
@ -134,6 +153,7 @@ namespace map_rotation
return scheduler::cond_end;
}, scheduler::pipeline::main, 1s);
}
}
class component final : public component_interface
@ -150,12 +170,15 @@ namespace map_rotation
{
game::Dvar_RegisterString("sv_mapRotation", "", game::DVAR_FLAG_NONE, "");
game::Dvar_RegisterString("sv_mapRotationCurrent", "", game::DVAR_FLAG_NONE, "");
game::Dvar_RegisterBool("sv_autoPriority", true, game::DVAR_FLAG_NONE, "Lowers the process priority during map changes to not cause lags on other servers.");
}, scheduler::pipeline::main);
command::add("map_rotate", &perform_map_rotation);
// Hook GScr_ExitLevel
utils::hook::jump(0x14032E490, &trigger_map_rotation);
previousPriority = GetPriorityClass(GetCurrentProcess());
}
};
}

View File

@ -302,6 +302,9 @@ namespace patches
// move chat position on the screen above menu splashes
dvars::override::Dvar_RegisterVector2("cg_hudChatPosition", 5, 170, 0, 640, game::DVAR_FLAG_SAVED);
// allow servers to check for new packages more often
dvars::override::Dvar_RegisterInt("sv_network_fps", 1000, 20, 1000, game::DVAR_FLAG_SAVED);
// Massively increate timeouts
dvars::override::Dvar_RegisterInt("cl_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE); // Seems unused
dvars::override::Dvar_RegisterInt("sv_timeout", 90, 90, 1800, game::DVAR_FLAG_NONE); // 30 - 0 - 1800