This commit is contained in:
Federico Cecchetto 2022-03-27 19:29:28 +02:00
parent acf56df54a
commit 59ee7caf42
13 changed files with 41 additions and 181 deletions

View File

@ -1,95 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "chat.hpp"
#include "scheduler.hpp"
#include <utils/string.hpp>
#include <utils/hook.hpp>
#define chat_font game::R_RegisterFont("fonts/fira_mono_regular.ttf", 25)
namespace chat
{
namespace
{
struct message
{
std::string text;
std::chrono::steady_clock::time_point time;
};
std::deque<message> history;
float color_white[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float screen_max[2];
void check_resize()
{
screen_max[0] = game::ScrPlace_GetViewPlacement()->realViewportSize[0];
screen_max[1] = game::ScrPlace_GetViewPlacement()->realViewportSize[1];
}
float relative(float value)
{
const auto ratio = screen_max[0] / 2560.f;
return value * ratio;
}
void draw_chat()
{
check_resize();
const auto now = std::chrono::high_resolution_clock::now();
for (auto i = 0; i < std::min(15, (int)history.size()); i++)
{
if (now - history[i].time > 11s)
{
return;
}
const auto diff = now - history[i].time;
float color[4] = { color_white[0], color_white[1], color_white[2], 1.f };
if (diff > 10.5s)
{
const auto milliseconds = (float)(11000 - std::chrono::duration_cast<std::chrono::milliseconds>(diff).count());
color[3] = (float)(milliseconds / 500.f);
}
game::R_AddCmdDrawText(history[i].text.data(), 0x7FFFFFFF, chat_font, relative(15.f), relative(600.f + i * 25), 1.f, 1.f, 0.f, color, 0);
}
}
}
void print(const std::string& msg)
{
message m;
m.text = msg;
m.time = std::chrono::high_resolution_clock::now();
history.push_front(m);
}
class component final : public component_interface
{
public:
void post_unpack() override
{
scheduler::loop([]()
{
draw_chat();
}, scheduler::pipeline::renderer);
}
};
}
REGISTER_COMPONENT(chat::component)

View File

@ -1,6 +0,0 @@
#pragma once
namespace chat
{
void print(const std::string& msg);
}

View File

@ -9,7 +9,6 @@
#include "command.hpp"
#include "scheduler.hpp"
#include "game_console.hpp"
#include "chat.hpp"
#include "fastfiles.hpp"
#include <utils/hook.hpp>
@ -116,7 +115,9 @@ namespace command
const auto command = utils::string::to_lower(name);
if (handlers.find(command) == handlers.end())
{
add_raw(name, main_handler);
}
handlers[command] = callback;
}
@ -168,11 +169,6 @@ namespace command
utils::hook::invoke<void>(0x1406B3AA0, map, 0, 0, 0, 0);
});
add("say", [](const params& params)
{
chat::print(params.join(1));
});
add("listassetpool", [](const params& params)
{
if (params.size() < 2)
@ -408,7 +404,7 @@ namespace command
try
{
const scripting::entity player = scripting::call("getentbynum", {0}).as<scripting::entity>();
const auto player = scripting::call("getentbynum", {0}).as<scripting::entity>();
if (weapon == "all"s)
{
player.call("takeallweapons");

View File

@ -1,24 +0,0 @@
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "command.hpp"
#include "game_console.hpp"
#include <utils/hook.hpp>
namespace config
{
class component final : public component_interface
{
public:
void post_unpack() override
{
dvars::register_bool("cg_autoUpdate", true, game::DvarFlags::DVAR_FLAG_SAVED);
}
};
}
REGISTER_COMPONENT(config::component)

View File

@ -4,7 +4,6 @@
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "chat.hpp"
#include "scheduler.hpp"
#include "command.hpp"

View File

@ -22,32 +22,31 @@ namespace asset_list
void on_frame()
{
if (!gui::enabled_menus["asset_list"])
static auto* enabled = &gui::enabled_menus["asset_list"];
if (!*enabled)
{
return;
}
ImGui::Begin("Asset list", enabled);
ImGui::InputText("asset type", &asset_type_filter);
ImGui::BeginChild("asset type list");
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
{
ImGui::Begin("Asset list", &gui::enabled_menus["asset_list"]);
const auto name = game::g_assetNames[i];
const auto type = static_cast<game::XAssetType>(i);
ImGui::InputText("asset type", &asset_type_filter);
ImGui::BeginChild("asset type list");
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
if (utils::string::find_lower(name, asset_type_filter))
{
const auto name = game::g_assetNames[i];
const auto type = static_cast<game::XAssetType>(i);
if (utils::string::find_lower(name, asset_type_filter))
{
ImGui::Checkbox(name, &shown_assets[type]);
}
ImGui::Checkbox(name, &shown_assets[type]);
}
ImGui::EndChild();
ImGui::End();
}
ImGui::EndChild();
ImGui::End();
for (auto i = 0; i < game::XAssetType::ASSET_TYPE_COUNT; i++)
{
const auto name = game::g_assetNames[i];

View File

@ -13,7 +13,7 @@
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace gui_console
namespace gui::console
{
namespace
{
@ -52,7 +52,7 @@ namespace gui_console
}
case ImGuiInputTextFlags_CallbackHistory:
{
const auto history = game_console::get_history();
const auto& history = game_console::get_history();
if (data->EventKey == ImGuiKey_UpArrow)
{
@ -96,7 +96,7 @@ namespace gui_console
{
std::string text{};
const auto output = game_console::get_output();
const auto& output = game_console::get_output();
for (const auto& line : output)
{
if (utils::string::find_lower(line, filter))
@ -116,7 +116,8 @@ namespace gui_console
void on_frame()
{
if (!gui::enabled_menus["console"])
static auto* enabled = &gui::enabled_menus["console"];
if (!*enabled)
{
return;
}
@ -126,7 +127,7 @@ namespace gui_console
static const auto input_text_flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackCompletion |
ImGuiInputTextFlags_CallbackHistory;
ImGui::Begin("Console", &gui::enabled_menus["console"]);
ImGui::Begin("Console", enabled);
if (ImGui::BeginPopup("Options"))
{
@ -159,7 +160,7 @@ namespace gui_console
ImGui::BeginChild("console_scroll", ImVec2(0, -footer_height_to_reserve), false);
const auto output = game_console::get_output();
const auto& output = game_console::get_output();
for (const auto& line : output)
{
if (utils::string::find_lower(line, filter))
@ -177,7 +178,7 @@ namespace gui_console
if (ImGui::InputText("Input", &input, input_text_flags, input_text_edit))
{
auto history = game_console::get_history();
auto& history = game_console::get_history();
if (history_index != -1)
{
@ -209,4 +210,4 @@ namespace gui_console
};
}
REGISTER_COMPONENT(gui_console::component)
REGISTER_COMPONENT(gui::console::component)

View File

@ -16,7 +16,7 @@
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace gui_debug
namespace gui::debug
{
namespace
{
@ -403,12 +403,13 @@ namespace gui_debug
void draw_window()
{
if (!gui::enabled_menus["debug"])
static auto* enabled = &gui::enabled_menus["debug"];
if (!*enabled)
{
return;
}
ImGui::Begin("Debug", &gui::enabled_menus["debug"]);
ImGui::Begin("Debug", enabled);
if (ImGui::TreeNode("Path nodes"))
{
@ -724,4 +725,4 @@ namespace gui_debug
};
}
REGISTER_COMPONENT(gui_debug::component)
REGISTER_COMPONENT(gui::debug::component)

View File

@ -15,7 +15,7 @@
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace entity_list
namespace gui::entity_list
{
namespace
{
@ -593,8 +593,9 @@ namespace entity_list
void show_entity_list_window(data_t& data)
{
static auto* enabled = &gui::enabled_menus["entity_list"];
ImGui::SetNextWindowSizeConstraints(ImVec2(500, 500), ImVec2(1000, 1000));
ImGui::Begin("Entity list", &gui::enabled_menus["entity_list"]);
ImGui::Begin("Entity list", enabled);
if (ImGui::Button("Update list"))
{
@ -808,7 +809,8 @@ namespace entity_list
void on_frame()
{
if (!gui::enabled_menus["entity_list"])
static auto* enabled = &gui::enabled_menus["entity_list"];
if (!*enabled)
{
return;
}
@ -858,4 +860,4 @@ namespace entity_list
};
}
REGISTER_COMPONENT(entity_list::component)
REGISTER_COMPONENT(gui::entity_list::component)

View File

@ -15,7 +15,7 @@
#include <utils/hook.hpp>
#include <utils/concurrency.hpp>
namespace gui_script_console
namespace gui::script_console
{
namespace
{
@ -228,4 +228,4 @@ namespace gui_script_console
};
}
REGISTER_COMPONENT(gui_script_console::component)
REGISTER_COMPONENT(gui::script_console::component)

View File

@ -4,7 +4,6 @@
#include "game/game.hpp"
#include "game/dvars.hpp"
#include "chat.hpp"
#include "scheduler.hpp"
#include "command.hpp"

View File

@ -70,16 +70,6 @@ namespace updater
return main;
}
std::string get_data_path()
{
if (GIT_BRANCH == "develop"s)
{
return DATA_PATH_DEV;
}
return DATA_PATH;
}
void set_update_check_status(bool done, bool success, const std::string& error = {})
{
update_data.access([done, success, error](update_data_t& data_)

View File

@ -9,7 +9,6 @@
#include "../../../component/notifies.hpp"
#include "../../../component/scripting.hpp"
#include "../../../component/command.hpp"
#include "../../../component/chat.hpp"
#include "../../../component/fastfiles.hpp"
#include <utils/string.hpp>
@ -377,9 +376,8 @@ namespace scripting::lua
command::execute(utils::string::va("setdiscordstate %s", state.data()), false);
};
game_type["say"] = [](const game&, const std::string& msg)
game_type["say"] = [](const game&)
{
chat::print(msg);
};
game_type["detour"] = [](const game&, const sol::this_state s, const std::string& filename,