Repository navigation
Expand file tree
/
Copy pathCascRootFile_MNDX.cpp
More file actions
2981 lines (2548 loc) · 103 KB
/
Copy pathCascRootFile_MNDX.cpp
File metadata and controls
2981 lines (2548 loc) · 103 KB
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
/*****************************************************************************/
/* CascRootFile_MNDX.cpp Copyright (c) Ladislav Zezula 2014 */
/*---------------------------------------------------------------------------*/
/* Common functions for CascLib */
/* Note: "HOTS" refers to Play.exe, v2.5.0.29049 (Heroes of the Storm Alpha) */
/*---------------------------------------------------------------------------*/
/* Date Ver Who Comment */
/* -------- ---- --- ------- */
/* 18.05.14 1.00 Lad The first version of CascRootFile_MNDX.cpp */
/*****************************************************************************/
#define __CASCLIB_SELF__
#include "CascLib.h"
#include "CascCommon.h"
//-----------------------------------------------------------------------------
// Local defines
#define MNDX_MAR_SIGNATURE 0x0052414d // 'MAR\0'
#define MAR_PACKAGE_NAMES 0 // MAR with package names only
#define MAR_STRIPPED_NAMES 1 // MAR with names where packages were stripped
#define MAR_FULL_NAMES 2 // MAR with full file names
#define MAR_COUNT 3 // Maximum of 3 MAR files are supported
#define MNDX_SEARCH_INITIALIZING 0
#define MNDX_SEARCH_SEARCHING 2
#define MNDX_SEARCH_FINISHED 4
#define MNDX_MAX_ENTRIES(type) (0xFFFFFFFF / sizeof(type))
#define MNDX_INVALID_SIZE_T ((size_t)(-1))
#define MNDX_LAST_CKEY_ENTRY 0x80000000
//-----------------------------------------------------------------------------
// Local structures
typedef union _SETBITS
{
struct
{
DWORD Lower08 : 8; // Number of set bits in the lower 1 byte
DWORD Lower16 : 8; // Number of set bits in the lower 2 bytes
DWORD Lower24 : 8; // Number of set bits in the lower 3 bytes
DWORD Lower32 : 8; // Number of set bits in the 32-bit integer
} u;
DWORD SetBitsAll; // The total set bits mask
} SETBITS, *PSETBITS;
typedef struct _HASH_ENTRY
{
DWORD NodeIndex; // Index of the path node
DWORD NextIndex; // ID of the first subnode in the hash table
union
{
DWORD FragmentOffset; // Offset of the path fragment in the TPathFragmentTable
DWORD ChildTableIndex; // Starting search index for the child database (if child database is present)
char SingleChar; // If the upper 24 bits of the FragmentOffset is 0xFFFFFFFF, this single character
};
// Otherwise --> Offset to the name fragment table
} HASH_ENTRY, *PHASH_ENTRY;
typedef struct _FILE_MNDX_HEADER
{
DWORD Signature; // 'MNDX'
DWORD HeaderVersion; // Must be <= 2
DWORD FormatVersion;
} FILE_MNDX_HEADER, *PFILE_MNDX_HEADER;
typedef struct _MNDX_PACKAGE
{
char * szFileName; // Pointer to file name
size_t nLength; // Length of the file name
size_t nIndex; // Package index
} MNDX_PACKAGE, *PMNDX_PACKAGE;
// Root file entry for CASC storages with MNDX root file (Heroes of the Storm)
// Corresponds to the in-file structure
typedef struct _MNDX_CKEY_ENTRY
{
DWORD Flags; // High 8 bits: Flags, low 24 bits: package index
BYTE CKey[MD5_HASH_SIZE]; // Content key for the file
DWORD ContentSize; // Uncompressed file size, in bytes
} MNDX_CKEY_ENTRY, *PMNDX_CKEY_ENTRY;
typedef struct _FILE_MAR_INFO
{
DWORD MarIndex;
DWORD MarDataSize;
DWORD MarDataSizeHi;
DWORD MarDataOffset;
DWORD MarDataOffsetHi;
} FILE_MAR_INFO, *PFILE_MAR_INFO;
//-----------------------------------------------------------------------------
// Local variables
unsigned char table_1BA1818[0x800] =
{
0x07, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x07, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x06, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x05, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x04, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00,
0x07, 0x07, 0x07, 0x01, 0x07, 0x02, 0x02, 0x01, 0x07, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x05, 0x05, 0x01, 0x05, 0x02, 0x02, 0x01, 0x05, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x05, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x06, 0x06, 0x01, 0x06, 0x02, 0x02, 0x01, 0x06, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x06, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x06, 0x05, 0x05, 0x01, 0x05, 0x02, 0x02, 0x01, 0x05, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x05, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x07, 0x07, 0x01, 0x07, 0x02, 0x02, 0x01, 0x07, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x05, 0x05, 0x01, 0x05, 0x02, 0x02, 0x01, 0x05, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x05, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x06, 0x06, 0x01, 0x06, 0x02, 0x02, 0x01, 0x06, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x06, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x06, 0x05, 0x05, 0x01, 0x05, 0x02, 0x02, 0x01, 0x05, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x05, 0x04, 0x04, 0x01, 0x04, 0x02, 0x02, 0x01, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02, 0x02, 0x01,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x02, 0x07, 0x07, 0x07, 0x03, 0x07, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x04, 0x07, 0x04, 0x04, 0x02, 0x07, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x02, 0x07, 0x05, 0x05, 0x03, 0x05, 0x03, 0x03, 0x02,
0x07, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x02, 0x05, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x02, 0x07, 0x06, 0x06, 0x03, 0x06, 0x03, 0x03, 0x02,
0x07, 0x06, 0x06, 0x04, 0x06, 0x04, 0x04, 0x02, 0x06, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x02, 0x06, 0x05, 0x05, 0x03, 0x05, 0x03, 0x03, 0x02,
0x06, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x02, 0x05, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x02, 0x07, 0x07, 0x07, 0x03, 0x07, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x04, 0x07, 0x04, 0x04, 0x02, 0x07, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x02, 0x07, 0x05, 0x05, 0x03, 0x05, 0x03, 0x03, 0x02,
0x07, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x02, 0x05, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x02, 0x07, 0x06, 0x06, 0x03, 0x06, 0x03, 0x03, 0x02,
0x07, 0x06, 0x06, 0x04, 0x06, 0x04, 0x04, 0x02, 0x06, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x02, 0x06, 0x05, 0x05, 0x03, 0x05, 0x03, 0x03, 0x02,
0x06, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x02, 0x05, 0x04, 0x04, 0x03, 0x04, 0x03, 0x03, 0x02,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x04, 0x07, 0x07, 0x07, 0x04, 0x07, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x03,
0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x04, 0x07, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x03,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x04, 0x07, 0x06, 0x06, 0x04, 0x06, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x03,
0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x04, 0x06, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x04, 0x07, 0x07, 0x07, 0x04, 0x07, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x03,
0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x04, 0x07, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x03,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x04, 0x07, 0x06, 0x06, 0x04, 0x06, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x03,
0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x04, 0x06, 0x05, 0x05, 0x04, 0x05, 0x04, 0x04, 0x03,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05, 0x07, 0x07, 0x07, 0x05, 0x07, 0x05, 0x05, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05,
0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05, 0x07, 0x06, 0x06, 0x05, 0x06, 0x05, 0x05, 0x04,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x07, 0x07, 0x07, 0x06, 0x07, 0x06, 0x06, 0x05,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07
};
//-----------------------------------------------------------------------------
// Local functions - Number of set bits in an integer
// HOTS: inlined
static SETBITS GetNumberOfSetBits(DWORD Value32)
{
SETBITS SetBits;
Value32 = ((Value32 >> 1) & 0x55555555) + (Value32 & 0x55555555);
Value32 = ((Value32 >> 2) & 0x33333333) + (Value32 & 0x33333333);
Value32 = ((Value32 >> 4) & 0x0F0F0F0F) + (Value32 & 0x0F0F0F0F);
SetBits.SetBitsAll = Value32 * 0x01010101;
return SetBits;
}
static DWORD GetNumberOfSetBits32(DWORD Value32)
{
return GetNumberOfSetBits(Value32).u.Lower32;
}
static LPBYTE CaptureData(LPBYTE pbRootPtr, LPBYTE pbRootEnd, void * pvBuffer, size_t cbLength)
{
// Check whether there is enough data in the buffer
if((pbRootPtr + cbLength) > pbRootEnd)
return NULL;
// Copy the data
memcpy(pvBuffer, pbRootPtr, cbLength);
return pbRootPtr + cbLength;
}
//-----------------------------------------------------------------------------
// The TPathStop structure
struct TPathStop
{
TPathStop()
{
LoBitsIndex = 0;
field_4 = 0;
Count = 0;
HiBitsIndex_PathFragment = CASC_INVALID_INDEX;
field_10 = 0xFFFFFFFF;
}
TPathStop(DWORD arg_0, DWORD arg_4, DWORD arg_8)
{
LoBitsIndex = arg_0;
field_4 = arg_4;
Count = arg_8;
HiBitsIndex_PathFragment = CASC_INVALID_INDEX;
field_10 = 0xFFFFFFFF;
}
DWORD LoBitsIndex;
DWORD field_4;
DWORD Count;
DWORD HiBitsIndex_PathFragment;
DWORD field_10;
};
//-----------------------------------------------------------------------------
// Basic array implementations
class TByteStream
{
public:
// HOTS: 01959990
TByteStream()
{
pbByteData = NULL;
pvMappedFile = NULL;
cbByteData = 0;
field_C = 0;
hFile = 0;
hMap = 0;
}
// HOTS: 19599F0
template <typename T>
int GetBytes(size_t length, T ** Pointer)
{
// Is there enough bytes in the array?
if(length > cbByteData)
return ERROR_BAD_FORMAT;
// Give the buffer to the caller
Pointer[0] = (T *)(pbByteData);
// Move pointers
pbByteData += length;
cbByteData -= length;
return ERROR_SUCCESS;
}
int CopyBytes(void * value, size_t length)
{
// Is there enough bytes in the array?
if(length > cbByteData)
return ERROR_BAD_FORMAT;
// Give the buffer to the caller
memcpy(value, pbByteData, length);
// Move pointers
pbByteData += length;
cbByteData -= length;
return ERROR_SUCCESS;
}
// HOTS: 1959A60
int SkipBytes(size_t cbByteCount)
{
LPBYTE Pointer;
return GetBytes<BYTE>(cbByteCount, &Pointer);
}
// HOTS: 1959AF0
int SetByteBuffer(LPBYTE pbNewByteData, size_t cbNewByteData)
{
if(pbNewByteData != NULL || cbNewByteData == 0)
{
pbByteData = pbNewByteData;
cbByteData = cbNewByteData;
return ERROR_SUCCESS;
}
return ERROR_INVALID_PARAMETER;
}
// HOTS: 1957160 <DWORD>
template <typename T>
DWORD GetValue(T & Value)
{
T * Pointer;
DWORD dwErrCode;
dwErrCode = GetBytes(sizeof(T), (LPBYTE *)(&Pointer));
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
Value = Pointer[0];
return ERROR_SUCCESS;
}
// Retrieves the item count in the array
template <typename T>
DWORD GetArrayItemCount(DWORD & ArraySize, DWORD & ItemCount)
{
ULONGLONG ByteCount;
DWORD dwErrCode;
// The first 8 bytes is the byte size of the array
dwErrCode = GetValue<ULONGLONG>(ByteCount);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
// Extract the number of bytes
if(ByteCount > 0xFFFFFFFF || (ByteCount % sizeof(T)) != 0)
return ERROR_BAD_FORMAT;
// Give the result to the caller
ItemCount = (DWORD)(ByteCount / sizeof(T));
ArraySize = (DWORD)(ByteCount);
return ERROR_SUCCESS;
}
// HOTS: 1957190: <DWORD>
// HOTS: 19571E0: <BASEVALS>
// HOTS: 1957230: <BYTE>
// HOTS: 1957280: <HASH_ENTRY>
template <typename T>
DWORD GetArray(T ** Pointer, size_t ItemCount)
{
DWORD dwErrCode = ERROR_SUCCESS;
// Verify parameters
if(Pointer == NULL && ItemCount != 0)
return ERROR_INVALID_PARAMETER;
if(ItemCount > MNDX_MAX_ENTRIES(T))
return ERROR_NOT_ENOUGH_MEMORY;
// Allocate bytes for the array
if (Pointer != NULL)
{
Pointer[0] = CASC_ALLOC<T>(ItemCount);
if (Pointer[0] == NULL)
return ERROR_NOT_ENOUGH_MEMORY;
// Get the pointer to the array
dwErrCode = CopyBytes(Pointer[0], sizeof(T) * ItemCount);
}
return dwErrCode;
}
LPBYTE pbByteData;
void * pvMappedFile;
size_t cbByteData;
DWORD field_C;
HANDLE hFile;
HANDLE hMap;
};
//-----------------------------------------------------------------------------
// TGenericArray interface/implementation
template <typename T>
class TGenericArray
{
public:
TGenericArray()
{
ItemArray = NULL;
ItemCount = 0;
MaxItemCount = 0;
bIsValidArray = false;
}
~TGenericArray()
{
CASC_FREE(ItemArray);
}
T & operator[] (size_t index)
{
assert(index < ItemCount);
return ItemArray[index];
}
// HOTS: 1957090 (SetDwordsValid)
// HOTS: 19570B0 (SetBaseValsValid)
// HOTS: 19570D0 (? SetBitsValid ?)
// HOTS: 19570F0 (SetPathFragmentsValid)
int SetArrayValid()
{
if(bIsValidArray != 0)
return ERROR_ALREADY_EXISTS;
bIsValidArray = true;
return ERROR_SUCCESS;
}
// HOTS: 19575A0 (char)
// HOTS: 1957600 (TPathStop)
void SetMaxItems(DWORD NewMaxItemCount)
{
T * OldArray = ItemArray;
T * NewArray;
// Allocate new data buffer
NewArray = CASC_ALLOC<T>(NewMaxItemCount);
if(NewArray != NULL)
{
// Copy the old items to the buffer
for(size_t i = 0; i < ItemCount; i++)
{
NewArray[i] = ItemArray[i];
}
}
ItemArray = NewArray;
MaxItemCount = NewMaxItemCount;
CASC_FREE(OldArray);
}
// HOTS: 19575A0 (char)
// HOTS: 1957600 (TPathStop)
void SetMaxItemsIf(DWORD NewMaxItemCount)
{
if(NewMaxItemCount > MaxItemCount)
{
if(MaxItemCount > (NewMaxItemCount / 2))
{
if(MaxItemCount <= (MNDX_MAX_ENTRIES(T) / 2))
NewMaxItemCount = MaxItemCount + MaxItemCount;
else
NewMaxItemCount = MNDX_MAX_ENTRIES(T);
}
SetMaxItems(NewMaxItemCount);
}
}
// HOTS: inline <char>
// HOTS: 1958330 <TPathStop>
void Insert(T NewItem)
{
// Make sure we have enough capacity for the new item
SetMaxItemsIf(ItemCount + 1);
// Put the character to the slot that has been reserved
ItemArray[ItemCount++] = NewItem;
}
// HOTS: 19583A0 <TPathStop>
void GrowArray(DWORD NewItemCount)
{
DWORD OldMaxItemCount = MaxItemCount;
// Make sure we have enough capacity for new items
SetMaxItemsIf(NewItemCount);
// Initialize the newly inserted items
for(DWORD i = OldMaxItemCount; i < NewItemCount; i++)
{
ItemArray[i] = T();
}
ItemCount = NewItemCount;
}
// HOTS: 1957440 <DWORD>
// HOTS: 19574E0 <BASEVALS>
// HOTS: 1957690 <BYTE>
// HOTS: 1957700 <HASH_ENTRY>
// HOTS: 195A220 <char>
// HOTS: 1958580 <TBitStream, DWORD>
DWORD LoadFromStream(TByteStream & InStream)
{
DWORD NumberOfBytes;
DWORD dwErrCode;
// Get and verify the number of items
dwErrCode = InStream.GetArrayItemCount<T>(NumberOfBytes, ItemCount);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
// Get the pointer to the array
dwErrCode = InStream.GetArray<T>(&ItemArray, ItemCount);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = InStream.SkipBytes((0 - (DWORD)NumberOfBytes) & 0x07);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
return SetArrayValid();
}
T * ItemArray;
DWORD ItemCount; // Number of items in the array
DWORD MaxItemCount; // Capacity of the array
bool bIsValidArray;
};
class TBitEntryArray : public TGenericArray<DWORD>
{
public:
TBitEntryArray() : TGenericArray()
{
BitsPerEntry = 0;
EntryBitMask = 0;
TotalEntries = 0;
}
~TBitEntryArray()
{}
DWORD GetItem(DWORD EntryIndex)
{
DWORD dwItemIndex = (EntryIndex * BitsPerEntry) >> 0x05;
DWORD dwStartBit = (EntryIndex * BitsPerEntry) & 0x1F;
DWORD dwEndBit = dwStartBit + BitsPerEntry;
DWORD dwResult;
// If the end bit index is greater than 32,
// we also need to load from the next 32-bit item
if(dwEndBit > 0x20)
{
dwResult = (ItemArray[dwItemIndex + 1] << (0x20 - dwStartBit)) | (ItemArray[dwItemIndex] >> dwStartBit);
}
else
{
dwResult = ItemArray[dwItemIndex] >> dwStartBit;
}
// Now we also need to mask the result by the bit mask
return dwResult & EntryBitMask;
}
DWORD LoadBitsFromStream(TByteStream & InStream)
{
ULONGLONG Value64 = 0;
DWORD dwErrCode;
dwErrCode = LoadFromStream(InStream);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = InStream.GetValue<DWORD>(BitsPerEntry);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
if(BitsPerEntry > 0x20)
return ERROR_BAD_FORMAT;
dwErrCode = InStream.GetValue<DWORD>(EntryBitMask);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = InStream.GetValue<ULONGLONG>(Value64);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
if(Value64 > 0xFFFFFFFF)
return ERROR_BAD_FORMAT;
TotalEntries = (DWORD)Value64;
assert((BitsPerEntry * TotalEntries) / 32 <= ItemCount);
return ERROR_SUCCESS;
}
DWORD BitsPerEntry;
DWORD EntryBitMask;
DWORD TotalEntries;
};
//-----------------------------------------------------------------------------
// TSparseArray functions
#define INDEX_TO_GROUP(val) (val >> 9)
#define GROUP_TO_INDEX(grp) (grp << 9)
// For each 0x200-th bit, this contains information about amount of "1" bits
typedef struct _BASEVALS
{
DWORD BaseValue200; // Item value of every 0x200-th item
DWORD AddValue40 : 7; // For each 0x40 items (above the base200),
DWORD AddValue80 : 8; // we have extra shortcut to the item value
DWORD AddValueC0 : 8; // that is to be added to BaseValue200
DWORD AddValue100 : 9;
DWORD AddValue140 : 9;
DWORD AddValue180 : 9;
DWORD AddValue1C0 : 9;
DWORD __xalignment : 5; // Filling
} BASEVALS, *PBASEVALS;
class TSparseArray
{
public:
TSparseArray()
{
TotalItemCount = 0;
ValidItemCount = 0;
}
// HOTS: 1958630
DWORD LoadFromStream(TByteStream & InStream)
{
DWORD total_count = 0;
DWORD valid_count = 0;
DWORD dwErrCode;
dwErrCode = ItemBits.LoadFromStream(InStream);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = InStream.GetValue<DWORD>(total_count);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = InStream.GetValue<DWORD>(valid_count);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
if(valid_count > total_count)
return ERROR_FILE_CORRUPT;
TotalItemCount = total_count;
ValidItemCount = valid_count;
dwErrCode = BaseVals.LoadFromStream(InStream);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = IndexToItem0.LoadFromStream(InStream);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
dwErrCode = IndexToItem1.LoadFromStream(InStream);
if(dwErrCode != ERROR_SUCCESS)
return dwErrCode;
return ERROR_SUCCESS;
}
// Returns true if the array is empty
bool IsEmpty()
{
return (TotalItemCount == 0);
}
// Returns true if the item at n-th position is present
bool IsItemPresent(size_t index)
{
// (index >> 0x05) gives the DWORD, (1 << (ItemIndex & 0x1F)) gives the bit
return (ItemBits[index >> 0x05] & (1 << (index & 0x1F))) ? true : false;
}
// Retrieves the value of the n-th item in the sparse array.
// Note that for items that are not present, the value is equal
// to the nearest lower present value
DWORD GetItemValueAt(size_t index)
{
BASEVALS & SetBitsCount = BaseVals[index >> 0x09];
DWORD IntValue;
DWORD BitMask;
//
// Since we don't want to count bits for the entire array,
// there are item value shortcuts every 0x200 items,
// and then every 0x40 items above the 0x200 base
//
// 1) We have base value for every 0x200-th item
IntValue = SetBitsCount.BaseValue200;
// 2) Add the base value for each 0x40-th item above the 0x200 base
switch(((index >> 0x06) & 0x07) - 1)
{
case 0: // Add the 1st value (7 bits)
IntValue += SetBitsCount.AddValue40;
break;
case 1: // Add the 2nd value (8 bits)
IntValue += SetBitsCount.AddValue80;
break;
case 2: // Add the 3rd value (8 bits)
IntValue += SetBitsCount.AddValueC0;
break;
case 3: // Add the 4th value (9 bits)
IntValue += SetBitsCount.AddValue100;
break;
case 4: // Add the 5th value (9 bits)
IntValue += SetBitsCount.AddValue140;
break;
case 5: // Add the 6th value (9 bits)
IntValue += SetBitsCount.AddValue180;
break;
case 6: // Add the 7th value (9 bits)
IntValue += SetBitsCount.AddValue1C0;
break;
}
// 3) Count the bits of the higher DWORD, if the index 0x20 - 0x30 above the 0x200 base
if(index & 0x20)
IntValue += GetNumberOfSetBits32(ItemBits[(index >> 0x05) - 1]);
// 4) Count the bits in the current DWORD (masked by bit index mask)
BitMask = (1 << (index & 0x1F)) - 1;
return IntValue + GetNumberOfSetBits32(ItemBits[index >> 0x05] & BitMask);
}
DWORD FindGroup_Items0(DWORD index)
{
// Setup the group range to search
DWORD minGroup = (IndexToItem0[INDEX_TO_GROUP(index) + 0]) >> 9;
DWORD maxGroup = (IndexToItem0[INDEX_TO_GROUP(index) + 1] + 0x1FF) >> 9;
// Search the groups and find the BASEVALS structure
// For spans less than 10 groups, use sequential search, otherwise binary search.
if ((maxGroup - minGroup) < 10)
{
// HOTS: 1959CF7
while (index >= GROUP_TO_INDEX(minGroup) - BaseVals[minGroup + 1].BaseValue200 + 0x200)
{
// HOTS: 1959D14
minGroup++;
}
}
else
{
// HOTS: 1959D2E
while ((minGroup + 1) < maxGroup)
{
// HOTS: 1959D38
DWORD middleValue = (maxGroup + minGroup) >> 1;
if (index < (maxGroup << 0x09) - BaseVals[maxGroup].BaseValue200)
{
// HOTS: 01959D4B
maxGroup = middleValue;
}
else
{
// HOTS: 1959D50
minGroup = middleValue;
}
}
}
return minGroup;
}
DWORD FindGroup_Items1(DWORD index)
{
DWORD groupIndex = (index >> 0x09);
DWORD startValue = IndexToItem1[groupIndex] >> 9;
DWORD nextValue = (IndexToItem1[groupIndex + 1] + 0x1FF) >> 9;
// Find the BASEVALS structure which the start index belongs to
// For less than 10 values, use sequential search. Otherwise, use binary search
if ((nextValue - startValue) < 10)
{
// HOTS: 01959F94
while (index >= BaseVals[startValue + 1].BaseValue200)
{
// HOTS: 1959FA3
startValue++;
}
}
else
{
// Binary search (HOTS: 1959FAD)
if ((startValue + 1) < nextValue)
{
// HOTS: 1959FB4
DWORD middleValue = (nextValue + startValue) >> 1;
if (index < BaseVals[middleValue].BaseValue200)
{
// HOTS: 1959FC4
nextValue = middleValue;
}
else
{
// HOTS: 1959FC8
startValue = middleValue;
}
}
}
return startValue;
}
// Returns the value of Item0[index] (HOTS: 1959CB0)
DWORD GetItem0(DWORD index)
{
SETBITS zeroBits;
DWORD groupIndex;
DWORD dwordIndex;
DWORD itemIndex;
DWORD bitGroup;
DWORD edx = index;
#ifdef _DEBUG
//if (TotalItemCount > 0x200)
//{
// FILE * fp = fopen("e:\\Ladik\\Appdir\\CascLib\\doc\\mndx-sparse-array.txt", "wt");
// Dump(fp);
// fclose(fp);
//}
#endif
// If the index is at begin of the group, we just return the start value
if ((index & 0x1FF) == 0)
return IndexToItem0[INDEX_TO_GROUP(index)];
// Find the group where the index belongs to
groupIndex = FindGroup_Items0(index);
// HOTS: 1959D5F
edx += BaseVals[groupIndex].BaseValue200 - (groupIndex << 0x09);
dwordIndex = (groupIndex << 4);
if (edx < 0x100 - BaseVals[groupIndex].AddValue100)
{
// HOTS: 1959D8C
if (edx < 0x80 - BaseVals[groupIndex].AddValue80)
{
// HOTS: 01959DA2
if (edx >= 0x40 - BaseVals[groupIndex].AddValue40)
{
// HOTS: 01959DB7
dwordIndex += 2;
edx = edx + BaseVals[groupIndex].AddValue40 - 0x40;
}
}
else
{
// HOTS: 1959DC0
if (edx < 0xC0 - BaseVals[groupIndex].AddValueC0)
{
// HOTS: 1959DD3
dwordIndex += 4;
edx = edx + BaseVals[groupIndex].AddValue80 - 0x80;
}
else
{
// HOTS: 1959DD3
dwordIndex += 6;
edx = edx + BaseVals[groupIndex].AddValueC0 - 0xC0;
}
}
}
else
{
// HOTS: 1959DE8
if (edx < 0x180 - BaseVals[groupIndex].AddValue180)
{
// HOTS: 01959E00
if (edx < 0x140 - BaseVals[groupIndex].AddValue140)
{
// HOTS: 1959E11
dwordIndex += 8;
edx = edx + BaseVals[groupIndex].AddValue100 - 0x100;
}
else
{
// HOTS: 1959E1D
dwordIndex += 10;
edx = edx + BaseVals[groupIndex].AddValue140 - 0x140;
}
}
else
{
// HOTS: 1959E29
if (edx < 0x1C0 - BaseVals[groupIndex].AddValue1C0)
{
// HOTS: 1959E3D
dwordIndex += 12;
edx = edx + BaseVals[groupIndex].AddValue180 - 0x180;
}
else
{
// HOTS: 1959E49
dwordIndex += 14;
edx = edx + BaseVals[groupIndex].AddValue1C0 - 0x1C0;
}
}
}
// HOTS: 1959E53:
// Calculate the number of bits set in the value of "bitGroup"
bitGroup = ~ItemBits[dwordIndex];
zeroBits = GetNumberOfSetBits(bitGroup);
if (edx >= zeroBits.u.Lower32)
{
// HOTS: 1959ea4
bitGroup = ~ItemBits[++dwordIndex];
edx = edx - zeroBits.u.Lower32;
zeroBits = GetNumberOfSetBits(bitGroup);
}
// Re-calculate the item index
itemIndex = (dwordIndex << 0x05);
// HOTS: 1959eea
if (edx < zeroBits.u.Lower16)
{
// HOTS: 1959EFC
if (edx >= zeroBits.u.Lower08)
{
// HOTS: 1959F05