ff7tk  1.2.0.13
Work with Final Fantasy 7 game data
FF7Save_Types.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012 - 2024 Chris Rizzitello <sithlord48@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-or-later
3 
4 #pragma once
5 
6 #ifdef _MSC_VER
7 # define PACK(structure) \
8  __pragma(pack(push, 1)) \
9  structure \
10  __pragma(pack(pop))
11 #elif defined(__MINGW32__)
12 #define PACK(structure) structure __attribute__ ((gcc_struct, __packed__))
13 #else
14 #define PACK(structure) structure Q_PACKED
15 #endif
16 
17 #include <QVector>
18 #include <ff7tkdata_export.h>
19 #include <Type_FF7CHAR>
20 #include <Type_FF7CHOCOBO>
21 //Materia Type is included as part of FF7Char
22 /*~~~~~~~~~~~~~~~~~~~~~~~~STRUCT TYPES AND SAVE STRUCT~~~~~~~~~~~~~~~~*/
23 PACK(
24 struct FF7TKDATA_EXPORT LOVE {
25  qint8 aeris;
26  qint8 tifa;
27  qint8 yuffie;
28  qint8 barret;
29 });
30 
36 PACK(
37 struct FF7TKDATA_EXPORT FF7DESC {
38  quint8 level;
39  qint8 party[3];
40  quint8 name[16];
41  quint16 curHP;
42  quint16 maxHP;
43  quint16 curMP;
44  quint16 maxMP;
45  quint32 gil;
46  quint32 time;
47  quint8 location[32];
48 });
49 
50 PACK(
51 struct FF7TKDATA_EXPORT FF7XYT {// size of 7. used for coords
52  qint16 x;
53  qint16 y;
54  quint16 t;
55  quint8 d;
56 });
57 
65 PACK(
66 struct FF7TKDATA_EXPORT FF7SLOT {
67  FF7SLOT() { clear(); }
68  static constexpr int emptyChecksum = 0x4D1D;
69  static constexpr int slotSize = 0x10F4;
70  inline bool operator==(FF7SLOT &other) { return other.toByteArray() == toByteArray(); }
71  inline bool operator!=(FF7SLOT &other) { return other.toByteArray() != toByteArray(); }
72  bool isEmpty() { return (checksum == emptyChecksum || toByteArray() == QByteArray(slotSize, 0x00)); }
73  void clear() { setData(QByteArray(slotSize, 0x00)); }
74  QByteArray toByteArray() { return QByteArray(reinterpret_cast<const char*>(&checksum), slotSize); }
75 
76  void setData(const QByteArray &data) {
77  if (data.size() == slotSize)
78  memcpy(&checksum, data, slotSize);
79  }
80 
81  static FF7SLOT fromByteArray(const QByteArray &data) {
82  FF7SLOT s;
83  s.setData(data);
84  return s;
85  }
86 
87  static quint16 generateChecksum(FF7SLOT ff7Slot) {
88  return generateChecksum(ff7Slot.toByteArray());
89  }
90 
91  static quint16 generateChecksum(QByteArray slotData) {
92  QByteArray data = slotData.mid(4);
93  int i = 0;
94  quint16 r = 0xFFFF;
95  quint16 len = data.size();
96  quint16 pbit = 0x8000;
97  while (len--) {
98  int t = data.at(i++);
99  r ^= t << 8;
100  for (int d = 0; d < 8; d++) {
101  if (r & pbit)
102  r = quint16(r << 1) ^ 0x1021;
103  else
104  r <<= 1;
105  }
106  r &= (1 << 16) - 1;
107  }
108  return ((r ^ 0xFFFF) & 0xFFFF);
109  }
110 
111  void updateChecksum() {
112  checksum = generateChecksum(toByteArray());
113  }
114 
115  quint16 checksum;
116  quint8 z_1[2];
117  FF7DESC desc;
118  quint8 colors[4][3];
119  FF7CHAR chars[9];
120  qint8 party[3];
121  quint8 z_2[1];
122  quint16 items[320];
123  materia materias[200];
124  materia stolen[48];
125  quint8 z_3[32];
126  quint32 gil;
127  quint32 time;
128  quint8 timer[3];
129  quint8 z_4[13];
130  quint16 mapid;
131  quint16 locationid;
132  quint8 z_5[2];
133  FF7XYT coord;
134  quint8 z_6[3];
135  quint16 mprogress;
136  quint8 z_7[1];
137  LOVE love;
138  quint8 z_8[17];
139  quint16 battles;
140  quint16 runs;
141  quint16 menu_visible;
142  quint16 menu_locked;
143  quint8 z_9[16];
144  quint8 itemsmask_1;
145  quint8 materiacaves;
146  quint8 z_10[14];
147  quint8 keyitems[8];
148  quint8 z_11[8];
149  LOVE b_love;
150  quint8 z_12[1];
151  qint8 pennedchocos[4];
152  quint8 z_13[2];
153  quint8 u_weapon_hp[3];
154  quint8 seenpandora;
155  quint8 z_14[27];
156  quint8 tut_sub;
157  quint8 ruby_emerald;
158  quint8 z_15[2];
159  quint8 world_map_chocobos;
160  quint8 world_map_vehicles;
161  quint8 z_16[38];
162  quint8 condorlosses;
163  quint8 condorwins;
164  quint8 z_17[12];
165  quint16 condorfunds;
166  quint8 z_18[43];
167  quint8 bm_progress1;
168  quint8 bm_progress2;
169  quint8 z_19[38];
170  quint8 f_party[3];
171  quint8 z_20[4];
172  quint8 aeris_church;
173  quint8 z_21[49];
174  quint8 bm_progress3;
175  quint8 z_22[7];
176  quint16 gp;
177  quint8 z_23[4];
178  quint16 battlepoints;
179  quint8 z_24[6];
180  qint8 stables;
181  qint8 stablesoccupied;
182  quint8 z_25[1];
183  qint8 chocobomask;
184  quint8 chocomated;
185  quint8 z_26[40];
186  quint8 yuffieforest;
187  quint8 z_27[28];
188  quint8 donprogress;
189  quint8 z_28[31];
190  quint8 turtleflyers;
191  quint8 z_29[12];
192  quint8 reg_yuffie;
193  quint8 z_30[15];
194  quint8 midgartrainflags;
195  quint8 z_31[64];
196  FF7CHOCOBO chocobos[4];
197  quint8 z_32[13];
198  quint16 BikeHighScore;
199  quint8 SnowUnused;
200  quint32 SnowBegFastTime;
201  quint32 SnowExpFastTime;
202  quint32 SnowCrazyFastTime;
203  quint8 SnowBegScore;
204  quint8 SnowExpScore;
205  quint8 SnowCrazyScore;
206  quint8 Snowtempvar;
207  quint16 coster_2;
208  quint16 coster_3;
209  quint8 z_33[17];
210  quint16 coster_1;
211  quint8 z_34[1];
212  quint8 battleArenaSpecialWins;
213  quint8 z_35[1];
214  quint8 stablechocorating[6];
215  quint8 z_36[24];
216  qint16 cratersaveMapId;
217  qint16 cratersaveX;
218  qint16 cratersaveY;
219  qint16 cratersaveZ;
220  quint8 z_37[64];
221  qint8 disc;
222  quint8 z_38[1];
223  quint8 intbombing;
224  quint8 z_39[3];
225  quint16 steps;
226  quint8 z_40[22];
227  quint8 field_help;
228  quint8 z_41[1];
229  quint8 chocobonames[6][6];
230  quint16 chocostaminas[6];
231  quint8 reg_vinny;
232  quint8 z_42[23];
233  quint8 location[24];
234  quint8 z_43[5];
235  quint8 tut_save;
236  quint8 z_44[14];
237  quint8 wonsubgame;
238  quint8 z_45[35];
239  quint32 l_world;
240  quint32 l_world2;
241  quint32 wc_world;
242  quint32 wc_world2;
243  quint32 tc_world;
244  quint32 tc_world2;
245  quint32 bh_world;
246  quint32 bh_world2;
247  quint32 sub_world;
248  quint32 sub_world2;
249  quint32 durw_world;
250  quint32 durw_world2;
251  quint16 pole1_x;
252  quint16 pole1_y;
253  quint16 pole2_x;
254  quint16 pole2_y;
255  quint16 pole3_x;
256  quint16 pole3_y;
257  quint8 z_46[236];
258  FF7CHOCOBO choco56[2];
259  quint16 phsallowed;
260  quint16 phsvisible;
261  quint8 z_47[48];
262  quint8 battlespeed;
263  quint8 battlemspeed;
264  quint16 options;
265  quint8 controller_map[16];
266  quint8 fieldmspeed;
267  quint8 z_48[8];
268 });
269 
270 PACK(
271  /* FF7HEADFOOT FORMAT COMPATIBILITY (Vegeta_Ss4) v0.8.3*/
272 struct FF7TKDATA_EXPORT FF7HEADFOOT {
273  quint8 sl_header[0x0200]; // [0x0000] Slot Header
274  quint8 sl_footer[0x0D0C]; // [0x0000] Slot Footer
275 });
276 
277 typedef QVector< QString > SubContainer;
FF7SLOT
Main FF7 Save Data Structure.
FF7DESC
Description of savegame used for previews.
SubContainer
QVector< QString > SubContainer
Definition: FF7Save_Types.h:277
PACK
#define PACK(structure)
Definition: FF7Save_Types.h:14
materia
materia format saved in materia list or on a character
FF7CHAR
Character Info in the save game.
FF7CHOCOBO
a chocobo in save game