From 6c65c19de74e67dd330cb22f71374c09c18e0c64 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 4 Jun 2022 21:13:52 +0200 Subject: [PATCH] Update UI, LOCFile, COLFile, add PCKFileReader/Writer, update codebase to use new reader/class objects --- MinecraftUSkinEditor.sln | 28 - MinecraftUSkinEditor/Classes/FileTypes/COL.cs | 165 ------ .../Classes/FileTypes/COLFile.cs | 116 ++++ MinecraftUSkinEditor/Classes/FileTypes/LOC.cs | 130 ----- .../Classes/FileTypes/LOCFile.cs | 47 ++ .../Classes/FileTypes/PCKFile.cs | 125 +--- .../Classes/FileTypes/PCKProperties.cs | 12 + MinecraftUSkinEditor/Classes/IO/FileBase.cs | 33 -- MinecraftUSkinEditor/Classes/IO/FileData.cs | 294 ---------- MinecraftUSkinEditor/Classes/IO/FileOutput.cs | 193 ------- .../Classes/IO/LOC/LOCFileReader.cs | 86 +++ .../Classes/IO/LOC/LOCFileWriter.cs | 72 +++ .../Classes/IO/PCK/PCKFileReader.cs | 105 ++++ .../Classes/IO/PCK/PCKFileWriter.cs | 90 +++ MinecraftUSkinEditor/Classes/Program.cs | 2 - .../Forms/Additional-Popups/AddPCKPassword.cs | 2 +- .../Forms/Additional-Popups/MetaADD.cs | 5 +- .../Forms/Additional-Popups/meta.cs | 2 +- .../Forms/Additional-Popups/presetMeta.cs | 2 +- MinecraftUSkinEditor/Forms/Form1.cs | 536 +++++++----------- .../Skins-And-Textures/AdvancedOptions.cs | 23 +- .../AdvancedOptions.ja.resx | 4 +- .../Skins-And-Textures/AdvancedOptions.resx | 477 ++++++++-------- .../Forms/Skins-And-Textures/EntryEditor.cs | 6 +- .../Forms/Skins-And-Textures/addMeta.cs | 2 +- .../Skins-And-Textures/addMetaAdvanced.cs | 2 +- .../Forms/Skins-And-Textures/addnewskin.cs | 49 +- .../Forms/Skins-And-Textures/generateModel.cs | 180 +++--- .../Utilities/Animation/AnimationEditor.cs | 33 +- .../Forms/Utilities/Audio/AudioEditor.cs | 122 ++-- .../Forms/Utilities/COLEditor.Designer.cs | 10 + .../Forms/Utilities/COLEditor.cs | 57 +- .../Forms/Utilities/LOCEditor.Designer.cs | 192 +++---- .../Forms/Utilities/LOCEditor.cs | 134 ++--- .../Forms/Utilities/LOCEditor.resx | 2 +- .../Forms/Utilities/pckCenterOpen.cs | 31 +- .../Forms/Utilities/renameLoc.Designer.cs | 87 ++- .../Forms/Utilities/renameLoc.cs | 21 +- .../Forms/Utilities/renameLoc.resx | 2 +- MinecraftUSkinEditor/PckStudio.csproj | 15 +- .../Properties/Resources.Designer.cs | 10 - .../Properties/Resources.resx | 3 - .../Resources/UntitledSkinPCK.pck | Bin 1539 -> 0 bytes 43 files changed, 1435 insertions(+), 2072 deletions(-) delete mode 100644 MinecraftUSkinEditor/Classes/FileTypes/COL.cs create mode 100644 MinecraftUSkinEditor/Classes/FileTypes/COLFile.cs delete mode 100644 MinecraftUSkinEditor/Classes/FileTypes/LOC.cs create mode 100644 MinecraftUSkinEditor/Classes/FileTypes/LOCFile.cs create mode 100644 MinecraftUSkinEditor/Classes/FileTypes/PCKProperties.cs delete mode 100644 MinecraftUSkinEditor/Classes/IO/FileBase.cs delete mode 100644 MinecraftUSkinEditor/Classes/IO/FileData.cs delete mode 100644 MinecraftUSkinEditor/Classes/IO/FileOutput.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/LOC/LOCFileReader.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/LOC/LOCFileWriter.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/PCK/PCKFileReader.cs create mode 100644 MinecraftUSkinEditor/Classes/IO/PCK/PCKFileWriter.cs delete mode 100644 MinecraftUSkinEditor/Resources/UntitledSkinPCK.pck diff --git a/MinecraftUSkinEditor.sln b/MinecraftUSkinEditor.sln index d5de3f0b..93663ebb 100644 --- a/MinecraftUSkinEditor.sln +++ b/MinecraftUSkinEditor.sln @@ -5,10 +5,6 @@ VisualStudioVersion = 17.1.32414.318 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PckStudio", "MinecraftUSkinEditor\PckStudio.csproj", "{0ACAAEDE-93F5-4B5D-B8D7-A0C43359C0D6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nobleUpdater", "nobleUpdater\nobleUpdater.csproj", "{F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSM Visualiser", "CSM Visualiser\CSM Visualiser.csproj", "{3530A9F2-AE0F-44B4-84F9-8FBACB456070}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -31,30 +27,6 @@ Global {0ACAAEDE-93F5-4B5D-B8D7-A0C43359C0D6}.Release|x64.Build.0 = Release|Any CPU {0ACAAEDE-93F5-4B5D-B8D7-A0C43359C0D6}.Release|x86.ActiveCfg = Release|Any CPU {0ACAAEDE-93F5-4B5D-B8D7-A0C43359C0D6}.Release|x86.Build.0 = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|x64.ActiveCfg = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|x64.Build.0 = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|x86.ActiveCfg = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Debug|x86.Build.0 = Debug|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|Any CPU.Build.0 = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|x64.ActiveCfg = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|x64.Build.0 = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|x86.ActiveCfg = Release|Any CPU - {F77A61F1-0C6F-45DC-A5B5-A7BF38D64322}.Release|x86.Build.0 = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|x64.ActiveCfg = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|x64.Build.0 = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|x86.ActiveCfg = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Debug|x86.Build.0 = Debug|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|Any CPU.Build.0 = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|x64.ActiveCfg = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|x64.Build.0 = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|x86.ActiveCfg = Release|Any CPU - {3530A9F2-AE0F-44B4-84F9-8FBACB456070}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MinecraftUSkinEditor/Classes/FileTypes/COL.cs b/MinecraftUSkinEditor/Classes/FileTypes/COL.cs deleted file mode 100644 index 0dc7985b..00000000 --- a/MinecraftUSkinEditor/Classes/FileTypes/COL.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PckStudio.Classes -{ - static class COL - { - public class COLFile - { - byte[] data; - List extradata = new List(); - public List entries = new List(); - public List waterEntries = new List(); - public void Open(byte[] filePath) - { - data = filePath; - COL.Open(this, entries, waterEntries, data, extradata); - foreach (object[] obj in entries) - { - Console.WriteLine(obj[0].ToString() + " - #" + obj[1]); - } - } - public byte[] Save() - { - List SaveData = new List(); - SaveData.AddRange(new byte[] { 0x00, 0x00, 0x00, 0x01 }); - Console.WriteLine(entries.Count); - List ItemAmmount = new List(); - List WaterItemAmmount = new List(); - ItemAmmount.AddRange(BitConverter.GetBytes(entries.Count)); - WaterItemAmmount.AddRange(BitConverter.GetBytes(waterEntries.Count / 3)); - ItemAmmount.Reverse(); - WaterItemAmmount.Reverse(); - byte[] ItemNum = ItemAmmount.ToArray(); - byte[] WaterItemNum = WaterItemAmmount.ToArray(); - ItemNum.Reverse(); - WaterItemNum.Reverse(); - Console.WriteLine(BitConverter.ToString(ItemNum)); - Console.WriteLine(BitConverter.ToString(WaterItemNum)); - SaveData.AddRange(ItemNum); - foreach (object[] obj in entries) - { - //Console.WriteLine(obj[0] + " - #" + obj[1]); - byte[] NameLength = (BitConverter.GetBytes(obj[0].ToString().Length)); - SaveData.Add(NameLength[1]); - SaveData.Add(NameLength[0]); - SaveData.AddRange(Encoding.ASCII.GetBytes(obj[0].ToString())); - SaveData.Add(data[SaveData.Count]); - SaveData.AddRange(StringToByteArrayFastest(obj[1].ToString())); - } - SaveData.AddRange(WaterItemNum); - foreach (object[] obj in waterEntries) - { - //Console.WriteLine(obj[0] + " - #" + obj[1]); - string name = obj[0].ToString(); - if (!name.EndsWith("(Underwater)") && !name.EndsWith("(Fog)")) - { - byte[] NameLength = (BitConverter.GetBytes(obj[0].ToString().Length)); - SaveData.Add(NameLength[1]); - SaveData.Add(NameLength[0]); - SaveData.AddRange(Encoding.ASCII.GetBytes(obj[0].ToString())); - } - SaveData.AddRange(StringToByteArrayFastest(obj[1].ToString())); - } - return SaveData.ToArray(); - //File.WriteAllBytes(Path.GetDirectoryName(filePath) + "\\coloursSaved.col", SaveData.ToArray()); - } - } - public static void Open(COLFile This, List entries, List waterEntries, byte[] data, List extradata) - { - List MaxEntArrTemp = new List(); - MaxEntArrTemp.AddRange(data.Skip(4).Take(4)); - MaxEntArrTemp.Reverse(); - int MaxEntries = BitConverter.ToInt32(MaxEntArrTemp.ToArray(), 0); - int i = 1; - int LeftAt = 8; - while (i <= MaxEntries) - { - List ItemNameLength = new List(); - ItemNameLength.AddRange(data.Skip(LeftAt).Take(2)); - ItemNameLength.Reverse(); - int EntryLength = BitConverter.ToInt16(ItemNameLength.ToArray(), 0); - //Console.WriteLine(EntryLength); - - byte[] ItemName = (data.Skip(LeftAt + 2).Take(EntryLength).ToArray()); - byte[] ItemHex = (data.Skip(LeftAt + 3 + EntryLength).Take(3).ToArray()); - - object[] outentry = { System.Text.Encoding.Default.GetString(ItemName), BitConverter.ToString(ItemHex).Replace("-", "") }; - entries.Add(outentry); - LeftAt = LeftAt + 6 + EntryLength; - - i++; - } - Console.WriteLine(LeftAt); - Console.WriteLine(data.Length); - Console.WriteLine(data.Length - LeftAt); - extradata.AddRange(data.Skip(LeftAt).Take((data.Length) - LeftAt).ToArray()); - try - { - List MaxEntArrTempB = new List(); - MaxEntArrTempB.AddRange(extradata.Skip(-1).Take(4)); - MaxEntArrTempB.Reverse(); - int MaxEntriesB = BitConverter.ToInt32(MaxEntArrTempB.ToArray(), 0); - int LeftAtB = 4; - Console.WriteLine("MaxEntries (Extra Data) - " + MaxEntriesB); - for (int j = 0; j < MaxEntriesB; j++) - { - List ItemNameLength = new List(); - ItemNameLength.AddRange(extradata.Skip(LeftAtB).Take(2)); - ItemNameLength.Reverse(); - int EntryLength = BitConverter.ToInt16(ItemNameLength.ToArray(), 0); - //Console.WriteLine(EntryLength); - - byte[] ItemName = (extradata.Skip(LeftAtB + 2).Take(EntryLength).ToArray()); - byte[] ItemHex = (extradata.Skip(LeftAtB + 2 + EntryLength).Take(4).ToArray()); - byte[] ItemHexB = (extradata.Skip(LeftAtB + 6 + EntryLength).Take(4).ToArray()); - byte[] ItemHexC = (extradata.Skip(LeftAtB + 10 + EntryLength).Take(4).ToArray()); - - object[] outentry = { System.Text.Encoding.Default.GetString(ItemName), BitConverter.ToString(ItemHex).Replace("-", "") }; - object[] outentryB = { System.Text.Encoding.Default.GetString(ItemName) + " (Underwater)", BitConverter.ToString(ItemHexB).Replace("-", "") }; - object[] outentryC = { System.Text.Encoding.Default.GetString(ItemName) + " (Fog)", BitConverter.ToString(ItemHexC).Replace("-", "") }; - waterEntries.Add(outentry); - waterEntries.Add(outentryB); - waterEntries.Add(outentryC); - LeftAtB = LeftAtB + 14 + EntryLength; - } - } - catch(Exception e) - { - Console.WriteLine(e.Message); - } - } - - - static byte[] StringToByteArrayFastest(string hex) - { - if (hex.Length % 2 == 1) - throw new Exception("The binary key cannot have an odd number of digits"); - - byte[] arr = new byte[hex.Length >> 1]; - - for (int i = 0; i < hex.Length >> 1; ++i) - { - arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1]))); - } - - return arr; - } - - static int GetHexVal(char hex) - { - int val = (int)hex; - //For uppercase A-F letters: - //return val - (val < 58 ? 48 : 55); - //For lowercase a-f letters: - //return val - (val < 58 ? 48 : 87); - //Or the two combined, but a bit slower: - return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); - } - } -} diff --git a/MinecraftUSkinEditor/Classes/FileTypes/COLFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/COLFile.cs new file mode 100644 index 00000000..2bc0f6dd --- /dev/null +++ b/MinecraftUSkinEditor/Classes/FileTypes/COLFile.cs @@ -0,0 +1,116 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.FileTypes +{ + public class COLFile + { + public struct COLEntry + { + public string name; + public uint color; + } + + List extradata = new List(); + public List entries = new List(); + public List waterEntries = new List(); + public void Open(Stream stream) + { + byte[] buffer = new byte[8]; + stream.Read(buffer, 0, 8); + int has_water_colors = BitConverter.ToInt32(buffer, 0); + int color_entries = BitConverter.ToInt32(buffer, 4); + for (int i = 0; i < color_entries; i++) + { + COLEntry entry = new COLEntry(); + entry.name = ReadString(stream); + entry.color = ReadUint(stream); + entries.Add(entry); + } + if (has_water_colors == 1) + { + int water_color_entries = ReadInt(stream); + for (int i = 0; i < water_color_entries; i++) + { + COLEntry entry = new COLEntry(); + entry.name = ReadString(stream); + entry.color = ReadUint(stream); + waterEntries.Add(entry); + } + } + } + + + private string ReadString(Stream stream) + { + byte[] bytes = new byte[2]; + stream.Read(bytes, 0, 2); + if (BitConverter.IsLittleEndian) + Array.Reverse(bytes); + int strlen = BitConverter.ToInt16(bytes, 0); + byte[] stringBuffer = new byte[strlen]; + stream.Read(stringBuffer, 0, strlen); + return Encoding.UTF8.GetString(stringBuffer, 0, strlen); + } + + private int ReadInt(Stream stream) + { + return (int)ReadUint(stream); + } + + private uint ReadUint(Stream stream) + { + byte[] bytes = new byte[4]; + stream.Read(bytes, 0, 4); + if (BitConverter.IsLittleEndian) + Array.Reverse(bytes); + return BitConverter.ToUInt32(bytes, 0); + } + + private void WriteUint(Stream stream, uint value) + { + byte[] bytes = BitConverter.GetBytes(value); + if (BitConverter.IsLittleEndian) + Array.Reverse(bytes); + stream.Write(bytes, 0, 4); + } + private void WriteInt(Stream stream, int value) + { + WriteUint(stream, (uint)value); + } + + private void WriteString(Stream stream, string s) + { + byte[] bytes = BitConverter.GetBytes((short)s.Length); + if (BitConverter.IsLittleEndian) + Array.Reverse(bytes); + byte[] stringBuffer = Encoding.UTF8.GetBytes(s); + stream.Write(bytes, 0, 2); + stream.Write(stringBuffer, 0, s.Length); + } + + public void Save(Stream stream) + { + WriteInt(stream, Convert.ToInt32(waterEntries.Count > 0)); + WriteInt(stream, entries.Count); + foreach (var colorEntry in entries) + { + WriteString(stream, colorEntry.name); + WriteUint(stream, colorEntry.color); + } + if (waterEntries.Count > 0) + { + WriteInt(stream, waterEntries.Count); + foreach (var colorEntry in waterEntries) + { + WriteString(stream, colorEntry.name); + WriteUint(stream, colorEntry.color); + } + } + } + } +} diff --git a/MinecraftUSkinEditor/Classes/FileTypes/LOC.cs b/MinecraftUSkinEditor/Classes/FileTypes/LOC.cs deleted file mode 100644 index f94edb7d..00000000 --- a/MinecraftUSkinEditor/Classes/FileTypes/LOC.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PckStudio -{ - public class LOC - { - public LOC() - { - - } - - public LOC(byte[] data) - { - Read(data); - } - - public string readString(FileData f) - { - int length = f.readShort(); - string str = f.readString(f.pos(), length); - f.skip(length); - return str; - } - - public class Language - { - public string name; - public int unk1; - public List names = new List(); - - public string readString(FileData f) - { - int length = f.readShort(); - string str = f.readString(f.pos(), length); - f.skip(length); - return str; - } - - public Language() { } - - public void Read(FileData f) - { - int idCount = f.readInt(); - for (int i = 0; i < idCount; i++) - names.Add(readString(f)); - } - - public byte[] Rebuild() - { - FileOutput f = new FileOutput(); - f.Endian = Endianness.Big; - - f.writeInt(names.Count); - foreach(string name in names) - { - f.writeShort(name.Length); - f.writeString(name); - } - - return f.getBytes(); - } - } - - public Language ids = new Language(); - public List langs = new List(); - - public void Read(byte[] data) - { - FileData f = new FileData(data); - f.Endian = Endianness.Big; - - int unk1 = f.readInt(); - if (unk1 != 2) - throw new NotImplementedException("Unsupported localization data"); - int langCount = f.readInt(); - f.skip(1); - - ids.Read(f); - - for(int i = 0; i < langCount; i++) - { - Language l = new Language(); - l.name = readString(f); - l.unk1 = f.readInt(); - langs.Add(l); - } - - foreach (Language l in langs) - { - f.skip(5); - f.skip(f.readShort()); - l.Read(f); - } - } - - public byte[] Rebuild() - { - FileOutput f = new FileOutput(); - f.Endian = Endianness.Big; - - f.writeInt(2); - f.writeInt(langs.Count); - f.writeByte(0); - - f.writeBytes(ids.Rebuild()); - - foreach(Language l in langs) - { - f.writeShort(l.name.Length); - f.writeString(l.name); - f.writeInt(7 + l.name.Length + l.Rebuild().Length); - } - - foreach(Language l in langs) - { - f.writeInt(2); - f.writeByte(0); - f.writeShort(l.name.Length); - f.writeString(l.name); - f.writeBytes(l.Rebuild()); - } - - return f.getBytes(); - } - } -} diff --git a/MinecraftUSkinEditor/Classes/FileTypes/LOCFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/LOCFile.cs new file mode 100644 index 00000000..d961b852 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/FileTypes/LOCFile.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.FileTypes +{ + public class LOCFile + { + public Dictionary> languages { get; set; } = new Dictionary>(); + + public void AddEntry(string key, string value) + { + foreach (var language in languages.Values) + { + language.Add(key, value); + } + } + + public void ChangeEntry(string keyId, string newValue) + { + foreach (var language in languages.Values) + { + if (!language.ContainsKey(keyId)) throw new Exception("Key not found"); + language[keyId] = newValue; + } + } + + public void ChangeSingleEntry(string language, string keyId, string newValue) + { + if (!languages.ContainsKey(language)) throw new Exception("Key not found"); + if (!languages[language].ContainsKey(keyId)) throw new Exception("Key Id not found"); + languages[language][keyId] = newValue; + } + + public void RemoveEntry(string keyId) + { + foreach (var language in languages.Values) + { + if (language.ContainsKey(keyId)) + language.Remove(keyId); + } + } + } +} diff --git a/MinecraftUSkinEditor/Classes/FileTypes/PCKFile.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKFile.cs index af1836d0..85fc95ee 100644 --- a/MinecraftUSkinEditor/Classes/FileTypes/PCKFile.cs +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKFile.cs @@ -1,20 +1,15 @@ -using System; +using PckStudio.Classes.IO; +using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace PckStudio.Classes.FileTypes { - using PCKProperties = Dictionary; public class PCKFile { public int type { get; } = -1; - public Dictionary meta_data { get; } = new Dictionary(); + public Dictionary meta_data { get; } = new Dictionary(); public List file_entries { get; set; } = new List(); - public bool isLittleEndian { get; } = false; - public class FileData { @@ -36,112 +31,38 @@ namespace PckStudio.Classes.FileTypes public string name; public int type { get; } - public byte[] data { get; set; } = null; - public int size { get; set; } + public byte[] data => _data; + public int size => _size; public PCKProperties properties { get; set; } = new PCKProperties(); - public FileData(string name, int type, int size) + private byte[] _data = new byte[0]; + private int _size = 0; + + public FileData(string name, int type) { this.type = type; this.name = name; - this.size = size; } - public FileData(int type) + + public FileData(string name, int type, int dataSize) { - name = "no_name"; this.type = type; + this.name = name; + _size = dataSize; + _data = new byte[dataSize]; } + + public void SetData(byte[] data) + { + _data = data; + _size = data.Length; + } + } - public PCKFile(Stream stream, bool isLittleEndian = false) - { - this.isLittleEndian = isLittleEndian; - type = ReadInt(stream); - ReadMetaData(stream); - ReadFileEntries(stream); - } - - public PCKFile(int type, bool isLittleEndian = false) + public PCKFile(int type) { this.type = type; - this.isLittleEndian = isLittleEndian; } - - internal void ReadMetaData(Stream stream) - { - int meta_entry_count = ReadInt(stream); - bool has_xml_tag = false; - for (; 0 < meta_entry_count; meta_entry_count--) - { - int index = ReadInt(stream); - string value = ReadString(stream); - if (value.Equals("XMLVERSION")) has_xml_tag = true; - meta_data[index] = value; - ReadInt(stream); // padding ???? - } - if (has_xml_tag) - Console.WriteLine(ReadInt(stream).ToString("X08")); - } - - internal void ReadFileEntries(Stream stream) - { - int file_entry_count = ReadInt(stream); - for (;0 < file_entry_count; file_entry_count--) - { - int file_size = ReadInt(stream); - int file_type = ReadInt(stream); - string name = ReadString(stream); - file_entries.Add(new FileData(name, file_type, file_size)); - ReadInt(stream); - } - foreach (var file_entry in file_entries) - { - int property_count = ReadInt(stream); - var properties = new PCKProperties(); - for(;0 < property_count; property_count--) - { - int index = ReadInt(stream); - string key = meta_data[index]; - string value = ReadString(stream); - ReadInt(stream); // padding ??? - properties[key] = value; - } - file_entry.properties = properties; - file_entry.data = new byte[file_entry.size]; - stream.Read(file_entry.data, 0, file_entry.size); - } - - } - - internal string ReadString(Stream stream) - { - int len = ReadInt(stream); - byte[] stringBuffer = new byte[len * 2]; - stream.Read(stringBuffer, 0, len * 2); - return Encoding.BigEndianUnicode.GetString(stringBuffer, 0, len * 2); - } - - internal int ReadInt(Stream stream) - { - byte[] buffer = new byte[4]; - stream.Read(buffer, 0, 4); - if (BitConverter.IsLittleEndian && !isLittleEndian) - Array.Reverse(buffer); - return BitConverter.ToInt32(buffer, 0); - } - internal short ReadShort(Stream stream) - { - byte[] buffer = new byte[2]; - stream.Read(buffer, 0, 2); - if (BitConverter.IsLittleEndian && !isLittleEndian) - Array.Reverse(buffer); - return BitConverter.ToInt16(buffer, 0); - } - - public override string ToString() - { - return $"type: {type}\nmeta entry count: {meta_data.Count}\nfile entry count: {file_entries.Count}"; - } - } -} +} \ No newline at end of file diff --git a/MinecraftUSkinEditor/Classes/FileTypes/PCKProperties.cs b/MinecraftUSkinEditor/Classes/FileTypes/PCKProperties.cs new file mode 100644 index 00000000..fd1b7102 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/FileTypes/PCKProperties.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.FileTypes +{ + public class PCKProperties : List> // class because `using` is file scoped :| + { + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/FileBase.cs b/MinecraftUSkinEditor/Classes/IO/FileBase.cs deleted file mode 100644 index 55130744..00000000 --- a/MinecraftUSkinEditor/Classes/IO/FileBase.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace PckStudio -{ - public enum Endianness - { - Little = 0, - Big = 1 - } - - public abstract class FileBase - { - public abstract Endianness Endian { get; set; } - - - public abstract void Read(string filename); - public abstract byte[] Rebuild(); - - public void Save(string filename) - { - var Data = Rebuild(); - if (Data.Length <= 0) - throw new Exception("Warning: Data was empty!"); - - File.WriteAllBytes(filename, Data); - } - } -} diff --git a/MinecraftUSkinEditor/Classes/IO/FileData.cs b/MinecraftUSkinEditor/Classes/IO/FileData.cs deleted file mode 100644 index 20fc0576..00000000 --- a/MinecraftUSkinEditor/Classes/IO/FileData.cs +++ /dev/null @@ -1,294 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; - -namespace PckStudio -{ - public class FileData - { - private byte[] b; - - private int p; - - public Endianness Endian; - - public FileData(string f) - { - b = File.ReadAllBytes(f); - } - - public FileData(byte[] b) - { - this.p = 0; - this.b = b; - } - - public int eof() - { - return b.Length; - } - - public byte[] read(int length) - { - if (length + p > b.Length) - { - throw new IndexOutOfRangeException(); - } - byte[] array = new byte[length]; - int num = 0; - while (num < length) - { - array[num] = b[p]; - num++; - p++; - } - return array; - } - - public int readInt() - { - if (Endian == Endianness.Little) - { - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 24); - } - return ((b[p++] & 0xFF) << 24) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - } - - public int readThree() - { - if (Endian == Endianness.Little) - { - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16); - } - return ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - } - - public int readShort() - { - if (Endian == Endianness.Little) - { - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8); - } - return ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - } - - public int readIntVita() - { - if (Endian != Endianness.Little) - { - int d = p; - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 24); - } - int oot = ((b[p++] & 0xFF) << 24) | ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - return oot; - } - - public int readThreeVita() - { - if (Endian != Endianness.Little) - { - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8) | ((b[p++] & 0xFF) << 16); - } - return ((b[p++] & 0xFF) << 16) | ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - } - - public int readShortVita() - { - if (Endian != Endianness.Little) - { - return (b[p++] & 0xFF) | ((b[p++] & 0xFF) << 8); - } - return ((b[p++] & 0xFF) << 8) | (b[p++] & 0xFF); - } - - public int readByte() - { - return b[p++] & 0xFF; - } - - public byte[] readBytes(int length) - { - List list = new List(); - for (int i = 0; i < length; i++) - { - list.Add((byte)readByte()); - } - return list.ToArray(); - } - - public float readFloat() - { - byte[] array = new byte[4]; - array = ((Endian != 0) ? new byte[4] - { - b[p + 3], - b[p + 2], - b[p + 1], - b[p] - } : new byte[4] - { - b[p], - b[p + 1], - b[p + 2], - b[p + 3] - }); - p += 4; - return BitConverter.ToSingle(array, 0); - } - - public float readHalfFloat() - { - return toFloat((short)readShort()); - } - - public static float toFloat(int hbits) - { - int num = hbits & 0x3FF; - int num2 = hbits & 0x7C00; - switch (num2) - { - case 31744: - num2 = 261120; - break; - default: - num2 += 114688; - if (num == 0 && num2 > 115712) - { - return BitConverter.ToSingle(BitConverter.GetBytes(((hbits & 0x8000) << 16) | (num2 << 13) | 0x3FF), 0); - } - break; - case 0: - if (num != 0) - { - num2 = 115712; - do - { - num <<= 1; - num2 -= 1024; - } - while ((num & 0x400) == 0); - num &= 0x3FF; - } - break; - } - return BitConverter.ToSingle(BitConverter.GetBytes(((hbits & 0x8000) << 16) | ((num2 | num) << 13)), 0); - } - - public static int fromFloat(float fval, bool littleEndian) - { - int num = FileOutput.SingleToInt32Bits(fval, littleEndian); - int num2 = (num >> 16) & 0x8000; - int num3 = (num & 0x7FFFFFFF) + 4096; - if (num3 >= 1199570944) - { - if ((num & 0x7FFFFFFF) >= 1199570944) - { - if (num3 < 2139095040) - { - return num2 | 0x7C00; - } - return num2 | 0x7C00 | ((num & 0x7FFFFF) >> 13); - } - return num2 | 0x7BFF; - } - if (num3 >= 947912704) - { - return num2 | (num3 - 939524096 >> 13); - } - if (num3 < 855638016) - { - return num2; - } - num3 = (num & 0x7FFFFFFF) >> 23; - return num2 | (((num & 0x7FFFFF) | 0x800000) + (8388608 >> num3 - 102) >> 126 - num3); - } - - public static int sign12Bit(int i) - { - if (((i >> 11) & 1) == 1) - { - i = ~i; - i &= 0xFFF; - i++; - i *= -1; - } - return i; - } - - public void skip(int i) - { - p += i; - } - - public void seek(int i) - { - p = i; - } - - public int pos() - { - return p; - } - - public int size() - { - return b.Length; - } - - public string readString() - { - string text = ""; - while (b[p] != 0) - { - string str = text; - char c = (char)b[p]; - text = str + c; - p++; - } - return text; - } - - public byte[] getSection(int offset, int size) - { - byte[] array = new byte[size]; - Array.Copy(b, offset, array, 0, size); - return array; - } - - public string readString(int p, int size) - { - if (size == -1) - { - string text = ""; - while (p < b.Length && (b[p] & 0xFFu) != 0) - { - text += (char)(b[p] & 0xFFu); - p++; - } - return text; - } - string text2 = ""; - for (int i = p; i < p + size; i++) - { - if ((b[i] & 0xFFu) != 0) - { - text2 += (char)(b[i] & 0xFFu); - } - } - return text2; - } - - public void align(int i) - { - while (p % i != 0) - { - p++; - } - } - - public int readOffset() - { - return p + readInt(); - } - } -} diff --git a/MinecraftUSkinEditor/Classes/IO/FileOutput.cs b/MinecraftUSkinEditor/Classes/IO/FileOutput.cs deleted file mode 100644 index e376e0a5..00000000 --- a/MinecraftUSkinEditor/Classes/IO/FileOutput.cs +++ /dev/null @@ -1,193 +0,0 @@ -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; - -namespace PckStudio -{ - public class FileOutput - { - - List data = new List(); - - public Endianness Endian; - - public byte[] getBytes() - { - return data.ToArray(); - } - - public void writeString(String s){ - char[] c = s.ToCharArray(); - for(int i = 0; i < c.Length ; i++) - data.Add((byte)c[i]); - } - - public int size(){ - return data.Count; - } - - public void writeOutput(FileOutput d){ - foreach(byte b in d.data) - data.Add(b); - } - - private static char[] HexToCharArray(string hex) - { - return Enumerable.Range(0, hex.Length) - .Where(x => x % 2 == 0) - .Select(x => Convert.ToByte(hex.Substring(x, 2), 16)) - .Select(x => Convert.ToChar(x)) - .ToArray(); - } - - public void writeHex(string s) - { - char[] c = HexToCharArray(s); - for (int i = 0; i < c.Length; i++) - data.Add((byte)c[i]); - } - - public void writeInt(int i){ - if(Endian == Endianness.Little){ - data.Add((byte)((i)&0xFF)); - data.Add((byte)((i>>8)&0xFF)); - data.Add((byte)((i>>16)&0xFF)); - data.Add((byte)((i>>24)&0xFF)); - }else{ - data.Add((byte)((i>>24)&0xFF)); - data.Add((byte)((i>>16)&0xFF)); - data.Add((byte)((i>>8)&0xFF)); - data.Add((byte)((i)&0xFF)); - } - } - - - - public void writeIntAt(int i, int p){ - if(Endian == Endianness.Little){ - data[p++] = (byte)((i)&0xFF); - data[p++] = (byte)((i>>8)&0xFF); - data[p++] = (byte)((i>>16)&0xFF); - data[p++] = (byte)((i>>24)&0xFF); - }else{ - data[p++] = (byte)((i>>24)&0xFF); - data[p++] = (byte)((i>>16)&0xFF); - data[p++] = (byte)((i>>8)&0xFF); - data[p++] = (byte)((i)&0xFF); - } - } - public void writeShortAt(int i, int p){ - if(Endian == Endianness.Little){ - data[p++] = (byte)((i)&0xFF); - data[p++] = (byte)((i>>8)&0xFF); - }else{ - data[p++] = (byte)((i>>8)&0xFF); - data[p++] = (byte)((i)&0xFF); - } - } - - public void writeIntVita(int i) - { - if (Endian != Endianness.Little) - { - data.Add((byte)((i) & 0xFF)); - data.Add((byte)((i >> 8) & 0xFF)); - data.Add((byte)((i >> 16) & 0xFF)); - data.Add((byte)((i >> 24) & 0xFF)); - } - else - { - data.Add((byte)((i >> 24) & 0xFF)); - data.Add((byte)((i >> 16) & 0xFF)); - data.Add((byte)((i >> 8) & 0xFF)); - data.Add((byte)((i) & 0xFF)); - } - } - - public void align(int i){ - while(data.Count % i != 0) - writeByte(0); - } - - public void align(int i, int v){ - while(data.Count % i != 0) - writeByte(v); - } - - /*public void align(int i, int value){ - while(data.size() % i != 0) - writeByte(value); - }*/ - - - public void writeFloat(float f){ - int i = SingleToInt32Bits (f, Endian == Endianness.Big); - data.Add((byte)((i)&0xFF)); - data.Add((byte)((i>>8)&0xFF)); - data.Add((byte)((i>>16)&0xFF)); - data.Add((byte)((i>>24)&0xFF)); - } - - public static int SingleToInt32Bits(float value, bool littleEndian) { - byte[] b = BitConverter.GetBytes (value); - int p = 0; - - if (!littleEndian) { - return (b [p++]&0xFF) | ((b [p++] & 0xFF) << 8) | ((b [p++] & 0xFF) << 16) | ((b [p++] & 0xFF) << 24); - }else - return ((b [p++] & 0xFF) << 24) | ((b [p++] & 0xFF) << 16) | ((b [p++] & 0xFF) << 8) | (b [p++]&0xFF); - } - - public void writeHalfFloat(float f){ - int i = FileData.fromFloat(f, Endian == Endianness.Little); - data.Add((byte)((i>>8)&0xFF)); - data.Add((byte)((i)&0xFF)); - } - - public void writeShort(int i){ - if(Endian == Endianness.Little){ - data.Add((byte)((i)&0xFF)); - data.Add((byte)((i>>8)&0xFF)); - } else { - data.Add((byte)((i>>8)&0xFF)); - data.Add((byte)((i)&0xFF)); - } - } - - public void writeByte(int i){ - data.Add((byte)((i)&0xFF)); - } - - public void writeChars(char[] c) - { - foreach (char ch in c) - writeByte(Convert.ToByte(ch)); - } - - public void writeBytes(byte[] bytes) - { - foreach(byte b in bytes) - writeByte(b); - } - - public void writeFlag(bool b) - { - if (b) - writeByte(1); - else - writeByte(0); - } - - public int pos() - { - return data.Count; - } - - public void save(String fname) - { - File.WriteAllBytes (fname, data.ToArray()); - } - } -} - diff --git a/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileReader.cs b/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileReader.cs new file mode 100644 index 00000000..7f1c764b --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileReader.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using PckStudio.Classes.FileTypes; + +namespace PckStudio.Classes.IO.LOC +{ + internal class LOCFileReader + { + internal LOCFile _file; + + public static LOCFile Read(Stream stream) + { + return new LOCFileReader().ReadFile(stream); + } + + private LOCFileReader() + { + _file = new LOCFile(); + } + + internal LOCFile ReadFile(Stream stream) + { + int loc_type = ReadInt(stream); + int language_count = ReadInt(stream); + List keys = null; + if (loc_type == 2) keys = ReadKeys(stream); + for (int i = 0; i < language_count; i++) + { + string language = ReadString(stream); + _file.languages[language] = new Dictionary(); + ReadInt(stream); // padding ??? + } + for (int i = 0; i < language_count; i++) + { + stream.ReadByte(); // unknown + ReadInt(stream); // unknown + string language = ReadString(stream); + int count = ReadInt(stream); + for (int j = 0; j < count; j++) + { + string key = loc_type == 2 ? keys[j] : ReadString(stream); + string value = ReadString(stream); + _file.languages[language].Add(key, value); + } + } + return _file; + } + + internal List ReadKeys(Stream stream) + { + stream.ReadByte(); // unknown + int keyCount = ReadInt(stream); + List keys = new List(); + for (; 0 < keyCount; keyCount--) + { + string key = ReadString(stream); + keys.Add(key); + } + return keys; + } + + internal short ReadShort(Stream stream) + { + byte[] bytes = new byte[2]; + stream.Read(bytes, 0, bytes.Length); + return BitConverter.ToInt16(bytes, 0); + } + internal int ReadInt(Stream stream) + { + byte[] bytes = new byte[4]; + stream.Read(bytes, 0, bytes.Length); + return BitConverter.ToInt32(bytes, 0); + } + + internal string ReadString(Stream stream) + { + int length = ReadShort(stream); + byte[] buffer = new byte[length]; + stream.Read(buffer, 0, length); + return Encoding.UTF8.GetString(buffer, 0, length); + } + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileWriter.cs b/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileWriter.cs new file mode 100644 index 00000000..8e43d1bf --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/LOC/LOCFileWriter.cs @@ -0,0 +1,72 @@ +using PckStudio.Classes.FileTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace PckStudio.Classes.IO.LOC +{ + internal class LOCFileWriter + { + internal LOCFile _file; + public static void Write(Stream stream, LOCFile file, int type = 0) + { + new LOCFileWriter(file).WriteToStream(stream, type); + } + + private LOCFileWriter(LOCFile file) + { + _file = file; + } + + private void WriteToStream(Stream stream, int type) + { + WriteInt(stream, type); + WriteInt(stream, _file.languages.Count); + if (type == 2) WriteKeys(stream); + + WriteLanguages(stream); + } + + + internal void WriteKeys(Stream stream) + { + stream.WriteByte(0); + // TODO: find all keys and write them + //WriteInt(stream, ) + } + + internal void WriteLanguages(Stream stream) + { + foreach (var language in _file.languages.Keys) + { + WriteString(stream, language); + WriteInt(stream, 0); // padding ??? + } + } + + internal void WriteLanguageEntries(Stream stream) + { + + } + + internal void WriteShort(Stream stream, short value) + { + byte[] bytes = BitConverter.GetBytes(value); + stream.Write(bytes, 0, bytes.Length); + } + internal void WriteInt(Stream stream, int value) + { + byte[] bytes = BitConverter.GetBytes(value); + stream.Write(bytes, 0, bytes.Length); + } + + internal void WriteString(Stream stream, string s) + { + WriteShort(stream, (short)s.Length); + byte[] buffer = Encoding.UTF8.GetBytes(s); + stream.Write(buffer, 0, buffer.Length); + } + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileReader.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileReader.cs new file mode 100644 index 00000000..507ac7fc --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileReader.cs @@ -0,0 +1,105 @@ +using PckStudio.Classes.FileTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using System.Windows; + +namespace PckStudio.Classes.IO +{ + internal class PCKFileReader + { + internal bool isLittleEndian = false; + internal PCKFile _file; + + public static PCKFile Read(Stream s, bool isLittleEndian) + { + return new PCKFileReader(isLittleEndian).ReadFileFromStream(s); + } + + private PCKFileReader(bool isLittleEndian) + { + this.isLittleEndian = isLittleEndian; + } + + private PCKFile ReadFileFromStream(Stream s) + { + _file = new PCKFile(ReadInt(s)); + ReadMetaData(s); + ReadFileEntries(s); + return _file; + } + + internal void ReadMetaData(Stream stream) + { + int meta_entry_count = ReadInt(stream); + bool has_xml_tag = false; + for (; 0 < meta_entry_count; meta_entry_count--) + { + int index = ReadInt(stream); + string value = ReadString(stream); + if (value.Equals("XMLVERSION")) has_xml_tag = true; + _file.meta_data[value] = index; + ReadInt(stream); // padding ???? + } + if (has_xml_tag) + Console.WriteLine(ReadInt(stream).ToString("X08")); // xml version num ?? + } + + internal void ReadFileEntries(Stream stream) + { + int file_entry_count = ReadInt(stream); + for (; 0 < file_entry_count; file_entry_count--) + { + int file_size = ReadInt(stream); + int file_type = ReadInt(stream); + string name = ReadString(stream); + var entry = new PCKFile.FileData(name, file_type, file_size); + _file.file_entries.Add(entry); + ReadInt(stream); + } + foreach (var file_entry in _file.file_entries) + { + int property_count = ReadInt(stream); + + var properties = new PCKProperties(); + for (; 0 < property_count; property_count--) + { + int index = ReadInt(stream); + if (!_file.meta_data.ContainsValue(index)) // should never happen with valid pck's + throw new Exception("Value not found"); + string key = GetKeyFromValue(_file.meta_data, index); + string value = ReadString(stream); + properties.Add(new Tuple(key, value)); + ReadInt(stream); // padding ??? + } + file_entry.properties = properties; + stream.Read(file_entry.data, 0, file_entry.size); // file data buffer is only allocated when FileData is constructed with `dataSize` + } + } + private static T1 GetKeyFromValue(Dictionary dict, T2 value) + { + foreach (KeyValuePair pair in dict) + if (EqualityComparer.Default.Equals(pair.Value, value)) + return pair.Key; + return default(T1); // should never return unless dict.ContainsValue(value) returns false + } + + internal int ReadInt(Stream stream) + { + byte[] buffer = new byte[4]; + stream.Read(buffer, 0, 4); + if (BitConverter.IsLittleEndian && !isLittleEndian) + Array.Reverse(buffer); + return BitConverter.ToInt32(buffer, 0); + } + + internal string ReadString(Stream stream) + { + int len = ReadInt(stream); + byte[] stringBuffer = new byte[len * 2]; + stream.Read(stringBuffer, 0, len * 2); + return Encoding.BigEndianUnicode.GetString(stringBuffer, 0, len * 2); + } + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileWriter.cs b/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileWriter.cs new file mode 100644 index 00000000..76c25b15 --- /dev/null +++ b/MinecraftUSkinEditor/Classes/IO/PCK/PCKFileWriter.cs @@ -0,0 +1,90 @@ +using PckStudio.Classes.FileTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.IO +{ + internal class PCKFileWriter + { + internal bool isLittleEndian = false; + internal PCKFile _file; + + public static void Write(Stream stream, PCKFile file, bool isLittleEndian) + { + new PCKFileWriter(file, isLittleEndian).WriteFileToStream(stream); + } + + private PCKFileWriter(PCKFile file, bool isLittleEndian) + { + _file = file; + this.isLittleEndian = isLittleEndian; + } + + private void WriteFileToStream(Stream stream) + { + WriteInt(stream, _file.type); + WriteMetaEntries(stream); + WriteFileEntries(stream); + } + + internal void WriteInt(Stream stream, int value) + { + byte[] buffer = BitConverter.GetBytes(value); + if (BitConverter.IsLittleEndian && !isLittleEndian) + Array.Reverse(buffer); + stream.Write(buffer, 0, buffer.Length); + } + + internal void WriteString(Stream stream, string s) + { + WriteInt(stream, s.Length); + byte[] byteString = Encoding.BigEndianUnicode.GetBytes(s); + stream.Write(byteString, 0, byteString.Length); + } + + internal void WriteMetaEntries(Stream stream) + { + WriteInt(stream, _file.meta_data.Count); + bool has_xmlverion_tag = false; + foreach (var metaEntry in _file.meta_data) + { + if (metaEntry.Key == "XMLVERION") has_xmlverion_tag = true; + WriteInt(stream, metaEntry.Value); + WriteString(stream, metaEntry.Key); + WriteInt(stream, 0); + } + if (has_xmlverion_tag) + WriteInt(stream, 0); + } + + internal void WriteFileEntries(Stream stream) + { + WriteInt(stream, _file.file_entries.Count); + foreach (var entry in _file.file_entries) + { + WriteInt(stream, entry.size); + WriteInt(stream, entry.type); + WriteString(stream, entry.name); + WriteInt(stream, 0); + } + foreach (var entry in _file.file_entries) + { + WriteInt(stream, entry.properties.Count); + foreach (var property in entry.properties) + { + if (!_file.meta_data.ContainsKey(property.Item1)) + throw new Exception("invalid meta type" + property.Item1); + WriteInt(stream, _file.meta_data[property.Item1]); + WriteString(stream, property.Item2); + WriteInt(stream, 0); + } + stream.Write(entry.data, 0, entry.size); + } + } + + } +} diff --git a/MinecraftUSkinEditor/Classes/Program.cs b/MinecraftUSkinEditor/Classes/Program.cs index 0864735c..06010a6b 100644 --- a/MinecraftUSkinEditor/Classes/Program.cs +++ b/MinecraftUSkinEditor/Classes/Program.cs @@ -16,14 +16,12 @@ namespace PckStudio public static string baseurl = "https://www.pckstudio.xyz/studio/PCK/api/"; public static string backurl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/"; public static string Appdata = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK Studio/"; - public static bool IsDev; /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { - IsDev = args.Length > 0 && args[0] == "-dev"; Application.Run(new PckStudio.FormMain()); } } diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/AddPCKPassword.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/AddPCKPassword.cs index 6413ae65..834605dc 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/AddPCKPassword.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/AddPCKPassword.cs @@ -25,7 +25,7 @@ namespace PckStudio.Forms private void buttonUnlocked_Click(object sender, EventArgs e) { - file.properties.Add("LOCK", MD5(textBoxPass.Text)); + file.properties.Add(new Tuple("LOCK", MD5(textBoxPass.Text))); Close(); } diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/MetaADD.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/MetaADD.cs index 72a5e5d2..dd7f0106 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/MetaADD.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/MetaADD.cs @@ -27,12 +27,13 @@ namespace PckStudio private void button1_Click(object sender, EventArgs e) { - if (currentPCK.meta_data.ContainsValue(textBox1.Text)) + if (currentPCK.meta_data.ContainsKey(textBox1.Text)) { MessageBox.Show("This metatag already exits"); return; } - currentPCK.meta_data.Add(currentPCK.meta_data.Count, textBox1.Text); + if (!currentPCK.meta_data.ContainsValue(currentPCK.meta_data.Count)) + currentPCK.meta_data.Add(textBox1.Text, currentPCK.meta_data.Count); Close(); } } diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/meta.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/meta.cs index d4878172..65847aa1 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/meta.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/meta.cs @@ -34,7 +34,7 @@ namespace PckStudio try { treeView1.Nodes.Clear(); - foreach (string key in currentPCK.meta_data.Values) + foreach (string key in currentPCK.meta_data.Keys) { treeView1.Nodes.Add(key); } diff --git a/MinecraftUSkinEditor/Forms/Additional-Popups/presetMeta.cs b/MinecraftUSkinEditor/Forms/Additional-Popups/presetMeta.cs index fcaa8533..6e55f85b 100644 --- a/MinecraftUSkinEditor/Forms/Additional-Popups/presetMeta.cs +++ b/MinecraftUSkinEditor/Forms/Additional-Popups/presetMeta.cs @@ -89,7 +89,7 @@ namespace PckStudio } else { - file.properties.Add(entryName, entryValue); + file.properties.Add(new Tuple(entryName, entryValue )); entryName = ""; entryValue = ""; entryStart = true; diff --git a/MinecraftUSkinEditor/Forms/Form1.cs b/MinecraftUSkinEditor/Forms/Form1.cs index 4e87982c..e46a695b 100644 --- a/MinecraftUSkinEditor/Forms/Form1.cs +++ b/MinecraftUSkinEditor/Forms/Form1.cs @@ -15,6 +15,7 @@ using System.Drawing.Imaging; using RichPresenceClient; using PckStudio.Classes.FileTypes; using PckStudio.Classes.IO; +using PckStudio.Classes.IO.LOC; namespace PckStudio { @@ -26,19 +27,14 @@ namespace PckStudio PCKFile.FileData mf;//Template minefile variable PCKFile currentPCK;//currently opened pck - LOC l; //Locdata - PCKFile.FileData mfLoc; //LOC minefile - PCKFile.FileData file; //template for a selected minefile - bool needsUpdate = false; + LOCFile l; //Locdata + PCKFile.FileData mfLoc = new PCKFile.FileData("CURRENTLOCDATA", 6); //LOC minefile + PCKFile.FileData file; //template for a selected minefile + bool needsUpdate = false; bool saved = true; + bool isTemplateFile = false; string appData = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK Studio/"; - public class displayId - { - public string id; - public string defaultName; - } - public FormMain() { InitializeComponent(); @@ -146,10 +142,15 @@ namespace PckStudio { fileEntryCountLabel.Text = "Files:" + currentPCK.file_entries.Count; treeMeta.Enabled = true; + buttonEdit.Visible = false; + //Sets preview image to "NO IMAGE" if selected file data isn't image data + pictureBoxImagePreview.Image = (Image)Resources.NoImageFound; int pictureBoxMaxHeight = (tabPage1.Height / 2) - (tabPage1.Height / 10); - if (treeViewMain.SelectedNode.Tag != null) //"Selects" node if it has data/isn't a folder + pictureBoxImagePreview.Size = new Size(pictureBoxMaxHeight, pictureBoxMaxHeight); + labelImageSize.Text = "";//Resets image size display if theres no image + if (treeViewMain.SelectedNode.Tag != null && treeViewMain.SelectedNode.Tag is PCKFile.FileData) //"Selects" node if it has data/isn't a folder { - PCKFile.FileData file = (PCKFile.FileData)e.Node.Tag; //Sets current minefile being read + PCKFile.FileData file = e.Node.Tag as PCKFile.FileData; treeMeta.Nodes.Clear(); //clears minefile metadata treeview @@ -318,14 +319,6 @@ namespace PckStudio labelImageSize.Text = ""; } } - else - { - buttonEdit.Visible = false; - //Sets preview image to "NO IMAGE" if selected file data isn't image data - pictureBoxImagePreview.Image = (Image)Resources.NoImageFound; - pictureBoxImagePreview.Size = new Size(pictureBoxMaxHeight, pictureBoxMaxHeight); - } - labelImageSize.Text = "";//Resets image size display if theres no image } #region Parses boxes and opens model generator @@ -475,193 +468,42 @@ namespace PckStudio } #endregion - #region saves pck - private void save(string saveType) + private void save() { - TreeView saveStructure = new TreeView();//Temporary new treeview to properly store minefiles in writable form - //structures minefile data based on wether it has parent nodes or not and with its proper minefile data - foreach (TreeNode item in treeViewMain.Nodes) + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "PCK (Minecraft Console Package)|*.pck"; + saveFileDialog.DefaultExt = ".pck"; + if (saveFileDialog.ShowDialog() == DialogResult.OK) { - TreeNode add = new TreeNode(); - if (item.Parent != null) + using (var fs = File.OpenWrite(saveFileDialog.FileName)) { - string itemPath = "";//item path template - List path = new List();//directory template - GetPathToRoot(treeViewMain.SelectedNode, path);//gets all parents nodes - //generates minefile directory to properly store in minedata - foreach (TreeNode dire in path) - { - itemPath += dire.Text + "/"; - } - add.Text = itemPath + item.Text; - } - else - { - add.Text = item.Text; - } - add.Tag = item.Tag; - saveStructure.Nodes.Add(add); - add.Remove(); - } - - //Reassignes each node with its minefile data to make sure everything is synced - foreach (TreeNode item in saveStructure.Nodes) - { - currentPCK.file_entries[item.Index] = (PCKFile.FileData)item.Tag; - } - - //Syncs minefile name with nodes name - for (int i = 0; i < saveStructure.Nodes.Count; i++) - currentPCK.file_entries[i].name = saveStructure.Nodes[i].Text; - - if (saveLocation == appData + @"\templates\UntitledSkinPCK.pck") - { - //writes pck data if pck is actually opened - using (var ofd = new SaveFileDialog()) - { - ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; - - if (ofd.ShowDialog() == DialogResult.OK) - { - try - { - MessageBox.Show("TODO!!!!"); - //Console.WriteLine(currentPCK.isLittleEndian.ToString() + "--"); - //if (LittleEndianCheckBox.Checked) - //{ - // byte[] oouput = currentPCK.RebuildVita(); - // oouput[0] = 0x03; - // File.WriteAllBytes(ofd.FileName, currentPCK.RebuildVita()); - //} - //else - //{ - // byte[] oouput = currentPCK.Rebuild(); - // File.WriteAllBytes(ofd.FileName, currentPCK.Rebuild()); - //} - //saveLocation = ofd.FileName; - //openedPCKS.SelectedTab.Text = Path.GetFileName(ofd.FileName); - //saved = true; - //MessageBox.Show("PCK Saved!"); - //PCKFilePath = Path.GetFileName(ofd.FileName); - } - catch (Exception) - { - MessageBox.Show("No PCK loaded"); - } - } + PCKFileWriter.Write(fs, currentPCK, LittleEndianCheckBox.Checked); } } - else if (saveType == "Save As") - { - //writes pck data if pck is actually opened - using (var ofd = new SaveFileDialog()) - { - ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; - - if (ofd.ShowDialog() == DialogResult.OK) - { - try - { - MessageBox.Show("TODO!!"); - //Console.WriteLine(currentPCK.isLittleEndian.ToString() + "--"); - //if (LittleEndianCheckBox.Checked) - //{ - // byte[] oouput = currentPCK.RebuildVita(); - // oouput[0] = 0x03; - // File.WriteAllBytes(ofd.FileName, currentPCK.RebuildVita()); - //} - //else - //{ - // byte[] oouput = currentPCK.Rebuild(); - // File.WriteAllBytes(ofd.FileName, currentPCK.Rebuild()); - //} - //saveLocation = ofd.FileName; - //openedPCKS.SelectedTab.Text = Path.GetFileName(ofd.FileName); - //saved = true; - //MessageBox.Show("PCK Saved!"); - } - catch (Exception) - { - MessageBox.Show("No PCK loaded"); - } - } - } - } - else - { - MessageBox.Show("TODO!!!"); - //if (MessageBox.Show("Are you sure you wanna save?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes) - //{ - // try - // { - // Console.WriteLine(currentPCK.isLittleEndian.ToString() + "--"); - // if (LittleEndianCheckBox.Checked) - // { - // byte[] oouput = currentPCK.RebuildVita(); - // oouput[0] = 0x03; - // File.WriteAllBytes(saveLocation, currentPCK.RebuildVita()); - // } - // else - // { - // byte[] oouput = currentPCK.Rebuild(); - // File.WriteAllBytes(saveLocation, currentPCK.Rebuild()); - // } - // } - // catch (Exception) - // { - // for (int i = 0; i < saveStructure.Nodes.Count; i++) - // currentPCK.file_entries[i].name = saveStructure.Nodes[i].Text; - - // using (var ofd = new SaveFileDialog()) - // { - // ofd.Filter = "PCK (Minecraft Console Package)|*.pck"; - - // if (ofd.ShowDialog() == DialogResult.OK) - // { - // try - // { - // File.WriteAllBytes(ofd.FileName, currentPCK.Rebuild()); - // saved = true; - // MessageBox.Show("PCK Saved!"); - // } - // catch (Exception) - // { - // MessageBox.Show("No PCK loaded"); - // } - // } - // } - // } - //} - } - saveStructure.Dispose();//disposes temporarily made treeview } - #endregion - #region replaces pck entry with selected file private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { - if (treeViewMain.SelectedNode.Tag is PCKFile.FileData)//Makes sure file being replaced is an actual minefile or not null + if (treeViewMain.SelectedNode.Tag is PCKFile.FileData) //Makes sure file being replaced is an actual minefile or not null { - PCKFile.FileData mf = (PCKFile.FileData)treeViewMain.SelectedNode.Tag; //backups minefile data for node + PCKFile.FileData mf = treeViewMain.SelectedNode.Tag as PCKFile.FileData; //backups minefile data for node using (var ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == DialogResult.OK) { - mf.data = File.ReadAllBytes(ofd.FileName);//overwrites minefile data with chosen files data + mf.SetData(File.ReadAllBytes(ofd.FileName)); //overwrites minefile data with chosen files data } } } saved = false; } - #endregion - #region deletes pck entry from treeview and PCKFile.FileDatas private void deleteFileToolStripMenuItem_Click(object sender, EventArgs e) { //Removes selected from current pcks minefiles list and nodes if (treeViewMain.SelectedNode.Tag is PCKFile.FileData) { - PCKFile.FileData mf = (PCKFile.FileData)treeViewMain.SelectedNode.Tag; + PCKFile.FileData mf = treeViewMain.SelectedNode.Tag as PCKFile.FileData; treeViewMain.Nodes.Remove(treeViewMain.SelectedNode); currentPCK.file_entries.Remove(mf); } @@ -690,13 +532,12 @@ namespace PckStudio } saved = false; } - #endregion #region renames pck entry from treeview and PCKFile.FileDatas private void renameFileToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = treeViewMain.SelectedNode; - PckStudio.rename diag = new PckStudio.rename(node); + rename diag = new rename(node); diag.ShowDialog(this); diag.Dispose();//diposes generated metadata adding dialog data treeViewMain.SelectedNode.Text = Path.GetFileName(node.Name); @@ -759,7 +600,7 @@ namespace PckStudio if (ofd.ShowDialog() == DialogResult.OK) { PCKFile.FileData mf = new PCKFile.FileData(Path.GetFileName(ofd.FileName), 0);//Creates new minefile template - mf.data = File.ReadAllBytes(ofd.FileName); + mf.SetData(File.ReadAllBytes(ofd.FileName)); TreeNode add = new TreeNode(mf.name) { Tag = mf }; //Gets proper file icon for minefile @@ -832,7 +673,7 @@ namespace PckStudio private void createSkinToolStripMenuItem_Click(object sender, EventArgs e) { int i = treeViewMain.Nodes.Count - 1;//Gets index of last item in treeview - int tempIDD;//sets variables for a temporary skin/cape id + int tempIDD; //sets variables for a temporary skin/cape id try { @@ -850,7 +691,10 @@ namespace PckStudio try { - l = new LOC(mf.data);//sets loc data + using (var stream = new MemoryStream(mf.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { @@ -860,13 +704,16 @@ namespace PckStudio } PckStudio.addnewskin add = new PckStudio.addnewskin(currentPCK, treeViewMain, tempIDD.ToString(), l);//Sets dialog data for skin creator add.ShowDialog();//opens skin creator - mf.data = l.Rebuild();//rebuilds loc data + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l); + mf.SetData(stream.ToArray()); + } add.Dispose();//disposes generated skin creator data saved = false; } #endregion - #region adds a new Audio.pck to the project private void audiopckToolStripMenuItem_Click(object sender, EventArgs e) { @@ -881,7 +728,6 @@ namespace PckStudio for (int i = 0; i < 3; i++) { PCKFile.FileData mf = new PCKFile.FileData("", i); - mf.data = new byte[0]; //audioPCKFile.file_entries.Add(mf); } PCKFile.FileData audioMF = new PCKFile.FileData("audio.pck", 8); @@ -944,7 +790,6 @@ namespace PckStudio treeViewToMineFiles(treeViewMain, currentPCK); diag.Dispose(); } - #endregion #region starts up form to create and add a animated texture private void createAnimatedTextureToolStripMenuItem_Click(object sender, EventArgs e) @@ -998,10 +843,13 @@ namespace PckStudio mf = treeViewMain.SelectedNode.Tag as PCKFile.FileData; if (mf.type == 6) { - LOC l; + LOCFile l; try { - l = new LOC(mf.data); + using (var stream = new MemoryStream(mf.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { @@ -1009,8 +857,12 @@ namespace PckStudio MessageBoxIcon.Error); return; } - (new LOCEditor(l)).ShowDialog(); //Opens LOC Editor - mf.data = l.Rebuild(); //Rebuilds loc file with locdata in grid view after closing dialog + (new LOCEditor(l)).ShowDialog(); + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l); + mf.SetData(stream.ToArray()); + } } } @@ -1074,11 +926,11 @@ namespace PckStudio private void treeMeta_AfterSelect(object sender, TreeViewEventArgs e) { comboBox1.Items.Clear(); //Resets metadata combobox of selectable entry names - var strings = (KeyValuePair>)e.Node.Tag; + var strings = (Tuple)e.Node.Tag; foreach (var type in currentPCK.meta_data.Keys) comboBox1.Items.Add(type); - comboBox1.Text = strings.Key; - textBox1.Text = strings.Value[0]; + comboBox1.Text = strings.Item1; + textBox1.Text = strings.Item2; } #endregion @@ -1386,13 +1238,11 @@ namespace PckStudio { Console.WriteLine("ERROR WITH RPC"); } - - Directory.CreateDirectory(appData + "\\template"); - if (!File.Exists(appData + "\\template\\UntitledSkinPCK.pck")) - File.WriteAllBytes(appData + "\\template\\UntitledSkinPCK.pck", Resources.UntitledSkinPCK); - - DBGLabel.Visible = Program.IsDev; - +#if DEBUG + DBGLabel.Visible = true; +#else + DBGLabel.Visible = false; +#endif //Makes sure appdata exists if (!Directory.Exists(appData)) { @@ -1404,16 +1254,13 @@ namespace PckStudio Directory.CreateDirectory(appData + "\\cache\\mods\\"); } } - #endregion - - #region deletes pck entires through the del key - private void treeViewMain_KeyDown(object sender, KeyEventArgs e) - { - - } #endregion - #region extracts a selected pck without opening the pck + private void treeViewMain_KeyDown(object sender, KeyEventArgs e) + { + // TODO + } + private void extractToolStripMenuItem1_Click(object sender, EventArgs e) { try @@ -1424,37 +1271,34 @@ namespace PckStudio ofd.CheckFileExists = true; ofd.Filter = "PCK (Minecraft Wii U Package)|*.pck"; - if (ofd.ShowDialog() == DialogResult.OK) + if (ofd.ShowDialog() == DialogResult.OK && sfd.ShowDialog() == DialogResult.OK) { - if (sfd.ShowDialog() == DialogResult.OK) + PCKFile pckfile = null; + using (var fs = File.OpenRead(ofd.FileName)) + { + pckfile = PCKFileReader.Read(fs, LittleEndianCheckBox.Checked); + } + foreach (PCKFile.FileData mf in pckfile.file_entries) { - PCKFile pckfile = null; - using (var fs = File.OpenRead(ofd.FileName)) - { - pckfile = PCKFileReader.Read(fs, LittleEndianCheckBox.Checked); - } - foreach (PCKFile.FileData mf in pckfile.file_entries) + foreach (var entry in mf.properties) { - foreach (var entry in mf.properties) + if (entry.Item1 == "LOCK" && new pckLocked(entry.Item2).ShowDialog() != DialogResult.OK) // Check for lock on PCK File { - if (entry.Item1 == "LOCK" && new pckLocked(entry.Item2).ShowDialog() != DialogResult.OK) // Check for lock on PCK File - { - return; // cancel extraction if password not provided - } + return; // cancel extraction if password not provided } - FileInfo file = new FileInfo(sfd.SelectedPath + @"\" + mf.name); - file.Directory.Create(); // If the directory already exists, this method does nothing. - File.WriteAllBytes(sfd.SelectedPath + @"\" + mf.name, mf.data); //writes minefile to file - //attempts to generate reimportable metadata file out of minefiles metadata - string metaData = ""; - - foreach (var entry in mf.properties) - { - metaData += entry.Item1 + ":" + entry.Item2 + Environment.NewLine; - } - - File.WriteAllText(sfd.SelectedPath + @"\" + mf.name + ".txt", metaData); } + FileInfo file = new FileInfo(sfd.SelectedPath + @"\" + mf.name); + file.Directory.Create(); // If the directory already exists, this method does nothing. + File.WriteAllBytes(sfd.SelectedPath + @"\" + mf.name, mf.data); //writes minefile to file + //attempts to generate reimportable metadata file out of minefiles metadata + string metaData = ""; + + foreach (var entry in mf.properties) + { + metaData += $"{entry.Item1}: {entry.Item2}{Environment.NewLine}"; + } + + File.WriteAllText(sfd.SelectedPath + @"\" + mf.name + ".txt", metaData); } } } catch (Exception) @@ -1462,37 +1306,33 @@ namespace PckStudio MessageBox.Show("Unsupported PCK"); } } - #endregion - #region deletes metadata entries through the del key +#region deletes metadata entries through the del key private void treeMeta_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyData == Keys.Delete)//makes sure pressed key was del + if (e.KeyData == Keys.Delete && treeMeta.SelectedNode != null)//makes sure pressed key was del { - if (treeMeta.SelectedNode != null)//makes sure selected node is a minefile + //removes selected treemeta entry + file.properties.Remove((Tuple)treeMeta.SelectedNode.Tag); + treeMeta.Nodes.Remove(treeMeta.SelectedNode); + + //reloads treemeta data + treeMeta.Nodes.Clear(); + foreach (var type in currentPCK.meta_data.Keys) + comboBox1.Items.Add(type); + + foreach (var entry in file.properties) { - //removes selected treemeta entry - file.properties.Remove((Tuple)treeMeta.SelectedNode.Tag); - treeMeta.Nodes.Remove(treeMeta.SelectedNode); - - //reloads treemeta data - treeMeta.Nodes.Clear(); - foreach (var type in currentPCK.meta_data.Keys) - comboBox1.Items.Add(type); - - foreach (var entry in file.properties) - { - TreeNode meta = new TreeNode(entry.Item1); - meta.Tag = entry; - treeMeta.Nodes.Add(meta); - } + TreeNode meta = new TreeNode(entry.Item1); + meta.Tag = entry; + treeMeta.Nodes.Add(meta); } + saved = false; } - saved = false; } - #endregion +#endregion - #region imports a folder of skins to pck +#region imports a folder of skins to pck private void importExtractedSkinsFolder(object sender, EventArgs e) { FolderBrowserDialog contents = new FolderBrowserDialog();//Creates folder browser instance @@ -1535,7 +1375,7 @@ namespace PckStudio type = 1; } PCKFile.FileData mfNew = new PCKFile.FileData("", type); //new minefile template - mfNew.data = File.ReadAllBytes(contents.SelectedPath + @"\" + file.Name.Remove(file.Name.Length - 4, 4) + ".png");//sets minefile data to image data of current skin + mfNew.SetData(File.ReadAllBytes(contents.SelectedPath + @"\" + file.Name.Remove(file.Name.Length - 4, 4) + ".png"));//sets minefile data to image data of current skin TreeNode skin = new TreeNode(); //create template treenode for minefile @@ -1606,11 +1446,14 @@ namespace PckStudio //creates displayname id in loc file if (locNameId != "" && locName != "") { - LOC l; + LOCFile l; try { - l = new LOC(mfLoc.data); + using (var stream = new MemoryStream(mf.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { @@ -1618,15 +1461,13 @@ namespace PckStudio return; } - displayId dis = new displayId(); - dis.id = locNameId; - dis.defaultName = locName; + l.AddEntry(locThemeId, locTheme); - l.ids.names.Add(dis.id); - - foreach (LOC.Language lo in l.langs) - lo.names.Add(dis.defaultName); - mfLoc.data = l.Rebuild(); + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l); + mfLoc.SetData(stream.ToArray()); + } locNameId = ""; locName = ""; } @@ -1634,11 +1475,14 @@ namespace PckStudio //creates metadata id in loc file if (locThemeId != "" && locTheme != "") { - LOC l; + LOCFile l; try { - l = new LOC(mfLoc.data); + using (var stream = new MemoryStream(mfLoc.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { @@ -1646,16 +1490,12 @@ namespace PckStudio return; } - displayId b = new displayId(); - b.id = locThemeId; - b.defaultName = locTheme; - - l.ids.names.Add(b.id); - - foreach (LOC.Language lo in l.langs) - lo.names.Add(b.defaultName); - - mfLoc.data = l.Rebuild(); + l.AddEntry(locThemeId, locTheme); + using (var stream = new MemoryStream(mf.data)) + { + LOCFileWriter.Write(stream, l); + mfLoc.SetData(stream.ToArray()); + } locThemeId = ""; locTheme = ""; } @@ -1681,9 +1521,9 @@ namespace PckStudio contents.Dispose();//disposes temporary data saved = false; } - #endregion +#endregion - #region imports individual skin to pck +#region imports individual skin to pck private void importSkin(object sender, EventArgs e) { OpenFileDialog contents = new OpenFileDialog(); @@ -1699,7 +1539,7 @@ namespace PckStudio Import.Text = skinNameImport.Remove(skinNameImport.Length - 4, 4); //gets file name without extension byte[] data = File.ReadAllBytes(contents.FileName.Remove(contents.FileName.Length - 4, 4)); PCKFile.FileData mfNew = new PCKFile.FileData("no_name", 0); - mfNew.data = data;//sets minefile data to image data of current skin + mfNew.SetData(data); //sets minefile data to image data of current skin bool mashupStructure = false;//creates variable to indicate wether current pck skin structure is mashup or regular skin int skinsFolder = 0;//temporary index for skins folder for if structure is mashup @@ -1781,27 +1621,26 @@ namespace PckStudio //creates displayname id in loc file if (locNameId != "" && locName != "") { - LOC l; + LOCFile l; try { - l = new LOC(mfLoc.data); + using (var stream = new MemoryStream(mf.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { MessageBox.Show("No localization data found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - - displayId dis = new displayId(); - dis.id = locNameId; - dis.defaultName = locName; - - l.ids.names.Add(dis.id); - - foreach (LOC.Language lo in l.langs) - lo.names.Add(dis.defaultName); - mfLoc.data = l.Rebuild(); + l.AddEntry(locThemeId, locTheme); + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l); + mfLoc.SetData(stream.ToArray()); + } locNameId = ""; locName = ""; } @@ -1809,28 +1648,27 @@ namespace PckStudio //creates metadata id in loc file if (locThemeId != "" && locTheme != "") { - LOC l; + LOCFile l; try { - l = new LOC(mfLoc.data); + using (var stream = new MemoryStream(mf.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { MessageBox.Show("No localization data found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + l.AddEntry(locThemeId, locTheme); - displayId b = new displayId(); - b.id = locThemeId; - b.defaultName = locTheme; - - l.ids.names.Add(b.id); - - foreach (LOC.Language lo in l.langs) - lo.names.Add(b.defaultName); - - mfLoc.data = l.Rebuild(); + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l);//sets loc data + mfLoc.SetData(stream.ToArray()); + } locThemeId = ""; locTheme = ""; } @@ -1859,9 +1697,9 @@ namespace PckStudio contents.Dispose();//disposes temporary data saved = false; } - #endregion +#endregion - #region adds folder/directory entry to pck +#region adds folder/directory entry to pck private void folderToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode NEW = new TreeNode(); @@ -1878,44 +1716,43 @@ namespace PckStudio } saved = false; } - #endregion +#endregion - #region opens pck installation page +#region opens pck installation page private void installationToolStripMenuItem_Click(object sender, EventArgs e) { //System.Diagnostics.Process.Start(hosturl + "pckStudio#install"); } - #endregion +#endregion - #region opens pck binka tutorial video +#region opens pck binka tutorial video private void binkaConversionToolStripMenuItem_Click(object sender, EventArgs e) { System.Diagnostics.Process.Start("https://www.youtube.com/watch?v=v6EYr4zc7rI"); } - #endregion +#endregion - #region opens pck donation page +#region opens pck donation page private void donateToolStripMenuItem_Click(object sender, EventArgs e) { } - #endregion +#endregion - #region opens pck faq page +#region opens pck faq page private void fAQToolStripMenuItem1_Click(object sender, EventArgs e) { //System.Diagnostics.Process.Start(hosturl + "pckStudio#faq"); } - #endregion +#endregion - #region items class for use in bedrock skin conversion +#region converts and ports all skins in pck to mc bedrock format + // items class for use in bedrock skin conversion public class Item { public string Id { get; set; } public string Name { get; set; } } - #endregion - #region converts and ports all skins in pck to mc bedrock format private void convertToBedrockToolStripMenuItem_Click(object sender, EventArgs e) { if (openedPCKS.Visible == true && MessageBox.Show("Convert " + openedPCKS.SelectedTab.Text + " to a Bedrock Edition format?", "Convert", MessageBoxButtons.YesNo, MessageBoxIcon.None) == DialogResult.Yes) @@ -2910,9 +2747,9 @@ namespace PckStudio return destImage; } - #endregion +#endregion - #region 3ds feature in testing +#region 3ds feature in testing private struct loadedTexture { @@ -3148,9 +2985,9 @@ namespace PckStudio } } - #endregion +#endregion - #region Tool/MenuStrips +#region Tool/MenuStrips private void openToolStripMenuItem1_Click(object sender, EventArgs e) { @@ -3287,7 +3124,8 @@ namespace PckStudio private void buttonEditModel_Click(object sender, EventArgs e) { - PCKFile.FileData file = (PCKFile.FileData)treeViewMain.SelectedNode.Tag; + if (treeViewMain.SelectedNode.Tag == null || !(treeViewMain.SelectedNode.Tag is PCKFile.FileData)) return; + PCKFile.FileData file = treeViewMain.SelectedNode.Tag as PCKFile.FileData; if (Path.GetExtension(file.name) == ".png") { @@ -3355,12 +3193,15 @@ namespace PckStudio } } - if (Path.GetExtension(file.name) == ".loc") + if (file.type == 6) // .loc file { - LOC l; + LOCFile l; try { - l = new LOC(file.data); + using (var stream = new MemoryStream(file.data)) + { + l = LOCFileReader.Read(stream);//sets loc data + } } catch { @@ -3368,12 +3209,17 @@ namespace PckStudio MessageBoxIcon.Error); return; } - (new LOCEditor(l)).ShowDialog();//Opens LOC Editor - //mf.data = l.Rebuild();//Rebuilds loc file with locdata in grid view after closing dialog + var locEditor = new LOCEditor(l); //Opens LOC Editor + locEditor.ShowDialog(); + using (var stream = new MemoryStream()) + { + LOCFileWriter.Write(stream, l); + mf.SetData(stream.ToArray()); + } } //Checks to see if selected minefile is a col file - if (Path.GetExtension(file.name) == ".col") + if (file.type == 9) // .col file { //MessageBox.Show(".COL Editor Coming Soon!"); @@ -3408,26 +3254,26 @@ namespace PckStudio private void FormMain_FormClosed(object sender, FormClosedEventArgs e) { - if (saved == false) + if (!saved) { if (MessageBox.Show("Save PCK?", "Unsaved PCK", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { - if (saveLocation == appData + @"\templates\UntitledSkinPCK.pck") + if (isTemplateFile) { - save("Save As"); + save(); } else { - save("Save"); + save(); } } } if (needsUpdate) { - Process UPDATE = new Process();//sets up updater - UPDATE.StartInfo.FileName = appData + @"\nobleUpdater.exe";//updater program path - UPDATE.Start();//starts updater - Application.Exit();//closes PCK Studio to let updatear finish the job + Process UPDATE = new Process(); //sets up updater + UPDATE.StartInfo.FileName = appData + @"\nobleUpdater.exe"; //updater program path + UPDATE.Start(); //starts updater + Application.Exit(); //closes PCK Studio to let updatear finish the job } } @@ -3462,12 +3308,12 @@ namespace PckStudio private void savePCK(object sender, EventArgs e) { - save("Save"); + save(); } private void saveAsPCK(object sender, EventArgs e) { - save("Save As"); + save(); } private void timer1_Tick(object sender, EventArgs e) diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.cs index 0bd78d4a..f88d3d9b 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.cs @@ -53,15 +53,14 @@ namespace PckStudio { if (comboBox1.Text == "All") { - MessageBox.Show("TODO!!!!"); - //foreach (var node in treeMeta.Nodes) - //{ - // foreach (PCKFile.FileData mf in currentPCK.file_entries) - // { - // mf.properties.Add(node.Text, node.Tag); - // } - //} - //MessageBox.Show("Data Added to All Entries"); + foreach (TreeNode node in treeMeta.Nodes) + { + foreach (PCKFile.FileData mf in currentPCK.file_entries) + { + mf.properties.Add(new Tuple(node.Text, node.Tag.ToString())); + } + } + MessageBox.Show("Data Added to All Entries"); } else if (comboBox1.Text == "64x64") { @@ -76,7 +75,7 @@ namespace PckStudio { if (Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width) { - mf.properties.Add(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString()); + mf.properties.Add(new Tuple(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString())); } } } @@ -99,7 +98,7 @@ namespace PckStudio { if (Image.FromStream(png).Size.Height == Image.FromStream(png).Size.Width / 2) { - mf.properties.Add(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString()); + mf.properties.Add(new Tuple(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString() )); } } } @@ -119,7 +118,7 @@ namespace PckStudio { if (Path.GetExtension(mf.name) == ".png") { - mf.properties.Add(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString()); + mf.properties.Add(new Tuple(treeMeta.Nodes[i].Text, treeMeta.Nodes[i].Tag.ToString() )); } } i += 1; diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.ja.resx b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.ja.resx index 7242c973..df09d508 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.ja.resx +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.ja.resx @@ -121,7 +121,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x + vQAADr0BR/uQrQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC @@ -135,7 +135,7 @@ iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAACESURBVDhPlY0B + vQAADr0BR/uQrQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAACESURBVDhPlY0B DoAgDAP3Dj7r09WTkqGUgJfUxtrOmHFEnL0U76FBqW8PZXmk/9uONEsIb3gsNRzoL/+R5hWC759mGsbQ DnzdZbhmiSvhLsM1S1wJdxmuWeJKuMtwzRJXwl2Ga5a4Eu4yXLPElXCX4Zol/WCl6YGdI62n2Zv2cSXV byIunLh7mD2ySLcAAAAASUVORK5CYII= diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.resx b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.resx index 370d27a1..b8497017 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.resx +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/AdvancedOptions.resx @@ -117,13 +117,182 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + $this + + + + 141, 21 + + + $this + Apply to - + + label1 + + + 315, 283 + + + comboBox1 + + + comboBox2 + + + MetroFramework.Forms.MetroForm, MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a + + + 52, 212 + + + textBox1 + + + Add Entry + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vQAADr0BR/uQrQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAACESURBVDhPlY0B + DoAgDAP3Dj7r09WTkqGUgJfUxtrOmHFEnL0U76FBqW8PZXmk/9uONEsIb3gsNRzoL/+R5hWC759mGsbQ + DnzdZbhmiSvhLsM1S1wJdxmuWeJKuMtwzRJXwl2Ga5a4Eu4yXLPElXCX4Zol/WCl6YGdI62n2Zv2cSXV + byIunLh7mD2ySLcAAAAASUVORK5CYII= + + + + Advanced + + + Delete Entry + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Popup + + + label2 + + + CenterParent + + + $this + + + 1 + + + + True + + 2 - + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 64x32 + + + 57, 13 + + + Entry Data + + + 208, 212 + + + $this + + + 11 + + + 5 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO + vQAADr0BR/uQrQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x + DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 + jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC + + + + $this + + + 45, 13 + + + 138, 48 + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + addEntryToolStripMenuItem + + + button1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.TreeView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 20, 259 + + + deleteEntryToolStripMenuItem + + + 58, 13 + + + Apply + + + 7 + + + 75, 23 + + + All + + + 3 + + + 0 + + + 1 + + + 3 + AAABAAYAEBAAAAEAIABoBAAAZgAAACAgAAABACAAqBAAAM4EAAAwMAAAAQAgAKglAAB2FQAAQEAAAAEA @@ -1849,273 +2018,104 @@ AABJRU5ErkJggg== - - comboBox1 - 164, 228 - - 8 - - - $this - - - 5 - - - - Popup - - - Apply - - - label1 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAABSSURBVDhP5c0x - DsAgDENRxt7/wmkNSpRGf0CCCZAegxNMM7MlGMp3dIU6dxhKf/QMNxRogeQC8ivw5Vn7C0heJlFA+kL5 - jWAohxRkde4wnGftBS90axNmphIGAAAAAElFTkSuQmCC - - - - 58, 13 - - - deleteEntryToolStripMenuItem - - - 6, 13 - - - label3 - - - - True - - - CenterParent - - - $this - - - $this - - - 52, 212 - - - 6 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 75, 23 - - - 2 - - - 12 - - - 45, 13 - - - 139, 20 - - - System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 4 - - - 12, 227 - - - 1 - - - 7 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 141, 21 - - - 228, 254 - - - 1 - - - 137, 22 - - - 57, 13 - - - $this - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - textBox1 - - - 3 - - - 138, 48 - - - treeMeta - - - Add Entry - - - contextMenuStrip2 - - - Entry Type - - - Delete Entry - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - comboBox2 - - - 82, 21 - - - 291, 142 - - - $this - - - PNG Files - - - button1 - - - True - - - 0 - 71, 256 - + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 12, 227 + + + 6, 13 + + + 6 + + + 228, 254 + + + 12 + + + Entry Type + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 4 + + + 139, 20 + + + $this + + True - - label2 + + contextMenuStrip2 - - 9 - - - - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO - vgAADr4B6kKxwAAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xMkMEa+wAAACESURBVDhPlY0B - DoAgDAP3Dj7r09WTkqGUgJfUxtrOmHFEnL0U76FBqW8PZXmk/9uONEsIb3gsNRzoL/+R5hWC759mGsbQ - DnzdZbhmiSvhLsM1S1wJdxmuWeJKuMtwzRJXwl2Ga5a4Eu4yXLPElXCX4Zol/WCl6YGdI62n2Zv2cSXV - byIunLh7mD2ySLcAAAAASUVORK5CYII= - - - - 64x32 + + 291, 142 AdvancedOptions - - 20, 259 + + 137, 22 - - Advanced + + 2 137, 22 - - Entry Data + + 64x64 - - 11 + + True - - 3 + + $this - - 208, 212 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + treeMeta 10 - - $this + + PNG Files - - All + + label3 - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - addEntryToolStripMenuItem - - - $this - - - 315, 283 - - - MetroFramework.Forms.MetroForm, MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a - - - System.Windows.Forms.TreeView, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 8 12, 63 - - 64x64 + + $this - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 9 + + + 82, 21 True @@ -2123,7 +2123,4 @@ 17, 17 - - ja - \ No newline at end of file diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/EntryEditor.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/EntryEditor.cs index a26b18d8..4dfd134d 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/EntryEditor.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/EntryEditor.cs @@ -35,7 +35,7 @@ namespace PckStudio foreach (var entry in file.properties) { - TreeNode meta = new TreeNode(entry.Key); + TreeNode meta = new TreeNode(entry.Item1); meta.Tag = entry; treeView1.Nodes.Add(meta); @@ -70,7 +70,7 @@ namespace PckStudio private void addEntryToolStripMenuItem_Click(object sender, EventArgs e) { - file.properties.Add("Replace me", "Or it won't save"); + file.properties.Add(new Tuple("Replace me", "Or it won't save")); TreeNode t = new TreeNode("temp name"); treeView1.Nodes.Add(t); renameProperly(); @@ -82,7 +82,7 @@ namespace PckStudio if (treeView1.SelectedNode != null) { var temp = (string)treeView1.SelectedNode.Tag; - file.properties.Remove(temp); + //file.properties.Remove(temp); treeView1.Nodes.Remove(treeView1.SelectedNode); } } diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMeta.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMeta.cs index 8d9486cb..162e9f18 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMeta.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMeta.cs @@ -24,7 +24,7 @@ namespace PckStudio private void button1_Click(object sender, EventArgs e) { - file.properties.Add(textBox1.Text, textBox2.Text); + file.properties.Add(new Tuple(textBox1.Text, textBox2.Text )); Close(); } } diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMetaAdvanced.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMetaAdvanced.cs index d4c1544a..4060fae9 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMetaAdvanced.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addMetaAdvanced.cs @@ -29,7 +29,7 @@ namespace PckStudio add.Tag = textBox2.Text; treeMeta.Nodes.Add(add); - this.Close(); + Close(); } private void addMetaAdvanced_Load(object sender, EventArgs e) diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addnewskin.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addnewskin.cs index 2e13fb4c..009e99b4 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/addnewskin.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/addnewskin.cs @@ -20,7 +20,7 @@ namespace PckStudio { PCKFile currentPCK; DataTable tbl; - LOC currentLoc; + LOCFile currentLoc; PCKFile.FileData mf = null; PCKFile.FileData mfc = null; TreeView treeView1; @@ -44,12 +44,12 @@ namespace PckStudio string skinid; List generatedModel = new List(); - public addnewskin(PCKFile currentPCKIn, TreeView treeView1In, string tempIDIn, LOC loc) + public addnewskin(PCKFile currentPCKIn, TreeView treeView1In, string tempIDIn, LOCFile loc) { InitializeComponent(); - mf = new PCKFile.FileData(0); - mfc = new PCKFile.FileData(0); + mf = new PCKFile.FileData("", 0); + mfc = new PCKFile.FileData("", 0); currentLoc = loc; tbl = new DataTable(); tbl.Columns.Add(new DataColumn("Language") { ReadOnly = true }); @@ -149,7 +149,7 @@ namespace PckStudio buttonDone.Enabled = true; labelSelectTexture.Visible = false; - mf.data = File.ReadAllBytes(ofd); + mf.SetData(File.ReadAllBytes(ofd)); } public class displayId @@ -297,7 +297,7 @@ namespace PckStudio pictureBoxWithInterpolationMode1.InterpolationMode = InterpolationMode.NearestNeighbor; pictureBoxWithInterpolationMode1.Image = Image.FromFile(ofd1.FileName); - mfc.data = File.ReadAllBytes(ofd1.FileName); + mfc.SetData(File.ReadAllBytes(ofd1.FileName)); contextMenuCape.Items[0].Text = "Replace"; } @@ -334,11 +334,11 @@ namespace PckStudio capePath.Text = "CAPEPATH"; capePath.Tag = "dlccape" + textSkinID.Text + ".png"; - mf.properties.Add(capePath.Text, capePath.Tag.ToString()); + mf.properties.Add(new Tuple(capePath.Text, capePath.Tag.ToString())); currentPCK.file_entries.Add(mfc); - mfc.size = mf.data.Length; if (mashupStructure == true) + if (mashupStructure == true) { mfc.name = "Skins/" + "dlccape" + textSkinID.Text + ".png"; } @@ -381,9 +381,9 @@ namespace PckStudio skinName.Tag = textSkinName.Text; anim.Text = "ANIM"; - mf.properties.Add(skinName.Text, textSkinName.Text); + mf.properties.Add(new Tuple(skinName.Text, textSkinName.Text)); - mf.properties.Add(displayNameId.Text, "IDS_dlcskin" + textSkinID.Text + "_DISPLAYNAME"); + mf.properties.Add(new Tuple(displayNameId.Text, "IDS_dlcskin" + textSkinID.Text + "_DISPLAYNAME" )); if (comboBoxSkinType.Text == "Default (64x32)") @@ -395,11 +395,11 @@ namespace PckStudio anim.Tag = "0x80000"; object[] ANIM = { anim.Text, anim.Tag }; - mf.properties.Add("ANIM", "0x80000"); + mf.properties.Add(new Tuple("ANIM", "0x80000")); } else if (comboBoxSkinType.Text == "Steve (64x64)" && skinType != "64x32") { - mf.properties.Add("ANIM", "0x40000"); + mf.properties.Add(new Tuple("ANIM", "0x40000")); } else if (comboBoxSkinType.Text == "Custom") { @@ -408,7 +408,7 @@ namespace PckStudio //{ // mf.properties.Add((object[])item); //} - mf.properties.Add("ANIM", "0x7ff5fc10"); + mf.properties.Add(new Tuple("ANIM", "0x7ff5fc10")); } if (generatedModel != null) { @@ -417,13 +417,12 @@ namespace PckStudio if (themeName.Tag.ToString() != "") { - mf.properties.Add(themeName.Text, themeName.Tag.ToString()); + mf.properties.Add(new Tuple(themeName.Text, themeName.Tag.ToString() )); } - mf.properties.Add("GAME_FLAGS", "0x18"); - mf.properties.Add("FREE", "1"); + mf.properties.Add(new Tuple("GAME_FLAGS", "0x18")); + mf.properties.Add(new Tuple("FREE", "1")); - mf.size = mf.data.Length; if (mashupStructure == true) { mf.name = "Skins/" + "dlcskin" + textSkinID.Text + ".png"; @@ -453,20 +452,20 @@ namespace PckStudio d.id = "IDS_dlcskin" + textSkinID.Text + "_DISPLAYNAME"; d.defaultName = textSkinName.Text; - currentLoc.ids.names.Add(d.id); + //currentLoc.ids.names.Add(d.id); - foreach (LOC.Language l in currentLoc.langs) - l.names.Add(d.defaultName); + //foreach (LOC.Language l in currentLoc.langs) + // l.names.Add(d.defaultName); displayId b = new displayId(); b.id = "IDS_dlcskin" + textSkinID.Text + "_THEMENAME"; b.defaultName = textThemeName.Text; - currentLoc.ids.names.Add(b.id); + //currentLoc.ids.names.Add(b.id); - foreach (LOC.Language l in currentLoc.langs) - l.names.Add(b.defaultName); - this.Close(); + //foreach (LOC.Language l in currentLoc.langs) + // l.names.Add(b.defaultName); + Close(); } else { @@ -559,7 +558,7 @@ namespace PckStudio skinType = "64x64"; } - mf.data = File.ReadAllBytes(ofd); + mf.SetData(File.ReadAllBytes(ofd)); } catch (Exception ex) { diff --git a/MinecraftUSkinEditor/Forms/Skins-And-Textures/generateModel.cs b/MinecraftUSkinEditor/Forms/Skins-And-Textures/generateModel.cs index 5af7a730..c16a3f26 100644 --- a/MinecraftUSkinEditor/Forms/Skins-And-Textures/generateModel.cs +++ b/MinecraftUSkinEditor/Forms/Skins-And-Textures/generateModel.cs @@ -29,9 +29,6 @@ namespace PckStudio bool autoTexture = true; - int textureW = 0; - int textureH = 0; - Color backgroundColor = Color.Black; ListViewItem selected; @@ -40,117 +37,87 @@ namespace PckStudio private void checkSelect() { //Deciphers wether to enable/disable things based on wether an item is selected or not - if (listViewBoxes.SelectedItems.Count != 0) + if (listViewBoxes.SelectedItems.Count != 0 && listViewBoxes.SelectedItems[0] != null) { - - selected = listViewBoxes.SelectedItems[0]; - if (selected == null) - { - this.textXc.Enabled = false; - this.textYc.Enabled = false; - this.textZc.Enabled = false; - this.textXf.Enabled = false; - this.textYf.Enabled = false; - this.textZf.Enabled = false; - this.textTextureX.Enabled = false; - this.textTextureY.Enabled = false; - this.buttonXcminus.Enabled = false; - this.buttonYcminus.Enabled = false; - this.buttonZcminus.Enabled = false; - this.buttonXcplus.Enabled = false; - this.buttonYcplus.Enabled = false; - this.buttonZcplus.Enabled = false; - this.buttonXfminus.Enabled = false; - this.buttonYfminus.Enabled = false; - this.buttonZfminus.Enabled = false; - this.buttonXfplus.Enabled = false; - this.buttonYfplus.Enabled = false; - this.buttonZfplus.Enabled = false; - } - else - { - this.textXc.Enabled = true; - this.textYc.Enabled = true; - this.textZc.Enabled = true; - this.textXf.Enabled = true; - this.textYf.Enabled = true; - this.textZf.Enabled = true; - this.textTextureX.Enabled = true; - this.textTextureY.Enabled = true; - this.buttonXcminus.Enabled = true; - this.buttonYcminus.Enabled = true; - this.buttonZcminus.Enabled = true; - this.buttonXcplus.Enabled = true; - this.buttonYcplus.Enabled = true; - this.buttonZcplus.Enabled = true; - this.buttonXfminus.Enabled = true; - this.buttonYfminus.Enabled = true; - this.buttonZfminus.Enabled = true; - this.buttonXfplus.Enabled = true; - this.buttonYfplus.Enabled = true; - this.buttonZfplus.Enabled = true; - comboParent.Enabled = true; - } - } - else - { - this.textXc.Enabled = false; - this.textYc.Enabled = false; - this.textZc.Enabled = false; - this.textXf.Enabled = false; - this.textYf.Enabled = false; - this.textZf.Enabled = false; - this.textTextureX.Enabled = false; - this.textTextureY.Enabled = false; - this.buttonXcminus.Enabled = false; - this.buttonYcminus.Enabled = false; - this.buttonZcminus.Enabled = false; - this.buttonXcplus.Enabled = false; - this.buttonYcplus.Enabled = false; - this.buttonZcplus.Enabled = false; - this.buttonXfminus.Enabled = false; - this.buttonYfminus.Enabled = false; - this.buttonZfminus.Enabled = false; - this.buttonXfplus.Enabled = false; - this.buttonYfplus.Enabled = false; - this.buttonZfplus.Enabled = false; - comboParent.Enabled = false; + textXc.Enabled = true; + textYc.Enabled = true; + textZc.Enabled = true; + textXf.Enabled = true; + textYf.Enabled = true; + textZf.Enabled = true; + textTextureX.Enabled = true; + textTextureY.Enabled = true; + buttonXcminus.Enabled = true; + buttonYcminus.Enabled = true; + buttonZcminus.Enabled = true; + buttonXcplus.Enabled = true; + buttonYcplus.Enabled = true; + buttonZcplus.Enabled = true; + buttonXfminus.Enabled = true; + buttonYfminus.Enabled = true; + buttonZfminus.Enabled = true; + buttonXfplus.Enabled = true; + buttonYfplus.Enabled = true; + buttonZfplus.Enabled = true; + comboParent.Enabled = true; + return; } + textXc.Enabled = false; + textYc.Enabled = false; + textZc.Enabled = false; + textXf.Enabled = false; + textYf.Enabled = false; + textZf.Enabled = false; + textTextureX.Enabled = false; + textTextureY.Enabled = false; + buttonXcminus.Enabled = false; + buttonYcminus.Enabled = false; + buttonZcminus.Enabled = false; + buttonXcplus.Enabled = false; + buttonYcplus.Enabled = false; + buttonZcplus.Enabled = false; + buttonXfminus.Enabled = false; + buttonYfminus.Enabled = false; + buttonZfminus.Enabled = false; + buttonXfplus.Enabled = false; + buttonYfplus.Enabled = false; + buttonZfplus.Enabled = false; + comboParent.Enabled = false; } //Initialization public generateModel(List boxesIn, PictureBox preview) { - this.InitializeComponent(); + InitializeComponent(); boxes = new List(); boxes = boxesIn; - this.skinPreview = preview; - this.direction = "front"; - this.bg = new Bitmap(this.displayBox.Image); - this.buttonIMPORT.Enabled = false; - this.buttonEXPORT.Enabled = false; - this.textXc.Enabled = false; - this.textYc.Enabled = false; - this.textZc.Enabled = false; - this.textXf.Enabled = false; - this.textYf.Enabled = false; - this.textZf.Enabled = false; - this.textTextureX.Enabled = false; - this.textTextureY.Enabled = false; - this.buttonXcminus.Enabled = false; - this.buttonYcminus.Enabled = false; - this.buttonZcminus.Enabled = false; - this.buttonXcplus.Enabled = false; - this.buttonYcplus.Enabled = false; - this.buttonZcplus.Enabled = false; - this.buttonXfminus.Enabled = false; - this.buttonYfminus.Enabled = false; - this.buttonZfminus.Enabled = false; - this.buttonXfplus.Enabled = false; - this.buttonYfplus.Enabled = false; - this.buttonZfplus.Enabled = false; - this.comboParent.Enabled = false; + skinPreview = preview; + direction = "front"; + bg = new Bitmap(this.displayBox.Image); + buttonIMPORT.Enabled = false; + buttonEXPORT.Enabled = false; + textXc.Enabled = false; + textYc.Enabled = false; + textZc.Enabled = false; + textXf.Enabled = false; + textYf.Enabled = false; + textZf.Enabled = false; + textTextureX.Enabled = false; + textTextureY.Enabled = false; + buttonXcminus.Enabled = false; + buttonYcminus.Enabled = false; + buttonZcminus.Enabled = false; + buttonXcplus.Enabled = false; + buttonYcplus.Enabled = false; + buttonZcplus.Enabled = false; + buttonXfminus.Enabled = false; + buttonYfminus.Enabled = false; + buttonZfminus.Enabled = false; + buttonXfplus.Enabled = false; + buttonYfplus.Enabled = false; + buttonZfplus.Enabled = false; + comboParent.Enabled = false; loadData(); } @@ -246,10 +213,7 @@ namespace PckStudio private void render() { //Disables template option if model parts exist - if (this.listViewBoxes.Items.Count == 0) - this.buttonTemplate.Enabled = true; - else - this.buttonTemplate.Enabled = false; + buttonTemplate.Enabled = listViewBoxes.Items.Count == 0; setZ(); //Organizes Z layers diff --git a/MinecraftUSkinEditor/Forms/Utilities/Animation/AnimationEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/Animation/AnimationEditor.cs index a26befe9..20707f75 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Animation/AnimationEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Animation/AnimationEditor.cs @@ -55,10 +55,9 @@ namespace PckStudio else { create = true; - PCKFile.FileData newMf = new PCKFile.FileData("", 2, 0); - newMf.properties.Add("ANIM", ""); - newMf.data = File.ReadAllBytes(createdFileName); - newMf.size = newMf.data.Length;//gets filesize for minefile + PCKFile.FileData newMf = new PCKFile.FileData("", 2); + newMf.properties.Add(new Tuple("ANIM", "")); + newMf.SetData(File.ReadAllBytes(createdFileName)); mf = newMf; Forms.Utilities.AnimationEditor.ChangeTile diag = new Forms.Utilities.AnimationEditor.ChangeTile(); diag.ShowDialog(this); @@ -74,9 +73,9 @@ namespace PckStudio foreach (var entry in mf.properties) //object = metadata entry(name:value) { - TreeNode meta = new TreeNode(); - strEntries.Add(entry.Value); - strEntryData.Add(entry.Value); + //TreeNode meta = new TreeNode(entry.Item1); + strEntries.Add(entry.Item2); + strEntryData.Add(entry.Item2); } //if (strEntries.Find(entry => entry == "ANIM") == null) throw new System.Exception("ANIM tag is missing. No animation code is present."); @@ -412,8 +411,7 @@ namespace PckStudio using (MemoryStream m = new MemoryStream()) { texture.Save(m, texture.RawFormat); - mf.data = m.ToArray(); - mf.size = mf.data.Length; + mf.SetData(m.ToArray()); } if (metroCheckBox2.Checked) @@ -430,9 +428,20 @@ namespace PckStudio Tuple frameData = node.Tag as Tuple; animationData += frameData.Item1 + "*" + frameData.Item2 + ","; } - animationData.TrimEnd(','); - if (mf.properties.ContainsKey("ANIM")) mf.properties["ANIM"] = animationData; - else mf.properties.Add("ANIM", animationData); + animationData.TrimEnd(','); + foreach (var pair in mf.properties) + { + if (pair.Item1 == "ANIM") + { + //pair.Item2 = animationData; // TODO + break; + } + else + { + mf.properties.Add(new Tuple("ANIM", animationData)); + break; + } + }; if (create) { diff --git a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs index 807496e8..d3b79caa 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/Audio/AudioEditor.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using MetroFramework.Forms; using PckStudio; using PckStudio.Classes.FileTypes; +using PckStudio.Classes.IO; // Audio Editor by MattNL @@ -19,7 +20,7 @@ namespace PckStudio.Forms.Utilities public partial class AudioEditor : MetroForm { public bool saved = false; - public string defaultType; + public string defaultType = "yes"; public string cat; public List cats = new List(); public List totalCats = new List(); @@ -91,14 +92,13 @@ namespace PckStudio.Forms.Utilities mf = MineFile; using (var stream = new MemoryStream(mf.data)) { - if (isVita) audioPCK = new PCKFile(stream, true); - else audioPCK = new PCKFile(stream); + audioPCK = PCKFileReader.Read(stream, isVita); } - defaultType = audioPCK.meta_data[0]; - if (!audioPCK.meta_data.ContainsValue("CUENAME")) + if (!audioPCK.meta_data.ContainsKey("CUENAME")) { throw new Exception("This is not a valid audio.pck file"); } + //defaultType = audioPCK.meta_data["CUENAME"]; int index = 0; List tempMineFiles = audioPCK.file_entries; foreach (PCKFile.FileData mineFile in tempMineFiles) @@ -131,19 +131,18 @@ namespace PckStudio.Forms.Utilities private void treeView2_AfterSelect(object sender, TreeViewEventArgs e) { - comboBox1.Items.Clear();//Resets metadata combobox of selectable entry names + comboBox1.Items.Clear(); //Resets metadata combobox of selectable entry names if (e.Node.Tag == null) return; var strings = (KeyValuePair)e.Node.Tag; - string type = audioPCK.meta_data[0]; - defaultType = type; - string value = ""; - type = (string)strings.Key; - value = (string)strings.Value; + //string type = audioPCK.meta_data[0]; + //defaultType = type; + //type = strings.Key; + string value = strings.Value; - foreach (int metaType in audioPCK.meta_data.Keys) - comboBox1.Items.Add(audioPCK.meta_data[metaType]);//fills combobox with metadata from the main metadatabase - comboBox1.Text = type;//Sets currently selected metadata type to type selected in selected metadata node + foreach (var metaType in audioPCK.meta_data) + comboBox1.Items.Add(metaType.Key); + comboBox1.Text = "TODO";//Sets currently selected metadata type to type selected in selected metadata node textBox1.Text = value;//Sets currently selected metadata value to value selected in selected metadata node } @@ -151,10 +150,10 @@ namespace PckStudio.Forms.Utilities { treeView2.Nodes.Clear(); PCKFile.FileData mineFile = (PCKFile.FileData)e.Node.Tag; - foreach (var entry in mineFile.properties) //object = metadata entry(name:value) + foreach (var entry in mineFile.properties) { TreeNode meta = new TreeNode(); - meta.Text = entry.Key; + meta.Text = entry.Item1; meta.Tag = entry; treeView2.Nodes.Add(meta); } @@ -193,9 +192,7 @@ namespace PckStudio.Forms.Utilities add.Dispose();//diposes generated metadata adding dialog data if (!cats.Contains(getCatID(cat))) cats.Add(getCatID(cat)); else return; - PCKFile.FileData mf = new PCKFile.FileData(cat, getCatID(cat), 0); //Creates new minefile template - mf.data = new byte[0]; //adds file data to minefile - + PCKFile.FileData mf = new PCKFile.FileData(cat, getCatID(cat)); //Creates new minefile template TreeNode addNode = new TreeNode(mf.name) { Tag = mf };//creates node for minefile //addNode.ImageIndex = mf.type; //addNode.SelectedImageIndex = mf.type; @@ -217,14 +214,14 @@ namespace PckStudio.Forms.Utilities TreeNode meta = new TreeNode("New Entry"); //meta.Tag = obj; treeView2.Nodes.Add(meta); - ((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Add(defaultType, "New Entry"); + //((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Add(defaultType, new List { "New Entry" }); } public void treeView2_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && treeView2.SelectedNode != null) { if (treeView1.SelectedNode == null) return; // makes sure you don't run this if there is nothing to delete - ((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Remove((string)treeView2.SelectedNode.Tag); + //((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Remove((string)treeView2.SelectedNode.Tag); treeView2.SelectedNode.Remove(); } } @@ -241,7 +238,7 @@ namespace PckStudio.Forms.Utilities PCKFile.FileData mineFile = (PCKFile.FileData)treeView1.SelectedNode.Tag; foreach (var entry in mineFile.properties) { - TreeNode meta = new TreeNode(entry.Key); + TreeNode meta = new TreeNode(entry.Item1); meta.Tag = entry; treeView2.Nodes.Add(meta); } @@ -270,40 +267,40 @@ namespace PckStudio.Forms.Utilities meta.Text = "CUENAME"; meta.Tag = obj; treeView2.Nodes.Add(meta); - ((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Add("CUENAME", System.IO.Path.GetFileNameWithoutExtension(binka)); - } + ((PCKFile.FileData)treeView1.SelectedNode.Tag).properties.Add(new Tuple("CUENAME", Path.GetFileNameWithoutExtension(binka))); + } } } } - private static void writeMinecraftString(FileOutput f, string str) - { - byte[] d = Encoding.BigEndianUnicode.GetBytes(str); - f.writeInt(d.Length / 2); - f.writeBytes(d); - f.writeInt(0); - } + //private static void writeMinecraftString(FileOutput f, string str) + //{ + // byte[] d = Encoding.BigEndianUnicode.GetBytes(str); + // f.writeInt(d.Length / 2); + // f.writeBytes(d); + // f.writeInt(0); + //} - private static void writeMinecraftStringVita(FileOutput f, string str) - { - Console.WriteLine("WriteVita -- " + str); - byte[] bytes = Encoding.Unicode.GetBytes(str); - f.writeIntVita(bytes.Length / 2); - f.writeBytes((bytes)); - f.writeIntVita(0); - } + //private static void writeMinecraftStringVita(FileOutput f, string str) + //{ + // Console.WriteLine("WriteVita -- " + str); + // byte[] bytes = Encoding.Unicode.GetBytes(str); + // f.writeIntVita(bytes.Length / 2); + // f.writeBytes((bytes)); + // f.writeIntVita(0); + //} - public static byte[] buildAudioPCKVita(PCKFile pck) - { - FileOutput fileOutput = new FileOutput(); - fileOutput.Endian = Endianness.Big; - fileOutput.writeIntVita(1); - fileOutput.writeIntVita(pck.meta_data.Count); - foreach (int num in pck.meta_data.Keys) - { - fileOutput.writeIntVita(num); - writeMinecraftStringVita(fileOutput, pck.meta_data[num]); - } + //public static byte[] buildAudioPCKVita(PCKFile pck) + //{ + // FileOutput fileOutput = new FileOutput(); + // fileOutput.Endian = Endianness.Big; + // fileOutput.writeIntVita(1); + // fileOutput.writeIntVita(pck.meta_data.Count); + //foreach (int num in pck.meta_data.Keys) + //{ + // fileOutput.writeIntVita(num); + // writeMinecraftStringVita(fileOutput, pck.meta_data[num]); + //} //fileOutput.writeIntVita(PCKFile.FileDatas.Count); //foreach (PCKFile.FileData mineFile in PCKFile.FileDatas) //{ @@ -332,21 +329,21 @@ namespace PckStudio.Forms.Utilities // break; // } //} - return fileOutput.getBytes(); - } + // return fileOutput.getBytes(); + //} public static byte[] buildAudioPCK(PCKFile pck) { - FileOutput f = new FileOutput(); - f.Endian = pck.isLittleEndian ? Endianness.Little : Endianness.Big; + //FileOutput f = new FileOutput(); + //f.Endian = pck.isLittleEndian ? Endianness.Little : Endianness.Big; - f.writeInt(1); - f.writeInt(pck.meta_data.Count); - foreach (int type in pck.meta_data.Keys) - { - f.writeInt(type); - writeMinecraftString(f, pck.meta_data[type]); - } + //f.writeInt(1); + //f.writeInt(pck.meta_data.Count); + //foreach (int type in pck.meta_data.Keys) + //{ + // f.writeInt(type); + // writeMinecraftString(f, pck.meta_data[type]); + //} //f.writeInt(PCKFile.FileDatas.Count); //Console.WriteLine(PCKFile.FileDatas.Count); @@ -379,7 +376,8 @@ namespace PckStudio.Forms.Utilities // break; // } //} - return f.getBytes(); + //return f.getBytes(); + return new byte[0]; } private void saveToolStripMenuItem1_Click(object sender, EventArgs e) diff --git a/MinecraftUSkinEditor/Forms/Utilities/COLEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Utilities/COLEditor.Designer.cs index 9c0ca1a1..b244a771 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/COLEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/COLEditor.Designer.cs @@ -1,4 +1,6 @@  +using System.Windows.Forms; + namespace PckStudio.Forms.Utilities { partial class COLEditor @@ -247,6 +249,14 @@ namespace PckStudio.Forms.Utilities this.waterTab.BackColor = System.Drawing.SystemColors.WindowFrame; resources.ApplyResources(this.waterTab, "waterTab"); this.waterTab.Name = "waterTab"; + //this.treeView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); + //this.treeView1.ForeColor = System.Drawing.Color.White; + //this.treeView1.LabelEdit = false; + //this.treeView1.LineColor = System.Drawing.Color.White; + //this.treeView1.Name = "treeView1"; + //this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect); + //this.treeView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeViews_KeyDown); + //this.treeView1.Dock = DockStyle.Fill; // // COLEditor // diff --git a/MinecraftUSkinEditor/Forms/Utilities/COLEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/COLEditor.cs index 7d6b852f..8a5a6ea7 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/COLEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/COLEditor.cs @@ -3,68 +3,47 @@ using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using MetroFramework.Forms; -using PckStudio; using PckStudio.Classes.FileTypes; namespace PckStudio.Forms.Utilities { public partial class COLEditor : MetroForm { - Classes.COL.COLFile cf = new Classes.COL.COLFile(); + COLFile cf = new COLFile(); PCKFile.FileData mf; TreeView treeView1 = new TreeView(); // Normal Color Table TreeView treeView2 = new TreeView(); // Water Color Table - public COLEditor(byte[] data, PCKFile.FileData MineFile) + public COLEditor(PCKFile.FileData MineFile) { InitializeComponent(); metroLabel6.Visible = false; numericUpDown2.Visible = false; - cf.Open(data); mf = MineFile; - - #region TreeView Controls Setup - - treeView1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - treeView1.ForeColor = System.Drawing.Color.White; - treeView1.LabelEdit = false; - treeView1.LineColor = System.Drawing.Color.White; - treeView1.Name = "treeView1"; - treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect); - treeView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeViews_KeyDown); - treeView1.Dock = DockStyle.Fill; - - treeView2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64))))); - treeView2.ForeColor = System.Drawing.Color.White; - treeView2.LabelEdit = false; - treeView2.LineColor = System.Drawing.Color.White; - treeView2.Name = "treeView2"; - treeView2.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViews_AfterSelect); - treeView2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeViews_KeyDown); - treeView2.Dock = DockStyle.Fill; - - #endregion + using (var stream = new MemoryStream(mf.data)) + { + cf.Open(stream); + } colorsTab.Controls.Add(treeView1); waterTab.Controls.Add(treeView2); tabControl.TabStop = true; - foreach (object[] obj in cf.entries) + foreach (var obj in cf.entries) { - TreeNode tn = new TreeNode(); - tn.Text = obj[0].ToString(); - tn.Tag = obj[1].ToString(); + TreeNode tn = new TreeNode(obj.name); + tn.Tag = obj.color; treeView1.Nodes.Add(tn); } - foreach (object[] obj in cf.waterEntries) + foreach (var obj in cf.waterEntries) { - TreeNode tn = new TreeNode(); - tn.Text = obj[0].ToString(); - tn.Tag = obj[1].ToString(); + TreeNode tn = new TreeNode(obj.name); + tn.Tag = obj.color; treeView2.Nodes.Add(tn); } } @@ -102,13 +81,17 @@ namespace PckStudio.Forms.Utilities cf.waterEntries.Clear(); foreach (TreeNode tn in treeView1.Nodes) { - cf.entries.Add(new object[] {tn.Text, tn.Tag.ToString() }); + cf.entries.Add(new COLFile.COLEntry(){ name = tn.Text, color = (uint)tn.Tag }); } foreach (TreeNode tn in treeView2.Nodes) { - cf.waterEntries.Add(new object[] { tn.Text, tn.Tag.ToString() }); + cf.waterEntries.Add(new COLFile.COLEntry() { name = tn.Text, color = (uint)tn.Tag }); + } + using (var stream = new MemoryStream()) + { + cf.Save(stream); + mf.SetData(stream.ToArray()); } - mf.data = cf.Save(); } static byte[] StringToByteArrayFastest(string hex) diff --git a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.Designer.cs b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.Designer.cs index a855eb96..24f745f6 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.Designer.cs @@ -28,104 +28,104 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LOCEditor)); - this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.addDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.renameDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.locSort = new PckStudio.Forms.MyTablePanel(); - this.buttonReplaceAll = new System.Windows.Forms.Button(); - this.dataGridViewLocEntryData = new System.Windows.Forms.DataGridView(); - this.textBoxReplaceAll = new System.Windows.Forms.TextBox(); - this.treeViewLocEntries = new System.Windows.Forms.TreeView(); - this.contextMenuStrip1.SuspendLayout(); - this.locSort.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLocEntryData)).BeginInit(); - this.SuspendLayout(); - // - // contextMenuStrip1 - // - this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.components = new System.ComponentModel.Container(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LOCEditor)); + this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); + this.addDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.renameDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteDisplayIDToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.locSort = new PckStudio.Forms.MyTablePanel(); + this.buttonReplaceAll = new System.Windows.Forms.Button(); + this.dataGridViewLocEntryData = new System.Windows.Forms.DataGridView(); + this.textBoxReplaceAll = new System.Windows.Forms.TextBox(); + this.treeViewLocEntries = new System.Windows.Forms.TreeView(); + this.contextMenuStrip1.SuspendLayout(); + this.locSort.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLocEntryData)).BeginInit(); + this.SuspendLayout(); + // + // contextMenuStrip1 + // + this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.addDisplayIDToolStripMenuItem, this.renameDisplayIDToolStripMenuItem, this.deleteDisplayIDToolStripMenuItem}); - this.contextMenuStrip1.Name = "contextMenuStrip1"; - resources.ApplyResources(this.contextMenuStrip1, "contextMenuStrip1"); - // - // addDisplayIDToolStripMenuItem - // - this.addDisplayIDToolStripMenuItem.Name = "addDisplayIDToolStripMenuItem"; - resources.ApplyResources(this.addDisplayIDToolStripMenuItem, "addDisplayIDToolStripMenuItem"); - this.addDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.addDisplayIDToolStripMenuItem_Click); - // - // renameDisplayIDToolStripMenuItem - // - this.renameDisplayIDToolStripMenuItem.Name = "renameDisplayIDToolStripMenuItem"; - resources.ApplyResources(this.renameDisplayIDToolStripMenuItem, "renameDisplayIDToolStripMenuItem"); - this.renameDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.renameDisplayIDToolStripMenuItem_Click); - // - // deleteDisplayIDToolStripMenuItem - // - this.deleteDisplayIDToolStripMenuItem.Name = "deleteDisplayIDToolStripMenuItem"; - resources.ApplyResources(this.deleteDisplayIDToolStripMenuItem, "deleteDisplayIDToolStripMenuItem"); - this.deleteDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.deleteDisplayIDToolStripMenuItem_Click); - // - // locSort - // - this.locSort.AccessibleRole = System.Windows.Forms.AccessibleRole.Table; - resources.ApplyResources(this.locSort, "locSort"); - this.locSort.Controls.Add(this.buttonReplaceAll, 2, 0); - this.locSort.Controls.Add(this.dataGridViewLocEntryData, 1, 1); - this.locSort.Controls.Add(this.textBoxReplaceAll, 1, 0); - this.locSort.Controls.Add(this.treeViewLocEntries, 0, 0); - this.locSort.Name = "locSort"; - // - // buttonReplaceAll - // - resources.ApplyResources(this.buttonReplaceAll, "buttonReplaceAll"); - this.buttonReplaceAll.ForeColor = System.Drawing.Color.White; - this.buttonReplaceAll.Name = "buttonReplaceAll"; - this.buttonReplaceAll.UseVisualStyleBackColor = true; - this.buttonReplaceAll.Click += new System.EventHandler(this.buttonReplaceAll_Click); - // - // dataGridViewLocEntryData - // - this.dataGridViewLocEntryData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.locSort.SetColumnSpan(this.dataGridViewLocEntryData, 2); - resources.ApplyResources(this.dataGridViewLocEntryData, "dataGridViewLocEntryData"); - this.dataGridViewLocEntryData.Name = "dataGridViewLocEntryData"; - this.dataGridViewLocEntryData.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit); - // - // textBoxReplaceAll - // - resources.ApplyResources(this.textBoxReplaceAll, "textBoxReplaceAll"); - this.textBoxReplaceAll.Name = "textBoxReplaceAll"; - // - // treeViewLocEntries - // - this.treeViewLocEntries.ContextMenuStrip = this.contextMenuStrip1; - resources.ApplyResources(this.treeViewLocEntries, "treeViewLocEntries"); - this.treeViewLocEntries.LabelEdit = true; - this.treeViewLocEntries.Name = "treeViewLocEntries"; - this.locSort.SetRowSpan(this.treeViewLocEntries, 2); - this.treeViewLocEntries.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); - this.treeViewLocEntries.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown); - // - // LOCEditor - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.locSort); - this.Name = "LOCEditor"; - this.Style = MetroFramework.MetroColorStyle.Silver; - this.Theme = MetroFramework.MetroThemeStyle.Dark; - this.Load += new System.EventHandler(this.LOCEditor_Load); - this.contextMenuStrip1.ResumeLayout(false); - this.locSort.ResumeLayout(false); - this.locSort.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLocEntryData)).EndInit(); - this.ResumeLayout(false); + this.contextMenuStrip1.Name = "contextMenuStrip1"; + resources.ApplyResources(this.contextMenuStrip1, "contextMenuStrip1"); + // + // addDisplayIDToolStripMenuItem + // + this.addDisplayIDToolStripMenuItem.Name = "addDisplayIDToolStripMenuItem"; + resources.ApplyResources(this.addDisplayIDToolStripMenuItem, "addDisplayIDToolStripMenuItem"); + this.addDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.addDisplayIDToolStripMenuItem_Click); + // + // renameDisplayIDToolStripMenuItem + // + this.renameDisplayIDToolStripMenuItem.Name = "renameDisplayIDToolStripMenuItem"; + resources.ApplyResources(this.renameDisplayIDToolStripMenuItem, "renameDisplayIDToolStripMenuItem"); + this.renameDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.renameDisplayIDToolStripMenuItem_Click); + // + // deleteDisplayIDToolStripMenuItem + // + this.deleteDisplayIDToolStripMenuItem.Name = "deleteDisplayIDToolStripMenuItem"; + resources.ApplyResources(this.deleteDisplayIDToolStripMenuItem, "deleteDisplayIDToolStripMenuItem"); + this.deleteDisplayIDToolStripMenuItem.Click += new System.EventHandler(this.deleteDisplayIDToolStripMenuItem_Click); + // + // locSort + // + this.locSort.AccessibleRole = System.Windows.Forms.AccessibleRole.Table; + resources.ApplyResources(this.locSort, "locSort"); + this.locSort.Controls.Add(this.buttonReplaceAll, 2, 0); + this.locSort.Controls.Add(this.dataGridViewLocEntryData, 1, 1); + this.locSort.Controls.Add(this.textBoxReplaceAll, 1, 0); + this.locSort.Controls.Add(this.treeViewLocEntries, 0, 0); + this.locSort.Name = "locSort"; + // + // buttonReplaceAll + // + resources.ApplyResources(this.buttonReplaceAll, "buttonReplaceAll"); + this.buttonReplaceAll.ForeColor = System.Drawing.Color.White; + this.buttonReplaceAll.Name = "buttonReplaceAll"; + this.buttonReplaceAll.UseVisualStyleBackColor = true; + this.buttonReplaceAll.Click += new System.EventHandler(this.buttonReplaceAll_Click); + // + // dataGridViewLocEntryData + // + this.dataGridViewLocEntryData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.locSort.SetColumnSpan(this.dataGridViewLocEntryData, 2); + resources.ApplyResources(this.dataGridViewLocEntryData, "dataGridViewLocEntryData"); + this.dataGridViewLocEntryData.Name = "dataGridViewLocEntryData"; + this.dataGridViewLocEntryData.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellEndEdit); + // + // textBoxReplaceAll + // + resources.ApplyResources(this.textBoxReplaceAll, "textBoxReplaceAll"); + this.textBoxReplaceAll.Name = "textBoxReplaceAll"; + // + // treeViewLocEntries + // + this.treeViewLocEntries.ContextMenuStrip = this.contextMenuStrip1; + resources.ApplyResources(this.treeViewLocEntries, "treeViewLocEntries"); + this.treeViewLocEntries.LabelEdit = true; + this.treeViewLocEntries.Name = "treeViewLocEntries"; + this.locSort.SetRowSpan(this.treeViewLocEntries, 2); + this.treeViewLocEntries.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect); + this.treeViewLocEntries.KeyDown += new System.Windows.Forms.KeyEventHandler(this.treeView1_KeyDown); + // + // LOCEditor + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.locSort); + this.Name = "LOCEditor"; + this.Style = MetroFramework.MetroColorStyle.Silver; + this.Theme = MetroFramework.MetroThemeStyle.Dark; + this.Load += new System.EventHandler(this.LOCEditor_Load); + this.contextMenuStrip1.ResumeLayout(false); + this.locSort.ResumeLayout(false); + this.locSort.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLocEntryData)).EndInit(); + this.ResumeLayout(false); } @@ -140,5 +140,5 @@ private PckStudio.Forms.MyTablePanel locSort; private System.Windows.Forms.Button buttonReplaceAll; private System.Windows.Forms.ToolStripMenuItem renameDisplayIDToolStripMenuItem; - } + } } \ No newline at end of file diff --git a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.cs b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.cs index 66db3f70..a09dc6ad 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.cs @@ -1,4 +1,5 @@ -using System; +using PckStudio.Classes.FileTypes; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,151 +13,124 @@ namespace PckStudio { public partial class LOCEditor : MetroFramework.Forms.MetroForm { - #region Variables - DataTable tbl; - LOC currentLoc; + DataTable tbl = new DataTable(); + LOCFile currentLoc; - public class displayId - { - public string id; - public string defaultName; - } - #endregion - public LOCEditor(LOC loc) + public LOCEditor(LOCFile loc) { InitializeComponent(); - - tbl = new DataTable(); currentLoc = loc; tbl.Columns.Add(new DataColumn("Language") { ReadOnly = true }); tbl.Columns.Add("Display Name"); dataGridViewLocEntryData.DataSource = tbl; DataGridViewColumn column = dataGridViewLocEntryData.Columns[1]; column.Width = 600; - } private void LOCEditor_Load(object sender, EventArgs e) { - foreach(string id in currentLoc.ids.names) + foreach(string id in currentLoc.languages.Keys) treeViewLocEntries.Nodes.Add(id); } private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { tbl.Rows.Clear(); - - foreach (LOC.Language l in currentLoc.langs) + if (treeViewLocEntries.SelectedNode == null || + !currentLoc.languages.ContainsKey(treeViewLocEntries.SelectedNode.Text)) { - string utf8str = l.names[e.Node.Index]; - - byte[] utf8Data = new byte[utf8str.Length]; - for (int i = 0; i < utf8str.Length; ++i) - { - utf8Data[i] = (byte)utf8str[i]; - } - - tbl.Rows.Add(l.name, Encoding.UTF8.GetString(utf8Data, 0, utf8Data.Length)); + MessageBox.Show("Selected Node does not seem to be in the loc file"); + return; } - - try + buttonReplaceAll.Enabled = true; + foreach (var l in currentLoc.languages[treeViewLocEntries.SelectedNode.Text]) { - if (treeViewLocEntries.SelectedNode != null) - { - buttonReplaceAll.Enabled = true; - } - else - { - buttonReplaceAll.Enabled = false; - } - }catch (Exception) - { - buttonReplaceAll.Enabled = false; + tbl.Rows.Add(l.Key, l.Value); } } private void renameDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode node = treeViewLocEntries.SelectedNode; - int index = currentLoc.ids.names.FindIndex(name => name == node.Text); - PckStudio.renameLoc diag = new PckStudio.renameLoc(node); + renameLoc diag = new renameLoc(node.Text); diag.ShowDialog(this); + if (diag.DialogResult == DialogResult.OK) + currentLoc.ChangeEntry("TODO", diag.NewText); diag.Dispose(); //diposes generated metadata adding dialog data - currentLoc.ids.names[index] = node.Text; } private void addDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { - int index = treeViewLocEntries.SelectedNode.Index; + MessageBox.Show("TODO"); + //int index = treeViewLocEntries.SelectedNode.Index; - if(index == -1) index = currentLoc.ids.names.Count; + //if(index == -1) index = currentLoc.ids.names.Count; - currentLoc.ids.names.Insert(index, "NewItem"); + //currentLoc.ids.names.Insert(index, "NewItem"); - foreach (LOC.Language l in currentLoc.langs) - l.names.Insert(index, "NewString"); + //foreach (LOCFile.Language l in currentLoc.langs) + // l.names.Insert(index, "NewString"); - treeViewLocEntries.Nodes.Insert(index, "NewItem"); + //treeViewLocEntries.Nodes.Insert(index, "NewItem"); } private void deleteDisplayIDToolStripMenuItem_Click(object sender, EventArgs e) { if(treeViewLocEntries.SelectedNode != null) { - int index = treeViewLocEntries.SelectedNode.Index; + MessageBox.Show("TODO"); + //int index = treeViewLocEntries.SelectedNode.Index; - currentLoc.ids.names.RemoveAt(index); + //currentLoc.ids.names.RemoveAt(index); - foreach (LOC.Language l in currentLoc.langs) - l.names.RemoveAt(index); + //foreach (LOCFile.Language l in currentLoc.langs) + // l.names.RemoveAt(index); - treeViewLocEntries.Nodes.RemoveAt(index); + //treeViewLocEntries.Nodes.RemoveAt(index); } } private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { - for (int i = 0; i < tbl.Rows.Count; i++) - { - byte[] data = Encoding.UTF8.GetBytes((string)tbl.Rows[i][1]); + MessageBox.Show("TODO"); + //for (int i = 0; i < tbl.Rows.Count; i++) + //{ + // byte[] data = Encoding.UTF8.GetBytes((string)tbl.Rows[i][1]); - string final = string.Empty; + // string final = string.Empty; - foreach (byte b in data) - final += (Char)b; + // foreach (byte b in data) + // final += (char)b; - currentLoc.langs[i].names[treeViewLocEntries.SelectedNode.Index] = final; - } + // currentLoc.langs[i].names[treeViewLocEntries.SelectedNode.Index] = final; + //} } private void treeView1_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyData == Keys.Delete) //checks to make sure pressed key was del + if (e.KeyData == Keys.Delete && treeViewLocEntries.SelectedNode != null) //checks to make sure pressed key was del { - if (treeViewLocEntries.SelectedNode != null) - { - int index = treeViewLocEntries.SelectedNode.Index; + int index = treeViewLocEntries.SelectedNode.Index; + MessageBox.Show("TODO"); + //currentLoc.languages..RemoveAt(index); - currentLoc.ids.names.RemoveAt(index); - - foreach (LOC.Language l in currentLoc.langs) - l.names.RemoveAt(index); - - treeViewLocEntries.Nodes.RemoveAt(index); - } + //foreach (var l in currentLoc.languages) + // l.names.RemoveAt(index); + //treeViewLocEntries.Nodes.RemoveAt(index); } } private void buttonReplaceAll_Click(object sender, EventArgs e) { - for (int i = 0; i < tbl.Rows.Count; i++) - { - tbl.Rows[i][1] = textBoxReplaceAll.Text; - } - for (int i = 0; i < tbl.Rows.Count; i++) - { - currentLoc.langs[i].names[treeViewLocEntries.SelectedNode.Index] = (string)tbl.Rows[i][1]; - } + MessageBox.Show("TODO"); + //for (int i = 0; i < tbl.Rows.Count; i++) + //{ + // tbl.Rows[i][1] = ; + //} + //for (int i = 0; i < tbl.Rows.Count; i++) + //{ + // currentLoc.langs[i].names[treeViewLocEntries.SelectedNode.Index] = (string)tbl.Rows[i][1]; + //} } private void contextMenuStrip1_Opening(object sender, CancelEventArgs e) diff --git a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.resx b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.resx index 53825b3a..46cceab9 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.resx +++ b/MinecraftUSkinEditor/Forms/Utilities/LOCEditor.resx @@ -283,7 +283,7 @@ 1 - <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="buttonReplaceAll" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="dataGridViewLocEntryData" Row="1" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="textBoxReplaceAll" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="treeViewLocEntries" Row="0" RowSpan="2" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Absolute,300,Percent,100,AutoSize,0" /><Rows Styles="AutoSize,0,Percent,100" /></TableLayoutSettings> + <?xml version="1.0" encoding="utf-16"?><TableLayoutSettings><Controls><Control Name="buttonReplaceAll" Row="0" RowSpan="1" Column="2" ColumnSpan="1" /><Control Name="dataGridViewLocEntryData" Row="1" RowSpan="1" Column="1" ColumnSpan="2" /><Control Name="textBoxReplaceAll" Row="0" RowSpan="1" Column="1" ColumnSpan="1" /><Control Name="treeViewLocEntries" Row="0" RowSpan="2" Column="0" ColumnSpan="1" /></Controls><Columns Styles="Absolute,300,Percent,100,AutoSize,0" /><Rows Styles="AutoSize,0,Percent,100,Absolute,20" /></TableLayoutSettings> True diff --git a/MinecraftUSkinEditor/Forms/Utilities/pckCenterOpen.cs b/MinecraftUSkinEditor/Forms/Utilities/pckCenterOpen.cs index 9ea92902..caeb50e4 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/pckCenterOpen.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/pckCenterOpen.cs @@ -17,6 +17,7 @@ using PckStudio; using System.IO.Compression; using static PckStudio.FormMain; using PckStudio.Classes.FileTypes; +using PckStudio.Classes.IO; namespace PckStudio.Forms { @@ -139,7 +140,7 @@ namespace PckStudio.Forms PCKFile pck = null; using (var stream = File.OpenRead(appData + "/PCK Center/myPcks/" + mod + ".pck")) { - pck = new PCKFile(stream); //sets opened pck + pck = PCKFileReader.Read(stream, false); //sets opened pck } PCKFile currentPCK = pck; //sets opened pck foreach (PCKFile.FileData skin in currentPCK.file_entries) @@ -185,15 +186,15 @@ namespace PckStudio.Forms foreach (var entry in newSkin.properties) { - if (entry.Key.ToString() == "DISPLAYNAME") + if (entry.Item1 == "DISPLAYNAME") { - skinName = entry.Value.ToString(); - skinDisplayNames.Add(new Item() { Id = newSkin.name.Remove(15, 4), Name = entry.Value.ToString() }); + skinName = entry.Item2; + skinDisplayNames.Add(new Item() { Id = newSkin.name.Remove(15, 4), Name = entry.Item2 }); } - if (entry.Key.ToString() == "CAPEPATH") + if (entry.Item1 == "CAPEPATH") { hasCape = true; - capePath = entry.Value.ToString(); + capePath = entry.Item2; } } @@ -267,11 +268,11 @@ namespace PckStudio.Forms //determines skin type based on image dimensions, existence of BOX tags, and the ANIM value foreach (var entry in newSkin.properties) { - if (entry.Key.ToString() == "BOX") + if (entry.Item1.ToString() == "BOX") { string mClass = ""; string mData = ""; - foreach (char dCheck in entry.Value.ToString()) + foreach (char dCheck in entry.Item2) { if (dCheck.ToString() != " ") { @@ -279,7 +280,7 @@ namespace PckStudio.Forms } else { - mData = entry.Value.ToString().Remove(0, mClass.Count() + 1); + mData = entry.Item2.Remove(0, mClass.Count() + 1); break; } } @@ -316,13 +317,13 @@ namespace PckStudio.Forms } } - if (entry.Key.ToString() == "OFFSET") + if (entry.Item1 == "OFFSET") { string oClass = ""; string oData = ""; - foreach (char oCheck in entry.Value.ToString()) + foreach (char oCheck in entry.Item2) { - oData = entry.Value.ToString(); + oData = entry.Item2; if (oCheck.ToString() != " ") { oClass += oCheck.ToString(); @@ -351,13 +352,13 @@ namespace PckStudio.Forms } } - if (entry.Key.ToString() == "ANIM") + if (entry.Item1 == "ANIM") { - if (entry.Value.ToString() == "0x40000") + if (entry.Item2 == "0x40000") { } - else if (entry.Value.ToString() == "0x80000") + else if (entry.Item2 == "0x80000") { skinType = "alex"; } diff --git a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.Designer.cs b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.Designer.cs index 8e2473dd..816a8a5f 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.Designer.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.Designer.cs @@ -28,50 +28,49 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(rename)); - this.label2 = new System.Windows.Forms.Label(); - this.button1 = new System.Windows.Forms.Button(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.SuspendLayout(); - // - // label2 - // - resources.ApplyResources(this.label2, "label2"); - this.label2.ForeColor = System.Drawing.Color.White; - this.label2.Name = "label2"; - // - // button1 - // - resources.ApplyResources(this.button1, "button1"); - this.button1.ForeColor = System.Drawing.Color.White; - this.button1.Name = "button1"; - this.button1.UseVisualStyleBackColor = true; - this.button1.Click += new System.EventHandler(this.button1_Click); - // - // textBox1 - // - resources.ApplyResources(this.textBox1, "textBox1"); - this.textBox1.Name = "textBox1"; - // - // rename - // - resources.ApplyResources(this, "$this"); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ControlBox = false; - this.Controls.Add(this.textBox1); - this.Controls.Add(this.button1); - this.Controls.Add(this.label2); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "rename"; - this.Resizable = false; - this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow; - this.Style = MetroFramework.MetroColorStyle.Silver; - this.Theme = MetroFramework.MetroThemeStyle.Dark; - this.Load += new System.EventHandler(this.addCategory_Load); - this.ResumeLayout(false); - this.PerformLayout(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(renameLoc)); + this.label2 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.ForeColor = System.Drawing.Color.White; + this.label2.Name = "label2"; + // + // button1 + // + resources.ApplyResources(this.button1, "button1"); + this.button1.ForeColor = System.Drawing.Color.White; + this.button1.Name = "button1"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // textBox1 + // + resources.ApplyResources(this.textBox1, "textBox1"); + this.textBox1.Name = "textBox1"; + // + // renameLoc + // + resources.ApplyResources(this, "$this"); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ControlBox = false; + this.Controls.Add(this.textBox1); + this.Controls.Add(this.button1); + this.Controls.Add(this.label2); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "renameLoc"; + this.Resizable = false; + this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow; + this.Style = MetroFramework.MetroColorStyle.Silver; + this.Theme = MetroFramework.MetroThemeStyle.Dark; + this.ResumeLayout(false); + this.PerformLayout(); } diff --git a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.cs b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.cs index b19c2f2f..8eda9260 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.cs @@ -13,27 +13,20 @@ namespace PckStudio { public partial class renameLoc : MetroFramework.Forms.MetroForm { - TreeNode node; + public string NewText = string.Empty; - public renameLoc(TreeNode nodeIn) + public renameLoc(string initialText) { InitializeComponent(); - node = nodeIn; - textBox1.Text = nodeIn.Text; + textBox1.Text = initialText; FormBorderStyle = FormBorderStyle.None; } private void button1_Click(object sender, EventArgs e) { - node.Name = textBox1.Text; - node.Text = textBox1.Text; - this.Close(); + NewText = textBox1.Text; + DialogResult = DialogResult.OK; + Close(); } - - private void addCategory_Load(object sender, EventArgs e) - { - - } - - } + } } diff --git a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.resx b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.resx index 41fb29d6..39548b68 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/renameLoc.resx +++ b/MinecraftUSkinEditor/Forms/Utilities/renameLoc.resx @@ -2428,7 +2428,7 @@ CenterParent - rename + renameLoc MetroFramework.Forms.MetroForm, MetroFramework, Version=1.4.0.0, Culture=neutral, PublicKeyToken=5f91a84759bf584a diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index a1749118..025b7a33 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -137,10 +137,15 @@ - + + + + + + @@ -243,9 +248,6 @@ EntryEditor.cs - - - Form @@ -380,7 +382,7 @@ Component - + Form @@ -627,7 +629,6 @@ - @@ -668,8 +669,6 @@ - - diff --git a/MinecraftUSkinEditor/Properties/Resources.Designer.cs b/MinecraftUSkinEditor/Properties/Resources.Designer.cs index 979a3c6d..c762222f 100644 --- a/MinecraftUSkinEditor/Properties/Resources.Designer.cs +++ b/MinecraftUSkinEditor/Properties/Resources.Designer.cs @@ -500,16 +500,6 @@ namespace PckStudio.Properties { } } - /// - /// Looks up a localized resource of type System.Byte[]. - /// - public static byte[] UntitledSkinPCK { - get { - object obj = ResourceManager.GetObject("UntitledSkinPCK", resourceCulture); - return ((byte[])(obj)); - } - } - /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/MinecraftUSkinEditor/Properties/Resources.resx b/MinecraftUSkinEditor/Properties/Resources.resx index a5857ff0..b31d6f95 100644 --- a/MinecraftUSkinEditor/Properties/Resources.resx +++ b/MinecraftUSkinEditor/Properties/Resources.resx @@ -190,9 +190,6 @@ ..\Resources\pckClosed.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Resources\UntitledSkinPCK.pck;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\Resources\apps.zip;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/MinecraftUSkinEditor/Resources/UntitledSkinPCK.pck b/MinecraftUSkinEditor/Resources/UntitledSkinPCK.pck deleted file mode 100644 index 4022ebbcf9ee5f4e3009ba37b6ffd52a0f205696..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1539 zcmaKqYi|-!5Qbmm(hHLGtDkItz!?9+!Y&knWy4}({X!5iA_ST)YT~c=o!vR0rsHY0 zGt4t*&fEah0d)B3X(PrEIWmk9;Q=ZCPmoj)HOec@aZig{|E4cU8|Y(35^iYh7J8*k zBhM{TgR+h;rubl%CS`-KrSzJZtwnjs+Y$3g_(kR06}+Ih#=!Dh@LkP#z}%~INzp3r z^e|$~*z8x79jD5(*EPM`&s2K$XqWM)e7DaxlT&3cX>Tx>Df1pt*Q1@$qgB`Nw$#yx zD7C^H>~O#eOUexj$|L0gd%Q7HUC{1pRdq(tzw^=fuk>dPH^Vqz#KSxrM-PiMnj~nh z3h8|$e2wPkrNo+)s%wdLN>tZ78O%)GOOl?{LD$qm678${7BbP1QT?)!{?ODX>05-& zQHDBYI(%EoyR1^T2N{{e{*$EB%DUf4I