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 837 by alloc, Mon Apr 29 15:26:54 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_Config.h"
14  
15   #include "Oni.h"
16  
17   #include "Oni_GL.h"
18   #include "Daodan_GL.h"
19  
18 #include "Inifile_Reader.h"
19
20   HMODULE DDrDLLModule;
21   HMODULE DDrONiModule;
22  
23 bool patch_fonttexturecache = true;
24 bool patch_largetextures = true;
25 bool patch_levelplugins = true;
26 bool patch_pathfinding = true;
27 bool patch_projaware = true;
28 bool patch_directinput = true;
29 bool patch_wpfadetime = true;
30 bool patch_kickguns = false;
31 bool patch_cooldowntimer = true;
32 bool patch_throwtest = false;
33 bool patch_alttab = true;
34 bool patch_particledisablebit = false;
35 bool patch_multibyte = false;
36 bool patch_cheattable = true;
37 bool patch_argb8888 = true;
38 bool patch_killvtune = true;
39 bool patch_getcmdline = true;
40 bool patch_disablecmdline = true;
41 bool patch_optionsvisible = true;
42
43 bool patch_binkplay = true;
44 bool patch_safeprintf = true;
45 bool patch_daodandisplayenum = true;
46 bool patch_usegettickcount = true;
47 bool patch_cheatsenabled = true;
48 bool patch_usedaodangl = true;
49 bool patch_clipcursor = 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 bool opt_gamma = true;
58
23   typedef int (__cdecl *CHINESEPROC)(DWORD ThreadId);
60 bool patch_chinese = true;
61
24  
25   // Hooked WMrSlider_SetRange() in ONiOGU_Options_InitDialog. Disables a gamma
26   // slider in windowed mode.
# Line 82 | Line 44 | void ONICALL DDrShowOptionsButton(WMtWin
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()
# Line 345 | Line 346 | bool DDrPatch_Init()
346          // call with our hook function.
347          DDrPatch_MakeCall((void*)(OniExe + 0x000d262c), (void*)DD_ONiOGU_GammaSlider_SetRange);
348  
348        return true;
349 }
350
351
352 enum {s_unknown, s_options, s_patch, s_bsl, s_language} ini_section;
353
354 bool DDrIniCallback(char* section, bool newsection, char* name, char* value)
355 {
356        if (newsection)
357        {
358                if (!_stricmp(section, "options"))
359                        ini_section = s_options;
360                else if (!_stricmp(section, "patch"))
361                        ini_section = s_patch;
362                else if (!_stricmp(section, "bsl"))
363                        ini_section = s_bsl;
364                else if (!_stricmp(section, "language"))
365                        ini_section = s_language;
366                else
367                {
368                        ini_section = s_unknown;
369                        DDrStartupMessage("Daodan: Unrecognised ini section \"%s\"", section);
370                }
371        }
372        
373        switch (ini_section)
374        {
375                case s_options:
376                        if (!_stricmp(name, "usedaodanbsl"))
377                                opt_usedaodanbsl = !_stricmp(inifile_cleanstr(value), "true");
378                        else if (!_stricmp(name, "border"))
379                                opt_border = !_stricmp(inifile_cleanstr(value), "true");
380                        else if (!_stricmp(name, "topmost"))
381                                opt_topmost = !_stricmp(inifile_cleanstr(value), "true");
382                        else if (!_stricmp(name, "multibyte"))
383                                patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
384                        else if (!_stricmp(name, "debug"))
385                                AKgDebug_DebugMaps = !_stricmp(inifile_cleanstr(value), "true");
386                        else if (!_stricmp(name, "debugfiles"))
387                                BFgDebugFileEnable = !_stricmp(inifile_cleanstr(value), "true");
388                        else if (!_stricmp(name, "findsounds"))
389                                SSgSearchOnDisk = !_stricmp(inifile_cleanstr(value), "true");
390                        else if (!_stricmp(name, "ignore_private_data"))
391                                opt_ignore_private_data = !_stricmp(inifile_cleanstr(value), "true");
392                        else if (!_stricmp(name, "sound"))
393                                opt_sound = !_stricmp(inifile_cleanstr(value), "true");
394                        else if (!_stricmp(name, "switch"))
395                                M3gResolutionSwitch = !_stricmp(inifile_cleanstr(value), "true");
396                        else if (!_stricmp(name, "gamma"))
397                                opt_gamma = !_stricmp(inifile_cleanstr(value), "true");
398                        else
399                                DDrStartupMessage("Daodan: Unrecognised ini option \"%s\"", name);
400                        break;
401                case s_patch:
402                        if (!_stricmp(name, "fonttexturecache"))
403                                patch_fonttexturecache = !_stricmp(inifile_cleanstr(value), "true");
404                        else if (!_stricmp(name, "largetextures"))
405                                patch_largetextures = !_stricmp(inifile_cleanstr(value), "true");
406                        else if (!_stricmp(name, "levelplugins"))
407                                patch_levelplugins = !_stricmp(inifile_cleanstr(value), "true");
408                        else if (!_stricmp(name, "pathfinding"))
409                                patch_pathfinding = !_stricmp(inifile_cleanstr(value), "true");
410                        else if (!_stricmp(name, "projaware"))
411                                patch_projaware = !_stricmp(inifile_cleanstr(value), "true");
412                        else if (!_stricmp(name, "directinput"))
413                                patch_directinput = !_stricmp(inifile_cleanstr(value), "true");
414                        else if (!_stricmp(name, "wpfadetime"))
415                                patch_wpfadetime = !_stricmp(inifile_cleanstr(value), "true");
416                        else if (!_stricmp(name, "kickguns"))
417                                patch_kickguns = !_stricmp(inifile_cleanstr(value), "true");
418                        else if (!_stricmp(name, "cooldowntimer"))
419                                patch_cooldowntimer = !_stricmp(inifile_cleanstr(value), "true");
420                        else if (!_stricmp(name, "throwtest"))
421                                patch_throwtest = !_stricmp(inifile_cleanstr(value), "true");
422                        else if (!_stricmp(name, "alttab"))
423                                patch_alttab = !_stricmp(inifile_cleanstr(value), "true");
424                        else if (!_stricmp(name, "particledisablebit"))
425                                patch_particledisablebit = !_stricmp(inifile_cleanstr(value), "true");
426                        else if (!_stricmp(name, "multibyte"))
427                                patch_multibyte = !_stricmp(inifile_cleanstr(value), "true");
428                        else if (!_stricmp(name, "cheattable"))
429                                patch_cheattable = !_stricmp(inifile_cleanstr(value), "true");
430                        else if (!_stricmp(name, "argb8888"))
431                                patch_argb8888 = !_stricmp(inifile_cleanstr(value), "true");
432                        else if (!_stricmp(name, "killvtune"))
433                                patch_killvtune = !_stricmp(inifile_cleanstr(value), "true");
434                        else if (!_stricmp(name, "getcmdline"))
435                                patch_getcmdline = !_stricmp(inifile_cleanstr(value), "true");
436                        else if (!_stricmp(name, "disablecmdline"))
437                                patch_disablecmdline = !_stricmp(inifile_cleanstr(value), "true");
438                        else if (!_stricmp(name, "safeprintf"))
439                                patch_safeprintf = !_stricmp(inifile_cleanstr(value), "true");
440                        else if (!_stricmp(name, "daodandisplayenum"))
441                                patch_daodandisplayenum = !_stricmp(inifile_cleanstr(value), "true");
442                        else if (!_stricmp(name, "usegettickcount"))
443                                patch_usegettickcount = !_stricmp(inifile_cleanstr(value), "true");
444                        else if (!_stricmp(name, "cheatsenabled"))
445                                patch_cheatsenabled = !_stricmp(inifile_cleanstr(value), "true");
446                        else if (!_stricmp(name, "usedaodangl"))
447                                patch_usedaodangl = !_stricmp(inifile_cleanstr(value), "true");
448                        else if (!_stricmp(name, "clipcursor"))
449                                patch_clipcursor = !_stricmp(inifile_cleanstr(value), "true");
450                        else if (!_stricmp(name, "daodaninit"))
451                                patch_daodaninit = !_stricmp(inifile_cleanstr(value), "true");
452                        else if (!_stricmp(name, "bsl"))
453                                patch_bsl = !_stricmp(inifile_cleanstr(value), "true");
454                        else if (!_stricmp(name, "cheater"))
455                                patch_cheater = !_stricmp(inifile_cleanstr(value), "true");
456                        else if (!_stricmp(name, "newweap"))
457                                patch_newweapon = !_stricmp(inifile_cleanstr(value), "true");
458                        else if (!_stricmp(name, "optionsvisible"))
459                                patch_optionsvisible = !_stricmp(inifile_cleanstr(value), "true");
460                        else if (!_stricmp(name, "binkplay"))
461                                patch_binkplay = !_stricmp(inifile_cleanstr(value), "true");
462                        else
463                                DDrStartupMessage("Daodan: Unrecognised ini patch \"%s\"", name);
464                        break;
465                case s_language:
466                        if (!_stricmp(name, "chinese"))
467                                patch_chinese = true;
468                        else if (!_stricmp(name, "savepoint"))
469                        {
470                                char* str = _strdup(value);
471                                DDrPatch_Int32((int*)(OniExe + 0x000fd730), (int)str);
472                                DDrPatch_Int32((int*)(OniExe + 0x000fd738), (int)str);
473                        }
474                        else if (!_stricmp(name, "syndicatewarehouse"))
475                        {
476                                char* str = _strdup(value);
477                                DDrPatch_Int32((int*)(OniExe + 0x000fd71a), (int)str);
478                                DDrPatch_Int32((int*)(OniExe + 0x0010ef75), (int)str);
479                        }
480                        else if (!_stricmp(name, "damn"))
481                                DDrPatch__strdup((int*)(OniExe + 0x0010fb6e), value);
482                        else if (!_stricmp(name, "blam"))
483                                DDrPatch__strdup((int*)(OniExe + 0x0010fb73), value);
484                        else if (!_stricmp(name, "shapeshifter_on"))
485                                DDr_CheatTable[0].message_on = _strdup(value);
486                        else if (!_stricmp(name, "shapeshifter_off"))
487                                DDr_CheatTable[0].message_off = _strdup(value);
488                        else if (!_stricmp(name, "liveforever_on"))
489                                DDr_CheatTable[1].message_on = _strdup(value);
490                        else if (!_stricmp(name, "liveforever_off"))
491                                DDr_CheatTable[1].message_off = _strdup(value);
492                        else if (!_stricmp(name, "touchofdeath_on"))
493                                DDr_CheatTable[2].message_on = _strdup(value);
494                        else if (!_stricmp(name, "touchofdeath_off"))
495                                DDr_CheatTable[2].message_off = _strdup(value);
496                        else if (!_stricmp(name, "canttouchthis_on"))
497                                DDr_CheatTable[3].message_on = _strdup(value);
498                        else if (!_stricmp(name, "canttouchthis_off"))
499                                DDr_CheatTable[3].message_off = _strdup(value);
500                        else if (!_stricmp(name, "fatloot_on"))
501                                DDr_CheatTable[4].message_on = _strdup(value);
502                        else if (!_stricmp(name, "glassworld_on"))
503                                DDr_CheatTable[5].message_on = _strdup(value);
504                        else if (!_stricmp(name, "glassworld_off"))
505                                DDr_CheatTable[5].message_off = _strdup(value);
506                        else if (!_stricmp(name, "winlevel_on"))
507                                DDr_CheatTable[6].message_on = _strdup(value);
508                        else if (!_stricmp(name, "loselevel_on"))
509                                DDr_CheatTable[7].message_on = _strdup(value);
510                        else if (!_stricmp(name, "bighead_on"))
511                                DDr_CheatTable[8].message_on = _strdup(value);
512                        else if (!_stricmp(name, "bighead_off"))
513                                DDr_CheatTable[8].message_off = _strdup(value);
514                        else if (!_stricmp(name, "minime_on"))
515                                DDr_CheatTable[9].message_on = _strdup(value);
516                        else if (!_stricmp(name, "minime_off"))
517                                DDr_CheatTable[9].message_off = _strdup(value);
518                        else if (!_stricmp(name, "superammo_on"))
519                                DDr_CheatTable[10].message_on = _strdup(value);
520                        else if (!_stricmp(name, "superammo_off"))
521                                DDr_CheatTable[10].message_off = _strdup(value);
522                        else if (!_stricmp(name, "devmode_on"))
523                        {
524                                char* str = _strdup(value);
525                                DDr_CheatTable[11].message_on = str;
526                                DDr_CheatTable[cheat_x].message_on = str;
527                        }
528                        else if (!_stricmp(name, "devmode_off"))
529                        {
530                                char* str = _strdup(value);
531                                DDr_CheatTable[11].message_off = str;
532                                DDr_CheatTable[cheat_x].message_off = str;
533                        }
534                        else if (!_stricmp(name, "reservoirdogs_on"))
535                                DDr_CheatTable[12].message_on = _strdup(value);
536                        else if (!_stricmp(name, "reservoirdogs_off"))
537                                DDr_CheatTable[12].message_off = _strdup(value);
538                        else if (!_stricmp(name, "roughjustice_on"))
539                                DDr_CheatTable[13].message_on = _strdup(value);
540                        else if (!_stricmp(name, "roughjustice_off"))
541                                DDr_CheatTable[13].message_off = _strdup(value);
542                        else if (!_stricmp(name, "chenille_on"))
543                                DDr_CheatTable[14].message_on = _strdup(value);
544                        else if (!_stricmp(name, "chenille_off"))
545                                DDr_CheatTable[14].message_off = _strdup(value);
546                        else if (!_stricmp(name, "behemoth_on"))
547                                DDr_CheatTable[15].message_on = _strdup(value);
548                        else if (!_stricmp(name, "behemoth_off"))
549                                DDr_CheatTable[15].message_off = _strdup(value);
550                        else if (!_stricmp(name, "elderrune_on"))
551                                DDr_CheatTable[16].message_on = _strdup(value);
552                        else if (!_stricmp(name, "elderrune_off"))
553                                DDr_CheatTable[16].message_off = _strdup(value);
554                        else if (!_stricmp(name, "moonshadow_on"))
555                                DDr_CheatTable[17].message_on = _strdup(value);
556                        else if (!_stricmp(name, "moonshadow_off"))
557                                DDr_CheatTable[17].message_off = _strdup(value);
558                        else if (!_stricmp(name, "munitionfrenzy_on"))
559                                DDr_CheatTable[18].message_on = _strdup(value);
560                        else if (!_stricmp(name, "fistsoflegend_on"))
561                                DDr_CheatTable[19].message_on = _strdup(value);
562                        else if (!_stricmp(name, "fistsoflegend_off"))
563                                DDr_CheatTable[19].message_off = _strdup(value);
564                        else if (!_stricmp(name, "killmequick_on"))
565                                DDr_CheatTable[20].message_on = _strdup(value);
566                        else if (!_stricmp(name, "killmequick_off"))
567                                DDr_CheatTable[20].message_off = _strdup(value);
568                        else if (!_stricmp(name, "carousel_on"))
569                                DDr_CheatTable[21].message_on = _strdup(value);
570                        else if (!_stricmp(name, "carousel_off"))
571                                DDr_CheatTable[21].message_off = _strdup(value);
572                        else
573                                DDrStartupMessage("Daodan: Unrecognised ini language item \"%s\"", name);
574                        break;
575                case s_bsl:
576                default:
577                        break;
578        }
579        
580        return true;
581 }
582
583 void DDrConfig()
584 {
585
586        if (GetFileAttributes("daodan.ini") == INVALID_FILE_ATTRIBUTES)
587        {
588                FILE* fp;
589                DDrStartupMessage("Daodan: daodan.ini doesn't exist, creating");
590                fp = fopen("daodan.ini", "w");
591                if (fp)
592                {
593                        fputs("[Options]\n", fp);
594                        fclose(fp);
595                }
596        }
597        
598        DDrStartupMessage("Daodan: Parsing daodan.ini...");
599        if (!inifile_read("daodan.ini", DDrIniCallback))
600                DDrStartupMessage("Daodan: Error reading daodan.ini, check your syntax!");
601        DDrStartupMessage("Daodan: Finished parsing");
602 }
603
604 void ONICALL DDrGame_Init()
605 {
606        if (opt_usedaodanbsl)
607                SLrDaodan_Initialize();
608 }
609
610 void DDrException() {
611        int* i = 0;
612        *i = 1;
613 }
614 #include <stdio.h>
615
616 //this was broken
617 FILE** _UUgError_WarningFile = (FILE**)0x005711B4;
618 FILE *__fastcall DDrPrintWarning(int filename, int linenumber, unsigned __int16 errornum, int message)
619 {
620
621        FILE *v4; // eax@1
622        FILE *result; // eax@4
623        char v6[512]; // [sp+0h] [bp-100h]@1
624        FILE* UUgError_WarningFile = *_UUgError_WarningFile;
625
626        if (filename && message && (strlen((const char*)filename)+strlen((const char*)message))<420) {
627                sprintf(
628                        v6,
629                        "Error %x reported from File: %s, Line: %d (message follows) \r\n%s",
630                        errornum,
631                        (const char*)filename,
632                        linenumber,
633                        (const char*)message);
634
635                if ( UUgError_WarningFile
636                        || (UUgError_WarningFile = oni_fopen("debugger.txt", "wb"), UUgError_WarningFile ) )
637                {
638                        oni_fprintf(UUgError_WarningFile, "%s\r\n", v6);
639                        oni_fflush(UUgError_WarningFile);
640                }
641        }
642        //oni_fprintf(stdout, v6);
643        //sprintf(&v6, "%s", message);
644        *_UUgError_WarningFile = UUgError_WarningFile;
645        result = UUgError_WarningFile;
646        return result;
647 }
648
649 void __cdecl DDrMain(int argc, char* argv[])
650 {
651        int i;
652        char* section;
653        char* option;
654        bool falseoption;
655
656        DDrStartupMessage("Daodan: Daodan attached!");
657        
658        // Tell Oni to not load non levelX_final-files by default:
659        opt_ignore_private_data = false;
660
661        // Enable sound by default:
662        opt_sound = true;
663        
664        DDrConfig();
665        DDrStartupMessage("Daodan: Parsing command line...");
666        for (i = 1; i < argc; i ++)
667        {
668                if (argv[i][0] == '-')
669                {
670                        section = argv[i] + 1;
671                        if ((option = strchr(argv[i], '.')))
672                        {
673                                *option = '\0';
674                                falseoption = (option[1] == 'n' || option[1] == 'N') && (option[2] = 'o' || option[2] == 'O');
675                                if (i < (argc - 1) && argv[i + 1][0] != '-')
676                                        DDrIniCallback(section, true, option + 1, argv[++i]);
677                                else
678                                        DDrIniCallback(section, true, option + (falseoption ? 3 : 1), (falseoption ? "false" : "true"));
679                                *option = '.';
680                        }
681                        else
682                        {
683                                falseoption = (section[0] == 'n' || section[0] == 'N') && (section[1] = 'o' || section[1] == 'O');
684                                ini_section = s_options;
685                                if (i < (argc - 1) && argv[i + 1][0] != '-')
686                                        DDrIniCallback(NULL, false, section, argv[++i]);
687                                else
688                                        DDrIniCallback(NULL, false, section + (falseoption ? 2 : 0), (falseoption ? "false" : "true"));
689                        }
690                }
691                else
692                {
693                        DDrStartupMessage("Daodan: Parse error \"%s\"", argv[i]);
694                        break;
695                }
696        }
697        DDrStartupMessage("Daodan: Finished parsing");
698        DDrPatch_Init();
699        
349          // Safe startup message printer
350          if (patch_safeprintf)
351                  DDrPatch_MakeJump((void*)UUrStartupMessage, (void*)DDrStartupMessage);
# Line 785 | 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);
464   }

Diff Legend

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