ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/Daodan/src/Daodan.c
(Generate patch)

Comparing Daodan/src/Daodan.c (file contents):
Revision 694 by alloc, Fri Mar 8 00:31:30 2013 UTC vs.
Revision 838 by alloc, Mon Apr 29 16:29:16 2013 UTC

# Line 1 | Line 1
1   #include <windows.h>
2   #include <string.h>
3 + #include <stdio.h>
4  
5   #include "Daodan.h"
6   #include "Daodan_Patch.h"
# Line 9 | Line 10
10   #include "Daodan_Persistence.h"
11   #include "Daodan_BSL.h"
12   #include "Daodan_Console.h"
13 < #include "Daodan_WindowHack.h"
13 > #include "Daodan_Config.h"
14  
15   #include "Oni.h"
16  
17   #include "Oni_GL.h"
18   #include "Daodan_GL.h"
19  
19 #include "Inifile_Reader.h"
20
20   HMODULE DDrDLLModule;
21   HMODULE DDrONiModule;
22  
23 < bool patch_fonttexturecache = true;
25 < bool patch_largetextures = true;
26 < bool patch_levelplugins = true;
27 < bool patch_pathfinding = true;
28 < bool patch_projaware = true;
29 < bool patch_directinput = true;
30 < bool patch_wpfadetime = true;
31 < bool patch_kickguns = false;
32 < bool patch_cooldowntimer = true;
33 < bool patch_throwtest = false;
34 < bool patch_alttab = true;
35 < bool patch_particledisablebit = false;
36 < bool patch_multibyte = false;
37 < bool patch_cheattable = true;
38 < bool patch_argb8888 = true;
39 < bool patch_killvtune = true;
40 < bool patch_getcmdline = true;
41 < bool patch_disablecmdline = true;
42 < bool patch_optionsvisible = true;
43 <
44 < bool patch_safeprintf = true;
45 < bool patch_daodandisplayenum = true;
46 < bool patch_usegettickcount = true;
47 < bool patch_cheatsenabled = true;
48 < bool patch_usedaodangl = false;
49 < bool patch_windowhack = true;
50 < bool patch_daodaninit = true;
51 < bool patch_bsl = true;
52 < bool patch_cheater = true;
53 < bool patch_newweapon = true;
54 < bool opt_usedaodanbsl = true;
55 < bool opt_border = true;
56 < bool opt_topmost = false;
57 <
58 < typedef int (__cdecl *CHINESEPROC)(DWORD WINAPI);
59 < bool patch_chinese = false;
23 > typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
24  
25 <
26 <
27 < void ONICALL DDrShowResumeButton(int window, int visibility)
25 > // Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
26 > // slider in windowed mode.
27 > static void ONICALL DD_ONiOGU_GammaSlider_SetRange(WMtWindow* window, int min_value, int max_value)
28 > {
29 >        WMrWindow_SetEnabled(window, M3gResolutionSwitch && opt_gamma);
30 >        WMrSlider_SetRange(window, min_value, max_value);
31 > }
32 >
33 > void ONICALL DDrShowResumeButton(WMtWindow* window, int visibility)
34   {
35          if (visibility)
36                  WMrWindow_SetLocation(window, 150, 350);
# Line 69 | Line 39 | void ONICALL DDrShowResumeButton(int win
39  
40  
41   /* Options always visible patch */
42 < void ONICALL DDrShowOptionsButton(int window, int visibility)
42 > void ONICALL DDrShowOptionsButton(WMtWindow* window, int visibility)
43   {
44          WMrWindow_SetVisible(window, 1);
45   }
46  
47 + void ONICALL DDrGame_Init()
48 + {
49 +        if (opt_usedaodanbsl)
50 +                SLrDaodan_Initialize();
51 + }
52 +
53 +
54 + //this was broken
55 + FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
56 + FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
57 + {
58 +
59 +        FILE *v4; // eax@1
60 +        FILE *result; // eax@4
61 +        char v6[512]; // [sp+0h] [bp-100h]@1
62 +        FILE* UUgError_WarningFile = *_UUgError_WarningFile;
63 +
64 +        if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
65 +                sprintf(
66 +                        v6,
67 +                        "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
68 +                        errornum,
69 +                        (const char*)filename,
70 +                        linenumber,
71 +                        (const char*)message);
72 +
73 +                if ( UUgError_WarningFile
74 +                        || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
75 +                {
76 +                        oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
77 +                        oni_fflush(UUgError_WarningFile);
78 +                }
79 +        }
80 +        //oni_fprintf(stdout, v6);
81 +        //sprintf(&v6, "%s", message);
82 +        *_UUgError_WarningFile = UUgError_WarningFile;
83 +        result = UUgError_WarningFile;
84 +        return result;
85 + }
86  
87  
88   bool DDrPatch_Init()
89   {
90 <        DDrStartupMessage("patching engine");
90 >        DDrStartupMessage("Daodan: Patching engine");
91          
92          // Font texture cache doubled
93          if (patch_fonttexturecache)
# Line 207 | Line 216 | bool DDrPatch_Init()
216          //Test newweap patch
217          if (patch_newweapon) {
218                  
219 <                //Makes it always say "Recieved weapon_name."
219 >                //Makes it always say "Received weapon_name."
220                  //Needs check for loc_4DFC66
221                  //DDrPatch_NOOP((char*)(OniExe + 0x000E4DF8),2);
222  
# Line 254 | Line 263 | bool DDrPatch_Init()
263          
264          if(patch_chinese)
265          {
266 <                DDrStartupMessage("Loading chinese DLL");
258 <                HMODULE dll = LoadLibrary("xfhsm_oni.dll");
259 <                DWORD err = GetLastError();
260 <                DDrStartupMessage(" - Module loading returned error %i", err);
261 <                if( dll )
266 >                if (GetFileAttributes("xfhsm_oni.dll") != INVALID_FILE_ATTRIBUTES)
267                  {
268 <                        void* proc = GetProcAddress( dll, "InstallHook" );
269 <                        if(proc)
268 >                        HMODULE dll;
269 >                        DWORD err;
270 >
271 >                        DDrStartupMessage("Daodan: Loading chinese DLL");
272 >                        dll = LoadLibrary("xfhsm_oni.dll");
273 >                        err = GetLastError();
274 >                        if( dll )
275                          {
276 <                                ((CHINESEPROC)proc)(GetCurrentThreadId());
276 >                                void* proc = GetProcAddress( dll, "InstallHook" );
277 >                                if(proc)
278 >                                {
279 >                                        ((CHINESEPROC)proc)(GetCurrentThreadId());
280 >                                }
281 >                        } else {
282 >                                char msg[100];
283 >                                FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0, msg, 100, NULL);
284 >                                DDrStartupMessage("Daodan: Loading DLL failed with error %i: %s", err, msg);
285                          }
286                  }
287          }
# Line 311 | Line 329 | bool DDrPatch_Init()
329                  DDrPatch_MakeCall((void*)(OniExe + 0x000d2d43), DDrShowResumeButton);
330          }
331  
332 <        return true;
333 < }
334 <
335 <
336 < enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
337 <
338 < bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
339 < {
340 <        if (newsection)
341 <        {
342 <                if (!_stricmp(section, "options"))
343 <                        ini_section = s_options;
344 <                else if (!_stricmp(section, "patch"))
345 <                        ini_section = s_patch;
346 <                else if (!_stricmp(section, "bsl"))
347 <                        ini_section = s_bsl;
330 <                else if (!_stricmp(section, "language"))
331 <                        ini_section = s_language;
332 <                else
333 <                {
334 <                        ini_section = s_unknown;
335 <                        DDrStartupMessage("unrecognised section \"%s\"", section);
336 <                }
337 <        }
338 <        
339 <        switch (ini_section)
340 <        {
341 <                case s_options:
342 <                        if (!_stricmp(name, "usedaodanbsl"))
343 <                                opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
344 <                        else if (!_stricmp(name, "border"))
345 <                                opt_border = !_stricmp(inifile_cleanstr(value), "true");
346 <                        else if (!_stricmp(name, "topmost"))
347 <                                opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
348 <                        else if (!_stricmp(name, "multibyte"))
349 <                                patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
350 <                        else if (!_stricmp(name, "debug"))
351 <                                AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true");
352 <                        else if (!_stricmp(name, "debugfiles"))
353 <                                BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true");
354 <                        else if (!_stricmp(name, "findsounds"))
355 <                                SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true");
356 <                        else if (!_stricmp(name, "ignore_private_data"))
357 <                                opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true");
358 <                        else if (!_stricmp(name, "sound"))
359 <                                opt_sound = !_stricmp(inifile_cleanstr(value), "true");
360 <                        else if (!_stricmp(name, "switch"))
361 <                                M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
362 <                        else
363 <                                DDrStartupMessage("unrecognised option \"%s\"", name);
364 <                        break;
365 <                case s_patch:
366 <                        if (!_stricmp(name, "fonttexturecache"))
367 <                                patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true");
368 <                        else if (!_stricmp(name, "largetextures"))
369 <                                patch_largetextures = !_stricmp(inifile_cleanstr(value), "true");
370 <                        else if (!_stricmp(name, "levelplugins"))
371 <                                patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true");
372 <                        else if (!_stricmp(name, "pathfinding"))
373 <                                patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true");
374 <                        else if (!_stricmp(name, "projaware"))
375 <                                patch_projaware = !_stricmp(inifile_cleanstr(value), "true");
376 <                        else if (!_stricmp(name, "directinput"))
377 <                                patch_directinput = !_stricmp(inifile_cleanstr(value), "true");
378 <                        else if (!_stricmp(name, "wpfadetime"))
379 <                                patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true");
380 <                        else if (!_stricmp(name, "kickguns"))
381 <                                patch_kickguns = !_stricmp(inifile_cleanstr(value), "true");
382 <                        else if (!_stricmp(name, "cooldowntimer"))
383 <                                patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true");
384 <                        else if (!_stricmp(name, "throwtest"))
385 <                                patch_throwtest = !_stricmp(inifile_cleanstr(value), "true");
386 <                        else if (!_stricmp(name, "alttab"))
387 <                                patch_alttab = !_stricmp(inifile_cleanstr(value), "true");
388 <                        else if (!_stricmp(name, "particledisablebit"))
389 <                                patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true");
390 <                        else if (!_stricmp(name, "multibyte"))
391 <                                patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
392 <                        else if (!_stricmp(name, "cheattable"))
393 <                                patch_cheattable = !_stricmp(inifile_cleanstr(value), "true");
394 <                        else if (!_stricmp(name, "argb8888"))
395 <                                patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true");
396 <                        else if (!_stricmp(name, "killvtune"))
397 <                                patch_killvtune = !_stricmp(inifile_cleanstr(value), "true");
398 <                        else if (!_stricmp(name, "getcmdline"))
399 <                                patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true");
400 <                        else if (!_stricmp(name, "disablecmdline"))
401 <                                patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true");
402 <                        else if (!_stricmp(name, "safeprintf"))
403 <                                patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true");
404 <                        else if (!_stricmp(name, "daodandisplayenum"))
405 <                                patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true");
406 <                        else if (!_stricmp(name, "usegettickcount"))
407 <                                patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true");
408 <                        else if (!_stricmp(name, "cheatsenabled"))
409 <                                patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
410 <                        else if (!_stricmp(name, "usedaodangl"))
411 <                                patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
412 <                        else if (!_stricmp(name, "windowhack"))
413 <                                patch_windowhack = !_stricmp(inifile_cleanstr(value), "true");
414 <                        else if (!_stricmp(name, "daodaninit"))
415 <                                patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
416 <                        else if (!_stricmp(name, "bsl"))
417 <                                patch_bsl = !_stricmp(inifile_cleanstr(value), "true");
418 <                        else if (!_stricmp(name, "cheater"))
419 <                                patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
420 <                        else if (!_stricmp(name, "newweap"))
421 <                                patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
422 <                        else if (!_stricmp(name, "optionsvisible"))
423 <                                patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true");
424 <                        else
425 <                                DDrStartupMessage("unrecognised patch \"%s\"", name);
426 <                        break;
427 <                case s_language:
428 <                        if (!_stricmp(name, "chinese"))
429 <                                patch_chinese = true;
430 <                        else if (!_stricmp(name, "savepoint"))
431 <                        {
432 <                                char* str = _strdup(value);
433 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd730), (int)str);
434 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd738), (int)str);
435 <                        }
436 <                        else if (!_stricmp(name, "syndicatewarehouse"))
437 <                        {
438 <                                char* str = _strdup(value);
439 <                                DDrPatch_Int32((int*)(OniExe + 0x000fd71a), (int)str);
440 <                                DDrPatch_Int32((int*)(OniExe + 0x0010ef75), (int)str);
441 <                        }
442 <                        else if (!_stricmp(name, "damn"))
443 <                                DDrPatch__strdup((int*)(OniExe + 0x0010fb6e), value);
444 <                        else if (!_stricmp(name, "blam"))
445 <                                DDrPatch__strdup((int*)(OniExe + 0x0010fb73), value);
446 <                        else if (!_stricmp(name, "shapeshifter_on"))
447 <                                DDr_CheatTable[0].message_on = _strdup(value);
448 <                        else if (!_stricmp(name, "shapeshifter_off"))
449 <                                DDr_CheatTable[0].message_off = _strdup(value);
450 <                        else if (!_stricmp(name, "liveforever_on"))
451 <                                DDr_CheatTable[1].message_on = _strdup(value);
452 <                        else if (!_stricmp(name, "liveforever_off"))
453 <                                DDr_CheatTable[1].message_off = _strdup(value);
454 <                        else if (!_stricmp(name, "touchofdeath_on"))
455 <                                DDr_CheatTable[2].message_on = _strdup(value);
456 <                        else if (!_stricmp(name, "touchofdeath_off"))
457 <                                DDr_CheatTable[2].message_off = _strdup(value);
458 <                        else if (!_stricmp(name, "canttouchthis_on"))
459 <                                DDr_CheatTable[3].message_on = _strdup(value);
460 <                        else if (!_stricmp(name, "canttouchthis_off"))
461 <                                DDr_CheatTable[3].message_off = _strdup(value);
462 <                        else if (!_stricmp(name, "fatloot_on"))
463 <                                DDr_CheatTable[4].message_on = _strdup(value);
464 <                        else if (!_stricmp(name, "glassworld_on"))
465 <                                DDr_CheatTable[5].message_on = _strdup(value);
466 <                        else if (!_stricmp(name, "glassworld_off"))
467 <                                DDr_CheatTable[5].message_off = _strdup(value);
468 <                        else if (!_stricmp(name, "winlevel_on"))
469 <                                DDr_CheatTable[6].message_on = _strdup(value);
470 <                        else if (!_stricmp(name, "loselevel_on"))
471 <                                DDr_CheatTable[7].message_on = _strdup(value);
472 <                        else if (!_stricmp(name, "bighead_on"))
473 <                                DDr_CheatTable[8].message_on = _strdup(value);
474 <                        else if (!_stricmp(name, "bighead_off"))
475 <                                DDr_CheatTable[8].message_off = _strdup(value);
476 <                        else if (!_stricmp(name, "minime_on"))
477 <                                DDr_CheatTable[9].message_on = _strdup(value);
478 <                        else if (!_stricmp(name, "minime_off"))
479 <                                DDr_CheatTable[9].message_off = _strdup(value);
480 <                        else if (!_stricmp(name, "superammo_on"))
481 <                                DDr_CheatTable[10].message_on = _strdup(value);
482 <                        else if (!_stricmp(name, "superammo_off"))
483 <                                DDr_CheatTable[10].message_off = _strdup(value);
484 <                        else if (!_stricmp(name, "devmode_on"))
485 <                        {
486 <                                char* str = _strdup(value);
487 <                                DDr_CheatTable[11].message_on = str;
488 <                                DDr_CheatTable[cheat_x].message_on = str;
489 <                        }
490 <                        else if (!_stricmp(name, "devmode_off"))
491 <                        {
492 <                                char* str = _strdup(value);
493 <                                DDr_CheatTable[11].message_off = str;
494 <                                DDr_CheatTable[cheat_x].message_off = str;
495 <                        }
496 <                        else if (!_stricmp(name, "reservoirdogs_on"))
497 <                                DDr_CheatTable[12].message_on = _strdup(value);
498 <                        else if (!_stricmp(name, "reservoirdogs_off"))
499 <                                DDr_CheatTable[12].message_off = _strdup(value);
500 <                        else if (!_stricmp(name, "roughjustice_on"))
501 <                                DDr_CheatTable[13].message_on = _strdup(value);
502 <                        else if (!_stricmp(name, "roughjustice_off"))
503 <                                DDr_CheatTable[13].message_off = _strdup(value);
504 <                        else if (!_stricmp(name, "chenille_on"))
505 <                                DDr_CheatTable[14].message_on = _strdup(value);
506 <                        else if (!_stricmp(name, "chenille_off"))
507 <                                DDr_CheatTable[14].message_off = _strdup(value);
508 <                        else if (!_stricmp(name, "behemoth_on"))
509 <                                DDr_CheatTable[15].message_on = _strdup(value);
510 <                        else if (!_stricmp(name, "behemoth_off"))
511 <                                DDr_CheatTable[15].message_off = _strdup(value);
512 <                        else if (!_stricmp(name, "elderrune_on"))
513 <                                DDr_CheatTable[16].message_on = _strdup(value);
514 <                        else if (!_stricmp(name, "elderrune_off"))
515 <                                DDr_CheatTable[16].message_off = _strdup(value);
516 <                        else if (!_stricmp(name, "moonshadow_on"))
517 <                                DDr_CheatTable[17].message_on = _strdup(value);
518 <                        else if (!_stricmp(name, "moonshadow_off"))
519 <                                DDr_CheatTable[17].message_off = _strdup(value);
520 <                        else if (!_stricmp(name, "munitionfrenzy_on"))
521 <                                DDr_CheatTable[18].message_on = _strdup(value);
522 <                        else if (!_stricmp(name, "fistsoflegend_on"))
523 <                                DDr_CheatTable[19].message_on = _strdup(value);
524 <                        else if (!_stricmp(name, "fistsoflegend_off"))
525 <                                DDr_CheatTable[19].message_off = _strdup(value);
526 <                        else if (!_stricmp(name, "killmequick_on"))
527 <                                DDr_CheatTable[20].message_on = _strdup(value);
528 <                        else if (!_stricmp(name, "killmequick_off"))
529 <                                DDr_CheatTable[20].message_off = _strdup(value);
530 <                        else if (!_stricmp(name, "carousel_on"))
531 <                                DDr_CheatTable[21].message_on = _strdup(value);
532 <                        else if (!_stricmp(name, "carousel_off"))
533 <                                DDr_CheatTable[21].message_off = _strdup(value);
534 <                        else
535 <                                DDrStartupMessage("unrecognised language item \"%s\"", name);
536 <                        break;
537 <                case s_bsl:
538 <                default:
539 <                        break;
540 <        }
541 <        
542 <        return true;
543 < }
544 <
545 < void DDrConfig()
546 < {
547 <
548 <        if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
549 <        {
550 <                FILE* fp;
551 <                DDrStartupMessage("daodan.ini doesn't exist, creating");
552 <                fp = fopen("daodan.ini", "w");
553 <                if (fp)
554 <                {
555 <                        fputs("[Options]\n", fp);
556 <                        fclose(fp);
557 <                }
558 <        }
559 <        
560 <        DDrStartupMessage("parsing daodan.ini...");
561 <        if (!inifile_read("daodan.ini", DDrIniCallback))
562 <                DDrStartupMessage("error reading daodan.ini, check your syntax!");
563 <        DDrStartupMessage("finished parsing");
564 < }
332 >        // Fix BinkBufferInit() call in BKrMovie_Play() to use GDI (DIB) blitting
333 >        // instead of DirectDraw; patch ONiRunGame to use the same method to play
334 >        // outro (ie., BKrMovie_Play() instead of ONrMovie_Play_Hardware() as the
335 >        // latter has problems on WINE).
336 >        if (patch_binkplay)
337 >        {
338 >                // push BINKBUFFERAUTO -> push BINKBUFFERDIBSECTION.
339 >                DDrPatch_Byte((void*)(OniExe + 0x0008829b + 1), 0x02);
340 >                // call ONrMovie_Play_Hardware -> call ONrMovie_Play
341 >                DDrPatch_MakeCall((void*)(OniExe + 0x000d496f), ONrMovie_Play);
342 >        }
343 >
344 >        // Patch a gamma slider in Options dialog (unconditionally).
345 >        // ONiOGU_Options_InitDialog: replace WMrSlider_SetRange(gammaSliderWindow, ...)
346 >        // call with our hook function.
347 >        DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
348  
566 void ONICALL DDrGame_Init()
567 {
568        if (opt_usedaodanbsl)
569                SLrDaodan_Initalize();
570 }
571
572 void DDrException() {
573        int* i = 0;
574        *i = 1;
575 }
576 #include <stdio.h>
577
578 //this was broken
579 FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
580 FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
581 {
582
583        FILE *v4; // eax@1
584        FILE *result; // eax@4
585        char v6[512]; // [sp+0h] [bp-100h]@1
586        FILE* UUgError_WarningFile = *_UUgError_WarningFile;
587
588        if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
589                sprintf(
590                        v6,
591                        "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
592                        errornum,
593                        (const char*)filename,
594                        linenumber,
595                        (const char*)message);
596
597                if ( UUgError_WarningFile
598                        || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
599                {
600                        oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
601                        oni_fflush(UUgError_WarningFile);
602                }
603        }
604        //oni_fprintf(stdout, v6);
605        //sprintf(&v6, "%s", message);
606        *_UUgError_WarningFile = UUgError_WarningFile;
607        result = UUgError_WarningFile;
608        return result;
609 }
610
611 void __cdecl DDrMain(int argc, char* argv[])
612 {
613        int i;
614        char* section;
615        char* option;
616        bool falseoption;
617
618        DDrStartupMessage("daodan attached!");
619        
620        // Tell Oni to not load non levelX_final-files by default:
621        opt_ignore_private_data = false;
622
623        // Enable sound by default:
624        opt_sound = true;
625        
626        DDrConfig();
627        DDrStartupMessage("parsing command line...");
628        for (i = 1; i < argc; i ++)
629        {
630                if (argv[i][0] == '-')
631                {
632                        section = argv[i] + 1;
633                        if ((option = strchr(argv[i], '.')))
634                        {
635                                *option = '\0';
636                                falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O');
637                                if (i < (argc - 1) && argv[i + 1][0] != '-')
638                                        DDrIniCallback(section, true, option + 1, argv[++i]);
639                                else
640                                        DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
641                                *option = '.';
642                        }
643                        else
644                        {
645                                falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O');
646                                ini_section = s_options;
647                                if (i < (argc - 1) && argv[i + 1][0] != '-')
648                                        DDrIniCallback(NULL, false, section, argv[++i]);
649                                else
650                                        DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
651                        }
652                }
653                else
654                {
655                        DDrStartupMessage("parse error \"%s\"", argv[i]);
656                        break;
657                }
658        }
659        DDrStartupMessage("finished parsing");
660        DDrPatch_Init();
661        
349          // Safe startup message printer
350          if (patch_safeprintf)
351                  DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
352          
353          // Daodan device mode enumeration function
354          if (patch_daodandisplayenum)
355 <                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)daodan_enumerate_valid_display_modes);
355 >                DDrPatch_MakeJump((void*)gl_enumerate_valid_display_modes, (void*)DD_GLrEnumerateDisplayModes);
356          
357          // Performance patch
358          if (patch_usegettickcount)
# Line 679 | Line 366 | void __cdecl DDrMain(int argc, char* arg
366          if (patch_cheatsenabled)
367                  DDrPatch_MakeJump((void*)ONrPersist_GetWonGame, (void*)DDrPersist_GetWonGame);
368  
369 <        // Windowed mode
369 >        // DaodanGL with windowed mode support.
370          if (patch_usedaodangl)
371          {
372 <                DDrPatch_NOOP((char*)(OniExe + 0x000032B7), 6);
373 <                DDrPatch_MakeCall((void*)(OniExe + 0x000032B7), (void*)LIiP_SetCursorPosHook);
374 <        
375 <                DDrPatch_NOOP((char*)(OniExe + 0x00003349), 6);
376 <                DDrPatch_MakeCall((void*)(OniExe + 0x00003349), (void*)LIiP_SetCursorPosHook);
377 <                DDrPatch_MakeJump((void*)ONrPlatform_Initialize, (void*)DDrPlatform_Initialize);
378 <                DDrPatch_MakeJump((void*)gl_platform_initialize, (void*)daodangl_platform_initialize);
379 <        }
380 <        // Hacked windowed mode (for when daodangl isn't working properly)
381 <        else if (patch_windowhack)
382 <                DDrWindowHack_Install();
372 >                // LIrPlatform_Mode_Set: GetWindowRect -> GetClientRect.
373 >                DDrPatch_NOOP((char*) OniExe + 0x00002dd6, 6);
374 >                DDrPatch_MakeCall((char*) OniExe + 0x00002dd6, (void*) GetClientRect);
375 >
376 >                // UUrWindow_GetSize: GetWindowRect -> GetClientRect.
377 >                DDrPatch_NOOP((char*) OniExe + 0x0002651c, 6);
378 >                DDrPatch_MakeCall((char*) OniExe + 0x0002651c, (void*) GetClientRect);
379 >
380 >                // LIrPlatform_PollInputForAction: fix GetCursorPos call to return client coordinates.
381 >                DDrPatch_NOOP((char*) OniExe + 0x000032cc, 6);
382 >                DDrPatch_MakeCall((char*) OniExe + 0x000032cc, (void*) DD_GetCursorPos);
383 >
384 >                // LIrPlatform_InputEvent_GetMouse: fix GetCursorPos call to return client coordinates.
385 >                DDrPatch_NOOP((char*) OniExe + 0x00002cc2, 6);
386 >                DDrPatch_MakeCall((char*) OniExe + 0x00002cc2, (void*) DD_GetCursorPos);
387 >
388 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
389 >                DDrPatch_NOOP((char*) OniExe + 0x000032b7, 6);
390 >                DDrPatch_MakeCall((char*) OniExe + 0x000032b7, (void*) DD_SetCursorPos);
391 >
392 >                // LIrPlatform_PollInputForAction: translate SetCursorPos position to screen coordinates.
393 >                DDrPatch_NOOP((char*) OniExe + 0x00003349, 6);
394 >                DDrPatch_MakeCall((char*) OniExe + 0x00003349, (void*) DD_SetCursorPos);
395 >
396 >                // Replace ONrPlatformInitialize.
397 >                DDrPatch_MakeJump((void*) ONrPlatform_Initialize, (void*) DD_ONrPlatform_Initialize);
398 >
399 >                // Replace gl_platform_initialize.
400 >                DDrPatch_MakeJump((void*) gl_platform_initialize, (void*) DD_GLrPlatform_Initialize);
401 >
402 >                // Replace gl_platform_dispose.
403 >                DDrPatch_MakeJump((void *) gl_platform_dispose, (void*) DD_GLrPlatform_Dispose);
404 >        }
405 >
406 >        if (patch_clipcursor)
407 >        {
408 >                // LIrMode_Set: replace LIrPlatform_Mode_Set call with our hook.
409 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003f9f), (void*) DD_LIrPlatform_Mode_Set);
410 >
411 >                // LIrMode_Set_Internal: replace LIrPlatform_Mode_Set call with our hook.
412 >                DDrPatch_MakeCall((void*)(OniExe + 0x00003fff), (void*) DD_LIrPlatform_Mode_Set);
413 >                
414 >                // LIrTermiante: replace LIrPlatform_Terminate call with our hook.
415 >                DDrPatch_MakeCall((void*)(OniExe + 0x000004cb8), (void*) DD_LIrPlatform_Terminate);
416 >        }
417 >
418          
419          if (patch_daodaninit)
420                  DDrPatch_MakeCall((void*)(OniExe + 0x000d345a), (void*)DDrGame_Init);
# Line 712 | Line 434 | void __cdecl DDrMain(int argc, char* arg
434          }
435  
436          DDrPatch_MakeJump((void*)(OniExe + 0x000245A0), (void*)DDrPrintWarning);
437 +
438 +
439 +        return true;
440 + }
441 +
442 +
443 + void DDrException() {
444 +        int* i = 0;
445 +        *i = 1;
446 + }
447 +
448 + void __cdecl DDrMain(int argc, char* argv[])
449 + {
450 +        DDrStartupMessage("Daodan: Daodan attached!");
451 +        
452 +        // Tell Oni to not load non levelX_final-files by default:
453 +        opt_ignore_private_data = false;
454 +
455 +        // Enable sound by default:
456 +        opt_sound = true;
457 +        
458 +        DDrConfig(argc, argv);
459 +
460 +        DDrPatch_Init();
461 +        
462          
463 <        ONiMain(argc, argv);
463 >        ONiMain(argc, argv);
464   }
465   /*
466   void DDrWrongExe()

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)