From 7613ca56cea9d0e1fb8c5cdc6e8d4826687c4add Mon Sep 17 00:00:00 2001 From: Sudakov Pavel Date: Tue, 4 Sep 2018 19:39:15 +0300 Subject: [PATCH] Added extract archive support. First release. Version 0.1 --- CBNSTT/AboutForm.Designer.cs | 65 +++ CBNSTT/AboutForm.cs | 20 + .../{FontEditorForm.resx => AboutForm.resx} | 22 +- CBNSTT/CBNSTT.csproj | 16 +- CBNSTT/FontEditorForm.Designer.cs | 209 --------- CBNSTT/FontEditorForm.cs | 361 --------------- CBNSTT/MainForm.Designer.cs | 32 +- CBNSTT/MainForm.cs | 13 +- CBNSTT/Packer_Tool_Form.Designer.cs | 19 +- CBNSTT/Packer_Tool_Form.cs | 410 +++++++++++++++++- CBNSTT/TextEditForm.Designer.cs | 6 +- 11 files changed, 556 insertions(+), 617 deletions(-) create mode 100644 CBNSTT/AboutForm.Designer.cs create mode 100644 CBNSTT/AboutForm.cs rename CBNSTT/{FontEditorForm.resx => AboutForm.resx} (90%) delete mode 100644 CBNSTT/FontEditorForm.Designer.cs delete mode 100644 CBNSTT/FontEditorForm.cs diff --git a/CBNSTT/AboutForm.Designer.cs b/CBNSTT/AboutForm.Designer.cs new file mode 100644 index 0000000..b8452be --- /dev/null +++ b/CBNSTT/AboutForm.Designer.cs @@ -0,0 +1,65 @@ +namespace CBNSTT +{ + partial class AboutForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutForm)); + this.aboutRichTextBox = new System.Windows.Forms.RichTextBox(); + this.SuspendLayout(); + // + // aboutRichTextBox + // + this.aboutRichTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.aboutRichTextBox.DetectUrls = false; + this.aboutRichTextBox.Location = new System.Drawing.Point(12, 12); + this.aboutRichTextBox.Name = "aboutRichTextBox"; + this.aboutRichTextBox.ReadOnly = true; + this.aboutRichTextBox.Size = new System.Drawing.Size(425, 390); + this.aboutRichTextBox.TabIndex = 0; + this.aboutRichTextBox.Text = resources.GetString("aboutRichTextBox.Text"); + // + // AboutForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.ClientSize = new System.Drawing.Size(449, 412); + this.Controls.Add(this.aboutRichTextBox); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "AboutForm"; + this.Text = "About tool"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.RichTextBox aboutRichTextBox; + } +} \ No newline at end of file diff --git a/CBNSTT/AboutForm.cs b/CBNSTT/AboutForm.cs new file mode 100644 index 0000000..bd0799a --- /dev/null +++ b/CBNSTT/AboutForm.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace CBNSTT +{ + public partial class AboutForm : Form + { + public AboutForm() + { + InitializeComponent(); + } + } +} diff --git a/CBNSTT/FontEditorForm.resx b/CBNSTT/AboutForm.resx similarity index 90% rename from CBNSTT/FontEditorForm.resx rename to CBNSTT/AboutForm.resx index 1b1035a..8d7af23 100644 --- a/CBNSTT/FontEditorForm.resx +++ b/CBNSTT/AboutForm.resx @@ -117,13 +117,17 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 177, 17 - - - 352, 17 - - - 17, 17 - + + This tool for translating game Crash Bandicoot N.Same Triology. +It can modify text files, change some textures (PVRTexToolCLI.exe will be needed), +extract and repack archives. + +If somebody made a full reasearch of fonts, you can help me with explaining or +you can modify my code on GitHub: +https://github.com/pashok6798/Crash-Bandicoot-NSAMETRIOLOGY-Tool + +Version 0.1: +First version. It has some problems with correctly work textures. +Not a full english text (sometimes you can see a russian instead english). + \ No newline at end of file diff --git a/CBNSTT/CBNSTT.csproj b/CBNSTT/CBNSTT.csproj index 4ff0480..d10855f 100644 --- a/CBNSTT/CBNSTT.csproj +++ b/CBNSTT/CBNSTT.csproj @@ -65,14 +65,14 @@ - - Component - - + Form - - FontEditorForm.cs + + AboutForm.cs + + + Component Form @@ -106,8 +106,8 @@ TextureToolForm.cs - - FontEditorForm.cs + + AboutForm.cs MainForm.cs diff --git a/CBNSTT/FontEditorForm.Designer.cs b/CBNSTT/FontEditorForm.Designer.cs deleted file mode 100644 index a26e9a4..0000000 --- a/CBNSTT/FontEditorForm.Designer.cs +++ /dev/null @@ -1,209 +0,0 @@ -namespace CBNSTT -{ - partial class FontEditorForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.textureDataGridView = new System.Windows.Forms.DataGridView(); - this.textureMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); - this.экспортироватьТекстурыPVRToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.импортироватьТекстурыPVRToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.CoordDataGridView = new System.Windows.Forms.DataGridView(); - this.coordsMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); - this.импортироватьКоординатыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.экспортироватьКоординатыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.formMenuStrip = new System.Windows.Forms.MenuStrip(); - this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.quitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - ((System.ComponentModel.ISupportInitialize)(this.textureDataGridView)).BeginInit(); - this.textureMenuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.CoordDataGridView)).BeginInit(); - this.coordsMenuStrip.SuspendLayout(); - this.formMenuStrip.SuspendLayout(); - this.SuspendLayout(); - // - // textureDataGridView - // - this.textureDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.textureDataGridView.ContextMenuStrip = this.textureMenuStrip; - this.textureDataGridView.Location = new System.Drawing.Point(12, 50); - this.textureDataGridView.Name = "textureDataGridView"; - this.textureDataGridView.RowTemplate.Height = 24; - this.textureDataGridView.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal; - this.textureDataGridView.Size = new System.Drawing.Size(523, 150); - this.textureDataGridView.TabIndex = 0; - // - // textureMenuStrip - // - this.textureMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.textureMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.экспортироватьТекстурыPVRToolStripMenuItem, - this.импортироватьТекстурыPVRToolStripMenuItem}); - this.textureMenuStrip.Name = "textureMenuStrip"; - this.textureMenuStrip.Size = new System.Drawing.Size(297, 52); - // - // экспортироватьТекстурыPVRToolStripMenuItem - // - this.экспортироватьТекстурыPVRToolStripMenuItem.Name = "экспортироватьТекстурыPVRToolStripMenuItem"; - this.экспортироватьТекстурыPVRToolStripMenuItem.Size = new System.Drawing.Size(296, 24); - this.экспортироватьТекстурыPVRToolStripMenuItem.Text = "Экспортировать текстуры (PVR)"; - this.экспортироватьТекстурыPVRToolStripMenuItem.Click += new System.EventHandler(this.экспортироватьТекстурыPVRToolStripMenuItem_Click); - // - // импортироватьТекстурыPVRToolStripMenuItem - // - this.импортироватьТекстурыPVRToolStripMenuItem.Name = "импортироватьТекстурыPVRToolStripMenuItem"; - this.импортироватьТекстурыPVRToolStripMenuItem.Size = new System.Drawing.Size(296, 24); - this.импортироватьТекстурыPVRToolStripMenuItem.Text = "Импортировать текстуры (PVR)"; - this.импортироватьТекстурыPVRToolStripMenuItem.Click += new System.EventHandler(this.импортироватьТекстурыPVRToolStripMenuItem_Click); - // - // CoordDataGridView - // - this.CoordDataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.CoordDataGridView.ContextMenuStrip = this.coordsMenuStrip; - this.CoordDataGridView.Location = new System.Drawing.Point(12, 224); - this.CoordDataGridView.Name = "CoordDataGridView"; - this.CoordDataGridView.RowTemplate.Height = 24; - this.CoordDataGridView.Size = new System.Drawing.Size(1238, 420); - this.CoordDataGridView.TabIndex = 2; - // - // coordsMenuStrip - // - this.coordsMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.coordsMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.импортироватьКоординатыToolStripMenuItem, - this.экспортироватьКоординатыToolStripMenuItem}); - this.coordsMenuStrip.Name = "coordsMenuStrip"; - this.coordsMenuStrip.Size = new System.Drawing.Size(281, 52); - // - // импортироватьКоординатыToolStripMenuItem - // - this.импортироватьКоординатыToolStripMenuItem.Name = "импортироватьКоординатыToolStripMenuItem"; - this.импортироватьКоординатыToolStripMenuItem.Size = new System.Drawing.Size(280, 24); - this.импортироватьКоординатыToolStripMenuItem.Text = "Импортировать координаты"; - this.импортироватьКоординатыToolStripMenuItem.Click += new System.EventHandler(this.импортироватьКоординатыToolStripMenuItem_Click); - // - // экспортироватьКоординатыToolStripMenuItem - // - this.экспортироватьКоординатыToolStripMenuItem.Name = "экспортироватьКоординатыToolStripMenuItem"; - this.экспортироватьКоординатыToolStripMenuItem.Size = new System.Drawing.Size(280, 24); - this.экспортироватьКоординатыToolStripMenuItem.Text = "Экспортировать координаты"; - // - // formMenuStrip - // - this.formMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.formMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.файлToolStripMenuItem}); - this.formMenuStrip.Location = new System.Drawing.Point(0, 0); - this.formMenuStrip.Name = "formMenuStrip"; - this.formMenuStrip.Size = new System.Drawing.Size(1262, 28); - this.formMenuStrip.TabIndex = 3; - this.formMenuStrip.Text = "menuStrip1"; - // - // файлToolStripMenuItem - // - this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.openToolStripMenuItem, - this.saveToolStripMenuItem, - this.saveAsToolStripMenuItem, - this.quitToolStripMenuItem}); - this.файлToolStripMenuItem.Name = "файлToolStripMenuItem"; - this.файлToolStripMenuItem.Size = new System.Drawing.Size(57, 24); - this.файлToolStripMenuItem.Text = "Файл"; - // - // openToolStripMenuItem - // - this.openToolStripMenuItem.Name = "openToolStripMenuItem"; - this.openToolStripMenuItem.Size = new System.Drawing.Size(216, 26); - this.openToolStripMenuItem.Text = "Открыть"; - this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); - // - // saveToolStripMenuItem - // - this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(216, 26); - this.saveToolStripMenuItem.Text = "Сохранить"; - // - // saveAsToolStripMenuItem - // - this.saveAsToolStripMenuItem.Name = "saveAsToolStripMenuItem"; - this.saveAsToolStripMenuItem.Size = new System.Drawing.Size(216, 26); - this.saveAsToolStripMenuItem.Text = "Сохранить как..."; - // - // quitToolStripMenuItem - // - this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; - this.quitToolStripMenuItem.Size = new System.Drawing.Size(216, 26); - this.quitToolStripMenuItem.Text = "Выйти"; - // - // FontEditorForm - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1262, 673); - this.Controls.Add(this.CoordDataGridView); - this.Controls.Add(this.textureDataGridView); - this.Controls.Add(this.formMenuStrip); - this.MainMenuStrip = this.formMenuStrip; - this.Name = "FontEditorForm"; - this.Text = "Font editor"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FontEditorForm_FormClosing); - this.Load += new System.EventHandler(this.FontEditorForm_Load); - ((System.ComponentModel.ISupportInitialize)(this.textureDataGridView)).EndInit(); - this.textureMenuStrip.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)(this.CoordDataGridView)).EndInit(); - this.coordsMenuStrip.ResumeLayout(false); - this.formMenuStrip.ResumeLayout(false); - this.formMenuStrip.PerformLayout(); - this.ResumeLayout(false); - this.PerformLayout(); - - } - - #endregion - - private System.Windows.Forms.DataGridView textureDataGridView; - private System.Windows.Forms.DataGridView CoordDataGridView; - private System.Windows.Forms.MenuStrip formMenuStrip; - private System.Windows.Forms.ToolStripMenuItem файлToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveAsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem quitToolStripMenuItem; - private System.Windows.Forms.ContextMenuStrip textureMenuStrip; - private System.Windows.Forms.ToolStripMenuItem экспортироватьТекстурыPVRToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem импортироватьТекстурыPVRToolStripMenuItem; - private System.Windows.Forms.ContextMenuStrip coordsMenuStrip; - private System.Windows.Forms.ToolStripMenuItem импортироватьКоординатыToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem экспортироватьКоординатыToolStripMenuItem; - } -} \ No newline at end of file diff --git a/CBNSTT/FontEditorForm.cs b/CBNSTT/FontEditorForm.cs deleted file mode 100644 index 87c2ef7..0000000 --- a/CBNSTT/FontEditorForm.cs +++ /dev/null @@ -1,361 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using System.IO; - -namespace CBNSTT -{ - public partial class FontEditorForm : Form - { - public FontEditorForm() - { - InitializeComponent(); - } - - Font file_font = new Font(); - bool opened_font = false; - - public class coords - { - public long one; - public long eight; - public int char_id; - public float x_offset; //float1 - public float y_offset; //float2 - public float x_advance; //float3 - public float hz_1; //float4 - public float hz_2; //float5 - public float x; //float6 - public float y; //float7 - public float coord_width; //float8 - public float coord_height; //float9 - public float end_x; //float10 - public float end_y; //float11 - - public coords() { } - - public coords(long _one, long _eight, int _char_id, float _x_offset, - float _y_offset, float _x_advance, float _hz_1, float _hz_2, float _x, - float _y, float _coord_width, float _coords_height, float _end_x, float _end_y) - { - this.one = _one; - this.eight = _eight; - this.char_id = _char_id; - this.x_offset = _x_offset; - this.y_offset = _y_offset; - this.x_advance = _x_advance; - this.hz_1 = _hz_1; - this.hz_2 = _hz_2; - this.x = _x; - this.y = _y; - this.coord_width = _coord_width; - this.coord_height = _coords_height; - this.end_x = _end_x; - this.end_y = _end_y; - } - } - - public class Textures - { - public short width; - public short height; - public int size; - public byte[] code; - public byte[] content; - - public Textures() { } - - public Textures(short _width, short _height, int _size, - byte[] _code, byte[] _content) - { - this.width = _width; - this.height = _height; - this.size = _size; - this.code = _code; - this.content = _content; - } - } - - public class Font : IDisposable - { - public List FontCoords; - public List FontTextures; - public int count; - public int[] offsets; - public int[] sizes; - public byte[] first_block; //Имеется в виду заголовок - public byte[] second_block; - public byte[] third_block; - public List sub_blocks; - - public int[] in_tex_offsets; - - public Font() - { - } - - public void Dispose() - { - /*FontCoords.Clear(); - FontTextures.Clear(); - sub_blocks.Clear();*/ - offsets = null; - sizes = null; - first_block = null; - second_block = null; - third_block = null; - } - } - - private void экспортироватьТекстурыPVRToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show("Если захочу, запилю позже"); - } - - private void импортироватьТекстурыPVRToolStripMenuItem_Click(object sender, EventArgs e) - { - MessageBox.Show("Потом"); - } - - private void импортироватьКоординатыToolStripMenuItem_Click(object sender, EventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - ofd.Filter = "FNT-coords (*.fnt) | *.fnt"; - - if (ofd.ShowDialog() == DialogResult.OK) - { - string[] strings = File.ReadAllLines(ofd.FileName); - - short width = -1; - short height = -1; - - long one = 1; - long eight = 8; - int char_id = -1; - float x = 1.0f; //float6 - float y = 1.0f; //float7 - float coord_width = 1.0f; //float8 - float coord_height = 1.0f; //float9 - float end_x = 1.0f; //float10 - float end_y = 1.0f; //float11 - float x_offset = 1.0f; //float1 - float y_offset = 1.0f; //float2 - float x_advance = 1.0f; //float3 - float hz_1 = 0.0f; //float4 - float hz_2 = 0.0f; //float5 - - bool coord = false; - int count = 0; - - for (int m = 0; m < strings.Length; m++) - { - string[] par = strings[m].Split(new char[] { ' ', '=', '\"', ',' }); - coord = false; - count = 0; - - for (int t = 0; t < par.Length; t++) - { - if (t <= par.Length - 1) - { - if (par[t] == "scaleW") - { - width = Convert.ToInt16(par[t + 1]); - } - if (par[t] == "scaleH") - { - height = Convert.ToInt16(par[t + 1]); - } - if (par[t] == "id") - { - char_id = Convert.ToInt32(par[t + 1]); - coord = true; - count++; - } - if (par[t] == "x") - { - x = Convert.ToSingle(par[t + 1]); - count++; - } - if (par[t] == "y") - { - y = Convert.ToSingle(par[t + 1]); - count++; - } - if (par[t] == "width") - { - coord_width = Convert.ToSingle(par[t + 1]); - end_x = x + coord_width; - x /= width; - end_x /= width; - count += 2; - } - if (par[t] == "height") - { - coord_height = Convert.ToSingle(par[t + 1]); - end_y = y + coord_height; - y /= height; - end_y /= height; - - count += 2; - } - if (par[t] == "xoffset") - { - x_offset = Convert.ToSingle(par[t + 1]); - count++; - } - if (par[t] == "yoffset") - { - y_offset = Convert.ToSingle(par[t + 1]); - count++; - } - if (par[t] == "xadvance") - { - x_advance = Convert.ToSingle(par[t + 1]); - count++; - } - } - } - - if(count == 10 && coord) - { - - } - } - } - } - - private void открытьToolStripMenuItem_Click(object sender, EventArgs e) - { - - - /*ofd.Filter = "IGZ (*.igz) | *.igz"; - - if (ofd.ShowDialog() == DialogResult.OK) - { - FileStream fs = new FileStream(ofd.FileName, FileMode.Open); - BinaryReader br = new BinaryReader(fs); - int offset = 16; - br.BaseStream.Seek(offset, SeekOrigin.Begin); - offset += 8; - file_font.count = br.ReadInt32(); - - br.BaseStream.Seek(8, SeekOrigin.Current); - - file_font.offsets = new int[3]; - file_font.sizes = new int[3]; - - for(int i = 0; i < 3; i++) - { - file_font.offsets[i] = br.ReadInt32(); - file_font.sizes[i] = br.ReadInt32(); - br.BaseStream.Seek(8, SeekOrigin.Current); - - offset += 16; - } - - br.BaseStream.Seek(0, SeekOrigin.Begin); - file_font.first_block = br.ReadBytes(file_font.offsets[0]); - - br.BaseStream.Seek(file_font.offsets[0], SeekOrigin.Begin); - file_font.second_block = br.ReadBytes(file_font.sizes[0]); - file_font.third_block = br.ReadBytes(file_font.sizes[1]); - - offset = 128; - - byte[] tmp = new byte[4]; - Array.Copy(file_font.third_block, offset, tmp, 0, tmp.Length); - - - br.Close(); - fs.Close(); - opened_font = true; - }*/ - } - - private void FontEditorForm_FormClosing(object sender, FormClosingEventArgs e) - { - if(!opened_font) file_font.Dispose(); - } - - private void FontEditorForm_Load(object sender, EventArgs e) - { - textureMenuStrip.Enabled = false; - coordsMenuStrip.Enabled = false; - opened_font = false; - saveToolStripMenuItem.Enabled = false; - saveAsToolStripMenuItem.Enabled = false; - } - - private void openToolStripMenuItem_Click(object sender, EventArgs e) - { - OpenFileDialog ofd = new OpenFileDialog(); - if(ofd.ShowDialog() == DialogResult.OK) - { - FileStream fs = new FileStream(ofd.FileName, FileMode.Open); - BinaryReader br = new BinaryReader(fs); - //int count = br.ReadInt32(); - //int count2 = br.ReadInt32(); - - List test = new List(); - List test2 = new List(); - List test3 = new List(); - List test4 = new List(); - - int off = 0; - - int tmp; - short tmp2; - - for(int i = 0; i < 13; i++) - { - tmp = br.ReadInt32(); - test.Add(tmp); - tmp = br.ReadInt32(); - test2.Add(tmp); - tmp = br.ReadInt32(); - test3.Add(tmp); - tmp = br.ReadInt32(); - tmp = tmp & 0x800; - test4.Add(tmp); - } - - CoordDataGridView.RowCount = 13; - CoordDataGridView.ColumnCount = 4; - - - for(int i = 0; i < CoordDataGridView.RowCount; i++) - { - CoordDataGridView[0, i].Value = test[i]; - CoordDataGridView[1, i].Value = test2[i]; - CoordDataGridView[2, i].Value = test3[i]; - CoordDataGridView[3, i].Value = test4[i]; - } - - - br.Close(); - fs.Close(); - } - - int res = 0xf194ac; - MessageBox.Show((0x80 & 0x22).ToString()); - /*SevenZip.Compression.LZMA.Encoder encode = new SevenZip.Compression.LZMA.Encoder(); - byte[] content = File.ReadAllBytes("D:\\Crash Bandicoot\\legal\\temporary\\mack\\data\\win64\\output\\packages\\generated\\ui\\legal_pkg.igz"); - //byte[] content2 = new byte[200]; - MemoryStream ms = new MemoryStream(content); - MemoryStream ms2 = new MemoryStream(); - encode.Code(ms, ms2, -1, -1, null); - content = ms2.ToArray(); - ms.Close(); - ms2.Close(); - - File.WriteAllBytes("D:\\Crash Bandicoot\\legal\\temporary\\mack\\data\\win64\\output\\packages\\generated\\ui\\legal_pkg.igz.cmp", content); - MessageBox.Show("Done");*/ - } - } -} diff --git a/CBNSTT/MainForm.Designer.cs b/CBNSTT/MainForm.Designer.cs index 30bbfd5..57a8f46 100644 --- a/CBNSTT/MainForm.Designer.cs +++ b/CBNSTT/MainForm.Designer.cs @@ -31,9 +31,9 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.PackerBtn = new System.Windows.Forms.Button(); this.TextEditBtn = new System.Windows.Forms.Button(); - this.FontEditBtn = new System.Windows.Forms.Button(); this.TextureBtn = new System.Windows.Forms.Button(); this.sndBtn = new System.Windows.Forms.Button(); + this.AboutBtn = new System.Windows.Forms.Button(); this.SuspendLayout(); // // PackerBtn @@ -56,19 +56,9 @@ private void InitializeComponent() this.TextEditBtn.UseVisualStyleBackColor = true; this.TextEditBtn.Click += new System.EventHandler(this.TextEditBtn_Click); // - // FontEditBtn - // - this.FontEditBtn.Location = new System.Drawing.Point(43, 92); - this.FontEditBtn.Name = "FontEditBtn"; - this.FontEditBtn.Size = new System.Drawing.Size(142, 23); - this.FontEditBtn.TabIndex = 2; - this.FontEditBtn.Text = "Font Editor"; - this.FontEditBtn.UseVisualStyleBackColor = true; - this.FontEditBtn.Click += new System.EventHandler(this.FontEditBtn_Click); - // // TextureBtn // - this.TextureBtn.Location = new System.Drawing.Point(235, 92); + this.TextureBtn.Location = new System.Drawing.Point(39, 91); this.TextureBtn.Name = "TextureBtn"; this.TextureBtn.Size = new System.Drawing.Size(142, 23); this.TextureBtn.TabIndex = 3; @@ -78,22 +68,32 @@ private void InitializeComponent() // // sndBtn // - this.sndBtn.Location = new System.Drawing.Point(141, 157); + this.sndBtn.Location = new System.Drawing.Point(235, 91); this.sndBtn.Name = "sndBtn"; - this.sndBtn.Size = new System.Drawing.Size(131, 23); + this.sndBtn.Size = new System.Drawing.Size(142, 23); this.sndBtn.TabIndex = 4; this.sndBtn.Text = "Sound Tool"; this.sndBtn.UseVisualStyleBackColor = true; this.sndBtn.Click += new System.EventHandler(this.sndBtn_Click); // + // AboutBtn + // + this.AboutBtn.Location = new System.Drawing.Point(148, 153); + this.AboutBtn.Name = "AboutBtn"; + this.AboutBtn.Size = new System.Drawing.Size(108, 23); + this.AboutBtn.TabIndex = 5; + this.AboutBtn.Text = "About"; + this.AboutBtn.UseVisualStyleBackColor = true; + this.AboutBtn.Click += new System.EventHandler(this.AboutBtn_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(421, 209); + this.Controls.Add(this.AboutBtn); this.Controls.Add(this.sndBtn); this.Controls.Add(this.TextureBtn); - this.Controls.Add(this.FontEditBtn); this.Controls.Add(this.TextEditBtn); this.Controls.Add(this.PackerBtn); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; @@ -110,9 +110,9 @@ private void InitializeComponent() private System.Windows.Forms.Button PackerBtn; private System.Windows.Forms.Button TextEditBtn; - private System.Windows.Forms.Button FontEditBtn; private System.Windows.Forms.Button TextureBtn; private System.Windows.Forms.Button sndBtn; + private System.Windows.Forms.Button AboutBtn; } } diff --git a/CBNSTT/MainForm.cs b/CBNSTT/MainForm.cs index 5a50197..c420d86 100644 --- a/CBNSTT/MainForm.cs +++ b/CBNSTT/MainForm.cs @@ -29,13 +29,6 @@ private void TextureBtn_Click(object sender, EventArgs e) tex_tool_form.Show(); } - private void FontEditBtn_Click(object sender, EventArgs e) - { - MessageBox.Show("Временно не работает. А может быть, никогда не заработает"); - //FontEditorForm FontEdit = new FontEditorForm(); - //FontEdit.Show(); - } - private void TextEditBtn_Click(object sender, EventArgs e) { TextEditForm txt_form = new TextEditForm(); @@ -47,5 +40,11 @@ private void sndBtn_Click(object sender, EventArgs e) SoundToolForm snd_frm = new SoundToolForm(); snd_frm.Show(); } + + private void AboutBtn_Click(object sender, EventArgs e) + { + AboutForm about = new AboutForm(); + about.Show(); + } } } diff --git a/CBNSTT/Packer_Tool_Form.Designer.cs b/CBNSTT/Packer_Tool_Form.Designer.cs index c8198ce..07dd05b 100644 --- a/CBNSTT/Packer_Tool_Form.Designer.cs +++ b/CBNSTT/Packer_Tool_Form.Designer.cs @@ -43,6 +43,7 @@ private void InitializeComponent() this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.listBox1 = new System.Windows.Forms.ListBox(); this.button3 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.SuspendLayout(); // @@ -92,7 +93,7 @@ private void InitializeComponent() // // saveBtn // - this.saveBtn.Location = new System.Drawing.Point(313, 189); + this.saveBtn.Location = new System.Drawing.Point(162, 192); this.saveBtn.Name = "saveBtn"; this.saveBtn.Size = new System.Drawing.Size(117, 23); this.saveBtn.TabIndex = 5; @@ -176,17 +177,28 @@ private void InitializeComponent() // this.button3.Location = new System.Drawing.Point(428, 45); this.button3.Name = "button3"; - this.button3.Size = new System.Drawing.Size(75, 23); + this.button3.Size = new System.Drawing.Size(165, 23); this.button3.TabIndex = 11; - this.button3.Text = "button3"; + this.button3.Text = "Тестовый репак"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // + // button4 + // + this.button4.Location = new System.Drawing.Point(348, 192); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(286, 23); + this.button4.TabIndex = 12; + this.button4.Text = "Экспортировать архивы (тест)"; + this.button4.UseVisualStyleBackColor = true; + this.button4.Click += new System.EventHandler(this.button4_Click); + // // Packer_Tool_Form // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(704, 786); + this.Controls.Add(this.button4); this.Controls.Add(this.button3); this.Controls.Add(this.listBox1); this.Controls.Add(this.progressBar1); @@ -227,5 +239,6 @@ private void InitializeComponent() private System.Windows.Forms.ProgressBar progressBar1; private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button button3; + private System.Windows.Forms.Button button4; } } \ No newline at end of file diff --git a/CBNSTT/Packer_Tool_Form.cs b/CBNSTT/Packer_Tool_Form.cs index fcde82a..96e34d3 100644 --- a/CBNSTT/Packer_Tool_Form.cs +++ b/CBNSTT/Packer_Tool_Form.cs @@ -158,6 +158,330 @@ public static void ResortTable(ref table[] table_resort) } } + //Попытка вытащить архив (тестировал на Nintendo Switch) + public string UnpackArchive(string input_path, string dir_path) + { + int num = -1; + if (!Directory.Exists(dir_path)) return "Папка не найдена. Укажите другую папку для распаковки"; + if (!File.Exists(input_path)) return "Файл не найден. Укажите правильный путь к файлу для распаковки"; + + FileStream fr = new FileStream(input_path, FileMode.Open); + BinaryReader br = new BinaryReader(fr); + + try + { + HeaderStruct head = new HeaderStruct(); + long header_offset = 0; + int new_head_offset = 0; + + head.header = br.ReadBytes(4); + header_offset += 4; + new_head_offset += 4; + head.count = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.table_size = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.file_count = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + + head.chunks_sz = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.unknown1 = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.unknown2 = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.zero1 = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.big_chunks_count = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.small_chunks_count = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.name_offset = br.ReadInt32(); + head.zero2 = br.ReadInt32(); + header_offset += 8; + new_head_offset += 8; + head.name_table_sz = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + head.one = br.ReadInt32(); + header_offset += 4; + new_head_offset += 4; + + head.IDs = new int[head.file_count]; + + int file_size = 0; + + for (int i = 0; i < head.file_count; i++) + { + head.IDs[i] = br.ReadInt32(); + file_size += 4; + } + + header_offset += (4 * head.file_count); + new_head_offset += (4 * head.file_count); + + head.file_table = new table[head.file_count]; + + for (int i = 0; i < head.file_count; i++) + { + head.file_table[i].offset = br.ReadInt32(); + head.file_table[i].order1 = br.ReadInt16(); + head.file_table[i].order2 = br.ReadInt16(); + head.file_table[i].size = br.ReadInt32(); + head.file_table[i].c_size = -1; //Пригодится, если окажется, что флаг не равен -1 + head.file_table[i].block_offset = br.ReadInt16(); + head.file_table[i].compression_flag = br.ReadInt16(); + head.file_table[i].index = i; + } + + header_offset += (16 * head.file_count); + new_head_offset += (16 * head.file_count); + file_size += (16 * head.file_count); + + head.big_chunks_table = new byte[1]; + if (head.big_chunks_count > 0) + { + head.big_chunks_table = br.ReadBytes(head.big_chunks_count * 2); + header_offset += head.big_chunks_count * 2; + } + + head.small_chunks_table = new byte[1]; + if (head.small_chunks_count > 0) + { + head.small_chunks_table = br.ReadBytes(head.small_chunks_count); + header_offset += head.small_chunks_count; + } + + head.small_chunks_count = 0; + head.big_chunks_count = 0; + head.table_size = file_size; + + int padded_off = pad_size((int)header_offset, 4); + br.BaseStream.Seek(padded_off, SeekOrigin.Begin); + + int new_size = (int)header_offset - head.small_chunks_count - (head.big_chunks_count * 2); + + //Какой-то изврат. Надо будет подумать над этим... + int padded_sz = pad_size(new_size, 4) - new_size; + byte[] tmp; + + if (padded_sz > 0) + { + tmp = new byte[padded_sz]; + header_offset += padded_sz; + } + + head.unknown_data = br.ReadBytes(24); + new_size += 24; + new_head_offset += 24; + padded_sz = pad_size(new_head_offset, 0x800) - new_head_offset; + + header_offset = pad_size(new_head_offset, 0x800); + + br.BaseStream.Seek(head.name_offset, SeekOrigin.Begin); + byte[] name_block = br.ReadBytes(head.name_table_sz); + int off = 0; + int offf = 0; + int counter = 0; + + int index = 0; + + for (int j = 0; j < head.file_count; j++) + { + tmp = new byte[4]; + counter = 0; + Array.Copy(name_block, off, tmp, 0, 4); + off += 4; + offf = BitConverter.ToInt32(tmp, 0); + + tmp = new byte[1]; + + char ch = '1'; + + tmp = new byte[name_block.Length - offf]; + Array.Copy(name_block, offf, tmp, 0, tmp.Length); + + index = 0; + + while (index < tmp.Length) + { + ch = (char)tmp[index]; + + if (ch == '\0') + { + break; + } + + index++; + counter++; + } + + tmp = new byte[counter]; + Array.Copy(name_block, offf, tmp, 0, tmp.Length); + + head.file_table[j].file_name = Encoding.ASCII.GetString(tmp); + if (head.file_table[j].file_name.Contains("/")) head.file_table[j].file_name = head.file_table[j].file_name.Replace('/', '\\'); + } + + table[] new_table = new table[head.file_count]; + + for (int i = 0; i < head.file_table.Length; i++) + { + new_table[i].offset = head.file_table[i].offset; + new_table[i].size = head.file_table[i].size; + new_table[i].c_size = head.file_table[i].c_size; + new_table[i].order1 = head.file_table[i].order1; + new_table[i].order2 = head.file_table[i].order2; + new_table[i].block_offset = head.file_table[i].block_offset; + new_table[i].compression_flag = head.file_table[i].compression_flag; + new_table[i].file_name = head.file_table[i].file_name; + new_table[i].index = head.file_table[i].index; + + if (head.file_table[i].size >= 0x40000 && head.big_chunks_count > 0) + { + int tmp_off = head.file_table[i].block_offset * 2; + int tmp_sz = (pad_size(head.file_table[i].size, 0x8000) / 0x8000) + 2; + head.file_table[i].big_chunks_data = new byte[tmp_sz]; + Array.Copy(head.big_chunks_table, tmp_off, head.file_table[i].big_chunks_data, 0, head.file_table[i].big_chunks_data.Length); + } + else head.file_table[i].big_chunks_data = null; + + new_table[i].big_chunks_data = head.file_table[i].big_chunks_data; + } + + + byte[] content; + int ch_size; + byte[] properties; + byte[] c_content; + + + //progressBar1.Minimum = 0; + //progressBar1.Maximum = new_table.Length - 1; + + //if (listBox1.Items.Count > 0) listBox1.Items.Clear(); + + for (int j = 0; j < new_table.Length; j++) + { + string pak_name = get_file_name(input_path); + pak_name = pak_name.Remove(pak_name.IndexOf('.'), pak_name.Length - pak_name.IndexOf('.')); + string dir = get_dir_path(new_table[j].file_name); + //MessageBox.Show(dir_path + "\\" + pak_name + "\\" + dir); + + if (!Directory.Exists(dir_path + "\\" + pak_name + "\\" + dir)) Directory.CreateDirectory(dir_path + "\\" + pak_name + "\\" + dir); + if (File.Exists(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name)) File.Delete(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name); + + if (new_table[j].compression_flag != -1) + { + int size = 0; + + int offset = new_table[j].offset; + int def_block = 0x8000; + + FileStream fw = new FileStream(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name, FileMode.CreateNew); + + while (size != new_table[j].size) + { + try + { + br.BaseStream.Seek(offset, SeekOrigin.Begin); + if (head.count == 11) ch_size = br.ReadInt16(); + else ch_size = br.ReadInt32(); + + if (def_block > new_table[j].size - size) def_block = new_table[j].size - size; + + properties = br.ReadBytes(5); + c_content = br.ReadBytes(ch_size); + + SevenZip.Compression.LZMA.Decoder decode = new SevenZip.Compression.LZMA.Decoder(); + decode.SetDecoderProperties(properties); + MemoryStream ms = new MemoryStream(c_content); + MemoryStream ms2 = new MemoryStream(); + decode.Code(ms, ms2, ch_size, def_block, null); + content = ms2.ToArray(); + ms.Close(); + ms2.Close(); + + fw.Write(content, 0, content.Length); + + if (head.count == 11) offset += pad_size(ch_size + 7, 0x800); + else offset += pad_size(ch_size + 9, 0x800); + + size += def_block; + + content = null; + c_content = null; + } + catch + { + if(size >= new_table[j].size) + { + if (fw != null) fw.Close(); + if (br != null) br.Close(); + if (fr != null) fr.Close(); + if (File.Exists(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name)) File.Delete(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name); + + return "Неверный формат файла в архиве " + get_file_name(pak_name); + } + else + { + br.BaseStream.Seek(offset, SeekOrigin.Begin); + def_block = 0x8000; + + if (def_block > new_table[j].size - size) def_block = new_table[j].size - size; + + content = br.ReadBytes(def_block); + fw.Write(content, 0, content.Length); + + offset += pad_size(def_block, 0x800); + size += def_block; + content = null; + } + } + } + + fw.Close(); + } + else + { + br.BaseStream.Seek(new_table[j].offset, SeekOrigin.Begin); + content = br.ReadBytes(new_table[j].size); + + FileStream fw = new FileStream(dir_path + "\\" + pak_name + "\\" + new_table[j].file_name, FileMode.CreateNew); + fw.Write(content, 0, content.Length); + fw.Close(); + content = null; + } + + //progressBar1.Value = j; + //listBox1.Items.Add((j + 1) + ". " + new_table[j].file_name); + } + + new_table = null; + head.Dispose(); + + br.Close(); + fr.Close(); + + return "Всё распаковалось охуенно!"; + } + catch + { + if (br != null) br.Close(); + if (fr != null) fr.Close(); + return "Что-то пошло не так. Последний файл был под номером " + num + 1; + } + } + //Экспериментальная версия с полной пересборкой архивов public string RepackNew(string input_path, string output_path, string dir_path) { @@ -1001,7 +1325,7 @@ public string RepackArchive(string input_path, string output_path, string dir_pa #endregion } - static public string get_file_name(string path) + public static string get_file_name(string path) { int len = path.Length - 1; @@ -1017,6 +1341,22 @@ static public string get_file_name(string path) return path; } + public static string get_dir_path(string path) + { + int len = path.Length - 1; + + while (path[len] != '\\') + { + len--; + + if (len < 0) return null; + } + + path = path.Remove(len, path.Length - len); + + return path; + } + private void button2_Click(object sender, EventArgs e) //Выбор папки с с ресурсами { FileFolderDialog fbd = new FileFolderDialog(); @@ -1205,5 +1545,73 @@ private void button3_Click(object sender, EventArgs e) } } } + + private void button4_Click(object sender, EventArgs e) + { + bool save_modal = checkBox1.Checked; + + string output_path = textBox1.Text; + + string pak_path = textBox1.Text; + + string dir_path = textBox2.Text; //Папка с ресурсами + + if (onlyOneRB.Checked) + { + if (File.Exists(pak_path) && Directory.Exists(dir_path)) + { + if (save_modal) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "PAK File | *.pak"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + output_path = sfd.FileName; + } + } + + //string result = RepackArchive(pak_path, output_path, textBox2.Text, compress, get_list); + + string result = UnpackArchive(pak_path, dir_path); + + MessageBox.Show(result); + } + } + else + { + //MessageBox.Show("Пока не работает"); + if (Directory.Exists(pak_path) && Directory.Exists(dir_path)) + { + DirectoryInfo di = new DirectoryInfo(pak_path); + FileInfo[] fi = di.GetFiles("*.pak"); + + if (fi.Length > 0) + { + progressBar1.Minimum = 0; + progressBar1.Maximum = fi.Length - 1; + + string result = ""; + + for (int i = 0; i < fi.Length; i++) + { + var Thread = new System.Threading.Thread( + () => + { + result = UnpackArchive(fi[i].FullName, dir_path); + } + ); + Thread.Start(); + Thread.Join(); + listBox1.Items.Add(result); + + progressBar1.Value = i; + } + } + else listBox1.Items.Add("Проверьте на наличие файлов pak или папок для пересборки архивов"); + + } + } + } } } diff --git a/CBNSTT/TextEditForm.Designer.cs b/CBNSTT/TextEditForm.Designer.cs index d931a3c..3deba8c 100644 --- a/CBNSTT/TextEditForm.Designer.cs +++ b/CBNSTT/TextEditForm.Designer.cs @@ -68,11 +68,11 @@ private void InitializeComponent() // removeTextCB // this.removeTextCB.AutoSize = true; - this.removeTextCB.Location = new System.Drawing.Point(348, 23); + this.removeTextCB.Location = new System.Drawing.Point(385, 24); this.removeTextCB.Name = "removeTextCB"; - this.removeTextCB.Size = new System.Drawing.Size(358, 21); + this.removeTextCB.Size = new System.Drawing.Size(231, 21); this.removeTextCB.TabIndex = 3; - this.removeTextCB.Text = "Удалить текстовые файлы после импорта текста"; + this.removeTextCB.Text = "Remove txt files after import text"; this.removeTextCB.UseVisualStyleBackColor = true; // // TextEditForm