diff --git a/ujlptr_subedit/Content/BG.xnb b/ujlptr_subedit/Content/BG.xnb index 0d26a6b..fc98750 100644 Binary files a/ujlptr_subedit/Content/BG.xnb and b/ujlptr_subedit/Content/BG.xnb differ diff --git a/ujlptr_subedit/EditorExtensions.cs b/ujlptr_subedit/EditorExtensions.cs new file mode 100644 index 0000000..c69e884 --- /dev/null +++ b/ujlptr_subedit/EditorExtensions.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ujlptr_subedit +{ + static class EditorExtensions + { + public static string ConvertTextToHex(this string text, Encoding codePage, Dictionary hexConverter = null) + { + string hex = BitConverter.ToString(codePage.GetBytes(text)).Replace("-", ""); + string outHex = ""; + + for (int i = 0; i < hex.Length / 2; i++) + { + if (hexConverter != null) + { + if (hexConverter.ContainsKey(hex.Substring(i * 2, 2))) + { + outHex += hexConverter[hex.Substring(i * 2, 2)]; + } + else + { + outHex += hex.Substring(i * 2, 2); + } + } + else + { + outHex += hex.Substring(i * 2, 2); + } + } + return outHex; + } + + public static string ConvertHexToText(this string text, Encoding codePage) + { + byte[] raw = new byte[text.Length / 2]; + for (int i = 0; i < raw.Length; i++) + { + raw[i] = Convert.ToByte(text.Substring(i * 2, 2), 16); + } + return codePage.GetString(raw); + } + + public static string ConvertTextFromPattern(this string text, Encoding codePage, Dictionary hexConverter) + { + if (hexConverter != null) + { + return text.ConvertTextToHex(codePage, hexConverter).ConvertHexToText(codePage); + } + return text; + } + + public static string GetTextFromAddress(this int address, byte[] file, Encoding codePage) + { + int count = 0; + bool StopFlag = false; + while (true) + { + if (address + count == file.Length) + { + break; + } + if (file[address + count] == 0x00) + { + StopFlag = true; + } + else if (StopFlag) + { + break; + } + count++; + } + if (count > 0) + { + count--; + } + + return codePage.GetString(file, address, count); + } + public static int GetTextLegthFromAddress(this int address, byte[] file) + { + int count = 0; + bool StopFlag = false; + while (true) + { + if (address + count == file.Length) + { + break; + } + if (file[address + count] == 0x00) + { + StopFlag = true; + } + else if (StopFlag) + { + break; + } + count++; + } + if (count > 0) + { + count--; + } + + return count; + } + } +} diff --git a/ujlptr_subedit/Group.cs b/ujlptr_subedit/Group.cs new file mode 100644 index 0000000..3e1d15d --- /dev/null +++ b/ujlptr_subedit/Group.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.ComponentModel; + +namespace ujlptr_subedit +{ + public class Group + { + public List Lines = new List(); + public int MaxChars = 0; + public int CurChars = 0; + public int TextLocation; + public bool Edit = false; + + public int UpdateCurChars() + { + CurChars = 0; + foreach (Line line in Lines) + { + CurChars += line.Text.Replace("\0", "").Length; + } + return CurChars; + } + + public Group(List pointersLocation, List pointers, List texts, int FirstCharAddress, int MaxChars) + { + TextLocation = FirstCharAddress; + this.MaxChars = MaxChars; + foreach (string text in texts) + { + CurChars += text.Replace("\0", "").Length; + } + + for (int i = 0; i < pointersLocation.Count; i++) + { + Lines.Add(new Line(pointersLocation[i], pointers[i], texts[i].Replace("\0", ""))); + } + } + } +} diff --git a/ujlptr_subedit/Line.cs b/ujlptr_subedit/Line.cs new file mode 100644 index 0000000..4e546b3 --- /dev/null +++ b/ujlptr_subedit/Line.cs @@ -0,0 +1,24 @@ +using System; + +namespace ujlptr_subedit +{ + public class Line + { + public int PointerLocation; + public string Text; + public string Time; + public string SwitchingTime; + + public Line(int pointerLocation, byte[] pointer, string text) + { + + PointerLocation = pointerLocation; + Text = text; + if (pointer.Length == 6) + { + Time = BitConverter.ToString(pointer, 3, 1).Replace("-", ""); + SwitchingTime = BitConverter.ToString(pointer, 4, 2).Replace("-", ""); + } + } + } +} diff --git a/ujlptr_subedit/MainForm.Designer.cs b/ujlptr_subedit/MainForm.Designer.cs index a82cedb..9d01552 100644 --- a/ujlptr_subedit/MainForm.Designer.cs +++ b/ujlptr_subedit/MainForm.Designer.cs @@ -80,7 +80,7 @@ private void InitializeComponent() this.StatusStrip.Location = new System.Drawing.Point(0, 570); this.StatusStrip.Name = "StatusStrip"; this.StatusStrip.ShowItemToolTips = true; - this.StatusStrip.Size = new System.Drawing.Size(1203, 22); + this.StatusStrip.Size = new System.Drawing.Size(1045, 22); this.StatusStrip.TabIndex = 3; this.StatusStrip.Text = "statusStrip1"; // @@ -121,7 +121,7 @@ private void InitializeComponent() this.MenuStrip.Location = new System.Drawing.Point(0, 0); this.MenuStrip.Name = "MenuStrip"; this.MenuStrip.ShowItemToolTips = true; - this.MenuStrip.Size = new System.Drawing.Size(1203, 24); + this.MenuStrip.Size = new System.Drawing.Size(1045, 24); this.MenuStrip.TabIndex = 4; // // FileToolStripMenuItem @@ -208,7 +208,7 @@ private void InitializeComponent() this.TextEncodingToolStripComboBox}); this.EncodingToolStripMenuItem.Enabled = false; this.EncodingToolStripMenuItem.Name = "EncodingToolStripMenuItem"; - this.EncodingToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.EncodingToolStripMenuItem.Size = new System.Drawing.Size(170, 22); this.EncodingToolStripMenuItem.Text = "&Encoding"; this.EncodingToolStripMenuItem.ToolTipText = "Setting the text encoding"; // @@ -232,7 +232,7 @@ private void InitializeComponent() this.FileDecodeOffsetToolStripComboBox}); this.FileOffsetToolStripMenuItem.Enabled = false; this.FileOffsetToolStripMenuItem.Name = "FileOffsetToolStripMenuItem"; - this.FileOffsetToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.FileOffsetToolStripMenuItem.Size = new System.Drawing.Size(170, 22); this.FileOffsetToolStripMenuItem.Text = "&FileOffset"; this.FileOffsetToolStripMenuItem.ToolTipText = "Setting the offsets for the file"; // @@ -268,7 +268,7 @@ private void InitializeComponent() this.ConversionPatternToolStripComboBox}); this.ConverterToolStripMenuItem.Enabled = false; this.ConverterToolStripMenuItem.Name = "ConverterToolStripMenuItem"; - this.ConverterToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.ConverterToolStripMenuItem.Size = new System.Drawing.Size(170, 22); this.ConverterToolStripMenuItem.Text = "&Сonverter"; this.ConverterToolStripMenuItem.ToolTipText = "Configuring the converter with a symbol"; // @@ -308,20 +308,20 @@ private void InitializeComponent() this.AdvancedModeToolStripMenuItem.CheckOnClick = true; this.AdvancedModeToolStripMenuItem.Enabled = false; this.AdvancedModeToolStripMenuItem.Name = "AdvancedModeToolStripMenuItem"; - this.AdvancedModeToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.AdvancedModeToolStripMenuItem.Size = new System.Drawing.Size(170, 22); this.AdvancedModeToolStripMenuItem.Text = "&Advanced Mode"; this.AdvancedModeToolStripMenuItem.CheckStateChanged += new System.EventHandler(this.AdvancedModeToolStripMenuItem_CheckStateChanged); // // ToolStripSeparator5 // this.ToolStripSeparator5.Name = "ToolStripSeparator5"; - this.ToolStripSeparator5.Size = new System.Drawing.Size(177, 6); + this.ToolStripSeparator5.Size = new System.Drawing.Size(167, 6); // // TextPreviewToolStripMenuItem // this.TextPreviewToolStripMenuItem.Enabled = false; this.TextPreviewToolStripMenuItem.Name = "TextPreviewToolStripMenuItem"; - this.TextPreviewToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.TextPreviewToolStripMenuItem.Size = new System.Drawing.Size(170, 22); this.TextPreviewToolStripMenuItem.Text = "TextPreview (beta)"; this.TextPreviewToolStripMenuItem.ToolTipText = "Display a preview of the text of the active window"; this.TextPreviewToolStripMenuItem.Click += new System.EventHandler(this.TextPreviewToolStripMenuItem_Click); @@ -374,18 +374,19 @@ private void InitializeComponent() // this.SearchToolStripMenuItem.Enabled = false; this.SearchToolStripMenuItem.Name = "SearchToolStripMenuItem"; - this.SearchToolStripMenuItem.Size = new System.Drawing.Size(109, 22); + this.SearchToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.SearchToolStripMenuItem.Text = "&Search"; + this.SearchToolStripMenuItem.Click += new System.EventHandler(this.SearchToolStripMenuItem_Click); // // ToolStripSeparator3 // this.ToolStripSeparator3.Name = "ToolStripSeparator3"; - this.ToolStripSeparator3.Size = new System.Drawing.Size(106, 6); + this.ToolStripSeparator3.Size = new System.Drawing.Size(177, 6); // // AboutToolStripMenuItem // this.AboutToolStripMenuItem.Name = "AboutToolStripMenuItem"; - this.AboutToolStripMenuItem.Size = new System.Drawing.Size(109, 22); + this.AboutToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.AboutToolStripMenuItem.Text = "&About"; this.AboutToolStripMenuItem.Click += new System.EventHandler(this.AboutToolStripMenuItem_Click); // @@ -404,7 +405,7 @@ private void InitializeComponent() this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1203, 592); + this.ClientSize = new System.Drawing.Size(1045, 592); this.Controls.Add(this.StatusStrip); this.Controls.Add(this.MenuStrip); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); diff --git a/ujlptr_subedit/MainForm.cs b/ujlptr_subedit/MainForm.cs index 008dbe8..da11fca 100644 --- a/ujlptr_subedit/MainForm.cs +++ b/ujlptr_subedit/MainForm.cs @@ -1,11 +1,8 @@ -using SharpDX.Direct3D9; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Windows.Forms; -using System.Windows.Input; -using ujlptr_subedit; namespace ujlptr_subedit { @@ -22,14 +19,14 @@ public MainForm() public class FileDecodeOffset { public string Name { get; set; } - public string Redion { get; set; } + public string Region { get; set; } public int FirstOffset { get; set; } public int LastOffset { get; set; } public FileDecodeOffset(string Name,string region, int FirstOffset, int LastOffset) { this.Name = Name; - this.Redion = region; + this.Region = region; this.FirstOffset = FirstOffset; this.LastOffset = LastOffset; } @@ -190,9 +187,9 @@ private void OpenFile(string file) catch(Exception e) { MessageBox.Show(e.Message, - "Error", - MessageBoxButtons.OK, - MessageBoxIcon.Error); + "Error", + MessageBoxButtons.OK, + MessageBoxIcon.Error); return; } editor.MdiParent = this; @@ -491,15 +488,6 @@ private void TextPreviewToolStripMenuItem_Click(object sender, EventArgs e) editor.TextPreview.Show(); editor.TextPreview.WindowState = FormWindowState.Normal; - - //Editor editor = ((Editor)this.ActiveMdiChild); - //string[] text = new string[1] { "54-65-73-74" }; - //text = editor.GetAllHexText(); - - //UjlTextPreview textPreview = new UjlTextPreview(text); - //textPreview.MdiParent = this; - //textPreview.Show(); - //textPreview.WindowState = FormWindowState.Normal; } } } @@ -542,5 +530,23 @@ private void AdvancedModeToolStripMenuItem_CheckStateChanged(object sender, Even } } + + private void SearchToolStripMenuItem_Click(object sender, EventArgs e) + { + if (this.MdiChildren.Length > 0 & this.ActiveMdiChild != null) + { + if (this.ActiveMdiChild.Name == "Editor") + { + Editor editor = ((Editor)this.ActiveMdiChild); + + TextSearch textSearch = new TextSearch(editor); + textSearch.Text = editor.FileName; + textSearch.MdiParent = this; + textSearch.Show(); + textSearch.WindowState = FormWindowState.Normal; + + } + } + } } } diff --git a/ujlptr_subedit/Properties/BuildInfo.cs b/ujlptr_subedit/Properties/BuildInfo.cs index 1744d00..9f7bcf9 100644 --- a/ujlptr_subedit/Properties/BuildInfo.cs +++ b/ujlptr_subedit/Properties/BuildInfo.cs @@ -8,6 +8,6 @@ internal class BuildInfo public const string Description = "Um Jammer Lammy & Parappa The Rapper Subtitle Editor"; public const string Author = "REDcat"; public const string Company = "https://github.com/RED1cat/UjlSubEdit"; - public const string Version = "3.0.0"; + public const string Version = "3.1.0"; } } diff --git a/ujlptr_subedit/TextSearch.Designer.cs b/ujlptr_subedit/TextSearch.Designer.cs new file mode 100644 index 0000000..723444c --- /dev/null +++ b/ujlptr_subedit/TextSearch.Designer.cs @@ -0,0 +1,74 @@ +namespace ujlptr_subedit +{ + partial class TextSearch + { + /// + /// 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.Search = new System.Windows.Forms.Button(); + this.TextTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // Search + // + this.Search.Location = new System.Drawing.Point(273, 12); + this.Search.Name = "Search"; + this.Search.Size = new System.Drawing.Size(75, 23); + this.Search.TabIndex = 0; + this.Search.Text = "Search"; + this.Search.UseVisualStyleBackColor = true; + this.Search.Click += new System.EventHandler(this.Search_Click); + // + // TextTextBox + // + this.TextTextBox.Location = new System.Drawing.Point(12, 12); + this.TextTextBox.Multiline = true; + this.TextTextBox.Name = "TextTextBox"; + this.TextTextBox.Size = new System.Drawing.Size(255, 57); + this.TextTextBox.TabIndex = 1; + // + // TextSearch + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(351, 75); + this.Controls.Add(this.TextTextBox); + this.Controls.Add(this.Search); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; + this.Name = "TextSearch"; + this.Text = "Search"; + this.TopMost = true; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button Search; + private System.Windows.Forms.TextBox TextTextBox; + } +} \ No newline at end of file diff --git a/ujlptr_subedit/TextSearch.cs b/ujlptr_subedit/TextSearch.cs new file mode 100644 index 0000000..4d072eb --- /dev/null +++ b/ujlptr_subedit/TextSearch.cs @@ -0,0 +1,23 @@ +using System; +using System.Windows.Forms; + +namespace ujlptr_subedit +{ + public partial class TextSearch : Form + { + private Editor Editor; + public TextSearch(Editor editor) + { + InitializeComponent(); + this.Editor = editor; + } + + private void Search_Click(object sender, EventArgs e) + { + if (TextTextBox.Text != "") + { + Editor.FindText(TextTextBox.Text); + } + } + } +} diff --git a/ujlptr_subedit/TextSearch.resx b/ujlptr_subedit/TextSearch.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/ujlptr_subedit/TextSearch.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ujlptr_subedit/UjlTextPreviewRender.cs b/ujlptr_subedit/UjlTextPreviewRender.cs index 7fdd337..cb6d002 100644 --- a/ujlptr_subedit/UjlTextPreviewRender.cs +++ b/ujlptr_subedit/UjlTextPreviewRender.cs @@ -254,7 +254,7 @@ private void LetterInit() Letters.Add("4A", new Letter(0, new Rectangle(70, 15, 10, 15), 1, new Rectangle(22, 15, 7, 15))); //J Letters.Add("6A", new Letter(1, new Rectangle(70, 30, 8, 15), 1, new Rectangle(227, 15, 5, 15))); //j Letters.Add("4B", new Letter(0, new Rectangle(80, 15, 10, 15), 1, new Rectangle(29, 15, 7, 15))); //K - Letters.Add("6B", new Letter(1, new Rectangle(78, 30, 9, 15), 0, new Rectangle(223, 15, 6, 15))); //k + Letters.Add("6B", new Letter(1, new Rectangle(78, 30, 9, 15), 0, new Rectangle(233, 15, 6, 15))); //k Letters.Add("4C", new Letter(0, new Rectangle(90, 15, 8, 15), 1, new Rectangle(37, 15, 7, 15))); //L Letters.Add("6C", new Letter(1, new Rectangle(87, 30, 7, 15), 1, new Rectangle(239, 15, 3, 15))); //l Letters.Add("4D", new Letter(0, new Rectangle(98, 15, 13, 15), 0, new Rectangle(44, 15, 11, 15))); //M diff --git a/ujlptr_subedit/editor.Designer.cs b/ujlptr_subedit/editor.Designer.cs index 519070e..48b0885 100644 --- a/ujlptr_subedit/editor.Designer.cs +++ b/ujlptr_subedit/editor.Designer.cs @@ -30,26 +30,21 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Editor)); this.ListView = new System.Windows.Forms.ListView(); + this.GroupColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.IdColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.PointerLocation = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.PointerLocationColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.MaxLenghtColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.CurrentLengthColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.TextColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.AddressInGameColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.AddressInFile = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.TimeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.SwitchingTimeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.Group = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Panel = new System.Windows.Forms.Panel(); this.SwitchingTimeTextBox = new System.Windows.Forms.TextBox(); this.SwitchingTimeLabel = new System.Windows.Forms.Label(); this.TimeLabel = new System.Windows.Forms.Label(); this.TimeTextBox = new System.Windows.Forms.TextBox(); - this.ReduceMaxSymbolOnLineButton = new System.Windows.Forms.Button(); - this.NumberSymbolsToChangeTextBox = new System.Windows.Forms.TextBox(); - this.IncreaseMaxSymbolOnLineButton = new System.Windows.Forms.Button(); this.GroupIdLabel = new System.Windows.Forms.Label(); - this.PointerLocationLabel = new System.Windows.Forms.Label(); + this.AllLengthLabel = new System.Windows.Forms.Label(); this.IdLabel = new System.Windows.Forms.Label(); this.EditButton = new System.Windows.Forms.Button(); this.MaxLengthLabel = new System.Windows.Forms.Label(); @@ -65,16 +60,14 @@ private void InitializeComponent() this.ListView.Activation = System.Windows.Forms.ItemActivation.OneClick; this.ListView.AutoArrange = false; this.ListView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.GroupColumn, this.IdColumn, - this.PointerLocation, + this.PointerLocationColumn, this.MaxLenghtColumn, this.CurrentLengthColumn, this.TextColumn, - this.AddressInGameColumn, - this.AddressInFile, this.TimeColumn, - this.SwitchingTimeColumn, - this.Group}); + this.SwitchingTimeColumn}); this.ListView.Dock = System.Windows.Forms.DockStyle.Fill; this.ListView.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ListView.FullRowSelect = true; @@ -83,22 +76,27 @@ private void InitializeComponent() this.ListView.Location = new System.Drawing.Point(0, 0); this.ListView.MultiSelect = false; this.ListView.Name = "ListView"; - this.ListView.Size = new System.Drawing.Size(1159, 478); + this.ListView.Size = new System.Drawing.Size(1025, 478); this.ListView.TabIndex = 0; this.ListView.UseCompatibleStateImageBehavior = false; this.ListView.View = System.Windows.Forms.View.Details; this.ListView.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.ListView_ItemChecked); this.ListView.ItemSelectionChanged += new System.Windows.Forms.ListViewItemSelectionChangedEventHandler(this.ListView_ItemSelectionChanged); // + // GroupColumn + // + this.GroupColumn.Text = "Group"; + this.GroupColumn.Width = 61; + // // IdColumn // this.IdColumn.Text = "Id"; this.IdColumn.Width = 52; // - // PointerLocation + // PointerLocationColumn // - this.PointerLocation.Text = "PointerLocation"; - this.PointerLocation.Width = 98; + this.PointerLocationColumn.Text = "PointerLocation"; + this.PointerLocationColumn.Width = 98; // // MaxLenghtColumn // @@ -115,16 +113,6 @@ private void InitializeComponent() this.TextColumn.Text = "Text"; this.TextColumn.Width = 474; // - // AddressInGameColumn - // - this.AddressInGameColumn.Text = "AddressInGame"; - this.AddressInGameColumn.Width = 104; - // - // AddressInFile - // - this.AddressInFile.Text = "AddressInFile"; - this.AddressInFile.Width = 93; - // // TimeColumn // this.TimeColumn.Text = "Time"; @@ -135,21 +123,14 @@ private void InitializeComponent() this.SwitchingTimeColumn.Text = "SwitchingTime"; this.SwitchingTimeColumn.Width = 99; // - // Group - // - this.Group.Text = "Group"; - // // Panel // this.Panel.Controls.Add(this.SwitchingTimeTextBox); this.Panel.Controls.Add(this.SwitchingTimeLabel); this.Panel.Controls.Add(this.TimeLabel); this.Panel.Controls.Add(this.TimeTextBox); - this.Panel.Controls.Add(this.ReduceMaxSymbolOnLineButton); - this.Panel.Controls.Add(this.NumberSymbolsToChangeTextBox); - this.Panel.Controls.Add(this.IncreaseMaxSymbolOnLineButton); this.Panel.Controls.Add(this.GroupIdLabel); - this.Panel.Controls.Add(this.PointerLocationLabel); + this.Panel.Controls.Add(this.AllLengthLabel); this.Panel.Controls.Add(this.IdLabel); this.Panel.Controls.Add(this.EditButton); this.Panel.Controls.Add(this.MaxLengthLabel); @@ -158,13 +139,13 @@ private void InitializeComponent() this.Panel.Dock = System.Windows.Forms.DockStyle.Bottom; this.Panel.Location = new System.Drawing.Point(0, 478); this.Panel.Name = "Panel"; - this.Panel.Size = new System.Drawing.Size(1159, 68); + this.Panel.Size = new System.Drawing.Size(1025, 68); this.Panel.TabIndex = 1; // // SwitchingTimeTextBox // this.SwitchingTimeTextBox.Enabled = false; - this.SwitchingTimeTextBox.Location = new System.Drawing.Point(893, 30); + this.SwitchingTimeTextBox.Location = new System.Drawing.Point(250, 30); this.SwitchingTimeTextBox.Name = "SwitchingTimeTextBox"; this.SwitchingTimeTextBox.Size = new System.Drawing.Size(66, 20); this.SwitchingTimeTextBox.TabIndex = 16; @@ -176,7 +157,7 @@ private void InitializeComponent() // this.SwitchingTimeLabel.AutoSize = true; this.SwitchingTimeLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.SwitchingTimeLabel.Location = new System.Drawing.Point(799, 31); + this.SwitchingTimeLabel.Location = new System.Drawing.Point(158, 31); this.SwitchingTimeLabel.Name = "SwitchingTimeLabel"; this.SwitchingTimeLabel.Size = new System.Drawing.Size(91, 15); this.SwitchingTimeLabel.TabIndex = 15; @@ -187,7 +168,7 @@ private void InitializeComponent() // this.TimeLabel.AutoSize = true; this.TimeLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.TimeLabel.Location = new System.Drawing.Point(799, 7); + this.TimeLabel.Location = new System.Drawing.Point(158, 8); this.TimeLabel.Name = "TimeLabel"; this.TimeLabel.Size = new System.Drawing.Size(38, 15); this.TimeLabel.TabIndex = 14; @@ -197,7 +178,7 @@ private void InitializeComponent() // TimeTextBox // this.TimeTextBox.Enabled = false; - this.TimeTextBox.Location = new System.Drawing.Point(893, 7); + this.TimeTextBox.Location = new System.Drawing.Point(250, 7); this.TimeTextBox.Name = "TimeTextBox"; this.TimeTextBox.Size = new System.Drawing.Size(66, 20); this.TimeTextBox.TabIndex = 13; @@ -205,71 +186,33 @@ private void InitializeComponent() this.TimeTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.TimeTextBox.Visible = false; // - // ReduceMaxSymbolOnLineButton - // - this.ReduceMaxSymbolOnLineButton.Enabled = false; - this.ReduceMaxSymbolOnLineButton.Location = new System.Drawing.Point(63, 28); - this.ReduceMaxSymbolOnLineButton.Name = "ReduceMaxSymbolOnLineButton"; - this.ReduceMaxSymbolOnLineButton.Size = new System.Drawing.Size(75, 23); - this.ReduceMaxSymbolOnLineButton.TabIndex = 12; - this.ReduceMaxSymbolOnLineButton.TabStop = false; - this.ReduceMaxSymbolOnLineButton.Text = "ReduceMax"; - this.ReduceMaxSymbolOnLineButton.UseVisualStyleBackColor = true; - this.ReduceMaxSymbolOnLineButton.Visible = false; - this.ReduceMaxSymbolOnLineButton.Click += new System.EventHandler(this.ChangeMaxSymbolOnLineButton_Click); - // - // NumberSymbolsToChangeTextBox - // - this.NumberSymbolsToChangeTextBox.Enabled = false; - this.NumberSymbolsToChangeTextBox.Location = new System.Drawing.Point(144, 30); - this.NumberSymbolsToChangeTextBox.Name = "NumberSymbolsToChangeTextBox"; - this.NumberSymbolsToChangeTextBox.Size = new System.Drawing.Size(66, 20); - this.NumberSymbolsToChangeTextBox.TabIndex = 11; - this.NumberSymbolsToChangeTextBox.TabStop = false; - this.NumberSymbolsToChangeTextBox.Text = "1"; - this.NumberSymbolsToChangeTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; - this.NumberSymbolsToChangeTextBox.Visible = false; - // - // IncreaseMaxSymbolOnLineButton - // - this.IncreaseMaxSymbolOnLineButton.Enabled = false; - this.IncreaseMaxSymbolOnLineButton.Location = new System.Drawing.Point(216, 28); - this.IncreaseMaxSymbolOnLineButton.Name = "IncreaseMaxSymbolOnLineButton"; - this.IncreaseMaxSymbolOnLineButton.Size = new System.Drawing.Size(75, 23); - this.IncreaseMaxSymbolOnLineButton.TabIndex = 10; - this.IncreaseMaxSymbolOnLineButton.TabStop = false; - this.IncreaseMaxSymbolOnLineButton.Text = "IncreaseMax"; - this.IncreaseMaxSymbolOnLineButton.UseVisualStyleBackColor = true; - this.IncreaseMaxSymbolOnLineButton.Visible = false; - this.IncreaseMaxSymbolOnLineButton.Click += new System.EventHandler(this.ChangeMaxSymbolOnLineButton_Click); - // // GroupIdLabel // this.GroupIdLabel.AutoSize = true; this.GroupIdLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.GroupIdLabel.Location = new System.Drawing.Point(4, 31); + this.GroupIdLabel.Location = new System.Drawing.Point(3, 8); this.GroupIdLabel.Name = "GroupIdLabel"; this.GroupIdLabel.Size = new System.Drawing.Size(51, 15); this.GroupIdLabel.TabIndex = 6; this.GroupIdLabel.Text = "GroupId"; this.GroupIdLabel.Visible = false; // - // PointerLocationLabel + // AllLengthLabel // - this.PointerLocationLabel.AutoSize = true; - this.PointerLocationLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.PointerLocationLabel.Location = new System.Drawing.Point(61, 4); - this.PointerLocationLabel.Name = "PointerLocationLabel"; - this.PointerLocationLabel.Size = new System.Drawing.Size(82, 15); - this.PointerLocationLabel.TabIndex = 5; - this.PointerLocationLabel.Text = "PointLocation"; - this.PointerLocationLabel.Visible = false; + this.AllLengthLabel.AutoSize = true; + this.AllLengthLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.AllLengthLabel.Location = new System.Drawing.Point(78, 26); + this.AllLengthLabel.Name = "AllLengthLabel"; + this.AllLengthLabel.Size = new System.Drawing.Size(58, 15); + this.AllLengthLabel.TabIndex = 5; + this.AllLengthLabel.Text = "AllLength"; + this.AllLengthLabel.Visible = false; // // IdLabel // this.IdLabel.AutoSize = true; this.IdLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.IdLabel.Location = new System.Drawing.Point(4, 4); + this.IdLabel.Location = new System.Drawing.Point(3, 26); this.IdLabel.Name = "IdLabel"; this.IdLabel.Size = new System.Drawing.Size(17, 15); this.IdLabel.TabIndex = 4; @@ -291,7 +234,7 @@ private void InitializeComponent() // this.MaxLengthLabel.AutoSize = true; this.MaxLengthLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.MaxLengthLabel.Location = new System.Drawing.Point(141, 4); + this.MaxLengthLabel.Location = new System.Drawing.Point(78, 8); this.MaxLengthLabel.Name = "MaxLengthLabel"; this.MaxLengthLabel.Size = new System.Drawing.Size(69, 15); this.MaxLengthLabel.TabIndex = 2; @@ -302,7 +245,7 @@ private void InitializeComponent() // this.LengthLabel.AutoSize = true; this.LengthLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); - this.LengthLabel.Location = new System.Drawing.Point(221, 4); + this.LengthLabel.Location = new System.Drawing.Point(78, 44); this.LengthLabel.Name = "LengthLabel"; this.LengthLabel.Size = new System.Drawing.Size(45, 15); this.LengthLabel.TabIndex = 1; @@ -329,21 +272,20 @@ private void InitializeComponent() this.panel1.Dock = System.Windows.Forms.DockStyle.Fill; this.panel1.Location = new System.Drawing.Point(0, 0); this.panel1.Name = "panel1"; - this.panel1.Size = new System.Drawing.Size(1159, 478); + this.panel1.Size = new System.Drawing.Size(1025, 478); this.panel1.TabIndex = 2; // // Editor // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1159, 546); + this.ClientSize = new System.Drawing.Size(1025, 546); this.Controls.Add(this.panel1); this.Controls.Add(this.Panel); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Editor"; this.Text = "Editor"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Editor_FormClosing); - this.SizeChanged += new System.EventHandler(this.Editor_SizeChanged); this.Panel.ResumeLayout(false); this.Panel.PerformLayout(); this.panel1.ResumeLayout(false); @@ -358,7 +300,6 @@ private void InitializeComponent() private System.Windows.Forms.ColumnHeader MaxLenghtColumn; private System.Windows.Forms.ColumnHeader CurrentLengthColumn; private System.Windows.Forms.ColumnHeader TextColumn; - private System.Windows.Forms.ColumnHeader AddressInGameColumn; private System.Windows.Forms.ColumnHeader TimeColumn; private System.Windows.Forms.ColumnHeader SwitchingTimeColumn; private System.Windows.Forms.Panel Panel; @@ -368,14 +309,10 @@ private void InitializeComponent() private System.Windows.Forms.Label LengthLabel; private System.Windows.Forms.Button EditButton; private System.Windows.Forms.Label IdLabel; - private System.Windows.Forms.ColumnHeader PointerLocation; - private System.Windows.Forms.ColumnHeader AddressInFile; - private System.Windows.Forms.Label PointerLocationLabel; - private System.Windows.Forms.ColumnHeader Group; + private System.Windows.Forms.ColumnHeader PointerLocationColumn; + private System.Windows.Forms.Label AllLengthLabel; + private System.Windows.Forms.ColumnHeader GroupColumn; private System.Windows.Forms.Label GroupIdLabel; - private System.Windows.Forms.Button IncreaseMaxSymbolOnLineButton; - private System.Windows.Forms.Button ReduceMaxSymbolOnLineButton; - private System.Windows.Forms.TextBox NumberSymbolsToChangeTextBox; private System.Windows.Forms.TextBox TimeTextBox; private System.Windows.Forms.TextBox SwitchingTimeTextBox; private System.Windows.Forms.Label SwitchingTimeLabel; diff --git a/ujlptr_subedit/editor.cs b/ujlptr_subedit/editor.cs index aa33427..a2825a3 100644 --- a/ujlptr_subedit/editor.cs +++ b/ujlptr_subedit/editor.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Drawing; -using System.IO; +using System.Linq; using System.Media; using System.Text; using System.Windows.Forms; @@ -26,6 +26,8 @@ public partial class Editor : Form private int FirstSelectedElement = 0; private bool SelectionStarted = false; + public List Groups = new List(); + public Editor(ToolStripProgressBar progressBar) { ProgressBar = progressBar; @@ -33,9 +35,14 @@ public Editor(ToolStripProgressBar progressBar) Panel.AutoScroll = true; Panel.HorizontalScroll.Enabled = false; Panel.HorizontalScroll.Visible = false; - - } + } + // 12 - 6C 8E 1D 80 87 00 00 00 DA 00 00 00 + // 4 - 6C 8E 1D 80 + // 6C 8E 1D - address + // 80 - pointer + // 87 - time + // DA 00 - switching time public void DecodeFile(int firstOffset = 0, int lastOffset = 0) { if (this.FilePath != null) @@ -49,12 +56,13 @@ public void DecodeFile(int firstOffset = 0, int lastOffset = 0) } ListView.Items.Clear(); - //this.Text = FileName; - int id = 1; - int group = 1; + Groups.Clear(); + int maxid = 0; ProgressBar.Visible = true; + List allPointsLocations = new List(); + for (int i = first; i < last; i++) { if (this.File[i] == 0x80) @@ -64,10 +72,12 @@ public void DecodeFile(int firstOffset = 0, int lastOffset = 0) if (this.File[i + 12] == 0x80 | this.File[i - 12] == 0x80) { maxid++; + allPointsLocations.Add(i - 3); } else if (this.File[i + 4] == 0x80 | this.File[i - 4] == 0x80) { maxid++; + allPointsLocations.Add(i - 3); } } } @@ -75,174 +85,130 @@ public void DecodeFile(int firstOffset = 0, int lastOffset = 0) ProgressBar.Maximum = maxid; ProgressBar.Value = 0; - for (int i = first; i < last; i++) + List pointersLocation = new List(); + List pointers = new List(); + List texts = new List(); + + foreach (int point in allPointsLocations) { - if (this.File[i] == 0x80) + byte[] address = new byte[3] { this.File[point + 2], this.File[point + 1], this.File[point] }; + int textAddressInFile = Convert.ToInt32(BitConverter.ToString(address, 0, 3).Replace("-", ""), 16) - AddressOffset; + if(textAddressInFile < 0 || textAddressInFile > this.File.Length) { - if (this.File[i + 2] == 0 & this.File[i + 3] == 0 & this.File[i + 4] == 0 & this.File[i + 7] == 0 & this.File[i + 8] == 0 || this.File[i - 1] != 0 & this.File[i - 2] != 0 & this.File[i - 3] != 0) + continue; + } + string text = textAddressInFile.GetTextFromAddress(File, CodePage); + + if (this.File[(point + 3) + 4] == 0x80 | this.File[(point + 3) - 4] == 0x80) //4 + { + pointersLocation.Add(point); + pointers.Add(new byte[3] { this.File[point + 2], this.File[point + 1], this.File[point] }); + texts.Add(text); + + if (this.File[(point + 3) + 4] != 0x80 & this.File[(point + 3) - 4] == 0x80) //end { - byte[] address = new byte[3] { this.File[i - 1], this.File[i - 2], this.File[i - 3]}; - int textaddressInFile = Convert.ToInt32(BitConverter.ToString(address, 0, 3).Replace("-", ""), 16) - AddressOffset; - int textaddressInGame = Convert.ToInt32(BitConverter.ToString(address, 0, 3).Replace("-", ""), 16); - if (textaddressInFile > 0 & textaddressInFile < this.File.Length) + int firstAdd = Convert.ToInt32(BitConverter.ToString(pointers.First(), 0, 3).Replace("-", ""), 16) - AddressOffset; + int lastAdd = (Convert.ToInt32(BitConverter.ToString(pointers.Last(), 0, 3).Replace("-", ""), 16) - AddressOffset); + lastAdd = lastAdd + lastAdd.GetTextFromAddress(File, CodePage).Length; + + if ((lastAdd - firstAdd) - texts.Count < 0) + { + lastAdd = Convert.ToInt32(BitConverter.ToString(pointers.First(), 0, 3).Replace("-", ""), 16) - AddressOffset; + lastAdd = lastAdd + lastAdd.GetTextFromAddress(File, CodePage).Length; + + firstAdd = Convert.ToInt32(BitConverter.ToString(pointers.Last(), 0, 3).Replace("-", ""), 16) - AddressOffset; + } + + if ((lastAdd - firstAdd) - texts.Count > 0) { - int count = 0; - bool StopFlag = false; - while (true) - { - if(textaddressInFile + count == this.File.Length) - { - break; - } - if (this.File[textaddressInFile + count] == 0x00) - { - StopFlag = true; - } - else if (StopFlag) - { - break; - } - count++; - } - if (count > 0) - { - count--; - } - string text = CodePage.GetString(this.File, textaddressInFile, count); - - if (this.File[i + 4] == 0x80 | this.File[i - 4] == 0x80) //4 - { - AddLineToListView(id, group, Convert.ToString(i - 3, 16), Convert.ToString(textaddressInGame, 16), Convert.ToString(textaddressInFile, 16), count, text); - id++; - ProgressBar.Value++; - - if (this.File[i + 4] != 0x80 & this.File[i - 4] == 0x80) - { - group++; - } - } - else if (this.File[i + 12] == 0x80 | this.File[i - 12] == 0x80) //12 - { - AddLineToListView(id, group, Convert.ToString(i - 3, 16), Convert.ToString(textaddressInGame, 16), Convert.ToString(textaddressInFile, 16), count, text, BitConverter.ToString(this.File, i + 1, 1), BitConverter.ToString(this.File, i + 5, 2).Replace("-", "")); - id++; - ProgressBar.Value++; - - if (this.File[i + 12] != 0x80 & this.File[i - 12] == 0x80) - { - group++; - } - } + Groups.Add(new Group(pointersLocation, pointers, texts, firstAdd, (lastAdd - firstAdd) - texts.Count)); } + + pointersLocation.Clear(); + pointers.Clear(); + texts.Clear(); } } - } - ProgressBar.Visible = false; - ListView.Items[0].Selected = true; - } - } - public void AddLineToListView(int id, int group, string pointLocation, string textLocationInGame , string textLocationInFile, int maxTextLength, string text, string time = "", string switchingTime = "") - { - ListViewItem tmpItem = ListView.Items.Add(id.ToString()); - tmpItem.SubItems.Add(pointLocation.ToString()); //pointlocation - tmpItem.SubItems.Add(maxTextLength.ToString()); //maxlength - tmpItem.SubItems.Add(text.Replace("\0", "").Length.ToString()); //curlength - tmpItem.SubItems.Add(text); //text - tmpItem.SubItems.Add(textLocationInGame); //textlocationingame - tmpItem.SubItems.Add(textLocationInFile); //textlocationinfile - tmpItem.SubItems.Add(time); //time - tmpItem.SubItems.Add(switchingTime); //switchingtime - tmpItem.SubItems.Add(group.ToString()); - } - private void ChangeMaxSymbolOnLineButton_Click(object sender, EventArgs e) - { - int count = 1; - int.TryParse(NumberSymbolsToChangeTextBox.Text, out count); - if(((Button)sender).Name == "ReduceMaxSymbolOnLineButton") - { - int group = int.Parse(ListView.SelectedItems[0].SubItems[9].Text); - int nextid = int.Parse(ListView.SelectedItems[0].SubItems[0].Text); - if (group == int.Parse(ListView.Items[nextid].SubItems[9].Text)) - { - int maxLength = int.Parse(ListView.SelectedItems[0].SubItems[2].Text) - count; - if(maxLength > 0) + else if (this.File[(point + 3) + 12] == 0x80 | this.File[(point + 3) - 12] == 0x80) //12 { - ListView.SelectedItems[0].SubItems[2].Text = maxLength.ToString(); + pointersLocation.Add(point); + pointers.Add(new byte[6] { this.File[point + 2], this.File[point + 1], this.File[point], this.File[point + 4], this.File[point + 8], this.File[point + 9] }); + texts.Add(text); - if (ListView.SelectedItems[0].SubItems[4].Text.Length > maxLength) + if (this.File[(point + 3) + 12] != 0x80 & this.File[(point + 3) - 12] == 0x80) //end { - ListView.SelectedItems[0].SubItems[4].Text = ListView.SelectedItems[0].SubItems[4].Text.Remove(maxLength); - ListView.SelectedItems[0].SubItems[3].Text = ListView.SelectedItems[0].SubItems[4].Text.Replace("\0", "").Length.ToString(); - } - ListView.SelectedItems[0].Font = new Font("Segoe UI", 9, FontStyle.Bold); + int firstAdd = Convert.ToInt32(BitConverter.ToString(pointers.First(), 0, 3).Replace("-", ""), 16) - AddressOffset; + int lastAdd = (Convert.ToInt32(BitConverter.ToString(pointers.Last(), 0, 3).Replace("-", ""), 16) - AddressOffset); + lastAdd = lastAdd + lastAdd.GetTextFromAddress(File, CodePage).Length; + + + if ((lastAdd - firstAdd) - texts.Count < 0) + { + lastAdd = Convert.ToInt32(BitConverter.ToString(pointers.First(), 0, 3).Replace("-", ""), 16) - AddressOffset; + lastAdd = lastAdd + lastAdd.GetTextFromAddress(File, CodePage).Length; - ListView.Items[nextid].SubItems[2].Text = (int.Parse(ListView.Items[nextid].SubItems[2].Text) + count).ToString(); - ListView.Items[nextid].SubItems[6].Text = Convert.ToString(Convert.ToInt32(ListView.Items[nextid].SubItems[6].Text, 16) - count, 16); - ListView.Items[nextid].SubItems[5].Text = Convert.ToString(Convert.ToInt32(ListView.Items[nextid].SubItems[5].Text, 16) - count, 16); + firstAdd = Convert.ToInt32(BitConverter.ToString(pointers.Last(), 0, 3).Replace("-", ""), 16) - AddressOffset; + } - ListView.Items[nextid].Font = new Font("Segoe UI", 9, FontStyle.Bold); + if((lastAdd - firstAdd) - texts.Count > 0) + { + Groups.Add(new Group(pointersLocation, pointers, texts, firstAdd, (lastAdd - firstAdd) - texts.Count)); + } - ListView_ItemSelectionChanged(sender, new ListViewItemSelectionChangedEventArgs(ListView.SelectedItems[0], nextid - 1, true)); - FileEdit = true; + pointersLocation.Clear(); + pointers.Clear(); + texts.Clear(); + } } + + ProgressBar.Value++; } + ProgressBar.Visible = false; + FillListView(); + ListView.Items[0].Selected = true; } - else if((((Button)sender).Name == "IncreaseMaxSymbolOnLineButton")) + } + private void FillListView() + { + for (int group = 0; group < Groups.Count; group++) { - int group = int.Parse(ListView.SelectedItems[0].SubItems[9].Text); - int nextid = int.Parse(ListView.SelectedItems[0].SubItems[0].Text); - if (group == int.Parse(ListView.Items[nextid].SubItems[9].Text)) + for (int line = 0; line < Groups[group].Lines.Count; line++) { - int maxLength = int.Parse(ListView.Items[nextid].SubItems[2].Text) - count; //next - if (int.Parse(ListView.Items[nextid].SubItems[2].Text) - count > 0) - { - ListView.Items[nextid].SubItems[2].Text = maxLength.ToString(); - - if (ListView.Items[nextid].SubItems[4].Text.Length > maxLength) - { - ListView.Items[nextid].SubItems[4].Text = ListView.Items[nextid].SubItems[4].Text.Remove(maxLength); - ListView.Items[nextid].SubItems[3].Text = ListView.Items[nextid].SubItems[4].Text.Replace("\0", "").Length.ToString(); - } - ListView.Items[nextid].SubItems[6].Text = Convert.ToString(Convert.ToInt32(ListView.Items[nextid].SubItems[6].Text, 16) + count, 16); - ListView.Items[nextid].SubItems[5].Text = Convert.ToString(Convert.ToInt32(ListView.Items[nextid].SubItems[5].Text, 16) + count, 16); - ListView.Items[nextid].Font = new Font("Segoe UI", 9, FontStyle.Bold); - - ListView.SelectedItems[0].SubItems[2].Text = (int.Parse(ListView.SelectedItems[0].SubItems[2].Text) + count).ToString(); - ListView.SelectedItems[0].Font = new Font("Segoe UI", 9, FontStyle.Bold); - - ListView_ItemSelectionChanged(sender, new ListViewItemSelectionChangedEventArgs(ListView.SelectedItems[0], nextid - 1, true)); - FileEdit = true; - } + ListViewItem tmpItem = ListView.Items.Add((group + 1).ToString()); //Group + tmpItem.SubItems.Add((line + 1).ToString()); //id + tmpItem.SubItems.Add(Convert.ToString(Groups[group].Lines[line].PointerLocation, 16)); //pointerLocation + tmpItem.SubItems.Add(Groups[group].MaxChars.ToString()); //maxlength + tmpItem.SubItems.Add(Groups[group].Lines[line].Text.Replace("\0", "").Length.ToString()); //curlength + tmpItem.SubItems.Add(Groups[group].Lines[line].Text); //text + tmpItem.SubItems.Add(Groups[group].Lines[line].Time); //time + tmpItem.SubItems.Add(Groups[group].Lines[line].SwitchingTime); //switchingtime } - } - } + private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { - if(SelectedItem != e.ItemIndex | sender.GetType().ToString() == "System.Windows.Forms.Button") + if(SelectedItem != e.ItemIndex) { EditButton.Enabled = true; TextBox.Enabled = true; - IncreaseMaxSymbolOnLineButton.Enabled = true; - ReduceMaxSymbolOnLineButton.Enabled = true; - NumberSymbolsToChangeTextBox.Enabled = true; - TextBox.Text = e.Item.SubItems[4].Text.Replace("\n", "\r\n"); + TextBox.Text = e.Item.SubItems[5].Text.Replace("\n", "\r\n"); - if(e.Item.SubItems[7].Text != "") + if(e.Item.SubItems[6].Text != "") { TimeTextBox.Enabled = true; - TimeTextBox.Text = e.Item.SubItems[7].Text; + TimeTextBox.Text = e.Item.SubItems[6].Text; } else { TimeTextBox.Text = ""; TimeTextBox.Enabled = false; } - if(e.Item.SubItems[8].Text != "") + if(e.Item.SubItems[7].Text != "") { SwitchingTimeTextBox.Enabled = true; - SwitchingTimeTextBox.Text = e.Item.SubItems[8].Text; + SwitchingTimeTextBox.Text = e.Item.SubItems[7].Text; } else { @@ -250,16 +216,16 @@ private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionC SwitchingTimeTextBox.Enabled = false; } - MaxLengthLabel.Text = $"Max:{e.Item.SubItems[2].Text}"; - IdLabel.Text = $"Id:{e.Item.SubItems[0].Text}"; - PointerLocationLabel.Text = $"Pointer:{e.Item.SubItems[1].Text}"; - GroupIdLabel.Text = $"Group:{e.Item.SubItems[9].Text}"; + MaxLengthLabel.Text = $"Max:{e.Item.SubItems[3].Text}"; + IdLabel.Text = $"Id:{e.Item.SubItems[1].Text}"; + AllLengthLabel.Text = $"CurAll:{Groups[int.Parse(e.Item.SubItems[0].Text) - 1].UpdateCurChars()}"; + GroupIdLabel.Text = $"Group:{e.Item.SubItems[0].Text}"; SelectedItem = e.ItemIndex; if (TextPreview != null) { - TextPreview.UjlTextRender.CurrentTextIndex = int.Parse(e.Item.SubItems[0].Text); + TextPreview.UjlTextRender.CurrentTextIndex = ListView.SelectedItems[0].Index; TextPreview.UjlTextRender.MaxTextIndex = ListView.Items.Count; } } @@ -267,18 +233,27 @@ private void ListView_ItemSelectionChanged(object sender, ListViewItemSelectionC private void TextBox_TextChanged(object sender, EventArgs e) { - int length = TextBox.Text.Replace("\r", "").Length; - int maxLenght = int.Parse(ListView.SelectedItems[0].SubItems[2].Text); + int groupId = int.Parse(ListView.SelectedItems[0].SubItems[0].Text) - 1; + int lineId = int.Parse(ListView.SelectedItems[0].SubItems[1].Text) - 1; + + Groups[groupId].Lines[lineId].Text = TextBox.Text.Replace("\r", ""); - LengthLabel.Text = $"Cur:{length}"; + int cur = Groups[groupId].Lines[lineId].Text.Length; + int curAll = Groups[groupId].UpdateCurChars(); - if (length > maxLenght) + LengthLabel.Text = $"Cur:{cur}"; + AllLengthLabel.Text = $"CurAll:{curAll}"; + + if (curAll > Groups[groupId].MaxChars) { - TextBox.Text = TextBox.Text.Remove(maxLenght); + int needToDell = curAll - Groups[groupId].MaxChars; + TextBox.Text = TextBox.Text.Remove(TextBox.Text.Length - needToDell); TextBox.SelectionStart = TextBox.Text.Length; SystemSounds.Exclamation.Play(); } + + if (DoCopy && TextBox.Text.Length > 0) { if(TextBox.Text[TextBox.Text.Length - 1] == '\n' && TextBox.Text[TextBox.Text.Length - 2] == '\r') @@ -288,26 +263,45 @@ private void TextBox_TextChanged(object sender, EventArgs e) DoCopy = false; } } + if(TextPreview != null) { - TextPreview.UjlTextRender.Hex = ConvertTextToHex(TextBox.Text); + TextPreview.UjlTextRender.Hex = TextBox.Text.ConvertTextToHex(codePage: CodePage); } } private void EditButton_Click(object sender, EventArgs e) { - ListView.SelectedItems[0].SubItems[4].Text = TextBox.Text.Replace("\r", ""); - ListView.SelectedItems[0].SubItems[3].Text = TextBox.Text.Replace("\r", "").Length.ToString(); - ListView.SelectedItems[0].Font = new Font("Segoe UI", 9, FontStyle.Bold); - if(SwitchingTimeTextBox.Text.Length == 4) + int groupId = int.Parse(ListView.SelectedItems[0].SubItems[0].Text) - 1; + int lineId = int.Parse(ListView.SelectedItems[0].SubItems[1].Text) - 1; + + Groups[groupId].UpdateCurChars(); + + Groups[groupId].Lines[lineId].Text = TextBox.Text.Replace("\r", ""); + ListView.SelectedItems[0].SubItems[5].Text = TextBox.Text.Replace("\r", ""); + ListView.SelectedItems[0].SubItems[4].Text = TextBox.Text.Replace("\r", "").Length.ToString(); + + if (SwitchingTimeTextBox.Text.Length == 4) { - ListView.SelectedItems[0].SubItems[8].Text = SwitchingTimeTextBox.Text; + Groups[groupId].Lines[lineId].SwitchingTime = SwitchingTimeTextBox.Text; + ListView.SelectedItems[0].SubItems[7].Text = SwitchingTimeTextBox.Text; } - if(TimeTextBox.Text.Length == 2) + if (TimeTextBox.Text.Length == 2) { - ListView.SelectedItems[0].SubItems[7].Text = TimeTextBox.Text; + Groups[groupId].Lines[lineId].Time = TimeTextBox.Text; + ListView.SelectedItems[0].SubItems[6].Text = TimeTextBox.Text; } + + Groups[groupId].Edit = true; FileEdit = true; + + foreach(ListViewItem line in ListView.Items) + { + if (line.SubItems[0].Text == (groupId + 1).ToString()) + { + line.Font = new Font("Segoe UI", 9, FontStyle.Bold); + } + } } public void SaveInFile(string filePath = "") { @@ -318,48 +312,55 @@ public void SaveInFile(string filePath = "") filePath = FilePath; } int count = 0; - foreach (ListViewItem item in ListView.Items) + + foreach(Group group in Groups) { - if (item.Font.Bold) + if (group.Edit) { - count++; + count += group.Lines.Count; } } - ProgressBar.Maximum = count + count + 1; + ProgressBar.Maximum = (count * 2) + 1; ProgressBar.Visible = true; ProgressBar.Value = 0; - foreach (ListViewItem item in ListView.Items) + + foreach(Group group in Groups) { - if (item.Font.Bold) + if (group.Edit) { - int maxLengthText = int.Parse(item.SubItems[2].Text); - string text = item.SubItems[4].Text; - int textAddress = Convert.ToInt32(item.SubItems[6].Text, 16); - int pointAddress = Convert.ToInt32(item.SubItems[1].Text, 16); - if (text.Length < maxLengthText) + int textLocation = group.TextLocation; + int maxChar = group.MaxChars + group.Lines.Count; + + for(int i = textLocation; i < textLocation + maxChar; i++) { - while (text.Length != maxLengthText) - { - text = text.Insert(text.Length, "\0"); - } + File[i] = 0x00; } - text = text.Insert(text.Length, "\0"); - - Array.Copy(CodePage.GetBytes(text), 0, File, textAddress, maxLengthText + 1); //text - File[pointAddress] = Convert.ToByte(Convert.ToInt32(item.SubItems[5].Text.Remove(0, 4), 16)); //textaddress - File[pointAddress + 1] = Convert.ToByte(Convert.ToInt32(item.SubItems[5].Text.Remove(0, 2).Remove(2), 16)); - File[pointAddress + 2] = Convert.ToByte(Convert.ToInt32(item.SubItems[5].Text.Remove(2), 16)); - if (item.SubItems[7].Text != "" & item.SubItems[8].Text != "") + foreach(Line line in group.Lines) { - File[pointAddress + 4] = Convert.ToByte(Convert.ToInt32(item.SubItems[7].Text, 16)); //time + Array.Copy(CodePage.GetBytes(line.Text), 0, File, textLocation, line.Text.Length); //text - File[pointAddress + 8] = Convert.ToByte(Convert.ToInt32(item.SubItems[8].Text.Remove(2), 16)); //switchtime - File[pointAddress + 9] = Convert.ToByte(Convert.ToInt32(item.SubItems[8].Text.Remove(0, 2), 16)); + byte[] addressInGame = BitConverter.GetBytes(textLocation + AddressOffset); //textaddress + File[line.PointerLocation] = addressInGame[0]; + File[line.PointerLocation + 1] = addressInGame[1]; + File[line.PointerLocation + 2] = addressInGame[2]; + + textLocation += line.Text.Length + 1; + + if(line.Time != "" && line.Time != null) + { + File[line.PointerLocation + 4] = Convert.ToByte(Convert.ToInt32(line.Time, 16)); //time + } + if(line.SwitchingTime != "" && line.SwitchingTime != null) + { + File[line.PointerLocation + 8] = Convert.ToByte(Convert.ToInt32(line.SwitchingTime.Remove(2), 16)); //switchtime + File[line.PointerLocation + 9] = Convert.ToByte(Convert.ToInt32(line.SwitchingTime.Remove(0, 2), 16)); + } + ProgressBar.Value++; } - ProgressBar.Value++; } } + try { System.IO.File.WriteAllBytes(filePath, File); @@ -391,9 +392,26 @@ public void SaveInFile(string filePath = "") MessageBoxButtons.OK, MessageBoxIcon.Information); } - } } + public void FindText(string text) + { + foreach(ListViewItem line in ListView.Items) + { + if (line.SubItems[5].Text.Contains(text)) + { + line.Selected = true; + line.EnsureVisible(); + SystemSounds.Exclamation.Play(); + return; + } + } + MessageBox.Show("The specified text could not be found", + text, + MessageBoxButtons.OK, + MessageBoxIcon.Information); + } + public void ConvertSelectedLines(Dictionary hexConverter) { if (hexConverter != null) @@ -402,9 +420,9 @@ public void ConvertSelectedLines(Dictionary hexConverter) { if(item.Checked == true) { - if (item.SubItems[4].Text.Replace("\0", "").Length > 0) + if (item.SubItems[5].Text.Replace("\0", "").Length > 0) { - item.SubItems[4].Text = ConvertTextFromPattern(item.SubItems[4].Text, hexConverter); + item.SubItems[5].Text = item.SubItems[5].Text.ConvertTextFromPattern(CodePage, hexConverter); item.Font = new Font("Segoe UI", 9, FontStyle.Bold); this.FileEdit = true; } @@ -416,62 +434,6 @@ public void EnableCheckboxesOnListView() { ListView.CheckBoxes = true; } - private string ConvertTextFromPattern(string text, Dictionary hexConverter) - { - if (hexConverter != null) - { - return ConvertHexToText(ConvertTextToHex(text, hexConverter)); - } - return text; - } - private string ConvertHexToText(string text) - { - byte[] raw = new byte[text.Length / 2]; - for (int i = 0; i < raw.Length; i++) - { - raw[i] = Convert.ToByte(text.Substring(i * 2, 2), 16); - } - return CodePage.GetString(raw); - } - private string ConvertTextToHex(string text, Dictionary hexConverter = null) - { - string hex = BitConverter.ToString(CodePage.GetBytes(text)).Replace("-", ""); - string outHex = ""; - - for (int i = 0; i < hex.Length / 2; i++) - { - if (hexConverter != null) - { - if(hexConverter.ContainsKey(hex.Substring(i * 2, 2))) - { - outHex += hexConverter[hex.Substring(i * 2, 2)]; - } - else - { - outHex += hex.Substring(i * 2, 2); - } - } - else - { - outHex += hex.Substring(i * 2, 2); - } - } - return outHex; - } - - public string[] GetAllHexText() - { - if(ListView.Items.Count > 0) - { - List hexs = new List(); - foreach (ListViewItem item in ListView.Items) - { - hexs.Add(ConvertTextToHex(item.SubItems[4].Text.Replace("\0", ""))); - } - return hexs.ToArray(); - } - return new string[1] { "54-65-73-74" }; - } private void Editor_FormClosing(object sender, FormClosingEventArgs e) { @@ -488,6 +450,8 @@ private void Editor_FormClosing(object sender, FormClosingEventArgs e) } else { + Groups.Clear(); + Array.Clear(File, 0, File.Length); GC.Collect(); this.Dispose(); } @@ -502,10 +466,6 @@ private void TextBox_KeyPress(object sender, KeyPressEventArgs e) } } - private void Editor_SizeChanged(object sender, EventArgs e) - { - - } private void ListView_ItemChecked(object sender, ItemCheckedEventArgs e) { @@ -549,17 +509,13 @@ public void ChangeMode() { IdLabel.Visible = true; GroupIdLabel.Visible = true; - PointerLocationLabel.Visible = true; + AllLengthLabel.Visible = true; MaxLengthLabel.Visible = true; LengthLabel.Visible = true; - IncreaseMaxSymbolOnLineButton.Visible = true; - ReduceMaxSymbolOnLineButton.Visible = true; - NumberSymbolsToChangeTextBox.Visible = true; TimeLabel.Visible = true; SwitchingTimeLabel.Visible = true; SwitchingTimeTextBox.Visible = true; TimeTextBox.Visible = true; - EditButton.Location = new Point(965, 23); AdvancedMode = true; } @@ -567,17 +523,13 @@ public void ChangeMode() { IdLabel.Visible = false; GroupIdLabel.Visible = false; - PointerLocationLabel.Visible = false; + AllLengthLabel.Visible = false; MaxLengthLabel.Visible = false; LengthLabel.Visible = false; - IncreaseMaxSymbolOnLineButton.Visible = false; - ReduceMaxSymbolOnLineButton.Visible = false; - NumberSymbolsToChangeTextBox.Visible = false; TimeLabel.Visible = false; SwitchingTimeLabel.Visible = false; SwitchingTimeTextBox.Visible = false; TimeTextBox.Visible = false; - EditButton.Location = new Point(799, 23); AdvancedMode = false; } diff --git a/ujlptr_subedit/ujlptr_subedit.csproj b/ujlptr_subedit/ujlptr_subedit.csproj index 4eb6ad7..74fa516 100644 --- a/ujlptr_subedit/ujlptr_subedit.csproj +++ b/ujlptr_subedit/ujlptr_subedit.csproj @@ -265,6 +265,9 @@ Editor.cs + + + Form @@ -279,6 +282,12 @@ True Resources.resx + + Form + + + TextSearch.cs + Form @@ -303,6 +312,9 @@ Designer Resources.Designer.cs + + TextSearch.cs + UjlTextPreview.cs