Small fix

This commit is contained in:
Federico Cecchetto 2022-06-28 12:33:49 +02:00
parent 4e648df210
commit 68e599f134
4 changed files with 11 additions and 6 deletions

View File

@ -226,7 +226,8 @@ namespace mapents
std::optional<std::string> get_mapents_data(std::string* real_path = nullptr)
{
std::string data{};
if (filesystem::read_file("addon_map_ents/"s + addon_mapname->current.string + ".mapents"s, &data, real_path))
if (addon_mapname->current.string != ""s &&
filesystem::read_file("addon_map_ents/"s + addon_mapname->current.string + ".mapents"s, &data, real_path))
{
return {data};
}
@ -271,10 +272,7 @@ namespace mapents
game::XAssetHeader db_find_xasset_header_stub(game::XAssetType type, const char* name, int allow_create_default)
{
const auto _0 = gsl::finally([]()
{
game::Dvar_SetFromStringFromSource("addon_mapname", "", game::DVAR_SOURCE_INTERNAL);
});
const auto _0 = gsl::finally(&mapents::clear_dvars);
const auto mapents = allocator.allocate<game::AddonMapEnts>();
mapents->name = allocator.duplicate_string(name);
@ -313,9 +311,13 @@ namespace mapents
}
}
void clear_dvars()
{
game::Dvar_SetString(addon_mapname, "");
}
void clear()
{
game::Dvar_SetFromStringFromSource("addon_mapname", "", game::DVAR_SOURCE_INTERNAL);
allocator.clear();
}

View File

@ -3,4 +3,5 @@
namespace mapents
{
void clear();
void clear_dvars();
}

View File

@ -30,6 +30,7 @@ namespace mods
{
materials::clear();
fonts::clear();
mapents::clear_dvars();
}
mapents::clear();

View File

@ -57,6 +57,7 @@ namespace game
WEAK symbol<const char*(dvar_t* dvar, void* a2, void* value)> Dvar_ValueToString{0x14061B8F0};
WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x14061A5C0};
WEAK symbol<void(const char* dvarName, const char* string, DvarSetSource source)> Dvar_SetFromStringFromSource{0x14061A910};
WEAK symbol<void(const dvar_t* dvar, const char* value)> Dvar_SetString{0x14061ABF0};
WEAK symbol<int(const char* fname)> generateHashValue{0x140343D20};