Skip to content

Commit

Permalink
Implement SeqActLogEnabler (from LE1). Since it doesn't show anything…
Browse files Browse the repository at this point in the history
…... it's not that useful.
  • Loading branch information
Mgamerz committed Sep 13, 2021
1 parent c19afef commit 1d6e17a
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 119 deletions.
8 changes: 7 additions & 1 deletion LE3-ASI-Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE3-SDK", "LE3-SDK\LE3-SDK.
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE3StreamingLevelsHUD", "LE3StreamingLevelsHUD\LE3StreamingLevelsHUD.vcxproj", "{24261DB1-E217-4234-B048-1ACEA2F67237}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KismetLogger", "LE3KismetLogger\KismetLogger.vcxproj", "{1F82E847-1848-4F1E-B458-E008C2FF8F43}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE3KismetLogger", "LE3KismetLogger\KismetLogger.vcxproj", "{1F82E847-1848-4F1E-B458-E008C2FF8F43}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE3SeqAct_LogEnabler", "LE3SeqAct_LogEnabler\LE3SeqAct_LogEnabler.vcxproj", "{C07CE6A9-F5DC-4C05-8AA5-C35BB5F1D27C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{1F82E847-1848-4F1E-B458-E008C2FF8F43}.Debug|x64.Build.0 = Debug|x64
{1F82E847-1848-4F1E-B458-E008C2FF8F43}.Release|x64.ActiveCfg = Release|x64
{1F82E847-1848-4F1E-B458-E008C2FF8F43}.Release|x64.Build.0 = Release|x64
{C07CE6A9-F5DC-4C05-8AA5-C35BB5F1D27C}.Debug|x64.ActiveCfg = Debug|x64
{C07CE6A9-F5DC-4C05-8AA5-C35BB5F1D27C}.Debug|x64.Build.0 = Debug|x64
{C07CE6A9-F5DC-4C05-8AA5-C35BB5F1D27C}.Release|x64.ActiveCfg = Release|x64
{C07CE6A9-F5DC-4C05-8AA5-C35BB5F1D27C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
25 changes: 17 additions & 8 deletions LE3-SDK/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace Common
// SDK and hook initialization macros.
// ============================================================

///
/// Initializes the SDK. If initialization fails, the function that calls this macro will return false.
///
#define INIT_CHECK_SDK() \
auto _ = SDKInitializer::Instance(); \
if (!SDKInitializer::Instance()->GetBioNamePools()) \
Expand All @@ -108,14 +111,9 @@ namespace Common
return false; \
}

#define INIT_FIND_PATTERN(VAR, PATTERN) \
if (auto rc = InterfacePtr->FindPattern((void**)&VAR, PATTERN); rc != SPIReturn::Success) \
{ \
errorln(L"Attach - failed to find " #VAR L" pattern: %d / %s", rc, SPIReturnToString(rc)); \
return false; \
} \
writeln(L"Attach - found " #VAR L" pattern: 0x%p", VAR);

///
/// Finds the address of a pattern, and returns it, subtracting 5 bytes. For this to work, give it a pattern, but exclude the first 5 bytes of the function, as they will be modified when a hook is installed.
///
#define INIT_FIND_PATTERN_POSTHOOK(VAR, PATTERN) \
if (auto rc = InterfacePtr->FindPattern((void**)&VAR, PATTERN); rc != SPIReturn::Success) \
{ \
Expand All @@ -130,10 +128,21 @@ namespace Common
VAR = (decltype(VAR))((char*)VAR + *(DWORD*)((char*)VAR - 4)); \
writeln(L"Attach - found " #VAR L" global variable: %#p", VAR);

///
/// Installs a hook at the specified address and redirects it to the specified function name. The origianl must end with _orig as this macro looks for a method with that name.
///
#define INIT_HOOK_PATTERN(VAR) \
if (auto rc = InterfacePtr->InstallHook(MYHOOK #VAR, VAR, CONCAT_NAME(VAR, _hook), (void**)& CONCAT_NAME(VAR, _orig)); rc != SPIReturn::Success) \
{ \
fwprintf_s(stdout, L"Attach - failed to hook " #VAR L": %d / %s\n", rc, SPIReturnToString(rc)); \
return false; \
} \
fwprintf_s(stdout, L"Attach - hooked " #VAR L": 0x%p -> 0x%p (saved at 0x%p)\n", VAR, CONCAT_NAME(VAR, _hook), CONCAT_NAME(VAR, _orig));


// COMMON HOOK PATTERNS
// THESE SHOULD BE PREFIXED WITH THE GAME ID IN CASE FILE IS COPY/PASTED TO OTHER ASI SOLUTIONS
// =====================================================

/// Post-Signature for hooking ProcessEvent. Works on LE1/LE2/LE3.
#define LE_PATTERN_POSTHOOK_PROCESSEVENT /*"40 55 41 56 41*/ "57 48 81 EC 90 00 00 00 48 8D 6C 24 20 48 C7 45 50 FE FF FF FF 48 89 9D 90 00 00 00 48 89 B5 98 00 00 00 48 89 BD A0 00 00 00 4C 89 A5 A8 00 00 00 48 8B"
71 changes: 0 additions & 71 deletions LE3-SDK/LE3-SDK.vcxproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
Expand Down Expand Up @@ -44,19 +36,6 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
Expand All @@ -75,69 +54,19 @@
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<PrecompiledHeaderFile>
</PrecompiledHeaderFile>
<LanguageStandard>stdcpp17</LanguageStandard>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<SubSystem>
</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
Expand Down
79 changes: 79 additions & 0 deletions LE3-SDK/ScreenLogger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

#include <string>
#include "SdkHeaders.h"
using namespace std;
using BYTE = unsigned char;

//adapted from WarrantyVoider's ME3OnTheHook
class ScreenLogger
{
wchar_t* Name;
wchar_t* MessageBuffer[20];

static void RenderText(wchar_t* msg, const float x, const float y, const float r, const float g, const float b, UCanvas* can)
{
can->SetDrawColor(BYTE(r) * 255, BYTE(g) * 255, BYTE(b) * 255, 255);
can->SetPos(x, y);
FLinearColor drawColor;
drawColor.R = r;
drawColor.G = g;
drawColor.B = b;
drawColor.A = 1.0f;
FVector2D glowBorder;
glowBorder.X = 2;
glowBorder.Y = 2;
FFontRenderInfo renderInfo;
renderInfo.bClipText = true;
renderInfo.bEnableShadow = true;
renderInfo.GlowInfo.bEnableGlow = false;
renderInfo.GlowInfo.GlowColor = drawColor;
renderInfo.GlowInfo.GlowInnerRadius = glowBorder;
renderInfo.GlowInfo.GlowOuterRadius = glowBorder;
can->DrawText(FString(msg), 1, 1.0f, 1.0f, &renderInfo);
}
public:

ScreenLogger(wchar_t* name) : Name(name)
{
ZeroMemory(MessageBuffer, sizeof(MessageBuffer));
}

~ScreenLogger()
{
for (auto& msg : MessageBuffer)
{
if (msg)
{
free(msg);
}
}
}

void PostRenderer(ABioHUD* hud) const
{
RenderText(Name, 0, 0, 0, 1, 0, hud->Canvas);
for (auto i = 0; i < 20; i++)
{
if (MessageBuffer[i])
{
RenderText(MessageBuffer[i], 0, float(i * 12 + 12), 0, 1, 0, hud->Canvas);
}
}
}

void LogMessage(const wstring& text)
{
const auto mtext = static_cast<wchar_t*>(malloc(sizeof(wchar_t) * 1024));
swprintf(mtext, 1024, L"%s", text.c_str());
if (MessageBuffer[19])
{
free(MessageBuffer[19]);
}
for (auto i = 19; i > 0; i--)
{
MessageBuffer[i] = MessageBuffer[i - 1];
}
MessageBuffer[0] = mtext;
}
};
17 changes: 5 additions & 12 deletions LE3KismetLogger/KismetLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,31 @@
#include <sstream>
#include "../LE3-SDK/Common.h"
#include "../LE3-SDK/Interface.h"
//#include "../LE3-SDK/ME3TweaksHeader.h"
#include "../LE3-SDK/SdkHeaders.h"
#include "../LE3-SDK/ME3TweaksHeader.h"
//#include "../LE3-SDK/SdkHeaders.h"

#define MYHOOK "KismetLogger_"

SPI_PLUGINSIDE_SUPPORT(L"KismetLogger", L"1.0.0", L"HenBagle", SPI_GAME_LE3, SPI_VERSION_ANY);
SPI_PLUGINSIDE_POSTLOAD;
SPI_PLUGINSIDE_ASYNCATTACH;

//ME3TweaksASILogger logger("Kismet Logger v1", "KismetLog.txt");


ME3TweaksASILogger logger("Kismet Logger v1", "KismetLog.txt");

// ProcessEvent hook
// ======================================================================
#define LE3PATT_PROCESSEVENT /*"40 55 41 56 41*/ "57 48 81 EC 90 00 00 00 48 8D 6C 24 20 48 C7 45 50 FE FF FF FF 48 89 9D 90 00 00 00 48 89 B5 98 00 00 00 48 89 BD A0 00 00 00 4C 89 A5 A8 00 00 00 48 8B"
typedef void (*tProcessEvent)(UObject* Context, UFunction* Function, void* Parms, void* Result);
tProcessEvent ProcessEvent = nullptr;
tProcessEvent ProcessEvent_orig = nullptr;
void ProcessEvent_hook(UObject* Context, UFunction* Function, void* Parms, void* Result)
{
/*if (!strcmp(Function->GetFullName(), "Function Engine.SequenceOp.Activated"))
if (!strcmp(Function->GetFullName(), "Function Engine.SequenceOp.Activated"))
{
const auto op = reinterpret_cast<USequenceOp*>(Context);
char* fullInstancedPath = op->GetFullPath();
char* className = op->Class->Name.GetName();
logger.writeToLog(string_format("%s %s\n", className, fullInstancedPath), true);
}
else
{
logger.writeToConsole(string_format("%s", Function->GetFullName()), true);
}*/
ProcessEvent_orig(Context, Function, Parms, Result);
}

Expand All @@ -49,7 +42,7 @@ SPI_IMPLEMENT_ATTACH
Common::OpenConsole();

INIT_CHECK_SDK();
INIT_FIND_PATTERN(ProcessEvent, LE3PATT_PROCESSEVENT);
INIT_FIND_PATTERN_POSTHOOK(ProcessEvent, LE_PATTERN_POSTHOOK_PROCESSEVENT);
INIT_HOOK_PATTERN(ProcessEvent);

return true;
Expand Down
Loading

0 comments on commit 1d6e17a

Please sign in to comment.