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

Commit

Permalink
Changes for v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
amrshaheen61 committed Apr 26, 2023
1 parent c4cf472 commit 443c566
Show file tree
Hide file tree
Showing 18 changed files with 487 additions and 376 deletions.
3 changes: 3 additions & 0 deletions UE4localizationsTool/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<setting name="DarkMode" serializeAs="String">
<value>False</value>
</setting>
<setting name="CheckForUpdates" serializeAs="String">
<value>True</value>
</setting>
</UE4localizationsTool.Properties.Settings>
</userSettings>
</configuration>
104 changes: 103 additions & 1 deletion UE4localizationsTool/Core/AssetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static string GetExportPropertyName(this Uasset SourceFile, int Index)

public static void ReadExtraByte(this MemoryList memoryList, Uexp SourceFile, bool fromStruct)
{
if (fromStruct && SourceFile.UassetData.EngineVersion >= UE4Version.VER_UE4_NAME_HASHES_SERIALIZED)
if (fromStruct && SourceFile.UassetData.EngineVersion >= UEVersions.VER_UE4_NAME_HASHES_SERIALIZED)
{
memoryList.Skip(1);
}
Expand Down Expand Up @@ -103,6 +103,11 @@ public static string GetStringUE(this MemoryList memoryList, Encoding encoding)
string Stringvalue = ReplaceBreaklines(memoryList.GetStringValueN(true, -1, encoding));
return Stringvalue.TrimEnd('\0');
}
public static void SetStringUE(this MemoryList memoryList, string str, Encoding encoding)
{
memoryList.SetStringValueN(ReplaceBreaklines(str, true), true, -1, encoding);
}


public static string GetStringUE(this MemoryList memoryList, int Lenght, bool SavePosition = true, int SeekAndRead = -1, Encoding encoding = null)
{
Expand Down Expand Up @@ -263,5 +268,102 @@ public ReadStringProperty(MemoryList memoryList, Uexp uexp, string PropertyName,
}
}

public class FName
{
public FName(MemoryList memoryList, Uexp uexp, string PropertyName, bool Modify = false)
{
int NameIndex = memoryList.GetIntValue();
memoryList.Skip(4);
if (!Modify)
{
uexp.Strings.Add(new List<string>() { PropertyName, uexp.UassetData.GetPropertyName(NameIndex), !uexp.UassetData.IOFile ? "be careful with this value." : "Can't edit this value.", !uexp.UassetData.IOFile ? "#FFBFB2" : "#FF0000", "#000000" });
}
else
{
uexp.UassetData.EditName(uexp.Strings[uexp.CurrentIndex][1], NameIndex);
uexp.CurrentIndex++;
}
}
}


public class TextHistory
{
public TextHistory(MemoryList memoryList, Uexp uexp, string PropertyName, bool Modify = false)
{
memoryList.Skip(4); //unkown
TextHistoryType texthistorytype = (TextHistoryType)memoryList.GetUByteValue();
switch (texthistorytype)
{
case TextHistoryType.None:
if (memoryList.GetIntValue() != 0)
{
new ReadStringProperty(memoryList, uexp, PropertyName, Modify);
}
break;

case TextHistoryType.Base:
new ReadStringProperty(memoryList, uexp, PropertyName + "_1", Modify);
new ReadStringProperty(memoryList, uexp, PropertyName + "_2", Modify);
new ReadStringProperty(memoryList, uexp, PropertyName + "_3", Modify);
break;
case TextHistoryType.NamedFormat:
case TextHistoryType.OrderedFormat:
{
new TextHistory(memoryList, uexp, PropertyName, Modify);
int ArgumentsCount = memoryList.GetIntValue();
for (int i = 0; i < ArgumentsCount; i++)
{
GetArgumentValue(memoryList, uexp, PropertyName, Modify);
}
}
break;

case TextHistoryType.AsNumber:
case TextHistoryType.AsPercent:
case TextHistoryType.AsCurrency:
{
GetArgumentValue(memoryList, uexp, PropertyName, Modify);
new ReadStringProperty(memoryList, uexp, PropertyName + "_1", Modify);
new ReadStringProperty(memoryList, uexp, PropertyName + "_2", Modify);
}
break;
case TextHistoryType.StringTableEntry:
new FName(memoryList, uexp, PropertyName, Modify);
new ReadStringProperty(memoryList, uexp, PropertyName + "_1", Modify);
break;

default:
throw new Exception("UnKnown 'TextProperty' type: " + texthistorytype.ToString());
}
}

private static void GetArgumentValue(MemoryList memoryList, Uexp uexp, string PropertyName, bool Modify)
{
FormatArgumentType Type = (FormatArgumentType)memoryList.GetUByteValue();

switch (Type)
{
case FormatArgumentType.Text:
new TextHistory(memoryList, uexp, PropertyName, Modify);
break;
case FormatArgumentType.Int:
case FormatArgumentType.UInt:
case FormatArgumentType.Double:
memoryList.Skip(8);
break;
case FormatArgumentType.Float:
memoryList.Skip(4);
break;
case FormatArgumentType.Gender:
memoryList.Skip(1);
break;
default:
throw new Exception("Unkown argument type: " + Type.ToString());
}
}
}



}
16 changes: 13 additions & 3 deletions UE4localizationsTool/Core/ConsoleMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ namespace AssetParser
{
public static class ConsoleMode
{

public static void Print(string Str, ConsoleColor color = ConsoleColor.White)
public enum ConsoleModeType
{
Normal,
Error
}
public static bool Show = false;
public static bool StopInError = false;
public static void Print(string Str, ConsoleColor color = ConsoleColor.White, ConsoleModeType type = ConsoleModeType.Normal)
{
bool Show = false;
if (Show)
{
Console.ForegroundColor = color;
Console.WriteLine(Str);
Console.ForegroundColor = ConsoleColor.White;
if (type == ConsoleModeType.Error && StopInError)
{
Print("Press \"Enter\" to continue...", ConsoleColor.White);
Console.ReadLine();
}
}
}
}
Expand Down
79 changes: 77 additions & 2 deletions UE4localizationsTool/Core/Enum.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace AssetParser
using System;

namespace AssetParser
{
public enum UE4Version
public enum UEVersions
{
UNKNOWN = 0,
VER_UE4_OLDEST_LOADABLE_PACKAGE = 214,
Expand Down Expand Up @@ -342,6 +344,18 @@ public enum UE4Version
VER_UE4_25 = 518,
VER_UE4_26 = 519,
VER_UE4_27 = 522,
INITIAL_VERSION = 1000,
NAMES_REFERENCED_FROM_EXPORT_DATA,
PAYLOAD_TOC,
OPTIONAL_RESOURCES,
LARGE_WORLD_COORDINATES,
REMOVE_OBJECT_EXPORT_PACKAGE_GUID,
TRACK_OBJECT_EXPORT_IS_INHERITED,
FSOFTOBJECTPATH_REMOVE_ASSET_PATH_FNAMES,
ADD_SOFTOBJECTPATH_LIST,
AUTOMATIC_VERSION_PLUS_ONE,
AUTOMATIC_VERSION = AUTOMATIC_VERSION_PLUS_ONE - 1,
VER_UE5_0 = AUTOMATIC_VERSION
};

public enum ExprToken
Expand Down Expand Up @@ -459,4 +473,65 @@ public enum TextHistoryType
TextGenerator
}



public enum FormatArgumentType
{
Int,
UInt,
Float,
Double,
Text,
Gender
}


/**
* Package flags, passed into UPackage::SetPackageFlags and related functions
* from:https://github.com/EpicGames/UnrealEngine/blob/cdaec5b33ea5d332e51eee4e4866495c90442122/Engine/Source/Runtime/CoreUObject/Public/UObject/ObjectMacros.h
*/
[Flags]
public enum EPackageFlags : uint
{
PKG_None = 0x00000000, ///< No flags
PKG_NewlyCreated = 0x00000001, ///< Newly created package, not saved yet. In editor only.
PKG_ClientOptional = 0x00000002, ///< Purely optional for clients.
PKG_ServerSideOnly = 0x00000004, ///< Only needed on the server side.
PKG_CompiledIn = 0x00000010, ///< This package is from "compiled in" classes.
PKG_ForDiffing = 0x00000020, ///< This package was loaded just for the purposes of diffing
PKG_EditorOnly = 0x00000040, ///< This is editor-only package (for example: editor module script package)
PKG_Developer = 0x00000080, ///< Developer module
PKG_UncookedOnly = 0x00000100, ///< Loaded only in uncooked builds (i.e. runtime in editor)
PKG_Cooked = 0x00000200, ///< Package is cooked
PKG_ContainsNoAsset = 0x00000400, ///< Package doesn't contain any asset object (although asset tags can be present)
PKG_NotExternallyReferenceable = 0x00000800, ///< Objects in this package cannot be referenced in a different plugin or mount point (i.e /Game -> /Engine)
// PKG_Unused = 0x00001000,
PKG_UnversionedProperties = 0x00002000, ///< Uses unversioned property serialization instead of versioned tagged property serialization
PKG_ContainsMapData = 0x00004000, ///< Contains map data (UObjects only referenced by a single ULevel) but is stored in a different package
PKG_IsSaving = 0x00008000, ///< Temporarily set on a package while it is being saved.
PKG_Compiling = 0x00010000, ///< package is currently being compiled
PKG_ContainsMap = 0x00020000, ///< Set if the package contains a ULevel/ UWorld object
PKG_RequiresLocalizationGather = 0x00040000, ///< Set if the package contains any data to be gathered by localization
// PKG_Unused = 0x00080000,
PKG_PlayInEditor = 0x00100000, ///< Set if the package was created for the purpose of PIE
PKG_ContainsScript = 0x00200000, ///< Package is allowed to contain UClass objects
PKG_DisallowExport = 0x00400000, ///< Editor should not export asset in this package
// PKG_Unused = 0x00800000,
// PKG_Unused = 0x01000000,
// PKG_Unused = 0x02000000,
// PKG_Unused = 0x04000000,
PKG_CookGenerated = 0x08000000, ///< This package was generated by the cooker and does not exist in the WorkspaceDomain
PKG_DynamicImports = 0x10000000, ///< This package should resolve dynamic imports from its export at runtime.
PKG_RuntimeGenerated = 0x20000000, ///< This package contains elements that are runtime generated, and may not follow standard loading order rules
PKG_ReloadingForCooker = 0x40000000, ///< This package is reloading in the cooker, try to avoid getting data we will never need. We won't save this package.
PKG_FilterEditorOnly = 0x80000000, ///< Package has editor-only data filtered out

// Transient Flags are cleared when serializing to or from PackageFileSummary
PKG_TransientFlags = PKG_NewlyCreated | PKG_IsSaving | PKG_ReloadingForCooker,
};



}


10 changes: 5 additions & 5 deletions UE4localizationsTool/Core/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Function(MemoryList memoryList, Uexp Uexp, bool modify = false)
offsetList = new List<int>();
stringOffset = new List<List<int>>();
NewSize = 0;
if (uexp.UassetData.EngineVersion < UE4Version.VER_UE4_16)
if (uexp.UassetData.EngineVersion < UEVersions.VER_UE4_16)
{
return;
}
Expand All @@ -43,11 +43,11 @@ public Function(MemoryList memoryList, Uexp Uexp, bool modify = false)
}

//TODO :(
if (uexp.UassetData.Exports_Directory[Uexp.ExportIndex].Value >= 4 || uexp.UassetData.EngineVersion >= UE4Version.VER_UE4_ADDED_PACKAGE_OWNER)
if (uexp.UassetData.Exports_Directory[Uexp.ExportIndex].Value >= 4 || uexp.UassetData.EngineVersion >= UEVersions.VER_UE4_ADDED_PACKAGE_OWNER)
{
if (uexp.UassetData.AutoVersion)
{
uexp.UassetData.EngineVersion = UE4Version.VER_UE4_26;
uexp.UassetData.EngineVersion = UEVersions.VER_UE4_26;
}

int num = memoryList.GetIntValue();
Expand Down Expand Up @@ -221,7 +221,7 @@ void ReadFProperty(MemoryList memoryList)

void ReadPPOINTER()
{
if (uexp.UassetData.EngineVersion >= UE4Version.VER_UE4_25)
if (uexp.UassetData.EngineVersion >= UEVersions.VER_UE4_25)
{
int num = FuncBlock.GetIntValue();
for (int i = 0; i < num; i++)
Expand Down Expand Up @@ -479,7 +479,7 @@ ExprToken ReadExpression()

case ExprToken.EX_SetArray:

if (uexp.UassetData.EngineVersion >= UE4Version.VER_UE4_CHANGE_SETARRAY_BYTECODE)
if (uexp.UassetData.EngineVersion >= UEVersions.VER_UE4_CHANGE_SETARRAY_BYTECODE)
{
ReadExpression();
}
Expand Down
16 changes: 5 additions & 11 deletions UE4localizationsTool/Core/Games/RED Game/REDLibraryTextData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ namespace AssetParser
{
public class REDLibraryTextData
{

int StartOffset;
int UncompressedSize;
int CompressedSize;
int StringCount;

public REDLibraryTextData(MemoryList memoryList, Uexp uexp, bool Modify = false)
{
memoryList.GetIntValue();//Null
Expand All @@ -21,8 +15,8 @@ public REDLibraryTextData(MemoryList memoryList, Uexp uexp, bool Modify = false)
memoryList.GetIntValue(); //Start Data offset
memoryList.Skip(8); //Unknown2
int ValuesPosition = memoryList.GetPosition();
UncompressedSize = memoryList.GetIntValue();
CompressedSize = memoryList.GetIntValue();
int UncompressedSize = memoryList.GetIntValue();
int CompressedSize = memoryList.GetIntValue();
if (UncompressedSize != CompressedSize)
{
throw new Exception("Can't Parse this file.");
Expand All @@ -31,11 +25,11 @@ public REDLibraryTextData(MemoryList memoryList, Uexp uexp, bool Modify = false)

memoryList.GetIntValue();//Null

StartOffset = memoryList.GetPosition();
int StartOffset = memoryList.GetPosition();

MemoryList Block = new MemoryList(memoryList.GetBytes(UncompressedSize));

StringCount = Block.GetIntValue();
int StringCount = Block.GetIntValue();


string[] IdValues = new string[StringCount];
Expand Down Expand Up @@ -64,7 +58,7 @@ public REDLibraryTextData(MemoryList memoryList, Uexp uexp, bool Modify = false)

for (int i = 0; i < StringCount; i++)
{
Block.SetStringValueN(uexp.Strings[uexp.CurrentIndex][1]);
Block.SetStringUE(uexp.Strings[uexp.CurrentIndex][1], Encoding.Unicode);
uexp.CurrentIndex++;
}

Expand Down
Loading

0 comments on commit 443c566

Please sign in to comment.