Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========================================================
- // alterIWnet project
- //
- // Component: aiw_client
- // Sub-component: steam_api
- // Purpose: singleplayer level loading code (reallocation,
- // address changes, other patches, ...)
- //
- // Initial author: NTAuthority
- // Started: 2011-05-25
- // ==========================================================
- #include "StdInc.h"
- #include "Hooking.h"
- // entity dumping, needs to be split?
- struct MapEnts
- {
- const char* name;
- const char* entitystring;
- };
- void DumpMapEntities(MapEnts* entities)
- {
- char filename[255];
- CreateDirectoryA("raw/maps", NULL);
- CreateDirectoryA("raw/maps/mp", NULL);
- _snprintf(filename, sizeof(filename), "raw/%s.ents", entities->name);
- FILE* file = fopen(filename, "w");
- if (file)
- {
- fwrite(entities->entitystring, 1, strlen(entities->entitystring), file);
- fclose(file);
- }
- }
- static char mapEntities[512 * 1024];
- void LoadMapEntities(MapEnts* entry)
- {
- char* buffer;
- char filename[255];
- _snprintf(filename, sizeof(filename), "%s.ents", entry->name);
- // why the weird casts?
- if (FS_ReadFile((const char*)(&filename), (void**)&buffer) >= 0)
- {
- strcpy(mapEntities, buffer);
- entry->entitystring = mapEntities;
- }
- }
- // more code
- static DWORD gameWorldSP;
- static DWORD gameWorldMP;
- // defined in Load.cpp
- void* ReallocateAssetPool(assetType_t type, unsigned int newSize);
- // TODO: load these dynamically
- struct LevelDependency
- {
- const char* level;
- const char* dependency;
- };
- LevelDependency _dependencies[] =
- {
- { "oilrig", "mp_subbase" },
- { 0, 0 }
- };
- // called during Com_LoadLevelZone, replaces the DB_LoadXAssets call
- CallHook mapZoneLoadHook;
- DWORD mapZoneLoadHookLoc = 0x42C2AF;
- // Com_Sprintf call in Com_GetBspFilename
- CallHook getBSPNameHook;
- DWORD getBSPNameHookLoc = 0x4C5979;
- static char levelDependencyName[64];
- static char levelAssetName[64];
- bool AssetRestrict_RestrictFromMaps(assetType_t type, const char* name, const char* zone)
- {
- if (!stricmp(zone, levelDependencyName))
- {
- // don't load other maps
- if (type == ASSET_TYPE_GAME_MAP_MP || type == ASSET_TYPE_COL_MAP_MP || type == ASSET_TYPE_GFX_MAP || type == ASSET_TYPE_MAP_ENTS || type == ASSET_TYPE_COM_MAP || type == ASSET_TYPE_FX_MAP)
- {
- return true;
- }
- // also don't load localize/fx
- if (type == ASSET_TYPE_LOCALIZE/* || type == ASSET_TYPE_FX*/) // we need to link 'fx' assets as otherwise we
- // crash at Mark_FxEffectDefAsset...
- // guess rule #1 needs to be expanded:
- // so rule #2 becomes 'don't touch fastfiles through code
- // if you do not understand the code'.
- // rule #1 still stands: 'don't touch fastfiles'
- {
- return true;
- }
- }
- if (type == ASSET_TYPE_WEAPON)
- {
- if (!stricmp(zone, levelAssetName))
- {
- return true;
- }
- }
- return false;
- }
- void MapZoneLoadHookFunc(XZoneInfo* data, int count, int unknown)
- {
- XZoneInfo newData[3];
- // flag us as loading level assets so we don't load weapons
- strcpy(levelAssetName, data[0].name);
- levelDependencyName[0] = '\0';
- // load the base XAsset
- DB_LoadXAssets(data, count, unknown);
- // add level dependencies
- count = 0;
- for (LevelDependency* dependency = _dependencies; dependency->level; dependency++)
- {
- if (!_stricmp(dependency->level, data[0].name))
- {
- newData[count].name = dependency->dependency;
- newData[count].type1 = data[0].type1;
- newData[count].type2 = data[0].type2;
- count++;
- break;
- }
- }
- // load level dependencies
- if (count > 0)
- {
- strcpy(levelDependencyName, newData[0].name);
- DB_LoadXAssets(newData, count, unknown);
- }
- // check for being MP/SP, and change data accordingly
- if (_strnicmp("mp_", data[0].name, 3))
- {
- // SP
- *(DWORD*)0x4D90B7 = gameWorldSP + 52; // some game data structure
- }
- else
- {
- // MP
- *(DWORD*)0x4D90B7 = gameWorldMP + 4; // some game data structure
- }
- }
- CallHook ignoreEntityHook;
- DWORD ignoreEntityHookLoc = 0x5FBD6E;
- bool IgnoreEntityHookFunc(const char* entity); // TODO: move here from Load
- void ReallocXAssetEntries();
- void PatchMW2_SPMaps()
- {
- // reallocate asset pools
- ReallocateAssetPool(ASSET_TYPE_IMAGE, 7168);
- ReallocateAssetPool(ASSET_TYPE_LOADED_SOUND, 2700);
- ReallocateAssetPool(ASSET_TYPE_FX, 1200);
- ReallocateAssetPool(ASSET_TYPE_LOCALIZE, 14000);
- ReallocateAssetPool(ASSET_TYPE_XANIM, 8192);
- ReallocateAssetPool(ASSET_TYPE_XMODEL, 3072);
- ReallocateAssetPool(ASSET_TYPE_PHYSPRESET, 128);
- // get and store GameWorld*p data
- gameWorldSP = (DWORD)ReallocateAssetPool(ASSET_TYPE_GAME_MAP_SP, 1);
- gameWorldMP = (*(DWORD*)0x4D90B7) - 4;
- // allow loading of IWffu (unsigned) files
- *(BYTE*)0x4158D9 = 0xEB; // main function
- *(WORD*)0x4A1D97 = 0x9090; // DB_AuthLoad_InflateInit
- // ignore 'node_' entities
- //ignoreEntityHook.initialize((PBYTE)ignoreEntityHookLoc);
- //ignoreEntityHook.installHook((void(*)())IgnoreEntityHookFunc, false);
- // asset zone loading
- mapZoneLoadHook.initialize((PBYTE)mapZoneLoadHookLoc);
- mapZoneLoadHook.installHook((void(*)())MapZoneLoadHookFunc, false);
- // BSP name
- getBSPNameHook.initialize((PBYTE)getBSPNameHookLoc);
- getBSPNameHook.installHook((void(*)())GetBSPNameHookFunc, false);
- // hunk size (was 300 MiB)
- *(DWORD*)0x64A029 = 0x1C200000; // 450 MiB
- *(DWORD*)0x64A057 = 0x1C200000;
- // XAsset entries
- ReallocXAssetEntries();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement