MCPcopy Index your code
hub / github.com/OpenDUNE/OpenDUNE / Load_Main

Function Load_Main

src/load.c:47–129  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47static bool Load_Main(FILE *fp)
48{
49 uint32 position;
50 uint32 length;
51 uint32 header;
52 uint16 version;
53
54 /* All OpenDUNE / Dune2 savegames should start with 'FORM' */
55 if (fread(&header, sizeof(uint32), 1, fp) != 1) return false;
56 if (BETOH32(header) != CC_FORM) {
57 Error("Invalid magic header in savegame. Not an OpenDUNE / Dune2 savegame.");
58 return false;
59 }
60
61 /* The total length field, which is ignored */
62 if (fread(&length, sizeof(uint32), 1, fp) != 1) return false;
63
64 /* The next 'chunk' is fake, and has no length field */
65 if (fread(&header, sizeof(uint32), 1, fp) != 1) return false;
66 if (BETOH32(header) != CC_SCEN) return false;
67
68 position = ftell(fp);
69
70 /* Find the 'INFO' chunk, as it contains the savegame version */
71 version = 0;
72 length = Load_FindChunk(fp, CC_INFO);
73 if (length == 0) return false;
74
75 /* Read the savegame version */
76 if (!fread_le_uint16(&version, fp)) return false;
77 length -= 2;
78 if (version == 0) return false;
79
80 if (version != 0x0290) {
81 /* Get the scenarioID / campaignID */
82 if (!Info_LoadOld(fp, length)) return false;
83
84 g_gameMode = GM_RESTART;
85
86 /* Find the 'PLYR' chunk */
87 fseek(fp, position, SEEK_SET);
88 length = Load_FindChunk(fp, CC_PLYR);
89 if (length == 0) return false;
90
91 /* Find the human player */
92 if (!House_LoadOld(fp, length)) return false;
93
94 GUI_DisplayModalMessage(String_Get_ByIndex(STR_WARNING_ORIGINAL_SAVED_GAMES_ARE_INCOMPATABLE_WITH_THE_NEW_VERSION_THE_BATTLE_WILL_BE_RESTARTED), 0xFFFF);
95
96 return true;
97 }
98
99 /* Load the 'INFO' chunk'. It has to be the first chunk loaded */
100 if (!Info_Load(fp, length)) return false;
101
102 /* Rewind, and read other chunks */
103 fseek(fp, position, SEEK_SET);
104 while (fread(&header, sizeof(uint32), 1, fp) == 1) {

Callers 1

SaveGame_LoadFileFunction · 0.85

Calls 14

Load_FindChunkFunction · 0.85
fread_le_uint16Function · 0.85
Info_LoadOldFunction · 0.85
House_LoadOldFunction · 0.85
GUI_DisplayModalMessageFunction · 0.85
String_Get_ByIndexFunction · 0.85
Info_LoadFunction · 0.85
Map_LoadFunction · 0.85
House_LoadFunction · 0.85
Unit_LoadFunction · 0.85
Structure_LoadFunction · 0.85
Team_LoadFunction · 0.85

Tested by

no test coverage detected