diff --git a/UE4localizationsTool/Core/StructProperty.cs b/UE4localizationsTool/Core/StructProperty.cs index 35b8142..527961e 100644 --- a/UE4localizationsTool/Core/StructProperty.cs +++ b/UE4localizationsTool/Core/StructProperty.cs @@ -6,19 +6,27 @@ namespace AssetParser { public class StructProperty { - - public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, bool Modify = false) + public Uexp uexp; + public StructProperty(MemoryList memoryList, Uexp Uexp, bool FromStruct = true, bool Modify = false) { - + uexp = Uexp; while (memoryList.GetPosition() < memoryList.GetSize()) { - - string PropertyName = uexp.UassetData.GetPropertyName(memoryList.GetIntValue()); - memoryList.Skip(4);//null or something + + long PropertyNameC = memoryList.GetInt64Value(); + // Console.WriteLine($"PropertyNameC- {PropertyNameC} > "+ memoryList.GetPosition()); + if (PropertyNameC > uexp.UassetData.Number_of_Names) + { + memoryList.Skip(-4); + continue; + } + + string PropertyName = uexp.UassetData.GetPropertyName((int)PropertyNameC); if (PropertyName == "None") { break; } + string Property = uexp.UassetData.GetPropertyName(memoryList.GetIntValue()); memoryList.Skip(4);//null or something int ThisPosition = memoryList.GetPosition(); @@ -26,9 +34,9 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, memoryList.Skip(4);//null Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"PropertyName-> " + PropertyName); - Console.WriteLine("Property-> " + Property); - Console.WriteLine("PropertyLength-> " + PropertyLength); + // Console.WriteLine($"PropertyName-> " + PropertyName); + // Console.WriteLine("Property-> " + Property); + // Console.WriteLine("PropertyLength-> " + PropertyLength); Console.ForegroundColor = ConsoleColor.White; if (Property == "MapProperty") @@ -48,7 +56,7 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, int MapCount = MapData.GetIntValue(); //Console.WriteLine("MapCount-> " + MapCount); Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("MapProperty"); + // Console.WriteLine("MapProperty"); Console.ForegroundColor = ConsoleColor.White; try { @@ -58,19 +66,19 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, { MapData.Skip(4);//null or something } - Console.WriteLine("Mapindex-> " + Mapindex); - Console.WriteLine("MapKey-> " + MapKey); - Console.WriteLine("MapValue-> " + MapValue); + // Console.WriteLine("Mapindex-> " + Mapindex); + // Console.WriteLine("MapKey-> " + MapKey); + // Console.WriteLine("MapValue-> " + MapValue); PropertyParser(PropertyName, MapKey, -1, MapData, uexp, Modify); PropertyParser(PropertyName, MapValue, -1, MapData, uexp, Modify); } } catch { - + uexp.IsGood = false; } Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("EndMapProperty"); + // Console.WriteLine("EndMapProperty"); Console.ForegroundColor = ConsoleColor.White; if (Modify) { @@ -81,8 +89,12 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, } else if (Property == "ArrayProperty") { + Console.ForegroundColor = ConsoleColor.Yellow; + // Console.WriteLine("ArrayProperty"); + Console.ForegroundColor = ConsoleColor.White; string ArrayType = uexp.UassetData.GetPropertyName(memoryList.GetIntValue()); memoryList.Skip(4);//null or something + // Console.WriteLine("ArrayType-> " + ArrayType); if (FromStruct) { memoryList.Skip(1); //null For "Struct" @@ -99,15 +111,18 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, if (ArrayType == "StructProperty") { string ArrayName /*?*/ = uexp.UassetData.GetPropertyName(ArrayData.GetIntValue()); + // Console.WriteLine("ArrayName-> " + ArrayName); ArrayData.Skip(12); //null bytes int StructLength = ArrayData.GetIntValue(); ArrayData.Skip(4); //null or something string StructType = uexp.UassetData.GetPropertyName(ArrayData.GetIntValue()); + // Console.WriteLine("ArrayStructType-> " + StructType); ArrayData.Skip(20); //Unkown bytes if (FromStruct) { ArrayData.Skip(1); //null For "Struct" } + for (int Arrayindex = 0; Arrayindex < ArrayCount; Arrayindex++) { PropertyParser(PropertyName, StructType, -1, ArrayData, uexp, Modify); @@ -123,7 +138,7 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, } catch { - + uexp.IsGood = false; } if (Modify) { @@ -131,11 +146,14 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, memoryList.Seek(ArrayPosition + ArrayData.GetSize()); memoryList.SetIntValue(ArrayData.GetSize(), false, ThisPosition); } + Console.ForegroundColor = ConsoleColor.Yellow; + // Console.WriteLine("EndArrayProperty"); + Console.ForegroundColor = ConsoleColor.White; } else if (Property == "StructProperty") { string StructType = uexp.UassetData.GetPropertyName(memoryList.GetIntValue()); - Console.WriteLine("StructType-> " + StructType); + // Console.WriteLine("StructType-> " + StructType); memoryList.Skip(4); //null or something memoryList.Skip(16); //null bytes if (FromStruct) @@ -143,6 +161,13 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, memoryList.Skip(1); //null For "Struct" } + + if (StructType == "MovieSceneEvalTemplatePtr" || StructType == "MovieSceneTrackImplementationPtr") + { + PropertyParser(PropertyName, StructType, PropertyLength, memoryList, uexp, Modify); + continue; + } + int StructPosition = memoryList.GetPosition(); MemoryList StructData = new MemoryList(memoryList.GetBytes(PropertyLength)); if (StructData.GetSize() <= 4) @@ -150,8 +175,9 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, continue; } - if (StructType != "Box" + if (StructType != "ActorReference" && StructType != "Box2D" + && StructType != "Box" && StructType != "BoxSphereBounds" && StructType != "Color" && StructType != "ColorMaterialInput" @@ -169,8 +195,9 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, && StructType != "IntPoint" && StructType != "IntVector" && StructType != "ItemsBitArray" + && StructType != "LevelSequenceObjectReferenceMap" && StructType != "LinearColor" - && StructType != "MovieSceneEvaluationFieldEntityTree" + && StructType != "MaterialAttributesInput" && StructType != "MovieSceneEvaluationKey" && StructType != "MovieSceneEvaluationTree" && StructType != "MovieSceneEvaluationTreeNode" @@ -181,28 +208,45 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, && StructType != "MovieSceneSegment" && StructType != "MovieSceneSegmentIdentifier" && StructType != "MovieSceneSequenceID" + && StructType != "MovieSceneSubSequenceTree" && StructType != "MovieSceneTangentData" && StructType != "MovieSceneTrackIdentifier" - && StructType != "MovieSceneTrackImplementationPtr" + && StructType != "NavAgentSelector" + && StructType != "PerPlatformBool" && StructType != "PerPlatformFloat" + && StructType != "PerPlatformInt" + && StructType != "PerQualityLevelInt" && StructType != "Plane" && StructType != "PointerToUberGraphFrame" && StructType != "Quat" && StructType != "RichCurveKey" && StructType != "Rotator" - && StructType != "ScalarMaterialInput" && StructType != "SHAHash" + && StructType != "ScalarMaterialInput" + && StructType != "SectionEvaluationDataTree" + && StructType != "ShadingModelMaterialInput" + && StructType != "SimpleCurveKey" + && StructType != "SkeletalMeshSamplingLODBuiltData" + && StructType != "SkeletalMeshSamplingRegionBuiltData" + && StructType != "SmartName" && StructType != "SoftClassPath" + && StructType != "SoftObjectPath" && StructType != "Sphere" && StructType != "StringAssetReference" + && StructType != "StringClassReference" && StructType != "Table" && StructType != "Timespan" && StructType != "Transform" && StructType != "UInt128" - && StructType != "Vector" && StructType != "Vector2D" + && StructType != "Vector2MaterialInput" && StructType != "Vector4" + && StructType != "Vector" && StructType != "VectorMaterialInput" + && StructType != "Vector_NetQuantize10" + && StructType != "Vector_NetQuantize100" + && StructType != "Vector_NetQuantize" + && StructType != "Vector_NetQuantizeNormal" && StructType != "ViewTargetBlendParams") { try @@ -211,6 +255,7 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, } catch { + uexp.IsGood = false; } } @@ -347,7 +392,7 @@ public StructProperty(MemoryList memoryList, Uexp uexp, bool FromStruct = true, } - private void PropertyParser(string PropertyName, string Property, int PropertyLength, MemoryList memoryList, Uexp uexp, bool Modify = false) + private void PropertyParser(string PropertyName, string Property, int PropertyLength, MemoryList memoryList, Uexp Uexp, bool Modify = false) { if (Property == "Int8Property") { @@ -450,7 +495,7 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe int MapCount = memoryList.GetIntValue(); //Console.WriteLine("MapCount-> " + MapCount); Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("MapProperty"); + // Console.WriteLine("MapProperty2"); Console.ForegroundColor = ConsoleColor.White; try { @@ -460,19 +505,20 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe { memoryList.Skip(4);//null or something } - Console.WriteLine("Mapindex-> " + Mapindex); - Console.WriteLine("MapKey-> " + MapKey); - Console.WriteLine("MapValue-> " + MapValue); + // Console.WriteLine("Mapindex2-> " + Mapindex); + // Console.WriteLine("MapKey2-> " + MapKey); + // Console.WriteLine("MapValue2-> " + MapValue); PropertyParser(PropertyName, MapKey, -1, memoryList, uexp, Modify); PropertyParser(PropertyName, MapValue, -1, memoryList, uexp, Modify); + } } catch { - + uexp.IsGood = false; } Console.ForegroundColor = ConsoleColor.Blue; - Console.WriteLine("EndMapProperty"); + // Console.WriteLine("EndMapProperty2"); Console.ForegroundColor = ConsoleColor.White; } else if (Property == "FieldPathProperty") @@ -547,11 +593,10 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe if (!Modify) { uexp.Strings.Add(new List() { PropertyName, memoryList.GetStringUE() }); - Console.WriteLine(uexp.Strings[uexp.Strings.Count - 1][1]); + // Console.WriteLine(uexp.Strings[uexp.Strings.Count - 1][1]); } else { - //memoryList.GetStringUE(); memoryList.ReplaceStringUE(uexp.Strings[uexp.CurrentIndex][1]); uexp.CurrentIndex++; } @@ -599,15 +644,65 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe else if (Property == "StructProperty") { Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("StructProperty"); + // Console.WriteLine("StructProperty->" + memoryList.GetPosition()); Console.ForegroundColor = ConsoleColor.White; new StructProperty(memoryList, uexp, true, Modify); Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("EndStructProperty"); + // Console.WriteLine("EndStructProperty->" + memoryList.GetPosition()); Console.ForegroundColor = ConsoleColor.White; } + //For StructProperty + else if (Property == "FrameNumber") + { + memoryList.Skip(4); + } + else if (Property == "MovieSceneEvalTemplatePtr") + { + + if (memoryList.GetStringUE().Length > 0) + { + + try + { + // Console.WriteLine("MovieSceneEvalTemplatePtr--> StructProperty"); + new StructProperty(memoryList, uexp, true, Modify); + // Console.WriteLine("MovieSceneEvalTemplatePtr--> EndStructProperty"); + } + catch + { + uexp.IsGood = false; + } + } + } + else if (Property == "MovieSceneTrackImplementationPtr") + { + //Console.ReadLine() + // Console.WriteLine("StartMovieSceneEvalTemplatePtrLength->"+PropertyLength); + if (memoryList.GetStringUE().Length > 0|| PropertyLength>0) + { + // Console.WriteLine("StartMovieSceneEvalTemplatePtr"); + try + { + Console.ForegroundColor = ConsoleColor.DarkYellow; + // Console.WriteLine("MovieSceneEvalTemplatePtr--> StructProperty"); + new StructProperty(memoryList, uexp, true, Modify); + // Console.WriteLine("MovieSceneEvalTemplatePtr--> EndStructProperty"); + Console.ForegroundColor = ConsoleColor.White; + } + catch + { + uexp.IsGood = false; + } + memoryList.Skip(4); //ImplementationPtr Index + Console.ForegroundColor = ConsoleColor.DarkYellow; + // Console.WriteLine("EndStartMovieSceneEvalTemplatePtr"); + Console.ForegroundColor = ConsoleColor.White; + } + } + + else { new StructProperty(memoryList, uexp, true, Modify); diff --git a/UE4localizationsTool/Core/Uasset.cs b/UE4localizationsTool/Core/Uasset.cs index c23577d..7f2eab7 100644 --- a/UE4localizationsTool/Core/Uasset.cs +++ b/UE4localizationsTool/Core/Uasset.cs @@ -216,7 +216,7 @@ public void UpdateExport() UassetFile.Skip(4 * 6); UassetFile.Skip(2 * 2); UassetFile.SetIntValue(Exports_Directory[n].ExportData.Count); - Console.WriteLine(Exports_Directory[n].ExportData.Count); + // Console.WriteLine(Exports_Directory[n].ExportData.Count); int NullIntsize = 0; if (UassetFile.GetIntValue(false) == 0) { diff --git a/UE4localizationsTool/Core/Uexp.cs b/UE4localizationsTool/Core/Uexp.cs index d1d230d..8f03cad 100644 --- a/UE4localizationsTool/Core/Uexp.cs +++ b/UE4localizationsTool/Core/Uexp.cs @@ -6,20 +6,11 @@ namespace AssetParser { public class Uexp { - public struct TextBlock - { - public int TextBlockName { get; set; } - public int TextOffset { get; set; } - public int TextBlockSize { get; set; } - //TextLenght + String Value - public List TextBlockData { get; set; } - } - public Uasset UassetData; public List> Strings; //[Text id,Text Value,...] private int _CurrentIndex; - + public bool IsGood = true; public int CurrentIndex { get @@ -49,6 +40,11 @@ private void ReadOrEdit(bool Modify = false) for (int n = 0; n < UassetData.Exports_Directory.Count; n++) { + + + // Console.Clear(); + // Console.ReadLine(); + using (MemoryList memoryList = new MemoryList(UassetData.Exports_Directory[n].ExportData)) { @@ -56,11 +52,11 @@ private void ReadOrEdit(bool Modify = false) //no need for now Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"-----------{n}------------"); + // Console.WriteLine($"-----------{n}------------"); Console.ForegroundColor = ConsoleColor.White; _ = new StructProperty(memoryList, this, true, Modify); Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"-----------End------------"); + // Console.WriteLine($"-----------End------------"); Console.ForegroundColor = ConsoleColor.White; switch (UassetData.GetExportPropertyName(UassetData.Exports_Directory[n].ExportClass)) @@ -78,6 +74,8 @@ private void ReadOrEdit(bool Modify = false) break; } } + + //Console.ReadLine(); } diff --git a/UE4localizationsTool/Core/locres.cs b/UE4localizationsTool/Core/locres.cs index de9b000..8726a19 100644 --- a/UE4localizationsTool/Core/locres.cs +++ b/UE4localizationsTool/Core/locres.cs @@ -49,11 +49,11 @@ private void ReadOrEdit(bool Modify = false) throw new Exception("Unsupported locres version"); } - Console.WriteLine(Version); + // Console.WriteLine(Version); if (Version >= LocresVersion.Compact) { - Console.WriteLine("Compact"); + // Console.WriteLine("Compact"); int localizedStringOffset = (int)locresData.GetInt64Value(); locresData.Seek(localizedStringOffset); @@ -119,7 +119,7 @@ private void ReadOrEdit(bool Modify = false) { locresData.GetStringUE(); //string hash locresData.Skip(4); //Unkown - Strings.Add(new List() { Strings.Count.ToString(), locresData.GetStringUE() }); + locresData.ReplaceStringUE(Strings[CurrentIndex][1]); CurrentIndex++; } } diff --git a/UE4localizationsTool/FrmMain.Designer.cs b/UE4localizationsTool/FrmMain.Designer.cs index ba98d45..49d5c56 100644 --- a/UE4localizationsTool/FrmMain.Designer.cs +++ b/UE4localizationsTool/FrmMain.Designer.cs @@ -43,12 +43,16 @@ private void InitializeComponent() this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.search = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.undoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.redoToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.copyToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.pasteToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); this.fontToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.rightToLeftToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.commandLinesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.aboutToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.TextName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.TextValue = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -61,6 +65,7 @@ private void InitializeComponent() this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.copyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.pasteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.StateLabel = new System.Windows.Forms.Label(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SearchPanal.SuspendLayout(); @@ -122,6 +127,8 @@ private void InitializeComponent() this.toolStripSeparator1, this.search, this.toolStripSeparator2, + this.undoToolStripMenuItem, + this.redoToolStripMenuItem, this.copyToolStripMenuItem1, this.pasteToolStripMenuItem1, this.toolStripSeparator3, @@ -165,9 +172,27 @@ private void InitializeComponent() this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Size = new System.Drawing.Size(183, 6); // + // undoToolStripMenuItem + // + this.undoToolStripMenuItem.Name = "undoToolStripMenuItem"; + this.undoToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Z))); + this.undoToolStripMenuItem.Size = new System.Drawing.Size(186, 22); + this.undoToolStripMenuItem.Text = "Undo"; + this.undoToolStripMenuItem.Click += new System.EventHandler(this.undoToolStripMenuItem_Click); + // + // redoToolStripMenuItem + // + this.redoToolStripMenuItem.Name = "redoToolStripMenuItem"; + this.redoToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) + | System.Windows.Forms.Keys.Z))); + this.redoToolStripMenuItem.Size = new System.Drawing.Size(186, 22); + this.redoToolStripMenuItem.Text = "Redo"; + this.redoToolStripMenuItem.Click += new System.EventHandler(this.redoToolStripMenuItem_Click); + // // copyToolStripMenuItem1 // this.copyToolStripMenuItem1.Name = "copyToolStripMenuItem1"; + this.copyToolStripMenuItem1.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.C))); this.copyToolStripMenuItem1.Size = new System.Drawing.Size(186, 22); this.copyToolStripMenuItem1.Text = "Copy"; this.copyToolStripMenuItem1.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); @@ -175,6 +200,7 @@ private void InitializeComponent() // pasteToolStripMenuItem1 // this.pasteToolStripMenuItem1.Name = "pasteToolStripMenuItem1"; + this.pasteToolStripMenuItem1.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.V))); this.pasteToolStripMenuItem1.Size = new System.Drawing.Size(186, 22); this.pasteToolStripMenuItem1.Text = "Paste"; this.pasteToolStripMenuItem1.Click += new System.EventHandler(this.pasteToolStripMenuItem_Click); @@ -200,10 +226,26 @@ private void InitializeComponent() // // aboutToolStripMenuItem // + this.aboutToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.commandLinesToolStripMenuItem, + this.aboutToolStripMenuItem1}); this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; this.aboutToolStripMenuItem.Size = new System.Drawing.Size(52, 20); this.aboutToolStripMenuItem.Text = "About"; - this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); + // + // commandLinesToolStripMenuItem + // + this.commandLinesToolStripMenuItem.Name = "commandLinesToolStripMenuItem"; + this.commandLinesToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.commandLinesToolStripMenuItem.Text = "Command Lines"; + this.commandLinesToolStripMenuItem.Click += new System.EventHandler(this.commandLinesToolStripMenuItem_Click); + // + // aboutToolStripMenuItem1 + // + this.aboutToolStripMenuItem1.Name = "aboutToolStripMenuItem1"; + this.aboutToolStripMenuItem1.Size = new System.Drawing.Size(180, 22); + this.aboutToolStripMenuItem1.Text = "About"; + this.aboutToolStripMenuItem1.Click += new System.EventHandler(this.aboutToolStripMenuItem1_Click); // // dataGridView1 // @@ -228,6 +270,7 @@ private void InitializeComponent() this.dataGridView1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.dataGridView1.Size = new System.Drawing.Size(689, 423); this.dataGridView1.TabIndex = 1; + this.dataGridView1.CellBeginEdit += new System.Windows.Forms.DataGridViewCellCancelEventHandler(this.dataGridView1_CellBeginEdit); this.dataGridView1.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged); this.dataGridView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView1_KeyDown); this.dataGridView1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.dataGridView1_MouseDown); @@ -336,12 +379,23 @@ private void InitializeComponent() this.pasteToolStripMenuItem.Text = "Paste"; this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Click); // + // StateLabel + // + this.StateLabel.AutoSize = true; + this.StateLabel.Location = new System.Drawing.Point(193, 3); + this.StateLabel.Name = "StateLabel"; + this.StateLabel.Size = new System.Drawing.Size(64, 13); + this.StateLabel.TabIndex = 3; + this.StateLabel.Tag = ""; + this.StateLabel.Text = "-------------------"; + // // FrmMain // this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(689, 450); + this.Controls.Add(this.StateLabel); this.Controls.Add(this.SearchPanal); this.Controls.Add(this.dataGridView1); this.Controls.Add(this.menuStrip1); @@ -391,6 +445,11 @@ private void InitializeComponent() private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; private System.Windows.Forms.ToolStripMenuItem fontToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem rightToLeftToolStripMenuItem; + private System.Windows.Forms.Label StateLabel; + private System.Windows.Forms.ToolStripMenuItem undoToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem redoToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem commandLinesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem1; } } diff --git a/UE4localizationsTool/FrmMain.cs b/UE4localizationsTool/FrmMain.cs index 958d8b5..c2aba08 100644 --- a/UE4localizationsTool/FrmMain.cs +++ b/UE4localizationsTool/FrmMain.cs @@ -9,13 +9,24 @@ namespace UE4localizationsTool { public partial class FrmMain : Form { + struct DataRow + { + public int Index; + public string StringValue; + } + + Uasset Uasset; Uexp Uexp; locres locres; - String ToolName = Application.ProductName + " v" + Application.ProductVersion; string FilePath = ""; FrmState state; + Stack BackupDataUndo; + Stack BackupDataRedo; + int BackupDataIndex = 0; + + public FrmMain() { InitializeComponent(); @@ -23,12 +34,17 @@ public FrmMain() saveToolStripMenuItem.Enabled = false; exportAllTextToolStripMenuItem.Enabled = false; importAllTextToolStripMenuItem.Enabled = false; + undoToolStripMenuItem.Enabled = false; + redoToolStripMenuItem.Enabled = false; + StateLabel.Text = ""; + BackupDataUndo = new Stack(); + BackupDataRedo = new Stack(); } private void AddToDataView(List> strings) { + int Index = 0; - foreach (var item in strings) { dataGridView1.Rows.Add(item[0], item[1]); @@ -59,8 +75,13 @@ private async void LoadFile(string filePath) saveToolStripMenuItem.Enabled = false; exportAllTextToolStripMenuItem.Enabled = false; importAllTextToolStripMenuItem.Enabled = false; + undoToolStripMenuItem.Enabled = false; + redoToolStripMenuItem.Enabled = false; FilePath = ""; + StateLabel.Text = ""; this.Text = ToolName; + BackupDataUndo = new Stack(); + BackupDataRedo = new Stack(); try { state = new FrmState(this, "loading File", "loading File please wait..."); @@ -72,11 +93,7 @@ private async void LoadFile(string filePath) locres = await Task.Run(() => new locres(filePath)); AddToDataView(locres.Strings); - saveToolStripMenuItem.Enabled = true; - exportAllTextToolStripMenuItem.Enabled = true; - importAllTextToolStripMenuItem.Enabled = true; - FilePath = filePath; - this.Text = ToolName + " - " + Path.GetFileName(FilePath); + } else if (filePath.ToLower().EndsWith(".uasset")) { @@ -84,12 +101,19 @@ private async void LoadFile(string filePath) Uexp = await Task.Run(() => new Uexp(Uasset)); AddToDataView(Uexp.Strings); - saveToolStripMenuItem.Enabled = true; - exportAllTextToolStripMenuItem.Enabled = true; - importAllTextToolStripMenuItem.Enabled = true; - FilePath = filePath; - this.Text = ToolName + " - " + Path.GetFileName(FilePath); + if (!Uexp.IsGood) + { + StateLabel.Text = "Warning: This file is't fully parsed and may not contain some text."; + } + } + undoToolStripMenuItem.Enabled = true; + redoToolStripMenuItem.Enabled = true; + saveToolStripMenuItem.Enabled = true; + exportAllTextToolStripMenuItem.Enabled = true; + importAllTextToolStripMenuItem.Enabled = true; + FilePath = filePath; + this.Text = ToolName + " - " + Path.GetFileName(FilePath); state.Close(); } catch (Exception ex) @@ -183,26 +207,18 @@ private async void SaveFile(object sender, EventArgs e) { try { - state = new FrmState(this, "Saving File", "Saving File please wait..."); - this.BeginInvoke(new Action(() => state.ShowDialog())); - if (FilePath.ToLower().EndsWith(".locres")) - { - //for (int i = 0; i < dataGridView1.Rows.Count; i++) - //{ - // locres.Strings[i][1] = dataGridView1.Rows[i].Cells[1].Value != null ? dataGridView1.Rows[i].Cells[1].Value.ToString() : ""; - //} - await Task.Run(() => locres.SaveFile(sfd.FileName)); - - } - else if (FilePath.ToLower().EndsWith(".uasset")) - { - - //for (int i = 0; i < dataGridView1.Rows.Count; i++) - //{ - // Uexp.Strings[i][1] = dataGridView1.Rows[i].Cells[1].Value != null ? dataGridView1.Rows[i].Cells[1].Value.ToString() : ""; - //} - await Task.Run(() => Uexp.SaveFile(sfd.FileName)); - } + state = new FrmState(this, "Saving File", "Saving File please wait..."); + this.BeginInvoke(new Action(() => state.ShowDialog())); + if (FilePath.ToLower().EndsWith(".locres")) + { + await Task.Run(() => locres.SaveFile(sfd.FileName)); + + } + else if (FilePath.ToLower().EndsWith(".uasset")) + { + + await Task.Run(() => Uexp.SaveFile(sfd.FileName)); + } } catch (Exception ex) { @@ -224,6 +240,7 @@ private void search_Click(object sender, EventArgs e) if (SearchPanal.Visible) { InputSearch.Focus(); + InputSearch.SelectAll(); } } @@ -317,7 +334,14 @@ private void copyToolStripMenuItem_Click(object sender, EventArgs e) private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedCells.Count > 0) - dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value = Clipboard.GetText(); + { + if (BackupDataUndo.Count == 0) + { + BackupDataRedo.Clear(); + } + BackupDataUndo.Push(new DataRow() { Index = dataGridView1.SelectedCells[0].RowIndex, StringValue = dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value != null ? dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value.ToString() : "" }); + dataGridView1.Rows[dataGridView1.SelectedCells[0].RowIndex].Cells[1].Value = Clipboard.GetText(); + } } private void exitToolStripMenuItem_Click(object sender, EventArgs e) @@ -327,10 +351,16 @@ private void exitToolStripMenuItem_Click(object sender, EventArgs e) private void InputSearch_KeyDown(object sender, KeyEventArgs e) { + if (!InputSearch.Focused) + { + InputSearch.Focus(); + } + if (e.KeyCode == Keys.Enter) { FindNext_Click(sender, e); } + } private void dataGridView1_Scroll(object sender, ScrollEventArgs e) @@ -349,9 +379,9 @@ private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEvent { if (dataGridView1.Created) { + if (FilePath.ToLower().EndsWith(".locres")) { - locres.Strings[e.RowIndex][1] = dataGridView1.Rows[e.RowIndex].Cells[1].Value != null ? dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() : ""; dataGridView1.Rows[e.RowIndex].Cells[1].Style.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); } @@ -380,11 +410,22 @@ private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (dataGridView1.CancelEdit()) { - //if (e.KeyCode == Keys.V && e.Control) - //{ - // this.pasteToolStripMenuItem_Click(sender, e); - //} else - if (e.KeyCode == Keys.L && e.Control && e.Alt) + if (e.KeyCode == Keys.V && e.Control) + { + this.pasteToolStripMenuItem_Click(sender, e); + } + else if (e.KeyCode == Keys.Z && e.Control) + { + undoToolStripMenuItem_Click(sender, e); + + } + else if ((e.KeyCode == Keys.Y && e.Control)|| (e.KeyCode == Keys.Z && e.Control && e.Shift)) + { + redoToolStripMenuItem_Click(sender, e); + } + + + else if (e.KeyCode == Keys.L && e.Control && e.Alt) { dataGridView1.RightToLeft = RightToLeft.No; } @@ -392,6 +433,7 @@ private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { dataGridView1.RightToLeft = RightToLeft.Yes; } + } } @@ -401,7 +443,67 @@ private void rightToLeftToolStripMenuItem_Click(object sender, EventArgs e) dataGridView1.RightToLeft = dataGridView1.RightToLeft == RightToLeft.Yes ? RightToLeft.No : RightToLeft.Yes; } - private void aboutToolStripMenuItem_Click(object sender, EventArgs e) + + private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) + { + if (BackupDataUndo.Count == 0) + { + BackupDataRedo.Clear(); + } + BackupDataUndo.Push(new DataRow() { Index = e.RowIndex, StringValue = dataGridView1.Rows[e.RowIndex].Cells[1].Value != null ? dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString() : "" }); + } + + private void undoToolStripMenuItem_Click(object sender, EventArgs e) + { + + if (BackupDataUndo.Count > 0) + { + + DataRow dataRow = BackupDataUndo.Pop(); + BackupDataRedo.Push(new DataRow() { Index = dataRow.Index, StringValue = dataGridView1.Rows[dataRow.Index].Cells[1].Value != null ? dataGridView1.Rows[dataRow.Index].Cells[1].Value.ToString() : "" }); + + //MessageBox.Show(dataRow.StringValue); + dataGridView1.Rows[dataRow.Index].Cells[1].Value = dataRow.StringValue; + if (dataRow.StringValue == (Uexp != null ? Uexp.Strings[dataRow.Index][1] : locres.Strings[dataRow.Index][1])) + dataGridView1.Rows[dataRow.Index].Cells[1].Style.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); + else + { + dataGridView1.Rows[dataRow.Index].Cells[1].Style.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); + } + dataGridView1.ClearSelection(); + dataGridView1.Rows[dataRow.Index].Selected = true; + } + + } + + private void redoToolStripMenuItem_Click(object sender, EventArgs e) + { + + if (BackupDataRedo.Count > 0) + { + //MessageBox.Show(BackupDataRedo.Peek().StringValue); + + DataRow dataRow = BackupDataRedo.Pop(); + BackupDataUndo.Push(new DataRow() { Index = dataRow.Index, StringValue = dataGridView1.Rows[dataRow.Index].Cells[1].Value != null ? dataGridView1.Rows[dataRow.Index].Cells[1].Value.ToString() : "" }); + dataGridView1.Rows[dataRow.Index].Cells[1].Value = dataRow.StringValue; + if (dataRow.StringValue == (Uexp != null ? Uexp.Strings[dataRow.Index][1] : locres.Strings[dataRow.Index][1])) + dataGridView1.Rows[dataRow.Index].Cells[1].Style.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); + else + { + dataGridView1.Rows[dataRow.Index].Cells[1].Style.BackColor = System.Drawing.Color.FromArgb(255, 204, 153); + } + + dataGridView1.ClearSelection(); + dataGridView1.Rows[dataRow.Index].Selected = true; + } + } + + private void commandLinesToolStripMenuItem_Click(object sender, EventArgs e) + { + MessageBox.Show(Program.commandlines, "Command Lines",MessageBoxButtons.OK,MessageBoxIcon.Information); + } + + private void aboutToolStripMenuItem1_Click(object sender, EventArgs e) { new FrmAbout(this).ShowDialog(); } diff --git a/UE4localizationsTool/FrmMain.resx b/UE4localizationsTool/FrmMain.resx index 66bbaeb..f0a6936 100644 --- a/UE4localizationsTool/FrmMain.resx +++ b/UE4localizationsTool/FrmMain.resx @@ -126,12 +126,6 @@ True - - True - - - True - 132, 17 diff --git a/UE4localizationsTool/FrmState.Designer.cs b/UE4localizationsTool/FrmState.Designer.cs index f88386b..b2bd247 100644 --- a/UE4localizationsTool/FrmState.Designer.cs +++ b/UE4localizationsTool/FrmState.Designer.cs @@ -68,7 +68,7 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoSize = true; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; - this.ClientSize = new System.Drawing.Size(228, 104); + this.ClientSize = new System.Drawing.Size(224, 100); this.ControlBox = false; this.Controls.Add(this.label2); this.Controls.Add(this.label1); diff --git a/UE4localizationsTool/FrmState.cs b/UE4localizationsTool/FrmState.cs index 8803013..ec70f8b 100644 --- a/UE4localizationsTool/FrmState.cs +++ b/UE4localizationsTool/FrmState.cs @@ -22,7 +22,13 @@ public FrmState(Form form, string Title, string state) timer1.Start(); } - + public FrmState(string Title, string state) + { + InitializeComponent(); + label1.Text = state; + this.Text = Title; + timer1.Start(); + } private void State_Load(object sender, EventArgs e) diff --git a/UE4localizationsTool/Program.cs b/UE4localizationsTool/Program.cs index 8ae8ee6..c013891 100644 --- a/UE4localizationsTool/Program.cs +++ b/UE4localizationsTool/Program.cs @@ -1,10 +1,190 @@ using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading.Tasks; using System.Windows.Forms; - +using AssetParser; namespace UE4localizationsTool { internal static class Program { + + [DllImport("kernel32.dll", SetLastError = true)] + static extern bool AttachConsole(int dwProcessId); + private const int ATTACH_PARENT_PROCESS = -1; + + + + public static string commandlines = + $"{AppDomain.CurrentDomain.FriendlyName} export <(Locres/Uasset) FilePath>\n" + + $"{AppDomain.CurrentDomain.FriendlyName} import <(txt) FilePath>\n" + + $"{AppDomain.CurrentDomain.FriendlyName} -import <(txt) FilePath>\n"; + // $"{AppDomain.CurrentDomain.FriendlyName} exportall \n" + Lazy to do that :( + // $"{AppDomain.CurrentDomain.FriendlyName} importall " + + + + public static void SaveTextFile(string FilePath,List> strings) + { + string[] stringsArray = new string[strings.Count]; + int i = 0; + foreach (var item in strings) + { + stringsArray[i] = item[1]; + i++; + } + File.WriteAllLines(FilePath + ".txt", stringsArray); + } + public static void EditList(string FilePath, ref List> strings) + { + string[] Texts= File.ReadAllLines(FilePath); + if (Texts.Length < strings.Count) + { + throw new Exception("Text file is too short"); + } + for (int i = 0; i < Texts.Length; i++) + { + strings[i][1] = Texts[i]; + } + } + + + public static void commandargs(string[] args) + { + string Command = args[0]; + string FilePath = args[1]; + + if (Command.ToLower() == "export") + { + if (!FilePath.ToLower().EndsWith(".locres") && !FilePath.ToLower().EndsWith(".uasset")) + { + throw new Exception("Invalid file type: " + Path.GetFileName(FilePath)); + } + if (!File.Exists(FilePath)) + { + throw new Exception("File not existed:" + FilePath); + + } + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine("Exporting please wait..."); + Console.ForegroundColor = ConsoleColor.White; + try + { + if (FilePath.ToLower().EndsWith(".locres")) + { + + locres locres = new locres(FilePath); + SaveTextFile(FilePath, locres.Strings); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Done!"); + Console.ForegroundColor = ConsoleColor.White; + } + else if (args[1].ToLower().EndsWith(".uasset")) + { + Uasset Uasset = new Uasset(FilePath); + Uexp Uexp = new Uexp(Uasset); + SaveTextFile(FilePath, Uexp.Strings); + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Done!"); + Console.ForegroundColor = ConsoleColor.White; + } + else + { + throw new Exception("Invalid file type: " + Path.GetFileName(FilePath)); + } + + } + catch + { + throw new Exception("Failed to export: " + Path.GetFileName(FilePath)); + } + } + else if (Command.ToLower() == "import"|| Command.ToLower() == "-import") + { + + if (FilePath.ToLower().EndsWith(".txt")) + { + if (!File.Exists(FilePath)) + { + throw new Exception("File not existed:" + FilePath); + } + + FilePath = Path.ChangeExtension(FilePath, null); + if (!FilePath.ToLower().EndsWith(".locres") && !FilePath.ToLower().EndsWith(".uasset")) + { + throw new Exception("Invalid file type: " +Path.GetFileName(FilePath)); + + } + + if (!File.Exists(FilePath)) + { + throw new Exception("File not existed:" + FilePath); + + } + + + Console.ForegroundColor = ConsoleColor.Blue; + Console.WriteLine("Importing please wait..."); + Console.ForegroundColor = ConsoleColor.White; + + try + { + if (FilePath.ToLower().EndsWith(".locres")) + { + + locres locres = new locres(FilePath); + EditList(FilePath+".txt", ref locres.Strings); + if (Command == "-import") + { + locres.SaveFile(FilePath); + } + else + { + locres.SaveFile(FilePath + ".NEW"); + } + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Done!"); + Console.ForegroundColor = ConsoleColor.White; + } + else if (FilePath.ToLower().EndsWith(".uasset")) + { + Uasset Uasset = new Uasset(FilePath); + Uexp Uexp = new Uexp(Uasset); + EditList(FilePath + ".txt", ref Uexp.Strings); + + if (Command == "-import") + { + Uexp.SaveFile(FilePath); + } + else + { + Uexp.SaveFile(Path.ChangeExtension(FilePath,null)+".NEW"); + } + + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("Done!"); + Console.ForegroundColor = ConsoleColor.White; + } + else + { + throw new Exception("Invalid file type: " + Path.GetFileName(FilePath)); + } + + } + catch + { + throw new Exception("Failed to import: " + Path.GetFileName(FilePath)); + } + + } + else + { + throw new Exception($"This file '{Path.GetFileName(FilePath)}' is not txt file."); + } + } + } /// @@ -12,9 +192,33 @@ internal static class Program /// [STAThread] - - static void Main() + static void Main(string[] args) { + + if (args.Length > 0) + { + AttachConsole(ATTACH_PARENT_PROCESS); + Console.WriteLine(); + if (args.Length < 2) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("Invalid number of arguments.\n" + commandlines); + Console.ForegroundColor = ConsoleColor.White; + return; + } + try + { + commandargs(args); + } + catch(Exception ex) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(ex.Message); + Console.ForegroundColor = ConsoleColor.White; + } + return; + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FrmMain()); diff --git a/UE4localizationsTool/Properties/AssemblyInfo.cs b/UE4localizationsTool/Properties/AssemblyInfo.cs index 78bcf7d..69d7b1c 100644 --- a/UE4localizationsTool/Properties/AssemblyInfo.cs +++ b/UE4localizationsTool/Properties/AssemblyInfo.cs @@ -32,4 +32,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0")] -[assembly: AssemblyFileVersion("1.0")] +[assembly: AssemblyFileVersion("1.1")] diff --git a/UE4localizationsTool/UE4localizationsTool.csproj b/UE4localizationsTool/UE4localizationsTool.csproj index e60b310..413a5f8 100644 --- a/UE4localizationsTool/UE4localizationsTool.csproj +++ b/UE4localizationsTool/UE4localizationsTool.csproj @@ -24,7 +24,7 @@ false false true - 2 + 4 1.0.0.%2a false true @@ -52,7 +52,8 @@ 4 - UE4localizationsTool.Program + + UE4.ico @@ -69,6 +70,10 @@ true + + + true +