public static void HandleUpdateFieldChangedValues(bool creating, Guid guid, ObjectType objType, Dictionary <int, UpdateField> updates, MovementInfo moves) { bool shouldCommit; bool isIntValue; bool flags; string fieldName = null; if (objType == ObjectType.Unit && guid.GetHighType() != HighGuidType.Pet) { foreach (var upVal in updates) { bool shouldOverride = false; int overrideVal = -1; Dictionary <string, string> overrideDict = new Dictionary <string, string>(); bool shouldOverrideDict = false; bool isTemplate = false; shouldCommit = true; isIntValue = true; flags = false; var idx = (UnitField)upVal.Key; var val = upVal.Value; switch (idx) { case UnitField.UNIT_CREATED_BY_SPELL: case UnitField.UNIT_FIELD_CREATEDBY: case UnitField.UNIT_FIELD_SUMMONEDBY: { shouldCommit = false; break; } case (UnitField)ObjectField.OBJECT_FIELD_SCALE_X: { fieldName = "scale"; isIntValue = false; break; } case UnitField.UNIT_DYNAMIC_FLAGS: { fieldName = "dynamicflags"; flags = true; break; } case UnitField.UNIT_NPC_FLAGS: { fieldName = "npcflag"; flags = true; break; } case UnitField.UNIT_FIELD_FLAGS: { fieldName = "unit_flags"; flags = true; break; } case UnitField.UNIT_FIELD_ATTACK_POWER: { fieldName = "attackpower"; break; } case UnitField.UNIT_FIELD_BASEATTACKTIME: { fieldName = "baseattacktime"; break; } case UnitField.UNIT_FIELD_LEVEL: { int lvl = val.Int32Value; uint entry = guid.GetEntry(); bool addMin = true; bool addMax = true; isTemplate = true; if (minLevels.ContainsKey(entry)) { if (lvl >= minLevels[entry]) { addMin = false; } } if (maxLevels.ContainsKey(entry)) { if (lvl <= maxLevels[entry]) { addMax = false; } } if (addMin) { overrideDict.Add("minlevel", lvl.ToString()); minLevels[entry] = lvl; } if (addMax) { overrideDict.Add("maxlevel", lvl.ToString()); maxLevels[entry] = lvl; } if (!addMin && !addMax) { shouldCommit = false; } shouldOverrideDict = true; break; } case UnitField.UNIT_FIELD_RANGED_ATTACK_POWER: { fieldName = "rangedattackpower"; break; } case UnitField.UNIT_FIELD_RANGEDATTACKTIME: { fieldName = "rangeattacktime"; break; } case UnitField.UNIT_FIELD_FACTIONTEMPLATE: { isTemplate = true; fieldName = "faction_A=" + val.Int32Value + ", faction_H"; break; } case UnitField.UNIT_FIELD_BASE_HEALTH: { fieldName = "minhealth = " + val.Int32Value + ", maxhealth"; break; } case UnitField.UNIT_FIELD_BASE_MANA: { fieldName = "minmana = " + val.Int32Value + ", maxmana"; break; } case UnitField.UNIT_FIELD_BYTES_0: { fieldName = "unitclass"; overrideVal = ((val.Int32Value & 0x00FF0000) >> 16); isTemplate = true; shouldOverride = true; break; } default: { shouldCommit = false; break; } } if (!shouldCommit) { continue; } var finalValue = shouldOverride ? (object)overrideVal : (isIntValue ? val.Int32Value : val.SingleValue); if (flags && finalValue is int) { finalValue = "0x" + ((int)finalValue).ToString("X8"); } if (isTemplate) { Dictionary <string, string> data; if (shouldOverrideDict) { data = overrideDict; } else { data = new Dictionary <string, string>(); data.Add(fieldName, finalValue.ToString()); } CreatureTemplateUpdate update = new CreatureTemplateUpdate(guid.GetEntry(), data); CreatureTemplateUpdateStorage.GetSingleton().Add(update); } else { } } } if (objType != ObjectType.GameObject) { return; } foreach (var upVal in updates) { shouldCommit = true; isIntValue = true; flags = false; var idx = (GameObjectField)upVal.Key; var val = upVal.Value; switch (idx) { case GameObjectField.OBJECT_FIELD_CREATED_BY: { shouldCommit = false; break; } case (GameObjectField)ObjectField.OBJECT_FIELD_SCALE_X: { fieldName = "size"; isIntValue = false; break; } case GameObjectField.GAMEOBJECT_FACTION: { fieldName = "faction"; break; } case GameObjectField.GAMEOBJECT_FLAGS: { fieldName = "flags"; flags = true; break; } default: { shouldCommit = false; break; } } if (!shouldCommit) { continue; } var finalValue = isIntValue ? (object)val.Int32Value : val.SingleValue; if (flags) { finalValue = "0x" + ((int)finalValue).ToString("X8"); } } // add to storage }
private static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; CmdLine = new CommandLine(args); string file; string loader; string nodump; string nohex; string tosql; string skiplarge; bool _toSQL = false; try { file = CmdLine.GetValue("-file"); loader = CmdLine.GetValue("-loader"); nodump = CmdLine.GetValue("-nodump"); nohex = CmdLine.GetValue("-nohex"); tosql = CmdLine.GetValue("-tosql"); skiplarge = CmdLine.GetValue("-skiplarge"); if (tosql.Equals(bool.TrueString, StringComparison.InvariantCultureIgnoreCase)) { _toSQL = true; } } catch (IndexOutOfRangeException) { PrintUsage("All command line options require an argument."); return; } try { var packets = Reader.Read(loader, file); if (packets == null) { PrintUsage("Could not open file " + file + " for reading."); return; } if (packets.Count() > 0) { var fullPath = Utilities.GetPathFromFullPath(file); Handler.InitializeLogFile(Path.Combine(fullPath, file + ".txt"), nodump, nohex, skiplarge); foreach (var packet in packets) { Handler.Parse(packet); } Handler.WriteToFile(); } } catch (Exception ex) { Console.WriteLine(ex.GetType()); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } Console.ResetColor(); if (_toSQL) { var fullPath = Utilities.GetPathFromFullPath(file); QuestStorage.GetSingleton().Output(Path.Combine(fullPath, file + "_questcache.sql")); CreatureStorage.GetSingleton().Output(Path.Combine(fullPath, file + "_creaturecache.sql")); GameObjectStorage.GetSingleton().Output(Path.Combine(fullPath, file + "_gameobjectcache.sql")); CreatureTemplateUpdateStorage.GetSingleton().Output(Path.Combine(fullPath, file + "_creaturecacheupdates.sql")); CreatureSpawnStorage css = CreatureSpawnStorage.GetSingleton(); GameObjectSpawnStorage gss = GameObjectSpawnStorage.GetSingleton(); Dictionary <int, Dictionary <Guid, WowObject> > dict = ObjectHandler.Objects; foreach (int map in dict.Keys) { Dictionary <Guid, WowObject> objectsInMap = dict[map]; foreach (Guid guid in objectsInMap.Keys) { WowObject obj = objectsInMap[guid]; if (obj.Type == ObjectType.Unit) { CreatureSpawn spawn = new CreatureSpawn(); spawn.Entry = guid.GetEntry(); spawn.Map = map; spawn.X = obj.Position.X; spawn.Y = obj.Position.Y; spawn.Z = obj.Position.Z; spawn.O = obj.Movement.Orientation; css.Add(spawn); } else if (obj.Type == ObjectType.GameObject) { GameObjectSpawn spawn = new GameObjectSpawn(); spawn.Entry = guid.GetEntry(); spawn.Map = map; spawn.X = obj.Position.X; spawn.Y = obj.Position.Y; spawn.Z = obj.Position.Z; spawn.O = obj.Movement.Orientation; gss.Add(spawn); } } } css.Output(Path.Combine(fullPath, file + "_creaturesniffedspawns.sql")); gss.Output(Path.Combine(fullPath, file + "_gameobjectsniffedspawns.sql")); } }