DEADSOFTWARE

no more old mapreader: use textmap reader both for text and for binary maps
[d2df-sdl.git] / src / game / g_saveload.pas
index 3d8c14cd669c6fed75253e9bf1f7916a79d02379..5a130981eae9232f2e22269e20275397098f1829 100644 (file)
@@ -1,4 +1,19 @@
-{$MODE DELPHI}
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
 unit g_saveload;
 
 interface
@@ -12,21 +27,69 @@ function g_LoadGame(n: Integer): Boolean;
 procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter);
 procedure Obj_LoadState(o: PObj; var Mem: TBinMemoryReader);
 
+type
+  TLoadSaveHook = procedure ();
+
+procedure g_SetPreLoadHook (ahook: TLoadSaveHook);
+procedure g_SetPostLoadHook (ahook: TLoadSaveHook);
+
+procedure g_CallPreLoadHooks ();
+procedure g_CallPostLoadHooks ();
+
+
 implementation
 
 uses
   g_game, g_items, g_map, g_monsters, g_triggers,
   g_basic, g_main, SysUtils, Math, wadreader,
-  MAPSTRUCT, MAPDEF, g_weapons, g_player, g_console,
+  MAPDEF, g_weapons, g_player, g_console,
   e_log, g_language;
 
 const
   SAVE_SIGNATURE = $56534644; // 'DFSV'
-  SAVE_VERSION = $02;
+  SAVE_VERSION = $03;
   END_MARKER_STRING = 'END';
   PLAYER_VIEW_SIGNATURE = $57564C50; // 'PLVW'
   OBJ_SIGNATURE = $4A424F5F; // '_OBJ'
 
+
+var
+  preloadHooks: array of TLoadSaveHook = nil;
+  postloadHooks: array of TLoadSaveHook = nil;
+
+
+procedure g_SetPreLoadHook (ahook: TLoadSaveHook);
+begin
+  if not assigned(ahook) then exit;
+  SetLength(preloadHooks, Length(preloadHooks)+1);
+  preloadHooks[High(preloadHooks)] := ahook;
+end;
+
+
+procedure g_SetPostLoadHook (ahook: TLoadSaveHook);
+begin
+  if not assigned(ahook) then exit;
+  SetLength(postloadHooks, Length(postloadHooks)+1);
+  postloadHooks[High(postloadHooks)] := ahook;
+end;
+
+
+procedure g_CallPreLoadHooks ();
+var
+  f: Integer;
+begin
+  for f := 0 to High(preloadHooks) do preloadHooks[f]();
+end;
+
+
+procedure g_CallPostLoadHooks ();
+var
+  f: Integer;
+begin
+  for f := 0 to High(postloadHooks) do postloadHooks[f]();
+end;
+
+
 procedure Obj_SaveState(o: PObj; var Mem: TBinMemoryWriter);
 var
   sig: DWORD;
@@ -344,6 +407,8 @@ begin
     g_Game_SetLoadingText(_lc[I_LOAD_SAVE_FILE], 0, False);
     gLoadGameMode := True;
 
+    g_CallPreLoadHooks();
+
   ///// Çàãðóæàåì ñîñòîÿíèå èãðû: /////
     bMem := TBinMemoryReader.Create();
     bFile.ReadMemory(bMem);
@@ -550,12 +615,13 @@ begin
   ///// /////
 
   // Èùåì òðèããåðû ñ óñëîâèåì ñìåðòè ìîíñòðîâ:
-    if (gMonsters <> nil) and (gTriggers <> nil) then
+    if {(gMonsters <> nil) and} (gTriggers <> nil) then
       g_Map_ReAdd_DieTriggers();
 
   // Çàêðûâàåì ôàéë çàãðóçêè:
     bFile.Close();
     gLoadGameMode := False;
+    g_CallPostLoadHooks();
     Result := True;
 
   except