forked from jewalky/a2mgr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
opengl.cpp
240 lines (200 loc) · 4.98 KB
/
opengl.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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#include "utils.h"
#include "zxmgr.h"
#include <windows.h>
#include <GL/GL.h>
#ifndef GL_TEXTURE_RECTANGLE_ARB
#define GL_TEXTURE_RECTANGLE_ARB 0x84F5
#endif
#ifndef GL_BGRA
#define GL_BGRA 0x80E1
#endif
#ifndef GL_COMBINE
#define GL_COMBINE 0x8570
#endif
#ifndef GL_COMBINE_RGB
#define GL_COMBINE_RGB 0x8571
#endif
#ifndef GL_COMBINE_ALPHA
#define GL_COMBINE_ALPHA 0x8572
#endif
#ifndef GL_UNSIGNED_SHORT_5_6_5
#define GL_UNSIGNED_SHORT_5_6_5 0x8363
#endif
extern int rwid, rhei;
#pragma comment (lib, "opengl32")
unsigned short ddP[1310720];
bool r_openGLReady = false;
HDC r_hDC = 0;
HGLRC r_hRC = 0;
RECT r_viewport;
GLuint r_texture = 0;
void GL_SetViewport(int x, int y, int w, int h)
{
r_viewport.left = x;
r_viewport.top = y;
r_viewport.right = x+w;
r_viewport.bottom = y+h;
int y2 = rhei - (h + y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(x, y2, w, h);
glOrtho(x, x+w, y+h, y, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void _stdcall GL_ResetViewport()
{
GL_SetViewport(0, 0, rwid, rhei);
}
void _stdcall OpenGLProc()
{
unsigned short* pixelsPtr = *(unsigned short**)(0x0062571C);
if(!r_openGLReady)
{
HWND hWnd = zxmgr::GetHWND();
r_hDC = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 0;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat(r_hDC, &pfd);
SetPixelFormat(r_hDC, iFormat, &pfd);
r_hRC = wglCreateContext(r_hDC);
log_format("r_hDC = %08X, format = %d, r_hRC = %08X\n", r_hDC, iFormat, r_hRC);
//ReleaseDC(hWnd, r_hDC);
bool okay = wglMakeCurrent(r_hDC, r_hRC);
log_format("wglMakeCurrent = %02X\n", okay);
glEnable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// create main texture
glGenTextures(1, &r_texture);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, r_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, rwid, rhei, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixelsPtr);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
r_openGLReady = true;
}
wglMakeCurrent(r_hDC, r_hRC);
GL_ResetViewport();
if(r_texture)
{
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, r_texture);
glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, rwid, rhei, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, pixelsPtr);
glColor4ub(255, 255, 255, 255);
glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, 0);
glTexCoord2i(rwid, 0);
glVertex2i(rwid, 0);
glTexCoord2i(rwid, rhei);
glVertex2i(rwid, rhei);
glTexCoord2i(0, rhei);
glVertex2i(0, rhei);
glEnd();
glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
}
/*glBegin(GL_QUADS);
glColor4ub(0, 0, 255, 255);
glVertex2i(32, 32);
glVertex2i(32, 64);
glVertex2i(64, 64);
glVertex2i(64, 32);
glEnd();*/
SwapBuffers(r_hDC);
}
void __declspec(naked) old_sub_unlock()
{
__asm
{
push ebp
mov ebp, esp
push ecx
mov edx, 0x00631770
cmp dword ptr [edx], 0
mov eax, 0x00457FC3
jmp eax
}
}
unsigned short prevArrSaved[327680];
void _stdcall ConsoleProc(bool load, int locks)
{
if(locks > 1) return;
unsigned short* pixelsPtr = *(unsigned short**)(0x0062571C);
if(!load)
{
memcpy(prevArrSaved, pixelsPtr, 327680*2);
memset(pixelsPtr, 0, 327680*2);
}
else
{
memcpy(pixelsPtr, prevArrSaved, 327680*2);
}
}
void __declspec(naked) GL_blockOldUpdate1()
{
__asm
{
push ebp
mov ebp, esp
push ecx
mov edx, 0x00631770
cmp dword ptr [edx], 0
jz bou1_unlock
xor eax, eax
jmp bou1_exit
bou1_unlock:
mov edx, 0x0062565C
cmp dword ptr [edx], 0
jz bou1_break
push dword ptr [edx]
push 0
call ConsoleProc
mov eax, 0x0062571C
push dword ptr [eax]
mov ecx, 0x006256F0
mov ecx, [ecx]
mov edx, [ecx]
push ecx
call [edx+0x80]
neg eax
sbb eax, eax
inc eax
mov [ebp-0x04], eax
mov edx, 0x0062565C
dec dword ptr [edx]
// unlocked
mov edx, 0x0062565C
push dword ptr [edx]
push 1
call ConsoleProc
bou1_break:
mov eax, [ebp-0x04]
bou1_exit:
mov esp, ebp
pop ebp
retn
}
}
void __declspec(naked) GL_blockOldUpdate2()
{
__asm retn; // stub
}
void __declspec(naked) GL_blockOldUpdate3()
{
__asm retn; // stub
}
void __declspec(naked) GL_setFlags()
{
__asm retn; // stub
}