-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathChitem.cpp
8033 lines (7351 loc) · 208 KB
/
Chitem.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// chitem.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include <fcntl.h>
#include <sys/stat.h>
#include <direct.h>
#include <process.h>
#include <mmsystem.h>
#include <math.h>
#include "2da.h"
#include "chitem.h"
#include "chitemDlg.h"
#include "zlib.h"
#include "acmsound.h"
#include "options.h"
#include "utf8.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define BLOCKSIZE 8192
UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);
//globally used constants
const unsigned char xorblock[64]={
0x88,0xA8,0x8F,0xBA,0x8A,0xD3,0xB9,0xF5,0xED,0xB1,0xCF,0xEA,0xAA,
0xE4,0xB5,0xFB,0xEB,0x82,0xF9,0x90,0xCA,0xC9,0xB5,0xE7,0xDC,0x8E,
0xB7,0xAC,0xEE,0xF7,0xE0,0xCA,0x8E,0xEA,0xCA,0x80,0xCE,0xC5,0xAD,
0xB7,0xC4,0xD0,0x84,0x93,0xD5,0xF0,0xEB,0xC8,0xB4,0x9D,0xCC,0xAF,
0xA5,0x95,0xBA,0x99,0x87,0xD2,0x9D,0xE3,0x91,0xBA,0x90,0xCA,
};
const unsigned short objrefs[NUM_OBJTYPE+1]={
0,REF_2DA,REF_ACM,REF_ARE,REF_BAM,REF_BCS,REF_BIO,REF_BMP,REF_CHR,REF_CHU,//9
REF_CRE,REF_DLG,REF_EFF,REF_GAM,REF_IDS,REF_INI,REF_ITM,REF_MOS,REF_MUS,//18
REF_MVE,REF_PLT,REF_PRO,REF_SPL,REF_SRC,REF_STO,REF_TIS,REF_VEF,REF_VVC,//27
REF_WAV,REF_WED,REF_WFX,REF_WMP,REF_FNT,REF_SQL,REF_GUI,REF_WBM, //35
REF_PVRZ,REF_GLSL, //37
};
const CString objexts[NUM_OBJTYPE+1]={
".*",".2da",".acm",".are",".bam",".bcs",".bio",".bmp",".chr",".chu",".cre",".dlg",//10
".eff",".gam",".ids",".ini",".itm",".mos",".mus",".mve",".plt",".pro",//20
".spl",".src",".sto",".tis",".vef",".vvc",".wav",".wed",".wfx",".wmp",//30
".fnt",".sql",".gui", ".wbm", ".pvrz", ".glsl" //34
};
const CString savedexts[]={".are",".sto",".tot",".toh","",
};
char tbgext[NUM_OBJTYPE+1]={
0,'r',0,'a',0,'b',0,0,'c','h','c','d',//10 chr is the same as cre
'e','n',0,0,'-',0,0,0,0,'m', //20
's','p','t',0,0,0,0,0,0,'w', //30
0,0,0,0,0,0 //33
};
int idstrings[NUM_OBJTYPE+1]={IDS_UNKNOWN,IDS_2DA,IDS_MUSIC,IDS_AREA, //4
IDS_ANIMATION, IDS_SCRIPT, IDS_BIO, IDS_BITMAP,IDS_CHR, IDS_CHU,IDS_CREATURE, IDS_DIALOG,//10
IDS_EFFECT,IDS_GAME,IDS_IDS,IDS_INI,IDS_ITEM,//15
IDS_MOS,IDS_MUS,IDS_MOVIE,IDS_PLT,IDS_PRO, //20
IDS_SPELL,IDS_SRC,IDS_STORE,IDS_TILESET,IDS_VEF,IDS_VVC,IDS_WAV,IDS_WED,//28
IDS_WFX,IDS_WMP, IDS_FNT, IDS_SQL, IDS_GUI, IDS_WBM, IDS_PVRZ,IDS_GLSL};//34
int menuids[NUM_OBJTYPE+1]={0,ID_EDIT_2DA,0,ID_EDIT_AREA,//4
ID_EDIT_ANIMATION,ID_EDIT_SCRIPT,0, ID_EDIT_ANIMATION,ID_EDIT_CREATURE,ID_EDIT_CHUI,ID_EDIT_CREATURE,//9
ID_EDIT_DIALOG, ID_EDIT_EFFECT, ID_EDIT_GAMES,ID_EDIT_IDS,0,ID_EDIT_ITEM,//15
ID_EDIT_GRAPHICS,ID_EDIT_MUSICLIST,0,ID_EDIT_ANIMATION,ID_EDIT_PROJECTILE,//20
ID_EDIT_SPELL,0,ID_EDIT_STORE, ID_EDIT_TILESET, ID_EDIT_VEF, ID_EDIT_VVC, 0, ID_EDIT_AREA,//28
ID_EDIT_WFX, ID_EDIT_WORLDMAP, 0, 0, 0, 0, 0, 0,//33
};
char *tokenlist[]={"CHARNAME", "GABBER",
"BROTHERSISTER","PRO_BROTHERSISTER","PROTAGONIST_BROTHERSISTER",
"GIRLBOY","PRO_GIRLBOY","PROTAGONIST_GIRLBOY",
"HESHE","PRO_HESHE","PROTAGONIST_HESHE",
"HIMHER","PRO_HIMHER","PROTAGONIST_HIMHER",
"HISHER","PRO_HISHER","PROTAGONIST_HISHER",
"LADYLORD","PRO_LADYLORD","PROTAGONIST_LADYLORD",
"MALEFEMALE","PRO_MALEFEMALE","PROTAGONIST_MALEFEMALE",
"MANWOMAN","PRO_MANWOMAN","PROTAGONIST_MANWOMAN",
"RACE","PRO_RACE","PROTAGONIST_RACE",
"SIRMAAM","PRO_SIRMAAM","PROTAGONIST_SIRMAAM",
"SONDAUGHTER","PRO_SONDAUGHTER","PROTAGONIST_SONDAUGHTER",
"FIGHTERTYPE","MAGESCHOOL","EXPERIENCEAMOUNT","TARGET", "CASTSPELL",
"MINUTE","CLOCK_HOUR","CLOCK_MINUTE","CLOCK_AMPM",
"LEVEL", "DAYANDMONTH", "DAYNIGHT","DAYNIGHTALL","TM","YEAR","MONTH","GAMEDAY","GAMEDAYS",
"MONTHNAME","PLAYER1","PLAYER2","PLAYER3","PLAYER4","PLAYER5","PLAYER6","SURFACE_UNDERDARK",
"SERVERVERSION","CLIENTVERSION","script","DURATIONNOAND","DAMAGER","AMOUNT","DAMAGEE",
"WEAPONNAME","ITEMCOST","ITEMNAME","CurrentChapter","DAY","HP","EXPERIENCE","NEXTLEVEL",
"MINIMUM","MAXIMUM","number", "SPELLLEVEL","SPECIALABILITYNAME","DURATION","HOUR","CLASS",
"LEVELDIF","CREATURE","DOTS1","DOTS2","DOTS3","DOTS4","DOTS5", "RESOURCE", "XPPENALTY",
"HIT_POINTS","TYPE","RESISTED","KEY","OPERATION","PAGE","NUMPAGES","TARGETNAME","VALUE",
" \\", ".\\",//hack for a hack
0};
char BASED_CODE szFilterKey[] = "chitin.key|chitin.key|All files (*.*)|*.*||";
char BASED_CODE szFilterTbg[] = "Tbg files (*.tbg)|*.tbg|All files (*.*)|*.*||";
char BASED_CODE szFilterTp2[] = "Tp2 files (*.tp2)|*.tp2|All files (*.*)|*.*||";
char BASED_CODE szFilterWeidu[] = "Dialog source files (*.d)|*.d|All files (*.*)|*.*||";
char BASED_CODE szFilterDlg[] = "Dialog files (*.dlg)|*.dlg|All files (*.*)|*.*||";
char BASED_CODE szFilterWeiduAll[] = "Source files (*.d;*.baf)|*.d;*.baf|Dialog source files (*.d)|*.d|Script source files (*.baf)|*.baf|All files (*.*)|*.*||";
char BASED_CODE szFilterBifc[] = "Bifc files (*.bif)|*.bif|All files (*.*)|*.*||";
char BASED_CODE szFilterBif[] = "Biff files (*.bif)|*.bif|All files (*.*)|*.*||";
//decompiled path (in bgfolder)
CString DECOMPILED="script compiler\\decompiled";
//weidu logfile
CString WEIDU_LOG="dltcep.log";
//this is the dialog's self reference (so one can save the dialog at other names)
CString SELF_REFERENCE="********";
//deleted reference in tlk
CString DELETED_REFERENCE="*!*";
CString bg2_slot_names[SLOT_COUNT]={"0-Helmet","1-Armor","2-Shield","3-Gloves","4-L.Ring","5-R.Ring","6-Amulet",
"7-Belt","8-Boots","9-Weapon 1","10-Weapon 2","11-Weapon 3","12-Weapon 4","13-Quiver 1","14-Quiver 2",
"15-Quiver 3","16-Unknown","17-Cloak","18-Quick item 1","19-Quick item 2","20-Quick item 3",
"21-Inventory 1","22-Inventory 2","23-Inventory 3","24-Inventory 4","25-Inventory 5","26-Inventory 6",
"27-Inventory 7","28-Inventory 8","29-Inventory 9","30-Inventory 10","31-Inventory 11","32-Inventory 12",
"33-Inventory 13","34-Inventory 14","35-Inventory 15","36-Inventory 16","37-Magic"};
CString pst_slot_names[PST_SLOT_COUNT]={"0-L.Ear/Lens","1-Chest","2-Upper tattoo","3-R.Hand","4-L.Ring","5-R.Ring","6-R.Ear/Eye",
"7-R.Tattoo","8-Wrist","9-Weapon 1","10-Weapon 2","11-Weapon 3","12-Weapon 4","13-Quiver 1","14-Quiver 2",
"15-Quiver 3","16-Quiver 4","17-Quiver 5","18-Unknown","19-L.Tattoo","20-Quick item 1","21-Quick item 2","22-Quick item 3",
"23-Quick item 4","24-Quick item 5","25-Inventory 1","26-Inventory 2","27-Inventory 3","28-Inventory 4","29-Inventory 5","30-Inventory 6",
"31-Inventory 7","32-Inventory 8","33-Inventory 9","34-Inventory 10","35-Inventory 11","36-Inventory 12",
"37-Inventory 13","38-Inventory 14","39-Inventory 15","40-Inventory 16","41-Inventory 17","42-Inventory 18",
"43-Inventory 19","44-Inventory 20","45-Magic"};
CString iwd2_slot_names[IWD2_SLOT_COUNT]={"0-Helmet","1-Armor","2-Unknown","3-Gloves","4-L.Ring","5-R.Ring","6-Amulet",
"7-Belt","8-Boots","9-Weapon 1","10-Shield 1","11-Weapon 2","12-Shield 2","13-Weapon 3","14-Shield 3","15-Weapon 4","16-Shield 4",
"17-Quiver 1","18-Quiver 2","19-Quiver 3","20-Unknown","21-Cloak","22-Quick item 1","23-Quick item 2","24-Quick item 3",
"25-Inventory 1","26-Inventory 2","27-Inventory 3","28-Inventory 4","29-Inventory 5","30-Inventory 6",
"31-Inventory 7","32-Inventory 8","33-Inventory 9","34-Inventory 10","35-Inventory 11","36-Inventory 12",
"37-Inventory 13","38-Inventory 14","39-Inventory 15","40-Inventory 16",
"41-Inventory 17","42-Inventory 18","43-Inventory 19","44-Inventory 20","45-Inventory 21","46-Inventory 22",
"47-Inventory 23","48-Inventory 24","49-Magic"};
int itvs2h[NUM_ITEMTYPE]={
1,1,1,1,1,1,1,1,1,1,//9
1,1,1,1,1,2,1,1,1,1,3,//14
3,1,1,1,3,2,3,1,2,2,//1e
1,1,1,1,1,1,1,1,5,5,//28
5,5,5,5,5,5,5,5,5,//31
5,5,5,5,5,5,5,6, //39
5,5,5,5,5,5,5,5, //41
5,5,5,5,5,5,5,5 //49
};
//inifile
CString setupname;
CString bgfolder;
CString descpath;
CString weidupath;
CString weiduextra;
CString weidudecompiled;
CString language;
int logtype;
int tooltips;
int do_progress;
int readonly;
int whichdialog; //enable both dialogs
int choosedialog; //selected dialog
unsigned long chkflg;
unsigned long editflg;
unsigned long optflg;
unsigned long weiduflg;
unsigned long winsize;
COLORREF color1, color2, color3;
/// game objects
CString itemname;
CString lasterrormsg;
Citem the_item;
Cstore the_store;
Cproj the_projectile;
Cspell the_spell;
Ceffect the_effect;
Ccreature the_creature;
Cpvr the_pvr;
CVVC the_videocell;
CVEF the_vef;
CWFX the_wfx;
Cscript the_script;
Cdialog the_dialog;
Carea the_area;
Cbam the_bam;
Cgame the_game;
Cmap the_map;
Cmos the_mos;
C2da the_2da;
Cids the_ids;
Cmus the_mus;
Cchui the_chui;
Csrc the_src;
Cini the_ini;
long creature_strrefs[SND_SLOT_COUNT];
//2da, ids
CStringMapInt dial_references;
CStringList exclude_item;
CStringList masterareas;
CStringList xplist;
CStringList pro_references;
CStringList pro_titles;
CStringList beastnames;
CStringList beastkillvars;
CStringList spawngroup;
CStringMapInt rnditems; //this is the mapping for ignored items (random treasure)
CStringMapArray store_spell_desc;
CStringList sectype_names;
CStringList school_names;
CString2List songlist;
CStringList containericons;
int base_slot=35;
CStringMapInt internal_slot_names;
CString slot_names[IWD2_SLOT_COUNT]; //IWD2 has more slots
CString snd_slots[SND_SLOT_COUNT];
CString action_defs[MAX_ACTION];
CString trigger_defs[MAX_TRIGGER];
CStringMapCStringMapInt idsmaps; //this is a cstring map to a cstringmapint
CIntMapString listspells; //iwd2 spell list (number to resref mapping)
CIntMapString listdomains; //iwd2 domain spell list (number to resref mapping)
CIntMapString listinnates; //iwd2 innate list (number to resref mapping)
CIntMapString listsongs; //iwd2 song list (number to resref mapping)
CIntMapString listshapes; //iwd2 wildshape list (number to resref mapping)
CStringMapInt ini_entry; //acceptable spawn ini entries
CStringMapPoint entries; //entries.2da mapping
CIntMapInt statdesc; //portrait icon descriptions for certain effects
CStringList campaignrefs; //bgee campaign names
CColorPicker colordlg;
CItemPicker pickerdlg;
//tlk/chitin
tlk_header tlk_headerinfo[2];
tlk_entry *tlk_entries[2];
bool global_changed[2]; //tlk_entries have changed (need save)
int global_date[2];
key_header key_headerinfo;
membif_entry *bifs;
CString cds[NUM_CD];
CStringMapLocEntry items;//1
CStringMapLocEntry icons;//2
CStringMapLocEntry bitmaps;//3
CStringMapLocEntry creatures;//4
CStringMapLocEntry chars;//5
CStringMapLocEntry spells;//6
CStringMapLocEntry strings; //7
CStringMapLocEntry stores;//8
CStringMapLocEntry darefs;//9
CStringMapLocEntry idrefs;//10
CStringMapLocEntry dialogs;//11
CStringMapLocEntry scripts;//12
CStringMapLocEntry projects;//13
CStringMapLocEntry effects;//14
CStringMapLocEntry vvcs;//15
CStringMapLocEntry areas;//16
CStringMapLocEntry chuis;//17
CStringMapLocEntry mos;//18
CStringMapLocEntry weds;//19
CStringMapLocEntry tis;//20
CStringMapLocEntry sounds;//21
CStringMapLocEntry games;//22
CStringMapLocEntry wmaps;//23
CStringMapLocEntry musics;//24
CStringMapLocEntry musiclists;//25
CStringMapLocEntry movies;//26
CStringMapLocEntry wfxs;//27
CStringMapLocEntry paperdolls; //28
CStringMapLocEntry vefs; //29
CStringMapLocEntry inis; //30
CStringMapLocEntry fonts; //31
CStringMapLocEntry wbms; //32
CStringMapLocEntry sqls; //33
CStringMapLocEntry guis; //34
CStringMapLocEntry pvrzs; //35
CStringMapLocEntry bios; //36
CStringMapLocEntry glsl; //37
CStringListLocEntry d_items;//1
CStringListLocEntry d_icons;//2
CStringListLocEntry d_bitmaps;//3
CStringListLocEntry d_creatures;//4
CStringListLocEntry d_chars;//5
CStringListLocEntry d_spells;//6
CStringListLocEntry d_strings; //7
CStringListLocEntry d_stores;//8
CStringListLocEntry d_darefs;//9
CStringListLocEntry d_idrefs;//10
CStringListLocEntry d_dialogs;//11
CStringListLocEntry d_scripts;//12
CStringListLocEntry d_projects;//13
CStringListLocEntry d_effects;//14
CStringListLocEntry d_vvcs;//15
CStringListLocEntry d_areas;//16
CStringListLocEntry d_chuis;//17
CStringListLocEntry d_mos;//18
CStringListLocEntry d_weds;//19
CStringListLocEntry d_tis;//20
CStringListLocEntry d_sounds;//21
CStringListLocEntry d_games;//22
CStringListLocEntry d_wmaps;//23
CStringListLocEntry d_musics;//24
CStringListLocEntry d_musiclists;//25
CStringListLocEntry d_movies;//26
CStringListLocEntry d_wfxs;//27
CStringListLocEntry d_paperdolls; //28
CStringListLocEntry d_vefs; //29
CStringListLocEntry d_inis; //30
CStringListLocEntry d_fonts; //31
CStringListLocEntry d_wbms; //32
CStringListLocEntry d_sqls; //33
CStringListLocEntry d_guis; //34
CStringListLocEntry d_pvrz; //35
CStringListLocEntry d_bios; //36
CStringListLocEntry d_glsl; //37
CStringMapLocEntry *resources[NUM_OBJTYPE+1]={0,&darefs,&musics,
&areas, &icons, &scripts, &bios, &bitmaps, &chars, &chuis, &creatures,
&dialogs, &effects, &games, &idrefs, &inis, &items, &mos,
&musiclists, &movies,&paperdolls, &projects, &spells, &strings,
&stores, &tis, &vefs, &vvcs, &sounds, &weds, &wfxs, &wmaps,
&fonts, &sqls, &guis, &wbms, &pvrzs, &glsl
};
CStringListLocEntry *duplicates[NUM_OBJTYPE+1]={0,&d_darefs,&d_musics,
&d_areas, &d_icons, &d_scripts, &d_bios, &d_bitmaps, &d_chars, &d_chuis, &d_creatures,
&d_dialogs, &d_effects, &d_games, &d_idrefs, &d_inis, &d_items, &d_mos,
&d_musiclists, &d_movies, &d_paperdolls, &d_projects, &d_spells, &d_strings,
&d_stores,&d_tis, &d_vefs, &d_vvcs,&d_sounds, &d_weds, &d_wfxs, &d_wmaps,
&d_fonts, &d_sqls, &d_guis, &d_wbms, &d_pvrz, &d_glsl
};
CStringMapInt variables;
CIntMapJournal journals;
CStringMapString usedtis;
CStringMapString usedwed;
///
/////////////////////////////////////////////////////////////////////////////
// CChitemApp
BEGIN_MESSAGE_MAP(CChitemApp, CWinApp)
//{{AFX_MSG_MAP(CChitemApp)
//}}AFX_MSG
//ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChitemApp construction
CChitemApp::CChitemApp()
{
tooltips=1;
do_progress=1;
logtype=1;
readonly=1;
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CChitemApp object
CChitemApp theApp;
CStringMapGameProps allgameprops;
/////////////////////////////////////////////////////////////////////////////
// CChitemApp initialization
COLORREF CChitemApp::ParseColor(CString tmp)
{
COLORREF ret;
int cc; //color count
CString *colors;
colors=explode(tmp,',',cc);
if (cc!=3)
{
ret = 0;
}
else
{
ret = RGB(atoi(colors[0]), atoi(colors[1]), atoi(colors[2]) );
}
delete [] colors;
return ret;
}
void CChitemApp::read_game_preferences()
{
gameprops gp;
CString *games;
int count;
CString tmp;
char *poi;
poi=tmp.GetBuffer(MAX_PATH);
GetPrivateProfileString("settings","games","",poi,MAX_PATH,m_pszProfileName);
tmp.ReleaseBuffer(-1);
games=explode2(tmp,count);
allgameprops.RemoveAll();
allgameprops.InitHashTable(get_hash_size(count));
while(count--)
{
gp.checkopt=GetPrivateProfileInt(games[count],"check options",0,m_pszProfileName);
gp.editopt=GetPrivateProfileInt(games[count],"edit options",0,m_pszProfileName);
gp.gameopt=GetPrivateProfileInt(games[count],"game options",0,m_pszProfileName);
gp.winsize=GetPrivateProfileInt(games[count],"window size",0,m_pszProfileName);
if (gp.winsize<10) gp.winsize=10;
if (gp.winsize>32) gp.winsize=32;
poi=gp.bgfolder.GetBuffer(MAX_PATH);
GetPrivateProfileString(games[count],"game location","",poi,MAX_PATH,m_pszProfileName);
gp.bgfolder.ReleaseBuffer(-1);
poi=gp.descpath.GetBuffer(MAX_PATH);
GetPrivateProfileString(games[count],"external defs","",poi,MAX_PATH,m_pszProfileName);
gp.descpath.ReleaseBuffer(-1);
poi=gp.lang.GetBuffer(MAX_PATH);
GetPrivateProfileString(games[count],"language","",poi,MAX_PATH,m_pszProfileName);
gp.lang.ReleaseBuffer(-1);
allgameprops.SetAt(games[count],gp);
}
delete [] games;
}
int CChitemApp::select_setup(CString setupname)
{
gameprops gp;
if(allgameprops.Lookup(setupname, gp))
{
bgfolder=gp.bgfolder;
chkflg=gp.checkopt;
editflg=gp.editopt;
optflg=gp.gameopt;
descpath=gp.descpath;
language=gp.lang;
winsize=gp.winsize;
return 1;
}
return 0;
}
void CChitemApp::save_settings()
{
POSITION pos;
CString gname;
gameprops gp;
FILE *fpoi;
fpoi=fopen(m_pszProfileName,"wt");
if(!fpoi) return;
fprintf(fpoi,
"[Settings]\n"
"Current setup=%s\n" //1
"Logtype=%d\n" //2
"Progressbar=%d\n" //3
"Readonly=%d\n" //4
"Tooltips=%d\n" //5
"Window Size=%d\n", //6
setupname,logtype,do_progress,readonly,tooltips, winsize);
fprintf(fpoi,
"Check Options=%d\n" //1
"Edit Options=%d\n" //2
"Game Options=%d\n" //3
"Game Location=%s\n" //4
"Language=%s\n" //5
"External Defs=%s\n" //6
"WeiDU Options=%d\n" //7
"WeiDU Path=%s\n" //8
"WeiDU Extra=%s\n" //9
"WeiDU Outpath=%s\n", //10
chkflg,editflg, optflg,bgfolder, language, descpath, weiduflg, weidupath,weiduextra, weidudecompiled); //1-9
fprintf(fpoi,
"Color1=%d,%d,%d\n"
"Color2=%d,%d,%d\n"
"Color3=%d,%d,%d\n",
(BYTE)color1,(BYTE)(color1>>8),(BYTE)(color1>>16),
(BYTE)color2,(BYTE)(color2>>8),(BYTE)(color2>>16),
(BYTE)color3,(BYTE)(color3>>8),(BYTE)(color3>>16) );
pos=allgameprops.GetStartPosition();
fprintf(fpoi,"Games=");
while(pos)
{
allgameprops.GetNextAssoc(pos, gname, gp);
if(pos) fprintf(fpoi,"%s,",gname);
else fprintf(fpoi,"%s\n",gname);
}
pos=allgameprops.GetStartPosition();
while(pos)
{
allgameprops.GetNextAssoc(pos, gname, gp);
fprintf(fpoi,"[%s]\n"
"Check Options=%d\n"
"Edit Options=%d\n"
"Game Options=%d\n"
"Game Location=%s\n"
"Language=%s\n"
"External Defs=%s\n"
"Window Size=%d\n",
gname,gp.checkopt,gp.editopt,gp.gameopt,gp.bgfolder, gp.lang, gp.descpath, gp.winsize);
}
fclose(fpoi);
}
CString CChitemApp::MyParseCommandLine(char param)
{
int getnow=false;
for (int i = 1; i < __argc; i++)
{
CString pszParam(__targv[i]);
if(getnow) return pszParam;
if(pszParam[0]=='-' || pszParam[0]=='/')
{
switch(pszParam.GetLength())
{
case 1:
continue;
case 2:
if(pszParam[1]==param) getnow=true;
break;
default:
if(pszParam[1]==param) return pszParam.Mid(2);
}
}
}
return "";
}
BOOL CChitemApp::InitInstance()
{
char inifile[MAX_PATH];
m_bbmp.LoadBitmap(IDB_GETFILES);
_getcwd(inifile,MAX_PATH-20);
m_defpath=inifile;
strcat(inifile,"\\chitem.ini");
free((void*)m_pszProfileName);
m_pszProfileName=_tcsdup(_T(inifile));
read_game_preferences();
setupname=MyParseCommandLine('s');
if(!setupname.GetLength() || !select_setup(setupname) )
{
GetPrivateProfileString("settings","current setup","",inifile,MAX_PATH,m_pszProfileName);
inifile[MAX_PATH-1]=0;
setupname=inifile;
GetPrivateProfileString("settings","game location","",inifile,MAX_PATH,m_pszProfileName);//path
inifile[MAX_PATH-1]=0;
bgfolder=inifile;
GetPrivateProfileString("settings","language","",inifile,MAX_PATH,m_pszProfileName);//path
inifile[MAX_PATH-1]=0;
language=inifile;
GetPrivateProfileString("settings","external defs","",inifile,MAX_PATH,m_pszProfileName);//path
inifile[MAX_PATH-1]=0;
descpath=inifile;
chkflg=GetPrivateProfileInt("settings","check options",0,m_pszProfileName);
editflg=GetPrivateProfileInt("settings","edit options",0,m_pszProfileName);
optflg=GetPrivateProfileInt("settings","game options",0,m_pszProfileName);
}
tooltips=!!GetPrivateProfileInt("settings","tooltips",1,m_pszProfileName);
logtype=GetPrivateProfileInt("settings","logtype",1,m_pszProfileName);
do_progress=!!GetPrivateProfileInt("settings","progressbar",1,m_pszProfileName);
readonly=!!GetPrivateProfileInt("settings","readonly",1,m_pszProfileName);
weiduflg=GetPrivateProfileInt("settings","weidu options",0,m_pszProfileName);
winsize=GetPrivateProfileInt("settings","window size",10,m_pszProfileName);
GetPrivateProfileString("settings","weidu path","",inifile,MAX_PATH,m_pszProfileName);//path
inifile[MAX_PATH-1]=0;
weidupath=inifile;
GetPrivateProfileString("settings","weidu extra","",inifile,MAX_PATH,m_pszProfileName); //not a path
inifile[MAX_PATH-1]=0;
weiduextra=inifile;
GetPrivateProfileString("settings","weidu outpath","",inifile,MAX_PATH,m_pszProfileName); //partial path
inifile[MAX_PATH-1]=0;
weidudecompiled=inifile;
if(weidudecompiled.IsEmpty()) weidudecompiled=DECOMPILED;
GetPrivateProfileString("settings","color1","0,255,0",inifile,MAX_PATH,m_pszProfileName);
color1=ParseColor(inifile);
GetPrivateProfileString("settings","color2","255,0,0",inifile,MAX_PATH,m_pszProfileName);
color2=ParseColor(inifile);
GetPrivateProfileString("settings","color3","0,0,255",inifile,MAX_PATH,m_pszProfileName);
color3=ParseColor(inifile);
LoadStdProfileSettings( ); //recent files
// SetDialogBkColor(RGB(180,192,192),RGB(32,32,32) ); //sets the background/text color of the forms
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// AfxEnableControlContainer();
AfxInitRichEdit();
// LoadAccelerators(theApp.m_hInstance,IDR_SHORTCUT);
CChitemDlg dlg;
m_pMainWnd = &dlg;
dlg.DoModal();
return FALSE;
}
int nop()
{
return 0;
}
//returns the first prime after num for hash table size
int incrementTable[] =
{10, 2, 10, 2, 4, 2, 4, 6, 2, 6,
4, 2, 4, 6, 6, 2, 6, 4, 2, 6,
4, 6, 8, 4, 2, 4, 2, 4, 8, 6,
4, 6, 2, 4, 6, 2, 6, 6, 4, 2,
4, 6, 2, 6, 4, 2, 4, 2, 4, 2,
2};
unsigned long get_hash_size(unsigned long num)
{
unsigned long p;
unsigned long cx;
long bp;
unsigned long dx;
unsigned long axbx;
p=num|1;
if(p<17) return 17;
while(p<0xffffffff)
{
cx=3;
bp=51;
do
{
dx=p%cx;
axbx=p/cx;
if(!dx) break;
if(axbx<cx) return p;
if (--bp < 0)
{
bp = 47;
}
cx+=incrementTable[bp];
}
while(1);
p+=2;
}
return 17;
}
int strtonum(CString str)
{
int len;
len=str.GetLength()-2;
if((len>0) && (str[0]=='0') && ((str[1]=='x') || (str[1]=='X')) )
{
return (int) strtoul(str.Right(len),0,16);
}
else return atoi(str);
}
bool invalidnumber(CString tmpstr)
{
if(strtonum(tmpstr)!=0) return false;
if((tmpstr.GetLength()==1) && (tmpstr[0]=='0')) return false;
if(tmpstr.GetLength()>2)
{
if(tmpstr[0]=='0' && tmpstr[1]=='x') return false;
}
return true;
}
//this code will break up lines stuck together, if possible
CString consolidate(char *poi, int textlength)
{
int space, crlf;
int bracket, neednewline;
int newp, oldp;
CString tmpstr;
char *newpoi;
newpoi=tmpstr.GetBufferSetLength(textlength*2);
newp=0;
crlf=0; //eat crlf by default
space=0; //eat spaces by default
bracket=0;
neednewline=0;
for(oldp=0;oldp<textlength;oldp++)
{
switch(poi[oldp])
{
case ')':
newpoi[newp++]=poi[oldp];
if(bracket)
{
bracket--;
if(!bracket) neednewline=1;
}
break;
case '(':
newpoi[newp++]=poi[oldp];
bracket++;
break;
case '\"':
newpoi[newp++]=poi[oldp];
if(editflg&EATSPACE)
{
space=!space; //toggle space, don't eat spaces in strings
}
break;
case ' ':
if(space)
{
newpoi[newp++]=poi[oldp];
}
break;
case '\r': case '\n':
if(crlf)
{
newpoi[newp++]='\n';
crlf=0;
space=0; //eat spaces after crlf, despite of a possibly open quote
}
bracket=0;
neednewline=0;
break;
default:
if(neednewline)
{
newpoi[newp++]='\n';
neednewline=0;
}
//don't do tolower here, we might want to edit dialogs, and users like caps
newpoi[newp++]=poi[oldp];
crlf=1; //allow one crlf now
break;
}
}
newpoi[newp]=0;
tmpstr.ReleaseBuffer(newp);
return tmpstr;
}
int WriteString(FILE *fpoi, CString mystring)
{
if(fprintf(fpoi,"%s",mystring) !=mystring.GetLength()) return -1;
return 0;
}
int member_array(int member, int *array)
{
int i;
i=0;
while(array[i]!=-1)
{
if(member==array[i]) return i;
i++;
}
return -1;
}
bool checkfile(CString fname, CString magic)
{
int fhandle;
bool ret;
char tmp[4];
if(magic.GetLength()>4) abort();
fhandle=open(fname,O_BINARY|O_RDONLY);
if(fhandle<1) return false;
memset(tmp,0,sizeof(tmp));
read(fhandle,tmp,sizeof(tmp));
ret=!memcmp(tmp,magic,magic.GetLength());
close(fhandle);
return ret;
}
bool file_exists(CString filename)
{
struct _stat the_stat;
int x;
the_stat.st_mode=0;
x=_stat(filename, &the_stat);
if(the_stat.st_mode&_S_IFDIR) return false; //it is a directory
return x!=-1;
}
long file_length(CString filename)
{
struct _stat the_stat;
int x;
the_stat.st_mode=0;
x=_stat(filename, &the_stat);
if(x==-1) return -1;
return(the_stat.st_size); //it is a directory
}
long file_date(CString filename)
{
struct _stat the_stat;
int x;
the_stat.st_mode=0;
x=_stat(filename, &the_stat);
if(x==-1) return -1;
return(the_stat.st_mtime); //it is a directory
}
// windows shell is useless
// some versions can't handle executable names in apostrophe, but they let you specify
// spaces in pathnames.
// simulating the system() function, breaking down syscommand into an argv structure
#define MAX_PAR 20
int my_system(CString syscommand)
{
CString cmd;
int maxlen;
char *poi;
char *argv[MAX_PAR];
int ret;
int apo, space;
int argc;
printf("Executing:%s\n",syscommand);
maxlen=syscommand.GetLength();
poi=syscommand.GetBuffer(0);
apo=0;
space=1;
argc=0;
while(*poi)
{
switch(*poi)
{
case ' ':
if(!apo)
{
*poi=0;
space=1;
}
break;
case '"':
if(!argc || (apo==argc) )
{
if(apo)
{
*poi=0;
}
apo=!apo;
break;
}
apo=!apo;
default:
if(space)
{
argv[argc++]=poi;
space=0;
}
}
poi++;
}
argv[argc]=NULL;
//even more hacks for this damn stuff
cmd=argv[0];
argv[0]="DLTCEP_enhanced_WeiDU";
ret=spawnv(_P_WAIT, cmd, argv);
return ret;
}
bool dir_exists(CString filename)
{
struct _stat the_stat;
int x;
the_stat.st_mode=0;
x=_stat(filename, &the_stat);
if(x) return false;
if(the_stat.st_mode&_S_IFDIR) return true;
return false;
}
bool assure_dir_exists(CString filename)
{
int len, pos;
CString temp;
pos=1;
do
{
len=filename.Find('\\',pos);
if(len<0) temp = filename;
else
{
pos=len+1;
temp = filename.Left(len);
}
mkdir(temp);
}
while(len>0);
return dir_exists(filename);
}
//removes files from a sav and copies it
int remove_from_sav(CString key, CString ext, int finput, int &maxlen, int fhandle)
{
sav_entry saventry;
CString filename;
CString tmpstr;
char *poi1;
long oflg;
int ret;
if(finput<1)
{
return -1;
}
if(fhandle<1)
{
return -1;
}
if(!maxlen) return 1; //end
if(maxlen<sizeof(oflg)) return -2;
if(read(finput,&oflg,sizeof(oflg) )!=sizeof(oflg) )
{
return -2;
}
if(oflg>200) return -2;
poi1=saventry.filename.GetBufferSetLength(oflg+1);
if(read(finput,poi1,oflg)!=oflg)
{
return -2;
}
saventry.filename.ReleaseBuffer(-1);
saventry.filename.MakeUpper();
if(read(finput, &saventry.uncompressed, sizeof(long)*2 )!=sizeof(long)*2 )
{
return -2;
}
maxlen-=oflg+sizeof(oflg)+2*sizeof(long)+saventry.compressed;
itemname=saventry.filename.Left(saventry.filename.Find('.'));
if(!key.IsEmpty() && !ext.IsEmpty()) {
if((itemname.Find(key,0)!=-1) && !saventry.filename.Right(4).CompareNoCase(ext) )
{
lseek(finput,saventry.compressed,SEEK_CUR);
return 2; //no match
}
}
else
{
if(!key.IsEmpty() && (itemname.Find(key,0)!=-1) )
{
lseek(finput,saventry.compressed,SEEK_CUR);
return 2; //no match
}
if(!ext.IsEmpty() && !saventry.filename.Right(4).CompareNoCase(ext) )
{
lseek(finput,saventry.compressed,SEEK_CUR);
return 2; //no match
}
}
oflg=saventry.filename.GetLength()+1;
//string length
if(write(fhandle,&oflg,sizeof(oflg) )!=sizeof(oflg) )
{
return -4;
}
//string
if(write(fhandle,saventry.filename,oflg)!=oflg)
{
return -4;
}
//sizes
if(write(fhandle,&saventry.uncompressed, sizeof(long)*2 )!=sizeof(long)*2 )
{
return -4;
}