register fs game path on fs startup [skip ci]
This commit is contained in:
parent
df2900e1b2
commit
e7972a270d
@ -108,28 +108,6 @@ namespace command
|
|||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void register_fs_game_path()
|
|
||||||
{
|
|
||||||
static const auto* fs_game = game::Dvar_FindVar("fs_game");
|
|
||||||
const auto new_mod_path = fs_game->current.string;
|
|
||||||
|
|
||||||
// check if the last saved fs_game value isn't empty and if it doesn't equal the new fs_game
|
|
||||||
if (!saved_fs_game.empty() && saved_fs_game != new_mod_path)
|
|
||||||
{
|
|
||||||
// unregister path to be used as a fs directory
|
|
||||||
filesystem::unregister_path(saved_fs_game);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_mod_path && !new_mod_path[0])
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// register fs_game value as a fs directory used for many things
|
|
||||||
filesystem::register_path(new_mod_path);
|
|
||||||
saved_fs_game = new_mod_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
void parse_startup_variables()
|
void parse_startup_variables()
|
||||||
{
|
{
|
||||||
auto& com_num_console_lines = *reinterpret_cast<int*>(0x35634B8_b);
|
auto& com_num_console_lines = *reinterpret_cast<int*>(0x35634B8_b);
|
||||||
@ -417,24 +395,6 @@ namespace command
|
|||||||
? "^2on"
|
? "^2on"
|
||||||
: "^1off"));
|
: "^1off"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void monitor_fs_game_values()
|
|
||||||
{
|
|
||||||
dvars::callback::on_register("fs_game", []()
|
|
||||||
{
|
|
||||||
register_fs_game_path();
|
|
||||||
});
|
|
||||||
|
|
||||||
// it might be overdone to change the filesystem path on every new value change, but to be fair,
|
|
||||||
// for the mods that don't need full restarts, this is good because it'll adjust and work like so
|
|
||||||
// in my opinion, this is fine. if a user tries to modify the dvar themselves, they'll have problems
|
|
||||||
// but i seriously doubt it'll be bad.
|
|
||||||
dvars::callback::on_new_value("fs_game", []()
|
|
||||||
{
|
|
||||||
console::warn("fs_game value changed, filesystem paths will be adjusted to new dvar value.");
|
|
||||||
register_fs_game_path();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_startup_variable(const std::string& dvar)
|
void read_startup_variable(const std::string& dvar)
|
||||||
@ -597,13 +557,42 @@ namespace command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void register_fs_game_path()
|
||||||
|
{
|
||||||
|
const auto* fs_game = game::Dvar_FindVar("fs_game");
|
||||||
|
const auto new_mod_path = fs_game->current.string;
|
||||||
|
|
||||||
|
// check if the last saved fs_game value isn't empty and if it doesn't equal the new fs_game
|
||||||
|
if (!saved_fs_game.empty() && saved_fs_game != new_mod_path)
|
||||||
|
{
|
||||||
|
// unregister path to be used as a fs directory
|
||||||
|
filesystem::unregister_path(saved_fs_game);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_mod_path && !new_mod_path[0])
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// register fs_game value as a fs directory used for many things
|
||||||
|
filesystem::register_path(new_mod_path);
|
||||||
|
saved_fs_game = new_mod_path;
|
||||||
|
}
|
||||||
|
|
||||||
class component final : public component_interface
|
class component final : public component_interface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
// monitor fs_game register and new value changes to adjust our paths for searching
|
// it might be overdone to change the filesystem path on every new value change, but to be fair,
|
||||||
monitor_fs_game_values();
|
// for the mods that don't need full restarts, this is good because it'll adjust and work like so
|
||||||
|
// in my opinion, this is fine. if a user tries to modify the dvar themselves, they'll have problems
|
||||||
|
// but i seriously doubt it'll be bad.
|
||||||
|
dvars::callback::on_new_value("fs_game", []()
|
||||||
|
{
|
||||||
|
console::warn("fs_game value changed, filesystem paths will be adjusted to new dvar value.");
|
||||||
|
register_fs_game_path();
|
||||||
|
});
|
||||||
|
|
||||||
if (game::environment::is_sp())
|
if (game::environment::is_sp())
|
||||||
{
|
{
|
||||||
|
@ -49,4 +49,6 @@ namespace command
|
|||||||
void add_sv(const char* name, std::function<void(int, const params_sv&)> callback);
|
void add_sv(const char* name, std::function<void(int, const params_sv&)> callback);
|
||||||
|
|
||||||
void execute(std::string command, bool sync = false);
|
void execute(std::string command, bool sync = false);
|
||||||
|
|
||||||
|
void register_fs_game_path();
|
||||||
}
|
}
|
@ -171,8 +171,8 @@ namespace fastfiles
|
|||||||
utils::hook::detour sys_createfile_hook;
|
utils::hook::detour sys_createfile_hook;
|
||||||
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
|
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
|
||||||
{
|
{
|
||||||
static const auto* fs_basepath = game::Dvar_FindVar("fs_basepath");
|
const auto* fs_basepath = game::Dvar_FindVar("fs_basepath");
|
||||||
static const auto* fs_game = game::Dvar_FindVar("fs_game");
|
const auto* fs_game = game::Dvar_FindVar("fs_game");
|
||||||
|
|
||||||
std::string dir = fs_basepath ? fs_basepath->current.string : "";
|
std::string dir = fs_basepath ? fs_basepath->current.string : "";
|
||||||
std::string mod_dir = fs_game ? fs_game->current.string : "";
|
std::string mod_dir = fs_game ? fs_game->current.string : "";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <std_include.hpp>
|
#include <std_include.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include "command.hpp"
|
||||||
#include "console.hpp"
|
#include "console.hpp"
|
||||||
#include "filesystem.hpp"
|
#include "filesystem.hpp"
|
||||||
#include "localized_strings.hpp"
|
#include "localized_strings.hpp"
|
||||||
@ -46,6 +47,8 @@ namespace filesystem
|
|||||||
filesystem::register_path(L"h1-mod");
|
filesystem::register_path(L"h1-mod");
|
||||||
|
|
||||||
fs_startup_hook.invoke<void>(name);
|
fs_startup_hook.invoke<void>(name);
|
||||||
|
|
||||||
|
command::register_fs_game_path();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::filesystem::path> get_paths(const std::filesystem::path& path)
|
std::vector<std::filesystem::path> get_paths(const std::filesystem::path& path)
|
||||||
|
Loading…
Reference in New Issue
Block a user