Fixes & cleanup

This commit is contained in:
Federico Cecchetto 2021-12-28 17:14:47 +01:00
parent 7b8e9c9bf1
commit d947d461f5
12 changed files with 72 additions and 91 deletions

View File

@ -30,8 +30,8 @@ namespace console
{
while (!kill)
{
// to do: get input and shit without blocking the thread
std::this_thread::sleep_for(1s);
// to do: get input without blocking the thread
std::this_thread::sleep_for(1ms);
}
std::this_thread::yield();

View File

@ -235,8 +235,7 @@ namespace exception
void post_unpack() override
{
dvars::cg_legacyCrashHandling = dvars::register_bool("cg_legacyCrashHandling", false,
game::DVAR_FLAG_SAVED, "Disable new crash handling");
dvars::cg_legacyCrashHandling = dvars::register_bool("cg_legacyCrashHandling", false, game::DVAR_FLAG_SAVED);
}
};
}

View File

@ -263,7 +263,7 @@ namespace fps
void post_unpack() override
{
cg_drawSpeed = dvars::register_int("cg_drawSpeed", 0, 0, 2, game::DVAR_FLAG_SAVED);
cg_drawFps = dvars::register_int("cg_drawFPS", 0, 0, 4, game::DVAR_FLAG_SAVED, false);
cg_drawFps = dvars::register_int("cg_drawFPS", 0, 0, 4, game::DVAR_FLAG_SAVED);
cg_speedGraph = dvars::register_bool("cg_speedGraph", false, game::DVAR_FLAG_SAVED);

View File

@ -55,7 +55,7 @@ namespace game_console
std::deque<std::string> history;
std::string fixed_input;
std::vector<std::string> matches;
std::unordered_set<std::string> matches;
float color_white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
float color_h2[4] = {0.9f, 0.9f, 0.5f, 1.0f};
@ -242,11 +242,12 @@ namespace game_console
}
else if (matches.size() == 1)
{
auto* const dvar = game::Dvar_FindVar(matches[0].data());
const auto first = *matches.begin();
auto* const dvar = game::Dvar_FindVar(first.data());
const auto line_count = dvar ? 2 : 1;
draw_hint_box(line_count, dvars::con_inputHintBoxColor->current.vector);
draw_hint_text(0, matches[0].data(),
draw_hint_text(0, first.data(),
dvar
? dvars::con_inputDvarMatchColor->current.vector
: dvars::con_inputCmdMatchColor->current.vector);
@ -262,7 +263,7 @@ namespace game_console
dvars::con_inputDvarInactiveValueColor->current.vector, offset);
}
strncpy_s(con.globals.auto_complete_choice, matches[0].data(), 64);
strncpy_s(con.globals.auto_complete_choice, first.data(), 64);
con.globals.may_auto_complete = true;
}
else if (matches.size() > 1)
@ -271,23 +272,26 @@ namespace game_console
const auto offset = (con.screen_max[0] - con.globals.x) / 2.5f;
for (size_t i = 0; i < matches.size(); i++)
auto index = 0;
for (const auto& match : matches)
{
auto* const dvar = game::Dvar_FindVar(matches[i].data());
auto* const dvar = game::Dvar_FindVar(match.data());
draw_hint_text(static_cast<int>(i), matches[i].data(),
draw_hint_text(static_cast<int>(index), match.data(),
dvar
? dvars::con_inputDvarMatchColor->current.vector
: dvars::con_inputCmdMatchColor->current.vector);
if (dvar)
{
draw_hint_text(static_cast<int>(i), game::Dvar_ValueToString(dvar, nullptr, &dvar->current),
draw_hint_text(static_cast<int>(index), game::Dvar_ValueToString(dvar, nullptr, &dvar->current),
dvars::con_inputDvarValueColor->current.vector, offset);
}
index++;
}
strncpy_s(con.globals.auto_complete_choice, matches[0].data(), 64);
strncpy_s(con.globals.auto_complete_choice, matches.begin()->data(), 64);
con.globals.may_auto_complete = true;
}
}
@ -638,7 +642,7 @@ namespace game_console
return true;
}
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact)
void find_matches(std::string input, std::unordered_set<std::string>& suggestions, const bool exact)
{
input = utils::string::to_lower(input);
@ -647,7 +651,7 @@ namespace game_console
auto name = utils::string::to_lower(dvar);
if (match_compare(input, name, exact))
{
suggestions.push_back(dvar);
suggestions.insert(dvar);
}
if (exact && suggestions.size() > 1)
@ -658,7 +662,7 @@ namespace game_console
if (suggestions.size() == 0 && game::Dvar_FindVar(input.data()))
{
suggestions.push_back(input.data());
suggestions.insert(input.data());
}
game::cmd_function_s* cmd = (*game::cmd_functions);
@ -670,7 +674,7 @@ namespace game_console
if (match_compare(input, name, exact))
{
suggestions.push_back(cmd->name);
suggestions.insert(cmd->name);
}
if (exact && suggestions.size() > 1)

View File

@ -16,7 +16,7 @@ namespace game_console
bool console_char_event(int local_client_num, int key);
bool console_key_event(int local_client_num, int key, int down);
void find_matches(std::string input, std::vector<std::string>& suggestions, const bool exact);
void find_matches(std::string input, std::unordered_set<std::string>& suggestions, const bool exact);
void execute(const char* cmd);
void clear_console();
void add(const std::string& cmd, bool print_ = true);

View File

@ -11,6 +11,7 @@ namespace gameplay
namespace
{
utils::hook::detour pm_player_trace_hook;
utils::hook::detour pm_crashland_hook;
void pm_player_trace_stub(game::pmove_t* pm, game::trace_t* trace, const float* f3,
const float* f4, const game::Bounds* bounds, int a6, int a7)
@ -50,6 +51,14 @@ namespace gameplay
a.bind(allsolid);
a.jmp(0x6878D4_b);
}
void pm_crashland_stub(void* ps, void* pm)
{
if (dvars::jump_enableFallDamage->current.enabled)
{
pm_crashland_hook.invoke<void>(ps, pm);
}
}
}
class component final : public component_interface
@ -57,14 +66,20 @@ namespace gameplay
public:
void post_unpack() override
{
dvars::g_enableElevators = dvars::register_bool("g_enableElevators", false,
game::DvarFlags::DVAR_FLAG_NONE, true);
dvars::g_enableElevators = dvars::register_bool("g_enableElevators", false, game::DvarFlags::DVAR_FLAG_NONE);
dvars::jump_enableFallDamage = dvars::register_bool("jump_enableFallDamage", true, game::DVAR_FLAG_REPLICATED);
// Influence PM_JitterPoint code flow so the trace->startsolid checks are 'ignored'
pm_player_trace_hook.create(0x068F0A0_b, &pm_player_trace_stub);
// If g_enableElevators is 1 the 'ducked' flag will always be removed from the player state
utils::hook::jump(0x6878C1_b, utils::hook::assemble(pm_trace_stub), true);
pm_crashland_hook.create(0x688A20_b, pm_crashland_stub);
dvars::register_float("jump_height", 39, 0, 1000, game::DVAR_FLAG_REPLICATED);
dvars::register_float("g_gravity", 800, 1, 1000, game::DVAR_FLAG_REPLICATED);
dvars::register_int("g_speed", 190, 0, 1000, game::DVAR_FLAG_REPLICATED);
}
};
}

View File

@ -16,8 +16,8 @@ namespace asset_list
namespace
{
bool shown_assets[game::XAssetType::ASSET_TYPE_COUNT];
std::string asset_type_filter{};
std::string assets_name_filter{};
std::string asset_type_filter;
std::string assets_name_filter;
void enum_assets(const game::XAssetType type, const std::function<void(game::XAssetHeader)>& callback, const bool includeOverride)
{

View File

@ -19,9 +19,9 @@ namespace gui_console
{
bool auto_scroll = true;
int history_index = -1;
std::string input{};
std::string filter{};
std::vector<std::string> matches{};
std::string input;
std::string filter;
std::unordered_set<std::string> matches;
int input_text_edit(ImGuiInputTextCallbackData* data)
{
@ -41,9 +41,9 @@ namespace gui_console
game_console::find_matches(text, matches, false);
}
if (matches.size() < 24)
if (matches.size() < 24 && matches.size() > 0)
{
const auto match = matches[0].data();
const auto match = matches.begin()->data();
data->DeleteChars(0, data->BufTextLen);
data->InsertChars(0, match, match + strlen(match));
}

View File

@ -55,21 +55,21 @@ namespace entity_list
struct filters_t
{
bool filter_by_range{};
float range{};
entity_team team{};
entity_type type{};
bool filter_by_range;
float range;
entity_team team;
entity_type type;
std::vector<std::pair<std::string, std::string>> fields;
};
struct data_t
{
bool auto_update{};
bool force_update{};
bool auto_update;
bool force_update;
filters_t filters;
std::chrono::milliseconds interval{};
std::chrono::high_resolution_clock::time_point last_call{};
std::vector<entity_info_t> entity_info{};
std::chrono::milliseconds interval;
std::chrono::high_resolution_clock::time_point last_call;
std::vector<entity_info_t> entity_info;
std::vector<std::function<void()>> tasks;
std::unordered_map<std::string, bool> selected_fields =
{
@ -277,7 +277,7 @@ namespace entity_list
};
};
utils::concurrency::container<data_t> data_;
utils::concurrency::container<data_t> data_{};
unsigned int selected_entity{};
bool set_field_window{};
bool selected_fields_window{};

View File

@ -10,23 +10,13 @@ namespace patches
{
namespace
{
utils::hook::detour pm_crashland_hook;
void pm_crashland_stub(void* ps, void* pm)
{
if (dvars::jump_enableFallDamage->current.enabled)
{
pm_crashland_hook.invoke<void>(ps, pm);
}
}
void* sub_46148()
{
static uint64_t off_11C52460 = 0xAD0C58_b;
return &off_11C52460;
}
DECLSPEC_NORETURN void quit_stub(const int code)
DECLSPEC_NORETURN void quit_stub()
{
component_loader::pre_destroy();
exit(0);
@ -38,7 +28,7 @@ namespace patches
public:
void post_unpack() override
{
// Not sure but it works
// Fix startup crashes
utils::hook::set(0x633080_b, 0xC301B0);
utils::hook::set(0x272F70_b, 0xC301B0);
utils::hook::jump(0x46148_b, sub_46148, true);
@ -50,13 +40,6 @@ namespace patches
// Disable battle net popup
utils::hook::nop(0x5F4496_b, 5);
pm_crashland_hook.create(0x688A20_b, pm_crashland_stub);
dvars::jump_enableFallDamage = dvars::register_bool("jump_enableFallDamage", 1, game::DVAR_FLAG_REPLICATED);
dvars::register_float("jump_height", 39, 0, 1000, game::DVAR_FLAG_REPLICATED);
dvars::register_float("g_gravity", 800, 1, 1000, game::DVAR_FLAG_REPLICATED);
dvars::register_int("g_speed", 190, 0, 1000, game::DVAR_FLAG_REPLICATED);
}
};
}

View File

@ -125,7 +125,7 @@ namespace dvars
}
}
std::vector<std::string> dvar_list =
std::unordered_set<std::string> dvar_list =
{
"ai_corpseLimit",
"band_12players",
@ -1163,54 +1163,34 @@ namespace dvars
};
game::dvar_t* register_int(const std::string& name, int value, int min, int max,
game::DvarFlags flags, bool add_to_list)
game::DvarFlags flags)
{
dvar_list.insert(name);
const auto hash = game::generateHashValue(name.data());
if (add_to_list)
{
dvar_list.push_back(name);
}
return game::Dvar_RegisterInt(hash, "", value, min, max, flags);
}
game::dvar_t* register_bool(const std::string& name, bool value,
game::DvarFlags flags, bool add_to_list)
game::DvarFlags flags)
{
dvar_list.insert(name);
const auto hash = game::generateHashValue(name.data());
if (add_to_list)
{
dvar_list.push_back(name);
}
return game::Dvar_RegisterBool(hash, "", value, flags);
}
game::dvar_t* register_float(const std::string& name, float value, float min,
float max, game::DvarFlags flags, bool add_to_list)
float max, game::DvarFlags flags)
{
dvar_list.insert(name);
const auto hash = game::generateHashValue(name.data());
if (add_to_list)
{
dvar_list.push_back(name);
}
return game::Dvar_RegisterFloat(hash, "", value, min, max, flags);
}
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z,
float w, float min, float max, game::DvarFlags flags, bool add_to_list)
float w, float min, float max, game::DvarFlags flags)
{
dvar_list.insert(name);
const auto hash = game::generateHashValue(name.data());
if (add_to_list)
{
dvar_list.push_back(name);
}
return game::Dvar_RegisterVec4(hash, "", x, y, z, w, min, max, flags);
}
}

View File

@ -24,13 +24,13 @@ namespace dvars
extern game::dvar_t* g_enableElevators;
extern std::vector<std::string> dvar_list;
extern std::unordered_set<std::string> dvar_list;
std::string dvar_get_vector_domain(const int components, const game::dvar_limits& domain);
std::string dvar_get_domain(const game::dvar_type type, const game::dvar_limits& domain);
game::dvar_t* register_int(const std::string& name, int value, int min, int max, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_bool(const std::string& name, bool value, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z, float w, float min, float max, game::DvarFlags flags, bool add_to_list = true);
game::dvar_t* register_int(const std::string& name, int value, int min, int max, game::DvarFlags flags);
game::dvar_t* register_bool(const std::string& name, bool value, game::DvarFlags flags);
game::dvar_t* register_float(const std::string& name, float value, float min, float max, game::DvarFlags flags);
game::dvar_t* register_vec4(const std::string& name, float x, float y, float z, float w, float min, float max, game::DvarFlags flags);
}