1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "TISImporter.h"
23 #include "RGBAColor.h"
26 #include "Interface.h"
29 TISImporter::TISImporter(void)
35 TISImporter::~TISImporter(void)
37 if (str
&& autoFree
) {
42 bool TISImporter::Open(DataStream
* stream
, bool autoFree
)
47 if (str
&& this->autoFree
) {
51 this->autoFree
= autoFree
;
53 str
->Read( Signature
, 8 );
55 if (Signature
[0] == 'T' && Signature
[1] == 'I' && Signature
[2] == 'S') {
56 if (strncmp( Signature
, "TIS V1 ", 8 ) != 0) {
57 printf( "[TISImporter]: Not a Valid TIS File.\n" );
60 str
->ReadDword( &TilesCount
);
61 str
->ReadDword( &TilesSectionLen
);
62 str
->ReadDword( &headerShift
);
63 str
->ReadDword( &TileSize
);
65 str
->Seek( -8, GEM_CURRENT_POS
);
70 Tile
* TISImporter::GetTile(unsigned short* indexes
, int count
,
71 unsigned short* secondary
)
73 Animation
* ani
= new Animation( count
);
75 //pause key stops animation
76 ani
->gameAnimation
= true;
77 for (int i
= 0; i
< count
; i
++) {
78 ani
->AddFrame( GetTile( indexes
[i
] ), i
);
81 Animation
* sec
= new Animation( count
);
83 for (int i
= 0; i
< count
; i
++) {
84 sec
->AddFrame( GetTile( secondary
[i
] ), i
);
86 return new Tile( ani
, sec
);
88 return new Tile( ani
);
91 Sprite2D
* TISImporter::GetTile(int index
)
95 void* pixels
= malloc( 4096 );
96 unsigned long pos
= index
*(1024+4096) + headerShift
;
97 if(str
->Size()<pos
+1024+4096) {
98 // try to only report error once per file
99 static TISImporter
*last_corrupt
= NULL
;
100 if (last_corrupt
!= this) {
101 /*printf("Invalid tile index: %d\n",index);
102 printf("FileSize: %ld\n", str->Size() );
103 printf("Position: %ld\n", pos);
104 printf("Shift: %d\n", headerShift);*/
105 printf("Corrupt WED file encountered; couldn't find any more tiles at tile %d\n", index
);
109 // original PS:T AR0609 and AR0612 report far more tiles than are actually present :(
110 memset(pixels
, 0, 4096);
111 memset(Palette
, 0, 256 * sizeof(Color
));
113 Sprite2D
* spr
= core
->GetVideoDriver()->CreateSprite8( 64, 64, 8, pixels
, Palette
, false, 0 );
114 spr
->XPos
= spr
->YPos
= 0;
117 str
->Seek( ( index
* ( 1024 + 4096 ) + headerShift
), GEM_STREAM_START
);
118 str
->Read( &RevCol
, 1024 );
120 bool transparent
= false;
121 for (int i
= 0; i
< 256; i
++) {
122 Palette
[i
].r
= RevCol
[i
].r
;
123 Palette
[i
].g
= RevCol
[i
].g
;
124 Palette
[i
].b
= RevCol
[i
].b
;
125 Palette
[i
].a
= RevCol
[i
].a
;
126 if (Palette
[i
].g
==255 && !Palette
[i
].r
&& !Palette
[i
].b
) {
128 printMessage( "TISImporter", "Tile has two green (transparent) palette entries\n", LIGHT_RED
);
135 str
->Read( pixels
, 4096 );
136 Sprite2D
* spr
= core
->GetVideoDriver()->CreateSprite8( 64, 64, 8, pixels
, Palette
, transparent
, transindex
);
137 spr
->XPos
= spr
->YPos
= 0;
141 #include "plugindef.h"
143 GEMRB_PLUGIN(0x19F91578, "TIS File Importer")
144 PLUGIN_CLASS(IE_TIS_CLASS_ID
, TISImporter
)