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

Commit

Permalink
Changes for v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
amrshaheen61 committed Sep 1, 2023
1 parent 443c566 commit ab03000
Show file tree
Hide file tree
Showing 21 changed files with 813 additions and 349 deletions.
54 changes: 23 additions & 31 deletions UE4localizationsTool/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Commands(string Options, string SourcePath, Args args)
Strings = new List<List<string>>();
Console.ForegroundColor = ConsoleColor.Blue;
ConsoleText = $"Exporting... '{Path.GetFileName(SourcePath)}' ";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;

Strings = Export(SourcePath);
Expand All @@ -55,8 +55,7 @@ public Commands(string Options, string SourcePath, Args args)
}

Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;

SaveTextFile(SourcePath + ".txt");
Expand All @@ -74,7 +73,7 @@ public Commands(string Options, string SourcePath, Args args)
case "-import"://Single File Without rename
Console.ForegroundColor = ConsoleColor.Blue;
ConsoleText = $"Importing... '{Path.GetFileName(SourcePath)}' ";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;

if (!SourcePath.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
Expand All @@ -84,8 +83,7 @@ public Commands(string Options, string SourcePath, Args args)

Import(Path.ChangeExtension(SourcePath, null), File.ReadAllLines(SourcePath), Options.ToLower());
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;


Expand Down Expand Up @@ -113,7 +111,7 @@ private void SaveTextFile(string FilePath)
{
Console.ForegroundColor = ConsoleColor.Blue;
string ConsoleText = "Saving text file... ";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;

string[] stringsArray = new string[Strings.Count];
Expand Down Expand Up @@ -141,8 +139,7 @@ private void SaveTextFile(string FilePath)
File.WriteAllLines(FilePath, stringsArray);

Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;
}

Expand All @@ -163,16 +160,16 @@ private List<List<string>> Export(string FilePath)
}
else if (FilePath.EndsWith(".uasset", StringComparison.OrdinalIgnoreCase) || FilePath.EndsWith(".umap", StringComparison.OrdinalIgnoreCase))
{
Uasset Uasset = new Uasset(FilePath);
IUasset Uasset = Uexp.GetUasset(FilePath);

if (Flags.HasFlag(Args.method2))
{
Uasset.UseMethod2 = true;
}

Uexp Uexp = new Uexp(Uasset);
return Uexp.Strings;
// SizeOfRecord = Uexp.Strings.Count;
Uexp uexp = new Uexp(Uasset);
return uexp.Strings;
// SizeOfRecord = uexp.Strings.Count;
}
else
{
Expand All @@ -189,13 +186,12 @@ private void ExportFolder(string FolderPath)
}
Console.ForegroundColor = ConsoleColor.Blue;
string ConsoleText = "Scaning for files...";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;

string[] LanguageFiles = Directory.GetFiles(FolderPath, "*.*", SearchOption.AllDirectories).Where(x => x.EndsWith(".locres", StringComparison.OrdinalIgnoreCase) || x.EndsWith(".uasset", StringComparison.OrdinalIgnoreCase) || x.EndsWith(".umap", StringComparison.OrdinalIgnoreCase)).ToArray<string>();
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;

if (LanguageFiles.Count() == 0)
Expand All @@ -207,7 +203,7 @@ private void ExportFolder(string FolderPath)
{
Console.ForegroundColor = ConsoleColor.Blue;
ConsoleText = $"[{i + 1}:{LanguageFiles.Count()}] Exporting... '{Path.GetFileName(LanguageFiles[i])}' ";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;

int ThisPosition = Strings.Count - 1;
Expand All @@ -227,8 +223,7 @@ private void ExportFolder(string FolderPath)
catch (Exception EX)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Fail");
Console.Write("Fail\n");
Console.ForegroundColor = ConsoleColor.White;

Console.ForegroundColor = ConsoleColor.Yellow;
Expand All @@ -238,8 +233,7 @@ private void ExportFolder(string FolderPath)

}
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;
}
}
Expand Down Expand Up @@ -304,18 +298,18 @@ private void Import(string FilePath, string[] Values, string Option)
}
else if (FilePath.EndsWith(".uasset", StringComparison.OrdinalIgnoreCase) || FilePath.EndsWith(".umap", StringComparison.OrdinalIgnoreCase))
{
Uasset Uasset = new Uasset(FilePath);
IUasset Uasset = Uexp.GetUasset(FilePath);
if (Flags.HasFlag(Args.method2))
{
Uasset.UseMethod2 = true;
}

Uexp Uexp = new Uexp(Uasset);
EditList(Uexp.Strings, Values);
Uexp uexp = new Uexp(Uasset);
EditList(uexp.Strings, Values);

if (Option == "-import")
{
Uexp.SaveFile(FilePath);
uexp.SaveFile(FilePath);
return;
}

Expand All @@ -328,7 +322,7 @@ private void Import(string FilePath, string[] Values, string Option)
FilePath = Path.ChangeExtension(FilePath, null) + "_NEW.umap";
}

Uexp.SaveFile(FilePath);
uexp.SaveFile(FilePath);
}
else
{
Expand Down Expand Up @@ -368,7 +362,7 @@ private void ImportFolder(string FolderPath, string[] Values, string Option)
FilePath = FilePath.Replace(@"\\", @"\");
Console.ForegroundColor = ConsoleColor.Blue;
string ConsoleText = $"[{PathIndex + 1}:{Indexs.Length}] Importing... '{Path.GetFileName(FilePath)}' ";
Console.WriteLine(ConsoleText);
Console.Write(ConsoleText);
Console.ForegroundColor = ConsoleColor.White;
string[] StringArrayValues = new string[ArraySize];
Array.Copy(Values, Indexs[PathIndex] + 1, StringArrayValues, 0, ArraySize);
Expand All @@ -383,8 +377,7 @@ private void ImportFolder(string FolderPath, string[] Values, string Option)
catch (Exception EX)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Fail");
Console.Write("Fail\n");
Console.ForegroundColor = ConsoleColor.White;

Console.ForegroundColor = ConsoleColor.Yellow;
Expand All @@ -393,8 +386,7 @@ private void ImportFolder(string FolderPath, string[] Values, string Option)
continue;
}
Console.ForegroundColor = ConsoleColor.Green;
Console.SetCursorPosition(ConsoleText.Length, Console.CursorTop - 1);
Console.WriteLine("Done");
Console.Write("Done\n");
Console.ForegroundColor = ConsoleColor.White;
}

Expand Down
39 changes: 32 additions & 7 deletions UE4localizationsTool/Core/AssetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace AssetParser
public static class AssetHelper
{

public static string GetPropertyName(this Uasset SourceFile, int Index)
public static string GetPropertyName(this IUasset SourceFile, int Index)
{
if (SourceFile.NAMES_DIRECTORY.Count > Index && Index > 0)
{
Expand All @@ -17,7 +17,7 @@ public static string GetPropertyName(this Uasset SourceFile, int Index)
return Index.ToString();
}

public static string GetExportPropertyName(this Uasset SourceFile, int Index)
public static string GetExportPropertyName(this IUasset SourceFile, int Index)
{
if (SourceFile.IOFile)
{
Expand Down Expand Up @@ -69,10 +69,11 @@ private static int GetRequiredUtf16Padding(uint NameData)
{
return (int)(NameData & 1u);
}
private static bool IsUtf16(byte NameData)
public static bool IsUtf16(byte NameData)
{
return (NameData & 0x80u) != 0;
}

public static string GetStringUES(this MemoryList memoryList)
{
string Stringvalue = "";
Expand All @@ -98,6 +99,29 @@ public static string GetStringUES(this MemoryList memoryList)

return ReplaceBreaklines(Stringvalue).TrimEnd('\0');
}

public static string GetStringUES(this MemoryList memoryList, short namedata)
{
string Stringvalue;
byte[] Data = new byte[2];
Data[0] = (byte)(namedata & 0xff);
Data[1] = (byte)(namedata >> 8);

int len = (int)((Data[0] & 0x7Fu) << 8) + Data[1];

if (IsUtf16(Data[0]))
{
Stringvalue = memoryList.GetStringValue(len * 2, true, -1, Encoding.Unicode);
}
else
{
Stringvalue = memoryList.GetStringValue(len);
}


return ReplaceBreaklines(Stringvalue).TrimEnd('\0');
}

public static string GetStringUE(this MemoryList memoryList, Encoding encoding)
{
string Stringvalue = ReplaceBreaklines(memoryList.GetStringValueN(true, -1, encoding));
Expand All @@ -119,20 +143,20 @@ public static string GetStringUE(this MemoryList memoryList, int Lenght, bool Sa



public static void ReplaceStringUE_Func(this MemoryList memoryList, string StringValue)
public static int ReplaceStringUE_Func(this MemoryList memoryList, string StringValue)
{

int StringLength = 0;
StringValue = ReplaceBreaklines(StringValue, true);

memoryList.Skip(-1);
ExprToken eExpr = (ExprToken)memoryList.GetByteValue();
if (eExpr == ExprToken.EX_StringConst)
{
memoryList.DeleteStringN(-1, Encoding.ASCII);
StringLength = memoryList.DeleteStringN(-1, Encoding.ASCII);
}
else if (eExpr == ExprToken.EX_UnicodeStringConst)
{
memoryList.DeleteStringN(-1, Encoding.Unicode);
StringLength = memoryList.DeleteStringN(-1, Encoding.Unicode);
}
memoryList.Skip(-1);

Expand All @@ -153,6 +177,7 @@ public static void ReplaceStringUE_Func(this MemoryList memoryList, string Strin
memoryList.SetByteValue((byte)ExprToken.EX_UnicodeStringConst);
memoryList.InsertStringValueN(StringValue, true, -1, encoding);
}
return StringLength;
}


Expand Down
2 changes: 1 addition & 1 deletion UE4localizationsTool/Core/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Function(MemoryList memoryList, Uexp Uexp, bool modify = false)
int ExportIndex = memoryList.GetIntValue();
IndexEntries.Add(ExportIndex);
}

//TODO :(
if (uexp.UassetData.Exports_Directory[Uexp.ExportIndex].Value >= 4 || uexp.UassetData.EngineVersion >= UEVersions.VER_UE4_ADDED_PACKAGE_OWNER)
{
Expand Down
Loading

0 comments on commit ab03000

Please sign in to comment.