Advertisement
SMF

AIW Source Code Snippet SP/MP Oilrig

SMF
Jun 4th, 2011
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. // ==========================================================
  2. // alterIWnet project
  3. //
  4. // Component: aiw_client
  5. // Sub-component: steam_api
  6. // Purpose: singleplayer level loading code (reallocation,
  7. // address changes, other patches, ...)
  8. //
  9. // Initial author: NTAuthority
  10. // Started: 2011-05-25
  11. // ==========================================================
  12.  
  13. #include "StdInc.h"
  14. #include "Hooking.h"
  15.  
  16. // entity dumping, needs to be split?
  17. struct MapEnts
  18. {
  19. const char* name;
  20. const char* entitystring;
  21. };
  22.  
  23. void DumpMapEntities(MapEnts* entities)
  24. {
  25. char filename[255];
  26.  
  27. CreateDirectoryA("raw/maps", NULL);
  28. CreateDirectoryA("raw/maps/mp", NULL);
  29.  
  30. _snprintf(filename, sizeof(filename), "raw/%s.ents", entities->name);
  31.  
  32. FILE* file = fopen(filename, "w");
  33. if (file)
  34. {
  35. fwrite(entities->entitystring, 1, strlen(entities->entitystring), file);
  36. fclose(file);
  37. }
  38. }
  39.  
  40. static char mapEntities[512 * 1024];
  41.  
  42. void LoadMapEntities(MapEnts* entry)
  43. {
  44. char* buffer;
  45. char filename[255];
  46. _snprintf(filename, sizeof(filename), "%s.ents", entry->name);
  47.  
  48. // why the weird casts?
  49. if (FS_ReadFile((const char*)(&filename), (void**)&buffer) >= 0)
  50. {
  51. strcpy(mapEntities, buffer);
  52. entry->entitystring = mapEntities;
  53. }
  54. }
  55.  
  56. // more code
  57. static DWORD gameWorldSP;
  58. static DWORD gameWorldMP;
  59.  
  60. // defined in Load.cpp
  61. void* ReallocateAssetPool(assetType_t type, unsigned int newSize);
  62.  
  63. // TODO: load these dynamically
  64. struct LevelDependency
  65. {
  66. const char* level;
  67. const char* dependency;
  68. };
  69.  
  70. LevelDependency _dependencies[] =
  71. {
  72. { "oilrig", "mp_subbase" },
  73. { 0, 0 }
  74. };
  75.  
  76. // called during Com_LoadLevelZone, replaces the DB_LoadXAssets call
  77. CallHook mapZoneLoadHook;
  78. DWORD mapZoneLoadHookLoc = 0x42C2AF;
  79.  
  80. // Com_Sprintf call in Com_GetBspFilename
  81. CallHook getBSPNameHook;
  82. DWORD getBSPNameHookLoc = 0x4C5979;
  83.  
  84. static char levelDependencyName[64];
  85. static char levelAssetName[64];
  86.  
  87. bool AssetRestrict_RestrictFromMaps(assetType_t type, const char* name, const char* zone)
  88. {
  89. if (!stricmp(zone, levelDependencyName))
  90. {
  91. // don't load other maps
  92. 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)
  93. {
  94. return true;
  95. }
  96.  
  97. // also don't load localize/fx
  98. if (type == ASSET_TYPE_LOCALIZE/* || type == ASSET_TYPE_FX*/) // we need to link 'fx' assets as otherwise we
  99. // crash at Mark_FxEffectDefAsset...
  100. // guess rule #1 needs to be expanded:
  101. // so rule #2 becomes 'don't touch fastfiles through code
  102. // if you do not understand the code'.
  103. // rule #1 still stands: 'don't touch fastfiles'
  104. {
  105. return true;
  106. }
  107. }
  108.  
  109. if (type == ASSET_TYPE_WEAPON)
  110. {
  111. if (!stricmp(zone, levelAssetName))
  112. {
  113. return true;
  114. }
  115. }
  116.  
  117. return false;
  118. }
  119.  
  120. void MapZoneLoadHookFunc(XZoneInfo* data, int count, int unknown)
  121. {
  122. XZoneInfo newData[3];
  123.  
  124. // flag us as loading level assets so we don't load weapons
  125. strcpy(levelAssetName, data[0].name);
  126. levelDependencyName[0] = '\0';
  127.  
  128. // load the base XAsset
  129. DB_LoadXAssets(data, count, unknown);
  130.  
  131. // add level dependencies
  132. count = 0;
  133.  
  134. for (LevelDependency* dependency = _dependencies; dependency->level; dependency++)
  135. {
  136. if (!_stricmp(dependency->level, data[0].name))
  137. {
  138. newData[count].name = dependency->dependency;
  139. newData[count].type1 = data[0].type1;
  140. newData[count].type2 = data[0].type2;
  141.  
  142. count++;
  143. break;
  144. }
  145. }
  146.  
  147. // load level dependencies
  148. if (count > 0)
  149. {
  150. strcpy(levelDependencyName, newData[0].name);
  151. DB_LoadXAssets(newData, count, unknown);
  152. }
  153.  
  154. // check for being MP/SP, and change data accordingly
  155. if (_strnicmp("mp_", data[0].name, 3))
  156. {
  157. // SP
  158. *(DWORD*)0x4D90B7 = gameWorldSP + 52; // some game data structure
  159. }
  160. else
  161. {
  162. // MP
  163. *(DWORD*)0x4D90B7 = gameWorldMP + 4; // some game data structure
  164. }
  165. }
  166.  
  167. CallHook ignoreEntityHook;
  168. DWORD ignoreEntityHookLoc = 0x5FBD6E;
  169.  
  170. bool IgnoreEntityHookFunc(const char* entity); // TODO: move here from Load
  171. void ReallocXAssetEntries();
  172.  
  173. void PatchMW2_SPMaps()
  174. {
  175. // reallocate asset pools
  176. ReallocateAssetPool(ASSET_TYPE_IMAGE, 7168);
  177. ReallocateAssetPool(ASSET_TYPE_LOADED_SOUND, 2700);
  178. ReallocateAssetPool(ASSET_TYPE_FX, 1200);
  179. ReallocateAssetPool(ASSET_TYPE_LOCALIZE, 14000);
  180. ReallocateAssetPool(ASSET_TYPE_XANIM, 8192);
  181. ReallocateAssetPool(ASSET_TYPE_XMODEL, 3072);
  182. ReallocateAssetPool(ASSET_TYPE_PHYSPRESET, 128);
  183.  
  184. // get and store GameWorld*p data
  185. gameWorldSP = (DWORD)ReallocateAssetPool(ASSET_TYPE_GAME_MAP_SP, 1);
  186. gameWorldMP = (*(DWORD*)0x4D90B7) - 4;
  187.  
  188. // allow loading of IWffu (unsigned) files
  189. *(BYTE*)0x4158D9 = 0xEB; // main function
  190. *(WORD*)0x4A1D97 = 0x9090; // DB_AuthLoad_InflateInit
  191.  
  192. // ignore 'node_' entities
  193. //ignoreEntityHook.initialize((PBYTE)ignoreEntityHookLoc);
  194. //ignoreEntityHook.installHook((void(*)())IgnoreEntityHookFunc, false);
  195.  
  196. // asset zone loading
  197. mapZoneLoadHook.initialize((PBYTE)mapZoneLoadHookLoc);
  198. mapZoneLoadHook.installHook((void(*)())MapZoneLoadHookFunc, false);
  199.  
  200. // BSP name
  201. getBSPNameHook.initialize((PBYTE)getBSPNameHookLoc);
  202. getBSPNameHook.installHook((void(*)())GetBSPNameHookFunc, false);
  203.  
  204. // hunk size (was 300 MiB)
  205. *(DWORD*)0x64A029 = 0x1C200000; // 450 MiB
  206. *(DWORD*)0x64A057 = 0x1C200000;
  207.  
  208. // XAsset entries
  209. ReallocXAssetEntries();
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement