Add ROM raid editor

This commit is contained in:
Kurt
2020-01-10 15:48:54 -08:00
parent a1c0edec5d
commit 9fe628b5c9
3 changed files with 38 additions and 10 deletions

View File

@@ -9,7 +9,7 @@ public class DataCache<T> : IDataEditor where T : class
public Func<byte[], T> Create { private get; set; }
public Func<T, byte[]> Write { protected get; set; }
protected DataCache(T[] cache) => Cache = cache;
public DataCache(T[] cache) => Cache = cache;
public DataCache(IFileContainer f) : this(new T[f.Count]) => Data = f;
protected readonly T[] Cache;

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
namespace pkNX.Structures
{
@@ -131,30 +132,36 @@ public class EncounterNest8
public int Species { get; set; }
public int AltForm { get; set; }
public ulong LevelTableID { get; set; }
public int Ability { get; set; }
public byte Ability { get; set; }
public bool IsGigantamax { get; set; }
public ulong DropTableID { get; set; }
public ulong BonusTableID { get; set; }
public int[] Probabilities { get; set; }
public int Gender { get; set; }
public int FlawlessIVs { get; set; }
public uint[] Probabilities { get; set; }
public byte Gender { get; set; }
public byte FlawlessIVs { get; set; }
[JsonIgnore]
public FixedAbility AbilityPermitted
{
get => (FixedAbility) Ability;
set => Ability = (int) value;
set => Ability = (byte) value;
}
[JsonIgnore]
public int MinRank => Array.FindIndex(Probabilities, z => z != 0);
[JsonIgnore]
public int MaxRank => Array.FindLastIndex(Probabilities, z => z != 0);
public override string ToString() => $"{EntryIndex:00} - {Species:000}";
}
public enum FixedAbility
{
Regular12 = 0,
Only1 = 1,
Only2 = 2,
OnlyH = 3,
Ability1 = 0,
Ability2 = 1,
AbilityH = 2,
Ability1_2 = 3,
Any = 4,
}
}

View File

@@ -215,6 +215,27 @@ private void PopWildEdit(string file)
fp[0] = data_table.Write();
}
public void EditRaid()
{
IFileContainer fp = ROM.GetFile(GameFile.NestData);
var data_table = new GFPack(fp[0]);
const string nest = "nest_hole_encount.bin";
var nest_encounts = FlatBufferConverter.DeserializeFrom<EncounterNest8Archive>(data_table.GetDataFileName(nest));
var arr = nest_encounts.Tables;
var cache = new DataCache<EncounterNest8Table>(arr);
var games = new[] {"Sword", "Shield"};
var names = arr.Select((z, i) => $"{games[z.GameVersion - 1]} - {i / 2}").ToArray();
using var form = new GenericEditor<EncounterNest8Table>(cache, names, "Raid Encounters");
form.ShowDialog();
if (!form.Modified)
return;
var data = FlatBufferConverter.SerializeFrom(nest_encounts);
data_table.SetDataFileName(nest, data);
fp[0] = data_table.Write();
}
public void EditStatic()
{
var arc = ROM.GetFile(GameFile.EncounterStatic);