Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Adds more implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
iainmckay committed Jul 30, 2019
1 parent 513aa4e commit 8029275
Show file tree
Hide file tree
Showing 13 changed files with 154 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,11 @@ internal virtual void SetupInputComponentInternal()
// This is eventually implemented in injected classes
}

internal virtual void UpdateRotationInternal(float DeltaTime)
{
// This is eventually implemented in injected classes
}

/// <summary>
/// Looks for a given function name
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace UnrealEngine.Engine
{
public partial class UActorComponent : UObject
{
private CachedUObject<UWorld> worldCached;
public UWorld World
{
get { return worldCached.Update(Native_UActorComponent.GetWorld(Address)); }
}

static int PrimaryComponentTick_Offset;
/// <summary>
/// Main tick function for the Actor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@ namespace UnrealEngine.Engine
{
public partial class APlayerController : AController
{
public FRotator RotationInput
{
get
{
CheckDestroyed();
return Native_APlayerController.Get_RotationInput(this.Address);
}
set
{
CheckDestroyed();
Native_APlayerController.Set_RotationInput(this.Address, ref value);
}
}

private VTableHacks.CachedFunctionRedirect<VTableHacks.PlayerControllerSetupInputComponentDel_ThisCall> setupInputComponentRedirect;
internal override void SetupInputComponentInternal()
{
SetupInputComponent();
}

private VTableHacks.CachedFunctionRedirect<VTableHacks.PlayerControllerUpdateRotationDel_ThisCall> updateRotationRedirect;
internal override void UpdateRotationInternal(float DeltaTime)
{
UpdateRotation(DeltaTime);
}

/// <summary>
/// Allows the PlayerController to set up custom input bindings.
/// </summary>
Expand All @@ -22,5 +42,16 @@ protected virtual void SetupInputComponent()
.Resolve(VTableHacks.PlayerControllerSetupInputComponent, this)
.Invoke(Address);
}

/// <summary>
/// Updates the rotation of player, based on ControlRotation after RotationInput has been applied.
/// This may then be modified by the PlayerCamera, and is passed to Pawn->FaceRotation().
/// </summary>
public virtual void UpdateRotation(float DeltaTime)
{
updateRotationRedirect
.Resolve(VTableHacks.PlayerControllerUpdateRotation, this)
.Invoke(Address, DeltaTime);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

#pragma warning disable 649 // Field is never assigned

namespace UnrealEngine.Runtime.Native
{
public static class Native_APlayerController
{
public delegate FRotator Del_Get_RotationInput(IntPtr instance);
public delegate void Del_Set_RotationInput(IntPtr instance, ref FRotator RotationInput);

public static Del_Get_RotationInput Get_RotationInput;
public static Del_Set_RotationInput Set_RotationInput;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public static class Native_UActorComponent
public delegate void Del_RegisterComponent(IntPtr instance);
public delegate void Del_ReregisterComponent(IntPtr instance);
public delegate void Del_UnregisterComponent(IntPtr instance);
public delegate IntPtr Del_GetWorld(IntPtr instance);

public static Del_RegisterComponent RegisterComponent;
public static Del_ReregisterComponent ReregisterComponent;
public static Del_UnregisterComponent UnregisterComponent;
public static Del_GetWorld GetWorld;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static class Native_VTableHacks
public delegate void Del_CallOriginal_ActorComponentBeginPlay(IntPtr originalFunc, IntPtr obj);
public delegate void Del_CallOriginal_ActorComponentEndPlay(IntPtr originalFunc, IntPtr obj, byte endPlayReason);
public delegate void Del_CallOriginal_PlayerControllerSetupInputComponent(IntPtr originalFunc, IntPtr obj);
public delegate void Del_CallOriginal_PlayerControllerUpdateRotation(IntPtr originalFunc, IntPtr obj, float deltaTime);

public static Del_Set_VTableCallback Set_VTableCallback;
public static Del_CallOriginal_GetLifetimeReplicatedProps CallOriginal_GetLifetimeReplicatedProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private static void AddVTableRedirects()
ActorComponentBeginPlay = AddVTableRedirect(actorComponentClass, "DummyActorComponentBeginPlay", new BeginPlayDel(OnActorComponentBeginPlay));
ActorComponentEndPlay = AddVTableRedirect(actorComponentClass, "DummyActorComponentEndPlay", new EndPlayDel(OnActorComponentEndPlay));
PlayerControllerSetupInputComponent = AddVTableRedirect(playerControllerClass, "DummyPlayerControllerSetupInputComponent", new PlayerControllerSetupInputComponentDel(OnPlayerControllerSetupInputComponent));
PlayerControllerUpdateRotation = AddVTableRedirect(playerControllerClass, "DummyPlayerControllerUpdateRotation", new PlayerControllerUpdateRotationDel(OnPlayerControllerUpdateRotation));
}

private static void LogCallbackException(string functionName, Exception e)
Expand Down Expand Up @@ -147,6 +148,23 @@ private static void OnPlayerControllerSetupInputComponent(IntPtr address)
}
}

public static FunctionRedirect PlayerControllerUpdateRotation { get; private set; }
delegate void PlayerControllerUpdateRotationDel(IntPtr address, float deltaTime);
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
public delegate void PlayerControllerUpdateRotationDel_ThisCall(IntPtr address, float deltaTime);
private static void OnPlayerControllerUpdateRotation(IntPtr address, float deltaTime)
{
try
{
UObject obj = GCHelper.Find(address);
obj.UpdateRotationInternal(deltaTime);
}
catch (Exception e)
{
LogCallbackException(nameof(OnPlayerControllerUpdateRotation), e);
}
}

////////////////////////////////////////////////////////////////////////////////////////
// Add vtable redirects above this line
////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
<Compile Include="Internal\NativeReflectionCached.cs" />
<Compile Include="Internal\Native\Internal\Native_UUSharpGameplayTask.cs" />
<Compile Include="Internal\Native\Internal\Native_UUSharpOnlineBlueprintCallProxyBase.cs" />
<Compile Include="Internal\Native\Native_APlayerController.cs" />
<Compile Include="Internal\Native\Native_FFeedbackContext.cs" />
<Compile Include="Internal\Native\Native_FGameplayResourceSet.cs" />
<Compile Include="Internal\Native\Native_FLatentActionManager.cs" />
Expand Down
15 changes: 15 additions & 0 deletions Source/USharp/Private/ExportedFunctions/Export_APlayerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CSEXPORT FRotator CSCONV Export_APlayerController_Get_RotationInput(APlayerController* instance)
{
return instance->RotationInput;
}

CSEXPORT void CSCONV Export_APlayerController_Set_RotationInput(APlayerController* instance, const FRotator& RotationInput)
{
instance->RotationInput = RotationInput;
}

CSEXPORT void CSCONV Export_APlayerController(RegisterFunc registerFunc)
{
REGISTER_FUNC(Export_APlayerController_Get_RotationInput);
REGISTER_FUNC(Export_APlayerController_Set_RotationInput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ CSEXPORT void CSCONV Export_UActorComponent_UnregisterComponent(UActorComponent*
instance->UnregisterComponent();
}

CSEXPORT UWorld* CSCONV Export_UActorComponent_GetWorld(UActorComponent* instance)
{
return instance->GetWorld();
}

CSEXPORT void CSCONV Export_UActorComponent(RegisterFunc registerFunc)
{
REGISTER_FUNC(Export_UActorComponent_RegisterComponent);
REGISTER_FUNC(Export_UActorComponent_ReregisterComponent);
REGISTER_FUNC(Export_UActorComponent_UnregisterComponent);
REGISTER_FUNC(Export_UActorComponent_GetWorld);
}
2 changes: 2 additions & 0 deletions Source/USharp/Private/ExportedFunctions/ExportedFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "Export_UGameInstance.h"
#include "Export_ULevel.h"
#include "Export_AActor.h"
#include "Export_APlayerController.h"
#include "Export_UActorComponent.h"
#include "Export_USceneComponent.h"
#include "Export_UMaterialInstanceDynamic.h"
Expand Down Expand Up @@ -207,6 +208,7 @@ CSEXPORT void CSCONV RegisterFunctions(RegisterFunc registerFunc)
Export_UGameInstance(registerFunc);
Export_ULevel(registerFunc);
Export_AActor(registerFunc);
Export_APlayerController(registerFunc);
Export_UActorComponent(registerFunc);
Export_USceneComponent(registerFunc);
Export_UMaterialInstanceDynamic(registerFunc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ActorEndPlayCallbackSig ActorEndPlayCallback = nullptr;
ActorComponentBeginPlayCallbackSig ActorComponentBeginPlayCallback = nullptr;
ActorComponentEndPlayCallbackSig ActorComponentEndPlayCallback = nullptr;
PlayerControllerSetupInputComponentCallbackSig PlayerControllerSetupInputComponentCallback = nullptr;
PlayerControllerUpdateRotationCallbackSig PlayerControllerUpdateRotationCallback = nullptr;

TMap<FString, void**> DummyNames;
CSEXPORT void CSCONV Export_VTableHacks_Set_VTableCallback(const FString& DummyName, void* Callback)
Expand All @@ -21,6 +22,7 @@ CSEXPORT void CSCONV Export_VTableHacks_Set_VTableCallback(const FString& DummyN
DummyNames.Add(TEXT("DummyActorComponentBeginPlay"), (void**)&ActorComponentBeginPlayCallback);
DummyNames.Add(TEXT("DummyActorComponentEndPlay"), (void**)&ActorComponentEndPlayCallback);
DummyNames.Add(TEXT("DummyPlayerControllerSetupInputComponent"), (void**)&PlayerControllerSetupInputComponentCallback);
DummyNames.Add(TEXT("DummyPlayerControllerUpdateRotation"), (void**)&PlayerControllerUpdateRotationCallback);
}

void*** Element = DummyNames.Find(DummyName);
Expand Down Expand Up @@ -73,6 +75,12 @@ CSEXPORT void CSCONV Export_VTableHacks_CallOriginal_PlayerControllerSetupInputC
(Obj->*Func)();
}

typedef void (UObject::*PlayerControllerUpdateRotationFunc)(float DeltaTime);
CSEXPORT void CSCONV Export_VTableHacks_CallOriginal_PlayerControllerUpdateRotation(PlayerControllerUpdateRotationFunc Func, UObject* Obj, float DeltaTime)
{
(Obj->*Func)(DeltaTime);
}

CSEXPORT void CSCONV Export_VTableHacks(RegisterFunc registerFunc)
{
REGISTER_FUNC(Export_VTableHacks_Set_VTableCallback);
Expand All @@ -83,4 +91,5 @@ CSEXPORT void CSCONV Export_VTableHacks(RegisterFunc registerFunc)
REGISTER_FUNC(Export_VTableHacks_CallOriginal_ActorComponentBeginPlay);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_ActorComponentEndPlay);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_PlayerControllerSetupInputComponent);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_PlayerControllerUpdateRotation);
}
40 changes: 40 additions & 0 deletions Source/USharp/Private/VTableHacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,44 @@ class USHARP_API ADummyPlayerControllerSetupInputComponent3 : public ADummyPlaye
{
FMsg::Logf("", 0, FName(TEXT("USharp")), ELogVerbosity::Log, TEXT("ADummyPlayerControllerSetupInputComponent3-SetupInputComponent"));
}
};

/////////////////////////////////////////////////////////////////////////////
// APlayerController::UpdateRotation
/////////////////////////////////////////////////////////////////////////////

typedef void(CSCONV *PlayerControllerUpdateRotationCallbackSig)(APlayerController* Obj, float DeltaTime);
extern PlayerControllerUpdateRotationCallbackSig PlayerControllerUpdateRotationCallback;

UCLASS(NotBlueprintable, NotBlueprintType)
class USHARP_API ADummyPlayerControllerUpdateRotation1 : public APlayerController
{
GENERATED_BODY()

protected:
virtual void UpdateRotation(float DeltaTime) override
{
if (PlayerControllerUpdateRotationCallback != nullptr)
{
PlayerControllerUpdateRotationCallback(this, DeltaTime);
}
}
};

UCLASS(NotBlueprintable, NotBlueprintType)
class USHARP_API ADummyPlayerControllerUpdateRotation2 : public ADummyPlayerControllerUpdateRotation1
{
GENERATED_BODY()
};

UCLASS(NotBlueprintable, NotBlueprintType)
class USHARP_API ADummyPlayerControllerUpdateRotation3 : public ADummyPlayerControllerUpdateRotation2
{
GENERATED_BODY()

protected:
virtual void UpdateRotation(float DeltaTime) override
{
FMsg::Logf("", 0, FName(TEXT("USharp")), ELogVerbosity::Log, TEXT("ADummyPlayerControllerUpdateRotation3-UpdateRotation"));
}
};

0 comments on commit 8029275

Please sign in to comment.