Convert legacy structs and endian-swapping routines to use exact-width types

- This because I discovered my compiler makes the long 8 bytes instead of 4
This commit is contained in:
2014-04-11 00:55:57 -04:00
parent 68c8ef7ba7
commit 4db8a0943b
3 changed files with 170 additions and 168 deletions

View File

@@ -8,18 +8,19 @@
#ifndef OLDSTRUCTS_H #ifndef OLDSTRUCTS_H
#define OLDSTRUCTS_H #define OLDSTRUCTS_H
#include <cstdint>
namespace legacy { namespace legacy {
// These definitions are basically copied from MacTypes.h // These definitions are basically copied from MacTypes.h
extern "C" { extern "C" {
struct Rect { struct Rect {
short top; int16_t top;
short left; int16_t left;
short bottom; int16_t bottom;
short right; int16_t right;
}; };
typedef struct Rect Rect; typedef struct Rect Rect;
typedef unsigned char Boolean; typedef uint8_t Boolean;
} }
//#define NLS 25 //#define NLS 25
// // number of left slots for buttons // // number of left slots for buttons
@@ -29,159 +30,159 @@ namespace legacy {
// // number of right slots for scrolling list on page at 1 time // // number of right slots for scrolling list on page at 1 time
struct location { struct location {
char x,y; int8_t x,y;
} __attribute__((packed)); } __attribute__((packed));
struct special_node_type { struct special_node_type {
short type,sd1,sd2,pic,m1,m2,ex1a,ex1b,ex2a,ex2b,jumpto; int16_t type,sd1,sd2,pic,m1,m2,ex1a,ex1b,ex2a,ex2b,jumpto;
} __attribute__((packed)); } __attribute__((packed));
struct talking_node_type { struct talking_node_type {
short personality,type; int16_t personality,type;
char link1[4],link2[4]; int8_t link1[4],link2[4];
short extras[4]; int16_t extras[4];
} __attribute__((packed)); } __attribute__((packed));
struct talking_record_type { struct talking_record_type {
unsigned char strlens[200]; uint8_t strlens[200];
talking_node_type talk_nodes[60]; talking_node_type talk_nodes[60];
} __attribute__((packed)); } __attribute__((packed));
struct terrain_type_type { struct terrain_type_type {
short picture; int16_t picture;
unsigned char blockage,flag1,flag2,special,trans_to_what,fly_over,boat_over; uint8_t blockage,flag1,flag2,special,trans_to_what,fly_over,boat_over;
unsigned char block_horse,light_radius,step_sound,shortcut_key,res1,res2,res3; uint8_t block_horse,light_radius,step_sound,shortcut_key,res1,res2,res3;
} __attribute__((packed)); } __attribute__((packed));
struct wandering_type { struct wandering_type {
unsigned char monst[4]; uint8_t monst[4];
} __attribute__((packed)); } __attribute__((packed));
struct out_wandering_type { struct out_wandering_type {
unsigned char monst[7]; uint8_t monst[7];
unsigned char friendly[3]; uint8_t friendly[3];
short spec_on_meet,spec_on_win,spec_on_flee,cant_flee; int16_t spec_on_meet,spec_on_win,spec_on_flee,cant_flee;
short end_spec1,end_spec2; int16_t end_spec1,end_spec2;
} __attribute__((packed)); } __attribute__((packed));
struct outdoor_record_type { struct outdoor_record_type {
unsigned char terrain[48][48]; uint8_t terrain[48][48];
location special_locs[18]; location special_locs[18];
unsigned char special_id[18]; uint8_t special_id[18];
location exit_locs[8]; location exit_locs[8];
char exit_dests[8]; int8_t exit_dests[8];
location sign_locs[8]; location sign_locs[8];
out_wandering_type wandering[4],special_enc[4]; out_wandering_type wandering[4],special_enc[4];
location wandering_locs[4]; location wandering_locs[4];
Rect info_rect[8]; Rect info_rect[8];
unsigned char strlens[180]; uint8_t strlens[180];
special_node_type specials[60]; special_node_type specials[60];
} __attribute__((packed)); } __attribute__((packed));
struct creature_start_type { struct creature_start_type {
unsigned char number; uint8_t number;
unsigned char start_attitude; uint8_t start_attitude;
location start_loc; location start_loc;
unsigned char mobile; uint8_t mobile;
unsigned char time_flag; uint8_t time_flag;
unsigned char extra1,extra2; uint8_t extra1,extra2;
short spec1, spec2; int16_t spec1, spec2;
char spec_enc_code,time_code; int8_t spec_enc_code,time_code;
short monster_time,personality; int16_t monster_time,personality;
short special_on_kill,facial_pic; int16_t special_on_kill,facial_pic;
} __attribute__((packed)); } __attribute__((packed));
struct short_item_record_type { struct short_item_record_type {
short variety, item_level; int16_t variety, item_level;
char awkward, bonus, protection, charges, type; int8_t awkward, bonus, protection, charges, type;
unsigned char graphic_num,ability, type_flag, is_special; uint8_t graphic_num,ability, type_flag, is_special;
short value; int16_t value;
Boolean identified, magic; Boolean identified, magic;
unsigned char weight, description_flag; uint8_t weight, description_flag;
char full_name[25], name[15]; char full_name[25], name[15];
unsigned char reserved1,reserved2; uint8_t reserved1,reserved2;
unsigned char magic_use_type, ability_strength, treas_class, real_abil; uint8_t magic_use_type, ability_strength, treas_class, real_abil;
} __attribute__((packed)); } __attribute__((packed));
struct item_record_type { struct item_record_type {
short variety, item_level; int16_t variety, item_level;
char awkward, bonus, protection, charges, type, magic_use_type; int8_t awkward, bonus, protection, charges, type, magic_use_type;
unsigned char graphic_num,ability, ability_strength,type_flag, is_special; uint8_t graphic_num,ability, ability_strength,type_flag, is_special;
short value __attribute__((aligned(2))); int16_t value __attribute__((aligned(2)));
unsigned char weight, special_class; uint8_t weight, special_class;
location item_loc; location item_loc;
char full_name[25], name[15]; char full_name[25], name[15];
unsigned char treas_class,item_properties,reserved1,reserved2; uint8_t treas_class,item_properties,reserved1,reserved2;
} __attribute__((packed)); } __attribute__((packed));
struct preset_item_type { struct preset_item_type {
location item_loc; location item_loc;
short item_code,ability; int16_t item_code,ability;
unsigned char charges,always_there,property,contained; uint8_t charges,always_there,property,contained;
} __attribute__((packed)); } __attribute__((packed));
struct preset_field_type { struct preset_field_type {
location field_loc; location field_loc;
short field_type; int16_t field_type;
} __attribute__((packed)); } __attribute__((packed));
struct town_record_type { struct town_record_type {
short town_chop_time,town_chop_key; int16_t town_chop_time,town_chop_key;
wandering_type wandering[4]; wandering_type wandering[4];
location wandering_locs[4]; location wandering_locs[4];
location special_locs[50]; location special_locs[50];
unsigned char spec_id[50]; uint8_t spec_id[50];
location sign_locs[15]; location sign_locs[15];
short lighting; int16_t lighting;
location start_locs[4]; location start_locs[4];
location exit_locs[4]; location exit_locs[4];
short exit_specs[4]; int16_t exit_specs[4];
Rect in_town_rect; Rect in_town_rect;
preset_item_type preset_items[64]; preset_item_type preset_items[64];
short max_num_monst; int16_t max_num_monst;
preset_field_type preset_fields[50]; preset_field_type preset_fields[50];
short spec_on_entry,spec_on_entry_if_dead; int16_t spec_on_entry,spec_on_entry_if_dead;
short timer_spec_times[8]; int16_t timer_spec_times[8];
short timer_specs[8]; int16_t timer_specs[8];
unsigned char strlens[180]; uint8_t strlens[180];
special_node_type specials[100]; special_node_type specials[100];
unsigned char specials1,specials2,res1,res2; uint8_t specials1,specials2,res1,res2;
short difficulty; int16_t difficulty;
} __attribute__((packed)); } __attribute__((packed));
struct big_tr_type { struct big_tr_type {
unsigned char terrain[64][64]; uint8_t terrain[64][64];
Rect room_rect[16]; Rect room_rect[16];
creature_start_type creatures[60]; creature_start_type creatures[60];
unsigned char lighting[8][64]; uint8_t lighting[8][64];
} __attribute__((packed)); } __attribute__((packed));
struct ave_tr_type { struct ave_tr_type {
unsigned char terrain[48][48]; uint8_t terrain[48][48];
Rect room_rect[16]; Rect room_rect[16];
creature_start_type creatures[40]; creature_start_type creatures[40];
unsigned char lighting[6][48]; uint8_t lighting[6][48];
} __attribute__((packed)); } __attribute__((packed));
struct tiny_tr_type { struct tiny_tr_type {
unsigned char terrain[32][32]; uint8_t terrain[32][32];
Rect room_rect[16]; Rect room_rect[16];
creature_start_type creatures[30]; creature_start_type creatures[30];
unsigned char lighting[4][32]; uint8_t lighting[4][32];
} __attribute__((packed)); } __attribute__((packed));
struct city_block_type { struct city_block_type {
short block_type; int16_t block_type;
short block_destroy_time; int16_t block_destroy_time;
char block_alignment; int8_t block_alignment;
char block_key_time; int8_t block_key_time;
location block_loc; location block_loc;
} __attribute__((packed)); } __attribute__((packed));
struct city_ter_rect_type { struct city_ter_rect_type {
Rect what_rect; Rect what_rect;
unsigned char ter_type; uint8_t ter_type;
unsigned char hollow; uint8_t hollow;
} __attribute__((packed)); } __attribute__((packed));
struct template_town_type { struct template_town_type {
@@ -197,152 +198,152 @@ namespace legacy {
} __attribute__((packed)); } __attribute__((packed));
struct item_storage_shortcut_type { struct item_storage_shortcut_type {
short ter_type,item_num[10],item_odds[10],property; int16_t ter_type,item_num[10],item_odds[10],property;
} __attribute__((packed)); } __attribute__((packed));
struct monster_record_type { struct monster_record_type {
unsigned char m_num,level,m_name[26]; uint8_t m_num,level,m_name[26];
short health,m_health,mp,max_mp; int16_t health,m_health,mp,max_mp;
unsigned char armor,skill; uint8_t armor,skill;
short a[3]; int16_t a[3];
unsigned char a1_type,a23_type,m_type,speed,ap,mu,cl,breath,breath_type,treasure,spec_skill,poison; uint8_t a1_type,a23_type,m_type,speed,ap,mu,cl,breath,breath_type,treasure,spec_skill,poison;
short morale,m_morale; int16_t morale,m_morale;
short corpse_item,corpse_item_chance; int16_t corpse_item,corpse_item_chance;
short status[15]; int16_t status[15];
unsigned char direction,immunities,x_width,y_width,radiate_1,radiate_2; uint8_t direction,immunities,x_width,y_width,radiate_1,radiate_2;
unsigned char default_attitude,summon_type,default_facial_pic,res1,res2,res3; uint8_t default_attitude,summon_type,default_facial_pic,res1,res2,res3;
short picture_num; int16_t picture_num;
} __attribute__((packed)); } __attribute__((packed));
struct horse_record_type { struct horse_record_type {
location horse_loc,horse_loc_in_sec,horse_sector; location horse_loc,horse_loc_in_sec,horse_sector;
short which_town; int16_t which_town;
Boolean exists,property; Boolean exists,property;
} __attribute__((packed)); } __attribute__((packed));
struct boat_record_type { struct boat_record_type {
location boat_loc,boat_loc_in_sec,boat_sector; location boat_loc,boat_loc_in_sec,boat_sector;
short which_town; int16_t which_town;
Boolean exists,property; Boolean exists,property;
} __attribute__((packed)); } __attribute__((packed));
struct talk_save_type { struct talk_save_type {
short personality; int16_t personality;
short town_num; int16_t town_num;
short str1,str2; int16_t str1,str2;
} __attribute__((packed)); } __attribute__((packed));
struct creature_data_type { struct creature_data_type {
short active,attitude; int16_t active,attitude;
unsigned char number; uint8_t number;
location m_loc; location m_loc;
monster_record_type m_d; monster_record_type m_d;
short mobile; int16_t mobile;
short summoned; int16_t summoned;
creature_start_type monst_start; creature_start_type monst_start;
} __attribute__((packed)); } __attribute__((packed));
struct creature_list_type { struct creature_list_type {
creature_data_type dudes[60]; creature_data_type dudes[60];
short which_town; int16_t which_town;
short friendly; int16_t friendly;
} __attribute__((packed)); } __attribute__((packed));
struct outdoor_creature_type { struct outdoor_creature_type {
Boolean exists; Boolean exists;
short direction; int16_t direction;
out_wandering_type what_monst; out_wandering_type what_monst;
location which_sector,m_loc; location which_sector,m_loc;
} __attribute__((packed)); } __attribute__((packed));
struct party_record_type { struct party_record_type {
long age; int32_t age;
short gold,food; int16_t gold,food;
unsigned char stuff_done[310][10],item_taken[200][8]; uint8_t stuff_done[310][10],item_taken[200][8];
short light_level; int16_t light_level;
location outdoor_corner,i_w_c,p_loc,loc_in_sec; location outdoor_corner,i_w_c,p_loc,loc_in_sec;
boat_record_type boats[30]; boat_record_type boats[30];
horse_record_type horses[30]; horse_record_type horses[30];
//char pad1[8]; //int8_t pad1[8];
creature_list_type creature_save[4]; creature_list_type creature_save[4];
short in_boat,in_horse; int16_t in_boat,in_horse;
outdoor_creature_type out_c[10]; outdoor_creature_type out_c[10];
item_record_type magic_store_items[5][10]; item_record_type magic_store_items[5][10];
short imprisoned_monst[4]; int16_t imprisoned_monst[4];
char m_seen[256]; int8_t m_seen[256];
char journal_str[50]; int8_t journal_str[50];
short journal_day[50]; int16_t journal_day[50];
short special_notes_str[140][2]; int16_t special_notes_str[140][2];
talk_save_type talk_save[120]; talk_save_type talk_save[120];
short direction,at_which_save_slot; int16_t direction,at_which_save_slot;
char alchemy[20]; int8_t alchemy[20];
Boolean can_find_town[200]; Boolean can_find_town[200];
short key_times[100]; int16_t key_times[100];
short party_event_timers[30]; int16_t party_event_timers[30];
short global_or_town[30]; int16_t global_or_town[30];
short node_to_call[30]; int16_t node_to_call[30];
char spec_items[50],help_received[120]; int8_t spec_items[50],help_received[120];
short m_killed[200]; int16_t m_killed[200];
long total_m_killed,total_dam_done,total_xp_gained,total_dam_taken; int32_t total_m_killed,total_dam_done,total_xp_gained,total_dam_taken;
char scen_name[256]; char scen_name[256];
} __attribute__((packed)); } __attribute__((packed));
struct scenario_data_type { struct scenario_data_type {
unsigned char out_width,out_height,difficulty,intro_pic,default_ground; uint8_t out_width,out_height,difficulty,intro_pic,default_ground;
unsigned char town_size[200]; uint8_t town_size[200];
unsigned char town_hidden[200]; uint8_t town_hidden[200];
short flag_a; int16_t flag_a;
short intro_mess_pic,intro_mess_len; int16_t intro_mess_pic,intro_mess_len;
location where_start __attribute__((aligned(2))); location where_start __attribute__((aligned(2)));
location out_sec_start,out_start; location out_sec_start,out_start;
short which_town_start; int16_t which_town_start;
short flag_b; int16_t flag_b;
short town_data_size[200][5]; int16_t town_data_size[200][5];
short town_to_add_to[10]; int16_t town_to_add_to[10];
short flag_to_add_to_town[10][2]; int16_t flag_to_add_to_town[10][2];
short flag_c; int16_t flag_c;
short out_data_size[100][2]; int16_t out_data_size[100][2];
Rect store_item_rects[3]; Rect store_item_rects[3];
short store_item_towns[3]; int16_t store_item_towns[3];
short flag_e; int16_t flag_e;
short special_items[50]; int16_t special_items[50];
short special_item_special[50]; int16_t special_item_special[50];
short rating,uses_custom_graphics; int16_t rating,uses_custom_graphics;
short flag_f; int16_t flag_f;
monster_record_type scen_monsters[256]; monster_record_type scen_monsters[256];
boat_record_type scen_boats[30]; boat_record_type scen_boats[30];
horse_record_type scen_horses[30]; horse_record_type scen_horses[30];
short flag_g; int16_t flag_g;
terrain_type_type ter_types[256]; terrain_type_type ter_types[256];
short scenario_timer_times[20]; int16_t scenario_timer_times[20];
short scenario_timer_specs[20]; int16_t scenario_timer_specs[20];
short flag_h; int16_t flag_h;
special_node_type scen_specials[256]; special_node_type scen_specials[256];
item_storage_shortcut_type storage_shortcuts[10]; item_storage_shortcut_type storage_shortcuts[10];
short flag_d; int16_t flag_d;
unsigned char scen_str_len[300]; uint8_t scen_str_len[300];
short flag_i; int16_t flag_i;
location last_out_edited; location last_out_edited;
short last_town_edited; int16_t last_town_edited;
} __attribute__((packed)); } __attribute__((packed));
struct setup_save_type { struct setup_save_type {
unsigned char setup[4][64][64]; uint8_t setup[4][64][64];
} __attribute__((packed)); } __attribute__((packed));
struct pc_record_type { struct pc_record_type {
short main_status; int16_t main_status;
char name[20]; char name[20];
short skills[30]; int16_t skills[30];
short max_health,cur_health,max_sp,cur_sp,experience,skill_pts,level; int16_t max_health,cur_health,max_sp,cur_sp,experience,skill_pts,level;
short status[15]; int16_t status[15];
item_record_type items[24]; item_record_type items[24];
Boolean equip[24]; Boolean equip[24];
Boolean priest_spells[62],mage_spells[62]; Boolean priest_spells[62],mage_spells[62];
short which_graphic,weap_poisoned; int16_t which_graphic,weap_poisoned;
Boolean advan[15],traits[15]; Boolean advan[15],traits[15];
short race,exp_adj,direction; int16_t race,exp_adj,direction;
} __attribute__((packed)); } __attribute__((packed));
struct town_item_list { struct town_item_list {
@@ -350,11 +351,11 @@ namespace legacy {
} __attribute__((packed)); } __attribute__((packed));
struct stored_town_maps_type { struct stored_town_maps_type {
char town_maps[200][8][64]; int8_t town_maps[200][8][64];
} __attribute__((packed)); } __attribute__((packed));
struct stored_outdoor_maps_type { struct stored_outdoor_maps_type {
char outdoor_maps[100][6][48]; int8_t outdoor_maps[100][6][48];
} __attribute__((packed)); } __attribute__((packed));
struct stored_items_list_type { struct stored_items_list_type {
@@ -362,9 +363,9 @@ namespace legacy {
} __attribute__((packed)); } __attribute__((packed));
struct current_town_type { struct current_town_type {
short town_num, difficulty; int16_t town_num, difficulty;
town_record_type town; town_record_type town;
char explored[64][64]; int8_t explored[64][64];
Boolean hostile; Boolean hostile;
creature_list_type monst; creature_list_type monst;
Boolean in_boat; Boolean in_boat;
@@ -372,16 +373,16 @@ namespace legacy {
} __attribute__((packed)); } __attribute__((packed));
struct out_info_type { struct out_info_type {
char expl[96][96]; int8_t expl[96][96];
} __attribute__((packed)); } __attribute__((packed));
// struct piles_of_stuff_dumping_type { // struct piles_of_stuff_dumping_type {
// char strings_ls[NLS][40]; // int8_t strings_ls[NLS][40];
// char strings_rs[NRS][40]; // int8_t strings_rs[NRS][40];
// char town_strs[180][256]; // int8_t town_strs[180][256];
// char out_strs[120][256]; // int8_t out_strs[120][256];
// char scen_strs[270][256]; // int8_t scen_strs[270][256];
// char talk_strs[170][256]; // int8_t talk_strs[170][256];
// scen_item_data_type scen_item_list; // scen_item_data_type scen_item_list;
// }; // };
}; };

View File

@@ -443,7 +443,7 @@ void flip_spec_node(legacy::special_node_type *spec)
flip_short(&(spec->jumpto)); flip_short(&(spec->jumpto));
} }
void flip_short(short *s) void flip_short(int16_t *s)
{ {
char store,*s1, *s2; char store,*s1, *s2;
@@ -455,7 +455,7 @@ void flip_short(short *s)
} }
void flip_long(long *s) void flip_long(int32_t *s)
{ {
char store,*s1, *s2, *s3, *s4; char store,*s1, *s2, *s3, *s4;
@@ -486,9 +486,9 @@ void alter_rect(legacy::Rect *r)
void flip_rect(legacy::Rect* s) void flip_rect(legacy::Rect* s)
{ {
flip_short((short *) &(s->top)); flip_short((int16_t *) &(s->top));
flip_short((short *) &(s->bottom)); flip_short((int16_t *) &(s->bottom));
flip_short((short *) &(s->left)); flip_short((int16_t *) &(s->left));
flip_short((short *) &(s->right)); flip_short((int16_t *) &(s->right));
if(!cur_scen_is_mac) alter_rect(s); if(!cur_scen_is_mac) alter_rect(s);
} }

View File

@@ -8,10 +8,11 @@
#include "oldstructs.h" #include "oldstructs.h"
#include "location.h" #include "location.h"
#include <cstdint>
void flip_long(long *s); void flip_long(int32_t *s);
void flip_spec_node(legacy::special_node_type *spec); void flip_spec_node(legacy::special_node_type *spec);
void flip_short(short *s); void flip_short(int16_t *s);
void flip_rect(legacy::Rect* s); void flip_rect(legacy::Rect* s);
void port_t_d(legacy::big_tr_type* old); void port_t_d(legacy::big_tr_type* old);
@@ -21,7 +22,7 @@ void port_scenario(legacy::scenario_data_type* old);
void port_item_list(legacy::scen_item_data_type* old); void port_item_list(legacy::scen_item_data_type* old);
void port_out(legacy::outdoor_record_type* out); void port_out(legacy::outdoor_record_type* out);
void port_talk_nodes(legacy::talking_record_type* dummy_talk_ptr); void port_talk_nodes(legacy::talking_record_type* dummy_talk_ptr);
void port_dummy_t_d(short size,char *buffer); //void port_dummy_t_d(short size,char *buffer);
void port_town(legacy::town_record_type* dummy_town_ptr); void port_town(legacy::town_record_type* dummy_town_ptr);
void port_party(legacy::party_record_type* old); void port_party(legacy::party_record_type* old);
void port_pc(legacy::pc_record_type* old); void port_pc(legacy::pc_record_type* old);