Misc updates

Recognize & init GG data when dropping folder in (containing rom/exe
folders)
This commit is contained in:
Kurt 2018-11-13 22:19:19 -08:00
parent 52d70f0b9f
commit e8cd9cc30f
13 changed files with 119 additions and 24 deletions

View File

@ -7,5 +7,6 @@ public enum ContainerType
SARC,
Folder,
SingleFile,
GFPack,
}
}

View File

@ -64,10 +64,10 @@ public byte[] GetFileData(int index)
public bool Modified => TrackModify.Count != 0;
public int Count => Paths.Count;
public Task<byte[][]> GetFiles() => new Task<byte[][]>(() => Paths.Select(File.ReadAllBytes).ToArray());
public Task<byte[]> GetFile(int file, int subFile = 0) => new Task<byte[]>(() => this[file]);
public Task SetFile(int file, byte[] value, int subFile = 0) => new Task(() => this[file] = value);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(SaveAll);
public Task<byte[][]> GetFiles() => Task.FromResult(Paths.Select(File.ReadAllBytes).ToArray());
public Task<byte[]> GetFile(int file, int subFile = 0) => Task.FromResult(this[file]);
public Task SetFile(int file, byte[] value, int subFile = 0) => Task.FromResult(this[file] = value);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(SaveAll, token);
private void SaveAll()
{

View File

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@ -27,9 +26,9 @@ public class Mini : IFileContainer
public bool Modified { get; set; }
public int Count => Files.Length;
public Task<byte[]> GetFile(int file, int subFile = 0) => new Task<byte[]>(()=>Files[file]);
public Task SetFile(int file, byte[] value, int subFile = 0) => new Task(() => Files[file] = value);
public Task<byte[][]> GetFiles() => new Task<byte[][]>(() => Files);
public Task<byte[]> GetFile(int file, int subFile = 0) => Task.FromResult(Files[file]);
public Task SetFile(int file, byte[] value, int subFile = 0) => Task.FromResult(Files[file] = value);
public Task<byte[][]> GetFiles() => Task.FromResult(Files);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token)
{
@ -37,7 +36,7 @@ public Task SaveAs(string path, ContainerHandler handler, CancellationToken toke
{
byte[] data = MiniUtil.PackMini(Files, Identifier);
File.WriteAllBytes(path, data);
});
}, token);
}
public void Dump(string path, ContainerHandler handler)

View File

@ -266,19 +266,22 @@ private void WriteHeaderTableList(BinaryWriter bw)
public string FilePath { get; set; }
public bool Modified { get; set; }
public Task<byte[][]> GetFiles() => new Task<byte[][]>(() => DecompressedFiles);
public Task<byte[]> GetFile(int file, int subFile = 0) => new Task<byte[]>(Write);
public Task SetFile(int file, byte[] value, int subFile = 0) => new Task(() => this[file] = value);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(() => Dump(path, handler));
public Task<byte[][]> GetFiles() => Task.FromResult(DecompressedFiles);
public Task<byte[]> GetFile(int file, int subFile = 0) => Task.FromResult(this[file]);
public Task SetFile(int file, byte[] value, int subFile = 0) => Task.FromResult(this[file] = value);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(() => Dump(path, handler), token);
public void Dump(string path, ContainerHandler handler)
{
handler.Initialize(FileTable.Length);
for (var i = 0; i < FileTable.Length; i++)
{
var hashFull = HashPaths[i].HashFnv1aPathFull;
var loc = Path.Combine(path ?? FilePath, $"{i:000} {hashFull:X16}");
var fn = $"{i:000} {hashFull:X16}.bin";
var loc = Path.Combine(path ?? FilePath, fn);
var data = DecompressedFiles[i];
File.WriteAllBytes(loc, data);
handler.StepFile(i, fileName: fn);
}
}
}

View File

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
@ -25,7 +24,7 @@ public SingleFileContainer(string path)
public Task<byte[][]> GetFiles() => new Task<byte[][]>(() => new[] {Data});
public Task<byte[]> GetFile(int file, int subFile = 0) => new Task<byte[]>(() => Data);
public Task SetFile(int file, byte[] value, int subFile = 0) => new Task(() => Data = value);
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(() => Dump(path, handler));
public Task SaveAs(string path, ContainerHandler handler, CancellationToken token) => new Task(() => Dump(path, handler), token);
public void Dump(string path, ContainerHandler handler) => File.WriteAllBytes(path ?? FilePath, Data);
}
}

View File

@ -142,5 +142,6 @@ public enum GameFile
/// <summary> UI Sprites for pretty in-game move descriptors. </summary>
MoveSprites,
EncounterTrade
}
}

View File

@ -295,7 +295,46 @@ public static IReadOnlyCollection<GameFileReference> GetMapping(GameVersion game
/// </summary>
private static readonly GameFileReference[] GG =
{
new GameFileReference(GameFile.TrainerData, "bin", "trainer", "trainer_data"),
new GameFileReference(GameFile.TrainerPoke, "bin", "trainer", "trainer_poke"),
new GameFileReference(GameFile.TrainerClass, "bin", "trainer", "trainer_type"),
new GameFileReference(GameFile.GameText0, 0, "bin", "message", "JPN", "common"),
new GameFileReference(GameFile.GameText1, 1, "bin", "message", "JPN_KANJI", "common"),
new GameFileReference(GameFile.GameText2, 2, "bin", "message", "English", "common"),
new GameFileReference(GameFile.GameText3, 3, "bin", "message", "French", "common"),
new GameFileReference(GameFile.GameText4, 4, "bin", "message", "Italian", "common"),
new GameFileReference(GameFile.GameText5, 5, "bin", "message", "German", "common"),
// 6 unused lang
new GameFileReference(GameFile.GameText6, 7, "bin", "message", "Spanish", "common"),
new GameFileReference(GameFile.GameText7, 8, "bin", "message", "Korean", "common"),
new GameFileReference(GameFile.GameText8, 9, "bin", "message", "Simp_Chinese", "common"),
new GameFileReference(GameFile.GameText9, 10, "bin", "message", "Trad_Chinese", "common"),
new GameFileReference(GameFile.StoryText0, 0, "bin", "message", "JPN", "script"),
new GameFileReference(GameFile.StoryText1, 1, "bin", "message", "JPN_KANJI", "script"),
new GameFileReference(GameFile.StoryText2, 2, "bin", "message", "English", "script"),
new GameFileReference(GameFile.StoryText3, 3, "bin", "message", "French", "script"),
new GameFileReference(GameFile.StoryText4, 4, "bin", "message", "Italian", "script"),
new GameFileReference(GameFile.StoryText5, 5, "bin", "message", "German", "script"),
// 6 unused lang
new GameFileReference(GameFile.StoryText6, 7, "bin", "message", "Spanish", "script"),
new GameFileReference(GameFile.StoryText7, 8, "bin", "message", "Korean", "script"),
new GameFileReference(GameFile.StoryText8, 9, "bin", "message", "Simp_Chinese", "script"),
new GameFileReference(GameFile.StoryText9, 10, "bin", "message", "Trad_Chinese", "script"),
new GameFileReference(GameFile.ItemStats, "bin", "pokelib", "item"),
new GameFileReference(GameFile.Evolutions, "bin", "pokelib", "evolution"),
new GameFileReference(GameFile.PersonalStats, "bin", "pokelib", "personal"),
new GameFileReference(GameFile.MegaEvolutions, "bin", "pokelib", "mega_evolution"),
new GameFileReference(GameFile.MoveStats, ContainerType.Mini, "bin", "pokelib", "waza", "waza_data.bin"),
new GameFileReference(GameFile.EncounterStatic, ContainerType.SingleFile, "bin", "script_event_data", "event_encount.bin"),
new GameFileReference(GameFile.EncounterTrade, ContainerType.SingleFile, "bin", "script_event_data", "field_trade_data"),
new GameFileReference(GameFile.Learnsets, ContainerType.GFPack, "bin", "archive", "waza_oboe.gfpak"),
// Cutscenes bin\demo
// Models bin\archive\pokemon
// pretty much everything is obviously named :)
};
#endregion

View File

@ -28,6 +28,8 @@ public class GameFileReference
/// </summary>
public bool LanguageVariant { get; }
public int Language { get; }
/// <summary>
/// Indicates the parent of the data.
/// </summary>
@ -53,6 +55,32 @@ internal GameFileReference(string relPath, ContainerType t, GameFile ident, bool
RelativePath = relPath;
}
internal GameFileReference(GameFile ident, int lang, params string[] relPath)
{
File = ident;
Type = ContainerType.Folder;
LanguageVariant = true;
Language = lang;
RelativePath = Path.Combine(relPath);
}
internal GameFileReference(GameFile ident, params string[] relPath)
{
File = ident;
Type = ContainerType.Folder;
RelativePath = Path.Combine(relPath);
}
internal GameFileReference(GameFile ident, ContainerType t, params string[] relPath)
{
File = ident;
Type = t;
RelativePath = Path.Combine(relPath);
}
public IFileContainer Get(string basePath)
{
var path = Path.Combine(basePath, RelativePath);

View File

@ -1,4 +1,6 @@
using pkNX.Containers;
using System.Linq;
using pkNX.Containers;
using pkNX.Structures;
namespace pkNX.Game
@ -84,7 +86,11 @@ private void Initialize()
{
Data = new GameData
{
MoveData = this[GameFile.MoveStats].GetFiles().GetArray(z => (Move)new Move6(z)),
MoveData = this[GameFile.MoveStats].GetFiles().GetArray(z => (Move)new Move7(z)),
EvolutionData = this[GameFile.Evolutions].GetFiles().GetArray(z => (EvolutionSet)new EvolutionSet7(z)),
LevelUpData = this[GameFile.Evolutions].GetFiles().GetArray(z => (Learnset)new Learnset6(z)),
PersonalData = new PersonalTable(this[GameFile.PersonalStats].GetFiles().Result.OrderBy(z => z.Length).First(), Game),
MegaEvolutionData = new MegaEvolutionTable(this[GameFile.MegaEvolutions].GetFiles().Result),
};
}
}

View File

@ -29,7 +29,11 @@ public static T[] GetArray<T>(this byte[] entries, Func<byte[], int, T> del, int
return data;
}
public static T[] GetArray<T>(this Task<byte[][]> task, Func<byte[], T> del) => GetArray(task.Result, del);
public static T[] GetArray<T>(this Task<byte[][]> task, Func<byte[], T> del)
{
return GetArray(task.Result, del);
}
public static T[] GetArray<T>(this Task<byte[]> task, Func<byte[], int, T> del, int size) => GetArray(task.Result, del, size);
public static string[] GetHexLines(byte[] data, int count = 4)

View File

@ -132,6 +132,7 @@ private void LoadROM(EditorBase editor)
FLP_Controls.Controls.Add(c);
Text = $"{nameof(pkNX)} - {Editor.Game}";
TB_Path.Text = Editor.Location;
System.Media.SystemSounds.Asterisk.Play();
}
}

View File

@ -5,5 +5,10 @@ namespace pkNX.WinForms.Controls
internal class EditorGG : EditorBase
{
protected internal EditorGG(GameManager rom) : base(rom) { }
public void EditTrainers()
{
WinFormsUtil.Alert("Not implemented yet.");
}
}
}

View File

@ -14,6 +14,7 @@ public abstract class EditorBase
public int Language { get => ROM.Language; set => ROM.Language = value; }
protected EditorBase(GameManager rom) => ROM = rom;
public string Location { get; internal set; }
public IEnumerable<Button> GetControls(int width, int height)
{
@ -21,11 +22,17 @@ public IEnumerable<Button> GetControls(int width, int height)
var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
foreach (var m in methods)
{
Button b = new Button
const string prefix = "Edit";
if (!m.Name.StartsWith(prefix))
continue;
var name = m.Name.Substring(prefix.Length);
var b = new Button
{
Width = width,
Height = height,
Name = m.Name,
Name = $"B_{name}",
Text = m.Name.Substring(prefix.Length),
};
b.Click += (s, e) => m.Invoke(this, null);
yield return b;
@ -51,7 +58,9 @@ public static EditorBase GetEditor(string loc, int language)
{
var gl = GameLocation.GetGame(loc);
var gm = new GameManager(gl, language);
return GetEditor(gm);
EditorBase editor = GetEditor(gm);
editor.Location = loc;
return editor;
}
}
}