More usermap fixes

This commit is contained in:
fed 2022-10-12 23:40:17 +02:00
parent c0c0d40533
commit 803973d29e
5 changed files with 37 additions and 24 deletions

View File

@ -232,7 +232,7 @@ namespace fastfiles
}
utils::hook::detour sys_createfile_hook;
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
HANDLE sys_create_file(game::Sys_Folder folder, const char* base_filename, bool ignore_usermap)
{
const auto* fs_basepath = game::Dvar_FindVar("fs_basepath");
const auto* fs_game = game::Dvar_FindVar("fs_game");
@ -264,10 +264,13 @@ namespace fastfiles
return handle;
}
const auto usermap = find_usermap(name);
if (usermap != INVALID_HANDLE_VALUE)
if (!ignore_usermap)
{
return usermap;
const auto usermap = find_usermap(name);
if (usermap != INVALID_HANDLE_VALUE)
{
return usermap;
}
}
if (name.ends_with(".ff"))
@ -278,6 +281,11 @@ namespace fastfiles
return handle;
}
HANDLE sys_create_file_stub(game::Sys_Folder folder, const char* base_filename)
{
return sys_create_file(folder, base_filename, false);
}
utils::hook::detour db_file_exists_hook;
bool db_file_exists_stub(const char* file, int a2)
{
@ -396,11 +404,11 @@ namespace fastfiles
}
}
bool exists(const std::string& zone)
bool exists(const std::string& zone, bool ignore_usermap)
{
const auto is_localized = game::DB_IsLocalized(zone.data());
const auto handle = game::Sys_CreateFile((is_localized ? game::SF_ZONE_LOC : game::SF_ZONE),
utils::string::va("%s.ff", zone.data()));
const auto handle = sys_create_file((is_localized ? game::SF_ZONE_LOC : game::SF_ZONE),
utils::string::va("%s.ff", zone.data()), ignore_usermap);
if (handle != INVALID_HANDLE_VALUE)
{
@ -474,15 +482,7 @@ namespace fastfiles
bool is_stock_map(const std::string& name)
{
for (auto map = &game::maps[0]; map->unk; ++map)
{
if (map->name == name)
{
return true;
}
}
return false;
return fastfiles::exists(name, true);
}
class component final : public component_interface

View File

@ -4,7 +4,7 @@
namespace fastfiles
{
bool exists(const std::string& zone);
bool exists(const std::string& zone, bool ignore_usermap = false);
std::string get_current_fastfile();

View File

@ -151,10 +151,14 @@ namespace party
utils::hook::detour cl_disconnect_hook;
void cl_disconnect_stub(int showMainMenu) // possibly bool
void cl_disconnect_stub(int show_main_menu) // possibly bool
{
party::clear_sv_motd();
cl_disconnect_hook.invoke<void>(showMainMenu);
if (!game::VirtualLobby_Loaded())
{
fastfiles::clear_usermap();
}
cl_disconnect_hook.invoke<void>(show_main_menu);
}
std::optional<std::string> get_file_hash(const std::string& file)
@ -288,7 +292,7 @@ namespace party
catch (const std::exception& e)
{
menu_error(e.what());
return false;
return true;
}
return false;
@ -301,11 +305,11 @@ namespace party
const std::string usermap_hash = game::MSG_ReadStringLine(msg,
buffer, static_cast<unsigned int>(sizeof(buffer)));
if (!fastfiles::is_stock_map(mapname))
if (!game::SV_Loaded() && !fastfiles::is_stock_map(mapname))
{
const auto filename = utils::string::va("usermaps\\%s\\%s.ff", mapname, mapname);
const auto hash = get_file_hash(filename);
if (!hash.has_value() || hash.value() != usermap_hash)
if (!hash.has_value() || (usermap_hash.empty() || hash.value() != usermap_hash))
{
command::execute("disconnect");
scheduler::once([]
@ -837,13 +841,15 @@ namespace party
if (!fastfiles::is_stock_map(mapname))
{
const auto hash = get_file_hash(utils::string::va("usermaps/%s/%s.ff", mapname.data(), mapname.data()));
const auto hash = get_file_hash(
utils::string::va("usermaps\\%s\\%s.ff", mapname.data(), mapname.data()));
if (hash.has_value())
{
info.set("usermaphash", hash.value());
}
const auto load_file_hash = get_file_hash(utils::string::va("usermaps/%s/%s_load.ff", mapname.data(), mapname.data()));
const auto load_file_hash = get_file_hash(
utils::string::va("usermaps\\%s\\%s_load.ff", mapname.data(), mapname.data()));
if (load_file_hash.has_value())
{
info.set("usermaploadhash", load_file_hash.value());

View File

@ -180,4 +180,9 @@ namespace utils::string
if (!exact && text.find(input) != std::string::npos) return true;
return false;
}
bool is_numeric(const std::string& text)
{
return std::to_string(atoi(text.data())) == text;
}
}

View File

@ -99,4 +99,6 @@ namespace utils::string
std::string replace(std::string str, const std::string& from, const std::string& to);
bool match_compare(const std::string& input, const std::string& text, const bool exact);
bool is_numeric(const std::string& text);
}