Working on asset name map + bug fixes

This commit is contained in:
Asval 2019-06-12 19:35:49 +02:00
parent e171b3772a
commit f36a0228e1
8 changed files with 158 additions and 126 deletions

View File

@ -130,10 +130,11 @@
<Compile Include="Methods\DLLImport.cs" />
<Compile Include="Methods\IconGenerator\DrawText.cs" />
<Compile Include="Methods\IconGenerator\Translations\LoadLocRes.cs" />
<Compile Include="Methods\IconGenerator\Translations\SearchNamespaces.cs" />
<Compile Include="Methods\IconGenerator\Translations\AssetNameMap.cs" />
<Compile Include="Methods\IconGenerator\Translations\SearchResource.cs" />
<Compile Include="Methods\ImagesMerger\ImagesMerger.cs" />
<Compile Include="Methods\LocRes\LocResSerializer.cs" />
<Compile Include="Methods\Serializer\AssetReader.cs" />
<Compile Include="Methods\Serializer\LocRes\LocResSerializer.cs" />
<Compile Include="Methods\Scintilla\MyScintilla.cs" />
<Compile Include="Methods\Utilities\FontUtilities.cs" />
<Compile Include="Methods\IconGenerator\ItemIcon.cs" />

View File

@ -54,6 +54,7 @@
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutFModelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.panel1 = new System.Windows.Forms.Panel();
this.AESKeyComboBox = new System.Windows.Forms.ComboBox();
this.StopButton = new System.Windows.Forms.Button();
this.OpenImageButton = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
@ -70,7 +71,6 @@
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
this.AESKeyComboBox = new System.Windows.Forms.ComboBox();
this.statusStrip1.SuspendLayout();
this.menuStrip1.SuspendLayout();
this.panel1.SuspendLayout();
@ -284,6 +284,15 @@
this.panel1.Size = new System.Drawing.Size(1191, 26);
this.panel1.TabIndex = 2;
//
// AESKeyComboBox
//
this.AESKeyComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.AESKeyComboBox.FormattingEnabled = true;
this.AESKeyComboBox.Location = new System.Drawing.Point(482, 4);
this.AESKeyComboBox.Name = "AESKeyComboBox";
this.AESKeyComboBox.Size = new System.Drawing.Size(454, 21);
this.AESKeyComboBox.TabIndex = 7;
//
// StopButton
//
this.StopButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -460,15 +469,6 @@
this.backgroundWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker2_DoWork);
this.backgroundWorker2.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker2_RunWorkerCompleted);
//
// AESKeyComboBox
//
this.AESKeyComboBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.AESKeyComboBox.FormattingEnabled = true;
this.AESKeyComboBox.Location = new System.Drawing.Point(482, 4);
this.AESKeyComboBox.Name = "AESKeyComboBox";
this.AESKeyComboBox.Size = new System.Drawing.Size(454, 21);
this.AESKeyComboBox.TabIndex = 7;
//
// MainWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

View File

@ -279,20 +279,15 @@ namespace FModel
break;
}
if (JohnWick.MyExtractor.GetFileList() != null)
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
if (CurrentUsedPakLines != null)
{
ThePak.PaksMountPoint.Add(arCurrentUsedPak, JohnWick.MyExtractor.GetMountPoint().Substring(9));
string mountPoint = JohnWick.MyExtractor.GetMountPoint();
ThePak.PaksMountPoint.Add(arCurrentUsedPak, mountPoint.Substring(9));
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
for (int ii = 0; ii < CurrentUsedPakLines.Length; ii++)
{
CurrentUsedPakLines[ii] = JohnWick.MyExtractor.GetMountPoint().Substring(6) + CurrentUsedPakLines[ii];
if (loadAllPaKs)
{
sb.Append(CurrentUsedPakLines[ii]);
sb.AppendLine();
}
CurrentUsedPakLines[ii] = mountPoint.Substring(6) + CurrentUsedPakLines[ii];
string CurrentUsedPakFileName = CurrentUsedPakLines[ii].Substring(CurrentUsedPakLines[ii].LastIndexOf("/", StringComparison.Ordinal) + 1);
if (CurrentUsedPakFileName.Contains(".uasset") || CurrentUsedPakFileName.Contains(".uexp") || CurrentUsedPakFileName.Contains(".ubulk"))
@ -309,47 +304,53 @@ namespace FModel
ThePak.AllpaksDictionary.Add(CurrentUsedPakFileName, arCurrentUsedPak);
}
}
}
if (loadAllPaKs)
{
UpdateConsole(".PAK mount point: " + JohnWick.MyExtractor.GetMountPoint().Substring(9), Color.FromArgb(255, 244, 132, 66), "Waiting");
File.WriteAllText(App.DefaultOutputPath + "\\FortnitePAKs.txt", sb.ToString());
ThePak.CurrentUsedPak = null;
ThePak.CurrentUsedPakGuid = null;
if (loadAllPaKs)
{
sb.Append(CurrentUsedPakLines[ii] + "\n");
}
}
if (loadAllPaKs) { UpdateConsole(".PAK mount point: " + mountPoint.Substring(9), Color.FromArgb(255, 244, 132, 66), "Waiting"); }
if (theSinglePak != null && arCurrentUsedPak == theSinglePak.ClickedItem.Text) { PakAsTxt = CurrentUsedPakLines; }
}
}
if (theSinglePak != null)
{
ThePak.CurrentUsedPak = theSinglePak.ClickedItem.Text;
ThePak.CurrentUsedPakGuid = ThePak.ReadPakGuid(Settings.Default.PAKsPath + "\\" + ThePak.CurrentUsedPak);
if (arCurrentUsedPak == theSinglePak.ClickedItem.Text && JohnWick.MyExtractor.GetFileList() != null)
PakAsTxt = JohnWick.MyExtractor.GetFileList().ToArray();
}
}
if (theSinglePak != null && ThePak.ReadPakGuid(Settings.Default.PAKsPath + "\\" + theSinglePak.ClickedItem.Text) != "0-0-0-0") //LOADING DYNAMIC PAK
if (theSinglePak != null)
{
ThePak.CurrentUsedPak = theSinglePak.ClickedItem.Text;
ThePak.CurrentUsedPakGuid = ThePak.ReadPakGuid(Settings.Default.PAKsPath + "\\" + ThePak.CurrentUsedPak);
try
if (ThePak.CurrentUsedPakGuid != "0-0-0-0") //LOADING DYNAMIC PAK
{
JohnWick.MyExtractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + theSinglePak.ClickedItem.Text, Settings.Default.AESKey);
if (JohnWick.MyExtractor.GetFileList() != null)
try
{
ThePak.PaksMountPoint.Add(theSinglePak.ClickedItem.Text, JohnWick.MyExtractor.GetMountPoint().Substring(9));
JohnWick.MyExtractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + ThePak.CurrentUsedPak, Settings.Default.AESKey);
PakAsTxt = JohnWick.MyExtractor.GetFileList().ToArray();
if (PakAsTxt != null)
{
string mountPoint = JohnWick.MyExtractor.GetMountPoint();
ThePak.PaksMountPoint.Add(ThePak.CurrentUsedPak, mountPoint.Substring(9));
for (int i = 0; i < PakAsTxt.Length; i++)
{
PakAsTxt[i] = mountPoint.Substring(6) + PakAsTxt[i];
}
}
}
catch (Exception)
{
UpdateConsole("Can't read " + ThePak.CurrentUsedPak + " with this key", Color.FromArgb(255, 244, 66, 66), "Error");
}
}
catch (Exception)
{
UpdateConsole("Can't read " + theSinglePak.ClickedItem.Text + " with this key", Color.FromArgb(255, 244, 66, 66), "Error");
}
}
if (loadAllPaKs)
{
File.WriteAllText(App.DefaultOutputPath + "\\FortnitePAKs.txt", sb.ToString()); //File will always exist
ThePak.CurrentUsedPak = null;
ThePak.CurrentUsedPakGuid = null;
}
UpdateConsole("Building tree, please wait...", Color.FromArgb(255, 244, 132, 66), "Loading");
}
@ -448,6 +449,7 @@ namespace FModel
ThePak.AllpaksDictionary = new Dictionary<string, string>();
_diffToExtract = new Dictionary<string, string>();
ThePak.PaksMountPoint = new Dictionary<string, string>();
PakAsTxt = null;
Invoke(new Action(() =>
{
@ -485,8 +487,9 @@ namespace FModel
//ADD TO DICTIONNARY
RegisterPaKsinDict(_paksArray, null, true);
if (!File.Exists(App.DefaultOutputPath + "\\FortnitePAKs.txt"))
if (new System.IO.FileInfo(App.DefaultOutputPath + "\\FortnitePAKs.txt").Length <= 0) //File will always exist so we check the file size instead
{
File.Delete(App.DefaultOutputPath + "\\FortnitePAKs.txt");
UpdateConsole("Can't read .PAK files with this key", Color.FromArgb(255, 244, 66, 66), "Error");
}
else
@ -582,18 +585,14 @@ namespace FModel
break;
}
if (JohnWick.MyExtractor.GetFileList() != null)
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
if (CurrentUsedPakLines != null)
{
if (!File.Exists(App.DefaultOutputPath + "\\Backup" + _backupFileName))
File.Create(App.DefaultOutputPath + "\\Backup" + _backupFileName).Dispose();
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
for (int ii = 0; ii < CurrentUsedPakLines.Length; ii++)
{
CurrentUsedPakLines[ii] = JohnWick.MyExtractor.GetMountPoint().Substring(6) + CurrentUsedPakLines[ii];
sb.Append(CurrentUsedPakLines[ii]);
sb.AppendLine();
sb.Append(CurrentUsedPakLines[ii] + "\n");
}
UpdateConsole(".PAK mount point: " + JohnWick.MyExtractor.GetMountPoint().Substring(9), Color.FromArgb(255, 244, 132, 66), "Waiting");
}
@ -626,15 +625,14 @@ namespace FModel
continue;
}
if (JohnWick.MyExtractor.GetFileList() != null)
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
if (CurrentUsedPakLines != null)
{
string[] CurrentUsedPakLines = JohnWick.MyExtractor.GetFileList().ToArray();
for (int ii = 0; ii < CurrentUsedPakLines.Length; ii++)
{
CurrentUsedPakLines[ii] = JohnWick.MyExtractor.GetMountPoint().Substring(6) + CurrentUsedPakLines[ii];
sb.Append(CurrentUsedPakLines[ii]);
sb.AppendLine();
sb.Append(CurrentUsedPakLines[ii] + "\n");
}
AppendText("Backing up ", Color.Black);
AppendText(arCurrentUsedPak, Color.DarkRed, true);
@ -643,12 +641,17 @@ namespace FModel
}
}
}
File.WriteAllText(App.DefaultOutputPath + "\\Backup" + _backupFileName, sb.ToString());
if (File.Exists(App.DefaultOutputPath + "\\Backup" + _backupFileName))
File.WriteAllText(App.DefaultOutputPath + "\\Backup" + _backupFileName, sb.ToString()); //File will always exist so we check the file size instead
if (new System.IO.FileInfo(App.DefaultOutputPath + "\\Backup" + _backupFileName).Length > 0)
{
UpdateConsole("\\Backup" + _backupFileName + " successfully created", Color.FromArgb(255, 66, 244, 66), "Success");
}
else
{
File.Delete(App.DefaultOutputPath + "\\Backup" + _backupFileName);
UpdateConsole("Can't create " + _backupFileName.Substring(1), Color.FromArgb(255, 244, 66, 66), "Error");
}
}
private void UpdateModeExtractSave()
{

View File

@ -131,7 +131,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABa
CAAAAk1TRnQBSQFMAgEBAgEAAQgBAQEIAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CAAAAk1TRnQBSQFMAgEBAgEAARABAQEQAQEBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

View File

@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -7,10 +8,10 @@ using System.Text.RegularExpressions;
namespace FModel
{
static class SearchNamespaces
static class AssetNameMap
{
public static List<string> myNamespacesList { get; set; }
public static void searchNamespacesInUexp(string filepath)
public static void searchStringsInUexp(string filepath)
{
myNamespacesList = new List<string>();
@ -72,5 +73,38 @@ namespace FModel
}
}
}
public static void getNameMap(string filepath)
{
Console.Clear();
using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.GetEncoding(1252)))
{
reader.ReadBytes(24);
int fileLength = reader.ReadInt32();
Console.WriteLine(fileLength);
reader.ReadBytes(13);
int NamespaceCount = reader.ReadInt32();
long LocalizedStringArrayOffset = -1;
LocalizedStringArrayOffset = reader.ReadInt64();
if (LocalizedStringArrayOffset != -1)
{
long newOffset = LocalizedStringArrayOffset - 4;
reader.BaseStream.Seek(newOffset, SeekOrigin.Begin);
string[] LocalizedStringArray = new string[NamespaceCount];
for (int i = 0; i < LocalizedStringArray.Length; i++)
{
string tag = AssetReader.readCleanString(reader);
if (tag != "None") { LocalizedStringArray[i] = tag; }
Console.WriteLine(LocalizedStringArray[i]);
}
}
}
}
}
}

View File

@ -61,7 +61,7 @@ namespace FModel
}
/// <summary>
/// We get the file list of currentPak, we find all files that matched our currentItem, for each result we get its indexes (it's used to get its data)
/// We get the file list of currentPak, we find all files that matched our currentItem, for each result we get its index (it's used to get its data)
/// Then we can use WriteFile to write each results with its data
/// If currentPak is the same twice in a row, we do not try to get a new file list
/// </summary>
@ -98,6 +98,11 @@ namespace FModel
}
currentPakToCheck = currentPak;
/*if (File.Exists(AssetPath.Substring(0, AssetPath.LastIndexOf(".")) + ".uasset")) //TEST
{
AssetNameMap.getNameMap(AssetPath.Substring(0, AssetPath.LastIndexOf(".")) + ".uasset");
}*/
return AssetPath;
}

View File

@ -0,0 +1,30 @@
using System;
using System.IO;
using System.Text;
namespace FModel
{
class AssetReader
{
public static string readCleanString(BinaryReader reader)
{
reader.ReadInt32();
int 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');
}
}
}
}

View File

@ -5,19 +5,25 @@ using System.Text;
namespace FModel
{
/*
* Author: Asval
* pretty sure it can be refactored
*
* */
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 string myKey { get; set; }
private static Dictionary<string, Dictionary<string, string>> LocResDict { get; set; }
public static string StringFinder(string filepath)
{
LocResDict = new Dictionary<string, Dictionary<string, string>>();
myKey = "LocResText";
NamespacesString = "";
LocalizedStringArrayOffset = -1;
using (BinaryReader reader = new BinaryReader(File.Open(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Encoding.GetEncoding(1252)))
{
@ -25,7 +31,6 @@ namespace FModel
byte VersionNumber = reader.ReadByte();
LocalizedStringArrayOffset = -1;
LocalizedStringArrayOffset = reader.ReadInt64();
if (LocalizedStringArrayOffset != -1)
{
@ -39,7 +44,7 @@ namespace FModel
LocalizedStringArray = new string[arrayLength];
for (int i = 0; i < LocalizedStringArray.Length; i++)
{
LocalizedStringArray[i] = readCleanString(reader);
LocalizedStringArray[i] = AssetReader.readCleanString(reader);
}
reader.BaseStream.Seek(CurrentFileOffset, SeekOrigin.Begin);
@ -58,31 +63,6 @@ namespace FModel
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; }
@ -104,7 +84,7 @@ namespace FModel
}
br.ReadInt32();
stringIndex = br.ReadInt32();
int stringIndex = br.ReadInt32();
if (stringIndex > LocalizedStringArray.Length || stringIndex < 0)
{
if (!LocResDict.ContainsKey(NamespacesString))
@ -118,7 +98,12 @@ namespace FModel
int KeyCount = br.ReadInt32();
for (int i = 0; i < KeyCount; i++)
{
readNpKeys(br);
myKey = AssetReader.readCleanString(br);
br.ReadInt32();
stringIndex = br.ReadInt32();
LocResDict[NamespacesString][myKey] = LocalizedStringArray[stringIndex];
}
}
else
@ -130,31 +115,5 @@ namespace FModel
}
}
}
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];
}
}
}