7
7
#define CRASHLOG OutputDebug (" %s::%d::%s\n " , __FILE__, __LINE__,__func__)
8
8
9
9
/*
10
- KURSE ALL SEEDS!
11
- Fushururu
12
- Are you with the Garden Master or Cid?
13
- >be non-human
14
- >pay a lot of money to build BalambGarden
15
- >after that some useless guy is the boss
16
- >no one knows about you
17
- >you are living in the basement
18
- >alone
19
-
20
- Yeah... So looks like money can't buy
21
- umm... well.. life? Hey, you are student
22
- in the garden built from my money
23
- and you were trained to be missionary
24
- and then you just walk in and kill me
25
- NICE JOB
10
+ Thomas the tank Engine
26
11
*/
27
12
28
13
/*
@@ -36,6 +21,7 @@ DWORD THIS_SIZE = 0;
36
21
DWORD OPENGL_HANDLE = 0 ;
37
22
const char * DIRECT_IO_EXPORT_DIR = " DEMASTER_EXP\\ " ;
38
23
std::unique_ptr<FILE, decltype(&fclose)> logFile{ nullptr , fclose };
24
+ void checkGlew ();
39
25
DWORD* tex_header = 0 ;
40
26
DWORD attr = -1 ;
41
27
DWORD DIRECT_IO_EXPORT_DIR_LEN = -1 ;
@@ -52,6 +38,10 @@ BOOL LINEAR_PATCH, OPENGL_HOOK;
52
38
int BATTLE_STAGE_ANIMATION_DELAY;
53
39
BOOL BATTLE_STAGE_FORCE_RELOAD;
54
40
41
+ static bool glewInitialized = false ;
42
+
43
+ static float frames = 0 .0f ;
44
+
55
45
void OutputDebug (const char * fmt, ...)
56
46
{
57
47
@@ -117,15 +107,103 @@ GLFWwindow* hookGlfwWindow(int width, int height, const char* title, GLFWmonitor
117
107
118
108
}
119
109
110
+ typedef void __stdcall _glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
111
+
112
+ static LPVOID oglViewport;
113
+
114
+ void * __stdcall hookGlViewport (GLint x, GLint y, GLsizei width, GLsizei height)
115
+ {
116
+ checkGlew ();
117
+ static bool backdoorUsed = false ;
118
+ if (glewInitialized && !backdoorUsed)
119
+ {
120
+ LPVOID test1 = __glewBufferData;
121
+ LPVOID test2 = glBufferData;
122
+ // Maki: PUT BACKDOORS FOR EXTENSIONS HERE
123
+
124
+ backdoorUsed = true ;
125
+ }
126
+
127
+ return ((void * (__stdcall*)(GLint, GLint, GLsizei, GLsizei))oglViewport)(x, y, width, height);
128
+ }
129
+
130
+ static LPVOID oglSwaPbuffers;
131
+
132
+ #define DEMFUNC (name,...) void * __stdcall hook##name##(##__VA_ARGS__##)
133
+
134
+ DEMFUNC (GlSwap, int );
135
+
136
+
137
+
120
138
121
- #define GETADDR (wntl ) IMAGE_BASE + GetAddress(##wntl)
122
139
void GetWindow ()
123
140
{
124
- unsigned int wndTitle = GETADDR (WINDOWTITLE);
141
+ unsigned int wndTitle = IMAGE_BASE + GetAddress (WINDOWTITLE);
125
142
_dllmainBackAddr2 = (DWORD)InjectJMP (wndTitle, (DWORD)_asm_ReplaceWindowTitle, 5 );
126
- wndTitle = wndTitle + 0x12 + (*(DWORD*)(GETADDR (WINDOWTITLE) + 0x12 )) + 4 ;
143
+ uint wndGlfw = wndTitle + 0x12 + (*(DWORD*)(IMAGE_BASE + GetAddress (WINDOWTITLE) + 0x12 )) + 4 ;
127
144
// MH_CreateHook((LPVOID)wndTitle, hookGlfwWindow, glfwWindowTrampoline);
128
- MH_CreateHook ((LPVOID)wndTitle, hookGlfwWindow, &glfwWindowTrampoline);
145
+ MH_CreateHook ((LPVOID)wndGlfw, hookGlfwWindow, &glfwWindowTrampoline); // Maki: We need trampoline here!
146
+ MH_STATUS hookApiViewport = MH_CreateHookApi (L" OPENGL32" , " glViewport" , hookGlViewport, &oglViewport);
147
+ }
148
+
149
+ // typedef void APIENTRY glClear(GLbitfield);
150
+ // typedef void (__stdcall * glClear)(GLbitfield);
151
+ // typedef void __stdcall * glClear(GLbitfield mask);
152
+ typedef void (__stdcall* oglClear)(GLbitfield);
153
+ typedef void (__stdcall* oglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
154
+ typedef void (__stdcall* oglBufferData)(GLenum target, GLsizeiptr size, const void * data, GLenum usage);
155
+
156
+ static oglClear _oglClear;
157
+ static oglClearColor _oglClearColor;
158
+ static oglBufferData _oglBufferData;
159
+
160
+ void __stdcall kglClear (GLbitfield mask)
161
+ {
162
+ _oglClear (mask);
163
+ }
164
+
165
+ void __stdcall kglClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
166
+ {
167
+ // _oglClearColor(red, green, 1.0f, 1.0f); //Maki: Try it :D
168
+ _oglClearColor (red, green, blue, alpha);
169
+
170
+ }
171
+
172
+ void __stdcall koglBufferData (GLenum target, GLsizeiptr size, const void * data, GLenum usage)
173
+ {
174
+ _oglBufferData (target, size, data, usage);
175
+ }
176
+
177
+ static LPVOID* oglBindBuffer;
178
+
179
+
180
+ // Maki: probably to be replaced by manual hook/minhook - it's just additional layer of doing the same things
181
+ // Maki: btw- this works on independent thread- so screw your context xD although they should share it naturally
182
+ int kieroThread ()
183
+ {
184
+ if (kiero::init (kiero::RenderType::OpenGL) == kiero::Status::Success)
185
+ {
186
+ // define KIERO_USE_MINHOOK must be 1
187
+ // the index of the required function can be found in the METHODSTABLE.txt
188
+ // kiero::bind(10, (void**)&_oglClear, kglClear); //Maki: This makes Nsight crash
189
+ // kiero::bind(12, (void**)&_oglClearColor, kglClearColor);
190
+ // kiero::bind(336, (void**)&_oglBufferData, koglBufferData);
191
+ // glewInit();
192
+ // auto testing = glBufferData;
193
+ // LPVOID orig;
194
+ // MH_CreateHook(glBufferData, koglBufferData, &orig);
195
+ // MH_EnableHook(MH_ALL_HOOKS);
196
+
197
+
198
+ // MH_CreateHook(bufferTest, koglBufferData, oglBindBuffer);
199
+ MH_EnableHook (MH_ALL_HOOKS);
200
+
201
+
202
+ // If you just need to get the function address you can use the kiero::getMethodsTable function
203
+ // _oglClear = (oglClear)kiero::getMethodsTable()[10];
204
+ }
205
+
206
+ return 0 ;
129
207
}
130
208
131
209
// DO NOT DELETE- it acts as an anchor for EFIGS.dll import
@@ -137,32 +215,6 @@ EXPORT void InitTest()
137
215
138
216
DWORD lastJMP;
139
217
140
- void DEB_JMP (char * c, DWORD a, DWORD b, DWORD cc, DWORD d, DWORD e)
141
- {
142
- if (c < (char *)IMAGE_BASE)
143
- return ;
144
- char localD[32 ];
145
- localD[0 ] = ' \0 ' ;
146
- sprintf (localD, " Wrong address at: %08x\n " , (unsigned int )c);
147
- if (IsBadReadPtr (c, 4 ))
148
- {
149
- __asm
150
- {
151
- // INT 3
152
- }
153
- return ;
154
- }
155
- if (*c == 183 )
156
- {
157
- __asm
158
- {
159
- INT 3
160
- }
161
- }
162
- OutputDebug (c, a, b, cc, d, e);
163
- return ;
164
- }
165
-
166
218
__declspec (naked) void nullsub()
167
219
{
168
220
__asm
@@ -208,6 +260,8 @@ void ReadConfigFile()
208
260
BATTLE_STAGE_FORCE_RELOAD = conf.GetInteger (" " , " BATTLE_STAGE_FORCE_RELOAD" , 0 );
209
261
}
210
262
263
+
264
+ // Maki: Why this doesn't work?
211
265
LONG WINAPI ExceptionHandler (EXCEPTION_POINTERS* ep)
212
266
{
213
267
DemasteredStackWalker sw;
@@ -229,25 +283,26 @@ LONG WINAPI ExceptionHandler(EXCEPTION_POINTERS* ep)
229
283
}
230
284
safe_bimg safe_bimg_init (bimg::ImageContainer* img)
231
285
{
232
- return { img, bimg::imageFree };
286
+ return {img, bimg::imageFree};
233
287
}
234
- safe_bimg LoadImageFromFile (const char * const filename)
235
- {
236
- static bool glewLoaded = false ;
237
288
238
- if (!glewLoaded)
239
- {
240
- glewLoaded = true ;
241
289
242
- // INIT GLEW - Add recent OpenGL extension support ( required for Texture Compression )
243
- GLenum err = glewInit ();
244
290
245
- if (GLEW_OK != err)
246
- {
247
- /* Problem: glewInit failed, something is seriously wrong. */
248
- OutputDebug (" %s - GLEW Error: %s\n " , __func__, glewGetErrorString (err));
249
- }
250
- }
291
+ void checkGlew ()
292
+ {
293
+ if (glewInitialized) return ;
294
+
295
+ glewInitialized = true ;
296
+ GLenum err = glewInit ();
297
+ if (GLEW_OK != err)
298
+ /* Problem: glewInit failed, something is seriously wrong. */
299
+ OutputDebug (" %s - GLEW Error: %s\n " , __func__, glewGetErrorString (err));
300
+
301
+ }
302
+
303
+ safe_bimg LoadImageFromFile (const char * const filename)
304
+ {
305
+ checkGlew ();
251
306
252
307
char msg[1024 ]{ 0 };
253
308
@@ -304,18 +359,15 @@ bool DDSorPNG(char* buffer, size_t in_size, const char* fmt, ...)
304
359
void RenderTexture (bimg::ImageContainer* img)
305
360
{
306
361
TextureFormatInfo& texInfo = s_textureFormat[img->m_format ];
307
- if (bimg::isCompressed (img->m_format ))
308
- {
309
- RenderCompressedTexture (img, texInfo);
310
- }
362
+ if (isCompressed (img->m_format ))
363
+ RenderCompressedTexture (img, texInfo);
311
364
else
312
- {
313
- RenderUncompressedTexture (img, texInfo);
314
- }
365
+ RenderUncompressedTexture (img, texInfo);
315
366
}
316
367
317
368
void RenderUncompressedTexture (bimg::ImageContainer* img, TextureFormatInfo& texInfo)
318
369
{
370
+ checkGlew ();
319
371
uint32_t width = img->m_width ;
320
372
uint32_t height = img->m_height ;
321
373
uint32_t depth = img->m_depth ;
@@ -328,7 +380,7 @@ void RenderUncompressedTexture(bimg::ImageContainer* img, TextureFormatInfo& tex
328
380
depth = 1 ;
329
381
330
382
bimg::ImageMip mip;
331
- if (bimg:: imageGetRawData (*img, 0 , lod + startLod, img->m_data , img->m_size , mip))
383
+ if (imageGetRawData (*img, 0 , lod + startLod, img->m_data , img->m_size , mip))
332
384
glTexImage2D (GL_TEXTURE_2D, lod, texInfo.m_internalFmt , img->m_width , img->m_height , 0 , texInfo.m_fmt , texInfo.m_type , mip.m_data );
333
385
}
334
386
}
@@ -357,64 +409,6 @@ void RenderCompressedTexture(bimg::ImageContainer* img, TextureFormatInfo& texIn
357
409
OutputDebug (" Texture is compressed, but compression is not supported on your GPU. Skipping draw." );
358
410
}
359
411
360
- // typedef void APIENTRY glClear(GLbitfield);
361
- // typedef void (__stdcall * glClear)(GLbitfield);
362
- // typedef void __stdcall * glClear(GLbitfield mask);
363
- typedef void (__stdcall* oglClear)(GLbitfield);
364
- typedef void (__stdcall* oglClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
365
- typedef void (__stdcall* oglBufferData)(GLenum target, GLsizeiptr size, const void * data, GLenum usage);
366
-
367
- static oglClear _oglClear;
368
- static oglClearColor _oglClearColor;
369
- static oglBufferData _oglBufferData;
370
-
371
- void __stdcall kglClear (GLbitfield mask)
372
- {
373
- _oglClear (mask);
374
- }
375
-
376
- void __stdcall kglClearColor (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
377
- {
378
- // _oglClearColor(red, green, 1.0f, 1.0f); //Maki: Try it :D
379
- _oglClearColor (red, green, blue, alpha);
380
-
381
- }
382
-
383
- void __stdcall koglBufferData (GLenum target, GLsizeiptr size, const void * data, GLenum usage)
384
- {
385
- _oglBufferData (target, size, data, usage);
386
- }
387
-
388
- static LPVOID* oglBindBuffer;
389
-
390
-
391
- int kieroThread ()
392
- {
393
- if (kiero::init (kiero::RenderType::OpenGL) == kiero::Status::Success)
394
- {
395
- // define KIERO_USE_MINHOOK must be 1
396
- // the index of the required function can be found in the METHODSTABLE.txt
397
- kiero::bind (10 , (void **)&_oglClear, kglClear);
398
- kiero::bind (12 , (void **)&_oglClearColor, kglClearColor);
399
- // kiero::bind(336, (void**)&_oglBufferData, koglBufferData);
400
- // glewInit();
401
- // auto testing = glBufferData;
402
- // LPVOID orig;
403
- // MH_CreateHook(glBufferData, koglBufferData, &orig);
404
- // MH_EnableHook(MH_ALL_HOOKS);
405
-
406
-
407
- // MH_CreateHook(bufferTest, koglBufferData, oglBindBuffer);
408
- MH_EnableHook (MH_ALL_HOOKS);
409
-
410
-
411
- // If you just need to get the function address you can use the kiero::getMethodsTable function
412
- // _oglClear = (oglClear)kiero::getMethodsTable()[10];
413
- }
414
-
415
- return 0 ;
416
- }
417
-
418
412
BOOL WINAPI DllMain (
419
413
420
414
HINSTANCE hinstDLL, // handle to DLL module
0 commit comments