diff --git a/PCK-Studio/Classes/FileTypes/ARCFile.cs b/PCK-Studio/Classes/FileTypes/ARCFile.cs new file mode 100644 index 00000000..ee32bcfd --- /dev/null +++ b/PCK-Studio/Classes/FileTypes/ARCFile.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PckStudio.Classes.FileTypes +{ + public struct ConsoleArchive + { + public ConsoleArchive() + { + } + + public Dictionary Files = new Dictionary(); + } + public class ConsoleArchiveItem + { + public string Name { get; set; } + public int Size { get; set; } + public int Position { get; set; } + + public ConsoleArchiveItem(string name, int size, int position) + { + Name = name; + Size = size; + Position = position; + } + } + + public class ConsoleArchiveActions + { + + + public ConsoleArchive AddItem(ConsoleArchive archive, string ItemName, byte[] data) + { + archive.Files.Add(ItemName, data); + return archive; + } + public ConsoleArchive RemoveItem(ConsoleArchive archive, string ItemName) + { + if(archive.Files.ContainsKey(ItemName)) + archive.Files.Remove(ItemName); + return archive; + } + public ConsoleArchive EditItem(ConsoleArchive archive, string ItemName, byte[] data) + { + archive.Files[ItemName] = data; + return archive; + } + public ConsoleArchive Clear(ConsoleArchive archive) + { + archive.Files = null; + archive = new ConsoleArchive(); + return archive; + } + + + } + +} diff --git a/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs b/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs new file mode 100644 index 00000000..36baae40 --- /dev/null +++ b/PCK-Studio/Classes/IO/ARC/ARCFileReader.cs @@ -0,0 +1,76 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Text; +using PckStudio.Classes.FileTypes; + +namespace PckStudio.Classes.IO.ARC +{ + internal class ARCFileReader : StreamDataReader + { + + + private ARCFileReader() : base(true) + { } + + public ConsoleArchive Parse(byte[] data, ConsoleArchive source) + { + return Parse(new MemoryStream(data), source); + } + public ConsoleArchive Parse(string Filepath, ConsoleArchive source) + { + return Parse(new MemoryStream(File.ReadAllBytes(Filepath)), source); + } + + public ConsoleArchive Parse(MemoryStream s, ConsoleArchive archive) + { + List items = new List(); + Encoding encoding = Encoding.UTF8; + int NumberOfFiles = ReadInt(s); + + + for(int i = 0; i < NumberOfFiles; i++) + { + string name = ReadString(s); + int pos = ReadInt(s); + int size = ReadInt(s); + + ConsoleArchiveItem citem = new ConsoleArchiveItem(name, size, pos); + items.Add(citem); + + + } + + foreach(ConsoleArchiveItem citem in items) + { + if (!archive.Files.ContainsKey(citem.Name)) + archive.Files.Add(citem.Name, ReadBytesFromPosition(s, citem.Size, citem.Position)); + else + { + System.Diagnostics.Debug.WriteLine("Copy of: " + citem.Name + " | size:" + citem.Size + " | position:" + citem.Position); + } + s.Flush(); + } + items.Clear(); + s.Close(); + s.Dispose(); + + return archive; + } + private string ReadString(Stream stream) + { + int length = ReadShort(stream); + return ReadString(stream, length, Encoding.UTF8); + } + + private byte[] ReadBytesFromPosition(Stream s, int length, int position) + { + long originalPOS = s.Position; + s.Position = position; + byte[] ByteArray = ReadBytes(s, length); + s.Position = originalPOS; + return ByteArray; + } + + } +} diff --git a/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs b/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs new file mode 100644 index 00000000..2835f9c6 --- /dev/null +++ b/PCK-Studio/Classes/IO/ARC/ARCFileWriter.cs @@ -0,0 +1,64 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PckStudio.Classes.FileTypes; + +namespace PckStudio.Classes.IO.ARC +{ + internal class ARCFileWriter : StreamDataWriter + { + + private ARCFileWriter() : base(true) + {} + + public byte[] Build(ConsoleArchive ConsoleArc, string Filename) + { + MemoryStream f = new MemoryStream(); + WriteInt(f, ConsoleArc.Files.Count); + foreach(ConsoleArchiveItem item in BuildTable(ConsoleArc)) + { + WriteString(f, item.Name); + WriteInt(f, item.Position); + WriteInt(f, item.Size); + } + foreach (KeyValuePair pair in ConsoleArc.Files) + { + WriteBytes(f, pair.Value); + } + f.Close(); + f.Dispose(); + return f.ToArray(); + } + + private List BuildTable(ConsoleArchive ConsoleArc) + { + List l = new List(); + int HeaderSize = 4; + int currentFileOffset = 0; + foreach(KeyValuePair pair in ConsoleArc.Files) + { + HeaderSize += pair.Key.Length; + HeaderSize += 10; + string name = pair.Key; + int size = pair.Value.Length; + int position = currentFileOffset; + ConsoleArchiveItem citem = new ConsoleArchiveItem(name, size, position); + l.Add(citem); + currentFileOffset += size; + } + foreach (ConsoleArchiveItem item in l) + { + item.Position += HeaderSize; + } + return l; + } + private void WriteString(Stream stream, string String) + { + WriteShort(stream, (short)String.Length); + WriteString(stream, String, Encoding.UTF8); + } + } +} diff --git a/PCK-Studio/Forms/Additional-Popups/programInfo.Designer.cs b/PCK-Studio/Forms/Additional-Popups/programInfo.Designer.cs index 7c052efd..b63bb0c5 100644 --- a/PCK-Studio/Forms/Additional-Popups/programInfo.Designer.cs +++ b/PCK-Studio/Forms/Additional-Popups/programInfo.Designer.cs @@ -28,103 +28,115 @@ /// private void InitializeComponent() { - this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); - this.pictureBox1 = new System.Windows.Forms.PictureBox(); - this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel2 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel3 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); - this.SuspendLayout(); - // - // pictureBox1 - // - this.pictureBox1.Image = global::PckStudio.Properties.Resources.Splash; - this.pictureBox1.Location = new System.Drawing.Point(14, 33); - this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(575, 293); - this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; - this.pictureBox1.TabIndex = 0; - this.pictureBox1.TabStop = false; - this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); - this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_Click); - // - // metroLabel1 - // - this.metroLabel1.AutoSize = true; - this.metroLabel1.Location = new System.Drawing.Point(6, 333); - this.metroLabel1.Name = "metroLabel1"; - this.metroLabel1.Size = new System.Drawing.Size(250, 19); - this.metroLabel1.TabIndex = 1; - this.metroLabel1.Text = "Restored and maintained by PhoenixARC"; - this.metroLabel1.Theme = MetroFramework.MetroThemeStyle.Dark; - // - // metroLabel2 - // - this.metroLabel2.AutoSize = true; - this.metroLabel2.Location = new System.Drawing.Point(331, 333); - this.metroLabel2.Name = "metroLabel2"; - this.metroLabel2.Size = new System.Drawing.Size(269, 19); - this.metroLabel2.TabIndex = 2; - this.metroLabel2.Text = "Utilizing the Nobledez Website by Newagent"; - this.metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark; - // - // metroLabel3 - // - this.metroLabel3.AutoSize = true; - this.metroLabel3.Location = new System.Drawing.Point(4, 367); - this.metroLabel3.Name = "metroLabel3"; - this.metroLabel3.Size = new System.Drawing.Size(212, 19); - this.metroLabel3.TabIndex = 3; - this.metroLabel3.Text = "3D skin renderer by Łukasz Rejman"; - this.metroLabel3.Theme = MetroFramework.MetroThemeStyle.Dark; - // - // metroLabel4 - // - this.metroLabel4.AutoSize = true; - this.metroLabel4.Location = new System.Drawing.Point(331, 367); - this.metroLabel4.Name = "metroLabel4"; - this.metroLabel4.Size = new System.Drawing.Size(199, 19); - this.metroLabel4.TabIndex = 4; - this.metroLabel4.Text = "3D renderer found by Newagent"; - this.metroLabel4.Theme = MetroFramework.MetroThemeStyle.Dark; - // - // metroLabel5 - // - this.metroLabel5.AutoSize = true; - this.metroLabel5.Location = new System.Drawing.Point(4, 350); - this.metroLabel5.Name = "metroLabel5"; - this.metroLabel5.Size = new System.Drawing.Size(236, 19); - this.metroLabel5.TabIndex = 5; - this.metroLabel5.Text = "Additional code and utilities by MattNL"; - this.metroLabel5.Theme = MetroFramework.MetroThemeStyle.Dark; - // - // programInfo - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.BorderStyle = MetroFramework.Forms.MetroFormBorderStyle.FixedSingle; - this.ClientSize = new System.Drawing.Size(602, 392); - this.Controls.Add(this.metroLabel1); - this.Controls.Add(this.metroLabel5); - this.Controls.Add(this.metroLabel4); - this.Controls.Add(this.metroLabel3); - this.Controls.Add(this.metroLabel2); - this.Controls.Add(this.pictureBox1); - this.DisplayHeader = false; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "programInfo"; - this.Padding = new System.Windows.Forms.Padding(20, 30, 20, 20); - this.Resizable = false; - this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow; - this.Style = MetroFramework.MetroColorStyle.Silver; - this.Text = "programInfo"; - this.Theme = MetroFramework.MetroThemeStyle.Dark; - ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); - this.ResumeLayout(false); - this.PerformLayout(); + this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog(); + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel2 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel3 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); + this.metroLabel6 = new MetroFramework.Controls.MetroLabel(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Image = global::PckStudio.Properties.Resources.Splash; + this.pictureBox1.Location = new System.Drawing.Point(4, 5); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(575, 293); + this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + this.pictureBox1.Click += new System.EventHandler(this.pictureBox1_Click); + this.pictureBox1.DoubleClick += new System.EventHandler(this.pictureBox1_Click); + // + // metroLabel1 + // + this.metroLabel1.AutoSize = true; + this.metroLabel1.Location = new System.Drawing.Point(4, 301); + this.metroLabel1.Name = "metroLabel1"; + this.metroLabel1.Size = new System.Drawing.Size(250, 19); + this.metroLabel1.TabIndex = 1; + this.metroLabel1.Text = "Restored and maintained by PhoenixARC"; + this.metroLabel1.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // metroLabel2 + // + this.metroLabel2.AutoSize = true; + this.metroLabel2.Location = new System.Drawing.Point(314, 301); + this.metroLabel2.Name = "metroLabel2"; + this.metroLabel2.Size = new System.Drawing.Size(269, 19); + this.metroLabel2.TabIndex = 2; + this.metroLabel2.Text = "Utilizing the Nobledez Website by Newagent"; + this.metroLabel2.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // metroLabel3 + // + this.metroLabel3.AutoSize = true; + this.metroLabel3.Location = new System.Drawing.Point(314, 339); + this.metroLabel3.Name = "metroLabel3"; + this.metroLabel3.Size = new System.Drawing.Size(212, 19); + this.metroLabel3.TabIndex = 3; + this.metroLabel3.Text = "3D skin renderer by Łukasz Rejman"; + this.metroLabel3.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // metroLabel4 + // + this.metroLabel4.AutoSize = true; + this.metroLabel4.Location = new System.Drawing.Point(314, 320); + this.metroLabel4.Name = "metroLabel4"; + this.metroLabel4.Size = new System.Drawing.Size(199, 19); + this.metroLabel4.TabIndex = 4; + this.metroLabel4.Text = "3D renderer found by Newagent"; + this.metroLabel4.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // metroLabel5 + // + this.metroLabel5.AutoSize = true; + this.metroLabel5.Location = new System.Drawing.Point(4, 320); + this.metroLabel5.Name = "metroLabel5"; + this.metroLabel5.Size = new System.Drawing.Size(300, 19); + this.metroLabel5.TabIndex = 5; + this.metroLabel5.Text = "Additional development by MattNL and Miku-666"; + this.metroLabel5.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // metroLabel6 + // + this.metroLabel6.AutoSize = true; + this.metroLabel6.Location = new System.Drawing.Point(4, 339); + this.metroLabel6.Name = "metroLabel6"; + this.metroLabel6.Size = new System.Drawing.Size(203, 19); + this.metroLabel6.TabIndex = 6; + this.metroLabel6.Text = "Code base overhaul by Miku-666"; + this.metroLabel6.Theme = MetroFramework.MetroThemeStyle.Dark; + // + // programInfo + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BorderStyle = MetroFramework.Forms.MetroFormBorderStyle.FixedSingle; + this.ClientSize = new System.Drawing.Size(585, 364); + this.Controls.Add(this.metroLabel6); + this.Controls.Add(this.metroLabel1); + this.Controls.Add(this.metroLabel5); + this.Controls.Add(this.metroLabel4); + this.Controls.Add(this.metroLabel3); + this.Controls.Add(this.metroLabel2); + this.Controls.Add(this.pictureBox1); + this.DisplayHeader = false; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "programInfo"; + this.Padding = new System.Windows.Forms.Padding(20, 30, 20, 20); + this.Resizable = false; + this.ShadowType = MetroFramework.Forms.MetroFormShadowType.DropShadow; + this.Style = MetroFramework.MetroColorStyle.Silver; + this.Text = "programInfo"; + this.Theme = MetroFramework.MetroThemeStyle.Dark; + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); } @@ -137,5 +149,6 @@ private MetroFramework.Controls.MetroLabel metroLabel3; private MetroFramework.Controls.MetroLabel metroLabel4; private MetroFramework.Controls.MetroLabel metroLabel5; - } + private MetroFramework.Controls.MetroLabel metroLabel6; + } } \ No newline at end of file diff --git a/PCK-Studio/PckStudio.csproj b/PCK-Studio/PckStudio.csproj index af9d4372..667ed559 100644 --- a/PCK-Studio/PckStudio.csproj +++ b/PCK-Studio/PckStudio.csproj @@ -140,11 +140,14 @@ + + +