├── .github └── workflows │ └── msbuild.yml ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── LICENSE ├── docs └── README.md ├── genshin-scripting-framework.sln ├── gsf-client ├── api │ ├── api_controls.cpp │ ├── api_controls.h │ ├── api_game.cpp │ ├── api_game.h │ ├── api_gsf.cpp │ ├── api_gsf.h │ ├── api_imgui.cpp │ ├── api_imgui.h │ ├── api_mem.cpp │ ├── api_mem.h │ ├── api_win.cpp │ ├── api_win.h │ ├── i_api.h │ └── script_apis.h ├── callback_manager.cpp ├── callback_manager.h ├── cpp.hint ├── dllmain.cpp ├── game.cpp ├── game.h ├── global.h ├── gsf-client.vcxproj ├── gsf-client.vcxproj.filters ├── gsf-client.vcxproj.user ├── gsf_client.cpp ├── gsf_client.h ├── helpers │ ├── imgui_prompts.cpp │ └── imgui_prompts.h ├── hooks.cpp ├── hooks.h ├── log_manager.cpp ├── log_manager.h ├── menu │ ├── menu.cpp │ ├── menu.h │ ├── tab_about.cpp │ ├── tab_about.h │ ├── tab_logs.cpp │ ├── tab_logs.h │ ├── tab_misc.cpp │ ├── tab_misc.h │ ├── tab_scripts.cpp │ └── tab_scripts.h ├── script.cpp ├── script.h ├── script_manager.cpp ├── script_manager.h └── sdk │ ├── il2cpp │ └── il2cpp.h │ ├── sdk.h │ ├── structures.h │ └── unity │ ├── enums.h │ ├── unity.h │ ├── unity_animator.h │ ├── unity_camera.h │ ├── unity_component.h │ ├── unity_cursor.h │ ├── unity_input.h │ ├── unity_jsonutility.h │ ├── unity_object.h │ ├── unity_primitive_types.h │ ├── unity_scripting_api.h │ ├── unity_transform.h │ └── unity_vector3.h ├── gsf-launcher ├── gsf-launcher.cpp ├── gsf-launcher.vcxproj ├── gsf-launcher.vcxproj.filters └── gsf-launcher.vcxproj.user ├── thirdparty ├── imgui │ ├── imconfig.h │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui.vcxitems │ ├── imgui.vcxitems.user │ ├── imgui_draw.cpp │ ├── imgui_impl_dx11.cpp │ ├── imgui_impl_dx11.h │ ├── imgui_impl_win32.cpp │ ├── imgui_impl_win32.h │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── license_imgui.txt ├── license_minhook.txt ├── lua │ ├── lapi.c │ ├── lapi.h │ ├── lauxlib.c │ ├── lauxlib.h │ ├── lbaselib.c │ ├── lcode.c │ ├── lcode.h │ ├── lcorolib.c │ ├── lctype.c │ ├── lctype.h │ ├── ldblib.c │ ├── ldebug.c │ ├── ldebug.h │ ├── ldo.c │ ├── ldo.h │ ├── ldump.c │ ├── lfunc.c │ ├── lfunc.h │ ├── lgc.c │ ├── lgc.h │ ├── linit.c │ ├── liolib.c │ ├── ljumptab.h │ ├── llex.c │ ├── llex.h │ ├── llimits.h │ ├── lmathlib.c │ ├── lmem.c │ ├── lmem.h │ ├── loadlib.c │ ├── lobject.c │ ├── lobject.h │ ├── lopcodes.c │ ├── lopcodes.h │ ├── lopnames.h │ ├── loslib.c │ ├── lparser.c │ ├── lparser.h │ ├── lprefix.h │ ├── lstate.c │ ├── lstate.h │ ├── lstring.c │ ├── lstring.h │ ├── lstrlib.c │ ├── ltable.c │ ├── ltable.h │ ├── ltablib.c │ ├── ltm.c │ ├── ltm.h │ ├── lua.c │ ├── lua.h │ ├── lua.hpp │ ├── lua.vcxitems │ ├── lua.vcxitems.user │ ├── luaconf.h │ ├── lualib.h │ ├── lundump.c │ ├── lundump.h │ ├── lutf8lib.c │ ├── lvm.c │ ├── lvm.h │ ├── lzio.c │ └── lzio.h ├── minhook │ ├── MinHook.h │ ├── minhook.vcxitems │ ├── minhook.vcxitems.user │ └── src │ │ ├── buffer.c │ │ ├── buffer.h │ │ ├── hde │ │ ├── hde32.c │ │ ├── hde32.h │ │ ├── hde64.c │ │ ├── hde64.h │ │ ├── pstdint.h │ │ ├── table32.h │ │ └── table64.h │ │ ├── hook.c │ │ ├── trampoline.c │ │ └── trampoline.h └── sol │ ├── config.hpp │ ├── forward.hpp │ ├── sol.hpp │ ├── sol.vcxitems │ └── sol.vcxitems.user └── utils ├── console.cpp ├── console.h ├── hash.h ├── hooking.cpp ├── hooking.h ├── loadlibrary.cpp ├── loadlibrary.h ├── macro.h ├── mem.cpp ├── mem.h ├── misc_utils.cpp ├── misc_utils.h ├── utils.vcxitems ├── utils.vcxitems.user ├── winapi_helper.cpp ├── winapi_helper.h ├── winternal.cpp └── winternal.h /.github/workflows/msbuild.yml: -------------------------------------------------------------------------------- 1 | name: MSBuild 2 | 3 | on: [push] 4 | 5 | env: 6 | # Path to the solution file relative to the root of the project. 7 | SOLUTION_FILE_PATH: ./genshin-scripting-framework.sln 8 | 9 | jobs: 10 | build: 11 | runs-on: windows-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Add MSBuild to PATH 17 | uses: microsoft/setup-msbuild@v1.0.2 18 | 19 | - name: Restore NuGet packages 20 | working-directory: ${{env.GITHUB_WORKSPACE}} 21 | run: nuget restore ${{env.SOLUTION_FILE_PATH}} 22 | 23 | - name: Build gsf-client (Release) 24 | working-directory: ${{env.GITHUB_WORKSPACE}} 25 | run: msbuild /m /p:Configuration=Release ${{env.SOLUTION_FILE_PATH}} /t:gsf-client 26 | 27 | - name: Build gsf-launcher (Release) 28 | working-directory: ${{env.GITHUB_WORKSPACE}} 29 | run: msbuild /m /p:Configuration=Release ${{env.SOLUTION_FILE_PATH}} /t:gsf-launcher 30 | 31 | - name: Build gsf-client (Debug) 32 | working-directory: ${{env.GITHUB_WORKSPACE}} 33 | run: msbuild /m /p:Configuration=Debug ${{env.SOLUTION_FILE_PATH}} /t:gsf-client 34 | 35 | - name: Build gsf-launcher (Debug) 36 | working-directory: ${{env.GITHUB_WORKSPACE}} 37 | run: msbuild /m /p:Configuration=Debug ${{env.SOLUTION_FILE_PATH}} /t:gsf-launcher 38 | 39 | - uses: actions/upload-artifact@v2 40 | with: 41 | name: build-artifacts 42 | path: | 43 | ./build/ 44 | !./build/obj/ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vs/ 2 | build/ 3 | bin/ 4 | obj/ 5 | *.exe 6 | *.dll 7 | *.obj 8 | *.ilk 9 | *.idb 10 | *.pdb 11 | gsf-client/git_hash.h 12 | gsf-client/git_info.h 13 | gsf-client/autoexecdef.h 14 | gsf-client/scripts/ 15 | re_stuff/ 16 | wiki/ 17 | scripts/ 18 | notes.txt -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gsf-bypass"] 2 | path = gsf-bypass 3 | url = git@github.com:u16rogue/gsf-bypass.git 4 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "algorithm": "cpp", 4 | "array": "cpp", 5 | "atomic": "cpp", 6 | "bit": "cpp", 7 | "bitset": "cpp", 8 | "cctype": "cpp", 9 | "charconv": "cpp", 10 | "chrono": "cpp", 11 | "clocale": "cpp", 12 | "cmath": "cpp", 13 | "compare": "cpp", 14 | "concepts": "cpp", 15 | "cstddef": "cpp", 16 | "cstdint": "cpp", 17 | "cstdio": "cpp", 18 | "cstdlib": "cpp", 19 | "cstring": "cpp", 20 | "ctime": "cpp", 21 | "cwchar": "cpp", 22 | "exception": "cpp", 23 | "filesystem": "cpp", 24 | "format": "cpp", 25 | "forward_list": "cpp", 26 | "functional": "cpp", 27 | "initializer_list": "cpp", 28 | "iomanip": "cpp", 29 | "ios": "cpp", 30 | "iosfwd": "cpp", 31 | "iostream": "cpp", 32 | "istream": "cpp", 33 | "iterator": "cpp", 34 | "limits": "cpp", 35 | "list": "cpp", 36 | "locale": "cpp", 37 | "map": "cpp", 38 | "memory": "cpp", 39 | "mutex": "cpp", 40 | "new": "cpp", 41 | "optional": "cpp", 42 | "ostream": "cpp", 43 | "ratio": "cpp", 44 | "sstream": "cpp", 45 | "stdexcept": "cpp", 46 | "stop_token": "cpp", 47 | "streambuf": "cpp", 48 | "string": "cpp", 49 | "system_error": "cpp", 50 | "thread": "cpp", 51 | "tuple": "cpp", 52 | "type_traits": "cpp", 53 | "typeinfo": "cpp", 54 | "unordered_map": "cpp", 55 | "utility": "cpp", 56 | "variant": "cpp", 57 | "vector": "cpp", 58 | "xfacet": "cpp", 59 | "xhash": "cpp", 60 | "xiosbase": "cpp", 61 | "xlocale": "cpp", 62 | "xlocbuf": "cpp", 63 | "xlocinfo": "cpp", 64 | "xlocmes": "cpp", 65 | "xlocmon": "cpp", 66 | "xlocnum": "cpp", 67 | "xloctime": "cpp", 68 | "xmemory": "cpp", 69 | "xstddef": "cpp", 70 | "xstring": "cpp", 71 | "xtr1common": "cpp", 72 | "xtree": "cpp", 73 | "xutility": "cpp" 74 | } 75 | } -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Genshin Impact Scripting Framework 2 | 3 | [![genshin](https://img.shields.io/badge/Genshin%20Impact-2.2-blue?style=for-the-badge&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAE/ElEQVRYw+2UW2wUVRjH/+fMzM7MLu222xbaIq0UCr3Q0GbpRYIBH5pABJVopEFNFOUS0ERDfBE04SKBCELR+kBAnkAFpAhFIlogsbZ0gYLcQrcul21h291ul2139jozxwcxokLpLqG88HucZM73+3/n+w7whMcM9zA/L7W+xlkzC8jp7stsGJ0JGGMAwHedaF/WecL+XjbS+DvfhgfGGH7aUl8UuNHjUJzu6z/XHihJVIDGlx1gbQyEEK7YWlAjGvrzBKLk5luL5hNCeF+Da3jSH9lcXxi45rRrN0+x6Pmz7Lbd5Ti49dCkRLoQVwdYy530UwpqpCQ1nxCAhDRIupqXXzZxPiGEv1R//dEJoAo4snFfviU7uYYKGiAYAcqB+mOwpI+Yt2Pz/oKil3IfjcDGhetACOGKyifNk5LZBMILgGACIxK0iABJF/MKy4rnE0L4JYvWx3sTg8MTAxhj+G7t7kn91zxX9L4uxoK3mK54WPjcDeZvcrOu1n7WftHj+HTD/jLGGAgRhnT2Ax6iv3be1xFLsvApz5dOLVmVnGm00liYIKoCUhKifoJARIBXE+DihNTkMZnFx5vt/hif3XXywrHoZ6tWJyawbUszwmEiW8SRM154uXrt2AlZH5oMhgnqgE6YKIJGYwAvQPFx8KsCwikC/CYePlnMMY1MnV0yuaSk8fgVn88vuF5990u19ej2oQvkjZ1lqJheUb7gzVc+mVySuzLDYrIaGDFwOoGuUoSDPCCI4KDBHxQRNolAKg9Z4iAZKXw8b+iTpEJjhmV2aWXlOP9tj7u9o9cd9tq1QQW2/aDjhrNXXrFh9UdTn524KTsndRoVeTmqAyFQhAhFjFKENKBngEMIAqIiRb/IQQHDgAoENYASQCUE5wKc3MdJZYXj0uc8M22a7LC7WxdvalCb9tX+M193C5TPIMCaAPWGIwZnROWu+TTY+wB3gCBIKQgh4AkDQCD6NVRLBCdvqvjDG4GmApoGgDAYRAJBolDAgecZPCkq4SMRGvK7SfW8p7G+5u4p+z9UNo83zV26stI6vert9JysWV4YzfYAhZ8noGZAVBimCAxzcwnWHNdwqVOHzDQIRgKzmSI5nYM5BUgKR3yqu+dwu6115/e1H9vCPkcQgP7vMb/f+APUklNhfnHx8umlU63vpGSNes6nynKnQpAhMZSPoyjgGdbbGGxOwGJhGJ1PkS0ypAYjSri395ij9ez2hrp1v3ZftfXfKczuVWjwPQToU6Vz0me9vmhmWVXpUjl1VEWSiUNaGsUYomPrJR0XPBTZOUBpps7Ezt6WjpZzdT/uqPvFcbbBe7/CD1zDu2D93fZg29FvLsak8ZcLi8dX6zHRbBAIZAr87mWgJoKcLCDL6+84VLd74a41bzT6uu2B/7b7Xgz1KWYA1KNfLTvT6XTV60yFp1uHEmJIZkBGEjCaqejpcH17ZNv7FwCog6VOROBvwmeaz+yOxZSufkXHgB9IkwjSBQbJq9htjU17AUTjOTBeAXb487fO33K6DshGDZ1eDQKAUUxDt8O19+AXSzqGmjxRAQAIn246tUuPDdyMEIBqGjhF6bCd+G1PvOkTFWANWxacdzpdB0wjGIwGhq7rrj0Haxe1x5s+UQEACLU1t+1i2oBLiw1cbWlsSij9Q5JpXL6zdcUHX59cDkAa5uIAAJqSVSmnjq6SkXgnn/D4+RPqTygogAMTxAAAAABJRU5ErkJggg==)](https://genshin.mihoyo.com/) 4 | [![issues](https://img.shields.io/github/issues/u16rogue/genshin-scripting-framework?style=for-the-badge)](https://github.com/u16rogue/genshin-scripting-framework/issues) 5 | [![license](https://img.shields.io/github/license/u16rogue/genshin-scripting-framework?style=for-the-badge)](https://github.com/u16rogue/genshin-scripting-framework/blob/master/LICENSE) 6 | [![master_activity](https://img.shields.io/github/last-commit/u16rogue/genshin-scripting-framework/master?label=master%20last%20activity&style=for-the-badge)](https://github.com/u16rogue/genshin-scripting-framework/tree/master) 7 | [![msbuild_master](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fu16rogue%2Fgenshin-scripting-framework%2Fbadge%3Fref%3Dmaster&style=for-the-badge&label=master%20build)](https://github.com/u16rogue/genshin-scripting-framework/actions/workflows/msbuild.yml?query=branch%3Amaster) 8 | [![dev_activity](https://img.shields.io/github/last-commit/u16rogue/genshin-scripting-framework/dev?label=dev%20last%20activity&style=for-the-badge)](https://github.com/u16rogue/genshin-scripting-framework/tree/dev) 9 | [![msbuild_dev](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fu16rogue%2Fgenshin-scripting-framework%2Fbadge%3Fref%3Ddev&style=for-the-badge&label=dev%20build)](https://github.com/u16rogue/genshin-scripting-framework/actions/workflows/msbuild.yml?query=branch%3Adev) 10 | 11 | [About](#About) • [Wiki](https://github.com/u16rogue/genshin-scripting-framework/wiki) • [Getting Started](https://github.com/u16rogue/genshin-scripting-framework/wiki/%5B2%5D-Getting-Started) • [Usage](https://github.com/u16rogue/genshin-scripting-framework/wiki/%5B3%5D-Usage) • [Scripting API Documentation](https://github.com/u16rogue/genshin-scripting-framework/wiki/%5B4.0%5D-Scripting) • [Libraries](#Libraries) • [License](#License) 12 | 13 | ![](https://raw.githubusercontent.com/wiki/u16rogue/genshin-scripting-framework/client_ss.jpg) 14 | 15 | ## About 16 | Provides a scripting framework and API for the game [Genshin Impact](https://genshin.mihoyo.com/). 17 | 18 | #### Disclaimer: 19 | * *GSF is not a cheat/hack. GSF does not contain any "advantage" enchancement features built in. GSF only provides a framework and API to its users.* 20 | * *The contributors of this repository/project/software bear no responsibility on whatever purpose the user does with this.* 21 | 22 | ## Libraries 23 | * [MinHook](https://github.com/TsudaKageyu/minhook) 1.3.3 - TsudaKageyu 24 | * [Dear ImGui](https://github.com/ocornut/imgui) 1.80 - ocornut 25 | * [Lua](https://www.lua.org/) 5.4.3 - Lua org, PUC-Rio 26 | * [sol2](https://github.com/ThePhD/sol2) 3.2.2 - Rapptz, ThePhD, and contributors 27 | 28 | ## License 29 | [GNU General Public License 3.0](https://www.gnu.org/licenses/gpl-3.0.en.html) -------------------------------------------------------------------------------- /genshin-scripting-framework.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31205.134 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "utils", "utils\utils.vcxitems", "{A2D09AC9-23C1-4B03-AF08-2EF6798147E3}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gsf-client", "gsf-client\gsf-client.vcxproj", "{36330540-2FDF-46AC-ACCA-68FBED6692AC}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "thirdparty", "thirdparty", "{924EAB71-3262-4B0E-97B2-0B475EB682D6}" 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imgui", "thirdparty\imgui\imgui.vcxitems", "{69063E09-D8A8-4FA9-A306-69F5F615DB38}" 13 | EndProject 14 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "minhook", "thirdparty\minhook\minhook.vcxitems", "{2956636E-C74F-4083-9493-873DA4E44CBF}" 15 | EndProject 16 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua", "thirdparty\lua\lua.vcxitems", "{8754E545-8E7D-4A4C-88D5-F5CC94A1BA04}" 17 | EndProject 18 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sol", "thirdparty\sol\sol.vcxitems", "{4C58FEAD-6F55-48E8-8B76-63337A70C361}" 19 | EndProject 20 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gsf-launcher", "gsf-launcher\gsf-launcher.vcxproj", "{A3415378-0073-4E01-982E-A7B99C249819}" 21 | ProjectSection(ProjectDependencies) = postProject 22 | {36330540-2FDF-46AC-ACCA-68FBED6692AC} = {36330540-2FDF-46AC-ACCA-68FBED6692AC} 23 | EndProjectSection 24 | EndProject 25 | Global 26 | GlobalSection(SharedMSBuildProjectFiles) = preSolution 27 | thirdparty\minhook\minhook.vcxitems*{2956636e-c74f-4083-9493-873da4e44cbf}*SharedItemsImports = 9 28 | thirdparty\imgui\imgui.vcxitems*{36330540-2fdf-46ac-acca-68fbed6692ac}*SharedItemsImports = 4 29 | thirdparty\lua\lua.vcxitems*{36330540-2fdf-46ac-acca-68fbed6692ac}*SharedItemsImports = 4 30 | thirdparty\minhook\minhook.vcxitems*{36330540-2fdf-46ac-acca-68fbed6692ac}*SharedItemsImports = 4 31 | thirdparty\sol\sol.vcxitems*{36330540-2fdf-46ac-acca-68fbed6692ac}*SharedItemsImports = 4 32 | utils\utils.vcxitems*{36330540-2fdf-46ac-acca-68fbed6692ac}*SharedItemsImports = 4 33 | thirdparty\sol\sol.vcxitems*{4c58fead-6f55-48e8-8b76-63337a70c361}*SharedItemsImports = 9 34 | thirdparty\imgui\imgui.vcxitems*{69063e09-d8a8-4fa9-a306-69f5f615db38}*SharedItemsImports = 9 35 | thirdparty\lua\lua.vcxitems*{8754e545-8e7d-4a4c-88d5-f5cc94a1ba04}*SharedItemsImports = 9 36 | utils\utils.vcxitems*{a2d09ac9-23c1-4b03-af08-2ef6798147e3}*SharedItemsImports = 9 37 | thirdparty\minhook\minhook.vcxitems*{a3415378-0073-4e01-982e-a7b99c249819}*SharedItemsImports = 4 38 | utils\utils.vcxitems*{a3415378-0073-4e01-982e-a7b99c249819}*SharedItemsImports = 4 39 | EndGlobalSection 40 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 41 | Debug|x64 = Debug|x64 42 | Release|x64 = Release|x64 43 | EndGlobalSection 44 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 45 | {36330540-2FDF-46AC-ACCA-68FBED6692AC}.Debug|x64.ActiveCfg = Debug|x64 46 | {36330540-2FDF-46AC-ACCA-68FBED6692AC}.Debug|x64.Build.0 = Debug|x64 47 | {36330540-2FDF-46AC-ACCA-68FBED6692AC}.Release|x64.ActiveCfg = Release|x64 48 | {36330540-2FDF-46AC-ACCA-68FBED6692AC}.Release|x64.Build.0 = Release|x64 49 | {A3415378-0073-4E01-982E-A7B99C249819}.Debug|x64.ActiveCfg = Debug|x64 50 | {A3415378-0073-4E01-982E-A7B99C249819}.Debug|x64.Build.0 = Debug|x64 51 | {A3415378-0073-4E01-982E-A7B99C249819}.Release|x64.ActiveCfg = Release|x64 52 | {A3415378-0073-4E01-982E-A7B99C249819}.Release|x64.Build.0 = Release|x64 53 | EndGlobalSection 54 | GlobalSection(SolutionProperties) = preSolution 55 | HideSolutionNode = FALSE 56 | EndGlobalSection 57 | GlobalSection(NestedProjects) = preSolution 58 | {69063E09-D8A8-4FA9-A306-69F5F615DB38} = {924EAB71-3262-4B0E-97B2-0B475EB682D6} 59 | {2956636E-C74F-4083-9493-873DA4E44CBF} = {924EAB71-3262-4B0E-97B2-0B475EB682D6} 60 | {8754E545-8E7D-4A4C-88D5-F5CC94A1BA04} = {924EAB71-3262-4B0E-97B2-0B475EB682D6} 61 | {4C58FEAD-6F55-48E8-8B76-63337A70C361} = {924EAB71-3262-4B0E-97B2-0B475EB682D6} 62 | EndGlobalSection 63 | GlobalSection(ExtensibilityGlobals) = postSolution 64 | SolutionGuid = {C27A1E17-7571-4265-B2E6-DCE1A9DAC05D} 65 | EndGlobalSection 66 | EndGlobal 67 | -------------------------------------------------------------------------------- /gsf-client/api/api_controls.cpp: -------------------------------------------------------------------------------- 1 | #include "api_controls.h" 2 | 3 | #include 4 | 5 | bool gsf::api_controls::setup_api(sol::state &slua) 6 | { 7 | auto namespace_controls = slua["controls"].get_or_create(); 8 | 9 | #define _ENUM_ENTRY_api_controls(_e, _v) #_v ## , ## api_controls:: ## _e ## :: ## _v 10 | 11 | namespace_controls.new_enum("keys", 12 | _ENUM_ENTRY_api_controls(keys, LMOUSE), 13 | _ENUM_ENTRY_api_controls(keys, ATTACK), 14 | 15 | _ENUM_ENTRY_api_controls(keys, RMOUSE), 16 | _ENUM_ENTRY_api_controls(keys, SPRINT), 17 | 18 | _ENUM_ENTRY_api_controls(keys, MMOUSE), 19 | _ENUM_ENTRY_api_controls(keys, ELEMENTAL_SIGHT), 20 | _ENUM_ENTRY_api_controls(keys, RESET_CAMERA) 21 | ); 22 | 23 | namespace_controls.new_enum("directions", 24 | _ENUM_ENTRY_api_controls(directions, UP), 25 | _ENUM_ENTRY_api_controls(directions, DOWN), 26 | _ENUM_ENTRY_api_controls(directions, LEFT), 27 | _ENUM_ENTRY_api_controls(directions, RIGHT) 28 | ); 29 | 30 | #undef _ENUM_ENTRY_api_controls 31 | 32 | namespace_controls.set_function("key_down", &gsf::api_controls::key_down); 33 | namespace_controls.set_function("look", &gsf::api_controls::look); 34 | 35 | return true; 36 | } 37 | 38 | void gsf::api_controls::key_down(api_controls::keys key, int ticks) 39 | { 40 | for (auto &flag_key : api_controls::flags_mouse) 41 | { 42 | if (flag_key.enum_tag != key) 43 | continue; 44 | 45 | // we're using decltype of variable ticks for consistency, int32's -1 and int64's -1 have different bits 46 | // this is for future proofing incase a refactoring would take place 47 | constexpr decltype(ticks) TICKS_HOLD_KEY = -1; 48 | constexpr decltype(ticks) TICKS_RELEASE_KEY = 0; 49 | if (ticks == TICKS_RELEASE_KEY || ticks == TICKS_HOLD_KEY || ticks > flag_key.ticks /* only accept new n ticks if its higher than the current tick count for the key */ ) 50 | flag_key.ticks = ticks; 51 | 52 | return; 53 | } 54 | } 55 | 56 | void gsf::api_controls::look(api_controls::directions direction, float amount) 57 | { 58 | constexpr int SHOULD_BE_NEGATIVE = (int)api_controls::directions::LEFT ^ (int)api_controls::directions::RIGHT ^ (int)api_controls::directions::UP ^ (int)api_controls::directions::DOWN; 59 | 60 | for (auto &flag_direction : api_controls::flags_look) 61 | { 62 | if (~(int)flag_direction.enum_tag & (int)direction) 63 | continue; 64 | 65 | flag_direction.amount = amount * ((int)direction & SHOULD_BE_NEGATIVE ? -1.f : 1.f); 66 | 67 | return; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /gsf-client/api/api_controls.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | #include 5 | 6 | namespace gsf 7 | { 8 | class api_controls : public i_api 9 | { 10 | template 11 | struct control_bridge_info 12 | { 13 | utils::fnv1a64_t game_identifier; // used for comparing from hooked unity engine scripting api 14 | enum_t enum_tag; // used for comparing within GSF's api 15 | 16 | union 17 | { 18 | value_t amount; 19 | value_t ticks; 20 | }; 21 | }; 22 | 23 | enum class keys : int 24 | { 25 | LMOUSE = 0, 26 | ATTACK = LMOUSE, 27 | 28 | RMOUSE = 1, 29 | SPRINT = RMOUSE, 30 | 31 | MMOUSE = 2, 32 | ELEMENTAL_SIGHT = MMOUSE, 33 | RESET_CAMERA = MMOUSE, 34 | }; 35 | 36 | enum class directions : int 37 | { 38 | UP = 0b0001, 39 | DOWN = 0b0011, 40 | RIGHT = 0b0100, 41 | LEFT = 0b1100, 42 | 43 | X_AXIS = LEFT | RIGHT, 44 | Y_AXIS = UP | DOWN, 45 | }; 46 | 47 | protected: 48 | api_controls() {} 49 | bool setup_api(sol::state &slua); 50 | 51 | private: 52 | static void key_down(api_controls::keys key, int ticks); 53 | static void look(api_controls::directions direction, float amount); 54 | 55 | public: 56 | 57 | inline static api_controls::control_bridge_info flags_mouse[] = 58 | { 59 | { utils::hash_fnv1a_cv("MouseButton0"), api_controls::keys::LMOUSE, 0 }, 60 | { utils::hash_fnv1a_cv("MouseButton1"), api_controls::keys::RMOUSE, 0 }, 61 | { utils::hash_fnv1a_cv("MouseButton2"), api_controls::keys::MMOUSE, 0 }, 62 | }; 63 | 64 | inline static api_controls::control_bridge_info flags_look[] = 65 | { 66 | { utils::hash_fnv1a_cv("MouseAxis1"), api_controls::directions::X_AXIS, 0.f }, 67 | { utils::hash_fnv1a_cv("MouseAxis2"), api_controls::directions::Y_AXIS, 0.f }, 68 | }; 69 | }; 70 | } -------------------------------------------------------------------------------- /gsf-client/api/api_game.cpp: -------------------------------------------------------------------------------- 1 | #include "api_game.h" 2 | #include "../game.h" 3 | 4 | bool gsf::api_game::setup_api(sol::state &slua) 5 | { 6 | auto namespace_game = slua["game"].get_or_create(); 7 | namespace_game.set_function("get_map_coords", &gsf::api_game::_api_get_map_coords, this); 8 | namespace_game.set_function("get_fn", [](const char *name) { return reinterpret_cast(game::sdk::unity_scripting_api<>::get_unity_api(name)); }); 9 | namespace_game.set_function("object_get_name", [](std::uintptr_t object) { return game::il2cpp_string_chars(reinterpret_cast(object)->get_name()); }); 10 | 11 | return true; 12 | } 13 | 14 | sol::table gsf::api_game::_api_get_map_coords() 15 | { 16 | return this->get_lua_state().create_table_with("x", game::player_map_coords->x, "z", game::player_map_coords->z); 17 | } -------------------------------------------------------------------------------- /gsf-client/api/api_game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | 5 | namespace gsf 6 | { 7 | class api_game : public i_api 8 | { 9 | protected: 10 | api_game() {} 11 | bool setup_api(sol::state &slua); 12 | 13 | private: 14 | sol::table _api_get_map_coords(); 15 | }; 16 | } -------------------------------------------------------------------------------- /gsf-client/api/api_gsf.cpp: -------------------------------------------------------------------------------- 1 | #include "api_gsf.h" 2 | #include 3 | #include "../log_manager.h" 4 | #include 5 | #include "../callback_manager.h" 6 | 7 | bool gsf::api_gsf::setup_api(sol::state &slua) 8 | { 9 | auto namespace_gsf = slua["gsf"].get_or_create(); 10 | namespace_gsf.set_function("log", &api_gsf::_api_log, this); 11 | namespace_gsf.set_function("register_callback", &api_gsf::_api_register_callback, this); 12 | namespace_gsf.set_function("get_script_dir", &api_gsf::_api_get_script_dir, this); 13 | namespace_gsf.set_function("create_detached_thread", &api_gsf::_api_create_detached_thread, this); 14 | 15 | return true; 16 | } 17 | 18 | void gsf::api_gsf::script_push_log(std::string msg) 19 | { 20 | DEBUG_COUT("\n[SCRIPT] " << msg); 21 | gsf::log_manager::push_log(std::move(msg), gsf::log_manager::log_type::SCRIPTS); 22 | } 23 | 24 | void gsf::api_gsf::_api_log(std::string txt) 25 | { 26 | this->script_push_log(std::move(txt)); 27 | } 28 | 29 | bool gsf::api_gsf::_api_register_callback(std::string id, sol::function callback) 30 | { 31 | return gsf::callback_manager::register_luafn(utils::hash_fnv1a(id.c_str()), this, callback); 32 | } 33 | 34 | std::string gsf::api_gsf::_api_get_script_dir() 35 | { 36 | auto abs = std::filesystem::canonical(this->get_filepath()).string(); 37 | return abs.substr(0, abs.find_last_of("/\\") + 1); 38 | } 39 | 40 | void gsf::api_gsf::_api_create_detached_thread(sol::function fn) 41 | { 42 | return std::thread([](sol::function fn) 43 | { 44 | fn(); 45 | }, std::move(fn)).detach(); 46 | } 47 | -------------------------------------------------------------------------------- /gsf-client/api/api_gsf.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace gsf 10 | { 11 | class api_gsf : public i_api 12 | { 13 | protected: 14 | api_gsf() {} 15 | bool setup_api(sol::state &slua); 16 | void script_push_log(std::string msg); 17 | 18 | private: 19 | void _api_log(std::string txt); 20 | bool _api_register_callback(std::string id, sol::function callback); 21 | std::string _api_get_script_dir(); 22 | void _api_create_detached_thread(sol::function fn); 23 | }; 24 | } -------------------------------------------------------------------------------- /gsf-client/api/api_imgui.cpp: -------------------------------------------------------------------------------- 1 | #include "api_imgui.h" 2 | #include 3 | 4 | bool gsf::api_imgui::setup_api(sol::state &slua) 5 | { 6 | auto namespace_imgui = slua["imgui"].get_or_create(); 7 | 8 | namespace_imgui.set_function("set_data_ref_string", &gsf::api_imgui::_api_set_data_ref, this); 9 | namespace_imgui.set_function("set_data_ref_bool", &gsf::api_imgui::_api_set_data_ref, this); 10 | namespace_imgui.set_function("set_data_ref_float", &gsf::api_imgui::_api_set_data_ref, this); 11 | 12 | namespace_imgui.set_function("begin", &gsf::api_imgui::_api_begin, this); 13 | namespace_imgui.set_function("iend", &gsf::api_imgui::_api_iend, this); 14 | namespace_imgui.set_function("check_box", &gsf::api_imgui::_api_check_box, this); 15 | namespace_imgui.set_function("input_text", &gsf::api_imgui::_api_input_text, this); 16 | namespace_imgui.set_function("slider_float", &gsf::api_imgui::_api_slider_float, this); 17 | 18 | namespace_imgui.set_function("text", [](const char *text) { ImGui::Text(text); }); 19 | namespace_imgui.set_function("same_line", []() { ImGui::SameLine(); }); 20 | namespace_imgui.set_function("button", [](const char *text) -> bool { return ImGui::Button(text); }); 21 | namespace_imgui.set_function("separator", &ImGui::Separator); 22 | namespace_imgui.set_function("push_id", static_cast(&ImGui::PushID)); 23 | namespace_imgui.set_function("pop_id", &ImGui::PopID); 24 | 25 | namespace_imgui.set_function("draw_text", [](const char *text, float x, float y, float r, float g, float b, float a) 26 | { 27 | ImGui::GetBackgroundDrawList()->AddText(ImVec2(x, y), ImColor(r, g, b, a), text); 28 | }); 29 | 30 | namespace_imgui.set_function("draw_line", [](float x1, float y1, float x2, float y2, float thickness, float r, float g, float b, float a) 31 | { 32 | ImGui::GetBackgroundDrawList()->AddLine(ImVec2(x1, y1), ImVec2(x2, y2), ImColor(r, g, b, a), thickness); 33 | }); 34 | 35 | namespace_imgui.set_function("draw_rect", [](float x1, float y1, float x2, float y2, bool filled, float thickness, float r, float g, float b, float a) 36 | { 37 | if (filled) 38 | { 39 | ImGui::GetBackgroundDrawList()->AddRectFilled(ImVec2(x1, y1), ImVec2(x2, y2), ImColor(r, g, b, a)); 40 | } 41 | else 42 | { 43 | ImGui::GetBackgroundDrawList()->AddRect(ImVec2(x1, y1), ImVec2(x2, y2), ImColor(r, g, b, a), 0.f, 15, thickness); 44 | } 45 | }); 46 | 47 | return true; 48 | } 49 | 50 | bool gsf::api_imgui::_api_begin(const char *text) 51 | { 52 | ++api_imgui::imgui_active_begin_count; 53 | return ImGui::Begin(text, nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_NoCollapse); 54 | } 55 | 56 | void gsf::api_imgui::_api_iend() 57 | { 58 | --api_imgui::imgui_active_begin_count; 59 | return ImGui::End(); 60 | } 61 | 62 | bool gsf::api_imgui::_api_check_box(const char *label) 63 | { 64 | auto &container = *reinterpret_cast(&this->imgui_data_ref[label]); 65 | ImGui::Checkbox(label, &container); 66 | return container; 67 | } 68 | 69 | const char *gsf::api_imgui::_api_input_text(const char *label) 70 | { 71 | auto &container = this->imgui_data_ref[label]; 72 | ImGui::InputText(label, container, sizeof(container)); 73 | return container; 74 | } 75 | 76 | float gsf::api_imgui::_api_slider_float(const char *label, float min, float max) 77 | { 78 | auto &container = *reinterpret_cast(&this->imgui_data_ref[label]); 79 | ImGui::SliderFloat(label, &container, min, max, "%.1f"); 80 | return container; 81 | } 82 | -------------------------------------------------------------------------------- /gsf-client/api/api_imgui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | #include 5 | 6 | namespace gsf 7 | { 8 | class api_imgui : public i_api 9 | { 10 | protected: 11 | api_imgui() {} 12 | bool setup_api(sol::state &slua); 13 | 14 | public: 15 | inline static std::int64_t imgui_active_begin_count = 0; 16 | 17 | private: 18 | using data_ref_t = char[128]; 19 | std::unordered_map imgui_data_ref; 20 | 21 | private: 22 | 23 | template 24 | void _api_set_data_ref(const char *label, T value) 25 | { 26 | *reinterpret_cast(&this->imgui_data_ref[label]) = value; 27 | }; 28 | 29 | template <> 30 | void _api_set_data_ref(const char *label, const char *value) 31 | { 32 | strncpy_s(this->imgui_data_ref[label], value, sizeof(data_ref_t)); 33 | }; 34 | 35 | bool _api_begin(const char *text); 36 | void _api_iend(); 37 | bool _api_check_box(const char *label); 38 | const char *_api_input_text(const char *label); 39 | float _api_slider_float(const char *label, float min, float max); 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /gsf-client/api/api_mem.cpp: -------------------------------------------------------------------------------- 1 | #include "api_mem.h" 2 | #include 3 | #include 4 | #include "../log_manager.h" 5 | 6 | bool gsf::api_mem::setup_api(sol::state &slua) 7 | { 8 | auto namespace_mem = slua["mem"].get_or_create(); 9 | namespace_mem.set_function("ida_scan", &gsf::api_mem::_api_ida_scan, this); 10 | namespace_mem.set_function("patch", &gsf::api_mem::_api_patch, this); 11 | namespace_mem.set_function("read_uint", &gsf::api_mem::_api_read_uint, this); 12 | namespace_mem.set_function("write_uint", &gsf::api_mem::_api_write_uint, this); 13 | namespace_mem.set_function("calc_rel2abs32", &gsf::api_mem::_api_calc_rel2abs32, this); 14 | 15 | return true; 16 | } 17 | 18 | sol::object gsf::api_mem::_api_ida_scan(std::uintptr_t start_adr, std::size_t size, std::string ida_pattern) 19 | { 20 | auto result = utils::ida_scan(reinterpret_cast(start_adr), size, ida_pattern.c_str()); 21 | 22 | if (!result) 23 | return sol::nil; 24 | 25 | return sol::make_object(this->get_lua_state(), reinterpret_cast(result)); 26 | } 27 | 28 | int gsf::api_mem::_api_patch(std::uintptr_t addr, std::vector byte_array) 29 | { 30 | // TODO: lua enum this 31 | enum result_e 32 | { 33 | SUCCESSFUL = 0, 34 | ALREADY_PATCHED = 1, 35 | PROT_CHANGE_XRW_FAILED = 2, 36 | PROT_CHANGE_RESTORE_FAILED = 3 37 | }; 38 | 39 | // TODO: store in a global static list all the patched memory and check for collisions 40 | // TODO: use win api helper 41 | 42 | void *addr_void = reinterpret_cast(addr); 43 | std::size_t byte_arr_size = byte_array.size(); 44 | DWORD old_prot = 0; 45 | 46 | if (!VirtualProtect(addr_void, byte_arr_size, PAGE_EXECUTE_READWRITE, &old_prot)) 47 | return result_e::PROT_CHANGE_XRW_FAILED; 48 | 49 | std::memcpy(addr_void, byte_array.data(), byte_arr_size); 50 | 51 | if (!VirtualProtect(addr_void, byte_arr_size, old_prot, &old_prot)) 52 | return result_e::PROT_CHANGE_RESTORE_FAILED; 53 | 54 | return result_e::SUCCESSFUL; 55 | } 56 | 57 | std::uint64_t gsf::api_mem::_api_read_uint(std::uintptr_t addr, std::size_t prim_t_size) 58 | { 59 | std::memcpy(&prim_t_size, reinterpret_cast(addr), prim_t_size); // optimization! 60 | return prim_t_size; 61 | } 62 | 63 | void gsf::api_mem::_api_write_uint(std::uintptr_t addr, std::size_t prim_t_size, std::uint64_t value) 64 | { 65 | std::memcpy(reinterpret_cast(addr), &value, prim_t_size); 66 | } 67 | 68 | std::uintptr_t gsf::api_mem::_api_calc_rel2abs32(std::uintptr_t inst_addr, std::size_t inst_size) 69 | { 70 | return reinterpret_cast(utils::calc_rel2abs32(reinterpret_cast(inst_addr), inst_size)); 71 | } 72 | -------------------------------------------------------------------------------- /gsf-client/api/api_mem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | 5 | namespace gsf 6 | { 7 | class api_mem : public i_api 8 | { 9 | protected: 10 | api_mem() {} 11 | bool setup_api(sol::state &slua); 12 | 13 | private: 14 | sol::object _api_ida_scan(std::uintptr_t start_adr, std::size_t size, std::string ida_pattern); 15 | int _api_patch(std::uintptr_t addr, std::vector byte_array); 16 | std::uint64_t _api_read_uint(std::uintptr_t addr, std::size_t prim_t_size); 17 | void _api_write_uint(std::uintptr_t addr, std::size_t prim_t_size, std::uint64_t value); 18 | std::uintptr_t _api_calc_rel2abs32(std::uintptr_t inst_addr, std::size_t inst_size); 19 | }; 20 | } -------------------------------------------------------------------------------- /gsf-client/api/api_win.cpp: -------------------------------------------------------------------------------- 1 | #include "api_win.h" 2 | #include 3 | #include 4 | 5 | bool gsf::api_win::setup_api(sol::state &slua) 6 | { 7 | auto namespace_win = slua["win"].get_or_create(); 8 | namespace_win.set_function("find_module", &gsf::api_win::_api_find_module, this); 9 | namespace_win.set_function("get_all_modules", &gsf::api_win::_api_get_all_modules, this); 10 | namespace_win.set_function("sleep", ::Sleep); 11 | 12 | return true; 13 | } 14 | 15 | sol::object gsf::api_win::_api_find_module(std::wstring module_name) 16 | { 17 | auto ldr = utils::ldr_data_table_entry_find(module_name.c_str()); 18 | 19 | if (ldr) 20 | return this->get_lua_state().create_table_with("base_address", reinterpret_cast(ldr->dll_base), "size", ldr->size_of_image); 21 | 22 | return sol::nil; 23 | } 24 | 25 | sol::table gsf::api_win::_api_get_all_modules() 26 | { 27 | auto result = this->get_lua_state().create_table(); 28 | 29 | utils::ldr_data_table_entry *entry = nullptr; 30 | while (utils::ldr_data_table_entry_next(entry)) 31 | { 32 | if (entry->dll_base) 33 | result[entry->base_dll_name] = this->get_lua_state().create_table_with("base_address", reinterpret_cast(entry->dll_base), "size", entry->size_of_image); 34 | } 35 | 36 | return result; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /gsf-client/api/api_win.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "i_api.h" 4 | #include 5 | 6 | namespace gsf 7 | { 8 | class api_win : public i_api 9 | { 10 | protected: 11 | api_win() {} 12 | bool setup_api(sol::state &slua); 13 | 14 | private: 15 | sol::object _api_find_module(std::wstring module_name); 16 | sol::table _api_get_all_modules(); 17 | }; 18 | } -------------------------------------------------------------------------------- /gsf-client/api/i_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace gsf 7 | { 8 | class i_api 9 | { 10 | public: 11 | virtual sol::state &get_lua_state() = 0; 12 | virtual void script_push_log(std::string msg) = 0; 13 | virtual const std::string_view get_filepath() const = 0; 14 | }; 15 | } -------------------------------------------------------------------------------- /gsf-client/api/script_apis.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "api_game.h" 4 | #include "api_gsf.h" 5 | #include "api_imgui.h" 6 | #include "api_mem.h" 7 | #include "api_win.h" 8 | #include "api_controls.h" 9 | 10 | namespace gsf 11 | { 12 | template 13 | class _script_apis : public components... 14 | { 15 | protected: 16 | _script_apis() {} 17 | 18 | bool setup_all_apis(sol::state &slua) 19 | { 20 | return (components::setup_api(slua) && ...); 21 | } 22 | }; 23 | 24 | using script_apis = _script_apis< 25 | api_gsf, 26 | api_game, 27 | api_imgui, 28 | api_mem, 29 | api_win, 30 | api_controls 31 | >; 32 | } -------------------------------------------------------------------------------- /gsf-client/callback_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "callback_manager.h" 2 | 3 | static std::mutex mut_active_cb_count_update; 4 | static gsf::callback_manager::_api_callback_container api_callbacks; 5 | 6 | static gsf::callback_manager::api_callback *api_callbacks_end = reinterpret_cast(reinterpret_cast(&api_callbacks) + sizeof(api_callbacks)); 7 | 8 | const gsf::callback_manager::_api_callback_container &gsf::callback_manager::get_callbacks() 9 | { 10 | return api_callbacks; 11 | } 12 | 13 | bool gsf::callback_manager::register_luafn(utils::fnv1a64_t hashed_name, void *parent, sol::function fn) 14 | { 15 | 16 | for (auto *_iter = reinterpret_cast(&api_callbacks); _iter != api_callbacks_end; _iter++) 17 | { 18 | auto &cb_api = *_iter; 19 | 20 | if (cb_api.hashed_name != hashed_name) 21 | continue; 22 | 23 | // check if it was registered previously 24 | for (auto &lua_api : cb_api.lua_callbacks) 25 | { 26 | if (lua_api.parent != parent) 27 | continue; 28 | 29 | if (lua_api.active) 30 | return false; // fail cb register if already active 31 | 32 | // update lua callback and set it back to active 33 | lua_api.lua_func = fn; 34 | lua_api.active = true; 35 | ++cb_api.active_callbacks_count; 36 | return true; 37 | } 38 | 39 | // for newly registered callbacks 40 | cb_api.lua_callbacks.emplace_back(reinterpret_cast(parent), true, std::move(fn)); 41 | 42 | const std::lock_guard lg(mut_active_cb_count_update); 43 | ++cb_api.active_callbacks_count; 44 | 45 | return true; 46 | } 47 | 48 | return false; 49 | } 50 | 51 | void gsf::callback_manager::disable_api_callbacks_for_script(gsf::script *parent) 52 | { 53 | for (auto *_iter = reinterpret_cast(&api_callbacks); _iter != api_callbacks_end; _iter++) 54 | { 55 | auto &cb_api = *_iter; 56 | 57 | for (auto &lua_api : cb_api.lua_callbacks) 58 | { 59 | if (lua_api.parent != parent) 60 | continue; 61 | 62 | lua_api.lua_func = sol::nil; 63 | lua_api.active = false; 64 | 65 | const std::lock_guard lg(mut_active_cb_count_update); 66 | --cb_api.active_callbacks_count; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /gsf-client/callback_manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "script.h" 7 | #include 8 | 9 | // For performance and lazy reasons 10 | // it would be better to just keep the registered callbacks in the vector 11 | // and just check their parent scripts if they're still loaded and active 12 | // having to safely remove a registered callback in a vector would be too much 13 | // effort when we can just keep it there just incase the script gets loaded again later 14 | // not only will this eliminate the need of mutex locks and checks when clearing lua callbacks 15 | 16 | namespace gsf::callback_manager 17 | { 18 | struct api_callback 19 | { 20 | struct lua_callback 21 | { 22 | gsf::script *parent = nullptr; 23 | bool active = false; 24 | sol::function lua_func = sol::nil; 25 | 26 | bool valid() 27 | { 28 | return parent && parent->get_current_state() == gsf::script::state::LOADED && active; 29 | } 30 | }; 31 | 32 | api_callback(const utils::fnv1a64_t _hashed_name) 33 | : hashed_name(_hashed_name) {} 34 | 35 | const utils::fnv1a64_t hashed_name; 36 | std::vector lua_callbacks; 37 | int active_callbacks_count = 0; 38 | 39 | template 40 | void dispatch(vargs_t... args) const 41 | { 42 | if (!this->active_callbacks_count) 43 | return; 44 | 45 | int total_dispatched = 0; 46 | for (auto &cb : this->lua_callbacks) 47 | { 48 | if (!cb.active) 49 | continue; 50 | 51 | cb.lua_func(args...); 52 | 53 | if (++total_dispatched == this->active_callbacks_count) 54 | return; 55 | } 56 | } 57 | 58 | template 59 | void dispatch_filtered(gsf::script *parent, vargs_t... args) const 60 | { 61 | if (!this->active_callbacks_count) 62 | return; 63 | 64 | for (auto &cb : this->lua_callbacks) 65 | { 66 | if (cb.parent != parent || !cb.active) 67 | continue; 68 | 69 | cb.lua_func(args...); 70 | } 71 | } 72 | 73 | template 74 | bool dispatch_cancelable(vargs_t... args) const 75 | { 76 | if (!this->active_callbacks_count) 77 | return false; 78 | 79 | int total_dispatched = 0; 80 | for (auto &cb : this->lua_callbacks) 81 | { 82 | if (!cb.active) 83 | continue; 84 | 85 | if (sol::protected_function_result cb_res = cb.lua_func(args...); cb_res.valid()) 86 | { 87 | sol::optional res = cb_res; 88 | if (res && *res) 89 | return true; 90 | } 91 | 92 | if (++total_dispatched == this->active_callbacks_count) 93 | return false; 94 | } 95 | 96 | return false; 97 | } 98 | 99 | using delegate_t = bool(*)(const gsf::script &, const sol::function &); 100 | bool dispatch_delegate(delegate_t delegate) const 101 | { 102 | if (!this->active_callbacks_count) 103 | return false; 104 | 105 | int total_dispatched = 0; 106 | for (auto &cb : this->lua_callbacks) 107 | { 108 | if (!cb.active) 109 | continue; 110 | 111 | if (delegate(*cb.parent, cb.lua_func)) 112 | return true; 113 | 114 | if (++total_dispatched == this->active_callbacks_count) 115 | return false; 116 | } 117 | } 118 | 119 | template 120 | bool dispatch_returnable(return_t &out_return, vargs_t... args) const 121 | { 122 | if (!this->active_callbacks_count) 123 | return false; 124 | 125 | int total_dispatched = 0; 126 | for (auto &cb : this->lua_callbacks) 127 | { 128 | if (!cb.active) 129 | continue; 130 | 131 | if (sol::protected_function_result cb_res = cb.lua_func(args...); cb_res.valid()) 132 | { 133 | sol::optional res = cb_res; 134 | if (res) 135 | out_return = *res; 136 | return true; 137 | } 138 | 139 | if (++total_dispatched == this->active_callbacks_count) 140 | return false; 141 | } 142 | 143 | return false; 144 | } 145 | }; 146 | 147 | #define _GSF_DECLARE_API_CALLBACK(name) api_callback name = api_callback(utils::hash_fnv1a(#name)); 148 | struct _api_callback_container 149 | { 150 | _GSF_DECLARE_API_CALLBACK(on_imgui_draw) 151 | _GSF_DECLARE_API_CALLBACK(dx_draw) 152 | _GSF_DECLARE_API_CALLBACK(dx_drawindexed) 153 | _GSF_DECLARE_API_CALLBACK(on_unload) 154 | _GSF_DECLARE_API_CALLBACK(menu_imgui_tab) 155 | _GSF_DECLARE_API_CALLBACK(on_key) 156 | _GSF_DECLARE_API_CALLBACK(on_animator_speed) 157 | }; 158 | #undef _GSF_DECLARE_API_CALLBACK 159 | 160 | bool register_luafn(utils::fnv1a64_t hashed_name, void *parent, sol::function fn); 161 | void disable_api_callbacks_for_script(gsf::script *parent); 162 | const _api_callback_container &get_callbacks(); 163 | 164 | inline bool use_mut_on_imgui_draw = true; 165 | inline std::mutex mut_on_imgui_draw; 166 | } -------------------------------------------------------------------------------- /gsf-client/cpp.hint: -------------------------------------------------------------------------------- 1 | // Hint files help the Visual Studio IDE interpret Visual C++ identifiers 2 | // such as names of functions and macros. 3 | // For more information see https://go.microsoft.com/fwlink/?linkid=865984 4 | #define _GSF_SCRIPT_DECLARE_CALLBACK(name) script::callback name = script::callback(utils::hash_fnv1a(#name)) 5 | #define _GSF_SCRIPT_DECLARE_CALLBACK(name) api_gsf::callback name = api_gsf::callback(utils::hash_fnv1a(#name)); 6 | -------------------------------------------------------------------------------- /gsf-client/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "global.h" 3 | #include "gsf_client.h" 4 | 5 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 6 | { 7 | if (HANDLE entry_thread = nullptr; ul_reason_for_call == DLL_PROCESS_ATTACH && (entry_thread = CreateThread(nullptr, NULL, [](LPVOID hModule) -> DWORD 8 | { 9 | global::dll_handle = hModule; 10 | const HMODULE &hmod = reinterpret_cast(hModule); 11 | 12 | DisableThreadLibraryCalls(hmod); 13 | 14 | if (!gsf::init()) 15 | { 16 | FreeLibraryAndExitThread(hmod, 0); 17 | return 0; 18 | //TerminateProcess(GetCurrentProcess(), 0); // :) 19 | } 20 | 21 | return 0; 22 | }, hModule, NULL, nullptr))) { CloseHandle(entry_thread); } 23 | 24 | return TRUE; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /gsf-client/game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "sdk/sdk.h" 4 | 5 | namespace game 6 | { 7 | inline IDXGISwapChain **dx_swapchain_ptr = nullptr; 8 | inline ID3D11DeviceContext **dx_devicectx_ptr = nullptr; 9 | 10 | inline HWND *window_handle_ptr = nullptr; 11 | inline game::sdk::player_map_coords *player_map_coords = nullptr; 12 | 13 | inline game::sdk::il2cpp_string_chars_t il2cpp_string_chars = nullptr; 14 | inline game::sdk::il2cpp_string_length_t il2cpp_string_length = nullptr; 15 | inline game::sdk::il2cpp_string_new_t il2cpp_string_new = nullptr; 16 | 17 | bool init(); 18 | } -------------------------------------------------------------------------------- /gsf-client/global.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace global 6 | { 7 | inline void *dll_handle = nullptr; 8 | inline bool cursor_is_visible = true; // TODO: decide if its still necessary alongside the ShowCursor hook 9 | 10 | inline ID3D11Device *dx_device = nullptr; 11 | inline IDXGISwapChain *dx_swapchain = nullptr; 12 | inline ID3D11DeviceContext *dx_context = nullptr; 13 | inline ID3D11RenderTargetView *dx_render_target_view = nullptr; 14 | } -------------------------------------------------------------------------------- /gsf-client/gsf-client.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /gsf-client/gsf_client.cpp: -------------------------------------------------------------------------------- 1 | #include "gsf_client.h" 2 | #include "global.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "script_manager.h" 14 | #include "hooks.h" 15 | #include "game.h" 16 | 17 | #include 18 | 19 | #if __has_include("autoexecdef.h") && !defined( GSF_AUTOEXEC_SCRIPT_PATH ) 20 | #include "autoexecdef.h" 21 | #endif 22 | 23 | // TODO: better logging by logging to file 24 | 25 | static bool init_dx() 26 | { 27 | DEBUG_COUT("\n[+] Initialize DirectX11..." 28 | "\n[+] Waiting for the game to create a swapchain and device context..."); 29 | 30 | while (!(global::dx_swapchain = *game::dx_swapchain_ptr) && !*game::dx_devicectx_ptr) 31 | Sleep(800); 32 | 33 | if (!DEBUG_CON_C_LOG(L"Get device", SUCCEEDED(global::dx_swapchain->GetDevice(__uuidof(ID3D11Device), reinterpret_cast(&global::dx_device))))) 34 | return false; 35 | 36 | DEBUG_COUT(" @ 0x" << global::dx_device); 37 | 38 | global::dx_device->GetImmediateContext(&global::dx_context); 39 | DEBUG_CON_C_LOG(L"Get context", global::dx_context != nullptr); 40 | DEBUG_COUT(" @ 0x" << global::dx_context); 41 | 42 | ID3D11Texture2D *dx_backbuffer = nullptr; 43 | if (!DEBUG_CON_C_LOG(L"Get buffer", SUCCEEDED(global::dx_swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast(&dx_backbuffer))))) 44 | return false; 45 | DEBUG_COUT(" @ 0x" << dx_backbuffer); 46 | 47 | if (!DEBUG_CON_C_LOG(L"Create render target", dx_backbuffer && SUCCEEDED(global::dx_device->CreateRenderTargetView(dx_backbuffer, nullptr, &global::dx_render_target_view)))) 48 | return false; 49 | DEBUG_COUT(" @ 0x" << global::dx_render_target_view); 50 | 51 | dx_backbuffer->Release(); 52 | 53 | DXGI_SWAP_CHAIN_DESC scd; 54 | if (!DEBUG_CON_C_LOG(L"Get swapchain description", SUCCEEDED(global::dx_swapchain->GetDesc(&scd)))) 55 | return false; 56 | 57 | if (!DEBUG_CON_C_LOG(L"Initialize ImGui implementation", ImGui_ImplWin32_Init(scd.OutputWindow) && ImGui_ImplDX11_Init(global::dx_device, global::dx_context))) 58 | return false; 59 | 60 | return true; 61 | } 62 | 63 | bool gsf::init() 64 | { 65 | #ifdef _DEBUG 66 | { 67 | if (!con::init() || !SetConsoleTitleW(utils::random_str().c_str())) 68 | return false; 69 | } 70 | #endif 71 | 72 | #ifdef GSF_AUTOEXEC_SCRIPT_PATH 73 | { 74 | if (!gsf::script_manager::script_autoexec(GSF_AUTOEXEC_SCRIPT_PATH)) 75 | return false; 76 | } 77 | #endif 78 | 79 | if (CURSORINFO ci = { .cbSize = sizeof(ci) }; DEBUG_CON_C_LOG(L"Loading cursor info", GetCursorInfo(&ci))) 80 | global::cursor_is_visible = ci.flags == CURSOR_SHOWING; 81 | 82 | ImGui::CreateContext(); 83 | ImGui::GetIO().IniFilename = nullptr; 84 | 85 | if (!game::init() || !init_dx() || !gsf::hooks::install()) 86 | return false; 87 | 88 | return true; 89 | } 90 | 91 | bool gsf::shutdown() 92 | { 93 | if (HANDLE exit_thread = nullptr; exit_thread = CreateThread(nullptr, NULL, [](LPVOID arg0) -> DWORD 94 | { 95 | gsf::hooks::uninstall(); 96 | gsf::script_manager::unload_all_scripts(); 97 | 98 | if (con::is_allocated()) 99 | FreeConsole(); 100 | 101 | HWND con_wnd = con::get_window(); 102 | if (con_wnd) 103 | PostMessageW(con_wnd, WM_CLOSE, NULL, NULL); 104 | 105 | FreeLibraryAndExitThread(reinterpret_cast(global::dll_handle), 0); 106 | return 0; 107 | }, nullptr, NULL, nullptr)) { CloseHandle(exit_thread); } 108 | 109 | return true; 110 | } -------------------------------------------------------------------------------- /gsf-client/gsf_client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gsf 4 | { 5 | bool init(); 6 | bool shutdown(); 7 | } -------------------------------------------------------------------------------- /gsf-client/helpers/imgui_prompts.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui_prompts.h" 2 | 3 | helpers::imgui_popup_modal::imgui_popup_modal(std::string_view str_, callback_t callback_) 4 | : str(str_), callback(callback_) 5 | { 6 | helpers::imgui_popup_modal::instances.push_back(this); 7 | } 8 | 9 | void helpers::imgui_popup_modal::show() 10 | { 11 | this->prompt_requested = true; 12 | } 13 | 14 | void helpers::imgui_popup_modal::on_imgui_draw() 15 | { 16 | for (helpers::imgui_popup_modal *&instance : helpers::imgui_popup_modal::instances) 17 | { 18 | if (instance->prompt_requested) 19 | { 20 | ImGui::OpenPopup(instance->str.c_str()); 21 | instance->prompt_requested = false; 22 | } 23 | 24 | if (ImGui::BeginPopupModal(instance->str.c_str(), nullptr, ImGuiWindowFlags_::ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_::ImGuiWindowFlags_NoMove)) 25 | { 26 | instance->callback(); 27 | ImGui::EndPopup(); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /gsf-client/helpers/imgui_prompts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace helpers 8 | { 9 | class imgui_popup_modal 10 | { 11 | using callback_t = void(*)(void); 12 | public: 13 | imgui_popup_modal(std::string_view str_, callback_t callback_); 14 | 15 | void show(); 16 | 17 | private: 18 | bool prompt_requested = false; 19 | std::string str; 20 | callback_t callback; 21 | 22 | private: 23 | inline static std::vector instances; 24 | 25 | public: 26 | // Used to draw the popup modal instances, call on imgui draw 27 | // This is static and must be called as is, this implements all the registered instances of a popup modal 28 | static void on_imgui_draw(); 29 | }; 30 | } -------------------------------------------------------------------------------- /gsf-client/hooks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace gsf::hooks 6 | { 7 | inline void *WorldEntityIterator_get_speed_ptr = nullptr; 8 | 9 | bool install(); 10 | bool uninstall(); 11 | } -------------------------------------------------------------------------------- /gsf-client/log_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "log_manager.h" 2 | 3 | static std::deque logs; 4 | 5 | const std::deque &gsf::log_manager::get_logs() 6 | { 7 | return logs; 8 | } 9 | 10 | void gsf::log_manager::push_log(std::string txt, log_type_t type) 11 | { 12 | logs.emplace_back(std::move(txt), type); 13 | } 14 | 15 | void gsf::log_manager::clear_log() 16 | { 17 | logs.clear(); 18 | } 19 | -------------------------------------------------------------------------------- /gsf-client/log_manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace gsf::log_manager 7 | { 8 | using log_type_t = unsigned char; 9 | 10 | struct log_type 11 | { 12 | enum : unsigned char 13 | { 14 | GAME, 15 | SCRIPTS, 16 | LUA, 17 | GSF, 18 | UNSPEC, 19 | _SIZE 20 | }; 21 | }; 22 | 23 | struct log_cont 24 | { 25 | std::string txt; 26 | log_type_t type; 27 | }; 28 | 29 | const std::deque &get_logs(); 30 | void push_log(std::string txt, log_type_t type = log_type::UNSPEC); 31 | void clear_log(); 32 | } -------------------------------------------------------------------------------- /gsf-client/menu/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.h" 2 | #include "../game.h" 3 | #include "../git_info.h" 4 | #include "../gsf_client.h" 5 | #include "../script_manager.h" 6 | #include "../callback_manager.h" 7 | #include 8 | 9 | #include "tab_scripts.h" 10 | #include "tab_logs.h" 11 | #include "tab_about.h" 12 | #include "tab_misc.h" 13 | 14 | static bool internal_window_vis_state = gsf::menu::is_open; 15 | 16 | static void set_open_state(bool open) 17 | { 18 | static int last_visible; 19 | static game::sdk::CursorLockMode last_lock; 20 | 21 | internal_window_vis_state = gsf::menu::is_open = open; 22 | 23 | if (gsf::menu::is_open) 24 | { 25 | last_visible = game::sdk::Cursor::visible; 26 | last_lock = game::sdk::Cursor::lockState; 27 | } 28 | 29 | game::sdk::Cursor::visible = gsf::menu::is_open ? true : last_visible; 30 | game::sdk::Cursor::lockState = gsf::menu::is_open ? game::sdk::CursorLockMode::None : last_lock; 31 | } 32 | 33 | bool gsf::menu::windowproc(UINT msg, WPARAM wParam, LPARAM lParam) 34 | { 35 | if (msg == WM_KEYDOWN && wParam == VK_INSERT) 36 | set_open_state(!gsf::menu::is_open); 37 | 38 | return gsf::menu::is_open; 39 | } 40 | 41 | void gsf::menu::render_imgui() 42 | { 43 | gsf::menu::tab_misc::render_window(); 44 | gsf::menu::tab_logs::render_window(); 45 | 46 | if (!gsf::menu::is_open) 47 | return; 48 | 49 | if (!internal_window_vis_state) 50 | { 51 | set_open_state(false); 52 | return; 53 | } 54 | 55 | static const auto _set_wh = []() 56 | { 57 | const auto display_wh = ImGui::GetIO().DisplaySize; 58 | ImGui::SetNextWindowSize({ display_wh.x * 0.8f, display_wh.y * 0.6f }, ImGuiCond_::ImGuiCond_FirstUseEver); 59 | return true; 60 | }(); 61 | 62 | if (ImGui::Begin("Genshin Impact Scripting Framework | " GIT_BRANCH " @ " GIT_HASH, &internal_window_vis_state, ImGuiWindowFlags_::ImGuiWindowFlags_MenuBar)) 63 | { 64 | // Menu bar 65 | if (ImGui::BeginMenuBar()) 66 | { 67 | if (ImGui::MenuItem("Shutdown (DEL)")) 68 | gsf::shutdown(); 69 | 70 | ImGui::EndMenuBar(); 71 | } 72 | 73 | // Tabs 74 | if (ImGui::BeginTabBar("##gsf_tabs")) 75 | { 76 | tab_scripts::render_tab(); 77 | tab_misc::render_tab(); 78 | tab_logs::render_tab(); 79 | 80 | // Render custom script tabs 81 | for (const auto &cbs : gsf::callback_manager::get_callbacks().menu_imgui_tab.lua_callbacks) 82 | { 83 | if (!cbs.active) 84 | continue; 85 | 86 | if (ImGui::BeginTabItem(cbs.parent->get_config().name.c_str())) 87 | { 88 | cbs.lua_func(); 89 | ImGui::EndTabItem(); 90 | } 91 | } 92 | 93 | tab_about::render_tab(); 94 | ImGui::EndTabBar(); 95 | } 96 | } 97 | ImGui::End(); 98 | } -------------------------------------------------------------------------------- /gsf-client/menu/menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace gsf::menu 6 | { 7 | inline bool is_open = false; 8 | 9 | bool windowproc(UINT msg, WPARAM wParam, LPARAM lParam); 10 | void render_imgui(); 11 | } -------------------------------------------------------------------------------- /gsf-client/menu/tab_about.cpp: -------------------------------------------------------------------------------- 1 | #include "tab_about.h" 2 | 3 | #include 4 | #include "../git_info.h" 5 | 6 | void gsf::menu::tab_about::render_tab() 7 | { 8 | if (ImGui::BeginTabItem("About")) 9 | { 10 | ImGui::Text( 11 | "Scripting API and Framework for Genshin Impact\n" 12 | "\n" 13 | 14 | "Build type: " 15 | #if defined(_DEBUG) && !defined(NDEBUG) 16 | "Debug" 17 | #elif defined(NDEBUG) && !defined(_DEBUG) 18 | "Release" 19 | #else 20 | "Unknown" 21 | #endif 22 | "\n" 23 | 24 | "Build Date: " __DATE__ " " __TIME__ "\n" 25 | "Git info: " GIT_HASH " @ " GIT_BRANCH "\n" 26 | "\n" 27 | "https://github.com/u16rogue/genshin-scripting-framework\n" 28 | "\n" 29 | "This software is licensed under the GNU General Public License 3.0\n" 30 | ); 31 | ImGui::EndTabItem(); 32 | } 33 | } -------------------------------------------------------------------------------- /gsf-client/menu/tab_about.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gsf::menu::tab_about 4 | { 5 | void render_tab(); 6 | } -------------------------------------------------------------------------------- /gsf-client/menu/tab_logs.cpp: -------------------------------------------------------------------------------- 1 | #include "tab_logs.h" 2 | #include 3 | #include "../log_manager.h" 4 | #include "menu.h" 5 | 6 | static bool logs_floating = false; 7 | static int logs_display_count = 0; 8 | 9 | static ImVec4 log_type_colors[gsf::log_manager::log_type::_SIZE] = 10 | { 11 | { 101.f / 255.f, 251.f / 255.f, 136.f / 255.f, 1.f }, 12 | { 239.f / 255.f, 136.f / 255.f, 251.f / 255.f, 1.f }, 13 | { 136.f / 255.f, 212.f / 255.f, 251.f / 255.f, 1.f }, 14 | { 247.f / 255.f, 251.f / 255.f, 136.f / 255.f, 1.f }, 15 | { 1.f, 1.f, 1.f, 1.f } 16 | }; 17 | 18 | static void render_logs_contents() 19 | { 20 | const auto &logs = gsf::log_manager::get_logs(); 21 | ImGui::BeginChild("##logs_list", ImVec2(0, 0), true); 22 | auto log_size = logs.size() - 1; 23 | for (auto i = log_size; i != -1 && (logs_display_count <= 0 || (log_size - i) < logs_display_count); --i) 24 | { 25 | ImGui::PushStyleColor(ImGuiCol_Text, log_type_colors[logs[i].type]); 26 | ImGui::TextWrapped(logs[i].txt.c_str()); 27 | ImGui::PopStyleColor(); 28 | } 29 | ImGui::EndChild(); 30 | } 31 | 32 | void gsf::menu::tab_logs::render_tab() 33 | { 34 | if (ImGui::BeginTabItem("Logs")) 35 | { 36 | ImGui::Text("Log colors:"); 37 | ImGui::SameLine(); 38 | ImGui::ColorEdit4("Game", reinterpret_cast(&log_type_colors[gsf::log_manager::log_type::GAME]), ImGuiColorEditFlags_::ImGuiColorEditFlags_NoInputs); 39 | ImGui::SameLine(); 40 | ImGui::ColorEdit4("Scripts", reinterpret_cast(&log_type_colors[gsf::log_manager::log_type::SCRIPTS]), ImGuiColorEditFlags_::ImGuiColorEditFlags_NoInputs); 41 | ImGui::SameLine(); 42 | ImGui::ColorEdit4("Lua", reinterpret_cast(&log_type_colors[gsf::log_manager::log_type::LUA]), ImGuiColorEditFlags_::ImGuiColorEditFlags_NoInputs); 43 | ImGui::SameLine(); 44 | ImGui::ColorEdit4("GSF", reinterpret_cast(&log_type_colors[gsf::log_manager::log_type::GSF]), ImGuiColorEditFlags_::ImGuiColorEditFlags_NoInputs); 45 | ImGui::SameLine(); 46 | ImGui::ColorEdit4("Unspecified", reinterpret_cast(&log_type_colors[gsf::log_manager::log_type::UNSPEC]), ImGuiColorEditFlags_::ImGuiColorEditFlags_NoInputs); 47 | ImGui::SameLine(); 48 | if (ImGui::Button(logs_floating ? "Dock Tab" : "Float Window")) logs_floating = !logs_floating; 49 | ImGui::SameLine(); 50 | if (ImGui::Button("Clear logs")) gsf::log_manager::clear_log(); 51 | ImGui::SameLine(); 52 | ImGui::Text("Display count"); 53 | ImGui::SameLine(); 54 | ImGui::InputInt("##disc", &logs_display_count); 55 | 56 | if (!logs_floating) 57 | render_logs_contents(); 58 | 59 | ImGui::EndTabItem(); 60 | } 61 | } 62 | 63 | void gsf::menu::tab_logs::render_window() 64 | { 65 | if (!logs_floating) 66 | return; 67 | 68 | ImGui::SetNextWindowSize({ 300, 200 }, ImGuiCond_::ImGuiCond_FirstUseEver); 69 | if (ImGui::Begin("Logs", &logs_floating, gsf::menu::is_open ? 0 : (ImGuiWindowFlags_::ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_::ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_::ImGuiWindowFlags_NoInputs))) 70 | { 71 | render_logs_contents(); 72 | } 73 | ImGui::End(); 74 | } 75 | -------------------------------------------------------------------------------- /gsf-client/menu/tab_logs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gsf::menu::tab_logs 4 | { 5 | void render_tab(); 6 | void render_window(); 7 | } -------------------------------------------------------------------------------- /gsf-client/menu/tab_misc.cpp: -------------------------------------------------------------------------------- 1 | #include "tab_misc.h" 2 | #include 3 | #include 4 | #include "../menu/menu.h" 5 | #include "../callback_manager.h" 6 | 7 | static bool toggle_fps_counter = true; 8 | 9 | void gsf::menu::tab_misc::render_tab() 10 | { 11 | if (ImGui::BeginTabItem("Misc")) 12 | { 13 | ImGui::Checkbox("Lock on_imgui_draw callback thread with mutex", &gsf::callback_manager::use_mut_on_imgui_draw); 14 | if (ImGui::IsItemHovered()) 15 | ImGui::SetTooltip("Disabling this might make things faster but might cause instability."); 16 | 17 | ImGui::Text("Information window: "); 18 | ImGui::Checkbox("Display FPS", &toggle_fps_counter); 19 | 20 | ImGui::EndTabItem(); 21 | } 22 | } 23 | 24 | void gsf::menu::tab_misc::render_window() 25 | { 26 | if (!toggle_fps_counter) 27 | return; 28 | 29 | ImGuiWindowFlags w_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoBringToFrontOnFocus; 30 | if (!gsf::menu::is_open) 31 | w_flags |= ImGuiWindowFlags_NoInputs; 32 | 33 | ImGui::SetNextWindowPos({ 4.f, 4.f }, ImGuiCond_Once); 34 | if (ImGui::Begin("##info_window", nullptr, w_flags)) 35 | { 36 | if (static auto &imgui_io = ImGui::GetIO(); toggle_fps_counter) 37 | ImGui::Text("FPS: %.1f", imgui_io.Framerate); 38 | } 39 | ImGui::End(); 40 | } 41 | -------------------------------------------------------------------------------- /gsf-client/menu/tab_misc.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gsf::menu::tab_misc 4 | { 5 | void render_tab(); 6 | void render_window(); 7 | } -------------------------------------------------------------------------------- /gsf-client/menu/tab_scripts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace gsf::menu::tab_scripts 4 | { 5 | void render_tab(); 6 | } -------------------------------------------------------------------------------- /gsf-client/script.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "api/script_apis.h" 9 | 10 | namespace gsf 11 | { 12 | struct script_config 13 | { 14 | std::string name; 15 | std::string description; 16 | }; 17 | 18 | class script : public script_apis 19 | { 20 | public: 21 | 22 | enum class state 23 | { 24 | UNLOADING, 25 | UNLOADED, 26 | LOADING, 27 | LOADED, 28 | }; 29 | 30 | public: 31 | inline static std::size_t count_loaded_scripts = 0; 32 | 33 | public: 34 | script(std::string_view filepath_); 35 | 36 | bool load(); 37 | bool unload(); 38 | 39 | bool script_file_exists(); 40 | operator bool() const; 41 | void load_mconfig(); 42 | 43 | const std::string_view get_filename() const; 44 | const gsf::script::state get_current_state() const; 45 | const gsf::script_config &get_config() const; 46 | 47 | const std::string_view get_filepath() const override; 48 | sol::state &get_lua_state() override; 49 | void script_push_log(std::string msg) override; 50 | 51 | static const char *state_to_cstr(script::state state_); 52 | 53 | public: 54 | mutable bool _tab_script_selected = false; 55 | mutable std::string _tab_script_notice = "None"; 56 | 57 | private: 58 | gsf::script_config config; 59 | const std::string filepath; 60 | std::string filename; 61 | std::unique_ptr lua_state = nullptr; 62 | script::state current_state = script::state::UNLOADED; 63 | }; 64 | } -------------------------------------------------------------------------------- /gsf-client/script_manager.cpp: -------------------------------------------------------------------------------- 1 | #include "script_manager.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static std::vector script_instances; 10 | 11 | const std::vector &gsf::script_manager::get_scripts() 12 | { 13 | return script_instances; 14 | } 15 | 16 | bool gsf::script_manager::script_autoexec(std::string_view file_path) 17 | { 18 | if (!std::filesystem::exists(file_path)) 19 | return false; 20 | 21 | sol::state autoexec_script; 22 | 23 | auto namespace_gsf = autoexec_script["gsf"].get_or_create(); 24 | namespace_gsf.set_function("import", [](const char *file_path) -> bool 25 | { 26 | return gsf::script_manager::script_import(file_path); 27 | }); 28 | 29 | namespace_gsf.set_function("load", [](const char *file_path) -> bool 30 | { 31 | if (gsf::script *script = nullptr; gsf::script_manager::script_import(file_path, &script)) 32 | return script->load(); 33 | 34 | return false; 35 | }); 36 | 37 | autoexec_script.script_file(file_path.data()); 38 | 39 | return true; 40 | } 41 | 42 | bool gsf::script_manager::script_import(std::string_view file_path, gsf::script **script_instance_out) 43 | { 44 | if (!std::filesystem::exists(file_path)) 45 | return false; 46 | 47 | for (auto &script : script_instances) 48 | if (script.get_filepath() == file_path) 49 | return false; 50 | 51 | auto &loaded_script = script_instances.emplace_back(file_path); 52 | if (script_instance_out) 53 | *script_instance_out = &loaded_script; 54 | 55 | return true; 56 | } 57 | 58 | void gsf::script_manager::unload_all_scripts() 59 | { 60 | for (auto &script : script_instances) 61 | script.unload(); 62 | } 63 | -------------------------------------------------------------------------------- /gsf-client/script_manager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "script.h" 6 | 7 | namespace gsf::script_manager 8 | { 9 | const std::vector &get_scripts(); 10 | bool script_autoexec(std::string_view file_path); 11 | bool script_import(std::string_view file_path, gsf::script **script_instance_out = nullptr); 12 | 13 | void unload_all_scripts(); 14 | } -------------------------------------------------------------------------------- /gsf-client/sdk/il2cpp/il2cpp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #pragma warning(disable: 4200) 5 | 6 | namespace game::sdk 7 | { 8 | constexpr auto IL2CPP_ZERO_LEN_ARRAY = 0; 9 | 10 | using Il2CppObject = void *; 11 | using Il2CppChar = wchar_t; 12 | 13 | // TODO: use proper type 14 | using Il2CppClass = void; 15 | using Il2CppArray = void; 16 | 17 | struct Il2CppString 18 | { 19 | Il2CppObject object; 20 | std::int32_t length; 21 | Il2CppChar chars[IL2CPP_ZERO_LEN_ARRAY]; 22 | }; 23 | 24 | using il2cpp_string_length_t = std::int32_t (*)(Il2CppString *); 25 | using il2cpp_string_chars_t = Il2CppChar *(*)(Il2CppString *); 26 | using il2cpp_string_new_t = Il2CppString *(*)(const char *); 27 | 28 | using il2cpp_array_element_size_t = int(*)(const Il2CppClass *); 29 | using il2cpp_array_length_t = std::uint32_t(*)(Il2CppArray *); 30 | } 31 | 32 | #pragma warning(default: 4200) -------------------------------------------------------------------------------- /gsf-client/sdk/sdk.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity/unity.h" 4 | #include "structures.h" 5 | #include "il2cpp/il2cpp.h" -------------------------------------------------------------------------------- /gsf-client/sdk/structures.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace game::sdk 4 | { 5 | struct player_map_coords 6 | { 7 | float x; 8 | float z; 9 | }; 10 | } -------------------------------------------------------------------------------- /gsf-client/sdk/unity/enums.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace game::sdk 4 | { 5 | enum class CursorLockMode : int 6 | { 7 | None, 8 | Locked, 9 | Confined 10 | }; 11 | 12 | enum class HumanBodyBones : int 13 | { 14 | Hips, 15 | LeftUpperLeg, 16 | RightUpperLeg, 17 | LeftLowerLeg, 18 | RightLowerLeg, 19 | LeftFoot, 20 | RightFoot, 21 | Spine, 22 | Chest, 23 | UpperChest, 24 | Neck, 25 | Head, 26 | LeftShoulder, 27 | RightShoulder, 28 | LeftUpperArm, 29 | RightUpperArm, 30 | LeftLowerArm, 31 | RightLowerArm, 32 | LeftHand, 33 | RightHand, 34 | LeftToes, 35 | RightToes, 36 | LeftEye, 37 | RightEye, 38 | Jaw, 39 | LeftThumbProximal, 40 | LeftThumbIntermediate, 41 | LeftThumbDistal, 42 | LeftIndexProximal, 43 | LeftIndexIntermediate, 44 | LeftIndexDistal, 45 | LeftMiddleProximal, 46 | LeftMiddleIntermediate, 47 | LeftMiddleDistal, 48 | LeftRingProximal, 49 | LeftRingIntermediate, 50 | LeftRingDistal, 51 | LeftLittleProximal, 52 | LeftLittleIntermediate, 53 | LeftLittleDistal, 54 | RightThumbProximal, 55 | RightThumbIntermediate, 56 | RightThumbDistal, 57 | RightIndexProximal, 58 | RightIndexIntermediate, 59 | RightIndexDistal, 60 | RightMiddleProximal, 61 | RightMiddleIntermediate, 62 | RightMiddleDistal, 63 | RightRingProximal, 64 | RightRingIntermediate, 65 | RightRingDistal, 66 | RightLittleProximal, 67 | RightLittleIntermediate, 68 | RightLittleDistal, 69 | LastBone 70 | }; 71 | } -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "enums.h" 4 | 5 | #include "unity_object.h" 6 | #include "unity_component.h" 7 | #include "unity_transform.h" 8 | #include "unity_vector3.h" 9 | #include "unity_camera.h" 10 | #include "unity_animator.h" 11 | #include "unity_cursor.h" 12 | #include "unity_jsonutility.h" 13 | #include "unity_input.h" 14 | 15 | #include "unity_primitive_types.h" 16 | #include "unity_scripting_api.h" 17 | 18 | #include "../il2cpp/il2cpp.h" 19 | #include 20 | #include 21 | #include -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_animator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_component.h" 4 | #include "unity_primitive_types.h" 5 | 6 | namespace game::sdk 7 | { 8 | union Animator_class_unk0 9 | { 10 | struct 11 | { 12 | char _pad0[0x0F0]; 13 | float *unk0; // speed value to use by the engine 14 | }; 15 | }; 16 | 17 | class Animator; 18 | union AnimatorStateInfo_MAYBE 19 | { 20 | struct 21 | { 22 | char _pad0[0x28]; 23 | Animator *parent; 24 | }; 25 | 26 | struct 27 | { 28 | char _pad1[0x314]; 29 | float speed; 30 | }; 31 | 32 | struct 33 | { 34 | char _pad2[0x0EC]; 35 | game::sdk::Boolean unk0; // unknown boolean, this is checked before doing speed value assignment 36 | }; 37 | 38 | struct 39 | { 40 | char _pad3[0x4A0]; 41 | Animator_class_unk0 *unk1; 42 | }; 43 | 44 | }; 45 | 46 | 47 | // NOTE: this is probably the boxed AnimatorStateInfo__Boxed that is being passed into animator get speed and the actual animator is Animator_Unkown0 48 | class Animator : public game::sdk::Component 49 | { 50 | private: 51 | char pad0[0x10]; 52 | public: 53 | AnimatorStateInfo_MAYBE *state_info; 54 | 55 | public: 56 | float get_speed() 57 | { 58 | return this->_get_speed(this); 59 | } 60 | 61 | public: 62 | inline static game::sdk::unity_scripting_api _get_speed = ("UnityEngine.Animator::get_speed()"); 63 | }; 64 | } 65 | 66 | static_assert(offsetof(game::sdk::Animator, state_info) == 0x10, "Offset mismatch for Animator::state_info!"); 67 | static_assert(offsetof(game::sdk::AnimatorStateInfo_MAYBE, speed) == 0x314, "Offset mismatch for AnimatorStateInfo_MAYBE::speed"); 68 | static_assert(offsetof(game::sdk::AnimatorStateInfo_MAYBE, parent) == 0x28, "Offset mismatch for AnimatorStateInfo_MAYBE::parent"); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_component.h" 4 | 5 | namespace game::sdk 6 | { 7 | class Camera : public game::sdk::Component 8 | { 9 | public: 10 | inline static auto get_main = game::sdk::unity_setter_getter_static("UnityEngine.Camera::get_main()", nullptr); 11 | }; 12 | } 13 | 14 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Camera); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_component.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_object.h" 4 | #include "unity_transform.h" 5 | 6 | namespace game::sdk 7 | { 8 | class Component : public game::sdk::Object 9 | { 10 | public: 11 | game::sdk::Transform *get_transform() 12 | { 13 | return this->_get_transform(this); 14 | } 15 | 16 | public: 17 | inline static game::sdk::unity_scripting_api _get_transform = ("UnityEngine.Component::get_transform()"); 18 | }; 19 | } 20 | 21 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Component); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_cursor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_scripting_api.h" 4 | #include "unity_primitive_types.h" 5 | 6 | namespace game::sdk 7 | { 8 | class Cursor 9 | { 10 | public: 11 | inline static auto visible = game::sdk::unity_setter_getter_static("UnityEngine.Cursor::get_visible()", "UnityEngine.Cursor::set_visible(System.Boolean)"); 12 | inline static auto lockState = game::sdk::unity_setter_getter_static("UnityEngine.Cursor::get_lockState()", "UnityEngine.Cursor::set_lockState(UnityEngine.CursorLockMode)"); 13 | }; 14 | } 15 | 16 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Cursor); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_scripting_api.h" 4 | #include "unity_primitive_types.h" 5 | 6 | namespace game::sdk 7 | { 8 | class Input 9 | { 10 | public: 11 | inline static game::sdk::unity_scripting_api GetButton = ("UnityEngine.Input::GetButton(System.String)"); 12 | inline static game::sdk::unity_scripting_api GetAxisRaw = ("UnityEngine.Input::GetAxisRaw(System.String)"); 13 | }; 14 | } 15 | 16 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Input); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_jsonutility.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_scripting_api.h" 4 | #include "unity_object.h" 5 | #include "unity_primitive_types.h" 6 | 7 | namespace game::sdk 8 | { 9 | class JsonUtility 10 | { 11 | public: 12 | inline static game::sdk::unity_scripting_api ToJson = ("UnityEngine.JsonUtility::ToJson(System.Object,System.Boolean)"); 13 | inline static game::sdk::unity_scripting_api FromJson = ("UnityEngine.JsonUtility::FromJson(System.String,System.Type)"); 14 | inline static game::sdk::unity_scripting_api FromJsonOverwrite = ("UnityEngine.JsonUtility::FromJsonOverwrite(System.String,System.Object)"); 15 | }; 16 | } 17 | 18 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::JsonUtility); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_object.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_scripting_api.h" 4 | 5 | namespace game::sdk 6 | { 7 | class Object 8 | { 9 | public: 10 | game::sdk::Il2CppString *get_name() 11 | { 12 | return this->_get_name(this); 13 | } 14 | 15 | game::sdk::Il2CppString *ToString() 16 | { 17 | return this->_ToString(this); 18 | } 19 | 20 | public: 21 | inline static game::sdk::unity_scripting_api _get_name = ("UnityEngine.Object::get_name()"); 22 | inline static game::sdk::unity_scripting_api _ToString = ("UnityEngine.Object::ToString()"); 23 | }; 24 | } 25 | 26 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Object); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_primitive_types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace game::sdk 4 | { 5 | using Boolean = int; 6 | using Type = void; 7 | } -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_scripting_api.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../il2cpp/il2cpp.h" 6 | 7 | namespace game::sdk 8 | { 9 | class _unity_scripting_api 10 | { 11 | using get_unity_api_t = void *(*)(const char *); 12 | 13 | public: 14 | _unity_scripting_api(const char *name_) 15 | : name(name_) 16 | { 17 | if (!name_) 18 | return; 19 | 20 | this->_instances.emplace_back(this); 21 | } 22 | 23 | bool load_function() 24 | { 25 | bool result = DEBUG_CON_C_LOG(this->name, (this->function = this->get_unity_api(this->name))); 26 | 27 | #ifdef _DEBUG 28 | { 29 | if (result) 30 | { 31 | DEBUG_COUT(" @ 0x" << this->function); 32 | } 33 | } 34 | #endif 35 | 36 | return result; 37 | } 38 | 39 | inline static bool load_function_all() 40 | { 41 | bool is_success = true; 42 | for (const auto &api : _unity_scripting_api::_instances) 43 | { 44 | if (!api->load_function()) 45 | { 46 | is_success = false; 47 | break; 48 | } 49 | } 50 | 51 | _unity_scripting_api::_instances.clear(); 52 | return is_success; 53 | } 54 | 55 | protected: 56 | void *function = nullptr; 57 | const char *name; 58 | 59 | public: 60 | inline static get_unity_api_t get_unity_api = nullptr; // TODO: reverse this and then implement hashable version 61 | 62 | private: 63 | inline static std::vector<_unity_scripting_api *> _instances; 64 | }; 65 | 66 | template 67 | class unity_scripting_api : public _unity_scripting_api 68 | { 69 | public: 70 | 71 | using type = fn_ret_t(*)(fn_args_t...); 72 | 73 | unity_scripting_api(const char *name_) 74 | : _unity_scripting_api(name_) 75 | {}; 76 | 77 | fn_ret_t operator()(fn_args_t... args) 78 | { 79 | return reinterpret_cast(this->function)(args...); 80 | } 81 | 82 | void *api_ptr() const 83 | { 84 | return this->function; 85 | } 86 | }; 87 | 88 | #if 0 89 | template 90 | class unity_setter_getter_bridge 91 | { 92 | public: 93 | unity_setter_getter_bridge() 94 | : {} 95 | }; 96 | #endif 97 | 98 | template 99 | class unity_setter_getter_static 100 | { 101 | unity_setter_getter_static(unity_setter_getter_static &) = delete; 102 | unity_setter_getter_static(const unity_setter_getter_static &) = delete; 103 | unity_setter_getter_static(unity_setter_getter_static &&) = delete; 104 | public: 105 | 106 | unity_setter_getter_static(const char *getter_api_name, const char *setter_api_name) 107 | : getter(getter_api_name), setter(setter_api_name) {} 108 | 109 | void operator=(unity_type rhs) noexcept 110 | { 111 | this->setter(rhs); 112 | } 113 | 114 | operator unity_type() noexcept 115 | { 116 | return this->getter(); 117 | } 118 | 119 | unity_type operator->() noexcept 120 | { 121 | return this->getter(); 122 | } 123 | 124 | public: 125 | unity_scripting_api getter; 126 | unity_scripting_api setter; 127 | }; 128 | } 129 | 130 | #define GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(class_interface) static_assert(sizeof(class_interface) <= 1, "[ " #class_interface " ] WARNING: Unity class interface in GSF's unity sdk might have member values! Classes made for interfacing with unity must be pure static and must not contain non static member variables!") -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_transform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unity_object.h" 4 | #include "unity_vector3.h" 5 | 6 | namespace game::sdk 7 | { 8 | class Transform : public game::sdk::Object 9 | { 10 | public: 11 | void get_position(game::sdk::Vector3 &position_out) 12 | { 13 | this->_INTERNAL_get_position(this, &position_out); 14 | } 15 | 16 | game::sdk::Vector3 get_position() 17 | { 18 | Vector3 out; 19 | this->_INTERNAL_get_position(this, &out); 20 | return out; 21 | } 22 | 23 | public: 24 | inline static game::sdk::unity_scripting_api _INTERNAL_get_position = ("UnityEngine.Transform::INTERNAL_get_position(UnityEngine.Vector3&)"); 25 | }; 26 | } 27 | 28 | GSF_UNITY_SDK_ENSURE_NO_NONSTATIC(game::sdk::Transform); -------------------------------------------------------------------------------- /gsf-client/sdk/unity/unity_vector3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace game::sdk 4 | { 5 | struct Vector3 6 | { 7 | float x, y, z; 8 | }; 9 | } -------------------------------------------------------------------------------- /gsf-launcher/gsf-launcher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // ------------------------------------------------------------------------ 7 | 8 | #define GAME_DIRECTORY \ 9 | L"C:\\Program Files\\Genshin Impact\\Genshin Impact game" 10 | 11 | #define GAME_PATH \ 12 | GAME_DIRECTORY L"\\GenshinImpact.exe" 13 | 14 | #define MSG_TITLE \ 15 | L"gsf-launcher" 16 | 17 | #define GAME_WND_CLASS \ 18 | L"UnityWndClass" 19 | 20 | #define GAME_WND_TITLE \ 21 | L"Genshin Impact" 22 | 23 | // ------------------------------------------------------------------------ 24 | 25 | void msgprompt(const wchar_t *msg) 26 | { 27 | MessageBoxW(nullptr, msg, MSG_TITLE, MB_OK); 28 | } 29 | 30 | bool launch_game(HANDLE &handle_out) 31 | { 32 | if (std::filesystem::exists(GAME_PATH)) 33 | { 34 | STARTUPINFO si{ sizeof(si) }; 35 | PROCESS_INFORMATION pi{ NULL }; 36 | 37 | if (CreateProcessW(GAME_PATH, nullptr, nullptr, nullptr, FALSE, NULL, nullptr, GAME_DIRECTORY, &si, &pi)) 38 | { 39 | CloseHandle(pi.hThread); 40 | handle_out = pi.hProcess; 41 | return true; 42 | } 43 | else 44 | { 45 | msgprompt(L"Failed to start game"); 46 | return false; 47 | } 48 | } 49 | else 50 | { 51 | msgprompt(L"The game was not found on its default path of " GAME_PATH L"! Please check the default path used by the launcher and modify it based off your needs. For further information check the README of the repo."); 52 | return false; 53 | } 54 | } 55 | 56 | bool attach_to_game(HANDLE &handle_out) 57 | { 58 | HWND game_wnd = FindWindowW(GAME_WND_CLASS, GAME_WND_TITLE); 59 | if (!game_wnd) 60 | return false; 61 | 62 | DWORD game_pid = 0; 63 | GetWindowThreadProcessId(game_wnd, &game_pid); 64 | 65 | if (game_pid == 0) 66 | return false; 67 | 68 | handle_out = OpenProcess(PROCESS_ALL_ACCESS, FALSE, game_pid); 69 | return handle_out != nullptr; 70 | } 71 | 72 | int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ PWSTR pCmdLine, _In_ int nCmdShow) 73 | { 74 | HANDLE game_handle = nullptr; 75 | 76 | attach_to_game(game_handle); 77 | 78 | if (!game_handle && !launch_game(game_handle)) 79 | return 1; 80 | 81 | if (!utils::remote_loadlibrary(game_handle, utils::get_full_path(L"gsf-client.dll"))) 82 | { 83 | msgprompt(L"Failed to load gsf-client to Genshin Impact!"); 84 | return 1; 85 | } 86 | 87 | CloseHandle(game_handle); 88 | 89 | return 0; 90 | } -------------------------------------------------------------------------------- /gsf-launcher/gsf-launcher.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | x64 7 | 8 | 9 | Release 10 | x64 11 | 12 | 13 | 14 | 16.0 15 | Win32Proj 16 | {a3415378-0073-4e01-982e-a7b99c249819} 17 | gsflauncher 18 | 10.0 19 | 20 | 21 | 22 | Application 23 | true 24 | v142 25 | Unicode 26 | 27 | 28 | Application 29 | false 30 | v142 31 | true 32 | Unicode 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | true 50 | $(SolutionDir)build\$(Configuration)_$(PlatformShortName)\ 51 | $(SolutionDir)build\obj\$(ProjectName)\$(Configuration)\$(PlatformShortName)\ 52 | 53 | 54 | false 55 | $(SolutionDir)build\$(Configuration)_$(PlatformShortName)\ 56 | $(SolutionDir)build\obj\$(ProjectName)\$(Configuration)\$(PlatformShortName)\ 57 | 58 | 59 | 60 | Level3 61 | true 62 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 63 | true 64 | stdcpp20 65 | 66 | 67 | Windows 68 | true 69 | 70 | 71 | 72 | 73 | Level3 74 | true 75 | true 76 | true 77 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 78 | true 79 | stdcpp20 80 | 81 | 82 | Windows 83 | true 84 | true 85 | true 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /gsf-launcher/gsf-launcher.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | -------------------------------------------------------------------------------- /gsf-launcher/gsf-launcher.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {69063e09-d8a8-4fa9-a306-69f5f615db38} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui.vcxitems.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui_impl_dx11.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for DirectX11 2 | // This needs to be used along with a Platform Backend (e.g. Win32) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'ID3D11ShaderResourceView*' as ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices. 7 | 8 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 10 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 11 | 12 | #pragma once 13 | #include "imgui.h" // IMGUI_IMPL_API 14 | 15 | struct ID3D11Device; 16 | struct ID3D11DeviceContext; 17 | 18 | IMGUI_IMPL_API bool ImGui_ImplDX11_Init(ID3D11Device* device, ID3D11DeviceContext* device_context); 19 | IMGUI_IMPL_API void ImGui_ImplDX11_Shutdown(); 20 | IMGUI_IMPL_API void ImGui_ImplDX11_NewFrame(); 21 | IMGUI_IMPL_API void ImGui_ImplDX11_RenderDrawData(ImDrawData* draw_data); 22 | 23 | // Use if you want to reset your rendering device without losing Dear ImGui state. 24 | IMGUI_IMPL_API void ImGui_ImplDX11_InvalidateDeviceObjects(); 25 | IMGUI_IMPL_API bool ImGui_ImplDX11_CreateDeviceObjects(); 26 | -------------------------------------------------------------------------------- /thirdparty/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 7 | // [X] Platform: Keyboard arrays indexed using VK_* Virtual Key Codes, e.g. ImGui::IsKeyPressed(VK_SPACE). 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | 10 | // You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 11 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 12 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 13 | 14 | #pragma once 15 | #include "imgui.h" // IMGUI_IMPL_API 16 | 17 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 18 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 19 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 20 | 21 | // Configuration 22 | // - Disable gamepad support or linking with xinput.lib 23 | //#define IMGUI_IMPL_WIN32_DISABLE_GAMEPAD 24 | //#define IMGUI_IMPL_WIN32_DISABLE_LINKING_XINPUT 25 | 26 | // Win32 message handler your application need to call. 27 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 28 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 29 | #if 0 30 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 31 | #endif 32 | 33 | // DPI-related helpers (optional) 34 | // - Use to enable DPI awareness without having to create an application manifest. 35 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 36 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 37 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 38 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 39 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 40 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 41 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 42 | -------------------------------------------------------------------------------- /thirdparty/license_imgui.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /thirdparty/license_minhook.txt: -------------------------------------------------------------------------------- 1 | MinHook - The Minimalistic API Hooking Library for x64/x86 2 | Copyright (C) 2009-2017 Tsuda Kageyu. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 18 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ================================================================================ 28 | Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov. 29 | ================================================================================ 30 | Hacker Disassembler Engine 32 C 31 | Copyright (c) 2008-2009, Vyacheslav Patkov. 32 | All rights reserved. 33 | 34 | Redistribution and use in source and binary forms, with or without 35 | modification, are permitted provided that the following conditions 36 | are met: 37 | 38 | 1. Redistributions of source code must retain the above copyright 39 | notice, this list of conditions and the following disclaimer. 40 | 2. Redistributions in binary form must reproduce the above copyright 41 | notice, this list of conditions and the following disclaimer in the 42 | documentation and/or other materials provided with the distribution. 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 45 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 48 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 49 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 50 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 51 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 52 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 53 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 54 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 | 56 | ------------------------------------------------------------------------------- 57 | Hacker Disassembler Engine 64 C 58 | Copyright (c) 2008-2009, Vyacheslav Patkov. 59 | All rights reserved. 60 | 61 | Redistribution and use in source and binary forms, with or without 62 | modification, are permitted provided that the following conditions 63 | are met: 64 | 65 | 1. Redistributions of source code must retain the above copyright 66 | notice, this list of conditions and the following disclaimer. 67 | 2. Redistributions in binary form must reproduce the above copyright 68 | notice, this list of conditions and the following disclaimer in the 69 | documentation and/or other materials provided with the distribution. 70 | 71 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 72 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 73 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 74 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 75 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 76 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 77 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 78 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 79 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 80 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 81 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | -------------------------------------------------------------------------------- /thirdparty/lua/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* Increments 'L->top', checking for stack overflows */ 16 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 17 | "stack overflow");} 18 | 19 | 20 | /* 21 | ** If a call returns too many multiple returns, the callee may not have 22 | ** stack space to accommodate all results. In this case, this macro 23 | ** increases its stack space ('L->ci->top'). 24 | */ 25 | #define adjustresults(L,nres) \ 26 | { if ((nres) <= LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 27 | 28 | 29 | /* Ensure the stack has at least 'n' elements */ 30 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 31 | "not enough elements in the stack") 32 | 33 | 34 | /* 35 | ** To reduce the overhead of returning from C functions, the presence of 36 | ** to-be-closed variables in these functions is coded in the CallInfo's 37 | ** field 'nresults', in a way that functions with no to-be-closed variables 38 | ** with zero, one, or "all" wanted results have no overhead. Functions 39 | ** with other number of wanted results, as well as functions with 40 | ** variables to be closed, have an extra check. 41 | */ 42 | 43 | #define hastocloseCfunc(n) ((n) < LUA_MULTRET) 44 | 45 | /* Map [-1, inf) (range of 'nresults') into (-inf, -2] */ 46 | #define codeNresults(n) (-(n) - 3) 47 | #define decodeNresults(n) (-(n) - 3) 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /thirdparty/lua/lcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lcode.h $ 3 | ** Code generator for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lcode_h 8 | #define lcode_h 9 | 10 | #include "llex.h" 11 | #include "lobject.h" 12 | #include "lopcodes.h" 13 | #include "lparser.h" 14 | 15 | 16 | /* 17 | ** Marks the end of a patch list. It is an invalid value both as an absolute 18 | ** address, and as a list link (would link an element to itself). 19 | */ 20 | #define NO_JUMP (-1) 21 | 22 | 23 | /* 24 | ** grep "ORDER OPR" if you change these enums (ORDER OP) 25 | */ 26 | typedef enum BinOpr { 27 | /* arithmetic operators */ 28 | OPR_ADD, OPR_SUB, OPR_MUL, OPR_MOD, OPR_POW, 29 | OPR_DIV, OPR_IDIV, 30 | /* bitwise operators */ 31 | OPR_BAND, OPR_BOR, OPR_BXOR, 32 | OPR_SHL, OPR_SHR, 33 | /* string operator */ 34 | OPR_CONCAT, 35 | /* comparison operators */ 36 | OPR_EQ, OPR_LT, OPR_LE, 37 | OPR_NE, OPR_GT, OPR_GE, 38 | /* logical operators */ 39 | OPR_AND, OPR_OR, 40 | OPR_NOBINOPR 41 | } BinOpr; 42 | 43 | 44 | /* true if operation is foldable (that is, it is arithmetic or bitwise) */ 45 | #define foldbinop(op) ((op) <= OPR_SHR) 46 | 47 | 48 | #define luaK_codeABC(fs,o,a,b,c) luaK_codeABCk(fs,o,a,b,c,0) 49 | 50 | 51 | typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; 52 | 53 | 54 | /* get (pointer to) instruction of given 'expdesc' */ 55 | #define getinstruction(fs,e) ((fs)->f->code[(e)->u.info]) 56 | 57 | 58 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) 59 | 60 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) 61 | 62 | LUAI_FUNC int luaK_code (FuncState *fs, Instruction i); 63 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); 64 | LUAI_FUNC int luaK_codeAsBx (FuncState *fs, OpCode o, int A, int Bx); 65 | LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, 66 | int B, int C, int k); 67 | LUAI_FUNC int luaK_isKint (expdesc *e); 68 | LUAI_FUNC int luaK_exp2const (FuncState *fs, const expdesc *e, TValue *v); 69 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); 70 | LUAI_FUNC void luaK_nil (FuncState *fs, int from, int n); 71 | LUAI_FUNC void luaK_reserveregs (FuncState *fs, int n); 72 | LUAI_FUNC void luaK_checkstack (FuncState *fs, int n); 73 | LUAI_FUNC void luaK_int (FuncState *fs, int reg, lua_Integer n); 74 | LUAI_FUNC void luaK_dischargevars (FuncState *fs, expdesc *e); 75 | LUAI_FUNC int luaK_exp2anyreg (FuncState *fs, expdesc *e); 76 | LUAI_FUNC void luaK_exp2anyregup (FuncState *fs, expdesc *e); 77 | LUAI_FUNC void luaK_exp2nextreg (FuncState *fs, expdesc *e); 78 | LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e); 79 | LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e); 80 | LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key); 81 | LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k); 82 | LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e); 83 | LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e); 84 | LUAI_FUNC void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e); 85 | LUAI_FUNC void luaK_setreturns (FuncState *fs, expdesc *e, int nresults); 86 | LUAI_FUNC void luaK_setoneret (FuncState *fs, expdesc *e); 87 | LUAI_FUNC int luaK_jump (FuncState *fs); 88 | LUAI_FUNC void luaK_ret (FuncState *fs, int first, int nret); 89 | LUAI_FUNC void luaK_patchlist (FuncState *fs, int list, int target); 90 | LUAI_FUNC void luaK_patchtohere (FuncState *fs, int list); 91 | LUAI_FUNC void luaK_concat (FuncState *fs, int *l1, int l2); 92 | LUAI_FUNC int luaK_getlabel (FuncState *fs); 93 | LUAI_FUNC void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v, int line); 94 | LUAI_FUNC void luaK_infix (FuncState *fs, BinOpr op, expdesc *v); 95 | LUAI_FUNC void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, 96 | expdesc *v2, int line); 97 | LUAI_FUNC void luaK_settablesize (FuncState *fs, int pc, 98 | int ra, int asize, int hsize); 99 | LUAI_FUNC void luaK_setlist (FuncState *fs, int base, int nelems, int tostore); 100 | LUAI_FUNC void luaK_finish (FuncState *fs); 101 | LUAI_FUNC l_noret luaK_semerror (LexState *ls, const char *msg); 102 | 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /thirdparty/lua/lctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.c $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lctype_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lctype.h" 14 | 15 | #if !LUA_USE_CTYPE /* { */ 16 | 17 | #include 18 | 19 | 20 | #if defined (LUA_UCID) /* accept UniCode IDentifiers? */ 21 | /* consider all non-ascii codepoints to be alphabetic */ 22 | #define NONA 0x01 23 | #else 24 | #define NONA 0x00 /* default */ 25 | #endif 26 | 27 | 28 | LUAI_DDEF const lu_byte luai_ctype_[UCHAR_MAX + 2] = { 29 | 0x00, /* EOZ */ 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0. */ 31 | 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 32 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 1. */ 33 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 34 | 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, /* 2. */ 35 | 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 36 | 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, 0x16, /* 3. */ 37 | 0x16, 0x16, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 38 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 4. */ 39 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 40 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 5. */ 41 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x05, 42 | 0x04, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x05, /* 6. */ 43 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 44 | 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, /* 7. */ 45 | 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x00, 46 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 8. */ 47 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 48 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* 9. */ 49 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 50 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* a. */ 51 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 52 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* b. */ 53 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 54 | 0x00, 0x00, NONA, NONA, NONA, NONA, NONA, NONA, /* c. */ 55 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 56 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* d. */ 57 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 58 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, /* e. */ 59 | NONA, NONA, NONA, NONA, NONA, NONA, NONA, NONA, 60 | NONA, NONA, NONA, NONA, NONA, 0x00, 0x00, 0x00, /* f. */ 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 62 | }; 63 | 64 | #endif /* } */ 65 | -------------------------------------------------------------------------------- /thirdparty/lua/lctype.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lctype.h $ 3 | ** 'ctype' functions for Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lctype_h 8 | #define lctype_h 9 | 10 | #include "lua.h" 11 | 12 | 13 | /* 14 | ** WARNING: the functions defined here do not necessarily correspond 15 | ** to the similar functions in the standard C ctype.h. They are 16 | ** optimized for the specific needs of Lua. 17 | */ 18 | 19 | #if !defined(LUA_USE_CTYPE) 20 | 21 | #if 'A' == 65 && '0' == 48 22 | /* ASCII case: can use its own tables; faster and fixed */ 23 | #define LUA_USE_CTYPE 0 24 | #else 25 | /* must use standard C ctype */ 26 | #define LUA_USE_CTYPE 1 27 | #endif 28 | 29 | #endif 30 | 31 | 32 | #if !LUA_USE_CTYPE /* { */ 33 | 34 | #include 35 | 36 | #include "llimits.h" 37 | 38 | 39 | #define ALPHABIT 0 40 | #define DIGITBIT 1 41 | #define PRINTBIT 2 42 | #define SPACEBIT 3 43 | #define XDIGITBIT 4 44 | 45 | 46 | #define MASK(B) (1 << (B)) 47 | 48 | 49 | /* 50 | ** add 1 to char to allow index -1 (EOZ) 51 | */ 52 | #define testprop(c,p) (luai_ctype_[(c)+1] & (p)) 53 | 54 | /* 55 | ** 'lalpha' (Lua alphabetic) and 'lalnum' (Lua alphanumeric) both include '_' 56 | */ 57 | #define lislalpha(c) testprop(c, MASK(ALPHABIT)) 58 | #define lislalnum(c) testprop(c, (MASK(ALPHABIT) | MASK(DIGITBIT))) 59 | #define lisdigit(c) testprop(c, MASK(DIGITBIT)) 60 | #define lisspace(c) testprop(c, MASK(SPACEBIT)) 61 | #define lisprint(c) testprop(c, MASK(PRINTBIT)) 62 | #define lisxdigit(c) testprop(c, MASK(XDIGITBIT)) 63 | 64 | 65 | /* 66 | ** In ASCII, this 'ltolower' is correct for alphabetic characters and 67 | ** for '.'. That is enough for Lua needs. ('check_exp' ensures that 68 | ** the character either is an upper-case letter or is unchanged by 69 | ** the transformation, which holds for lower-case letters and '.'.) 70 | */ 71 | #define ltolower(c) \ 72 | check_exp(('A' <= (c) && (c) <= 'Z') || (c) == ((c) | ('A' ^ 'a')), \ 73 | (c) | ('A' ^ 'a')) 74 | 75 | 76 | /* one entry for each character and for -1 (EOZ) */ 77 | LUAI_DDEC(const lu_byte luai_ctype_[UCHAR_MAX + 2];) 78 | 79 | 80 | #else /* }{ */ 81 | 82 | /* 83 | ** use standard C ctypes 84 | */ 85 | 86 | #include 87 | 88 | 89 | #define lislalpha(c) (isalpha(c) || (c) == '_') 90 | #define lislalnum(c) (isalnum(c) || (c) == '_') 91 | #define lisdigit(c) (isdigit(c)) 92 | #define lisspace(c) (isspace(c)) 93 | #define lisprint(c) (isprint(c)) 94 | #define lisxdigit(c) (isxdigit(c)) 95 | 96 | #define ltolower(c) (tolower(c)) 97 | 98 | #endif /* } */ 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /thirdparty/lua/ldebug.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldebug.h $ 3 | ** Auxiliary functions from Debug Interface module 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldebug_h 8 | #define ldebug_h 9 | 10 | 11 | #include "lstate.h" 12 | 13 | 14 | #define pcRel(pc, p) (cast_int((pc) - (p)->code) - 1) 15 | 16 | 17 | /* Active Lua function (given call info) */ 18 | #define ci_func(ci) (clLvalue(s2v((ci)->func))) 19 | 20 | 21 | #define resethookcount(L) (L->hookcount = L->basehookcount) 22 | 23 | /* 24 | ** mark for entries in 'lineinfo' array that has absolute information in 25 | ** 'abslineinfo' array 26 | */ 27 | #define ABSLINEINFO (-0x80) 28 | 29 | 30 | /* 31 | ** MAXimum number of successive Instructions WiTHout ABSolute line 32 | ** information. (A power of two allows fast divisions.) 33 | */ 34 | #if !defined(MAXIWTHABS) 35 | #define MAXIWTHABS 128 36 | #endif 37 | 38 | 39 | LUAI_FUNC int luaG_getfuncline (const Proto *f, int pc); 40 | LUAI_FUNC const char *luaG_findlocal (lua_State *L, CallInfo *ci, int n, 41 | StkId *pos); 42 | LUAI_FUNC l_noret luaG_typeerror (lua_State *L, const TValue *o, 43 | const char *opname); 44 | LUAI_FUNC l_noret luaG_callerror (lua_State *L, const TValue *o); 45 | LUAI_FUNC l_noret luaG_forerror (lua_State *L, const TValue *o, 46 | const char *what); 47 | LUAI_FUNC l_noret luaG_concaterror (lua_State *L, const TValue *p1, 48 | const TValue *p2); 49 | LUAI_FUNC l_noret luaG_opinterror (lua_State *L, const TValue *p1, 50 | const TValue *p2, 51 | const char *msg); 52 | LUAI_FUNC l_noret luaG_tointerror (lua_State *L, const TValue *p1, 53 | const TValue *p2); 54 | LUAI_FUNC l_noret luaG_ordererror (lua_State *L, const TValue *p1, 55 | const TValue *p2); 56 | LUAI_FUNC l_noret luaG_runerror (lua_State *L, const char *fmt, ...); 57 | LUAI_FUNC const char *luaG_addinfo (lua_State *L, const char *msg, 58 | TString *src, int line); 59 | LUAI_FUNC l_noret luaG_errormsg (lua_State *L); 60 | LUAI_FUNC int luaG_traceexec (lua_State *L, const Instruction *pc); 61 | 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /thirdparty/lua/ldo.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ldo.h $ 3 | ** Stack and Call structure of Lua 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ldo_h 8 | #define ldo_h 9 | 10 | 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Macro to check stack size and grow stack if needed. Parameters 18 | ** 'pre'/'pos' allow the macro to preserve a pointer into the 19 | ** stack across reallocations, doing the work only when needed. 20 | ** It also allows the running of one GC step when the stack is 21 | ** reallocated. 22 | ** 'condmovestack' is used in heavy tests to force a stack reallocation 23 | ** at every check. 24 | */ 25 | #define luaD_checkstackaux(L,n,pre,pos) \ 26 | if (l_unlikely(L->stack_last - L->top <= (n))) \ 27 | { pre; luaD_growstack(L, n, 1); pos; } \ 28 | else { condmovestack(L,pre,pos); } 29 | 30 | /* In general, 'pre'/'pos' are empty (nothing to save) */ 31 | #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0) 32 | 33 | 34 | 35 | #define savestack(L,p) ((char *)(p) - (char *)L->stack) 36 | #define restorestack(L,n) ((StkId)((char *)L->stack + (n))) 37 | 38 | 39 | /* macro to check stack size, preserving 'p' */ 40 | #define checkstackGCp(L,n,p) \ 41 | luaD_checkstackaux(L, n, \ 42 | ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \ 43 | luaC_checkGC(L), /* stack grow uses memory */ \ 44 | p = restorestack(L, t__)) /* 'pos' part: restore 'p' */ 45 | 46 | 47 | /* macro to check stack size and GC */ 48 | #define checkstackGC(L,fsize) \ 49 | luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0) 50 | 51 | 52 | /* type of protected functions, to be ran by 'runprotected' */ 53 | typedef void (*Pfunc) (lua_State *L, void *ud); 54 | 55 | LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); 56 | LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name, 57 | const char *mode); 58 | LUAI_FUNC void luaD_hook (lua_State *L, int event, int line, 59 | int fTransfer, int nTransfer); 60 | LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci); 61 | LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n); 62 | LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults); 63 | LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); 64 | LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults); 65 | LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func); 66 | LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status); 67 | LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, 68 | ptrdiff_t oldtop, ptrdiff_t ef); 69 | LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres); 70 | LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror); 71 | LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror); 72 | LUAI_FUNC void luaD_shrinkstack (lua_State *L); 73 | LUAI_FUNC void luaD_inctop (lua_State *L); 74 | 75 | LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode); 76 | LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); 77 | 78 | #endif 79 | 80 | -------------------------------------------------------------------------------- /thirdparty/lua/lfunc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lfunc.h $ 3 | ** Auxiliary functions to manipulate prototypes and closures 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lfunc_h 8 | #define lfunc_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | #define sizeCclosure(n) (cast_int(offsetof(CClosure, upvalue)) + \ 15 | cast_int(sizeof(TValue)) * (n)) 16 | 17 | #define sizeLclosure(n) (cast_int(offsetof(LClosure, upvals)) + \ 18 | cast_int(sizeof(TValue *)) * (n)) 19 | 20 | 21 | /* test whether thread is in 'twups' list */ 22 | #define isintwups(L) (L->twups != L) 23 | 24 | 25 | /* 26 | ** maximum number of upvalues in a closure (both C and Lua). (Value 27 | ** must fit in a VM register.) 28 | */ 29 | #define MAXUPVAL 255 30 | 31 | 32 | #define upisopen(up) ((up)->v != &(up)->u.value) 33 | 34 | 35 | #define uplevel(up) check_exp(upisopen(up), cast(StkId, (up)->v)) 36 | 37 | 38 | /* 39 | ** maximum number of misses before giving up the cache of closures 40 | ** in prototypes 41 | */ 42 | #define MAXMISS 10 43 | 44 | 45 | 46 | /* special status to close upvalues preserving the top of the stack */ 47 | #define CLOSEKTOP (-1) 48 | 49 | 50 | LUAI_FUNC Proto *luaF_newproto (lua_State *L); 51 | LUAI_FUNC CClosure *luaF_newCclosure (lua_State *L, int nupvals); 52 | LUAI_FUNC LClosure *luaF_newLclosure (lua_State *L, int nupvals); 53 | LUAI_FUNC void luaF_initupvals (lua_State *L, LClosure *cl); 54 | LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); 55 | LUAI_FUNC void luaF_newtbcupval (lua_State *L, StkId level); 56 | LUAI_FUNC void luaF_closeupval (lua_State *L, StkId level); 57 | LUAI_FUNC void luaF_close (lua_State *L, StkId level, int status, int yy); 58 | LUAI_FUNC void luaF_unlinkupval (UpVal *uv); 59 | LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); 60 | LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, 61 | int pc); 62 | 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /thirdparty/lua/linit.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: linit.c $ 3 | ** Initialization of libraries for lua.c and other clients 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #define linit_c 9 | #define LUA_LIB 10 | 11 | /* 12 | ** If you embed Lua in your program and need to open the standard 13 | ** libraries, call luaL_openlibs in your program. If you need a 14 | ** different set of libraries, copy this file to your project and edit 15 | ** it to suit your needs. 16 | ** 17 | ** You can also *preload* libraries, so that a later 'require' can 18 | ** open the library, which is already linked to the application. 19 | ** For that, do the following code: 20 | ** 21 | ** luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE); 22 | ** lua_pushcfunction(L, luaopen_modname); 23 | ** lua_setfield(L, -2, modname); 24 | ** lua_pop(L, 1); // remove PRELOAD table 25 | */ 26 | 27 | #include "lprefix.h" 28 | 29 | 30 | #include 31 | 32 | #include "lua.h" 33 | 34 | #include "lualib.h" 35 | #include "lauxlib.h" 36 | 37 | 38 | /* 39 | ** these libs are loaded by lua.c and are readily available to any Lua 40 | ** program 41 | */ 42 | static const luaL_Reg loadedlibs[] = { 43 | {LUA_GNAME, luaopen_base}, 44 | {LUA_LOADLIBNAME, luaopen_package}, 45 | {LUA_COLIBNAME, luaopen_coroutine}, 46 | {LUA_TABLIBNAME, luaopen_table}, 47 | {LUA_IOLIBNAME, luaopen_io}, 48 | {LUA_OSLIBNAME, luaopen_os}, 49 | {LUA_STRLIBNAME, luaopen_string}, 50 | {LUA_MATHLIBNAME, luaopen_math}, 51 | {LUA_UTF8LIBNAME, luaopen_utf8}, 52 | {LUA_DBLIBNAME, luaopen_debug}, 53 | {NULL, NULL} 54 | }; 55 | 56 | 57 | LUALIB_API void luaL_openlibs (lua_State *L) { 58 | const luaL_Reg *lib; 59 | /* "require" functions from 'loadedlibs' and set results to global table */ 60 | for (lib = loadedlibs; lib->func; lib++) { 61 | luaL_requiref(L, lib->name, lib->func, 1); 62 | lua_pop(L, 1); /* remove lib */ 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /thirdparty/lua/ljumptab.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ljumptab.h $ 3 | ** Jump Table for the Lua interpreter 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #undef vmdispatch 9 | #undef vmcase 10 | #undef vmbreak 11 | 12 | #define vmdispatch(x) goto *disptab[x]; 13 | 14 | #define vmcase(l) L_##l: 15 | 16 | #define vmbreak vmfetch(); vmdispatch(GET_OPCODE(i)); 17 | 18 | 19 | static const void *const disptab[NUM_OPCODES] = { 20 | 21 | #if 0 22 | ** you can update the following list with this command: 23 | ** 24 | ** sed -n '/^OP_/\!d; s/OP_/\&\&L_OP_/ ; s/,.*/,/ ; s/\/.*// ; p' lopcodes.h 25 | ** 26 | #endif 27 | 28 | &&L_OP_MOVE, 29 | &&L_OP_LOADI, 30 | &&L_OP_LOADF, 31 | &&L_OP_LOADK, 32 | &&L_OP_LOADKX, 33 | &&L_OP_LOADFALSE, 34 | &&L_OP_LFALSESKIP, 35 | &&L_OP_LOADTRUE, 36 | &&L_OP_LOADNIL, 37 | &&L_OP_GETUPVAL, 38 | &&L_OP_SETUPVAL, 39 | &&L_OP_GETTABUP, 40 | &&L_OP_GETTABLE, 41 | &&L_OP_GETI, 42 | &&L_OP_GETFIELD, 43 | &&L_OP_SETTABUP, 44 | &&L_OP_SETTABLE, 45 | &&L_OP_SETI, 46 | &&L_OP_SETFIELD, 47 | &&L_OP_NEWTABLE, 48 | &&L_OP_SELF, 49 | &&L_OP_ADDI, 50 | &&L_OP_ADDK, 51 | &&L_OP_SUBK, 52 | &&L_OP_MULK, 53 | &&L_OP_MODK, 54 | &&L_OP_POWK, 55 | &&L_OP_DIVK, 56 | &&L_OP_IDIVK, 57 | &&L_OP_BANDK, 58 | &&L_OP_BORK, 59 | &&L_OP_BXORK, 60 | &&L_OP_SHRI, 61 | &&L_OP_SHLI, 62 | &&L_OP_ADD, 63 | &&L_OP_SUB, 64 | &&L_OP_MUL, 65 | &&L_OP_MOD, 66 | &&L_OP_POW, 67 | &&L_OP_DIV, 68 | &&L_OP_IDIV, 69 | &&L_OP_BAND, 70 | &&L_OP_BOR, 71 | &&L_OP_BXOR, 72 | &&L_OP_SHL, 73 | &&L_OP_SHR, 74 | &&L_OP_MMBIN, 75 | &&L_OP_MMBINI, 76 | &&L_OP_MMBINK, 77 | &&L_OP_UNM, 78 | &&L_OP_BNOT, 79 | &&L_OP_NOT, 80 | &&L_OP_LEN, 81 | &&L_OP_CONCAT, 82 | &&L_OP_CLOSE, 83 | &&L_OP_TBC, 84 | &&L_OP_JMP, 85 | &&L_OP_EQ, 86 | &&L_OP_LT, 87 | &&L_OP_LE, 88 | &&L_OP_EQK, 89 | &&L_OP_EQI, 90 | &&L_OP_LTI, 91 | &&L_OP_LEI, 92 | &&L_OP_GTI, 93 | &&L_OP_GEI, 94 | &&L_OP_TEST, 95 | &&L_OP_TESTSET, 96 | &&L_OP_CALL, 97 | &&L_OP_TAILCALL, 98 | &&L_OP_RETURN, 99 | &&L_OP_RETURN0, 100 | &&L_OP_RETURN1, 101 | &&L_OP_FORLOOP, 102 | &&L_OP_FORPREP, 103 | &&L_OP_TFORPREP, 104 | &&L_OP_TFORCALL, 105 | &&L_OP_TFORLOOP, 106 | &&L_OP_SETLIST, 107 | &&L_OP_CLOSURE, 108 | &&L_OP_VARARG, 109 | &&L_OP_VARARGPREP, 110 | &&L_OP_EXTRAARG 111 | 112 | }; 113 | -------------------------------------------------------------------------------- /thirdparty/lua/llex.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: llex.h $ 3 | ** Lexical Analyzer 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef llex_h 8 | #define llex_h 9 | 10 | #include 11 | 12 | #include "lobject.h" 13 | #include "lzio.h" 14 | 15 | 16 | /* 17 | ** Single-char tokens (terminal symbols) are represented by their own 18 | ** numeric code. Other tokens start at the following value. 19 | */ 20 | #define FIRST_RESERVED (UCHAR_MAX + 1) 21 | 22 | 23 | #if !defined(LUA_ENV) 24 | #define LUA_ENV "_ENV" 25 | #endif 26 | 27 | 28 | /* 29 | * WARNING: if you change the order of this enumeration, 30 | * grep "ORDER RESERVED" 31 | */ 32 | enum RESERVED { 33 | /* terminal symbols denoted by reserved words */ 34 | TK_AND = FIRST_RESERVED, TK_BREAK, 35 | TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION, 36 | TK_GOTO, TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT, 37 | TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE, 38 | /* other terminal symbols */ 39 | TK_IDIV, TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, 40 | TK_SHL, TK_SHR, 41 | TK_DBCOLON, TK_EOS, 42 | TK_FLT, TK_INT, TK_NAME, TK_STRING 43 | }; 44 | 45 | /* number of reserved words */ 46 | #define NUM_RESERVED (cast_int(TK_WHILE-FIRST_RESERVED + 1)) 47 | 48 | 49 | typedef union { 50 | lua_Number r; 51 | lua_Integer i; 52 | TString *ts; 53 | } SemInfo; /* semantics information */ 54 | 55 | 56 | typedef struct Token { 57 | int token; 58 | SemInfo seminfo; 59 | } Token; 60 | 61 | 62 | /* state of the lexer plus state of the parser when shared by all 63 | functions */ 64 | typedef struct LexState { 65 | int current; /* current character (charint) */ 66 | int linenumber; /* input line counter */ 67 | int lastline; /* line of last token 'consumed' */ 68 | Token t; /* current token */ 69 | Token lookahead; /* look ahead token */ 70 | struct FuncState *fs; /* current function (parser) */ 71 | struct lua_State *L; 72 | ZIO *z; /* input stream */ 73 | Mbuffer *buff; /* buffer for tokens */ 74 | Table *h; /* to avoid collection/reuse strings */ 75 | struct Dyndata *dyd; /* dynamic structures used by the parser */ 76 | TString *source; /* current source name */ 77 | TString *envn; /* environment variable name */ 78 | } LexState; 79 | 80 | 81 | LUAI_FUNC void luaX_init (lua_State *L); 82 | LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, 83 | TString *source, int firstchar); 84 | LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); 85 | LUAI_FUNC void luaX_next (LexState *ls); 86 | LUAI_FUNC int luaX_lookahead (LexState *ls); 87 | LUAI_FUNC l_noret luaX_syntaxerror (LexState *ls, const char *s); 88 | LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); 89 | 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /thirdparty/lua/lmem.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lmem.h $ 3 | ** Interface to Memory Manager 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lmem_h 8 | #define lmem_h 9 | 10 | 11 | #include 12 | 13 | #include "llimits.h" 14 | #include "lua.h" 15 | 16 | 17 | #define luaM_error(L) luaD_throw(L, LUA_ERRMEM) 18 | 19 | 20 | /* 21 | ** This macro tests whether it is safe to multiply 'n' by the size of 22 | ** type 't' without overflows. Because 'e' is always constant, it avoids 23 | ** the runtime division MAX_SIZET/(e). 24 | ** (The macro is somewhat complex to avoid warnings: The 'sizeof' 25 | ** comparison avoids a runtime comparison when overflow cannot occur. 26 | ** The compiler should be able to optimize the real test by itself, but 27 | ** when it does it, it may give a warning about "comparison is always 28 | ** false due to limited range of data type"; the +1 tricks the compiler, 29 | ** avoiding this warning but also this optimization.) 30 | */ 31 | #define luaM_testsize(n,e) \ 32 | (sizeof(n) >= sizeof(size_t) && cast_sizet((n)) + 1 > MAX_SIZET/(e)) 33 | 34 | #define luaM_checksize(L,n,e) \ 35 | (luaM_testsize(n,e) ? luaM_toobig(L) : cast_void(0)) 36 | 37 | 38 | /* 39 | ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that 40 | ** the result is not larger than 'n' and cannot overflow a 'size_t' 41 | ** when multiplied by the size of type 't'. (Assumes that 'n' is an 42 | ** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) 43 | */ 44 | #define luaM_limitN(n,t) \ 45 | ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \ 46 | cast_uint((MAX_SIZET/sizeof(t)))) 47 | 48 | 49 | /* 50 | ** Arrays of chars do not need any test 51 | */ 52 | #define luaM_reallocvchar(L,b,on,n) \ 53 | cast_charp(luaM_saferealloc_(L, (b), (on)*sizeof(char), (n)*sizeof(char))) 54 | 55 | #define luaM_freemem(L, b, s) luaM_free_(L, (b), (s)) 56 | #define luaM_free(L, b) luaM_free_(L, (b), sizeof(*(b))) 57 | #define luaM_freearray(L, b, n) luaM_free_(L, (b), (n)*sizeof(*(b))) 58 | 59 | #define luaM_new(L,t) cast(t*, luaM_malloc_(L, sizeof(t), 0)) 60 | #define luaM_newvector(L,n,t) cast(t*, luaM_malloc_(L, (n)*sizeof(t), 0)) 61 | #define luaM_newvectorchecked(L,n,t) \ 62 | (luaM_checksize(L,n,sizeof(t)), luaM_newvector(L,n,t)) 63 | 64 | #define luaM_newobject(L,tag,s) luaM_malloc_(L, (s), tag) 65 | 66 | #define luaM_growvector(L,v,nelems,size,t,limit,e) \ 67 | ((v)=cast(t *, luaM_growaux_(L,v,nelems,&(size),sizeof(t), \ 68 | luaM_limitN(limit,t),e))) 69 | 70 | #define luaM_reallocvector(L, v,oldn,n,t) \ 71 | (cast(t *, luaM_realloc_(L, v, cast_sizet(oldn) * sizeof(t), \ 72 | cast_sizet(n) * sizeof(t)))) 73 | 74 | #define luaM_shrinkvector(L,v,size,fs,t) \ 75 | ((v)=cast(t *, luaM_shrinkvector_(L, v, &(size), fs, sizeof(t)))) 76 | 77 | LUAI_FUNC l_noret luaM_toobig (lua_State *L); 78 | 79 | /* not to be called directly */ 80 | LUAI_FUNC void *luaM_realloc_ (lua_State *L, void *block, size_t oldsize, 81 | size_t size); 82 | LUAI_FUNC void *luaM_saferealloc_ (lua_State *L, void *block, size_t oldsize, 83 | size_t size); 84 | LUAI_FUNC void luaM_free_ (lua_State *L, void *block, size_t osize); 85 | LUAI_FUNC void *luaM_growaux_ (lua_State *L, void *block, int nelems, 86 | int *size, int size_elem, int limit, 87 | const char *what); 88 | LUAI_FUNC void *luaM_shrinkvector_ (lua_State *L, void *block, int *nelem, 89 | int final_n, int size_elem); 90 | LUAI_FUNC void *luaM_malloc_ (lua_State *L, size_t size, int tag); 91 | 92 | #endif 93 | 94 | -------------------------------------------------------------------------------- /thirdparty/lua/lopcodes.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopcodes.c $ 3 | ** Opcodes for Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lopcodes_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include "lopcodes.h" 14 | 15 | 16 | /* ORDER OP */ 17 | 18 | LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { 19 | /* MM OT IT T A mode opcode */ 20 | opmode(0, 0, 0, 0, 1, iABC) /* OP_MOVE */ 21 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADI */ 22 | ,opmode(0, 0, 0, 0, 1, iAsBx) /* OP_LOADF */ 23 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADK */ 24 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_LOADKX */ 25 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADFALSE */ 26 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LFALSESKIP */ 27 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADTRUE */ 28 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LOADNIL */ 29 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETUPVAL */ 30 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETUPVAL */ 31 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABUP */ 32 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETTABLE */ 33 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETI */ 34 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_GETFIELD */ 35 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABUP */ 36 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETTABLE */ 37 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETI */ 38 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_SETFIELD */ 39 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NEWTABLE */ 40 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SELF */ 41 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDI */ 42 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADDK */ 43 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUBK */ 44 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MULK */ 45 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MODK */ 46 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POWK */ 47 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIVK */ 48 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIVK */ 49 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BANDK */ 50 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BORK */ 51 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXORK */ 52 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHRI */ 53 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHLI */ 54 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_ADD */ 55 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SUB */ 56 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MUL */ 57 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_MOD */ 58 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_POW */ 59 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_DIV */ 60 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_IDIV */ 61 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BAND */ 62 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BOR */ 63 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BXOR */ 64 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHL */ 65 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_SHR */ 66 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBIN */ 67 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINI*/ 68 | ,opmode(1, 0, 0, 0, 0, iABC) /* OP_MMBINK*/ 69 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_UNM */ 70 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_BNOT */ 71 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_NOT */ 72 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_LEN */ 73 | ,opmode(0, 0, 0, 0, 1, iABC) /* OP_CONCAT */ 74 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_CLOSE */ 75 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TBC */ 76 | ,opmode(0, 0, 0, 0, 0, isJ) /* OP_JMP */ 77 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQ */ 78 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LT */ 79 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LE */ 80 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQK */ 81 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_EQI */ 82 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LTI */ 83 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_LEI */ 84 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GTI */ 85 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_GEI */ 86 | ,opmode(0, 0, 0, 1, 0, iABC) /* OP_TEST */ 87 | ,opmode(0, 0, 0, 1, 1, iABC) /* OP_TESTSET */ 88 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_CALL */ 89 | ,opmode(0, 1, 1, 0, 1, iABC) /* OP_TAILCALL */ 90 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_RETURN */ 91 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN0 */ 92 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_RETURN1 */ 93 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORLOOP */ 94 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_FORPREP */ 95 | ,opmode(0, 0, 0, 0, 0, iABx) /* OP_TFORPREP */ 96 | ,opmode(0, 0, 0, 0, 0, iABC) /* OP_TFORCALL */ 97 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_TFORLOOP */ 98 | ,opmode(0, 0, 1, 0, 0, iABC) /* OP_SETLIST */ 99 | ,opmode(0, 0, 0, 0, 1, iABx) /* OP_CLOSURE */ 100 | ,opmode(0, 1, 0, 0, 1, iABC) /* OP_VARARG */ 101 | ,opmode(0, 0, 1, 0, 1, iABC) /* OP_VARARGPREP */ 102 | ,opmode(0, 0, 0, 0, 0, iAx) /* OP_EXTRAARG */ 103 | }; 104 | 105 | -------------------------------------------------------------------------------- /thirdparty/lua/lopnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lopnames.h $ 3 | ** Opcode names 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #if !defined(lopnames_h) 8 | #define lopnames_h 9 | 10 | #include 11 | 12 | 13 | /* ORDER OP */ 14 | 15 | static const char *const opnames[] = { 16 | "MOVE", 17 | "LOADI", 18 | "LOADF", 19 | "LOADK", 20 | "LOADKX", 21 | "LOADFALSE", 22 | "LFALSESKIP", 23 | "LOADTRUE", 24 | "LOADNIL", 25 | "GETUPVAL", 26 | "SETUPVAL", 27 | "GETTABUP", 28 | "GETTABLE", 29 | "GETI", 30 | "GETFIELD", 31 | "SETTABUP", 32 | "SETTABLE", 33 | "SETI", 34 | "SETFIELD", 35 | "NEWTABLE", 36 | "SELF", 37 | "ADDI", 38 | "ADDK", 39 | "SUBK", 40 | "MULK", 41 | "MODK", 42 | "POWK", 43 | "DIVK", 44 | "IDIVK", 45 | "BANDK", 46 | "BORK", 47 | "BXORK", 48 | "SHRI", 49 | "SHLI", 50 | "ADD", 51 | "SUB", 52 | "MUL", 53 | "MOD", 54 | "POW", 55 | "DIV", 56 | "IDIV", 57 | "BAND", 58 | "BOR", 59 | "BXOR", 60 | "SHL", 61 | "SHR", 62 | "MMBIN", 63 | "MMBINI", 64 | "MMBINK", 65 | "UNM", 66 | "BNOT", 67 | "NOT", 68 | "LEN", 69 | "CONCAT", 70 | "CLOSE", 71 | "TBC", 72 | "JMP", 73 | "EQ", 74 | "LT", 75 | "LE", 76 | "EQK", 77 | "EQI", 78 | "LTI", 79 | "LEI", 80 | "GTI", 81 | "GEI", 82 | "TEST", 83 | "TESTSET", 84 | "CALL", 85 | "TAILCALL", 86 | "RETURN", 87 | "RETURN0", 88 | "RETURN1", 89 | "FORLOOP", 90 | "FORPREP", 91 | "TFORPREP", 92 | "TFORCALL", 93 | "TFORLOOP", 94 | "SETLIST", 95 | "CLOSURE", 96 | "VARARG", 97 | "VARARGPREP", 98 | "EXTRAARG", 99 | NULL 100 | }; 101 | 102 | #endif 103 | 104 | -------------------------------------------------------------------------------- /thirdparty/lua/lprefix.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lprefix.h $ 3 | ** Definitions for Lua code that must come before any other header file 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lprefix_h 8 | #define lprefix_h 9 | 10 | 11 | /* 12 | ** Allows POSIX/XSI stuff 13 | */ 14 | #if !defined(LUA_USE_C89) /* { */ 15 | 16 | #if !defined(_XOPEN_SOURCE) 17 | #define _XOPEN_SOURCE 600 18 | #elif _XOPEN_SOURCE == 0 19 | #undef _XOPEN_SOURCE /* use -D_XOPEN_SOURCE=0 to undefine it */ 20 | #endif 21 | 22 | /* 23 | ** Allows manipulation of large files in gcc and some other compilers 24 | */ 25 | #if !defined(LUA_32BITS) && !defined(_FILE_OFFSET_BITS) 26 | #define _LARGEFILE_SOURCE 1 27 | #define _FILE_OFFSET_BITS 64 28 | #endif 29 | 30 | #endif /* } */ 31 | 32 | 33 | /* 34 | ** Windows stuff 35 | */ 36 | #if defined(_WIN32) /* { */ 37 | 38 | #if !defined(_CRT_SECURE_NO_WARNINGS) 39 | #define _CRT_SECURE_NO_WARNINGS /* avoid warnings about ISO C functions */ 40 | #endif 41 | 42 | #endif /* } */ 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /thirdparty/lua/lstring.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lstring.h $ 3 | ** String table (keep all strings handled by Lua) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lstring_h 8 | #define lstring_h 9 | 10 | #include "lgc.h" 11 | #include "lobject.h" 12 | #include "lstate.h" 13 | 14 | 15 | /* 16 | ** Memory-allocation error message must be preallocated (it cannot 17 | ** be created after memory is exhausted) 18 | */ 19 | #define MEMERRMSG "not enough memory" 20 | 21 | 22 | /* 23 | ** Size of a TString: Size of the header plus space for the string 24 | ** itself (including final '\0'). 25 | */ 26 | #define sizelstring(l) (offsetof(TString, contents) + ((l) + 1) * sizeof(char)) 27 | 28 | #define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ 29 | (sizeof(s)/sizeof(char))-1)) 30 | 31 | 32 | /* 33 | ** test whether a string is a reserved word 34 | */ 35 | #define isreserved(s) ((s)->tt == LUA_VSHRSTR && (s)->extra > 0) 36 | 37 | 38 | /* 39 | ** equality for short strings, which are always internalized 40 | */ 41 | #define eqshrstr(a,b) check_exp((a)->tt == LUA_VSHRSTR, (a) == (b)) 42 | 43 | 44 | LUAI_FUNC unsigned int luaS_hash (const char *str, size_t l, unsigned int seed); 45 | LUAI_FUNC unsigned int luaS_hashlongstr (TString *ts); 46 | LUAI_FUNC int luaS_eqlngstr (TString *a, TString *b); 47 | LUAI_FUNC void luaS_resize (lua_State *L, int newsize); 48 | LUAI_FUNC void luaS_clearcache (global_State *g); 49 | LUAI_FUNC void luaS_init (lua_State *L); 50 | LUAI_FUNC void luaS_remove (lua_State *L, TString *ts); 51 | LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, int nuvalue); 52 | LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); 53 | LUAI_FUNC TString *luaS_new (lua_State *L, const char *str); 54 | LUAI_FUNC TString *luaS_createlngstrobj (lua_State *L, size_t l); 55 | 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /thirdparty/lua/ltable.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltable.h $ 3 | ** Lua tables (hash) 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltable_h 8 | #define ltable_h 9 | 10 | #include "lobject.h" 11 | 12 | 13 | #define gnode(t,i) (&(t)->node[i]) 14 | #define gval(n) (&(n)->i_val) 15 | #define gnext(n) ((n)->u.next) 16 | 17 | 18 | /* 19 | ** Clear all bits of fast-access metamethods, which means that the table 20 | ** may have any of these metamethods. (First access that fails after the 21 | ** clearing will set the bit again.) 22 | */ 23 | #define invalidateTMcache(t) ((t)->flags &= ~maskflags) 24 | 25 | 26 | /* true when 't' is using 'dummynode' as its hash part */ 27 | #define isdummy(t) ((t)->lastfree == NULL) 28 | 29 | 30 | /* allocated size for hash nodes */ 31 | #define allocsizenode(t) (isdummy(t) ? 0 : sizenode(t)) 32 | 33 | 34 | /* returns the Node, given the value of a table entry */ 35 | #define nodefromval(v) cast(Node *, (v)) 36 | 37 | 38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); 39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, 40 | TValue *value); 41 | LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); 42 | LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); 43 | LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); 44 | LUAI_FUNC void luaH_newkey (lua_State *L, Table *t, const TValue *key, 45 | TValue *value); 46 | LUAI_FUNC void luaH_set (lua_State *L, Table *t, const TValue *key, 47 | TValue *value); 48 | LUAI_FUNC void luaH_finishset (lua_State *L, Table *t, const TValue *key, 49 | const TValue *slot, TValue *value); 50 | LUAI_FUNC Table *luaH_new (lua_State *L); 51 | LUAI_FUNC void luaH_resize (lua_State *L, Table *t, unsigned int nasize, 52 | unsigned int nhsize); 53 | LUAI_FUNC void luaH_resizearray (lua_State *L, Table *t, unsigned int nasize); 54 | LUAI_FUNC void luaH_free (lua_State *L, Table *t); 55 | LUAI_FUNC int luaH_next (lua_State *L, Table *t, StkId key); 56 | LUAI_FUNC lua_Unsigned luaH_getn (Table *t); 57 | LUAI_FUNC unsigned int luaH_realasize (const Table *t); 58 | 59 | 60 | #if defined(LUA_DEBUG) 61 | LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); 62 | LUAI_FUNC int luaH_isdummy (const Table *t); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /thirdparty/lua/ltm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: ltm.h $ 3 | ** Tag methods 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef ltm_h 8 | #define ltm_h 9 | 10 | 11 | #include "lobject.h" 12 | 13 | 14 | /* 15 | * WARNING: if you change the order of this enumeration, 16 | * grep "ORDER TM" and "ORDER OP" 17 | */ 18 | typedef enum { 19 | TM_INDEX, 20 | TM_NEWINDEX, 21 | TM_GC, 22 | TM_MODE, 23 | TM_LEN, 24 | TM_EQ, /* last tag method with fast access */ 25 | TM_ADD, 26 | TM_SUB, 27 | TM_MUL, 28 | TM_MOD, 29 | TM_POW, 30 | TM_DIV, 31 | TM_IDIV, 32 | TM_BAND, 33 | TM_BOR, 34 | TM_BXOR, 35 | TM_SHL, 36 | TM_SHR, 37 | TM_UNM, 38 | TM_BNOT, 39 | TM_LT, 40 | TM_LE, 41 | TM_CONCAT, 42 | TM_CALL, 43 | TM_CLOSE, 44 | TM_N /* number of elements in the enum */ 45 | } TMS; 46 | 47 | 48 | /* 49 | ** Mask with 1 in all fast-access methods. A 1 in any of these bits 50 | ** in the flag of a (meta)table means the metatable does not have the 51 | ** corresponding metamethod field. (Bit 7 of the flag is used for 52 | ** 'isrealasize'.) 53 | */ 54 | #define maskflags (~(~0u << (TM_EQ + 1))) 55 | 56 | 57 | /* 58 | ** Test whether there is no tagmethod. 59 | ** (Because tagmethods use raw accesses, the result may be an "empty" nil.) 60 | */ 61 | #define notm(tm) ttisnil(tm) 62 | 63 | 64 | #define gfasttm(g,et,e) ((et) == NULL ? NULL : \ 65 | ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) 66 | 67 | #define fasttm(l,et,e) gfasttm(G(l), et, e) 68 | 69 | #define ttypename(x) luaT_typenames_[(x) + 1] 70 | 71 | LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) 72 | 73 | 74 | LUAI_FUNC const char *luaT_objtypename (lua_State *L, const TValue *o); 75 | 76 | LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); 77 | LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, 78 | TMS event); 79 | LUAI_FUNC void luaT_init (lua_State *L); 80 | 81 | LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, 82 | const TValue *p2, const TValue *p3); 83 | LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, 84 | const TValue *p1, const TValue *p2, StkId p3); 85 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, 86 | StkId res, TMS event); 87 | LUAI_FUNC void luaT_tryconcatTM (lua_State *L); 88 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, 89 | const TValue *p2, int inv, StkId res, TMS event); 90 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2, 91 | int inv, StkId res, TMS event); 92 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, 93 | const TValue *p2, TMS event); 94 | LUAI_FUNC int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2, 95 | int inv, int isfloat, TMS event); 96 | 97 | LUAI_FUNC void luaT_adjustvarargs (lua_State *L, int nfixparams, 98 | struct CallInfo *ci, const Proto *p); 99 | LUAI_FUNC void luaT_getvarargs (lua_State *L, struct CallInfo *ci, 100 | StkId where, int wanted); 101 | 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /thirdparty/lua/lua.hpp: -------------------------------------------------------------------------------- 1 | // lua.hpp 2 | // Lua header files for C++ 3 | // <> not supplied automatically because Lua also compiles as C++ 4 | 5 | extern "C" { 6 | #include "lua.h" 7 | #include "lualib.h" 8 | #include "lauxlib.h" 9 | } 10 | -------------------------------------------------------------------------------- /thirdparty/lua/lua.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {8754e545-8e7d-4a4c-88d5-f5cc94a1ba04} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /thirdparty/lua/lua.vcxitems.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /thirdparty/lua/lualib.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lualib.h $ 3 | ** Lua standard libraries 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lualib_h 9 | #define lualib_h 10 | 11 | #include "lua.h" 12 | 13 | 14 | /* version suffix for environment variable names */ 15 | #define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR 16 | 17 | 18 | LUAMOD_API int (luaopen_base) (lua_State *L); 19 | 20 | #define LUA_COLIBNAME "coroutine" 21 | LUAMOD_API int (luaopen_coroutine) (lua_State *L); 22 | 23 | #define LUA_TABLIBNAME "table" 24 | LUAMOD_API int (luaopen_table) (lua_State *L); 25 | 26 | #define LUA_IOLIBNAME "io" 27 | LUAMOD_API int (luaopen_io) (lua_State *L); 28 | 29 | #define LUA_OSLIBNAME "os" 30 | LUAMOD_API int (luaopen_os) (lua_State *L); 31 | 32 | #define LUA_STRLIBNAME "string" 33 | LUAMOD_API int (luaopen_string) (lua_State *L); 34 | 35 | #define LUA_UTF8LIBNAME "utf8" 36 | LUAMOD_API int (luaopen_utf8) (lua_State *L); 37 | 38 | #define LUA_MATHLIBNAME "math" 39 | LUAMOD_API int (luaopen_math) (lua_State *L); 40 | 41 | #define LUA_DBLIBNAME "debug" 42 | LUAMOD_API int (luaopen_debug) (lua_State *L); 43 | 44 | #define LUA_LOADLIBNAME "package" 45 | LUAMOD_API int (luaopen_package) (lua_State *L); 46 | 47 | 48 | /* open all previous libraries */ 49 | LUALIB_API void (luaL_openlibs) (lua_State *L); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /thirdparty/lua/lundump.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lundump.h $ 3 | ** load precompiled Lua chunks 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lundump_h 8 | #define lundump_h 9 | 10 | #include "llimits.h" 11 | #include "lobject.h" 12 | #include "lzio.h" 13 | 14 | 15 | /* data to catch conversion errors */ 16 | #define LUAC_DATA "\x19\x93\r\n\x1a\n" 17 | 18 | #define LUAC_INT 0x5678 19 | #define LUAC_NUM cast_num(370.5) 20 | 21 | /* 22 | ** Encode major-minor version in one byte, one nibble for each 23 | */ 24 | #define MYINT(s) (s[0]-'0') /* assume one-digit numerals */ 25 | #define LUAC_VERSION (MYINT(LUA_VERSION_MAJOR)*16+MYINT(LUA_VERSION_MINOR)) 26 | 27 | #define LUAC_FORMAT 0 /* this is the official format */ 28 | 29 | /* load one chunk; from lundump.c */ 30 | LUAI_FUNC LClosure* luaU_undump (lua_State* L, ZIO* Z, const char* name); 31 | 32 | /* dump one chunk; from ldump.c */ 33 | LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, 34 | void* data, int strip); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /thirdparty/lua/lvm.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lvm.h $ 3 | ** Lua virtual machine 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lvm_h 8 | #define lvm_h 9 | 10 | 11 | #include "ldo.h" 12 | #include "lobject.h" 13 | #include "ltm.h" 14 | 15 | 16 | #if !defined(LUA_NOCVTN2S) 17 | #define cvt2str(o) ttisnumber(o) 18 | #else 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ 20 | #endif 21 | 22 | 23 | #if !defined(LUA_NOCVTS2N) 24 | #define cvt2num(o) ttisstring(o) 25 | #else 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ 27 | #endif 28 | 29 | 30 | /* 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers 32 | ** by flooring them (instead of raising an error if they are not 33 | ** integral values) 34 | */ 35 | #if !defined(LUA_FLOORN2I) 36 | #define LUA_FLOORN2I F2Ieq 37 | #endif 38 | 39 | 40 | /* 41 | ** Rounding modes for float->integer coercion 42 | */ 43 | typedef enum { 44 | F2Ieq, /* no rounding; accepts only integral values */ 45 | F2Ifloor, /* takes the floor of the number */ 46 | F2Iceil /* takes the ceil of the number */ 47 | } F2Imod; 48 | 49 | 50 | /* convert an object to a float (including string coercion) */ 51 | #define tonumber(o,n) \ 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 53 | 54 | 55 | /* convert an object to a float (without string coercion) */ 56 | #define tonumberns(o,n) \ 57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ 58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) 59 | 60 | 61 | /* convert an object to an integer (including string coercion) */ 62 | #define tointeger(o,i) \ 63 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 64 | : luaV_tointeger(o,i,LUA_FLOORN2I)) 65 | 66 | 67 | /* convert an object to an integer (without string coercion) */ 68 | #define tointegerns(o,i) \ 69 | (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \ 70 | : luaV_tointegerns(o,i,LUA_FLOORN2I)) 71 | 72 | 73 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 74 | 75 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 76 | 77 | 78 | /* 79 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present, 80 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). 81 | ** Otherwise, return 0 (meaning it will have to check metamethod) 82 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL 83 | ** (otherwise). 'f' is the raw get function to use. 84 | */ 85 | #define luaV_fastget(L,t,k,slot,f) \ 86 | (!ttistable(t) \ 87 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 88 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ 89 | !isempty(slot))) /* result not empty? */ 90 | 91 | 92 | /* 93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case 94 | ** of 'luaH_getint'. 95 | */ 96 | #define luaV_fastgeti(L,t,k,slot) \ 97 | (!ttistable(t) \ 98 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 99 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \ 100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ 101 | !isempty(slot))) /* result not empty? */ 102 | 103 | 104 | /* 105 | ** Finish a fast set operation (when fast get succeeds). In that case, 106 | ** 'slot' points to the place to put the value. 107 | */ 108 | #define luaV_finishfastset(L,t,slot,v) \ 109 | { setobj2t(L, cast(TValue *,slot), v); \ 110 | luaC_barrierback(L, gcvalue(t), v); } 111 | 112 | 113 | 114 | 115 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 116 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 117 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 118 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 119 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); 120 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, 121 | F2Imod mode); 122 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); 123 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 124 | StkId val, const TValue *slot); 125 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 126 | TValue *val, const TValue *slot); 127 | LUAI_FUNC void luaV_finishOp (lua_State *L); 128 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci); 129 | LUAI_FUNC void luaV_concat (lua_State *L, int total); 130 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y); 131 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 132 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y); 133 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 134 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 135 | 136 | #endif 137 | -------------------------------------------------------------------------------- /thirdparty/lua/lzio.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.c $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #define lzio_c 8 | #define LUA_CORE 9 | 10 | #include "lprefix.h" 11 | 12 | 13 | #include 14 | 15 | #include "lua.h" 16 | 17 | #include "llimits.h" 18 | #include "lmem.h" 19 | #include "lstate.h" 20 | #include "lzio.h" 21 | 22 | 23 | int luaZ_fill (ZIO *z) { 24 | size_t size; 25 | lua_State *L = z->L; 26 | const char *buff; 27 | lua_unlock(L); 28 | buff = z->reader(L, z->data, &size); 29 | lua_lock(L); 30 | if (buff == NULL || size == 0) 31 | return EOZ; 32 | z->n = size - 1; /* discount char being returned */ 33 | z->p = buff; 34 | return cast_uchar(*(z->p++)); 35 | } 36 | 37 | 38 | void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) { 39 | z->L = L; 40 | z->reader = reader; 41 | z->data = data; 42 | z->n = 0; 43 | z->p = NULL; 44 | } 45 | 46 | 47 | /* --------------------------------------------------------------- read --- */ 48 | size_t luaZ_read (ZIO *z, void *b, size_t n) { 49 | while (n) { 50 | size_t m; 51 | if (z->n == 0) { /* no bytes in buffer? */ 52 | if (luaZ_fill(z) == EOZ) /* try to read more */ 53 | return n; /* no more input; return number of missing bytes */ 54 | else { 55 | z->n++; /* luaZ_fill consumed first byte; put it back */ 56 | z->p--; 57 | } 58 | } 59 | m = (n <= z->n) ? n : z->n; /* min. between n and z->n */ 60 | memcpy(b, z->p, m); 61 | z->n -= m; 62 | z->p += m; 63 | b = (char *)b + m; 64 | n -= m; 65 | } 66 | return 0; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /thirdparty/lua/lzio.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lzio.h $ 3 | ** Buffered streams 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | 8 | #ifndef lzio_h 9 | #define lzio_h 10 | 11 | #include "lua.h" 12 | 13 | #include "lmem.h" 14 | 15 | 16 | #define EOZ (-1) /* end of stream */ 17 | 18 | typedef struct Zio ZIO; 19 | 20 | #define zgetc(z) (((z)->n--)>0 ? cast_uchar(*(z)->p++) : luaZ_fill(z)) 21 | 22 | 23 | typedef struct Mbuffer { 24 | char *buffer; 25 | size_t n; 26 | size_t buffsize; 27 | } Mbuffer; 28 | 29 | #define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0) 30 | 31 | #define luaZ_buffer(buff) ((buff)->buffer) 32 | #define luaZ_sizebuffer(buff) ((buff)->buffsize) 33 | #define luaZ_bufflen(buff) ((buff)->n) 34 | 35 | #define luaZ_buffremove(buff,i) ((buff)->n -= (i)) 36 | #define luaZ_resetbuffer(buff) ((buff)->n = 0) 37 | 38 | 39 | #define luaZ_resizebuffer(L, buff, size) \ 40 | ((buff)->buffer = luaM_reallocvchar(L, (buff)->buffer, \ 41 | (buff)->buffsize, size), \ 42 | (buff)->buffsize = size) 43 | 44 | #define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0) 45 | 46 | 47 | LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, 48 | void *data); 49 | LUAI_FUNC size_t luaZ_read (ZIO* z, void *b, size_t n); /* read next n bytes */ 50 | 51 | 52 | 53 | /* --------- Private Part ------------------ */ 54 | 55 | struct Zio { 56 | size_t n; /* bytes still unread */ 57 | const char *p; /* current position in buffer */ 58 | lua_Reader reader; /* reader function */ 59 | void *data; /* additional data */ 60 | lua_State *L; /* Lua state (for reader) */ 61 | }; 62 | 63 | 64 | LUAI_FUNC int luaZ_fill (ZIO *z); 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /thirdparty/minhook/minhook.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {2956636e-c74f-4083-9493-873da4e44cbf} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /thirdparty/minhook/minhook.vcxitems.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | // Size of each memory slot. 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #define MEMORY_SLOT_SIZE 64 34 | #else 35 | #define MEMORY_SLOT_SIZE 32 36 | #endif 37 | 38 | VOID InitializeBuffer(VOID); 39 | VOID UninitializeBuffer(VOID); 40 | LPVOID AllocateBuffer(LPVOID pOrigin); 41 | VOID FreeBuffer(LPVOID pBuffer); 42 | BOOL IsExecutableAddress(LPVOID pAddress); 43 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_DISP8 0x00000020 30 | #define F_DISP16 0x00000040 31 | #define F_DISP32 0x00000080 32 | #define F_RELATIVE 0x00000100 33 | #define F_2IMM16 0x00000800 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_ANY 0x3f000000 47 | 48 | #define PREFIX_SEGMENT_CS 0x2e 49 | #define PREFIX_SEGMENT_SS 0x36 50 | #define PREFIX_SEGMENT_DS 0x3e 51 | #define PREFIX_SEGMENT_ES 0x26 52 | #define PREFIX_SEGMENT_FS 0x64 53 | #define PREFIX_SEGMENT_GS 0x65 54 | #define PREFIX_LOCK 0xf0 55 | #define PREFIX_REPNZ 0xf2 56 | #define PREFIX_REPX 0xf3 57 | #define PREFIX_OPERAND_SIZE 0x66 58 | #define PREFIX_ADDRESS_SIZE 0x67 59 | 60 | #pragma pack(push,1) 61 | 62 | typedef struct { 63 | uint8_t len; 64 | uint8_t p_rep; 65 | uint8_t p_lock; 66 | uint8_t p_seg; 67 | uint8_t p_66; 68 | uint8_t p_67; 69 | uint8_t opcode; 70 | uint8_t opcode2; 71 | uint8_t modrm; 72 | uint8_t modrm_mod; 73 | uint8_t modrm_reg; 74 | uint8_t modrm_rm; 75 | uint8_t sib; 76 | uint8_t sib_scale; 77 | uint8_t sib_index; 78 | uint8_t sib_base; 79 | union { 80 | uint8_t imm8; 81 | uint16_t imm16; 82 | uint32_t imm32; 83 | } imm; 84 | union { 85 | uint8_t disp8; 86 | uint16_t disp16; 87 | uint32_t disp32; 88 | } disp; 89 | uint32_t flags; 90 | } hde32s; 91 | 92 | #pragma pack(pop) 93 | 94 | #ifdef __cplusplus 95 | extern "C" { 96 | #endif 97 | 98 | /* __cdecl */ 99 | unsigned int hde32_disasm(const void *code, hde32s *hs); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* _HDE32_H_ */ 106 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void *code, hde64s *hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/hde/table32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xf1 30 | #define DELTA_FPU_MODRM 0xf8 31 | #define DELTA_PREFIXES 0x130 32 | #define DELTA_OP_LOCK_OK 0x1a1 33 | #define DELTA_OP2_LOCK_OK 0x1b9 34 | #define DELTA_OP_ONLY_MEM 0x1cb 35 | #define DELTA_OP2_ONLY_MEM 0x1da 36 | 37 | unsigned char hde32_table[] = { 38 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 39 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 40 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 41 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 42 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 43 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 44 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 45 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 46 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 47 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 48 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 49 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 50 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 51 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 52 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 53 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 54 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 55 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 56 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 57 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 59 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 60 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 61 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 62 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 63 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 64 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 65 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 66 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 67 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 68 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 69 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 70 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 71 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 72 | 0xe7,0x08,0x00,0xf0,0x02,0x00 73 | }; 74 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /thirdparty/minhook/src/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #pragma pack(push, 1) 32 | 33 | // Structs for writing x86/x64 instructions. 34 | 35 | // 8-bit relative jump. 36 | typedef struct _JMP_REL_SHORT 37 | { 38 | UINT8 opcode; // EB xx: JMP +2+xx 39 | UINT8 operand; 40 | } JMP_REL_SHORT, *PJMP_REL_SHORT; 41 | 42 | // 32-bit direct relative jump/call. 43 | typedef struct _JMP_REL 44 | { 45 | UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx 46 | UINT32 operand; // Relative destination address 47 | } JMP_REL, *PJMP_REL, CALL_REL; 48 | 49 | // 64-bit indirect absolute jump. 50 | typedef struct _JMP_ABS 51 | { 52 | UINT8 opcode0; // FF25 00000000: JMP [+6] 53 | UINT8 opcode1; 54 | UINT32 dummy; 55 | UINT64 address; // Absolute destination address 56 | } JMP_ABS, *PJMP_ABS; 57 | 58 | // 64-bit indirect absolute call. 59 | typedef struct _CALL_ABS 60 | { 61 | UINT8 opcode0; // FF15 00000002: CALL [+6] 62 | UINT8 opcode1; 63 | UINT32 dummy0; 64 | UINT8 dummy1; // EB 08: JMP +10 65 | UINT8 dummy2; 66 | UINT64 address; // Absolute destination address 67 | } CALL_ABS; 68 | 69 | // 32-bit direct relative conditional jumps. 70 | typedef struct _JCC_REL 71 | { 72 | UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx 73 | UINT8 opcode1; 74 | UINT32 operand; // Relative destination address 75 | } JCC_REL; 76 | 77 | // 64bit indirect absolute conditional jumps that x64 lacks. 78 | typedef struct _JCC_ABS 79 | { 80 | UINT8 opcode; // 7* 0E: J** +16 81 | UINT8 dummy0; 82 | UINT8 dummy1; // FF25 00000000: JMP [+6] 83 | UINT8 dummy2; 84 | UINT32 dummy3; 85 | UINT64 address; // Absolute destination address 86 | } JCC_ABS; 87 | 88 | #pragma pack(pop) 89 | 90 | typedef struct _TRAMPOLINE 91 | { 92 | LPVOID pTarget; // [In] Address of the target function. 93 | LPVOID pDetour; // [In] Address of the detour function. 94 | LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. 95 | 96 | #if defined(_M_X64) || defined(__x86_64__) 97 | LPVOID pRelay; // [Out] Address of the relay function. 98 | #endif 99 | BOOL patchAbove; // [Out] Should use the hot patch area? 100 | UINT nIP; // [Out] Number of the instruction boundaries. 101 | UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function. 102 | UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function. 103 | } TRAMPOLINE, *PTRAMPOLINE; 104 | 105 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct); 106 | -------------------------------------------------------------------------------- /thirdparty/sol/config.hpp: -------------------------------------------------------------------------------- 1 | // The MIT License (MIT) 2 | 3 | // Copyright (c) 2013-2020 Rapptz, ThePhD and contributors 4 | 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | // the Software, and to permit persons to whom the Software is furnished to do so, 10 | // subject to the following conditions: 11 | 12 | // The above copyright notice and this permission notice shall be included in all 13 | // copies or substantial portions of the Software. 14 | 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | // This file was generated with a script. 23 | // Generated 2020-10-03 21:34:25.034794 UTC 24 | // This header was generated with sol v3.2.1 (revision 48eea7b5) 25 | // https://github.com/ThePhD/sol2 26 | 27 | #ifndef SOL_SINGLE_CONFIG_HPP 28 | #define SOL_SINGLE_CONFIG_HPP 29 | 30 | // beginning of sol/config.hpp 31 | 32 | /* Base, empty configuration file! 33 | 34 | To override, place a file in your include paths of the form: 35 | 36 | . (your include path here) 37 | | sol (directory, or equivalent) 38 | | config.hpp (your config.hpp file) 39 | 40 | So that when sol2 includes the file 41 | 42 | #include 43 | 44 | it gives you the configuration values you desire. Configuration values can be 45 | seen in the safety.rst of the doc/src, or at 46 | https://sol2.readthedocs.io/en/latest/safety.html ! You can also pass them through 47 | the build system, or the command line options of your compiler. 48 | 49 | */ 50 | 51 | // end of sol/config.hpp 52 | 53 | #endif // SOL_SINGLE_CONFIG_HPP 54 | -------------------------------------------------------------------------------- /thirdparty/sol/sol.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {4c58fead-6f55-48e8-8b76-63337a70c361} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /thirdparty/sol/sol.vcxitems.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /utils/console.cpp: -------------------------------------------------------------------------------- 1 | #include "console.h" 2 | 3 | static HANDLE stdout_handle = nullptr; 4 | static HWND window_handle = nullptr; 5 | static bool flag_allocated = false; 6 | 7 | con::color::color( con::colors foreground, con::colors background ) 8 | : fg_color(static_cast(foreground)), bg_color(static_cast(background)) 9 | { 10 | } 11 | 12 | bool con::init() 13 | { 14 | if ( AllocConsole() ) 15 | { 16 | FILE *file_ptr; 17 | _wfreopen_s( &file_ptr, L"CONOUT$", L"w", stdout ); 18 | _wfreopen_s( &file_ptr, L"CONOUT$", L"w", stderr ); 19 | _wfreopen_s( &file_ptr, L"CONIN$", L"r", stdin ); 20 | 21 | flag_allocated = true; 22 | } 23 | else 24 | { 25 | flag_allocated = false; 26 | } 27 | 28 | window_handle = GetConsoleWindow(); 29 | stdout_handle = GetStdHandle( STD_OUTPUT_HANDLE ); 30 | 31 | if ( stdout_handle && window_handle ) 32 | { 33 | con::print(); 34 | return true; 35 | } 36 | 37 | return false; 38 | } 39 | 40 | bool con::is_focused() 41 | { 42 | return window_handle == GetForegroundWindow(); 43 | } 44 | 45 | bool con::is_allocated() 46 | { 47 | return flag_allocated; 48 | } 49 | 50 | HWND con::get_window() 51 | { 52 | return window_handle; 53 | } 54 | 55 | HANDLE con::get_std() 56 | { 57 | return stdout_handle; 58 | } 59 | 60 | void con::print( void ) 61 | { 62 | con::print( con::color() ); 63 | } 64 | 65 | void con::print( con::color val ) 66 | { 67 | SetConsoleTextAttribute( stdout_handle, val.full ); 68 | } 69 | 70 | void con::print( con::colors val ) 71 | { 72 | con::print( con::color( val ) ); 73 | } 74 | 75 | void con::log::status(const wchar_t text[10], con::colors txtcol) 76 | { 77 | CONSOLE_SCREEN_BUFFER_INFO csbi{}; 78 | GetConsoleScreenBufferInfo(stdout_handle, &csbi); 79 | SetConsoleCursorPosition(stdout_handle, { this->status_point.x, this->status_point.y }); 80 | con::print(txtcol, text); 81 | SetConsoleCursorPosition(stdout_handle, csbi.dwCursorPosition); 82 | } 83 | 84 | void con::log::success() 85 | { 86 | this->status(L" SUCCESS ", con::colors::LGREEN); 87 | } 88 | 89 | void con::log::error() 90 | { 91 | this->status(L" ERROR ", con::colors::LRED); 92 | } 93 | 94 | bool con::log::check(bool result) 95 | { 96 | if (result) 97 | this->success(); 98 | else 99 | this->error(); 100 | 101 | return result; 102 | } 103 | -------------------------------------------------------------------------------- /utils/console.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace con 8 | { 9 | enum class colors 10 | { 11 | BLACK, 12 | BLUE, 13 | GREEN, 14 | AQUA, 15 | RED, 16 | PURPLE, 17 | YELLOW, 18 | WHITE, 19 | GRAY, 20 | LBLUE, 21 | LGREEN, 22 | LAQUA, 23 | LRED, 24 | LPURPLE, 25 | LYELLOW, 26 | BWHITE, 27 | }; 28 | 29 | struct color 30 | { 31 | color(con::colors foreground = con::colors::BWHITE, con::colors background = con::colors::BLACK); 32 | 33 | union 34 | { 35 | std::uint16_t full; 36 | std::uint8_t half[2]; 37 | struct 38 | { 39 | std::uint8_t fg_color; 40 | std::uint8_t bg_color; 41 | }; 42 | }; 43 | }; 44 | 45 | bool init(); 46 | 47 | bool is_focused(); 48 | bool is_allocated(); 49 | 50 | HWND get_window(); 51 | HANDLE get_std(); 52 | 53 | void print( void ); 54 | void print( con::color val ); 55 | void print( con::colors val ); 56 | 57 | template 58 | void print( T val ) 59 | { 60 | std::wcout << val; 61 | con::print(); 62 | } 63 | 64 | template 65 | void print( T val, targs... arg ) 66 | { 67 | con::print( val ); 68 | con::print( arg... ); 69 | } 70 | 71 | template 72 | void print( con::color val, targs... arg ) 73 | { 74 | con::print( val ); 75 | con::print( arg... ); 76 | } 77 | 78 | template 79 | void print( con::colors val, targs... arg ) 80 | { 81 | con::print( val ); 82 | con::print( arg... ); 83 | } 84 | 85 | class log 86 | { 87 | struct con_point_t 88 | { 89 | short x, y; 90 | }; 91 | 92 | public: 93 | 94 | template 95 | log(const T *text, bool newline = true, const wchar_t def_status[10] = L" WAIT... ") 96 | { 97 | if (newline) 98 | std::cout << '\n'; 99 | 100 | CONSOLE_SCREEN_BUFFER_INFO csbi{}; 101 | GetConsoleScreenBufferInfo(con::get_std(), &csbi); 102 | this->status_point.x = csbi.dwCursorPosition.X + 1; 103 | this->status_point.y = csbi.dwCursorPosition.Y; 104 | 105 | con::print(con::colors::BWHITE, "[", con::colors::GRAY, def_status, con::colors::BWHITE, "] ", text); 106 | } 107 | 108 | void status(const wchar_t text[10], con::colors txtcol = con::colors::WHITE); 109 | void success(); 110 | void error(); 111 | 112 | bool check(bool result); 113 | 114 | template 115 | static void out( T text ) 116 | { 117 | con::print(con::colors::BWHITE, "\n[ LOG ] ", text); 118 | } 119 | 120 | template 121 | static void warn( T text ) 122 | { 123 | con::print( con::colors::BWHITE, "\n[", con::colors::LYELLOW, " WARNING ", con::colors::BWHITE, "] ", text ); 124 | } 125 | 126 | template 127 | static void critical( T text ) 128 | { 129 | con::print( con::colors::BWHITE, "\n[", con::colors::LRED, " CRITERR ", con::colors::BWHITE, "] ", text ); 130 | } 131 | 132 | private: 133 | con_point_t status_point = {}; 134 | }; 135 | } -------------------------------------------------------------------------------- /utils/hash.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace utils 7 | { 8 | using fnv1a64_t = std::uint64_t; 9 | using fnv1a32_t = std::uint32_t; 10 | 11 | template 12 | constexpr hash_size hash_fnv1a(const string_t *string) 13 | { 14 | static_assert(std::is_same::value || std::is_same::value, "Invalid hash size type! Only supported types: utils::fnv1a64_t and utils::fnv1a32_t"); 15 | 16 | constexpr hash_size prime = std::is_same::value ? 0x00000100000001B3 : 0x01000193; 17 | hash_size result = std::is_same::value ? 0xcbf29ce484222325 : 0x811c9dc5; 18 | 19 | while (*string) 20 | { 21 | result = (result ^ *string) * prime; 22 | ++string; 23 | } 24 | 25 | return result; 26 | } 27 | 28 | template 29 | consteval hash_size hash_fnv1a_cv(const string_t *string) 30 | { 31 | return utils::hash_fnv1a(string); 32 | } 33 | } -------------------------------------------------------------------------------- /utils/hooking.cpp: -------------------------------------------------------------------------------- 1 | #include "hooking.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include "winapi_helper.h" 7 | 8 | bool utils::hook_vmt_swap(void **vtable, int index, void *hook_fn, void **out_orig_fn) 9 | { 10 | void ** const vfunc_entry = vtable + index; 11 | 12 | DWORD o_prot = 0; 13 | if (!VirtualProtect(vfunc_entry, sizeof(void *), PAGE_EXECUTE_READWRITE, &o_prot)) 14 | return false; 15 | 16 | if (out_orig_fn) 17 | *out_orig_fn = *vfunc_entry; 18 | 19 | *vfunc_entry = hook_fn; 20 | 21 | if (!VirtualProtect(vfunc_entry, sizeof(void *), o_prot, &o_prot)) 22 | return false; 23 | 24 | return true; 25 | } 26 | 27 | utils::hook_base::hook_base() 28 | { 29 | utils::hook_base::instances.push_back(this); 30 | } 31 | 32 | utils::hook_base::hook_base(void *target_, void *hookfn_) 33 | : target(target_), hookfn(hookfn_) 34 | { 35 | utils::hook_base::instances.push_back(this); 36 | } 37 | 38 | utils::hook_base::~hook_base() 39 | { 40 | // this->unhook(); 41 | } 42 | 43 | void utils::hook_base::internal_on_unhook() 44 | { 45 | utils::hook_base::instances.remove(this); 46 | } 47 | 48 | utils::hook_vmt::hook_vmt(int index_, void *hook_) 49 | : index(index_), utils::hook_base(nullptr, hook_) 50 | { 51 | } 52 | 53 | bool utils::hook_vmt::init(void **vtable) 54 | { 55 | this->vfunc_entry = vtable + this->index; 56 | return true; 57 | } 58 | 59 | bool utils::hook_vmt::hook() 60 | { 61 | utils::change_page_protection page_prot_vfunc(this->vfunc_entry, sizeof(void*), PAGE_EXECUTE_READWRITE); 62 | if (!page_prot_vfunc) 63 | return false; 64 | 65 | this->originalfn = *this->vfunc_entry; 66 | *this->vfunc_entry = this->hookfn; 67 | 68 | return true; 69 | } 70 | 71 | bool utils::hook_vmt::unhook() 72 | { 73 | utils::change_page_protection page_prot_vfunc(this->vfunc_entry, sizeof(void *), PAGE_EXECUTE_READWRITE); 74 | if (!page_prot_vfunc) 75 | return false; 76 | 77 | *this->vfunc_entry = this->originalfn; 78 | 79 | this->internal_on_unhook(); 80 | 81 | return true; 82 | } 83 | 84 | utils::hook_wndproc::hook_wndproc(void *hookfn_) 85 | : utils::hook_base(nullptr, hookfn_) 86 | { 87 | } 88 | 89 | bool utils::hook_wndproc::init(void *window_handle_) 90 | { 91 | this->window_handle = window_handle_; 92 | return true; 93 | } 94 | 95 | bool utils::hook_wndproc::hook() 96 | { 97 | this->originalfn = reinterpret_cast(SetWindowLongPtrW(reinterpret_cast(this->window_handle), GWLP_WNDPROC, reinterpret_cast(this->hookfn))); 98 | return this->originalfn != nullptr; 99 | } 100 | 101 | bool utils::hook_wndproc::unhook() 102 | { 103 | this->internal_on_unhook(); 104 | return SetWindowLongPtrW(reinterpret_cast(this->window_handle), GWLP_WNDPROC, reinterpret_cast(this->originalfn)) != NULL; 105 | } 106 | 107 | bool utils::hook_wndproc::inhook(void *target_) 108 | { 109 | return this->init(target_) && this->hook(); 110 | } 111 | 112 | utils::hook_detour::hook_detour(void *hookfn_) 113 | : utils::hook_base(nullptr, hookfn_) 114 | { 115 | } 116 | 117 | bool utils::hook_detour::init(void *target_) 118 | { 119 | this->target = target_; 120 | return MH_CreateHook(target_, this->hookfn, reinterpret_cast(&this->originalfn)) == MH_OK; 121 | } 122 | 123 | bool utils::hook_detour::hook() 124 | { 125 | return MH_EnableHook(this->target) == MH_OK; 126 | } 127 | 128 | bool utils::hook_detour::unhook() 129 | { 130 | this->internal_on_unhook(); 131 | return MH_DisableHook(this->target) == MH_OK; 132 | } 133 | 134 | bool utils::hook_detour::inhook(void *target_) 135 | { 136 | return this->init(target_) && this->hook(); 137 | } 138 | -------------------------------------------------------------------------------- /utils/hooking.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace utils 7 | { 8 | bool hook_vmt_swap(void **vtable, int index, void *hook_fn, void **out_orig_fn); 9 | 10 | class hook_base 11 | { 12 | public: 13 | hook_base(); 14 | hook_base(void *target_, void *hookfn_); 15 | 16 | virtual ~hook_base(); 17 | 18 | virtual bool hook() { return false; }; 19 | virtual bool unhook() { return false; }; 20 | 21 | template 22 | T *get_original() 23 | { 24 | return reinterpret_cast(this->originalfn); 25 | } 26 | 27 | private: 28 | 29 | void internal_on_unhook(); 30 | 31 | void *target = nullptr; 32 | void *originalfn = nullptr; 33 | void *hookfn = nullptr; 34 | 35 | friend class hook_vmt; 36 | friend class hook_wndproc; 37 | friend class hook_detour; 38 | 39 | public: 40 | inline static std::list instances; 41 | }; 42 | 43 | class hook_detour : public hook_base 44 | { 45 | public: 46 | hook_detour(void *hookfn_); 47 | 48 | bool init(void *target_); 49 | 50 | bool hook() override; 51 | bool unhook() override; 52 | bool inhook(void *target_); 53 | }; 54 | 55 | class hook_vmt : public hook_base 56 | { 57 | public: 58 | hook_vmt(int index_, void *hook_); 59 | 60 | bool init(void **vtable); 61 | 62 | bool hook() override; 63 | bool unhook() override; 64 | 65 | private: 66 | int index; 67 | void **vfunc_entry = nullptr; 68 | }; 69 | 70 | class hook_wndproc : public hook_base 71 | { 72 | public: 73 | hook_wndproc(void *hookfn_); 74 | 75 | bool init(void *window_handle_); 76 | 77 | bool hook() override; 78 | bool unhook() override; 79 | bool inhook(void *target_); 80 | 81 | private: 82 | void *window_handle = nullptr; 83 | }; 84 | 85 | } -------------------------------------------------------------------------------- /utils/loadlibrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace utils 8 | { 9 | void *_debug_get_address_of_shellcode_map_module(); 10 | bool map_module(void *proc_handle, void *thread_handle, void *module_bin, std::size_t bin_size); 11 | bool remote_loadlibrary(void *proc_handle, std::wstring_view path); 12 | } -------------------------------------------------------------------------------- /utils/macro.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(_DEBUG) && !defined(NDEBUG) 4 | #include 5 | #include 6 | #define DEBUG_WCOUT(x) std::wcout << x 7 | #define DEBUG_COUT(x) std::cout << x 8 | #define DEBUG_CON_PRINT(...) con::print(__VA_ARGS__); 9 | #define DEBUG_CON_C_LOG(message, expr) con::log(message).check((expr)) 10 | #elif defined(NDEBUG) && !defined(_DEBUG) 11 | #define DEBUG_WCOUT(x) 12 | #define DEBUG_COUT(x) 13 | #define DEBUG_CON_PRINT(...) 14 | #define DEBUG_CON_C_LOG(message, expr) (expr) 15 | #endif 16 | 17 | // Used for converting ascii constant strings defined as macros to unicode by appending an L (simple turns "hello" to L"hello" but works for macros too) 18 | #define UTILS_A2W_MDEF(m) L"" ## m 19 | 20 | #define GET_VFUNC_FROM_VTABLE_BY_IDX(table, index) reinterpret_cast(table)[static_cast(index)] 21 | #define GET_VFUNC_FROM_VCLASS_BY_IDX(vclass, vtable, index) reinterpret_cast(vclass)[vtable][static_cast(index)] -------------------------------------------------------------------------------- /utils/mem.cpp: -------------------------------------------------------------------------------- 1 | #include "mem.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | std::uint8_t *utils::aob_scan(void *start, std::size_t size, const char *signature, const char *mask) 8 | { 9 | if (!start || size < 1 || !signature || !mask) 10 | return nullptr; 11 | 12 | std::uint8_t *current_address = reinterpret_cast(start); 13 | const std::size_t byte_count = std::strlen(mask); 14 | const std::uint8_t *end = current_address + size; 15 | 16 | do 17 | { 18 | for (int i = 0; i <= byte_count; i++) 19 | { 20 | if (mask[i] == '?') 21 | continue; 22 | else if (mask[i] != 'x' || current_address[i] != reinterpret_cast(signature)[i]) 23 | break; 24 | else if (mask[i + 1] == '\0') 25 | return current_address; 26 | } 27 | } while (++current_address + byte_count <= end); 28 | 29 | return nullptr; 30 | } 31 | 32 | std::uint8_t *utils::aob_scan(void *proc_handle, void *start, std::size_t size, const char *signature, const char *mask) 33 | { 34 | std::unique_ptr buffer = std::make_unique(size); 35 | if (!ReadProcessMemory(proc_handle, start, buffer.get(), size, nullptr)) 36 | return nullptr; 37 | 38 | std::uint8_t *result = utils::aob_scan(buffer.get(), size, signature, mask); 39 | if (!result) 40 | return nullptr; 41 | 42 | return reinterpret_cast(start) + (reinterpret_cast(result) - reinterpret_cast(buffer.get())); 43 | } 44 | 45 | constexpr std::uint8_t INVALID_NIBBLE = 0xF0; 46 | std::uint8_t hex_char_to_nibble(const char cnibble) 47 | { 48 | if (cnibble >= '0' && cnibble <= '9') 49 | return static_cast(cnibble - '0'); 50 | else if (cnibble >= 'A' && cnibble <= 'F') 51 | return static_cast((cnibble - 'A') + 0xA); 52 | else if (cnibble >= 'a' && cnibble <= 'f') 53 | return static_cast((cnibble - 'a') + 0xa); 54 | 55 | return INVALID_NIBBLE; 56 | } 57 | 58 | bool hex_str_to_byte(std::uint8_t &byte_out, const char strhex[2]) 59 | { 60 | auto upper_nibble = hex_char_to_nibble(strhex[0]); 61 | auto lower_nibble = hex_char_to_nibble(strhex[1]); 62 | 63 | if (upper_nibble == INVALID_NIBBLE || lower_nibble == INVALID_NIBBLE) 64 | return false; 65 | 66 | byte_out = (upper_nibble << 4) | lower_nibble; 67 | return true; 68 | } 69 | 70 | std::uint8_t *utils::ida_scan(void *start, std::size_t size, const char *signature) 71 | { 72 | // is this lazy? just creating data from an ida pattern for the aob scanner. 73 | // perhaps i could argue that atleast you only have to parse the ida pattern once instead of doing it everytime you check for sigs. 74 | 75 | std::vector aob; 76 | std::string mask; 77 | 78 | do 79 | { 80 | if (*signature == ' ') 81 | continue; 82 | 83 | if (*signature == '?') 84 | { 85 | aob.push_back(0); 86 | mask.append("?"); 87 | continue; 88 | } 89 | 90 | std::uint8_t byte_result = 0; 91 | 92 | if (!hex_str_to_byte(byte_result, signature)) 93 | return nullptr; 94 | 95 | aob.push_back(byte_result); 96 | mask.append("x"); 97 | if (*++signature == '\0') // skip the second nibble, the if statement is for ensuring that we dont go oob incase of a bad signature (all sig should be a pair, this will be caught by hex_str_to_byte anyway but just incase, you'll never know!) 98 | return nullptr; 99 | 100 | } while (*++signature != '\0'); 101 | 102 | if (aob.size() != mask.length()) 103 | return nullptr; // this should throw an exception instead 104 | 105 | return utils::aob_scan(start, size, reinterpret_cast(aob.data()), mask.c_str()); 106 | } 107 | 108 | std::uint8_t *utils::calc_rel2abs32(void *instruction_address, std::size_t instruction_size) 109 | { 110 | auto next_inst = reinterpret_cast(instruction_address) + instruction_size; 111 | return reinterpret_cast(next_inst + *reinterpret_cast((next_inst - sizeof(std::uint32_t)))); 112 | } 113 | 114 | std::int32_t utils::calc_abs2rel32(void *instruction_address, std::size_t instruction_size, void *absolute_target) 115 | { 116 | return static_cast(reinterpret_cast(absolute_target) - (reinterpret_cast(instruction_address) + instruction_size)); 117 | } 118 | -------------------------------------------------------------------------------- /utils/mem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace utils 7 | { 8 | std::uint8_t *aob_scan(void *start, std::size_t size, const char *signature, const char *mask); 9 | std::uint8_t *aob_scan(void *proc_handle, void *start, std::size_t size, const char *signature, const char *mask); 10 | 11 | std::uint8_t *ida_scan(void *start, std::size_t size, const char *signature); 12 | 13 | template 14 | T *aob_scan(void *start, std::size_t size, const char *signature, const char *mask) 15 | { 16 | return reinterpret_cast(utils::aob_scan(start, size, signature, mask)); 17 | } 18 | 19 | std::uint8_t *calc_rel2abs32(void *instruction_address, std::size_t instruction_size); 20 | std::int32_t calc_abs2rel32(void *instruction_address, std::size_t instruction_size, void *absolute_target); 21 | } -------------------------------------------------------------------------------- /utils/misc_utils.cpp: -------------------------------------------------------------------------------- 1 | #include "misc_utils.h" 2 | #include 3 | #include 4 | 5 | std::wstring utils::random_str(int length, std::wstring_view char_set) 6 | { 7 | std::srand(static_cast(std::time(nullptr))); 8 | const std::size_t set_max_idx = char_set.length(); 9 | std::wstring result; 10 | result.reserve(length + 1); 11 | 12 | for (int i = 0; i < length; i++) 13 | result += char_set[std::rand() % set_max_idx]; 14 | 15 | return result; 16 | } 17 | 18 | #pragma warning (disable: 28159) 19 | 20 | utils::fader_float::fader_float(float fadeout_duration_, float duration_) 21 | : fadeout_duration(fadeout_duration_), duration(duration_) 22 | { 23 | } 24 | 25 | void utils::fader_float::mark(float duration_) 26 | { 27 | if (duration_) 28 | this->duration = duration_; 29 | 30 | this->duration_absolute = static_cast(GetTickCount()) + this->duration + this->fadeout_duration; 31 | } 32 | 33 | float utils::fader_float::get() 34 | { 35 | return static_cast(this->duration_absolute - GetTickCount()) / this->fadeout_duration; 36 | } 37 | 38 | #pragma warning (default: 28159) 39 | -------------------------------------------------------------------------------- /utils/misc_utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | namespace utils 7 | { 8 | std::wstring random_str(int length = 12, std::wstring_view char_set = L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"); 9 | 10 | class fader_float 11 | { 12 | public: 13 | fader_float(float fadeout_duration_, float duration_ = 0.f); 14 | 15 | void mark(float duration_ = 0.f); 16 | float get(); 17 | 18 | private: 19 | float fadeout_duration = 0.f; 20 | float duration = 0.f; 21 | float duration_absolute = 0; 22 | }; 23 | } -------------------------------------------------------------------------------- /utils/utils.vcxitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | {a2d09ac9-23c1-4b03-af08-2ef6798147e3} 7 | 8 | 9 | 10 | %(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory) 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /utils/utils.vcxitems.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /utils/winapi_helper.cpp: -------------------------------------------------------------------------------- 1 | #include "winapi_helper.h" 2 | #include 3 | 4 | bool utils::enumerate_modules(void *proc_handle, enumerate_modules_callback_t callback) 5 | { 6 | if (!proc_handle) 7 | return false; 8 | 9 | HMODULE proc_modules[1024] = { nullptr }; 10 | DWORD module_size_total = NULL; 11 | 12 | if (!EnumProcessModules(proc_handle, proc_modules, sizeof(proc_modules), &module_size_total)) 13 | return false; 14 | 15 | for (int i = 0; i < module_size_total / sizeof(HMODULE); i++) 16 | { 17 | wchar_t module_name[MAX_PATH] = { L'\0' }; 18 | if (GetModuleFileNameEx(proc_handle, proc_modules[i], module_name, sizeof(module_name) / sizeof(wchar_t))) 19 | if (!callback(proc_modules[i], module_name)) 20 | break; 21 | } 22 | 23 | return true; 24 | } 25 | 26 | utils::open_winthread::open_winthread(DWORD thread_id) 27 | : id(thread_id) 28 | { 29 | this->thread_handle = OpenThread(THREAD_ALL_ACCESS, false, thread_id); 30 | } 31 | 32 | utils::open_winthread::~open_winthread() 33 | { 34 | if (this->thread_handle) 35 | CloseHandle(this->thread_handle); 36 | } 37 | 38 | bool utils::open_winthread::suspend() 39 | { 40 | return SuspendThread(this->thread_handle) != 0xFFFFFFFF; 41 | } 42 | 43 | bool utils::open_winthread::resume() 44 | { 45 | return ResumeThread(this->thread_handle) != 0xFFFFFFFF; 46 | } 47 | 48 | utils::remote_allocate::remote_allocate(HANDLE proc_handle_, std::size_t alloc_size_, DWORD page_prot_) 49 | : proc_handle(proc_handle_), alloc_size(alloc_size_), page_prot(page_prot_) 50 | { 51 | this->alloc(); 52 | } 53 | 54 | utils::remote_allocate::~remote_allocate() 55 | { 56 | if (this->ptr) 57 | this->free(); 58 | } 59 | 60 | bool utils::remote_allocate::alloc(HANDLE proc_handle_, std::size_t alloc_size_, DWORD page_prot_) 61 | { 62 | if (proc_handle_) 63 | this->proc_handle = proc_handle_; 64 | 65 | if (alloc_size_) 66 | this->alloc_size = alloc_size_; 67 | 68 | if (page_prot_) 69 | this->page_prot = page_prot_; 70 | 71 | this->ptr = VirtualAllocEx(proc_handle, nullptr, alloc_size, MEM_COMMIT | MEM_RESERVE, page_prot); 72 | return this->ptr != nullptr; 73 | } 74 | 75 | bool utils::remote_allocate::free() 76 | { 77 | if (this->proc_handle && this->ptr && VirtualFreeEx(proc_handle, this->ptr, NULL, MEM_RELEASE)) 78 | { 79 | this->ptr = nullptr; 80 | return true; 81 | } 82 | 83 | return false; 84 | } 85 | 86 | void utils::remote_allocate::leak() 87 | { 88 | this->proc_handle = nullptr; 89 | } 90 | 91 | std::wstring utils::get_full_path(std::wstring_view initial_path) 92 | { 93 | wchar_t path_buffer[MAX_PATH] = { '\0' }; 94 | 95 | if (!GetFullPathNameW(initial_path.data(), sizeof(path_buffer) / sizeof(wchar_t), path_buffer, nullptr)) 96 | return std::wstring(); 97 | 98 | return std::wstring(path_buffer); 99 | } 100 | 101 | utils::remote_execute::remote_execute(HANDLE proc_handle_, LPVOID routine_adr_, void *arg_ptr_) 102 | : proc_handle(proc_handle_), routine_adr(routine_adr_), arg_ptr(arg_ptr_) 103 | { 104 | } 105 | 106 | utils::remote_execute::~remote_execute() 107 | { 108 | if (this->crt_handle) 109 | { 110 | CloseHandle(this->crt_handle); 111 | this->crt_handle = nullptr; 112 | } 113 | } 114 | 115 | bool utils::remote_execute::execute(HANDLE proc_handle_, LPVOID routine_adr_, void *arg_ptr_) 116 | { 117 | if (proc_handle_) 118 | this->proc_handle = proc_handle_; 119 | 120 | if (routine_adr_) 121 | this->routine_adr = routine_adr_; 122 | 123 | if (arg_ptr_) 124 | this->arg_ptr = arg_ptr_; 125 | 126 | this->crt_handle = CreateRemoteThread(this->proc_handle, nullptr, NULL, reinterpret_cast(this->routine_adr), this->arg_ptr, NULL, nullptr); 127 | return this->crt_handle != nullptr; 128 | } 129 | 130 | void utils::remote_execute::wait(DWORD timeout) 131 | { 132 | if (this->crt_handle) 133 | WaitForSingleObject(this->crt_handle, timeout); 134 | } 135 | 136 | bool utils::remote_execute::execute_wait(DWORD timeout, HANDLE proc_handle_, LPVOID routine_adr_, void *arg_ptr_) 137 | { 138 | this->execute(proc_handle_, routine_adr_, arg_ptr_); 139 | this->wait(timeout); 140 | 141 | return this->crt_handle != nullptr; 142 | } 143 | 144 | utils::change_page_protection::change_page_protection(void *address_, std::size_t size_, DWORD new_page_protection) 145 | { 146 | this->is_success = VirtualProtect(address_, size_, new_page_protection, &this->old_prot); 147 | } 148 | 149 | utils::change_page_protection::~change_page_protection() 150 | { 151 | VirtualProtect(this->address, this->size, this->old_prot, &this->old_prot); 152 | } 153 | -------------------------------------------------------------------------------- /utils/winapi_helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace utils 9 | { 10 | using enumerate_modules_callback_t = bool(*)(void *handle, const wchar_t *modname); 11 | bool enumerate_modules(void *proc_handle, enumerate_modules_callback_t callback); 12 | 13 | class open_winthread 14 | { 15 | public: 16 | open_winthread(DWORD thread_id); 17 | ~open_winthread(); 18 | 19 | operator bool() const 20 | { 21 | return this->thread_handle != nullptr; 22 | } 23 | 24 | bool suspend(); 25 | bool resume(); 26 | 27 | const DWORD id = 0; 28 | 29 | private: 30 | HANDLE thread_handle = nullptr; 31 | }; 32 | 33 | class remote_allocate 34 | { 35 | public: 36 | remote_allocate() = default; 37 | remote_allocate(HANDLE proc_handle_, std::size_t alloc_size_, DWORD page_prot_ = PAGE_READWRITE); 38 | ~remote_allocate(); 39 | 40 | operator bool() const 41 | { 42 | return this->ptr != nullptr; 43 | } 44 | 45 | bool alloc(HANDLE proc_handle_ = nullptr, std::size_t alloc_size_ = 0, DWORD page_prot_ = NULL); 46 | bool free(); 47 | void leak(); 48 | 49 | LPVOID ptr = nullptr; 50 | 51 | private: 52 | HANDLE proc_handle = nullptr; 53 | std::size_t alloc_size = 0; 54 | DWORD page_prot = PAGE_READWRITE; 55 | }; 56 | 57 | class remote_execute 58 | { 59 | public: 60 | remote_execute() = default; 61 | remote_execute(HANDLE proc_handle_, LPVOID routine_adr_, void *arg_ptr_ = nullptr); 62 | ~remote_execute(); 63 | 64 | bool execute(HANDLE proc_handle_ = nullptr, LPVOID routine_adr_ = nullptr, void *arg_ptr_ = nullptr); 65 | void wait(DWORD timeout = INFINITE); 66 | bool execute_wait(DWORD timeout = INFINITE, HANDLE proc_handle_ = nullptr, LPVOID routine_adr_ = nullptr, void *arg_ptr_ = nullptr); 67 | 68 | private: 69 | HANDLE proc_handle = nullptr; 70 | LPVOID routine_adr = nullptr; 71 | void *arg_ptr = nullptr; 72 | HANDLE crt_handle = nullptr; 73 | }; 74 | 75 | class change_page_protection 76 | { 77 | public: 78 | change_page_protection(void *address_, std::size_t size_, DWORD new_page_protection); 79 | ~change_page_protection(); 80 | 81 | operator bool() const 82 | { 83 | return this->is_success; 84 | } 85 | 86 | private: 87 | void *address = nullptr; 88 | std::size_t size = 0; 89 | DWORD old_prot = 0; 90 | bool is_success = false; 91 | }; 92 | 93 | std::wstring get_full_path(std::wstring_view initial_path); 94 | } -------------------------------------------------------------------------------- /utils/winternal.cpp: -------------------------------------------------------------------------------- 1 | #include "winternal.h" 2 | 3 | std::unique_ptr utils::load_raw_pe_sections_to_local_memory(void *pe_bin) 4 | { 5 | if (!utils::pe_validate_dosheader(pe_bin)) 6 | return nullptr; 7 | 8 | auto nt_header = utils::pe_get_ntheaderptr(pe_bin); 9 | if (!nt_header) 10 | return nullptr; 11 | 12 | std::unique_ptr mapped_pe_sections = std::make_unique(nt_header->OptionalHeader.SizeOfImage); 13 | 14 | memcpy(mapped_pe_sections.get(), pe_bin, nt_header->OptionalHeader.SizeOfHeaders); 15 | 16 | PIMAGE_SECTION_HEADER sections = reinterpret_cast(nt_header + 1); 17 | for (int i = 0; i < nt_header->FileHeader.NumberOfSections; i++) 18 | memcpy(mapped_pe_sections.get() + sections[i].VirtualAddress, reinterpret_cast(pe_bin) + sections[i].PointerToRawData, sections[i].SizeOfRawData); 19 | 20 | return mapped_pe_sections; 21 | } 22 | --------------------------------------------------------------------------------