From 7d3c2f850b01fd5cd623bcb300dffabf637f1ece Mon Sep 17 00:00:00 2001 From: mn1712trungson Date: Wed, 14 Jun 2023 02:43:35 +0700 Subject: [PATCH 1/7] CGx files can edit --- Plugins/SF FEATHER/SF FEATHER/CGx.cs | 399 +++++++++++------- Plugins/SF FEATHER/SF FEATHER/Helper.cs | 154 +++++++ Plugins/SF FEATHER/SF FEATHER/Main.cs | 140 ++++-- Plugins/SF FEATHER/SF FEATHER/PAC.cs | 102 ++--- .../SF FEATHER/Properties/AssemblyInfo.cs | 2 +- .../Properties/Resources.Designer.cs | 7 +- Plugins/SF FEATHER/SF FEATHER/SCx.cs | 50 +-- .../SF FEATHER/SF FEATHER/SF FEATHER.csproj | 3 + 8 files changed, 574 insertions(+), 283 deletions(-) create mode 100644 Plugins/SF FEATHER/SF FEATHER/Helper.cs diff --git a/Plugins/SF FEATHER/SF FEATHER/CGx.cs b/Plugins/SF FEATHER/SF FEATHER/CGx.cs index a5015150..0e14d5c8 100644 --- a/Plugins/SF FEATHER/SF FEATHER/CGx.cs +++ b/Plugins/SF FEATHER/SF FEATHER/CGx.cs @@ -14,210 +14,285 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * By: pleoNeX + * By: mn1712trungson * */ + using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; using System.Drawing; -using System.Windows.Forms; +using System.IO; +using System.Net; +using System.Runtime.CompilerServices; +using System.Runtime.Remoting.Messaging; using Ekona; using Ekona.Images; +using static System.Net.Mime.MediaTypeNames; namespace SF_FEATHER { - public class CGx : ImageBase + public static class CGx { - const ushort WIDTH = 32; - ColorFormat depth; - sCGx cgx; - PaletteBase pb; - - public CGx(string file, int id, bool cg8, string fileName = "") - : base() + public static sFolder Unpack(sFile file) { - this.id = id; - if (fileName != "") - this.fileName = fileName; - else - this.fileName = Path.GetFileName(file); - - depth = cg8 ? ColorFormat.colors256 : Ekona.Images.ColorFormat.colors16; - Read(file); - } + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); - public PaletteBase Palette - { - get { return pb; } - } + char[] id = br.ReadChars(4); + uint u_Value = br.ReadUInt32(); + uint mappingType = br.ReadUInt32(); + uint NULL = br.ReadUInt32(); - public override void Read(string file) - { - BinaryReader br = new BinaryReader(File.OpenRead(file)); - cgx = new sCGx(); - - cgx.type = br.ReadChars(4); // CG4 - cgx.unknown1 = br.ReadUInt32(); - cgx.unknown2 = br.ReadUInt32(); - cgx.unknown3 = br.ReadUInt32(); // Usually 0 - - cgx.unknown4 = br.ReadUInt32(); // Usually 0 - cgx.size_tiles = br.ReadUInt32(); - cgx.unknown5 = br.ReadUInt32(); - cgx.num_tiles = br.ReadUInt32(); - - cgx.palColors = br.ReadUInt32(); - cgx.tileOffset = br.ReadUInt32(); - cgx.palOffset = br.ReadUInt32(); - cgx.unknonwnOffset = br.ReadUInt32(); // If 0, it doesn't exist - - // Read tiles - br.BaseStream.Position = cgx.tileOffset; - int tile_size = (depth == ColorFormat.colors16 ? 0x20 : 0x40); - Byte[] tiles = br.ReadBytes((int)cgx.num_tiles * tile_size); - Set_Tiles(tiles, WIDTH, (int)(tiles.Length / WIDTH), depth, TileForm.Horizontal, false); - if (depth == Ekona.Images.ColorFormat.colors16) - Height *= 2; - - // Read palette - br.BaseStream.Position = cgx.palOffset; - Color[][] colors; - if (depth == Ekona.Images.ColorFormat.colors16) + uint transparency = br.ReadUInt32(); + uint bitmapSize = br.ReadUInt32(); + uint paletteSize = br.ReadUInt32(); + uint tileNumber = br.ReadUInt32(); + + uint objectType = br.ReadUInt32(); + uint bitmapPointer = br.ReadUInt32(); + uint palettePointer = br.ReadUInt32(); + uint positionPointer = br.ReadUInt32(); + + sFolder unpack = new sFolder(); + unpack.files = new List(); + + if (positionPointer != 0) { - colors = new Color[cgx.palColors / 0x10][]; - for (int i = 0; i < colors.Length; i++) - colors[i] = Actions.BGR555ToColor(br.ReadBytes(32)); + uint fileNumber = 3; + for (int count = 0; count < fileNumber; count++) + { + sFile newFile = new sFile(); + newFile.name = file.name + '_' + count.ToString(); + string ext = new string(id); + + if (count == 0) + { + if (ext == "CG4 ") + newFile.name += ".TIL4"; + else if (ext == "CG8 ") + newFile.name += ".TIL8"; + newFile.offset = bitmapPointer; + newFile.size = bitmapSize; + } + else if (count == 1) + { + if (ext == "CG4 ") + newFile.name += ".P16"; + else if (ext == "CG8 ") + newFile.name += ".P256"; + newFile.offset = palettePointer; + newFile.size = paletteSize; + } + else if (count == 2) + { + newFile.name += ".CPOS"; + newFile.offset = positionPointer; + newFile.size = 0x8; + } + + newFile.path = file.path; + unpack.files.Add(newFile); + } } - else + + else if (positionPointer == 0) { - colors = new Color[1][]; - colors[0] = Actions.BGR555ToColor(br.ReadBytes((int)cgx.palColors * 2)); + uint fileNumber = 2; + for (int count = 0; count < fileNumber; count++) + { + sFile newFile = new sFile(); + newFile.name = file.name + '_' + count.ToString(); + string ext = new string(id); + + if (count == 0) + { + if (ext == "CG4 ") + newFile.name += ".TIL4"; + else if (ext == "CG8 ") + newFile.name += ".TIL8"; + newFile.offset = bitmapPointer; + newFile.size = bitmapSize; + } + else if (count == 1) + { + if (ext == "CG4 ") + newFile.name += ".P16"; + else if(ext == "CG8 ") + newFile.name += ".P256"; + newFile.offset = palettePointer; + newFile.size = paletteSize; + } + + newFile.path = file.path; + unpack.files.Add(newFile); + } } - PaletteBase palette = new RawPalette(colors, false, depth); - - br.BaseStream.Position = cgx.unknonwnOffset; - cgx.unknown = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position)); br.Close(); + return unpack; } - public override void Write(string fileOut, PaletteBase palette) + + public static void Pack(string fileOG, string fileOut, ref sFolder unpacked) { - if (depth != FormatColor) - throw new NotImplementedException("The current file doesn't support this depth"); - - // Update the struct - cgx.size_tiles = (uint)Tiles.Length; - if (depth == Ekona.Images.ColorFormat.colors16) - cgx.num_tiles = cgx.size_tiles / 0x20; - else - cgx.num_tiles = cgx.size_tiles / 0x40; - cgx.palColors = (uint)palette.NumberOfColors; - cgx.palOffset = 0x30 + cgx.size_tiles; - cgx.unknonwnOffset = cgx.palOffset + cgx.palColors * 2; - - BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut)); - - bw.Write(cgx.type); - bw.Write(cgx.unknown1); - bw.Write(cgx.unknown2); - bw.Write(cgx.unknown3); - - bw.Write(cgx.unknown4); - bw.Write(cgx.size_tiles); - bw.Write(cgx.unknown5); - bw.Write(cgx.num_tiles); - - bw.Write(cgx.palColors); - bw.Write(cgx.tileOffset); - bw.Write(cgx.palOffset); - bw.Write(cgx.unknonwnOffset); - - bw.Write(Tiles); - for (int i = 0; i < palette.NumberOfPalettes; i++) - bw.Write(Actions.ColorToBGR555(palette.Palette[i])); - - bw.Flush(); - bw.Close(); + throw new NotImplementedException(); } - public struct sCGx + public struct CGxS { - public char[] type; - public uint unknown1; - public uint unknown2; - public uint unknown3; - public uint unknown4; - - public uint size_tiles; - public uint unknown5; - public uint num_tiles; - - public uint palColors; - public uint tileOffset; - public uint palOffset; - public uint unknonwnOffset; - - public byte[] unknown; + public char[] id; + public uint u_Value; + public uint mappingType; + public uint NULL; + public uint transparency; + + public uint bitmapSize; + public uint paletteSize; + public uint tileNumber; + + public uint objectType; + public uint bitmapPointer; + public uint palettePointer; + public uint positionPointer; + + public byte[] bitmapArray; } } - public class CGT : ImageBase + public static class CGT { - bool transparency; - PaletteBase pb; - - public CGT(string file, int id, string fileName = "") : base(file, id, fileName) { } - - public PaletteBase Palette - { - get { return pb; } - } - - public override void Read(string file) + public static sFolder Unpack(sFile file) { - BinaryReader br = new BinaryReader(File.OpenRead(file)); + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); char[] id = br.ReadChars(4); - uint unknown1 = br.ReadUInt32(); // Usually is 0x00 - uint unknown2 = br.ReadUInt32(); // Usually is 0x00 - uint unknown3 = br.ReadUInt32(); // Usually is 0x00 - - uint format = br.ReadUInt32(); - uint tile_size = br.ReadUInt32(); - uint header_size = br.ReadUInt32(); - uint palette_size = br.ReadUInt32(); + uint NULL1 = br.ReadUInt32(); + uint mappingType = br.ReadUInt32(); + uint NULL2 = br.ReadUInt32(); - uint palette_offset = br.ReadUInt32(); - uint unknown4 = br.ReadUInt32(); - uint unknown_offset = br.ReadUInt32(); - uint unknown5 = br.ReadUInt32(); + uint pxFormat = br.ReadUInt32(); + uint bitmapSize = br.ReadUInt32(); + uint bitmapPointer = br.ReadUInt32(); + uint paletteSize = br.ReadUInt32(); - transparency = (br.ReadUInt32() == 0x00 ? false : true); - transparency = false; + uint palettePointer = br.ReadUInt32(); + uint positionSize = br.ReadUInt32(); + uint positionPointer = br.ReadUInt32(); + uint NULL3 = br.ReadUInt32(); - int width = (int)Math.Pow(2, (double)(br.ReadUInt16() + 3)); - int height = (int)Math.Pow(2, (double)(br.ReadUInt16() + 3)); - uint unknown6 = br.ReadUInt32(); + br.BaseStream.Position = 0; + sFolder unpack = new sFolder(); + unpack.files = new List(); - byte[] data = br.ReadBytes((int)tile_size); - + if (positionPointer != 0) + { + uint fileNumber = 3; + for (int count = 0; count < fileNumber; count++) + { + sFile newFile = new sFile(); + newFile.name = file.name + '_' + count.ToString(); + + if (count == 0) + { + if (pxFormat == 0x01) + newFile.name += ".T3I5"; + else if (pxFormat == 0x03) + newFile.name += ".TILT"; + else if (pxFormat == 0x04) + newFile.name += ".TILT"; + else if (pxFormat == 0x06) + newFile.name += ".T5I3"; + newFile.offset = bitmapPointer; + newFile.size = bitmapSize; + } + else if (count == 1 && palettePointer != positionPointer) + { + if (pxFormat == 0x01) + newFile.name += ".P3I5"; + else if (pxFormat == 0x03) + newFile.name += ".P16"; + else if (pxFormat == 0x04) + newFile.name += ".P256"; + else if (pxFormat == 0x06) + newFile.name += ".P5I3"; + newFile.offset = palettePointer; + newFile.size = paletteSize; + } + else if (count == 1 && palettePointer == positionPointer) + { + newFile.name = ".dummy"; + newFile.offset = palettePointer; + newFile.size = paletteSize; + } + else if (count == 2) + { + newFile.name += ".CPOS"; + newFile.offset = positionPointer; + newFile.size = positionSize * 8; + } + newFile.path = file.path; + + unpack.files.Add(newFile); + } + } - br.BaseStream.Position = palette_offset; - Color[][] palette = new Color[1][]; - palette[0] = Actions.BGR555ToColor(br.ReadBytes((int)palette_size)); + else if (positionPointer == 0) + { + uint fileNumber = 2; + for (int count = 0; count < fileNumber; count++) + { + sFile newFile = new sFile(); + newFile.name = file.name + '_' + count.ToString(); + + if (count == 0) + { + newFile.name += ".TILT"; + newFile.offset = bitmapPointer; + newFile.size = bitmapSize; + } + else if (count == 1) + { + if (pxFormat == 0x01) + newFile.name += ".P3I5"; + else if (pxFormat == 0x03) + newFile.name += ".P16"; + else if (pxFormat == 0x04) + newFile.name += ".P256"; + else if (pxFormat == 0x06) + newFile.name += ".P5I3"; + newFile.offset = palettePointer; + newFile.size = paletteSize; + } + + newFile.path = file.path; + + unpack.files.Add(newFile); + } + } br.Close(); - - Set_Tiles(data, width, height, (ColorFormat)format, TileForm.Lineal, false); - pb = new RawPalette(palette, false, ColorFormat.colors256); + return unpack; } - - public override void Write(string fileOut, PaletteBase palette) + public static void Pack(string fileOG, string fileOut, ref sFolder unpacked) { throw new NotImplementedException(); } + + public struct CGTs + { + public char[] id; + public uint NULL1; + public uint mappingType; + public uint NULL2; + + public uint pxFormat; + public uint bitmapSize; + public uint bitmapPointer; + public uint paletteSize; + + public uint palettePointer; + public uint positionSize; + public uint positionPointer; + public uint NULL3; + } } } + diff --git a/Plugins/SF FEATHER/SF FEATHER/Helper.cs b/Plugins/SF FEATHER/SF FEATHER/Helper.cs new file mode 100644 index 00000000..2c4a6beb --- /dev/null +++ b/Plugins/SF FEATHER/SF FEATHER/Helper.cs @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2011 pleoNeX + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * By: mn1712trungson + * + */ + +using Ekona.Images; +using Ekona; +using System; +using System.Collections.Generic; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SF_FEATHER +{ + public class Helper + { + public static Format ReadRAW(sFile file, IPluginHost pluginHost) + { + //Palette + if (file.name.EndsWith(".P3I5")) + { + RawPalette palette = new RawPalette(file.path, file.id, true, ColorFormat.A3I5, 0, -1, file.name); + pluginHost.Set_Palette(palette); + return Format.Palette; + } + else if (file.name.EndsWith(".P5I3")) + { + RawPalette palette = new RawPalette(file.path, file.id, true, ColorFormat.A5I3, 0, -1, file.name); + pluginHost.Set_Palette(palette); + return Format.Palette; + } + else if (file.name.EndsWith(".P16")) + { + RawPalette palette = new RawPalette(file.path, file.id, true, ColorFormat.colors16, 0, -1, file.name); + pluginHost.Set_Palette(palette); + return Format.Palette; + } + else if (file.name.EndsWith(".P256")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + int palette_length = 0x200; + Color[][] palette = new Color[1][]; + for (int i = 0; i < palette.Length; i++) + palette[i] = Actions.BGR555ToColor(br.ReadBytes(palette_length)); + + br.Close(); + + RawPalette pb = new RawPalette(palette, true, ColorFormat.colors256); + pluginHost.Set_Palette(pb); + return Format.Palette; + } + + //Tile + ColorFormat depth; + if (pluginHost.Get_Palette().Loaded) + depth = pluginHost.Get_Palette().Depth; + else + depth = ColorFormat.direct; + + if (file.name.EndsWith(".TIL8")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + byte[] data = br.ReadBytes((int)file.size); + + br.Close(); + + RawImage image = new RawImage(data, TileForm.Horizontal, ColorFormat.colors256, 0x8, data.Length / 8, true, file.name); + pluginHost.Set_Image(image); + return Format.Tile; + } + + else if (file.name.EndsWith(".TIL4")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + byte[] data = br.ReadBytes((int)file.size); + + br.Close(); + + RawImage image = new RawImage(data, TileForm.Horizontal, ColorFormat.colors16, 0x8, data.Length / 4, true, file.name); + pluginHost.Set_Image(image); + return Format.Tile; + } + else if (file.name.EndsWith(".TILT")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + bool transparency = br.ReadUInt32() == 0x00 ? false : true; + Console.WriteLine($"Transparency = {transparency}"); + + int width = (int)Math.Pow(2, br.ReadUInt16() + 3); + int height = (int)Math.Pow(2, br.ReadUInt16() + 3); + uint bitmapArrayPointer = br.ReadUInt32(); + + br.Close(); + + RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, depth, width, height, true, (int)bitmapArrayPointer, (int)(file.size - bitmapArrayPointer), file.name); + pluginHost.Set_Image(image); + return Format.Tile; + } + + else if (file.name.EndsWith(".T3I5")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + bool transparency = br.ReadUInt32() == 0x00 ? false : true; + Console.WriteLine($"Transparency = {transparency}"); + + int width = (int)Math.Pow(2, br.ReadUInt16() + 3); + int height = (int)Math.Pow(2, br.ReadUInt16() + 3); + uint bitmapArrayPointer = br.ReadUInt32(); + + br.Close(); + + RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, ColorFormat.A3I5, width, height, true, (int)bitmapArrayPointer, (int)(file.size - bitmapArrayPointer), file.name); + pluginHost.Set_Image(image); + return Format.Tile; + } + else if (file.name.EndsWith(".T5I3")) + { + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + bool transparency = br.ReadUInt32() == 0x00 ? false : true; + Console.WriteLine($"Transparency = {transparency}"); + + int width = (int)Math.Pow(2, br.ReadUInt16() + 3); + int height = (int)Math.Pow(2, br.ReadUInt16() + 3); + uint bitmapArrayPointer = br.ReadUInt32(); + + br.Close(); + + RawImage image = new RawImage(file.path, file.id, TileForm.Lineal, ColorFormat.A5I3, width, height, true, (int)bitmapArrayPointer, (int)(file.size - bitmapArrayPointer), file.name); + pluginHost.Set_Image(image); + return Format.Tile; + } + + return Format.Unknown; + } + } +} diff --git a/Plugins/SF FEATHER/SF FEATHER/Main.cs b/Plugins/SF FEATHER/SF FEATHER/Main.cs index c3a59cdf..734b1440 100644 --- a/Plugins/SF FEATHER/SF FEATHER/Main.cs +++ b/Plugins/SF FEATHER/SF FEATHER/Main.cs @@ -15,10 +15,13 @@ * along with this program. If not, see . * * By: pleoNeX + * Update: mn1712trungson * */ + using System; -using System.Collections.Generic; +using System.Drawing; +using System.IO; using System.Text; using Ekona; using Ekona.Images; @@ -28,7 +31,7 @@ namespace SF_FEATHER public class Main : IGamePlugin { IPluginHost pluginHost; - String gameCode; + string gameCode; public void Initialize(IPluginHost pluginHost, string gameCode) { @@ -38,89 +41,146 @@ public void Initialize(IPluginHost pluginHost, string gameCode) public bool IsCompatible() { if (gameCode == "CS4J") + { return true; - + } return false; } - public Format Get_Format(sFile file, byte[] magic) + public Format Get_Format(sFile file, byte[] mSeed) { - string ext = new String(Encoding.ASCII.GetChars(magic)); + string ext = new string(Encoding.ASCII.GetChars(mSeed)); - if (file.name.EndsWith(".pac") && (magic[2] == 0x01 && magic[3] == 0x00)) + if (file.name.EndsWith(".pac") && (mSeed[2] == 0x01 && mSeed[3] == 0x00)) return Format.Pack; if (ext == "CG4 " || ext == "CG8 ") - return Format.FullImage; + return Format.Pack; else if (ext == "SC4 " || ext == "SC8 ") return Format.Map; else if (ext == "CGT ") - return Format.FullImage; + return Format.Pack; + else if (file.name.EndsWith(".TIL4")) + return Format.Tile; + else if (file.name.EndsWith(".TIL8")) + return Format.Tile; + else if (file.name.EndsWith(".TILT")) + return Format.Tile; + else if (file.name.EndsWith(".T3I5")) + return Format.Tile; + else if (file.name.EndsWith(".T5I3")) + return Format.Tile; + else if (file.name.EndsWith(".P16")) + return Format.Palette; + else if (file.name.EndsWith(".P256")) + return Format.Palette; + else if (file.name.EndsWith(".P3I5")) + return Format.Palette; + else if (file.name.EndsWith(".P5I3")) + return Format.Palette; + else if (file.name.EndsWith(".CPOS")) + return Format.Cell; else if (ext == "PSI3") return Format.Script; + else if (ext == "BIT ") + return Format.Font; + else if (ext == "ANT ") + return Format.Texture; + else if (ext == "ANP ") + return Format.Animation; + else if (ext == "MBG " || ext == "ABG " || ext == "HBG ") + return Format.Model3D; return Format.Unknown; } - public string Pack(ref sFolder unpacked, sFile file) { - string fileOut = pluginHost.Get_TempFile(); - PAC.Pack(file.path, fileOut, ref unpacked); + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + string ext = new string(br.ReadChars(4)); + br.Close(); - return fileOut; + if (file.name.EndsWith(".pac")) + { + string fileOut = pluginHost.Get_TempFile(); + PAC.Pack(file.path, fileOut, ref unpacked); + + return fileOut; + } + + else if (ext == "CG4 " || ext == "CG8 ") + { + string fileOut = pluginHost.Get_TempFile(); + CGx.Pack(fileOut, fileOut, ref unpacked); + + return fileOut; + } + + else if (ext == "CGT ") + { + string fileOut = pluginHost.Get_TempFile(); + CGT.Pack(fileOut, fileOut, ref unpacked); + + return fileOut; + } + return null; } + public sFolder Unpack(sFile file) { - return PAC.Unpack(file.path, file.name); + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + string ext = new string(br.ReadChars(4)); + br.Close(); + if (file.name.EndsWith(".pac")) + { + return PAC.Unpack(file.path, file.name); + } + else if (ext == "CG4 " || ext == "CG8 ") + { + return CGx.Unpack(file); + } + else if (ext == "CGT ") + { + return CGT.Unpack(file); + } + return new sFolder(); } public void Read(sFile file) { - System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path)); - string ext = new String(Encoding.ASCII.GetChars(br.ReadBytes(4))); + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + string ext = new string(Encoding.ASCII.GetChars(br.ReadBytes(4))); br.Close(); - if (ext == "CG4 ") - { - CGx cgx = new CGx(file.path, file.id, false, file.name); - pluginHost.Set_Palette(cgx.Palette); - pluginHost.Set_Image(cgx); - } - else if (ext == "CG8 ") - { - CGx cgx = new CGx(file.path, file.id, true, file.name); - pluginHost.Set_Palette(cgx.Palette); - pluginHost.Set_Image(cgx); - } - else if (ext == "SC4 " || ext == "SC8 ") + if (ext == "SC4 " || ext == "SC8 ") { SCx scx = new SCx(file.path, file.id, file.name); pluginHost.Set_Map(scx); } - else if (ext == "CGT ") + else { - CGT cgt = new CGT(file.path, file.id, file.name); - pluginHost.Set_Palette(cgt.Palette); - pluginHost.Set_Image(cgt); + Helper.ReadRAW(file, pluginHost); } } public System.Windows.Forms.Control Show_Info(sFile file) { Read(file); - System.IO.BinaryReader br = new System.IO.BinaryReader(System.IO.File.OpenRead(file.path)); - string ext = new String(Encoding.ASCII.GetChars(br.ReadBytes(4))); + BinaryReader br = new BinaryReader(File.OpenRead(file.path)); + string ext = new string(Encoding.ASCII.GetChars(br.ReadBytes(4))); br.Close(); - if (ext == "CG4 " || ext == "CG8 ") - return new ImageControl(pluginHost, false); - else if (ext == "SC4 " || ext == "SC8 ") + if (ext == "SC4 " || ext == "SC8 ") return new ImageControl(pluginHost, true); - else if (ext == "CGT ") - return new ImageControl(pluginHost, false); + + Format format = Helper.ReadRAW(file, pluginHost); + + if (format == Format.Palette) + return new PaletteControl(pluginHost, pluginHost.Get_Palette()); + + if (format == Format.Tile && pluginHost.Get_Palette().Loaded) + return new ImageControl(pluginHost, pluginHost.Get_Image(), pluginHost.Get_Palette()); return new System.Windows.Forms.Control(); } - } } diff --git a/Plugins/SF FEATHER/SF FEATHER/PAC.cs b/Plugins/SF FEATHER/SF FEATHER/PAC.cs index ce770669..a4acd677 100644 --- a/Plugins/SF FEATHER/SF FEATHER/PAC.cs +++ b/Plugins/SF FEATHER/SF FEATHER/PAC.cs @@ -15,11 +15,12 @@ * along with this program. If not, see . * * By: pleoNeX + * Update: mn1712trungson * */ + using System; using System.Collections.Generic; -using System.Linq; using System.Text; using System.IO; using Ekona; @@ -35,14 +36,15 @@ public static sFolder Unpack(string file, string name) sFolder unpacked = new sFolder(); unpacked.files = new List(); - ushort num_element = br.ReadUInt16(); - ushort unknown = br.ReadUInt16(); - uint type_file = br.ReadUInt32(); + ushort fileNumber = br.ReadUInt16(); + ushort uValue1 = br.ReadUInt16(); + ushort uValue2 = br.ReadUInt16(); + ushort padding = br.ReadUInt16(); - for (int i = 0; i < num_element; i++) + for (int fCount = 0; fCount < fileNumber; fCount++) { sFile newFile = new sFile(); - newFile.name = name + '_' + i.ToString(); + newFile.name = name + '_' + fCount.ToString(); newFile.offset = br.ReadUInt32() * 0x10; newFile.size = br.ReadUInt32() * 0x10; newFile.path = file; @@ -53,11 +55,11 @@ public static sFolder Unpack(string file, string name) bool compressed = false; // Check if this file is pac, it searches the extension - long currPos = br.BaseStream.Position; + long currentPos = br.BaseStream.Position; br.BaseStream.Position = newFile.offset; - byte cInd = br.ReadByte(); - uint cSize = br.ReadUInt32(); - if ((cInd == 0x11 || cInd == 0x10) && cSize < 0x2000000) + byte typeLZ = br.ReadByte(); + uint compressedSize = br.ReadUInt32(); + if ((typeLZ == 0x11 || typeLZ == 0x10) && compressedSize < 0x2000000) compressed = true; // Search the indicator of the pac file @@ -65,9 +67,9 @@ public static sFolder Unpack(string file, string name) br.BaseStream.Position = newFile.offset + 9; else br.BaseStream.Position = newFile.offset + 4; - uint currType = br.ReadUInt32(); + uint fileType = br.ReadUInt32(); - if (currType == 0x04) + if (fileType == 0x04) newFile.name += ".pac"; else { @@ -77,12 +79,12 @@ public static sFolder Unpack(string file, string name) else br.BaseStream.Position = newFile.offset; - currType = br.ReadUInt32(); - char[] ext = Encoding.ASCII.GetChars(BitConverter.GetBytes(currType)); + fileType = br.ReadUInt32(); + char[] ext = Encoding.ASCII.GetChars(BitConverter.GetBytes(fileType)); String extS = "."; - for (int s = 0; s < 4; s++) - if (Char.IsLetterOrDigit(ext[s]) || ext[s] == 0x20) - extS += ext[s]; + for (int sCount = 0; sCount < 4; sCount++) + if (Char.IsLetterOrDigit(ext[sCount]) || ext[sCount] == 0x20) + extS += ext[sCount]; if (extS != "." && extS.Length == 5) newFile.name += extS; @@ -90,7 +92,7 @@ public static sFolder Unpack(string file, string name) newFile.name += ".bin"; } - br.BaseStream.Position = currPos; + br.BaseStream.Position = currentPos; } else continue; @@ -102,73 +104,75 @@ public static sFolder Unpack(string file, string name) return unpacked; } - public static void Pack(string file_original, string fileOut, ref sFolder unpacked) + public static void Pack(string fileOG, string fileOut, ref sFolder unpacked) { - BinaryReader br = new BinaryReader(File.OpenRead(file_original)); + BinaryReader br = new BinaryReader(File.OpenRead(fileOG)); BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut)); List buffer = new List(); - ushort num_element = br.ReadUInt16(); - bw.Write(num_element); - bw.Write(br.ReadUInt16()); // Unknown - bw.Write(br.ReadUInt32()); // Type of element + ushort fileNumber = br.ReadUInt16(); + bw.Write(fileNumber); + //uValue1, uValue2, padding + bw.Write(br.ReadUInt16()); + bw.Write(br.ReadUInt16()); + bw.Write(br.ReadUInt16()); - uint offset = (uint)num_element * 8 + 8; - uint size; - int f = 0; // Pointer to the unpacked.files array + uint fOffset = (uint)fileNumber * 8 + 8; + uint fSize; + int unpackedPointer = 0; // Pointer to the unpacked.files array - // Write the final padding of the FAT section - if (offset % 0x10 != 0) + // Write the final padding of the dict section + if (fOffset % 0x10 != 0) { - for (int r = 0; r < 0x10 - (offset % 0x10); r++) + for (int dictPadding = 0; dictPadding < 0x10 - (fOffset % 0x10); dictPadding++) buffer.Add(0x00); - offset += 0x10 - (offset % 0x10); + fOffset += 0x10 - (fOffset % 0x10); } - for (int i = 0; i < num_element; i++) + for (int dictCount = 0; dictCount < fileNumber; dictCount++) { uint older_offset = br.ReadUInt32(); - size = br.ReadUInt32(); + fSize = br.ReadUInt32(); // If it's a null file - if (size == 0) + if (fSize == 0) { bw.Write(older_offset); - bw.Write(size); + bw.Write(fSize); continue; } // Get a normalized size - size = unpacked.files[f].size; - if (size % 0x10 != 0) - size += 0x10 - (size % 0x10); + fSize = unpacked.files[unpackedPointer].size; + if (fSize % 0x10 != 0) + fSize += 0x10 - (fSize % 0x10); // Write the FAT section - bw.Write((uint)(offset / 0x10)); - bw.Write((uint)(size / 0x10)); + bw.Write((uint)(fOffset / 0x10)); + bw.Write((uint)(fSize / 0x10)); // Write file - BinaryReader fileRead = new BinaryReader(File.OpenRead(unpacked.files[f].path)); - fileRead.BaseStream.Position = unpacked.files[f].offset; - buffer.AddRange(fileRead.ReadBytes((int)unpacked.files[f].size)); + BinaryReader fileRead = new BinaryReader(File.OpenRead(unpacked.files[unpackedPointer].path)); + fileRead.BaseStream.Position = unpacked.files[unpackedPointer].offset; + buffer.AddRange(fileRead.ReadBytes((int)unpacked.files[unpackedPointer].size)); fileRead.Close(); // Write the padding - for (int r = 0; r < (size - unpacked.files[f].size); r++) + for (int fPadding = 0; fPadding < (fSize - unpacked.files[unpackedPointer].size); fPadding++) buffer.Add(0x00); // Set the new offset - sFile newFile = unpacked.files[f]; - newFile.offset = offset; + sFile newFile = unpacked.files[unpackedPointer]; + newFile.offset = fOffset; newFile.path = fileOut; - unpacked.files[f] = newFile; + unpacked.files[unpackedPointer] = newFile; // Set new offset - offset += size; - f++; + fOffset += fSize; + unpackedPointer++; } bw.Flush(); diff --git a/Plugins/SF FEATHER/SF FEATHER/Properties/AssemblyInfo.cs b/Plugins/SF FEATHER/SF FEATHER/Properties/AssemblyInfo.cs index bf1b728b..2bfc22df 100644 --- a/Plugins/SF FEATHER/SF FEATHER/Properties/AssemblyInfo.cs +++ b/Plugins/SF FEATHER/SF FEATHER/Properties/AssemblyInfo.cs @@ -6,7 +6,7 @@ // conjunto de atributos. Cambie estos atributos para modificar la información // asociada con un ensamblado. [assembly: AssemblyTitle("SF FEATHER")] -[assembly: AssemblyDescription("")] +[assembly: AssemblyDescription("Update mn1712trungson")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Tinke")] diff --git a/Plugins/SF FEATHER/SF FEATHER/Properties/Resources.Designer.cs b/Plugins/SF FEATHER/SF FEATHER/Properties/Resources.Designer.cs index 32897a7b..94652952 100644 --- a/Plugins/SF FEATHER/SF FEATHER/Properties/Resources.Designer.cs +++ b/Plugins/SF FEATHER/SF FEATHER/Properties/Resources.Designer.cs @@ -8,10 +8,9 @@ // //------------------------------------------------------------------------------ -namespace SF_FEATHER.Properties { - using System; - - +namespace SF_FEATHER.Properties +{ + /// /// Clase de recurso con establecimiento inflexible de tipos, para buscar cadenas traducidas, etc. /// diff --git a/Plugins/SF FEATHER/SF FEATHER/SCx.cs b/Plugins/SF FEATHER/SF FEATHER/SCx.cs index d74adce5..a7b76694 100644 --- a/Plugins/SF FEATHER/SF FEATHER/SCx.cs +++ b/Plugins/SF FEATHER/SF FEATHER/SCx.cs @@ -15,12 +15,8 @@ * along with this program. If not, see . * * By: pleoNeX - * + * Update: mn1712trungson */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using System.IO; using Ekona; using Ekona.Images; @@ -29,27 +25,27 @@ namespace SF_FEATHER { public class SCx : MapBase { - sSCx scx; + sSCx typeSC; public SCx(string file, int id, string fileName = "") : base(file, id, fileName) { } public override void Read(string file) { BinaryReader br = new BinaryReader(File.OpenRead(file)); - scx = new sSCx(); + typeSC = new sSCx(); - scx.type = br.ReadChars(4); - scx.unknown1 = br.ReadUInt32(); - scx.unknown2 = br.ReadUInt32(); - scx.unknown3 = br.ReadUInt32(); // Usually 0x00 - scx.unknown4 = br.ReadUInt32(); + typeSC.mSeed = br.ReadChars(4); + typeSC.u_Value = br.ReadUInt32(); + typeSC.mappingType = br.ReadUInt32(); + typeSC.NULL = br.ReadUInt32(); + typeSC.u_Value2 = br.ReadUInt32(); ushort width = br.ReadUInt16(); ushort height = br.ReadUInt16(); - scx.size_mapData2 = br.ReadUInt32(); // Is alway the same? - scx.size_mapData = br.ReadUInt32(); + typeSC.mapSize1 = br.ReadUInt32(); + typeSC.mapSize2 = br.ReadUInt32(); - NTFS[] map = new NTFS[scx.size_mapData / 2]; + NTFS[] map = new NTFS[typeSC.mapSize2 / 2]; for (int i = 0; i < map.Length; i++) map[i] = Actions.MapInfo(br.ReadUInt16()); @@ -60,11 +56,11 @@ public override void Write(string fileOut, ImageBase image, PaletteBase palette) { BinaryWriter bw = new BinaryWriter(File.OpenWrite(fileOut)); - bw.Write(scx.type); - bw.Write(scx.unknown1); - bw.Write(scx.unknown2); - bw.Write(scx.unknown3); - bw.Write(scx.unknown4); + bw.Write(typeSC.mSeed); + bw.Write(typeSC.u_Value); + bw.Write(typeSC.mappingType); + bw.Write(typeSC.NULL); + bw.Write(typeSC.u_Value2); bw.Write((ushort)Width); bw.Write((ushort)Height); @@ -80,14 +76,14 @@ public override void Write(string fileOut, ImageBase image, PaletteBase palette) public struct sSCx { - public char[] type; - public uint unknown1; - public uint unknown2; - public uint unknown3; - public uint unknown4; + public char[] mSeed; + public uint u_Value; + public uint mappingType; + public uint NULL; + public uint u_Value2; - public uint size_mapData2; - public uint size_mapData; + public uint mapSize1; + public uint mapSize2; } } } diff --git a/Plugins/SF FEATHER/SF FEATHER/SF FEATHER.csproj b/Plugins/SF FEATHER/SF FEATHER/SF FEATHER.csproj index 0f894323..ad1ca1c9 100644 --- a/Plugins/SF FEATHER/SF FEATHER/SF FEATHER.csproj +++ b/Plugins/SF FEATHER/SF FEATHER/SF FEATHER.csproj @@ -41,9 +41,11 @@ + + @@ -63,6 +65,7 @@ +