-
Notifications
You must be signed in to change notification settings - Fork 72
/
d3Dx9.ahk
177 lines (146 loc) · 3.91 KB
/
d3Dx9.ahk
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
#include <DirectX\Headers\d3DX9>
global ID3DXBuffer
class d3DX9 {
__new(dll = "d3dx9_24.dll")
{
this.h_dll := ""
this.pD3DXLoadSurfaceFromFile := ""
this.pD3DXCreateFont := ""
h_dll := dllcall("GetModuleHandle", str, dll)
h_dll ?: h_dll := dllcall("LoadLibraryW", str, dll)
if not h_dll
return ""
this.h_dll := h_dll
this.pD3DXLoadSurfaceFromFile := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXLoadSurfaceFromFileW")
this.pD3DXCreateFont := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXCreateFontW")
this.D3DXCompileShader := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXCompileShader")
this.D3DXCompileShaderFromFile := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXCompileShaderFromFileA")
this.D3DXGetPixelShaderProfile := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXGetPixelShaderProfile")
this.D3DXCreateBuffer := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXCreateBuffer")
this.D3DXCreateTextureFromFile := dllcall("GetProcAddress", uint, this.h_dll, astr, "D3DXCreateTextureFromFileW")
this.rect := Struct("LONG left; LONG top; LONG right; LONG bottom;")
this.POINT := Struct("LONG x; LONG y;")
}
CreateTextureFromFile(pDevice, file, byref pTexture){
return dllcall(this.D3DXCreateTextureFromFile
,uint, pdevice, str, file, "uint*", pTexture)
}
LoadSurfaceFromFile(pSurface, file, filter = 1)
{
RETURN dllcall(this.pD3DXLoadSurfaceFromFile
, uint, pSurface
, uint, pDestPalette
, uint, 0
, str, file
, uint, 0
, uint, filter
, uint, ColorKey
, uint, pSrcInfo, uint)
}
CreateFontW(pDevice, font = "Verdana", italic = False)
{
r := dllcall(this.pD3DXCreateFont
, uint, pDevice
, int, 0
, int, 0
, int, 600
, uint, 0
, uint, italic
, uint, 0
, uint, 0
, uint, 0
, uint, 0
, str, font
, "uint*", pID3DXFont, uint)
if r
return r
fnt := new ComInterfaceWrapper(d3DX9core.ID3DXFont, pID3DXFont, True)
return fnt
}
DrawText(byref fnt, txt, clr = 0xFFFFFFFF, rct = "")
{
if not rct
rct := "0|0|640|480"
rct_ := strsplit(rct, "|")
this.rect.left := rct_[1]
this.rect.top := rct_[2]
this.rect.right := rct_[3]
this.rect.bottom := rct_[4]
r := dllcall(fnt.DrawTextW, uint, fnt.p
, uint, 0
, str, txt
, int, -1
, uint, this.RECT[]
, uint, 256
, uint, clr
, uint)
return r
}
CompileShaderFromFile(pDevice, file, entrypoint, byref pShader)
{
r := dllcall(this.D3DXCompileShaderFromFile
, astr, file
, uint, 0
, uint, 0
, astr, entrypoint
, astr, "ps_3_0"
, uint, 0
, "uint*", pShader
, "uint*", pError
, uint, 0, uint)
if r
use := pError
else use := pShader
if not ID3DXBuffer
ID3DXBuffer := new ComInterfaceWrapper(D3DX9Mesh.ID3DXBuffer, use, True)
else ID3DXBuffer.p := use
_ptr := dllcall(ID3DXBuffer.GetBufferPointer, uint, ID3DXBuffer.p)
size := dllcall(ID3DXBuffer.GetBufferSize, uint, ID3DXBuffer.p)
if r
{
rr := strget(_ptr+0, size, "CP0")
ID3DXBuffer.__release()
return rr
}
else
{
r := dllcall(IDirect3DDevice9.CreatePixelShader, uint, pDevice, uint, _ptr, "uint*", pShader)
ID3DXBuffer.__release()
return r
}
}
CompileShader(pDevice, byref Shader, entrypoint, byref pShader)
{
r := dllcall(this.D3DXCompileShader
, astr, Shader
, UINT, strlen(Shader)
, uint, 0
, uint, 0
, astr, entrypoint
, astr, "ps_3_0"
, uint, 0
, "uint*", pShader
, "uint*", pError
, uint, 0, uint)
if r
use := pError
else use := pShader
if not ID3DXBuffer
ID3DXBuffer := new ComInterfaceWrapper(D3DX9Mesh.ID3DXBuffer, use, True)
else ID3DXBuffer.p := use
_ptr := dllcall(ID3DXBuffer.GetBufferPointer, uint, ID3DXBuffer.p)
size := dllcall(ID3DXBuffer.GetBufferSize, uint, ID3DXBuffer.p)
if r
{
rr := strget(_ptr+0, size, "CP0")
ID3DXBuffer.__release()
return rr
}
else
{
r := dllcall(IDirect3DDevice9.CreatePixelShader, uint, pDevice, uint, _ptr, "uint*", pShader)
ID3DXBuffer.__release()
return r
}
}
}