Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ riderModule.iml
/_ReSharper.Caches/

# Visual Studio build files
.vs
.vs
*.sln.DotSettings.user

# Jetbrains IDE
.idea/*
global.json
3 changes: 2 additions & 1 deletion UE.Toolkit.Core/Common/ToolkitUtils.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Concurrent;
using UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Common;

public static unsafe class ToolkitUtils
{
private static readonly Dictionary<FName, string> PrivateToNativeNameMap = [];
private static readonly ConcurrentDictionary<FName, string> PrivateToNativeNameMap = [];

public static nint GetGlobalAddress(nint address) => *(int*)address + address + 4;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
public unsafe abstract class InlineAllocator<TType, TSize> : ContainerAllocationPolicy<TType, TSize>
where TType : unmanaged where TSize : INumber<TSize>
{
protected TType* Heap;
protected TType* Heap = null;
protected TSize NumInlineElements;

Check warning on line 50 in UE.Toolkit.Core/Types/Interfaces/IContainerAllocationPolicies.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'NumInlineElements' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

public bool HasAllocation() => Heap != null;
public TSize GetInitialCapacity() => NumInlineElements;
Expand All @@ -62,12 +62,8 @@
public override nint GetAllocatedSize(int NumAllocatedElements, nint NumBytesPerElement)
{
if (NumAllocatedElements > NumInlineElements)
{
return (NumAllocatedElements - NumInlineElements) * NumBytesPerElement;
} else
{
return 0;
}
return 0;
}
}

Expand All @@ -79,7 +75,7 @@
public unsafe class FixedAllocator<TType, TSize> : ContainerAllocationPolicy<TType, TSize>
where TType : unmanaged where TSize : INumber<TSize>
{
protected TSize NumInlineElements;

Check warning on line 78 in UE.Toolkit.Core/Types/Interfaces/IContainerAllocationPolicies.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'NumInlineElements' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public TSize GetInitialCapacity() => NumInlineElements;

public bool HasAllocation() => false;
Expand Down
25 changes: 25 additions & 0 deletions UE.Toolkit.Core/Types/Interfaces/IInvocationParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Runtime.InteropServices;

namespace UE.Toolkit.Core.Types.Interfaces;

public interface IInvocationParameter
{
object? Value { get; }

void ToAlloc(nint pAlloc); // for in parameters
void FromAlloc(nint pAlloc); // for out parameters/return type

string ExpectedPropertyClass { get; }
int ExpectedSize { get; }
}

public abstract class InvocationParameterCopyable<T>(T value) : IInvocationParameter where T: unmanaged
{
protected T InnerValue { get; set; } = value;
public object? Value => InnerValue;

public unsafe void ToAlloc(nint pAlloc) => *(T*)pAlloc = InnerValue;
public unsafe void FromAlloc(nint pAlloc) => InnerValue = *(T*)pAlloc;
public int ExpectedSize => Marshal.SizeOf<T>();
public abstract string ExpectedPropertyClass { get; }
}
23 changes: 23 additions & 0 deletions UE.Toolkit.Core/Types/Interfaces/IUnrealClassesInternal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Interfaces;

public class FieldClassGlobal(nint vtable, IFFieldClass param)
{
public readonly nint Vtable = vtable;
public readonly IFFieldClass Params = param;
}

public interface IUnrealClassesInternal
{
public bool GetFieldClassGlobal(FName Name, out FieldClassGlobal FieldClass);
}

[Flags]
public enum StructType
{
None = 0,
Class = 1 << 0,
ScriptStruct = 1 << 1
}
26 changes: 26 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/BaseUnrealFactory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using UE.Toolkit.Core.Types.Interfaces;
using UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

namespace UE.Toolkit.Core.Types.Unreal.Factories;

public abstract class BaseUnrealFactory : IUnrealFactory
{

public IUnrealMemoryInternal? Memory { get; set; }

public T Cast<T>(IPtr obj)
{
var typeName = typeof(T).Name;
Expand All @@ -19,8 +23,11 @@ public T Cast<T>(IPtr obj)
return (T)CreateUEnum(obj.Ptr);
case nameof(IUUserDefinedEnum):
return (T)CreateUUserDefinedEnum(obj.Ptr);

case nameof(IFByteProperty):
return (T)CreateFByteProperty(obj.Ptr);
case nameof(IFBoolProperty):
return (T)CreateFBoolProperty(obj.Ptr);
case nameof(IFEnumProperty):
return (T)CreateFEnumProperty(obj.Ptr);
case nameof(IFObjectProperty):
Expand All @@ -41,12 +48,15 @@ public T Cast<T>(IPtr obj)
return (T)CreateFSetProperty(obj.Ptr);
case nameof(IFOptionalProperty):
return (T)CreateFOptionalProperty(obj.Ptr);

default:
throw new NotSupportedException(typeName);
}
}
public abstract nint SizeOf<T>();

public abstract IFProperty CreateFProperty(nint ptr);
public abstract IFBoolProperty CreateFBoolProperty(nint ptr);
public abstract IFByteProperty CreateFByteProperty(nint ptr);
public abstract IFEnumProperty CreateFEnumProperty(nint ptr);
public abstract IFObjectProperty CreateFObjectProperty(nint ptr);
Expand All @@ -58,14 +68,30 @@ public T Cast<T>(IPtr obj)
public abstract IFArrayProperty CreateFArrayProperty(nint ptr);
public abstract IFSetProperty CreateFSetProperty(nint ptr);
public abstract IFOptionalProperty CreateFOptionalProperty(nint ptr);

public abstract IUObjectArray CreateUObjectArray(nint ptr);

public abstract IUObject CreateUObject(nint ptr);
public abstract IUClass CreateUClass(nint ptr);
public abstract IUScriptStruct CreateUScriptStruct(nint ptr);
public abstract IUEnum CreateUEnum(nint ptr);
public abstract IUField CreateUField(nint ptr);
public abstract IUStruct CreateUStruct(nint ptr);
public abstract IUUserDefinedEnum CreateUUserDefinedEnum(nint ptr);
// public abstract IUPackage CreateUPackage(nint ptr);
public abstract IUFunction CreateUFunction(nint ptr);

public abstract IFFieldClass CreateFFieldClass(nint ptr);
public abstract IFField CreateFField(nint ptr);

public abstract IFStructParams CreateFStructParams(nint ptr);
public abstract IFPropertyParams CreateFPropertyParams(nint ptr);
public abstract IFGenericPropertyParams CreateFGenericPropertyParams(nint ptr);

public abstract IFWorldContext CreateFWorldContext(nint ptr);
public abstract IUEngine CreateUEngine(nint ptr);
public abstract IUGameInstance CreateUGameInstance(nint ptr);

public abstract IFStaticConstructObjectParameters CreateFStaticConstructObjectParameters();
public abstract IFActorSpawnParameters CreateFActorSpawnParameters();
}
20 changes: 20 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/IUnrealFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using UE.Toolkit.Core.Types.Interfaces;
using UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

namespace UE.Toolkit.Core.Types.Unreal.Factories;
Expand All @@ -8,7 +9,11 @@ namespace UE.Toolkit.Core.Types.Unreal.Factories;
public interface IUnrealFactory
{
T Cast<T>(IPtr obj);
nint SizeOf<T>();
IUnrealMemoryInternal? Memory { get; set; }

IFProperty CreateFProperty(nint ptr);
IFBoolProperty CreateFBoolProperty(nint ptr);
IFByteProperty CreateFByteProperty(nint ptr);
IFEnumProperty CreateFEnumProperty(nint ptr);
IFObjectProperty CreateFObjectProperty(nint ptr);
Expand All @@ -20,6 +25,7 @@ public interface IUnrealFactory
IFArrayProperty CreateFArrayProperty(nint ptr);
IFSetProperty CreateFSetProperty(nint ptr);
IFOptionalProperty CreateFOptionalProperty(nint ptr);

IUObjectArray CreateUObjectArray(nint ptr);
IUObject CreateUObject(nint ptr);
IUClass CreateUClass(nint ptr);
Expand All @@ -28,6 +34,20 @@ public interface IUnrealFactory
IUField CreateUField(nint ptr);
IUStruct CreateUStruct(nint ptr);
IUUserDefinedEnum CreateUUserDefinedEnum(nint ptr);
// IUPackage CreateUPackage(nint ptr);
IUFunction CreateUFunction(nint ptr);

IFFieldClass CreateFFieldClass(nint ptr);
IFField CreateFField(nint ptr);

IFStructParams CreateFStructParams(nint ptr);
IFPropertyParams CreateFPropertyParams(nint ptr);
IFGenericPropertyParams CreateFGenericPropertyParams(nint ptr);

IFWorldContext CreateFWorldContext(nint ptr);
IUEngine CreateUEngine(nint ptr);
IUGameInstance CreateUGameInstance(nint ptr);

IFStaticConstructObjectParameters CreateFStaticConstructObjectParameters();
IFActorSpawnParameters CreateFActorSpawnParameters();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFActorSpawnParameters : IPtr
{
void SetParams(EObjectFlags Flags);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFBoolProperty : IFProperty
{
byte FieldSize { get; }
byte ByteOffset { get; }
byte ByteMask { get; }
byte FieldMask { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFFieldClass
public interface IFFieldClass : IPtr
{
string Name { get; }
ulong Id { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFPropertyParams : IPtr
{
string Name { get; }
EPropertyFlags PropertyFlags { get; }
EPropertyGenFlags GenFlags { get; }
EObjectFlags ObjectFlags { get; }
}

public interface IFGenericPropertyParams : IFPropertyParams
{
int ArrayDim { get; }
int Offset { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFStaticConstructObjectParameters : IPtr
{
void SetParams(IUClass Class, IUObject? Owner, FName Name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFStructParams : IPtr
{
nint OuterFunc { get; }
nint SuperFunc { get; }
nint StructOpsFunc { get; }
string Name { get; }
ulong Size { get; }
ulong Alignment { get; }
EObjectFlags ObjectFlags { get; }
EStructFlags StructFlags { get; }
int PropertyCount { get; }
IFPropertyParams? GetProperty(int Index);
IEnumerable<IFPropertyParams> Properties { get; }
// IEnumerable<IFPropertyParams> Properties { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IFWorldContext : IPtr
{
public WorldType GetWorldType();
public nint GetWorld();
}
2 changes: 2 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/Interfaces/IUClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;
public interface IUClass : IUStruct
{
IUClass? GetSuperClass();

IUFunction? GetFunction(string Name);
}
6 changes: 6 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/Interfaces/IUEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IUEngine : IUObject
{
public IEnumerable<IFWorldContext> GetWorldList();
}
13 changes: 13 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/Interfaces/IUFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IUFunction : IUStruct
{
EFunctionFlags FunctionFlags { get; }
int ParamCount { get; }
int ParamSize { get; }
int ReturnValueOffset { get; }

int GetTotalParameterSize();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IUGameInstance : IUObject
{
bool TryGetSubsystem(IUClass Class, out IUObject? Subsystem);
}
2 changes: 2 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/Interfaces/IUObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public interface IUObject : IPtr
IUObject GetOutermost();

string GetNativeName();

// IUObject GetWorld();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public interface IUObjectArray

IUObject? IndexToObject(int idx);

void AddToRootSet(int idx);

void RemoveFromRootSet(int idx);

}
10 changes: 10 additions & 0 deletions UE.Toolkit.Core/Types/Unreal/Factories/Interfaces/IUPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UE.Toolkit.Core.Types.Unreal.UE5_4_4;

namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public interface IUPackage : IUObject
{
public ulong PackageId { get; }
public ulong FileSize { get; }
public FName FileName { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UE.Toolkit.Core.Types.Unreal.Factories.Interfaces;

public enum PropertyVisibility
{
Public, // CPF_NativeAccessSpecifierPublic
Protected, // CPF_NativeAccessSpecifierProtected
Private // CPF_NativeAccessSpecifierPrivate
}
Loading
Loading