Skip to content

Commit

Permalink
Merge pull request #4 from petfriendamy/master
Browse files Browse the repository at this point in the history
Add attack and command data
  • Loading branch information
Shojy authored Dec 16, 2023
2 parents f39fef5 + 2dd8c10 commit e3fab69
Show file tree
Hide file tree
Showing 12 changed files with 321 additions and 3 deletions.
45 changes: 45 additions & 0 deletions Shojy.FF7.Elena/Attacks/Attack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Shojy.FF7.Elena.Battle;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shojy.FF7.Elena.Attacks
{
public class Attack
{
#region Public Constructors

public Attack() { }

#endregion

#region Public Properties

public byte AccuracyRate { get; set; }
public byte AditionalEffects { get; set; }
public byte AdditionalEffectsModifier { get; set; }
public byte AttackEffectID { get; set; }
public byte AttackStrength { get; set; }
public ushort CameraMovementIDSingle { get; set; }
public ushort CameraMovementIDMulti { get; set; }
public ConditionSubmenu ConditionSubmenu { get; set; }
public byte DamageCalculationID { get; set; }
public string Description { get; set; }
public Elements Elements { get; set; }
public byte ImpactEffectID { get; set; }
public ushort ImpactSound { get; set; }
public int Index { get; set; }
public ushort MPCost { get; set; }
public string Name { get; set; }
public SpecialEffects SpecialAttackFlags { get; set; }
public StatusChange StatusChange { get; set; }
public Statuses Statuses { get; set; }
public TargetData TargetFlags { get; set; }
public byte TargetHurtActionIndex { get; set; }

#endregion
}
}
16 changes: 16 additions & 0 deletions Shojy.FF7.Elena/Attacks/ConditionSubmenu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shojy.FF7.Elena.Attacks
{
public enum ConditionSubmenu : byte
{
PartyHP = 0x00,
PartyMP = 0x01,
PartyStatus = 0x02,
None = 0xFF
}
}
43 changes: 43 additions & 0 deletions Shojy.FF7.Elena/Attacks/StatusChange.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shojy.FF7.Elena.Attacks
{
public enum StatusChangeType
{
None, Inflict, Cure, Swap
}

public class StatusChange
{
public StatusChangeType Type { get; set; }
public int Amount { get; set; }

public StatusChange(byte value)
{
if (value == 0xFF)
{
Type = StatusChangeType.None;
Amount = 0;
}
else if ((value & 0x40) != 0)
{
Type = StatusChangeType.Cure;
Amount = value - 0x40;
}
else if ((value & 0x80) != 0)
{
Type = StatusChangeType.Swap;
Amount = value - 0x80;
}
else
{
Type = StatusChangeType.Inflict;
Amount = value;
}
}
}
}
29 changes: 29 additions & 0 deletions Shojy.FF7.Elena/Battle/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shojy.FF7.Elena.Battle
{
public class Command
{
#region Public Constructors

public Command() { }

#endregion

#region Public Properties

public ushort CameraMovementIDSingle { get; set; }
public ushort CameraMovementIDMulti { get; set; }
public string Description { get; set; }
public int Index { get; set; }
public string Name { get; set; }
public byte InitialCursorAction { get; set; }
public TargetData TargetFlags { get; set; }

#endregion
}
}
5 changes: 5 additions & 0 deletions Shojy.FF7.Elena/Equipment/Weapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ public Weapon()
public byte BoostedStat3Bonus { get; set; }
public CharacterStat BoostedStat4 { get; set; }
public byte BoostedStat4Bonus { get; set; }
public byte CriticalHitSoundID { get; set; }
public byte CriticalRate { get; set; }
public byte DamageCalculationId { get; set; }
public string Description { get; set; }
public EquipableBy EquipableBy { get; set; }
public GrowthRate GrowthRate { get; set; }
public byte HighSoundIDMask { get; set; }
public byte ImpactEffectID { get; set; }
public int Index { get; set; }
public MateriaSlot[] MateriaSlots { get; set; }
public byte MissedAttackSoundID { get; set; }
public string Name { get; set; }
public byte NormalHitSoundID { get; set; }
public Restrictions Restrictions { get; set; }
public EquipmentStatus Status { get; set; }
public TargetData Targets { get; set; }
Expand Down
4 changes: 4 additions & 0 deletions Shojy.FF7.Elena/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class Item
public byte AttackEffectId { get; set; }
public byte DamageCalculationId { get; set; }
public byte AttackPower { get; set; }
public ConditionSubmenu ConditionSubmenu { get; set; }
public StatusChange StatusChange { get; set; }
public byte AdditionalEffects { get; set; }
public byte AdditionalEffectsModifier { get; set; }
public Statuses Status { get; set; }
public Elements Element { get; set; }
public SpecialEffects Special { get; set; }
Expand Down
20 changes: 20 additions & 0 deletions Shojy.FF7.Elena/KernelReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,21 @@ private static Dictionary<KernelSection, byte[]> DecompressKernel2(string path)
/// </summary>
public TextSection ArmorNames { get; protected set; }

/// <summary>
/// Kernel section 2
/// </summary>
public AttackData AttackData { get; protected set; }

/// <summary>
/// Kernel section 26
/// </summary>
public TextSection BattleText { get; protected set; }

/// <summary>
/// Kernel section 1
/// </summary>
public CommandData CommandData { get; protected set; }

/// <summary>
/// Kernel section 10
/// </summary>
Expand Down Expand Up @@ -313,6 +323,16 @@ private void LoadSections()
this.BattleText = new TextSection(this.KernelData[KernelSection.BattleText]);
this.SummonAttackNames = new TextSection(this.KernelData[KernelSection.SummonAttackNames]);

this.CommandData = new CommandData(
this.KernelData[KernelSection.CommandData],
this.CommandNames.Strings,
this.CommandDescriptions.Strings);

this.AttackData = new AttackData(
this.KernelData[KernelSection.AttackData],
this.MagicNames.Strings,
this.MagicDescriptions.Strings);

this.WeaponData = new WeaponData(
this.KernelData[KernelSection.WeaponData],
this.WeaponNames.Strings,
Expand Down
81 changes: 81 additions & 0 deletions Shojy.FF7.Elena/Sections/AttackData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using Shojy.FF7.Elena.Attacks;
using Shojy.FF7.Elena.Battle;
using System;
using System.Collections.Generic;

namespace Shojy.FF7.Elena.Sections
{
public class AttackData
{
#region Private Fields

private const int AttackSize = 28;
private readonly byte[] _sectionData;

#endregion

#region Public Constructors

public AttackData(byte[] sectionData, IReadOnlyList<string> names, IReadOnlyList<string> descriptions)
{
this._sectionData = sectionData;

var count = sectionData.Length / AttackSize;
var attacks = new Attack[count];

for (var atk = 0; atk < count; ++atk)
{
var atkBytes = new byte[AttackSize];
Array.Copy(
sectionData,
atk * AttackSize,
atkBytes,
0,
AttackSize);
attacks[atk] = this.ParseAttackData(atkBytes);

attacks[atk].Index = atk;
attacks[atk].Name = names[atk];
attacks[atk].Description = descriptions[atk];
}
this.Attacks = attacks;
}

#endregion

#region Public Properties

public Attack[] Attacks;

#endregion

#region Private Methods

private Attack ParseAttackData(byte[] atkData)
{
var atk = new Attack();
atk.AccuracyRate = atkData[0x0];
atk.ImpactEffectID = atkData[0x1];
atk.TargetHurtActionIndex = atkData[0x2];
atk.MPCost = BitConverter.ToUInt16(atkData, 0x4);
atk.ImpactSound = BitConverter.ToUInt16(atkData, 0x6);
atk.CameraMovementIDSingle = BitConverter.ToUInt16(atkData, 0x8);
atk.CameraMovementIDMulti = BitConverter.ToUInt16(atkData, 0xA);
atk.TargetFlags = (TargetData)atkData[0xC];
atk.AttackEffectID = atkData[0xD];
atk.DamageCalculationID = atkData[0xE];
atk.AttackStrength = atkData[0xF];
atk.ConditionSubmenu = (ConditionSubmenu)atkData[0x10];
atk.StatusChange = new StatusChange(atkData[0x11]);
atk.AditionalEffects = atkData[0x12];
atk.AdditionalEffectsModifier = atkData[0x13];
atk.Statuses = (Statuses)BitConverter.ToUInt32(atkData, 0x14);
atk.Elements = (Elements)BitConverter.ToUInt16(atkData, 0x18);

atk.SpecialAttackFlags = (SpecialEffects) ~ BitConverter.ToUInt16(atkData, 0x1A);
return atk;
}

#endregion
}
}
63 changes: 61 additions & 2 deletions Shojy.FF7.Elena/Sections/CommandData.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,66 @@
namespace Shojy.FF7.Elena.Sections
using Shojy.FF7.Elena.Attacks;
using Shojy.FF7.Elena.Battle;
using System.Collections.Generic;
using System;

namespace Shojy.FF7.Elena.Sections
{
public class CommandData
{

#region Private Fields

private const int CommandSize = 8;
private readonly byte[] _sectionData;

#endregion

#region Public Constructors

public CommandData(byte[] sectionData, IReadOnlyList<string> names, IReadOnlyList<string> descriptions)
{
this._sectionData = sectionData;

var count = sectionData.Length / CommandSize;
var commands = new Command[count];

for (var cmd = 0; cmd < count; ++cmd)
{
var cmdBytes = new byte[CommandSize];
Array.Copy(
sectionData,
cmd * CommandSize,
cmdBytes,
0,
CommandSize);
commands[cmd] = this.ParseCommandData(cmdBytes);

commands[cmd].Index = cmd;
commands[cmd].Name = names[cmd];
commands[cmd].Description = descriptions[cmd];
}
this.Commands = commands;
}

#endregion

#region Public Properties

public Command[] Commands;

#endregion

#region Private Methods

private Command ParseCommandData(byte[] cmdData)
{
var cmd = new Command();
cmd.InitialCursorAction = cmdData[0x0];
cmd.TargetFlags = (TargetData)cmdData[0x1];
cmd.CameraMovementIDSingle = BitConverter.ToUInt16(cmdData, 0x4);
cmd.CameraMovementIDMulti = BitConverter.ToUInt16(cmdData, 0x6);
return cmd;
}

#endregion
}
}
8 changes: 7 additions & 1 deletion Shojy.FF7.Elena/Sections/ItemData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shojy.FF7.Elena.Battle;
using Shojy.FF7.Elena.Attacks;
using Shojy.FF7.Elena.Battle;
using Shojy.FF7.Elena.Items;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -62,8 +63,13 @@ private Item ParseItemData(byte[] data)
item.AttackEffectId = data[0xD];
item.DamageCalculationId = data[0xE];
item.AttackPower = data[0xF];
item.ConditionSubmenu = (ConditionSubmenu)data[0x10];
item.StatusChange = new StatusChange(data[0x11]);
item.AdditionalEffects = data[0x12];
item.AdditionalEffectsModifier = data[0x13];
item.Status = (Statuses)BitConverter.ToUInt32(data, 0x14);
item.Element = (Elements)BitConverter.ToUInt16(data, 0x18);
item.Special = (SpecialEffects) ~ BitConverter.ToUInt16(data, 0x1A);

return item;
}
Expand Down
4 changes: 4 additions & 0 deletions Shojy.FF7.Elena/Sections/MateriaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ private static Materia ParseData(byte[] data)
materia.Level3AP = BitConverter.ToUInt16(data, 0x2) * 100;
materia.Level4AP = BitConverter.ToUInt16(data, 0x4) * 100;
materia.Level5AP = BitConverter.ToUInt16(data, 0x6) * 100;
materia.EquipEffect = data[0x8];
var temp = new byte[4];
Array.Copy(data, 0x9, temp, 0, 3);
materia.Status = (Statuses)BitConverter.ToUInt32(temp);

materia.Element = (MateriaElements)data[0xC];
materia.MateriaType = Materia.GetMateriaType(data[0xD]);
Expand Down
Loading

0 comments on commit e3fab69

Please sign in to comment.