├── assets ├── icon.ico ├── icon.png ├── icon-v2.ai └── icon-v2.png ├── lib ├── DirectXTK.lib ├── ViGEmClient.lib ├── alt-minhook.lib ├── openxr_loader.lib └── libMinHook.x64.lib ├── third-party ├── ViGEm │ ├── Client.h │ ├── Util.h │ └── Common.h ├── DirectXTK │ ├── GraphicsMemory.h │ ├── ScreenGrab.h │ ├── CommonStates.h │ ├── SpriteBatch.h │ ├── Mouse.h │ ├── SpriteFont.h │ ├── PrimitiveBatch.h │ ├── BufferHelpers.h │ ├── WICTextureLoader.h │ ├── DDSTextureLoader.h │ ├── GeometricPrimitive.h │ ├── DirectXHelpers.h │ ├── PostProcess.h │ └── GamePad.h ├── OpenXR │ ├── openxr_platform_defines.h │ └── xrmath.h ├── minhook │ └── MinHook.h └── INI.h ├── src ├── BF2VR │ ├── dllmain.h │ ├── PixelShader.hlsl │ ├── VertexShader.hlsl │ ├── InputService.h │ ├── Utils.h │ ├── GameService.h │ ├── InputService.cpp │ ├── DirectXService.h │ ├── BF2VR.vcxproj.filters │ ├── dllmain.cpp │ ├── OpenXRService.h │ ├── Types.h │ ├── PixelShader.h │ ├── VertexShader.h │ └── Utils.cpp └── Injector │ ├── resource.h │ ├── DLL_Injector.vcxproj.filters │ ├── DLL_Injector.rc │ ├── DLL_Injector.vcxproj │ └── Source.cpp ├── .github └── FUNDING.yml ├── BF2VR.sln ├── .gitattributes ├── README.md └── .gitignore /assets/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/assets/icon.ico -------------------------------------------------------------------------------- /assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/assets/icon.png -------------------------------------------------------------------------------- /assets/icon-v2.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/assets/icon-v2.ai -------------------------------------------------------------------------------- /assets/icon-v2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/assets/icon-v2.png -------------------------------------------------------------------------------- /lib/DirectXTK.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/lib/DirectXTK.lib -------------------------------------------------------------------------------- /lib/ViGEmClient.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/lib/ViGEmClient.lib -------------------------------------------------------------------------------- /lib/alt-minhook.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/lib/alt-minhook.lib -------------------------------------------------------------------------------- /lib/openxr_loader.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/lib/openxr_loader.lib -------------------------------------------------------------------------------- /lib/libMinHook.x64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/lib/libMinHook.x64.lib -------------------------------------------------------------------------------- /third-party/ViGEm/Client.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ethanporcaro/BF2VR-Alpha/HEAD/third-party/ViGEm/Client.h -------------------------------------------------------------------------------- /src/BF2VR/dllmain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace BF2VR { 5 | static HMODULE OwnModule; 6 | static HWND OwnWindow; 7 | } -------------------------------------------------------------------------------- /src/Injector/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by DLL_Injector.rc 4 | // 5 | #define IDB_PNG1 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: IfanSnek 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: ethanporcaro 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /src/BF2VR/PixelShader.hlsl: -------------------------------------------------------------------------------- 1 | // PixelShader.hlsl - Shader for converting DirectX framebuffer to OpenXR compatible texture. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | SamplerState s0; 15 | Texture2D tex0; 16 | 17 | struct PS_INPUT 18 | { 19 | float4 Position : SV_Position; 20 | float2 TexCoords : TEXCOORD0; 21 | }; 22 | 23 | float4 PS(PS_INPUT input) : SV_Target0 24 | { 25 | return tex0.Sample(s0, input.TexCoords); 26 | } -------------------------------------------------------------------------------- /src/BF2VR/VertexShader.hlsl: -------------------------------------------------------------------------------- 1 | // VertexShader.hlsl - Shader for converting DirectX framebuffer to OpenXR compatible texture. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | struct VS_OUTPUT 15 | { 16 | float4 Position : SV_Position; 17 | float2 TexCoords : TEXCOORD0; 18 | }; 19 | 20 | VS_OUTPUT VS(uint id : SV_VertexID) { 21 | VS_OUTPUT output; 22 | output.TexCoords = float2((id << 1) & 2, id & 2); 23 | output.Position = float4(output.TexCoords.x * 2 - 1, -output.TexCoords.y * 2 + 1, 0, 1); 24 | 25 | return output; 26 | } -------------------------------------------------------------------------------- /src/BF2VR/InputService.h: -------------------------------------------------------------------------------- 1 | // InputService.h - Headers for the code that manages XInput input via 2 | // ViGEm. 3 | // Copyright(C) 2023 Ethan Porcaro 4 | 5 | // This program is free software : you can redistribute itand /or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | #include 16 | #include 17 | 18 | #include "../../third-party/ViGEm/Client.h" 19 | 20 | namespace BF2VR { 21 | class InputService { 22 | public: 23 | 24 | static inline short thumbLX = 0; 25 | static inline short thumbLY = 0; 26 | static inline byte leftTrigger = 0; 27 | static inline byte rightTrigger = 0; 28 | static inline WORD buttons = 0; 29 | static inline bool useRight = false; 30 | 31 | static bool connect(); 32 | static void update(); 33 | static void disconnect(); 34 | 35 | private: 36 | static inline PVIGEM_CLIENT pVigemClient; 37 | static inline PVIGEM_TARGET pVigemGamepad; 38 | }; 39 | } -------------------------------------------------------------------------------- /src/Injector/DLL_Injector.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;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 | 23 | 24 | Header Files 25 | 26 | 27 | 28 | 29 | Resource Files 30 | 31 | 32 | 33 | 34 | Resource Files 35 | 36 | 37 | -------------------------------------------------------------------------------- /third-party/DirectXTK/GraphicsMemory.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: GraphicsMemory.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | 22 | namespace DirectX 23 | { 24 | inline namespace DX11 25 | { 26 | class GraphicsMemory 27 | { 28 | public: 29 | #if defined(_XBOX_ONE) && defined(_TITLE) 30 | GraphicsMemory(_In_ ID3D11DeviceX* device, unsigned int backBufferCount = 2); 31 | #else 32 | GraphicsMemory(_In_ ID3D11Device* device, unsigned int backBufferCount = 2); 33 | #endif 34 | 35 | GraphicsMemory(GraphicsMemory&&) noexcept; 36 | GraphicsMemory& operator= (GraphicsMemory&&) noexcept; 37 | 38 | GraphicsMemory(GraphicsMemory const&) = delete; 39 | GraphicsMemory& operator=(GraphicsMemory const&) = delete; 40 | 41 | virtual ~GraphicsMemory(); 42 | 43 | void* __cdecl Allocate(_In_opt_ ID3D11DeviceContext* context, size_t size, int alignment); 44 | 45 | void __cdecl Commit(); 46 | 47 | // Singleton 48 | static GraphicsMemory& __cdecl Get(); 49 | 50 | private: 51 | // Private implementation. 52 | class Impl; 53 | 54 | std::unique_ptr pImpl; 55 | }; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Injector/DLL_Injector.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // English (United States) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 19 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 20 | #pragma code_page(1252) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // PNG 51 | // 52 | 53 | MAINICON ICON "..\\..\\assets\\icon.ico" 54 | 55 | #endif // English (United States) resources 56 | ///////////////////////////////////////////////////////////////////////////// 57 | 58 | 59 | 60 | #ifndef APSTUDIO_INVOKED 61 | ///////////////////////////////////////////////////////////////////////////// 62 | // 63 | // Generated from the TEXTINCLUDE 3 resource. 64 | // 65 | 66 | 67 | ///////////////////////////////////////////////////////////////////////////// 68 | #endif // not APSTUDIO_INVOKED 69 | 70 | -------------------------------------------------------------------------------- /third-party/DirectXTK/ScreenGrab.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: ScreenGrab.h 3 | // 4 | // Function for capturing a 2D texture and saving it to a file (aka a 'screenshot' 5 | // when used on a Direct3D Render Target). 6 | // 7 | // Note these functions are useful as a light-weight runtime screen grabber. For 8 | // full-featured texture capture, DDS writer, and texture processing pipeline, 9 | // see the 'Texconv' sample and the 'DirectXTex' library. 10 | // 11 | // Copyright (c) Microsoft Corporation. 12 | // Licensed under the MIT License. 13 | // 14 | // http://go.microsoft.com/fwlink/?LinkId=248926 15 | // http://go.microsoft.com/fwlink/?LinkId=248929 16 | //-------------------------------------------------------------------------------------- 17 | 18 | #pragma once 19 | 20 | #if defined(_XBOX_ONE) && defined(_TITLE) 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | #include 27 | 28 | #if defined(NTDDI_WIN10_FE) || defined(__MINGW32__) 29 | #include 30 | #else 31 | #include 32 | #endif 33 | 34 | #pragma comment(lib,"uuid.lib") 35 | 36 | 37 | namespace DirectX 38 | { 39 | HRESULT __cdecl SaveDDSTextureToFile( 40 | _In_ ID3D11DeviceContext* pContext, 41 | _In_ ID3D11Resource* pSource, 42 | _In_z_ const wchar_t* fileName) noexcept; 43 | 44 | HRESULT __cdecl SaveWICTextureToFile( 45 | _In_ ID3D11DeviceContext* pContext, 46 | _In_ ID3D11Resource* pSource, 47 | _In_ REFGUID guidContainerFormat, 48 | _In_z_ const wchar_t* fileName, 49 | _In_opt_ const GUID* targetFormat = nullptr, 50 | _In_opt_ std::function setCustomProps = nullptr, 51 | _In_ bool forceSRGB = false); 52 | } 53 | -------------------------------------------------------------------------------- /src/BF2VR/Utils.h: -------------------------------------------------------------------------------- 1 | // Utils.h - Headers for various utilities like logging, config loading and saving, 2 | // and a few math ones. 3 | // Copyright(C) 2023 Ethan Porcaro 4 | 5 | // This program is free software : you can redistribute itand /or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | #pragma once 16 | #include 17 | #include 18 | #include "Types.h" 19 | #include "../../third-party/minhook/MinHook.h" 20 | #include 21 | #include 22 | 23 | namespace BF2VR { 24 | 25 | inline HMODULE ownModule; 26 | inline HWND ownWindow; 27 | 28 | static std::ofstream logFile("logs.txt", std::ios_base::app); 29 | 30 | void log(std::string message); 31 | void error(std::string message); 32 | 33 | static inline int warnCount = 0; 34 | static inline std::string lastWarn = ""; 35 | void warn(std::string message); 36 | 37 | void success(std::string message); 38 | void info(std::string message); 39 | void deb(std::string message); 40 | 41 | void shutdown(); 42 | void shutdownNoHooks(); 43 | 44 | void loadConfig(); 45 | void saveConfig(); 46 | 47 | Vec3 eulerFromQuat(Vec4 q); 48 | Vec4 quatFromEuler(Vec3 e); 49 | 50 | // Config settings 51 | inline float RATIO = 1; 52 | inline float FOV = 90.0f; 53 | inline float FOVOverride = -1.f; 54 | inline int ConvergeOverride = -1; 55 | inline bool HEADAIM = false; 56 | 57 | const inline float PI = 3.14159265358979323846f; 58 | } -------------------------------------------------------------------------------- /src/BF2VR/GameService.h: -------------------------------------------------------------------------------- 1 | // GameService.h - Headers for the code that interacts with the reverse 2 | // engineered game memory structure. It also implements hooks into some 3 | // game functions. 4 | // Copyright(C) 2023 Ethan Porcaro 5 | 6 | // This program is free software : you can redistribute itand /or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | 16 | #pragma once 17 | #include "SDK.h" 18 | 19 | #pragma warning(disable: 4703) // Make the compiler shut up about null pointers that Minhook will assign 20 | 21 | namespace BF2VR { 22 | class GameService { 23 | public: 24 | static inline char* level = nullptr; 25 | 26 | static void updateCamera(Vec3 cameraLocation, Matrix4 cameraViewMatrix, float aimYaw, float aimPitch); 27 | 28 | static void updateBone(const char* boneName, Vec3 location = Vec3(0, 0, 0), Vec4 rotation = Vec4(0, 0, 0, 1)); 29 | 30 | static bool applyBones(); 31 | 32 | static bool enableHooks(); 33 | 34 | static void setUIDrawState(bool enabled); 35 | 36 | static bool worldToScreen(Vec3 world, Vec3& screen); 37 | 38 | private: 39 | typedef struct boneState 40 | { 41 | const char* boneName; 42 | Vec3 location; 43 | Vec4 rotation; 44 | Vec3 scale; 45 | } boneState; 46 | 47 | static inline Matrix4 cameraTransfrom; 48 | static inline std::vector boneStates; 49 | 50 | // Camera update hook 51 | typedef __int64(CameraUpdate)(class CameraObject*, class CameraObject*); 52 | static CameraUpdate cameraUpdateDetour; 53 | static inline CameraUpdate* cameraUpdateOriginal = nullptr; 54 | static inline void* pRenderView = nullptr; 55 | 56 | // Pose update hook 57 | typedef __int64(PoseUpdate)(int a1, int a2, int a3, int a4, __int64 a5); 58 | static PoseUpdate poseUpdateDetour; 59 | static inline PoseUpdate* poseUpdateOriginal = nullptr; 60 | static inline bool isPosing = false; 61 | }; 62 | } -------------------------------------------------------------------------------- /src/BF2VR/InputService.cpp: -------------------------------------------------------------------------------- 1 | // InputService.cpp - Code that manages XInput input via 2 | // ViGEm. 3 | // Copyright(C) 2023 Ethan Porcaro 4 | 5 | // This program is free software : you can redistribute itand /or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | #include "Utils.h" 16 | #include "InputService.h" 17 | 18 | #include 19 | 20 | namespace BF2VR { 21 | bool InputService::connect() { 22 | 23 | pVigemClient = vigem_alloc(); 24 | 25 | if (pVigemClient == nullptr) 26 | { 27 | error("Could not allocate memory for ViGEm."); 28 | return false; 29 | } 30 | 31 | const auto retval = vigem_connect(pVigemClient); 32 | if (!VIGEM_SUCCESS(retval)) 33 | { 34 | error("Could not conntect to ViGEm. Error: " + std::to_string(retval)); 35 | return false; 36 | } 37 | 38 | // Create a controller 39 | 40 | pVigemGamepad = vigem_target_x360_alloc(); 41 | const auto pir = vigem_target_add(pVigemClient, pVigemGamepad); 42 | 43 | if (!VIGEM_SUCCESS(pir)) 44 | { 45 | error("Could not plug in ViGEm gamepad. Error: " + std::to_string(pir)); 46 | return false; 47 | } 48 | 49 | return true; 50 | } 51 | 52 | void InputService::update() { 53 | 54 | XINPUT_GAMEPAD gamepad{}; 55 | if (useRight) 56 | { 57 | gamepad.sThumbRX = thumbLX; 58 | gamepad.sThumbRY = thumbLY; 59 | } 60 | else 61 | { 62 | gamepad.sThumbLX = thumbLX; 63 | gamepad.sThumbLY = thumbLY; 64 | } 65 | 66 | gamepad.bRightTrigger = rightTrigger; 67 | gamepad.bLeftTrigger = leftTrigger; 68 | gamepad.wButtons = buttons; 69 | 70 | VIGEM_ERROR err = vigem_target_x360_update(pVigemClient, pVigemGamepad, *reinterpret_cast(&gamepad)); 71 | if (!VIGEM_SUCCESS(err)) 72 | { 73 | warn("Could not update the virtual gamepad. Error: " + std::to_string(err)); 74 | } 75 | } 76 | 77 | void InputService::disconnect() { 78 | vigem_disconnect(pVigemClient); 79 | vigem_free(pVigemClient); 80 | } 81 | } -------------------------------------------------------------------------------- /src/BF2VR/DirectXService.h: -------------------------------------------------------------------------------- 1 | // DirectXService.h - Headers for the code that interacts with the DirectX API, including hooks and rendering. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | #pragma once 15 | 16 | #include 17 | #include "../../third-party/DirectXTK/PrimitiveBatch.h" 18 | #include "../../third-party/DirectXTK/VertexTypes.h" 19 | #include "../../third-party/DirectXTK/Effects.h" 20 | 21 | #include 22 | #include 23 | 24 | namespace BF2VR { 25 | class DirectXService { 26 | public: 27 | static inline ID3D11Device* pDevice = nullptr; 28 | static inline ID3D11DeviceContext* pContext = nullptr; 29 | static inline ID3D11Texture2D* pFrame = nullptr; 30 | 31 | static inline float crosshairX = 0; 32 | static inline float crosshairY = 0; 33 | 34 | static bool hookDirectX(); 35 | static void unhookDirectX(); 36 | static void renderOverlays(); 37 | static bool renderXRFrame(ID3D11Texture2D* pTexture, ID3D11RenderTargetView* pRTV); 38 | 39 | private: 40 | // Present hook 41 | typedef HRESULT(Present)(IDXGISwapChain* pInstance, UINT SyncInterval, UINT Flags); 42 | static Present presentDetour; 43 | static inline Present* pPresentTarget = nullptr; 44 | static inline Present* pPresentOriginal = nullptr; 45 | 46 | // renderOverlays 47 | static inline std::unique_ptr> batch; 48 | static inline std::unique_ptr effect; 49 | static inline ID3D11InputLayout* pInputLayout; 50 | 51 | // renderXRFrame 52 | static inline bool shadersCreated = false; 53 | static inline ID3D11VertexShader* pVertexShader = nullptr; 54 | static inline ID3D11PixelShader* pPixelShader = nullptr; 55 | static inline bool srvCreated = false; 56 | static inline ID3D11ShaderResourceView* pSRV = nullptr; 57 | static inline ID3D11Texture2D* pFrameCopy = nullptr; 58 | }; 59 | } -------------------------------------------------------------------------------- /BF2VR.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.3.32825.248 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BF2VR", "src\BF2VR\BF2VR.vcxproj", "{44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DLL_Injector", "src\Injector\DLL_Injector.vcxproj", "{E80316C9-A824-45FA-997F-491509A04AB7}" 9 | ProjectSection(ProjectDependencies) = postProject 10 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5} = {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5} 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|x64 = Release|x64 18 | Release|x86 = Release|x86 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Debug|x64.ActiveCfg = Debug|x64 22 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Debug|x64.Build.0 = Debug|x64 23 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Debug|x86.ActiveCfg = Debug|Win32 24 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Debug|x86.Build.0 = Debug|Win32 25 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Release|x64.ActiveCfg = Release|x64 26 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Release|x64.Build.0 = Release|x64 27 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Release|x86.ActiveCfg = Release|Win32 28 | {44A45E6D-FDB8-4B50-8520-D1A4F1E61FB5}.Release|x86.Build.0 = Release|Win32 29 | {E80316C9-A824-45FA-997F-491509A04AB7}.Debug|x64.ActiveCfg = Debug|x64 30 | {E80316C9-A824-45FA-997F-491509A04AB7}.Debug|x64.Build.0 = Debug|x64 31 | {E80316C9-A824-45FA-997F-491509A04AB7}.Debug|x86.ActiveCfg = Debug|Win32 32 | {E80316C9-A824-45FA-997F-491509A04AB7}.Debug|x86.Build.0 = Debug|Win32 33 | {E80316C9-A824-45FA-997F-491509A04AB7}.Release|x64.ActiveCfg = Release|x64 34 | {E80316C9-A824-45FA-997F-491509A04AB7}.Release|x64.Build.0 = Release|x64 35 | {E80316C9-A824-45FA-997F-491509A04AB7}.Release|x86.ActiveCfg = Release|Win32 36 | {E80316C9-A824-45FA-997F-491509A04AB7}.Release|x86.Build.0 = Release|Win32 37 | EndGlobalSection 38 | GlobalSection(SolutionProperties) = preSolution 39 | HideSolutionNode = FALSE 40 | EndGlobalSection 41 | GlobalSection(ExtensibilityGlobals) = postSolution 42 | SolutionGuid = {6F3CD8CF-B4A4-4438-85DB-3E382418BA9C} 43 | EndGlobalSection 44 | EndGlobal 45 | -------------------------------------------------------------------------------- /third-party/DirectXTK/CommonStates.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: CommonStates.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #include 19 | 20 | 21 | namespace DirectX 22 | { 23 | inline namespace DX11 24 | { 25 | class CommonStates 26 | { 27 | public: 28 | explicit CommonStates(_In_ ID3D11Device* device); 29 | 30 | CommonStates(CommonStates&&) noexcept; 31 | CommonStates& operator= (CommonStates&&) noexcept; 32 | 33 | CommonStates(CommonStates const&) = delete; 34 | CommonStates& operator= (CommonStates const&) = delete; 35 | 36 | virtual ~CommonStates(); 37 | 38 | // Blend states. 39 | ID3D11BlendState* __cdecl Opaque() const; 40 | ID3D11BlendState* __cdecl AlphaBlend() const; 41 | ID3D11BlendState* __cdecl Additive() const; 42 | ID3D11BlendState* __cdecl NonPremultiplied() const; 43 | 44 | // Depth stencil states. 45 | ID3D11DepthStencilState* __cdecl DepthNone() const; 46 | ID3D11DepthStencilState* __cdecl DepthDefault() const; 47 | ID3D11DepthStencilState* __cdecl DepthRead() const; 48 | ID3D11DepthStencilState* __cdecl DepthReverseZ() const; 49 | ID3D11DepthStencilState* __cdecl DepthReadReverseZ() const; 50 | 51 | // Rasterizer states. 52 | ID3D11RasterizerState* __cdecl CullNone() const; 53 | ID3D11RasterizerState* __cdecl CullClockwise() const; 54 | ID3D11RasterizerState* __cdecl CullCounterClockwise() const; 55 | ID3D11RasterizerState* __cdecl Wireframe() const; 56 | 57 | // Sampler states. 58 | ID3D11SamplerState* __cdecl PointWrap() const; 59 | ID3D11SamplerState* __cdecl PointClamp() const; 60 | ID3D11SamplerState* __cdecl LinearWrap() const; 61 | ID3D11SamplerState* __cdecl LinearClamp() const; 62 | ID3D11SamplerState* __cdecl AnisotropicWrap() const; 63 | ID3D11SamplerState* __cdecl AnisotropicClamp() const; 64 | 65 | private: 66 | // Private implementation. 67 | class Impl; 68 | 69 | std::shared_ptr pImpl; 70 | }; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /src/BF2VR/BF2VR.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 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Header Files 40 | 41 | 42 | Header Files 43 | 44 | 45 | Header Files 46 | 47 | 48 | Header Files 49 | 50 | 51 | Header Files 52 | 53 | 54 | Header Files 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | 67 | 68 | Resource Files 69 | 70 | 71 | Resource Files 72 | 73 | 74 | -------------------------------------------------------------------------------- /third-party/ViGEm/Util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ViGEm/Common.h" 4 | #include 5 | 6 | VOID FORCEINLINE XUSB_TO_DS4_REPORT( 7 | _Out_ PXUSB_REPORT Input, 8 | _Out_ PDS4_REPORT Output 9 | ) 10 | { 11 | if (Input->wButtons & XUSB_GAMEPAD_BACK) Output->wButtons |= DS4_BUTTON_SHARE; 12 | if (Input->wButtons & XUSB_GAMEPAD_START) Output->wButtons |= DS4_BUTTON_OPTIONS; 13 | if (Input->wButtons & XUSB_GAMEPAD_LEFT_THUMB) Output->wButtons |= DS4_BUTTON_THUMB_LEFT; 14 | if (Input->wButtons & XUSB_GAMEPAD_RIGHT_THUMB) Output->wButtons |= DS4_BUTTON_THUMB_RIGHT; 15 | if (Input->wButtons & XUSB_GAMEPAD_LEFT_SHOULDER) Output->wButtons |= DS4_BUTTON_SHOULDER_LEFT; 16 | if (Input->wButtons & XUSB_GAMEPAD_RIGHT_SHOULDER) Output->wButtons |= DS4_BUTTON_SHOULDER_RIGHT; 17 | if (Input->wButtons & XUSB_GAMEPAD_GUIDE) Output->bSpecial |= DS4_SPECIAL_BUTTON_PS; 18 | if (Input->wButtons & XUSB_GAMEPAD_A) Output->wButtons |= DS4_BUTTON_CROSS; 19 | if (Input->wButtons & XUSB_GAMEPAD_B) Output->wButtons |= DS4_BUTTON_CIRCLE; 20 | if (Input->wButtons & XUSB_GAMEPAD_X) Output->wButtons |= DS4_BUTTON_SQUARE; 21 | if (Input->wButtons & XUSB_GAMEPAD_Y) Output->wButtons |= DS4_BUTTON_TRIANGLE; 22 | 23 | Output->bTriggerL = Input->bLeftTrigger; 24 | Output->bTriggerR = Input->bRightTrigger; 25 | 26 | if (Input->bLeftTrigger > 0)Output->wButtons |= DS4_BUTTON_TRIGGER_LEFT; 27 | if (Input->bRightTrigger > 0)Output->wButtons |= DS4_BUTTON_TRIGGER_RIGHT; 28 | 29 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_UP) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_NORTH); 30 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_RIGHT) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_EAST); 31 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_DOWN) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_SOUTH); 32 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_LEFT) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_WEST); 33 | 34 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_UP 35 | && Input->wButtons & XUSB_GAMEPAD_DPAD_RIGHT) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_NORTHEAST); 36 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_RIGHT 37 | && Input->wButtons & XUSB_GAMEPAD_DPAD_DOWN) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_SOUTHEAST); 38 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_DOWN 39 | && Input->wButtons & XUSB_GAMEPAD_DPAD_LEFT) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_SOUTHWEST); 40 | if (Input->wButtons & XUSB_GAMEPAD_DPAD_LEFT 41 | && Input->wButtons & XUSB_GAMEPAD_DPAD_UP) DS4_SET_DPAD(Output, DS4_BUTTON_DPAD_NORTHWEST); 42 | 43 | Output->bThumbLX = ((Input->sThumbLX + ((USHRT_MAX / 2) + 1)) / 257); 44 | Output->bThumbLY = (-(Input->sThumbLY + ((USHRT_MAX / 2) - 1)) / 257); 45 | Output->bThumbLY = (Output->bThumbLY == 0) ? 0xFF : Output->bThumbLY; 46 | Output->bThumbRX = ((Input->sThumbRX + ((USHRT_MAX / 2) + 1)) / 257); 47 | Output->bThumbRY = (-(Input->sThumbRY + ((USHRT_MAX / 2) + 1)) / 257); 48 | Output->bThumbRY = (Output->bThumbRY == 0) ? 0xFF : Output->bThumbRY; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/BF2VR/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp - Entry point and main setup/loop for the mod. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | #include "DirectXService.h" 15 | #include "OpenXRService.h" 16 | #include "GameService.h" 17 | #include "InputService.h" 18 | #include "Utils.h" 19 | 20 | using namespace BF2VR; 21 | 22 | // Main mod thread 23 | DWORD __stdcall mainThread(HMODULE module) 24 | { 25 | ownModule = module; 26 | 27 | AllocConsole(); 28 | freopen("CONOUT$", "w", stdout); 29 | 30 | time_t my_time = time(NULL); 31 | std::cout << "New startup at " << ctime(&my_time) << std::endl; 32 | logFile << std::endl << std::endl << "New startup at " << ctime(&my_time) << std::endl; 33 | 34 | log("Attempting to find Battlefront window ..."); 35 | ownWindow = FindWindowA("Frostbite", "STAR WARS Battlefront II"); 36 | if (!ownWindow) 37 | { 38 | error("Couldn't find window."); 39 | shutdownNoHooks(); 40 | return 1; 41 | } 42 | else { 43 | success("Found window."); 44 | } 45 | 46 | loadConfig(); 47 | 48 | // Eye resolution stuff 49 | RECT desktop; 50 | GetWindowRect(ownWindow, &desktop); 51 | 52 | OpenXRService::eyeWidth = desktop.right; 53 | OpenXRService::eyeHeight = desktop.bottom; 54 | 55 | MH_Initialize(); 56 | 57 | // Initialize OpenXR 58 | log("Attempting to initialize OpenXR ..."); 59 | if (!OpenXRService::createXRInstance()) { 60 | error("Unable to initialize vr"); 61 | shutdownNoHooks(); 62 | return 1; 63 | } 64 | else { 65 | success("Initialized OpenXR."); 66 | } 67 | 68 | // Hook DirectX. Present will be the main logic loop. 69 | log("Attempting to hook DirectX ..."); 70 | if (!DirectXService::hookDirectX()) { 71 | error("Unable to Hook DirectX."); 72 | shutdownNoHooks(); 73 | return 1; 74 | } 75 | else { 76 | success("Hooked DirectX."); 77 | } 78 | 79 | log("Attempting to start ViGEm ..."); 80 | if (!InputService::connect()) { 81 | error("Unable to start ViGEm."); 82 | DirectXService::unhookDirectX(); 83 | shutdownNoHooks(); 84 | return 1; 85 | } 86 | else { 87 | success("Started ViGEm."); 88 | } 89 | 90 | log("Attempting to hook the BF2 Camera ..."); 91 | if (!GameService::enableHooks()) { 92 | error("Unable to Hook the BF2 Camera."); 93 | shutdown(); 94 | return 1; 95 | } 96 | else { 97 | success("Hooked the BF2 Camera."); 98 | } 99 | 100 | info("Started Sucessfully"); 101 | 102 | for (;;) { 103 | Sleep(200); 104 | if (GetAsyncKeyState(VK_END)) { 105 | shutdown(); 106 | return 0; 107 | } 108 | if (GetAsyncKeyState(VK_HOME)) { 109 | loadConfig(); 110 | } 111 | } 112 | return 0; 113 | } 114 | 115 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) 116 | { 117 | switch (ul_reason_for_call) 118 | { 119 | case DLL_PROCESS_ATTACH: 120 | CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)mainThread, hModule, NULL, NULL); 121 | case DLL_THREAD_ATTACH: 122 | case DLL_THREAD_DETACH: 123 | case DLL_PROCESS_DETACH: 124 | break; 125 | } 126 | return TRUE; 127 | } -------------------------------------------------------------------------------- /src/BF2VR/OpenXRService.h: -------------------------------------------------------------------------------- 1 | // OpenXRService.h - Headers for the code that interacts with the OpenXR runtime. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | #pragma once 15 | 16 | #define XR_USE_GRAPHICS_API_D3D11 17 | #define XR_USE_PLATFORM_WIN32 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../../third-party/OpenXR/openxr.h" 25 | #include "../../third-party/OpenXR/openxr_platform.h" 26 | #include "../../third-party/OpenXR/xrmath.h" 27 | 28 | #include "SDK.h" 29 | 30 | namespace BF2VR { 31 | class OpenXRService { 32 | public: 33 | static inline XrInstance xrInstance; 34 | static inline XrSession xrSession; 35 | static inline std::vector xrSwapchains; 36 | static inline std::map> xrRTVs; 37 | 38 | static inline int eyeWidth; 39 | static inline int eyeHeight; 40 | 41 | static inline bool onLeftEye = true; 42 | static inline bool isVRReady = false; 43 | 44 | static inline bool isFiring = false; 45 | static inline bool showUI = true; 46 | static inline bool isPressingMenu = false; 47 | 48 | static inline bool shouldStop = false; 49 | static inline bool stopping = false; 50 | 51 | static bool createXRInstance(); 52 | static bool createXRSession(); 53 | static bool beginXRSession(); 54 | static bool prepareActions(); 55 | static void consumeEvents(); 56 | static bool beginFrame(); 57 | static bool submitFrame(ID3D11Texture2D* pTexture); 58 | static bool updateActions(); 59 | static bool updatePoses(); 60 | static bool endFrame(); 61 | static void endXR(); 62 | 63 | private: 64 | 65 | // CreateXRInstanceWithExtensions 66 | static inline XrEnvironmentBlendMode xrBlend = {}; 67 | 68 | // BeginXRSession 69 | static inline XrSystemId xrSystemId = XR_NULL_SYSTEM_ID; 70 | static inline XrSpace xrAppSpace = {}; 71 | static inline uint32_t xrViewCount = 0; 72 | static inline std::vector xrConfigViews; 73 | static inline std::vector xrViews; 74 | static inline XrFrameState xrFrameState = {}; 75 | static inline uint32_t xrProjectionViewCount = 0; 76 | static inline std::vector xrProjectionViews; 77 | 78 | // PrepareActions 79 | static inline XrActionSet actionSet; 80 | 81 | static inline std::array handPaths; 82 | static inline std::array triggerPaths; 83 | static inline std::array gripPaths; 84 | static inline XrPath basicPath; 85 | static inline XrPath walkPath; 86 | static inline XrPath rollPath; 87 | static inline XrPath jumpPath; 88 | static inline XrPath reloadPath; 89 | 90 | static inline XrAction poseAction; 91 | static inline XrAction triggerAction; 92 | static inline XrAction gripAction; 93 | static inline XrAction basicAction; 94 | static inline XrAction walkAction; 95 | static inline XrAction rollAction; 96 | static inline XrAction jumpAction; 97 | static inline XrAction reloadAction; 98 | 99 | static inline XrSpace poseActionSpaces[2]; 100 | 101 | // Action values 102 | static inline XrSpaceLocation handLocations[2]; 103 | static inline XrActionStateFloat grabValue[2]; 104 | static inline XrActionStateFloat gripValue[2]; 105 | static inline XrActionStateBoolean basicValue; 106 | static inline XrActionStateVector2f walkValue; 107 | static inline XrActionStateBoolean rollValue; 108 | static inline XrActionStateBoolean jumpValue; 109 | static inline XrActionStateBoolean reloadValue; 110 | }; 111 | } -------------------------------------------------------------------------------- /third-party/OpenXR/openxr_platform_defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (c) 2017-2023, The Khronos Group Inc. 3 | ** 4 | ** SPDX-License-Identifier: Apache-2.0 OR MIT 5 | */ 6 | 7 | #ifndef OPENXR_PLATFORM_DEFINES_H_ 8 | #define OPENXR_PLATFORM_DEFINES_H_ 1 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | /* Platform-specific calling convention macros. 15 | * 16 | * Platforms should define these so that OpenXR clients call OpenXR functions 17 | * with the same calling conventions that the OpenXR implementation expects. 18 | * 19 | * XRAPI_ATTR - Placed before the return type in function declarations. 20 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 21 | * XRAPI_CALL - Placed after the return type in function declarations. 22 | * Useful for MSVC-style calling convention syntax. 23 | * XRAPI_PTR - Placed between the '(' and '*' in function pointer types. 24 | * 25 | * Function declaration: XRAPI_ATTR void XRAPI_CALL xrFunction(void); 26 | * Function pointer type: typedef void (XRAPI_PTR *PFN_xrFunction)(void); 27 | */ 28 | #if defined(_WIN32) 29 | #define XRAPI_ATTR 30 | // On Windows, functions use the stdcall convention 31 | #define XRAPI_CALL __stdcall 32 | #define XRAPI_PTR XRAPI_CALL 33 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 34 | #error "API not supported for the 'armeabi' NDK ABI" 35 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 36 | // On Android 32-bit ARM targets, functions use the "hardfloat" 37 | // calling convention, i.e. float parameters are passed in registers. This 38 | // is true even if the rest of the application passes floats on the stack, 39 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 40 | #define XRAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 41 | #define XRAPI_CALL 42 | #define XRAPI_PTR XRAPI_ATTR 43 | #else 44 | // On other platforms, use the default calling convention 45 | #define XRAPI_ATTR 46 | #define XRAPI_CALL 47 | #define XRAPI_PTR 48 | #endif 49 | 50 | #include 51 | 52 | #if !defined(XR_NO_STDINT_H) 53 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 54 | typedef signed __int8 int8_t; 55 | typedef unsigned __int8 uint8_t; 56 | typedef signed __int16 int16_t; 57 | typedef unsigned __int16 uint16_t; 58 | typedef signed __int32 int32_t; 59 | typedef unsigned __int32 uint32_t; 60 | typedef signed __int64 int64_t; 61 | typedef unsigned __int64 uint64_t; 62 | #else 63 | #include 64 | #endif 65 | #endif // !defined( XR_NO_STDINT_H ) 66 | 67 | // XR_PTR_SIZE (in bytes) 68 | #if (defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__) ) || defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)) 69 | #define XR_PTR_SIZE 8 70 | #else 71 | #define XR_PTR_SIZE 4 72 | #endif 73 | 74 | // Needed so we can use clang __has_feature portably. 75 | #if !defined(XR_COMPILER_HAS_FEATURE) 76 | #if defined(__clang__) 77 | #define XR_COMPILER_HAS_FEATURE(x) __has_feature(x) 78 | #else 79 | #define XR_COMPILER_HAS_FEATURE(x) 0 80 | #endif 81 | #endif 82 | 83 | // Identifies if the current compiler has C++11 support enabled. 84 | // Does not by itself identify if any given C++11 feature is present. 85 | #if !defined(XR_CPP11_ENABLED) && defined(__cplusplus) 86 | #if defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) 87 | #define XR_CPP11_ENABLED 1 88 | #elif defined(_MSC_VER) && (_MSC_VER >= 1600) 89 | #define XR_CPP11_ENABLED 1 90 | #elif (__cplusplus >= 201103L) // 201103 is the first C++11 version. 91 | #define XR_CPP11_ENABLED 1 92 | #endif 93 | #endif 94 | 95 | // Identifies if the current compiler supports C++11 nullptr. 96 | #if !defined(XR_CPP_NULLPTR_SUPPORTED) 97 | #if defined(XR_CPP11_ENABLED) && \ 98 | ((defined(__clang__) && XR_COMPILER_HAS_FEATURE(cxx_nullptr)) || \ 99 | (defined(__GNUC__) && (((__GNUC__ * 1000) + __GNUC_MINOR__) >= 4006)) || \ 100 | (defined(_MSC_VER) && (_MSC_VER >= 1600)) || \ 101 | (defined(__EDG_VERSION__) && (__EDG_VERSION__ >= 403))) 102 | #define XR_CPP_NULLPTR_SUPPORTED 1 103 | #endif 104 | #endif 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /src/BF2VR/Types.h: -------------------------------------------------------------------------------- 1 | // Types.h - Basic types for Frostbyte 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | #pragma once 15 | #include 16 | 17 | struct Vec2 { 18 | float x; 19 | float y; 20 | }; 21 | 22 | struct Vec3 { 23 | float x; 24 | float y; 25 | float z; 26 | 27 | Vec3 operator+(Vec3 v2) 28 | { 29 | v2.x += x; 30 | v2.y += y; 31 | v2.z += z; 32 | 33 | return v2; 34 | } 35 | 36 | Vec3 operator*(Vec3 v2) 37 | { 38 | v2.x *= x; 39 | v2.y *= y; 40 | v2.z *= z; 41 | 42 | return v2; 43 | } 44 | 45 | Vec3 operator-(Vec3 v2) 46 | { 47 | Vec3 v1 = Vec3(x, y, z); 48 | v1.x -= v2.x; 49 | v1.y -= v2.y; 50 | v1.z -= v2.z; 51 | 52 | return v1; 53 | } 54 | 55 | std::string toString() 56 | { 57 | return std::format("X={:.4f} Y={:.4f} Z={:.4f}", x, y, z); 58 | } 59 | }; 60 | 61 | struct Vec4 { 62 | float x; 63 | float y; 64 | float z; 65 | float w; 66 | 67 | Vec4 rotateByEuler(float eulerX, float eulerY, float eulerZ) { 68 | // Convert Euler angles to quaternion 69 | Vec4 eulerQuat; 70 | float cosX = cos(eulerX / 2); 71 | float sinX = sin(eulerX / 2); 72 | float cosY = cos(eulerY / 2); 73 | float sinY = sin(eulerY / 2); 74 | float cosZ = cos(eulerZ / 2); 75 | float sinZ = sin(eulerZ / 2); 76 | eulerQuat.w = cosX * cosY * cosZ + sinX * sinY * sinZ; 77 | eulerQuat.x = sinX * cosY * cosZ - cosX * sinY * sinZ; 78 | eulerQuat.y = cosX * sinY * cosZ + sinX * cosY * sinZ; 79 | eulerQuat.z = cosX * cosY * sinZ - sinX * sinY * cosZ; 80 | 81 | // Multiply original quaternion by Euler angle quaternion to apply rotation 82 | Vec4 rotatedQuat; 83 | rotatedQuat.w = w * eulerQuat.w - x * eulerQuat.x - y * eulerQuat.y - z * eulerQuat.z; 84 | rotatedQuat.x = w * eulerQuat.x + x * eulerQuat.w + y * eulerQuat.z - z * eulerQuat.y; 85 | rotatedQuat.y = w * eulerQuat.y - x * eulerQuat.z + y * eulerQuat.w + z * eulerQuat.x; 86 | rotatedQuat.z = w * eulerQuat.z + x * eulerQuat.y - y * eulerQuat.x + z * eulerQuat.w; 87 | 88 | return rotatedQuat; 89 | } 90 | 91 | Vec4 operator*(Vec4 v2) 92 | { 93 | Vec4 v1 = Vec4(x, y, z, w); 94 | v1.x *= v2.x; 95 | v1.y *= v2.y; 96 | v1.z *= v2.z; 97 | v1.w *= v2.w; 98 | 99 | return v1; 100 | } 101 | 102 | Vec4 operator/(Vec4 v2) 103 | { 104 | Vec4 v1 = Vec4(x, y, z, w); 105 | v1.x /= v2.x; 106 | v1.y /= v2.y; 107 | v1.z /= v2.z; 108 | v1.w /= v2.w; 109 | 110 | return v1; 111 | } 112 | 113 | Vec4 operator+(Vec4 v2) 114 | { 115 | v2.x += x; 116 | v2.y += y; 117 | v2.z += z; 118 | v2.w += w; 119 | 120 | return v2; 121 | } 122 | 123 | Vec3 dropW() 124 | { 125 | return Vec3(x, y, z); 126 | } 127 | 128 | std::string toString() 129 | { 130 | return std::format("X={:.4f} Y={:.4f} Z={:.4f} W={:.4f}", x, y, z, w); 131 | } 132 | }; 133 | 134 | static inline Vec3 rotateAround(Vec3 point, Vec3 pivot, float rad) 135 | { 136 | Vec3 out = Vec3(point); 137 | 138 | out.x = pivot.x + (cos(rad) * (point.x - pivot.x)) - (sin(rad) * (point.z - pivot.z)); 139 | out.z = pivot.z + (sin(rad) * (point.x - pivot.x)) + (cos(rad) * (point.z - pivot.z)); 140 | 141 | return out; 142 | } 143 | 144 | static inline Vec4 appendW(Vec3 v2, float w = 0.f) 145 | { 146 | Vec4 v1; 147 | v1.x = v2.x; 148 | v1.y = v2.y; 149 | v1.z = v2.z; 150 | v1.w = w; 151 | return v1; 152 | } 153 | 154 | struct Matrix4 { 155 | Vec4 x; 156 | Vec4 y; 157 | Vec4 z; 158 | Vec4 o; 159 | }; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BF2VR 2 | ### VR Mod for Star Wars: Battlefront II 3 | #### Note this is a work-in-progress 4 | 5 | 6 | [![](https://img.shields.io/badge/Discord-Releases%20-blueviolet)](https://discord.gg/mrKYwzd3N4) 7 | 8 | # About 9 | Battlefront II VR (BF2VR) is a project by developer, musician, and Star Wars enthusiast [Ethan Porcaro](https://ethanporcaro.com/). He has played Battlefront II for a while, and after being inspired by [praydog](https://github.com/praydog)'s upcoming Unreal Engine VR Injector, decided to see what would be possible to mod in the Frostbite Engine. 10 | 11 | BF2VR started with code from [OpenGameCamera](https://github.com/coltonon/OpenGameCamera) to position the Battlefront Camera to the transformation matrix from the OpenVR API. The game's DirectX calls were intercepted to get access to the framebuffer, which was then sent to the VR screen. Stereoscopy was provided using Alternate Eye Rendering, a technique in which the rendered eye alternates every frame while the game camera shifts left and right to give a sense of depth. The game "Soldier" was also hooked to aim where the player looked. 12 | 13 | New updates led the mod to be ported to [OpenXR](https://www.khronos.org/openxr/), a standard for XR runtime interaction. This improves performance and compatibility. Motion controls were added, allowing the player to aim with a controller rather than the headset. 14 | 15 | BF2VR is in early alpha, with frequent updates but limited features. Releases to the mod can be found at Ethan's [Discord Server](https://discord.gg/mrKYwzd3N4). Keep in mind that the mod is unstable, and you won't get all the features a VR mod should include just yet. 16 | 17 | # Using the mod 18 | ## Installation and setup 19 | See [https://ifansnek.github.io/BF2VR-Docs/setup.html](https://ifansnek.github.io/BF2VR-Docs/setup.html). 20 | 21 | ## Playing the game 22 | Most modes work in the game, with the following limitations: 23 | * Mountable vehicles or turrets do not work yet. Mountable meaning the character model is also present. Eg. speeders don't work but X-wings do. Vehicles don't work *well* yet. 24 | * **DO NOT** play multiplayer, as you risk **getting banned**. Please use [3rd party Kyber Servers](http://kyber.gg/) instead. 25 | * Characters that do not support 1st person work, but a little bit weirdly. 26 | * The campaign has lots of custom vehicles and modes that are incompatible with the mod currently. It is not recommended to play it yet. 27 | 28 | Because the mod is still being worked on, you may experience random errors and crashes. Please report these. 29 | 30 | ### Hotkeys 31 | * END: Attempts to eject the mod while keeping the game open. This sometimes crashes. 32 | * HOME: This will reload and apply the configuration. 33 | 34 | # Contributing 35 | This code is open source. Please read the license if you want to fork. Contributions are welcome. 36 | ## Code structure 37 | The code is split into the launcher and the mod DLL. The launcher is a single simple file. This explanation is for the mod DLL. 38 | 39 | The different parts of the mod each have their own class in the BF2VR namespace. These "services" are: 40 | 41 | ### DirectXService 42 | This is responsible for managing hooks and calls related to DirectX. This includes: 43 | * Hooking `Present()` from the original game. 44 | * Drawing the presented buffer onto a fullscreen quad for OpenXR 45 | * Drawing the crosshair over the quad. 46 | 47 | ### OpenXRService 48 | This is responsible for OpenXR code including: 49 | * Initialization 50 | * Reading input 51 | * Submitting frames 52 | 53 | ### GameService 54 | This manages hooks and memory structure as defined in `sdk.h`. Things like: 55 | * Setting the render view matrix. 56 | * Setting the aim rotation. 57 | * Toggling visibility of the game UI. 58 | 59 | ### InputService 60 | Manages gamepad input using [ViGEm](https://github.com/ViGEm/ViGEmBus). 61 | 62 | ### Utils 63 | Here are some useful utilities 64 | * #### log (and others) 65 | Logs a message to the console and `logs.txt`. Styles text color based on the logging type. 66 | 67 | * #### IsValidPtr 68 | Checks if a pointer is not null and has a valid memory range. 69 | 70 | * #### Shutdown 71 | Attempts to eject the mod from a hooked state by shutting down used hooks. 72 | 73 | * #### ShutdownNoHooks 74 | Attempts to shutdown the mod from a non-hooked state. 75 | 76 | * #### GetClassFromName 77 | Finds any child member class of a class reference by name. (Can be found in SDK) 78 | 79 | ## Current problems 80 | - [ ] Add UI separation or a triggerable menu mode 81 | - [ ] Find the mountable vehicle member for location 82 | - [ ] Make the player turn with vehicles 83 | - [ ] Make the crosshair look nicer and compensate for 3rd person offset from the character model 84 | - [ ] Figure out how to set the view projection (it can be set, but it doesn't change anything) or a better auto calibration 85 | - [ ] Make distant objects appear clearer. 86 | 87 | # Credits 88 | * [OpenGameCamera](https://github.com/coltonon/OpenGameCamera/) 89 | * Some help from [BattleDash](https://github.com/BattleDash) 90 | * My testers in my Discord server 91 | * You? -------------------------------------------------------------------------------- /src/BF2VR/PixelShader.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | // 3 | // Generated by Microsoft (R) HLSL Shader Compiler 10.1 4 | // 5 | // 6 | // Resource Bindings: 7 | // 8 | // Name Type Format Dim HLSL Bind Count 9 | // ------------------------------ ---------- ------- ----------- -------------- ------ 10 | // s0 sampler NA NA s0 1 11 | // tex0 texture float4 2d t0 1 12 | // 13 | // 14 | // 15 | // Input signature: 16 | // 17 | // Name Index Mask Register SysValue Format Used 18 | // -------------------- ----- ------ -------- -------- ------- ------ 19 | // SV_Position 0 xyzw 0 POS float 20 | // TEXCOORD 0 xy 1 NONE float xy 21 | // 22 | // 23 | // Output signature: 24 | // 25 | // Name Index Mask Register SysValue Format Used 26 | // -------------------- ----- ------ -------- -------- ------- ------ 27 | // SV_Target 0 xyzw 0 TARGET float xyzw 28 | // 29 | ps_4_0 30 | dcl_sampler s0, mode_default 31 | dcl_resource_texture2d (float,float,float,float) t0 32 | dcl_input_ps linear v1.xy 33 | dcl_output o0.xyzw 34 | sample o0.xyzw, v1.xyxx, t0.xyzw, s0 35 | ret 36 | // Approximately 2 instruction slots used 37 | #endif 38 | 39 | const BYTE gPS[] = 40 | { 41 | 68, 88, 66, 67, 52, 239, 42 | 205, 10, 1, 155, 18, 98, 43 | 231, 59, 2, 136, 165, 171, 44 | 192, 15, 1, 0, 0, 0, 45 | 60, 2, 0, 0, 5, 0, 46 | 0, 0, 52, 0, 0, 0, 47 | 200, 0, 0, 0, 32, 1, 48 | 0, 0, 84, 1, 0, 0, 49 | 192, 1, 0, 0, 82, 68, 50 | 69, 70, 140, 0, 0, 0, 51 | 0, 0, 0, 0, 0, 0, 52 | 0, 0, 2, 0, 0, 0, 53 | 28, 0, 0, 0, 0, 4, 54 | 255, 255, 0, 1, 0, 0, 55 | 100, 0, 0, 0, 92, 0, 56 | 0, 0, 3, 0, 0, 0, 57 | 0, 0, 0, 0, 0, 0, 58 | 0, 0, 0, 0, 0, 0, 59 | 0, 0, 0, 0, 1, 0, 60 | 0, 0, 0, 0, 0, 0, 61 | 95, 0, 0, 0, 2, 0, 62 | 0, 0, 5, 0, 0, 0, 63 | 4, 0, 0, 0, 255, 255, 64 | 255, 255, 0, 0, 0, 0, 65 | 1, 0, 0, 0, 12, 0, 66 | 0, 0, 115, 48, 0, 116, 67 | 101, 120, 48, 0, 77, 105, 68 | 99, 114, 111, 115, 111, 102, 69 | 116, 32, 40, 82, 41, 32, 70 | 72, 76, 83, 76, 32, 83, 71 | 104, 97, 100, 101, 114, 32, 72 | 67, 111, 109, 112, 105, 108, 73 | 101, 114, 32, 49, 48, 46, 74 | 49, 0, 73, 83, 71, 78, 75 | 80, 0, 0, 0, 2, 0, 76 | 0, 0, 8, 0, 0, 0, 77 | 56, 0, 0, 0, 0, 0, 78 | 0, 0, 1, 0, 0, 0, 79 | 3, 0, 0, 0, 0, 0, 80 | 0, 0, 15, 0, 0, 0, 81 | 68, 0, 0, 0, 0, 0, 82 | 0, 0, 0, 0, 0, 0, 83 | 3, 0, 0, 0, 1, 0, 84 | 0, 0, 3, 3, 0, 0, 85 | 83, 86, 95, 80, 111, 115, 86 | 105, 116, 105, 111, 110, 0, 87 | 84, 69, 88, 67, 79, 79, 88 | 82, 68, 0, 171, 171, 171, 89 | 79, 83, 71, 78, 44, 0, 90 | 0, 0, 1, 0, 0, 0, 91 | 8, 0, 0, 0, 32, 0, 92 | 0, 0, 0, 0, 0, 0, 93 | 0, 0, 0, 0, 3, 0, 94 | 0, 0, 0, 0, 0, 0, 95 | 15, 0, 0, 0, 83, 86, 96 | 95, 84, 97, 114, 103, 101, 97 | 116, 0, 171, 171, 83, 72, 98 | 68, 82, 100, 0, 0, 0, 99 | 64, 0, 0, 0, 25, 0, 100 | 0, 0, 90, 0, 0, 3, 101 | 0, 96, 16, 0, 0, 0, 102 | 0, 0, 88, 24, 0, 4, 103 | 0, 112, 16, 0, 0, 0, 104 | 0, 0, 85, 85, 0, 0, 105 | 98, 16, 0, 3, 50, 16, 106 | 16, 0, 1, 0, 0, 0, 107 | 101, 0, 0, 3, 242, 32, 108 | 16, 0, 0, 0, 0, 0, 109 | 69, 0, 0, 9, 242, 32, 110 | 16, 0, 0, 0, 0, 0, 111 | 70, 16, 16, 0, 1, 0, 112 | 0, 0, 70, 126, 16, 0, 113 | 0, 0, 0, 0, 0, 96, 114 | 16, 0, 0, 0, 0, 0, 115 | 62, 0, 0, 1, 83, 84, 116 | 65, 84, 116, 0, 0, 0, 117 | 2, 0, 0, 0, 0, 0, 118 | 0, 0, 0, 0, 0, 0, 119 | 2, 0, 0, 0, 0, 0, 120 | 0, 0, 0, 0, 0, 0, 121 | 0, 0, 0, 0, 1, 0, 122 | 0, 0, 0, 0, 0, 0, 123 | 0, 0, 0, 0, 0, 0, 124 | 0, 0, 0, 0, 0, 0, 125 | 0, 0, 0, 0, 0, 0, 126 | 0, 0, 1, 0, 0, 0, 127 | 0, 0, 0, 0, 0, 0, 128 | 0, 0, 0, 0, 0, 0, 129 | 0, 0, 0, 0, 0, 0, 130 | 0, 0, 0, 0, 0, 0, 131 | 0, 0, 0, 0, 0, 0, 132 | 0, 0, 0, 0, 0, 0, 133 | 0, 0, 0, 0, 0, 0, 134 | 0, 0, 0, 0, 0, 0, 135 | 0, 0, 0, 0, 0, 0, 136 | 0, 0 137 | }; 138 | -------------------------------------------------------------------------------- /third-party/DirectXTK/SpriteBatch.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: SpriteBatch.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #include 17 | #endif 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | 27 | namespace DirectX 28 | { 29 | inline namespace DX11 30 | { 31 | enum SpriteSortMode 32 | { 33 | SpriteSortMode_Deferred, 34 | SpriteSortMode_Immediate, 35 | SpriteSortMode_Texture, 36 | SpriteSortMode_BackToFront, 37 | SpriteSortMode_FrontToBack, 38 | }; 39 | 40 | enum SpriteEffects : uint32_t 41 | { 42 | SpriteEffects_None = 0, 43 | SpriteEffects_FlipHorizontally = 1, 44 | SpriteEffects_FlipVertically = 2, 45 | SpriteEffects_FlipBoth = SpriteEffects_FlipHorizontally | SpriteEffects_FlipVertically, 46 | }; 47 | 48 | class SpriteBatch 49 | { 50 | public: 51 | explicit SpriteBatch(_In_ ID3D11DeviceContext* deviceContext); 52 | 53 | SpriteBatch(SpriteBatch&&) noexcept; 54 | SpriteBatch& operator= (SpriteBatch&&) noexcept; 55 | 56 | SpriteBatch(SpriteBatch const&) = delete; 57 | SpriteBatch& operator= (SpriteBatch const&) = delete; 58 | 59 | virtual ~SpriteBatch(); 60 | 61 | // Begin/End a batch of sprite drawing operations. 62 | void XM_CALLCONV Begin(SpriteSortMode sortMode = SpriteSortMode_Deferred, 63 | _In_opt_ ID3D11BlendState* blendState = nullptr, 64 | _In_opt_ ID3D11SamplerState* samplerState = nullptr, 65 | _In_opt_ ID3D11DepthStencilState* depthStencilState = nullptr, 66 | _In_opt_ ID3D11RasterizerState* rasterizerState = nullptr, 67 | _In_opt_ std::function setCustomShaders = nullptr, 68 | FXMMATRIX transformMatrix = MatrixIdentity); 69 | void __cdecl End(); 70 | 71 | // Draw overloads specifying position, origin and scale as XMFLOAT2. 72 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, FXMVECTOR color = Colors::White); 73 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 74 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, XMFLOAT2 const& position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 75 | 76 | // Draw overloads specifying position, origin and scale via the first two components of an XMVECTOR. 77 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, FXMVECTOR color = Colors::White); 78 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 79 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, FXMVECTOR position, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 80 | 81 | // Draw overloads specifying position as a RECT. 82 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, FXMVECTOR color = Colors::White); 83 | void XM_CALLCONV Draw(_In_ ID3D11ShaderResourceView* texture, RECT const& destinationRectangle, _In_opt_ RECT const* sourceRectangle, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0); 84 | 85 | // Rotation mode to be applied to the sprite transformation 86 | void __cdecl SetRotation(DXGI_MODE_ROTATION mode); 87 | DXGI_MODE_ROTATION __cdecl GetRotation() const noexcept; 88 | 89 | // Set viewport for sprite transformation 90 | void __cdecl SetViewport(const D3D11_VIEWPORT& viewPort); 91 | 92 | private: 93 | // Private implementation. 94 | struct Impl; 95 | 96 | std::unique_ptr pImpl; 97 | 98 | static const XMMATRIX MatrixIdentity; 99 | static const XMFLOAT2 Float2Zero; 100 | }; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /third-party/DirectXTK/Mouse.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: Mouse.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | // http://go.microsoft.com/fwlink/?LinkID=615561 9 | //-------------------------------------------------------------------------------------- 10 | 11 | #pragma once 12 | 13 | #if !defined(USING_XINPUT) && !defined(USING_GAMEINPUT) && !defined(USING_COREWINDOW) 14 | 15 | #ifdef _GAMING_DESKTOP 16 | #include 17 | #endif 18 | 19 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES)) || (defined(_GAMING_DESKTOP) && (_GRDK_EDITION >= 220600)) 20 | #define USING_GAMEINPUT 21 | #elif (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)) || (defined(_XBOX_ONE) && defined(_TITLE)) 22 | #define USING_COREWINDOW 23 | #endif 24 | 25 | #endif // !USING_XINPUT && !USING_GAMEINPUT && !USING_WINDOWS_GAMING_INPUT 26 | 27 | #if defined(USING_GAMEINPUT) && !defined(_GAMING_XBOX) 28 | #pragma comment(lib,"gameinput.lib") 29 | #endif 30 | 31 | #include 32 | 33 | #ifdef USING_COREWINDOW 34 | namespace ABI { namespace Windows { namespace UI { namespace Core { struct ICoreWindow; } } } } 35 | #endif 36 | 37 | #ifdef __clang__ 38 | #pragma clang diagnostic push 39 | #pragma clang diagnostic ignored "-Wunknown-pragmas" 40 | #endif 41 | 42 | 43 | namespace DirectX 44 | { 45 | class Mouse 46 | { 47 | public: 48 | Mouse() noexcept(false); 49 | 50 | Mouse(Mouse&&) noexcept; 51 | Mouse& operator= (Mouse&&) noexcept; 52 | 53 | Mouse(Mouse const&) = delete; 54 | Mouse& operator=(Mouse const&) = delete; 55 | 56 | virtual ~Mouse(); 57 | 58 | enum Mode 59 | { 60 | MODE_ABSOLUTE = 0, 61 | MODE_RELATIVE, 62 | }; 63 | 64 | struct State 65 | { 66 | bool leftButton; 67 | bool middleButton; 68 | bool rightButton; 69 | bool xButton1; 70 | bool xButton2; 71 | int x; 72 | int y; 73 | int scrollWheelValue; 74 | Mode positionMode; 75 | }; 76 | 77 | class ButtonStateTracker 78 | { 79 | public: 80 | enum ButtonState 81 | { 82 | UP = 0, // Button is up 83 | HELD = 1, // Button is held down 84 | RELEASED = 2, // Button was just released 85 | PRESSED = 3, // Buton was just pressed 86 | }; 87 | 88 | ButtonState leftButton; 89 | ButtonState middleButton; 90 | ButtonState rightButton; 91 | ButtonState xButton1; 92 | ButtonState xButton2; 93 | 94 | #pragma prefast(suppress: 26495, "Reset() performs the initialization") 95 | ButtonStateTracker() noexcept { Reset(); } 96 | 97 | void __cdecl Update(const State& state) noexcept; 98 | 99 | void __cdecl Reset() noexcept; 100 | 101 | State __cdecl GetLastState() const noexcept { return lastState; } 102 | 103 | private: 104 | State lastState; 105 | }; 106 | 107 | // Retrieve the current state of the mouse 108 | State __cdecl GetState() const; 109 | 110 | // Resets the accumulated scroll wheel value 111 | void __cdecl ResetScrollWheelValue() noexcept; 112 | 113 | // Sets mouse mode (defaults to absolute) 114 | void __cdecl SetMode(Mode mode); 115 | 116 | // Feature detection 117 | bool __cdecl IsConnected() const; 118 | 119 | // Cursor visibility 120 | bool __cdecl IsVisible() const noexcept; 121 | void __cdecl SetVisible(bool visible); 122 | 123 | #ifdef USING_COREWINDOW 124 | void __cdecl SetWindow(ABI::Windows::UI::Core::ICoreWindow* window); 125 | #ifdef __cplusplus_winrt 126 | void __cdecl SetWindow(Windows::UI::Core::CoreWindow^ window) 127 | { 128 | // See https://msdn.microsoft.com/en-us/library/hh755802.aspx 129 | SetWindow(reinterpret_cast(window)); 130 | } 131 | #endif 132 | #ifdef CPPWINRT_VERSION 133 | void __cdecl SetWindow(winrt::Windows::UI::Core::CoreWindow window) 134 | { 135 | // See https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/interop-winrt-abi 136 | SetWindow(reinterpret_cast(winrt::get_abi(window))); 137 | } 138 | #endif 139 | 140 | static void __cdecl SetDpi(float dpi); 141 | #elif defined(WM_USER) 142 | void __cdecl SetWindow(HWND window); 143 | static void __cdecl ProcessMessage(UINT message, WPARAM wParam, LPARAM lParam); 144 | 145 | #ifdef _GAMING_XBOX 146 | static void __cdecl SetResolution(float scale); 147 | #endif 148 | #endif 149 | 150 | // Singleton 151 | static Mouse& __cdecl Get(); 152 | 153 | private: 154 | // Private implementation. 155 | class Impl; 156 | 157 | std::unique_ptr pImpl; 158 | }; 159 | } 160 | 161 | #ifdef __clang__ 162 | #pragma clang diagnostic pop 163 | #endif 164 | -------------------------------------------------------------------------------- /third-party/DirectXTK/SpriteFont.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: SpriteFont.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #include "SpriteBatch.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | 19 | namespace DirectX 20 | { 21 | inline namespace DX11 22 | { 23 | class SpriteFont 24 | { 25 | public: 26 | struct Glyph; 27 | 28 | SpriteFont(_In_ ID3D11Device* device, _In_z_ wchar_t const* fileName, bool forceSRGB = false); 29 | SpriteFont(_In_ ID3D11Device* device, _In_reads_bytes_(dataSize) uint8_t const* dataBlob, _In_ size_t dataSize, bool forceSRGB = false); 30 | SpriteFont(_In_ ID3D11ShaderResourceView* texture, _In_reads_(glyphCount) Glyph const* glyphs, _In_ size_t glyphCount, _In_ float lineSpacing); 31 | 32 | SpriteFont(SpriteFont&&) noexcept; 33 | SpriteFont& operator= (SpriteFont&&) noexcept; 34 | 35 | SpriteFont(SpriteFont const&) = delete; 36 | SpriteFont& operator= (SpriteFont const&) = delete; 37 | 38 | virtual ~SpriteFont(); 39 | 40 | // Wide-character / UTF-16LE 41 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 42 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 43 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 44 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ wchar_t const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 45 | 46 | XMVECTOR XM_CALLCONV MeasureString(_In_z_ wchar_t const* text, bool ignoreWhitespace = true) const; 47 | 48 | RECT __cdecl MeasureDrawBounds(_In_z_ wchar_t const* text, XMFLOAT2 const& position, bool ignoreWhitespace = true) const; 49 | RECT XM_CALLCONV MeasureDrawBounds(_In_z_ wchar_t const* text, FXMVECTOR position, bool ignoreWhitespace = true) const; 50 | 51 | // UTF-8 52 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, XMFLOAT2 const& position, FXMVECTOR color = Colors::White, float rotation = 0, XMFLOAT2 const& origin = Float2Zero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 53 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, XMFLOAT2 const& position, FXMVECTOR color, float rotation, XMFLOAT2 const& origin, XMFLOAT2 const& scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 54 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, FXMVECTOR position, FXMVECTOR color = Colors::White, float rotation = 0, FXMVECTOR origin = g_XMZero, float scale = 1, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 55 | void XM_CALLCONV DrawString(_In_ SpriteBatch* spriteBatch, _In_z_ char const* text, FXMVECTOR position, FXMVECTOR color, float rotation, FXMVECTOR origin, GXMVECTOR scale, SpriteEffects effects = SpriteEffects_None, float layerDepth = 0) const; 56 | 57 | XMVECTOR XM_CALLCONV MeasureString(_In_z_ char const* text, bool ignoreWhitespace = true) const; 58 | 59 | RECT __cdecl MeasureDrawBounds(_In_z_ char const* text, XMFLOAT2 const& position, bool ignoreWhitespace = true) const; 60 | RECT XM_CALLCONV MeasureDrawBounds(_In_z_ char const* text, FXMVECTOR position, bool ignoreWhitespace = true) const; 61 | 62 | // Spacing properties 63 | float __cdecl GetLineSpacing() const noexcept; 64 | void __cdecl SetLineSpacing(float spacing); 65 | 66 | // Font properties 67 | wchar_t __cdecl GetDefaultCharacter() const noexcept; 68 | void __cdecl SetDefaultCharacter(wchar_t character); 69 | 70 | bool __cdecl ContainsCharacter(wchar_t character) const; 71 | 72 | // Custom layout/rendering 73 | Glyph const* __cdecl FindGlyph(wchar_t character) const; 74 | void __cdecl GetSpriteSheet(ID3D11ShaderResourceView** texture) const; 75 | 76 | // Describes a single character glyph. 77 | struct Glyph 78 | { 79 | uint32_t Character; 80 | RECT Subrect; 81 | float XOffset; 82 | float YOffset; 83 | float XAdvance; 84 | }; 85 | 86 | 87 | private: 88 | // Private implementation. 89 | class Impl; 90 | 91 | std::unique_ptr pImpl; 92 | 93 | static const XMFLOAT2 Float2Zero; 94 | }; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /third-party/DirectXTK/PrimitiveBatch.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: PrimitiveBatch.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | namespace DirectX 26 | { 27 | inline namespace DX11 28 | { 29 | namespace Private 30 | { 31 | // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch. 32 | class PrimitiveBatchBase 33 | { 34 | protected: 35 | PrimitiveBatchBase(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices, size_t maxVertices, size_t vertexSize); 36 | 37 | PrimitiveBatchBase(PrimitiveBatchBase&&) noexcept; 38 | PrimitiveBatchBase& operator= (PrimitiveBatchBase&&) noexcept; 39 | 40 | PrimitiveBatchBase(PrimitiveBatchBase const&) = delete; 41 | PrimitiveBatchBase& operator= (PrimitiveBatchBase const&) = delete; 42 | 43 | virtual ~PrimitiveBatchBase(); 44 | 45 | public: 46 | // Begin/End a batch of primitive drawing operations. 47 | void __cdecl Begin(); 48 | void __cdecl End(); 49 | 50 | protected: 51 | // Internal, untyped drawing method. 52 | void __cdecl Draw(D3D11_PRIMITIVE_TOPOLOGY topology, bool isIndexed, _In_opt_count_(indexCount) uint16_t const* indices, size_t indexCount, size_t vertexCount, _Out_ void** pMappedVertices); 53 | 54 | private: 55 | // Private implementation. 56 | class Impl; 57 | 58 | std::unique_ptr pImpl; 59 | }; 60 | } 61 | 62 | // Template makes the API typesafe, eg. PrimitiveBatch. 63 | template 64 | class PrimitiveBatch : public Private::PrimitiveBatchBase 65 | { 66 | static constexpr size_t DefaultBatchSize = 2048; 67 | 68 | public: 69 | explicit PrimitiveBatch(_In_ ID3D11DeviceContext* deviceContext, size_t maxIndices = DefaultBatchSize * 3, size_t maxVertices = DefaultBatchSize) 70 | : PrimitiveBatchBase(deviceContext, maxIndices, maxVertices, sizeof(TVertex)) 71 | { 72 | } 73 | 74 | PrimitiveBatch(PrimitiveBatch&&) = default; 75 | PrimitiveBatch& operator= (PrimitiveBatch&&) = default; 76 | 77 | PrimitiveBatch(PrimitiveBatch const&) = delete; 78 | PrimitiveBatch& operator= (PrimitiveBatch const&) = delete; 79 | 80 | // Similar to the D3D9 API DrawPrimitiveUP. 81 | void Draw(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) 82 | { 83 | void* mappedVertices; 84 | 85 | PrimitiveBatchBase::Draw(topology, false, nullptr, 0, vertexCount, &mappedVertices); 86 | 87 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); 88 | } 89 | 90 | 91 | // Similar to the D3D9 API DrawIndexedPrimitiveUP. 92 | void DrawIndexed(D3D11_PRIMITIVE_TOPOLOGY topology, _In_reads_(indexCount) uint16_t const* indices, size_t indexCount, _In_reads_(vertexCount) TVertex const* vertices, size_t vertexCount) 93 | { 94 | void* mappedVertices; 95 | 96 | PrimitiveBatchBase::Draw(topology, true, indices, indexCount, vertexCount, &mappedVertices); 97 | 98 | memcpy(mappedVertices, vertices, vertexCount * sizeof(TVertex)); 99 | } 100 | 101 | 102 | void DrawLine(TVertex const& v1, TVertex const& v2) 103 | { 104 | TVertex* mappedVertices; 105 | 106 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_LINELIST, false, nullptr, 0, 2, reinterpret_cast(&mappedVertices)); 107 | 108 | mappedVertices[0] = v1; 109 | mappedVertices[1] = v2; 110 | } 111 | 112 | 113 | void DrawTriangle(TVertex const& v1, TVertex const& v2, TVertex const& v3) 114 | { 115 | TVertex* mappedVertices; 116 | 117 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, false, nullptr, 0, 3, reinterpret_cast(&mappedVertices)); 118 | 119 | mappedVertices[0] = v1; 120 | mappedVertices[1] = v2; 121 | mappedVertices[2] = v3; 122 | } 123 | 124 | 125 | void DrawQuad(TVertex const& v1, TVertex const& v2, TVertex const& v3, TVertex const& v4) 126 | { 127 | static const uint16_t quadIndices[] = { 0, 1, 2, 0, 2, 3 }; 128 | 129 | TVertex* mappedVertices; 130 | 131 | PrimitiveBatchBase::Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, true, quadIndices, 6, 4, reinterpret_cast(&mappedVertices)); 132 | 133 | mappedVertices[0] = v1; 134 | mappedVertices[1] = v2; 135 | mappedVertices[2] = v3; 136 | mappedVertices[3] = v4; 137 | } 138 | }; 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/BF2VR/VertexShader.h: -------------------------------------------------------------------------------- 1 | #if 0 2 | // 3 | // Generated by Microsoft (R) HLSL Shader Compiler 10.1 4 | // 5 | // 6 | // 7 | // Input signature: 8 | // 9 | // Name Index Mask Register SysValue Format Used 10 | // -------------------- ----- ------ -------- -------- ------- ------ 11 | // SV_VertexID 0 x 0 VERTID uint x 12 | // 13 | // 14 | // Output signature: 15 | // 16 | // Name Index Mask Register SysValue Format Used 17 | // -------------------- ----- ------ -------- -------- ------- ------ 18 | // SV_Position 0 xyzw 0 POS float xyzw 19 | // TEXCOORD 0 xy 1 NONE float xy 20 | // 21 | vs_4_0 22 | dcl_input_sgv v0.x, vertex_id 23 | dcl_output_siv o0.xyzw, position 24 | dcl_output o1.xy 25 | dcl_temps 1 26 | ishl r0.x, v0.x, l(1) 27 | and r0.x, r0.x, l(2) 28 | utof r0.x, r0.x 29 | mad o0.x, r0.x, l(2.000000), l(-1.000000) 30 | and r0.z, v0.x, l(2) 31 | utof r0.y, r0.z 32 | mad o0.y, r0.y, l(-2.000000), l(1.000000) 33 | mov o1.xy, r0.xyxx 34 | mov o0.zw, l(0,0,0,1.000000) 35 | ret 36 | // Approximately 10 instruction slots used 37 | #endif 38 | 39 | const BYTE gVS[] = 40 | { 41 | 68, 88, 66, 67, 3, 34, 42 | 134, 52, 179, 241, 3, 211, 43 | 118, 241, 117, 23, 12, 123, 44 | 64, 241, 1, 0, 0, 0, 45 | 200, 2, 0, 0, 5, 0, 46 | 0, 0, 52, 0, 0, 0, 47 | 128, 0, 0, 0, 180, 0, 48 | 0, 0, 12, 1, 0, 0, 49 | 76, 2, 0, 0, 82, 68, 50 | 69, 70, 68, 0, 0, 0, 51 | 0, 0, 0, 0, 0, 0, 52 | 0, 0, 0, 0, 0, 0, 53 | 28, 0, 0, 0, 0, 4, 54 | 254, 255, 0, 1, 0, 0, 55 | 28, 0, 0, 0, 77, 105, 56 | 99, 114, 111, 115, 111, 102, 57 | 116, 32, 40, 82, 41, 32, 58 | 72, 76, 83, 76, 32, 83, 59 | 104, 97, 100, 101, 114, 32, 60 | 67, 111, 109, 112, 105, 108, 61 | 101, 114, 32, 49, 48, 46, 62 | 49, 0, 73, 83, 71, 78, 63 | 44, 0, 0, 0, 1, 0, 64 | 0, 0, 8, 0, 0, 0, 65 | 32, 0, 0, 0, 0, 0, 66 | 0, 0, 6, 0, 0, 0, 67 | 1, 0, 0, 0, 0, 0, 68 | 0, 0, 1, 1, 0, 0, 69 | 83, 86, 95, 86, 101, 114, 70 | 116, 101, 120, 73, 68, 0, 71 | 79, 83, 71, 78, 80, 0, 72 | 0, 0, 2, 0, 0, 0, 73 | 8, 0, 0, 0, 56, 0, 74 | 0, 0, 0, 0, 0, 0, 75 | 1, 0, 0, 0, 3, 0, 76 | 0, 0, 0, 0, 0, 0, 77 | 15, 0, 0, 0, 68, 0, 78 | 0, 0, 0, 0, 0, 0, 79 | 0, 0, 0, 0, 3, 0, 80 | 0, 0, 1, 0, 0, 0, 81 | 3, 12, 0, 0, 83, 86, 82 | 95, 80, 111, 115, 105, 116, 83 | 105, 111, 110, 0, 84, 69, 84 | 88, 67, 79, 79, 82, 68, 85 | 0, 171, 171, 171, 83, 72, 86 | 68, 82, 56, 1, 0, 0, 87 | 64, 0, 1, 0, 78, 0, 88 | 0, 0, 96, 0, 0, 4, 89 | 18, 16, 16, 0, 0, 0, 90 | 0, 0, 6, 0, 0, 0, 91 | 103, 0, 0, 4, 242, 32, 92 | 16, 0, 0, 0, 0, 0, 93 | 1, 0, 0, 0, 101, 0, 94 | 0, 3, 50, 32, 16, 0, 95 | 1, 0, 0, 0, 104, 0, 96 | 0, 2, 1, 0, 0, 0, 97 | 41, 0, 0, 7, 18, 0, 98 | 16, 0, 0, 0, 0, 0, 99 | 10, 16, 16, 0, 0, 0, 100 | 0, 0, 1, 64, 0, 0, 101 | 1, 0, 0, 0, 1, 0, 102 | 0, 7, 18, 0, 16, 0, 103 | 0, 0, 0, 0, 10, 0, 104 | 16, 0, 0, 0, 0, 0, 105 | 1, 64, 0, 0, 2, 0, 106 | 0, 0, 86, 0, 0, 5, 107 | 18, 0, 16, 0, 0, 0, 108 | 0, 0, 10, 0, 16, 0, 109 | 0, 0, 0, 0, 50, 0, 110 | 0, 9, 18, 32, 16, 0, 111 | 0, 0, 0, 0, 10, 0, 112 | 16, 0, 0, 0, 0, 0, 113 | 1, 64, 0, 0, 0, 0, 114 | 0, 64, 1, 64, 0, 0, 115 | 0, 0, 128, 191, 1, 0, 116 | 0, 7, 66, 0, 16, 0, 117 | 0, 0, 0, 0, 10, 16, 118 | 16, 0, 0, 0, 0, 0, 119 | 1, 64, 0, 0, 2, 0, 120 | 0, 0, 86, 0, 0, 5, 121 | 34, 0, 16, 0, 0, 0, 122 | 0, 0, 42, 0, 16, 0, 123 | 0, 0, 0, 0, 50, 0, 124 | 0, 9, 34, 32, 16, 0, 125 | 0, 0, 0, 0, 26, 0, 126 | 16, 0, 0, 0, 0, 0, 127 | 1, 64, 0, 0, 0, 0, 128 | 0, 192, 1, 64, 0, 0, 129 | 0, 0, 128, 63, 54, 0, 130 | 0, 5, 50, 32, 16, 0, 131 | 1, 0, 0, 0, 70, 0, 132 | 16, 0, 0, 0, 0, 0, 133 | 54, 0, 0, 8, 194, 32, 134 | 16, 0, 0, 0, 0, 0, 135 | 2, 64, 0, 0, 0, 0, 136 | 0, 0, 0, 0, 0, 0, 137 | 0, 0, 0, 0, 0, 0, 138 | 128, 63, 62, 0, 0, 1, 139 | 83, 84, 65, 84, 116, 0, 140 | 0, 0, 10, 0, 0, 0, 141 | 1, 0, 0, 0, 0, 0, 142 | 0, 0, 3, 0, 0, 0, 143 | 2, 0, 0, 0, 1, 0, 144 | 0, 0, 2, 0, 0, 0, 145 | 1, 0, 0, 0, 0, 0, 146 | 0, 0, 0, 0, 0, 0, 147 | 0, 0, 0, 0, 0, 0, 148 | 0, 0, 0, 0, 0, 0, 149 | 0, 0, 0, 0, 0, 0, 150 | 0, 0, 0, 0, 0, 0, 151 | 0, 0, 0, 0, 0, 0, 152 | 0, 0, 0, 0, 0, 0, 153 | 2, 0, 0, 0, 0, 0, 154 | 0, 0, 2, 0, 0, 0, 155 | 0, 0, 0, 0, 0, 0, 156 | 0, 0, 0, 0, 0, 0, 157 | 0, 0, 0, 0, 0, 0, 158 | 0, 0, 0, 0, 0, 0, 159 | 0, 0, 0, 0 160 | }; 161 | -------------------------------------------------------------------------------- /third-party/DirectXTK/BufferHelpers.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: BufferHelpers.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #if defined(_XBOX_ONE) && defined(_TITLE) 16 | #include 17 | #include "GraphicsMemory.h" 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | 24 | 25 | namespace DirectX 26 | { 27 | // Helpers for creating initialized Direct3D buffer resources. 28 | HRESULT __cdecl CreateStaticBuffer(_In_ ID3D11Device* device, 29 | _In_reads_bytes_(count* stride) const void* ptr, 30 | size_t count, 31 | size_t stride, 32 | unsigned int bindFlags, 33 | _COM_Outptr_ ID3D11Buffer** pBuffer) noexcept; 34 | 35 | template 36 | HRESULT CreateStaticBuffer(_In_ ID3D11Device* device, 37 | _In_reads_(count) T const* data, 38 | size_t count, 39 | unsigned int bindFlags, 40 | _COM_Outptr_ ID3D11Buffer** pBuffer) noexcept 41 | { 42 | return CreateStaticBuffer(device, data, count, sizeof(T), bindFlags, pBuffer); 43 | } 44 | 45 | template 46 | HRESULT CreateStaticBuffer(_In_ ID3D11Device* device, 47 | T const& data, 48 | unsigned int bindFlags, 49 | _COM_Outptr_ ID3D11Buffer** pBuffer) noexcept 50 | { 51 | return CreateStaticBuffer(device, data.data(), data.size(), sizeof(typename T::value_type), bindFlags, pBuffer); 52 | } 53 | 54 | // Helpers for creating texture from memory arrays. 55 | HRESULT __cdecl CreateTextureFromMemory(_In_ ID3D11Device* device, 56 | size_t width, 57 | DXGI_FORMAT format, 58 | const D3D11_SUBRESOURCE_DATA& initData, 59 | _COM_Outptr_opt_ ID3D11Texture1D** texture, 60 | _COM_Outptr_opt_ ID3D11ShaderResourceView** textureView, 61 | unsigned int bindFlags = D3D11_BIND_SHADER_RESOURCE) noexcept; 62 | 63 | HRESULT __cdecl CreateTextureFromMemory(_In_ ID3D11Device* device, 64 | size_t width, size_t height, 65 | DXGI_FORMAT format, 66 | const D3D11_SUBRESOURCE_DATA& initData, 67 | _COM_Outptr_opt_ ID3D11Texture2D** texture, 68 | _COM_Outptr_opt_ ID3D11ShaderResourceView** textureView, 69 | unsigned int bindFlags = D3D11_BIND_SHADER_RESOURCE) noexcept; 70 | 71 | HRESULT __cdecl CreateTextureFromMemory( 72 | #if defined(_XBOX_ONE) && defined(_TITLE) 73 | _In_ ID3D11DeviceX* d3dDeviceX, 74 | _In_ ID3D11DeviceContextX* d3dContextX, 75 | #else 76 | _In_ ID3D11Device* device, 77 | _In_ ID3D11DeviceContext* d3dContext, 78 | #endif 79 | size_t width, size_t height, 80 | DXGI_FORMAT format, 81 | const D3D11_SUBRESOURCE_DATA& initData, 82 | _COM_Outptr_opt_ ID3D11Texture2D** texture, 83 | _COM_Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept; 84 | 85 | HRESULT __cdecl CreateTextureFromMemory(_In_ ID3D11Device* device, 86 | size_t width, size_t height, size_t depth, 87 | DXGI_FORMAT format, 88 | const D3D11_SUBRESOURCE_DATA& initData, 89 | _COM_Outptr_opt_ ID3D11Texture3D** texture, 90 | _COM_Outptr_opt_ ID3D11ShaderResourceView** textureView, 91 | unsigned int bindFlags = D3D11_BIND_SHADER_RESOURCE) noexcept; 92 | 93 | // Strongly typed wrapper around a Direct3D constant buffer. 94 | inline namespace DX11 95 | { 96 | namespace Private 97 | { 98 | // Base class, not to be used directly: clients should access this via the derived PrimitiveBatch. 99 | class ConstantBufferBase 100 | { 101 | protected: 102 | void __cdecl CreateBuffer(_In_ ID3D11Device* device, size_t bytes, _Outptr_ ID3D11Buffer** pBuffer); 103 | }; 104 | } 105 | } 106 | 107 | template 108 | class ConstantBuffer : public DX11::Private::ConstantBufferBase 109 | { 110 | public: 111 | // Constructor. 112 | ConstantBuffer() = default; 113 | explicit ConstantBuffer(_In_ ID3D11Device* device) noexcept(false) 114 | { 115 | CreateBuffer(device, sizeof(T), mConstantBuffer.GetAddressOf()); 116 | } 117 | 118 | ConstantBuffer(ConstantBuffer&&) = default; 119 | ConstantBuffer& operator= (ConstantBuffer&&) = default; 120 | 121 | ConstantBuffer(ConstantBuffer const&) = delete; 122 | ConstantBuffer& operator= (ConstantBuffer const&) = delete; 123 | 124 | void Create(_In_ ID3D11Device* device) 125 | { 126 | CreateBuffer(device, sizeof(T), mConstantBuffer.ReleaseAndGetAddressOf()); 127 | } 128 | 129 | // Writes new data into the constant buffer. 130 | #if defined(_XBOX_ONE) && defined(_TITLE) 131 | void __cdecl SetData(_In_ ID3D11DeviceContext* deviceContext, T const& value, void** grfxMemory) 132 | { 133 | assert(grfxMemory != nullptr); 134 | 135 | void* ptr = GraphicsMemory::Get().Allocate(deviceContext, sizeof(T), 64); 136 | assert(ptr != nullptr); 137 | 138 | *(T*)ptr = value; 139 | 140 | *grfxMemory = ptr; 141 | } 142 | #else 143 | 144 | void __cdecl SetData(_In_ ID3D11DeviceContext* deviceContext, T const& value) noexcept 145 | { 146 | assert(mConstantBuffer); 147 | 148 | D3D11_MAPPED_SUBRESOURCE mappedResource; 149 | if (SUCCEEDED(deviceContext->Map(mConstantBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource))) 150 | { 151 | *static_cast(mappedResource.pData) = value; 152 | 153 | deviceContext->Unmap(mConstantBuffer.Get(), 0); 154 | } 155 | } 156 | #endif // _XBOX_ONE && _TITLE 157 | 158 | // Looks up the underlying D3D constant buffer. 159 | ID3D11Buffer* GetBuffer() const noexcept { return mConstantBuffer.Get(); } 160 | 161 | private: 162 | Microsoft::WRL::ComPtr mConstantBuffer; 163 | }; 164 | } 165 | -------------------------------------------------------------------------------- /third-party/DirectXTK/WICTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: WICTextureLoader.h 3 | // 4 | // Function for loading a WIC image and creating a Direct3D runtime texture for it 5 | // (auto-generating mipmaps if possible) 6 | // 7 | // Note: Assumes application has already called CoInitializeEx 8 | // 9 | // Warning: CreateWICTexture* functions are not thread-safe if given a d3dContext instance for 10 | // auto-gen mipmap support. 11 | // 12 | // Note these functions are useful for images created as simple 2D textures. For 13 | // more complex resources, DDSTextureLoader is an excellent light-weight runtime loader. 14 | // For a full-featured DDS file reader, writer, and texture processing pipeline see 15 | // the 'Texconv' sample and the 'DirectXTex' library. 16 | // 17 | // Copyright (c) Microsoft Corporation. 18 | // Licensed under the MIT License. 19 | // 20 | // http://go.microsoft.com/fwlink/?LinkId=248926 21 | // http://go.microsoft.com/fwlink/?LinkId=248929 22 | //-------------------------------------------------------------------------------------- 23 | 24 | #pragma once 25 | 26 | #if defined(_XBOX_ONE) && defined(_TITLE) 27 | #include 28 | #else 29 | #include 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #pragma comment(lib,"uuid.lib") 36 | 37 | 38 | namespace DirectX 39 | { 40 | inline namespace DX11 41 | { 42 | enum WIC_LOADER_FLAGS : uint32_t 43 | { 44 | WIC_LOADER_DEFAULT = 0, 45 | WIC_LOADER_FORCE_SRGB = 0x1, 46 | WIC_LOADER_IGNORE_SRGB = 0x2, 47 | WIC_LOADER_SRGB_DEFAULT = 0x4, 48 | WIC_LOADER_FIT_POW2 = 0x20, 49 | WIC_LOADER_MAKE_SQUARE = 0x40, 50 | WIC_LOADER_FORCE_RGBA32 = 0x80, 51 | }; 52 | } 53 | 54 | // Standard version 55 | HRESULT __cdecl CreateWICTextureFromMemory( 56 | _In_ ID3D11Device* d3dDevice, 57 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 58 | _In_ size_t wicDataSize, 59 | _Outptr_opt_ ID3D11Resource** texture, 60 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 61 | _In_ size_t maxsize = 0) noexcept; 62 | 63 | HRESULT __cdecl CreateWICTextureFromFile( 64 | _In_ ID3D11Device* d3dDevice, 65 | _In_z_ const wchar_t* szFileName, 66 | _Outptr_opt_ ID3D11Resource** texture, 67 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 68 | _In_ size_t maxsize = 0) noexcept; 69 | 70 | // Standard version with optional auto-gen mipmap support 71 | HRESULT __cdecl CreateWICTextureFromMemory( 72 | #if defined(_XBOX_ONE) && defined(_TITLE) 73 | _In_ ID3D11DeviceX* d3dDevice, 74 | _In_opt_ ID3D11DeviceContextX* d3dContext, 75 | #else 76 | _In_ ID3D11Device* d3dDevice, 77 | _In_opt_ ID3D11DeviceContext* d3dContext, 78 | #endif 79 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 80 | _In_ size_t wicDataSize, 81 | _Outptr_opt_ ID3D11Resource** texture, 82 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 83 | _In_ size_t maxsize = 0) noexcept; 84 | 85 | HRESULT __cdecl CreateWICTextureFromFile( 86 | #if defined(_XBOX_ONE) && defined(_TITLE) 87 | _In_ ID3D11DeviceX* d3dDevice, 88 | _In_opt_ ID3D11DeviceContextX* d3dContext, 89 | #else 90 | _In_ ID3D11Device* d3dDevice, 91 | _In_opt_ ID3D11DeviceContext* d3dContext, 92 | #endif 93 | _In_z_ const wchar_t* szFileName, 94 | _Outptr_opt_ ID3D11Resource** texture, 95 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 96 | _In_ size_t maxsize = 0) noexcept; 97 | 98 | // Extended version 99 | HRESULT __cdecl CreateWICTextureFromMemoryEx( 100 | _In_ ID3D11Device* d3dDevice, 101 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 102 | _In_ size_t wicDataSize, 103 | _In_ size_t maxsize, 104 | _In_ D3D11_USAGE usage, 105 | _In_ unsigned int bindFlags, 106 | _In_ unsigned int cpuAccessFlags, 107 | _In_ unsigned int miscFlags, 108 | _In_ WIC_LOADER_FLAGS loadFlags, 109 | _Outptr_opt_ ID3D11Resource** texture, 110 | _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept; 111 | 112 | HRESULT __cdecl CreateWICTextureFromFileEx( 113 | _In_ ID3D11Device* d3dDevice, 114 | _In_z_ const wchar_t* szFileName, 115 | _In_ size_t maxsize, 116 | _In_ D3D11_USAGE usage, 117 | _In_ unsigned int bindFlags, 118 | _In_ unsigned int cpuAccessFlags, 119 | _In_ unsigned int miscFlags, 120 | _In_ WIC_LOADER_FLAGS loadFlags, 121 | _Outptr_opt_ ID3D11Resource** texture, 122 | _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept; 123 | 124 | // Extended version with optional auto-gen mipmap support 125 | HRESULT __cdecl CreateWICTextureFromMemoryEx( 126 | #if defined(_XBOX_ONE) && defined(_TITLE) 127 | _In_ ID3D11DeviceX* d3dDevice, 128 | _In_opt_ ID3D11DeviceContextX* d3dContext, 129 | #else 130 | _In_ ID3D11Device* d3dDevice, 131 | _In_opt_ ID3D11DeviceContext* d3dContext, 132 | #endif 133 | _In_reads_bytes_(wicDataSize) const uint8_t* wicData, 134 | _In_ size_t wicDataSize, 135 | _In_ size_t maxsize, 136 | _In_ D3D11_USAGE usage, 137 | _In_ unsigned int bindFlags, 138 | _In_ unsigned int cpuAccessFlags, 139 | _In_ unsigned int miscFlags, 140 | _In_ WIC_LOADER_FLAGS loadFlags, 141 | _Outptr_opt_ ID3D11Resource** texture, 142 | _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept; 143 | 144 | HRESULT __cdecl CreateWICTextureFromFileEx( 145 | #if defined(_XBOX_ONE) && defined(_TITLE) 146 | _In_ ID3D11DeviceX* d3dDevice, 147 | _In_opt_ ID3D11DeviceContextX* d3dContext, 148 | #else 149 | _In_ ID3D11Device* d3dDevice, 150 | _In_opt_ ID3D11DeviceContext* d3dContext, 151 | #endif 152 | _In_z_ const wchar_t* szFileName, 153 | _In_ size_t maxsize, 154 | _In_ D3D11_USAGE usage, 155 | _In_ unsigned int bindFlags, 156 | _In_ unsigned int cpuAccessFlags, 157 | _In_ unsigned int miscFlags, 158 | _In_ WIC_LOADER_FLAGS loadFlags, 159 | _Outptr_opt_ ID3D11Resource** texture, 160 | _Outptr_opt_ ID3D11ShaderResourceView** textureView) noexcept; 161 | 162 | #ifdef __clang__ 163 | #pragma clang diagnostic push 164 | #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" 165 | #endif 166 | 167 | inline namespace DX11 168 | { 169 | DEFINE_ENUM_FLAG_OPERATORS(WIC_LOADER_FLAGS); 170 | } 171 | 172 | #ifdef __clang__ 173 | #pragma clang diagnostic pop 174 | #endif 175 | } 176 | -------------------------------------------------------------------------------- /third-party/DirectXTK/DDSTextureLoader.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DDSTextureLoader.h 3 | // 4 | // Functions for loading a DDS texture and creating a Direct3D runtime resource for it 5 | // 6 | // Note these functions are useful as a light-weight runtime loader for DDS files. For 7 | // a full-featured DDS file reader, writer, and texture processing pipeline see 8 | // the 'Texconv' sample and the 'DirectXTex' library. 9 | // 10 | // Copyright (c) Microsoft Corporation. 11 | // Licensed under the MIT License. 12 | // 13 | // http://go.microsoft.com/fwlink/?LinkId=248926 14 | // http://go.microsoft.com/fwlink/?LinkId=248929 15 | //-------------------------------------------------------------------------------------- 16 | 17 | #pragma once 18 | 19 | #if defined(_XBOX_ONE) && defined(_TITLE) 20 | #include 21 | #else 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | 29 | namespace DirectX 30 | { 31 | #ifndef DDS_ALPHA_MODE_DEFINED 32 | #define DDS_ALPHA_MODE_DEFINED 33 | enum DDS_ALPHA_MODE : uint32_t 34 | { 35 | DDS_ALPHA_MODE_UNKNOWN = 0, 36 | DDS_ALPHA_MODE_STRAIGHT = 1, 37 | DDS_ALPHA_MODE_PREMULTIPLIED = 2, 38 | DDS_ALPHA_MODE_OPAQUE = 3, 39 | DDS_ALPHA_MODE_CUSTOM = 4, 40 | }; 41 | #endif 42 | 43 | inline namespace DX11 44 | { 45 | enum DDS_LOADER_FLAGS : uint32_t 46 | { 47 | DDS_LOADER_DEFAULT = 0, 48 | DDS_LOADER_FORCE_SRGB = 0x1, 49 | DDS_LOADER_IGNORE_SRGB = 0x2, 50 | }; 51 | } 52 | 53 | // Standard version 54 | HRESULT __cdecl CreateDDSTextureFromMemory( 55 | _In_ ID3D11Device* d3dDevice, 56 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 57 | _In_ size_t ddsDataSize, 58 | _Outptr_opt_ ID3D11Resource** texture, 59 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 60 | _In_ size_t maxsize = 0, 61 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 62 | 63 | HRESULT __cdecl CreateDDSTextureFromFile( 64 | _In_ ID3D11Device* d3dDevice, 65 | _In_z_ const wchar_t* szFileName, 66 | _Outptr_opt_ ID3D11Resource** texture, 67 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 68 | _In_ size_t maxsize = 0, 69 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 70 | 71 | // Standard version with optional auto-gen mipmap support 72 | HRESULT __cdecl CreateDDSTextureFromMemory( 73 | #if defined(_XBOX_ONE) && defined(_TITLE) 74 | _In_ ID3D11DeviceX* d3dDevice, 75 | _In_opt_ ID3D11DeviceContextX* d3dContext, 76 | #else 77 | _In_ ID3D11Device* d3dDevice, 78 | _In_opt_ ID3D11DeviceContext* d3dContext, 79 | #endif 80 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 81 | _In_ size_t ddsDataSize, 82 | _Outptr_opt_ ID3D11Resource** texture, 83 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 84 | _In_ size_t maxsize = 0, 85 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 86 | 87 | HRESULT __cdecl CreateDDSTextureFromFile( 88 | #if defined(_XBOX_ONE) && defined(_TITLE) 89 | _In_ ID3D11DeviceX* d3dDevice, 90 | _In_opt_ ID3D11DeviceContextX* d3dContext, 91 | #else 92 | _In_ ID3D11Device* d3dDevice, 93 | _In_opt_ ID3D11DeviceContext* d3dContext, 94 | #endif 95 | _In_z_ const wchar_t* szFileName, 96 | _Outptr_opt_ ID3D11Resource** texture, 97 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 98 | _In_ size_t maxsize = 0, 99 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 100 | 101 | // Extended version 102 | HRESULT __cdecl CreateDDSTextureFromMemoryEx( 103 | _In_ ID3D11Device* d3dDevice, 104 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 105 | _In_ size_t ddsDataSize, 106 | _In_ size_t maxsize, 107 | _In_ D3D11_USAGE usage, 108 | _In_ unsigned int bindFlags, 109 | _In_ unsigned int cpuAccessFlags, 110 | _In_ unsigned int miscFlags, 111 | _In_ DDS_LOADER_FLAGS loadFlags, 112 | _Outptr_opt_ ID3D11Resource** texture, 113 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 114 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 115 | 116 | HRESULT __cdecl CreateDDSTextureFromFileEx( 117 | _In_ ID3D11Device* d3dDevice, 118 | _In_z_ const wchar_t* szFileName, 119 | _In_ size_t maxsize, 120 | _In_ D3D11_USAGE usage, 121 | _In_ unsigned int bindFlags, 122 | _In_ unsigned int cpuAccessFlags, 123 | _In_ unsigned int miscFlags, 124 | _In_ DDS_LOADER_FLAGS loadFlags, 125 | _Outptr_opt_ ID3D11Resource** texture, 126 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 127 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 128 | 129 | // Extended version with optional auto-gen mipmap support 130 | HRESULT __cdecl CreateDDSTextureFromMemoryEx( 131 | #if defined(_XBOX_ONE) && defined(_TITLE) 132 | _In_ ID3D11DeviceX* d3dDevice, 133 | _In_opt_ ID3D11DeviceContextX* d3dContext, 134 | #else 135 | _In_ ID3D11Device* d3dDevice, 136 | _In_opt_ ID3D11DeviceContext* d3dContext, 137 | #endif 138 | _In_reads_bytes_(ddsDataSize) const uint8_t* ddsData, 139 | _In_ size_t ddsDataSize, 140 | _In_ size_t maxsize, 141 | _In_ D3D11_USAGE usage, 142 | _In_ unsigned int bindFlags, 143 | _In_ unsigned int cpuAccessFlags, 144 | _In_ unsigned int miscFlags, 145 | _In_ DDS_LOADER_FLAGS loadFlags, 146 | _Outptr_opt_ ID3D11Resource** texture, 147 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 148 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 149 | 150 | HRESULT __cdecl CreateDDSTextureFromFileEx( 151 | #if defined(_XBOX_ONE) && defined(_TITLE) 152 | _In_ ID3D11DeviceX* d3dDevice, 153 | _In_opt_ ID3D11DeviceContextX* d3dContext, 154 | #else 155 | _In_ ID3D11Device* d3dDevice, 156 | _In_opt_ ID3D11DeviceContext* d3dContext, 157 | #endif 158 | _In_z_ const wchar_t* szFileName, 159 | _In_ size_t maxsize, 160 | _In_ D3D11_USAGE usage, 161 | _In_ unsigned int bindFlags, 162 | _In_ unsigned int cpuAccessFlags, 163 | _In_ unsigned int miscFlags, 164 | _In_ DDS_LOADER_FLAGS loadFlags, 165 | _Outptr_opt_ ID3D11Resource** texture, 166 | _Outptr_opt_ ID3D11ShaderResourceView** textureView, 167 | _Out_opt_ DDS_ALPHA_MODE* alphaMode = nullptr) noexcept; 168 | 169 | #ifdef __clang__ 170 | #pragma clang diagnostic push 171 | #pragma clang diagnostic ignored "-Wdeprecated-dynamic-exception-spec" 172 | #endif 173 | 174 | inline namespace DX11 175 | { 176 | DEFINE_ENUM_FLAG_OPERATORS(DDS_LOADER_FLAGS); 177 | } 178 | 179 | #ifdef __clang__ 180 | #pragma clang diagnostic pop 181 | #endif 182 | } 183 | -------------------------------------------------------------------------------- /third-party/DirectXTK/GeometricPrimitive.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: GeometricPrimitive.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #include "VertexTypes.h" 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | 23 | namespace DirectX 24 | { 25 | inline namespace DX11 26 | { 27 | class IEffect; 28 | 29 | class GeometricPrimitive 30 | { 31 | public: 32 | GeometricPrimitive(GeometricPrimitive&&) = default; 33 | GeometricPrimitive& operator= (GeometricPrimitive&&) = default; 34 | 35 | GeometricPrimitive(GeometricPrimitive const&) = delete; 36 | GeometricPrimitive& operator= (GeometricPrimitive const&) = delete; 37 | 38 | using VertexType = VertexPositionNormalTexture; 39 | using VertexCollection = std::vector; 40 | using IndexCollection = std::vector; 41 | 42 | virtual ~GeometricPrimitive(); 43 | 44 | // Factory methods. 45 | static std::unique_ptr __cdecl CreateCube(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 46 | static std::unique_ptr __cdecl CreateBox(_In_ ID3D11DeviceContext* deviceContext, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false); 47 | static std::unique_ptr __cdecl CreateSphere(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false); 48 | static std::unique_ptr __cdecl CreateGeoSphere(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); 49 | static std::unique_ptr __cdecl CreateCylinder(_In_ ID3D11DeviceContext* deviceContext, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true); 50 | static std::unique_ptr __cdecl CreateCone(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true); 51 | static std::unique_ptr __cdecl CreateTorus(_In_ ID3D11DeviceContext* deviceContext, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true); 52 | static std::unique_ptr __cdecl CreateTetrahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 53 | static std::unique_ptr __cdecl CreateOctahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 54 | static std::unique_ptr __cdecl CreateDodecahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 55 | static std::unique_ptr __cdecl CreateIcosahedron(_In_ ID3D11DeviceContext* deviceContext, float size = 1, bool rhcoords = true); 56 | static std::unique_ptr __cdecl CreateTeapot(_In_ ID3D11DeviceContext* deviceContext, float size = 1, size_t tessellation = 8, bool rhcoords = true); 57 | static std::unique_ptr __cdecl CreateCustom(_In_ ID3D11DeviceContext* deviceContext, const VertexCollection& vertices, const IndexCollection& indices); 58 | 59 | static void __cdecl CreateCube(VertexCollection& vertices, IndexCollection& indices, float size = 1, bool rhcoords = true); 60 | static void __cdecl CreateBox(VertexCollection& vertices, IndexCollection& indices, const XMFLOAT3& size, bool rhcoords = true, bool invertn = false); 61 | static void __cdecl CreateSphere(VertexCollection& vertices, IndexCollection& indices, float diameter = 1, size_t tessellation = 16, bool rhcoords = true, bool invertn = false); 62 | static void __cdecl CreateGeoSphere(VertexCollection& vertices, IndexCollection& indices, float diameter = 1, size_t tessellation = 3, bool rhcoords = true); 63 | static void __cdecl CreateCylinder(VertexCollection& vertices, IndexCollection& indices, float height = 1, float diameter = 1, size_t tessellation = 32, bool rhcoords = true); 64 | static void __cdecl CreateCone(VertexCollection& vertices, IndexCollection& indices, float diameter = 1, float height = 1, size_t tessellation = 32, bool rhcoords = true); 65 | static void __cdecl CreateTorus(VertexCollection& vertices, IndexCollection& indices, float diameter = 1, float thickness = 0.333f, size_t tessellation = 32, bool rhcoords = true); 66 | static void __cdecl CreateTetrahedron(VertexCollection& vertices, IndexCollection& indices, float size = 1, bool rhcoords = true); 67 | static void __cdecl CreateOctahedron(VertexCollection& vertices, IndexCollection& indices, float size = 1, bool rhcoords = true); 68 | static void __cdecl CreateDodecahedron(VertexCollection& vertices, IndexCollection& indices, float size = 1, bool rhcoords = true); 69 | static void __cdecl CreateIcosahedron(VertexCollection& vertices, IndexCollection& indices, float size = 1, bool rhcoords = true); 70 | static void __cdecl CreateTeapot(VertexCollection& vertices, IndexCollection& indices, float size = 1, size_t tessellation = 8, bool rhcoords = true); 71 | 72 | // Draw the primitive. 73 | void XM_CALLCONV Draw(FXMMATRIX world, CXMMATRIX view, CXMMATRIX projection, 74 | FXMVECTOR color = Colors::White, 75 | _In_opt_ ID3D11ShaderResourceView* texture = nullptr, 76 | bool wireframe = false, 77 | _In_opt_ std::function setCustomState = nullptr) const; 78 | 79 | // Draw the primitive using a custom effect. 80 | void __cdecl Draw(_In_ IEffect* effect, 81 | _In_ ID3D11InputLayout* inputLayout, 82 | bool alpha = false, bool wireframe = false, 83 | _In_opt_ std::function setCustomState = nullptr) const; 84 | 85 | void __cdecl DrawInstanced(_In_ IEffect* effect, 86 | _In_ ID3D11InputLayout* inputLayout, 87 | uint32_t instanceCount, 88 | bool alpha = false, bool wireframe = false, 89 | uint32_t startInstanceLocation = 0, 90 | _In_opt_ std::function setCustomState = nullptr) const; 91 | 92 | // Create input layout for drawing with a custom effect. 93 | void __cdecl CreateInputLayout(_In_ IEffect* effect, _Outptr_ ID3D11InputLayout** inputLayout) const; 94 | 95 | static void SetDepthBufferMode(bool reverseZ) 96 | { 97 | s_reversez = reverseZ; 98 | } 99 | 100 | private: 101 | static bool s_reversez; 102 | 103 | GeometricPrimitive() noexcept(false); 104 | 105 | // Private implementation. 106 | class Impl; 107 | 108 | std::unique_ptr pImpl; 109 | }; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /third-party/DirectXTK/DirectXHelpers.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: DirectXHelpers.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) 19 | #if !defined(_XBOX_ONE) || !defined(_TITLE) 20 | #pragma comment(lib,"dxguid.lib") 21 | #endif 22 | #endif 23 | 24 | #ifndef IID_GRAPHICS_PPV_ARGS 25 | #define IID_GRAPHICS_PPV_ARGS(x) IID_PPV_ARGS(x) 26 | #endif 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | // 35 | // The core Direct3D headers provide the following helper C++ classes 36 | // CD3D11_RECT 37 | // CD3D11_BOX 38 | // CD3D11_DEPTH_STENCIL_DESC 39 | // CD3D11_BLEND_DESC, CD3D11_BLEND_DESC1 40 | // CD3D11_RASTERIZER_DESC, CD3D11_RASTERIZER_DESC1 41 | // CD3D11_BUFFER_DESC 42 | // CD3D11_TEXTURE1D_DESC 43 | // CD3D11_TEXTURE2D_DESC 44 | // CD3D11_TEXTURE3D_DESC 45 | // CD3D11_SHADER_RESOURCE_VIEW_DESC 46 | // CD3D11_RENDER_TARGET_VIEW_DESC 47 | // CD3D11_VIEWPORT 48 | // CD3D11_DEPTH_STENCIL_VIEW_DESC 49 | // CD3D11_UNORDERED_ACCESS_VIEW_DESC 50 | // CD3D11_SAMPLER_DESC 51 | // CD3D11_QUERY_DESC 52 | // CD3D11_COUNTER_DESC 53 | // 54 | 55 | 56 | namespace DirectX 57 | { 58 | inline namespace DX11 59 | { 60 | class IEffect; 61 | } 62 | 63 | // simliar to std::lock_guard for exception-safe Direct3D resource locking 64 | class MapGuard : public D3D11_MAPPED_SUBRESOURCE 65 | { 66 | public: 67 | MapGuard(_In_ ID3D11DeviceContext* context, 68 | _In_ ID3D11Resource *resource, 69 | _In_ unsigned int subresource, 70 | _In_ D3D11_MAP mapType, 71 | _In_ unsigned int mapFlags) noexcept(false) 72 | : mContext(context), mResource(resource), mSubresource(subresource) 73 | { 74 | HRESULT hr = mContext->Map(resource, subresource, mapType, mapFlags, this); 75 | if (FAILED(hr)) 76 | { 77 | throw std::exception(); 78 | } 79 | } 80 | 81 | MapGuard(MapGuard&&) = default; 82 | MapGuard& operator= (MapGuard&&) = default; 83 | 84 | MapGuard(MapGuard const&) = delete; 85 | MapGuard& operator= (MapGuard const&) = delete; 86 | 87 | ~MapGuard() 88 | { 89 | mContext->Unmap(mResource, mSubresource); 90 | } 91 | 92 | uint8_t* get() const noexcept 93 | { 94 | return static_cast(pData); 95 | } 96 | uint8_t* get(size_t slice) const noexcept 97 | { 98 | return static_cast(pData) + (slice * DepthPitch); 99 | } 100 | 101 | uint8_t* scanline(size_t row) const noexcept 102 | { 103 | return static_cast(pData) + (row * RowPitch); 104 | } 105 | uint8_t* scanline(size_t slice, size_t row) const noexcept 106 | { 107 | return static_cast(pData) + (slice * DepthPitch) + (row * RowPitch); 108 | } 109 | 110 | template 111 | void copy(_In_reads_(count) T const* data, size_t count) noexcept 112 | { 113 | memcpy(pData, data, count * sizeof(T)); 114 | } 115 | 116 | template 117 | void copy(T const& data) noexcept 118 | { 119 | memcpy(pData, data.data(), data.size() * sizeof(typename T::value_type)); 120 | } 121 | 122 | private: 123 | ID3D11DeviceContext* mContext; 124 | ID3D11Resource* mResource; 125 | unsigned int mSubresource; 126 | }; 127 | 128 | 129 | // Helper sets a D3D resource name string (used by PIX and debug layer leak reporting). 130 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) 131 | template 132 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const char(&name)[TNameLength]) noexcept 133 | { 134 | #if defined(_XBOX_ONE) && defined(_TITLE) 135 | wchar_t wname[MAX_PATH]; 136 | int result = MultiByteToWideChar(CP_UTF8, 0, name, TNameLength, wname, MAX_PATH); 137 | if (result > 0) 138 | { 139 | resource->SetName(wname); 140 | } 141 | #else 142 | resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); 143 | #endif 144 | } 145 | #else 146 | template 147 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild*, _In_z_ const char(&)[TNameLength]) noexcept 148 | { 149 | } 150 | #endif 151 | 152 | #if !defined(NO_D3D11_DEBUG_NAME) && ( defined(_DEBUG) || defined(PROFILE) ) 153 | template 154 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild* resource, _In_z_ const wchar_t(&name)[TNameLength]) 155 | { 156 | #if defined(_XBOX_ONE) && defined(_TITLE) 157 | resource->SetName(name); 158 | #else 159 | char aname[MAX_PATH]; 160 | int result = WideCharToMultiByte(CP_UTF8, 0, name, TNameLength, aname, MAX_PATH, nullptr, nullptr); 161 | if (result > 0) 162 | { 163 | resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, aname); 164 | } 165 | #endif 166 | } 167 | #else 168 | template 169 | inline void SetDebugObjectName(_In_ ID3D11DeviceChild*, _In_z_ const wchar_t(&)[TNameLength]) 170 | { 171 | } 172 | #endif 173 | 174 | inline namespace DX11 175 | { 176 | // Helper to check for power-of-2 177 | template 178 | constexpr bool IsPowerOf2(T x) noexcept { return ((x != 0) && !(x & (x - 1))); } 179 | 180 | // Helpers for aligning values by a power of 2 181 | template 182 | inline T AlignDown(T size, size_t alignment) noexcept 183 | { 184 | if (alignment > 0) 185 | { 186 | assert(((alignment - 1) & alignment) == 0); 187 | auto mask = static_cast(alignment - 1); 188 | return size & ~mask; 189 | } 190 | return size; 191 | } 192 | 193 | template 194 | inline T AlignUp(T size, size_t alignment) noexcept 195 | { 196 | if (alignment > 0) 197 | { 198 | assert(((alignment - 1) & alignment) == 0); 199 | auto mask = static_cast(alignment - 1); 200 | return (size + mask) & ~mask; 201 | } 202 | return size; 203 | } 204 | } 205 | 206 | // Helper for creating a Direct3D input layout to match a shader from an IEffect 207 | HRESULT __cdecl CreateInputLayoutFromEffect(_In_ ID3D11Device* device, 208 | _In_ IEffect* effect, 209 | _In_reads_(count) const D3D11_INPUT_ELEMENT_DESC* desc, 210 | size_t count, 211 | _COM_Outptr_ ID3D11InputLayout** pInputLayout) noexcept; 212 | 213 | template 214 | HRESULT CreateInputLayoutFromEffect(_In_ ID3D11Device* device, 215 | _In_ IEffect* effect, 216 | _COM_Outptr_ ID3D11InputLayout** pInputLayout) noexcept 217 | { 218 | return CreateInputLayoutFromEffect(device, effect, T::InputElements, T::InputElementCount, pInputLayout); 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # Tests 7 | Tests/ 8 | 9 | # User-specific files 10 | *.rsuser 11 | *.suo 12 | *.user 13 | *.userosscache 14 | *.sln.docstates 15 | 16 | # User-specific files (MonoDevelop/Xamarin Studio) 17 | *.userprefs 18 | 19 | # Mono auto generated files 20 | mono_crash.* 21 | 22 | # Build results 23 | [Dd]ebug/ 24 | [Dd]ebugPublic/ 25 | [Rr]elease/ 26 | [Rr]eleases/ 27 | x64/ 28 | x86/ 29 | [Ww][Ii][Nn]32/ 30 | [Aa][Rr][Mm]/ 31 | [Aa][Rr][Mm]64/ 32 | bld/ 33 | [Bb]in/ 34 | [Oo]bj/ 35 | [Oo]ut/ 36 | [Ll]og/ 37 | [Ll]ogs/ 38 | 39 | # Visual Studio 2015/2017 cache/options directory 40 | .vs/ 41 | # Uncomment if you have tasks that create the project's static files in wwwroot 42 | #wwwroot/ 43 | 44 | # Visual Studio 2017 auto generated files 45 | Generated\ Files/ 46 | 47 | # MSTest test Results 48 | [Tt]est[Rr]esult*/ 49 | [Bb]uild[Ll]og.* 50 | 51 | # NUnit 52 | *.VisualState.xml 53 | TestResult.xml 54 | nunit-*.xml 55 | 56 | # Build Results of an ATL Project 57 | [Dd]ebugPS/ 58 | [Rr]eleasePS/ 59 | dlldata.c 60 | 61 | # Benchmark Results 62 | BenchmarkDotNet.Artifacts/ 63 | 64 | # .NET Core 65 | project.lock.json 66 | project.fragment.lock.json 67 | artifacts/ 68 | 69 | # ASP.NET Scaffolding 70 | ScaffoldingReadMe.txt 71 | 72 | # StyleCop 73 | StyleCopReport.xml 74 | 75 | # Files built by Visual Studio 76 | *_i.c 77 | *_p.c 78 | *_h.h 79 | *.ilk 80 | *.meta 81 | *.obj 82 | *.iobj 83 | *.pch 84 | *.pdb 85 | *.ipdb 86 | *.pgc 87 | *.pgd 88 | *.rsp 89 | *.sbr 90 | *.tlb 91 | *.tli 92 | *.tlh 93 | *.tmp 94 | *.tmp_proj 95 | *_wpftmp.csproj 96 | *.log 97 | *.vspscc 98 | *.vssscc 99 | .builds 100 | *.pidb 101 | *.svclog 102 | *.scc 103 | 104 | # Chutzpah Test files 105 | _Chutzpah* 106 | 107 | # Visual C++ cache files 108 | ipch/ 109 | *.aps 110 | *.ncb 111 | *.opendb 112 | *.opensdf 113 | *.sdf 114 | *.cachefile 115 | *.VC.db 116 | *.VC.VC.opendb 117 | 118 | # Visual Studio profiler 119 | *.psess 120 | *.vsp 121 | *.vspx 122 | *.sap 123 | 124 | # Visual Studio Trace Files 125 | *.e2e 126 | 127 | # TFS 2012 Local Workspace 128 | $tf/ 129 | 130 | # Guidance Automation Toolkit 131 | *.gpState 132 | 133 | # ReSharper is a .NET coding add-in 134 | _ReSharper*/ 135 | *.[Rr]e[Ss]harper 136 | *.DotSettings.user 137 | 138 | # TeamCity is a build add-in 139 | _TeamCity* 140 | 141 | # DotCover is a Code Coverage Tool 142 | *.dotCover 143 | 144 | # AxoCover is a Code Coverage Tool 145 | .axoCover/* 146 | !.axoCover/settings.json 147 | 148 | # Coverlet is a free, cross platform Code Coverage Tool 149 | coverage*.json 150 | coverage*.xml 151 | coverage*.info 152 | 153 | # Visual Studio code coverage results 154 | *.coverage 155 | *.coveragexml 156 | 157 | # NCrunch 158 | _NCrunch_* 159 | .*crunch*.local.xml 160 | nCrunchTemp_* 161 | 162 | # MightyMoose 163 | *.mm.* 164 | AutoTest.Net/ 165 | 166 | # Web workbench (sass) 167 | .sass-cache/ 168 | 169 | # Installshield output folder 170 | [Ee]xpress/ 171 | 172 | # DocProject is a documentation generator add-in 173 | DocProject/buildhelp/ 174 | DocProject/Help/*.HxT 175 | DocProject/Help/*.HxC 176 | DocProject/Help/*.hhc 177 | DocProject/Help/*.hhk 178 | DocProject/Help/*.hhp 179 | DocProject/Help/Html2 180 | DocProject/Help/html 181 | 182 | # Click-Once directory 183 | publish/ 184 | 185 | # Publish Web Output 186 | *.[Pp]ublish.xml 187 | *.azurePubxml 188 | # Note: Comment the next line if you want to checkin your web deploy settings, 189 | # but database connection strings (with potential passwords) will be unencrypted 190 | *.pubxml 191 | *.publishproj 192 | 193 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 194 | # checkin your Azure Web App publish settings, but sensitive information contained 195 | # in these scripts will be unencrypted 196 | PublishScripts/ 197 | 198 | # NuGet Packages 199 | *.nupkg 200 | # NuGet Symbol Packages 201 | *.snupkg 202 | # The packages folder can be ignored because of Package Restore 203 | **/[Pp]ackages/* 204 | # except build/, which is used as an MSBuild target. 205 | !**/[Pp]ackages/build/ 206 | # Uncomment if necessary however generally it will be regenerated when needed 207 | #!**/[Pp]ackages/repositories.config 208 | # NuGet v3's project.json files produces more ignorable files 209 | *.nuget.props 210 | *.nuget.targets 211 | 212 | # Microsoft Azure Build Output 213 | csx/ 214 | *.build.csdef 215 | 216 | # Microsoft Azure Emulator 217 | ecf/ 218 | rcf/ 219 | 220 | # Windows Store app package directories and files 221 | AppPackages/ 222 | BundleArtifacts/ 223 | Package.StoreAssociation.xml 224 | _pkginfo.txt 225 | *.appx 226 | *.appxbundle 227 | *.appxupload 228 | 229 | # Visual Studio cache files 230 | # files ending in .cache can be ignored 231 | *.[Cc]ache 232 | # but keep track of directories ending in .cache 233 | !?*.[Cc]ache/ 234 | 235 | # Others 236 | ClientBin/ 237 | ~$* 238 | *~ 239 | *.dbmdl 240 | *.dbproj.schemaview 241 | *.jfm 242 | *.pfx 243 | *.publishsettings 244 | orleans.codegen.cs 245 | 246 | # Including strong name files can present a security risk 247 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 248 | #*.snk 249 | 250 | # Since there are multiple workflows, uncomment next line to ignore bower_components 251 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 252 | #bower_components/ 253 | 254 | # RIA/Silverlight projects 255 | Generated_Code/ 256 | 257 | # Backup & report files from converting an old project file 258 | # to a newer Visual Studio version. Backup files are not needed, 259 | # because we have git ;-) 260 | _UpgradeReport_Files/ 261 | Backup*/ 262 | UpgradeLog*.XML 263 | UpgradeLog*.htm 264 | ServiceFabricBackup/ 265 | *.rptproj.bak 266 | 267 | # SQL Server files 268 | *.mdf 269 | *.ldf 270 | *.ndf 271 | 272 | # Business Intelligence projects 273 | *.rdl.data 274 | *.bim.layout 275 | *.bim_*.settings 276 | *.rptproj.rsuser 277 | *- [Bb]ackup.rdl 278 | *- [Bb]ackup ([0-9]).rdl 279 | *- [Bb]ackup ([0-9][0-9]).rdl 280 | 281 | # Microsoft Fakes 282 | FakesAssemblies/ 283 | 284 | # GhostDoc plugin setting file 285 | *.GhostDoc.xml 286 | 287 | # Node.js Tools for Visual Studio 288 | .ntvs_analysis.dat 289 | node_modules/ 290 | 291 | # Visual Studio 6 build log 292 | *.plg 293 | 294 | # Visual Studio 6 workspace options file 295 | *.opt 296 | 297 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 298 | *.vbw 299 | 300 | # Visual Studio LightSwitch build output 301 | **/*.HTMLClient/GeneratedArtifacts 302 | **/*.DesktopClient/GeneratedArtifacts 303 | **/*.DesktopClient/ModelManifest.xml 304 | **/*.Server/GeneratedArtifacts 305 | **/*.Server/ModelManifest.xml 306 | _Pvt_Extensions 307 | 308 | # Paket dependency manager 309 | .paket/paket.exe 310 | paket-files/ 311 | 312 | # FAKE - F# Make 313 | .fake/ 314 | 315 | # CodeRush personal settings 316 | .cr/personal 317 | 318 | # Python Tools for Visual Studio (PTVS) 319 | __pycache__/ 320 | *.pyc 321 | 322 | # Cake - Uncomment if you are using it 323 | # tools/** 324 | # !tools/packages.config 325 | 326 | # Tabs Studio 327 | *.tss 328 | 329 | # Telerik's JustMock configuration file 330 | *.jmconfig 331 | 332 | # BizTalk build output 333 | *.btp.cs 334 | *.btm.cs 335 | *.odx.cs 336 | *.xsd.cs 337 | 338 | # OpenCover UI analysis results 339 | OpenCover/ 340 | 341 | # Azure Stream Analytics local run output 342 | ASALocalRun/ 343 | 344 | # MSBuild Binary and Structured Log 345 | *.binlog 346 | 347 | # NVidia Nsight GPU debugger configuration file 348 | *.nvuser 349 | 350 | # MFractors (Xamarin productivity tool) working folder 351 | .mfractor/ 352 | 353 | # Local History for Visual Studio 354 | .localhistory/ 355 | 356 | # BeatPulse healthcheck temp database 357 | healthchecksdb 358 | 359 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 360 | MigrationBackup/ 361 | 362 | # Ionide (cross platform F# VS Code tools) working folder 363 | .ionide/ 364 | 365 | # Fody - auto-generated XML schema 366 | FodyWeavers.xsd -------------------------------------------------------------------------------- /third-party/ViGEm/Common.h: -------------------------------------------------------------------------------- 1 | /* 2 | MIT License 3 | 4 | Copyright (c) 2017-2019 Nefarius Software Solutions e.U. and Contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | */ 24 | 25 | 26 | #pragma once 27 | 28 | // 29 | // Represents the desired target type for the emulated device. 30 | // 31 | typedef enum _VIGEM_TARGET_TYPE 32 | { 33 | // 34 | // Microsoft Xbox 360 Controller (wired) 35 | // 36 | Xbox360Wired = 0, 37 | // 38 | // Sony DualShock 4 (wired) 39 | // 40 | DualShock4Wired = 2 // NOTE: 1 skipped on purpose to maintain compatibility 41 | 42 | } VIGEM_TARGET_TYPE, *PVIGEM_TARGET_TYPE; 43 | 44 | // 45 | // Possible XUSB report buttons. 46 | // 47 | typedef enum _XUSB_BUTTON 48 | { 49 | XUSB_GAMEPAD_DPAD_UP = 0x0001, 50 | XUSB_GAMEPAD_DPAD_DOWN = 0x0002, 51 | XUSB_GAMEPAD_DPAD_LEFT = 0x0004, 52 | XUSB_GAMEPAD_DPAD_RIGHT = 0x0008, 53 | XUSB_GAMEPAD_START = 0x0010, 54 | XUSB_GAMEPAD_BACK = 0x0020, 55 | XUSB_GAMEPAD_LEFT_THUMB = 0x0040, 56 | XUSB_GAMEPAD_RIGHT_THUMB = 0x0080, 57 | XUSB_GAMEPAD_LEFT_SHOULDER = 0x0100, 58 | XUSB_GAMEPAD_RIGHT_SHOULDER = 0x0200, 59 | XUSB_GAMEPAD_GUIDE = 0x0400, 60 | XUSB_GAMEPAD_A = 0x1000, 61 | XUSB_GAMEPAD_B = 0x2000, 62 | XUSB_GAMEPAD_X = 0x4000, 63 | XUSB_GAMEPAD_Y = 0x8000 64 | 65 | } XUSB_BUTTON, *PXUSB_BUTTON; 66 | 67 | // 68 | // Represents an XINPUT_GAMEPAD-compatible report structure. 69 | // 70 | typedef struct _XUSB_REPORT 71 | { 72 | USHORT wButtons; 73 | BYTE bLeftTrigger; 74 | BYTE bRightTrigger; 75 | SHORT sThumbLX; 76 | SHORT sThumbLY; 77 | SHORT sThumbRX; 78 | SHORT sThumbRY; 79 | 80 | } XUSB_REPORT, *PXUSB_REPORT; 81 | 82 | // 83 | // Initializes a _XUSB_REPORT structure. 84 | // 85 | VOID FORCEINLINE XUSB_REPORT_INIT( 86 | _Out_ PXUSB_REPORT Report 87 | ) 88 | { 89 | RtlZeroMemory(Report, sizeof(XUSB_REPORT)); 90 | } 91 | 92 | // 93 | // The color value (RGB) of a DualShock 4 Lightbar 94 | // 95 | typedef struct _DS4_LIGHTBAR_COLOR 96 | { 97 | // 98 | // Red part of the Lightbar (0-255). 99 | // 100 | UCHAR Red; 101 | 102 | // 103 | // Green part of the Lightbar (0-255). 104 | // 105 | UCHAR Green; 106 | 107 | // 108 | // Blue part of the Lightbar (0-255). 109 | // 110 | UCHAR Blue; 111 | 112 | } DS4_LIGHTBAR_COLOR, *PDS4_LIGHTBAR_COLOR; 113 | 114 | // 115 | // DualShock 4 digital buttons 116 | // 117 | typedef enum _DS4_BUTTONS 118 | { 119 | DS4_BUTTON_THUMB_RIGHT = 1 << 15, 120 | DS4_BUTTON_THUMB_LEFT = 1 << 14, 121 | DS4_BUTTON_OPTIONS = 1 << 13, 122 | DS4_BUTTON_SHARE = 1 << 12, 123 | DS4_BUTTON_TRIGGER_RIGHT = 1 << 11, 124 | DS4_BUTTON_TRIGGER_LEFT = 1 << 10, 125 | DS4_BUTTON_SHOULDER_RIGHT = 1 << 9, 126 | DS4_BUTTON_SHOULDER_LEFT = 1 << 8, 127 | DS4_BUTTON_TRIANGLE = 1 << 7, 128 | DS4_BUTTON_CIRCLE = 1 << 6, 129 | DS4_BUTTON_CROSS = 1 << 5, 130 | DS4_BUTTON_SQUARE = 1 << 4 131 | 132 | } DS4_BUTTONS, *PDS4_BUTTONS; 133 | 134 | // 135 | // DualShock 4 special buttons 136 | // 137 | typedef enum _DS4_SPECIAL_BUTTONS 138 | { 139 | DS4_SPECIAL_BUTTON_PS = 1 << 0, 140 | DS4_SPECIAL_BUTTON_TOUCHPAD = 1 << 1 141 | 142 | } DS4_SPECIAL_BUTTONS, *PDS4_SPECIAL_BUTTONS; 143 | 144 | // 145 | // DualShock 4 directional pad (HAT) values 146 | // 147 | typedef enum _DS4_DPAD_DIRECTIONS 148 | { 149 | DS4_BUTTON_DPAD_NONE = 0x8, 150 | DS4_BUTTON_DPAD_NORTHWEST = 0x7, 151 | DS4_BUTTON_DPAD_WEST = 0x6, 152 | DS4_BUTTON_DPAD_SOUTHWEST = 0x5, 153 | DS4_BUTTON_DPAD_SOUTH = 0x4, 154 | DS4_BUTTON_DPAD_SOUTHEAST = 0x3, 155 | DS4_BUTTON_DPAD_EAST = 0x2, 156 | DS4_BUTTON_DPAD_NORTHEAST = 0x1, 157 | DS4_BUTTON_DPAD_NORTH = 0x0 158 | 159 | } DS4_DPAD_DIRECTIONS, *PDS4_DPAD_DIRECTIONS; 160 | 161 | // 162 | // DualShock 4 HID Input report 163 | // 164 | typedef struct _DS4_REPORT 165 | { 166 | BYTE bThumbLX; 167 | BYTE bThumbLY; 168 | BYTE bThumbRX; 169 | BYTE bThumbRY; 170 | USHORT wButtons; 171 | BYTE bSpecial; 172 | BYTE bTriggerL; 173 | BYTE bTriggerR; 174 | 175 | } DS4_REPORT, *PDS4_REPORT; 176 | 177 | // 178 | // Sets the current state of the D-PAD on a DualShock 4 report. 179 | // 180 | VOID FORCEINLINE DS4_SET_DPAD( 181 | _Out_ PDS4_REPORT Report, 182 | _In_ DS4_DPAD_DIRECTIONS Dpad 183 | ) 184 | { 185 | Report->wButtons &= ~0xF; 186 | Report->wButtons |= (USHORT)Dpad; 187 | } 188 | 189 | VOID FORCEINLINE DS4_REPORT_INIT( 190 | _Out_ PDS4_REPORT Report 191 | ) 192 | { 193 | RtlZeroMemory(Report, sizeof(DS4_REPORT)); 194 | 195 | Report->bThumbLX = 0x80; 196 | Report->bThumbLY = 0x80; 197 | Report->bThumbRX = 0x80; 198 | Report->bThumbRY = 0x80; 199 | 200 | DS4_SET_DPAD(Report, DS4_BUTTON_DPAD_NONE); 201 | } 202 | 203 | #include // pack structs tightly 204 | // 205 | // DualShock 4 HID Touchpad structure 206 | // 207 | typedef struct _DS4_TOUCH 208 | { 209 | BYTE bPacketCounter; // timestamp / packet counter associated with touch event 210 | BYTE bIsUpTrackingNum1; // 0 means down; active low 211 | // unique to each finger down, so for a lift and repress the value is incremented 212 | BYTE bTouchData1[3]; // Two 12 bits values (for X and Y) 213 | // middle byte holds last 4 bits of X and the starting 4 bits of Y 214 | BYTE bIsUpTrackingNum2; // second touch data immediately follows data of first touch 215 | BYTE bTouchData2[3]; // resolution is 1920x943 216 | } DS4_TOUCH, * PDS4_TOUCH; 217 | 218 | // 219 | // DualShock 4 v1 complete HID Input report 220 | // 221 | typedef struct _DS4_REPORT_EX 222 | { 223 | union 224 | { 225 | struct 226 | { 227 | BYTE bThumbLX; 228 | BYTE bThumbLY; 229 | BYTE bThumbRX; 230 | BYTE bThumbRY; 231 | USHORT wButtons; 232 | BYTE bSpecial; 233 | BYTE bTriggerL; 234 | BYTE bTriggerR; 235 | USHORT wTimestamp; 236 | BYTE bBatteryLvl; 237 | SHORT wGyroX; 238 | SHORT wGyroY; 239 | SHORT wGyroZ; 240 | SHORT wAccelX; 241 | SHORT wAccelY; 242 | SHORT wAccelZ; 243 | BYTE _bUnknown1[5]; 244 | BYTE bBatteryLvlSpecial; 245 | // really should have a enum to show everything that this can represent (USB charging, battery level; EXT, headset, microphone connected) 246 | BYTE _bUnknown2[2]; 247 | BYTE bTouchPacketsN; // 0x00 to 0x03 (USB max) 248 | DS4_TOUCH sCurrentTouch; 249 | DS4_TOUCH sPreviousTouch[2]; 250 | } Report; 251 | 252 | UCHAR ReportBuffer[63]; 253 | }; 254 | } DS4_REPORT_EX, *PDS4_REPORT_EX; 255 | 256 | typedef struct _DS4_OUTPUT_BUFFER 257 | { 258 | // 259 | // The output report buffer 260 | // 261 | _Out_ UCHAR Buffer[64]; 262 | 263 | } DS4_OUTPUT_BUFFER, *PDS4_OUTPUT_BUFFER; 264 | 265 | #include 266 | -------------------------------------------------------------------------------- /src/Injector/DLL_Injector.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {E80316C9-A824-45FA-997F-491509A04AB7} 23 | Win32Proj 24 | DLL_Injector 25 | 10.0 26 | 27 | 28 | 29 | Application 30 | true 31 | v143 32 | NotSet 33 | 34 | 35 | Application 36 | false 37 | v143 38 | true 39 | Unicode 40 | 41 | 42 | Application 43 | true 44 | v143 45 | Unicode 46 | 47 | 48 | Application 49 | false 50 | v143 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | 75 | 76 | true 77 | 78 | 79 | false 80 | 81 | 82 | false 83 | Launcher 84 | 85 | 86 | 87 | 88 | 89 | Level3 90 | Disabled 91 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 92 | 93 | 94 | Console 95 | true 96 | 97 | 98 | 99 | 100 | 101 | 102 | Level3 103 | Disabled 104 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 105 | 106 | 107 | Console 108 | true 109 | 110 | 111 | 112 | 113 | Level3 114 | 115 | 116 | MaxSpeed 117 | true 118 | true 119 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 120 | 121 | 122 | Console 123 | true 124 | true 125 | true 126 | 127 | 128 | 129 | 130 | Level3 131 | 132 | 133 | MaxSpeed 134 | true 135 | true 136 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 137 | 138 | 139 | Console 140 | true 141 | true 142 | true 143 | 144 | 145 | copy "$(SOLUTIONDIR)x64\Release\Launcher.exe" "$(SOLUTIONDIR)bin" 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /third-party/minhook/MinHook.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 | #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) 32 | #error MinHook supports only x86 and x64 systems. 33 | #endif 34 | 35 | #include 36 | 37 | // MinHook Error Codes. 38 | typedef enum MH_STATUS 39 | { 40 | // Unknown error. Should not be returned. 41 | MH_UNKNOWN = -1, 42 | 43 | // Successful. 44 | MH_OK = 0, 45 | 46 | // MinHook is already initialized. 47 | MH_ERROR_ALREADY_INITIALIZED, 48 | 49 | // MinHook is not initialized yet, or already uninitialized. 50 | MH_ERROR_NOT_INITIALIZED, 51 | 52 | // The hook for the specified target function is already created. 53 | MH_ERROR_ALREADY_CREATED, 54 | 55 | // The hook for the specified target function is not created yet. 56 | MH_ERROR_NOT_CREATED, 57 | 58 | // The hook for the specified target function is already enabled. 59 | MH_ERROR_ENABLED, 60 | 61 | // The hook for the specified target function is not enabled yet, or already 62 | // disabled. 63 | MH_ERROR_DISABLED, 64 | 65 | // The specified pointer is invalid. It points the address of non-allocated 66 | // and/or non-executable region. 67 | MH_ERROR_NOT_EXECUTABLE, 68 | 69 | // The specified target function cannot be hooked. 70 | MH_ERROR_UNSUPPORTED_FUNCTION, 71 | 72 | // Failed to allocate memory. 73 | MH_ERROR_MEMORY_ALLOC, 74 | 75 | // Failed to change the memory protection. 76 | MH_ERROR_MEMORY_PROTECT, 77 | 78 | // The specified module is not loaded. 79 | MH_ERROR_MODULE_NOT_FOUND, 80 | 81 | // The specified function is not found. 82 | MH_ERROR_FUNCTION_NOT_FOUND 83 | } 84 | MH_STATUS; 85 | 86 | // Can be passed as a parameter to MH_EnableHook, MH_DisableHook, 87 | // MH_QueueEnableHook or MH_QueueDisableHook. 88 | #define MH_ALL_HOOKS NULL 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | // Initialize the MinHook library. You must call this function EXACTLY ONCE 95 | // at the beginning of your program. 96 | MH_STATUS WINAPI MH_Initialize(VOID); 97 | 98 | // Uninitialize the MinHook library. You must call this function EXACTLY 99 | // ONCE at the end of your program. 100 | MH_STATUS WINAPI MH_Uninitialize(VOID); 101 | 102 | // Creates a hook for the specified target function, in disabled state. 103 | // Parameters: 104 | // pTarget [in] A pointer to the target function, which will be 105 | // overridden by the detour function. 106 | // pDetour [in] A pointer to the detour function, which will override 107 | // the target function. 108 | // ppOriginal [out] A pointer to the trampoline function, which will be 109 | // used to call the original target function. 110 | // This parameter can be NULL. 111 | MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal); 112 | 113 | // Creates a hook for the specified API function, in disabled state. 114 | // Parameters: 115 | // pszModule [in] A pointer to the loaded module name which contains the 116 | // target function. 117 | // pszProcName [in] A pointer to the target function name, which will be 118 | // overridden by the detour function. 119 | // pDetour [in] A pointer to the detour function, which will override 120 | // the target function. 121 | // ppOriginal [out] A pointer to the trampoline function, which will be 122 | // used to call the original target function. 123 | // This parameter can be NULL. 124 | MH_STATUS WINAPI MH_CreateHookApi( 125 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal); 126 | 127 | // Creates a hook for the specified API function, in disabled state. 128 | // Parameters: 129 | // pszModule [in] A pointer to the loaded module name which contains the 130 | // target function. 131 | // pszProcName [in] A pointer to the target function name, which will be 132 | // overridden by the detour function. 133 | // pDetour [in] A pointer to the detour function, which will override 134 | // the target function. 135 | // ppOriginal [out] A pointer to the trampoline function, which will be 136 | // used to call the original target function. 137 | // This parameter can be NULL. 138 | // ppTarget [out] A pointer to the target function, which will be used 139 | // with other functions. 140 | // This parameter can be NULL. 141 | MH_STATUS WINAPI MH_CreateHookApiEx( 142 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal, LPVOID *ppTarget); 143 | 144 | // Removes an already created hook. 145 | // Parameters: 146 | // pTarget [in] A pointer to the target function. 147 | MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); 148 | 149 | // Enables an already created hook. 150 | // Parameters: 151 | // pTarget [in] A pointer to the target function. 152 | // If this parameter is MH_ALL_HOOKS, all created hooks are 153 | // enabled in one go. 154 | MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); 155 | 156 | // Disables an already created hook. 157 | // Parameters: 158 | // pTarget [in] A pointer to the target function. 159 | // If this parameter is MH_ALL_HOOKS, all created hooks are 160 | // disabled in one go. 161 | MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); 162 | 163 | // Queues to enable an already created hook. 164 | // Parameters: 165 | // pTarget [in] A pointer to the target function. 166 | // If this parameter is MH_ALL_HOOKS, all created hooks are 167 | // queued to be enabled. 168 | MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); 169 | 170 | // Queues to disable an already created hook. 171 | // Parameters: 172 | // pTarget [in] A pointer to the target function. 173 | // If this parameter is MH_ALL_HOOKS, all created hooks are 174 | // queued to be disabled. 175 | MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); 176 | 177 | // Applies all queued changes in one go. 178 | MH_STATUS WINAPI MH_ApplyQueued(VOID); 179 | 180 | // Translates the MH_STATUS to its name as a string. 181 | const char * WINAPI MH_StatusToString(MH_STATUS status); 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | -------------------------------------------------------------------------------- /third-party/DirectXTK/PostProcess.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: PostProcess.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | //-------------------------------------------------------------------------------------- 9 | 10 | #pragma once 11 | 12 | #if defined(_XBOX_ONE) && defined(_TITLE) 13 | #include 14 | #else 15 | #include 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | #include 22 | 23 | 24 | namespace DirectX 25 | { 26 | inline namespace DX11 27 | { 28 | //------------------------------------------------------------------------------ 29 | // Abstract interface representing a post-process pass 30 | class IPostProcess 31 | { 32 | public: 33 | virtual ~IPostProcess() = default; 34 | 35 | IPostProcess(const IPostProcess&) = delete; 36 | IPostProcess& operator=(const IPostProcess&) = delete; 37 | 38 | virtual void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, 39 | _In_opt_ std::function setCustomState = nullptr) = 0; 40 | 41 | protected: 42 | IPostProcess() = default; 43 | IPostProcess(IPostProcess&&) = default; 44 | IPostProcess& operator=(IPostProcess&&) = default; 45 | }; 46 | 47 | 48 | //------------------------------------------------------------------------------ 49 | // Basic post-process 50 | class BasicPostProcess : public IPostProcess 51 | { 52 | public: 53 | enum Effect : unsigned int 54 | { 55 | Copy, 56 | Monochrome, 57 | Sepia, 58 | DownScale_2x2, 59 | DownScale_4x4, 60 | GaussianBlur_5x5, 61 | BloomExtract, 62 | BloomBlur, 63 | Effect_Max 64 | }; 65 | 66 | explicit BasicPostProcess(_In_ ID3D11Device* device); 67 | 68 | BasicPostProcess(BasicPostProcess&&) noexcept; 69 | BasicPostProcess& operator= (BasicPostProcess&&) noexcept; 70 | 71 | BasicPostProcess(BasicPostProcess const&) = delete; 72 | BasicPostProcess& operator= (BasicPostProcess const&) = delete; 73 | 74 | ~BasicPostProcess() override; 75 | 76 | // IPostProcess methods. 77 | void __cdecl Process( 78 | _In_ ID3D11DeviceContext* deviceContext, 79 | _In_opt_ std::function setCustomState = nullptr) override; 80 | 81 | // Shader control 82 | void __cdecl SetEffect(Effect fx); 83 | 84 | // Properties 85 | void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value); 86 | 87 | // Sets multiplier for GaussianBlur_5x5 88 | void __cdecl SetGaussianParameter(float multiplier); 89 | 90 | // Sets parameters for BloomExtract 91 | void __cdecl SetBloomExtractParameter(float threshold); 92 | 93 | // Sets parameters for BloomBlur 94 | void __cdecl SetBloomBlurParameters(bool horizontal, float size, float brightness); 95 | 96 | private: 97 | // Private implementation. 98 | class Impl; 99 | 100 | std::unique_ptr pImpl; 101 | }; 102 | 103 | 104 | //------------------------------------------------------------------------------ 105 | // Dual-texure post-process 106 | class DualPostProcess : public IPostProcess 107 | { 108 | public: 109 | enum Effect : unsigned int 110 | { 111 | Merge, 112 | BloomCombine, 113 | Effect_Max 114 | }; 115 | 116 | explicit DualPostProcess(_In_ ID3D11Device* device); 117 | 118 | DualPostProcess(DualPostProcess&&) noexcept; 119 | DualPostProcess& operator= (DualPostProcess&&) noexcept; 120 | 121 | DualPostProcess(DualPostProcess const&) = delete; 122 | DualPostProcess& operator= (DualPostProcess const&) = delete; 123 | 124 | ~DualPostProcess() override; 125 | 126 | // IPostProcess methods. 127 | void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, 128 | _In_opt_ std::function setCustomState = nullptr) override; 129 | 130 | // Shader control 131 | void __cdecl SetEffect(Effect fx); 132 | 133 | // Properties 134 | void __cdecl SetSourceTexture(_In_opt_ ID3D11ShaderResourceView* value); 135 | void __cdecl SetSourceTexture2(_In_opt_ ID3D11ShaderResourceView* value); 136 | 137 | // Sets parameters for Merge 138 | void __cdecl SetMergeParameters(float weight1, float weight2); 139 | 140 | // Sets parameters for BloomCombine 141 | void __cdecl SetBloomCombineParameters(float bloom, float base, float bloomSaturation, float baseSaturation); 142 | 143 | private: 144 | // Private implementation. 145 | class Impl; 146 | 147 | std::unique_ptr pImpl; 148 | }; 149 | 150 | 151 | //------------------------------------------------------------------------------ 152 | // Tone-map post-process 153 | class ToneMapPostProcess : public IPostProcess 154 | { 155 | public: 156 | // Tone-mapping operator 157 | enum Operator : unsigned int 158 | { 159 | None, // Pass-through 160 | Saturate, // Clamp [0,1] 161 | Reinhard, // x/(1+x) 162 | ACESFilmic, 163 | Operator_Max 164 | }; 165 | 166 | // Electro-Optical Transfer Function (EOTF) 167 | enum TransferFunction : unsigned int 168 | { 169 | Linear, // Pass-through 170 | SRGB, // sRGB (Rec.709 and approximate sRGB display curve) 171 | ST2084, // HDR10 (Rec.2020 color primaries and ST.2084 display curve) 172 | TransferFunction_Max 173 | }; 174 | 175 | // Color Rotation Transform for HDR10 176 | enum ColorPrimaryRotation : unsigned int 177 | { 178 | HDTV_to_UHDTV, // Rec.709 to Rec.2020 179 | DCI_P3_D65_to_UHDTV, // DCI-P3-D65 (a.k.a Display P3 or P3D65) to Rec.2020 180 | HDTV_to_DCI_P3_D65, // Rec.709 to DCI-P3-D65 (a.k.a Display P3 or P3D65) 181 | }; 182 | 183 | explicit ToneMapPostProcess(_In_ ID3D11Device* device); 184 | 185 | ToneMapPostProcess(ToneMapPostProcess&&) noexcept; 186 | ToneMapPostProcess& operator= (ToneMapPostProcess&&) noexcept; 187 | 188 | ToneMapPostProcess(ToneMapPostProcess const&) = delete; 189 | ToneMapPostProcess& operator= (ToneMapPostProcess const&) = delete; 190 | 191 | ~ToneMapPostProcess() override; 192 | 193 | // IPostProcess methods. 194 | void __cdecl Process(_In_ ID3D11DeviceContext* deviceContext, 195 | _In_opt_ std::function setCustomState = nullptr) override; 196 | 197 | // Shader control 198 | void __cdecl SetOperator(Operator op); 199 | 200 | void __cdecl SetTransferFunction(TransferFunction func); 201 | 202 | #if defined(_XBOX_ONE) && defined(_TITLE) 203 | // Uses Multiple Render Targets to generate both HDR10 and GameDVR SDR signals 204 | void __cdecl SetMRTOutput(bool value = true); 205 | #endif 206 | 207 | // Properties 208 | void __cdecl SetHDRSourceTexture(_In_opt_ ID3D11ShaderResourceView* value); 209 | 210 | // Sets the Color Rotation Transform for HDR10 signal output 211 | void __cdecl SetColorRotation(ColorPrimaryRotation value); 212 | void __cdecl SetColorRotation(CXMMATRIX value); 213 | 214 | // Sets exposure value for LDR tonemap operators 215 | void __cdecl SetExposure(float exposureValue); 216 | 217 | // Sets ST.2084 parameter for how bright white should be in nits 218 | void __cdecl SetST2084Parameter(float paperWhiteNits); 219 | 220 | private: 221 | // Private implementation. 222 | class Impl; 223 | 224 | std::unique_ptr pImpl; 225 | }; 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /src/BF2VR/Utils.cpp: -------------------------------------------------------------------------------- 1 | // Utils.cpp - Various utilities like logging, config loading and saving, 2 | // and a few math ones. 3 | // Copyright(C) 2023 Ethan Porcaro 4 | 5 | // This program is free software : you can redistribute itand /or modify 6 | // it under the terms of the GNU General Public License as published by 7 | // the Free Software Foundation, either version 3 of the License, or 8 | // (at your option) any later version. 9 | 10 | // This program is distributed in the hope that it will be useful, 11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | // GNU General Public License for more details. 14 | 15 | #include "Utils.h" 16 | #include "GameService.h" 17 | #include 18 | #include "DirectXService.h" 19 | #include "OpenXRService.h" 20 | #include "InputService.h" 21 | 22 | #include "../../third-party/INI.h" 23 | 24 | namespace BF2VR 25 | { 26 | // Print to console and a file 27 | void log(std::string message) { 28 | logFile << message << std::endl; 29 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 30 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 31 | 32 | time_t my_time = time(NULL); 33 | std::cout << "[BF2VR] "; 34 | 35 | std::cout << message << std::endl; 36 | } 37 | void error(std::string message) { 38 | logFile << message << std::endl; 39 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 40 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 41 | 42 | time_t my_time = time(NULL); 43 | std::cout << "[BF2VR] "; 44 | 45 | SetConsoleTextAttribute(hConsole, 46 | FOREGROUND_RED); 47 | std::cout << message << std::endl; 48 | } 49 | void warn(std::string message) { 50 | 51 | if (warnCount == -1) 52 | { 53 | return; 54 | } 55 | 56 | if (warnCount > 50) 57 | { 58 | error("Too many warnings. Halting log."); 59 | warnCount = -1; 60 | return; 61 | } 62 | 63 | if (message == lastWarn) 64 | { 65 | if (message == "Mod has no focus. Please return to the game.") 66 | { 67 | return; 68 | } 69 | warnCount++; 70 | } 71 | else { 72 | warnCount = 0; 73 | } 74 | logFile << message << std::endl; 75 | 76 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 77 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 78 | 79 | std::cout << "[BF2VR] "; 80 | 81 | SetConsoleTextAttribute(hConsole, 82 | FOREGROUND_RED | FOREGROUND_GREEN); 83 | std::cout << message << std::endl; 84 | 85 | lastWarn = message; 86 | } 87 | void success(std::string message) { 88 | logFile << message << std::endl; 89 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 90 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 91 | 92 | std::cout << "[BF2VR] "; 93 | 94 | SetConsoleTextAttribute(hConsole, 95 | FOREGROUND_GREEN); 96 | std::cout << message << std::endl; 97 | } 98 | void info(std::string message) { 99 | logFile << message << std::endl; 100 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 101 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 102 | 103 | std::cout << "[BF2VR] "; 104 | 105 | SetConsoleTextAttribute(hConsole, 106 | FOREGROUND_BLUE | FOREGROUND_INTENSITY); 107 | std::cout << message << std::endl; 108 | } 109 | void deb(std::string message) { 110 | logFile << message << std::endl; 111 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 112 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 113 | 114 | std::cout << "[BF2VR] "; 115 | 116 | SetConsoleTextAttribute(hConsole, 117 | FOREGROUND_RED | FOREGROUND_BLUE); 118 | std::cout << message << std::endl; 119 | } 120 | 121 | // Shutdown and eject the mod. 122 | void shutdown() { 123 | log("Ending VR"); 124 | OpenXRService::shouldStop = true; 125 | while (!OpenXRService::stopping) { 126 | Sleep(10); 127 | } 128 | 129 | OpenXRService::isVRReady = false; 130 | OpenXRService::endXR(); 131 | 132 | log("Unhooking Camera"); 133 | MH_DisableHook((LPVOID)OFFSETCAMERA); 134 | MH_RemoveHook((LPVOID)OFFSETCAMERA); 135 | 136 | log("Unhooking Pose"); 137 | MH_DisableHook((LPVOID)OFFSETPOSE); 138 | MH_RemoveHook((LPVOID)OFFSETPOSE); 139 | 140 | log("Unhooking DirectX"); 141 | DirectXService::unhookDirectX(); 142 | 143 | // Reset override FOV 144 | GameRenderer* pGameRenderer = GameRenderer::GetInstance(); 145 | if (!isValidPtr(pGameRenderer)) 146 | { 147 | warn("Unable to restore FOV to default value."); 148 | } 149 | else { 150 | GameRenderSettings* pSettings = pGameRenderer->gameRenderSettings; 151 | if (!isValidPtr(pSettings)) 152 | { 153 | warn("Unable to restore FOV to default value."); 154 | } 155 | else { 156 | pSettings->forceFov = -1; 157 | } 158 | } 159 | 160 | log("Disconnecting ViGEm"); 161 | InputService::disconnect(); 162 | 163 | shutdownNoHooks(); 164 | } 165 | 166 | // Shutdown without removing hooks. This is for early initialization when nothing has been hooked yet. 167 | void shutdownNoHooks() { 168 | log("Uninitializing Minhook"); 169 | MH_Uninitialize(); 170 | 171 | info("Mod shut down."); 172 | 173 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 174 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 175 | std::cout << "You may now close this window." << std::endl; 176 | logFile << "End of log." << std::endl; 177 | 178 | FreeConsole(); 179 | FreeLibraryAndExitThread(ownModule, 0); 180 | } 181 | 182 | 183 | void loadConfig() { 184 | log("Loading Config"); 185 | 186 | // Open config.txt and read it line by line, applying the values 187 | 188 | std::ofstream Config("config.ini", std::ios_base::app); 189 | Config.close(); 190 | 191 | // Set global parsing/saving options 192 | INI::PARSE_FLAGS = INI::PARSE_COMMENTS_ALL | INI::PARSE_COMMENTS_SLASH | INI::PARSE_COMMENTS_HASH; 193 | INI::SAVE_FLAGS = INI::SAVE_PRUNE | INI::SAVE_PADDING_SECTIONS | INI::SAVE_SPACE_SECTIONS | INI::SAVE_SPACE_KEYS | INI::SAVE_TAB_KEYS | INI::SAVE_SEMICOLON_KEYS; 194 | 195 | INI ini("config.ini", true); // Assign ini file and parse 196 | 197 | ini.select("Core"); 198 | 199 | RATIO = ini.getAs("Core", "EyeAspectRatio", 1.f); 200 | HEADAIM = ini.getAs("Core", "AimWithHead", false); 201 | FOVOverride = ini.getAs("Core", "FOVOverride", -1.f); 202 | ConvergeOverride = ini.getAs("Core", "EyeConvergenceOverride", -1); 203 | 204 | success("Loaded Config."); 205 | 206 | // Prevent multi-triggering 207 | Sleep(100); 208 | } 209 | 210 | void saveConfig() { 211 | log("Saving Config"); 212 | 213 | // Make the file 214 | std::ofstream Config("config.ini", std::ios_base::app); 215 | Config.close(); 216 | 217 | // Set global parsing/saving options 218 | INI::PARSE_FLAGS = INI::PARSE_COMMENTS_ALL | INI::PARSE_COMMENTS_SLASH | INI::PARSE_COMMENTS_HASH; 219 | INI::SAVE_FLAGS = INI::SAVE_PRUNE | INI::SAVE_PADDING_SECTIONS | INI::SAVE_SPACE_SECTIONS | INI::SAVE_SPACE_KEYS | INI::SAVE_TAB_KEYS | INI::SAVE_SEMICOLON_KEYS; 220 | 221 | INI ini("config.ini", true); // Assign ini file and parse 222 | 223 | ini.create("Core"); 224 | 225 | // Does nothing for now 226 | 227 | 228 | ini.save("config.ini"); 229 | success("Saved Config."); 230 | } 231 | 232 | // Converts quats to euler for the Aiming function 233 | Vec3 eulerFromQuat(Vec4 q) 234 | { 235 | Vec3 v; 236 | 237 | float test = q.x * q.y + q.z * q.w; 238 | if (test > 0.499) 239 | { // singularity at north pole 240 | v.x = 2 * atan2(q.x, q.w); // heading 241 | v.y = PI / 2; // attitude 242 | v.z = 0; // bank 243 | return v; 244 | } 245 | if (test < -0.499) 246 | { // singularity at south pole 247 | v.x = -2 * atan2(q.x, q.w); // headingq 248 | v.y = -PI / 2; // attitude 249 | v.z = 0; // bank 250 | return v; 251 | } 252 | float sqx = q.x * q.x; 253 | float sqy = q.y * q.y; 254 | float sqz = q.z * q.z; 255 | v.y = atan2(2 * q.y * q.w - 2 * q.x * q.z, 1 - 2 * sqy - 2 * sqz); // heading 256 | v.x = asin(2 * test); // attitude 257 | v.z = atan2(2 * q.x * q.w - 2 * q.y * q.z, 1 - 2 * sqx - 2 * sqz); // bank 258 | return v; 259 | } 260 | 261 | 262 | Vec4 quatFromEuler(Vec3 e) 263 | { 264 | auto [pitch, yaw, roll] = e; 265 | float qx = sin(roll / 2) * cos(pitch / 2) * cos(yaw / 2) - cos(roll / 2) * sin(pitch / 2) * sin(yaw / 2); 266 | float qy = cos(roll / 2) * sin(pitch / 2) * cos(yaw / 2) + sin(roll / 2) * cos(pitch / 2) * sin(yaw / 2); 267 | float qz = cos(roll / 2) * cos(pitch / 2) * sin(yaw / 2) - sin(roll / 2) * sin(pitch / 2) * cos(yaw / 2); 268 | float qw = cos(roll / 2) * cos(pitch / 2) * cos(yaw / 2) + sin(roll / 2) * sin(pitch / 2) * sin(yaw / 2); 269 | return Vec4(qx, qy, qz, qw); 270 | } 271 | } -------------------------------------------------------------------------------- /src/Injector/Source.cpp: -------------------------------------------------------------------------------- 1 | // Source.cpp - Source code for the DLL injector and mod installer. 2 | // Copyright(C) 2023 Ethan Porcaro 3 | 4 | // This program is free software : you can redistribute itand /or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // This program is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "resource.h" 21 | #include 22 | 23 | #pragma comment(lib, "Shlwapi.lib") 24 | #pragma comment(lib, "xinput.lib") 25 | 26 | using namespace std; 27 | 28 | 29 | int inject() 30 | { 31 | // Get the DLL file path 32 | char buffer[MAX_PATH]; 33 | GetModuleFileNameA(NULL, buffer, MAX_PATH); 34 | std::string::size_type pos = std::string(buffer).find_last_of("\\/"); 35 | std::string path = std::string(buffer).substr(0, pos); 36 | path += "\\BF2VR.dll"; 37 | if (!PathFileExists(std::wstring(path.begin(), path.end()).c_str())) 38 | { 39 | cerr << "DLL not in the directory." << endl; 40 | return 1; 41 | } 42 | LPCSTR DllPath = const_cast(path.c_str()); // The Path to our DLL 43 | 44 | // Get running procceses 45 | HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 46 | PROCESSENTRY32 structprocsnapshot = { 0 }; 47 | structprocsnapshot.dwSize = sizeof(PROCESSENTRY32); 48 | if (snapshot == INVALID_HANDLE_VALUE)return 0; 49 | if (Process32First(snapshot, &structprocsnapshot) == FALSE)return 0; 50 | 51 | // Iterate through processes 52 | DWORD pid = -1; 53 | DWORD pid2 = -1; 54 | 55 | while (Process32Next(snapshot, &structprocsnapshot)) 56 | { 57 | // Convert WCHAR* into string 58 | WCHAR* procexe = structprocsnapshot.szExeFile; 59 | wstring ws_procexe(procexe); 60 | std::string s_procexe(ws_procexe.begin(), ws_procexe.end()); 61 | 62 | // Check for game process 63 | if (!strcmp(s_procexe.c_str(), "starwarsbattlefrontii.exe")) 64 | { 65 | pid = structprocsnapshot.th32ProcessID; 66 | } 67 | 68 | // Check for xr runtime process 69 | if (!strcmp(s_procexe.c_str(), "vrserver.exe")) 70 | { 71 | pid2 = structprocsnapshot.th32ProcessID; 72 | } 73 | if (!strcmp(s_procexe.c_str(), "OVRServiceLauncher.exe")) 74 | { 75 | pid2 = structprocsnapshot.th32ProcessID; 76 | } 77 | } 78 | 79 | // Never found game process 80 | if (pid == -1) 81 | { 82 | cerr << "Game not open or found." << endl; 83 | return 1; 84 | } 85 | 86 | // Never found xr runtime 87 | if (pid2 == -1) 88 | { 89 | cerr << "Oculus or SteamVR is not open. Press enter within 5 seconds to continue anyway." << endl; 90 | Sleep(500); 91 | bool pressed = false; 92 | for (int i = 0; i < 250; i++) 93 | { 94 | // No sleep because the AsyncKeyState already causes a delay 95 | if (GetAsyncKeyState(VK_RETURN)) { 96 | pressed = true; 97 | break; 98 | } 99 | } 100 | if (!pressed) 101 | { 102 | return 1; 103 | } 104 | } 105 | 106 | CloseHandle(snapshot); 107 | 108 | // Inject the mod DLL 109 | 110 | HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); // Opening the Process with All Access 111 | // Allocate memory for the dllpath in the target process, length of the path string + null terminator 112 | LPVOID pDllPath = VirtualAllocEx(handle, 0, strlen(DllPath) + 1, MEM_COMMIT, PAGE_READWRITE); 113 | // Write the path to the address of the memory we just allocated in the target process 114 | WriteProcessMemory(handle, pDllPath, (LPVOID)DllPath, strlen(DllPath) + 1, 0); 115 | // Create a Remote Thread in the target process which calls LoadLibraryA as our dllpath as an argument -> program loads our dll 116 | HANDLE hLoadThread = CreateRemoteThread(handle, 0, 0, 117 | (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"), pDllPath, 0, 0); 118 | WaitForSingleObject(hLoadThread, INFINITE); // Wait for the execution of our loader thread to finish 119 | 120 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 121 | SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN); 122 | cout << "Dll path allocated at: " << hex << pDllPath << endl; 123 | 124 | Sleep(1000); 125 | 126 | VirtualFreeEx(handle, pDllPath, strlen(DllPath) + 1, MEM_RELEASE); // Free the memory allocated for our dll path 127 | return 0; 128 | } 129 | 130 | 131 | void reinstall() 132 | { 133 | cout << "Reinstalling. You will need to find the folder where Battlefront is installed. You may paste the path into the field at the next step. Press enter to continue." << endl; 134 | 135 | for (;;) 136 | { 137 | Sleep(10); 138 | if (GetAsyncKeyState(VK_RETURN)) { 139 | break; 140 | } 141 | } 142 | 143 | // Open file picker 144 | TCHAR szTitle[MAX_PATH]; 145 | BROWSEINFO bi = { 0 }; 146 | bi.lpszTitle = L"Select a folder containing starwarsbattlefrontii.exe"; 147 | bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; 148 | bi.lpfn = NULL; 149 | bi.lParam = 0; 150 | LPITEMIDLIST pidl = SHBrowseForFolder(&bi); 151 | if (pidl != NULL) 152 | { 153 | if (SHGetPathFromIDList(pidl, szTitle)) 154 | { 155 | char szString[MAX_PATH]; 156 | size_t nNumCharConverted; 157 | wcstombs_s(&nNumCharConverted, szString, MAX_PATH, 158 | szTitle, MAX_PATH); 159 | 160 | // Copy openxr_runtime.dll 161 | 162 | // Get the DLL file path 163 | char buffer[MAX_PATH]; 164 | GetModuleFileNameA(NULL, buffer, MAX_PATH); 165 | std::string::size_type pos = std::string(buffer).find_last_of("\\/"); 166 | std::string path = std::string(buffer).substr(0, pos); 167 | path += "\\openxr_loader.dll"; 168 | if (!PathFileExists(std::wstring(path.begin(), path.end()).c_str())) 169 | { 170 | cerr << "openxr_loader.dll is not in the directory. Press enter to close." << endl; 171 | Sleep(500); 172 | for (;;) 173 | { 174 | if (GetAsyncKeyState(VK_RETURN)) { 175 | return; 176 | } 177 | } 178 | } 179 | 180 | std::string path2 = std::string(buffer).substr(0, pos); 181 | path2 += "\\starwarsbattlefrontii.exe"; 182 | 183 | if (PathFileExists(std::wstring(path2.begin(), path2.end()).c_str())) 184 | { 185 | cerr << "Please move the mod into it's own folder.. Press enter to close." << endl; 186 | Sleep(500); 187 | for (;;) 188 | { 189 | if (GetAsyncKeyState(VK_RETURN)) { 190 | return; 191 | } 192 | } 193 | } 194 | 195 | // Get the new file path 196 | std::string newpath = std::string(szString); 197 | newpath += "\\openxr_loader.dll"; 198 | 199 | bool result = CopyFile(std::wstring(path.begin(), path.end()).c_str(), std::wstring(newpath.begin(), newpath.end()).c_str(), FALSE); 200 | if (!result) 201 | { 202 | Sleep(500); 203 | cerr << "openxr_loader.dll copy failed. Press enter to close" << endl; 204 | for (;;) 205 | { 206 | if (GetAsyncKeyState(VK_RETURN)) { 207 | return; 208 | } 209 | } 210 | } 211 | 212 | // Rename the config 213 | string newpath2 = std::string(szString); 214 | string newpath3 = newpath2; 215 | newpath2 += "\\config.txt"; 216 | newpath3 += "\\config.txt.bak"; 217 | 218 | result = MoveFile(std::wstring(newpath2.begin(), newpath2.end()).c_str(), std::wstring(newpath3.begin(), newpath3.end()).c_str()); 219 | 220 | cout << "Installed. Press enter to launch." << endl; 221 | Sleep(500); 222 | for (;;) 223 | { 224 | if (GetAsyncKeyState(VK_RETURN)) { 225 | inject(); 226 | return; 227 | } 228 | } 229 | } 230 | else { 231 | cout << "You did not select a window. Press enter to retry or ESC to close." << endl; 232 | for (;;) 233 | { 234 | if (GetAsyncKeyState(VK_RETURN)) { 235 | reinstall(); 236 | return; 237 | } 238 | if (GetAsyncKeyState(VK_ESCAPE)) { 239 | return; 240 | } 241 | } 242 | return; 243 | } 244 | } 245 | 246 | 247 | } 248 | 249 | 250 | int main(const char* argv[]) { 251 | // Print fancy thing 252 | 253 | 254 | HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); 255 | SetConsoleTextAttribute(hConsole, 256 | FOREGROUND_BLUE | FOREGROUND_INTENSITY); 257 | 258 | cout << R""""( 259 | $$$$$$$\ $$$$$$$$\ $$$$$$\ $$\ $$\ $$$$$$$\ 260 | $$ __$$\ $$ _____|$$ __$$\ $$ | $$ |$$ __$$\ 261 | $$ | $$ |$$ | \__/ $$ |$$ | $$ |$$ | $$ | 262 | $$$$$$$\ |$$$$$\ $$$$$$ |\$$\ $$ |$$$$$$$ | 263 | $$ __$$\ $$ __| $$ ____/ \$$\$$ / $$ __$$< 264 | $$ | $$ |$$ | $$ | \$$$ / $$ | $$ | 265 | $$$$$$$ |$$ | $$$$$$$$\ \$ / $$ | $$ | 266 | \_______/ \__| \________| \_/ \__| \__| 267 | )""""; 268 | 269 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 270 | cout << "Press enter to launch or F10 to install/reinstall" << endl; 271 | 272 | for (;;) 273 | { 274 | SetConsoleTextAttribute(hConsole, FOREGROUND_RED); 275 | 276 | if (GetAsyncKeyState(VK_F10)) { 277 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 278 | Sleep(300); 279 | reinstall(); 280 | break; 281 | } 282 | 283 | if (GetAsyncKeyState(VK_RETURN)) { 284 | Sleep(300); 285 | if (inject() == 0) 286 | { 287 | cout << "Injected! If you need to reinject, press F1 then Enter within 10 seconds of injection" << endl; 288 | Sleep(300); 289 | bool pressed = false; 290 | for (int i = 0; i < 500; i++) 291 | { 292 | Sleep(1); 293 | if (GetAsyncKeyState(VK_F1)) { // This delays for some reason 294 | pressed = true; 295 | break; 296 | } 297 | } 298 | if (!pressed) 299 | { 300 | return 0; 301 | } 302 | } 303 | else { 304 | SetConsoleTextAttribute(hConsole, FOREGROUND_INTENSITY); 305 | cout << "Press enter to try again or escape to close" << endl; 306 | } 307 | } 308 | 309 | if (GetAsyncKeyState(VK_ESCAPE)) { 310 | break; 311 | } 312 | } 313 | return 0; 314 | } -------------------------------------------------------------------------------- /third-party/OpenXR/xrmath.h: -------------------------------------------------------------------------------- 1 | // adapted from 2 | 3 | // Copyright (c) 2017 The Khronos Group Inc. 4 | // Copyright (c) 2016 Oculus VR, LLC. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | // Author: J.M.P. van Waveren 19 | 20 | #pragma once 21 | 22 | #include "openxr.h" 23 | #include 24 | #include 25 | 26 | typedef enum 27 | { 28 | GRAPHICS_VULKAN, 29 | GRAPHICS_OPENGL, 30 | GRAPHICS_OPENGL_ES 31 | } GraphicsAPI; 32 | 33 | typedef struct XrMatrix4x4f 34 | { 35 | float m[16]; 36 | } XrMatrix4x4f; 37 | 38 | inline static void 39 | XrMatrix4x4f_CreateProjectionFov(XrMatrix4x4f *result, 40 | GraphicsAPI graphicsApi, 41 | const XrFovf fov, 42 | const float nearZ, 43 | const float farZ) 44 | { 45 | const float tanAngleLeft = tanf(fov.angleLeft); 46 | const float tanAngleRight = tanf(fov.angleRight); 47 | 48 | const float tanAngleDown = tanf(fov.angleDown); 49 | const float tanAngleUp = tanf(fov.angleUp); 50 | 51 | const float tanAngleWidth = tanAngleRight - tanAngleLeft; 52 | 53 | // Set to tanAngleDown - tanAngleUp for a clip space with positive Y 54 | // down (Vulkan). Set to tanAngleUp - tanAngleDown for a clip space with 55 | // positive Y up (OpenGL / D3D / Metal). 56 | const float tanAngleHeight = 57 | graphicsApi == GRAPHICS_VULKAN ? (tanAngleDown - tanAngleUp) : (tanAngleUp - tanAngleDown); 58 | 59 | // Set to nearZ for a [-1,1] Z clip space (OpenGL / OpenGL ES). 60 | // Set to zero for a [0,1] Z clip space (Vulkan / D3D / Metal). 61 | const float offsetZ = 62 | (graphicsApi == GRAPHICS_OPENGL || graphicsApi == GRAPHICS_OPENGL_ES) ? nearZ : 0; 63 | 64 | if (farZ <= nearZ) { 65 | // place the far plane at infinity 66 | result->m[0] = 2 / tanAngleWidth; 67 | result->m[4] = 0; 68 | result->m[8] = (tanAngleRight + tanAngleLeft) / tanAngleWidth; 69 | result->m[12] = 0; 70 | 71 | result->m[1] = 0; 72 | result->m[5] = 2 / tanAngleHeight; 73 | result->m[9] = (tanAngleUp + tanAngleDown) / tanAngleHeight; 74 | result->m[13] = 0; 75 | 76 | result->m[2] = 0; 77 | result->m[6] = 0; 78 | result->m[10] = -1; 79 | result->m[14] = -(nearZ + offsetZ); 80 | 81 | result->m[3] = 0; 82 | result->m[7] = 0; 83 | result->m[11] = -1; 84 | result->m[15] = 0; 85 | } else { 86 | // normal projection 87 | result->m[0] = 2 / tanAngleWidth; 88 | result->m[4] = 0; 89 | result->m[8] = (tanAngleRight + tanAngleLeft) / tanAngleWidth; 90 | result->m[12] = 0; 91 | 92 | result->m[1] = 0; 93 | result->m[5] = 2 / tanAngleHeight; 94 | result->m[9] = (tanAngleUp + tanAngleDown) / tanAngleHeight; 95 | result->m[13] = 0; 96 | 97 | result->m[2] = 0; 98 | result->m[6] = 0; 99 | result->m[10] = -(farZ + offsetZ) / (farZ - nearZ); 100 | result->m[14] = -(farZ * (nearZ + offsetZ)) / (farZ - nearZ); 101 | 102 | result->m[3] = 0; 103 | result->m[7] = 0; 104 | result->m[11] = -1; 105 | result->m[15] = 0; 106 | } 107 | } 108 | 109 | inline static void 110 | XrMatrix4x4f_CreateFromQuaternion(XrMatrix4x4f *result, const XrQuaternionf *quat) 111 | { 112 | const float x2 = quat->x + quat->x; 113 | const float y2 = quat->y + quat->y; 114 | const float z2 = quat->z + quat->z; 115 | 116 | const float xx2 = quat->x * x2; 117 | const float yy2 = quat->y * y2; 118 | const float zz2 = quat->z * z2; 119 | 120 | const float yz2 = quat->y * z2; 121 | const float wx2 = quat->w * x2; 122 | const float xy2 = quat->x * y2; 123 | const float wz2 = quat->w * z2; 124 | const float xz2 = quat->x * z2; 125 | const float wy2 = quat->w * y2; 126 | 127 | result->m[0] = 1.0f - yy2 - zz2; 128 | result->m[1] = xy2 + wz2; 129 | result->m[2] = xz2 - wy2; 130 | result->m[3] = 0.0f; 131 | 132 | result->m[4] = xy2 - wz2; 133 | result->m[5] = 1.0f - xx2 - zz2; 134 | result->m[6] = yz2 + wx2; 135 | result->m[7] = 0.0f; 136 | 137 | result->m[8] = xz2 + wy2; 138 | result->m[9] = yz2 - wx2; 139 | result->m[10] = 1.0f - xx2 - yy2; 140 | result->m[11] = 0.0f; 141 | 142 | result->m[12] = 0.0f; 143 | result->m[13] = 0.0f; 144 | result->m[14] = 0.0f; 145 | result->m[15] = 1.0f; 146 | } 147 | 148 | inline static void 149 | XrMatrix4x4f_CreateTranslation(XrMatrix4x4f *result, const float x, const float y, const float z) 150 | { 151 | result->m[0] = 1.0f; 152 | result->m[1] = 0.0f; 153 | result->m[2] = 0.0f; 154 | result->m[3] = 0.0f; 155 | result->m[4] = 0.0f; 156 | result->m[5] = 1.0f; 157 | result->m[6] = 0.0f; 158 | result->m[7] = 0.0f; 159 | result->m[8] = 0.0f; 160 | result->m[9] = 0.0f; 161 | result->m[10] = 1.0f; 162 | result->m[11] = 0.0f; 163 | result->m[12] = x; 164 | result->m[13] = y; 165 | result->m[14] = z; 166 | result->m[15] = 1.0f; 167 | } 168 | 169 | inline static void 170 | XrMatrix4x4f_Multiply(XrMatrix4x4f *result, const XrMatrix4x4f *a, const XrMatrix4x4f *b) 171 | { 172 | result->m[0] = a->m[0] * b->m[0] + a->m[4] * b->m[1] + a->m[8] * b->m[2] + a->m[12] * b->m[3]; 173 | result->m[1] = a->m[1] * b->m[0] + a->m[5] * b->m[1] + a->m[9] * b->m[2] + a->m[13] * b->m[3]; 174 | result->m[2] = a->m[2] * b->m[0] + a->m[6] * b->m[1] + a->m[10] * b->m[2] + a->m[14] * b->m[3]; 175 | result->m[3] = a->m[3] * b->m[0] + a->m[7] * b->m[1] + a->m[11] * b->m[2] + a->m[15] * b->m[3]; 176 | 177 | result->m[4] = a->m[0] * b->m[4] + a->m[4] * b->m[5] + a->m[8] * b->m[6] + a->m[12] * b->m[7]; 178 | result->m[5] = a->m[1] * b->m[4] + a->m[5] * b->m[5] + a->m[9] * b->m[6] + a->m[13] * b->m[7]; 179 | result->m[6] = a->m[2] * b->m[4] + a->m[6] * b->m[5] + a->m[10] * b->m[6] + a->m[14] * b->m[7]; 180 | result->m[7] = a->m[3] * b->m[4] + a->m[7] * b->m[5] + a->m[11] * b->m[6] + a->m[15] * b->m[7]; 181 | 182 | result->m[8] = a->m[0] * b->m[8] + a->m[4] * b->m[9] + a->m[8] * b->m[10] + a->m[12] * b->m[11]; 183 | result->m[9] = a->m[1] * b->m[8] + a->m[5] * b->m[9] + a->m[9] * b->m[10] + a->m[13] * b->m[11]; 184 | result->m[10] = a->m[2] * b->m[8] + a->m[6] * b->m[9] + a->m[10] * b->m[10] + a->m[14] * b->m[11]; 185 | result->m[11] = a->m[3] * b->m[8] + a->m[7] * b->m[9] + a->m[11] * b->m[10] + a->m[15] * b->m[11]; 186 | 187 | result->m[12] = 188 | a->m[0] * b->m[12] + a->m[4] * b->m[13] + a->m[8] * b->m[14] + a->m[12] * b->m[15]; 189 | result->m[13] = 190 | a->m[1] * b->m[12] + a->m[5] * b->m[13] + a->m[9] * b->m[14] + a->m[13] * b->m[15]; 191 | result->m[14] = 192 | a->m[2] * b->m[12] + a->m[6] * b->m[13] + a->m[10] * b->m[14] + a->m[14] * b->m[15]; 193 | result->m[15] = 194 | a->m[3] * b->m[12] + a->m[7] * b->m[13] + a->m[11] * b->m[14] + a->m[15] * b->m[15]; 195 | } 196 | 197 | inline static void 198 | XrMatrix4x4f_Invert(XrMatrix4x4f *result, const XrMatrix4x4f *src) 199 | { 200 | result->m[0] = src->m[0]; 201 | result->m[1] = src->m[4]; 202 | result->m[2] = src->m[8]; 203 | result->m[3] = 0.0f; 204 | result->m[4] = src->m[1]; 205 | result->m[5] = src->m[5]; 206 | result->m[6] = src->m[9]; 207 | result->m[7] = 0.0f; 208 | result->m[8] = src->m[2]; 209 | result->m[9] = src->m[6]; 210 | result->m[10] = src->m[10]; 211 | result->m[11] = 0.0f; 212 | result->m[12] = -(src->m[0] * src->m[12] + src->m[1] * src->m[13] + src->m[2] * src->m[14]); 213 | result->m[13] = -(src->m[4] * src->m[12] + src->m[5] * src->m[13] + src->m[6] * src->m[14]); 214 | result->m[14] = -(src->m[8] * src->m[12] + src->m[9] * src->m[13] + src->m[10] * src->m[14]); 215 | result->m[15] = 1.0f; 216 | } 217 | 218 | inline static void 219 | XrMatrix4x4f_CreateViewMatrix(XrMatrix4x4f *result, 220 | const XrVector3f *translation, 221 | const XrQuaternionf *rotation) 222 | { 223 | 224 | XrMatrix4x4f rotationMatrix; 225 | XrMatrix4x4f_CreateFromQuaternion(&rotationMatrix, rotation); 226 | 227 | XrMatrix4x4f translationMatrix; 228 | XrMatrix4x4f_CreateTranslation(&translationMatrix, translation->x, translation->y, 229 | translation->z); 230 | 231 | XrMatrix4x4f viewMatrix; 232 | XrMatrix4x4f_Multiply(&viewMatrix, &translationMatrix, &rotationMatrix); 233 | 234 | XrMatrix4x4f_Invert(result, &viewMatrix); 235 | } 236 | 237 | // Creates a scale matrix. 238 | inline static void 239 | XrMatrix4x4f_CreateScale(XrMatrix4x4f *result, const float x, const float y, const float z) 240 | { 241 | result->m[0] = x; 242 | result->m[1] = 0.0f; 243 | result->m[2] = 0.0f; 244 | result->m[3] = 0.0f; 245 | result->m[4] = 0.0f; 246 | result->m[5] = y; 247 | result->m[6] = 0.0f; 248 | result->m[7] = 0.0f; 249 | result->m[8] = 0.0f; 250 | result->m[9] = 0.0f; 251 | result->m[10] = z; 252 | result->m[11] = 0.0f; 253 | result->m[12] = 0.0f; 254 | result->m[13] = 0.0f; 255 | result->m[14] = 0.0f; 256 | result->m[15] = 1.0f; 257 | } 258 | 259 | inline static void 260 | XrMatrix4x4f_CreateModelMatrix(XrMatrix4x4f *result, 261 | const XrVector3f *translation, 262 | const XrQuaternionf *rotation, 263 | const XrVector3f *scale) 264 | { 265 | XrMatrix4x4f scaleMatrix; 266 | XrMatrix4x4f_CreateScale(&scaleMatrix, scale->x, scale->y, scale->z); 267 | 268 | XrMatrix4x4f rotationMatrix; 269 | XrMatrix4x4f_CreateFromQuaternion(&rotationMatrix, rotation); 270 | 271 | XrMatrix4x4f translationMatrix; 272 | XrMatrix4x4f_CreateTranslation(&translationMatrix, translation->x, translation->y, 273 | translation->z); 274 | 275 | XrMatrix4x4f combinedMatrix; 276 | XrMatrix4x4f_Multiply(&combinedMatrix, &rotationMatrix, &scaleMatrix); 277 | XrMatrix4x4f_Multiply(result, &translationMatrix, &combinedMatrix); 278 | } 279 | 280 | inline static void 281 | printXrMatrix4x4(XrMatrix4x4f matrix) 282 | { 283 | printf( 284 | "%6.1f %6.1f %6.1f %6.1f\n%6.1f %6.1f %6.1f %6.1f\n%6.1f %6.1f " 285 | "%6.1f %6.1f\n%6.1f %6.1f %6.1f %6.1f\n", 286 | matrix.m[0], matrix.m[1], matrix.m[2], matrix.m[3], matrix.m[4], matrix.m[5], matrix.m[6], 287 | matrix.m[7], matrix.m[8], matrix.m[9], matrix.m[10], matrix.m[11], matrix.m[12], matrix.m[13], 288 | matrix.m[14], matrix.m[15]); 289 | } 290 | -------------------------------------------------------------------------------- /third-party/INI.h: -------------------------------------------------------------------------------- 1 | /* 2 | Feather INI Parser - 2.0 3 | You are free to use this however you wish. 4 | 5 | If you find a bug, please attept to debug the cause. 6 | Post your environment details and the cause or fix in the issues section of GitHub. 7 | 8 | Written by Turbine1991. 9 | 10 | Website: 11 | http://code.google.com/p/feather-ini-parser/downloads 12 | 13 | Help: 14 | Bundled example & readme. 15 | https://github.com/Turbine1991/cpp-feather-ini-parser/tree/master/example 16 | */ 17 | 18 | #pragma once 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifndef FINI_WIDE_SUPPORT 31 | typedef std::stringstream fini_sstream_t; 32 | typedef std::string fini_string_t; 33 | typedef char fini_char_t; 34 | typedef std::ifstream fini_ifstream_t; 35 | typedef std::ofstream fini_ofstream_t; 36 | #else 37 | typedef std::wstringstream fini_sstream_t; 38 | typedef std::wstring fini_string_t; 39 | typedef wchar_t fini_char_t; 40 | typedef std::wifstream fini_ifstream_t; 41 | typedef std::wofstream fini_ofstream_t; 42 | #endif 43 | 44 | 45 | fini_string_t& l_trim(fini_string_t& str, const fini_string_t trim_chars = "\t\v\f; ") { 46 | str.erase(0, str.find_first_not_of(trim_chars)); return str; 47 | } 48 | 49 | fini_string_t& r_trim(fini_string_t& str, const fini_string_t trim_chars = "\t\v\f; ") { 50 | str.erase(str.find_last_not_of(trim_chars) + 1); return str; 51 | } 52 | 53 | fini_string_t& trim(fini_string_t& str, const fini_string_t trim_chars = "\t\v\f; ") { 54 | return l_trim(r_trim(str, trim_chars), trim_chars); 55 | } 56 | 57 | template 58 | T convert_to (const fini_string_t &str) { 59 | fini_sstream_t ss(str); 60 | T num; 61 | ss >> num; 62 | return num; 63 | } 64 | 65 | template <> 66 | fini_string_t convert_to(const fini_string_t &str) { 67 | return str; 68 | } 69 | 70 | template <> 71 | const char* convert_to(const fini_string_t &str) { 72 | return str.c_str(); 73 | } 74 | 75 | /// 76 | class INI 77 | { 78 | public: 79 | /// Define 80 | static int PARSE_FLAGS, SAVE_FLAGS; 81 | 82 | typedef fini_char_t data_t; 83 | 84 | typedef typename std::map keys_t; 85 | typedef typename std::map sections_t; 86 | typedef typename keys_t::value_type keyspair_t; 87 | typedef typename sections_t::value_type sectionspair_t; 88 | 89 | enum source_e {SOURCE_FILE, SOURCE_MEMORY}; 90 | enum save_e {SAVE_PRUNE = 1 << 0, SAVE_PADDING_SECTIONS = 1 << 1, SAVE_SPACE_SECTIONS = 1 << 2, SAVE_SPACE_KEYS = 1 << 3, SAVE_TAB_KEYS = 1 << 4, SAVE_SEMICOLON_KEYS = 1 << 5}; 91 | enum parse_e {PARSE_COMMENTS_SLASH = 1 << 0, PARSE_COMMENTS_HASH = 1 << 1, PARSE_COMMENTS_ALL = 1 << 2}; 92 | 93 | /// Data 94 | const source_e source; 95 | const fini_string_t filename; 96 | //data_t* data; 97 | //size_t dataSize; 98 | 99 | keys_t* current; 100 | sections_t sections; 101 | 102 | /// Methods 103 | INI(const INI& from); 104 | INI(fini_string_t filename, bool doParse, int parseFlags = 0); 105 | //INI(void* data, size_t dataSize, bool doParse) 106 | ~INI(); 107 | void clear(); 108 | bool parse(int parseFlags = 0); 109 | void _parseFile(fini_ifstream_t& file, int parseFlags); 110 | bool save(fini_string_t filename, int saveFlags = 0); 111 | 112 | keys_t& operator[](fini_string_t section); 113 | void create(fini_string_t section); 114 | void remove(fini_string_t section); 115 | bool select(fini_string_t section, bool noCreate = false); 116 | fini_string_t get(fini_string_t section, fini_string_t key, fini_string_t def); 117 | fini_string_t get(fini_string_t key, fini_string_t def); 118 | template 119 | T getAs(fini_string_t section, fini_string_t key, T def = T()); 120 | template 121 | T getAs(fini_string_t key, T def = T()); 122 | void set(fini_string_t section, fini_string_t key, fini_string_t value); 123 | void set(fini_string_t key, fini_string_t value); 124 | }; 125 | 126 | /// Definition 127 | INI::INI(const INI& from): source(from.source), filename(from.filename) { 128 | // Deep clone INI 129 | for(auto i: from.sections) { 130 | select(i.first); 131 | for(auto j: *i.second) 132 | set(j.first, j.second); 133 | } 134 | } 135 | 136 | INI::INI(fini_string_t filename, bool doParse, int parseFlags): source(SOURCE_FILE), filename(filename) { 137 | this->create(""); 138 | 139 | if (doParse) 140 | parse(parseFlags); 141 | } 142 | 143 | INI:: ~INI() { 144 | clear(); 145 | } 146 | 147 | void INI::clear() { 148 | sections.clear(); 149 | } 150 | 151 | bool INI::parse(int parseFlags) { 152 | parseFlags = (parseFlags > 0)? parseFlags: PARSE_FLAGS; 153 | 154 | switch(source) 155 | { 156 | case SOURCE_FILE: { 157 | fini_ifstream_t file(filename); 158 | 159 | if (!file.is_open()) 160 | return false; 161 | 162 | _parseFile(file, parseFlags); 163 | 164 | file.close(); 165 | } break; 166 | 167 | case SOURCE_MEMORY: 168 | /*std::stringstream sstream; 169 | sstream.rdbuf()->pubsetbuf(data, dataSize); 170 | parse(sstream);*/ 171 | break; 172 | } 173 | 174 | return true; 175 | } 176 | 177 | int INI::PARSE_FLAGS = 0, INI::SAVE_FLAGS = 0; 178 | 179 | void INI::_parseFile(fini_ifstream_t& file, int parseFlags) { 180 | fini_string_t line; 181 | fini_string_t section; // Set default section (support for sectionless files) 182 | size_t i = 0; 183 | keys_t* current = this->current; 184 | 185 | while(std::getline(file, line)) { 186 | i++; 187 | 188 | // Parse comments 189 | if (parseFlags & PARSE_COMMENTS_SLASH || parseFlags & PARSE_COMMENTS_ALL) 190 | line = line.substr(0, line.find("//")); 191 | if (parseFlags & PARSE_COMMENTS_HASH || parseFlags & PARSE_COMMENTS_ALL) 192 | line = line.substr(0, line.find("#")); 193 | 194 | if (trim(line).size() == 0) // Skip empty lines 195 | continue; 196 | 197 | if ('[' == line.at(0)) { // Section 198 | section = trim(line, "[] "); // Obtain key value, including contained spaced 199 | if (section.size() == 0) // If no section value, use default section 200 | current = this->current; 201 | 202 | if (sections.find(section) != sections.end()) { 203 | std::cerr << "Error: cpp-feather-ini-parser: Duplicate section '" + section + "':" << i << std::endl; 204 | throw -1; 205 | } 206 | 207 | current = new keys_t; 208 | sections[section] = current; 209 | } else { 210 | size_t indexEquals = line.find("="); 211 | if (indexEquals != fini_string_t::npos) { 212 | fini_string_t key = line.substr(0, indexEquals), value = line.substr(indexEquals + 1); 213 | r_trim(key); 214 | l_trim(value); 215 | 216 | if ((*current).find(key) != (*current).end()) { 217 | std::cerr << "Error: cpp-feather-ini-parser: Duplicate key '" + key + "':" << i << std::endl; 218 | throw -1; 219 | } 220 | 221 | (*current).emplace(key, value); 222 | } 223 | } 224 | } 225 | } 226 | 227 | bool INI::save(fini_string_t filename, int saveFlags) { 228 | saveFlags = (saveFlags > 0)? saveFlags: SAVE_FLAGS; 229 | 230 | fini_ofstream_t file((filename == "")? this->filename: filename, std::ios::trunc); 231 | if (!file.is_open()) 232 | return false; 233 | 234 | // Save remaining sections 235 | for(auto i: sections) { 236 | //if (i.first == "") 237 | // continue; 238 | if (saveFlags & SAVE_PRUNE && i.second->size() == 0) // No keys/values in section, skip to next 239 | continue; 240 | 241 | // Write section 242 | if (i.first != "") { 243 | if (saveFlags & SAVE_SPACE_SECTIONS) 244 | file << "[ " << i.first << " ]" << std::endl; 245 | else 246 | file << '[' << i.first << ']' << std::endl; 247 | } 248 | 249 | // Loop through key & values 250 | for(auto j: *i.second) { 251 | if (saveFlags & SAVE_PRUNE && j.second == "") 252 | continue; 253 | 254 | // Write key & value 255 | if (saveFlags & SAVE_TAB_KEYS && i.first != "") 256 | file << '\t'; // Insert indent 257 | 258 | if (saveFlags & SAVE_SPACE_KEYS) 259 | file << j.first << " = " << j.second; 260 | else 261 | file << j.first << '=' << j.second; 262 | 263 | if (saveFlags & SAVE_SEMICOLON_KEYS) 264 | file << ';'; 265 | 266 | file << std::endl; 267 | } 268 | 269 | // New section line 270 | if (saveFlags & SAVE_PADDING_SECTIONS) 271 | file << '\n'; 272 | } 273 | 274 | file.close(); 275 | 276 | return true; 277 | } 278 | 279 | //Provide bracket access to section contents 280 | INI::keys_t& INI::operator[](fini_string_t section) { 281 | select(section); 282 | return *current; 283 | } 284 | 285 | //Create a new section and select it 286 | void INI::create(fini_string_t section) { 287 | if (section != "" && sections.find(section) != sections.end()) { 288 | std::cerr << "Error: cpp-feather-ini-parser: Duplicate section '" << section << "'" << std::endl; 289 | throw -1; 290 | } 291 | 292 | current = new keys_t; 293 | sections[section] = current; 294 | } 295 | 296 | //Removes a section including all key/value pairs 297 | void INI::remove(fini_string_t section) { 298 | if (select(section, true)) 299 | sections.erase(section); 300 | 301 | current = NULL; 302 | } 303 | 304 | //Select a section for performing operations 305 | bool INI::select(fini_string_t section, bool noCreate) { 306 | sections_t::iterator sectionsit = sections.find(section); 307 | if (sectionsit == sections.end()) { 308 | if (!noCreate) 309 | create(section); 310 | 311 | return false; 312 | } 313 | 314 | current = sectionsit->second; 315 | return true; 316 | } 317 | 318 | fini_string_t INI::get(fini_string_t section, fini_string_t key, fini_string_t def) { 319 | return get(key, def); 320 | } 321 | 322 | fini_string_t INI::get(fini_string_t key, fini_string_t def) { 323 | auto it = current->find(key); 324 | if (it == current->end()) 325 | return def; 326 | 327 | return it->second; 328 | } 329 | 330 | template 331 | T INI::getAs(fini_string_t section, fini_string_t key, T def) { 332 | return getAs(key, def); 333 | } 334 | 335 | template 336 | T INI::getAs(fini_string_t key, T def) { 337 | auto it = current->find(key); 338 | if (it == current->end()) 339 | return def; 340 | 341 | return convert_to(it->second); 342 | } 343 | 344 | void INI::set(fini_string_t section, fini_string_t key, fini_string_t value) { 345 | if (!select(section)) 346 | create(section); 347 | 348 | set(key, value); 349 | } 350 | 351 | void INI::set(fini_string_t key, fini_string_t value) { 352 | (*current)[key] = value; 353 | } 354 | -------------------------------------------------------------------------------- /third-party/DirectXTK/GamePad.h: -------------------------------------------------------------------------------- 1 | //-------------------------------------------------------------------------------------- 2 | // File: GamePad.h 3 | // 4 | // Copyright (c) Microsoft Corporation. 5 | // Licensed under the MIT License. 6 | // 7 | // http://go.microsoft.com/fwlink/?LinkId=248929 8 | // http://go.microsoft.com/fwlink/?LinkID=615561 9 | //-------------------------------------------------------------------------------------- 10 | 11 | #pragma once 12 | 13 | #if !defined(USING_XINPUT) && !defined(USING_GAMEINPUT) && !defined(USING_WINDOWS_GAMING_INPUT) 14 | 15 | #ifdef _GAMING_DESKTOP 16 | #include 17 | #endif 18 | 19 | #if (defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES)) || (defined(_GAMING_DESKTOP) && (_GRDK_EDITION >= 220600)) 20 | #define USING_GAMEINPUT 21 | #elif (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/) && !defined(_GAMING_DESKTOP) && !defined(__MINGW32__) 22 | #define USING_WINDOWS_GAMING_INPUT 23 | #elif !defined(_XBOX_ONE) 24 | #define USING_XINPUT 25 | #endif 26 | 27 | #endif // !USING_XINPUT && !USING_GAMEINPUT && !USING_WINDOWS_GAMING_INPUT 28 | 29 | #ifdef USING_GAMEINPUT 30 | interface IGameInputDevice; 31 | #ifndef _GAMING_XBOX 32 | #pragma comment(lib,"gameinput.lib") 33 | #endif 34 | 35 | #elif defined(USING_WINDOWS_GAMING_INPUT) 36 | #pragma comment(lib,"runtimeobject.lib") 37 | #include 38 | 39 | #elif defined(_XBOX_ONE) 40 | // Legacy Xbox One XDK uses Windows::Xbox::Input 41 | 42 | #elif defined(USING_XINPUT) 43 | #if (_WIN32_WINNT >= 0x0602 /*_WIN32_WINNT_WIN8*/ ) 44 | #pragma comment(lib,"xinput.lib") 45 | #else 46 | #pragma comment(lib,"xinput9_1_0.lib") 47 | #endif 48 | 49 | #endif 50 | 51 | #include 52 | #include 53 | 54 | #ifdef __clang__ 55 | #pragma clang diagnostic push 56 | #pragma clang diagnostic ignored "-Wunknown-pragmas" 57 | #endif 58 | 59 | 60 | namespace DirectX 61 | { 62 | class GamePad 63 | { 64 | public: 65 | GamePad() noexcept(false); 66 | 67 | GamePad(GamePad&&) noexcept; 68 | GamePad& operator= (GamePad&&) noexcept; 69 | 70 | GamePad(GamePad const&) = delete; 71 | GamePad& operator=(GamePad const&) = delete; 72 | 73 | virtual ~GamePad(); 74 | 75 | #if defined(USING_GAMEINPUT) || defined(USING_WINDOWS_GAMING_INPUT) || defined(_XBOX_ONE) 76 | static constexpr int MAX_PLAYER_COUNT = 8; 77 | #else 78 | static constexpr int MAX_PLAYER_COUNT = 4; 79 | #endif 80 | 81 | static constexpr int c_MostRecent = -1; 82 | 83 | #ifdef USING_GAMEINPUT 84 | static constexpr int c_MergedInput = -2; 85 | #endif 86 | 87 | enum DeadZone 88 | { 89 | DEAD_ZONE_INDEPENDENT_AXES = 0, 90 | DEAD_ZONE_CIRCULAR, 91 | DEAD_ZONE_NONE, 92 | }; 93 | 94 | struct Buttons 95 | { 96 | bool a; 97 | bool b; 98 | bool x; 99 | bool y; 100 | bool leftStick; 101 | bool rightStick; 102 | bool leftShoulder; 103 | bool rightShoulder; 104 | union 105 | { 106 | bool back; 107 | bool view; 108 | }; 109 | union 110 | { 111 | bool start; 112 | bool menu; 113 | }; 114 | }; 115 | 116 | struct DPad 117 | { 118 | bool up; 119 | bool down; 120 | bool right; 121 | bool left; 122 | }; 123 | 124 | struct ThumbSticks 125 | { 126 | float leftX; 127 | float leftY; 128 | float rightX; 129 | float rightY; 130 | }; 131 | 132 | struct Triggers 133 | { 134 | float left; 135 | float right; 136 | }; 137 | 138 | struct State 139 | { 140 | bool connected; 141 | uint64_t packet; 142 | Buttons buttons; 143 | DPad dpad; 144 | ThumbSticks thumbSticks; 145 | Triggers triggers; 146 | 147 | bool __cdecl IsConnected() const noexcept { return connected; } 148 | 149 | // Is the button pressed currently? 150 | bool __cdecl IsAPressed() const noexcept { return buttons.a; } 151 | bool __cdecl IsBPressed() const noexcept { return buttons.b; } 152 | bool __cdecl IsXPressed() const noexcept { return buttons.x; } 153 | bool __cdecl IsYPressed() const noexcept { return buttons.y; } 154 | 155 | bool __cdecl IsLeftStickPressed() const noexcept { return buttons.leftStick; } 156 | bool __cdecl IsRightStickPressed() const noexcept { return buttons.rightStick; } 157 | 158 | bool __cdecl IsLeftShoulderPressed() const noexcept { return buttons.leftShoulder; } 159 | bool __cdecl IsRightShoulderPressed() const noexcept { return buttons.rightShoulder; } 160 | 161 | bool __cdecl IsBackPressed() const noexcept { return buttons.back; } 162 | bool __cdecl IsViewPressed() const noexcept { return buttons.view; } 163 | bool __cdecl IsStartPressed() const noexcept { return buttons.start; } 164 | bool __cdecl IsMenuPressed() const noexcept { return buttons.menu; } 165 | 166 | bool __cdecl IsDPadDownPressed() const noexcept { return dpad.down; } 167 | bool __cdecl IsDPadUpPressed() const noexcept { return dpad.up; } 168 | bool __cdecl IsDPadLeftPressed() const noexcept { return dpad.left; } 169 | bool __cdecl IsDPadRightPressed() const noexcept { return dpad.right; } 170 | 171 | bool __cdecl IsLeftThumbStickUp() const noexcept { return (thumbSticks.leftY > 0.5f) != 0; } 172 | bool __cdecl IsLeftThumbStickDown() const noexcept { return (thumbSticks.leftY < -0.5f) != 0; } 173 | bool __cdecl IsLeftThumbStickLeft() const noexcept { return (thumbSticks.leftX < -0.5f) != 0; } 174 | bool __cdecl IsLeftThumbStickRight() const noexcept { return (thumbSticks.leftX > 0.5f) != 0; } 175 | 176 | bool __cdecl IsRightThumbStickUp() const noexcept { return (thumbSticks.rightY > 0.5f) != 0; } 177 | bool __cdecl IsRightThumbStickDown() const noexcept { return (thumbSticks.rightY < -0.5f) != 0; } 178 | bool __cdecl IsRightThumbStickLeft() const noexcept { return (thumbSticks.rightX < -0.5f) != 0; } 179 | bool __cdecl IsRightThumbStickRight() const noexcept { return (thumbSticks.rightX > 0.5f) != 0; } 180 | 181 | bool __cdecl IsLeftTriggerPressed() const noexcept { return (triggers.left > 0.5f) != 0; } 182 | bool __cdecl IsRightTriggerPressed() const noexcept { return (triggers.right > 0.5f) != 0; } 183 | }; 184 | 185 | struct Capabilities 186 | { 187 | enum Type 188 | { 189 | UNKNOWN = 0, 190 | GAMEPAD, 191 | WHEEL, 192 | ARCADE_STICK, 193 | FLIGHT_STICK, 194 | DANCE_PAD, 195 | GUITAR, 196 | GUITAR_ALTERNATE, 197 | DRUM_KIT, 198 | GUITAR_BASS = 11, 199 | ARCADE_PAD = 19, 200 | }; 201 | 202 | bool connected; 203 | Type gamepadType; 204 | #ifdef USING_GAMEINPUT 205 | APP_LOCAL_DEVICE_ID id; 206 | #elif defined(USING_WINDOWS_GAMING_INPUT) 207 | std::wstring id; 208 | #else 209 | uint64_t id; 210 | #endif 211 | uint16_t vid; 212 | uint16_t pid; 213 | 214 | Capabilities() noexcept : connected(false), gamepadType(UNKNOWN), id{}, vid(0), pid(0) {} 215 | 216 | bool __cdecl IsConnected() const noexcept { return connected; } 217 | }; 218 | 219 | class ButtonStateTracker 220 | { 221 | public: 222 | enum ButtonState 223 | { 224 | UP = 0, // Button is up 225 | HELD = 1, // Button is held down 226 | RELEASED = 2, // Button was just released 227 | PRESSED = 3, // Buton was just pressed 228 | }; 229 | 230 | ButtonState a; 231 | ButtonState b; 232 | ButtonState x; 233 | ButtonState y; 234 | 235 | ButtonState leftStick; 236 | ButtonState rightStick; 237 | 238 | ButtonState leftShoulder; 239 | ButtonState rightShoulder; 240 | 241 | union 242 | { 243 | ButtonState back; 244 | ButtonState view; 245 | }; 246 | 247 | union 248 | { 249 | ButtonState start; 250 | ButtonState menu; 251 | }; 252 | 253 | ButtonState dpadUp; 254 | ButtonState dpadDown; 255 | ButtonState dpadLeft; 256 | ButtonState dpadRight; 257 | 258 | ButtonState leftStickUp; 259 | ButtonState leftStickDown; 260 | ButtonState leftStickLeft; 261 | ButtonState leftStickRight; 262 | 263 | ButtonState rightStickUp; 264 | ButtonState rightStickDown; 265 | ButtonState rightStickLeft; 266 | ButtonState rightStickRight; 267 | 268 | ButtonState leftTrigger; 269 | ButtonState rightTrigger; 270 | 271 | #pragma prefast(suppress: 26495, "Reset() performs the initialization") 272 | ButtonStateTracker() noexcept { Reset(); } 273 | 274 | void __cdecl Update(const State& state) noexcept; 275 | 276 | void __cdecl Reset() noexcept; 277 | 278 | State __cdecl GetLastState() const noexcept { return lastState; } 279 | 280 | private: 281 | State lastState; 282 | }; 283 | 284 | // Retrieve the current state of the gamepad of the associated player index 285 | State __cdecl GetState(int player, DeadZone deadZoneMode = DEAD_ZONE_INDEPENDENT_AXES); 286 | 287 | // Retrieve the current capabilities of the gamepad of the associated player index 288 | Capabilities __cdecl GetCapabilities(int player); 289 | 290 | // Set the vibration motor speeds of the gamepad 291 | bool __cdecl SetVibration(int player, float leftMotor, float rightMotor, float leftTrigger = 0.f, float rightTrigger = 0.f) noexcept; 292 | 293 | // Handle suspending/resuming 294 | void __cdecl Suspend() noexcept; 295 | void __cdecl Resume() noexcept; 296 | 297 | #ifdef USING_GAMEINPUT 298 | void __cdecl RegisterEvents(void* ctrlChanged) noexcept; 299 | 300 | // Underlying device access 301 | _Success_(return) 302 | bool __cdecl GetDevice(int player, _Outptr_ IGameInputDevice * *device) noexcept; 303 | #elif defined(USING_WINDOWS_GAMING_INPUT) || defined(_XBOX_ONE) 304 | void __cdecl RegisterEvents(void* ctrlChanged, void* userChanged) noexcept; 305 | #endif 306 | 307 | // Singleton 308 | static GamePad& __cdecl Get(); 309 | 310 | private: 311 | // Private implementation. 312 | class Impl; 313 | 314 | std::unique_ptr pImpl; 315 | }; 316 | } 317 | 318 | #ifdef __clang__ 319 | #pragma clang diagnostic pop 320 | #endif 321 | --------------------------------------------------------------------------------