Skip to content

Commit

Permalink
Fix namers crashing in online mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Dec 20, 2024
1 parent 8620b1a commit ec4be55
Showing 1 changed file with 54 additions and 48 deletions.
102 changes: 54 additions & 48 deletions Controllers/NamingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,34 +227,37 @@ public string Start()

var goNames = new Dictionary<uint, string>();

foreach (var gobjectCacheFile in Directory.GetFiles(SettingsManager.wowFolder, "gameobjectcache.wdb", SearchOption.AllDirectories))
if (!string.IsNullOrWhiteSpace(SettingsManager.wowFolder))
{
var flavorDir = new DirectoryInfo(gobjectCacheFile).Parent.Parent.Parent.Parent.Name;
foreach (var gobjectCacheFile in Directory.GetFiles(SettingsManager.wowFolder, "gameobjectcache.wdb", SearchOption.AllDirectories))
{
var flavorDir = new DirectoryInfo(gobjectCacheFile).Parent.Parent.Parent.Parent.Name;

// Don't bother with Classic or non-Flavor directories
if (flavorDir.Contains("classic") || !flavorDir.StartsWith('_'))
continue;
// Don't bother with Classic or non-Flavor directories
if (flavorDir.Contains("classic") || !flavorDir.StartsWith('_'))
continue;

// Skip if we don't have a build for this flavor
if (!CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).Any())
continue;
// Skip if we don't have a build for this flavor
if (!CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).Any())
continue;

var productVersionByFlavor = CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).First().Version;
var productVersionByFlavor = CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).First().Version;

if (productVersionByFlavor == null)
continue;
if (productVersionByFlavor == null)
continue;

Console.WriteLine("Loading " + gobjectCacheFile + " for " + productVersionByFlavor);
Console.WriteLine("Loading " + gobjectCacheFile + " for " + productVersionByFlavor);

var gobjectCache = WDBReader.Read(gobjectCacheFile, productVersionByFlavor);
foreach (var entry in gobjectCache.entries)
{
if (entry.Value.TryGetValue("GameObjectDisplayID", out var displayID))
var gobjectCache = WDBReader.Read(gobjectCacheFile, productVersionByFlavor);
foreach (var entry in gobjectCache.entries)
{
var displayIDButInt = uint.Parse(displayID);
if (entry.Value.TryGetValue("Name[0]", out var name) && !name.Contains(' ') && (name.Contains("10") || name.Contains("11")))
if (entry.Value.TryGetValue("GameObjectDisplayID", out var displayID))
{
goNames.TryAdd(displayIDButInt, name);
var displayIDButInt = uint.Parse(displayID);
if (entry.Value.TryGetValue("Name[0]", out var name) && !name.Contains(' ') && (name.Contains("10") || name.Contains("11")))
{
goNames.TryAdd(displayIDButInt, name);
}
}
}
}
Expand Down Expand Up @@ -348,44 +351,47 @@ public string Start()

var currentCreatureNames = SQLiteDB.GetCreatureNames();

foreach (var creatureCacheFile in Directory.GetFiles(SettingsManager.wowFolder, "creaturecache.wdb", SearchOption.AllDirectories))
if (!string.IsNullOrEmpty(SettingsManager.wowFolder))
{
var flavorDir = new DirectoryInfo(creatureCacheFile).Parent.Parent.Parent.Parent.Name;
foreach (var creatureCacheFile in Directory.GetFiles(SettingsManager.wowFolder, "creaturecache.wdb", SearchOption.AllDirectories))
{
var flavorDir = new DirectoryInfo(creatureCacheFile).Parent.Parent.Parent.Parent.Name;

// Don't bother with Classic or non-Flavor directories
if (flavorDir.Contains("classic") || !flavorDir.StartsWith('_'))
continue;
// Don't bother with Classic or non-Flavor directories
if (flavorDir.Contains("classic") || !flavorDir.StartsWith('_'))
continue;

// Skip if we don't have a build for this flavor
if (!CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).Any())
continue;
// Skip if we don't have a build for this flavor
if (!CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).Any())
continue;

var productVersionByFlavor = CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).First().Version;
var productVersionByFlavor = CASC.AvailableBuilds.Where(x => x.Folder == flavorDir).First().Version;

if (productVersionByFlavor == null)
continue;
if (productVersionByFlavor == null)
continue;

Console.WriteLine("Loading " + creatureCacheFile + " for " + productVersionByFlavor);
Console.WriteLine("Loading " + creatureCacheFile + " for " + productVersionByFlavor);

var creatureCache = WDBReader.Read(creatureCacheFile, productVersionByFlavor);
foreach (var entry in creatureCache.entries)
{
if (!currentCreatureNames.TryGetValue(entry.Key, out var currentCreatureName))
{
Console.WriteLine("Discovered new creature: " + entry.Value["Name[0]"] + " (" + entry.Key + ")");
SQLiteDB.InsertOrUpdateCreature((int)entry.Key, entry.Value["Name[0]"], creatureCache.buildInfo.build);
currentCreatureNames[entry.Key] = entry.Value["Name[0]"];
}
else if (currentCreatureName != entry.Value["Name[0]"] && creatureCache.clientBuild > SQLiteDB.creatureCache[(int)entry.Key])
var creatureCache = WDBReader.Read(creatureCacheFile, productVersionByFlavor);
foreach (var entry in creatureCache.entries)
{
Console.WriteLine("Updating creature name: " + currentCreatureName + " => " + entry.Value["Name[0]"] + " (" + entry.Key + ")");
SQLiteDB.InsertOrUpdateCreature((int)entry.Key, entry.Value["Name[0]"], creatureCache.buildInfo.build);
currentCreatureNames[entry.Key] = entry.Value["Name[0]"];
}
if (!currentCreatureNames.TryGetValue(entry.Key, out var currentCreatureName))
{
Console.WriteLine("Discovered new creature: " + entry.Value["Name[0]"] + " (" + entry.Key + ")");
SQLiteDB.InsertOrUpdateCreature((int)entry.Key, entry.Value["Name[0]"], creatureCache.buildInfo.build);
currentCreatureNames[entry.Key] = entry.Value["Name[0]"];
}
else if (currentCreatureName != entry.Value["Name[0]"] && creatureCache.clientBuild > SQLiteDB.creatureCache[(int)entry.Key])
{
Console.WriteLine("Updating creature name: " + currentCreatureName + " => " + entry.Value["Name[0]"] + " (" + entry.Key + ")");
SQLiteDB.InsertOrUpdateCreature((int)entry.Key, entry.Value["Name[0]"], creatureCache.buildInfo.build);
currentCreatureNames[entry.Key] = entry.Value["Name[0]"];
}

for (var i = 0; i < int.Parse(entry.Value["NumCreatureDisplays"]); i++)
{
SQLiteDB.InsertOrUpdateDisplayIDToCreatureID(int.Parse(entry.Value["CreatureDisplayInfoID[" + i + "]"]), (int)entry.Key);
for (var i = 0; i < int.Parse(entry.Value["NumCreatureDisplays"]); i++)
{
SQLiteDB.InsertOrUpdateDisplayIDToCreatureID(int.Parse(entry.Value["CreatureDisplayInfoID[" + i + "]"]), (int)entry.Key);
}
}
}
}
Expand Down

0 comments on commit ec4be55

Please sign in to comment.