Fix a crash with arena reloading on custom maps

This commit is contained in:
Louvenarde 2024-06-16 00:58:16 +02:00
parent 21d5b05554
commit 835f74065c
4 changed files with 250 additions and 225 deletions

View File

@ -315,7 +315,10 @@ namespace Components
Friends::LoggedOn = (Steam::Proxy::SteamUser_ && Steam::Proxy::SteamUser_->LoggedOn());
if (!Steam::Proxy::SteamFriends) return;
if (Game::Sys_IsMainThread())
{
Game::UI_UpdateArenas();
}
int count = Steam::Proxy::SteamFriends->GetFriendCount(4);

View File

@ -262,6 +262,8 @@ namespace Components
{
const auto* g_log = (*Game::g_log) ? (*Game::g_log)->current.string : "";
if (g_log) // This can be null - has happened before
{
if (std::strcmp(g_log, file) == 0)
{
if (std::strcmp(folder, "userraw") != 0)
@ -273,6 +275,7 @@ namespace Components
}
}
}
}
__declspec(naked) void Logger::BuildOSPath_Stub()
{

View File

@ -103,7 +103,7 @@ namespace Components
const char* Maps::LoadArenaFileStub(const char* name, char* buffer, int size)
{
std::string data = RawFiles::ReadRawFile(name, buffer, size);
std::string data;
if (Maps::UserMap.isValid())
{
@ -116,6 +116,10 @@ namespace Components
data = Utils::IO::ReadFile(arena);
}
}
else
{
data = RawFiles::ReadRawFile(name, buffer, size);
}
strncpy_s(buffer, size, data.data(), _TRUNCATE);
return buffer;
@ -314,6 +318,22 @@ namespace Components
}
}
void Maps::ForceRefreshArenas()
{
if (Game::Sys_IsMainThread())
{
Game::sharedUiInfo_t* uiInfo = reinterpret_cast<Game::sharedUiInfo_t*>(0x62E4B78);
uiInfo->updateArenas = 1;
Game::UI_UpdateArenas();
}
else
{
// Dangerous!!
assert(false, "Arenas refreshed from wrong thread??");
Logger::Print("Tried to refresh arenas from a thread that is NOT the main thread!! This could have lead to a crash. Please report this bug and how you got it!");
}
}
// TODO : Remove hook entirely?
void Maps::GetBSPName(char* buffer, size_t size, const char* format, const char* mapname)
{
@ -845,12 +865,6 @@ namespace Components
// Load usermap arena file
Utils::Hook(0x630A88, Maps::LoadArenaFileStub, HOOK_CALL).install()->quick();
// Always refresh arena when loading or unloading a zone
Utils::Hook::Nop(0x485017, 2);
Utils::Hook::Nop(0x4BDFB7, 2); // Unknown
Utils::Hook::Nop(0x45ED6F, 2); // loadGameInfo
Utils::Hook::Nop(0x4A5888, 2); // UI_InitOnceForAllClients
// Allow hiding specific smodels
Utils::Hook(0x50E67C, Maps::HideModelStub, HOOK_CALL).install()->quick();

View File

@ -13,7 +13,7 @@ namespace Components
{
ZeroMemory(&this->searchPath, sizeof this->searchPath);
this->hash = Maps::GetUsermapHash(this->mapname);
Game::UI_UpdateArenas();
Maps::ForceRefreshArenas();
}
~UserMapContainer()
@ -29,7 +29,10 @@ namespace Components
{
bool wasValid = this->isValid();
this->mapname.clear();
if (wasValid) Game::UI_UpdateArenas();
if (wasValid)
{
Maps::ForceRefreshArenas();
}
}
void loadIwd();
@ -95,6 +98,8 @@ namespace Components
static Dvar::Var RListSModels;
static void ForceRefreshArenas();
static void GetBSPName(char* buffer, size_t size, const char* format, const char* mapname);
static void LoadAssetRestrict(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name, bool* restrict);
static void LoadMapZones(Game::XZoneInfo *zoneInfo, unsigned int zoneCount, int sync);