Skip to content

Commit

Permalink
Add LE2HotReload ASI code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mgamerz committed Aug 31, 2022
1 parent fbe3d0f commit 4329259
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
6 changes: 6 additions & 0 deletions LE2-ASI-Plugins.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE2ConsoleExtension", "LE2C
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE2LEXInterop", "LE2LEXInterop\LE2LEXInterop.vcxproj", "{3E825F49-5D7E-4064-B5B2-03011B408B6F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LE2HotReload", "LE2HotReload\LE2HotReload.vcxproj", "{D56CAF33-BA78-4541-98EE-02BCD292EECF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -81,6 +83,10 @@ Global
{3E825F49-5D7E-4064-B5B2-03011B408B6F}.Debug|x64.Build.0 = Debug|x64
{3E825F49-5D7E-4064-B5B2-03011B408B6F}.Release|x64.ActiveCfg = Release|x64
{3E825F49-5D7E-4064-B5B2-03011B408B6F}.Release|x64.Build.0 = Release|x64
{D56CAF33-BA78-4541-98EE-02BCD292EECF}.Debug|x64.ActiveCfg = Debug|x64
{D56CAF33-BA78-4541-98EE-02BCD292EECF}.Debug|x64.Build.0 = Debug|x64
{D56CAF33-BA78-4541-98EE-02BCD292EECF}.Release|x64.ActiveCfg = Release|x64
{D56CAF33-BA78-4541-98EE-02BCD292EECF}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
55 changes: 55 additions & 0 deletions LE2HotReload/LE2HotReload.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "../../Shared-ASI/Interface.h"
#include "../../Shared-ASI/Common.h"

SPI_PLUGINSIDE_SUPPORT(L"LE2HotReload", L"1.0.0", L"ME3Tweaks", SPI_GAME_LE2, SPI_VERSION_LATEST);
SPI_PLUGINSIDE_PRELOAD;
SPI_PLUGINSIDE_ASYNCATTACH;

/**
* \brief Patches a segment of process memory.
* \param address The address to start the overwrite of patch data to
* \param patch The patch data
* \param patchSize The size of patch
* \return true if patched, false otherwise
*/
bool PatchMemory(void* address, const void* patch, const SIZE_T patchSize)
{
//make the memory we're going to patch writeable
DWORD oldProtect;
if (!VirtualProtect(address, patchSize, PAGE_EXECUTE_READWRITE, &oldProtect))
return false;

//overwrite with our patch
memcpy(address, patch, patchSize);

//restore the memory's old protection level
VirtualProtect(address, patchSize, oldProtect, &oldProtect);
FlushInstructionCache(GetCurrentProcess(), address, patchSize);
return true;
}

void* PatchOffset;
const BYTE patchData[] = { 0x03 };
SPI_IMPLEMENT_ATTACH
{
//Common::OpenConsole();
INIT_FIND_PATTERN(PatchOffset, "01 ff 15 97 41 f0 00 48 89 06 48 83 f8");
if (PatchOffset != nullptr)
{
PatchMemory(PatchOffset, patchData , 1);
writeln("Patched for hot reload at %p", PatchOffset);
} else
{
writeln("Failed to patch for hot reload");
}
}


SPI_IMPLEMENT_DETACH
{
return true;
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD reason, LPVOID) {
return TRUE;
}
102 changes: 102 additions & 0 deletions LE2HotReload/LE2HotReload.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{D56CAF33-BA78-4541-98EE-02BCD292EECF}</ProjectGuid>
<RootNamespace>SeqActLog Enabler</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>LE2HotReload</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</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|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetExt>.asi</TargetExt>
<TargetName>LE2HotReload</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetExt>.asi</TargetExt>
<TargetName>LE2HotReload</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>ASI_DEBUG;_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>false</ConformanceMode>
<LanguageStandard>stdcpp17</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="LE2HotReload.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="HookPrototypes.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

0 comments on commit 4329259

Please sign in to comment.