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

Commit

Permalink
Merge pull request #102 from iainmckay/add-playercontroller-setupinpu…
Browse files Browse the repository at this point in the history
…tcomponent

Adds PlayerController::SetupInputComponent
  • Loading branch information
pixeltris authored Jul 22, 2019
2 parents 1ebc3f0 + 2050e33 commit 24417e3
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,11 @@ internal virtual void EndPlayInternal(byte endPlayReason)
// This is eventually implemented in injected classes
}

internal virtual void SetupInputComponentInternal()
{
// 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 @@ -75,6 +75,7 @@ public static class Classes
public static IntPtr AActor;
public static IntPtr APawn;
public static IntPtr UActorComponent;
public static IntPtr APlayerController;

// USharp
public static IntPtr USharpClass;
Expand Down Expand Up @@ -158,6 +159,7 @@ internal static void OnNativeFunctionsRegistered()
AActor = Native_Classes.AActor();
APawn = Native_Classes.APawn();
UActorComponent = Native_Classes.UActorComponent();
APlayerController = Native_Classes.APlayerController();

// USharp
USharpClass = Native_Classes.USharpClass();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using UnrealEngine.Engine;
using UnrealEngine.Runtime;
using UnrealEngine.Runtime.Native;

namespace UnrealEngine.Engine
{
public partial class APlayerController : AController
{
internal override void SetupInputComponentInternal()
{
SetupInputComponent();
}

/// <summary>
/// Allows the PlayerController to set up custom input bindings.
/// </summary>
protected virtual void SetupInputComponent()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ static class Native_Classes
public static Del_StaticClass USharpClass;
public static Del_StaticClass USharpStruct;
public static Del_StaticClass UActorComponent;
public static Del_StaticClass APlayerController;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static class Native_VTableHacks
public delegate void Del_CallOriginal_ActorEndPlay(IntPtr originalFunc, IntPtr obj, byte endPlayReason);
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 static Del_Set_VTableCallback Set_VTableCallback;
public static Del_CallOriginal_GetLifetimeReplicatedProps CallOriginal_GetLifetimeReplicatedProps;
Expand All @@ -25,5 +26,6 @@ static class Native_VTableHacks
public static Del_CallOriginal_ActorEndPlay CallOriginal_ActorEndPlay;
public static Del_CallOriginal_ActorComponentBeginPlay CallOriginal_ActorComponentBeginPlay;
public static Del_CallOriginal_ActorComponentEndPlay CallOriginal_ActorComponentEndPlay;
public static Del_CallOriginal_PlayerControllerSetupInputComponent CallOriginal_PlayerControllerSetupInputComponent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ private static void AddVTableRedirects()
IntPtr pawnClass = Runtime.Classes.APawn;
IntPtr actorClass = Runtime.Classes.AActor;
IntPtr actorComponentClass = Runtime.Classes.UActorComponent;
IntPtr playerControllerClass = Runtime.Classes.APlayerController;

repProps = AddVTableRedirect(objectClass, "DummyRepProps", new GetLifetimeReplicatedPropsDel(OnGetLifetimeReplicatedProps));
setupPlayerInput = AddVTableRedirect(pawnClass, "DummySetupPlayerInput", new SetupPlayerInputComponentDel(OnSetupPlayerInputComponent));
actorBeginPlay = AddVTableRedirect(actorClass, "DummyActorBeginPlay", new ActorBeginPlayDel(OnActorBeginPlay));
actorEndPlay = AddVTableRedirect(actorClass, "DummyActorEndPlay", new ActorEndPlayDel(OnActorEndPlay));
actorComponentBeginPlay = AddVTableRedirect(actorComponentClass, "DummyActorComponentBeginPlay", new ActorComponentBeginPlayDel(OnActorComponentBeginPlay));
actorComponentEndPlay = AddVTableRedirect(actorComponentClass, "DummyActorComponentEndPlay", new ActorComponentEndPlayDel(OnActorComponentEndPlay));
playerControllerSetupInputComponent = AddVTableRedirect(playerControllerClass, "DummyPlayerControllerSetupInputComponent", new PlayerControllerSetupInputComponentDel(OnPlayerControllerSetupInputComponent));
}

private static void LogCallbackException(string functionName, Exception e)
Expand Down Expand Up @@ -168,6 +170,28 @@ private static void OnActorComponentEndPlay(IntPtr address, byte endPlayReason)
}
}

private static FunctionRedirect playerControllerSetupInputComponent;
delegate void PlayerControllerSetupInputComponentDel(IntPtr address);
[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
delegate void PlayerControllerSetupInputComponentDel_ThisCall(IntPtr address);
private static void OnPlayerControllerSetupInputComponent(IntPtr address)
{
try
{
UObject obj = GCHelper.Find(address);

PlayerControllerSetupInputComponentDel_ThisCall original = playerControllerSetupInputComponent.GetOriginal<PlayerControllerSetupInputComponentDel_ThisCall>(obj);
original(address);
//Native_VTableHacks.CallOriginal_PlayerControllerSetupInputComponent(original)

obj.SetupInputComponentInternal();
}
catch (Exception e)
{
LogCallbackException(nameof(OnPlayerControllerSetupInputComponent), e);
}
}

////////////////////////////////////////////////////////////////////////////////////////
// Add vtable redirects above this line
////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<None Include="Internal\InjectedClasses\Engine\Actor_Injected.cs" />
<None Include="Internal\InjectedClasses\Engine\Engine_Injected.cs" />
<None Include="Internal\InjectedClasses\Engine\GameplayStatics_Injected.cs" />
<None Include="Internal\InjectedClasses\Engine\PlayerController_Injected.cs" />
<None Include="Internal\InjectedClasses\Engine\WorldContext_Extensions.cs" />
<None Include="Internal\InjectedClasses\Engine\World_Injected.cs" />
<None Include="Internal\InjectedClasses\Engine\InputComponent_Injected.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ CSEXPORT UClass* CSCONV Export_Classes_UActorComponent()
return UActorComponent::StaticClass();
}

CSEXPORT UClass* CSCONV Export_Classes_APlayerController()
{
return APlayerController::StaticClass();
}

CSEXPORT UClass* CSCONV Export_Classes_USharpClass()
{
return USharpClass::StaticClass();
Expand Down Expand Up @@ -343,6 +348,7 @@ CSEXPORT void CSCONV Export_Classes(RegisterFunc registerFunc)
REGISTER_FUNC(Export_Classes_AActor);
REGISTER_FUNC(Export_Classes_APawn);
REGISTER_FUNC(Export_Classes_UActorComponent);
REGISTER_FUNC(Export_Classes_APlayerController);


// USharp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ActorBeginPlayCallbackSig ActorBeginPlayCallback = nullptr;
ActorEndPlayCallbackSig ActorEndPlayCallback = nullptr;
ActorComponentBeginPlayCallbackSig ActorComponentBeginPlayCallback = nullptr;
ActorComponentEndPlayCallbackSig ActorComponentEndPlayCallback = nullptr;
PlayerControllerSetupInputComponentCallbackSig PlayerControllerSetupInputComponentCallback = nullptr;

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

void*** Element = DummyNames.Find(DummyName);
Expand Down Expand Up @@ -65,6 +67,12 @@ CSEXPORT void CSCONV Export_VTableHacks_CallOriginal_ActorComponentEndPlay(Actor
(Obj->*Func)(EndPlayReason);
}

typedef void (UObject::*PlayerControllerSetupInputComponentFunc)();
CSEXPORT void CSCONV Export_VTableHacks_CallOriginal_PlayerControllerSetupInputComponent(PlayerControllerSetupInputComponentFunc Func, UObject* Obj)
{
(Obj->*Func)();
}

CSEXPORT void CSCONV Export_VTableHacks(RegisterFunc registerFunc)
{
REGISTER_FUNC(Export_VTableHacks_Set_VTableCallback);
Expand All @@ -74,4 +82,5 @@ CSEXPORT void CSCONV Export_VTableHacks(RegisterFunc registerFunc)
REGISTER_FUNC(Export_VTableHacks_CallOriginal_ActorEndPlay);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_ActorComponentBeginPlay);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_ActorComponentEndPlay);
REGISTER_FUNC(Export_VTableHacks_CallOriginal_PlayerControllerSetupInputComponent);
}
41 changes: 41 additions & 0 deletions Source/USharp/Private/VTableHacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Engine/EngineBaseTypes.h"
#include "GameFramework/Actor.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/PlayerController.h"
#include "Components/ActorComponent.h"
#include "ExportedFunctions/ExportedFunctionsConventions.h"
#include "VTableHacks.generated.h"
Expand Down Expand Up @@ -309,4 +310,44 @@ class USHARP_API UDummyActorComponentEndPlay3 : public UDummyActorComponentEndPl
{
FMsg::Logf("", 0, FName(TEXT("USharp")), ELogVerbosity::Log, TEXT("ADummyActorComponentEndPlay3-EndPlay"));
}
};

/////////////////////////////////////////////////////////////////////////////
// APlayerController::SetupInputComponent
/////////////////////////////////////////////////////////////////////////////

typedef void(CSCONV *PlayerControllerSetupInputComponentCallbackSig)(APlayerController* Obj);
extern PlayerControllerSetupInputComponentCallbackSig PlayerControllerSetupInputComponentCallback;

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

protected:
virtual void SetupInputComponent() override
{
if (PlayerControllerSetupInputComponentCallback != nullptr)
{
PlayerControllerSetupInputComponentCallback(this);
}
}
};

UCLASS(NotBlueprintable, NotBlueprintType)
class USHARP_API ADummyPlayerControllerSetupInputComponent2 : public ADummyPlayerControllerSetupInputComponent1
{
GENERATED_BODY()
};

UCLASS(NotBlueprintable, NotBlueprintType)
class USHARP_API ADummyPlayerControllerSetupInputComponent3 : public ADummyPlayerControllerSetupInputComponent2
{
GENERATED_BODY()

protected:
virtual void SetupInputComponent() override
{
FMsg::Logf("", 0, FName(TEXT("USharp")), ELogVerbosity::Log, TEXT("ADummyPlayerControllerSetupInputComponent3-SetupInputComponent"));
}
};

0 comments on commit 24417e3

Please sign in to comment.