Skip to content

Commit

Permalink
Merge pull request #15 from RussellJerome/development
Browse files Browse the repository at this point in the history
Merging for V2.2.0
  • Loading branch information
RussellJerome authored Feb 16, 2022
2 parents ead5871 + ab25f31 commit 3cb500a
Show file tree
Hide file tree
Showing 26 changed files with 346 additions and 203 deletions.
29 changes: 21 additions & 8 deletions ExampleMod/ExampleMod.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#include "ExampleMod.h"
#include "Utilities/MinHook.h"

BPFUNCTION(WriteToFile)
{
std::cout << "WriteToFile" << std::endl;
struct InputParams
{
UE4::FString NameTest;
};
auto Inputs = stack->GetInputParams<InputParams>();
stack->SetOutput<UE4::FString>("OutPutString", L"KboyGang");
stack->SetOutput<bool>("ReturnValue", true);
}

// Only Called Once, if you need to hook shit, declare some global non changing values
void ExampleMod::InitializeMod()
{
UE4::InitSDK();
SetupHooks();
//UseMenuButton = true; // Allows Mod Loader To Show Button
}

void ExampleMod::ProcessFunction(UE4::UObject* obj, UE4::FFrame* Frame)
{
if (obj)
{
//if(obj == ModActor) // Checks If the actor calling this function is your Mod Actor Function
}
REGISTER_FUNCTION(WriteToFile);

//MinHook::Init(); //Uncomment if you plan to do hooks

//UseMenuButton = true; // Allows Mod Loader To Show Button
}

void ExampleMod::InitGameState()
Expand All @@ -36,6 +45,10 @@ void ExampleMod::PostBeginPlay(std::wstring ModActorName, UE4::AActor* Actor)
}
}

void ExampleMod::DX11Present(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* pRenderTargetView)
{
}

void ExampleMod::OnModMenuButtonPressed()
{
}
Expand Down
8 changes: 4 additions & 4 deletions ExampleMod/ExampleMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ExampleMod : public Mod
ModVersion = "1.0.0"; // Mod Version
ModDescription = "HAHAHAHA MOD GO BURR"; // Mod Description
ModAuthors = "RussellJ"; // Mod Author
ModLoaderVersion = "2.1.0";
ModLoaderVersion = "2.2.0";

// Dont Touch The Internal Stuff
ModRef = this;
Expand All @@ -22,9 +22,6 @@ class ExampleMod : public Mod
//Called When Internal Mod Setup is finished
virtual void InitializeMod() override;

//Either ProcessInternals or ProcessLocalScriptFunction which you use to communicate between your BPMod and your C++ Mod
virtual void ProcessFunction(UE4::UObject* obj, UE4::FFrame* Frame) override;

//InitGameState Call
virtual void InitGameState() override;

Expand All @@ -34,6 +31,9 @@ class ExampleMod : public Mod
//PostBeginPlay of EVERY Blueprint ModActor
virtual void PostBeginPlay(std::wstring ModActorName, UE4::AActor* Actor) override;

//DX11 hook for when an image will be presented to the screen
virtual void DX11Present(ID3D11Device* pDevice, ID3D11DeviceContext* pContext, ID3D11RenderTargetView* pRenderTargetView) override;

virtual void OnModMenuButtonPressed() override;

//Call ImGui Here (CALLED EVERY FRAME ON DX HOOK)
Expand Down
70 changes: 39 additions & 31 deletions UnrealEngineModLoader/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@ namespace Hooks
PVOID(*origProcessFunction)(UE4::UObject*, UE4::FFrame*, void* const);
PVOID hookProcessFunction(UE4::UObject* obj, UE4::FFrame* Frame, void* const Result)
{
PVOID ret = nullptr;
if (!GameStateClassInitNotRan)
{
if (Frame->Node->GetName() == "PrintToModLoader")
{
auto msg = Frame->GetParams<PrintStringParams>()->Message;
auto msg = Frame->GetInputParams<PrintStringParams>()->Message;
if (msg.IsValid())
{
Log::Print("%s", msg.ToString().c_str());
}
}
if (Frame->Node->GetName() == "GetPersistentObject")
{
auto ModName = Frame->GetParams<GetPersistentObject>()->ModName;
for (size_t i = 0; i < Global::ModInfoList.size(); i++)
auto ModName = Frame->GetInputParams<GetPersistentObject>()->ModName;
for (size_t i = 0; i < Global::GetGlobals()->ModInfoList.size(); i++)
{
auto ModInfo = Global::ModInfoList[i];
auto ModInfo = Global::GetGlobals()->ModInfoList[i];
if (ModName.c_str() == ModInfo.ModName)
{
if (ModInfo.PersistentObject)
Expand All @@ -53,7 +54,14 @@ namespace Hooks
}
}
}
Global::eventSystem.dispatchEvent("ProcessFunction", obj, Frame);
for (size_t i = 0; i < Global::GetGlobals()->GetBPFunctionWrappers().size(); i++)
{
if (Frame->Node->GetName() == Global::GetGlobals()->GetBPFunctionWrappers()[i].FunctionName)
{
reinterpret_cast<void(*)(UE4::UObject*, UE4::FFrame*, void*)> (Global::GetGlobals()->GetBPFunctionWrappers()[i].FuncPtr) (obj, Frame, (void*)Result);
return nullptr;
}
}
}
return origProcessFunction(obj, Frame, Result);

Expand All @@ -67,11 +75,11 @@ namespace Hooks
{
UE4::InitSDK();
Log::Info("Engine Classes Loaded");
if (Global::CoreMods.size() > 0)
if (Global::GetGlobals()->CoreMods.size() > 0)
{
for (size_t i = 0; i < Global::CoreMods.size(); i++)
for (size_t i = 0; i < Global::GetGlobals()->CoreMods.size(); i++)
{
auto CurrentCoreMod = Global::CoreMods[i];
auto CurrentCoreMod = Global::GetGlobals()->CoreMods[i];
if (CurrentCoreMod->IsFinishedCreating)
{
Log::Info("InitializeMod Called For %s", CurrentCoreMod->ModName.c_str());
Expand All @@ -96,9 +104,9 @@ namespace Hooks
}
GameStateClassInitNotRan = false;
}
for (int i = 0; i < Global::ModInfoList.size(); i++)
for (int i = 0; i < Global::GetGlobals()->ModInfoList.size(); i++)
{
UE4::AActor* CurrentModActor = Global::ModInfoList[i].CurrentModActor;
UE4::AActor* CurrentModActor = Global::GetGlobals()->ModInfoList[i].CurrentModActor;
if (CurrentModActor)
{
if (CurrentModActor->IsA(UE4::AActor::StaticClass()))
Expand All @@ -107,8 +115,8 @@ namespace Hooks
}
}

Global::ModInfoList[i].CurrentModActor = nullptr;
Global::ModInfoList[i].ModButtons.clear();
Global::GetGlobals()->ModInfoList[i].CurrentModActor = nullptr;
Global::GetGlobals()->ModInfoList[i].ModButtons.clear();
}
if (GameProfile::SelectedGameProfile.StaticLoadObject)
{
Expand All @@ -117,12 +125,12 @@ namespace Hooks
transform.Rotation = UE4::FQuat(0, 0, 0, 0);
transform.Scale3D = UE4::FVector(1, 1, 1);
UE4::FActorSpawnParameters spawnParams = UE4::FActorSpawnParameters::FActorSpawnParameters();
for (int i = 0; i < Global::ModInfoList.size(); i++)
for (int i = 0; i < Global::GetGlobals()->ModInfoList.size(); i++)
{
std::wstring CurrentMod;
//StartSpawningMods
CurrentMod = Global::ModInfoList[i].ModName;
if (Global::ModInfoList[i].IsEnabled)
CurrentMod = Global::GetGlobals()->ModInfoList[i].ModName;
if (Global::GetGlobals()->ModInfoList[i].IsEnabled)
{
if (GameProfile::SelectedGameProfile.StaticLoadObject)
{
Expand Down Expand Up @@ -165,45 +173,45 @@ namespace Hooks
Log::Warn("ProcessBlueprintFunctions could not be located! Mod Loader Functionality Will be Limited!");
}

for (size_t i = 0; i < Global::ModInfoList.size(); i++)
for (size_t i = 0; i < Global::GetGlobals()->ModInfoList.size(); i++)
{
if (Global::ModInfoList[i].ModName == CurrentMod)
if (Global::GetGlobals()->ModInfoList[i].ModName == CurrentMod)
{
Global::ModInfoList[i].CurrentModActor = ModActor;
if (!Global::ModInfoList[i].WasInitialized)
Global::GetGlobals()->ModInfoList[i].CurrentModActor = ModActor;
if (!Global::GetGlobals()->ModInfoList[i].WasInitialized)
{
Global::ModInfoList[i].ContainsButton = ModActor->DoesObjectContainFunction("ModMenuButtonPressed");
Global::GetGlobals()->ModInfoList[i].ContainsButton = ModActor->DoesObjectContainFunction("ModMenuButtonPressed");
UE4::FString Author;
UE4::FString Description;
UE4::FString Version;
if (UE4::GetVariable<UE4::FString>(ModActor, "ModAuthor", Author))
{
if (Author.IsValid())
{
Global::ModInfoList[i].ModAuthor = Author.ToString();
Global::GetGlobals()->ModInfoList[i].ModAuthor = Author.ToString();
}
}
if (UE4::GetVariable<UE4::FString>(ModActor, "ModDescription", Description))
{
if (Description.IsValid())
{
Global::ModInfoList[i].ModDescription = Description.ToString();
Global::GetGlobals()->ModInfoList[i].ModDescription = Description.ToString();
}
}
if (UE4::GetVariable<UE4::FString>(ModActor, "ModVersion", Version))
{
if (Version.IsValid())
{
Global::ModInfoList[i].ModVersion = Version.ToString();
Global::GetGlobals()->ModInfoList[i].ModVersion = Version.ToString();
}
}
const std::wstring ModInstancePath = L"/Game/Mods/" + CurrentMod + L"/ModInstanceObject.ModInstanceObject_C";
UE4::UClass* ModObjectInstanceClass = UE4::UClass::LoadClassFromString(ModInstancePath.c_str(), false);
if (ModObjectInstanceClass) // Check if ModInstanceObject Exists
{
Global::ModInfoList[i].PersistentObject = UE4::UObject::StaticConstructObject_Internal(ModObjectInstanceClass, UE4::UGameplayStatics::GetGameInstance(), "", 0, UE4::EInternalObjectFlags::GarbageCollectionKeepFlags, nullptr, false, nullptr, false);
Global::GetGlobals()->ModInfoList[i].PersistentObject = UE4::UObject::StaticConstructObject_Internal(ModObjectInstanceClass, UE4::UGameplayStatics::GetGameInstance(), "", 0, UE4::EInternalObjectFlags::GarbageCollectionKeepFlags, nullptr, false, nullptr, false);
}
Global::ModInfoList[i].WasInitialized = true;
Global::GetGlobals()->ModInfoList[i].WasInitialized = true;
}
}
}
Expand All @@ -219,7 +227,7 @@ namespace Hooks
}
}
Log::Info("Finished Spawning PakMods");
Global::eventSystem.dispatchEvent("InitGameState");
Global::GetGlobals()->eventSystem.dispatchEvent("InitGameState");
}
Log::Info("Returning to GameState --------------------------------------------------------");
return origInitGameState(Ret);
Expand All @@ -233,9 +241,9 @@ namespace Hooks
if (Actor->IsA(UE4::ACustomClass::StaticClass(GameProfile::SelectedGameProfile.BeginPlayOverwrite)))
{
Log::Info("Beginplay Called");
for (int i = 0; i < Global::ModInfoList.size(); i++)
for (int i = 0; i < Global::GetGlobals()->ModInfoList.size(); i++)
{
UE4::AActor* CurrentModActor = Global::ModInfoList[i].CurrentModActor;
UE4::AActor* CurrentModActor = Global::GetGlobals()->ModInfoList[i].CurrentModActor;
if (CurrentModActor != nullptr)
{
UE4::TArray<UE4::FString> ModButtons;
Expand All @@ -246,16 +254,16 @@ namespace Hooks
auto CurrentButton = ModButtons[bi];
if (CurrentButton.IsValid())
{
Global::ModInfoList[i].ModButtons.push_back(CurrentButton.ToString());
Global::GetGlobals()->ModInfoList[i].ModButtons.push_back(CurrentButton.ToString());
}
}
}
CurrentModActor->CallFunctionByNameWithArguments(L"PostBeginPlay", nullptr, NULL, true);
Global::eventSystem.dispatchEvent("PostBeginPlay", Global::ModInfoList[i].ModName, CurrentModActor);
Global::GetGlobals()->eventSystem.dispatchEvent("PostBeginPlay", Global::GetGlobals()->ModInfoList[i].ModName, CurrentModActor);
}
}
}
Global::eventSystem.dispatchEvent("BeginPlay", Actor);
Global::GetGlobals()->eventSystem.dispatchEvent("BeginPlay", Actor);
}
return origBeginPlay(Actor);
}
Expand Down
2 changes: 1 addition & 1 deletion UnrealEngineModLoader/ImGui/imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Index of this file:
#include <stdarg.h> // va_list, va_start, va_end
#include <stddef.h> // ptrdiff_t, NULL
#include <string.h> // memset, memmove, memcpy, strlen, strchr, strcpy, strcmp
#include "../Lib.h"
#include "../UMLDefs.h"

// Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
Expand Down
9 changes: 0 additions & 9 deletions UnrealEngineModLoader/Lib.h

This file was deleted.

Loading

0 comments on commit 3cb500a

Please sign in to comment.