Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
add name table
Browse files Browse the repository at this point in the history
  • Loading branch information
amrshaheen61 committed May 28, 2022
1 parent 0765ba9 commit 25956f4
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 86 deletions.
9 changes: 8 additions & 1 deletion UE4localizationsTool/Core/AssetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ public static string GetStringUE(this MemoryList memoryList)

public static bool IsASCII(string StringValue)
{
return (Encoding.UTF8.GetBytes(StringValue).Length == StringValue.Length);
for(int n=0; n< StringValue.Length; n++)
{
if (StringValue[n]>127)
{
return false;
}
}
return true;
}

public static void DeleteStringUE(this MemoryList memoryList)
Expand Down
2 changes: 1 addition & 1 deletion UE4localizationsTool/Core/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public DataTable(MemoryList memoryList, Uexp uexp, bool Modify = false)
for (int TableIndex = 0; TableIndex < TableCount; TableIndex++)
{
memoryList.Skip(8); //no neeed
_ = new StructProperty(memoryList, uexp, true, Modify);
_ = new StructProperty(memoryList, uexp, uexp.UassetData.UseFromStruct, Modify);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion UE4localizationsTool/Core/Spreadsheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Spreadsheet(MemoryList memoryList, Uexp uexp, bool Modify = false)

for (int TableIndex = 0; TableIndex < TableCount; TableIndex++)
{
_ = new StructProperty(memoryList, uexp, true, Modify);
_ = new StructProperty(memoryList, uexp, uexp.UassetData.UseFromStruct, Modify);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions UE4localizationsTool/Core/StructProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe
if (!Modify)
{
uexp.Strings.Add(new List<string>() { PropertyName, memoryList.GetStringUE() });
//Console.WriteLine(uexp.Strings[uexp.Strings.Count - 1][1]);
// Console.WriteLine(uexp.Strings[uexp.Strings.Count - 1][1]);
}
else
{
Expand Down Expand Up @@ -708,7 +708,7 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe
//Console.WriteLine("StructProperty->" + memoryList.GetPosition());
//Console.ForegroundColor = //ConsoleColor.White;

new StructProperty(memoryList, uexp, true, Modify);
new StructProperty(memoryList, uexp, uexp.UassetData.UseFromStruct, Modify);

//Console.ForegroundColor = //ConsoleColor.Yellow;
//Console.WriteLine("EndStructProperty->" + memoryList.GetPosition());
Expand Down Expand Up @@ -743,7 +743,7 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe
try
{
//Console.WriteLine("MovieSceneEvalTemplatePtr--> StructProperty");
new StructProperty(memoryList, uexp, true, Modify);
new StructProperty(memoryList, uexp, uexp.UassetData.UseFromStruct, Modify);
//Console.WriteLine("MovieSceneEvalTemplatePtr--> EndStructProperty");
}
catch
Expand Down Expand Up @@ -781,7 +781,7 @@ private void PropertyParser(string PropertyName, string Property, int PropertyLe

else
{
new StructProperty(memoryList, uexp, true, Modify);
new StructProperty(memoryList, uexp, uexp.UassetData.UseFromStruct, Modify);
}

}
Expand Down
158 changes: 109 additions & 49 deletions UE4localizationsTool/Core/Uasset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,21 @@ public struct ExportsDirectory
public List<byte> ExportData;
}

public enum AssetVersions : int
{
VersionZero = 0, //no example yet
VersionOne, //no example yet
VersionTwo, //no example yet
VersioneThere, //no example yet
VersionFour, //no example yet
VersionFive, //no example yet
VersionSix,
VersionSeven
}


public int FileVersion;

public AssetVersions FileVersion;
public int File_Directory_Offset;
public int Number_of_Names;
public int Name_Directory_Offset;
Expand All @@ -50,6 +62,7 @@ public struct ExportsDirectory
public MemoryList UassetFile;
public MemoryList UexpFile;
public bool IsNotUseUexp;
public bool UseFromStruct = true;
public Uasset(string FilePath)
{

Expand Down Expand Up @@ -85,12 +98,20 @@ public Uasset(string FilePath)
throw new Exception($"This file \'{FilePath}\' is not uasset file!");
}

FileVersion = UassetFile.GetIntValue();
if (FileVersion != -7)

FileVersion = (AssetVersions)Math.Abs(UassetFile.GetIntValue());


if (FileVersion != AssetVersions.VersionSeven && FileVersion != AssetVersions.VersionSix)
{
throw new Exception("Not supported version!");
}

if (FileVersion == AssetVersions.VersionSix)
{
UseFromStruct = false;
}


//3 Null Bytes
UassetFile.Seek(3 * 4, SeekOrigin.Current);
Expand Down Expand Up @@ -120,6 +141,7 @@ public Uasset(string FilePath)
Number_Of_Imports = UassetFile.GetIntValue();
Imports_Directory_Offset = UassetFile.GetIntValue();


//seek to position
UassetFile.Seek(Name_Directory_Offset, SeekOrigin.Begin);
//Get Names
Expand All @@ -129,7 +151,8 @@ public Uasset(string FilePath)
NAMES_DIRECTORY.Add(UassetFile.GetStringUE());
//Console.WriteLine(NAMES_DIRECTORY[n]);
//Flags
UassetFile.Seek(4, SeekOrigin.Current);
if (FileVersion == AssetVersions.VersionSeven)
UassetFile.Seek(4, SeekOrigin.Current);
}

//seek to position
Expand All @@ -150,85 +173,122 @@ public Uasset(string FilePath)



//Get Exports
Exports_Directory = new List<ExportsDirectory>();
ExportReadOrEdit();
}



public void ExportReadOrEdit(bool Modify = false)
{
int NextExportPosition = File_Directory_Offset;
//seek to position
UassetFile.Seek(Exports_Directory_Offset, SeekOrigin.Begin);
//Get Imports
Exports_Directory = new List<ExportsDirectory>();
for (int n = 0; n < Number_Of_Exports; n++)
{
ExportsDirectory ExportsDirectory = new ExportsDirectory();
ExportsDirectory.ExportClass = UassetFile.GetIntValue();
ExportsDirectory.ExportParent_1 = UassetFile.GetIntValue();
ExportsDirectory.ExportParent_2 = UassetFile.GetIntValue();
if (FileVersion >= AssetVersions.VersionSeven)
{
ExportsDirectory.ExportParent_2 = UassetFile.GetIntValue();
}

_ = UassetFile.GetIntValue();
ExportsDirectory.ExportName = UassetFile.GetIntValue();
_ = UassetFile.GetIntValue();
ExportsDirectory.ExportMemberType = UassetFile.GetShortValue();
_ = UassetFile.GetShortValue();
ExportsDirectory.ExportLength = UassetFile.GetIntValue();
int NullIntsize = 0;
if (UassetFile.GetIntValue(false) == 0)
if (FileVersion >= AssetVersions.VersionSeven)
{
_ = UassetFile.GetIntValue();
}
else
{
NullIntsize = 1;
}
ExportsDirectory.ExportStart = UassetFile.GetIntValue();
UassetFile.Seek(4 * 16 - NullIntsize, SeekOrigin.Current);


if (IsNotUseUexp)
if (FileVersion < AssetVersions.VersionSeven)
{
_ = UassetFile.GetIntValue(); //Unknown
ExportsDirectory.ExportMemberType = UassetFile.GetShortValue();
_ = UassetFile.GetShortValue();//Unknown
if (!Modify)
{
ExportsDirectory.ExportLength = UassetFile.GetIntValue();
}
else
{
UassetFile.SetIntValue(Exports_Directory[n].ExportData.Count);
}

ExportsDirectory.ExportData = new List<byte>();
ExportsDirectory.ExportData.AddRange(UassetFile.GetBytes(ExportsDirectory.ExportLength, false, ExportsDirectory.ExportStart));
Exports_Directory.Add(ExportsDirectory);
}
else


if (FileVersion >= AssetVersions.VersionSeven)
{
UexpFile.Seek(ExportsDirectory.ExportStart - File_Directory_Offset, SeekOrigin.Begin);
ExportsDirectory.ExportData = new List<byte>();
ExportsDirectory.ExportData.AddRange(UexpFile.GetBytes(ExportsDirectory.ExportLength));
Exports_Directory.Add(ExportsDirectory);
ExportsDirectory.ExportMemberType = UassetFile.GetShortValue();
_ = UassetFile.GetShortValue();
if (!Modify)
{
ExportsDirectory.ExportLength = UassetFile.GetIntValue();

}
else
{
UassetFile.SetIntValue(Exports_Directory[n].ExportData.Count);
}
}
}


if (UassetFile.GetIntValue(false) == 0)
{
_ = UassetFile.GetIntValue();
}


if (!Modify)
{
ExportsDirectory.ExportStart = UassetFile.GetIntValue();
}
else
{
UassetFile.SetIntValue(NextExportPosition);
NextExportPosition += Exports_Directory[n].ExportData.Count;
}


}
if (FileVersion >= AssetVersions.VersionSeven)
{
UassetFile.Skip(4 * 4);
}

_ = UassetFile.GetIntValue();

if (FileVersion >= AssetVersions.VersionSeven)
{
UassetFile.Skip(4 * 4);
}

public void UpdateExport()
{
int NextExportPosition = File_Directory_Offset;
//seek to position
UassetFile.Seek(Exports_Directory_Offset, SeekOrigin.Begin);
for (int n = 0; n < Exports_Directory.Count; n++)
{
UassetFile.Skip(4 * 6);
UassetFile.Skip(2 * 2);
UassetFile.SetIntValue(Exports_Directory[n].ExportData.Count);
// Console.WriteLine(Exports_Directory[n].ExportData.Count);
int NullIntsize = 0;
if (UassetFile.GetIntValue(false) == 0)
UassetFile.Skip(4 * 7);

if (FileVersion < AssetVersions.VersionSeven)
{
_ = UassetFile.GetIntValue();
UassetFile.Skip(4 * 2);
}
else

if (!Modify)
{
NullIntsize = 1;
if (IsNotUseUexp)
{

ExportsDirectory.ExportData = new List<byte>();
ExportsDirectory.ExportData.AddRange(UassetFile.GetBytes(ExportsDirectory.ExportLength, false, ExportsDirectory.ExportStart));
Exports_Directory.Add(ExportsDirectory);
}
else
{
UexpFile.Seek(ExportsDirectory.ExportStart - File_Directory_Offset, SeekOrigin.Begin);
ExportsDirectory.ExportData = new List<byte>();
ExportsDirectory.ExportData.AddRange(UexpFile.GetBytes(ExportsDirectory.ExportLength));
Exports_Directory.Add(ExportsDirectory);
}
}
UassetFile.SetIntValue(NextExportPosition);
NextExportPosition += Exports_Directory[n].ExportData.Count;
UassetFile.Skip(4 * (16 - NullIntsize));
}
}

Expand Down
4 changes: 2 additions & 2 deletions UE4localizationsTool/Core/Uexp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void ReadOrEdit(bool Modify = false)
Console.ForegroundColor = ConsoleColor.Red;
// Console.WriteLine($"-----------{n}------------");
Console.ForegroundColor = ConsoleColor.White;
_ = new StructProperty(memoryList, this, true, Modify);
_ = new StructProperty(memoryList, this, UassetData.UseFromStruct, Modify);
Console.ForegroundColor = ConsoleColor.Red;
// Console.WriteLine($"-----------End------------");
Console.ForegroundColor = ConsoleColor.White;
Expand Down Expand Up @@ -91,7 +91,7 @@ private void ModifyStrings()
public void SaveFile(string FilPath)
{
ModifyStrings();
UassetData.UpdateExport();
UassetData.ExportReadOrEdit(true);
if (UassetData.IsNotUseUexp)
{
MakeBlocks();
Expand Down
4 changes: 3 additions & 1 deletion UE4localizationsTool/FrmMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion UE4localizationsTool/FrmState.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 25956f4

Please sign in to comment.