forked from opentibia/yatc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.cpp
1003 lines (891 loc) · 27.2 KB
/
objects.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
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
// Object data
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include "objects.h"
#include "engine.h" // used to create engine specific sprites
#include "util.h"
#include "options.h"
#include "net/connection.h"
#include "product.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_LIBINTL_H)
#include <libintl.h>
#else
#define gettext(x) (x)
#endif
uint16_t ObjectType::minItemId = 0;
uint16_t ObjectType::maxItemId = 0;
uint16_t ObjectType::minOutfitId = 0;
uint16_t ObjectType::maxOutfitId = 0;
uint16_t ObjectType::minEffectId = 0;
uint16_t ObjectType::maxEffectId = 0;
uint16_t ObjectType::minDistanceId = 0;
uint16_t ObjectType::maxDistanceId = 0;
Objects* Objects::m_instance = NULL;
ObjectType::ObjectType(uint16_t _id)
{
id = _id;
imageData = NULL;
ground = false;
speed = 0;
alwaysOnTopOrder = 5; //0: ground 1-3: topItems 4: creatures 5: default for downItems,
alwaysOnTop = false;
container = false;
stackable = false;
useable = false;
rune = false;
readable = false;
writeable = false;
fluidContainer = false;
splash = false;
blockSolid = false;
moveable = false;
blockProjectile = false;
blockPathFind = false;
pickupable = false;
isHangable = false;
isHorizontal = false;
isVertical = false;
rotatable = false;
lightLevel = 0;
lightColor = 0;
xOffset = 0;
yOffset = 0;
hasHeight = false;
mapColor = 0;
lookThrough = false;
width = 1;
height = 1;
rendersize = 32;
blendframes = 0;
xdiv = 1;
ydiv = 1;
zdiv = 0;
animcount = 1;
numsprites = 0;
//0x06 property
alwaysUsed = false;
instancesOnMap = 0;
}
ObjectType::~ObjectType()
{
unloadGfx();
}
void ObjectType::loadGfx()
{
ASSERT(imageData)
if (m_gfx.size() != numsprites) { // graphics not loaded yet?
for(uint32_t i = 0; i < numsprites; i++){
m_gfx.insert(m_gfx.end(), g_engine->createSprite("Tibia.spr", imageData[i]));
}
}
}
void ObjectType::unloadGfx()
{
std::vector<Sprite*>::iterator it;
for(it = m_gfx.begin(); it != m_gfx.end(); ++it){
delete *it;
}
m_gfx.clear();
}
const std::vector<Sprite*>& ObjectType::getGfx() const {
return m_gfx;
}
bool ObjectType::isGfxLoaded() const {
ASSERT(imageData);
return (m_gfx.size()) && (numsprites != 0);
}
Objects::Objects() : m_item(8192), m_outfit(256),
m_effect(32), m_distance(32)
{
m_datLoaded = false;
}
Objects::~Objects()
{
}
Objects* Objects::getInstance()
{
// TODO (mips_act#3#): Choose Object instance depending on selected version
if(!m_instance)
m_instance = new Objects();
return m_instance;
}
bool Objects::unloadDat()
{
if(m_datLoaded){
unsigned int i = 100;
while(ObjectType* oType = m_item.getElement(i)){
if(oType->imageData != NULL){
delete[] oType->imageData;
oType->imageData = NULL;
}
delete oType;
++i;
}
printf("Unloaded %d item objects\n",i);
i = 1;
while(ObjectType* oType = m_outfit.getElement(i)){
if(oType->imageData != NULL){
delete[] oType->imageData;
oType->imageData = NULL;
}
delete oType;
++i;
}
printf("Unloaded %d outfit objects\n",i);
i = 1;
while(ObjectType* oType = m_effect.getElement(i)){
if(oType->imageData != NULL){
delete[] oType->imageData;
oType->imageData = NULL;
}
delete oType;
++i;
}
printf("Unloaded %d effect objects\n",i);
i = 1;
while(ObjectType* oType = m_distance.getElement(i)){
if(oType->imageData != NULL){
delete[] oType->imageData;
oType->imageData = NULL;
}
delete oType;
++i;
}
printf("Unloaded %d distance objects\n",i);
m_datLoaded = false;
}
return true;
}
void Objects::unloadGfx()
{
if(m_datLoaded){
unsigned int i = 100;
while(ObjectType* oType = m_item.getElement(i)){
oType->unloadGfx();
++i;
}
printf("Unloaded %d item gfx\n",i);
i = 1;
while(ObjectType* oType = m_outfit.getElement(i)){
oType->unloadGfx();
++i;
}
printf("Unloaded %d outfit gfx\n",i);
i = 1;
while(ObjectType* oType = m_effect.getElement(i)){
oType->unloadGfx();
++i;
}
printf("Unloaded %d effect gfx\n",i);
i = 1;
while(ObjectType* oType = m_distance.getElement(i)){
oType->unloadGfx();
++i;
}
printf("Unloaded %d distance gfx\n",i);
}
}
bool Objects::loadDat(const char* filename)
{
bool success = false;
if(m_datLoaded) {
printf("LOADING DATA FILE %s BUT ALREADY LOADED\n", filename);
return false;
}
ClientVersion_t ver = options.protocol;
if(ver == CLIENT_VERSION_AUTO) {
// detectVersion will return CLIENT_VERSION_AUTO in case of failure
ver = ProtocolConfig::detectVersion();
}
/*
outline of revamped loader:
- we have a std::map with all loaders
- key of std::map is minimal version where the loader applies
- value of std::map is pointer to loader function
- if detected version is larger or equal to a certain member, load, and if successful abort
- otherwise try again
in case detection of version failed (e.g. custom data file signatures) then ver == CLIENT_VERSION_AUTO
and then we try to load with each and every loader. if we're successful, yay, we're happy and we bail out.
*/
std::map<ClientVersion_t, bool (Objects::*)(const char*)> loaders;
loaders[CLIENT_VERSION_780] = &Objects::load780plus; /* 7.80 - 8.5 use almost same .dat format (with an addition hereanddthere)*/
loaders[CLIENT_VERSION_755] = &Objects::load76_77series; /* 7.55 - 7.72 use same .dat format to the best of my knowledge */
loaders[CLIENT_VERSION_740] = &Objects::load74_75series;
for(std::map<ClientVersion_t, bool(Objects::*)(const char*)>::reverse_iterator it = loaders.rbegin(); it != loaders.rend(); it++)
{
if(ver >= it->first || ver == CLIENT_VERSION_AUTO)
{
success = (this->*it->second)(filename);
if(success)
break;
}
}
if (!success)
{
NativeGUIError( str_replace( "$$PRODUCTSHORT$$", PRODUCTSHORT, gettext(
"Unrecognized data files.\n"
"\n"
"* Please install a supported version of data files, or override\n"
" autodetection manually in configuration.\n"
"\n"
"* You may be attempting to use a too new version of data files.\n"
" Check if a new version of $$PRODUCTSHORT$$ came out which\n"
" supports this version of data files.")).c_str(),
gettext("Data files not recognized"));
}
return success;
}
bool Objects::load780plus(const char* filename)
{
uint16_t id = 100;
int32_t size;
uint16_t read_short, read_short2;
uint32_t maxObjects = 0;
FILE *fp = yatc_fopen(filename, "rb");
if(!fp){
return false;
}
fseek(fp,0,SEEK_END);
size = ftell(fp);
//get max id
fseek(fp, 0x04, SEEK_SET);
//Items
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minItemId = 100;
ObjectType::maxItemId = read_short;
maxObjects += ObjectType::maxItemId;
//Outfits
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minOutfitId = 0;
ObjectType::maxOutfitId = read_short;
maxObjects += ObjectType::maxOutfitId;
//Effects
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minEffectId = 0;
ObjectType::maxEffectId = read_short;
maxObjects += ObjectType::maxEffectId;
//Distance
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minDistanceId = 0;
ObjectType::maxDistanceId = read_short;
maxObjects += ObjectType::maxDistanceId;
while(ftell(fp) < size && id <= maxObjects){
ObjectType* oType = new ObjectType(id);
int optbyte;
//bool colorTemplate = false;
while(((optbyte = fgetc(fp)) >= 0) && (optbyte != 0xFF)){
switch(optbyte){
case 0x00: //Ground tile
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
oType->speed = read_short;
oType->ground = true;
oType->alwaysOnTopOrder = 0;
break;
case 0x01: //ontop
oType->alwaysOnTop = true;
oType->alwaysOnTopOrder = 1;
break;
case 0x02: //Walk through (doors etc)
oType->alwaysOnTop = true;
oType->alwaysOnTopOrder = 2;
break;
case 0x03: //Can walk trough (arces)
oType->alwaysOnTop = true;
oType->alwaysOnTopOrder = 3;
break;
case 0x04: //Container
oType->container = true;
break;
case 0x05: //Stackable
oType->stackable = true;
break;
case 0x06: //Ladders?
oType->alwaysUsed = true;
break;
case 0x07: //Useable
oType->useable = true;
break;
case 0x08: //Runes
oType->rune = true;
break;
case 0x09: //Writtable/Readable Objectss
oType->readable = true;
oType->writeable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x0A: //Writtable Objectss that can't be edited
oType->readable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x0B: //Fluid containers
oType->fluidContainer = true;
break;
case 0x0C: //Splashes?
oType->splash = true;
break;
case 0x0D: //Is blocking
oType->blockSolid = true;
break;
case 0x0E: //Is not moveable
oType->moveable = false;
break;
case 0x0F: //Blocks missiles (walls, magic wall etc)
oType->blockProjectile = true;
break;
case 0x10: //Blocks monster movement (flowers, parcels etc)
oType->blockPathFind = true;
break;
case 0x11: //Can be equipped
oType->pickupable = true;
break;
case 0x12: //Wall items
oType->isHangable = true;
break;
case 0x13:
oType->isHorizontal = true;
break;
case 0x14:
oType->isVertical = true;
break;
case 0x15: //Rotatable items
oType->rotatable = true;
break;
case 0x16: //Light info
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->lightLevel = read_short;
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->lightColor = read_short;
break;
case 0x17: //Floor change?
break;
case 0x18: //??
optbyte = optbyte;
break;
case 0x19: //Offset?
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->xOffset = read_short;
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->yOffset = read_short;
break;
case 0x1A:
oType->hasHeight = true;
// (should be) the height change in px; Cipsoft always uses 8
yatc_fread(&read_short, sizeof(read_short), 1, fp); // ?
ECORR16(read_short);
break;
case 0x1B://draw with height offset for all parts (2x2) of the sprite
break;
case 0x1C://idle animated
oType->idleAnim = true;
break;
case 0x1D:
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->mapColor = read_short;
break;
case 0x1E: //line spot
int tmp;
tmp = fgetc(fp); // 86 -> openable holes, 77-> can be used to go down, 76 can be used to go up, 82 -> stairs up, 79 switch,
if(tmp == 0x58)
oType->readable = true;
fgetc(fp); // always 4
break;
case 0x1F: //?
break;
case 0x20: // New with Tibia 8.5 - "look through"
// NOTE (nfries88): Not sure if client or server does this...
// NOTE (ivucica): It's almost certainly the client
oType->lookThrough = true;
break;
default:
optbyte = optbyte;
std::cout << "unknown byte: " << (uint16_t)optbyte << std::endl;
return false;
break;
}
}
oType->width = fgetc(fp);
oType->height = fgetc(fp);
if((oType->width > 1) || (oType->height > 1)){
oType->rendersize = fgetc(fp);
}
oType->blendframes = fgetc(fp);
oType->xdiv = fgetc(fp);
oType->ydiv = fgetc(fp);
oType->zdiv = fgetc(fp);
oType->animcount = fgetc(fp);
oType->numsprites = oType->width * oType->height * oType->blendframes * oType->xdiv * oType->ydiv * oType->animcount * oType->zdiv;
oType->imageData = new uint16_t[oType->numsprites];
ASSERT(oType->imageData);
for(unsigned int i = 0; i < oType->numsprites; i++) {
yatc_fread(&oType->imageData[i], sizeof(uint16_t), 1, fp);
ECORR16(oType->imageData[i]);
}
if(id <= ObjectType::maxItemId){
m_item.addElement(oType, id);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId)){
m_outfit.addElement(oType, id - ObjectType::maxItemId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId)){
m_effect.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId + ObjectType::maxDistanceId)){
m_distance.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId - ObjectType::maxEffectId);
}
id++;
}
fclose(fp);
m_datLoaded = true;
return true;
}
// NOTE (nfries88): This actually loads 755 too
bool Objects::load76_77series(const char* filename)
{
uint16_t id = 100;
int32_t size;
uint16_t read_short, read_short2;
uint32_t maxObjects = 0;
FILE *fp = yatc_fopen(filename, "rb");
if(!fp){
return false;
}
fseek(fp,0,SEEK_END);
size = ftell(fp);
//get max id
fseek(fp, 0x04, SEEK_SET);
//Items
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minItemId = 100;
ObjectType::maxItemId = read_short;
maxObjects += ObjectType::maxItemId;
//Outfits
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minOutfitId = 0;
ObjectType::maxOutfitId = read_short;
maxObjects += ObjectType::maxOutfitId;
//Effects
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minEffectId = 0;
ObjectType::maxEffectId = read_short;
maxObjects += ObjectType::maxEffectId;
//Distance
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minDistanceId = 0;
ObjectType::maxDistanceId = read_short;
maxObjects += ObjectType::maxDistanceId;
while(ftell(fp) < size && id <= maxObjects){
ObjectType* oType = new ObjectType(id);
int optbyte;
//bool colorTemplate = false;
while(((optbyte = fgetc(fp)) >= 0) && (optbyte != 0xFF)){
switch(optbyte){
case 0x00: //is groundtile
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
oType->speed = read_short;
oType->ground = true;
break;
case 0x01: //all OnTop
oType->alwaysOnTop = 1;
break;
case 0x02: //can walk trough (open doors, arces, bug pen fence ??)
oType->alwaysOnTop = 2;
break;
case 0x03: //can walk trough (arces)
oType->alwaysOnTop = 3;
break;
case 0x04: //is a container
oType->useable = true;
oType->container = true;
//oType->stackable = true;
break;
case 0x05: //is stackable
oType->stackable = true;
break;
case 0x06: //ladders
oType->useable = true;
break;
case 0x07: //is useable
oType->useable = true;
//
break;
case 0x08: //writtable objects
oType->readable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x09: //writtable objects that can't be edited
oType->readable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x0A: //can contain fluids
oType->fluidContainer = true;
break;
case 0x0B: //liquid with states
oType->splash = true;
break;
case 0x0C: //is blocking
oType->blockSolid = true;
break;
case 0x0D: //is no moveable
oType->moveable = false;
break;
case 0x0E: //blocks missiles (walls, magic wall etc)
oType->blockProjectile = true;
break;
case 0x0F: //blocks monster movement (flowers, parcels etc)
oType->blockPathFind = true;
break;
case 0x10: //can be equipped
oType->pickupable = true;
break;
case 0x11: //wall items
oType->isHangable = true;
break;
case 0x12:
oType->isHorizontal = true;
break;
case 0x13:
oType->isVertical = true;
break;
case 0x14: //rotable items
oType->rotatable = true;
break;
case 0x15: //light info .. //sprite-drawing related
unsigned short lightlevel;
yatc_fread(&lightlevel, sizeof(lightlevel), 1, fp);
ECORR16(read_short);
oType->lightLevel = lightlevel;
unsigned short lightcolor;
yatc_fread(&lightcolor, sizeof(lightcolor), 1, fp);
ECORR16(read_short);
oType->lightColor = lightcolor;
break;
case 0x17: //floor change
break;
case 0x18: //offset
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->xOffset = read_short;
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->yOffset = read_short;
break;
case 0x19: //height
oType->hasHeight = true;
// (should be) the height change in px; Cipsoft always uses 8
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
break;
case 0x1A://draw with height offset for all parts (2x2) of the sprite
break;
case 0x1B: //some monsters
break;
case 0x1C:
unsigned short color;
yatc_fread(&color, sizeof(color), 1, fp);
ECORR16(read_short);
oType->mapColor = color;
break;
case 0x1D: //line spot
int tmp;
tmp = fgetc(fp); // 86 -> openable holes, 77-> can be used to go down, 76 can be used to go up, 82 -> stairs up, 79 switch,
oType->useable=true;
if(tmp == 0x58)
oType->readable = true;
fgetc(fp); // always 4
break;
case 0x1E: //ground items
break;
default:
//optbyte = optbyte;
//std::cout << "unknown byte: " << (unsigned short)optbyte << std::endl;
//DEBUGPRINT("DATLOADER: Unknown byte %.02x, item %d, at offset %d; lastok was = %.02x\n", optbyte, id, ftell(fp), lastokbyte);
return false;
break;
}
}
oType->width = fgetc(fp);
oType->height = fgetc(fp);
if((oType->width > 1) || (oType->height > 1)){
oType->rendersize = fgetc(fp);
}
oType->blendframes = fgetc(fp);
oType->xdiv = fgetc(fp);
oType->ydiv = fgetc(fp);
oType->zdiv = fgetc(fp);
oType->animcount = fgetc(fp);
oType->numsprites = oType->width * oType->height * oType->blendframes * oType->xdiv * oType->ydiv * oType->animcount * oType->zdiv;
oType->imageData = new uint16_t[oType->numsprites];
ASSERT(oType->imageData);
for(unsigned int i = 0; i < oType->numsprites; i++) {
yatc_fread(&oType->imageData[i], sizeof(uint16_t), 1, fp);
ECORR16(oType->imageData[i]);
}
if(id <= ObjectType::maxItemId){
m_item.addElement(oType, id);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId)){
m_outfit.addElement(oType, id - ObjectType::maxItemId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId)){
m_effect.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId + ObjectType::maxDistanceId)){
m_distance.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId - ObjectType::maxEffectId);
}
id++;
}
fclose(fp);
m_datLoaded = true;
return true;
}
// NOTE (nfries88): 740 - 750 loader
bool Objects::load74_75series(const char* filename)
{
uint16_t id = 100;
int32_t size;
uint16_t read_short, read_short2;
uint32_t maxObjects = 0;
FILE *fp = yatc_fopen(filename, "rb");
if(!fp){
return false;
}
fseek(fp,0,SEEK_END);
size = ftell(fp);
//get max id
fseek(fp, 0x04, SEEK_SET);
//Items
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minItemId = 100;
ObjectType::maxItemId = read_short;
maxObjects += ObjectType::maxItemId;
//Outfits
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minOutfitId = 0;
ObjectType::maxOutfitId = read_short;
maxObjects += ObjectType::maxOutfitId;
//Effects
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minEffectId = 0;
ObjectType::maxEffectId = read_short;
maxObjects += ObjectType::maxEffectId;
//Distance
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
ObjectType::minDistanceId = 0;
ObjectType::maxDistanceId = read_short;
maxObjects += ObjectType::maxDistanceId;
while(ftell(fp) < size && id <= maxObjects){
ObjectType* oType = new ObjectType(id);
int optbyte;
//bool colorTemplate = false;
while(((optbyte = fgetc(fp)) >= 0) && (optbyte != 0xFF)){
switch(optbyte){
case 0x00: //Ground tile
yatc_fread(&read_short, 2, 1, fp);
ECORR16(read_short);
oType->speed = read_short;
oType->ground = true;
oType->alwaysOnTopOrder = 0;
break;
case 0x01: //ontop
oType->alwaysOnTop = true;
oType->alwaysOnTopOrder = 1;
break;
case 0x02: //Walk through (doors etc)
oType->alwaysOnTop = true;
oType->alwaysOnTopOrder = 2;
break;
case 0x03: //Container
oType->container = true;
break;
case 0x04: //Stackable
oType->stackable = true;
break;
case 0x05: //Useable
oType->useable = true;
break;
case 0x06: //Ladders?
oType->alwaysUsed = true;
break;
case 0x07: //Writtable/Readable Objectss
oType->readable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x08: //Writtable Objectss that can't be edited
oType->readable = true;
yatc_fread(&read_short2, sizeof(read_short2), 1, fp); //maximum size of text entry TODO (ivucica#3#) store this data
ECORR16(read_short);
break;
case 0x09: //Fluid containers
oType->fluidContainer = true;
break;
case 0x0A: //Splashes?
oType->splash = true;
break;
case 0x0B: //Is blocking
oType->blockSolid = true;
break;
case 0x0C: //Is not moveable
oType->moveable = false;
break;
case 0x0D: //Blocks missiles (walls, magic wall etc)
oType->blockProjectile = true;
break;
case 0x0E: //Blocks monster movement (flowers, parcels etc)
oType->blockPathFind = true;
break;
case 0x0F: //Can be equipped
oType->pickupable = true;
break;
case 0x10: //Light info
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->lightLevel = read_short;
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->lightColor = read_short;
break;
case 0x11: //Floor change?
break;
case 0x12: // "Solid Floor" According to BlackDemon
break;
case 0x13:
oType->hasHeight = true;
// (should be) the height change in px; Cipsoft always uses 8
yatc_fread(&read_short, sizeof(read_short), 1, fp); // ?
ECORR16(read_short);
break;
case 0x14: // "Adjusted" According to BlackDemon: 8px x and y offset
oType->xOffset = 8;
oType->yOffset = 8;
break;
case 0x16: // Minimap
yatc_fread(&read_short, sizeof(read_short), 1, fp);
ECORR16(read_short);
oType->mapColor = read_short;
break;
case 0x17: //Rotatable items
oType->rotatable = true;
case 0x18: // "Bottom Layer" according to BlackDemon?
break;
case 0x19: //Wall items
oType->isHangable = true;
break;
case 0x1A:
oType->isHorizontal = true;
break;
case 0x1B:
oType->isVertical = true;
break;
case 0x1C://idle animated
oType->idleAnim = true;
break;
case 0x1D: //line spot
int tmp;
tmp = fgetc(fp); // 86 -> openable holes, 77-> can be used to go down, 76 can be used to go up, 82 -> stairs up, 79 switch,
if(tmp == 0x58)
oType->readable = true;
fgetc(fp); // always 4
break;
default:
optbyte = optbyte;
std::cout << "unknown byte: " << (uint16_t)optbyte << std::endl;
return false;
break;
}
}
oType->width = fgetc(fp);
oType->height = fgetc(fp);
if((oType->width > 1) || (oType->height > 1)){
oType->rendersize = fgetc(fp);
}
oType->blendframes = fgetc(fp);
oType->xdiv = fgetc(fp);
oType->ydiv = fgetc(fp);
// NOTE (nfries88): Black Demon says "zdiv" (our "unk1") was not added until 7.55
oType->zdiv = 1;
oType->animcount = fgetc(fp);
oType->numsprites = oType->width * oType->height * oType->blendframes * oType->xdiv * oType->ydiv * oType->animcount * oType->zdiv;
oType->imageData = new uint16_t[oType->numsprites];
ASSERT(oType->imageData);
for(unsigned int i = 0; i < oType->numsprites; i++) {
yatc_fread(&oType->imageData[i], sizeof(uint16_t), 1, fp);
ECORR16(oType->imageData[i]);
}
if(id <= ObjectType::maxItemId){
m_item.addElement(oType, id);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId)){
m_outfit.addElement(oType, id - ObjectType::maxItemId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId)){
m_effect.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId);
}
else if(id <= (ObjectType::maxItemId + ObjectType::maxOutfitId + ObjectType::maxEffectId + ObjectType::maxDistanceId)){
m_distance.addElement(oType, id - ObjectType::maxItemId - ObjectType::maxOutfitId - ObjectType::maxEffectId);
}
id++;
}
fclose(fp);
m_datLoaded = true;
return true;
}
ObjectType* Objects::getItemType(uint16_t id)
{
return m_item.getElement(id);
}
ObjectType* Objects::getOutfitType(uint16_t id)
{
return m_outfit.getElement(id);
}
ObjectType* Objects::getEffectType(uint16_t id)
{
return m_effect.getElement(id);
}
ObjectType* Objects::getDistanceType(uint16_t id)