ref: 718cb714ee39d818c3c6a181ac64ff3310644dfc
parent: ce4373481b4b67cc98ef6d3b908fd0188c328891
author: Clownacy <Clownacy@users.noreply.github.com>
date: Tue Jan 7 15:58:46 EST 2020
More-accurate NpcTbl.cpp variable arrangement For some reason, the Linux debug data notes a 2000-line gap before any declarations. Might be the SDL header or something.
--- a/src/NpcTbl.cpp
+++ b/src/NpcTbl.cpp
@@ -9,67 +9,6 @@
#include "Generic.h"
#include "NpcAct.h"
-NPC_TABLE *gNpcTable;
-
-BOOL LoadNpcTable(const char *path)
-{
- FILE *fp;
- int n;
- int num;
- size_t size;
-
- size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not
- if (size == INVALID_FILE_SIZE)
- return FALSE;
-
- num = (int)(size / 0x18);
-
- gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE));
- if (gNpcTable == NULL)
- return FALSE;
-
- fp = fopen(path, "rb");
- if (fp == NULL)
- {
- free(gNpcTable);
- gNpcTable = NULL;
- return FALSE;
- }
-
- for (n = 0; n < num; ++n) // bits
- fread(&gNpcTable[n].bits, 2, 1, fp);
- for (n = 0; n < num; ++n) // life
- fread(&gNpcTable[n].life, 2, 1, fp);
- for (n = 0; n < num; ++n) // surf
- fread(&gNpcTable[n].surf, 1, 1, fp);
- for (n = 0; n < num; ++n) // destroy_voice
- fread(&gNpcTable[n].destroy_voice, 1, 1, fp);
- for (n = 0; n < num; ++n) // hit_voice
- fread(&gNpcTable[n].hit_voice, 1, 1, fp);
- for (n = 0; n < num; ++n) // size
- fread(&gNpcTable[n].size, 1, 1, fp);
- for (n = 0; n < num; ++n) // exp
- fread(&gNpcTable[n].exp, 4, 1, fp);
- for (n = 0; n < num; ++n) // damage
- fread(&gNpcTable[n].damage, 4, 1, fp);
- for (n = 0; n < num; ++n) // hit
- fread(&gNpcTable[n].hit, 4, 1, fp);
- for (n = 0; n < num; ++n) // view
- fread(&gNpcTable[n].view, 4, 1, fp);
-
- fclose(fp);
- return TRUE;
-}
-
-void ReleaseNpcTable(void)
-{
- if (gNpcTable != NULL)
- {
- free(gNpcTable);
- gNpcTable = NULL;
- }
-}
-
// Npc function table
const NPCFUNCTION gpNpcFuncTbl[361] = {
ActNpc000,
@@ -434,3 +373,64 @@
ActNpc359,
ActNpc360,
};
+
+NPC_TABLE *gNpcTable;
+
+BOOL LoadNpcTable(const char *path)
+{
+ FILE *fp;
+ int n;
+ size_t size;
+ int num;
+
+ size = GetFileSizeLong(path); // TODO - Investigate whether GetFileSizeLong actually returns an unsigned long or not
+ if (size == INVALID_FILE_SIZE)
+ return FALSE;
+
+ num = (int)(size / 0x18);
+
+ gNpcTable = (NPC_TABLE*)malloc(num * sizeof(NPC_TABLE));
+ if (gNpcTable == NULL)
+ return FALSE;
+
+ fp = fopen(path, "rb");
+ if (fp == NULL)
+ {
+ free(gNpcTable);
+ gNpcTable = NULL;
+ return FALSE;
+ }
+
+ for (n = 0; n < num; ++n) // bits
+ fread(&gNpcTable[n].bits, 2, 1, fp);
+ for (n = 0; n < num; ++n) // life
+ fread(&gNpcTable[n].life, 2, 1, fp);
+ for (n = 0; n < num; ++n) // surf
+ fread(&gNpcTable[n].surf, 1, 1, fp);
+ for (n = 0; n < num; ++n) // destroy_voice
+ fread(&gNpcTable[n].destroy_voice, 1, 1, fp);
+ for (n = 0; n < num; ++n) // hit_voice
+ fread(&gNpcTable[n].hit_voice, 1, 1, fp);
+ for (n = 0; n < num; ++n) // size
+ fread(&gNpcTable[n].size, 1, 1, fp);
+ for (n = 0; n < num; ++n) // exp
+ fread(&gNpcTable[n].exp, 4, 1, fp);
+ for (n = 0; n < num; ++n) // damage
+ fread(&gNpcTable[n].damage, 4, 1, fp);
+ for (n = 0; n < num; ++n) // hit
+ fread(&gNpcTable[n].hit, 4, 1, fp);
+ for (n = 0; n < num; ++n) // view
+ fread(&gNpcTable[n].view, 4, 1, fp);
+
+ fclose(fp);
+ return TRUE;
+}
+
+void ReleaseNpcTable(void)
+{
+ if (gNpcTable != NULL)
+ {
+ free(gNpcTable);
+ gNpcTable = NULL;
+ }
+}