41
41
#include " game/savegame_internal.h"
42
42
#include " gui/animatingguibutton.h"
43
43
#include " gui/guimain.h"
44
+ #include " gui/guibutton.h"
45
+ #include " gui/guiinv.h"
46
+ #include " gui/guilabel.h"
47
+ #include " gui/guilistbox.h"
48
+ #include " gui/guislider.h"
49
+ #include " gui/guitextbox.h"
44
50
#include " media/audio/audio.h"
45
51
#include " plugin/plugin_engine.h"
46
52
#include " script/script.h"
@@ -63,6 +69,21 @@ extern RoomStatus troom;
63
69
64
70
static const uint32_t MAGICNUMBER = 0xbeefcafe ;
65
71
72
+ // List of game objects, used to compare with the save contents
73
+ struct ObjectCounts
74
+ {
75
+ int CharacterCount = 0 ;
76
+ int DialogCount = 0 ;
77
+ int InvItemCount = 0 ;
78
+ int ViewCount = 0 ;
79
+ int GUICount = 0 ;
80
+ int GUILabelCount = 0 ;
81
+ int GUIButtonCount = 0 ;
82
+ int GUIInvWindowCount = 0 ;
83
+ int GUIListBoxCount = 0 ;
84
+ int GUISliderCount = 0 ;
85
+ int GUITextBoxCount = 0 ;
86
+ };
66
87
67
88
static HSaveError restore_game_head_dynamic_values (Stream *in, RestoredData &r_data)
68
89
{
@@ -241,17 +262,33 @@ void ReadAnimatedButtons_Aligned(Stream *in, int num_abuts)
241
262
}
242
263
}
243
264
244
- static HSaveError restore_game_gui (Stream *in , int numGuisWas )
265
+ inline bool AssertGameContent (HSaveError &err , int new_val, int original_val, const char *content_name )
245
266
{
246
- HError err = GUI::ReadGUI (in, true );
247
- if (!err)
248
- return new SavegameError (kSvgErr_GameObjectInitFailed , err);
249
- game.numgui = guis.size ();
250
-
251
- if (numGuisWas != game.numgui )
267
+ if (new_val != original_val)
252
268
{
253
- return new SavegameError (kSvgErr_GameContentAssertion , " Mismatching number of GUI." );
269
+ err = new SavegameError (kSvgErr_GameContentAssertion ,
270
+ String::FromFormat (" Mismatching number of %s (game: %d, save: %d)." ,
271
+ content_name, original_val, new_val));
254
272
}
273
+ return new_val == original_val;
274
+ }
275
+
276
+ static HSaveError restore_game_gui (Stream *in, const ObjectCounts &guiwas)
277
+ {
278
+ HError guierr = GUI::ReadGUI (in, true );
279
+ if (!guierr)
280
+ return new SavegameError (kSvgErr_GameObjectInitFailed , guierr);
281
+ game.numgui = guis.size ();
282
+
283
+ HSaveError err;
284
+ if (!AssertGameContent (err, game.numgui , guiwas.GUICount , " GUIs" ) ||
285
+ !AssertGameContent (err, guibuts.size (), guiwas.GUIButtonCount , " GUI Buttons" ) ||
286
+ !AssertGameContent (err, guiinv.size (), guiwas.GUIInvWindowCount , " GUI InvWindows" ) ||
287
+ !AssertGameContent (err, guilabels.size (), guiwas.GUILabelCount , " GUI Labels" ) ||
288
+ !AssertGameContent (err, guilist.size (), guiwas.GUIListBoxCount , " GUI ListBoxes" ) ||
289
+ !AssertGameContent (err, guislider.size (), guiwas.GUISliderCount , " GUI Sliders" ) ||
290
+ !AssertGameContent (err, guitext.size (), guiwas.GUITextBoxCount , " GUI TextBoxes" ))
291
+ return err;
255
292
256
293
RemoveAllButtonAnimations ();
257
294
int anim_count = in->ReadInt32 ();
@@ -474,31 +511,27 @@ HSaveError restore_save_data_v321(Stream *in, GameDataVersion data_ver, const Pr
474
511
restore_game_play (in, data_ver, r_data);
475
512
ReadMoveList_Aligned (in);
476
513
477
- const int numchwas = game.numcharacters ;
478
- const int numdiwas = game.numdialog ;
479
- const int numinvwas = game.numinvitems ;
480
- const int numviewswas = game.numviews ;
481
- const int numGuisWas = game.numgui ;
514
+ ObjectCounts objwas;
515
+ objwas.CharacterCount = game.numcharacters ;
516
+ objwas.DialogCount = game.numdialog ;
517
+ objwas.InvItemCount = game.numinvitems ;
518
+ objwas.ViewCount = game.numviews ;
519
+ objwas.GUICount = game.numgui ;
520
+ objwas.GUIButtonCount = guibuts.size ();
521
+ objwas.GUIInvWindowCount = guiinv.size ();
522
+ objwas.GUILabelCount = guilabels.size ();
523
+ objwas.GUIListBoxCount = guilist.size ();
524
+ objwas.GUISliderCount = guislider.size ();
525
+ objwas.GUITextBoxCount = guitext.size ();
482
526
483
527
GameSetupStruct::SerializeInfo info;
484
528
ReadGameSetupStructBase_Aligned (in, data_ver, info);
485
529
486
- if (game.numdialog !=numdiwas)
487
- {
488
- return new SavegameError (kSvgErr_GameContentAssertion , " Mismatching number of Dialogs." );
489
- }
490
- if (numchwas != game.numcharacters )
491
- {
492
- return new SavegameError (kSvgErr_GameContentAssertion , " Mismatching number of Characters." );
493
- }
494
- if (numinvwas != game.numinvitems )
495
- {
496
- return new SavegameError (kSvgErr_GameContentAssertion , " Mismatching number of Inventory Items." );
497
- }
498
- if (game.numviews != numviewswas)
499
- {
500
- return new SavegameError (kSvgErr_GameContentAssertion , " Mismatching number of Views." );
501
- }
530
+ if (!AssertGameContent (err, game.numcharacters , objwas.CharacterCount , " Characters" ) ||
531
+ !AssertGameContent (err, game.numdialog , objwas.DialogCount , " Dialogs" ) ||
532
+ !AssertGameContent (err, game.numinvitems , objwas.InvItemCount , " Inventory Items" ) ||
533
+ !AssertGameContent (err, game.numviews , objwas.ViewCount , " Views" ))
534
+ return err;
502
535
503
536
game.ReadFromSaveGame_v321 (in, data_ver);
504
537
@@ -509,7 +542,7 @@ HSaveError restore_save_data_v321(Stream *in, GameDataVersion data_ver, const Pr
509
542
restore_game_palette (in);
510
543
restore_game_dialogs (in);
511
544
restore_game_more_dynamic_values (in);
512
- err = restore_game_gui (in, numGuisWas );
545
+ err = restore_game_gui (in, objwas );
513
546
if (!err)
514
547
return err;
515
548
err = restore_game_audiocliptypes (in);
0 commit comments