Minor tweaks

Cleaning things up before things go dark?
This commit is contained in:
Kurt
2022-10-27 11:59:42 -07:00
parent 930b35d52d
commit f591257e7a
61 changed files with 346 additions and 403 deletions

View File

@@ -10,19 +10,16 @@ public static class Container
/// </summary>
/// <param name="path">File location</param>
/// <param name="t">File type</param>
public static IFileContainer GetContainer(string path, ContainerType t)
public static IFileContainer GetContainer(string path, ContainerType t) => t switch
{
return t switch
{
ContainerType.GARC => new GARC(path),
ContainerType.Mini => MiniUtil.GetMini(path),
ContainerType.SARC => new SARC(path),
ContainerType.Folder => new FolderContainer(path),
ContainerType.SingleFile => new SingleFileContainer(path),
ContainerType.GFPack => new GFPack(path),
_ => throw new ArgumentOutOfRangeException(nameof(t), t, null),
};
}
ContainerType.GARC => new GARC(path),
ContainerType.Mini => MiniUtil.GetMini(path),
ContainerType.SARC => new SARC(path),
ContainerType.Folder => new FolderContainer(path),
ContainerType.SingleFile => new SingleFileContainer(path),
ContainerType.GFPack => new GFPack(path),
_ => throw new ArgumentOutOfRangeException(nameof(t), t, null),
};
/// <summary>
/// Gets a <see cref="IFileContainer"/> for the stream.

View File

@@ -135,7 +135,8 @@ await using (var bw = new BinaryWriter(stream))
File.Move(writePath, path);
}
Stream?.Dispose();
if (Stream is { } x)
await x.DisposeAsync().ConfigureAwait(false);
Reader?.Dispose();
Stream = stream;

View File

@@ -68,11 +68,10 @@ public static byte[] GetTypeChartImageData(int itemsize, int itemsPerRow, byte[]
byte[] gridColor = BitConverter.GetBytes(0x17000000);
for (int i = 0; i < width * height; i++)
{
if (i % itemsize == 0 || i / (itemsize * itemsPerRow) % itemsize == 0)
{
var ofs = (i / (itemsize * itemsPerRow) * width * 4) + (i % (itemsize * itemsPerRow) * 4);
Buffer.BlockCopy(gridColor, 0, bmpData, ofs, 4);
}
if (i % itemsize != 0 && i / (itemsize * itemsPerRow) % itemsize != 0)
continue;
var ofs = (i / (itemsize * itemsPerRow) * width * 4) + (i % (itemsize * itemsPerRow) * 4);
Buffer.BlockCopy(gridColor, 0, bmpData, ofs, 4);
}
return bmpData;

View File

@@ -37,9 +37,8 @@ internal string[] GetStrings(TextName file, IFileContainer textFile, bool remap
throw new ArgumentException($"Unknown {nameof(TextName)} provided.", file.ToString());
byte[] data;
string path = info.FileName;
if (!string.IsNullOrWhiteSpace(path) && textFile is FolderContainer c)
data = c.GetFileData(info.FileName) ?? throw new ArgumentException($"File not found: {path}", nameof(textFile));
if (textFile is FolderContainer c)
data = c.GetFileData(info.FileName) ?? throw new ArgumentException($"File not found: {info.FileName}", nameof(textFile));
else
data = textFile[info.Index];

View File

@@ -1,203 +1,201 @@
using System.Collections.Generic;
using pkNX.Structures;
using static pkNX.Game.TextName;
namespace pkNX.Game;
public static class TextMapping
{
public static IReadOnlyCollection<TextReference> GetMapping(GameVersion game)
public static IReadOnlyCollection<TextReference> GetMapping(GameVersion game) => game switch
{
return game switch
{
GameVersion.XY => XY,
GameVersion.ORASDEMO => AO,
GameVersion.ORAS => AO,
GameVersion.SMDEMO => SMDEMO,
GameVersion.SN => SM,
GameVersion.MN => SM,
GameVersion.US => USUM,
GameVersion.UM => USUM,
GameVersion.GP => GG,
GameVersion.GE => GG,
GameVersion.GG => GG,
GameVersion.SW => SWSH,
GameVersion.SH => SWSH,
GameVersion.SWSH => SWSH,
GameVersion.PLA => PLA,
_ => throw new System.ArgumentOutOfRangeException($"No text mapping for {game}"),
};
}
GameVersion.XY => XY,
GameVersion.ORASDEMO => AO,
GameVersion.ORAS => AO,
GameVersion.SMDEMO => SMDEMO,
GameVersion.SN => SM,
GameVersion.MN => SM,
GameVersion.US => USUM,
GameVersion.UM => USUM,
GameVersion.GP => GG,
GameVersion.GE => GG,
GameVersion.GG => GG,
GameVersion.SW => SWSH,
GameVersion.SH => SWSH,
GameVersion.SWSH => SWSH,
GameVersion.PLA => PLA,
_ => throw new System.ArgumentOutOfRangeException($"No text mapping for {game}"),
};
private static readonly TextReference[] XY =
{
new(005, TextName.Forms),
new(013, TextName.MoveNames),
new(015, TextName.MoveFlavor),
new(017, TextName.Types),
new(020, TextName.TrainerClasses),
new(021, TextName.TrainerNames),
new(022, TextName.TrainerText),
new(034, TextName.AbilityNames),
new(047, TextName.Natures),
new(072, TextName.metlist_00000),
new(080, TextName.SpeciesNames),
new(096, TextName.ItemNames),
new(099, TextName.ItemFlavor),
new(130, TextName.MaisonTrainerNames),
new(131, TextName.SuperTrainerNames),
new(141, TextName.OPowerFlavor),
new(005, Forms),
new(013, MoveNames),
new(015, MoveFlavor),
new(017, TypeNames),
new(020, TrainerClasses),
new(021, TrainerNames),
new(022, TrainerText),
new(034, AbilityNames),
new(047, Natures),
new(072, metlist_00000),
new(080, SpeciesNames),
new(096, ItemNames),
new(099, ItemFlavor),
new(130, MaisonTrainerNames),
new(131, SuperTrainerNames),
new(141, OPowerFlavor),
};
private static readonly TextReference[] AO =
{
new(005, TextName.Forms),
new(014, TextName.MoveNames),
new(016, TextName.MoveFlavor),
new(018, TextName.Types),
new(021, TextName.TrainerClasses),
new(022, TextName.TrainerNames),
new(023, TextName.TrainerText),
new(037, TextName.AbilityNames),
new(051, TextName.Natures),
new(090, TextName.metlist_00000),
new(098, TextName.SpeciesNames),
new(114, TextName.ItemNames),
new(117, TextName.ItemFlavor),
new(153, TextName.MaisonTrainerNames),
new(154, TextName.SuperTrainerNames),
new(165, TextName.OPowerFlavor),
new(005, Forms),
new(014, MoveNames),
new(016, MoveFlavor),
new(018, TypeNames),
new(021, TrainerClasses),
new(022, TrainerNames),
new(023, TrainerText),
new(037, AbilityNames),
new(051, Natures),
new(090, metlist_00000),
new(098, SpeciesNames),
new(114, ItemNames),
new(117, ItemFlavor),
new(153, MaisonTrainerNames),
new(154, SuperTrainerNames),
new(165, OPowerFlavor),
};
private static readonly TextReference[] SMDEMO =
{
new(020, TextName.ItemFlavor),
new(021, TextName.ItemNames),
new(026, TextName.SpeciesNames),
new(030, TextName.metlist_00000),
new(044, TextName.Forms),
new(044, TextName.Natures),
new(046, TextName.AbilityNames),
new(049, TextName.TrainerText),
new(050, TextName.TrainerNames),
new(051, TextName.TrainerClasses),
new(052, TextName.Types),
new(054, TextName.MoveFlavor),
new(055, TextName.MoveNames),
new(020, ItemFlavor),
new(021, ItemNames),
new(026, SpeciesNames),
new(030, metlist_00000),
new(044, Forms),
new(044, Natures),
new(046, AbilityNames),
new(049, TrainerText),
new(050, TrainerNames),
new(051, TrainerClasses),
new(052, TypeNames),
new(054, MoveFlavor),
new(055, MoveNames),
};
private static readonly TextReference[] SM =
{
new(035, TextName.ItemFlavor),
new(036, TextName.ItemNames),
new(055, TextName.SpeciesNames),
new(067, TextName.metlist_00000),
new(086, TextName.BattleRoyalNames),
new(087, TextName.Natures),
new(096, TextName.AbilityNames),
new(099, TextName.BattleTreeNames),
new(104, TextName.TrainerText),
new(105, TextName.TrainerNames),
new(106, TextName.TrainerClasses),
new(107, TextName.Types),
new(112, TextName.MoveFlavor),
new(113, TextName.MoveNames),
new(114, TextName.Forms),
new(116, TextName.SpeciesClassifications),
new(119, TextName.PokedexEntry1),
new(120, TextName.PokedexEntry2),
new(035, ItemFlavor),
new(036, ItemNames),
new(055, SpeciesNames),
new(067, metlist_00000),
new(086, BattleRoyalNames),
new(087, Natures),
new(096, AbilityNames),
new(099, BattleTreeNames),
new(104, TrainerText),
new(105, TrainerNames),
new(106, TrainerClasses),
new(107, TypeNames),
new(112, MoveFlavor),
new(113, MoveNames),
new(114, Forms),
new(116, SpeciesClassifications),
new(119, PokedexEntry1),
new(120, PokedexEntry2),
};
private static readonly TextReference[] USUM =
{
new(039, TextName.ItemFlavor),
new(040, TextName.ItemNames),
new(060, TextName.SpeciesNames),
new(072, TextName.metlist_00000),
new(091, TextName.BattleRoyalNames),
new(092, TextName.Natures),
new(101, TextName.AbilityNames),
new(104, TextName.BattleTreeNames),
new(109, TextName.TrainerText),
new(110, TextName.TrainerNames),
new(111, TextName.TrainerClasses),
new(112, TextName.Types),
new(117, TextName.MoveFlavor),
new(118, TextName.MoveNames),
new(119, TextName.Forms),
new(121, TextName.SpeciesClassifications),
new(124, TextName.PokedexEntry1),
new(125, TextName.PokedexEntry2),
new(039, ItemFlavor),
new(040, ItemNames),
new(060, SpeciesNames),
new(072, metlist_00000),
new(091, BattleRoyalNames),
new(092, Natures),
new(101, AbilityNames),
new(104, BattleTreeNames),
new(109, TrainerText),
new(110, TrainerNames),
new(111, TrainerClasses),
new(112, TypeNames),
new(117, MoveFlavor),
new(118, MoveNames),
new(119, Forms),
new(121, SpeciesClassifications),
new(124, PokedexEntry1),
new(125, PokedexEntry2),
};
private static readonly TextReference[] GG =
{
new("iteminfo.dat", TextName.ItemFlavor),
new("itemname.dat", TextName.ItemNames),
new("monsname.dat", TextName.SpeciesNames),
new("place_name.dat", TextName.metlist_00000),
new("seikaku.dat", TextName.Natures),
new("tokusei.dat", TextName.AbilityNames),
new("tokuseiinfo.dat", TextName.AbilityFlavor),
new("trname.dat", TextName.TrainerNames),
new("trtype.dat", TextName.TrainerClasses),
new("trmsg.dat", TextName.TrainerText),
new("typename.dat", TextName.Types),
new("wazainfo.dat", TextName.MoveFlavor),
new("wazaname.dat", TextName.MoveNames),
new("zkn_form.dat", TextName.Forms),
new("zkn_type.dat", TextName.SpeciesClassifications),
new("zukan_comment_A.dat", TextName.PokedexEntry1),
new("iteminfo.dat", ItemFlavor),
new("itemname.dat", ItemNames),
new("monsname.dat", SpeciesNames),
new("place_name.dat", metlist_00000),
new("seikaku.dat", Natures),
new("tokusei.dat", AbilityNames),
new("tokuseiinfo.dat", AbilityFlavor),
new("trname.dat", TrainerNames),
new("trtype.dat", TrainerClasses),
new("trmsg.dat", TrainerText),
new("typename.dat", TypeNames),
new("wazainfo.dat", MoveFlavor),
new("wazaname.dat", MoveNames),
new("zkn_form.dat", Forms),
new("zkn_type.dat", SpeciesClassifications),
new("zukan_comment_A.dat", PokedexEntry1),
};
private static readonly TextReference[] SWSH =
{
new("iteminfo.dat", TextName.ItemFlavor),
new("itemname.dat", TextName.ItemNames),
new("monsname.dat", TextName.SpeciesNames),
new("place_name_indirect.dat", TextName.metlist_00000),
new("place_name_spe.dat", TextName.metlist_30000),
new("place_name_out.dat", TextName.metlist_40000),
new("place_name_per.dat", TextName.metlist_60000),
new("seikaku.dat", TextName.Natures),
new("tokusei.dat", TextName.AbilityNames),
new("tokuseiinfo.dat", TextName.AbilityFlavor),
new("trname.dat", TextName.TrainerNames),
new("trtype.dat", TextName.TrainerClasses),
new("trmsg.dat", TextName.TrainerText),
new("typename.dat", TextName.Types),
new("wazainfo.dat", TextName.MoveFlavor),
new("wazaname.dat", TextName.MoveNames),
new("zkn_form.dat", TextName.Forms),
new("zkn_type.dat", TextName.SpeciesClassifications),
new("zukan_comment_A.dat", TextName.PokedexEntry1),
new("zukan_comment_B.dat", TextName.PokedexEntry2),
new("ribbon.dat", TextName.RibbonMark),
new("poke_memory_feeling.dat", TextName.MemoryFeelings),
new("iteminfo.dat", ItemFlavor),
new("itemname.dat", ItemNames),
new("monsname.dat", SpeciesNames),
new("place_name_indirect.dat", metlist_00000),
new("place_name_spe.dat", metlist_30000),
new("place_name_out.dat", metlist_40000),
new("place_name_per.dat", metlist_60000),
new("seikaku.dat", Natures),
new("tokusei.dat", AbilityNames),
new("tokuseiinfo.dat", AbilityFlavor),
new("trname.dat", TrainerNames),
new("trtype.dat", TrainerClasses),
new("trmsg.dat", TrainerText),
new("typename.dat", TypeNames),
new("wazainfo.dat", MoveFlavor),
new("wazaname.dat", MoveNames),
new("zkn_form.dat", Forms),
new("zkn_type.dat", SpeciesClassifications),
new("zukan_comment_A.dat", PokedexEntry1),
new("zukan_comment_B.dat", PokedexEntry2),
new("ribbon.dat", RibbonMark),
new("poke_memory_feeling.dat", MemoryFeelings),
};
private static readonly TextReference[] PLA =
{
new("iteminfo.dat", TextName.ItemFlavor),
new("itemname.dat", TextName.ItemNames),
new("monsname.dat", TextName.SpeciesNames),
new("place_name_indirect.dat", TextName.metlist_00000),
new("place_name_spe.dat", TextName.metlist_30000),
new("place_name_out.dat", TextName.metlist_40000),
new("place_name_per.dat", TextName.metlist_60000),
new("seikaku.dat", TextName.Natures),
new("tokusei.dat", TextName.AbilityNames),
new("tokuseiinfo.dat", TextName.AbilityFlavor),
new("trname.dat", TextName.TrainerNames),
new("trtype.dat", TextName.TrainerClasses),
new("trmsg.dat", TextName.TrainerText),
new("typename.dat", TextName.Types),
new("wazainfo.dat", TextName.MoveFlavor),
new("wazaname.dat", TextName.MoveNames),
new("zkn_form.dat", TextName.Forms),
new("zkn_type.dat", TextName.SpeciesClassifications),
new("zukan_comment_A.dat", TextName.PokedexEntry1),
new("zukan_comment_B.dat", TextName.PokedexEntry2),
new("ribbon.dat", TextName.RibbonMark),
new("poke_memory_feeling.dat", TextName.MemoryFeelings),
new("iteminfo.dat", ItemFlavor),
new("itemname.dat", ItemNames),
new("monsname.dat", SpeciesNames),
new("place_name_indirect.dat", metlist_00000),
new("place_name_spe.dat", metlist_30000),
new("place_name_out.dat", metlist_40000),
new("place_name_per.dat", metlist_60000),
new("seikaku.dat", Natures),
new("tokusei.dat", AbilityNames),
new("tokuseiinfo.dat", AbilityFlavor),
new("trname.dat", TrainerNames),
new("trtype.dat", TrainerClasses),
new("trmsg.dat", TrainerText),
new("typename.dat", TypeNames),
new("wazainfo.dat", MoveFlavor),
new("wazaname.dat", MoveNames),
new("zkn_form.dat", Forms),
new("zkn_type.dat", SpeciesClassifications),
new("zukan_comment_A.dat", PokedexEntry1),
new("zukan_comment_B.dat", PokedexEntry2),
new("ribbon.dat", RibbonMark),
new("poke_memory_feeling.dat", MemoryFeelings),
};
}

View File

@@ -12,7 +12,7 @@ public enum TextName
ItemFlavor,
SpeciesNames,
Types,
TypeNames,
Natures,
Forms,

View File

@@ -58,11 +58,10 @@ private void Randomize(EvolutionSet evos, int species)
{
foreach (var evo in evos.PossibleEvolutions)
{
if (evo.Method != 0)
{
evo.Species = (ushort)RandSpec.GetRandomSpecies(evo.Species, species);
evo.Form = (byte)RandForm.GetRandomForme(evo.Species, false, false, true, Game.SWSH, Personal.Table);
}
if (evo.Method == 0)
continue;
evo.Species = (ushort)RandSpec.GetRandomSpecies(evo.Species, species);
evo.Form = (byte)RandForm.GetRandomForme(evo.Species, false, false, true, Game.SWSH, Personal.Table);
}
}

View File

@@ -23,10 +23,12 @@ public PersonalRandomizer(IPersonalTable table, GameInfo game, EvolutionSet[] ev
Game = game;
Table = table;
Evolutions = evolutions;
if (File.Exists("bannedabilites.txt"))
const string bannedExternalFile = "bannedabilites.txt";
if (File.Exists(bannedExternalFile))
{
var data = File.ReadAllLines("bannedabilities.txt");
var list = new List<int>(BannedAbilities);
var data = File.ReadLines(bannedExternalFile);
list.AddRange(data.Select(z => Convert.ToInt32(z)));
BannedAbilities = list;
}

View File

@@ -134,14 +134,13 @@ private void SetRandomClass(VsTrainer tr)
private void DetermineSpecies(IPokeData pk)
{
if (Settings.RandomizeTeam)
{
int Type = Settings.TeamTypeThemed ? Util.Random.Next(17) : -1;
RandomizeSpecFormItem(pk, Type);
if (!Settings.RandomizeTeam)
return;
int Type = Settings.TeamTypeThemed ? Util.Random.Next(17) : -1;
RandomizeSpecFormItem(pk, Type);
pk.Gender = 0; // random
pk.Nature = Util.Random.Next(25); // random
}
pk.Gender = 0; // random
pk.Nature = Util.Random.Next(25); // random
}
private void RandomizeSpecFormItem(IPokeData pk, int Type)
@@ -270,9 +269,6 @@ public static void BoostLevel(IPokeData pk, double ratio)
public void ModifyAllPokemon(Action<IPokeData> act)
{
if (act == null)
throw new ArgumentException(nameof(act));
foreach (var tr in Trainers.Where(z => z.Team.Count != 0))
{
foreach (var pk in tr.Team)

View File

@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using FlatSharp.Attributes;
using pkNX.Containers;
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable ClassNeverInstantiated.Global

View File

@@ -1,7 +1,6 @@
using FlatSharp.Attributes;
using FlatSharp.Attributes;
// ReSharper disable UnusedMember.Global
#pragma warning disable RCS1154 // Sort enum members.
namespace pkNX.Structures.FlatBuffers;

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel;
using FlatSharp.Attributes;
@@ -74,7 +74,6 @@ public class DressUpEntry8a
[FlatBufferItem(49)] public string MotionPath { get; set; } = string.Empty;
[FlatBufferItem(50)] public byte Field_50 { get; set; }
[FlatBufferItem(51)] public uint Field_51 { get; set; } // Unused
[FlatBufferItem(52)] public string CategoryName { get; set; } = String.Empty;
[FlatBufferItem(53)] public string SubCategoryName { get; set; } = String.Empty;
[FlatBufferItem(52)] public string CategoryName { get; set; } = string.Empty;
[FlatBufferItem(53)] public string SubCategoryName { get; set; } = string.Empty;
}

View File

@@ -47,7 +47,6 @@ public class NewHugeOutbreakLottery8a
[Category(MapSetting), Description("Number of outbreaks that use the Rare1 table.")]
[FlatBufferItem(06)] public int OutbreakRare1 { get; set; }
[Category(OutbreakSetting), Description("Minimum number of Pokémon to spawn in the first wave.")]
[FlatBufferItem(07)] public int CountFirstMin { get; set; }

View File

@@ -30,8 +30,8 @@ public EncounterMultiplier8a GetEncounterMultiplier(EncounterSlot8a slot)
public EncounterMultiplier8a GetEntry(ushort species, ushort form)
{
return Table.FirstOrDefault(x => x.Species == species && x.Form == form) ??
new EncounterMultiplier8a { };
return Array.Find(Table, x => x.Species == species && x.Form == form) ??
new EncounterMultiplier8a();
}
public bool HasEntry(ushort species, ushort form)

View File

@@ -1,8 +1,6 @@
using FlatSharp.Attributes;
using FlatSharp.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace pkNX.Structures.FlatBuffers;
@@ -68,4 +66,4 @@ public class NPCModelColorConfig
[FlatBufferItem(07)] public uint[] R3 { get; set; } = Array.Empty<uint>();
[FlatBufferItem(08)] public uint[] G3 { get; set; } = Array.Empty<uint>();
[FlatBufferItem(09)] public uint[] B3 { get; set; } = Array.Empty<uint>();
}
}

View File

@@ -1,10 +1,7 @@
using FlatSharp.Attributes;
using FlatSharp.Attributes;
namespace pkNX.Structures.FlatBuffers;
#pragma warning disable RCS1154 // Sort enum members.
[FlatBufferEnum(typeof(ulong))]
public enum NPCResidentType8a : ulong
{

View File

@@ -32,8 +32,8 @@ public byte[] Write()
if (Table is null)
return Array.Empty<byte>();
using MemoryStream ms = new();
using BinaryWriter bw = new(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
foreach (var evo in Table)
{
// ReSharper disable RedundantCast

View File

@@ -1,11 +1,9 @@
using FlatSharp.Attributes;
using pkNX.Containers;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace pkNX.Structures.FlatBuffers;
@@ -17,8 +15,8 @@ public class PokeModelSet8a : IFlatBufferArchive<PokeModelSetEntry8a>
public PokeModelSetEntry8a GetEntry(ushort species)
{
return Table.FirstOrDefault(z => z.Species == species) ??
new PokeModelSetEntry8a { };
return Array.Find(Table, z => z.Species == species) ??
new PokeModelSetEntry8a();
}
public bool HasEntry(ushort species)

View File

@@ -22,8 +22,8 @@ public class PokeAIArchive8a : IFlatBufferArchive<PokeAI8a>
public PokeAI8a GetEntry(ushort species, ushort form)
{
return Table.FirstOrDefault(z => z.Species == species && z.Form == form) ??
new PokeAI8a { };
return Array.Find(Table, z => z.Species == species && z.Form == form) ??
new PokeAI8a();
}
public bool HasEntry(ushort species, ushort form, bool isAlpha)
@@ -167,5 +167,5 @@ public class PokeAIBehaviour
public static readonly PokeAIBehaviour Behaviour_04_Params = new() { BehaviourHash = 1234775724179408742, Parameters = new string[] { "3", "5", "60", "90", "4", "run", "Normal" } };
[FlatBufferItem(00)] public ulong BehaviourHash { get; set; } = 9252365659083253459;
[FlatBufferItem(01)] public string[] Parameters { get; set; } = new string[] { "0.5", "35" };
[FlatBufferItem(01)] public string[] Parameters { get; set; } = { "0.5", "35" };
}

View File

@@ -22,7 +22,7 @@ public class PokeMiscTable8a : IFlatBufferArchive<PokeMisc8a>
public PokeMisc8a GetEntry(ushort species, ushort form)
{
return Table.FirstOrDefault(z => z.Species == species && z.Form == form) ??
return Array.Find(Table, z => z.Species == species && z.Form == form) ??
new PokeMisc8a { Value = $"{species}-{form} is not in {nameof(PokeMiscTable8a)}." };
}
@@ -61,7 +61,7 @@ public class PokeMisc8a
public PokeDropItem8a? AlphaDropTable { get; set; }
[FlatBufferItem(09)] public string Value { get; set; } = "pm0000_00_00";
[FlatBufferItem(10)] public uint[] Field_10 { get; set; } = new uint[] { 0, 1, 2, 3 };
[FlatBufferItem(10)] public uint[] Field_10 { get; set; } = { 0, 1, 2, 3 };
[FlatBufferItem(11)] public int Field_11 { get; set; } = 0;
[FlatBufferItem(12)] public int Field_12 { get; set; } = 4;
[FlatBufferItem(13)] public int Field_13 { get; set; } = 10;

View File

@@ -26,13 +26,13 @@ public class PokeInfoList8a : IFlatBufferArchive<PokeInfo8a>
public PokeInfo8a GetEntry(ushort species)
{
return Table.FirstOrDefault(z => z.Species == species) ??
new PokeInfo8a { };
return Array.Find(Table, z => z.Species == species) ??
new PokeInfo8a();
}
public bool HasEntry(ushort species)
{
return Table.Any(x => x.Species == species);
return Array.Exists(Table, x => x.Species == species);
}
public PokeInfo8a AddEntry(ushort species, byte formCount)
@@ -60,7 +60,7 @@ public PokeInfo8a AddEntry(ushort species, byte formCount)
new() {
Detail = new PokeInfoDetail8a_5[] {
new() {
AssetName = $"{species:0000}_{genderId:000}_{form:000}_n_00000000_fn_n"
AssetName = $"{species:0000}_{genderId:000}_{form:000}_n_00000000_fn_n",
}
}
}
@@ -72,7 +72,7 @@ public PokeInfo8a AddEntry(ushort species, byte formCount)
new() {
Detail = new PokeInfoDetail8a_5[] {
new() {
AssetName = $"{species:0000}_{genderId:000}_{form:000}_n_00000000_fn_r"
AssetName = $"{species:0000}_{genderId:000}_{form:000}_n_00000000_fn_r",
}
}
}
@@ -82,7 +82,6 @@ public PokeInfo8a AddEntry(ushort species, byte formCount)
};
}
Table = Table.Append(entry)
.OrderBy(x => x.Species)
.ToArray();

View File

@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using FlatSharp.Attributes;
@@ -23,8 +22,8 @@ public class PokeResourceTable8a : IFlatBufferArchive<PokeModelConfig8a>
public PokeModelConfig8a GetEntry(ushort species, ushort form, byte gender)
{
return Table.FirstOrDefault(x => x.Meta.Species == species && x.Meta.Form == form && x.Meta.Gender == gender) ??
new PokeModelConfig8a { };
return Array.Find(Table, x => x.Meta.Species == species && x.Meta.Form == form && x.Meta.Gender == gender) ??
new PokeModelConfig8a();
}
public bool HasEntry(ushort species, ushort form, byte gender)

View File

@@ -17,5 +17,5 @@ public enum ThrowEffectHitType8a : ulong
EffectUnk1Hit = 0x262b03b924121730,
EffectUnk2Hit = 0x7f5d5908e7deb625,
EffectUnk3Hit = 0x9fa86e9cc66822a,
EffectUnk4Hit = 0x69d10d3d31d81522,
EffectUnk4Hit = 0x69d10d3d31d81522,
}

View File

@@ -1,8 +1,6 @@
using FlatSharp.Attributes;
// ReSharper disable UnusedMember.Global
#pragma warning disable RCS1154 // Sort enum members.
namespace pkNX.Structures.FlatBuffers;
[FlatBufferEnum(typeof(ulong))]

View File

@@ -1,8 +1,6 @@
using FlatSharp.Attributes;
// ReSharper disable UnusedMember.Global
#pragma warning disable RCS1154 // Sort enum members.
namespace pkNX.Structures.FlatBuffers;
[FlatBufferEnum(typeof(ulong))]

View File

@@ -18,7 +18,7 @@ public class ThrowableParamTable8a : IFlatBufferArchive<ThrowableParam8a>
public void AddEntry(int itemID)
{
Table = Table.Append(new ThrowableParam8a() { ItemID = itemID });
Table = Table.Append(new ThrowableParam8a { ItemID = itemID });
}
[FlatBufferItem(0)] public ThrowableParam8a[] Table { get; set; } = Array.Empty<ThrowableParam8a>();

View File

@@ -22,7 +22,7 @@ public class ArchiveContents8a : IFlatBufferArchive<ArchiveContent8a>
public ArchiveContent8a AddEntry()
{
var entry = new ArchiveContent8a { };
var entry = new ArchiveContent8a();
Table = Table.Append(entry);
return entry;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -8,7 +8,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -9,7 +9,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -6,7 +6,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -8,7 +8,6 @@
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedMember.Global
#nullable disable
#pragma warning disable CA1819 // Properties should not return arrays
namespace pkNX.Structures.FlatBuffers;

View File

@@ -39,8 +39,8 @@ private static EvolutionMethod GetEvo(byte[] data, int offset)
public override byte[] Write()
{
using MemoryStream ms = new MemoryStream();
using BinaryWriter bw = new BinaryWriter(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
foreach (EvolutionMethod evo in PossibleEvolutions)
{
bw.Write((ushort)evo.Method);

View File

@@ -20,8 +20,8 @@ public EvolutionSet7(ReadOnlySpan<byte> data)
public override byte[] Write()
{
using MemoryStream ms = new();
using BinaryWriter bw = new(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
foreach (EvolutionMethod evo in PossibleEvolutions)
{
bw.Write((ushort)evo.Method);

View File

@@ -20,8 +20,8 @@ public EvolutionSet8(ReadOnlySpan<byte> data)
public override byte[] Write()
{
using MemoryStream ms = new();
using BinaryWriter bw = new(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
foreach (EvolutionMethod evo in PossibleEvolutions)
{
bw.Write((ushort)evo.Method);

View File

@@ -101,7 +101,7 @@ public static Item8[] GetArray(byte[] bin)
for (var i = 0; i < result.Length; i++)
{
var entryIndex = BitConverter.ToUInt16(bin, 0x44 + (2 * i));
if (entryIndex >= maxEntryIndex) { throw new ArgumentException(); }
if (entryIndex >= maxEntryIndex) { throw new IndexOutOfRangeException(); }
result[i] = new Item8(i, bin.Slice(entriesStart + (entryIndex * SIZE), SIZE));
}
@@ -119,7 +119,7 @@ public static byte[] SetArray(Item8[] array, byte[] bin)
for (int i = 0; i < array.Length; i++)
{
var entryIndex = BitConverter.ToUInt16(bin, 0x44 + (2 * i));
if (entryIndex >= maxEntryIndex) { throw new ArgumentException(); }
if (entryIndex >= maxEntryIndex) { throw new IndexOutOfRangeException(); }
var data = array[i].Data;
data.CopyTo(bin, entriesStart + (entryIndex * SIZE));

View File

@@ -85,7 +85,7 @@ public static Item8a[] GetArray(byte[] bin)
for (var i = 0; i < result.Length; i++)
{
var entryIndex = BitConverter.ToUInt16(bin, 0x4C + (2 * i));
if (entryIndex >= maxEntryIndex) { throw new ArgumentException(); }
if (entryIndex >= maxEntryIndex) { throw new IndexOutOfRangeException(); }
result[i] = new Item8a(i, bin.Slice(entriesStart + (entryIndex * SIZE), SIZE));
}
@@ -103,7 +103,7 @@ public static byte[] SetArray(Item8a[] array, byte[] bin)
for (int i = 0; i < array.Length; i++)
{
var entryIndex = BitConverter.ToUInt16(bin, 0x4C + (2 * i));
if (entryIndex >= maxEntryIndex) { throw new ArgumentException(); }
if (entryIndex >= maxEntryIndex) { throw new IndexOutOfRangeException(); }
var data = array[i].Data;
data.CopyTo(bin, entriesStart + (entryIndex * SIZE));

View File

@@ -24,8 +24,8 @@ public Learnset6(byte[] data)
public override byte[] Write()
{
Count = (ushort)Moves.Length;
using MemoryStream ms = new MemoryStream();
using BinaryWriter bw = new BinaryWriter(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
for (int i = 0; i < Count; i++)
{
bw.Write((short)Moves[i]);

View File

@@ -38,8 +38,8 @@ public Learnset8(byte[] data)
public override byte[] Write()
{
Count = (ushort)Moves.Length;
using MemoryStream ms = new MemoryStream();
using BinaryWriter bw = new BinaryWriter(ms);
using var ms = new MemoryStream();
using var bw = new BinaryWriter(ms);
for (int i = 0; i < Count; i++)
{
bw.Write((short)Moves[i]);

View File

@@ -15,7 +15,7 @@ public static class TableUtil
/// <returns>2 dimensional sheet of cells</returns>
public static string GetTable<T>(IEnumerable<T> arr) where T : class => string.Join(Environment.NewLine, GetTableRaw(arr));
private const string sep = "\t";
private const char sep = '\t';
private static IEnumerable<string> GetTableRaw<T>(IEnumerable<T> arr) where T : class
=> Table(arr).Select(row => string.Join(sep, row));
private static IEnumerable<string> GetTableRaw<T>(IEnumerable<T> arr, Type t) where T : class
@@ -94,7 +94,7 @@ private static string GetFormattedString(object? obj)
if (obj is ulong u)
return u.ToString("X16");
if (obj is IEnumerable x and not string)
return string.Join("|", JoinEnumerator(x.GetEnumerator()).Select(GetFormattedString));
return string.Join('|', JoinEnumerator(x.GetEnumerator()).Select(GetFormattedString));
var objType = obj.GetType();
if (objType.IsEnum)
@@ -104,7 +104,7 @@ private static string GetFormattedString(object? obj)
return obj.ToString() ?? string.Empty;
var props = objType.GetProperties();
return string.Join("|", props.Select(z => GetFormattedString(z.GetValue(obj))));
return string.Join('|', props.Select(z => GetFormattedString(z.GetValue(obj))));
}
private static IEnumerable<object> JoinEnumerator(IEnumerator x)

View File

@@ -84,7 +84,7 @@ public void DumpPokeInfo()
Abilities = ROM.GetStrings(TextName.AbilityNames),
Items = ROM.GetStrings(TextName.ItemNames),
Moves = moveNames,
Types = ROM.GetStrings(TextName.Types),
Types = ROM.GetStrings(TextName.TypeNames),
Species = ROM.GetStrings(TextName.SpeciesNames),
ZukanA = ROM.GetStrings(TextName.PokedexEntry1),
ZukanB = ROM.GetStrings(TextName.PokedexEntry2),

View File

@@ -89,7 +89,7 @@ public void DumpPokeInfo()
Abilities = ROM.GetStrings(TextName.AbilityNames),
Items = ROM.GetStrings(TextName.ItemNames),
Moves = moveNames,
Types = ROM.GetStrings(TextName.Types),
Types = ROM.GetStrings(TextName.TypeNames),
Species = ROM.GetStrings(TextName.SpeciesNames),
ZukanA = ROM.GetStrings(TextName.PokedexEntry1),
ZukanB = ROM.GetStrings(TextName.PokedexEntry2),

View File

@@ -253,7 +253,7 @@ private void AdjustWindowSize()
// Adjust for scrollbar width
if (FLP_Controls.VerticalScroll.Visible)
ClientSize = new(newClientSize.Width + SystemInformation.VerticalScrollBarWidth, newClientSize.Height);
ClientSize = newClientSize with { Width = newClientSize.Width + SystemInformation.VerticalScrollBarWidth };
}
private void LoadROM(EditorBase editor)

View File

@@ -20,12 +20,11 @@ public enum EditorCategory
Misc,
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
[AttributeUsage(AttributeTargets.Method)]
public class EditorCallableAttribute : Attribute
{
public EditorCategory Category { get; set; }
public string EditorName { get; set; }
public EditorCategory Category { get; }
public string EditorName { get; }
/// <summary>
/// Add this attribute to customize the button that will be displayed in the main editor
@@ -38,13 +37,7 @@ public EditorCallableAttribute(EditorCategory category = EditorCategory.Misc, st
EditorName = editorName;
}
public bool HasCustomEditorName()
{
return !string.IsNullOrWhiteSpace(EditorName);
}
public bool HasCustomEditorName() => !string.IsNullOrWhiteSpace(EditorName);
public bool HasCategory()
{
return Category != EditorCategory.None;
}
public bool HasCategory() => Category != EditorCategory.None;
}

View File

@@ -308,7 +308,7 @@ public void EditTypeChart()
ofs += pattern.Length + 0x24; // 0x5B4C0C in lgpe 1.0 RO
var cdata = new byte[18 * 18];
var types = ROM.GetStrings(TextName.Types);
var types = ROM.GetStrings(TextName.TypeNames);
Array.Copy(nso.DecompressedRO, ofs, cdata, 0, cdata.Length);
var chart = new TypeChartEditor(cdata);
using var editor = new TypeChart(chart, types);

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using pkNX.Containers;
using pkNX.Game;
@@ -11,6 +10,7 @@
using pkNX.Structures.FlatBuffers;
using pkNX.WinForms.Subforms;
using static pkNX.Structures.Species;
// ReSharper disable UnusedMember.Global
namespace pkNX.WinForms.Controls;
@@ -38,21 +38,18 @@ private static void CheckOodleDllPresence()
var obj = ROM.GetFile(file);
var tableCache = new TableCache<T1, T2>(obj);
var dataLoader = (GenericEditor<T2> form) =>
DataCache<T2> loader(GenericEditor<T2> form)
{
if (form.Modified)
tableCache.Save();
tableCache = new TableCache<T1, T2>(obj);
return tableCache.Cache;
};
}
Action? cb = addEntryCallback == null ? null : (() =>
{
addEntryCallback?.Invoke(tableCache.Root);
});
Action? cb = addEntryCallback is { } x ? () => x.Invoke(tableCache.Root) : null;
using var form = new GenericEditor<T2>(dataLoader, getName, title, rand, cb, canSave);
using var form = new GenericEditor<T2>(loader, getName, title, rand, cb, canSave);
form.ShowDialog();
if (form.Modified)
{
@@ -62,7 +59,7 @@ private static void CheckOodleDllPresence()
private static bool PopFlat<T2>(T2[] arr, string title, Func<T2, int, string> getName, Action<IEnumerable<T2>>? rand = null, bool canSave = true) where T2 : class
{
using var form = new GenericEditor<T2>(_ => { return new DataCache<T2>(arr); }, getName, title, rand, null, canSave);
using var form = new GenericEditor<T2>(_ => new DataCache<T2>(arr), getName, title, rand, null, canSave);
form.ShowDialog();
return form.Modified;
}

View File

@@ -17,8 +17,8 @@ public abstract class EditorBase
public string? Location { get; private set; }
private const string prefix = "Edit";
private MethodInfo[] editorMethods = Array.Empty<MethodInfo>();
private EditorCallableAttribute[] editorAttributes = Array.Empty<EditorCallableAttribute>();
private readonly MethodInfo[] editorMethods;
private readonly EditorCallableAttribute[] editorAttributes;
protected EditorBase()
{
@@ -26,7 +26,8 @@ protected EditorBase()
// The method name needs to start with `Edit` or an EditorCallableAttribute should be added
var editors = GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Select(x => new { Method = x, Callable = x.GetCustomAttribute<EditorCallableAttribute>() })
.Where(x => x.Callable != null || x.Method.Name.StartsWith(prefix));
.Where(x => x.Callable != null || x.Method.Name.StartsWith(prefix))
.ToList();
editorMethods = editors.Select(x => x.Method).ToArray();
editorAttributes = editors.Select(x => x.Callable ?? new EditorCallableAttribute(EditorCategory.None)).ToArray();
@@ -55,7 +56,7 @@ public IEnumerable<Button> GetControls(Button templateButton, EditorCategory cat
Margin = templateButton.Margin,
Font = templateButton.Font,
Name = $"B_{name}",
Text = (callable?.HasCustomEditorName() ?? false) ? callable.EditorName : WinFormsUtil.GetSpacedCapitalized(name),
Text = callable.HasCustomEditorName() ? callable.EditorName : WinFormsUtil.GetSpacedCapitalized(name),
};
b.Click += (s, e) =>
{

View File

@@ -190,7 +190,7 @@ public void NotWorking_EditTypeChart()
ofs += pattern.Length + 0x24; // 0x5B4C0C in lgpe 1.0 RO
var cdata = new byte[18 * 18];
var types = ROM.GetStrings(TextName.Types);
var types = ROM.GetStrings(TextName.TypeNames);
Array.Copy(nso.DecompressedRO, ofs, cdata, 0, cdata.Length);
var chart = new TypeChartEditor(cdata);
using var editor = new TypeChart(chart, types);

View File

@@ -60,7 +60,7 @@ public BTTE(GameData data, TrainerEditor editor, GameManager game)
movelist = Game.GetStrings(TextName.MoveNames);
itemlist = Game.GetStrings(TextName.ItemNames);
specieslist = Game.GetStrings(TextName.SpeciesNames);
types = Game.GetStrings(TextName.Types);
types = Game.GetStrings(TextName.TypeNames);
natures = Game.GetStrings(TextName.Natures);
trName = Game.GetStrings(TextName.TrainerNames);
trClass = Game.GetStrings(TextName.TrainerClasses);

View File

@@ -33,7 +33,7 @@ public PokeDataUI(PokeEditor editor, GameManager rom, GameData data)
movelist = ROM.GetStrings(TextName.MoveNames);
species = ROM.GetStrings(TextName.SpeciesNames);
abilities = ROM.GetStrings(TextName.AbilityNames);
types = ROM.GetStrings(TextName.Types);
types = ROM.GetStrings(TextName.TypeNames);
movelist = EditorUtil.SanitizeMoveList(movelist);
species[0] = "---";

View File

@@ -62,7 +62,7 @@ public PokeDataUI8a(PokeEditor8a editor, GameManager rom, GameData8a data)
speciesNames = ROM.GetStrings(TextName.SpeciesNames);
classifications = ROM.GetStrings(TextName.SpeciesClassifications);
abilities = ROM.GetStrings(TextName.AbilityNames);
types = ROM.GetStrings(TextName.Types);
types = ROM.GetStrings(TextName.TypeNames);
movelist = EditorUtil.SanitizeMoveList(movelist);
speciesNames[0] = "---";
@@ -355,16 +355,14 @@ private bool ValidateRegionalDexIndex()
if ((dexIndex == 0 && cPersonal.IsPresentInGame) || dexIndex == cPersonal.DexIndexRegional)
return true;
if (regionalDex.Contains(dexIndex))
{
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Regional Dex Index '{dexIndex}' is already in use.", "Would you like the index to be automatically updated to a valid one?");
if (prompt == DialogResult.Yes)
{
TB_HisuianDex.Text = (regionalDex.Max() + 1).ToString();
return true;
}
}
return false;
if (!regionalDex.Contains(dexIndex))
return false;
var prompt = WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Regional Dex Index '{dexIndex}' is already in use.", "Would you like the index to be automatically updated to a valid one?");
if (prompt != DialogResult.Yes)
return false;
TB_HisuianDex.Text = (regionalDex.Max() + 1).ToString();
return true;
}
private bool SavePersonal()
@@ -556,23 +554,21 @@ private void AutoFillEvolutions()
EvolutionMethod[] evoSet = swsh[i];
EvolutionMethod[] usumEvos = usum[i];
if (evoSet[0].Method == EvolutionType.None && usumEvos[0].Method != EvolutionType.None)
{
for (int j = 0; j < usumEvos.Length; j++)
{
if (usumEvos[j].Method == EvolutionType.None)
{
continue;
}
if (evoSet[0].Method != EvolutionType.None || usumEvos[0].Method == EvolutionType.None)
continue;
var usumEntry = usumEvos[j];
var evoEntry = evoSet[j];
evoEntry.Species = usumEntry.Species;
evoEntry.Form = usumEntry.Form;
evoEntry.Argument = usumEntry.Argument;
evoEntry.Method = usumEntry.Method;
evoEntry.Level = usumEntry.Level;
}
for (int j = 0; j < usumEvos.Length; j++)
{
if (usumEvos[j].Method == EvolutionType.None)
continue;
var usumEntry = usumEvos[j];
var evoEntry = evoSet[j];
evoEntry.Species = usumEntry.Species;
evoEntry.Form = usumEntry.Form;
evoEntry.Argument = usumEntry.Argument;
evoEntry.Method = usumEntry.Method;
evoEntry.Level = usumEntry.Level;
}
}
@@ -580,43 +576,41 @@ private void AutoFillEvolutions()
for (int i = 0; i < la.Length; i++)
{
EvolutionSet8a evoSet = la[i];
if (evoSet.Table == null || evoSet.Table.Length == 0)
if (evoSet.Table != null && evoSet.Table.Length != 0)
continue;
var species = evoSet.Species;
var form = evoSet.Form;
if (species > Legal.MaxSpeciesID_8)
{
var species = evoSet.Species;
var form = evoSet.Form;
if (species > Legal.MaxSpeciesID_8)
{
continue;
}
int index = swshPersonal.GetFormIndex(species, (byte)form);
if (index == 0)
{
// Assume the form doesn't exsist in the game
continue;
}
var swshEvos = swsh[index];
var entries = new List<EvolutionEntry8a>();
foreach (var evo in swshEvos)
{
if (evo.Method == EvolutionType.None)
{
continue;
}
entries.Add(new EvolutionEntry8a
{
Species = evo.Species,
Form = evo.Form,
Argument = evo.Argument,
Method = (ushort)evo.Method,
Level = evo.Level,
});
}
evoSet.Table = entries.ToArray();
continue;
}
int index = swshPersonal.GetFormIndex(species, (byte)form);
if (index == 0)
{
// Assume the form doesn't exsist in the game
continue;
}
var swshEvos = swsh[index];
var entries = new List<EvolutionEntry8a>();
foreach (var evo in swshEvos)
{
if (evo.Method == EvolutionType.None)
continue;
entries.Add(new EvolutionEntry8a
{
Species = evo.Species,
Form = evo.Form,
Argument = evo.Argument,
Method = (ushort)evo.Method,
Level = evo.Level,
});
}
evoSet.Table = entries.ToArray();
}
}
@@ -834,40 +828,38 @@ private void PokeDataUI8a_FormClosing(object sender, FormClosingEventArgs e)
private void CHK_IsPresentInGame_CheckedChanged(object sender, EventArgs e)
{
cPersonal.IsPresentInGame = CHK_IsPresentInGame.Checked;
if (!cPersonal.IsPresentInGame)
return;
if (cPersonal.IsPresentInGame)
ValidateRegionalDexIndex();
var rMisc = Editor.PokeMisc.Root;
if (!rMisc.HasEntry(cPersonal.DexIndexNational, cPersonal.Form))
{
ValidateRegionalDexIndex();
var entry = rMisc.AddEntry(cPersonal.DexIndexNational, cPersonal.Form);
if (!Editor.PokeMisc.Root.HasEntry(cPersonal.DexIndexNational, cPersonal.Form))
{
var entry = Editor.PokeMisc.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.Form);
// Reload entry with correct misc data
LoadMisc(entry);
}
if (!Editor.SymbolBehave.Root.HasEntry(cPersonal.DexIndexNational, cPersonal.Form, false))
{
Editor.SymbolBehave.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, false);
Editor.SymbolBehave.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, true);
}
if (!Editor.PokeResourceList.Root.HasEntry(cPersonal.DexIndexNational))
{
Editor.PokeResourceList.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.FormCount);
}
if (!Editor.PokeResourceTable.Root.HasEntry(cPersonal.DexIndexNational, cPersonal.Form, 0))
{
Editor.PokeResourceTable.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, 0);
}
if (!Editor.EncounterRateTable.Root.HasEntry(cPersonal.DexIndexNational, cPersonal.Form))
{
Editor.EncounterRateTable.Root.AddEntry(cPersonal.DexIndexNational, cPersonal.Form);
}
// Reload entry with correct misc data
LoadMisc(entry);
}
var rBehave = Editor.SymbolBehave.Root;
if (!rBehave.HasEntry(cPersonal.DexIndexNational, cPersonal.Form, false))
{
rBehave.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, false);
rBehave.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, true);
}
var rResL = Editor.PokeResourceList.Root;
if (!rResL.HasEntry(cPersonal.DexIndexNational))
rResL.AddEntry(cPersonal.DexIndexNational, cPersonal.FormCount);
var rResT = Editor.PokeResourceTable.Root;
if (!rResT.HasEntry(cPersonal.DexIndexNational, cPersonal.Form, 0))
rResT.AddEntry(cPersonal.DexIndexNational, cPersonal.Form, 0);
var rEnc = Editor.EncounterRateTable.Root;
if (!rEnc.HasEntry(cPersonal.DexIndexNational, cPersonal.Form))
rEnc.AddEntry(cPersonal.DexIndexNational, cPersonal.Form);
}
private void TB_Gender_TextChanged(object sender, EventArgs e)

View File

@@ -66,7 +66,7 @@ private void B_Import_Click(object sender, EventArgs e)
public static void ExportTextFile(string fileName, bool newline, TextContainer lineData)
{
using MemoryStream ms = new();
using var ms = new MemoryStream();
ms.Write(new byte[] {0xFF, 0xFE}, 0, 2); // Write Unicode BOM
using (TextWriter tw = new StreamWriter(ms, new UnicodeEncoding()))
{
@@ -308,7 +308,7 @@ private void B_Randomize_Click(object sender, EventArgs e)
{
string[] data = TextData[i];
strings.AddRange(smart
? data.Where(line => !line.Contains("["))
? data.Where(line => !line.Contains('['))
: data);
}