| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include "common/BinGZipFile.h"
- #include "common/TypeDefine.h"
- #include "Characters.h"
- class KernelDataInstaller{
- public:
- /**
- * Constructor.
- *
- * @param[in] path Absolute path to the KERNEL.BIN file
- */
- KernelDataInstaller(std::string path);
- /**
- * Destructor.
- */
- ~KernelDataInstaller();
- /**
- * Reads the items from the kernel.
- *
- * @return The number of items read.
- */
- int ReadItems();
- /**
- * Saves item data to an xml file
- *
- * @param file[in] Absolute path to the target XML file.
- */
- void WriteItems(std::string file);
- /**
- * Reads the command from the kernel.
- *
- * @return The number of items read.
- */
- int ReadCommands();
- /**
- * Saves command data to an xml file
- *
- * @param file[in] Absolute path to the target XML file.
- */
- void WriteCommands(std::string file);
- private:
- enum KERNEL_SECTIONS{
- /**
- * Command data section in KERNEL.BIN.
- */
- KERNEL_COMMAND_DATA = 0,
- /**
- * Attack data section in KERNEL.BIN.
- */
- KERNEL_ATTACK_DATA,
- /**
- * Battle and growth data section in KERNEL.BIN.
- */
- KERNEL_BATTLE_AND_GROWTH_DATA,
- /**
- * Initialization data section in KERNEL.BIN.
- */
- KERNEL_INITIALIZATION_DATA,
- /**
- * Item data section in KERNEL.BIN.
- */
- KERNEL_ITEM_DATA,
- /**
- * Weapon data section in KERNEL.BIN.
- */
- KERNEL_WEAPON_DATA,
- /**
- * Armor data section in KERNEL.BIN.
- */
- KERNEL_ARMOR_DATA,
- /**
- * Accessory data section in KERNEL.BIN.
- */
- KERNEL_ACCESSORY_DATA,
- /**
- * Materia data section in KERNEL.BIN.
- */
- KERNEL_MATERIA_DATA,
- /**
- * Command descriptions section in KERNEL.BIN.
- */
- KERNEL_COMMAND_DESCRIPTIONS,
- /**
- * Magic descriptions section in KERNEL.BIN.
- */
- KERNEL_MAGIC_DESCRIPTIONS,
- /**
- * Item descriptions section in KERNEL.BIN.
- */
- KERNEL_ITEM_DESCRIPTIONS,
- /**
- * Weapon descriptions section in KERNEL.BIN.
- */
- KERNEL_WEAPON_DESCRIPTIONS,
- /**
- * Armor descriptions section in KERNEL.BIN.
- */
- KERNEL_ARMOR_DESCRIPTIONS,
- /**
- * Accessory descriptions section in KERNEL.BIN.
- */
- KERNEL_ACCESSORY_DESCRIPTIONS,
- /**
- * Materia descriptions section in KERNEL.BIN.
- */
- KERNEL_MATERIA_DESCRIPTIONS,
- /**
- * Key Item descriptions section in KERNEL.BIN.
- */
- KERNEL_KEY_ITEM_DESCRIPTIONS,
- /**
- * Command Names section in KERNEL.BIN.
- */
- KERNEL_COMMAND_NAMES,
- /**
- * Magic Names section in KERNEL.BIN.
- */
- KERNEL_MAGIC_NAMES,
- /**
- * Item Names section in KERNEL.BIN.
- */
- KERNEL_ITEM_NAMES,
- /**
- * Weapon Names section in KERNEL.BIN.
- */
- KERNEL_WEAPON_NAMES,
- /**
- * Armor Names section in KERNEL.BIN.
- */
- KERNEL_ARMOR_NAMES,
- /**
- * Accessory Names section in KERNEL.BIN.
- */
- KERNEL_ACCESSORY_NAMES,
- /**
- * Materia Names section in KERNEL.BIN.
- */
- KERNEL_MATERIA_NAMES,
- /**
- * Key Item Names section in KERNEL.BIN.
- */
- KERNEL_KEY_ITEM_NAMES,
- /**
- * Battle and Battle-Screen Text section in KERNEL.BIN.
- */
- KERNEL_BATTLE_AND_BATTLE_SCREEN_TEXT,
- /**
- * Summon Attack Names section in KERNEL.BIN.
- */
- KERNEL_SUMMON_ATTACK_NAMES
- };
- enum ELEMENT{
- /**
- * Fire element.
- */
- FIRE = 0,
- /**
- * Ice element.
- */
- ICE,
- /**
- * Bolt element.
- */
- BOLT,
- /**
- * Earth element.
- */
- EARTH,
- /**
- * Poison element.
- */
- POISON,
- /**
- * Gravity element.
- */
- GRAVITY,
- /**
- * Water element.
- */
- WATER,
- /**
- * Wind element.
- */
- WIND,
- /**
- * Holy element.
- */
- HOLY,
- /**
- * Restorative element.
- */
- RESTORATIVE,
- /**
- * Cut element.
- */
- CUT,
- /**
- * Hit element.
- */
- HIT,
- /**
- * Punch element.
- */
- PUNCH,
- /**
- * Shoot element.
- */
- SHOOT,
- /**
- * Shout element.
- */
- SHOUT,
- /**
- * Hidden element.
- */
- HIDDEN,
- };
- /**
- * List of target selection options.
- */
- struct Target{
- /**
- * The target can be selected.
- *
- * If the target of the attack is selectable, at least between some subset of possible
- * targets, this must be true.
- */
- bool selection_enabled;
- /**
- * The default target is an enemy.
- *
- * When true, the cursor starts in an enemy row. When false, it starts in the ally row.
- * It may or may not be possible to change it.
- */
- bool default_enemy;
- /**
- * The default target is a group.
- *
- * When true, the cursor starts will all the members of a row selected. When false, it
- * starts with only one target selected. It may or may not be possible to change it.
- */
- bool default_multiple;
- /**
- * The selection can change between groups and individuals.
- *
- * When true, the target can be changed between groups and individuals When false,
- * only {@see default_multiple} determines if the target is an individual or a group.
- */
- bool toggle_multiple;
- /**
- * The target group can be changed.
- *
- * When true, the target cannot be changed between enemies and allies. In this case
- * {@see default_enemy} will determine the group that can be targeted.
- */
- bool fixed_row;
- /**
- * The command is short ranged.
- *
- * When true, if the target or the caster is not in the front of their row, the target
- * will take half damage. Also, when true, an enemy covered by another enemy can't be
- * targeted.
- */
- bool short_range;
- /**
- * Targets all, enemies and allies.
- *
- * When true, all allies and enemies are targets, and the selection can't be changed.
- */
- bool all_rows;
- /**
- * The target is random.
- *
- * When multiple targets are selected, one will be selected at random to be the
- * receiving target. Cursor will cycle among all viable targets.
- */
- bool random;
- };
- /**
- * Determines what an item affects on when used from the menu.
- */
- enum RESTORE_TYPE{
- /**
- * The item affects a party member or group HP.
- */
- RESTORE_HP = 0,
- /**
- * The item affects a party member or group MP.
- */
- RESTORE_MP = 1,
- /**
- * The item affects a party member or group status.
- */
- RESTORE_STATUS = 2,
- /**
- * The item is not restorative.
- */
- RESTORE_NONE = 3
- };
- /**
- * List of altered status.
- */
- enum STATUS{
- /**
- * The character is dead.
- */
- DEATH = 0,
- /**
- * The character has critical HP.
- */
- NEAR_DEATH,
- /**
- * The character is asleep.
- */
- SLEEP,
- /**
- * The character is poisoned.
- */
- POISONED,
- /**
- * The character is sad.
- */
- SADNESS,
- /**
- * The character is furious.
- */
- FURY,
- /**
- * The character is confused.
- */
- CONFU,
- /**
- * The character is silenced.
- */
- SILENCE,
- /**
- * The character is slow.
- */
- HASTE,
- /**
- * The character is
- */
- SLOW,
- /**
- * The character is stopped.
- */
- STOP,
- /**
- * The character is a frog.
- */
- FROG,
- /**
- * The character is small.
- */
- SMALL,
- /**
- * The character is going to be petrified.
- */
- SLOW_NUMB,
- /**
- * The character is petrified.
- */
- PETRIFY,
- /**
- * The character is regenerating health.
- */
- REGEN,
- /**
- * The character has a physical barrier.
- */
- BARRIER,
- /**
- * The character has a magical barrier
- */
- M_BARRIER,
- /**
- * The character reflects magical attacks.
- */
- REFLECT,
- /**
- * The character has dual status.
- *
- * @todo What does it do.
- */
- DUAL,
- /**
- * The character has a shield.
- */
- SHIELD,
- /**
- * The character has a death sentence.
- */
- D_SENTENCE,
- /**
- * The character is being manipulated.
- */
- MANIPULATE,
- /**
- * The character is berserk.
- */
- BERSERK,
- /**
- * The character is invincible.
- */
- PEERLESS,
- /**
- * The character is paralyzed.
- */
- PARALYSIS,
- /**
- * The character is blinded.
- */
- DARKNESS,
- /**
- * The character has dual drain.
- */
- DUAL_DRAIN,
- /**
- * The character has deathforce.
- */
- DEATH_FORCE,
- /**
- * The character has resist.
- */
- RESIST,
- /**
- * Cait' Sith lucky girl mode.
- */
- LUCKY_GIRL,
- /**
- * The character is imprisioned.
- */
- IMPRISONED
- };
- /**
- * How a status effect modifier attack or item can act.
- */
- enum STATUS_EFFECT{
- /**
- * Inflicts status changes.
- */
- INFLICT = 0,
- /**
- * Cures status changes.
- */
- CURE = 1,
- /**
- * Toggles status changes.
- *
- * If the target doesn't have the status change, inflict it. If the target already has
- * the status change, cure it.
- */
- TOGGLE = 2
- };
- struct StatusEffect{
- /**
- * The list of status to inflict or cure.
- */
- std::vector<int> status;
- /**
- * The chance of landing a status effect (out of 63).
- */
- u16 chance;
- /**
- * The status change mode.
- */
- STATUS_EFFECT mode;
- };
- /**
- * Data for each command.
- *
- * As found in KERNEL.BIN, file 0, in order, up to camera_multiple. Members after
- * camera_multiple are not found literally in KERNEL.BIN, but are derived from other
- * members or found in other files of the kernel (text files).
- */
- struct CommandData{
- /**
- * Cursor action when the command is selected.
- */
- u8 cursor_action;
- /**
- * Targeting mode. 1 byte.
- *
- * See {@see target} and {@TargetModes} for more information.
- */
- u8 target_raw;
- /**
- * Unknown data (Always 0XFFFF). 2 bytes.
- */
- u16 unknown;
- /**
- * Camera movement ID for single target. 2 bytes.
- *
- * Determines the camera movement when the command is executed over a single target.
- */
- u16 camera_single;
- /**
- * Camera movement ID for multiple target. 2 bytes.
- *
- * Determines the camera movement when the command is executed over multiple targets.
- */
- u16 camera_multiple;
- /**
- * Command ID.
- *
- * Not actually in the item file data, it's the order at which it appears.
- */
- int id;
- /**
- * Command name.
- *
- * Not found in the same file as the rest of the data, but on file 17.
- */
- std::string name;
- /**
- * Command description.
- *
- * Not found in the same file as the rest of the data, but on file 9.
- */
- std::string description;
- /**
- * Target selection mode.
- *
- * Derived from {@see target_raw}.
- */
- Target target;
- };
- /**
- * Data for each items
- *
- * As found in KERNEL.BIN, file 4, in order, up to special. Members after special are not
- * found literally in KERNEL.BIN, but are derived from other members or found in other
- * files of the kernel (text files).
- */
- struct ItemData{
- /**
- * Unknown data (Always 0XFFFF). 4 bytes.
- */
- u32 unknown_0;
- /**
- * Unknown data (Always 0XFFFF). 4 bytes.
- */
- u32 unknown_1;
- /**
- * Camera movement ID. 2 bytes.
- *
- * Used for items useable in battle, determines the camera movement.
- */
- u16 camera;
- /**
- * Item restrictions. 2 bytes.
- *
- * Contains bits indicating if the item is {@see selleable}, {@see useable_battle} and
- * {@see useable_menu}.
- */
- u16 restrict_raw;
- /**
- * Targeting mode. 1 byte.
- *
- * See {@see target} and {@TargetModes} for more information.
- */
- u8 target_raw;
- /**
- * Item effect ID. 1 byte.
- *
- * Used for animation in battle.
- */
- u8 effect;
- /**
- * Damage formula. 1 byte.
- *
- * This byte is divided into two nybbles (four bits). Upper nybble determines what
- * considerations are made in calculating damage such as physical/magical, allowing
- * criticals, how to calculate accuracy, etc. There are also three sets of known
- * formulae that are paired with the upper nybble values. These are selected in the
- * Lower Nybble and determine how to calculate pre-defense damage
- */
- u8 damage_raw;
- /**
- * The item power. 1 byte.
- *
- * Used for damage/healing calculation.
- */
- u8 power;
- /**
- * The restore type.
- *
- * See {@restore_typ} and {@RESTORE_TYPE} for more information.
- */
- u8 condition_raw;
- /**
- * Information about status change mode and chance. 1 bytes.
- */
- u8 status_change_raw;
- /**
- * Special flags. 1 byte.
- *
- * @todo Document and retrieve with info from
- * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Attack_Special_Effects
- */
- u8 additional_effects_raw;
- /**
- * Special flags. 1 byte.
- *
- * @todo Document and retrieve with info from
- * https://wiki.ffrtt.ru/index.php?title=FF7/Item_data
- */
- u8 additional_effects_mod_raw;
- /**
- * Information about what status can be inflicted or cured. 4 bytes.
- *
- * The first six bits are the chance of inflicting/curing (out of 63). If the seventh
- * bit is set, the status is cured instead of inflicted. If the eighth bit is set, then
- * the status is toggled (cured if present, inflicted if not present).
- */
- u32 status_raw;
- /**
- * Information about the item elements. 2 bytes.
- */
- u16 element_raw;
- /**
- * Special flags. 2 bytes.
- *
- * @todo document and parse with info from
- * https://wiki.ffrtt.ru/index.php?title=FF7/Battle/Special_Attack_Flags
- */
- u16 special_raw;
- /**
- * Item ID.
- *
- * Not actually in the item file data, it's the order at which it appears.
- */
- int id;
- /**
- * Item name.
- *
- * Not found in the same file as the rest of the data, but on file 19.
- */
- std::string name;
- /**
- * Item description.
- *
- * Not found in the same file as the rest of the data, but on file 11.
- */
- std::string description;
- /**
- * Indicates if the item can be sold.
- *
- * True if the bit 0 in {@see restrict_raw} is 0.
- */
- bool sellable;
- /**
- * Indicates if the item can be used in battle.
- *
- * True if the bit 2 in {@see restrict_raw} is 0.
- */
- bool useable_battle;
- /**
- * Indicates if the item can be used in the menu.
- *
- * True if the bit 4 in {@see restrict_raw} is 0.
- */
- bool useable_menu;
- /**
- * Target selection mode.
- *
- * Derived from {@see target_raw}.
- */
- Target target;
- /**
- * The damage formula.
- *
- * It's the upper nybble in {@see damage_raw}.
- */
- u8 damage_formula;
- /**
- * The damage modifier.
- *
- * It's the lower nybble in {@see damage_raw}.
- */
- u8 damage_modifier;
- /**
- * What the item restores when used.
- *
- * Same as {@see condition_raw}, except for the wrong cases.
- */
- RESTORE_TYPE restore_type;
- /**
- * Status effects.
- *
- * Derived from {@see status_change_raw} and {@see status_raw}.
- */
- StatusEffect status;
- /**
- * Elements of the item.
- *
- * Derived from {@see element_raw}.
- */
- std::vector<int> elements;
- };
- /**
- * Items read from the kernel
- */
- std::vector<CommandData> commands_;
- /**
- * Items read from the kernel
- */
- std::vector<ItemData> items_;
- /**
- * The kernel file.
- */
- BinGZipFile kernel_;
- };
|