Skip to content

Commit

Permalink
Change CurrentDifficultyID to null for sniffs started mid session
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Dec 26, 2024
1 parent d64020d commit f16ce25
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion WowPacketParser/Parsing/Parsers/MovementHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class MovementHandler
[ThreadStatic]
public static uint CurrentMapId;

public static uint CurrentDifficultyID = 1;
public static uint? CurrentDifficultyID = null; // null and not -1 to force compiler errors when code isnt right
public static int CurrentPhaseMask = 1;

// this is a dictionary because ConcurrentSet does not exist
Expand Down
2 changes: 1 addition & 1 deletion WowPacketParser/Parsing/Parsers/SpellHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ public static void FillSpellListCooldown(uint spellId, int time, uint entry)
if (!Settings.SQLOutputFlag.HasAnyFlagBit(SQLOutput.creature_spell_list))
return;

var existingEntry = Storage.CreatureSpellLists.Where(p => p.Item1.SpellId == spellId && p.Item1.Id == (entry * 100 + 5 + CoreParsers.MovementHandler.CurrentDifficultyID)).SingleOrDefault();
var existingEntry = Storage.CreatureSpellLists.Where(p => p.Item1.SpellId == spellId && p.Item1.Id == (entry * 100 + CreatureSpellList.ConvertDifficultyToIdx(CoreParsers.MovementHandler.CurrentDifficultyID))).SingleOrDefault();
if (existingEntry != null)
{
// can be min max, not just fixed
Expand Down
4 changes: 2 additions & 2 deletions WowPacketParser/SQL/Builders/Spawns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static string Creature(Dictionary<WowGuid, Unit> units)
(ClientVersion.Expansion >= ClientType.Cataclysm && creature.Movement.Flags.HasAnyFlag(Enums.v4.MovementFlag.Hover)))
row.Data.PositionZ -= creature.UnitData.HoverHeight;

row.Data.SpawnTimeSecs = creature.GetDefaultSpawnTime(creature.DifficultyID);
row.Data.SpawnTimeSecs = creature.GetDefaultSpawnTime(creature.DifficultyID ?? 0);
row.Data.WanderDistance = wanderDistance;
row.Data.MovementType = movementType;

Expand Down Expand Up @@ -503,7 +503,7 @@ public static string GameObject(Dictionary<WowGuid, GameObject> gameObjects)
addonRows.Add(addonRow);
}

row.Data.SpawnTimeSecs = go.GetDefaultSpawnTime(go.DifficultyID);
row.Data.SpawnTimeSecs = go.GetDefaultSpawnTime(go.DifficultyID ?? 0);
row.Data.AnimProgress = go.GameObjectData.PercentHealth;
row.Data.State = (uint)go.GameObjectData.State;

Expand Down
18 changes: 13 additions & 5 deletions WowPacketParser/SQL/Builders/UnitMisc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public static Dictionary<ValueTuple<uint, uint>, ValueTuple<int, int>> GetDiffic

foreach (var pair in entries.SelectMany(entry => entry))
{
if (list.ContainsKey((pair.Key.GetEntry(), pair.Value.DifficultyID)))
list[(pair.Key.GetEntry(), pair.Value.DifficultyID)].Add(pair.Value.UnitData.Level ?? 0);
if (list.ContainsKey((pair.Key.GetEntry(), pair.Value.DifficultyID ?? 0)))
list[(pair.Key.GetEntry(), pair.Value.DifficultyID ?? 0)].Add(pair.Value.UnitData.Level ?? 0);
else
list.Add((pair.Key.GetEntry(), pair.Value.DifficultyID), new List<int> { pair.Value.UnitData.Level ?? 0 });
list.Add((pair.Key.GetEntry(), pair.Value.DifficultyID ?? 0), new List<int> { pair.Value.UnitData.Level ?? 0 });
}

var result = list.ToDictionary(pair => pair.Key, pair => ValueTuple.Create(pair.Value.Min(), pair.Value.Max()));
Expand Down Expand Up @@ -228,8 +228,8 @@ public static string CreatureTemplateScalingData(Dictionary<WowGuid, Unit> units
{
Entry = unit.Key.GetEntry(),
DifficultyID = npc.DifficultyID,
MinLevel = difficultyLevels[(unit.Key.GetEntry(), npc.DifficultyID)].Item1,
MaxLevel = difficultyLevels[(unit.Key.GetEntry(), npc.DifficultyID)].Item2,
MinLevel = difficultyLevels[(unit.Key.GetEntry(), npc.DifficultyID ?? 0)].Item1,
MaxLevel = difficultyLevels[(unit.Key.GetEntry(), npc.DifficultyID ?? 0)].Item2,
};
UpdateCreatureStaticFlags(ref npc, ref creatureDifficulty);
WowPacketParser.SQL.SQLDatabase.CheckCreatureTemplateDifficultyNonWDBFallbacks(ref creatureDifficulty, creatureDifficulty.DifficultyID.Value);
Expand Down Expand Up @@ -363,6 +363,10 @@ public static string CreatureSpellLists()
spellList.Item1.Comments = split[0] + "(Heroic)" + " - " + split[1];
}
}
else if (spellList.Item1.Id % 10 == 4)
{
spellList.Item1.Comments = "(UNK DIFFICULTY) - " + spellList.Item1.Comments;
}
}
}
else if (Settings.TargetedDatabase == TargetedDatabase.WrathOfTheLichKing)
Expand Down Expand Up @@ -406,6 +410,10 @@ public static string CreatureSpellLists()
spellList.Item1.Comments = split[0] + stringAddition + " - " + split[1];
}
}
else if (modulo == 4)
{
spellList.Item1.Comments = "(UNK DIFFICULTY) - " + spellList.Item1.Comments;
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions WowPacketParser/Store/Objects/CreatureSpellList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,15 @@ public sealed record CreatureSpellList : IDataModel

[DBFieldName("Comments")]
public string Comments = "";

public static int ConvertDifficultyToIdx(uint? difficultyId)
{
switch (difficultyId)
{
case null: return 4;
default: return 5 + (int)difficultyId - 1;
case 0: return 5; // open world
}
}
}
}
2 changes: 1 addition & 1 deletion WowPacketParser/Store/Objects/WoWObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public record WoWObject

public int? PhaseOverride = null;

public uint DifficultyID;
public uint? DifficultyID;

public bool ForceTemporarySpawn;

Expand Down
2 changes: 1 addition & 1 deletion WowPacketParserModule.V3_4_0_45166/Parsers/PetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void HandlePetSpells(Packet packet)
else
operationName = StoreGetters.GetName(StoreNameType.Spell, (int)spellId, false);

var potentialKey = (int)(petGuid.GetEntry() * 100 + 5 + CoreParsers.MovementHandler.CurrentDifficultyID);
var potentialKey = (int)(petGuid.GetEntry() * 100 + CreatureSpellList.ConvertDifficultyToIdx(CoreParsers.MovementHandler.CurrentDifficultyID));
if (Storage.CreatureSpellLists.Where(p => p.Item1.Id == potentialKey && p.Item1.SpellId == spellId).SingleOrDefault() == null)
Storage.CreatureSpellLists.Add(new CreatureSpellList
{
Expand Down
2 changes: 1 addition & 1 deletion WowPacketParserModule.V4_4_0_54481/Parsers/PetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static void HandlePetSpells(Packet packet)
else
operationName = StoreGetters.GetName(StoreNameType.Spell, (int)spellId, false);

var potentialKey = (int)(petGuid.GetEntry() * 100 + 5 + CoreParsers.MovementHandler.CurrentDifficultyID);
var potentialKey = (int)(petGuid.GetEntry() * 100 + CreatureSpellList.ConvertDifficultyToIdx(CoreParsers.MovementHandler.CurrentDifficultyID));
if (Storage.CreatureSpellLists.Where(p => p.Item1.Id == potentialKey && p.Item1.SpellId == spellId).SingleOrDefault() == null)
Storage.CreatureSpellLists.Add(new CreatureSpellList
{
Expand Down
2 changes: 1 addition & 1 deletion WowPacketParserModule.V6_0_2_19033/Parsers/PetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void HandlePetSpells(Packet packet)
else
operationName = StoreGetters.GetName(StoreNameType.Spell, (int)spellId, false);

var potentialKey = (int)(petGuid.GetEntry() * 100 + 5 + CoreParsers.MovementHandler.CurrentDifficultyID);
var potentialKey = (int)(petGuid.GetEntry() * 100 + CreatureSpellList.ConvertDifficultyToIdx(CoreParsers.MovementHandler.CurrentDifficultyID));
if (Storage.CreatureSpellLists.Where(p => p.Item1.Id == potentialKey && p.Item1.SpellId == spellId).SingleOrDefault() == null)
Storage.CreatureSpellLists.Add(new CreatureSpellList
{
Expand Down
2 changes: 1 addition & 1 deletion WowPacketParserModule.V7_0_3_22248/Parsers/PetHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void HandlePetSpells(Packet packet)
else
operationName = StoreGetters.GetName(StoreNameType.Spell, (int)spellId, false);

var potentialKey = (int)(petGuid.GetEntry() * 100 + 5 + CoreParsers.MovementHandler.CurrentDifficultyID);
var potentialKey = (int)(petGuid.GetEntry() * 100 + CreatureSpellList.ConvertDifficultyToIdx(CoreParsers.MovementHandler.CurrentDifficultyID));
if (Storage.CreatureSpellLists.Where(p => p.Item1.Id == potentialKey && p.Item1.SpellId == spellId).SingleOrDefault() == null)
Storage.CreatureSpellLists.Add(new CreatureSpellList
{
Expand Down

0 comments on commit f16ce25

Please sign in to comment.