KernelDataInstaller.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775
  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 command data from the kernel.
  33. *
  34. * @return The number of commands read.
  35. */
  36. int ReadCommands();
  37. /**
  38. * Saves command data to an xml file
  39. *
  40. * @param file[in] Absolute path to the target XML file.
  41. */
  42. void WriteCommands(std::string file);
  43. /**
  44. * Reads the attack data from the kernel.
  45. *
  46. * @return The number of attacks read.
  47. */
  48. int ReadAttacks();
  49. /**
  50. * Saves command data to an xml file
  51. *
  52. * @param file[in] Absolute path to the target XML file.
  53. */
  54. void WriteAttacks(std::string file);
  55. /**
  56. * Reads character data from the kernel.
  57. *
  58. * @return The number of characters read.
  59. */
  60. int ReadCharacters();
  61. /**
  62. * Saves character data to an xml file
  63. *
  64. * @param file[in] Absolute path to the target XML file.
  65. */
  66. void WriteCharacters(std::string file);
  67. /**
  68. * Reads growth data from the kernel.
  69. */
  70. void ReadGrowth();
  71. /**
  72. * Saves growth data to an xml file
  73. *
  74. * @param file[in] Absolute path to the target XML file.
  75. */
  76. void WriteGrowth(std::string file);
  77. /**
  78. * Reads the items from the kernel.
  79. *
  80. * @return The number of items read.
  81. */
  82. int ReadItems();
  83. /**
  84. * Saves item data to an xml file
  85. *
  86. * @param file[in] Absolute path to the target XML file.
  87. */
  88. void WriteItems(std::string file);
  89. /**
  90. * Reads the weapon info from the kernel.
  91. *
  92. * @return The number of weapons read.
  93. */
  94. int ReadWeapons();
  95. /**
  96. * Saves weapon data to an xml file
  97. *
  98. * @param file[in] Absolute path to the target XML file.
  99. */
  100. void WriteWeapons(std::string file);
  101. private:
  102. enum KERNEL_SECTIONS{
  103. /**
  104. * Command data section in KERNEL.BIN.
  105. */
  106. KERNEL_COMMAND_DATA = 0,
  107. /**
  108. * Attack data section in KERNEL.BIN.
  109. */
  110. KERNEL_ATTACK_DATA,
  111. /**
  112. * Battle and growth data section in KERNEL.BIN.
  113. */
  114. KERNEL_BATTLE_AND_GROWTH_DATA,
  115. /**
  116. * Initialization data section in KERNEL.BIN.
  117. */
  118. KERNEL_INITIALIZATION_DATA,
  119. /**
  120. * Item data section in KERNEL.BIN.
  121. */
  122. KERNEL_ITEM_DATA,
  123. /**
  124. * Weapon data section in KERNEL.BIN.
  125. */
  126. KERNEL_WEAPON_DATA,
  127. /**
  128. * Armor data section in KERNEL.BIN.
  129. */
  130. KERNEL_ARMOR_DATA,
  131. /**
  132. * Accessory data section in KERNEL.BIN.
  133. */
  134. KERNEL_ACCESSORY_DATA,
  135. /**
  136. * Materia data section in KERNEL.BIN.
  137. */
  138. KERNEL_MATERIA_DATA,
  139. /**
  140. * Command descriptions section in KERNEL.BIN.
  141. */
  142. KERNEL_COMMAND_DESCRIPTIONS,
  143. /**
  144. * Magic descriptions section in KERNEL.BIN.
  145. */
  146. KERNEL_MAGIC_DESCRIPTIONS,
  147. /**
  148. * Item descriptions section in KERNEL.BIN.
  149. */
  150. KERNEL_ITEM_DESCRIPTIONS,
  151. /**
  152. * Weapon descriptions section in KERNEL.BIN.
  153. */
  154. KERNEL_WEAPON_DESCRIPTIONS,
  155. /**
  156. * Armor descriptions section in KERNEL.BIN.
  157. */
  158. KERNEL_ARMOR_DESCRIPTIONS,
  159. /**
  160. * Accessory descriptions section in KERNEL.BIN.
  161. */
  162. KERNEL_ACCESSORY_DESCRIPTIONS,
  163. /**
  164. * Materia descriptions section in KERNEL.BIN.
  165. */
  166. KERNEL_MATERIA_DESCRIPTIONS,
  167. /**
  168. * Key Item descriptions section in KERNEL.BIN.
  169. */
  170. KERNEL_KEY_ITEM_DESCRIPTIONS,
  171. /**
  172. * Command Names section in KERNEL.BIN.
  173. */
  174. KERNEL_COMMAND_NAMES,
  175. /**
  176. * Magic Names section in KERNEL.BIN.
  177. */
  178. KERNEL_MAGIC_NAMES,
  179. /**
  180. * Item Names section in KERNEL.BIN.
  181. */
  182. KERNEL_ITEM_NAMES,
  183. /**
  184. * Weapon Names section in KERNEL.BIN.
  185. */
  186. KERNEL_WEAPON_NAMES,
  187. /**
  188. * Armor Names section in KERNEL.BIN.
  189. */
  190. KERNEL_ARMOR_NAMES,
  191. /**
  192. * Accessory Names section in KERNEL.BIN.
  193. */
  194. KERNEL_ACCESSORY_NAMES,
  195. /**
  196. * Materia Names section in KERNEL.BIN.
  197. */
  198. KERNEL_MATERIA_NAMES,
  199. /**
  200. * Key Item Names section in KERNEL.BIN.
  201. */
  202. KERNEL_KEY_ITEM_NAMES,
  203. /**
  204. * Battle and Battle-Screen Text section in KERNEL.BIN.
  205. */
  206. KERNEL_BATTLE_AND_BATTLE_SCREEN_TEXT,
  207. /**
  208. * Summon Attack Names section in KERNEL.BIN.
  209. */
  210. KERNEL_SUMMON_ATTACK_NAMES
  211. };
  212. enum ELEMENT{
  213. /**
  214. * Fire element.
  215. */
  216. FIRE = 0,
  217. /**
  218. * Ice element.
  219. */
  220. ICE,
  221. /**
  222. * Bolt element.
  223. */
  224. BOLT,
  225. /**
  226. * Earth element.
  227. */
  228. EARTH,
  229. /**
  230. * Poison element.
  231. */
  232. POISON,
  233. /**
  234. * Gravity element.
  235. */
  236. GRAVITY,
  237. /**
  238. * Water element.
  239. */
  240. WATER,
  241. /**
  242. * Wind element.
  243. */
  244. WIND,
  245. /**
  246. * Holy element.
  247. */
  248. HOLY,
  249. /**
  250. * Restorative element.
  251. */
  252. RESTORATIVE,
  253. /**
  254. * Cut element.
  255. */
  256. CUT,
  257. /**
  258. * Hit element.
  259. */
  260. HIT,
  261. /**
  262. * Punch element.
  263. */
  264. PUNCH,
  265. /**
  266. * Shoot element.
  267. */
  268. SHOOT,
  269. /**
  270. * Shout element.
  271. */
  272. SHOUT,
  273. /**
  274. * Hidden element.
  275. */
  276. HIDDEN,
  277. };
  278. /**
  279. * List of target selection options.
  280. */
  281. struct Target{
  282. /**
  283. * The target can be selected.
  284. *
  285. * If the target of the attack is selectable, at least between some subset of possible
  286. * targets, this must be true.
  287. */
  288. bool selection_enabled;
  289. /**
  290. * The default target is an enemy.
  291. *
  292. * When true, the cursor starts in an enemy row. When false, it starts in the ally row.
  293. * It may or may not be possible to change it.
  294. */
  295. bool default_enemy;
  296. /**
  297. * The default target is a group.
  298. *
  299. * When true, the cursor starts will all the members of a row selected. When false, it
  300. * starts with only one target selected. It may or may not be possible to change it.
  301. */
  302. bool default_multiple;
  303. /**
  304. * The selection can change between groups and individuals.
  305. *
  306. * When true, the target can be changed between groups and individuals When false,
  307. * only {@see default_multiple} determines if the target is an individual or a group.
  308. */
  309. bool toggle_multiple;
  310. /**
  311. * The target group can be changed.
  312. *
  313. * When true, the target cannot be changed between enemies and allies. In this case
  314. * {@see default_enemy} will determine the group that can be targeted.
  315. */
  316. bool fixed_row;
  317. /**
  318. * The command is short ranged.
  319. *
  320. * When true, if the target or the caster is not in the front of their row, the target
  321. * will take half damage. Also, when true, an enemy covered by another enemy can't be
  322. * targeted.
  323. */
  324. bool short_range;
  325. /**
  326. * Targets all, enemies and allies.
  327. *
  328. * When true, all allies and enemies are targets, and the selection can't be changed.
  329. */
  330. bool all_rows;
  331. /**
  332. * The target is random.
  333. *
  334. * When multiple targets are selected, one will be selected at random to be the
  335. * receiving target. Cursor will cycle among all viable targets.
  336. */
  337. bool random;
  338. };
  339. /**
  340. * Determines what an item affects on when used from the menu.
  341. */
  342. enum RESTORE_TYPE{
  343. /**
  344. * The item affects a party member or group HP.
  345. */
  346. RESTORE_HP = 0,
  347. /**
  348. * The item affects a party member or group MP.
  349. */
  350. RESTORE_MP = 1,
  351. /**
  352. * The item affects a party member or group status.
  353. */
  354. RESTORE_STATUS = 2,
  355. /**
  356. * The item is not restorative.
  357. */
  358. RESTORE_NONE = 3
  359. };
  360. /**
  361. * List of altered status.
  362. */
  363. enum STATUS{
  364. /**
  365. * The character is dead.
  366. */
  367. DEATH = 0,
  368. /**
  369. * The character has critical HP.
  370. */
  371. NEAR_DEATH,
  372. /**
  373. * The character is asleep.
  374. */
  375. SLEEP,
  376. /**
  377. * The character is poisoned.
  378. */
  379. POISONED,
  380. /**
  381. * The character is sad.
  382. */
  383. SADNESS,
  384. /**
  385. * The character is furious.
  386. */
  387. FURY,
  388. /**
  389. * The character is confused.
  390. */
  391. CONFU,
  392. /**
  393. * The character is silenced.
  394. */
  395. SILENCE,
  396. /**
  397. * The character is slow.
  398. */
  399. HASTE,
  400. /**
  401. * The character is
  402. */
  403. SLOW,
  404. /**
  405. * The character is stopped.
  406. */
  407. STOP,
  408. /**
  409. * The character is a frog.
  410. */
  411. FROG,
  412. /**
  413. * The character is small.
  414. */
  415. SMALL,
  416. /**
  417. * The character is going to be petrified.
  418. */
  419. SLOW_NUMB,
  420. /**
  421. * The character is petrified.
  422. */
  423. PETRIFY,
  424. /**
  425. * The character is regenerating health.
  426. */
  427. REGEN,
  428. /**
  429. * The character has a physical barrier.
  430. */
  431. BARRIER,
  432. /**
  433. * The character has a magical barrier
  434. */
  435. M_BARRIER,
  436. /**
  437. * The character reflects magical attacks.
  438. */
  439. REFLECT,
  440. /**
  441. * The character has dual status.
  442. *
  443. * @todo What does it do.
  444. */
  445. DUAL,
  446. /**
  447. * The character has a shield.
  448. */
  449. SHIELD,
  450. /**
  451. * The character has a death sentence.
  452. */
  453. D_SENTENCE,
  454. /**
  455. * The character is being manipulated.
  456. */
  457. MANIPULATE,
  458. /**
  459. * The character is berserk.
  460. */
  461. BERSERK,
  462. /**
  463. * The character is invincible.
  464. */
  465. PEERLESS,
  466. /**
  467. * The character is paralyzed.
  468. */
  469. PARALYSIS,
  470. /**
  471. * The character is blinded.
  472. */
  473. DARKNESS,
  474. /**
  475. * The character has dual drain.
  476. */
  477. DUAL_DRAIN,
  478. /**
  479. * The character has deathforce.
  480. */
  481. DEATH_FORCE,
  482. /**
  483. * The character has resist.
  484. */
  485. RESIST,
  486. /**
  487. * Cait' Sith lucky girl mode.
  488. */
  489. LUCKY_GIRL,
  490. /**
  491. * The character is imprisioned.
  492. */
  493. IMPRISONED
  494. };
  495. /**
  496. * How a status effect modifier attack or item can act.
  497. */
  498. enum STATUS_EFFECT{
  499. /**
  500. * Inflicts status changes.
  501. */
  502. INFLICT = 0,
  503. /**
  504. * Cures status changes.
  505. */
  506. CURE = 1,
  507. /**
  508. * Toggles status changes.
  509. *
  510. * If the target doesn't have the status change, inflict it. If the target already has
  511. * the status change, cure it.
  512. */
  513. TOGGLE = 2
  514. };
  515. struct StatusEffect{
  516. /**
  517. * The list of status to inflict or cure.
  518. */
  519. std::vector<int> status;
  520. /**
  521. * The chance of landing a status effect (out of 63).
  522. */
  523. u16 chance;
  524. /**
  525. * The status change mode.
  526. */
  527. STATUS_EFFECT mode;
  528. };
  529. /**
  530. * Data for each command.
  531. *
  532. * As found in KERNEL.BIN, file 0, in order, up to camera_multiple. Members after
  533. * camera_multiple are not found literally in KERNEL.BIN, but are derived from other
  534. * members or found in other files of the kernel (text files).
  535. */
  536. struct CommandData{
  537. /**
  538. * Cursor action when the command is selected.
  539. */
  540. u8 cursor_action;
  541. /**
  542. * Targeting mode. 1 byte.
  543. *
  544. * See {@see target} and {@TargetModes} for more information.
  545. */
  546. u8 target_raw;
  547. /**
  548. * Unknown data (Always 0XFFFF). 2 bytes.
  549. */
  550. u16 unknown;
  551. /**
  552. * Camera movement ID for single target. 2 bytes.
  553. *
  554. * Determines the camera movement when the command is executed over a single target.
  555. */
  556. u16 camera_single;
  557. /**
  558. * Camera movement ID for multiple target. 2 bytes.
  559. *
  560. * Determines the camera movement when the command is executed over multiple targets.
  561. */
  562. u16 camera_multiple;
  563. /**
  564. * Command ID.
  565. *
  566. * Not actually in the item file data, it's the order at which it appears.
  567. */
  568. int id;
  569. /**
  570. * Command name.
  571. *
  572. * Not found in the same file as the rest of the data, but on file 17.
  573. */
  574. std::string name;
  575. /**
  576. * Command description.
  577. *
  578. * Not found in the same file as the rest of the data, but on file 9.
  579. */
  580. std::string description;
  581. /**
  582. * Target selection mode.
  583. *
  584. * Derived from {@see target_raw}.
  585. */
  586. Target target;
  587. };
  588. /**
  589. * Data for each attack.
  590. *
  591. * As found in KERNEL.BIN, file 1, in order, up to camera_multiple. Members after
  592. * special_raw are not found literally in KERNEL.BIN, but are derived from other
  593. * members.
  594. */
  595. struct AttackData{
  596. /**
  597. * Probability of the attack to land. 1 byte.
  598. */
  599. u8 accuracy;
  600. /**
  601. * Impact effect. 1 byte.
  602. *
  603. * The sprite shown when the attack hits.
  604. */
  605. u8 impact_effect;
  606. /**
  607. * Index of the animation played by the target when hit. 1 byte.
  608. */
  609. u8 hurt_anim;
  610. /**
  611. * Unknown data. 1 bytes.
  612. */
  613. u8 unknown;
  614. /**
  615. * MP cost. 2 bytes.
  616. *
  617. * Determines the camera movement when the command is executed over a single target.
  618. */
  619. u16 mp;
  620. /**
  621. * Impact sound. 2 bytes.
  622. *
  623. * Determines the camera movement when the command is executed over multiple targets.
  624. */
  625. u16 sound;
  626. /**
  627. * Camera movement ID for single target. 2 bytes.
  628. *
  629. * Determines the camera movement when the command is executed over a single target.
  630. */
  631. u16 camera_single;
  632. /**
  633. * Camera movement ID for multiple target. 2 bytes.
  634. *
  635. * Determines the camera movement when the command is executed over multiple targets.
  636. */
  637. u16 camera_multiple;
  638. /**
  639. * Targeting mode. 1 byte.
  640. *
  641. * See {@see target} and {@TargetModes} for more information.
  642. */
  643. u8 target_raw;
  644. /**
  645. * Atack effect ID. 1 byte.
  646. *
  647. * Used for animation in battle.
  648. */
  649. u8 effect;
  650. /**
  651. * Damage formula. 1 byte.
  652. *
  653. * This byte is divided into two nybbles (four bits). Upper nybble determines what
  654. * considerations are made in calculating damage such as physical/magical, allowing
  655. * criticals, how to calculate accuracy, etc. There are also three sets of known
  656. * formulae that are paired with the upper nybble values. These are selected in the
  657. * Lower Nybble and determine how to calculate pre-defense damage
  658. */
  659. u8 damage_raw;
  660. /**
  661. * The attack power. 1 byte.
  662. *
  663. * Used for damage/healing calculation.
  664. */
  665. u8 power;
  666. /**
  667. * The restore type.
  668. *
  669. * See {@restore_typ} and {@RESTORE_TYPE} for more information.
  670. */
  671. u8 condition_raw;
  672. /**
  673. * Information about status change mode and chance. 1 bytes.
  674. */
  675. u8 status_change_raw;
  676. /**
  677. * Special flags. 1 byte.
  678. *
  679. * @todo Document and retrieve with info from
  680. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Attack_Special_Effects
  681. */
  682. u8 additional_effects_raw;
  683. /**
  684. * Special flags. 1 byte.
  685. *
  686. * @todo Document and retrieve with info from
  687. * https://wiki.ffrtt.ru/index.php?title=FF7/Item_data
  688. */
  689. u8 additional_effects_mod_raw;
  690. /**
  691. * Information about what status can be inflicted or cured. 4 bytes.
  692. *
  693. * The first six bits are the chance of inflicting/curing (out of 63). If the seventh
  694. * bit is set, the status is cured instead of inflicted. If the eighth bit is set, then
  695. * the status is toggled (cured if present, inflicted if not present).
  696. */
  697. u32 status_raw;
  698. /**
  699. * Information about the item elements. 2 bytes.
  700. */
  701. u16 element_raw;
  702. /**
  703. * Special flags. 2 bytes.
  704. *
  705. * @todo document and parse with info from
  706. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Special_Attack_Flags
  707. */
  708. u16 special_raw;
  709. /**
  710. * Attack ID.
  711. *
  712. * Not actually in the item file data, it's the order at which it appears.
  713. */
  714. int id;
  715. /**
  716. * Target selection mode.
  717. *
  718. * Derived from {@see target_raw}.
  719. */
  720. Target target;
  721. /**
  722. * The damage formula.
  723. *
  724. * It's the upper nybble in {@see damage_raw}.
  725. */
  726. u8 damage_formula;
  727. /**
  728. * The damage modifier.
  729. *
  730. * It's the lower nybble in {@see damage_raw}.
  731. */
  732. u8 damage_modifier;
  733. /**
  734. * What the attack restores when used.
  735. *
  736. * Same as {@see condition_raw}, except for the wrong cases.
  737. */
  738. RESTORE_TYPE restore_type;
  739. /**
  740. * Status effects.
  741. *
  742. * Derived from {@see status_change_raw} and {@see status_raw}.
  743. */
  744. StatusEffect status;
  745. /**
  746. * Elements of the attack.
  747. *
  748. * Derived from {@see element_raw}.
  749. */
  750. std::vector<int> elements;
  751. };
  752. /**
  753. * Data for each items
  754. *
  755. * As found in KERNEL.BIN, file 4, in order, up to special. Members after special are not
  756. * found literally in KERNEL.BIN, but are derived from other members or found in other
  757. * files of the kernel (text files).
  758. */
  759. struct ItemData{
  760. /**
  761. * Unknown data (Always 0XFFFF). 4 bytes.
  762. */
  763. u32 unknown_0;
  764. /**
  765. * Unknown data (Always 0XFFFF). 4 bytes.
  766. */
  767. u32 unknown_1;
  768. /**
  769. * Camera movement ID. 2 bytes.
  770. *
  771. * Used for items useable in battle, determines the camera movement.
  772. */
  773. u16 camera;
  774. /**
  775. * Item restrictions. 2 bytes.
  776. *
  777. * Contains bits indicating if the item is {@see selleable}, {@see useable_battle} and
  778. * {@see useable_menu}.
  779. */
  780. u16 restrict_raw;
  781. /**
  782. * Targeting mode. 1 byte.
  783. *
  784. * See {@see target} and {@TargetModes} for more information.
  785. */
  786. u8 target_raw;
  787. /**
  788. * Item effect ID. 1 byte.
  789. *
  790. * Used for animation in battle.
  791. */
  792. u8 effect;
  793. /**
  794. * Damage formula. 1 byte.
  795. *
  796. * This byte is divided into two nybbles (four bits). Upper nybble determines what
  797. * considerations are made in calculating damage such as physical/magical, allowing
  798. * criticals, how to calculate accuracy, etc. There are also three sets of known
  799. * formulae that are paired with the upper nybble values. These are selected in the
  800. * Lower Nybble and determine how to calculate pre-defense damage
  801. */
  802. u8 damage_raw;
  803. /**
  804. * The item power. 1 byte.
  805. *
  806. * Used for damage/healing calculation.
  807. */
  808. u8 power;
  809. /**
  810. * The restore type.
  811. *
  812. * See {@restore_typ} and {@RESTORE_TYPE} for more information.
  813. */
  814. u8 condition_raw;
  815. /**
  816. * Information about status change mode and chance. 1 bytes.
  817. */
  818. u8 status_change_raw;
  819. /**
  820. * Special flags. 1 byte.
  821. *
  822. * @todo Document and retrieve with info from
  823. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Attack_Special_Effects
  824. */
  825. u8 additional_effects_raw;
  826. /**
  827. * Special flags. 1 byte.
  828. *
  829. * @todo Document and retrieve with info from
  830. * https://wiki.ffrtt.ru/index.php?title=FF7/Item_data
  831. */
  832. u8 additional_effects_mod_raw;
  833. /**
  834. * Information about what status can be inflicted or cured. 4 bytes.
  835. *
  836. * The first six bits are the chance of inflicting/curing (out of 63). If the seventh
  837. * bit is set, the status is cured instead of inflicted. If the eighth bit is set, then
  838. * the status is toggled (cured if present, inflicted if not present).
  839. */
  840. u32 status_raw;
  841. /**
  842. * Information about the item elements. 2 bytes.
  843. */
  844. u16 element_raw;
  845. /**
  846. * Special flags. 2 bytes.
  847. *
  848. * @todo document and parse with info from
  849. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Special_Attack_Flags
  850. */
  851. u16 special_raw;
  852. /**
  853. * Item ID.
  854. *
  855. * Not actually in the item file data, it's the order at which it appears.
  856. */
  857. int id;
  858. /**
  859. * Item name.
  860. *
  861. * Not found in the same file as the rest of the data, but on file 19.
  862. */
  863. std::string name;
  864. /**
  865. * Item description.
  866. *
  867. * Not found in the same file as the rest of the data, but on file 11.
  868. */
  869. std::string description;
  870. /**
  871. * Indicates if the item can be sold.
  872. *
  873. * True if the bit 0 in {@see restrict_raw} is 0.
  874. */
  875. bool sellable;
  876. /**
  877. * Indicates if the item can be used in battle.
  878. *
  879. * True if the bit 2 in {@see restrict_raw} is 0.
  880. */
  881. bool useable_battle;
  882. /**
  883. * Indicates if the item can be used in the menu.
  884. *
  885. * True if the bit 4 in {@see restrict_raw} is 0.
  886. */
  887. bool useable_menu;
  888. /**
  889. * Target selection mode.
  890. *
  891. * Derived from {@see target_raw}.
  892. */
  893. Target target;
  894. /**
  895. * The damage formula.
  896. *
  897. * It's the upper nybble in {@see damage_raw}.
  898. */
  899. u8 damage_formula;
  900. /**
  901. * The damage modifier.
  902. *
  903. * It's the lower nybble in {@see damage_raw}.
  904. */
  905. u8 damage_modifier;
  906. /**
  907. * What the item restores when used.
  908. *
  909. * Same as {@see condition_raw}, except for the wrong cases.
  910. */
  911. RESTORE_TYPE restore_type;
  912. /**
  913. * Status effects.
  914. *
  915. * Derived from {@see status_change_raw} and {@see status_raw}.
  916. */
  917. StatusEffect status;
  918. /**
  919. * Elements of the item.
  920. *
  921. * Derived from {@see element_raw}.
  922. */
  923. std::vector<int> elements;
  924. };
  925. /**
  926. * Materia slot types.
  927. */
  928. enum SLOT_TYPE{
  929. /**
  930. * A non linked slot.
  931. */
  932. SLOT_UNLINKED = 0,
  933. /**
  934. * A linked slot.
  935. *
  936. * If the slot is in an even position, it's linked to the one in the right. If it's in
  937. * an odd position, it;s linked to the one in the Left. Remember that slot positions
  938. * are 0-index.
  939. */
  940. SLOT_LINKED = 1
  941. };
  942. /**
  943. * Bonus in stat givven by weapons or armor.
  944. */
  945. struct StatBonus{
  946. /**
  947. * ID of the raised stat.
  948. */
  949. u8 stat;
  950. /**
  951. * Stat value raise.
  952. */
  953. u32 bonus;
  954. };
  955. /**
  956. * Data for each weapon
  957. *
  958. * As found in KERNEL.BIN, file 5, in order, up to special. Members after special are not
  959. * found literally in KERNEL.BIN, but are derived from other members or found in other
  960. * files of the kernel (text files).
  961. */
  962. struct WeaponData{
  963. /**
  964. * Targeting mode. 1 byte.
  965. *
  966. * See {@see target} and {@TargetModes} for more information.
  967. */
  968. u8 target_raw;
  969. /**
  970. * Effect ID, unused (Always 0XFFFF). 1 byte.
  971. */
  972. u8 unused_0;
  973. /**
  974. * Damage formula. 1 byte.
  975. *
  976. * This byte is divided into two nybbles (four bits). Upper nybble determines what
  977. * considerations are made in calculating damage such as physical/magical, allowing
  978. * criticals, how to calculate accuracy, etc. There are also three sets of known
  979. * formulae that are paired with the upper nybble values. These are selected in the
  980. * Lower Nybble and determine how to calculate pre-defense damage
  981. */
  982. u8 damage_raw;
  983. /**
  984. * Unused data (Always 0XFFFF). 1 byte.
  985. */
  986. u8 unused_1;
  987. /**
  988. * The weapon power. 1 byte.
  989. *
  990. * Used for damage calculation.
  991. */
  992. u8 power;
  993. /**
  994. * The status effect the weapon induces. 1 byte.
  995. */
  996. u8 status;
  997. /**
  998. * Weapon materia growth multiplier. 1 byte.
  999. */
  1000. u8 growth;
  1001. /**
  1002. * Weapon critical chance. 1 byte.
  1003. */
  1004. u8 critical;
  1005. /**
  1006. * Weapon accuracy. 1 byte.
  1007. */
  1008. u8 accuracy;
  1009. /**
  1010. * Weapon battle model. 1 byte.
  1011. *
  1012. * This byte is divided into two nybbles (four bits). Upper nybble determines the
  1013. * attack animation modifier, and it's only used for Barret and Vincent. The lower
  1014. * nybble is actually the index of the weapon model.
  1015. */
  1016. u8 model_raw;
  1017. /**
  1018. * Unused data (Always 0XFF). 1 byte.
  1019. */
  1020. u8 unused_2;
  1021. /**
  1022. * Consider it unused.
  1023. *
  1024. * @todo Verify.
  1025. */
  1026. u8 high_sound;
  1027. /**
  1028. * Camera movement ID. 2 bytes.
  1029. *
  1030. * Used for both single and multiple targeted attacks with this weapon. Always 0xFFFF.
  1031. */
  1032. u16 camera;
  1033. /**
  1034. * Characters that can equip the weapon. 2 bytes.
  1035. *
  1036. * Contains bits indicating the characters that can equip the weapon {@see character}
  1037. * for more info.
  1038. */
  1039. u16 equip_raw;
  1040. /**
  1041. * Weapon element id.
  1042. */
  1043. u16 element_raw;
  1044. /**
  1045. * Unused data (Always 0XFFFF). 1 byte.
  1046. */
  1047. u8 unused_3;
  1048. /**
  1049. * Stat the weapon raises.
  1050. *
  1051. * {@see stat_bonus} for more info.
  1052. */
  1053. u32 stat_raw;
  1054. /**
  1055. * The amount the raised stats are raised by.
  1056. *
  1057. * {@see stat_bonus} for more info.
  1058. */
  1059. u32 stat_bonus_raw;
  1060. /**
  1061. * Materia slots.
  1062. *
  1063. * {@see slots} for more info.
  1064. */
  1065. u8 slots_raw[8];
  1066. /**
  1067. * Sound effect id for normal hit.
  1068. */
  1069. u8 sound;
  1070. /**
  1071. * Sound effect id for critical hit.
  1072. */
  1073. u8 sound_critical;
  1074. /**
  1075. * Sound effect id for miss hit.
  1076. */
  1077. u8 sound_miss;
  1078. /**
  1079. * Impcat effect ID. 1 byte.
  1080. *
  1081. * Used for animation in battle.
  1082. */
  1083. u8 effect;
  1084. /**
  1085. * Special flags. 2 bytes.
  1086. *
  1087. * @todo document and parse with info from
  1088. * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Special_Attack_Flags
  1089. */
  1090. u16 special_raw;
  1091. /**
  1092. * Weapon restrictions. 2 bytes.
  1093. *
  1094. * Contains bits indicating if the item is {@see selleable}, {@see useable_battle} and
  1095. * {@see useable_menu}and {@see throwable}.
  1096. */
  1097. u16 restrict_raw;
  1098. /**
  1099. * Weapon ID.
  1100. *
  1101. * Not actually in the item file data, it's the order at which it appears.
  1102. */
  1103. int id;
  1104. /**
  1105. * Weapon name.
  1106. *
  1107. * Not found in the same file as the rest of the data, but on file 20.
  1108. */
  1109. std::string name;
  1110. /**
  1111. * Weapon description.
  1112. *
  1113. * Not found in the same file as the rest of the data, but on file 12.
  1114. */
  1115. std::string description;
  1116. /**
  1117. * Indicates if the weapon can be sold.
  1118. *
  1119. * True if the bit 0 in {@see restrict_raw} is 0.
  1120. */
  1121. bool sellable;
  1122. /**
  1123. * Indicates if the weapon can be used in battle.
  1124. *
  1125. * True if the bit 2 in {@see restrict_raw} is 0.
  1126. */
  1127. bool useable_battle;
  1128. /**
  1129. * Indicates if the weapon can be used in the menu.
  1130. *
  1131. * True if the bit 4 in {@see restrict_raw} is 0.
  1132. */
  1133. bool useable_menu;
  1134. /**
  1135. * Indicates if the weapon can be sold.
  1136. *
  1137. * True if the bit 8 in {@see restrict_raw} is 0.
  1138. */
  1139. bool throwable;
  1140. /**
  1141. * Target selection mode.
  1142. *
  1143. * Derived from {@see target_raw}.
  1144. */
  1145. Target target;
  1146. /**
  1147. * The damage formula.
  1148. *
  1149. * It's the upper nybble in {@see damage_raw}.
  1150. */
  1151. u8 damage_formula;
  1152. /**
  1153. * The damage modifier.
  1154. *
  1155. * It's the lower nybble in {@see damage_raw}.
  1156. */
  1157. u8 damage_modifier;
  1158. /**
  1159. * Attack animation ID.
  1160. *
  1161. * It's the upper nybble in {@see model_raw}. It's only used for Barret and Vincent.
  1162. */
  1163. u8 animation_index;
  1164. /**
  1165. * Weapon model ID.
  1166. *
  1167. * It's the lower nybble in {@see model_raw}.
  1168. */
  1169. u8 model;
  1170. /**
  1171. * The weapon battle model index.
  1172. *
  1173. * It's the lower nybble in {@see model_raw}.
  1174. */
  1175. std::vector<u8> equip;
  1176. /**
  1177. * Bonus in stats.
  1178. *
  1179. * Derived from {@see stat_raw} and {@stat_bonus_raw}.
  1180. */
  1181. std::vector<StatBonus> stat_bonus;
  1182. /**
  1183. * Materia slots.
  1184. *
  1185. * Derived and simplified from {@see slots_raw}.
  1186. */
  1187. std::vector<u8> materia_slots;
  1188. /**
  1189. * Elements of the weapon.
  1190. *
  1191. * Derived from {@see element_raw}.
  1192. */
  1193. std::vector<int> elements;
  1194. };
  1195. /**
  1196. * Character data.
  1197. *
  1198. * Contains information about a character. Contained in the file 3 of the kernel, one
  1199. * entry for each character. Each section is 56 bytes long. The character ID is not
  1200. * actually in the data, but it's the order at which they appear. The character name is
  1201. * also not in the dataand it must be filled manually.
  1202. */
  1203. struct CharacterData{
  1204. /**
  1205. * Strength stat growth curve. 1 byte.
  1206. */
  1207. u8 curve_str;
  1208. /**
  1209. * Vitality stat growth curve. 1 byte.
  1210. */
  1211. u8 curve_vit;
  1212. /**
  1213. * Magic stat growth curve. 1 byte.
  1214. */
  1215. u8 curve_mag;
  1216. /**
  1217. * Spirit stat growth curve. 1 byte.
  1218. */
  1219. u8 curve_spr;
  1220. /**
  1221. * Dexterity stat growth curve. 1 byte.
  1222. */
  1223. u8 curve_dex;
  1224. /**
  1225. * Luck stat growth curve. 1 byte.
  1226. */
  1227. u8 curve_lck;
  1228. /**
  1229. * HP stat growth curve. 1 byte.
  1230. */
  1231. u8 curve_hp;
  1232. /**
  1233. * MP stat growth curve. 1 byte.
  1234. */
  1235. u8 curve_mp;
  1236. /**
  1237. * Experience-for-next-level growth curve. 1 byte.
  1238. */
  1239. u8 curve_exp;
  1240. /**
  1241. * Ignored data. 1 byte.
  1242. */
  1243. u8 unused_0;
  1244. /**
  1245. * Starting level. 1 byte.
  1246. */
  1247. u8 initial_level;
  1248. /**
  1249. * Ignored data. 1 byte.
  1250. */
  1251. u8 unused_1;
  1252. /**
  1253. * 1-1 limit slot command. 1 byte.
  1254. */
  1255. u8 limit_1_1;
  1256. /**
  1257. * 1-2 limit slot command. 1 byte.
  1258. */
  1259. u8 limit_1_2;
  1260. /**
  1261. * 1-3 limit slot command. 1 byte, unused.
  1262. */
  1263. u8 limit_1_3;
  1264. /**
  1265. * 2-1 limit slot command. 1 byte.
  1266. */
  1267. u8 limit_2_1;
  1268. /**
  1269. * 2-2 limit slot command. 1 byte.
  1270. */
  1271. u8 limit_2_2;
  1272. /**
  1273. * 2-3 limit slot command. 1 byte, unused.
  1274. */
  1275. u8 limit_2_3;
  1276. /**
  1277. * 3-1 limit slot command. 1 byte.
  1278. */
  1279. u8 limit_3_1;
  1280. /**
  1281. * 3-2 limit slot command. 1 byte.
  1282. */
  1283. u8 limit_3_2;
  1284. /**
  1285. * 3-3 limit slot command. 1 byte, unused.
  1286. */
  1287. u8 limit_3_3;
  1288. /**
  1289. * 4-1 limit slot command. 1 byte.
  1290. */
  1291. u8 limit_4_1;
  1292. /**
  1293. * 4-2 limit slot command. 1 byte, unused.
  1294. */
  1295. u8 limit_4_2;
  1296. /**
  1297. * 4-3 limit slot command. 1 byte, unused.
  1298. */
  1299. u8 limit_4_3;
  1300. /**
  1301. * Kills required to unlock limit level 2. 2 bytes.
  1302. */
  1303. u16 limit_2_kills;
  1304. /**
  1305. * Kills required to unlock limit level 3. 2 bytes.
  1306. */
  1307. u16 limit_3_kills;
  1308. /**
  1309. * Kills required to unlock limit 1-2. 2 bytes.
  1310. */
  1311. u16 limit_1_2_uses;
  1312. /**
  1313. * Kills required to unlock limit 1-3. 2 bytes, unused.
  1314. */
  1315. u16 limit_1_3_uses;
  1316. /**
  1317. * Kills required to unlock limit 2-2. 2 bytes.
  1318. */
  1319. u16 limit_2_2_uses;
  1320. /**
  1321. * Kills required to unlock limit 2-3. 2 bytes, unused.
  1322. */
  1323. u16 limit_2_3_uses;
  1324. /**
  1325. * Kills required to unlock limit 3-2. 2 bytes.
  1326. */
  1327. u16 limit_3_2_uses;
  1328. /**
  1329. * Kills required to unlock limit 3-3. 2 bytes, unused.
  1330. */
  1331. u16 limit_3_3_uses;
  1332. /**
  1333. * HP divisor for limit level 1.
  1334. */
  1335. u32 limit_1_div;
  1336. /**
  1337. * HP divisor for limit level 2.
  1338. */
  1339. u32 limit_2_div;
  1340. /**
  1341. * HP divisor for limit level 3.
  1342. */
  1343. u32 limit_3_div;
  1344. /**
  1345. * HP divisor for limit level 4.
  1346. */
  1347. u32 limit_4_div;
  1348. /**
  1349. * Character ID.
  1350. */
  1351. int id;
  1352. /**
  1353. * Character default name.
  1354. */
  1355. std::string name;
  1356. };
  1357. /**
  1358. * Types of stat curves.
  1359. *
  1360. * Althought any of them can be used for any stat, this is their intended use.
  1361. */
  1362. enum STAT_CURVE_TYPE{
  1363. /**
  1364. * Normal curve, used for primary stat.
  1365. */
  1366. CURVE_PRIMARY = 0,
  1367. /**
  1368. * HP curve. Base values must be multiplied by 40 when calculating.
  1369. */
  1370. CURVE_HP,
  1371. /**
  1372. * MP curve. Base values must be multiplied by 2 when calculating.
  1373. */
  1374. CURVE_MP,
  1375. /**
  1376. * Experience curve. Base must be ignored when calculating. Gradient is quadratic.
  1377. */
  1378. CURVE_EXP
  1379. };
  1380. /**
  1381. * Stat curve.
  1382. *
  1383. * determines value growth
  1384. */
  1385. struct StatCurve{
  1386. /**
  1387. * Curve ID.
  1388. */
  1389. int id;
  1390. /**
  1391. * Type of curve.
  1392. */
  1393. STAT_CURVE_TYPE type;
  1394. /**
  1395. * Curve gradients.
  1396. */
  1397. u8 gradient[8];
  1398. /**
  1399. * Curve bases.
  1400. */
  1401. u8 base[8];
  1402. };
  1403. /**
  1404. * Battle data.
  1405. *
  1406. * Contains several pieces of data related to character growth. Contained in the file 3 of
  1407. * the kernel, after the character data (starts at offset 0x01F8). The kernel contains more
  1408. * data, but it's not needed for V-Gears (random table, scene lookup...)
  1409. */
  1410. struct GrowthData{
  1411. /**
  1412. * Random bonus to primary stats, 12 entries of 1 byte.
  1413. */
  1414. u8 bonus_stat[12];
  1415. /**
  1416. * Random bonus to HP stat, 12 entries of 1 byte.
  1417. */
  1418. u8 bonus_hp[12];
  1419. /**
  1420. * Random bonus to MP stat, 12 entries of 1 byte.
  1421. */
  1422. u8 bonus_mp[12];
  1423. /**
  1424. * Stat curves. 64 curves of 16 bit each.
  1425. *
  1426. * 37 for primary stats, 9 for HP, 9 form MP, 9 for experience.
  1427. */
  1428. StatCurve curves[64];
  1429. };
  1430. /**
  1431. * Items read from the kernel.
  1432. */
  1433. std::vector<CommandData> commands_;
  1434. /**
  1435. * Attacks read from the kernel.
  1436. */
  1437. std::vector<AttackData> attacks_;
  1438. /**
  1439. * Character info read from the kernel.
  1440. */
  1441. std::vector<CharacterData> characters_;
  1442. GrowthData growth_;
  1443. /**
  1444. * Items read from the kernel.
  1445. */
  1446. std::vector<ItemData> items_;
  1447. /**
  1448. * Weapons read from the kernel.
  1449. */
  1450. std::vector<WeaponData> weapons_;
  1451. /**
  1452. * The kernel file.
  1453. */
  1454. BinGZipFile kernel_;
  1455. };