KernelDataInstaller.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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/BinGZipFile.h"
  17. #include "common/TypeDefine.h"
  18. #include "Characters.h"
  19. class KernelDataInstaller{
  20. public:
  21. /**
  22. * Constructor.
  23. *
  24. * @param[in] path Absolute path to the KERNEL.BIN file
  25. */
  26. KernelDataInstaller(std::string path);
  27. /**
  28. * Destructor.
  29. */
  30. ~KernelDataInstaller();
  31. /**
  32. * Reads the items from the kernel.
  33. *
  34. * @return The number of items read.
  35. */
  36. int ReadItems();
  37. /**
  38. * Saves item data to an xml file
  39. *
  40. * @param file[in] Absolute path to the target XML file.
  41. */
  42. void WriteItems(std::string file);
  43. /**
  44. * Reads the command from the kernel.
  45. *
  46. * @return The number of items read.
  47. */
  48. int ReadCommands();
  49. /**
  50. * Saves command data to an xml file
  51. *
  52. * @param file[in] Absolute path to the target XML file.
  53. */
  54. void WriteCommands(std::string file);
  55. private:
  56. enum KERNEL_SECTIONS{
  57. /**
  58. * Command data section in KERNEL.BIN.
  59. */
  60. KERNEL_COMMAND_DATA = 0,
  61. /**
  62. * Attack data section in KERNEL.BIN.
  63. */
  64. KERNEL_ATTACK_DATA,
  65. /**
  66. * Battle and growth data section in KERNEL.BIN.
  67. */
  68. KERNEL_BATTLE_AND_GROWTH_DATA,
  69. /**
  70. * Initialization data section in KERNEL.BIN.
  71. */
  72. KERNEL_INITIALIZATION_DATA,
  73. /**
  74. * Item data section in KERNEL.BIN.
  75. */
  76. KERNEL_ITEM_DATA,
  77. /**
  78. * Weapon data section in KERNEL.BIN.
  79. */
  80. KERNEL_WEAPON_DATA,
  81. /**
  82. * Armor data section in KERNEL.BIN.
  83. */
  84. KERNEL_ARMOR_DATA,
  85. /**
  86. * Accessory data section in KERNEL.BIN.
  87. */
  88. KERNEL_ACCESSORY_DATA,
  89. /**
  90. * Materia data section in KERNEL.BIN.
  91. */
  92. KERNEL_MATERIA_DATA,
  93. /**
  94. * Command descriptions section in KERNEL.BIN.
  95. */
  96. KERNEL_COMMAND_DESCRIPTIONS,
  97. /**
  98. * Magic descriptions section in KERNEL.BIN.
  99. */
  100. KERNEL_MAGIC_DESCRIPTIONS,
  101. /**
  102. * Item descriptions section in KERNEL.BIN.
  103. */
  104. KERNEL_ITEM_DESCRIPTIONS,
  105. /**
  106. * Weapon descriptions section in KERNEL.BIN.
  107. */
  108. KERNEL_WEAPON_DESCRIPTIONS,
  109. /**
  110. * Armor descriptions section in KERNEL.BIN.
  111. */
  112. KERNEL_ARMOR_DESCRIPTIONS,
  113. /**
  114. * Accessory descriptions section in KERNEL.BIN.
  115. */
  116. KERNEL_ACCESSORY_DESCRIPTIONS,
  117. /**
  118. * Materia descriptions section in KERNEL.BIN.
  119. */
  120. KERNEL_MATERIA_DESCRIPTIONS,
  121. /**
  122. * Key Item descriptions section in KERNEL.BIN.
  123. */
  124. KERNEL_KEY_ITEM_DESCRIPTIONS,
  125. /**
  126. * Command Names section in KERNEL.BIN.
  127. */
  128. KERNEL_COMMAND_NAMES,
  129. /**
  130. * Magic Names section in KERNEL.BIN.
  131. */
  132. KERNEL_MAGIC_NAMES,
  133. /**
  134. * Item Names section in KERNEL.BIN.
  135. */
  136. KERNEL_ITEM_NAMES,
  137. /**
  138. * Weapon Names section in KERNEL.BIN.
  139. */
  140. KERNEL_WEAPON_NAMES,
  141. /**
  142. * Armor Names section in KERNEL.BIN.
  143. */
  144. KERNEL_ARMOR_NAMES,
  145. /**
  146. * Accessory Names section in KERNEL.BIN.
  147. */
  148. KERNEL_ACCESSORY_NAMES,
  149. /**
  150. * Materia Names section in KERNEL.BIN.
  151. */
  152. KERNEL_MATERIA_NAMES,
  153. /**
  154. * Key Item Names section in KERNEL.BIN.
  155. */
  156. KERNEL_KEY_ITEM_NAMES,
  157. /**
  158. * Battle and Battle-Screen Text section in KERNEL.BIN.
  159. */
  160. KERNEL_BATTLE_AND_BATTLE_SCREEN_TEXT,
  161. /**
  162. * Summon Attack Names section in KERNEL.BIN.
  163. */
  164. KERNEL_SUMMON_ATTACK_NAMES
  165. };
  166. enum ELEMENT{
  167. /**
  168. * Fire element.
  169. */
  170. FIRE = 0,
  171. /**
  172. * Ice element.
  173. */
  174. ICE,
  175. /**
  176. * Bolt element.
  177. */
  178. BOLT,
  179. /**
  180. * Earth element.
  181. */
  182. EARTH,
  183. /**
  184. * Poison element.
  185. */
  186. POISON,
  187. /**
  188. * Gravity element.
  189. */
  190. GRAVITY,
  191. /**
  192. * Water element.
  193. */
  194. WATER,
  195. /**
  196. * Wind element.
  197. */
  198. WIND,
  199. /**
  200. * Holy element.
  201. */
  202. HOLY,
  203. /**
  204. * Restorative element.
  205. */
  206. RESTORATIVE,
  207. /**
  208. * Cut element.
  209. */
  210. CUT,
  211. /**
  212. * Hit element.
  213. */
  214. HIT,
  215. /**
  216. * Punch element.
  217. */
  218. PUNCH,
  219. /**
  220. * Shoot element.
  221. */
  222. SHOOT,
  223. /**
  224. * Shout element.
  225. */
  226. SHOUT,
  227. /**
  228. * Hidden element.
  229. */
  230. HIDDEN,
  231. };
  232. /**
  233. * List of target selection options.
  234. */
  235. struct Target{
  236. /**
  237. * The target can be selected.
  238. *
  239. * If the target of the attack is selectable, at least between some subset of possible
  240. * targets, this must be true.
  241. */
  242. bool selection_enabled;
  243. /**
  244. * The default target is an enemy.
  245. *
  246. * When true, the cursor starts in an enemy row. When false, it starts in the ally row.
  247. * It may or may not be possible to change it.
  248. */
  249. bool default_enemy;
  250. /**
  251. * The default target is a group.
  252. *
  253. * When true, the cursor starts will all the members of a row selected. When false, it
  254. * starts with only one target selected. It may or may not be possible to change it.
  255. */
  256. bool default_multiple;
  257. /**
  258. * The selection can change between groups and individuals.
  259. *
  260. * When true, the target can be changed between groups and individuals When false,
  261. * only {@see default_multiple} determines if the target is an individual or a group.
  262. */
  263. bool toggle_multiple;
  264. /**
  265. * The target group can be changed.
  266. *
  267. * When true, the target cannot be changed between enemies and allies. In this case
  268. * {@see default_enemy} will determine the group that can be targeted.
  269. */
  270. bool fixed_row;
  271. /**
  272. * The command is short ranged.
  273. *
  274. * When true, if the target or the caster is not in the front of their row, the target
  275. * will take half damage. Also, when true, an enemy covered by another enemy can't be
  276. * targeted.
  277. */
  278. bool short_range;
  279. /**
  280. * Targets all, enemies and allies.
  281. *
  282. * When true, all allies and enemies are targets, and the selection can't be changed.
  283. */
  284. bool all_rows;
  285. /**
  286. * The target is random.
  287. *
  288. * When multiple targets are selected, one will be selected at random to be the
  289. * receiving target. Cursor will cycle among all viable targets.
  290. */
  291. bool random;
  292. };
  293. /**
  294. * Determines what an item affects on when used from the menu.
  295. */
  296. enum RESTORE_TYPE{
  297. /**
  298. * The item affects a party member or group HP.
  299. */
  300. RESTORE_HP = 0,
  301. /**
  302. * The item affects a party member or group MP.
  303. */
  304. RESTORE_MP = 1,
  305. /**
  306. * The item affects a party member or group status.
  307. */
  308. RESTORE_STATUS = 2,
  309. /**
  310. * The item is not restorative.
  311. */
  312. RESTORE_NONE = 3
  313. };
  314. /**
  315. * List of altered status.
  316. */
  317. enum STATUS{
  318. /**
  319. * The character is dead.
  320. */
  321. DEATH = 0,
  322. /**
  323. * The character has critical HP.
  324. */
  325. NEAR_DEATH,
  326. /**
  327. * The character is asleep.
  328. */
  329. SLEEP,
  330. /**
  331. * The character is poisoned.
  332. */
  333. POISONED,
  334. /**
  335. * The character is sad.
  336. */
  337. SADNESS,
  338. /**
  339. * The character is furious.
  340. */
  341. FURY,
  342. /**
  343. * The character is confused.
  344. */
  345. CONFU,
  346. /**
  347. * The character is silenced.
  348. */
  349. SILENCE,
  350. /**
  351. * The character is slow.
  352. */
  353. HASTE,
  354. /**
  355. * The character is
  356. */
  357. SLOW,
  358. /**
  359. * The character is stopped.
  360. */
  361. STOP,
  362. /**
  363. * The character is a frog.
  364. */
  365. FROG,
  366. /**
  367. * The character is small.
  368. */
  369. SMALL,
  370. /**
  371. * The character is going to be petrified.
  372. */
  373. SLOW_NUMB,
  374. /**
  375. * The character is petrified.
  376. */
  377. PETRIFY,
  378. /**
  379. * The character is regenerating health.
  380. */
  381. REGEN,
  382. /**
  383. * The character has a physical barrier.
  384. */
  385. BARRIER,
  386. /**
  387. * The character has a magical barrier
  388. */
  389. M_BARRIER,
  390. /**
  391. * The character reflects magical attacks.
  392. */
  393. REFLECT,
  394. /**
  395. * The character has dual status.
  396. *
  397. * @todo What does it do.
  398. */
  399. DUAL,
  400. /**
  401. * The character has a shield.
  402. */
  403. SHIELD,
  404. /**
  405. * The character has a death sentence.
  406. */
  407. D_SENTENCE,
  408. /**
  409. * The character is being manipulated.
  410. */
  411. MANIPULATE,
  412. /**
  413. * The character is berserk.
  414. */
  415. BERSERK,
  416. /**
  417. * The character is invincible.
  418. */
  419. PEERLESS,
  420. /**
  421. * The character is paralyzed.
  422. */
  423. PARALYSIS,
  424. /**
  425. * The character is blinded.
  426. */
  427. DARKNESS,
  428. /**
  429. * The character has dual drain.
  430. */
  431. DUAL_DRAIN,
  432. /**
  433. * The character has deathforce.
  434. */
  435. DEATH_FORCE,
  436. /**
  437. * The character has resist.
  438. */
  439. RESIST,
  440. /**
  441. * Cait' Sith lucky girl mode.
  442. */
  443. LUCKY_GIRL,
  444. /**
  445. * The character is imprisioned.
  446. */
  447. IMPRISONED
  448. };
  449. /**
  450. * How a status effect modifier attack or item can act.
  451. */
  452. enum STATUS_EFFECT{
  453. /**
  454. * Inflicts status changes.
  455. */
  456. INFLICT = 0,
  457. /**
  458. * Cures status changes.
  459. */
  460. CURE = 1,
  461. /**
  462. * Toggles status changes.
  463. *
  464. * If the target doesn't have the status change, inflict it. If the target already has
  465. * the status change, cure it.
  466. */
  467. TOGGLE = 2
  468. };
  469. struct StatusEffect{
  470. /**
  471. * The list of status to inflict or cure.
  472. */
  473. std::vector<int> status;
  474. /**
  475. * The chance of landing a status effect (out of 63).
  476. */
  477. u16 chance;
  478. /**
  479. * The status change mode.
  480. */
  481. STATUS_EFFECT mode;
  482. };
  483. /**
  484. * Data for each command.
  485. *
  486. * As found in KERNEL.BIN, file 0, in order, up to camera_multiple. Members after
  487. * camera_multiple are not found literally in KERNEL.BIN, but are derived from other
  488. * members or found in other files of the kernel (text files).
  489. */
  490. struct CommandData{
  491. /**
  492. * Cursor action when the command is selected.
  493. */
  494. u8 cursor_action;
  495. /**
  496. * Targeting mode. 1 byte.
  497. *
  498. * See {@see target} and {@TargetModes} for more information.
  499. */
  500. u8 target_raw;
  501. /**
  502. * Unknown data (Always 0XFFFF). 2 bytes.
  503. */
  504. u16 unknown;
  505. /**
  506. * Camera movement ID for single target. 2 bytes.
  507. *
  508. * Determines the camera movement when the command is executed over a single target.
  509. */
  510. u16 camera_single;
  511. /**
  512. * Camera movement ID for multiple target. 2 bytes.
  513. *
  514. * Determines the camera movement when the command is executed over multiple targets.
  515. */
  516. u16 camera_multiple;
  517. /**
  518. * Command ID.
  519. *
  520. * Not actually in the item file data, it's the order at which it appears.
  521. */
  522. int id;
  523. /**
  524. * Command name.
  525. *
  526. * Not found in the same file as the rest of the data, but on file 17.
  527. */
  528. std::string name;
  529. /**
  530. * Command description.
  531. *
  532. * Not found in the same file as the rest of the data, but on file 9.
  533. */
  534. std::string description;
  535. /**
  536. * Target selection mode.
  537. *
  538. * Derived from {@see target_raw}.
  539. */
  540. Target target;
  541. };
  542. /**
  543. * Data for each items
  544. *
  545. * As found in KERNEL.BIN, file 4, in order, up to special. Members after special are not
  546. * found literally in KERNEL.BIN, but are derived from other members or found in other
  547. * files of the kernel (text files).
  548. */
  549. struct ItemData{
  550. /**
  551. * Unknown data (Always 0XFFFF). 4 bytes.
  552. */
  553. u32 unknown_0;
  554. /**
  555. * Unknown data (Always 0XFFFF). 4 bytes.
  556. */
  557. u32 unknown_1;
  558. /**
  559. * Camera movement ID. 2 bytes.
  560. *
  561. * Used for items useable in battle, determines the camera movement.
  562. */
  563. u16 camera;
  564. /**
  565. * Item restrictions. 2 bytes.
  566. *
  567. * Contains bits indicating if the item is {@see selleable}, {@see useable_battle} and
  568. * {@see useable_menu}.
  569. */
  570. u16 restrict_raw;
  571. /**
  572. * Targeting mode. 1 byte.
  573. *
  574. * See {@see target} and {@TargetModes} for more information.
  575. */
  576. u8 target_raw;
  577. /**
  578. * Item effect ID. 1 byte.
  579. *
  580. * Used for animation in battle.
  581. */
  582. u8 effect;
  583. /**
  584. * Damage formula. 1 byte.
  585. *
  586. * This byte is divided into two nybbles (four bits). Upper nybble determines what
  587. * considerations are made in calculating damage such as physical/magical, allowing
  588. * criticals, how to calculate accuracy, etc. There are also three sets of known
  589. * formulae that are paired with the upper nybble values. These are selected in the
  590. * Lower Nybble and determine how to calculate pre-defense damage
  591. */
  592. u8 damage_raw;
  593. /**
  594. * The item power. 1 byte.
  595. *
  596. * Used for damage/healing calculation.
  597. */
  598. u8 power;
  599. /**
  600. * The restore type.
  601. *
  602. * See {@restore_typ} and {@RESTORE_TYPE} for more information.
  603. */
  604. u8 condition_raw;
  605. /**
  606. * Information about status change mode and chance. 1 bytes.
  607. */
  608. u8 status_change_raw;
  609. /**
  610. * Special flags. 1 byte.
  611. *
  612. * @todo Document and retrieve with info from
  613. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Attack_Special_Effects
  614. */
  615. u8 additional_effects_raw;
  616. /**
  617. * Special flags. 1 byte.
  618. *
  619. * @todo Document and retrieve with info from
  620. * https://wiki.ffrtt.ru/index.php?title=FF7/Item_data
  621. */
  622. u8 additional_effects_mod_raw;
  623. /**
  624. * Information about what status can be inflicted or cured. 4 bytes.
  625. *
  626. * The first six bits are the chance of inflicting/curing (out of 63). If the seventh
  627. * bit is set, the status is cured instead of inflicted. If the eighth bit is set, then
  628. * the status is toggled (cured if present, inflicted if not present).
  629. */
  630. u32 status_raw;
  631. /**
  632. * Information about the item elements. 2 bytes.
  633. */
  634. u16 element_raw;
  635. /**
  636. * Special flags. 2 bytes.
  637. *
  638. * @todo document and parse with info from
  639. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Special_Attack_Flags
  640. */
  641. u16 special_raw;
  642. /**
  643. * Item ID.
  644. *
  645. * Not actually in the item file data, it's the order at which it appears.
  646. */
  647. int id;
  648. /**
  649. * Item name.
  650. *
  651. * Not found in the same file as the rest of the data, but on file 19.
  652. */
  653. std::string name;
  654. /**
  655. * Item description.
  656. *
  657. * Not found in the same file as the rest of the data, but on file 11.
  658. */
  659. std::string description;
  660. /**
  661. * Indicates if the item can be sold.
  662. *
  663. * True if the bit 0 in {@see restrict_raw} is 0.
  664. */
  665. bool sellable;
  666. /**
  667. * Indicates if the item can be used in battle.
  668. *
  669. * True if the bit 2 in {@see restrict_raw} is 0.
  670. */
  671. bool useable_battle;
  672. /**
  673. * Indicates if the item can be used in the menu.
  674. *
  675. * True if the bit 4 in {@see restrict_raw} is 0.
  676. */
  677. bool useable_menu;
  678. /**
  679. * Target selection mode.
  680. *
  681. * Derived from {@see target_raw}.
  682. */
  683. Target target;
  684. /**
  685. * The damage formula.
  686. *
  687. * It's the upper nybble in {@see damage_raw}.
  688. */
  689. u8 damage_formula;
  690. /**
  691. * The damage modifier.
  692. *
  693. * It's the lower nybble in {@see damage_raw}.
  694. */
  695. u8 damage_modifier;
  696. /**
  697. * What the item restores when used.
  698. *
  699. * Same as {@see condition_raw}, except for the wrong cases.
  700. */
  701. RESTORE_TYPE restore_type;
  702. /**
  703. * Status effects.
  704. *
  705. * Derived from {@see status_change_raw} and {@see status_raw}.
  706. */
  707. StatusEffect status;
  708. /**
  709. * Elements of the item.
  710. *
  711. * Derived from {@see element_raw}.
  712. */
  713. std::vector<int> elements;
  714. };
  715. /**
  716. * Items read from the kernel
  717. */
  718. std::vector<CommandData> commands_;
  719. /**
  720. * Items read from the kernel
  721. */
  722. std::vector<ItemData> items_;
  723. /**
  724. * The kernel file.
  725. */
  726. BinGZipFile kernel_;
  727. };