KernelDataInstaller.h 19 KB

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