-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from TechnologicNick/main
Add SMLuaHook plugin and various other changes
- Loading branch information
Showing
24 changed files
with
1,151 additions
and
320 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?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> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="hooks.h" /> | ||
<ClInclude Include="lua_hook_config.h" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<PropertyGroup Label="Globals"> | ||
<VCProjectVersion>16.0</VCProjectVersion> | ||
<Keyword>Win32Proj</Keyword> | ||
<ProjectGuid>{93661f1d-21dc-4b5b-88ec-6bea337df56b}</ProjectGuid> | ||
<RootNamespace>SMLuaHook</RootNamespace> | ||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>true</UseDebugLibraries> | ||
<PlatformToolset>v142</PlatformToolset> | ||
<CharacterSet>Unicode</CharacterSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> | ||
<ConfigurationType>DynamicLibrary</ConfigurationType> | ||
<UseDebugLibraries>false</UseDebugLibraries> | ||
<PlatformToolset>v142</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> | ||
<IncludePath>$(SolutionDir)..\SMLibrary\include;$(IncludePath)</IncludePath> | ||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<LinkIncremental>false</LinkIncremental> | ||
<IncludePath>$(SolutionDir)..\SMLibrary\include;$(IncludePath)</IncludePath> | ||
<LibraryPath>$(OutDir);$(LibraryPath)</LibraryPath> | ||
</PropertyGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>_DEBUG;SMLUAHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableUAC>false</EnableUAC> | ||
<AdditionalDependencies>smlibrary.lib</AdditionalDependencies> | ||
</Link> | ||
<PostBuildEvent> | ||
<Command>if not exist "$(OutputPath)plugins\" mkdir "$(OutputPath)plugins\" | ||
copy /B "$(LocalDebuggerCommand)" "$(OutputPath)plugins\$(TargetFileName)"</Command> | ||
</PostBuildEvent> | ||
</ItemDefinitionGroup> | ||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> | ||
<ClCompile> | ||
<WarningLevel>Level3</WarningLevel> | ||
<FunctionLevelLinking>true</FunctionLevelLinking> | ||
<IntrinsicFunctions>true</IntrinsicFunctions> | ||
<SDLCheck>true</SDLCheck> | ||
<PreprocessorDefinitions>NDEBUG;SMLUAHOOK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> | ||
<ConformanceMode>true</ConformanceMode> | ||
<PrecompiledHeader>NotUsing</PrecompiledHeader> | ||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> | ||
<LanguageStandard>stdcpp17</LanguageStandard> | ||
</ClCompile> | ||
<Link> | ||
<SubSystem>Windows</SubSystem> | ||
<EnableCOMDATFolding>true</EnableCOMDATFolding> | ||
<OptimizeReferences>true</OptimizeReferences> | ||
<GenerateDebugInformation>true</GenerateDebugInformation> | ||
<EnableUAC>false</EnableUAC> | ||
<AdditionalDependencies>smlibrary.lib</AdditionalDependencies> | ||
</Link> | ||
<PostBuildEvent> | ||
<Command>if not exist "$(OutputPath)plugins\" mkdir "$(OutputPath)plugins\" | ||
copy /B "$(LocalDebuggerCommand)" "$(OutputPath)plugins\$(TargetFileName)"</Command> | ||
</PostBuildEvent> | ||
</ItemDefinitionGroup> | ||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | ||
<ImportGroup Label="ExtensionTargets"> | ||
<Import Project="..\..\SMInjector\packages\luajit.native.2.0.5\build\native\luajit.native.targets" Condition="Exists('..\..\SMInjector\packages\luajit.native.2.0.5\build\native\luajit.native.targets')" /> | ||
<Import Project="..\..\SMInjector\packages\nlohmann.json.3.10.2\build\native\nlohmann.json.targets" Condition="Exists('..\..\SMInjector\packages\nlohmann.json.3.10.2\build\native\nlohmann.json.targets')" /> | ||
</ImportGroup> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\..\SMInjector\packages\luajit.native.2.0.5\build\native\luajit.native.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\SMInjector\packages\luajit.native.2.0.5\build\native\luajit.native.targets'))" /> | ||
<Error Condition="!Exists('..\..\SMInjector\packages\nlohmann.json.3.10.2\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\SMInjector\packages\nlohmann.json.3.10.2\build\native\nlohmann.json.targets'))" /> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<ItemGroup> | ||
<Filter Include="Source Files"> | ||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> | ||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> | ||
</Filter> | ||
<Filter Include="Header Files"> | ||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> | ||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> | ||
</Filter> | ||
<Filter Include="Resource Files"> | ||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> | ||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> | ||
</Filter> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClCompile Include="main.cpp"> | ||
<Filter>Source Files</Filter> | ||
</ClCompile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ClInclude Include="hooks.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
<ClInclude Include="lua_hook_config.h"> | ||
<Filter>Header Files</Filter> | ||
</ClInclude> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#pragma once | ||
#include <stdio.h> | ||
#include <gamehook.h> | ||
#include <path_helper.h> | ||
#include <lua.hpp> | ||
|
||
#include <console.h> | ||
using Console::Color; | ||
|
||
#include "lua_hook_config.h" | ||
|
||
|
||
// LUAL_REGISTER | ||
typedef void (*pluaL_register)(lua_State*, const char*, const luaL_Reg*); | ||
GameHook* hck_luaL_register; | ||
|
||
// LUAL_LOADSTRING | ||
typedef int (*pluaL_loadstring)(lua_State*, const char*); | ||
GameHook* hck_luaL_loadstring; | ||
|
||
// LUA_NEWSTATE | ||
typedef lua_State* (*plua_newstate)(lua_Alloc, void*); | ||
GameHook* hck_lua_newstate; | ||
|
||
// LUAL_LOADBUFFER | ||
typedef int (*pluaL_loadbuffer)(lua_State*, const char*, size_t, const char*); | ||
GameHook* hck_luaL_loadbuffer; | ||
|
||
// ============= | ||
|
||
namespace LuaHook::Hooks { | ||
void hook_luaL_register(lua_State* L, const char* libname, const luaL_Reg* l) { | ||
Console::log(Color::Aqua, "hook_luaL_register: libname=[%s]", libname); | ||
|
||
const luaL_Reg* ptr = l; | ||
|
||
int i = 0; | ||
while (ptr->name != NULL) { | ||
Console::log(Color::Aqua, "hook_luaL_register: luaL_Reg[%d] name=[%s] func=[%p]", i++, ptr->name, (void*)ptr->func); | ||
|
||
ptr++; | ||
} | ||
|
||
return ((pluaL_register)*hck_luaL_register)(L, libname, l); | ||
} | ||
|
||
int hook_luaL_loadstring(lua_State* L, const char* s) { | ||
Console::log(Color::Aqua, "hook_luaL_loadstring: s=[ ... ]"); | ||
|
||
std::map<std::string, std::any> fields = { | ||
{"s", &s} | ||
}; | ||
|
||
std::string input(s); | ||
|
||
if (LuaHook::runLuaHook("luaL_loadstring", &input, fields)) { | ||
Console::log(Color::Green, "Set contents to:\n%s", input.c_str()); | ||
return ((pluaL_loadstring)*hck_luaL_loadstring)(L, input.c_str()); | ||
} | ||
|
||
return ((pluaL_loadstring)*hck_luaL_loadstring)(L, s); | ||
} | ||
|
||
lua_State* hook_lua_newstate(lua_Alloc f, void* ud) { | ||
Console::log(Color::Aqua, "hck_lua_newstate: ud=[%p]", ud); | ||
return ((plua_newstate)*hck_lua_newstate)(f, ud); | ||
} | ||
|
||
int hook_luaL_loadbuffer(lua_State* L, const char* buff, size_t sz, const char* name) { | ||
Console::log(Color::Aqua, "hck_luaL_loadbuffer: buff=[ ... ], sz=[%zu], name=[%s]", sz, name); | ||
|
||
std::map<std::string, std::any> fields = { | ||
{"buff", &buff}, | ||
{"name", &name} | ||
}; | ||
|
||
std::string input(buff, sz); | ||
|
||
if (size_t executeCount = LuaHook::runLuaHook("luaL_loadbuffer", &input, fields)) { | ||
Console::log(Color::Green, "Set contents to:\n%s", input.c_str()); | ||
return ((pluaL_loadbuffer)*hck_luaL_loadbuffer)(L, input.c_str(), input.size(), name); | ||
} | ||
|
||
return ((pluaL_loadbuffer)*hck_luaL_loadbuffer)(L, buff, sz, name); | ||
} | ||
} |
Oops, something went wrong.