mirror of
https://github.com/4sval/FModel.git
synced 2026-03-24 10:44:51 -05:00
added LocRes serializer + removed temp string finder
This commit is contained in:
parent
ec70727d1c
commit
a7c051f0cf
|
|
@ -5,7 +5,7 @@
|
|||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8FABCD3A-9D55-4B54-B237-B259D815DEB8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<RootNamespace>FModel</RootNamespace>
|
||||
<AssemblyName>FModel</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
|
|
@ -128,7 +128,7 @@
|
|||
<Compile Include="Methods\DLLImport.cs" />
|
||||
<Compile Include="Methods\IconGenerator\DrawText.cs" />
|
||||
<Compile Include="Methods\ImagesMerger\ImagesMerger.cs" />
|
||||
<Compile Include="Methods\LocRes\TempStringFinder.cs" />
|
||||
<Compile Include="Methods\LocRes\LocResSerializer.cs" />
|
||||
<Compile Include="Methods\Scintilla\MyScintilla.cs" />
|
||||
<Compile Include="Methods\Utilities\FontUtilities.cs" />
|
||||
<Compile Include="Methods\IconGenerator\ItemIcon.cs" />
|
||||
|
|
|
|||
14
FModel/MainWindow.Designer.cs
generated
14
FModel/MainWindow.Designer.cs
generated
|
|
@ -71,7 +71,6 @@
|
|||
this.pictureBox1 = new System.Windows.Forms.PictureBox();
|
||||
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
|
||||
this.backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
|
||||
this.locresStringFinderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.statusStrip1.SuspendLayout();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
|
|
@ -204,8 +203,7 @@
|
|||
// filesToolStripMenuItem
|
||||
//
|
||||
this.filesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.searchToolStripMenuItem,
|
||||
this.locresStringFinderToolStripMenuItem});
|
||||
this.searchToolStripMenuItem});
|
||||
this.filesToolStripMenuItem.Name = "filesToolStripMenuItem";
|
||||
this.filesToolStripMenuItem.Size = new System.Drawing.Size(42, 20);
|
||||
this.filesToolStripMenuItem.Text = "Files";
|
||||
|
|
@ -213,7 +211,7 @@
|
|||
// searchToolStripMenuItem
|
||||
//
|
||||
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);
|
||||
//
|
||||
|
|
@ -471,13 +469,6 @@
|
|||
this.backgroundWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker2_DoWork);
|
||||
this.backgroundWorker2.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker2_RunWorkerCompleted);
|
||||
//
|
||||
// locresStringFinderToolStripMenuItem
|
||||
//
|
||||
this.locresStringFinderToolStripMenuItem.Name = "locresStringFinderToolStripMenuItem";
|
||||
this.locresStringFinderToolStripMenuItem.Size = new System.Drawing.Size(181, 22);
|
||||
this.locresStringFinderToolStripMenuItem.Text = "LocRes String Finder";
|
||||
this.locresStringFinderToolStripMenuItem.Click += new System.EventHandler(this.LocresStringFinderToolStripMenuItem_Click);
|
||||
//
|
||||
// MainWindow
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
|
@ -552,7 +543,6 @@
|
|||
private System.ComponentModel.BackgroundWorker backgroundWorker2;
|
||||
private System.Windows.Forms.ToolStripMenuItem filesToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem searchToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem locresStringFinderToolStripMenuItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1110,6 +1110,10 @@ namespace FModel
|
|||
scintilla1.Text = File.ReadAllText(ExtractedFilePath);
|
||||
}));
|
||||
}
|
||||
if (ExtractedFilePath.Contains(".locres") && !ExtractedFilePath.Contains("EngineOverrides"))
|
||||
{
|
||||
SerializeLocRes();
|
||||
}
|
||||
}
|
||||
else
|
||||
UpdateConsole("Error while extracting " + ThePak.CurrentUsedItem, Color.FromArgb(255, 244, 66, 66), "Error");
|
||||
|
|
@ -1333,6 +1337,31 @@ namespace FModel
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// because the filename is usually the same for each language, John Wick extract all of them
|
||||
/// but then i have to manually get the right path from the treeview
|
||||
/// TODO: find bug for EngineOverrides
|
||||
/// </summary>
|
||||
private void SerializeLocRes()
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
string treeviewPath = treeView1.SelectedNode.FullPath;
|
||||
if (treeviewPath.StartsWith("..\\")) { treeviewPath = treeviewPath.Substring(3); } //if loading all paks
|
||||
|
||||
string filePath = App.DefaultOutputPath + "\\Extracted\\" + treeviewPath + "\\" + listBox1.SelectedItem;
|
||||
Console.WriteLine(filePath);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
scintilla1.Text = LocResSerializer.StringFinder(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendText("Error while searching " + listBox1.SelectedItem, Color.DarkRed, true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void ConvertTexture2D()
|
||||
{
|
||||
UpdateConsole(ThePak.CurrentUsedItem + " is a Texture2D", Color.FromArgb(255, 66, 244, 66), "Success");
|
||||
|
|
@ -1483,20 +1512,5 @@ namespace FModel
|
|||
ImagesMerger.AskMergeImages();
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void LocresStringFinderToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Directory.Exists(App.DefaultOutputPath + "\\Extracted\\FortniteGame\\Content\\Localization\\"))
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
scintilla1.Text = TempStringFinder.locresOpenFile(App.DefaultOutputPath + "\\Extracted\\FortniteGame\\Content\\Localization\\");
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
AppendText("No .locres file currently extracted", Color.DarkRed, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@
|
|||
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
|
||||
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
|
||||
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABa
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAAdgBAAHYAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
CAAAAk1TRnQBSQFMAgEBAgEAAegBAAHoAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
|
||||
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
|
||||
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
|
||||
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
|
||||
|
|
|
|||
160
FModel/Methods/LocRes/LocResSerializer.cs
Normal file
160
FModel/Methods/LocRes/LocResSerializer.cs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace FModel
|
||||
{
|
||||
static class LocResSerializer
|
||||
{
|
||||
//TODO: refactor
|
||||
private static long LocalizedStringArrayOffset { get; set; }
|
||||
private static string[] LocalizedStringArray { get; set; }
|
||||
private static int stringIndex { get; set; }
|
||||
private static string NamespacesString { get; set; }
|
||||
private static string myKey = "LocResText";
|
||||
private static Dictionary<string, Dictionary<string, string>> LocResDict { get; set; }
|
||||
|
||||
public static string StringFinder(string filepath)
|
||||
{
|
||||
LocResDict = new Dictionary<string, Dictionary<string, string>>();
|
||||
|
||||
using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.GetEncoding(1252)))
|
||||
{
|
||||
byte[] MagicNumber = reader.ReadBytes(16);
|
||||
|
||||
byte VersionNumber = reader.ReadByte();
|
||||
|
||||
LocalizedStringArrayOffset = -1;
|
||||
LocalizedStringArrayOffset = reader.ReadInt64();
|
||||
if (LocalizedStringArrayOffset != -1)
|
||||
{
|
||||
long CurrentFileOffset = reader.BaseStream.Position;
|
||||
|
||||
reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin);
|
||||
int arrayLength = reader.ReadInt32();
|
||||
|
||||
reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin);
|
||||
|
||||
LocalizedStringArray = new string[arrayLength];
|
||||
for (int i = 0; i < LocalizedStringArray.Length; i++)
|
||||
{
|
||||
LocalizedStringArray[i] = readCleanString(reader);
|
||||
}
|
||||
|
||||
reader.BaseStream.Seek(CurrentFileOffset, SeekOrigin.Begin);
|
||||
|
||||
uint NamespaceCount = reader.ReadUInt32();
|
||||
reader.ReadBytes(17);
|
||||
|
||||
for (uint i = 0; i < NamespaceCount; i++)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
readNamespaces(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(LocResDict, Formatting.Indented);
|
||||
}
|
||||
|
||||
private static string readCleanString(BinaryReader reader)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
int stringLength = 0;
|
||||
if (reader.BaseStream.Position != reader.BaseStream.Length)
|
||||
{
|
||||
stringLength = reader.ReadInt32();
|
||||
}
|
||||
|
||||
if (stringLength < 0)
|
||||
{
|
||||
byte[] data = reader.ReadBytes((-1 - stringLength) * 2);
|
||||
reader.ReadBytes(2);
|
||||
return Encoding.Unicode.GetString(data);
|
||||
}
|
||||
else if (stringLength == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return Encoding.GetEncoding(1252).GetString(reader.ReadBytes(stringLength)).TrimEnd('\0');
|
||||
}
|
||||
}
|
||||
|
||||
private static void readNamespaces(BinaryReader br)
|
||||
{
|
||||
if (br.BaseStream.Position > LocalizedStringArrayOffset) { return; }
|
||||
|
||||
int stringLength = br.ReadInt32();
|
||||
if (stringLength > 0)
|
||||
{
|
||||
NamespacesString = Encoding.GetEncoding(1252).GetString(br.ReadBytes(stringLength)).TrimEnd('\0');
|
||||
}
|
||||
else if (stringLength == 0)
|
||||
{
|
||||
NamespacesString = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] data = br.ReadBytes((-1 - stringLength) * 2);
|
||||
br.ReadBytes(2);
|
||||
NamespacesString = Encoding.Unicode.GetString(data);
|
||||
}
|
||||
|
||||
br.ReadInt32();
|
||||
stringIndex = br.ReadInt32();
|
||||
if (stringIndex > LocalizedStringArray.Length || stringIndex < 0)
|
||||
{
|
||||
if (!LocResDict.ContainsKey(NamespacesString))
|
||||
{
|
||||
LocResDict[NamespacesString] = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
long newOffset = br.BaseStream.Position - 8;
|
||||
br.BaseStream.Seek(newOffset, SeekOrigin.Begin);
|
||||
|
||||
int KeyCount = br.ReadInt32();
|
||||
for (int i = 0; i < KeyCount; i++)
|
||||
{
|
||||
readNpKeys(br);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!LocResDict.ContainsKey(NamespacesString))
|
||||
{
|
||||
LocResDict[NamespacesString] = new Dictionary<string, string>();
|
||||
LocResDict[NamespacesString][myKey] = LocalizedStringArray[stringIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void readNpKeys(BinaryReader reader)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
int stringLength = reader.ReadInt32();
|
||||
|
||||
if (stringLength < 0)
|
||||
{
|
||||
byte[] data = reader.ReadBytes((-1 - stringLength) * 2);
|
||||
reader.ReadBytes(2);
|
||||
myKey = Encoding.Unicode.GetString(data);
|
||||
}
|
||||
else if (stringLength == 0)
|
||||
{
|
||||
myKey = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
myKey = Encoding.GetEncoding(1252).GetString(reader.ReadBytes(stringLength)).TrimEnd('\0');
|
||||
}
|
||||
|
||||
reader.ReadInt32();
|
||||
stringIndex = reader.ReadInt32();
|
||||
|
||||
LocResDict[NamespacesString][myKey] = LocalizedStringArray[stringIndex];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FModel
|
||||
{
|
||||
static class TempStringFinder
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="filepath"></param>
|
||||
/// <returns></returns>
|
||||
private static string StringFinder(string filepath)
|
||||
{
|
||||
var dict = new Dictionary<string, string>();
|
||||
|
||||
using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.GetEncoding(1252)))
|
||||
{
|
||||
byte[] MagicNumber = reader.ReadBytes(16);
|
||||
|
||||
byte VersionNumber = reader.ReadByte();
|
||||
|
||||
long LocalizedStringArrayOffset = -1;
|
||||
LocalizedStringArrayOffset = reader.ReadInt64();
|
||||
if (LocalizedStringArrayOffset != -1)
|
||||
{
|
||||
long CurrentFileOffset = reader.BaseStream.Position;
|
||||
|
||||
reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin);
|
||||
int arrayLength = reader.ReadInt32();
|
||||
Console.WriteLine("arrayLength: " + arrayLength);
|
||||
|
||||
reader.BaseStream.Seek(LocalizedStringArrayOffset, SeekOrigin.Begin);
|
||||
|
||||
string[] LocalizedStringArray = new string[arrayLength];
|
||||
for (int i = 0; i < LocalizedStringArray.Length; i++)
|
||||
{
|
||||
if (!dict.ContainsKey("key " + i))
|
||||
{
|
||||
dict.Add("key " + i, readCleanString(reader));
|
||||
}
|
||||
}
|
||||
|
||||
reader.BaseStream.Seek(CurrentFileOffset, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
/*uint NamespaceCount = reader.ReadUInt32();
|
||||
Console.WriteLine("NamespaceCount: " + NamespaceCount);
|
||||
|
||||
uint KeyCount = reader.ReadUInt32();
|
||||
Console.WriteLine("KeyCount: " + KeyCount);*/
|
||||
}
|
||||
|
||||
return JsonConvert.SerializeObject(dict, Formatting.Indented);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <param name="allMyStrings"></param>
|
||||
private static string readCleanString(BinaryReader reader)
|
||||
{
|
||||
reader.ReadInt32();
|
||||
int stringLength = 0;
|
||||
if (reader.BaseStream.Position != reader.BaseStream.Length)
|
||||
{
|
||||
stringLength = reader.ReadInt32();
|
||||
}
|
||||
|
||||
if (stringLength < 0)
|
||||
{
|
||||
byte[] data = reader.ReadBytes((-1 - stringLength) * 2);
|
||||
reader.ReadBytes(2);
|
||||
return Encoding.Unicode.GetString(data);
|
||||
}
|
||||
else if (stringLength == 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return Encoding.GetEncoding(1252).GetString(reader.ReadBytes(stringLength)).TrimEnd('\0');
|
||||
}
|
||||
}
|
||||
|
||||
public static string locresOpenFile(string defaultPath)
|
||||
{
|
||||
OpenFileDialog theDialog = new OpenFileDialog();
|
||||
theDialog.Multiselect = false;
|
||||
theDialog.InitialDirectory = defaultPath;
|
||||
theDialog.Title = @"Choose your LocRes file";
|
||||
theDialog.Filter = @"All Files (*.*)|*.*";
|
||||
|
||||
if (theDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
return StringFinder(theDialog.FileName);
|
||||
}
|
||||
else { return null; }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user