Skip to content

Commit

Permalink
Fix FName issues (#7).
Browse files Browse the repository at this point in the history
  • Loading branch information
just-ero committed Oct 18, 2022
1 parent 72a3569 commit 4c45e90
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 69 deletions.
Binary file modified lib/asl-help
Binary file not shown.
2 changes: 2 additions & 0 deletions src/Basic/HelperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ await TaskBuilder<bool>.Create(_cts)
.Catch<RuntimeBinderException>()
.RetryOnFailure()
.Catch<InvalidAddressException>()
.WithFailureMessage(ex => ex.Message)
.RetryOnFailure()
.Catch<NotFoundException>()
.WithFailureMessage(ex => ex.Message)
.RetryOnFailure()
.WithTimeout(TryLoadTimeout)
.WithFailureMessage("TryLoad not successful.")
Expand Down
2 changes: 1 addition & 1 deletion src/Basic/MemoryUtils/Reflect/ReflectXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static ReflectXml GetFromResources(string engine, string major, string mi
}

ReflectXml refXml = CreateFromInherited(root.Element("Inherit"));
refXml.AddStructs(engine is "Unreal", root.Elements("Struct"));
refXml.AddStructs(engine == "Unreal", root.Elements("Struct"));

return refXml;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Basic/Tasks/ExceptionStage/ExceptionStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ IExceptionStage<TResult, TException> IExceptionStage<TResult, TException>.WithFa
return this;
}

IExceptionStage<TResult, TException> IExceptionStage<TResult, TException>.WithFailureMessage(Func<TException, string> message)
IExceptionStage<TResult, TException> IExceptionStage<TResult, TException>.WithFailureMessage(Func<Exception, string> message)
{
if (FailureMessage is not null)
{
string msg = "Failure message was already set.";
throw new InvalidOperationException(msg);
}

FailureMessage = new((Func<Exception, string>)message);
FailureMessage = new(message);
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Basic/Tasks/ExceptionStage/IExceptionStage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IExceptionStage<TResult, TException>
where TException : Exception
{
IExceptionStage<TResult, TException> WithFailureMessage(string message);
IExceptionStage<TResult, TException> WithFailureMessage(Func<TException, string> message);
IExceptionStage<TResult, TException> WithFailureMessage(Func<Exception, string> message);

ICatchStage<TResult> RetryOnFailure();
ICatchStage<TResult> BreakOnFailure();
Expand Down
2 changes: 1 addition & 1 deletion src/Unity/Mono/Models/MonoImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override void OnFound(MonoClass monoClass)
monoClass.DebugAllFields();
}

protected override void OnNotFound(string key)
protected override void OnNotFound(string name)
{
Debug.Info(" => Not found!");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Unreal/Helper/Unreal.Load.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ protected override UEMemManager MakeManager()
(4, < 8) => new UE4_0Manager(UEVersion.Major, UEVersion.Minor),
(4, < 11) => new UE4_8Manager(UEVersion.Major, UEVersion.Minor),
(4, < 20) => new UE4_11Manager(UEVersion.Major, UEVersion.Minor),
(4, < 22) => new UE4_20Manager(UEVersion.Major, UEVersion.Minor),
(4, < 23) => new UE4_23Manager(UEVersion.Major, UEVersion.Minor),
(4, < 23) => new UE4_20Manager(UEVersion.Major, UEVersion.Minor),
(4, < 25) => new UE4_23Manager(UEVersion.Major, UEVersion.Minor),
(4, _) or (5, _) => new UE4_25Manager(UEVersion.Major, UEVersion.Minor),
_ => throw new NotSupportedException($"Unreal Engine version {UEVersion.Major}.{UEVersion.Minor} is not supported yet.")
};
Expand Down
20 changes: 10 additions & 10 deletions src/Unreal/Structs/4_23.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<Structs>
<Inherit Engine="Unreal" Major="4" Minor="22" />

<Struct Name="FNamePool">
<Field Name="Entries" Type="FNameEntryAllocator" />
</Struct>
<Struct Name="FNameEntryAllocator">
<Field Name="Lock" Type="FRWLock" />
<Field Name="CurrentBlock" Type="uint" />
<Field Name="CurrentByteCursor" Type="uint" />
<Field Name="Blocks" Type="byte*" />
</Struct>
<Struct Name="FNamePool">
<Field Name="Entries" Type="FNameEntryAllocator" />
</Struct>

<Struct Name="FNameEntry">
<Field Name="Header" Type="FNameEntryHeader" />
<Field Name="Name" Type="char[]" />
</Struct>
<Struct Name="FNameEntryHeader">
<Field Name="bIsWide" Type="ushort:1" />
<Field Name="LowercaseProbeHash" Type="ushort:5" />
<Field Name="Len" Type="ushort:10" />
</Struct>
<Struct Name="FNameEntry">
<Field Name="Header" Type="FNameEntryHeader" />
<Field Name="Name" Type="string" />
</Struct>
<Struct Name="FNameEntryId">
<Field Name="Value" Type="uint" />
</Struct>
<Struct Name="FName">
<Field Name="ComparisonIndex" Type="FNameEntryId" />
<Field Name="Number" Type="int" />
</Struct>
<Struct Name="FNameEntryId">
<Field Name="Value" Type="uint" />
</Struct>
</Structs>
42 changes: 2 additions & 40 deletions src/Unreal/UE/Managers/Base/UEMemManager.Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,66 +28,28 @@ private bool Scan(int major, int minor)
_fNamePool = _game.Scan(_fNamesTrg);
if (_fNamePool == default)
{
if (_game.MainModule.Symbols.TryGetValue("FNamePool", out DebugSymbol symbol))
{
_fNamePool = symbol.Address;
}
else
{
throw new FatalNotFoundException("FNamePool could not be found.");
}
throw new FatalNotFoundException("FNamePool could not be found.");
}

Debug.Info($"FNamePool: 0x{_fNamePool.ToString("X")}");

_gUObjectArray = _game.Scan(_uObjectsTrg);
if (_gUObjectArray == default)
{
if (_game.MainModule.Symbols.TryGetValue("GUObjectArray", out DebugSymbol symbol))
{
_gUObjectArray = symbol.Address;
}
else
{
throw new FatalNotFoundException("GUObjectArray could not be found.");
}
throw new FatalNotFoundException("GUObjectArray could not be found.");
}

Debug.Info($"GUObjectArray: 0x{_gUObjectArray.ToString("X")}");

GWorld = _game.ScanRel(_gWorldTrg);
if (GWorld == default)
{
if (_game.MainModule.Symbols.TryGetValue("GWorld", out DebugSymbol symbol))
{
GWorld = symbol.Address;
}
}

Debug.Info($"GWorld: 0x{GWorld.ToString("X")}");

GEngine = _game.ScanRel(_gEngineTrg);
if (GEngine == default)
{
if (_game.MainModule.Symbols.TryGetValue("GEngine", out DebugSymbol symbol))
{
GEngine = symbol.Address;
}
}

Debug.Info($"GEngine: 0x{GEngine.ToString("X")}");

if ((major, minor) is (4, >= 20) or (5, _))
{
GSyncLoadCount = _game.ScanRel(_gSyncLoadCountTrg);
if (GSyncLoadCount == default)
{
if (_game.MainModule.Symbols.TryGetValue("GSyncLoadCount", out DebugSymbol symbol))
{
GSyncLoadCount = symbol.Address;
}
}

Debug.Info($"GSyncLoadCount: 0x{GSyncLoadCount.ToString("X")}");
}

Expand Down
17 changes: 6 additions & 11 deletions src/Unreal/UE/Managers/UE4_23Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,27 @@ internal override IEnumerable<FName> EnumerateFNames()
break;
}

yield return new((chunkId << 16) | offset);
yield return new((chunkId << 16) | offset, FNameName(cursor));

cursor += 2 + length;

if ((cursor & 1) != 0)
{
cursor += 1;
}
cursor += 2 + length + (cursor & 1);

offset = getOffset(cursor);
}

chunkId++;
chunk = fNamePool + (ptrSize * chunkId);
chunk = ReadPtr(fNamePool + (ptrSize * chunkId));
}

int getOffset(nint cursor)
{
return (int)(cursor - (long)chunk) >> 1;
return (int)((long)cursor - (long)chunk) >> 1;
}
}

internal override nint FNameNameEntry(int fNameIndex)
{
nint entry = ReadPtr(FNamePool + (_game.PtrSize * (fNameIndex >> 16)));
return (entry + (fNameIndex & ushort.MaxValue)) << 1;
return entry + ((fNameIndex & ushort.MaxValue) << 1);
}

internal override int FNameIndex(nint fName)
Expand All @@ -67,7 +62,7 @@ internal override string FNameName(nint fName)
int length = FNameLength(fName, out bool isWide);
ReadStringType type = isWide ? ReadStringType.UTF16 : ReadStringType.UTF8;

return _game.ReadString(length, type, fName + _engine["FNameEntry"]["Name"]) ?? "";
return _game.ReadString(length, type, fName + _engine["FNameEntry"]["Name"]);
}

internal virtual int FNameLength(nint fName, out bool isWide)
Expand Down
16 changes: 15 additions & 1 deletion src/Unreal/UE/Models/UObjectCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ public override IEnumerator<UObject> GetEnumerator()

protected override string GetKey(UObject uObject)
{
return uObject.Outer + "." + uObject;
string obj = uObject.ToString();

if (uObject.Outer?.ToString() is string outer && outer != "")
{
return outer + "." + obj;
}
else
{
return obj;
}
}

protected override void OnSearch(string name)
Expand All @@ -44,4 +53,9 @@ protected override void OnFound(UObject uObject)

// uObject.DebugAllFields();
}

protected override void OnNotFound(string name)
{
Debug.Info(" => Not found!");
}
}

0 comments on commit 4c45e90

Please sign in to comment.