@@ -53,22 +53,10 @@ public Imc(DirectoryInfo gameDirectory, XivDataFile dataFile)
53
53
/// <param name="item">The item to get the version for</param>
54
54
/// <param name="modelInfo">The model info of the item</param>
55
55
/// <returns>The XivImc Data</returns>
56
- public async Task < XivImc > GetImcInfo ( IItemModel item , XivModelInfo modelInfo = null )
56
+ public async Task < XivImc > GetImcInfo ( IItemModel item , bool useSecondary = false )
57
57
{
58
58
var xivImc = new XivImc ( ) ;
59
59
60
- // Set based on item if we don't have one provided directly.
61
- if ( modelInfo == null )
62
- {
63
- modelInfo = item . ModelInfo ;
64
- }
65
-
66
- // If it's still null, error.
67
- if ( modelInfo == null )
68
- {
69
- throw new NotSupportedException ( "Cannot get IMC info." ) ;
70
- }
71
-
72
60
// These are the offsets to relevant data
73
61
// These will need to be changed if data gets added or removed with a patch
74
62
const int headerLength = 4 ;
@@ -78,8 +66,8 @@ public async Task<XivImc> GetImcInfo(IItemModel item, XivModelInfo modelInfo = n
78
66
var index = new Index ( _gameDirectory ) ;
79
67
var dat = new Dat ( _gameDirectory ) ;
80
68
81
- var itemType = ItemType . GetPrimaryItemType ( item ) ;
82
- var imcPath = GetImcPath ( modelInfo , itemType ) ;
69
+ var itemType = item . GetPrimaryItemType ( ) ;
70
+ var imcPath = GetImcPath ( item , useSecondary ) ;
83
71
84
72
var itemCategory = item . SecondaryCategory ;
85
73
@@ -90,9 +78,15 @@ public async Task<XivImc> GetImcInfo(IItemModel item, XivModelInfo modelInfo = n
90
78
{
91
79
if ( item . SecondaryCategory == XivStrings . Two_Handed )
92
80
{
93
- itemCategory = XivStrings . Hands ;
94
- itemType = XivItemType . equipment ;
95
- imcPath = GetImcPath ( modelInfo , itemType ) ;
81
+ // Jank workaround for two handed weapons that are actually gloves.
82
+ var tempItem = new XivGear ( )
83
+ {
84
+ PrimaryCategory = XivStrings . Gear ,
85
+ SecondaryCategory = XivStrings . Hands ,
86
+ Name = item . Name ,
87
+ ModelInfo = ( XivModelInfo ) item . ModelInfo . Clone ( )
88
+ } ;
89
+ imcPath = GetImcPath ( tempItem ) ;
96
90
97
91
imcOffset = await index . GetDataOffset ( HashGenerator . GetHash ( imcPath . Folder ) ,
98
92
HashGenerator . GetHash ( imcPath . File ) , _dataFile ) ;
@@ -123,7 +117,12 @@ await Task.Run(() =>
123
117
if ( itemType == XivItemType . weapon || itemType == XivItemType . monster )
124
118
{
125
119
// weapons and monsters do not have variant sets
126
- variantOffset = ( modelInfo . ImcSubsetID * variantLength ) + headerLength ;
120
+ variantOffset = ( item . ModelInfo . ImcSubsetID * variantLength ) + headerLength ;
121
+ if ( useSecondary )
122
+ {
123
+ XivGear gear = ( XivGear ) item ;
124
+ variantOffset = ( gear . SecondaryModelInfo . ImcSubsetID * variantLength ) + headerLength ;
125
+ }
127
126
128
127
// use default if offset is out of range
129
128
if ( variantOffset >= imcData . Length )
@@ -136,7 +135,7 @@ await Task.Run(() =>
136
135
// Variant Sets contain 5 variants for each slot
137
136
// These can be Head, Body, Hands, Legs, Feet or Ears, Neck, Wrists, LRing, RRing
138
137
// This skips to the correct variant set, then to the correct slot within that set for the item
139
- variantOffset = ( modelInfo . ImcSubsetID * variantSetLength ) +
138
+ variantOffset = ( item . ModelInfo . ImcSubsetID * variantSetLength ) +
140
139
( _slotOffsetDictionary [ itemCategory ] * variantLength ) + headerLength ;
141
140
142
141
// use defalut if offset is out of range
@@ -165,24 +164,15 @@ await Task.Run(() =>
165
164
/// Gets the full IMC information for a given item
166
165
/// </summary>
167
166
/// <param name="item"></param>
168
- /// <param name="modelInfo"> </param>
167
+ /// <param name="useSecondary">Determines if the SecondaryModelInfo should be used instead.(XivGear only) </param>
169
168
/// <returns>The ImcData data</returns>
170
- public async Task < FullImcInfo > GetFullImcInfo ( IItemModel item , XivModelInfo modelInfo = null )
169
+ public async Task < FullImcInfo > GetFullImcInfo ( IItemModel item , bool useSecondary = false )
171
170
{
172
- if ( modelInfo == null )
173
- {
174
- modelInfo = item . ModelInfo ;
175
- }
176
- if ( modelInfo == null )
177
- {
178
- throw new NotSupportedException ( "Attempted to get IMC info for invalid item." ) ;
179
- }
180
-
181
171
var index = new Index ( _gameDirectory ) ;
182
172
var dat = new Dat ( _gameDirectory ) ;
183
173
184
174
var itemType = ItemType . GetPrimaryItemType ( item ) ;
185
- var imcPath = GetImcPath ( modelInfo , itemType ) ;
175
+ var imcPath = GetImcPath ( item , useSecondary ) ;
186
176
187
177
var imcOffset = await index . GetDataOffset ( HashGenerator . GetHash ( imcPath . Folder ) , HashGenerator . GetHash ( imcPath . File ) , _dataFile ) ;
188
178
@@ -271,35 +261,39 @@ public async Task<FullImcInfo> GetFullImcInfo(IItemModel item, XivModelInfo mode
271
261
/// <param name="modelInfo">The model info of the item</param>
272
262
/// <param name="itemType">The type of the item</param>
273
263
/// <returns>A touple containing the Folder and File strings</returns>
274
- private static ( string Folder , string File ) GetImcPath ( XivModelInfo modelInfo , XivItemType itemType )
264
+ private static ( string Folder , string File ) GetImcPath ( IItemModel item , bool useSecondary = false )
275
265
{
276
- string imcFolder ;
266
+ string imcFolder = item . GetItemRootFolder ( ) ;
277
267
string imcFile ;
278
268
279
- var modelID = modelInfo . PrimaryID . ToString ( ) . PadLeft ( 4 , '0' ) ;
280
- var body = modelInfo . SecondaryID . ToString ( ) . PadLeft ( 4 , '0' ) ;
269
+ var primaryId = item . ModelInfo . PrimaryID . ToString ( ) . PadLeft ( 4 , '0' ) ;
270
+ var secondaryId = item . ModelInfo . SecondaryID . ToString ( ) . PadLeft ( 4 , '0' ) ;
271
+ var itemType = item . GetPrimaryItemType ( ) ;
281
272
282
273
switch ( itemType )
283
274
{
284
275
case XivItemType . equipment :
285
- imcFolder = $ "chara/{ itemType } /e{ modelID } ";
286
- imcFile = $ "e{ modelID } { ImcExtension } ";
276
+ imcFile = $ "e{ primaryId } { ImcExtension } ";
277
+ if ( useSecondary )
278
+ {
279
+ XivGear gear = ( XivGear ) item ;
280
+ var alternateId = gear . SecondaryModelInfo . PrimaryID . ToString ( ) . PadLeft ( 4 , '0' ) ;
281
+
282
+ imcFile = $ "e{ alternateId } { ImcExtension } ";
283
+ }
284
+
287
285
break ;
288
286
case XivItemType . accessory :
289
- imcFolder = $ "chara/{ itemType } /a{ modelID } ";
290
- imcFile = $ "a{ modelID } { ImcExtension } ";
287
+ imcFile = $ "a{ primaryId } { ImcExtension } ";
291
288
break ;
292
289
case XivItemType . weapon :
293
- imcFolder = $ "chara/{ itemType } /w{ modelID } /obj/body/b{ body } ";
294
- imcFile = $ "b{ body } { ImcExtension } ";
290
+ imcFile = $ "b{ secondaryId } { ImcExtension } ";
295
291
break ;
296
292
case XivItemType . monster :
297
- imcFolder = $ "chara/{ itemType } /m{ modelID } /obj/body/b{ body } ";
298
- imcFile = $ "b{ body } { ImcExtension } ";
293
+ imcFile = $ "b{ secondaryId } { ImcExtension } ";
299
294
break ;
300
295
case XivItemType . demihuman :
301
- imcFolder = $ "chara/{ itemType } /d{ modelID } /obj/equipment/e{ body } ";
302
- imcFile = $ "e{ body } { ImcExtension } ";
296
+ imcFile = $ "e{ secondaryId } { ImcExtension } ";
303
297
break ;
304
298
default :
305
299
imcFolder = "" ;
0 commit comments