forked from crosire/d3d8to9
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3d8to9.cpp
80 lines (66 loc) · 2.56 KB
/
d3d8to9.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Copyright (C) 2015 Patrick Mours. All rights reserved.
* License: https://github.com/crosire/d3d8to9#license
*/
#include "d3dx9.hpp"
#include "d3d8to9.hpp"
PFN_D3DXAssembleShader D3DXAssembleShader = nullptr;
PFN_D3DXDisassembleShader D3DXDisassembleShader = nullptr;
PFN_D3DXLoadSurfaceFromSurface D3DXLoadSurfaceFromSurface = nullptr;
#ifndef D3D8TO9NOLOG
// Very simple logging for the purpose of debugging only.
std::ofstream LOG;
#endif
extern "C" IDirect3D8 *WINAPI Direct3DCreate8(UINT SDKVersion)
{
#ifndef D3D8TO9NOLOG
static bool LogMessageFlag = true;
if (!LOG.is_open())
{
LOG.open("d3d8.log", std::ios::trunc);
}
if (!LOG.is_open() && LogMessageFlag)
{
LogMessageFlag = false;
MessageBox(nullptr, TEXT("Failed to open debug log file \"d3d8.log\"!"), nullptr, MB_ICONWARNING);
}
LOG << "Redirecting '" << "Direct3DCreate8" << "(" << SDKVersion << ")' ..." << std::endl;
LOG << "> Passing on to 'Direct3DCreate9Ex':" << std::endl;
#endif
IDirect3D9Ex* d3d = nullptr;
Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d);
if (d3d == nullptr)
{
return nullptr;
}
// Load D3DX
if (!D3DXAssembleShader || !D3DXDisassembleShader || !D3DXLoadSurfaceFromSurface)
{
const HMODULE module = LoadLibrary(TEXT("d3dx9_43.dll"));
if (module != nullptr)
{
D3DXAssembleShader = reinterpret_cast<PFN_D3DXAssembleShader>(GetProcAddress(module, "D3DXAssembleShader"));
D3DXDisassembleShader = reinterpret_cast<PFN_D3DXDisassembleShader>(GetProcAddress(module, "D3DXDisassembleShader"));
D3DXLoadSurfaceFromSurface = reinterpret_cast<PFN_D3DXLoadSurfaceFromSurface>(GetProcAddress(module, "D3DXLoadSurfaceFromSurface"));
}
else
{
#ifndef D3D8TO9NOLOG
LOG << "Failed to load d3dx9_43.dll! Some features will not work correctly." << std::endl;
#endif
if (MessageBox(nullptr, TEXT(
"Failed to load d3dx9_43.dll! Some features will not work correctly.\n\n"
"It's required to install the \"Microsoft DirectX End-User Runtime\" in order to use d3d8to9, or alternatively get the DLLs from this NuGet package:\nhttps://www.nuget.org/packages/Microsoft.DXSDK.D3DX\n\n"
"Please click \"OK\" to open the official download page or \"Cancel\" to continue anyway."), nullptr, MB_ICONWARNING | MB_TOPMOST | MB_SETFOREGROUND | MB_OKCANCEL | MB_DEFBUTTON1) == IDOK)
{
ShellExecute(nullptr, TEXT("open"), TEXT("https://www.microsoft.com/download/details.aspx?id=35"), nullptr, nullptr, SW_SHOW);
return nullptr;
}
}
}
return new Direct3D8(d3d);
}
IDirect3D8 *WINAPI Direct3DCreate8to9ex(UINT SDKVersion)
{
return Direct3DCreate8(SDKVersion);
}