SaveMap.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "common/TypeDefine.h"
  17. /**
  18. * The structure of a savemap.
  19. */
  20. struct SaveMap{
  21. /**
  22. * Contains the window colours, grouped by corner. 12 bytes.
  23. */
  24. struct WindowColor{
  25. /**
  26. * Each corner of the window. Three colour components. 3 bytes.
  27. */
  28. struct Corner{
  29. /**
  30. * Red component of the corner. 1 byte.
  31. */
  32. u8 red;
  33. /**
  34. * Green component of the window. 1 byte.
  35. */
  36. u8 green;
  37. /**
  38. * BLue component of the window. 1 byte.
  39. */
  40. u8 blue;
  41. };
  42. /**
  43. * Top left corner. 3 bytes.
  44. */
  45. Corner top_left;
  46. /**
  47. * Top right corner. 3 bytes.
  48. */
  49. Corner top_right;
  50. /**
  51. * Bottom left corner. 3 bytes.
  52. */
  53. Corner bottom_left;
  54. /**
  55. * Bottom right corner. 3 bytes.
  56. */
  57. Corner bottom_right;
  58. };
  59. /**
  60. * A materia. 4 bytes.
  61. *
  62. * @todo
  63. */
  64. struct Materia{
  65. /**
  66. * Materia index. 1 byte.
  67. */
  68. u8 id;
  69. /**
  70. * Materia AP. 3 bytes, not four.
  71. *
  72. * For Enemy Skill materia, ap is not the actual AP, but each byte set indicates a learned
  73. * skill.
  74. */
  75. u32 ap;
  76. };
  77. /**
  78. * Type of inventory item record.
  79. */
  80. enum class INVENTORY_TYPE{
  81. /**
  82. * A normal item.
  83. */
  84. ITEM = 0,
  85. /**
  86. * A weapon.
  87. */
  88. WEAPON,
  89. /**
  90. * An armor.
  91. */
  92. ARMOR,
  93. /**
  94. * An accessory.
  95. */
  96. ACCESSORY
  97. };
  98. /**
  99. * Items, weapons, armors and accessories in inventory. 2 byte.
  100. *
  101. * The first 7 bits are the item quantity. The 9 last bits are the index.
  102. */
  103. struct Item{
  104. /**
  105. * The item bytes, as read from KERNEL.BIN in the save map.
  106. *
  107. * The first 7 bits are the item quantity. The 9 last bits are the index. All the other
  108. * members can be derived from this. Indexex 0-127 are items, 128-255 are weapons, 256-287
  109. * are weapons and 288-319 are accessories.
  110. */
  111. u16 item_raw;
  112. /**
  113. * Item index.
  114. */
  115. int item;
  116. /**
  117. * Item quantity.
  118. */
  119. int quantity;
  120. };
  121. /**
  122. * Information about the player location in a field map. 7 bytes.
  123. */
  124. struct FieldPosition{
  125. /**
  126. * X coordinate on the map. 2 bytes.
  127. */
  128. u16 x;
  129. /**
  130. * Y coordinate on the map. 2 bytes.
  131. */
  132. u16 y;
  133. /**
  134. * Triangle of the walkmesh. 2 bytes.
  135. */
  136. u16 triangle;
  137. /**
  138. * Player orientation. 1 byte.
  139. */
  140. u8 orientation;
  141. };
  142. /**
  143. * Character record. 132 bytes.
  144. */
  145. struct Character{
  146. /**
  147. * Character identifier 1 byte.
  148. *
  149. * It's not the standard character ID. Used only for Cait Sith and Vincent, to distinguish
  150. * them from Young Cloud and Sephiroth. V-Gears mostly ignores this.
  151. */
  152. u8 identifier;
  153. /**
  154. * Character level. 1 byte.
  155. */
  156. u8 level;
  157. /**
  158. * Character strength stat. 1 byte.
  159. */
  160. u8 str;
  161. /**
  162. * Character vitality stat. 1 byte.
  163. */
  164. u8 vit;
  165. /**
  166. * Character magic stat. 1 byte.
  167. */
  168. u8 mag;
  169. /**
  170. * Character spirit stat. 1 byte.
  171. */
  172. u8 spr;
  173. /**
  174. * Character dexterity stat. 1 byte.
  175. */
  176. u8 dex;
  177. /**
  178. * Character luck stat. 1 byte.
  179. */
  180. u8 lck;
  181. /**
  182. * Character strength bonus from sources. 1 byte.
  183. */
  184. u8 str_bonus;
  185. /**
  186. * Character vitality bonus from sources. 1 byte.
  187. */
  188. u8 vit_bonus;
  189. /**
  190. * Character magic bonus from sources. 1 byte.
  191. */
  192. u8 mag_bonus;
  193. /**
  194. * Character spirit bonus from sources. 1 byte.
  195. */
  196. u8 spr_bonus;
  197. /**
  198. * Character dexterity bonus from sources. 1 byte.
  199. */
  200. u8 dex_bonus;
  201. /**
  202. * Character luck bonus from sources. 1 byte.
  203. */
  204. u8 lck_bonus;
  205. /**
  206. * Current limit level (1-4). 1 byte.
  207. */
  208. u8 limit_level;
  209. /**
  210. * Limit bar fill status (0x00: empty, 0xFF, full)
  211. */
  212. u8 limit_bar;
  213. /**
  214. * Character name. FF Text format, ended in 0xFF. 12 bytes.
  215. */
  216. u8 name_raw[12];
  217. /**
  218. * Equipped weapon ID. 1 byte.
  219. */
  220. u8 weapon;
  221. /**
  222. * Equipped armor ID. 1 byte.
  223. */
  224. u8 armor;
  225. /**
  226. * Equipped accessory ID. 0xFF if none. 1 byte.
  227. */
  228. u8 accessory;
  229. /**
  230. * Fury/sadness flags. 1 byte.
  231. *
  232. * 0x10: Sadness.
  233. * 0x20: Fury.
  234. * Other: None.
  235. */
  236. u8 status_raw;
  237. /**
  238. * Character row. 1 byte.
  239. *
  240. * 0xFF: Front row (default).
  241. * 0xFE: Back row.
  242. */
  243. u8 row_raw;
  244. /**
  245. * Progress of the level bar. 1 byte.
  246. *
  247. * Cosmetic only. V-Gears ignores it.
  248. */
  249. u8 level_progress;
  250. /**
  251. * Learned limits. 2 bytes.
  252. *
  253. * XORed values:
  254. * 0x0001: 1-1 Learned.
  255. * 0x0002: 1-2 Learned.
  256. * 0x0008: 2-1 Learned.
  257. * 0x0010: 2-2 Learned.
  258. * 0x0040: 3-1 Learned.
  259. * 0x0080: 3-2 Learned.
  260. * 0x0200: 4-1 Learned.
  261. */
  262. u16 learned_limits_raw;
  263. /**
  264. * Number of monster kills. 2 bytes.
  265. */
  266. u16 kills;
  267. /**
  268. * Number of times the limit 1-1 has been used. 3 x 2 bytes.
  269. *
  270. * 0: Uses of limit 1-1.
  271. * 1: Uses of limit 2-1.
  272. * 2: Uses of limit 3-1.
  273. */
  274. u16 limit_uses[3];
  275. /**
  276. * Current HP. 2 bytes.
  277. */
  278. u16 hp;
  279. /**
  280. * Base HP. 2 bytes.
  281. *
  282. * The max HP before materia alterations.
  283. */
  284. u16 base_hp;
  285. /**
  286. * Current MP. 2 bytes.
  287. */
  288. u16 mp;
  289. /**
  290. * Base MP. 2 bytes.
  291. *
  292. * The max MP before materia alterations.
  293. */
  294. u16 base_mp;
  295. /**
  296. * Unknown data. 4 bytes.
  297. */
  298. u32 unknown;
  299. /**
  300. * Max HP. 2 bytes.
  301. *
  302. * The max HP after materia alterations.
  303. */
  304. u16 max_hp;
  305. /**
  306. * Max MP. 2 bytes.
  307. *
  308. * The max MP after materia alterations.
  309. */
  310. u16 max_mp;
  311. /**
  312. * Total gained experience. 4 bytes.
  313. */
  314. u32 exp;
  315. /**
  316. * Materia equipped in the weapon. 8 x 4 bytes.
  317. */
  318. Materia weapon_materia[8];
  319. /**
  320. * Materia equipped in the armor. 8 x 4 bytes.
  321. */
  322. Materia armor_materia[8];
  323. /**
  324. * Remaining experience to reach next level. 4 bytes.
  325. */
  326. u32 exp_to_next;
  327. /**
  328. * Character name.
  329. *
  330. * Derived from {@see name_raw}.
  331. */
  332. std::string name;
  333. /**
  334. * Indicates if the character is in fury state.
  335. *
  336. * Derived from {@see status_raw}.
  337. */
  338. bool fury;
  339. /**
  340. * Indicates if the character is in saddness state.
  341. *
  342. * Derived from {@see status_raw}.
  343. */
  344. bool sadness;
  345. /**
  346. * Indicates if the character is in the back row.
  347. */
  348. bool back_row;
  349. /**
  350. * Indicates which limits the character have learned.
  351. */
  352. bool limits_learned[4][2];
  353. };
  354. /**
  355. * Each of the memory banks dumped to the savemap. 256 bytes.
  356. */
  357. struct MemoryBank{
  358. /**
  359. * Bank data. 256 x 1 byte.
  360. */
  361. u8 byte[256];
  362. };
  363. /**
  364. * Selections related to the PHS. 2 bytes.
  365. */
  366. struct PhsSelection{
  367. /**
  368. * The mask, as in the savemap.
  369. *
  370. * The first 9 bits, when set, represents characters, sorted by id.
  371. */
  372. u16 mask;
  373. /**
  374. * Character seelction with the mask applied. Selected character IDs are true.
  375. */
  376. bool character[9];
  377. };
  378. /**
  379. * User defined settings. 21 bytes.
  380. */
  381. struct UserSettings{
  382. /**
  383. * Key mappings. 16 bytes.
  384. */
  385. struct KeyMapping{
  386. /**
  387. * L2 key mapping. 1 byte.
  388. */
  389. u8 l2;
  390. /**
  391. * R2 key mapping. 1 byte.
  392. */
  393. u8 r2;
  394. /**
  395. * L1 key mapping. 1 byte.
  396. */
  397. u8 l1;
  398. /**
  399. * R1 key mapping. 1 byte.
  400. */
  401. u8 r1;
  402. /**
  403. * Triangle key mapping. 1 byte.
  404. */
  405. u8 triangle;
  406. /**
  407. * Circle key mapping. 1 byte.
  408. */
  409. u8 circle;
  410. /**
  411. * Cross key mapping. 1 byte.
  412. */
  413. u8 cross;
  414. /**
  415. * Square key mapping. 1 byte.
  416. */
  417. u8 square;
  418. /**
  419. * Select key mapping. 1 byte.
  420. */
  421. u8 select;
  422. /**
  423. * Unknown key mapping. 1 byte.
  424. */
  425. u8 unknown_0;
  426. /**
  427. * Unknown key mapping. 1 byte.
  428. */
  429. u8 unknown_1;
  430. /**
  431. * Start key mapping. 1 byte.
  432. */
  433. u8 start;
  434. /**
  435. * Up key mapping. 1 byte.
  436. */
  437. u8 up;
  438. /**
  439. * Right key mapping. 1 byte.
  440. */
  441. u8 right;
  442. /**
  443. * Down key mapping. 1 byte.
  444. */
  445. u8 down;
  446. /**
  447. * Left key mapping. 1 byte.
  448. */
  449. u8 left;
  450. };
  451. /**
  452. * Battle ATB speed, 0x00: Fast, 0xFF: Slow. 1 byte.
  453. */
  454. u8 battle_speed;
  455. /**
  456. * Battle message speed, 0x00: Fast, 0xFF: Slow. 1 byte.
  457. */
  458. u8 battle_message_speed;
  459. /**
  460. * Several XORed settings. 1 byte.
  461. *
  462. * Sound: mono (0x00); stereo (0x01).
  463. * Controller: normal (0x00); customize (0x04).
  464. * Cursor: initial (0x00); memory (0x10).
  465. * ATB: Active (0x00); Recommended (0x40); Wait (0x80).
  466. */
  467. u8 mask_1;
  468. /**
  469. * Several XORed settings. 1 byte.
  470. *
  471. * Camera angle: Auto (0x00); Fix (0x01)
  472. * Magic order: Restore attack indirect (0x00)
  473. * Magic order: Restore indirect attack (0x04)
  474. * Magic order: Attack indirect restore (0x08)
  475. * Magic order: Attack restore indirect (0x0C)
  476. * Magic order: Indirect restore attack (0x10)
  477. * Magic order: Indirect attack restore (0x14)
  478. * Extra battle window displaying information: Inactive (0x00); Active (0x40)
  479. */
  480. u8 mask_2;
  481. /**
  482. * Key mapping. 16 bytes.
  483. */
  484. KeyMapping mapping;
  485. /**
  486. * Message speed, 0x00: Fast, 0xFF: Slow. 1 byte.
  487. */
  488. u8 message_speed;
  489. };
  490. // TODO: Maybe the header needs to be skipped.
  491. // PSX: 512 bytes.
  492. // PC: 9 bytes.
  493. /**
  494. * Savemap checksum. 4 bytes.
  495. *
  496. * Unused in V-Gears. Never generated.
  497. */
  498. u32 checksum;
  499. /**
  500. * Bytes used for the save preview. 68 bytes
  501. *
  502. * Unused in V-Gears, can be skipped.
  503. */
  504. u8 preview[68];
  505. /**
  506. * Bytes for window color. 12 bytes.
  507. */
  508. WindowColor window_colour;
  509. /**
  510. * Character records. 9 x 132 bytes.
  511. *
  512. * 0: Cloud.
  513. * 1: Barret.
  514. * 2: Tifa.
  515. * 3: Aeris.
  516. * 4: Red XIII.
  517. * 5: Yuffie.
  518. * 6: Cait Sith / Young Cloud.
  519. * 7: Vincent / Sephiroth.
  520. */
  521. Character characters[9];
  522. /**
  523. * IDs of characters in the party. 3 x 1 byte.
  524. */
  525. u8 party[3];
  526. /**
  527. * Unused data. Always 0xFF. 1 byte.
  528. */
  529. u8 unused_0;
  530. /**
  531. * Inventory list. 320 x 2 bytes,
  532. *
  533. * It includes items, unequipped weapons, unequipped armor and unequipped accessories.
  534. */
  535. Item inventory[320];
  536. /**
  537. * Unequipped materia list. 200 x 4 bytes.
  538. */
  539. Materia materia[200];
  540. /**
  541. * Materia stolen by Yuffie. 48 x 4 bytes.
  542. */
  543. Materia stolen_materia[48];
  544. /**
  545. * Unknown data. Always 0xFFFFFFFF. 4 bytes.
  546. */
  547. u32 unknown_0;
  548. /**
  549. * Current Gil. 4 bytes.
  550. */
  551. u32 gil;
  552. /**
  553. * Total played time, in seconds. 4 bytes.
  554. */
  555. u32 time;
  556. /**
  557. * Countdown time, in seconds. 4 bytes.
  558. */
  559. u32 countdown;
  560. /**
  561. * Unknown data. 3 bytes.
  562. */
  563. u8 unknown_1[3];
  564. /**
  565. * Total played time, fractions of seconds. 4 bytes.
  566. *
  567. * Ignored by V-Gears.
  568. */
  569. u32 time_fractions;
  570. /**
  571. * Countdown time, fractions of seconds. 4 bytes.
  572. *
  573. * Ignored by V-Gears.
  574. */
  575. u32 countdown_fractions;
  576. /**
  577. * Current game module, redundant. 4 bytes.
  578. *
  579. * Ignored by V-Gears.
  580. */
  581. u32 module_redundant;
  582. /**
  583. * Current game module. 4 bytes.
  584. *
  585. * 1: Game saved in a field.
  586. * 3: Game saved in the world map.
  587. */
  588. u16 module;
  589. /**
  590. * Saving location. 2 bytes.
  591. *
  592. * @todo Does this indicte the current field? The coordinates in a field? If so, 2 nybbles?
  593. */
  594. u16 location;
  595. /**
  596. * Unused data. Always 0xFF. 1 byte.
  597. */
  598. u8 unused_1;
  599. /**
  600. * Position information on a field map. 5 bytes.
  601. */
  602. FieldPosition field_position;
  603. /**
  604. * Unknown data. 3 bytes.
  605. */
  606. u8 unknown_2[3];
  607. /**
  608. * Information to seed encounter data.
  609. *
  610. * V-Gears ignores this.
  611. */
  612. u8 encounter_step;
  613. /**
  614. * Information to seed encounter data.
  615. *
  616. * V-Gears ignores this.
  617. */
  618. u8 encounter_offset;
  619. /**
  620. * Unused data. Always 0xFF. 1 byte.
  621. */
  622. u8 unused_2;
  623. /**
  624. * Memory banks dumped in the savemap. 5 x 256 bytes.
  625. */
  626. MemoryBank bank[5];
  627. /**
  628. * Characters locked in the PHS. 2 bytes.
  629. *
  630. * Locked characters can be switched to or from the party.
  631. */
  632. PhsSelection phs_lock;
  633. /**
  634. * Characters available in the PHS. 2 bytes.
  635. *
  636. * Available characters appear in the PHS.
  637. */
  638. PhsSelection phs_available;
  639. /**
  640. * Unknown data. 48 bytes.
  641. */
  642. u8 unknown_3[48];
  643. /**
  644. * UserSettings. 21 bytes.
  645. */
  646. UserSettings user_settings;
  647. /**
  648. * Unknown data. 8 bytes.
  649. */
  650. u8 unknown_4[8];
  651. };