mirror of
https://github.com/4sval/FModel.git
synced 2026-09-25 02:29:21 -05:00
Working on asset name map + bug fixes
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
30
FModel/Methods/Serializer/AssetReader.cs
Normal file
30
FModel/Methods/Serializer/AssetReader.cs
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user