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.
22 #include "../../includes/win32def.h"
23 #include "../Core/Interface.h"
24 #include "../Core/EffectMgr.h"
25 #include "ITMImporter.h"
41 bool ITMImp::Open(DataStream
* stream
, bool autoFree
)
50 this->autoFree
= autoFree
;
52 str
->Read( Signature
, 8 );
53 if (strncmp( Signature
, "ITM V1 ", 8 ) == 0) {
55 } else if (strncmp( Signature
, "ITM V1.1", 8 ) == 0) {
57 } else if (strncmp( Signature
, "ITM V2.0", 8 ) == 0) {
60 printf( "[ITMImporter]: This file is not a valid ITM File\n" );
67 Item
* ITMImp::GetItem(Item
*s
)
75 str
->ReadDword( &s
->ItemName
);
76 str
->ReadDword( &s
->ItemNameIdentified
);
77 str
->ReadResRef( s
->ReplacementItem
);
78 str
->ReadDword( &s
->Flags
);
79 str
->ReadWord( &s
->ItemType
);
80 str
->ReadDword( &s
->UsabilityBitmask
);
81 str
->Read( s
->AnimationType
,2 ); //intentionally not reading word!
83 if (s
->AnimationType
[i
]==' ') {
84 s
->AnimationType
[i
]=0;
87 str
->Read( &s
->MinLevel
, 1 );
88 str
->Read( &s
->unknown1
, 1 );
89 str
->Read( &s
->MinStrength
,1 );
90 str
->Read( &s
->unknown2
, 1 );
91 str
->Read( &s
->MinStrengthBonus
, 1 );
93 str
->Read( &s
->MinIntelligence
, 1 );
95 str
->Read( &s
->MinDexterity
, 1 );
97 str
->Read( &s
->MinWisdom
, 1 );
99 s
->KitUsability
=(k1
<<24) | (k2
<<16) | (k3
<<8) | k4
; //bg2/iwd2 specific
100 str
->Read( &s
->MinConstitution
, 1 );
101 str
->Read( &s
->WeaProf
, 1 ); //bg2 specific
102 str
->Read( &s
->MinCharisma
, 1 );
103 str
->Read( &s
->unknown3
, 1 );
104 str
->ReadDword( &s
->Price
);
105 str
->ReadWord( &s
->StackAmount
);
106 str
->ReadResRef( s
->ItemIcon
);
107 str
->ReadWord( &s
->LoreToID
);
108 str
->ReadResRef( s
->GroundIcon
);
109 str
->ReadDword( &s
->Weight
);
110 str
->ReadDword( &s
->ItemDesc
);
111 str
->ReadDword( &s
->ItemDescIdentified
);
112 str
->ReadResRef( s
->DescriptionIcon
);
113 str
->ReadDword( &s
->Enchantment
);
114 str
->ReadDword( &s
->ExtHeaderOffset
);
115 str
->ReadWord( &s
->ExtHeaderCount
);
116 str
->ReadDword( &s
->FeatureBlockOffset
);
117 str
->ReadWord( &s
->EquippingFeatureOffset
);
118 str
->ReadWord( &s
->EquippingFeatureCount
);
122 s
->WieldColor
= 0xffff;
123 memset( s
->unknown
, 0, 26 );
125 //skipping header data for iwd2
126 if (version
== ITM_VER_IWD2
) {
127 str
->Read( s
->unknown
, 16 );
130 if (version
== ITM_VER_PST
) {
131 str
->ReadResRef( s
->Dialog
);
132 str
->ReadDword( &s
->DialogName
);
134 str
->ReadWord( &WieldColor
);
135 if (s
->AnimationType
[0]) {
136 s
->WieldColor
= WieldColor
;
138 str
->Read( s
->unknown
, 26 );
141 s
->DialogName
= core
->GetItemDialStr(s
->Name
);
142 core
->GetItemDialRes(s
->Name
, s
->Dialog
);
144 s
->ItemExcl
=core
->GetItemExcl(s
->Name
);
146 s
->ext_headers
= core
->GetITMExt( s
->ExtHeaderCount
);
148 for (i
= 0; i
< s
->ExtHeaderCount
; i
++) {
149 str
->Seek( s
->ExtHeaderOffset
+ i
* 56, GEM_STREAM_START
);
150 GetExtHeader( s
, s
->ext_headers
+ i
);
153 //48 is the size of the feature block
154 s
->equipping_features
= core
->GetFeatures( s
->EquippingFeatureCount
);
156 str
->Seek( s
->FeatureBlockOffset
+ 48*s
->EquippingFeatureOffset
,
158 for (i
= 0; i
< s
->EquippingFeatureCount
; i
++) {
159 GetFeature(s
->equipping_features
+i
);
163 if (!core
->IsAvailable( IE_BAM_CLASS_ID
)) {
164 printf( "[ITMImporter]: No BAM Importer Available.\n" );
170 void ITMImp::GetExtHeader(Item
*s
, ITMExtHeader
* eh
)
173 ieWord ProjectileType
;
175 str
->Read( &eh
->AttackType
,1 );
176 str
->Read( &eh
->IDReq
,1 );
177 str
->Read( &eh
->Location
,1 );
178 str
->Read( &eh
->unknown1
,1 );
179 str
->ReadResRef( eh
->UseIcon
);
180 str
->Read( &eh
->Target
,1 );
181 str
->Read( &tmpByte
,1 );
185 eh
->TargetNumber
= tmpByte
;
186 str
->ReadWord( &eh
->Range
);
187 str
->ReadWord( &ProjectileType
);
188 str
->ReadWord( &eh
->Speed
);
189 str
->ReadWord( &eh
->THAC0Bonus
);
190 str
->ReadWord( &eh
->DiceSides
);
191 str
->ReadWord( &eh
->DiceThrown
);
192 //if your compiler doesn't like this, then we need a ReadWordSigned
193 str
->ReadWord( (ieWord
*) &eh
->DamageBonus
);
194 str
->ReadWord( &eh
->DamageType
);
195 str
->ReadWord( &eh
->FeatureCount
);
196 str
->ReadWord( &eh
->FeatureOffset
);
197 str
->ReadWord( &eh
->Charges
);
198 str
->ReadWord( &eh
->ChargeDepletion
);
199 str
->ReadDword( &eh
->RechargeFlags
);
200 str
->ReadWord( &eh
->ProjectileAnimation
);
201 //for some odd reasons 0 and 1 are the same
202 if (eh
->ProjectileAnimation
) {
203 eh
->ProjectileAnimation
--;
206 unsigned int i
; //msvc6.0 can't cope with index variable scope
208 for (i
= 0; i
< 3; i
++) {
209 str
->ReadWord( &eh
->MeleeAnimation
[i
] );
214 str
->ReadWord( &tmp
); //arrow
215 if (tmp
) i
|=PROJ_ARROW
;
216 str
->ReadWord( &tmp
); //xbow
217 if (tmp
) i
|=PROJ_BOLT
;
218 str
->ReadWord( &tmp
); //bullet
219 if (tmp
) i
|=PROJ_BULLET
;
220 //this hack is required for Nordom's crossbow in PST
221 if (!i
&& (eh
->AttackType
==ITEM_AT_BOW
) ) {
225 //this hack is required for the practicing arrows in BG1
226 if (!i
&& (eh
->AttackType
==ITEM_AT_PROJECTILE
) ) {
231 i
|=(1<<ProjectileType
)>>1;
233 eh
->ProjectileQualifier
=i
;
235 //48 is the size of the feature block
236 eh
->features
= core
->GetFeatures(eh
->FeatureCount
);
237 str
->Seek( s
->FeatureBlockOffset
+ 48*eh
->FeatureOffset
, GEM_STREAM_START
);
238 for (i
= 0; i
< eh
->FeatureCount
; i
++) {
239 GetFeature(eh
->features
+i
);
243 void ITMImp::GetFeature(Effect
*fx
)
245 EffectMgr
* eM
= ( EffectMgr
* ) core
->GetInterface( IE_EFF_CLASS_ID
);
246 eM
->Open( str
, false );
248 core
->FreeInterface( eM
);
251 #include "../../includes/plugindef.h"
253 GEMRB_PLUGIN(0xD913A54, "ITM File Importer")
254 PLUGIN_CLASS(IE_ITM_CLASS_ID
, ITMImp
)