Skip to content

Commit 2b4f2a7

Browse files
committed
Merge branch 'index_rework' into develop
2 parents 6a075b8 + 6d2a8aa commit 2b4f2a7

File tree

18 files changed

+1937
-2419
lines changed

18 files changed

+1937
-2419
lines changed

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ public static async Task<List<XivDependencyRoot>> GetDependencyRoots(string inte
16731673
/// <param name="primary"></param>
16741674
/// <param name="secondary"></param>
16751675
/// <returns></returns>
1676-
private static async Task<List<XivDependencyRootInfo>> TestAllRoots(Dictionary<int, HashSet<int>> Hashes, XivItemType primary, XivItemType secondary) {
1676+
private static async Task<List<XivDependencyRootInfo>> TestAllRoots(Dictionary<uint, HashSet<uint>> Hashes, XivItemType primary, XivItemType secondary) {
16771677

16781678

16791679
var result = new List<XivDependencyRootInfo>(3000);
@@ -1717,10 +1717,10 @@ await Task.Run(() => {
17171717
{
17181718
// For furniture, they're valid as long as they have an assets folder we can find.
17191719
var assetFolder = folder + "/asset";
1720-
var folderHash = HashGenerator.GetHash(assetFolder);
1720+
var folderHash = (uint)HashGenerator.GetHash(assetFolder);
17211721

17221722
var sgdName = root.GetSgdName();
1723-
var sgdHash = HashGenerator.GetHash(sgdName);
1723+
var sgdHash = (uint)HashGenerator.GetHash(sgdName);
17241724

17251725
if (Hashes.ContainsKey(folderHash) && Hashes[folderHash].Contains(sgdHash))
17261726
{
@@ -1730,9 +1730,9 @@ await Task.Run(() => {
17301730
else
17311731
{
17321732
// Test to see if the IMC file exists.
1733-
var folderHash = HashGenerator.GetHash(folder);
1733+
var folderHash = (uint)HashGenerator.GetHash(folder);
17341734
var imcName = root.GetBaseFileName(false) + ".imc";
1735-
var imcHash = HashGenerator.GetHash(imcName);
1735+
var imcHash = (uint)HashGenerator.GetHash(imcName);
17361736

17371737
if (Hashes.ContainsKey(folderHash) && Hashes[folderHash].Contains(imcHash))
17381738
{
@@ -1764,9 +1764,9 @@ await Task.Run(() => {
17641764
if (usesImc)
17651765
{
17661766
// Test to see if the IMC file exists.
1767-
var folderHash = HashGenerator.GetHash(folder);
1767+
var folderHash = (uint)HashGenerator.GetHash(folder);
17681768
var imcName = XivItemTypes.GetSystemPrefix((XivItemType)root.SecondaryType) + root.SecondaryId.ToString().PadLeft(4,'0') + ".imc";
1769-
var imcHash = HashGenerator.GetHash(imcName);
1769+
var imcHash = (uint)HashGenerator.GetHash(imcName);
17701770

17711771
if (Hashes.ContainsKey(folderHash) && Hashes[folderHash].Contains(imcHash))
17721772
{
@@ -1789,13 +1789,13 @@ await Task.Run(() => {
17891789
{
17901790

17911791
var mfolder = folder + "/model";
1792-
var mfolderHash = HashGenerator.GetHash(mfolder);
1792+
var mfolderHash = (uint)HashGenerator.GetHash(mfolder);
17931793
var matFolder = folder + "/material";
1794-
var matFolderHash = HashGenerator.GetHash(matFolder);
1794+
var matFolderHash = (uint)HashGenerator.GetHash(matFolder);
17951795
var matFolder1 = folder + "/material/v0001";
1796-
var matFolder1Hash = HashGenerator.GetHash(matFolder1);
1796+
var matFolder1Hash = (uint)HashGenerator.GetHash(matFolder1);
17971797
var texFolder = folder + "/texture";
1798-
var texFolderHash = HashGenerator.GetHash(texFolder);
1798+
var texFolderHash = (uint)HashGenerator.GetHash(texFolder);
17991799

18001800
// Things that don't use IMC files are basically only the human tree, which is a complete mess.
18011801
foreach (var slot in slots)
@@ -1813,7 +1813,7 @@ await Task.Run(() => {
18131813
// If they have an MDL or MTRL we can resolve, they're valid.
18141814

18151815
var mdlFile = nRoot.GetBaseFileName(true) + ".mdl";
1816-
var mdlFileHash = HashGenerator.GetHash(mdlFile);
1816+
var mdlFileHash = (uint)HashGenerator.GetHash(mdlFile);
18171817

18181818
var mtrlFile = "mt_" + nRoot.GetBaseFileName(true) + "_a.mtrl";
18191819
if(secondary == XivItemType.tail)
@@ -1823,7 +1823,7 @@ await Task.Run(() => {
18231823
mtrlFile = "mt_" + nRoot.GetBaseFileName(false) + "_a.mtrl";
18241824
}
18251825

1826-
var mtrlFileHash = HashGenerator.GetHash(mtrlFile);
1826+
var mtrlFileHash = (uint)HashGenerator.GetHash(mtrlFile);
18271827

18281828
var hasModel = Hashes.ContainsKey(mfolderHash) && Hashes[mfolderHash].Contains(mdlFileHash);
18291829
var hasMat = Hashes.ContainsKey(matFolderHash) && Hashes[matFolderHash].Contains(mtrlFileHash);

xivModdingFramework/Items/Categories/Companions.cs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -435,98 +435,6 @@ public async Task<List<string>> GetDemiHumanMountModelEquipPartList(IItemModel i
435435
return equipPartList;
436436
}
437437

438-
/// <summary>
439-
/// Searches for monsters with the given model ID
440-
/// </summary>
441-
/// <param name="modelID">The ID of the monster model</param>
442-
/// <param name="type">The type of monster to look for</param>
443-
/// <returns>A list of Search Results</returns>
444-
public async Task<List<SearchResults>> SearchMonstersByModelID(int modelID, XivItemType type)
445-
{
446-
var monsterSearchLock = new object();
447-
var monsterSearchLock1 = new object();
448-
var searchResultsList = new List<SearchResults>();
449-
var index = new Index(_gameDirectory);
450-
var id = modelID.ToString().PadLeft(4, '0');
451-
452-
var bodyVariantDictionary = new Dictionary<int, List<int>>();
453-
454-
if (type == XivItemType.monster)
455-
{
456-
var folder = $"chara/monster/m{id}/obj/body/b";
457-
458-
await Task.Run(() => Parallel.For(0, 100, (i) =>
459-
{
460-
var folderHashDictionary = new Dictionary<int, int>();
461-
462-
var mtrlFolder = $"{folder}{i.ToString().PadLeft(4, '0')}/material/v";
463-
464-
for (var j = 1; j < 100; j++)
465-
{
466-
lock (monsterSearchLock)
467-
{
468-
folderHashDictionary.Add(HashGenerator.GetHash($"{mtrlFolder}{j.ToString().PadLeft(4, '0')}"),
469-
j);
470-
}
471-
}
472-
473-
var variantList = index.GetFolderExistsList(folderHashDictionary, XivDataFile._04_Chara).Result;
474-
475-
if (variantList.Count > 0)
476-
{
477-
lock (monsterSearchLock1)
478-
{
479-
variantList.Sort();
480-
bodyVariantDictionary.Add(i, variantList);
481-
}
482-
483-
}
484-
}));
485-
}
486-
else if (type == XivItemType.demihuman)
487-
{
488-
var folder = $"chara/demihuman/d{id}/obj/equipment/e";
489-
490-
await Task.Run(() => Parallel.For(0, 100, (i) =>
491-
{
492-
var folderHashDictionary = new Dictionary<int, int>();
493-
494-
var mtrlFolder = $"{folder}{i.ToString().PadLeft(4, '0')}/material/v";
495-
496-
for (var j = 1; j < 100; j++)
497-
{
498-
lock (monsterSearchLock)
499-
{
500-
folderHashDictionary.Add(HashGenerator.GetHash($"{mtrlFolder}{j.ToString().PadLeft(4, '0')}"),
501-
j);
502-
}
503-
}
504-
505-
var variantList = index.GetFolderExistsList(folderHashDictionary, XivDataFile._04_Chara).Result;
506-
507-
if (variantList.Count > 0)
508-
{
509-
lock (monsterSearchLock1)
510-
{
511-
variantList.Sort();
512-
bodyVariantDictionary.Add(i, variantList);
513-
}
514-
}
515-
}));
516-
}
517-
518-
foreach (var bodyVariant in bodyVariantDictionary)
519-
{
520-
foreach (var variant in bodyVariant.Value)
521-
{
522-
searchResultsList.Add(new SearchResults { Body = bodyVariant.Key.ToString(), Slot = XivStrings.Monster, Variant = variant });
523-
}
524-
}
525-
526-
searchResultsList.Sort();
527-
528-
return searchResultsList;
529-
}
530438

531439
/// <summary>
532440
/// A dictionary containing the slot abbreviations in the format [equipment slot, slot abbreviation]

xivModdingFramework/Items/Categories/Gear.cs

Lines changed: 0 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -508,154 +508,6 @@ public async Task<List<XivRace>> GetRacesForModels(XivGear xivGear, XivDataFile
508508
return raceList;
509509
}
510510

511-
/// <summary>
512-
/// Searches for items given a model ID and item type
513-
/// </summary>
514-
/// <param name="modelID"> The model id used for searching</param>
515-
/// <param name="type">The type of item</param>
516-
/// <returns>A list of SearchResults objects</returns>
517-
public async Task<List<SearchResults>> SearchGearByModelID(int modelID, string type)
518-
{
519-
var searchLock = new object();
520-
var searchLock1 = new object();
521-
var searchResultsList = new List<SearchResults>();
522-
var resultCheckList = new List<string>();
523-
524-
var equipmentSlots = new string[] { "met", "glv", "dwn", "sho", "top", };
525-
var accessorySlots = new string[] { "ear", "nek", "rir", "ril", "wrs" };
526-
var parts = new string[] { "a", "b", "c", "d", "e", "f" };
527-
528-
var id = modelID.ToString().PadLeft(4, '0');
529-
var folder = "";
530-
531-
if (type.Equals("Equipment"))
532-
{
533-
folder = $"chara/equipment/e{id}/material/v";
534-
}
535-
else if (type.Equals("Accessory"))
536-
{
537-
folder = $"chara/accessory/a{id}/material/v";
538-
}
539-
else if (type.Equals("Weapon"))
540-
{
541-
folder = $"chara/weapon/w{id}/obj/body/b";
542-
}
543-
544-
var bodyVariantDictionary = new Dictionary<int, List<int>>();
545-
List<int> variantList = null;
546-
547-
if (type.Equals("Weapon"))
548-
{
549-
await Task.Run(() => Parallel.For(1, 200, (i) =>
550-
{
551-
var folderHashDictionary = new Dictionary<int, int>();
552-
553-
var wFolder = $"{folder}{i.ToString().PadLeft(4, '0')}/material/v";
554-
555-
Parallel.For(1, 200, (j) =>
556-
{
557-
lock (searchLock)
558-
{
559-
folderHashDictionary.Add(HashGenerator.GetHash($"{wFolder}{j.ToString().PadLeft(4, '0')}"), j);
560-
}
561-
});
562-
563-
variantList = _index.GetFolderExistsList(folderHashDictionary, XivDataFile._04_Chara).Result;
564-
565-
if (variantList.Count > 0)
566-
{
567-
variantList.Sort();
568-
569-
lock (searchLock1)
570-
{
571-
bodyVariantDictionary.Add(i, variantList);
572-
}
573-
}
574-
}));
575-
}
576-
else
577-
{
578-
var folderHashDictionary = new Dictionary<int, int>();
579-
580-
await Task.Run(() => Parallel.For(1, 200, (i) =>
581-
{
582-
lock (searchLock)
583-
{
584-
folderHashDictionary.Add(HashGenerator.GetHash($"{folder}{i.ToString().PadLeft(4, '0')}"), i);
585-
}
586-
}));
587-
588-
variantList = _index.GetFolderExistsList(folderHashDictionary, XivDataFile._04_Chara).Result;
589-
}
590-
591-
if (!type.Equals("Weapon"))
592-
{
593-
foreach (var variant in variantList)
594-
{
595-
var mtrlFolder = $"{folder}{variant.ToString().PadLeft(4, '0')}";
596-
var mtrlFile = "";
597-
598-
var mtrlFolderHashes =
599-
await _index.GetAllHashedFilesInFolder(HashGenerator.GetHash(mtrlFolder), XivDataFile._04_Chara);
600-
601-
foreach (var race in IDRaceDictionary.Keys)
602-
{
603-
string[] slots = null;
604-
605-
if (type.Equals("Equipment"))
606-
{
607-
slots = equipmentSlots;
608-
}
609-
else if (type.Equals("Accessory"))
610-
{
611-
slots = accessorySlots;
612-
}
613-
614-
foreach (var slot in slots)
615-
{
616-
foreach (var part in parts)
617-
{
618-
if (type.Equals("Equipment"))
619-
{
620-
mtrlFile = $"mt_c{race}e{id}_{slot}_{part}.mtrl";
621-
}
622-
else if (type.Equals("Accessory"))
623-
{
624-
mtrlFile = $"mt_c{race}a{id}_{slot}_{part}.mtrl";
625-
}
626-
627-
if (mtrlFolderHashes.Contains(HashGenerator.GetHash(mtrlFile)))
628-
{
629-
var abbrSlot = AbbreviationSlotDictionary[slot];
630-
if (!resultCheckList.Contains($"{abbrSlot}{variant.ToString()}"))
631-
{
632-
searchResultsList.Add(new SearchResults { Body = "-", Slot = abbrSlot, Variant = variant });
633-
resultCheckList.Add($"{abbrSlot}{variant.ToString()}");
634-
}
635-
636-
}
637-
}
638-
}
639-
}
640-
}
641-
}
642-
else
643-
{
644-
foreach (var bodyVariant in bodyVariantDictionary)
645-
{
646-
foreach (var variant in bodyVariant.Value)
647-
{
648-
searchResultsList.Add(new SearchResults { Body = bodyVariant.Key.ToString(), Slot = XivStrings.Main_Hand, Variant = variant });
649-
}
650-
}
651-
}
652-
653-
searchResultsList.Sort();
654-
655-
656-
return searchResultsList;
657-
}
658-
659511

660512

661513
// A dictionary containg <Slot ID, Gear Category>

xivModdingFramework/Items/Categories/Housing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public async Task<List<SearchResults>> SearchHousingByModelID(int modelID, XivIt
612612
folder = $"bgcommon/hou/indoor/general/{id}/material";
613613
}
614614

615-
if (await index.FolderExists(HashGenerator.GetHash(folder), XivDataFile._01_Bgcommon))
615+
if (await index.FolderExists(folder, XivDataFile._01_Bgcommon))
616616
{
617617
var searchResults = new SearchResults
618618
{
@@ -626,7 +626,7 @@ public async Task<List<SearchResults>> SearchHousingByModelID(int modelID, XivIt
626626

627627
folder = $"bgcommon/hou/outdoor/general/{id}/material";
628628

629-
if (await index.FolderExists(HashGenerator.GetHash(folder), XivDataFile._01_Bgcommon))
629+
if (await index.FolderExists(folder, XivDataFile._01_Bgcommon))
630630
{
631631
var searchResults = new SearchResults
632632
{

xivModdingFramework/Materials/FileTypes/Mtrl.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,7 @@ await Task.Run((Func<Task>)(async () =>
505505
.Replace("\0", "");
506506
var dx11FileName = Path.GetFileName(texturePath).Insert(0, "--");
507507

508-
if (await index.FileExists(HashGenerator.GetHash(dx11FileName),
509-
HashGenerator.GetHash(Path.GetDirectoryName(texturePath).Replace("\\", "/")),
508+
if (await index.FileExists(Path.GetDirectoryName(texturePath).Replace("\\", "/") + "/" + dx11FileName,
510509
DataFile))
511510
{
512511
texturePath = texturePath.Insert(texturePath.LastIndexOf("/") + 1, "--");
@@ -706,7 +705,7 @@ public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
706705
var dat = new Dat(_gameDirectory);
707706

708707
// Create the actual raw MTRL first. - Files should always be created top down.
709-
long offset = await dat.ImportType2Data(mtrlBytes.ToArray(), item.Name, xivMtrl.MTRLPath, item.SecondaryCategory, source);
708+
long offset = await dat.ImportType2Data(mtrlBytes.ToArray(), xivMtrl.MTRLPath, source, item);
710709

711710
// The MTRL file is now ready to go, but we need to validate the texture paths and create them if needed.
712711
var mapInfoList = xivMtrl.GetAllMapInfos(false);
@@ -715,9 +714,7 @@ public async Task<long> ImportMtrl(XivMtrl xivMtrl, IItem item, string source)
715714
foreach (var mapInfo in mapInfoList)
716715
{
717716
var path = mapInfo.Path;
718-
var fileHash = HashGenerator.GetHash(Path.GetFileName(path));
719-
var pathHash = HashGenerator.GetHash(path.Substring(0, path.LastIndexOf("/", StringComparison.Ordinal)));
720-
var exists = await _index.FileExists(fileHash, pathHash, IOUtil.GetDataFileFromPath(path));
717+
var exists = await _index.FileExists(mapInfo.Path, IOUtil.GetDataFileFromPath(path));
721718

722719
if(exists)
723720
{

0 commit comments

Comments
 (0)