Created
April 18, 2011 14:08
-
-
Save Konctantin/925418 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using System.Collections.Generic; | |
using Kamilla; | |
using Kamilla.WorldOfWarcraft; | |
using Kamilla.WorldOfWarcraft.OpcodeDatas; | |
namespace PacketViewer.UpdatePacketParser | |
{ | |
internal partial class UpdateParser | |
{ | |
public string StatementParsedString(WoWObject obj) | |
{ | |
StringBuilder content = new StringBuilder(); | |
content.AppendFormatLine("-- Wow Object: {0}", obj.WowGuid); | |
var coord = obj.Movement.Position; | |
var splin = obj.Movement.Spline.Splines; | |
var sflags = (uint)obj.Movement.Spline.Flags; | |
#region Gameobgect | |
if (obj.TypeId == ObjectTypeId.GameObject && | |
!(obj.WowGuid.High == HighGuid.MoTransport)) | |
{ | |
var owner = obj.GetUlongValue(GameObjectUpdateFields.OBJECT_FIELD_CREATED_BY); | |
if (owner != 0ul) | |
{ | |
content.AppendFormatLine("-- This object created by: {0}", new WowGuid(owner)); | |
content.AppendLine("/*"); | |
} | |
var flags = obj.GetUIntValue(GameObjectUpdateFields.GAMEOBJECT_FLAGS); | |
var faction = obj.GetUIntValue(GameObjectUpdateFields.GAMEOBJECT_FACTION); | |
//var level = obj.GetUIntValue(GameObjectUpdateFields.GAMEOBJECT_LEVEL); | |
var state = obj.GetByteValue(GameObjectUpdateFields.GAMEOBJECT_BYTES_1, 0); | |
//var goType = obj.GetByteValue(GameObjectUpdateFields.GAMEOBJECT_BYTES_1, 1); | |
//var goArtKit = obj.GetByteValue(GameObjectUpdateFields.GAMEOBJECT_BYTES_1, 2); | |
var animProgress = obj.GetByteValue(GameObjectUpdateFields.GAMEOBJECT_BYTES_1, 3); | |
// надо продумать и понять как увязывать Quaternion & GAMEOBJECT_PARENTROTATION | |
var r0 = obj.GetFloatValue(GameObjectUpdateFields.GAMEOBJECT_PARENTROTATION); | |
var r1 = obj.GetFloatValue(GameObjectUpdateFields.GAMEOBJECT_PARENTROTATION_2); | |
var r2 = obj.GetFloatValue(GameObjectUpdateFields.GAMEOBJECT_PARENTROTATION_3); | |
var r3 = obj.GetFloatValue(GameObjectUpdateFields.GAMEOBJECT_PARENTROTATION_4); | |
#region Quaternion | |
// Пока что эти данные будут не доступны | |
//Quaternion rotation = new Quaternion(mInfo.GoRotationULong); | |
//var r0 = rotation.X; | |
//var r1 = rotation.Y; | |
//var r2 = rotation.Z; | |
//var r3 = rotation.W; | |
#endregion | |
content.AppendLine( | |
@"REPLACE INTO `gameobject` (`guid`, `id`, `map`, `spawnMask`, `phaseMask`, `position_x`, `position_y`, `position_z`, `orientation`, `rotation0`, `rotation1`, `rotation2`, `rotation3`, `spawntimesecs`, `animprogress`, `state`)"); | |
content.AppendFormatLine( | |
@"VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15});", | |
obj.WowGuid.Counter, obj.Entry, obj.Map, 1, obj.Phase, | |
coord.X, coord.Y, coord.Z, coord.O, r0, r1, r2, r3, | |
300, animProgress, state); | |
if (flags != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `gameobject_template` SET `flags` = {0} WHERE `entry` = {1};", | |
flags, obj.Entry); | |
} | |
if (faction != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `gameobject_template` SET `faction` = {0} WHERE `entry` = {1};", | |
faction, obj.Entry); | |
} | |
if (owner != 0ul) | |
{ | |
content.AppendLine("*/"); | |
} | |
} | |
#endregion | |
#region Unit | |
if (obj.TypeId == ObjectTypeId.Unit && | |
!(obj.WowGuid.High == HighGuid.Pet || obj.WowGuid.High == HighGuid.Pet2)) | |
{ | |
var owner = obj.GetUlongValue(UnitUpdateFields.UNIT_FIELD_CREATEDBY); | |
if (owner != 0ul) | |
{ | |
content.AppendFormatLine("-- This object created by: {0}", new WowGuid(owner)); | |
content.AppendLine("/*"); | |
} | |
var modelId = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_NATIVEDISPLAYID); | |
var curHealth = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_MAXHEALTH); | |
var curMana = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_MAXPOWER1); | |
var faction = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_FACTIONTEMPLATE); | |
var unitClass = obj.GetByteValue(UnitUpdateFields.UNIT_FIELD_BYTES_0, 1); | |
var npcFlag = obj.GetUIntValue(UnitUpdateFields.UNIT_NPC_FLAGS); | |
var npcLevel = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_LEVEL); | |
var dynamicFlags = obj.GetUIntValue(UnitUpdateFields.UNIT_DYNAMIC_FLAGS); | |
var attackPower = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_ATTACK_POWER); | |
var rangeAtackPower = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_RANGED_ATTACK_POWER); | |
var dmgMultiplier = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_ATTACK_POWER_MULTIPLIER); | |
var sheath = obj.GetByteValue(UnitUpdateFields.UNIT_FIELD_BYTES_2, 0); | |
var pvpState = obj.GetByteValue(UnitUpdateFields.UNIT_FIELD_BYTES_2, 1); | |
var bytes1 = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_BYTES_1); | |
var bytes2 = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_BYTES_2); | |
var emote = obj.GetUIntValue(UnitUpdateFields.UNIT_NPC_EMOTESTATE); | |
var mount = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_MOUNTDISPLAYID); | |
var baseAttackTime = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_BASEATTACKTIME); | |
var baseAttackTime2 = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_BASEATTACKTIME_2);// not used | |
var rangeAttackTime = obj.GetUIntValue(UnitUpdateFields.UNIT_FIELD_RANGEDATTACKTIME); | |
var equipEntry1 = obj.GetUIntValue(UnitUpdateFields.UNIT_VIRTUAL_ITEM_SLOT_ID); | |
var equipEntry2 = obj.GetUIntValue(UnitUpdateFields.UNIT_VIRTUAL_ITEM_SLOT_ID_2); | |
var equipEntry3 = obj.GetUIntValue(UnitUpdateFields.UNIT_VIRTUAL_ITEM_SLOT_ID_3); | |
var minDamage = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_MINDAMAGE); | |
var maxDamage = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_MAXDAMAGE); | |
var minOfHandeDmg = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_MINOFFHANDDAMAGE);// not used | |
var maxOfHandeDmg = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_MAXOFFHANDDAMAGE);// not used | |
var scale = obj.GetFloatValue(ObjectUpdateFields.OBJECT_FIELD_SCALE_X); | |
var speedWalk = obj.GetFloatValue(UnitUpdateFields.UNIT_MOD_CAST_SPEED); | |
var boundingRadius = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_BOUNDINGRADIUS); | |
var combatReach = obj.GetFloatValue(UnitUpdateFields.UNIT_FIELD_COMBATREACH); | |
var auras = GetAuras(obj); | |
#region Movement Type | |
var MovementType = 0; | |
// зверьки и простые смертные мобы практически всегда ходят рамдомно | |
// возможно прийдется построить какую-то коссвенную цепочку флагов - для определения | |
// типа движения моба | |
if(npcFlag == 0 ) | |
MovementType = 1; | |
// если есть хоть какой-то сплин, но только 1, значит моб будет рандомником | |
if (splin.Count == 1) | |
MovementType = 1; | |
// у кого есть точки движения - ходят только по ним, это могут быть и простые смертные мобы | |
if (splin.Count > 1) | |
MovementType = 2; | |
#endregion | |
content.AppendLine( | |
@"REPLACE INTO `creature` (`guid`, `id`, `map`, `spawnMask`, `phaseMask`, `modelid`, `equipment_id`, `position_x`, `position_y`, `position_z`, `orientation`, `spawntimesecs`, `spawndist`, `currentwaypoint`, `curhealth`, `curmana`, `DeathState`, `MovementType`)"); | |
content.AppendFormatLine( | |
@"VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17});", | |
obj.WowGuid.Counter, obj.Entry, obj.Map, 1, obj.Phase, modelId, 0, coord.X, coord.Y, coord.Z, coord.O, 300, 0, 0, curHealth, curMana, 0, MovementType); | |
if (equipEntry1 != 0 || equipEntry2 != 0 || equipEntry3 != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `equipment_id` = {0}, WHERE entry = {0};", obj.Entry); | |
content.AppendFormatLine( | |
@"REPLACE INTO `creature_equip_template` VALUES ({0}, {1}, {2}, {3});", | |
obj.Entry, equipEntry1, equipEntry2, equipEntry3); | |
} | |
if (mount != 0 || bytes1 != 0 || sheath != 0 || pvpState != 0 || emote != 0 || sflags != 0) | |
{ | |
content.AppendFormatLine( | |
@"REPLACE INTO `creature_addon` VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, '{7}');", | |
obj.WowGuid.Counter, mount, bytes1, sheath, pvpState, emote, sflags/*moveflags*/, auras); | |
} | |
if (mount != 0 || bytes1 != 0 || bytes2 != 0 || emote != 0 || sflags != 0) | |
{ | |
content.AppendFormatLine( | |
@"-- REPLACE INTO `creature_addon` VALUES ({0}, {1}, {2}, {3}, {4}, {5}, '{6}');", | |
obj.WowGuid.Counter, mount, bytes1, bytes2, emote, sflags/*moveflags*/, auras); | |
} | |
if (scale != 1.0f)// default = 1 | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `scale` = {0} WHERE entry = {1};", | |
scale, obj.Entry); | |
} | |
if (speedWalk != 1.0f)// default = 1 | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `speed_walk` = {0} WHERE entry = {1};", | |
speedWalk, obj.Entry); | |
} | |
if (faction != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `faction_A` = {0}, `faction_H` = {0} WHERE `entry` = {1};", | |
faction, obj.Entry); | |
} | |
if (baseAttackTime != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `baseattacktime` = {0} WHERE `entry` = {1};", | |
baseAttackTime, obj.Entry); | |
} | |
if (rangeAttackTime != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `rangeattacktime` = {0} WHERE `entry` = {1};", | |
rangeAttackTime, obj.Entry); | |
} | |
if (unitClass != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `unit_class` = {0} WHERE `entry` = {1};", | |
unitClass, obj.Entry); | |
} | |
if (npcFlag != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `npcflag` = `npcflag` | {0} WHERE `entry` = {1};", | |
npcFlag, obj.Entry); | |
} | |
if (npcLevel != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `minlevel` = {0}, `maxlevel` = {0} WHERE `entry` = {1};", | |
npcLevel, obj.Entry); | |
} | |
if (curHealth != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `minhealth` = {0}, `maxhealth` = {0} WHERE `entry` = {1};", | |
curHealth, obj.Entry); | |
} | |
if (curMana != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `minmana` = {0}, `maxmana` = {0} WHERE `entry` = {1};", | |
curMana, obj.Entry); | |
} | |
if (dynamicFlags != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `dynamicflags` = {0} WHERE `entry` = {1};", | |
dynamicFlags, obj.Entry); | |
} | |
if (minDamage != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `mindmg` = {0} WHERE `entry` = {1};", | |
minDamage, obj.Entry); | |
} | |
if (maxDamage != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `maxdmg` = {0} WHERE `entry` = {1};", | |
maxDamage, obj.Entry); | |
} | |
if (attackPower != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `attackpower` = {0} WHERE `entry` = {1};", | |
attackPower, obj.Entry); | |
} | |
if (rangeAtackPower != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `rangedattackpower` = {0} WHERE `entry` = {1};", | |
rangeAtackPower, obj.Entry); | |
} | |
if (dmgMultiplier != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `dmg_multiplier` = {0} WHERE `entry` = {1};", | |
dmgMultiplier, obj.Entry); | |
} | |
if (obj.Movement.VehicleId != 0) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_template` SET `VehicleId` = {0} WHERE `entry` = {1};", | |
obj.Movement.VehicleId, obj.Entry); | |
} | |
if (boundingRadius != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_model_info` SET `bounding_radius` = {0} WHERE `modelid` = {1};", | |
boundingRadius, modelId); | |
} | |
if (combatReach != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"UPDATE `creature_model_info` SET `combat_reach` = {0} WHERE `modelid` = {1};", | |
combatReach, modelId); | |
} | |
#region Not Used | |
if (baseAttackTime2 != 0) | |
{ | |
content.AppendFormatLine( | |
@"-- UPDATE `creature_template` SET `baseattacktime_2` = {0} WHERE `entry` = {1};", | |
baseAttackTime2, obj.Entry); | |
} | |
if (minOfHandeDmg != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"-- UPDATE `creature_template` SET `minofhandedmg` = {0} WHERE `entry` = {1};", | |
minOfHandeDmg, obj.Entry); | |
} | |
if (maxOfHandeDmg != 0.0f) | |
{ | |
content.AppendFormatLine( | |
@"-- UPDATE `creature_template` SET `maxofhandedmg` = {0} WHERE `entry` = {1};", | |
maxOfHandeDmg, obj.Entry); | |
} | |
#endregion | |
if (splin.Count > 1) | |
{ | |
content.AppendLine( | |
@"REPLACE INTO `creature_movement` (`id`, `point`, `position_x`, `position_y`, `position_z`) VALUES"); | |
for (int i = 0; i < splin.Count; ++i) | |
{ | |
content.AppendFormatLine( | |
@"({0}, {1}, {2:F5}, {3:F5}, {4:F5}){5}", | |
obj.WowGuid.Counter, i + 1, splin[i].X, splin[i].Y, splin[i].Z, | |
(i < splin.Count - 1 ? "," : ";")); | |
} | |
} | |
if (owner != 0ul) | |
{ | |
content.AppendLine("*/"); | |
} | |
} | |
#endregion | |
#region MoTransport | |
if (obj.TypeId == ObjectTypeId.GameObject && | |
(obj.WowGuid.High == HighGuid.MoTransport)) | |
{ | |
var entry = obj.GetUIntValue(ObjectUpdateFields.OBJECT_FIELD_ENTRY); | |
var period = obj.GetUIntValue(GameObjectUpdateFields.GAMEOBJECT_LEVEL); | |
content.AppendFormatLine( | |
@"REPLACE INTO `transports` VALUES ({0}, '<Need Name for entry: {0}>', {1});", | |
entry, period); | |
} | |
#endregion | |
content.AppendLine(); | |
return content.ToString(); | |
} | |
private string GetAuras(WoWObject obj) | |
{ | |
StringBuilder content = new StringBuilder(); | |
if (Auras.ContainsKey(obj.WowGuid)) | |
{ | |
foreach (AuraUpdate spellInfo in Auras[obj.WowGuid].Updates) | |
{ | |
if (spellInfo.SpellId > 0 && (spellInfo.Flags & AuraFlags.NotCaster) != 0) | |
{ | |
for (int i = 0; i < AuraUpdate.MAX_EFFECT_INDEX; ++i) | |
{ | |
if ((spellInfo.Flags & AuraFlags.EffectIndex_0 + i) != 0) | |
{ | |
content.AppendFormat("{0} {1} ", spellInfo.SpellId, i); | |
} | |
} | |
} | |
} | |
} | |
return content.ToString().Trim(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment