C++ hook attach code in Mod Module not running
I have been trying to get this simple function hook to work but I can't figure out why it isn't working.
I've tried putting logs everywhere and they're not coming through... I put the Declare log category extern and the define log category in the files that the documentation told me to... Anyone got some more insight?
cpp
#pragma once
#include "Module/GameInstanceModule.h"
#include "TPRRootGameWorldModule.generated.h"
UCLASS()
class TRAINPATHINGREWORK_API UTPRRootGameWorldModule : public UGameInstanceModule
{
GENERATED_BODY()
public:
UTPRRootGameWorldModule();
~UTPRRootGameWorldModule();
virtual void DispatchLifecycleEvent(ELifecyclePhase phase) override;
}; cpp
#pragma once
#include "Module/GameInstanceModule.h"
#include "TPRRootGameWorldModule.generated.h"
UCLASS()
class TRAINPATHINGREWORK_API UTPRRootGameWorldModule : public UGameInstanceModule
{
GENERATED_BODY()
public:
UTPRRootGameWorldModule();
~UTPRRootGameWorldModule();
virtual void DispatchLifecycleEvent(ELifecyclePhase phase) override;
};#pragma once
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
#include "CoreMinimal.h"
#include "FGRailroadSignalBlock.h"
#include "Patching/NativeHookManager.h"
#include "FGRailroadVehicle.h"
#include "FGRailroadSubsystem.h"
#include "FGTrain.h"
#include "FGLocomotive.h"
void TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks()
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Registering"));
if (!WITH_EDITOR) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Inside if"));
SUBSCRIBE_METHOD(FFGRailroadSignalBlock::BlockEntered, [](auto& scope, const FFGRailroadSignalBlock* self, AFGRailroadVehicle* byVehicle)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Block entered"));
//UWorld* world = GEngine->GameViewport->GetWorld();
//auto railroadSubsystem = GEngine->GetEngineSubsystem<AFGRailroadSubsystem>();
auto railroadSubsystem = AFGRailroadSubsystem::Get(GEngine->GameViewport->GetWorld());
TArray<AFGTrain*> trains;
railroadSubsystem->GetAllTrains(trains);
for (AFGTrain* train : trains)
{
train->GetMultipleUnitMaster()->HonkShort();
}
}
);
SUBSCRIBE_METHOD(AFGTrain::TickSelfDriving, [](auto& scope, const AFGTrain* self, float dt) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Self driving tick"));
});
}
}#pragma once
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
#include "CoreMinimal.h"
#include "FGRailroadSignalBlock.h"
#include "Patching/NativeHookManager.h"
#include "FGRailroadVehicle.h"
#include "FGRailroadSubsystem.h"
#include "FGTrain.h"
#include "FGLocomotive.h"
void TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks()
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Registering"));
if (!WITH_EDITOR) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Inside if"));
SUBSCRIBE_METHOD(FFGRailroadSignalBlock::BlockEntered, [](auto& scope, const FFGRailroadSignalBlock* self, AFGRailroadVehicle* byVehicle)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Block entered"));
//UWorld* world = GEngine->GameViewport->GetWorld();
//auto railroadSubsystem = GEngine->GetEngineSubsystem<AFGRailroadSubsystem>();
auto railroadSubsystem = AFGRailroadSubsystem::Get(GEngine->GameViewport->GetWorld());
TArray<AFGTrain*> trains;
railroadSubsystem->GetAllTrains(trains);
for (AFGTrain* train : trains)
{
train->GetMultipleUnitMaster()->HonkShort();
}
}
);
SUBSCRIBE_METHOD(AFGTrain::TickSelfDriving, [](auto& scope, const AFGTrain* self, float dt) {
UE_LOG(LogTrainPathingRework, Verbose, TEXT("Self driving tick"));
});
}
}#include "TPRRootGameWorldModule.h"
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
}
UTPRRootGameWorldModule::~UTPRRootGameWorldModule()
{
}
void UTPRRootGameWorldModule::DispatchLifecycleEvent(ELifecyclePhase phase)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("TEST"))
if (phase != ELifecyclePhase::INITIALIZATION) return;
//if (WITH_EDITOR) return;
TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks();
Super::DispatchLifecycleEvent(phase);
}#include "TPRRootGameWorldModule.h"
#include "TPRRegisterWindowsHooks.h"
#include "TrainPathingRework.h"
UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
}
UTPRRootGameWorldModule::~UTPRRootGameWorldModule()
{
}
void UTPRRootGameWorldModule::DispatchLifecycleEvent(ELifecyclePhase phase)
{
UE_LOG(LogTrainPathingRework, Verbose, TEXT("TEST"))
if (phase != ELifecyclePhase::INITIALIZATION) return;
//if (WITH_EDITOR) return;
TPRRegisterWindowsHooks::RegisterWindowsOnlyHooks();
Super::DispatchLifecycleEvent(phase);
}I've tried putting logs everywhere and they're not coming through... I put the Declare log category extern and the define log category in the files that the documentation told me to... Anyone got some more insight?
Solution
UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
bRootModule = true;
}UTPRRootGameWorldModule::UTPRRootGameWorldModule()
{
bRootModule = true;
}