├── user_mode
├── directx9
│ ├── d3dx9.lib
│ ├── d3dx9.h
│ ├── d3dx9shape.h
│ ├── d3dx9xof.h
│ └── d3dx9core.h
├── user_mode.vcxproj.user
├── espdef.h
├── Imgui
│ ├── imgui_impl_dx9.h
│ ├── imgui_impl_win32.h
│ ├── imconfig.h
│ ├── imgui_impl_dx9.cpp
│ └── imstb_rectpack.h
├── user_mode.vcxproj.filters
├── windowoverlay.h
├── communication.h
├── math.h
├── main.cpp
└── user_mode.vcxproj
├── kernel_mode
├── cache.h
├── km.vcxproj.user
├── cleaning.h
├── crt.h
├── interface.h
├── km.vcxproj.filters
├── encrypt.h
├── physical_internals.h
├── entry.cpp
├── km.vcxproj
├── definitions.h
└── utils.h
└── km.sln
/user_mode/directx9/d3dx9.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kejsik/driver-leak/HEAD/user_mode/directx9/d3dx9.lib
--------------------------------------------------------------------------------
/kernel_mode/cache.h:
--------------------------------------------------------------------------------
1 | namespace cache
2 | {
3 | inline PBYTE qword_address = NULL;
4 | inline __int64( __fastcall* o_hook )(void*) = nullptr;
5 |
6 | __int64 __fastcall f_hook( void* a1 );
7 | }
--------------------------------------------------------------------------------
/user_mode/user_mode.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/kernel_mode/km.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Off
5 |
6 |
--------------------------------------------------------------------------------
/user_mode/espdef.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Imgui/imgui.h"
3 |
4 |
5 | void DrawBox(float X, float Y, float W, float H, const ImU32& color, int thickness)
6 | {
7 | ImDrawList* Drawlist = ImGui::GetBackgroundDrawList();
8 |
9 | Drawlist->AddRect(ImVec2(X + 1, Y + 1), ImVec2(((X + W) - 1), ((Y + H) - 1)), ImGui::GetColorU32(color), thickness);
10 | Drawlist->AddRect(ImVec2(X, Y), ImVec2(X + W, Y + H), ImGui::GetColorU32(color), thickness);
11 | }
--------------------------------------------------------------------------------
/kernel_mode/cleaning.h:
--------------------------------------------------------------------------------
1 | namespace clean
2 | {
3 | bool null_pfn( PMDL mdl )
4 | {
5 | PPFN_NUMBER mdl_pages = MmGetMdlPfnArray( mdl );
6 | if ( !mdl_pages ) { return false; }
7 |
8 | ULONG mdl_page_count = ADDRESS_AND_SIZE_TO_SPAN_PAGES( MmGetMdlVirtualAddress( mdl ), MmGetMdlByteCount( mdl ) );
9 |
10 | ULONG null_pfn = 0x0;
11 |
12 | MM_COPY_ADDRESS source_address = { 0 };
13 | source_address.VirtualAddress = &null_pfn;
14 |
15 | for ( ULONG i = 0; i < mdl_page_count; i++ )
16 | {
17 | size_t bytes = 0;
18 | MmCopyMemory( &mdl_pages[i], source_address, sizeof( ULONG ), MM_COPY_MEMORY_VIRTUAL, &bytes );
19 | }
20 |
21 | return true;
22 | }
23 | }
--------------------------------------------------------------------------------
/kernel_mode/crt.h:
--------------------------------------------------------------------------------
1 | namespace crt
2 | {
3 | template
4 | __forceinline int strlen( t str ) {
5 | if ( !str )
6 | {
7 | return 0;
8 | }
9 |
10 | t buffer = str;
11 |
12 | while ( *buffer )
13 | {
14 | *buffer++;
15 | }
16 |
17 | return ( int )( buffer - str );
18 | }
19 |
20 | bool strcmp( const char *src, const char *dst )
21 | {
22 | if ( !src || !dst )
23 | {
24 | return true;
25 | }
26 |
27 | const auto src_sz = crt::strlen( src );
28 | const auto dst_sz = crt::strlen( dst );
29 |
30 | if ( src_sz != dst_sz )
31 | {
32 | return true;
33 | }
34 |
35 | for ( int i = 0; i < src_sz; i++ )
36 | {
37 | if ( src[i] != dst[i] )
38 | {
39 | return true;
40 | }
41 | }
42 |
43 | return false;
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/kernel_mode/interface.h:
--------------------------------------------------------------------------------
1 | typedef enum _request_codes
2 | {
3 | request_base = 0x6AAE0,
4 | request_process_base = 0x6AAE1,
5 | request_read = 0x6AAE2,
6 | request_write = 0x6AAE3,
7 | request_success = 0x6AAE4,
8 | request_unique = 0x6AAE5,
9 | request_guardreg = 0x6AAE6,
10 | request_cr3 = 0x6AAE7,
11 | }request_codes, *prequest_codes;
12 |
13 | typedef struct _read_request {
14 | uint32_t pid;
15 | uintptr_t address;
16 | void *buffer;
17 | size_t size;
18 | } read_request, *pread_request;
19 |
20 | typedef struct _write_request {
21 | uint32_t pid;
22 | uintptr_t address;
23 | void *buffer;
24 | size_t size;
25 | } write_request, *pwrite_request;
26 |
27 | typedef struct _base_request {
28 | uint32_t pid;
29 | uintptr_t handle;
30 | WCHAR name[260];
31 | } base_request, *pbase_request;
32 |
33 | typedef struct _guardreg_request {
34 | uintptr_t allocation;
35 | } guardreg_request, * pguardreg_request;
36 |
37 |
38 | typedef struct _process_base_request {
39 | uint32_t pid;
40 | uintptr_t handle;
41 | } process_base_request, * p_process_base_request;
42 |
43 |
44 | typedef struct _request_data
45 | {
46 | uint32_t unique;
47 | request_codes code;
48 | void *data;
49 | }request_data, *prequest_data;
50 |
51 |
52 | typedef struct _cr3_request {
53 | uint32_t pid;
54 | } cr3_request, * pcr3_request;
--------------------------------------------------------------------------------
/user_mode/Imgui/imgui_impl_dx9.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer Backend for DirectX9
2 | // This needs to be used along with a Platform Backend (e.g. Win32)
3 |
4 | // Implemented features:
5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID!
6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
7 |
8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
10 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
11 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
12 |
13 | #pragma once
14 | #include "imgui.h" // IMGUI_IMPL_API
15 |
16 | struct IDirect3DDevice9;
17 |
18 | IMGUI_IMPL_API bool ImGui_ImplDX9_Init(IDirect3DDevice9* device);
19 | IMGUI_IMPL_API void ImGui_ImplDX9_Shutdown();
20 | IMGUI_IMPL_API void ImGui_ImplDX9_NewFrame();
21 | IMGUI_IMPL_API void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data);
22 |
23 | // Use if you want to reset your rendering device without losing Dear ImGui state.
24 | IMGUI_IMPL_API bool ImGui_ImplDX9_CreateDeviceObjects();
25 | IMGUI_IMPL_API void ImGui_ImplDX9_InvalidateDeviceObjects();
26 |
--------------------------------------------------------------------------------
/kernel_mode/km.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | utilities
9 |
10 |
11 | hook
12 |
13 |
14 | hook
15 |
16 |
17 | utilities\ntos
18 |
19 |
20 | utilities\ntos
21 |
22 |
23 | utilities\ntos
24 |
25 |
26 | utilities\software
27 |
28 |
29 | utilities\memory
30 |
31 |
32 |
33 |
34 | {0c7080d5-6e82-4501-8f1f-de13998f53c5}
35 |
36 |
37 | {acf5fbe8-528e-4128-ab9a-b90eafd58e5f}
38 |
39 |
40 | {8bb08769-321e-4322-873b-e73c84fd30f1}
41 |
42 |
43 | {7c350629-4a10-47e8-96c7-d035ca89d984}
44 |
45 |
46 | {ab99a127-5baf-463b-941e-b04cb42a5b2e}
47 |
48 |
49 |
--------------------------------------------------------------------------------
/user_mode/directx9/d3dx9.h:
--------------------------------------------------------------------------------
1 | //////////////////////////////////////////////////////////////////////////////
2 | //
3 | // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 | //
5 | // File: d3dx9.h
6 | // Content: D3DX utility library
7 | //
8 | //////////////////////////////////////////////////////////////////////////////
9 |
10 | #ifdef __D3DX_INTERNAL__
11 | #error Incorrect D3DX header used
12 | #endif
13 |
14 | #ifndef __D3DX9_H__
15 | #define __D3DX9_H__
16 |
17 |
18 | // Defines
19 | #include
20 |
21 | #define D3DX_DEFAULT ((UINT) -1)
22 | #define D3DX_DEFAULT_NONPOW2 ((UINT) -2)
23 | #define D3DX_DEFAULT_FLOAT FLT_MAX
24 | #define D3DX_FROM_FILE ((UINT) -3)
25 | #define D3DFMT_FROM_FILE ((D3DFORMAT) -3)
26 |
27 | #ifndef D3DXINLINE
28 | #ifdef _MSC_VER
29 | #if (_MSC_VER >= 1200)
30 | #define D3DXINLINE __forceinline
31 | #else
32 | #define D3DXINLINE __inline
33 | #endif
34 | #else
35 | #ifdef __cplusplus
36 | #define D3DXINLINE inline
37 | #else
38 | #define D3DXINLINE
39 | #endif
40 | #endif
41 | #endif
42 |
43 |
44 |
45 | // Includes
46 | #include "d3d9.h"
47 | #include "d3dx9math.h"
48 | #include "d3dx9core.h"
49 | #include "d3dx9xof.h"
50 | #include "d3dx9mesh.h"
51 | #include "d3dx9shader.h"
52 | #include "d3dx9effect.h"
53 |
54 | #include "d3dx9tex.h"
55 | #include "d3dx9shape.h"
56 | #include "d3dx9anim.h"
57 |
58 |
59 |
60 | // Errors
61 | #define _FACDD 0x876
62 | #define MAKE_DDHRESULT( code ) MAKE_HRESULT( 1, _FACDD, code )
63 |
64 | enum _D3DXERR {
65 | D3DXERR_CANNOTMODIFYINDEXBUFFER = MAKE_DDHRESULT(2900),
66 | D3DXERR_INVALIDMESH = MAKE_DDHRESULT(2901),
67 | D3DXERR_CANNOTATTRSORT = MAKE_DDHRESULT(2902),
68 | D3DXERR_SKINNINGNOTSUPPORTED = MAKE_DDHRESULT(2903),
69 | D3DXERR_TOOMANYINFLUENCES = MAKE_DDHRESULT(2904),
70 | D3DXERR_INVALIDDATA = MAKE_DDHRESULT(2905),
71 | D3DXERR_LOADEDMESHASNODATA = MAKE_DDHRESULT(2906),
72 | D3DXERR_DUPLICATENAMEDFRAGMENT = MAKE_DDHRESULT(2907),
73 | D3DXERR_CANNOTREMOVELASTITEM = MAKE_DDHRESULT(2908),
74 | };
75 |
76 |
77 | #endif //__D3DX9_H__
78 |
--------------------------------------------------------------------------------
/km.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.2.32630.192
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kernel_mode", "kernel_mode\km.vcxproj", "{4C4C54E5-C199-4146-B5D7-FDDC9FE74066}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "user_mode", "user_mode\user_mode.vcxproj", "{408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Debug|x64.ActiveCfg = Debug|x64
19 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Debug|x64.Build.0 = Debug|x64
20 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Debug|x86.ActiveCfg = Debug|Win32
21 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Debug|x86.Build.0 = Debug|Win32
22 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Release|x64.ActiveCfg = Release|x64
23 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Release|x64.Build.0 = Release|x64
24 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Release|x64.Deploy.0 = Release|x64
25 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Release|x86.ActiveCfg = Release|Win32
26 | {4C4C54E5-C199-4146-B5D7-FDDC9FE74066}.Release|x86.Build.0 = Release|Win32
27 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Debug|x64.ActiveCfg = Debug|x64
28 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Debug|x64.Build.0 = Debug|x64
29 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Debug|x86.ActiveCfg = Debug|Win32
30 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Debug|x86.Build.0 = Debug|Win32
31 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Release|x64.ActiveCfg = Release|x64
32 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Release|x64.Build.0 = Release|x64
33 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Release|x86.ActiveCfg = Release|Win32
34 | {408B9E7F-A20F-49BC-AF1D-4D1365EEEED6}.Release|x86.Build.0 = Release|Win32
35 | EndGlobalSection
36 | GlobalSection(SolutionProperties) = preSolution
37 | HideSolutionNode = FALSE
38 | EndGlobalSection
39 | GlobalSection(ExtensibilityGlobals) = postSolution
40 | SolutionGuid = {71059B11-4D27-4A17-A843-3D58F584FF76}
41 | EndGlobalSection
42 | EndGlobal
43 |
--------------------------------------------------------------------------------
/user_mode/Imgui/imgui_impl_win32.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Platform Backend for Windows (standard windows API for 32 and 64 bits applications)
2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..)
3 |
4 | // Implemented features:
5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui)
6 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
7 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
8 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'.
9 |
10 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
11 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
12 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
13 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
14 |
15 | #pragma once
16 | #include "imgui.h" // IMGUI_IMPL_API
17 |
18 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd);
19 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown();
20 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame();
21 |
22 | // Win32 message handler your application need to call.
23 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper.
24 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it.
25 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE.
26 |
27 | #if 0
28 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
29 | #endif
30 |
31 | // DPI-related helpers (optional)
32 | // - Use to enable DPI awareness without having to create an application manifest.
33 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps.
34 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc.
35 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime,
36 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies.
37 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness();
38 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd
39 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor
40 |
41 | // Transparency related helpers (optional) [experimental]
42 | // - Use to enable alpha compositing transparency with the desktop.
43 | // - Use together with e.g. clearing your framebuffer with zero-alpha.
44 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd
45 |
--------------------------------------------------------------------------------
/kernel_mode/encrypt.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | /*____________________________________________________________________________________________________________
4 | Original Author: skadro
5 | Github: https://github.com/skadro-official
6 | License: See end of file
7 | skCrypter
8 | Compile-time, Usermode + Kernelmode, safe and lightweight string crypter library for C++11+
9 | *Not removing this part is appreciated*
10 | ____________________________________________________________________________________________________________*/
11 |
12 | #ifdef _KERNEL_MODE
13 | namespace std
14 | {
15 | // STRUCT TEMPLATE remove_reference
16 | template
17 | struct remove_reference {
18 | using type = _Ty;
19 | };
20 |
21 | template
22 | struct remove_reference<_Ty &> {
23 | using type = _Ty;
24 | };
25 |
26 | template
27 | struct remove_reference<_Ty &&> {
28 | using type = _Ty;
29 | };
30 |
31 | template
32 | using remove_reference_t = typename remove_reference<_Ty>::type;
33 |
34 | // STRUCT TEMPLATE remove_const
35 | template
36 | struct remove_const { // remove top-level const qualifier
37 | using type = _Ty;
38 | };
39 |
40 | template
41 | struct remove_const {
42 | using type = _Ty;
43 | };
44 |
45 | template
46 | using remove_const_t = typename remove_const<_Ty>::type;
47 | }
48 | #else
49 | #include
50 | #endif
51 |
52 | namespace skc
53 | {
54 | template
55 | using clean_type = typename std::remove_const_t>;
56 |
57 | template
58 | class skCrypter
59 | {
60 | public:
61 | __forceinline constexpr skCrypter( T *data )
62 | {
63 | crypt( data );
64 | }
65 |
66 | __forceinline T *get( )
67 | {
68 | return _storage;
69 | }
70 |
71 | __forceinline int size( ) // (w)char count
72 | {
73 | return _size;
74 | }
75 |
76 | __forceinline char key( )
77 | {
78 | return _key1;
79 | }
80 |
81 | __forceinline T *encrypt( )
82 | {
83 | if ( !isEncrypted( ) )
84 | crypt( _storage );
85 |
86 | return _storage;
87 | }
88 |
89 | __forceinline T *decrypt( )
90 | {
91 | if ( isEncrypted( ) )
92 | crypt( _storage );
93 |
94 | return _storage;
95 | }
96 |
97 | __forceinline bool isEncrypted( )
98 | {
99 | return _storage[_size - 1] != 0;
100 | }
101 |
102 | __forceinline void clear( ) // set full storage to 0
103 | {
104 | for ( int i = 0; i < _size; i++ )
105 | {
106 | _storage[i] = 0;
107 | }
108 | }
109 |
110 | __forceinline operator T *( )
111 | {
112 | decrypt( );
113 |
114 | return _storage;
115 | }
116 |
117 | private:
118 | __forceinline constexpr void crypt( T *data )
119 | {
120 | for ( int i = 0; i < _size; i++ )
121 | {
122 | _storage[i] = data[i] ^ ( _key1 + i % ( 1 + _key2 ) );
123 | }
124 | }
125 |
126 | T _storage[_size] {};
127 | };
128 | }
129 |
130 | #define e(str) skCrypt_key(str, __TIME__[4], __TIME__[7])
131 | #define skCrypt_key(str, key1, key2) []() { \
132 | constexpr static auto crypted = skc::skCrypter \
133 | >((skc::clean_type*)str); \
134 | return crypted; }()
135 |
--------------------------------------------------------------------------------
/user_mode/user_mode.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | directx9
8 |
9 |
10 | directx9
11 |
12 |
13 | directx9
14 |
15 |
16 | directx9
17 |
18 |
19 | directx9
20 |
21 |
22 | directx9
23 |
24 |
25 | directx9
26 |
27 |
28 | directx9
29 |
30 |
31 | directx9
32 |
33 |
34 | directx9
35 |
36 |
37 | Imgui
38 |
39 |
40 | Imgui
41 |
42 |
43 | Imgui
44 |
45 |
46 | Imgui
47 |
48 |
49 | Imgui
50 |
51 |
52 | Imgui
53 |
54 |
55 | Imgui
56 |
57 |
58 | Imgui
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | Imgui
68 |
69 |
70 | Imgui
71 |
72 |
73 | Imgui
74 |
75 |
76 | Imgui
77 |
78 |
79 | Imgui
80 |
81 |
82 | Imgui
83 |
84 |
85 | Imgui
86 |
87 |
88 |
89 |
90 | {03bceba1-ba17-48ef-ac34-1a1cb2f59793}
91 |
92 |
93 | {a0754f8a-dfc2-4b7a-83d8-fac24eabe2db}
94 |
95 |
96 |
97 |
98 | directx9
99 |
100 |
101 |
102 |
103 | directx9
104 |
105 |
106 |
--------------------------------------------------------------------------------
/user_mode/windowoverlay.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "Imgui/imgui_impl_win32.h"
8 | #include "Imgui/imgui_impl_dx9.h"
9 | #include
10 | #include
11 |
12 | HWND hwnd = NULL;
13 | int Width;
14 | int Depth;
15 | int Height;
16 | DWORD ScreenCenterX;
17 | DWORD ScreenCenterY;
18 | static HWND Window = NULL;
19 | RECT GameRect = { NULL };
20 | IDirect3D9Ex* p_Object = NULL;
21 | static LPDIRECT3DDEVICE9 D3dDevice = NULL;
22 | D3DPRESENT_PARAMETERS d3dpp;
23 | static LPDIRECT3DVERTEXBUFFER9 TriBuf = NULL;
24 | extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
25 |
26 | void SetWindowToTarget()
27 | {
28 | while (true)
29 | {
30 | if (hwnd)
31 | {
32 | ZeroMemory(&GameRect, sizeof(GameRect));
33 | GetWindowRect(hwnd, &GameRect);
34 | Width = GameRect.right - GameRect.left;
35 | Height = GameRect.bottom - GameRect.top;
36 | DWORD dwStyle = GetWindowLong(hwnd, GWL_STYLE);
37 |
38 | if (dwStyle & WS_BORDER)
39 | {
40 | GameRect.top += 32;
41 | Height -= 39;
42 | }
43 | ScreenCenterX = Width / 2;
44 | ScreenCenterY = Height / 2;
45 | MoveWindow(Window, GameRect.left, GameRect.top, Width, Height, true);
46 | }
47 | else
48 | {
49 | exit(0);
50 | }
51 | }
52 | }
53 |
54 |
55 | void xShutdown()
56 | {
57 | TriBuf->Release();
58 | D3dDevice->Release();
59 | p_Object->Release();
60 | DestroyWindow(Window);
61 | UnregisterClass(L"EdgeUiInputTopWndClass", NULL);
62 | }
63 |
64 |
65 | LRESULT CALLBACK WinProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
66 | {
67 | if (ImGui_ImplWin32_WndProcHandler(hWnd, Message, wParam, lParam))
68 | return true;
69 |
70 | switch (Message)
71 | {
72 | case WM_DESTROY:
73 | xShutdown();
74 | PostQuitMessage(0);
75 | exit(4);
76 | break;
77 | case WM_SIZE:
78 | if (D3dDevice != NULL && wParam != SIZE_MINIMIZED)
79 | {
80 | ImGui_ImplDX9_InvalidateDeviceObjects();
81 | d3dpp.BackBufferWidth = LOWORD(lParam);
82 | d3dpp.BackBufferHeight = HIWORD(lParam);
83 | HRESULT hr = D3dDevice->Reset(&d3dpp);
84 | if (hr == D3DERR_INVALIDCALL)
85 | IM_ASSERT(0);
86 | ImGui_ImplDX9_CreateDeviceObjects();
87 | }
88 | break;
89 | default:
90 | return DefWindowProc(hWnd, Message, wParam, lParam);
91 | break;
92 | }
93 | return 0;
94 | }
95 |
96 | const MARGINS Margin = { -1 };
97 | void xCreateWindow()
98 | {
99 | CreateThread(0, 0, (LPTHREAD_START_ROUTINE)SetWindowToTarget, 0, 0, 0);
100 |
101 | WNDCLASSEX wc;
102 | ZeroMemory(&wc, sizeof(wc));
103 | wc.cbSize = sizeof(wc);
104 | wc.lpszClassName = L"WindowClass";
105 | wc.lpfnWndProc = WinProc;
106 | RegisterClassEx(&wc);
107 |
108 | if (hwnd)
109 | {
110 | GetClientRect(hwnd, &GameRect);
111 | POINT xy;
112 | ClientToScreen(hwnd, &xy);
113 | GameRect.left = xy.x;
114 | GameRect.top = xy.y;
115 |
116 | Width = GameRect.right;
117 | Height = GameRect.bottom;
118 | }
119 | else
120 | exit(2);
121 | ShowWindow(Window, SW_SHOW);
122 |
123 | Window = CreateWindowEx(NULL, L"WindowClass", L"Performance Counter", WS_POPUP | WS_VISIBLE, 0, 0, Width, Height, 0, 0, 0, 0);
124 |
125 | DwmExtendFrameIntoClientArea(Window, &Margin);
126 | SetWindowLong(Window, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW | WS_EX_LAYERED);
127 | ShowWindow(Window, SW_SHOW);
128 | UpdateWindow(Window);
129 | }
130 |
131 |
132 |
133 | void xInitD3d()
134 | {
135 | if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &p_Object)))
136 | exit(3);
137 | ZeroMemory(&d3dpp, sizeof(d3dpp));
138 | d3dpp.BackBufferWidth = Width;
139 | d3dpp.BackBufferHeight = Height;
140 | d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
141 | d3dpp.MultiSampleQuality = D3DMULTISAMPLE_NONE;
142 | d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
143 | d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
144 | d3dpp.EnableAutoDepthStencil = TRUE;
145 | d3dpp.hDeviceWindow = Window;
146 | d3dpp.Windowed = TRUE;
147 | p_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &D3dDevice);
148 | IMGUI_CHECKVERSION();
149 | ImGui::CreateContext();
150 | ImGuiIO& io = ImGui::GetIO();
151 | (void)io;
152 | ImGui_ImplWin32_Init(Window);
153 | ImGui_ImplDX9_Init(D3dDevice);
154 | auto& Style = ImGui::GetStyle();
155 | p_Object->Release();
156 | }
157 |
158 |
159 |
--------------------------------------------------------------------------------
/kernel_mode/physical_internals.h:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 | //https://ntdiff.github.io/
5 | #define WINDOWS_1803 17134
6 | #define WINDOWS_1809 17763
7 | #define WINDOWS_1903 18362
8 | #define WINDOWS_1909 18363
9 | #define WINDOWS_2004 19041
10 | #define WINDOWS_20H2 19569
11 | #define WINDOWS_21H1 20180
12 | namespace internals
13 | {
14 | DWORD directory( )
15 | {
16 | RTL_OSVERSIONINFOW ver = { 0 };
17 | RtlGetVersion( &ver );
18 |
19 | switch (ver.dwBuildNumber) {
20 | case WINDOWS_1803:
21 | return 0x0278;
22 | break;
23 | case WINDOWS_1809:
24 | return 0x0278;
25 | break;
26 | case WINDOWS_1903:
27 | return 0x0280;
28 | break;
29 | case WINDOWS_1909:
30 | return 0x0280;
31 | break;
32 | case WINDOWS_2004:
33 | return 0x0388;
34 | break;
35 | case WINDOWS_20H2:
36 | return 0x0388;
37 | break;
38 | case WINDOWS_21H1:
39 | return 0x0388;
40 | break;
41 | default:
42 | return 0x0388;
43 | }
44 | }
45 |
46 | ULONG_PTR process_cr3( PEPROCESS pProcess )
47 | {
48 | PUCHAR process = (PUCHAR)pProcess;
49 | ULONG_PTR process_dirbase = *(PULONG_PTR)(process + 0x28);
50 | if (process_dirbase == 0)
51 | {
52 | DWORD UserDirOffset = directory( );
53 | ULONG_PTR process_userdirbase = *(PULONG_PTR)(process + UserDirOffset);
54 | return process_userdirbase;
55 | }
56 | return process_dirbase;
57 | }
58 |
59 | NTSTATUS write_physical_address( uintptr_t TargetAddress, PVOID lpBuffer, SIZE_T Size, SIZE_T* BytesWritten )
60 | {
61 | if (!TargetAddress)
62 | return STATUS_UNSUCCESSFUL;
63 |
64 | PHYSICAL_ADDRESS AddrToWrite = { 0 };
65 | AddrToWrite.QuadPart = (LONGLONG)TargetAddress;
66 |
67 | PVOID pmapped_mem = MmMapIoSpaceEx( AddrToWrite, Size, PAGE_READWRITE );
68 |
69 | if (!pmapped_mem)
70 | return STATUS_UNSUCCESSFUL;
71 |
72 | memcpy( pmapped_mem, lpBuffer, Size );
73 |
74 | *BytesWritten = Size;
75 | MmUnmapIoSpace( pmapped_mem, Size );
76 | return STATUS_SUCCESS;
77 | }
78 |
79 | #define PAGE_OFFSET_SIZE 12
80 | static const uint64_t PMASK = (~0xfull << 8) & 0xfffffffffull;
81 |
82 | NTSTATUS read_physical_memory(uint64_t target_address, PVOID buffer, SIZE_T size, SIZE_T* bytes_read)
83 | {
84 | PHYSICAL_ADDRESS phys_addr = { 0 };
85 | phys_addr.QuadPart = target_address;
86 | PVOID mapped_addr = MmMapIoSpace(phys_addr, size, MmNonCached);
87 |
88 | if (!mapped_addr)
89 | {
90 | return STATUS_UNSUCCESSFUL;
91 | }
92 |
93 | RtlCopyMemory(buffer, mapped_addr, size);
94 | *bytes_read = size;
95 |
96 | MmUnmapIoSpace(mapped_addr, size);
97 | return STATUS_SUCCESS;
98 | }
99 |
100 |
101 | uint64_t translate_linear_address( uint64_t directoryTableBase, uint64_t virtualAddress ) {
102 | directoryTableBase &= ~0xf;
103 |
104 | uint64_t pageOffset = virtualAddress & ~(~0ul << PAGE_OFFSET_SIZE);
105 | uint64_t pte = ((virtualAddress >> 12) & (0x1ffll));
106 | uint64_t pt = ((virtualAddress >> 21) & (0x1ffll));
107 | uint64_t pd = ((virtualAddress >> 30) & (0x1ffll));
108 | uint64_t pdp = ((virtualAddress >> 39) & (0x1ffll));
109 |
110 | SIZE_T readsize = 0;
111 | uint64_t pdpe = 0;
112 | read_physical_memory( directoryTableBase + 8 * pdp, &pdpe, sizeof( pdpe ), &readsize );
113 | if (~pdpe & 1)
114 | return 0;
115 |
116 | uint64_t pde = 0;
117 | read_physical_memory( (pdpe & PMASK) + 8 * pd, &pde, sizeof( pde ), &readsize );
118 | if (~pde & 1)
119 | return 0;
120 |
121 | /* 1GB large page, use pde's 12-34 bits */
122 | if (pde & 0x80)
123 | return (pde & (~0ull << 42 >> 12)) + (virtualAddress & ~(~0ull << 30));
124 |
125 | uint64_t pteAddr = 0;
126 | read_physical_memory( (pde & PMASK) + 8 * pt, &pteAddr, sizeof( pteAddr ), &readsize );
127 | if (~pteAddr & 1)
128 | return 0;
129 |
130 | /* 2MB large page */
131 | if (pteAddr & 0x80)
132 | return (pteAddr & PMASK) + (virtualAddress & ~(~0ull << 21));
133 |
134 | virtualAddress = 0;
135 | read_physical_memory( (pteAddr & PMASK) + 8 * pte, &virtualAddress, sizeof( virtualAddress ), &readsize );
136 | virtualAddress &= PMASK;
137 |
138 | if (!virtualAddress)
139 | return 0;
140 |
141 | return virtualAddress + pageOffset;
142 | }
143 | }
--------------------------------------------------------------------------------
/user_mode/communication.h:
--------------------------------------------------------------------------------
1 | #pragma warning(disable : 4996).
2 |
3 | class rcdrv
4 | {
5 | private:
6 | typedef LONG_PTR(__cdecl* pfunc_hk_t)(ULONG_PTR a1);
7 | pfunc_hk_t pHookFunc = (pfunc_hk_t)NULL;
8 |
9 | typedef enum _request_codes
10 | {
11 | request_base = 0x6AAE0,
12 | request_process_base = 0x6AAE1,
13 | request_read = 0x6AAE2,
14 | request_write = 0x6AAE3,
15 | request_success = 0x6AAE4,
16 | request_unique = 0x6AAE5,
17 | request_guardreg = 0x6AAE6,
18 | request_cr3 = 0x6AAE7,
19 | }request_codes, * prequest_codes;
20 |
21 | typedef struct _read_request {
22 | uint32_t pid;
23 | uintptr_t address;
24 | void* buffer;
25 | size_t size;
26 | } read_request, * pread_request;
27 |
28 | typedef struct _write_request {
29 | uint32_t pid;
30 | uintptr_t address;
31 | void* buffer;
32 | size_t size;
33 | } write_request, * pwrite_request;
34 |
35 | typedef struct _base_request {
36 | uint32_t pid;
37 | uintptr_t handle;
38 | WCHAR name[260];
39 | } base_request, * pbase_request;
40 |
41 | typedef struct _guardreg_request {
42 | uintptr_t allocation;
43 | } guardreg_request, * pguardreg_request;
44 |
45 |
46 |
47 | typedef struct _process_base_request {
48 | uint32_t pid;
49 | uintptr_t handle;
50 | } process_base_request, * p_process_base_request;
51 |
52 | typedef struct _cr3_request {
53 | uint32_t pid;
54 | } cr3_request, * pcr3_request;
55 |
56 |
57 | typedef struct _request_data
58 | {
59 | uint32_t unique;
60 | request_codes code;
61 | void* data;
62 | }request_data, * prequest_data;
63 |
64 | int32_t pid = 0;
65 | public:
66 | uint64_t _guardedregion;
67 | inline bool attach( int _pid )
68 | {
69 | if (!_pid)
70 | return false;
71 |
72 | pid = _pid;
73 |
74 | return true;
75 | }
76 |
77 | inline bool reqcr3()
78 | {
79 | cr3_request data{ 0 };
80 | data.pid = pid;
81 |
82 |
83 |
84 | return send_cmd(&data, request_cr3);
85 | }
86 |
87 | inline auto send_cmd( void* data, request_codes code ) -> bool
88 | {
89 | if (!data || !code)
90 | {
91 | return false;
92 | }
93 |
94 | request_data request{ 0 };
95 |
96 | request.unique = request_unique;
97 | request.data = data;
98 | request.code = code;
99 |
100 | const auto result = pHookFunc((uintptr_t) & request );
101 |
102 | if (result != request_success)
103 | {
104 | return false;
105 | }
106 |
107 | return true;
108 | }
109 |
110 | inline auto get_module_base( const std::string module_name ) -> const std::uintptr_t
111 | {
112 | base_request data{ 0 };
113 |
114 | data.pid = pid;
115 | data.handle = 0;
116 |
117 | std::wstring wstr{ std::wstring( module_name.begin( ), module_name.end( ) ) };
118 |
119 | memset( data.name, 0, sizeof( WCHAR ) * 260 );
120 | wcscpy( data.name, wstr.c_str( ) );
121 |
122 | send_cmd( &data, request_base );
123 |
124 | return data.handle;
125 | }
126 |
127 | inline auto guarded_region() -> uintptr_t
128 | {
129 | guardreg_request data{ 0 };
130 | send_cmd(&data, request_guardreg);
131 | _guardedregion = data.allocation;
132 | return data.allocation;
133 | }
134 |
135 | inline auto get_process_base( ) -> const std::uintptr_t
136 | {
137 | process_base_request data{ 0 };
138 |
139 | data.pid = pid;
140 | data.handle = 0;
141 |
142 | send_cmd( &data, request_process_base );
143 |
144 | return data.handle;
145 | }
146 |
147 | HMODULE ensure_dll_load( )
148 | {
149 | #define LOAD_DLL(str) LoadLibrary((str))
150 |
151 | LOAD_DLL(L"user32.dll" );
152 |
153 | #undef LOAD_DLL
154 | return LoadLibrary(L"win32u.dll" );
155 | }
156 |
157 | inline auto initialize( ) -> bool
158 | {
159 | if (!pHookFunc)
160 | {
161 | HMODULE hDll = GetModuleHandleA("win32u.dll" );
162 | if (!hDll)
163 | {
164 | hDll = ensure_dll_load( );
165 | if (!hDll) return false;
166 | }
167 |
168 | pHookFunc = (pfunc_hk_t)GetProcAddress( hDll, ( "NtGdiUnloadPrinterDriver" ) );
169 | if (!pHookFunc)
170 | {
171 | pHookFunc = (pfunc_hk_t)NULL;
172 | return false;
173 | }
174 | }
175 |
176 | pid = GetCurrentProcessId( );
177 | return true;
178 | }
179 |
180 | inline auto read_physical_memory( const std::uintptr_t address, void* buffer, const std::size_t size ) -> bool
181 | {
182 | read_request data{ 0 };
183 |
184 | data.pid = pid;
185 | data.address = address;
186 | data.buffer = buffer;
187 | data.size = size;
188 |
189 | return send_cmd( &data, request_read );
190 | }
191 |
192 | template
193 | inline auto read_physical_memory( const std::uintptr_t address ) -> t
194 | {
195 | t response{ };
196 | read_physical_memory( address, &response, sizeof( t ) );
197 | return response;
198 | }
199 |
200 | inline auto write_physical_memory( const std::uintptr_t address, void* buffer, const std::size_t size ) -> bool
201 | {
202 | write_request data{ 0 };
203 |
204 | data.pid = pid;
205 | data.address = address;
206 | data.buffer = buffer;
207 | data.size = size;
208 |
209 | return send_cmd( &data, request_write );
210 | }
211 |
212 | template
213 | inline auto write_physical_memory( const std::uintptr_t address, t value ) -> bool
214 | {
215 | return write_physical_memory( address, &value, sizeof( t ) );
216 | }
217 | };
218 |
219 | rcdrv* communication = new rcdrv( );
--------------------------------------------------------------------------------
/user_mode/math.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define PI 3.14159265358979323846f
5 |
6 | class Vector3
7 | {
8 | public:
9 | Vector3() : x(0.f), y(0.f), z(0.f) {}
10 | Vector3(double _x, double _y, double _z) : x(_x), y(_y), z(_z) {}
11 | ~Vector3() {}
12 | double x;
13 | double y;
14 | double z;
15 | inline double Dot(Vector3 v)
16 | {
17 | return x * v.x + y * v.y + z * v.z;
18 | }
19 | inline double Distance(Vector3 v)
20 | {
21 | return double(sqrtf(powf(v.x - x, 2.0) + powf(v.y - y, 2.0) + powf(v.z - z, 2.0)));
22 | }
23 | inline double Length()
24 | {
25 | return sqrt(x * x + y * y + z * z);
26 | }
27 | Vector3 operator+(Vector3 v)
28 | {
29 | return Vector3(x + v.x, y + v.y, z + v.z);
30 | }
31 | Vector3 operator-(Vector3 v)
32 | {
33 | return Vector3(x - v.x, y - v.y, z - v.z);
34 | }
35 | Vector3 operator*(double v)
36 | {
37 | return Vector3(x * v, y * v, z * v);
38 | }
39 | };
40 |
41 |
42 | struct FQuat
43 | {
44 | double x;
45 | double y;
46 | double z;
47 | double w;
48 | };
49 |
50 | struct FTransform
51 | {
52 | FQuat rot;
53 | Vector3 translation;
54 | Vector3 scale;
55 | D3DMATRIX ToMatrixWithScale()
56 | {
57 | D3DMATRIX m;
58 | m._41 = translation.x;
59 | m._42 = translation.y;
60 | m._43 = translation.z;
61 |
62 | float x2 = rot.x + rot.x;
63 | float y2 = rot.y + rot.y;
64 | float z2 = rot.z + rot.z;
65 |
66 | float xx2 = rot.x * x2;
67 | float yy2 = rot.y * y2;
68 | float zz2 = rot.z * z2;
69 | m._11 = (1.0f - (yy2 + zz2)) * scale.x;
70 | m._22 = (1.0f - (xx2 + zz2)) * scale.y;
71 | m._33 = (1.0f - (xx2 + yy2)) * scale.z;
72 |
73 | float yz2 = rot.y * z2;
74 | float wx2 = rot.w * x2;
75 | m._32 = (yz2 - wx2) * scale.z;
76 | m._23 = (yz2 + wx2) * scale.y;
77 |
78 | float xy2 = rot.x * y2;
79 | float wz2 = rot.w * z2;
80 | m._21 = (xy2 - wz2) * scale.y;
81 | m._12 = (xy2 + wz2) * scale.x;
82 |
83 | float xz2 = rot.x * z2;
84 | float wy2 = rot.w * y2;
85 | m._31 = (xz2 + wy2) * scale.z;
86 | m._13 = (xz2 - wy2) * scale.x;
87 |
88 | m._14 = 0.0f;
89 | m._24 = 0.0f;
90 | m._34 = 0.0f;
91 | m._44 = 1.0f;
92 |
93 | return m;
94 | }
95 | };
96 |
97 | D3DMATRIX MatrixMultiplication(D3DMATRIX pM1, D3DMATRIX pM2)
98 | {
99 | D3DMATRIX pOut;
100 | pOut._11 = pM1._11 * pM2._11 + pM1._12 * pM2._21 + pM1._13 * pM2._31 + pM1._14 * pM2._41;
101 | pOut._12 = pM1._11 * pM2._12 + pM1._12 * pM2._22 + pM1._13 * pM2._32 + pM1._14 * pM2._42;
102 | pOut._13 = pM1._11 * pM2._13 + pM1._12 * pM2._23 + pM1._13 * pM2._33 + pM1._14 * pM2._43;
103 | pOut._14 = pM1._11 * pM2._14 + pM1._12 * pM2._24 + pM1._13 * pM2._34 + pM1._14 * pM2._44;
104 | pOut._21 = pM1._21 * pM2._11 + pM1._22 * pM2._21 + pM1._23 * pM2._31 + pM1._24 * pM2._41;
105 | pOut._22 = pM1._21 * pM2._12 + pM1._22 * pM2._22 + pM1._23 * pM2._32 + pM1._24 * pM2._42;
106 | pOut._23 = pM1._21 * pM2._13 + pM1._22 * pM2._23 + pM1._23 * pM2._33 + pM1._24 * pM2._43;
107 | pOut._24 = pM1._21 * pM2._14 + pM1._22 * pM2._24 + pM1._23 * pM2._34 + pM1._24 * pM2._44;
108 | pOut._31 = pM1._31 * pM2._11 + pM1._32 * pM2._21 + pM1._33 * pM2._31 + pM1._34 * pM2._41;
109 | pOut._32 = pM1._31 * pM2._12 + pM1._32 * pM2._22 + pM1._33 * pM2._32 + pM1._34 * pM2._42;
110 | pOut._33 = pM1._31 * pM2._13 + pM1._32 * pM2._23 + pM1._33 * pM2._33 + pM1._34 * pM2._43;
111 | pOut._34 = pM1._31 * pM2._14 + pM1._32 * pM2._24 + pM1._33 * pM2._34 + pM1._34 * pM2._44;
112 | pOut._41 = pM1._41 * pM2._11 + pM1._42 * pM2._21 + pM1._43 * pM2._31 + pM1._44 * pM2._41;
113 | pOut._42 = pM1._41 * pM2._12 + pM1._42 * pM2._22 + pM1._43 * pM2._32 + pM1._44 * pM2._42;
114 | pOut._43 = pM1._41 * pM2._13 + pM1._42 * pM2._23 + pM1._43 * pM2._33 + pM1._44 * pM2._43;
115 | pOut._44 = pM1._41 * pM2._14 + pM1._42 * pM2._24 + pM1._43 * pM2._34 + pM1._44 * pM2._44;
116 |
117 | return pOut;
118 | }
119 |
120 | std::string string_To_UTF8(const std::string& str)
121 | {
122 | int nwLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
123 |
124 | wchar_t* pwBuf = new wchar_t[nwLen + 1];
125 | ZeroMemory(pwBuf, nwLen * 2 + 2);
126 |
127 | ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), pwBuf, nwLen);
128 |
129 | int nLen = ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, NULL, NULL, NULL);
130 |
131 | char* pBuf = new char[nLen + 1];
132 | ZeroMemory(pBuf, nLen + 1);
133 |
134 | ::WideCharToMultiByte(CP_UTF8, 0, pwBuf, nwLen, pBuf, nLen, NULL, NULL);
135 |
136 | std::string retStr(pBuf);
137 |
138 | delete[]pwBuf;
139 | delete[]pBuf;
140 |
141 | pwBuf = NULL;
142 | pBuf = NULL;
143 |
144 | return retStr;
145 | }
146 |
147 | typedef struct
148 | {
149 | DWORD R;
150 | DWORD G;
151 | DWORD B;
152 | DWORD A;
153 | }RGBA;
154 |
155 |
156 |
157 | struct Camera
158 | {
159 | float FieldOfView;
160 | Vector3 Rotation;
161 | Vector3 Location;
162 | };
163 |
164 |
165 |
166 | struct _MATRIX {
167 | union {
168 | struct {
169 | float _11, _12, _13, _14;
170 | float _21, _22, _23, _24;
171 | float _31, _32, _33, _34;
172 | float _41, _42, _43, _44;
173 | };
174 | float m[4][4];
175 | };
176 | };
177 |
178 | _MATRIX Matrix(Vector3 Vec4, Vector3 origin = Vector3(0, 0, 0))
179 | {
180 | double radPitch = (Vec4.x * double(PI) / 180.f);
181 | double radYaw = (Vec4.y * double(PI) / 180.f);
182 | double radRoll = (Vec4.z * double(PI) / 180.f);
183 | double SP = sinf(radPitch);
184 | double CP = cosf(radPitch);
185 | double SY = sinf(radYaw);
186 | double CY = cosf(radYaw);
187 | double SR = sinf(radRoll);
188 | double CR = cosf(radRoll);
189 | _MATRIX matrix;
190 | matrix.m[0][0] = CP * CY;
191 | matrix.m[0][1] = CP * SY;
192 | matrix.m[0][2] = SP;
193 | matrix.m[0][3] = 0.f;
194 | matrix.m[1][0] = SR * SP * CY - CR * SY;
195 | matrix.m[1][1] = SR * SP * SY + CR * CY;
196 | matrix.m[1][2] = -SR * CP;
197 | matrix.m[1][3] = 0.f;
198 | matrix.m[2][0] = -(CR * SP * CY + SR * SY);
199 | matrix.m[2][1] = CY * SR - CR * SP * SY;
200 | matrix.m[2][2] = CR * CP;
201 | matrix.m[2][3] = 0.f;
202 | matrix.m[3][0] = origin.x;
203 | matrix.m[3][1] = origin.y;
204 | matrix.m[3][2] = origin.z;
205 | matrix.m[3][3] = 1.f;
206 | return matrix;
207 | }
208 |
209 |
210 |
--------------------------------------------------------------------------------
/user_mode/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "communication.h"
6 | #include
7 | #include
8 | #include
9 | #include "math.h"
10 |
11 | uintptr_t test_ptr = 0x50;
12 | uint64_t base_address;
13 | DWORD_PTR Uworld;
14 | DWORD_PTR Rootcomp;
15 | DWORD_PTR Localplayer;
16 | DWORD_PTR PlayerController;
17 | DWORD_PTR LocalPawn;
18 | DWORD_PTR PlayerState;
19 | Vector3 localactorpos;
20 |
21 | float FOV = 120.0f;
22 |
23 | namespace APlayerCameraManager
24 | {
25 | DWORD DefaultFOV = 0x29c;
26 | };
27 |
28 | #define M_PI 3.14159265358979323846264338327950288419716939937510
29 | #define GWorld 0xEE5A148 // gworld is a pointer of uworld.
30 |
31 | DWORD GetProcessID(const std::wstring processName)
32 | {
33 | PROCESSENTRY32 processInfo;
34 | processInfo.dwSize = sizeof(processInfo);
35 |
36 | HANDLE processesSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
37 | if (processesSnapshot == INVALID_HANDLE_VALUE)
38 | {
39 | return 0;
40 | }
41 |
42 | Process32First(processesSnapshot, &processInfo);
43 | if (!processName.compare(processInfo.szExeFile))
44 | {
45 | CloseHandle(processesSnapshot);
46 | return processInfo.th32ProcessID;
47 | }
48 |
49 | while (Process32Next(processesSnapshot, &processInfo))
50 | {
51 | if (!processName.compare(processInfo.szExeFile))
52 | {
53 | CloseHandle(processesSnapshot);
54 | return processInfo.th32ProcessID;
55 | }
56 | }
57 |
58 | CloseHandle(processesSnapshot);
59 | return 0;
60 | }
61 |
62 | int pid3;
63 |
64 | namespace utils
65 | {
66 | auto getuworld(uintptr_t pointer) -> uintptr_t
67 | {
68 | uintptr_t uworld_addr = communication->read_physical_memory< uintptr_t >(pointer + 0x60);
69 |
70 | unsigned long long uworld_offset;
71 |
72 | if (uworld_addr > 0x10000000000)
73 | {
74 | uworld_offset = uworld_addr - 0x10000000000;
75 | }
76 | else {
77 | uworld_offset = uworld_addr - 0x8000000000;
78 | }
79 |
80 | return pointer + uworld_offset;
81 | }
82 |
83 |
84 | inline static bool isguarded(uintptr_t pointer) noexcept
85 | {
86 | static constexpr uintptr_t filter = 0xFFFFFFF000000000;
87 | uintptr_t result = pointer & filter;
88 | return result == 0x8000000000 || result == 0x10000000000;
89 | }
90 | }
91 |
92 | Vector3 GetBoneWithRotation(DWORD_PTR mesh, int id)
93 | {
94 | uintptr_t bone_array = communication->read_physical_memory(mesh + 0x5E8);
95 | int is_bone_array_cached = communication->read_physical_memory(mesh + 0x5F8);
96 | if (is_bone_array_cached) bone_array = communication->read_physical_memory(mesh + 0x5F8);
97 | FTransform bone = communication->read_physical_memory(bone_array + (id * 0x60));
98 | FTransform component_to_world = communication->read_physical_memory(mesh + 0x240);
99 | D3DMATRIX matrix = MatrixMultiplication(bone.ToMatrixWithScale(), component_to_world.ToMatrixWithScale());
100 | return Vector3(matrix._41, matrix._42, matrix._43);
101 | }
102 |
103 |
104 | Camera GetCamera(__int64 a1)
105 | {
106 | Camera LocalCamera;
107 | __int64 v1;
108 | v1 = communication->read_physical_memory<__int64>(Localplayer + 0xd0);
109 | __int64 v9 = communication->read_physical_memory<__int64>(v1 + 0x8); // 0x10
110 | LocalCamera.FieldOfView = 80.f / (communication->read_physical_memory(v9 + 0x7F0) / 1.19f); // 0x600
111 | LocalCamera.Rotation.x = communication->read_physical_memory(v9 + 0x9C0);
112 | LocalCamera.Rotation.y = communication->read_physical_memory(a1 + 0x148);
113 | uint64_t FGC_Pointerloc = communication->read_physical_memory(Uworld + 0x110);
114 | LocalCamera.Location = communication->read_physical_memory(FGC_Pointerloc);
115 | return LocalCamera;
116 | }
117 |
118 | Vector3 ProjectWorldToScreen(Vector3 WorldLocation)
119 | {
120 | Camera vCamera = GetCamera(Rootcomp);
121 | vCamera.Rotation.x = (asin(vCamera.Rotation.x)) * (180.0 / M_PI);
122 | //Rotation.x: 0.870931
123 | //Rotation.y: -88.0719
124 | //std::cout << "Rotation.x: " << vCamera.Rotation.x << std::endl;
125 | //std::cout << "Rotation.y: " << vCamera.Rotation.y << std::endl;
126 | _MATRIX tempMatrix = Matrix(vCamera.Rotation, Vector3(0, 0, 0));
127 | Vector3 vAxisX = Vector3(tempMatrix.m[0][0], tempMatrix.m[0][1], tempMatrix.m[0][2]);
128 | Vector3 vAxisY = Vector3(tempMatrix.m[1][0], tempMatrix.m[1][1], tempMatrix.m[1][2]);
129 | Vector3 vAxisZ = Vector3(tempMatrix.m[2][0], tempMatrix.m[2][1], tempMatrix.m[2][2]);
130 | Vector3 vDelta = WorldLocation - vCamera.Location;
131 | Vector3 vTransformed = Vector3(vDelta.Dot(vAxisY), vDelta.Dot(vAxisZ), vDelta.Dot(vAxisX));
132 | if (vTransformed.z < 1.f) vTransformed.z = 1.f;
133 | return Vector3((1920 / 2.0f) + vTransformed.x * (((1920 / 2.0f) / tanf(vCamera.FieldOfView * (float)M_PI / 360.f))) / vTransformed.z, (1080 / 2.0f) - vTransformed.y * (((1920 / 2.0f) / tanf(vCamera.FieldOfView * (float)M_PI / 360.f))) / vTransformed.z, 0);
134 | }
135 |
136 |
137 | auto cachethread() -> void
138 | {
139 | auto guardedregion = communication->guarded_region();
140 | printf("guardedregion: 0x%p\n", guardedregion);
141 |
142 | while (true)
143 | {
144 | auto uworld = utils::getuworld(guardedregion);
145 | printf("uworld: 0x%p\n", uworld);
146 |
147 | auto ulevel = communication->read_physical_memory< uintptr_t >(uworld + 0x38);
148 | printf("ulevel: 0x%p\n", ulevel);
149 |
150 | auto gamestate = communication->read_physical_memory< uintptr_t >(uworld + 0x140);
151 | printf("gamestate: 0x%p\n", gamestate);
152 |
153 | Sleep(2000);
154 | }
155 | }
156 |
157 | //void main(int argc, char* argv[])
158 | void main()
159 | {
160 | /*
161 | if (argc > 1)
162 | {
163 | if (!strcmp( argv[argc - 1], "--test" ))
164 | {
165 | if (!communication->initialize( ))
166 | {
167 | printf( "driver not loaded.\n" );
168 | Sleep( 3000 );
169 | return;
170 | }
171 | printf( "driver loaded.\n" );
172 | Sleep( 3000 );
173 | return;
174 | }
175 |
176 | printf( "Unknown arguments given:\n" );
177 | for (int i = 0; i < argc; i++)
178 | {
179 | printf( "arg[%i] = %s\n", i, argv[i] );
180 | }
181 | Sleep( 15000 );
182 | return;
183 | }
184 | */
185 | if (!communication->initialize())
186 | {
187 | printf("failed to initialize the driver.\n");
188 | std::cin.get();
189 | }
190 |
191 |
192 |
193 | pid3 = GetProcessID(L"notepad.exe");
194 |
195 | if (!communication->attach(pid3))
196 | {
197 | printf("failed to attatch to the process\n");
198 | std::cin.get();
199 | }
200 | std::thread(cachethread).detach();
201 |
202 |
203 | printf("finished operation\n");
204 | }
--------------------------------------------------------------------------------
/kernel_mode/entry.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "ia32.h"
10 | #include "definitions.h"
11 | #include "encrypt.h"
12 | #include "crt.h"
13 | #include "utils.h"
14 | #include "interface.h"
15 | #include "cache.h"
16 | #include "cleaning.h"
17 | #include "physical_internals.h"
18 | ULONG_PTR FnCR3;
19 |
20 |
21 | __int64 __fastcall cache::f_hook( void *a1 )
22 | {
23 | PKTHREAD_META thread = ((PKTHREAD_META)((uintptr_t)KeGetCurrentThread( )));
24 |
25 | //if (thread->ApcQueueable == 1 )
26 | // thread->ApcQueueable = 0;
27 |
28 | if ( !a1 || ExGetPreviousMode( ) != UserMode || reinterpret_cast< request_data * >( a1 )->unique != request_unique )
29 | {
30 | return cache::o_hook( a1 );
31 | }
32 |
33 | const auto request = reinterpret_cast< request_data * >( a1 );
34 |
35 | switch ( request->code )
36 | {
37 | case request_base:
38 | {
39 | base_request data { 0 };
40 |
41 | if ( !utils::safe_copy( &data, request->data, sizeof( base_request ) ) )
42 | {
43 | return 0;
44 | }
45 |
46 | if ( !data.pid )
47 | {
48 | return 0;
49 | }
50 |
51 | const auto base = utils::get_module_handle( data.pid, data.name );
52 |
53 | if ( !base )
54 | {
55 | return 0;
56 | }
57 |
58 | reinterpret_cast< base_request * > ( request->data )->handle = base;
59 |
60 | break;
61 | }
62 | case request_guardreg:
63 | {
64 | guardreg_request data{ 0 };
65 |
66 | const auto allocation = utils::find_guarded_region();
67 |
68 | reinterpret_cast (request->data)->allocation = allocation;
69 |
70 | break;
71 | }
72 | case request_cr3:
73 | {
74 | cr3_request data{ 0 };
75 |
76 | if (!utils::safe_copy(&data, request->data, sizeof(cr3_request)))
77 | {
78 | return 0;
79 | }
80 |
81 | if (!data.pid)
82 | {
83 | return 0;
84 | }
85 |
86 | PEPROCESS process = 0;
87 | if (!NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)data.pid, &process)))
88 | return 0;
89 |
90 |
91 | KeAttachProcess(process);
92 | FnCR3 = __readcr3();
93 | KeDetachProcess();
94 | break;
95 | }
96 | case request_write:
97 | {
98 | write_request data = { 0 };
99 |
100 | if (!utils::safe_copy(&data, request->data, sizeof(write_request)))
101 | {
102 | return 0;
103 | }
104 |
105 | if (!data.address || !data.pid || !data.buffer || !data.size)
106 | {
107 | return 0;
108 | }
109 |
110 | PEPROCESS process = nullptr;
111 | if (!NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)data.pid, &process)))
112 | {
113 | return 0;
114 | }
115 |
116 | const ULONG_PTR process_dirbase = internals::process_cr3(process);
117 | ObDereferenceObject(process);
118 |
119 | if (!process_dirbase)
120 | {
121 | return 0;
122 | }
123 |
124 | SIZE_T total_size = data.size;
125 | SIZE_T cur_offset = 0;
126 |
127 | while (total_size)
128 | {
129 | const uint64_t cur_phys_addr = internals::translate_linear_address(process_dirbase, (ULONG64)data.address + cur_offset);
130 | if (!cur_phys_addr)
131 | {
132 | return STATUS_UNSUCCESSFUL;
133 | }
134 |
135 | const ULONG64 write_size = min(PAGE_SIZE - (cur_phys_addr & 0xFFF), total_size);
136 | SIZE_T bytes_written = 0;
137 | const NTSTATUS out = internals::write_physical_address(cur_phys_addr, (PVOID)((ULONG64)data.buffer + cur_offset), write_size, &bytes_written);
138 |
139 | if (out != STATUS_SUCCESS || bytes_written == 0)
140 | {
141 | break;
142 | }
143 |
144 | total_size -= bytes_written;
145 | cur_offset += bytes_written;
146 | }
147 |
148 | break;
149 | }
150 |
151 |
152 | case request_process_base:
153 | {
154 | process_base_request data{ 0 };
155 |
156 | if (!utils::safe_copy( &data, request->data, sizeof( process_base_request ) ))
157 | {
158 | return 0;
159 | }
160 |
161 | if (!data.pid)
162 | {
163 | return 0;
164 | }
165 |
166 | PEPROCESS target_proc;
167 | if (!NT_SUCCESS( PsLookupProcessByProcessId( (HANDLE)data.pid, &target_proc ) ))
168 | return 0;
169 |
170 | uintptr_t base = (uintptr_t)PsGetProcessSectionBaseAddress( target_proc );
171 | if (!base)
172 | return 0;
173 |
174 | reinterpret_cast (request->data)->handle = base;
175 |
176 | ObDereferenceObject( target_proc );
177 | break;
178 | }
179 |
180 | case request_read:
181 | {
182 | read_request data = { 0 };
183 |
184 | if (!utils::safe_copy(&data, request->data, sizeof(read_request)))
185 | {
186 | return 0;
187 | }
188 |
189 | if (!data.address || !data.pid || !data.buffer || !data.size)
190 | {
191 | return 0;
192 | }
193 |
194 | PEPROCESS process = nullptr;
195 | if (!NT_SUCCESS(PsLookupProcessByProcessId((HANDLE)data.pid, &process)))
196 | {
197 | return 0;
198 | }
199 |
200 | const ULONG_PTR process_dirbase = FnCR3;
201 | ObDereferenceObject(process);
202 |
203 | if (!process_dirbase)
204 | {
205 | return 0;
206 | }
207 |
208 | SIZE_T total_size = data.size;
209 | SIZE_T cur_offset = 0;
210 |
211 | while (total_size)
212 | {
213 | const uint64_t cur_phys_addr = internals::translate_linear_address(process_dirbase, (ULONG64)data.address + cur_offset);
214 | if (!cur_phys_addr)
215 | {
216 | return STATUS_UNSUCCESSFUL;
217 | }
218 |
219 | const ULONG64 read_size = min(PAGE_SIZE - (cur_phys_addr & 0xFFF), total_size);
220 | SIZE_T bytes_read = 0;
221 | const NTSTATUS out = internals::read_physical_memory(cur_phys_addr, (PVOID)((ULONG64)data.buffer + cur_offset), read_size, &bytes_read);
222 |
223 | if (out != STATUS_SUCCESS || bytes_read == 0)
224 | {
225 | break;
226 | }
227 |
228 | total_size -= bytes_read;
229 | cur_offset += bytes_read;
230 | }
231 |
232 | break;
233 | }
234 | }
235 |
236 |
237 | return 0;
238 | }
239 |
240 |
241 | LPCSTR pattern = "";
242 | LPCSTR mask = "";
243 |
244 | NTSTATUS DriverEntry(PDRIVER_OBJECT, PUNICODE_STRING)
245 | {
246 | const auto win32k = utils::get_kernel_module(e("win32k.sys"));
247 | if (!win32k)
248 | return STATUS_ABANDONED;
249 |
250 | void* win32kpvoid = (void*)win32k;
251 | cache::qword_address = utils::find_pattern(win32kpvoid, e("\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x38\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x12\x4C\x8B\x54\x24\x00\x4C\x89\x54\x24\x00\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x38\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x28\x48\x8B\x05\x00\x00\x00\x00\x48\x85\xC0\x74\x08\xFF\x15\x00\x00\x00\x00\xEB\x05\xB8\x00\x00\x00\x00\x48\x83\xC4\x28\xC3\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\xCC\x48\x83\xEC\x38"), e("xxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxxxxx????xxxxxxxxx?xxxx?xx????xxx????xxxxxxxxxxxxxxxxxxxx????xxxxxxx????xxx????xxxxxxxxxxxxxxxxxxx"));
252 | if (!cache::qword_address)
253 | return STATUS_ABANDONED;
254 |
255 |
256 | *(void**)&cache::o_hook = InterlockedExchangePointer((void**)dereference(cache::qword_address), (void*)cache::f_hook);
257 |
258 | return STATUS_SUCCESS;
259 | }
--------------------------------------------------------------------------------
/user_mode/directx9/d3dx9shape.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | //
3 | // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 | //
5 | // File: d3dx9shapes.h
6 | // Content: D3DX simple shapes
7 | //
8 | ///////////////////////////////////////////////////////////////////////////
9 |
10 | #include "d3dx9.h"
11 |
12 | #ifndef __D3DX9SHAPES_H__
13 | #define __D3DX9SHAPES_H__
14 |
15 | ///////////////////////////////////////////////////////////////////////////
16 | // Functions:
17 | ///////////////////////////////////////////////////////////////////////////
18 |
19 | #ifdef __cplusplus
20 | extern "C" {
21 | #endif //__cplusplus
22 |
23 |
24 | //-------------------------------------------------------------------------
25 | // D3DXCreatePolygon:
26 | // ------------------
27 | // Creates a mesh containing an n-sided polygon. The polygon is centered
28 | // at the origin.
29 | //
30 | // Parameters:
31 | //
32 | // pDevice The D3D device with which the mesh is going to be used.
33 | // Length Length of each side.
34 | // Sides Number of sides the polygon has. (Must be >= 3)
35 | // ppMesh The mesh object which will be created
36 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
37 | //-------------------------------------------------------------------------
38 | HRESULT WINAPI
39 | D3DXCreatePolygon(
40 | LPDIRECT3DDEVICE9 pDevice,
41 | FLOAT Length,
42 | UINT Sides,
43 | LPD3DXMESH* ppMesh,
44 | LPD3DXBUFFER* ppAdjacency);
45 |
46 |
47 | //-------------------------------------------------------------------------
48 | // D3DXCreateBox:
49 | // --------------
50 | // Creates a mesh containing an axis-aligned box. The box is centered at
51 | // the origin.
52 | //
53 | // Parameters:
54 | //
55 | // pDevice The D3D device with which the mesh is going to be used.
56 | // Width Width of box (along X-axis)
57 | // Height Height of box (along Y-axis)
58 | // Depth Depth of box (along Z-axis)
59 | // ppMesh The mesh object which will be created
60 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
61 | //-------------------------------------------------------------------------
62 | HRESULT WINAPI
63 | D3DXCreateBox(
64 | LPDIRECT3DDEVICE9 pDevice,
65 | FLOAT Width,
66 | FLOAT Height,
67 | FLOAT Depth,
68 | LPD3DXMESH* ppMesh,
69 | LPD3DXBUFFER* ppAdjacency);
70 |
71 |
72 | //-------------------------------------------------------------------------
73 | // D3DXCreateCylinder:
74 | // -------------------
75 | // Creates a mesh containing a cylinder. The generated cylinder is
76 | // centered at the origin, and its axis is aligned with the Z-axis.
77 | //
78 | // Parameters:
79 | //
80 | // pDevice The D3D device with which the mesh is going to be used.
81 | // Radius1 Radius at -Z end (should be >= 0.0f)
82 | // Radius2 Radius at +Z end (should be >= 0.0f)
83 | // Length Length of cylinder (along Z-axis)
84 | // Slices Number of slices about the main axis
85 | // Stacks Number of stacks along the main axis
86 | // ppMesh The mesh object which will be created
87 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
88 | //-------------------------------------------------------------------------
89 | HRESULT WINAPI
90 | D3DXCreateCylinder(
91 | LPDIRECT3DDEVICE9 pDevice,
92 | FLOAT Radius1,
93 | FLOAT Radius2,
94 | FLOAT Length,
95 | UINT Slices,
96 | UINT Stacks,
97 | LPD3DXMESH* ppMesh,
98 | LPD3DXBUFFER* ppAdjacency);
99 |
100 |
101 | //-------------------------------------------------------------------------
102 | // D3DXCreateSphere:
103 | // -----------------
104 | // Creates a mesh containing a sphere. The sphere is centered at the
105 | // origin.
106 | //
107 | // Parameters:
108 | //
109 | // pDevice The D3D device with which the mesh is going to be used.
110 | // Radius Radius of the sphere (should be >= 0.0f)
111 | // Slices Number of slices about the main axis
112 | // Stacks Number of stacks along the main axis
113 | // ppMesh The mesh object which will be created
114 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
115 | //-------------------------------------------------------------------------
116 | HRESULT WINAPI
117 | D3DXCreateSphere(
118 | LPDIRECT3DDEVICE9 pDevice,
119 | FLOAT Radius,
120 | UINT Slices,
121 | UINT Stacks,
122 | LPD3DXMESH* ppMesh,
123 | LPD3DXBUFFER* ppAdjacency);
124 |
125 |
126 | //-------------------------------------------------------------------------
127 | // D3DXCreateTorus:
128 | // ----------------
129 | // Creates a mesh containing a torus. The generated torus is centered at
130 | // the origin, and its axis is aligned with the Z-axis.
131 | //
132 | // Parameters:
133 | //
134 | // pDevice The D3D device with which the mesh is going to be used.
135 | // InnerRadius Inner radius of the torus (should be >= 0.0f)
136 | // OuterRadius Outer radius of the torue (should be >= 0.0f)
137 | // Sides Number of sides in a cross-section (must be >= 3)
138 | // Rings Number of rings making up the torus (must be >= 3)
139 | // ppMesh The mesh object which will be created
140 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
141 | //-------------------------------------------------------------------------
142 | HRESULT WINAPI
143 | D3DXCreateTorus(
144 | LPDIRECT3DDEVICE9 pDevice,
145 | FLOAT InnerRadius,
146 | FLOAT OuterRadius,
147 | UINT Sides,
148 | UINT Rings,
149 | LPD3DXMESH* ppMesh,
150 | LPD3DXBUFFER* ppAdjacency);
151 |
152 |
153 | //-------------------------------------------------------------------------
154 | // D3DXCreateTeapot:
155 | // -----------------
156 | // Creates a mesh containing a teapot.
157 | //
158 | // Parameters:
159 | //
160 | // pDevice The D3D device with which the mesh is going to be used.
161 | // ppMesh The mesh object which will be created
162 | // ppAdjacency Returns a buffer containing adjacency info. Can be NULL.
163 | //-------------------------------------------------------------------------
164 | HRESULT WINAPI
165 | D3DXCreateTeapot(
166 | LPDIRECT3DDEVICE9 pDevice,
167 | LPD3DXMESH* ppMesh,
168 | LPD3DXBUFFER* ppAdjacency);
169 |
170 |
171 | //-------------------------------------------------------------------------
172 | // D3DXCreateText:
173 | // ---------------
174 | // Creates a mesh containing the specified text using the font associated
175 | // with the device context.
176 | //
177 | // Parameters:
178 | //
179 | // pDevice The D3D device with which the mesh is going to be used.
180 | // hDC Device context, with desired font selected
181 | // pText Text to generate
182 | // Deviation Maximum chordal deviation from true font outlines
183 | // Extrusion Amount to extrude text in -Z direction
184 | // ppMesh The mesh object which will be created
185 | // pGlyphMetrics Address of buffer to receive glyph metric data (or NULL)
186 | //-------------------------------------------------------------------------
187 | HRESULT WINAPI
188 | D3DXCreateTextA(
189 | LPDIRECT3DDEVICE9 pDevice,
190 | HDC hDC,
191 | LPCSTR pText,
192 | FLOAT Deviation,
193 | FLOAT Extrusion,
194 | LPD3DXMESH* ppMesh,
195 | LPD3DXBUFFER* ppAdjacency,
196 | LPGLYPHMETRICSFLOAT pGlyphMetrics);
197 |
198 | HRESULT WINAPI
199 | D3DXCreateTextW(
200 | LPDIRECT3DDEVICE9 pDevice,
201 | HDC hDC,
202 | LPCWSTR pText,
203 | FLOAT Deviation,
204 | FLOAT Extrusion,
205 | LPD3DXMESH* ppMesh,
206 | LPD3DXBUFFER* ppAdjacency,
207 | LPGLYPHMETRICSFLOAT pGlyphMetrics);
208 |
209 | #ifdef UNICODE
210 | #define D3DXCreateText D3DXCreateTextW
211 | #else
212 | #define D3DXCreateText D3DXCreateTextA
213 | #endif
214 |
215 |
216 | #ifdef __cplusplus
217 | }
218 | #endif //__cplusplus
219 |
220 | #endif //__D3DX9SHAPES_H__
221 |
--------------------------------------------------------------------------------
/user_mode/user_mode.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 | 16.0
23 | Win32Proj
24 | {408b9e7f-a20f-49bc-af1d-4d1365eeeed6}
25 | usermode
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v142
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | $(SolutionDir)builds\
75 | $(SolutionDir)builds\.logs\
76 | $(ProjectName)_x64
77 |
78 |
79 |
80 | Level3
81 | true
82 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
83 | true
84 |
85 |
86 | Console
87 | true
88 |
89 |
90 |
91 |
92 | Level3
93 | true
94 | true
95 | true
96 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
97 | true
98 |
99 |
100 | Console
101 | true
102 | true
103 | true
104 |
105 |
106 |
107 |
108 | Level3
109 | true
110 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
111 | true
112 |
113 |
114 | Console
115 | true
116 |
117 |
118 |
119 |
120 | Level3
121 | true
122 | true
123 | true
124 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
125 | true
126 |
127 |
128 | Console
129 | true
130 | true
131 | true
132 | d3d9.lib;%(AdditionalDependencies)
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
--------------------------------------------------------------------------------
/kernel_mode/km.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 | 16.0
23 | Win32Proj
24 | {4c4c54e5-c199-4146-b5d7-fddc9fe74066}
25 | km
26 | kernel_mode
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Driver
50 | false
51 | WindowsKernelModeDriver10.0
52 | true
53 | MultiByte
54 | Windows10
55 | Universal
56 | KMDF
57 | 1
58 | false
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | true
80 |
81 |
82 | false
83 |
84 |
85 | true
86 |
87 |
88 | false
89 | $(SolutionDir)builds\
90 | $(SolutionDir)builds\.logs\
91 | $(ProjectName)_x64
92 | false
93 |
94 |
95 |
96 | Level3
97 | true
98 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
99 | true
100 |
101 |
102 | Console
103 | true
104 |
105 |
106 |
107 |
108 | Level3
109 | true
110 | true
111 | true
112 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
113 | true
114 |
115 |
116 | Console
117 | true
118 | true
119 | true
120 |
121 |
122 |
123 |
124 | Level3
125 | true
126 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
127 | true
128 |
129 |
130 | Console
131 | true
132 |
133 |
134 |
135 |
136 | TurnOffAllWarnings
137 | false
138 | true
139 | false
140 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
141 | false
142 | stdcpp20
143 | stdc17
144 | MaxSpeed
145 | AnySuitable
146 | true
147 | true
148 | Size
149 | true
150 | None
151 | true
152 | false
153 | false
154 | true
155 |
156 |
157 | Native
158 | true
159 | true
160 | false
161 | false
162 | $(SUBSYSTEM_NATVER)
163 | Driver
164 | DriverEntry
165 |
166 |
167 | true
168 | %(AdditionalDependencies)
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/user_mode/Imgui/imconfig.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI
3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
5 | //-----------------------------------------------------------------------------
6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
8 | //-----------------------------------------------------------------------------
9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
13 | //-----------------------------------------------------------------------------
14 |
15 | #pragma once
16 |
17 | //---- Define assertion handler. Defaults to calling assert().
18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
21 |
22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
26 | //#define IMGUI_API __declspec( dllexport )
27 | //#define IMGUI_API __declspec( dllimport )
28 |
29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
32 |
33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools.
34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
38 |
39 | //---- Don't implement some functions to reduce linkage requirements.
40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
51 |
52 | //---- Include imgui_user.h at the end of imgui.h as a convenience
53 | //#define IMGUI_INCLUDE_IMGUI_USER_H
54 |
55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
56 | //#define IMGUI_USE_BGRA_PACKED_COLOR
57 |
58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
59 | //#define IMGUI_USE_WCHAR32
60 |
61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled
66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
68 |
69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
70 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
71 | //#define IMGUI_USE_STB_SPRINTF
72 |
73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
74 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
76 | //#define IMGUI_ENABLE_FREETYPE
77 |
78 | //---- Use stb_truetype to build and rasterize the font atlas (default)
79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
80 | //#define IMGUI_ENABLE_STB_TRUETYPE
81 |
82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations.
84 | /*
85 | #define IM_VEC2_CLASS_EXTRA \
86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
87 | operator MyVec2() const { return MyVec2(x,y); }
88 |
89 | #define IM_VEC4_CLASS_EXTRA \
90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
91 | operator MyVec4() const { return MyVec4(x,y,z,w); }
92 | */
93 |
94 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
95 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
96 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
97 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
98 | //#define ImDrawIdx unsigned int
99 |
100 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
101 | //struct ImDrawList;
102 | //struct ImDrawCmd;
103 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
104 | //#define ImDrawCallback MyImDrawCallback
105 |
106 | //---- Debug Tools: Macro to break in Debugger
107 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
108 | //#define IM_DEBUG_BREAK IM_ASSERT(0)
109 | //#define IM_DEBUG_BREAK __debugbreak()
110 |
111 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(),
112 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.)
113 | // This adds a small runtime cost which is why it is not enabled by default.
114 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX
115 |
116 | //---- Debug Tools: Enable slower asserts
117 | //#define IMGUI_DEBUG_PARANOID
118 |
119 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
120 | /*
121 | namespace ImGui
122 | {
123 | void MyFunction(const char* name, const MyMatrix44& v);
124 | }
125 | */
126 |
--------------------------------------------------------------------------------
/kernel_mode/definitions.h:
--------------------------------------------------------------------------------
1 | #define PFN_TO_PAGE(pfn) ( pfn << 12 )
2 | #define dereference(ptr) (const uintptr_t)(ptr + *( int * )( ( BYTE * )ptr + 3 ) + 7)
3 | #define in_range(x,a,b) (x >= a && x <= b)
4 | #define get_bits( x ) (in_range((x&(~0x20)),'A','F') ? ((x&(~0x20)) - 'A' + 0xA) : (in_range(x,'0','9') ? x - '0' : 0))
5 | #define get_byte( x ) (get_bits(x[0]) << 4 | get_bits(x[1]))
6 | #define size_align(Size) ((Size + 0xFFF) & 0xFFFFFFFFFFFFF000)
7 | #define to_lower_i(Char) ((Char >= 'A' && Char <= 'Z') ? (Char + 32) : Char)
8 | #define to_lower_c(Char) ((Char >= (char*)'A' && Char <= (char*)'Z') ? (Char + 32) : Char)
9 |
10 | typedef unsigned int uint32_t;
11 |
12 | typedef struct _RTL_PROCESS_MODULE_INFORMATION
13 | {
14 | HANDLE Section;
15 | PVOID MappedBase;
16 | PVOID ImageBase;
17 | ULONG ImageSize;
18 | ULONG Flags;
19 | USHORT LoadOrderIndex;
20 | USHORT InitOrderIndex;
21 | USHORT LoadCount;
22 | USHORT OffsetToFileName;
23 | UCHAR FullPathName[256];
24 | } RTL_PROCESS_MODULE_INFORMATION, *PRTL_PROCESS_MODULE_INFORMATION;
25 |
26 | typedef struct _RTL_PROCESS_MODULES
27 | {
28 | ULONG NumberOfModules;
29 | RTL_PROCESS_MODULE_INFORMATION Modules[1];
30 | } RTL_PROCESS_MODULES, *PRTL_PROCESS_MODULES;
31 |
32 | typedef struct _LDR_DATA_TABLE_ENTRY
33 | {
34 | LIST_ENTRY InLoadOrderLinks;
35 | LIST_ENTRY InMemoryOrderLinks;
36 | LIST_ENTRY InInitializationOrderLinks;
37 | PVOID DllBase;
38 | PVOID EntryPoint;
39 | ULONG SizeOfImage;
40 | UNICODE_STRING FullDllName;
41 | UNICODE_STRING BaseDllName;
42 | ULONG Flags;
43 | WORD LoadCount;
44 | WORD TlsIndex;
45 | union
46 | {
47 | LIST_ENTRY HashLinks;
48 | struct
49 | {
50 | PVOID SectionPointer;
51 | ULONG CheckSum;
52 | };
53 | };
54 | union
55 | {
56 | ULONG TimeDateStamp;
57 | PVOID LoadedImports;
58 | };
59 | VOID *EntryPointActivationContext;
60 | PVOID PatchInformation;
61 | LIST_ENTRY ForwarderLinks;
62 | LIST_ENTRY ServiceTagLinks;
63 | LIST_ENTRY StaticLinks;
64 | } LDR_DATA_TABLE_ENTRY, *PLDR_DATA_TABLE_ENTRY;
65 |
66 | typedef struct _SYSTEM_BIGPOOL_ENTRY
67 | {
68 | union {
69 | PVOID VirtualAddress;
70 | ULONG_PTR NonPaged : 1;
71 | };
72 | ULONG_PTR SizeInBytes;
73 | union {
74 | UCHAR Tag[4];
75 | ULONG TagUlong;
76 | };
77 | } SYSTEM_BIGPOOL_ENTRY, * PSYSTEM_BIGPOOL_ENTRY;
78 |
79 |
80 | typedef struct _SYSTEM_BIGPOOL_INFORMATION {
81 | ULONG Count;
82 | SYSTEM_BIGPOOL_ENTRY AllocatedInfo[ANYSIZE_ARRAY];
83 | } SYSTEM_BIGPOOL_INFORMATION, * PSYSTEM_BIGPOOL_INFORMATION;
84 |
85 | typedef struct _RTL_CRITICAL_SECTION
86 | {
87 | VOID *DebugInfo;
88 | LONG LockCount;
89 | LONG RecursionCount;
90 | PVOID OwningThread;
91 | PVOID LockSemaphore;
92 | ULONG SpinCount;
93 | } RTL_CRITICAL_SECTION, *PRTL_CRITICAL_SECTION;
94 |
95 | typedef struct _PEB_LDR_DATA
96 | {
97 | ULONG Length;
98 | UCHAR Initialized;
99 | PVOID SsHandle;
100 | LIST_ENTRY InLoadOrderModuleList;
101 | LIST_ENTRY InMemoryOrderModuleList;
102 | LIST_ENTRY InInitializationOrderModuleList;
103 | PVOID EntryInProgress;
104 | } PEB_LDR_DATA, *PPEB_LDR_DATA;
105 |
106 | typedef struct _PEB
107 | {
108 | UCHAR InheritedAddressSpace;
109 | UCHAR ReadImageFileExecOptions;
110 | UCHAR BeingDebugged;
111 | UCHAR BitField;
112 | ULONG ImageUsesLargePages : 1;
113 | ULONG IsProtectedProcess : 1;
114 | ULONG IsLegacyProcess : 1;
115 | ULONG IsImageDynamicallyRelocated : 1;
116 | ULONG SpareBits : 4;
117 | PVOID Mutant;
118 | PVOID ImageBaseAddress;
119 | PPEB_LDR_DATA Ldr;
120 | VOID *ProcessParameters;
121 | PVOID SubSystemData;
122 | PVOID ProcessHeap;
123 | PRTL_CRITICAL_SECTION FastPebLock;
124 | PVOID AtlThunkSListPtr;
125 | PVOID IFEOKey;
126 | ULONG CrossProcessFlags;
127 | ULONG ProcessInJob : 1;
128 | ULONG ProcessInitializing : 1;
129 | ULONG ReservedBits0 : 30;
130 | union
131 | {
132 | PVOID KernelCallbackTable;
133 | PVOID UserSharedInfoPtr;
134 | };
135 | ULONG SystemReserved[1];
136 | ULONG SpareUlong;
137 | VOID *FreeList;
138 | ULONG TlsExpansionCounter;
139 | PVOID TlsBitmap;
140 | ULONG TlsBitmapBits[2];
141 | PVOID ReadOnlySharedMemoryBase;
142 | PVOID HotpatchInformation;
143 | VOID **ReadOnlyStaticServerData;
144 | PVOID AnsiCodePageData;
145 | PVOID OemCodePageData;
146 | PVOID UnicodeCaseTableData;
147 | ULONG NumberOfProcessors;
148 | ULONG NtGlobalFlag;
149 | LARGE_INTEGER CriticalSectionTimeout;
150 | ULONG HeapSegmentReserve;
151 | ULONG HeapSegmentCommit;
152 | ULONG HeapDeCommitTotalFreeThreshold;
153 | ULONG HeapDeCommitFreeBlockThreshold;
154 | ULONG NumberOfHeaps;
155 | ULONG MaximumNumberOfHeaps;
156 | VOID **ProcessHeaps;
157 | PVOID GdiSharedHandleTable;
158 | PVOID ProcessStarterHelper;
159 | ULONG GdiDCAttributeList;
160 | PRTL_CRITICAL_SECTION LoaderLock;
161 | ULONG OSMajorVersion;
162 | ULONG OSMinorVersion;
163 | WORD OSBuildNumber;
164 | WORD OSCSDVersion;
165 | ULONG OSPlatformId;
166 | ULONG ImageSubsystem;
167 | ULONG ImageSubsystemMajorVersion;
168 | ULONG ImageSubsystemMinorVersion;
169 | ULONG ImageProcessAffinityMask;
170 | ULONG GdiHandleBuffer[34];
171 | PVOID PostProcessInitRoutine;
172 | PVOID TlsExpansionBitmap;
173 | ULONG TlsExpansionBitmapBits[32];
174 | ULONG SessionId;
175 | ULARGE_INTEGER AppCompatFlags;
176 | ULARGE_INTEGER AppCompatFlagsUser;
177 | PVOID pShimData;
178 | PVOID AppCompatInfo;
179 | UNICODE_STRING CSDVersion;
180 | VOID *ActivationContextData;
181 | VOID *ProcessAssemblyStorageMap;
182 | VOID *SystemDefaultActivationContextData;
183 | VOID *SystemAssemblyStorageMap;
184 | ULONG MinimumStackCommit;
185 | VOID *FlsCallback;
186 | LIST_ENTRY FlsListHead;
187 | PVOID FlsBitmap;
188 | ULONG FlsBitmapBits[4];
189 | ULONG FlsHighIndex;
190 | PVOID WerRegistrationData;
191 | PVOID WerShipAssertPtr;
192 | } PEB, *PPEB;
193 |
194 | typedef enum _SYSTEM_INFORMATION_CLASS
195 | {
196 | SystemBasicInformation,
197 | SystemProcessorInformation,
198 | SystemPerformanceInformation,
199 | SystemTimeOfDayInformation,
200 | SystemPathInformation,
201 | SystemProcessInformation,
202 | SystemCallCountInformation,
203 | SystemDeviceInformation,
204 | SystemProcessorPerformanceInformation,
205 | SystemFlagsInformation,
206 | SystemCallTimeInformation,
207 | SystemModuleInformation,
208 | SystemLocksInformation,
209 | SystemStackTraceInformation,
210 | SystemPagedPoolInformation,
211 | SystemNonPagedPoolInformation,
212 | SystemHandleInformation,
213 | SystemObjectInformation,
214 | SystemPageFileInformation,
215 | SystemVdmInstemulInformation,
216 | SystemVdmBopInformation,
217 | SystemFileCacheInformation,
218 | SystemPoolTagInformation,
219 | SystemInterruptInformation,
220 | SystemDpcBehaviorInformation,
221 | SystemFullMemoryInformation,
222 | SystemLoadGdiDriverInformation,
223 | SystemUnloadGdiDriverInformation,
224 | SystemTimeAdjustmentInformation,
225 | SystemSummaryMemoryInformation,
226 | SystemNextEventIdInformation,
227 | SystemEventIdsInformation,
228 | SystemCrashDumpInformation,
229 | SystemExceptionInformation,
230 | SystemCrashDumpStateInformation,
231 | SystemKernelDebuggerInformation,
232 | SystemContextSwitchInformation,
233 | SystemRegistryQuotaInformation,
234 | SystemExtendServiceTableInformation,
235 | SystemPrioritySeperation,
236 | SystemPlugPlayBusInformation,
237 | SystemDockInformation,
238 | SystemProcessorSpeedInformation,
239 | SystemCurrentTimeZoneInformation,
240 | SystemLookasideInformation,
241 | system_bigpool_information = 0x42
242 | } SYSTEM_INFORMATION_CLASS, *PSYSTEM_INFORMATION_CLASS;
243 |
244 | typedef struct _PAGE_INFORMATION
245 | {
246 | PML4E_64 *PML4E;
247 | PDPTE_64 *PDPTE;
248 | PDE_64 *PDE;
249 | PTE_64 *PTE;
250 | }PAGE_INFORMATION, *PPAGE_INFORMATION;
251 |
252 | typedef struct _MDL_INFORMATION
253 | {
254 | MDL *mdl;
255 | uintptr_t va;
256 | }MDL_INFORMATION, *PMDL_INFORMATION;
257 |
258 | typedef union _VIRTUAL_ADDRESS
259 | {
260 | PVOID value;
261 | struct
262 | {
263 | ULONG64 offset : 12;
264 | ULONG64 pt_index : 9;
265 | ULONG64 pd_index : 9;
266 | ULONG64 pdpt_index : 9;
267 | ULONG64 pml4_index : 9;
268 | ULONG64 reserved : 16;
269 | };
270 | } VIRTUAL_ADDRESS, *PVIRTUAL_ADDRESS;
271 |
272 | extern "C"
273 | {
274 | NTKERNELAPI NTSTATUS NTAPI ZwQuerySystemInformation(
275 | _In_ SYSTEM_INFORMATION_CLASS SystemInformationClass,
276 | _Inout_ PVOID SystemInformation,
277 | _In_ ULONG SystemInformationLength,
278 | _Out_opt_ PULONG ReturnLength
279 | );
280 |
281 | NTSTATUS NTAPI MmCopyVirtualMemory(
282 | PEPROCESS SourceProcess,
283 | PVOID SourceAddress,
284 | PEPROCESS TargetProcess,
285 | PVOID TargetAddress,
286 | SIZE_T BufferSize,
287 | KPROCESSOR_MODE PreviousMode,
288 | PSIZE_T ReturnSize
289 | );
290 |
291 | NTSTATUS ZwAllocateVirtualMemory(
292 | _In_ HANDLE ProcessHandle,
293 | _Inout_ PVOID *BaseAddress,
294 | _In_ ULONG_PTR ZeroBits,
295 | _Inout_ PSIZE_T RegionSize,
296 | _In_ ULONG AllocationType,
297 | _In_ ULONG Protect
298 | );
299 |
300 | NTKERNELAPI
301 | PPEB
302 | PsGetProcessPeb(
303 | IN PEPROCESS Process
304 | );
305 |
306 | NTKERNELAPI
307 | PVOID NTAPI RtlFindExportedRoutineByName(
308 | _In_ PVOID ImageBase,
309 | _In_ PCCH RoutineName
310 | );
311 |
312 | NTKERNELAPI
313 | PVOID
314 | PsGetProcessSectionBaseAddress(
315 | __in PEPROCESS Process
316 | );
317 | }
318 |
319 | typedef union _KWAIT_STATUS_REGISTER
320 | {
321 | union
322 | {
323 | /* 0x0000 */ unsigned char Flags;
324 | struct /* bitfield */
325 | {
326 | /* 0x0000 */ unsigned char State : 3; /* bit position: 0 */
327 | /* 0x0000 */ unsigned char Affinity : 1; /* bit position: 3 */
328 | /* 0x0000 */ unsigned char Priority : 1; /* bit position: 4 */
329 | /* 0x0000 */ unsigned char Apc : 1; /* bit position: 5 */
330 | /* 0x0000 */ unsigned char UserApc : 1; /* bit position: 6 */
331 | /* 0x0000 */ unsigned char Alert : 1; /* bit position: 7 */
332 | }; /* bitfield */
333 | }; /* size: 0x0001 */
334 | } KWAIT_STATUS_REGISTER, * PKWAIT_STATUS_REGISTER; /* size: 0x0001 */
335 |
336 | typedef struct _KTHREAD_META
337 | {
338 | /* 0x0000 */ struct _DISPATCHER_HEADER Header;
339 | /* 0x0018 */ void* SListFaultAddress;
340 | /* 0x0020 */ unsigned __int64 QuantumTarget;
341 | /* 0x0028 */ void* InitialStack;
342 | /* 0x0030 */ void* volatile StackLimit;
343 | /* 0x0038 */ void* StackBase;
344 | /* 0x0040 */ unsigned __int64 ThreadLock;
345 | /* 0x0048 */ volatile unsigned __int64 CycleTime;
346 | /* 0x0050 */ unsigned long CurrentRunTime;
347 | /* 0x0054 */ unsigned long ExpectedRunTime;
348 | /* 0x0058 */ void* KernelStack;
349 | /* 0x0060 */ struct _XSAVE_FORMAT* StateSaveArea;
350 | /* 0x0068 */ struct _KSCHEDULING_GROUP* volatile SchedulingGroup;
351 | /* 0x0070 */ union _KWAIT_STATUS_REGISTER WaitRegister;
352 | /* 0x0071 */ volatile unsigned char Running;
353 | /* 0x0072 */ unsigned char Alerted[2];
354 | union
355 | {
356 | struct /* bitfield */
357 | {
358 | /* 0x0074 */ unsigned long AutoBoostActive : 1; /* bit position: 0 */
359 | /* 0x0074 */ unsigned long ReadyTransition : 1; /* bit position: 1 */
360 | /* 0x0074 */ unsigned long WaitNext : 1; /* bit position: 2 */
361 | /* 0x0074 */ unsigned long SystemAffinityActive : 1; /* bit position: 3 */
362 | /* 0x0074 */ unsigned long Alertable : 1; /* bit position: 4 */
363 | /* 0x0074 */ unsigned long UserStackWalkActive : 1; /* bit position: 5 */
364 | /* 0x0074 */ unsigned long ApcInterruptRequest : 1; /* bit position: 6 */
365 | /* 0x0074 */ unsigned long QuantumEndMigrate : 1; /* bit position: 7 */
366 | /* 0x0074 */ unsigned long UmsDirectedSwitchEnable : 1; /* bit position: 8 */
367 | /* 0x0074 */ unsigned long TimerActive : 1; /* bit position: 9 */
368 | /* 0x0074 */ unsigned long SystemThread : 1; /* bit position: 10 */
369 | /* 0x0074 */ unsigned long ProcessDetachActive : 1; /* bit position: 11 */
370 | /* 0x0074 */ unsigned long CalloutActive : 1; /* bit position: 12 */
371 | /* 0x0074 */ unsigned long ScbReadyQueue : 1; /* bit position: 13 */
372 | /* 0x0074 */ unsigned long ApcQueueable : 1; /* bit position: 14 */
373 | /* 0x0074 */ unsigned long ReservedStackInUse : 1; /* bit position: 15 */
374 | /* 0x0074 */ unsigned long UmsPerformingSyscall : 1; /* bit position: 16 */
375 | /* 0x0074 */ unsigned long TimerSuspended : 1; /* bit position: 17 */
376 | /* 0x0074 */ unsigned long SuspendedWaitMode : 1; /* bit position: 18 */
377 | /* 0x0074 */ unsigned long SuspendSchedulerApcWait : 1; /* bit position: 19 */
378 | /* 0x0074 */ unsigned long CetUserShadowStack : 1; /* bit position: 20 */
379 | /* 0x0074 */ unsigned long BypassProcessFreeze : 1; /* bit position: 21 */
380 | /* 0x0074 */ unsigned long CetKernelShadowStack : 1; /* bit position: 22 */
381 | /* 0x0074 */ unsigned long Reserved : 9; /* bit position: 23 */
382 | }; /* bitfield */
383 | /* 0x0074 */ long MiscFlags;
384 | }; /* size: 0x0004 */
385 | } KTHREAD_META, * PKTHREAD_META; /* size: 0x0430 */
--------------------------------------------------------------------------------
/user_mode/directx9/d3dx9xof.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | //
3 | // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 | //
5 | // File: d3dx9xof.h
6 | // Content: D3DX .X File types and functions
7 | //
8 | ///////////////////////////////////////////////////////////////////////////
9 |
10 | #include "d3dx9.h"
11 |
12 | #if !defined( __D3DX9XOF_H__ )
13 | #define __D3DX9XOF_H__
14 |
15 | #if defined( __cplusplus )
16 | extern "C" {
17 | #endif // defined( __cplusplus )
18 |
19 | //----------------------------------------------------------------------------
20 | // D3DXF_FILEFORMAT
21 | // This flag is used to specify what file type to use when saving to disk.
22 | // _BINARY, and _TEXT are mutually exclusive, while
23 | // _COMPRESSED is an optional setting that works with all file types.
24 | //----------------------------------------------------------------------------
25 | typedef DWORD D3DXF_FILEFORMAT;
26 |
27 | #define D3DXF_FILEFORMAT_BINARY 0
28 | #define D3DXF_FILEFORMAT_TEXT 1
29 | #define D3DXF_FILEFORMAT_COMPRESSED 2
30 |
31 | //----------------------------------------------------------------------------
32 | // D3DXF_FILESAVEOPTIONS
33 | // This flag is used to specify where to save the file to. Each flag is
34 | // mutually exclusive, indicates the data location of the file, and also
35 | // chooses which additional data will specify the location.
36 | // _TOFILE is paired with a filename (LPCSTR)
37 | // _TOWFILE is paired with a filename (LPWSTR)
38 | //----------------------------------------------------------------------------
39 | typedef DWORD D3DXF_FILESAVEOPTIONS;
40 |
41 | #define D3DXF_FILESAVE_TOFILE 0x00L
42 | #define D3DXF_FILESAVE_TOWFILE 0x01L
43 |
44 | //----------------------------------------------------------------------------
45 | // D3DXF_FILELOADOPTIONS
46 | // This flag is used to specify where to load the file from. Each flag is
47 | // mutually exclusive, indicates the data location of the file, and also
48 | // chooses which additional data will specify the location.
49 | // _FROMFILE is paired with a filename (LPCSTR)
50 | // _FROMWFILE is paired with a filename (LPWSTR)
51 | // _FROMRESOURCE is paired with a (D3DXF_FILELOADRESOUCE*) description.
52 | // _FROMMEMORY is paired with a (D3DXF_FILELOADMEMORY*) description.
53 | //----------------------------------------------------------------------------
54 | typedef DWORD D3DXF_FILELOADOPTIONS;
55 |
56 | #define D3DXF_FILELOAD_FROMFILE 0x00L
57 | #define D3DXF_FILELOAD_FROMWFILE 0x01L
58 | #define D3DXF_FILELOAD_FROMRESOURCE 0x02L
59 | #define D3DXF_FILELOAD_FROMMEMORY 0x03L
60 |
61 | //----------------------------------------------------------------------------
62 | // D3DXF_FILELOADRESOURCE:
63 | //----------------------------------------------------------------------------
64 |
65 | typedef struct _D3DXF_FILELOADRESOURCE
66 | {
67 | HMODULE hModule; // Desc
68 | LPCSTR lpName; // Desc
69 | LPCSTR lpType; // Desc
70 | } D3DXF_FILELOADRESOURCE;
71 |
72 | //----------------------------------------------------------------------------
73 | // D3DXF_FILELOADMEMORY:
74 | //----------------------------------------------------------------------------
75 |
76 | typedef struct _D3DXF_FILELOADMEMORY
77 | {
78 | LPCVOID lpMemory; // Desc
79 | SIZE_T dSize; // Desc
80 | } D3DXF_FILELOADMEMORY;
81 |
82 | #if defined( _WIN32 ) && !defined( _NO_COM )
83 |
84 | // {cef08cf9-7b4f-4429-9624-2a690a933201}
85 | DEFINE_GUID( IID_ID3DXFile,
86 | 0xcef08cf9, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 );
87 |
88 | // {cef08cfa-7b4f-4429-9624-2a690a933201}
89 | DEFINE_GUID( IID_ID3DXFileSaveObject,
90 | 0xcef08cfa, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 );
91 |
92 | // {cef08cfb-7b4f-4429-9624-2a690a933201}
93 | DEFINE_GUID( IID_ID3DXFileSaveData,
94 | 0xcef08cfb, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 );
95 |
96 | // {cef08cfc-7b4f-4429-9624-2a690a933201}
97 | DEFINE_GUID( IID_ID3DXFileEnumObject,
98 | 0xcef08cfc, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 );
99 |
100 | // {cef08cfd-7b4f-4429-9624-2a690a933201}
101 | DEFINE_GUID( IID_ID3DXFileData,
102 | 0xcef08cfd, 0x7b4f, 0x4429, 0x96, 0x24, 0x2a, 0x69, 0x0a, 0x93, 0x32, 0x01 );
103 |
104 | #endif // defined( _WIN32 ) && !defined( _NO_COM )
105 |
106 | #if defined( __cplusplus )
107 | #if !defined( DECLSPEC_UUID )
108 | #if _MSC_VER >= 1100
109 | #define DECLSPEC_UUID( x ) __declspec( uuid( x ) )
110 | #else // !( _MSC_VER >= 1100 )
111 | #define DECLSPEC_UUID( x )
112 | #endif // !( _MSC_VER >= 1100 )
113 | #endif // !defined( DECLSPEC_UUID )
114 |
115 | interface DECLSPEC_UUID( "cef08cf9-7b4f-4429-9624-2a690a933201" )
116 | ID3DXFile;
117 | interface DECLSPEC_UUID( "cef08cfa-7b4f-4429-9624-2a690a933201" )
118 | ID3DXFileSaveObject;
119 | interface DECLSPEC_UUID( "cef08cfb-7b4f-4429-9624-2a690a933201" )
120 | ID3DXFileSaveData;
121 | interface DECLSPEC_UUID( "cef08cfc-7b4f-4429-9624-2a690a933201" )
122 | ID3DXFileEnumObject;
123 | interface DECLSPEC_UUID( "cef08cfd-7b4f-4429-9624-2a690a933201" )
124 | ID3DXFileData;
125 |
126 | #if defined( _COM_SMARTPTR_TYPEDEF )
127 | _COM_SMARTPTR_TYPEDEF( ID3DXFile,
128 | __uuidof( ID3DXFile ) );
129 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveObject,
130 | __uuidof( ID3DXFileSaveObject ) );
131 | _COM_SMARTPTR_TYPEDEF( ID3DXFileSaveData,
132 | __uuidof( ID3DXFileSaveData ) );
133 | _COM_SMARTPTR_TYPEDEF( ID3DXFileEnumObject,
134 | __uuidof( ID3DXFileEnumObject ) );
135 | _COM_SMARTPTR_TYPEDEF( ID3DXFileData,
136 | __uuidof( ID3DXFileData ) );
137 | #endif // defined( _COM_SMARTPTR_TYPEDEF )
138 | #endif // defined( __cplusplus )
139 |
140 | typedef interface ID3DXFile ID3DXFile;
141 | typedef interface ID3DXFileSaveObject ID3DXFileSaveObject;
142 | typedef interface ID3DXFileSaveData ID3DXFileSaveData;
143 | typedef interface ID3DXFileEnumObject ID3DXFileEnumObject;
144 | typedef interface ID3DXFileData ID3DXFileData;
145 |
146 | //////////////////////////////////////////////////////////////////////////////
147 | // ID3DXFile /////////////////////////////////////////////////////////////////
148 | //////////////////////////////////////////////////////////////////////////////
149 |
150 | #undef INTERFACE
151 | #define INTERFACE ID3DXFile
152 |
153 | DECLARE_INTERFACE_( ID3DXFile, IUnknown )
154 | {
155 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE;
156 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE;
157 | STDMETHOD_( ULONG, Release )( THIS ) PURE;
158 |
159 | STDMETHOD( CreateEnumObject )( THIS_ LPCVOID, D3DXF_FILELOADOPTIONS,
160 | ID3DXFileEnumObject** ) PURE;
161 | STDMETHOD( CreateSaveObject )( THIS_ LPCVOID, D3DXF_FILESAVEOPTIONS,
162 | D3DXF_FILEFORMAT, ID3DXFileSaveObject** ) PURE;
163 | STDMETHOD( RegisterTemplates )( THIS_ LPCVOID, SIZE_T ) PURE;
164 | STDMETHOD( RegisterEnumTemplates )( THIS_ ID3DXFileEnumObject* ) PURE;
165 | };
166 |
167 | //////////////////////////////////////////////////////////////////////////////
168 | // ID3DXFileSaveObject ///////////////////////////////////////////////////////
169 | //////////////////////////////////////////////////////////////////////////////
170 |
171 | #undef INTERFACE
172 | #define INTERFACE ID3DXFileSaveObject
173 |
174 | DECLARE_INTERFACE_( ID3DXFileSaveObject, IUnknown )
175 | {
176 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE;
177 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE;
178 | STDMETHOD_( ULONG, Release )( THIS ) PURE;
179 |
180 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE;
181 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*,
182 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE;
183 | STDMETHOD( Save )( THIS ) PURE;
184 | };
185 |
186 | //////////////////////////////////////////////////////////////////////////////
187 | // ID3DXFileSaveData /////////////////////////////////////////////////////////
188 | //////////////////////////////////////////////////////////////////////////////
189 |
190 | #undef INTERFACE
191 | #define INTERFACE ID3DXFileSaveData
192 |
193 | DECLARE_INTERFACE_( ID3DXFileSaveData, IUnknown )
194 | {
195 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE;
196 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE;
197 | STDMETHOD_( ULONG, Release )( THIS ) PURE;
198 |
199 | STDMETHOD( GetSave )( THIS_ ID3DXFileSaveObject** ) PURE;
200 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE;
201 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE;
202 | STDMETHOD( GetType )( THIS_ GUID* ) PURE;
203 | STDMETHOD( AddDataObject )( THIS_ REFGUID, LPCSTR, CONST GUID*,
204 | SIZE_T, LPCVOID, ID3DXFileSaveData** ) PURE;
205 | STDMETHOD( AddDataReference )( THIS_ LPCSTR, CONST GUID* ) PURE;
206 | };
207 |
208 | //////////////////////////////////////////////////////////////////////////////
209 | // ID3DXFileEnumObject ///////////////////////////////////////////////////////
210 | //////////////////////////////////////////////////////////////////////////////
211 |
212 | #undef INTERFACE
213 | #define INTERFACE ID3DXFileEnumObject
214 |
215 | DECLARE_INTERFACE_( ID3DXFileEnumObject, IUnknown )
216 | {
217 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE;
218 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE;
219 | STDMETHOD_( ULONG, Release )( THIS ) PURE;
220 |
221 | STDMETHOD( GetFile )( THIS_ ID3DXFile** ) PURE;
222 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE;
223 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE;
224 | STDMETHOD( GetDataObjectById )( THIS_ REFGUID, ID3DXFileData** ) PURE;
225 | STDMETHOD( GetDataObjectByName )( THIS_ LPCSTR, ID3DXFileData** ) PURE;
226 | };
227 |
228 | //////////////////////////////////////////////////////////////////////////////
229 | // ID3DXFileData /////////////////////////////////////////////////////////////
230 | //////////////////////////////////////////////////////////////////////////////
231 |
232 | #undef INTERFACE
233 | #define INTERFACE ID3DXFileData
234 |
235 | DECLARE_INTERFACE_( ID3DXFileData, IUnknown )
236 | {
237 | STDMETHOD( QueryInterface )( THIS_ REFIID, LPVOID* ) PURE;
238 | STDMETHOD_( ULONG, AddRef )( THIS ) PURE;
239 | STDMETHOD_( ULONG, Release )( THIS ) PURE;
240 |
241 | STDMETHOD( GetEnum )( THIS_ ID3DXFileEnumObject** ) PURE;
242 | STDMETHOD( GetName )( THIS_ LPSTR, SIZE_T* ) PURE;
243 | STDMETHOD( GetId )( THIS_ LPGUID ) PURE;
244 | STDMETHOD( Lock )( THIS_ SIZE_T*, LPCVOID* ) PURE;
245 | STDMETHOD( Unlock )( THIS ) PURE;
246 | STDMETHOD( GetType )( THIS_ GUID* ) PURE;
247 | STDMETHOD_( BOOL, IsReference )( THIS ) PURE;
248 | STDMETHOD( GetChildren )( THIS_ SIZE_T* ) PURE;
249 | STDMETHOD( GetChild )( THIS_ SIZE_T, ID3DXFileData** ) PURE;
250 | };
251 |
252 | STDAPI D3DXFileCreate( ID3DXFile** lplpDirectXFile );
253 |
254 | /*
255 | * DirectX File errors.
256 | */
257 |
258 | #define _FACD3DXF 0x876
259 |
260 | #define D3DXFERR_BADOBJECT MAKE_HRESULT( 1, _FACD3DXF, 900 )
261 | #define D3DXFERR_BADVALUE MAKE_HRESULT( 1, _FACD3DXF, 901 )
262 | #define D3DXFERR_BADTYPE MAKE_HRESULT( 1, _FACD3DXF, 902 )
263 | #define D3DXFERR_NOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 903 )
264 | #define D3DXFERR_NOTDONEYET MAKE_HRESULT( 1, _FACD3DXF, 904 )
265 | #define D3DXFERR_FILENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 905 )
266 | #define D3DXFERR_RESOURCENOTFOUND MAKE_HRESULT( 1, _FACD3DXF, 906 )
267 | #define D3DXFERR_BADRESOURCE MAKE_HRESULT( 1, _FACD3DXF, 907 )
268 | #define D3DXFERR_BADFILETYPE MAKE_HRESULT( 1, _FACD3DXF, 908 )
269 | #define D3DXFERR_BADFILEVERSION MAKE_HRESULT( 1, _FACD3DXF, 909 )
270 | #define D3DXFERR_BADFILEFLOATSIZE MAKE_HRESULT( 1, _FACD3DXF, 910 )
271 | #define D3DXFERR_BADFILE MAKE_HRESULT( 1, _FACD3DXF, 911 )
272 | #define D3DXFERR_PARSEERROR MAKE_HRESULT( 1, _FACD3DXF, 912 )
273 | #define D3DXFERR_BADARRAYSIZE MAKE_HRESULT( 1, _FACD3DXF, 913 )
274 | #define D3DXFERR_BADDATAREFERENCE MAKE_HRESULT( 1, _FACD3DXF, 914 )
275 | #define D3DXFERR_NOMOREOBJECTS MAKE_HRESULT( 1, _FACD3DXF, 915 )
276 | #define D3DXFERR_NOMOREDATA MAKE_HRESULT( 1, _FACD3DXF, 916 )
277 | #define D3DXFERR_BADCACHEFILE MAKE_HRESULT( 1, _FACD3DXF, 917 )
278 |
279 | /*
280 | * DirectX File object types.
281 | */
282 |
283 | #ifndef WIN_TYPES
284 | #define WIN_TYPES(itype, ptype) typedef interface itype *LP##ptype, **LPLP##ptype
285 | #endif
286 |
287 | WIN_TYPES(ID3DXFile, D3DXFILE);
288 | WIN_TYPES(ID3DXFileEnumObject, D3DXFILEENUMOBJECT);
289 | WIN_TYPES(ID3DXFileSaveObject, D3DXFILESAVEOBJECT);
290 | WIN_TYPES(ID3DXFileData, D3DXFILEDATA);
291 | WIN_TYPES(ID3DXFileSaveData, D3DXFILESAVEDATA);
292 |
293 | #if defined( __cplusplus )
294 | } // extern "C"
295 | #endif // defined( __cplusplus )
296 |
297 | #endif // !defined( __D3DX9XOF_H__ )
298 |
299 |
--------------------------------------------------------------------------------
/kernel_mode/utils.h:
--------------------------------------------------------------------------------
1 | namespace utils
2 | {
3 | uintptr_t swap_process( uintptr_t new_process )
4 | {
5 | auto current_thread = ( uintptr_t )KeGetCurrentThread( );
6 |
7 | auto apc_state = *( uintptr_t * )( current_thread + 0x98 );
8 | auto old_process = *( uintptr_t * )( apc_state + 0x20 );
9 | *( uintptr_t * )( apc_state + 0x20 ) = new_process;
10 |
11 | auto dir_table_base = *( uintptr_t * )( new_process + 0x28 );
12 | __writecr3( dir_table_base );
13 |
14 | return old_process;
15 | }
16 |
17 | uintptr_t resolve_relative_address( uintptr_t instruction, ULONG offset_offset, ULONG instruction_size )
18 | {
19 | auto instr = instruction;
20 |
21 | const auto rip_offset = *( PLONG )( instr + offset_offset );
22 |
23 | const auto resolved_addr = instr + instruction_size + rip_offset;
24 |
25 | return resolved_addr;
26 | }
27 |
28 | void *get_system_information( SYSTEM_INFORMATION_CLASS information_class )
29 | {
30 | unsigned long size = 32;
31 | char buffer[32];
32 |
33 | ZwQuerySystemInformation( information_class, buffer, size, &size );
34 |
35 | void *info = ExAllocatePoolZero( NonPagedPool, size, 7265746172 );
36 |
37 | if ( !info )
38 | return nullptr;
39 |
40 | if ( !NT_SUCCESS( ZwQuerySystemInformation( information_class, info, size, &size ) ) )
41 | {
42 | ExFreePool( info );
43 | return nullptr;
44 | }
45 |
46 | return info;
47 | }
48 |
49 | uintptr_t get_kernel_module(const char* name) {
50 | auto to_lower = [](char* string) {
51 | while (*string) {
52 | *string = tolower(*string);
53 | string++;
54 | }
55 | };
56 |
57 | PRTL_PROCESS_MODULES info = (PRTL_PROCESS_MODULES)get_system_information(SystemModuleInformation);
58 |
59 | if (!info)
60 | return NULL;
61 |
62 | for (size_t i = 0; i < info->NumberOfModules; i++) {
63 | const auto& mod = info->Modules[i];
64 | char* modName = (char*)mod.FullPathName + mod.OffsetToFileName;
65 | to_lower(modName);
66 | if (strcmp(modName, name) == 0) {
67 | const void* address = mod.ImageBase;
68 | ExFreePool(info);
69 | return (uintptr_t)address;
70 | }
71 | }
72 |
73 | ExFreePool(info);
74 | return NULL;
75 | }
76 |
77 |
78 | auto get_kernel_export( const char *module_name, LPCSTR export_name ) -> uintptr_t
79 | {
80 | return reinterpret_cast< uintptr_t > ( RtlFindExportedRoutineByName( reinterpret_cast< void * > ( utils::get_kernel_module( module_name ) ), export_name ) );
81 | }
82 |
83 | void sleep( int ms )
84 | {
85 | LARGE_INTEGER time;
86 | time.QuadPart = -( ms ) * 10 * 1000;
87 | KeDelayExecutionThread( KernelMode, TRUE, &time );
88 | }
89 |
90 |
91 | PIMAGE_NT_HEADERS get_nt_headers(PVOID module)
92 | {
93 | if (!module)
94 | return nullptr;
95 | return (PIMAGE_NT_HEADERS)((PBYTE)module + PIMAGE_DOS_HEADER(module)->e_lfanew);
96 | }
97 |
98 | PBYTE find_pattern(PVOID module, DWORD size, LPCSTR pattern, LPCSTR mask)
99 | {
100 | if (!module)
101 | return nullptr;
102 |
103 | auto checkMask = [](PBYTE buffer, LPCSTR pattern, LPCSTR mask) -> BOOL
104 | {
105 | for (auto x = buffer; *mask; pattern++, mask++, x++) {
106 | auto addr = *(BYTE*)(pattern);
107 | if (addr != *x && *mask != '?')
108 | return FALSE;
109 | }
110 |
111 | return TRUE;
112 | };
113 |
114 | for (auto x = 0; x < size - strlen(mask); x++) {
115 |
116 | auto addr = (PBYTE)module + x;
117 | if (checkMask(addr, pattern, mask)) {
118 | return addr;
119 | }
120 | }
121 |
122 | return NULL;
123 | }
124 |
125 | PBYTE find_pattern(PVOID base, LPCSTR pattern, LPCSTR mask)
126 | {
127 | if (!base) return 0;
128 |
129 | auto header = get_nt_headers(base);
130 | auto section = IMAGE_FIRST_SECTION(header);
131 |
132 | for (auto x = 0; x < header->FileHeader.NumberOfSections; x++, section++) {
133 |
134 | if (!memcmp(section->Name, e(".text"), 5) || !memcmp(section->Name, e("PAGE"), 4))
135 | {
136 | auto addr = find_pattern((PBYTE)base + section->VirtualAddress, section->Misc.VirtualSize, pattern, mask);
137 | if (addr)
138 | return addr;
139 | }
140 | }
141 |
142 | return NULL;
143 | }
144 | uintptr_t get_module_handle( uintptr_t pid, LPCWSTR module_name )
145 | {
146 | PEPROCESS target_proc;
147 | uintptr_t base = 0;
148 | if ( !NT_SUCCESS( PsLookupProcessByProcessId( ( HANDLE )pid, &target_proc ) ) )
149 | return 0;
150 |
151 | const auto o_process = swap_process( ( uintptr_t )target_proc );
152 |
153 | PPEB peb = PsGetProcessPeb( target_proc );
154 | if ( !peb )
155 | goto end;
156 |
157 | if ( !peb->Ldr || !peb->Ldr->Initialized )
158 | goto end;
159 |
160 |
161 | UNICODE_STRING module_name_unicode;
162 | RtlInitUnicodeString( &module_name_unicode, module_name );
163 | for ( PLIST_ENTRY list = peb->Ldr->InLoadOrderModuleList.Flink;
164 | list != &peb->Ldr->InLoadOrderModuleList;
165 | list = list->Flink ) {
166 | PLDR_DATA_TABLE_ENTRY entry = CONTAINING_RECORD( list, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks );
167 | if ( RtlCompareUnicodeString( &entry->BaseDllName, &module_name_unicode, TRUE ) == 0 ) {
168 | base = ( uintptr_t )entry->DllBase;
169 | goto end;
170 | }
171 | }
172 |
173 | end:
174 |
175 | swap_process( ( uintptr_t )o_process );
176 |
177 | ObDereferenceObject( target_proc );
178 |
179 | return base;
180 | }
181 |
182 | bool safe_copy( void* dst, void *src, size_t size )
183 | {
184 | SIZE_T bytes = 0;
185 |
186 | if ( MmCopyVirtualMemory( IoGetCurrentProcess( ), src, IoGetCurrentProcess( ), dst, size, KernelMode, &bytes ) == STATUS_SUCCESS && bytes == size )
187 | {
188 | return true;
189 | }
190 |
191 | return false;
192 | }
193 |
194 | MEMORY_BASIC_INFORMATION query_virtual_memory( void* address )
195 | {
196 | MEMORY_BASIC_INFORMATION mbi;
197 | ZwQueryVirtualMemory( ( HANDLE )-1, address, MemoryBasicInformation, &mbi, sizeof( MEMORY_BASIC_INFORMATION ), 0 );
198 | return mbi;
199 | }
200 |
201 | PAGE_INFORMATION get_page_information( void *va, CR3 cr3 )
202 | {
203 | ADDRESS_TRANSLATION_HELPER helper;
204 | UINT32 level;
205 | PML4E_64 *pml4, *pml4e;
206 | PDPTE_64 *pdpt, *pdpte;
207 | PDE_64 *pd, *pde;
208 | PTE_64 *pt, *pte;
209 |
210 | PAGE_INFORMATION info;
211 |
212 | helper.AsUInt64 = ( uintptr_t )va;
213 |
214 | PHYSICAL_ADDRESS pa;
215 |
216 | pa.QuadPart = cr3.AddressOfPageDirectory << PAGE_SHIFT;
217 |
218 | pml4 = ( PML4E_64 * )MmGetVirtualForPhysical( pa );
219 |
220 | pml4e = &pml4[helper.AsIndex.Pml4];
221 |
222 | info.PML4E = pml4e;
223 |
224 | if ( pml4e->Present == FALSE )
225 | {
226 | info.PTE = nullptr;
227 | info.PDE = nullptr;
228 | info.PDPTE = nullptr;
229 |
230 | goto end;
231 | }
232 |
233 | pa.QuadPart = pml4e->PageFrameNumber << PAGE_SHIFT;
234 |
235 | pdpt = ( PDPTE_64 * )MmGetVirtualForPhysical( pa );
236 |
237 | pdpte = &pdpt[helper.AsIndex.Pdpt];
238 |
239 | info.PDPTE = pdpte;
240 |
241 | if ( ( pdpte->Present == FALSE ) || ( pdpte->LargePage != FALSE ) )
242 | {
243 | info.PTE = nullptr;
244 | info.PDE = nullptr;
245 |
246 | goto end;
247 | }
248 |
249 | pa.QuadPart = pdpte->PageFrameNumber << PAGE_SHIFT;
250 |
251 | pd = ( PDE_64 * )MmGetVirtualForPhysical( pa );
252 |
253 | pde = &pd[helper.AsIndex.Pd];
254 |
255 | info.PDE = pde;
256 |
257 | if ( ( pde->Present == FALSE ) || ( pde->LargePage != FALSE ) )
258 | {
259 | info.PTE = nullptr;
260 |
261 | goto end;
262 | }
263 |
264 | pa.QuadPart = pde->PageFrameNumber << PAGE_SHIFT;
265 |
266 | pt = ( PTE_64 * )MmGetVirtualForPhysical( pa );
267 |
268 | pte = &pt[helper.AsIndex.Pt];
269 |
270 | info.PTE = pte;
271 |
272 | return info;
273 |
274 | end:
275 | return info;
276 | }
277 |
278 | MDL_INFORMATION allocate_mdl_memory( size_t size )
279 | {
280 | MDL_INFORMATION memory;
281 |
282 | PHYSICAL_ADDRESS lower, higher;
283 | lower.QuadPart = 0;
284 | higher.QuadPart = 0xffff'ffff'ffff'ffffULL;
285 |
286 | const auto pages = ( size / PAGE_SIZE ) + 1;
287 |
288 | const auto mdl = MmAllocatePagesForMdl( lower, higher, lower, pages * ( uintptr_t )0x1000 );
289 |
290 | if ( !mdl )
291 | {
292 | return { 0, 0 };
293 | }
294 |
295 | const auto mapping_start_address = MmMapLockedPagesSpecifyCache( mdl, KernelMode, MmCached, NULL, FALSE, NormalPagePriority );
296 |
297 | if ( !mapping_start_address )
298 | {
299 | return { 0, 0 };
300 | }
301 |
302 | if ( !NT_SUCCESS( MmProtectMdlSystemAddress( mdl, PAGE_EXECUTE_READWRITE ) ) )
303 | {
304 | return { 0, 0 };
305 | }
306 |
307 | memory.mdl = mdl;
308 | memory.va = reinterpret_cast ( mapping_start_address );
309 |
310 | return memory;
311 | }
312 |
313 | void free_mdl_memory( MDL_INFORMATION &memory )
314 | {
315 | MmUnmapLockedPages( reinterpret_cast< void * >( memory.va ), memory.mdl );
316 | MmFreePagesFromMdl( memory.mdl );
317 | ExFreePool( memory.mdl );
318 | }
319 |
320 | void* allocate_kernel_memory( const size_t _size, uintptr_t* mdl )
321 | {
322 | const auto size = size_align( _size );
323 |
324 | auto memory = allocate_mdl_memory( size );
325 |
326 | while ( memory.va % 0x10000 != 0 )
327 | {
328 | free_mdl_memory( memory );
329 | memory = allocate_mdl_memory( size );
330 | }
331 |
332 | *mdl = (uintptr_t)memory.mdl;
333 | return (void*)memory.va;
334 | }
335 |
336 | bool expose_kernel_memory( const int pid, const uintptr_t kernel_address, const size_t size )
337 | {
338 | PEPROCESS process;
339 | if ( PsLookupProcessByProcessId( ( HANDLE )pid, &process ) == STATUS_SUCCESS )
340 | {
341 | const auto o_process = utils::swap_process( ( uintptr_t )process );
342 |
343 | CR3 cr3 { };
344 | cr3.Flags = __readcr3( );
345 |
346 | for ( uintptr_t address = kernel_address; address <= kernel_address + size; address += 0x1000 )
347 | {
348 | const auto page_information = utils::get_page_information( ( void * )address, cr3 );
349 |
350 | page_information.PDE->Supervisor = 1;
351 | page_information.PDPTE->Supervisor = 1;
352 | page_information.PML4E->Supervisor = 1;
353 |
354 | if ( !page_information.PDE || ( page_information.PTE && !page_information.PTE->Present ) )
355 | {
356 |
357 | }
358 | else
359 | {
360 | page_information.PTE->Supervisor = 1;
361 | }
362 | }
363 |
364 | utils::swap_process( ( uintptr_t )o_process );
365 | }
366 | else
367 | {
368 | return false;
369 | }
370 |
371 | return true;
372 | }
373 |
374 | auto find_guarded_region() -> UINT_PTR
375 | {
376 | PSYSTEM_BIGPOOL_INFORMATION pool_information = 0;
377 |
378 | ULONG information_length = 0;
379 | NTSTATUS status = ZwQuerySystemInformation(system_bigpool_information, &information_length, 0, &information_length);
380 |
381 | while (status == STATUS_INFO_LENGTH_MISMATCH)
382 | {
383 | if (pool_information)
384 | ExFreePool(pool_information);
385 |
386 | pool_information = (PSYSTEM_BIGPOOL_INFORMATION)ExAllocatePool(NonPagedPool, information_length);
387 | status = ZwQuerySystemInformation(system_bigpool_information, pool_information, information_length, &information_length);
388 | }
389 | UINT_PTR saved_virtual_address = 0;
390 |
391 | if (pool_information)
392 | {
393 | for (ULONG i = 0; i < pool_information->Count; i++)
394 | {
395 | SYSTEM_BIGPOOL_ENTRY* allocation_entry = &pool_information->AllocatedInfo[i];
396 |
397 | UINT_PTR virtual_address = (UINT_PTR)allocation_entry->VirtualAddress & ~1ull;
398 |
399 | if (allocation_entry->NonPaged && allocation_entry->SizeInBytes == 0x200000)
400 | {
401 | if (saved_virtual_address == 0 && allocation_entry->TagUlong == 'TnoC') {
402 | saved_virtual_address = virtual_address;
403 | }
404 |
405 | //dbg("FindGuardedRegion => %llX og %p", virtual_address, allocation_entry->VirtualAddress);
406 | //dbg("TAG => %s", allocation_entry->Tag);
407 | }
408 | }
409 |
410 | ExFreePool(pool_information);
411 | }
412 | //dbg("Return %llX", saved_virtual_address);
413 | return saved_virtual_address;
414 | }
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 | }
--------------------------------------------------------------------------------
/user_mode/Imgui/imgui_impl_dx9.cpp:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer Backend for DirectX9
2 | // This needs to be used along with a Platform Backend (e.g. Win32)
3 |
4 | // Implemented features:
5 | // [X] Renderer: User texture binding. Use 'LPDIRECT3DTEXTURE9' as ImTextureID. Read the FAQ about ImTextureID!
6 | // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
7 |
8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
10 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
11 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
12 |
13 | // CHANGELOG
14 | // (minor and older changes stripped away, please see git history for details)
15 | // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
16 | // 2021-06-25: DirectX9: Explicitly disable texture state stages after >= 1.
17 | // 2021-05-19: DirectX9: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
18 | // 2021-04-23: DirectX9: Explicitly setting up more graphics states to increase compatibility with unusual non-default states.
19 | // 2021-03-18: DirectX9: Calling IDirect3DStateBlock9::Capture() after CreateStateBlock() as a workaround for state restoring issues (see #3857).
20 | // 2021-03-03: DirectX9: Added support for IMGUI_USE_BGRA_PACKED_COLOR in user's imconfig file.
21 | // 2021-02-18: DirectX9: Change blending equation to preserve alpha in output buffer.
22 | // 2019-05-29: DirectX9: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
23 | // 2019-04-30: DirectX9: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
24 | // 2019-03-29: Misc: Fixed erroneous assert in ImGui_ImplDX9_InvalidateDeviceObjects().
25 | // 2019-01-16: Misc: Disabled fog before drawing UI's. Fixes issue #2288.
26 | // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
27 | // 2018-06-08: Misc: Extracted imgui_impl_dx9.cpp/.h away from the old combined DX9+Win32 example.
28 | // 2018-06-08: DirectX9: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
29 | // 2018-05-07: Render: Saving/restoring Transform because they don't seem to be included in the StateBlock. Setting shading mode to Gouraud.
30 | // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplDX9_RenderDrawData() in the .h file so you can call it yourself.
31 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
32 |
33 | #include "imgui.h"
34 | #include "imgui_impl_dx9.h"
35 |
36 | // DirectX
37 | #include
38 |
39 | // DirectX data
40 | struct ImGui_ImplDX9_Data
41 | {
42 | LPDIRECT3DDEVICE9 pd3dDevice;
43 | LPDIRECT3DVERTEXBUFFER9 pVB;
44 | LPDIRECT3DINDEXBUFFER9 pIB;
45 | LPDIRECT3DTEXTURE9 FontTexture;
46 | int VertexBufferSize;
47 | int IndexBufferSize;
48 |
49 | ImGui_ImplDX9_Data() { memset((void*)this, 0, sizeof(*this)); VertexBufferSize = 5000; IndexBufferSize = 10000; }
50 | };
51 |
52 | struct CUSTOMVERTEX
53 | {
54 | float pos[3];
55 | D3DCOLOR col;
56 | float uv[2];
57 | };
58 | #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
59 |
60 | #ifdef IMGUI_USE_BGRA_PACKED_COLOR
61 | #define IMGUI_COL_TO_DX9_ARGB(_COL) (_COL)
62 | #else
63 | #define IMGUI_COL_TO_DX9_ARGB(_COL) (((_COL) & 0xFF00FF00) | (((_COL) & 0xFF0000) >> 16) | (((_COL) & 0xFF) << 16))
64 | #endif
65 |
66 | // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
67 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
68 | static ImGui_ImplDX9_Data* ImGui_ImplDX9_GetBackendData()
69 | {
70 | return ImGui::GetCurrentContext() ? (ImGui_ImplDX9_Data*)ImGui::GetIO().BackendRendererUserData : NULL;
71 | }
72 |
73 | // Functions
74 | static void ImGui_ImplDX9_SetupRenderState(ImDrawData* draw_data)
75 | {
76 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
77 |
78 | // Setup viewport
79 | D3DVIEWPORT9 vp;
80 | vp.X = vp.Y = 0;
81 | vp.Width = (DWORD)draw_data->DisplaySize.x;
82 | vp.Height = (DWORD)draw_data->DisplaySize.y;
83 | vp.MinZ = 0.0f;
84 | vp.MaxZ = 1.0f;
85 | bd->pd3dDevice->SetViewport(&vp);
86 |
87 | // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing, shade mode (for gradient), bilinear sampling.
88 | bd->pd3dDevice->SetPixelShader(NULL);
89 | bd->pd3dDevice->SetVertexShader(NULL);
90 | bd->pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
91 | bd->pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
92 | bd->pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
93 | bd->pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
94 | bd->pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
95 | bd->pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE);
96 | bd->pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
97 | bd->pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
98 | bd->pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
99 | bd->pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
100 | bd->pd3dDevice->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
101 | bd->pd3dDevice->SetRenderState(D3DRS_SRCBLENDALPHA, D3DBLEND_ONE);
102 | bd->pd3dDevice->SetRenderState(D3DRS_DESTBLENDALPHA, D3DBLEND_INVSRCALPHA);
103 | bd->pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
104 | bd->pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
105 | bd->pd3dDevice->SetRenderState(D3DRS_RANGEFOGENABLE, FALSE);
106 | bd->pd3dDevice->SetRenderState(D3DRS_SPECULARENABLE, FALSE);
107 | bd->pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
108 | bd->pd3dDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
109 | bd->pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
110 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
111 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
112 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
113 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
114 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
115 | bd->pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
116 | bd->pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
117 | bd->pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
118 | bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
119 | bd->pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
120 |
121 | // Setup orthographic projection matrix
122 | // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
123 | // Being agnostic of whether or can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
124 | {
125 | float L = draw_data->DisplayPos.x + 0.5f;
126 | float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x + 0.5f;
127 | float T = draw_data->DisplayPos.y + 0.5f;
128 | float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y + 0.5f;
129 | D3DMATRIX mat_identity = { { { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } } };
130 | D3DMATRIX mat_projection =
131 | { { {
132 | 2.0f/(R-L), 0.0f, 0.0f, 0.0f,
133 | 0.0f, 2.0f/(T-B), 0.0f, 0.0f,
134 | 0.0f, 0.0f, 0.5f, 0.0f,
135 | (L+R)/(L-R), (T+B)/(B-T), 0.5f, 1.0f
136 | } } };
137 | bd->pd3dDevice->SetTransform(D3DTS_WORLD, &mat_identity);
138 | bd->pd3dDevice->SetTransform(D3DTS_VIEW, &mat_identity);
139 | bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat_projection);
140 | }
141 | }
142 |
143 | // Render function.
144 | void ImGui_ImplDX9_RenderDrawData(ImDrawData* draw_data)
145 | {
146 | // Avoid rendering when minimized
147 | if (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f)
148 | return;
149 |
150 | // Create and grow buffers if needed
151 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
152 | if (!bd->pVB || bd->VertexBufferSize < draw_data->TotalVtxCount)
153 | {
154 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; }
155 | bd->VertexBufferSize = draw_data->TotalVtxCount + 5000;
156 | if (bd->pd3dDevice->CreateVertexBuffer(bd->VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &bd->pVB, NULL) < 0)
157 | return;
158 | }
159 | if (!bd->pIB || bd->IndexBufferSize < draw_data->TotalIdxCount)
160 | {
161 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; }
162 | bd->IndexBufferSize = draw_data->TotalIdxCount + 10000;
163 | if (bd->pd3dDevice->CreateIndexBuffer(bd->IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &bd->pIB, NULL) < 0)
164 | return;
165 | }
166 |
167 | // Backup the DX9 state
168 | IDirect3DStateBlock9* d3d9_state_block = NULL;
169 | if (bd->pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0)
170 | return;
171 | if (d3d9_state_block->Capture() < 0)
172 | {
173 | d3d9_state_block->Release();
174 | return;
175 | }
176 |
177 | // Backup the DX9 transform (DX9 documentation suggests that it is included in the StateBlock but it doesn't appear to)
178 | D3DMATRIX last_world, last_view, last_projection;
179 | bd->pd3dDevice->GetTransform(D3DTS_WORLD, &last_world);
180 | bd->pd3dDevice->GetTransform(D3DTS_VIEW, &last_view);
181 | bd->pd3dDevice->GetTransform(D3DTS_PROJECTION, &last_projection);
182 |
183 | // Allocate buffers
184 | CUSTOMVERTEX* vtx_dst;
185 | ImDrawIdx* idx_dst;
186 | if (bd->pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
187 | {
188 | d3d9_state_block->Release();
189 | return;
190 | }
191 | if (bd->pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0)
192 | {
193 | bd->pVB->Unlock();
194 | d3d9_state_block->Release();
195 | return;
196 | }
197 |
198 | // Copy and convert all vertices into a single contiguous buffer, convert colors to DX9 default format.
199 | // FIXME-OPT: This is a minor waste of resource, the ideal is to use imconfig.h and
200 | // 1) to avoid repacking colors: #define IMGUI_USE_BGRA_PACKED_COLOR
201 | // 2) to avoid repacking vertices: #define IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT struct ImDrawVert { ImVec2 pos; float z; ImU32 col; ImVec2 uv; }
202 | for (int n = 0; n < draw_data->CmdListsCount; n++)
203 | {
204 | const ImDrawList* cmd_list = draw_data->CmdLists[n];
205 | const ImDrawVert* vtx_src = cmd_list->VtxBuffer.Data;
206 | for (int i = 0; i < cmd_list->VtxBuffer.Size; i++)
207 | {
208 | vtx_dst->pos[0] = vtx_src->pos.x;
209 | vtx_dst->pos[1] = vtx_src->pos.y;
210 | vtx_dst->pos[2] = 0.0f;
211 | vtx_dst->col = IMGUI_COL_TO_DX9_ARGB(vtx_src->col);
212 | vtx_dst->uv[0] = vtx_src->uv.x;
213 | vtx_dst->uv[1] = vtx_src->uv.y;
214 | vtx_dst++;
215 | vtx_src++;
216 | }
217 | memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
218 | idx_dst += cmd_list->IdxBuffer.Size;
219 | }
220 | bd->pVB->Unlock();
221 | bd->pIB->Unlock();
222 | bd->pd3dDevice->SetStreamSource(0, bd->pVB, 0, sizeof(CUSTOMVERTEX));
223 | bd->pd3dDevice->SetIndices(bd->pIB);
224 | bd->pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
225 |
226 | // Setup desired DX state
227 | ImGui_ImplDX9_SetupRenderState(draw_data);
228 |
229 | // Render command lists
230 | // (Because we merged all buffers into a single one, we maintain our own offset into them)
231 | int global_vtx_offset = 0;
232 | int global_idx_offset = 0;
233 | ImVec2 clip_off = draw_data->DisplayPos;
234 | for (int n = 0; n < draw_data->CmdListsCount; n++)
235 | {
236 | const ImDrawList* cmd_list = draw_data->CmdLists[n];
237 | for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
238 | {
239 | const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
240 | if (pcmd->UserCallback != NULL)
241 | {
242 | // User callback, registered via ImDrawList::AddCallback()
243 | // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
244 | if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
245 | ImGui_ImplDX9_SetupRenderState(draw_data);
246 | else
247 | pcmd->UserCallback(cmd_list, pcmd);
248 | }
249 | else
250 | {
251 | // Project scissor/clipping rectangles into framebuffer space
252 | ImVec2 clip_min(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y);
253 | ImVec2 clip_max(pcmd->ClipRect.z - clip_off.x, pcmd->ClipRect.w - clip_off.y);
254 | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
255 | continue;
256 |
257 | // Apply Scissor/clipping rectangle, Bind texture, Draw
258 | const RECT r = { (LONG)clip_min.x, (LONG)clip_min.y, (LONG)clip_max.x, (LONG)clip_max.y };
259 | const LPDIRECT3DTEXTURE9 texture = (LPDIRECT3DTEXTURE9)pcmd->GetTexID();
260 | bd->pd3dDevice->SetTexture(0, texture);
261 | bd->pd3dDevice->SetScissorRect(&r);
262 | bd->pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, pcmd->VtxOffset + global_vtx_offset, 0, (UINT)cmd_list->VtxBuffer.Size, pcmd->IdxOffset + global_idx_offset, pcmd->ElemCount / 3);
263 | }
264 | }
265 | global_idx_offset += cmd_list->IdxBuffer.Size;
266 | global_vtx_offset += cmd_list->VtxBuffer.Size;
267 | }
268 |
269 | // Restore the DX9 transform
270 | bd->pd3dDevice->SetTransform(D3DTS_WORLD, &last_world);
271 | bd->pd3dDevice->SetTransform(D3DTS_VIEW, &last_view);
272 | bd->pd3dDevice->SetTransform(D3DTS_PROJECTION, &last_projection);
273 |
274 | // Restore the DX9 state
275 | d3d9_state_block->Apply();
276 | d3d9_state_block->Release();
277 | }
278 |
279 | bool ImGui_ImplDX9_Init(IDirect3DDevice9* device)
280 | {
281 | ImGuiIO& io = ImGui::GetIO();
282 | IM_ASSERT(io.BackendRendererUserData == NULL && "Already initialized a renderer backend!");
283 |
284 | // Setup backend capabilities flags
285 | ImGui_ImplDX9_Data* bd = IM_NEW(ImGui_ImplDX9_Data)();
286 | io.BackendRendererUserData = (void*)bd;
287 | io.BackendRendererName = "imgui_impl_dx9";
288 | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
289 |
290 | bd->pd3dDevice = device;
291 | bd->pd3dDevice->AddRef();
292 |
293 | return true;
294 | }
295 |
296 | void ImGui_ImplDX9_Shutdown()
297 | {
298 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
299 | IM_ASSERT(bd != NULL && "No renderer backend to shutdown, or already shutdown?");
300 | ImGuiIO& io = ImGui::GetIO();
301 |
302 | ImGui_ImplDX9_InvalidateDeviceObjects();
303 | if (bd->pd3dDevice) { bd->pd3dDevice->Release(); }
304 | io.BackendRendererName = NULL;
305 | io.BackendRendererUserData = NULL;
306 | IM_DELETE(bd);
307 | }
308 |
309 | static bool ImGui_ImplDX9_CreateFontsTexture()
310 | {
311 | // Build texture atlas
312 | ImGuiIO& io = ImGui::GetIO();
313 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
314 | unsigned char* pixels;
315 | int width, height, bytes_per_pixel;
316 | io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &bytes_per_pixel);
317 |
318 | // Convert RGBA32 to BGRA32 (because RGBA32 is not well supported by DX9 devices)
319 | #ifndef IMGUI_USE_BGRA_PACKED_COLOR
320 | if (io.Fonts->TexPixelsUseColors)
321 | {
322 | ImU32* dst_start = (ImU32*)ImGui::MemAlloc((size_t)width * height * bytes_per_pixel);
323 | for (ImU32* src = (ImU32*)pixels, *dst = dst_start, *dst_end = dst_start + (size_t)width * height; dst < dst_end; src++, dst++)
324 | *dst = IMGUI_COL_TO_DX9_ARGB(*src);
325 | pixels = (unsigned char*)dst_start;
326 | }
327 | #endif
328 |
329 | // Upload texture to graphics system
330 | bd->FontTexture = NULL;
331 | if (bd->pd3dDevice->CreateTexture(width, height, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &bd->FontTexture, NULL) < 0)
332 | return false;
333 | D3DLOCKED_RECT tex_locked_rect;
334 | if (bd->FontTexture->LockRect(0, &tex_locked_rect, NULL, 0) != D3D_OK)
335 | return false;
336 | for (int y = 0; y < height; y++)
337 | memcpy((unsigned char*)tex_locked_rect.pBits + (size_t)tex_locked_rect.Pitch * y, pixels + (size_t)width * bytes_per_pixel * y, (size_t)width * bytes_per_pixel);
338 | bd->FontTexture->UnlockRect(0);
339 |
340 | // Store our identifier
341 | io.Fonts->SetTexID((ImTextureID)bd->FontTexture);
342 |
343 | #ifndef IMGUI_USE_BGRA_PACKED_COLOR
344 | if (io.Fonts->TexPixelsUseColors)
345 | ImGui::MemFree(pixels);
346 | #endif
347 |
348 | return true;
349 | }
350 |
351 | bool ImGui_ImplDX9_CreateDeviceObjects()
352 | {
353 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
354 | if (!bd || !bd->pd3dDevice)
355 | return false;
356 | if (!ImGui_ImplDX9_CreateFontsTexture())
357 | return false;
358 | return true;
359 | }
360 |
361 | void ImGui_ImplDX9_InvalidateDeviceObjects()
362 | {
363 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
364 | if (!bd || !bd->pd3dDevice)
365 | return;
366 | if (bd->pVB) { bd->pVB->Release(); bd->pVB = NULL; }
367 | if (bd->pIB) { bd->pIB->Release(); bd->pIB = NULL; }
368 | if (bd->FontTexture) { bd->FontTexture->Release(); bd->FontTexture = NULL; ImGui::GetIO().Fonts->SetTexID(NULL); } // We copied bd->pFontTextureView to io.Fonts->TexID so let's clear that as well.
369 | }
370 |
371 | void ImGui_ImplDX9_NewFrame()
372 | {
373 | ImGui_ImplDX9_Data* bd = ImGui_ImplDX9_GetBackendData();
374 | IM_ASSERT(bd != NULL && "Did you call ImGui_ImplDX9_Init()?");
375 |
376 | if (!bd->FontTexture)
377 | ImGui_ImplDX9_CreateDeviceObjects();
378 | }
379 |
--------------------------------------------------------------------------------
/user_mode/Imgui/imstb_rectpack.h:
--------------------------------------------------------------------------------
1 | // [DEAR IMGUI]
2 | // This is a slightly modified version of stb_rect_pack.h 1.01.
3 | // Grep for [DEAR IMGUI] to find the changes.
4 | //
5 | // stb_rect_pack.h - v1.01 - public domain - rectangle packing
6 | // Sean Barrett 2014
7 | //
8 | // Useful for e.g. packing rectangular textures into an atlas.
9 | // Does not do rotation.
10 | //
11 | // Before #including,
12 | //
13 | // #define STB_RECT_PACK_IMPLEMENTATION
14 | //
15 | // in the file that you want to have the implementation.
16 | //
17 | // Not necessarily the awesomest packing method, but better than
18 | // the totally naive one in stb_truetype (which is primarily what
19 | // this is meant to replace).
20 | //
21 | // Has only had a few tests run, may have issues.
22 | //
23 | // More docs to come.
24 | //
25 | // No memory allocations; uses qsort() and assert() from stdlib.
26 | // Can override those by defining STBRP_SORT and STBRP_ASSERT.
27 | //
28 | // This library currently uses the Skyline Bottom-Left algorithm.
29 | //
30 | // Please note: better rectangle packers are welcome! Please
31 | // implement them to the same API, but with a different init
32 | // function.
33 | //
34 | // Credits
35 | //
36 | // Library
37 | // Sean Barrett
38 | // Minor features
39 | // Martins Mozeiko
40 | // github:IntellectualKitty
41 | //
42 | // Bugfixes / warning fixes
43 | // Jeremy Jaussaud
44 | // Fabian Giesen
45 | //
46 | // Version history:
47 | //
48 | // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
49 | // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
50 | // 0.99 (2019-02-07) warning fixes
51 | // 0.11 (2017-03-03) return packing success/fail result
52 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
53 | // 0.09 (2016-08-27) fix compiler warnings
54 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
55 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
56 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
57 | // 0.05: added STBRP_ASSERT to allow replacing assert
58 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support
59 | // 0.01: initial release
60 | //
61 | // LICENSE
62 | //
63 | // See end of file for license information.
64 |
65 | //////////////////////////////////////////////////////////////////////////////
66 | //
67 | // INCLUDE SECTION
68 | //
69 |
70 | #ifndef STB_INCLUDE_STB_RECT_PACK_H
71 | #define STB_INCLUDE_STB_RECT_PACK_H
72 |
73 | #define STB_RECT_PACK_VERSION 1
74 |
75 | #ifdef STBRP_STATIC
76 | #define STBRP_DEF static
77 | #else
78 | #define STBRP_DEF extern
79 | #endif
80 |
81 | #ifdef __cplusplus
82 | extern "C" {
83 | #endif
84 |
85 | typedef struct stbrp_context stbrp_context;
86 | typedef struct stbrp_node stbrp_node;
87 | typedef struct stbrp_rect stbrp_rect;
88 |
89 | typedef int stbrp_coord;
90 |
91 | #define STBRP__MAXVAL 0x7fffffff
92 | // Mostly for internal use, but this is the maximum supported coordinate value.
93 |
94 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
95 | // Assign packed locations to rectangles. The rectangles are of type
96 | // 'stbrp_rect' defined below, stored in the array 'rects', and there
97 | // are 'num_rects' many of them.
98 | //
99 | // Rectangles which are successfully packed have the 'was_packed' flag
100 | // set to a non-zero value and 'x' and 'y' store the minimum location
101 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left
102 | // if you imagine y increasing downwards). Rectangles which do not fit
103 | // have the 'was_packed' flag set to 0.
104 | //
105 | // You should not try to access the 'rects' array from another thread
106 | // while this function is running, as the function temporarily reorders
107 | // the array while it executes.
108 | //
109 | // To pack into another rectangle, you need to call stbrp_init_target
110 | // again. To continue packing into the same rectangle, you can call
111 | // this function again. Calling this multiple times with multiple rect
112 | // arrays will probably produce worse packing results than calling it
113 | // a single time with the full rectangle array, but the option is
114 | // available.
115 | //
116 | // The function returns 1 if all of the rectangles were successfully
117 | // packed and 0 otherwise.
118 |
119 | struct stbrp_rect
120 | {
121 | // reserved for your use:
122 | int id;
123 |
124 | // input:
125 | stbrp_coord w, h;
126 |
127 | // output:
128 | stbrp_coord x, y;
129 | int was_packed; // non-zero if valid packing
130 |
131 | }; // 16 bytes, nominally
132 |
133 |
134 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
135 | // Initialize a rectangle packer to:
136 | // pack a rectangle that is 'width' by 'height' in dimensions
137 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long
138 | //
139 | // You must call this function every time you start packing into a new target.
140 | //
141 | // There is no "shutdown" function. The 'nodes' memory must stay valid for
142 | // the following stbrp_pack_rects() call (or calls), but can be freed after
143 | // the call (or calls) finish.
144 | //
145 | // Note: to guarantee best results, either:
146 | // 1. make sure 'num_nodes' >= 'width'
147 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
148 | //
149 | // If you don't do either of the above things, widths will be quantized to multiples
150 | // of small integers to guarantee the algorithm doesn't run out of temporary storage.
151 | //
152 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm
153 | // may run out of temporary storage and be unable to pack some rectangles.
154 |
155 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
156 | // Optionally call this function after init but before doing any packing to
157 | // change the handling of the out-of-temp-memory scenario, described above.
158 | // If you call init again, this will be reset to the default (false).
159 |
160 |
161 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
162 | // Optionally select which packing heuristic the library should use. Different
163 | // heuristics will produce better/worse results for different data sets.
164 | // If you call init again, this will be reset to the default.
165 |
166 | enum
167 | {
168 | STBRP_HEURISTIC_Skyline_default=0,
169 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
170 | STBRP_HEURISTIC_Skyline_BF_sortHeight
171 | };
172 |
173 |
174 | //////////////////////////////////////////////////////////////////////////////
175 | //
176 | // the details of the following structures don't matter to you, but they must
177 | // be visible so you can handle the memory allocations for them
178 |
179 | struct stbrp_node
180 | {
181 | stbrp_coord x,y;
182 | stbrp_node *next;
183 | };
184 |
185 | struct stbrp_context
186 | {
187 | int width;
188 | int height;
189 | int align;
190 | int init_mode;
191 | int heuristic;
192 | int num_nodes;
193 | stbrp_node *active_head;
194 | stbrp_node *free_head;
195 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
196 | };
197 |
198 | #ifdef __cplusplus
199 | }
200 | #endif
201 |
202 | #endif
203 |
204 | //////////////////////////////////////////////////////////////////////////////
205 | //
206 | // IMPLEMENTATION SECTION
207 | //
208 |
209 | #ifdef STB_RECT_PACK_IMPLEMENTATION
210 | #ifndef STBRP_SORT
211 | #include
212 | #define STBRP_SORT qsort
213 | #endif
214 |
215 | #ifndef STBRP_ASSERT
216 | #include
217 | #define STBRP_ASSERT assert
218 | #endif
219 |
220 | #ifdef _MSC_VER
221 | #define STBRP__NOTUSED(v) (void)(v)
222 | #define STBRP__CDECL __cdecl
223 | #else
224 | #define STBRP__NOTUSED(v) (void)sizeof(v)
225 | #define STBRP__CDECL
226 | #endif
227 |
228 | enum
229 | {
230 | STBRP__INIT_skyline = 1
231 | };
232 |
233 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
234 | {
235 | switch (context->init_mode) {
236 | case STBRP__INIT_skyline:
237 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
238 | context->heuristic = heuristic;
239 | break;
240 | default:
241 | STBRP_ASSERT(0);
242 | }
243 | }
244 |
245 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
246 | {
247 | if (allow_out_of_mem)
248 | // if it's ok to run out of memory, then don't bother aligning them;
249 | // this gives better packing, but may fail due to OOM (even though
250 | // the rectangles easily fit). @TODO a smarter approach would be to only
251 | // quantize once we've hit OOM, then we could get rid of this parameter.
252 | context->align = 1;
253 | else {
254 | // if it's not ok to run out of memory, then quantize the widths
255 | // so that num_nodes is always enough nodes.
256 | //
257 | // I.e. num_nodes * align >= width
258 | // align >= width / num_nodes
259 | // align = ceil(width/num_nodes)
260 |
261 | context->align = (context->width + context->num_nodes-1) / context->num_nodes;
262 | }
263 | }
264 |
265 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
266 | {
267 | int i;
268 |
269 | for (i=0; i < num_nodes-1; ++i)
270 | nodes[i].next = &nodes[i+1];
271 | nodes[i].next = NULL;
272 | context->init_mode = STBRP__INIT_skyline;
273 | context->heuristic = STBRP_HEURISTIC_Skyline_default;
274 | context->free_head = &nodes[0];
275 | context->active_head = &context->extra[0];
276 | context->width = width;
277 | context->height = height;
278 | context->num_nodes = num_nodes;
279 | stbrp_setup_allow_out_of_mem(context, 0);
280 |
281 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
282 | context->extra[0].x = 0;
283 | context->extra[0].y = 0;
284 | context->extra[0].next = &context->extra[1];
285 | context->extra[1].x = (stbrp_coord) width;
286 | context->extra[1].y = (1<<30);
287 | context->extra[1].next = NULL;
288 | }
289 |
290 | // find minimum y position if it starts at x1
291 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
292 | {
293 | stbrp_node *node = first;
294 | int x1 = x0 + width;
295 | int min_y, visited_width, waste_area;
296 |
297 | STBRP__NOTUSED(c);
298 |
299 | STBRP_ASSERT(first->x <= x0);
300 |
301 | #if 0
302 | // skip in case we're past the node
303 | while (node->next->x <= x0)
304 | ++node;
305 | #else
306 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
307 | #endif
308 |
309 | STBRP_ASSERT(node->x <= x0);
310 |
311 | min_y = 0;
312 | waste_area = 0;
313 | visited_width = 0;
314 | while (node->x < x1) {
315 | if (node->y > min_y) {
316 | // raise min_y higher.
317 | // we've accounted for all waste up to min_y,
318 | // but we'll now add more waste for everything we've visted
319 | waste_area += visited_width * (node->y - min_y);
320 | min_y = node->y;
321 | // the first time through, visited_width might be reduced
322 | if (node->x < x0)
323 | visited_width += node->next->x - x0;
324 | else
325 | visited_width += node->next->x - node->x;
326 | } else {
327 | // add waste area
328 | int under_width = node->next->x - node->x;
329 | if (under_width + visited_width > width)
330 | under_width = width - visited_width;
331 | waste_area += under_width * (min_y - node->y);
332 | visited_width += under_width;
333 | }
334 | node = node->next;
335 | }
336 |
337 | *pwaste = waste_area;
338 | return min_y;
339 | }
340 |
341 | typedef struct
342 | {
343 | int x,y;
344 | stbrp_node **prev_link;
345 | } stbrp__findresult;
346 |
347 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
348 | {
349 | int best_waste = (1<<30), best_x, best_y = (1 << 30);
350 | stbrp__findresult fr;
351 | stbrp_node **prev, *node, *tail, **best = NULL;
352 |
353 | // align to multiple of c->align
354 | width = (width + c->align - 1);
355 | width -= width % c->align;
356 | STBRP_ASSERT(width % c->align == 0);
357 |
358 | // if it can't possibly fit, bail immediately
359 | if (width > c->width || height > c->height) {
360 | fr.prev_link = NULL;
361 | fr.x = fr.y = 0;
362 | return fr;
363 | }
364 |
365 | node = c->active_head;
366 | prev = &c->active_head;
367 | while (node->x + width <= c->width) {
368 | int y,waste;
369 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
370 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
371 | // bottom left
372 | if (y < best_y) {
373 | best_y = y;
374 | best = prev;
375 | }
376 | } else {
377 | // best-fit
378 | if (y + height <= c->height) {
379 | // can only use it if it first vertically
380 | if (y < best_y || (y == best_y && waste < best_waste)) {
381 | best_y = y;
382 | best_waste = waste;
383 | best = prev;
384 | }
385 | }
386 | }
387 | prev = &node->next;
388 | node = node->next;
389 | }
390 |
391 | best_x = (best == NULL) ? 0 : (*best)->x;
392 |
393 | // if doing best-fit (BF), we also have to try aligning right edge to each node position
394 | //
395 | // e.g, if fitting
396 | //
397 | // ____________________
398 | // |____________________|
399 | //
400 | // into
401 | //
402 | // | |
403 | // | ____________|
404 | // |____________|
405 | //
406 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
407 | //
408 | // This makes BF take about 2x the time
409 |
410 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
411 | tail = c->active_head;
412 | node = c->active_head;
413 | prev = &c->active_head;
414 | // find first node that's admissible
415 | while (tail->x < width)
416 | tail = tail->next;
417 | while (tail) {
418 | int xpos = tail->x - width;
419 | int y,waste;
420 | STBRP_ASSERT(xpos >= 0);
421 | // find the left position that matches this
422 | while (node->next->x <= xpos) {
423 | prev = &node->next;
424 | node = node->next;
425 | }
426 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
427 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
428 | if (y + height <= c->height) {
429 | if (y <= best_y) {
430 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
431 | best_x = xpos;
432 | //STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
433 | best_y = y;
434 | best_waste = waste;
435 | best = prev;
436 | }
437 | }
438 | }
439 | tail = tail->next;
440 | }
441 | }
442 |
443 | fr.prev_link = best;
444 | fr.x = best_x;
445 | fr.y = best_y;
446 | return fr;
447 | }
448 |
449 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
450 | {
451 | // find best position according to heuristic
452 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
453 | stbrp_node *node, *cur;
454 |
455 | // bail if:
456 | // 1. it failed
457 | // 2. the best node doesn't fit (we don't always check this)
458 | // 3. we're out of memory
459 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
460 | res.prev_link = NULL;
461 | return res;
462 | }
463 |
464 | // on success, create new node
465 | node = context->free_head;
466 | node->x = (stbrp_coord) res.x;
467 | node->y = (stbrp_coord) (res.y + height);
468 |
469 | context->free_head = node->next;
470 |
471 | // insert the new node into the right starting point, and
472 | // let 'cur' point to the remaining nodes needing to be
473 | // stiched back in
474 |
475 | cur = *res.prev_link;
476 | if (cur->x < res.x) {
477 | // preserve the existing one, so start testing with the next one
478 | stbrp_node *next = cur->next;
479 | cur->next = node;
480 | cur = next;
481 | } else {
482 | *res.prev_link = node;
483 | }
484 |
485 | // from here, traverse cur and free the nodes, until we get to one
486 | // that shouldn't be freed
487 | while (cur->next && cur->next->x <= res.x + width) {
488 | stbrp_node *next = cur->next;
489 | // move the current node to the free list
490 | cur->next = context->free_head;
491 | context->free_head = cur;
492 | cur = next;
493 | }
494 |
495 | // stitch the list back in
496 | node->next = cur;
497 |
498 | if (cur->x < res.x + width)
499 | cur->x = (stbrp_coord) (res.x + width);
500 |
501 | #ifdef _DEBUG
502 | cur = context->active_head;
503 | while (cur->x < context->width) {
504 | STBRP_ASSERT(cur->x < cur->next->x);
505 | cur = cur->next;
506 | }
507 | STBRP_ASSERT(cur->next == NULL);
508 |
509 | {
510 | int count=0;
511 | cur = context->active_head;
512 | while (cur) {
513 | cur = cur->next;
514 | ++count;
515 | }
516 | cur = context->free_head;
517 | while (cur) {
518 | cur = cur->next;
519 | ++count;
520 | }
521 | STBRP_ASSERT(count == context->num_nodes+2);
522 | }
523 | #endif
524 |
525 | return res;
526 | }
527 |
528 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
529 | {
530 | const stbrp_rect *p = (const stbrp_rect *) a;
531 | const stbrp_rect *q = (const stbrp_rect *) b;
532 | if (p->h > q->h)
533 | return -1;
534 | if (p->h < q->h)
535 | return 1;
536 | return (p->w > q->w) ? -1 : (p->w < q->w);
537 | }
538 |
539 | static int STBRP__CDECL rect_original_order(const void *a, const void *b)
540 | {
541 | const stbrp_rect *p = (const stbrp_rect *) a;
542 | const stbrp_rect *q = (const stbrp_rect *) b;
543 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
544 | }
545 |
546 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
547 | {
548 | int i, all_rects_packed = 1;
549 |
550 | // we use the 'was_packed' field internally to allow sorting/unsorting
551 | for (i=0; i < num_rects; ++i) {
552 | rects[i].was_packed = i;
553 | }
554 |
555 | // sort according to heuristic
556 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
557 |
558 | for (i=0; i < num_rects; ++i) {
559 | if (rects[i].w == 0 || rects[i].h == 0) {
560 | rects[i].x = rects[i].y = 0; // empty rect needs no space
561 | } else {
562 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
563 | if (fr.prev_link) {
564 | rects[i].x = (stbrp_coord) fr.x;
565 | rects[i].y = (stbrp_coord) fr.y;
566 | } else {
567 | rects[i].x = rects[i].y = STBRP__MAXVAL;
568 | }
569 | }
570 | }
571 |
572 | // unsort
573 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
574 |
575 | // set was_packed flags and all_rects_packed status
576 | for (i=0; i < num_rects; ++i) {
577 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
578 | if (!rects[i].was_packed)
579 | all_rects_packed = 0;
580 | }
581 |
582 | // return the all_rects_packed status
583 | return all_rects_packed;
584 | }
585 | #endif
586 |
587 | /*
588 | ------------------------------------------------------------------------------
589 | This software is available under 2 licenses -- choose whichever you prefer.
590 | ------------------------------------------------------------------------------
591 | ALTERNATIVE A - MIT License
592 | Copyright (c) 2017 Sean Barrett
593 | Permission is hereby granted, free of charge, to any person obtaining a copy of
594 | this software and associated documentation files (the "Software"), to deal in
595 | the Software without restriction, including without limitation the rights to
596 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
597 | of the Software, and to permit persons to whom the Software is furnished to do
598 | so, subject to the following conditions:
599 | The above copyright notice and this permission notice shall be included in all
600 | copies or substantial portions of the Software.
601 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
602 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
603 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
604 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
605 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
606 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
607 | SOFTWARE.
608 | ------------------------------------------------------------------------------
609 | ALTERNATIVE B - Public Domain (www.unlicense.org)
610 | This is free and unencumbered software released into the public domain.
611 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
612 | software, either in source code form or as a compiled binary, for any purpose,
613 | commercial or non-commercial, and by any means.
614 | In jurisdictions that recognize copyright laws, the author or authors of this
615 | software dedicate any and all copyright interest in the software to the public
616 | domain. We make this dedication for the benefit of the public at large and to
617 | the detriment of our heirs and successors. We intend this dedication to be an
618 | overt act of relinquishment in perpetuity of all present and future rights to
619 | this software under copyright law.
620 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
621 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
622 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
623 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
624 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
625 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
626 | ------------------------------------------------------------------------------
627 | */
628 |
--------------------------------------------------------------------------------
/user_mode/directx9/d3dx9core.h:
--------------------------------------------------------------------------------
1 | ///////////////////////////////////////////////////////////////////////////
2 | //
3 | // Copyright (C) Microsoft Corporation. All Rights Reserved.
4 | //
5 | // File: d3dx9core.h
6 | // Content: D3DX core types and functions
7 | //
8 | ///////////////////////////////////////////////////////////////////////////
9 |
10 | #include "d3dx9.h"
11 |
12 | #ifndef __D3DX9CORE_H__
13 | #define __D3DX9CORE_H__
14 |
15 |
16 | ///////////////////////////////////////////////////////////////////////////
17 | // D3DX_SDK_VERSION:
18 | // -----------------
19 | // This identifier is passed to D3DXCheckVersion in order to ensure that an
20 | // application was built against the correct header files and lib files.
21 | // This number is incremented whenever a header (or other) change would
22 | // require applications to be rebuilt. If the version doesn't match,
23 | // D3DXCheckVersion will return FALSE. (The number itself has no meaning.)
24 | ///////////////////////////////////////////////////////////////////////////
25 |
26 | #define D3DX_VERSION 0x0902
27 |
28 | #define D3DX_SDK_VERSION 43
29 |
30 | #ifdef __cplusplus
31 | extern "C" {
32 | #endif //__cplusplus
33 |
34 | BOOL WINAPI
35 | D3DXCheckVersion(UINT D3DSdkVersion, UINT D3DXSdkVersion);
36 |
37 | #ifdef __cplusplus
38 | }
39 | #endif //__cplusplus
40 |
41 |
42 |
43 | ///////////////////////////////////////////////////////////////////////////
44 | // D3DXDebugMute
45 | // Mutes D3DX and D3D debug spew (TRUE - mute, FALSE - not mute)
46 | //
47 | // returns previous mute value
48 | //
49 | ///////////////////////////////////////////////////////////////////////////
50 |
51 | #ifdef __cplusplus
52 | extern "C" {
53 | #endif //__cplusplus
54 |
55 | BOOL WINAPI
56 | D3DXDebugMute(BOOL Mute);
57 |
58 | #ifdef __cplusplus
59 | }
60 | #endif //__cplusplus
61 |
62 |
63 | ///////////////////////////////////////////////////////////////////////////
64 | // D3DXGetDriverLevel:
65 | // Returns driver version information:
66 | //
67 | // 700 - DX7 level driver
68 | // 800 - DX8 level driver
69 | // 900 - DX9 level driver
70 | ///////////////////////////////////////////////////////////////////////////
71 |
72 | #ifdef __cplusplus
73 | extern "C" {
74 | #endif //__cplusplus
75 |
76 | UINT WINAPI
77 | D3DXGetDriverLevel(LPDIRECT3DDEVICE9 pDevice);
78 |
79 | #ifdef __cplusplus
80 | }
81 | #endif //__cplusplus
82 |
83 |
84 | ///////////////////////////////////////////////////////////////////////////
85 | // ID3DXBuffer:
86 | // ------------
87 | // The buffer object is used by D3DX to return arbitrary size data.
88 | //
89 | // GetBufferPointer -
90 | // Returns a pointer to the beginning of the buffer.
91 | //
92 | // GetBufferSize -
93 | // Returns the size of the buffer, in bytes.
94 | ///////////////////////////////////////////////////////////////////////////
95 |
96 | typedef interface ID3DXBuffer ID3DXBuffer;
97 | typedef interface ID3DXBuffer *LPD3DXBUFFER;
98 |
99 | // {8BA5FB08-5195-40e2-AC58-0D989C3A0102}
100 | DEFINE_GUID(IID_ID3DXBuffer,
101 | 0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2);
102 |
103 | #undef INTERFACE
104 | #define INTERFACE ID3DXBuffer
105 |
106 | DECLARE_INTERFACE_(ID3DXBuffer, IUnknown)
107 | {
108 | // IUnknown
109 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
110 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
111 | STDMETHOD_(ULONG, Release)(THIS) PURE;
112 |
113 | // ID3DXBuffer
114 | STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
115 | STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
116 | };
117 |
118 |
119 |
120 | //////////////////////////////////////////////////////////////////////////////
121 | // D3DXSPRITE flags:
122 | // -----------------
123 | // D3DXSPRITE_DONOTSAVESTATE
124 | // Specifies device state is not to be saved and restored in Begin/End.
125 | // D3DXSPRITE_DONOTMODIFY_RENDERSTATE
126 | // Specifies device render state is not to be changed in Begin. The device
127 | // is assumed to be in a valid state to draw vertices containing POSITION0,
128 | // TEXCOORD0, and COLOR0 data.
129 | // D3DXSPRITE_OBJECTSPACE
130 | // The WORLD, VIEW, and PROJECTION transforms are NOT modified. The
131 | // transforms currently set to the device are used to transform the sprites
132 | // when the batch is drawn (at Flush or End). If this is not specified,
133 | // WORLD, VIEW, and PROJECTION transforms are modified so that sprites are
134 | // drawn in screenspace coordinates.
135 | // D3DXSPRITE_BILLBOARD
136 | // Rotates each sprite about its center so that it is facing the viewer.
137 | // D3DXSPRITE_ALPHABLEND
138 | // Enables ALPHABLEND(SRCALPHA, INVSRCALPHA) and ALPHATEST(alpha > 0).
139 | // ID3DXFont expects this to be set when drawing text.
140 | // D3DXSPRITE_SORT_TEXTURE
141 | // Sprites are sorted by texture prior to drawing. This is recommended when
142 | // drawing non-overlapping sprites of uniform depth. For example, drawing
143 | // screen-aligned text with ID3DXFont.
144 | // D3DXSPRITE_SORT_DEPTH_FRONTTOBACK
145 | // Sprites are sorted by depth front-to-back prior to drawing. This is
146 | // recommended when drawing opaque sprites of varying depths.
147 | // D3DXSPRITE_SORT_DEPTH_BACKTOFRONT
148 | // Sprites are sorted by depth back-to-front prior to drawing. This is
149 | // recommended when drawing transparent sprites of varying depths.
150 | // D3DXSPRITE_DO_NOT_ADDREF_TEXTURE
151 | // Disables calling AddRef() on every draw, and Release() on Flush() for
152 | // better performance.
153 | //////////////////////////////////////////////////////////////////////////////
154 |
155 | #define D3DXSPRITE_DONOTSAVESTATE (1 << 0)
156 | #define D3DXSPRITE_DONOTMODIFY_RENDERSTATE (1 << 1)
157 | #define D3DXSPRITE_OBJECTSPACE (1 << 2)
158 | #define D3DXSPRITE_BILLBOARD (1 << 3)
159 | #define D3DXSPRITE_ALPHABLEND (1 << 4)
160 | #define D3DXSPRITE_SORT_TEXTURE (1 << 5)
161 | #define D3DXSPRITE_SORT_DEPTH_FRONTTOBACK (1 << 6)
162 | #define D3DXSPRITE_SORT_DEPTH_BACKTOFRONT (1 << 7)
163 | #define D3DXSPRITE_DO_NOT_ADDREF_TEXTURE (1 << 8)
164 |
165 |
166 | //////////////////////////////////////////////////////////////////////////////
167 | // ID3DXSprite:
168 | // ------------
169 | // This object intends to provide an easy way to drawing sprites using D3D.
170 | //
171 | // Begin -
172 | // Prepares device for drawing sprites.
173 | //
174 | // Draw -
175 | // Draws a sprite. Before transformation, the sprite is the size of
176 | // SrcRect, with its top-left corner specified by Position. The color
177 | // and alpha channels are modulated by Color.
178 | //
179 | // Flush -
180 | // Forces all batched sprites to submitted to the device.
181 | //
182 | // End -
183 | // Restores device state to how it was when Begin was called.
184 | //
185 | // OnLostDevice, OnResetDevice -
186 | // Call OnLostDevice() on this object before calling Reset() on the
187 | // device, so that this object can release any stateblocks and video
188 | // memory resources. After Reset(), the call OnResetDevice().
189 | //////////////////////////////////////////////////////////////////////////////
190 |
191 | typedef interface ID3DXSprite ID3DXSprite;
192 | typedef interface ID3DXSprite *LPD3DXSPRITE;
193 |
194 |
195 | // {BA0B762D-7D28-43ec-B9DC-2F84443B0614}
196 | DEFINE_GUID(IID_ID3DXSprite,
197 | 0xba0b762d, 0x7d28, 0x43ec, 0xb9, 0xdc, 0x2f, 0x84, 0x44, 0x3b, 0x6, 0x14);
198 |
199 |
200 | #undef INTERFACE
201 | #define INTERFACE ID3DXSprite
202 |
203 | DECLARE_INTERFACE_(ID3DXSprite, IUnknown)
204 | {
205 | // IUnknown
206 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
207 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
208 | STDMETHOD_(ULONG, Release)(THIS) PURE;
209 |
210 | // ID3DXSprite
211 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
212 |
213 | STDMETHOD(GetTransform)(THIS_ D3DXMATRIX *pTransform) PURE;
214 | STDMETHOD(SetTransform)(THIS_ CONST D3DXMATRIX *pTransform) PURE;
215 |
216 | STDMETHOD(SetWorldViewRH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE;
217 | STDMETHOD(SetWorldViewLH)(THIS_ CONST D3DXMATRIX *pWorld, CONST D3DXMATRIX *pView) PURE;
218 |
219 | STDMETHOD(Begin)(THIS_ DWORD Flags) PURE;
220 | STDMETHOD(Draw)(THIS_ LPDIRECT3DTEXTURE9 pTexture, CONST RECT *pSrcRect, CONST D3DXVECTOR3 *pCenter, CONST D3DXVECTOR3 *pPosition, D3DCOLOR Color) PURE;
221 | STDMETHOD(Flush)(THIS) PURE;
222 | STDMETHOD(End)(THIS) PURE;
223 |
224 | STDMETHOD(OnLostDevice)(THIS) PURE;
225 | STDMETHOD(OnResetDevice)(THIS) PURE;
226 | };
227 |
228 |
229 | #ifdef __cplusplus
230 | extern "C" {
231 | #endif //__cplusplus
232 |
233 | HRESULT WINAPI
234 | D3DXCreateSprite(
235 | LPDIRECT3DDEVICE9 pDevice,
236 | LPD3DXSPRITE* ppSprite);
237 |
238 | #ifdef __cplusplus
239 | }
240 | #endif //__cplusplus
241 |
242 |
243 |
244 | //////////////////////////////////////////////////////////////////////////////
245 | // ID3DXFont:
246 | // ----------
247 | // Font objects contain the textures and resources needed to render a specific
248 | // font on a specific device.
249 | //
250 | // GetGlyphData -
251 | // Returns glyph cache data, for a given glyph.
252 | //
253 | // PreloadCharacters/PreloadGlyphs/PreloadText -
254 | // Preloads glyphs into the glyph cache textures.
255 | //
256 | // DrawText -
257 | // Draws formatted text on a D3D device. Some parameters are
258 | // surprisingly similar to those of GDI's DrawText function. See GDI
259 | // documentation for a detailed description of these parameters.
260 | // If pSprite is NULL, an internal sprite object will be used.
261 | //
262 | // OnLostDevice, OnResetDevice -
263 | // Call OnLostDevice() on this object before calling Reset() on the
264 | // device, so that this object can release any stateblocks and video
265 | // memory resources. After Reset(), the call OnResetDevice().
266 | //////////////////////////////////////////////////////////////////////////////
267 |
268 | typedef struct _D3DXFONT_DESCA
269 | {
270 | INT Height;
271 | UINT Width;
272 | UINT Weight;
273 | UINT MipLevels;
274 | BOOL Italic;
275 | BYTE CharSet;
276 | BYTE OutputPrecision;
277 | BYTE Quality;
278 | BYTE PitchAndFamily;
279 | CHAR FaceName[LF_FACESIZE];
280 |
281 | } D3DXFONT_DESCA, *LPD3DXFONT_DESCA;
282 |
283 | typedef struct _D3DXFONT_DESCW
284 | {
285 | INT Height;
286 | UINT Width;
287 | UINT Weight;
288 | UINT MipLevels;
289 | BOOL Italic;
290 | BYTE CharSet;
291 | BYTE OutputPrecision;
292 | BYTE Quality;
293 | BYTE PitchAndFamily;
294 | WCHAR FaceName[LF_FACESIZE];
295 |
296 | } D3DXFONT_DESCW, *LPD3DXFONT_DESCW;
297 |
298 | #ifdef UNICODE
299 | typedef D3DXFONT_DESCW D3DXFONT_DESC;
300 | typedef LPD3DXFONT_DESCW LPD3DXFONT_DESC;
301 | #else
302 | typedef D3DXFONT_DESCA D3DXFONT_DESC;
303 | typedef LPD3DXFONT_DESCA LPD3DXFONT_DESC;
304 | #endif
305 |
306 |
307 | typedef interface ID3DXFont ID3DXFont;
308 | typedef interface ID3DXFont *LPD3DXFONT;
309 |
310 |
311 | // {D79DBB70-5F21-4d36-BBC2-FF525C213CDC}
312 | DEFINE_GUID(IID_ID3DXFont,
313 | 0xd79dbb70, 0x5f21, 0x4d36, 0xbb, 0xc2, 0xff, 0x52, 0x5c, 0x21, 0x3c, 0xdc);
314 |
315 |
316 | #undef INTERFACE
317 | #define INTERFACE ID3DXFont
318 |
319 | DECLARE_INTERFACE_(ID3DXFont, IUnknown)
320 | {
321 | // IUnknown
322 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
323 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
324 | STDMETHOD_(ULONG, Release)(THIS) PURE;
325 |
326 | // ID3DXFont
327 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9 *ppDevice) PURE;
328 | STDMETHOD(GetDescA)(THIS_ D3DXFONT_DESCA *pDesc) PURE;
329 | STDMETHOD(GetDescW)(THIS_ D3DXFONT_DESCW *pDesc) PURE;
330 | STDMETHOD_(BOOL, GetTextMetricsA)(THIS_ TEXTMETRICA *pTextMetrics) PURE;
331 | STDMETHOD_(BOOL, GetTextMetricsW)(THIS_ TEXTMETRICW *pTextMetrics) PURE;
332 |
333 | STDMETHOD_(HDC, GetDC)(THIS) PURE;
334 | STDMETHOD(GetGlyphData)(THIS_ UINT Glyph, LPDIRECT3DTEXTURE9 *ppTexture, RECT *pBlackBox, POINT *pCellInc) PURE;
335 |
336 | STDMETHOD(PreloadCharacters)(THIS_ UINT First, UINT Last) PURE;
337 | STDMETHOD(PreloadGlyphs)(THIS_ UINT First, UINT Last) PURE;
338 | STDMETHOD(PreloadTextA)(THIS_ LPCSTR pString, INT Count) PURE;
339 | STDMETHOD(PreloadTextW)(THIS_ LPCWSTR pString, INT Count) PURE;
340 |
341 | STDMETHOD_(INT, DrawTextA)(THIS_ LPD3DXSPRITE pSprite, LPCSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
342 | STDMETHOD_(INT, DrawTextW)(THIS_ LPD3DXSPRITE pSprite, LPCWSTR pString, INT Count, LPRECT pRect, DWORD Format, D3DCOLOR Color) PURE;
343 |
344 | STDMETHOD(OnLostDevice)(THIS) PURE;
345 | STDMETHOD(OnResetDevice)(THIS) PURE;
346 |
347 | #ifdef __cplusplus
348 | #ifdef UNICODE
349 | HRESULT GetDesc(D3DXFONT_DESCW *pDesc) { return GetDescW(pDesc); }
350 | HRESULT PreloadText(LPCWSTR pString, INT Count) { return PreloadTextW(pString, Count); }
351 | #else
352 | HRESULT GetDesc(D3DXFONT_DESCA *pDesc) { return GetDescA(pDesc); }
353 | HRESULT PreloadText(LPCSTR pString, INT Count) { return PreloadTextA(pString, Count); }
354 | #endif
355 | #endif //__cplusplus
356 | };
357 |
358 | #ifndef GetTextMetrics
359 | #ifdef UNICODE
360 | #define GetTextMetrics GetTextMetricsW
361 | #else
362 | #define GetTextMetrics GetTextMetricsA
363 | #endif
364 | #endif
365 |
366 | #ifndef DrawText
367 | #ifdef UNICODE
368 | #define DrawText DrawTextW
369 | #else
370 | #define DrawText DrawTextA
371 | #endif
372 | #endif
373 |
374 |
375 | #ifdef __cplusplus
376 | extern "C" {
377 | #endif //__cplusplus
378 |
379 |
380 | HRESULT WINAPI
381 | D3DXCreateFontA(
382 | LPDIRECT3DDEVICE9 pDevice,
383 | INT Height,
384 | UINT Width,
385 | UINT Weight,
386 | UINT MipLevels,
387 | BOOL Italic,
388 | DWORD CharSet,
389 | DWORD OutputPrecision,
390 | DWORD Quality,
391 | DWORD PitchAndFamily,
392 | LPCSTR pFaceName,
393 | LPD3DXFONT* ppFont);
394 |
395 | HRESULT WINAPI
396 | D3DXCreateFontW(
397 | LPDIRECT3DDEVICE9 pDevice,
398 | INT Height,
399 | UINT Width,
400 | UINT Weight,
401 | UINT MipLevels,
402 | BOOL Italic,
403 | DWORD CharSet,
404 | DWORD OutputPrecision,
405 | DWORD Quality,
406 | DWORD PitchAndFamily,
407 | LPCWSTR pFaceName,
408 | LPD3DXFONT* ppFont);
409 |
410 | #ifdef UNICODE
411 | #define D3DXCreateFont D3DXCreateFontW
412 | #else
413 | #define D3DXCreateFont D3DXCreateFontA
414 | #endif
415 |
416 |
417 | HRESULT WINAPI
418 | D3DXCreateFontIndirectA(
419 | LPDIRECT3DDEVICE9 pDevice,
420 | CONST D3DXFONT_DESCA* pDesc,
421 | LPD3DXFONT* ppFont);
422 |
423 | HRESULT WINAPI
424 | D3DXCreateFontIndirectW(
425 | LPDIRECT3DDEVICE9 pDevice,
426 | CONST D3DXFONT_DESCW* pDesc,
427 | LPD3DXFONT* ppFont);
428 |
429 | #ifdef UNICODE
430 | #define D3DXCreateFontIndirect D3DXCreateFontIndirectW
431 | #else
432 | #define D3DXCreateFontIndirect D3DXCreateFontIndirectA
433 | #endif
434 |
435 |
436 | #ifdef __cplusplus
437 | }
438 | #endif //__cplusplus
439 |
440 |
441 |
442 | ///////////////////////////////////////////////////////////////////////////
443 | // ID3DXRenderToSurface:
444 | // ---------------------
445 | // This object abstracts rendering to surfaces. These surfaces do not
446 | // necessarily need to be render targets. If they are not, a compatible
447 | // render target is used, and the result copied into surface at end scene.
448 | //
449 | // BeginScene, EndScene -
450 | // Call BeginScene() and EndScene() at the beginning and ending of your
451 | // scene. These calls will setup and restore render targets, viewports,
452 | // etc..
453 | //
454 | // OnLostDevice, OnResetDevice -
455 | // Call OnLostDevice() on this object before calling Reset() on the
456 | // device, so that this object can release any stateblocks and video
457 | // memory resources. After Reset(), the call OnResetDevice().
458 | ///////////////////////////////////////////////////////////////////////////
459 |
460 | typedef struct _D3DXRTS_DESC
461 | {
462 | UINT Width;
463 | UINT Height;
464 | D3DFORMAT Format;
465 | BOOL DepthStencil;
466 | D3DFORMAT DepthStencilFormat;
467 |
468 | } D3DXRTS_DESC, *LPD3DXRTS_DESC;
469 |
470 |
471 | typedef interface ID3DXRenderToSurface ID3DXRenderToSurface;
472 | typedef interface ID3DXRenderToSurface *LPD3DXRENDERTOSURFACE;
473 |
474 |
475 | // {6985F346-2C3D-43b3-BE8B-DAAE8A03D894}
476 | DEFINE_GUID(IID_ID3DXRenderToSurface,
477 | 0x6985f346, 0x2c3d, 0x43b3, 0xbe, 0x8b, 0xda, 0xae, 0x8a, 0x3, 0xd8, 0x94);
478 |
479 |
480 | #undef INTERFACE
481 | #define INTERFACE ID3DXRenderToSurface
482 |
483 | DECLARE_INTERFACE_(ID3DXRenderToSurface, IUnknown)
484 | {
485 | // IUnknown
486 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
487 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
488 | STDMETHOD_(ULONG, Release)(THIS) PURE;
489 |
490 | // ID3DXRenderToSurface
491 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
492 | STDMETHOD(GetDesc)(THIS_ D3DXRTS_DESC* pDesc) PURE;
493 |
494 | STDMETHOD(BeginScene)(THIS_ LPDIRECT3DSURFACE9 pSurface, CONST D3DVIEWPORT9* pViewport) PURE;
495 | STDMETHOD(EndScene)(THIS_ DWORD MipFilter) PURE;
496 |
497 | STDMETHOD(OnLostDevice)(THIS) PURE;
498 | STDMETHOD(OnResetDevice)(THIS) PURE;
499 | };
500 |
501 |
502 | #ifdef __cplusplus
503 | extern "C" {
504 | #endif //__cplusplus
505 |
506 | HRESULT WINAPI
507 | D3DXCreateRenderToSurface(
508 | LPDIRECT3DDEVICE9 pDevice,
509 | UINT Width,
510 | UINT Height,
511 | D3DFORMAT Format,
512 | BOOL DepthStencil,
513 | D3DFORMAT DepthStencilFormat,
514 | LPD3DXRENDERTOSURFACE* ppRenderToSurface);
515 |
516 | #ifdef __cplusplus
517 | }
518 | #endif //__cplusplus
519 |
520 |
521 |
522 | ///////////////////////////////////////////////////////////////////////////
523 | // ID3DXRenderToEnvMap:
524 | // --------------------
525 | // This object abstracts rendering to environment maps. These surfaces
526 | // do not necessarily need to be render targets. If they are not, a
527 | // compatible render target is used, and the result copied into the
528 | // environment map at end scene.
529 | //
530 | // BeginCube, BeginSphere, BeginHemisphere, BeginParabolic -
531 | // This function initiates the rendering of the environment map. As
532 | // parameters, you pass the textures in which will get filled in with
533 | // the resulting environment map.
534 | //
535 | // Face -
536 | // Call this function to initiate the drawing of each face. For each
537 | // environment map, you will call this six times.. once for each face
538 | // in D3DCUBEMAP_FACES.
539 | //
540 | // End -
541 | // This will restore all render targets, and if needed compose all the
542 | // rendered faces into the environment map surfaces.
543 | //
544 | // OnLostDevice, OnResetDevice -
545 | // Call OnLostDevice() on this object before calling Reset() on the
546 | // device, so that this object can release any stateblocks and video
547 | // memory resources. After Reset(), the call OnResetDevice().
548 | ///////////////////////////////////////////////////////////////////////////
549 |
550 | typedef struct _D3DXRTE_DESC
551 | {
552 | UINT Size;
553 | UINT MipLevels;
554 | D3DFORMAT Format;
555 | BOOL DepthStencil;
556 | D3DFORMAT DepthStencilFormat;
557 |
558 | } D3DXRTE_DESC, *LPD3DXRTE_DESC;
559 |
560 |
561 | typedef interface ID3DXRenderToEnvMap ID3DXRenderToEnvMap;
562 | typedef interface ID3DXRenderToEnvMap *LPD3DXRenderToEnvMap;
563 |
564 |
565 | // {313F1B4B-C7B0-4fa2-9D9D-8D380B64385E}
566 | DEFINE_GUID(IID_ID3DXRenderToEnvMap,
567 | 0x313f1b4b, 0xc7b0, 0x4fa2, 0x9d, 0x9d, 0x8d, 0x38, 0xb, 0x64, 0x38, 0x5e);
568 |
569 |
570 | #undef INTERFACE
571 | #define INTERFACE ID3DXRenderToEnvMap
572 |
573 | DECLARE_INTERFACE_(ID3DXRenderToEnvMap, IUnknown)
574 | {
575 | // IUnknown
576 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
577 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
578 | STDMETHOD_(ULONG, Release)(THIS) PURE;
579 |
580 | // ID3DXRenderToEnvMap
581 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
582 | STDMETHOD(GetDesc)(THIS_ D3DXRTE_DESC* pDesc) PURE;
583 |
584 | STDMETHOD(BeginCube)(THIS_
585 | LPDIRECT3DCUBETEXTURE9 pCubeTex) PURE;
586 |
587 | STDMETHOD(BeginSphere)(THIS_
588 | LPDIRECT3DTEXTURE9 pTex) PURE;
589 |
590 | STDMETHOD(BeginHemisphere)(THIS_
591 | LPDIRECT3DTEXTURE9 pTexZPos,
592 | LPDIRECT3DTEXTURE9 pTexZNeg) PURE;
593 |
594 | STDMETHOD(BeginParabolic)(THIS_
595 | LPDIRECT3DTEXTURE9 pTexZPos,
596 | LPDIRECT3DTEXTURE9 pTexZNeg) PURE;
597 |
598 | STDMETHOD(Face)(THIS_ D3DCUBEMAP_FACES Face, DWORD MipFilter) PURE;
599 | STDMETHOD(End)(THIS_ DWORD MipFilter) PURE;
600 |
601 | STDMETHOD(OnLostDevice)(THIS) PURE;
602 | STDMETHOD(OnResetDevice)(THIS) PURE;
603 | };
604 |
605 |
606 | #ifdef __cplusplus
607 | extern "C" {
608 | #endif //__cplusplus
609 |
610 | HRESULT WINAPI
611 | D3DXCreateRenderToEnvMap(
612 | LPDIRECT3DDEVICE9 pDevice,
613 | UINT Size,
614 | UINT MipLevels,
615 | D3DFORMAT Format,
616 | BOOL DepthStencil,
617 | D3DFORMAT DepthStencilFormat,
618 | LPD3DXRenderToEnvMap* ppRenderToEnvMap);
619 |
620 | #ifdef __cplusplus
621 | }
622 | #endif //__cplusplus
623 |
624 |
625 |
626 | ///////////////////////////////////////////////////////////////////////////
627 | // ID3DXLine:
628 | // ------------
629 | // This object intends to provide an easy way to draw lines using D3D.
630 | //
631 | // Begin -
632 | // Prepares device for drawing lines
633 | //
634 | // Draw -
635 | // Draws a line strip in screen-space.
636 | // Input is in the form of a array defining points on the line strip. of D3DXVECTOR2
637 | //
638 | // DrawTransform -
639 | // Draws a line in screen-space with a specified input transformation matrix.
640 | //
641 | // End -
642 | // Restores device state to how it was when Begin was called.
643 | //
644 | // SetPattern -
645 | // Applies a stipple pattern to the line. Input is one 32-bit
646 | // DWORD which describes the stipple pattern. 1 is opaque, 0 is
647 | // transparent.
648 | //
649 | // SetPatternScale -
650 | // Stretches the stipple pattern in the u direction. Input is one
651 | // floating-point value. 0.0f is no scaling, whereas 1.0f doubles
652 | // the length of the stipple pattern.
653 | //
654 | // SetWidth -
655 | // Specifies the thickness of the line in the v direction. Input is
656 | // one floating-point value.
657 | //
658 | // SetAntialias -
659 | // Toggles line antialiasing. Input is a BOOL.
660 | // TRUE = Antialiasing on.
661 | // FALSE = Antialiasing off.
662 | //
663 | // SetGLLines -
664 | // Toggles non-antialiased OpenGL line emulation. Input is a BOOL.
665 | // TRUE = OpenGL line emulation on.
666 | // FALSE = OpenGL line emulation off.
667 | //
668 | // OpenGL line: Regular line:
669 | // *\ *\
670 | // | \ / \
671 | // | \ *\ \
672 | // *\ \ \ \
673 | // \ \ \ \
674 | // \ * \ *
675 | // \ | \ /
676 | // \| *
677 | // *
678 | //
679 | // OnLostDevice, OnResetDevice -
680 | // Call OnLostDevice() on this object before calling Reset() on the
681 | // device, so that this object can release any stateblocks and video
682 | // memory resources. After Reset(), the call OnResetDevice().
683 | ///////////////////////////////////////////////////////////////////////////
684 |
685 |
686 | typedef interface ID3DXLine ID3DXLine;
687 | typedef interface ID3DXLine *LPD3DXLINE;
688 |
689 |
690 | // {D379BA7F-9042-4ac4-9F5E-58192A4C6BD8}
691 | DEFINE_GUID(IID_ID3DXLine,
692 | 0xd379ba7f, 0x9042, 0x4ac4, 0x9f, 0x5e, 0x58, 0x19, 0x2a, 0x4c, 0x6b, 0xd8);
693 |
694 | #undef INTERFACE
695 | #define INTERFACE ID3DXLine
696 |
697 | DECLARE_INTERFACE_(ID3DXLine, IUnknown)
698 | {
699 | // IUnknown
700 | STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
701 | STDMETHOD_(ULONG, AddRef)(THIS) PURE;
702 | STDMETHOD_(ULONG, Release)(THIS) PURE;
703 |
704 | // ID3DXLine
705 | STDMETHOD(GetDevice)(THIS_ LPDIRECT3DDEVICE9* ppDevice) PURE;
706 |
707 | STDMETHOD(Begin)(THIS) PURE;
708 |
709 | STDMETHOD(Draw)(THIS_ CONST D3DXVECTOR2 *pVertexList,
710 | DWORD dwVertexListCount, D3DCOLOR Color) PURE;
711 |
712 | STDMETHOD(DrawTransform)(THIS_ CONST D3DXVECTOR3 *pVertexList,
713 | DWORD dwVertexListCount, CONST D3DXMATRIX* pTransform,
714 | D3DCOLOR Color) PURE;
715 |
716 | STDMETHOD(SetPattern)(THIS_ DWORD dwPattern) PURE;
717 | STDMETHOD_(DWORD, GetPattern)(THIS) PURE;
718 |
719 | STDMETHOD(SetPatternScale)(THIS_ FLOAT fPatternScale) PURE;
720 | STDMETHOD_(FLOAT, GetPatternScale)(THIS) PURE;
721 |
722 | STDMETHOD(SetWidth)(THIS_ FLOAT fWidth) PURE;
723 | STDMETHOD_(FLOAT, GetWidth)(THIS) PURE;
724 |
725 | STDMETHOD(SetAntialias)(THIS_ BOOL bAntialias) PURE;
726 | STDMETHOD_(BOOL, GetAntialias)(THIS) PURE;
727 |
728 | STDMETHOD(SetGLLines)(THIS_ BOOL bGLLines) PURE;
729 | STDMETHOD_(BOOL, GetGLLines)(THIS) PURE;
730 |
731 | STDMETHOD(End)(THIS) PURE;
732 |
733 | STDMETHOD(OnLostDevice)(THIS) PURE;
734 | STDMETHOD(OnResetDevice)(THIS) PURE;
735 | };
736 |
737 |
738 | #ifdef __cplusplus
739 | extern "C" {
740 | #endif //__cplusplus
741 |
742 |
743 | HRESULT WINAPI
744 | D3DXCreateLine(
745 | LPDIRECT3DDEVICE9 pDevice,
746 | LPD3DXLINE* ppLine);
747 |
748 | #ifdef __cplusplus
749 | }
750 | #endif //__cplusplus
751 |
752 | #endif //__D3DX9CORE_H__
753 |
--------------------------------------------------------------------------------