Cleanup arena

This commit is contained in:
fed 2022-11-10 01:16:50 +01:00
parent cc15a83384
commit 6f67602434
3 changed files with 50 additions and 66 deletions

View File

@ -13,91 +13,45 @@
namespace
{
struct UISpawnPos
{
float allySpawnPos[2];
float axisSpawnPos[2];
float objectives[5][2];
};
struct mapInfo
{
char mapName[32];
char mapLoadName[16];
char mapDescription[32];
char mapLoadImage[32];
char mapCustomKey[32][16];
char mapCustomValue[32][64];
int mapCustomCount;
char mapCamoTypes[2][16];
int isAliensMap;
int mapPack;
int unk1;
int gametype;
char __pad0[132];
UISpawnPos mapSpawnPos[32];
};
static_assert(sizeof(mapInfo) == 4648);
int* ui_num_arenas;
int* ui_arena_buf_pos;
std::recursive_mutex _mutex;
std::recursive_mutex arena_mutex;
bool parse_arena(const std::string& path)
{
std::lock_guard<std::recursive_mutex> $(_mutex);
std::lock_guard<std::recursive_mutex> _0(arena_mutex);
char rawfile_buffer[0x18000];
memset(rawfile_buffer, 0, sizeof(rawfile_buffer));
// read from disk
auto buffer = filesystem::read_file(path);
if (buffer.size())
std::string buffer{};
if (filesystem::read_file(path, &buffer) && !buffer.empty())
{
//console::debug("[DISK]: parsing arena \"%s\"...\n", path.data());
// GameInfo_ParseArenas
*ui_num_arenas += utils::hook::invoke<int>(0x4DE0B0_b, buffer.data(), MAX_ARENAS - *ui_num_arenas,
reinterpret_cast<char*>(std::uintptr_t(0xAA55AE0_b) + (*ui_num_arenas * 8)));
*game::ui_num_arenas += game::GameInfo_ParseArenas(buffer.data(), MAX_ARENAS - *game::ui_num_arenas,
&game::ui_arena_infos[*game::ui_num_arenas]);
return true;
}
// read from fastfile
// DB_ReadRawFile
auto* buf = utils::hook::invoke<char*>(0x3994B0_b, path.data(), rawfile_buffer, sizeof(rawfile_buffer));
char rawfile_buffer[0x18000] = {0};
const auto buf = game::DB_ReadRawFile(path.data(), rawfile_buffer, sizeof(rawfile_buffer));
if (buf)
{
//console::debug("[FF]: parsing arena \"%s\"...\n", path.data());
// GameInfo_ParseArenas
*ui_num_arenas += utils::hook::invoke<int>(0x4DE0B0_b, buf, MAX_ARENAS - *ui_num_arenas,
reinterpret_cast<char*>(std::uintptr_t(0xAA55AE0_b) + (*ui_num_arenas * 8)));
*game::ui_num_arenas += game::GameInfo_ParseArenas(buf, MAX_ARENAS - *game::ui_num_arenas,
&game::ui_arena_infos[*game::ui_num_arenas]);
return true;
}
//console::debug("could not parse arena \"%s\"\n", path.data());
return false;
}
void load_arenas_stub()
{
*ui_num_arenas = 0;
*ui_arena_buf_pos = 0;
*game::ui_num_arenas = 0;
*game::ui_arena_buf_pos = 0;
// parse basemaps
parse_arena("mp/basemaps.arena");
// read usermap arena from disk
auto mapname = game::Dvar_FindVar("ui_mapname");
const auto mapname = game::Dvar_FindVar("ui_mapname");
if (mapname && mapname->current.string)
{
auto usermap_path = "usermaps/"s + mapname->current.string;
auto arena_path = usermap_path + "/" + mapname->current.string + ".arena";
// try parsing arena
const auto usermap_path = "usermaps/"s + mapname->current.string;
const auto arena_path = usermap_path + "/" + mapname->current.string + ".arena";
parse_arena(arena_path);
}
}
@ -115,10 +69,6 @@ namespace arena
return;
}
// patch arena stuff
ui_num_arenas = reinterpret_cast<int*>(0xAA55AD8_b);
ui_arena_buf_pos = reinterpret_cast<int*>(0xAA55ADC_b);
// load custom arenas
utils::hook::jump(0x4DE030_b, load_arenas_stub);
}

View File

@ -1563,6 +1563,33 @@ namespace game
int unk;
};
struct UISpawnPos
{
float allySpawnPos[2];
float axisSpawnPos[2];
float objectives[5][2];
};
struct mapInfo
{
char mapName[32];
char mapLoadName[16];
char mapDescription[32];
char mapLoadImage[32];
char mapCustomKey[32][16];
char mapCustomValue[32][64];
int mapCustomCount;
char mapCamoTypes[2][16];
int isAliensMap;
int mapPack;
int unk1;
int gametype;
char __pad0[132];
UISpawnPos mapSpawnPos[32];
};
static_assert(sizeof(mapInfo) == 4648);
namespace mp
{
struct cachedSnapshot_t

View File

@ -112,6 +112,8 @@ namespace game
WEAK symbol<void(int clientNum, unsigned int weapon)> G_SelectWeapon{0x2F2EA0, 0x462560};
WEAK symbol<int(playerState_s* ps, unsigned int weapon)> G_TakePlayerWeapon{0x2F3050, 0x462770};
WEAK symbol<int(const char* buf, int max, char** infos)> GameInfo_ParseArenas{0x0, 0x4DE0B0};
WEAK symbol<char*(char* string)> I_CleanStr{0x4293E0, 0x5AF2E0};
WEAK symbol<const char*(int, int, int)> Key_KeynumToString{0x1AC410, 0x199990};
@ -192,6 +194,7 @@ namespace game
WEAK symbol<int(const RawFile* rawfile)> DB_GetRawFileLen{0x1F1F40, 0x3961B0};
WEAK symbol<int(const RawFile* rawfile, char* buf, int size)> DB_GetRawBuffer{0x1F1E00, 0x396080};
WEAK symbol<char*(const char* filename, char* buf, int size)> DB_ReadRawFile{0x0, 0x3994B0};
WEAK symbol<bool(const char* zone, int source)> DB_FileExists{0x1F0D50, 0x394DC0};
WEAK symbol<void(XZoneInfo* zoneInfo, unsigned int zoneCount, DBSyncMode syncMode)> DB_LoadXAssets{0x1F31E0, 0x397500};
@ -303,6 +306,10 @@ namespace game
WEAK symbol<DWORD> threadIds{0xB896210, 0xAC80740};
WEAK symbol<int> ui_num_arenas{0x0, 0xAA55AD8};
WEAK symbol<int> ui_arena_buf_pos{0x0, 0xAA55ADC};
WEAK symbol<char*> ui_arena_infos{0x0, 0xAA55AE0};
WEAK symbol<int> level_time{0x56DBAA0, 0x7361F9C};
WEAK symbol<map_t> maps{0x7CE5A0, 0x926C80};