Skip to content

Commit 260ba51

Browse files
committed
Update 2.0.12.9
2 parents 2b0b63a + 9e2feea commit 260ba51

File tree

14 files changed

+644
-476
lines changed

14 files changed

+644
-476
lines changed

xivModdingFramework/Cache/XivCache.cs

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Data.SQLite;
44
using System.IO;
5+
using System.Linq;
56
using System.Threading.Tasks;
67
using xivModdingFramework.General.Enums;
78
using xivModdingFramework.Items;
@@ -20,7 +21,7 @@ public class XivCache
2021
{
2122
private GameInfo _gameInfo;
2223
private DirectoryInfo _dbPath;
23-
private static readonly Version CacheVersion = new Version("0.0.0.24");
24+
private static readonly Version CacheVersion = new Version("0.0.0.25");
2425
private const string dbFileName = "mod_cache.db";
2526
private const string creationScript = "CreateDB.sql";
2627
private string _connectionString { get
@@ -134,10 +135,10 @@ public void RebuildCache()
134135
throw new NotSupportedException("A valid language must be specified when rebuilding the Cache.");
135136
}
136137

137-
CreateCache();
138-
139138
try
140139
{
140+
CreateCache();
141+
141142
await RebuildItemsCache();
142143
await RebuildMonstersCache();
143144
await RebuildUiCache();
@@ -426,21 +427,19 @@ private async Task RebuildItemsCache()
426427
{
427428
foreach (var item in items)
428429
{
429-
var query = @"insert into items (exd_id, primary_id, secondary_id, imc_variant, slot, slot_full, name, icon_id, primary_id_2, secondary_id_2, imc_variant_2)
430-
values($exd_id, $primary_id, $secondary_id, $imc_variant, $slot, $slot_full, $name, $icon_id, $primary_id_2, $secondary_id_2, $imc_variant_2)";
430+
var query = @"insert into items ( exd_id, primary_id, secondary_id, imc_variant, slot, slot_full, name, icon_id, is_weapon)
431+
values($exd_id, $primary_id, $secondary_id, $imc_variant, $slot, $slot_full, $name, $icon_id, $is_weapon)";
431432
using (var cmd = new SQLiteCommand(query, db))
432433
{
433434
cmd.Parameters.AddWithValue("exd_id", item.ExdID);
434435
cmd.Parameters.AddWithValue("primary_id", item.ModelInfo.PrimaryID);
435436
cmd.Parameters.AddWithValue("secondary_id", item.ModelInfo.SecondaryID);
437+
cmd.Parameters.AddWithValue("is_weapon", ((XivGearModelInfo)item.ModelInfo).IsWeapon);
436438
cmd.Parameters.AddWithValue("slot", item.GetItemSlotAbbreviation());
437439
cmd.Parameters.AddWithValue("slot_full", item.SecondaryCategory);
438440
cmd.Parameters.AddWithValue("imc_variant", item.ModelInfo.ImcSubsetID);
439441
cmd.Parameters.AddWithValue("name", item.Name);
440442
cmd.Parameters.AddWithValue("icon_id", item.IconNumber);
441-
cmd.Parameters.AddWithValue("primary_id_2", item.SecondaryModelInfo == null ? 0 : (int?)item.SecondaryModelInfo.PrimaryID);
442-
cmd.Parameters.AddWithValue("secondary_id_2", item.SecondaryModelInfo == null ? 0 : (int?)item.SecondaryModelInfo.SecondaryID);
443-
cmd.Parameters.AddWithValue("imc_variant_2", item.SecondaryModelInfo == null ? 0 : (int?)item.SecondaryModelInfo.ImcSubsetID);
444443
cmd.ExecuteScalar();
445444
}
446445
}
@@ -694,37 +693,49 @@ public async Task<List<XivGear>> GetCachedGearList(string substring = null)
694693
where.Value = "%" + substring + "%";
695694
}
696695

697-
return await BuildListFromTable("items", where, async (reader) =>
696+
List<XivGear> mainHands = new List<XivGear>();
697+
List<XivGear> offHands = new List<XivGear>();
698+
var list = await BuildListFromTable("items", where, async (reader) =>
698699
{
700+
var primaryMi = new XivGearModelInfo();
701+
699702
var item = new XivGear
700703
{
701704
ExdID = reader.GetInt32("exd_id"),
702705
PrimaryCategory = XivStrings.Gear,
703706
SecondaryCategory = reader.GetString("slot_full"),
704-
ModelInfo = new XivModelInfo(),
705-
SecondaryModelInfo = new XivModelInfo()
707+
ModelInfo = primaryMi,
706708
};
707709

708710
item.Name = reader.GetString("name");
709711
item.IconNumber = (uint)reader.GetInt32("icon_id");
710-
item.ModelInfo.PrimaryID = reader.GetInt32("primary_id");
711-
item.ModelInfo.SecondaryID = reader.GetInt32("secondary_id");
712-
item.ModelInfo.ImcSubsetID = reader.GetInt32("imc_variant");
712+
primaryMi.IsWeapon = reader.GetBoolean("is_weapon");
713+
primaryMi.PrimaryID = reader.GetInt32("primary_id");
714+
primaryMi.SecondaryID = reader.GetInt32("secondary_id");
715+
primaryMi.ImcSubsetID = reader.GetInt32("imc_variant");
713716

714-
if (reader.GetInt32("primary_id_2") > 0)
717+
if(item.Name.Contains(XivStrings.Main_Hand))
715718
{
716-
item.SecondaryModelInfo.PrimaryID = reader.GetInt32("primary_id_2");
717-
item.SecondaryModelInfo.SecondaryID = reader.GetInt32("secondary_id_2");
718-
item.SecondaryModelInfo.ImcSubsetID = reader.GetInt32("imc_variant_2");
719-
}
720-
else
719+
mainHands.Add(item);
720+
} else if (item.Name.Contains(XivStrings.Off_Hand))
721721
{
722-
item.SecondaryModelInfo = null;
722+
offHands.Add(item);
723723
}
724724

725725
return item;
726726
});
727727

728+
// Assign pairs based on items that came out of the same EXD row.
729+
foreach(var item in mainHands)
730+
{
731+
var pair = offHands.FirstOrDefault(x => x.ExdID == item.ExdID);
732+
if(pair != null)
733+
{
734+
pair.PairedItem = item;
735+
item.PairedItem = pair;
736+
}
737+
}
738+
return list;
728739
}
729740

730741
/// <summary>
@@ -909,6 +920,12 @@ public WhereClause()
909920
/// <returns></returns>
910921
public string GetSql(bool includeWhere = true, bool skipJoin = true)
911922
{
923+
// No clause if no valid value.
924+
if((Inner == null || Inner.Count == 0) && (Column == null || Column == ""))
925+
{
926+
return "";
927+
}
928+
912929
var result = "";
913930
if(includeWhere)
914931
{
@@ -960,7 +977,7 @@ public string GetSql(bool includeWhere = true, bool skipJoin = true)
960977

961978

962979
// [AND/OR] [COLUMN] [=/LIKE]
963-
if (Comparer == ComparisonType.Like)
980+
if (Comparer == ComparisonType.Equal)
964981
{
965982
result += " = ";
966983
}
@@ -987,7 +1004,10 @@ public void AddParameters(SQLiteCommand cmd)
9871004
}
9881005
else
9891006
{
990-
cmd.Parameters.AddWithValue(Column, Value);
1007+
if (Column != null && Column != "")
1008+
{
1009+
cmd.Parameters.AddWithValue(Column, Value);
1010+
}
9911011
}
9921012
}
9931013
}

xivModdingFramework/Items/Categories/Gear.cs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
using System;
1718
using System.Collections.Generic;
1819
using System.IO;
1920
using System.Linq;
@@ -97,16 +98,15 @@ await Task.Run(() => Parallel.ForEach(itemDictionary, (item) =>
9798
// This checks whether there is any model data present in the current item
9899
if (item.Value[modelDataCheckOffset] <= 0 && item.Value[modelDataCheckOffset + 1] <= 0) return;
99100

100-
// Gear can have 2 separate models (MNK weapons for example)
101-
var primaryMi = new XivModelInfo();
102-
var secondaryMi = new XivModelInfo();
101+
var primaryMi = new XivGearModelInfo();
102+
var secondaryMi = new XivGearModelInfo();
103+
var hasSecondary = false;
103104

104105
var xivGear = new XivGear
105106
{
106107
ExdID = item.Key,
107108
PrimaryCategory = XivStrings.Gear,
108109
ModelInfo = primaryMi,
109-
SecondaryModelInfo = secondaryMi
110110
};
111111

112112
/* Used to determine if the given model is a weapon
@@ -140,6 +140,7 @@ await Task.Run(() => Parallel.ForEach(itemDictionary, (item) =>
140140
if (weaponVariant != 0)
141141
{
142142
primaryMi.ImcSubsetID = weaponVariant;
143+
primaryMi.IsWeapon = true;
143144
isWeapon = true;
144145
}
145146

@@ -170,6 +171,7 @@ await Task.Run(() => Parallel.ForEach(itemDictionary, (item) =>
170171
if (weaponVariant != 0)
171172
{
172173
secondaryMi.ImcSubsetID = weaponVariant;
174+
secondaryMi.IsWeapon = true;
173175
isWeapon = true;
174176
}
175177

@@ -208,9 +210,29 @@ await Task.Run(() => Parallel.ForEach(itemDictionary, (item) =>
208210
xivGear.Name = new string(nameString.Where(c => !char.IsControl(c)).ToArray());
209211
xivGear.Name = xivGear.Name.Trim();
210212

213+
// If we have a secondary model
214+
215+
XivGear secondaryItem = null;
216+
if(secondaryMi.PrimaryID != 0)
217+
{
218+
// Make a new item for it.
219+
secondaryItem = (XivGear)xivGear.Clone();
220+
secondaryItem.ModelInfo = secondaryMi;
221+
xivGear.Name += " - " + XivStrings.Main_Hand;
222+
secondaryItem.Name += " - " + XivStrings.Off_Hand;
223+
xivGear.PairedItem = secondaryItem;
224+
secondaryItem.PairedItem = xivGear;
225+
xivGear.SecondaryCategory = XivStrings.Dual_Wield;
226+
secondaryItem.SecondaryCategory = XivStrings.Dual_Wield;
227+
}
228+
211229
lock (_gearLock)
212230
{
213231
xivGearList.Add(xivGear);
232+
if(secondaryItem != null)
233+
{
234+
xivGearList.Add(secondaryItem);
235+
}
214236
}
215237
}
216238
}));
@@ -233,7 +255,7 @@ private List<XivGear> GetMissingGear()
233255
Name = "SmallClothes Body",
234256
PrimaryCategory = XivStrings.Gear,
235257
SecondaryCategory = _slotNameDictionary[4],
236-
ModelInfo = new XivModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0}
258+
ModelInfo = new XivGearModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0}
237259
};
238260

239261
xivGearList.Add(xivGear);
@@ -243,7 +265,7 @@ private List<XivGear> GetMissingGear()
243265
Name = "SmallClothes Hands",
244266
PrimaryCategory = XivStrings.Gear,
245267
SecondaryCategory = _slotNameDictionary[5],
246-
ModelInfo = new XivModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
268+
ModelInfo = new XivGearModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
247269
};
248270

249271
xivGearList.Add(xivGear);
@@ -253,7 +275,7 @@ private List<XivGear> GetMissingGear()
253275
Name = "SmallClothes Legs",
254276
PrimaryCategory = XivStrings.Gear,
255277
SecondaryCategory = _slotNameDictionary[7],
256-
ModelInfo = new XivModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
278+
ModelInfo = new XivGearModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
257279
};
258280

259281
xivGearList.Add(xivGear);
@@ -263,7 +285,7 @@ private List<XivGear> GetMissingGear()
263285
Name = "SmallClothes Feet",
264286
PrimaryCategory = XivStrings.Gear,
265287
SecondaryCategory = _slotNameDictionary[8],
266-
ModelInfo = new XivModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
288+
ModelInfo = new XivGearModelInfo { PrimaryID = 0, ImcSubsetID = 1, SecondaryID = 0 }
267289
};
268290

269291
xivGearList.Add(xivGear);
@@ -273,7 +295,7 @@ private List<XivGear> GetMissingGear()
273295
Name = "SmallClothes Body (NPC)",
274296
PrimaryCategory = XivStrings.Gear,
275297
SecondaryCategory = _slotNameDictionary[4],
276-
ModelInfo = new XivModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
298+
ModelInfo = new XivGearModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
277299
};
278300

279301
xivGearList.Add(xivGear);
@@ -283,7 +305,7 @@ private List<XivGear> GetMissingGear()
283305
Name = "SmallClothes Hands (NPC)",
284306
PrimaryCategory = XivStrings.Gear,
285307
SecondaryCategory = _slotNameDictionary[5],
286-
ModelInfo = new XivModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
308+
ModelInfo = new XivGearModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
287309
};
288310

289311
xivGearList.Add(xivGear);
@@ -293,7 +315,7 @@ private List<XivGear> GetMissingGear()
293315
Name = "SmallClothes Legs (NPC)",
294316
PrimaryCategory = XivStrings.Gear,
295317
SecondaryCategory = _slotNameDictionary[7],
296-
ModelInfo = new XivModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
318+
ModelInfo = new XivGearModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
297319
};
298320

299321
xivGearList.Add(xivGear);
@@ -303,7 +325,7 @@ private List<XivGear> GetMissingGear()
303325
Name = "SmallClothes Feet (NPC)",
304326
PrimaryCategory = XivStrings.Gear,
305327
SecondaryCategory = _slotNameDictionary[8],
306-
ModelInfo = new XivModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
328+
ModelInfo = new XivGearModelInfo { PrimaryID = 9903, ImcSubsetID = 1, SecondaryID = 0 }
307329
};
308330

309331
xivGearList.Add(xivGear);
@@ -313,7 +335,7 @@ private List<XivGear> GetMissingGear()
313335
Name = "SmallClothes Feet 2 (NPC)",
314336
PrimaryCategory = XivStrings.Gear,
315337
SecondaryCategory = _slotNameDictionary[8],
316-
ModelInfo = new XivModelInfo { PrimaryID = 9901, ImcSubsetID = 1, SecondaryID = 0 }
338+
ModelInfo = new XivGearModelInfo { PrimaryID = 9901, ImcSubsetID = 1, SecondaryID = 0 }
317339
};
318340

319341
xivGearList.Add(xivGear);
@@ -372,10 +394,10 @@ public async Task<List<XivRace>> GetRacesForTextures(XivGear xivGear, XivDataFil
372394
switch (itemType)
373395
{
374396
case XivItemType.equipment:
375-
mtrlFile = $"mt_c{ID}e{modelID}_{SlotAbbreviationDictionary[xivGear.SecondaryCategory]}_a.mtrl";
397+
mtrlFile = $"mt_c{ID}e{modelID}_{xivGear.GetItemSlotAbbreviation()}_a.mtrl";
376398
break;
377399
case XivItemType.accessory:
378-
mtrlFile = $"mt_c{ID}a{modelID}_{SlotAbbreviationDictionary[xivGear.SecondaryCategory]}_a.mtrl";
400+
mtrlFile = $"mt_c{ID}a{modelID}_{xivGear.GetItemSlotAbbreviation()}_a.mtrl";
379401
break;
380402
default:
381403
mtrlFile = "";
@@ -451,10 +473,10 @@ public async Task<List<XivRace>> GetRacesForModels(XivGear xivGear, XivDataFile
451473
switch (itemType)
452474
{
453475
case XivItemType.equipment:
454-
mdlFile = $"c{ID}e{modelID}_{SlotAbbreviationDictionary[xivGear.SecondaryCategory]}.mdl";
476+
mdlFile = $"c{ID}e{modelID}_{xivGear.GetItemSlotAbbreviation()}.mdl";
455477
break;
456478
case XivItemType.accessory:
457-
mdlFile = $"c{ID}a{modelID}_{SlotAbbreviationDictionary[xivGear.SecondaryCategory]}.mdl";
479+
mdlFile = $"c{ID}a{modelID}_{xivGear.GetItemSlotAbbreviation()}.mdl";
458480
break;
459481
default:
460482
mdlFile = "";

xivModdingFramework/Items/Categories/Housing.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,6 @@ await Task.Run(() => Parallel.ForEach(pictureDictionary.Values, (housingItem) =>
241241
int itemDataLength = 168;
242242
const int itemIconDataOffset = 136;
243243

244-
if (_xivLanguage == XivLanguage.Chinese)
245-
{
246-
itemDataLength = 160;
247-
}
248-
249244
var ex = new Ex(_gameDirectory, _xivLanguage);
250245
var pictureDictionary = await ex.ReadExData(XivEx.picture);
251246
var itemDictionary = await ex.ReadExData(XivEx.item);

xivModdingFramework/Items/DataContainers/XivGear.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ public class XivGear : IItemModel
7373
/// </summary>
7474
public XivModelInfo ModelInfo { get; set; }
7575

76-
/// <summary>
77-
/// The Secondary Model Information for the gear item
78-
/// </summary>
79-
public XivModelInfo SecondaryModelInfo { get; set; }
80-
8176
/// <summary>
8277
/// The Icon Number associated with the gear item
8378
/// </summary>
@@ -88,15 +83,15 @@ public class XivGear : IItemModel
8883
/// </summary>
8984
public int EquipSlotCategory { get; set; }
9085

86+
/// <summary>
87+
/// The other item in this pair (main or offhand)
88+
/// </summary>
89+
public XivGear PairedItem { get; set; }
90+
9191
public object Clone()
9292
{
9393
var copy = (XivGear)this.MemberwiseClone();
94-
copy.ModelInfo = (XivModelInfo)ModelInfo.Clone();
95-
96-
if (SecondaryModelInfo != null)
97-
{
98-
copy.SecondaryModelInfo = (XivModelInfo)SecondaryModelInfo.Clone();
99-
}
94+
copy.ModelInfo = (XivGearModelInfo)ModelInfo.Clone();
10095

10196
return copy;
10297
}
@@ -108,4 +103,9 @@ public int CompareTo(object obj)
108103

109104
public override string ToString() => Name;
110105
}
106+
107+
public class XivGearModelInfo : XivModelInfo
108+
{
109+
public bool IsWeapon = false;
110+
}
111111
}

0 commit comments

Comments
 (0)