/MaximusParserX/Dump/SQL/GameObjectSpawnHandler.cs

https://github.com/devmaximus/MaximusParserX · C# · 186 lines · 165 code · 21 blank · 0 comment · 19 complexity · 4cb4b9aaacb9f2549d6abb481b888328 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace MaximusParserX.Dump.SQL
  6. {
  7. public static class GameObjectSpawnHandler
  8. {
  9. public static IDictionary<string, Custom.gameobject_spawn> GameObjectSpawnList = new Dictionary<string, Custom.gameobject_spawn>();
  10. public static void AddGameObjectSpawn(WoW.GameObject gameobject)
  11. {
  12. var gameobjectspawn = new Custom.gameobject_spawn()
  13. {
  14. guid = gameobject.Guid.Full,
  15. map = (ushort?)gameobject.MapID,
  16. clientbuild = gameobject.Core.ClientBuildAmount,
  17. phasemask = (ushort?)gameobject.PhaseMask,
  18. position_x = gameobject.MovementInfo.PositionInfo_0x100.X,
  19. position_y = gameobject.MovementInfo.PositionInfo_0x100.Y,
  20. position_z = gameobject.MovementInfo.PositionInfo_0x100.Z,
  21. orientation = gameobject.MovementInfo.PositionInfo_0x100_2.O,
  22. rotation0 = gameobject.MovementInfo.GameObjectRotation.X,
  23. rotation1 = gameobject.MovementInfo.GameObjectRotation.Y,
  24. rotation2 = gameobject.MovementInfo.GameObjectRotation.Z,
  25. rotation3 = gameobject.MovementInfo.GameObjectRotation.W,
  26. state = 1,
  27. };
  28. if (gameobject.MovementInfo.UpdateFlags.HasFlag(MaximusParserX.OBJECT_UPDATE_FLAGS.UPDATEFLAG_TRANSPORT))
  29. {
  30. gameobjectspawn.position_x = gameobject.MovementInfo.PositionInfo_0x40.X;
  31. gameobjectspawn.position_y = gameobject.MovementInfo.PositionInfo_0x40.Y;
  32. gameobjectspawn.position_z = gameobject.MovementInfo.PositionInfo_0x40.Z;
  33. gameobjectspawn.orientation = gameobject.MovementInfo.PositionInfo_0x40.O;
  34. }
  35. var key = string.Format("{0}_{1}_{2}_{3}_{4}_{5}_{6}", gameobject.Core.ClientBuildAmount, gameobject.Guid.Full, gameobjectspawn.position_x, gameobjectspawn.position_y, gameobjectspawn.position_z, gameobjectspawn.orientation, gameobjectspawn.phasemask);
  36. if (gameobjectspawn.position_x == 0 && gameobjectspawn.position_y == 0 && gameobjectspawn.position_z == 0)
  37. {
  38. }
  39. else
  40. {
  41. if (!GameObjectSpawnList.ContainsKey(key))
  42. {
  43. var shouldcommit = true;
  44. foreach (var updatefield in gameobject.UpdateFields)
  45. {
  46. var updatefieldname = MaximusParserX.Parsing.ParsingHandler.GetGameObjectUpdateFieldName(updatefield.Key, (ClientBuild)gameobject.Core.ClientBuildAmount);
  47. switch (updatefieldname)
  48. {
  49. case "OBJECT_FIELD_CREATED_BY":
  50. {
  51. shouldcommit = false;
  52. break;
  53. }
  54. case "OBJECT_FIELD_ENTRY":
  55. {
  56. gameobjectspawn.entry = (uint?)updatefield.Value.Int32Value;
  57. break;
  58. }
  59. case "GAMEOBJECT_ANIMPROGRESS":
  60. {
  61. gameobjectspawn.animprogress = (byte?)updatefield.Value.Int32Value;
  62. break;
  63. }
  64. case "GAMEOBJECT_STATE":
  65. {
  66. gameobjectspawn.state = (byte?)updatefield.Value.Int32Value;
  67. break;
  68. }
  69. case "GAMEOBJECT_ROTATION":
  70. {
  71. if (gameobject.Core.ClientBuildAmount >= 9183 && gameobject.Core.ClientBuildAmount <= 9551)
  72. {
  73. var low = (uint)gameobject.UpdateFields[updatefield.Key].Int32Value;
  74. var high = (uint)0;
  75. if (gameobject.UpdateFields.ContainsKey(updatefield.Key + 1)) high = (uint)gameobject.UpdateFields[updatefield.Key + 1].Int32Value;
  76. long packed = (long)((ulong)high << 32 | low);
  77. var x = (packed >> 42) * (1.0f / 2097152.0f);
  78. var y = (((packed << 22) >> 32) >> 11) * (1.0f / 1048576.0f);
  79. var z = (packed << 43 >> 43) * (1.0f / 1048576.0f);
  80. var w = x * x + y * y + z * z;
  81. if (Math.Abs(w - 1.0f) >= (1 / 1048576.0f))
  82. w = (float)Math.Sqrt(1.0f - w);
  83. else
  84. w = 0.0f;
  85. var t = new Quaternion(x, y, z, w);
  86. gameobjectspawn.rotation0 = x;
  87. gameobjectspawn.rotation1 = y;
  88. gameobjectspawn.rotation2 = z;
  89. gameobjectspawn.rotation3 = w;
  90. }
  91. else if (gameobject.Core.ClientBuildAmount <= 8125)
  92. {
  93. gameobjectspawn.rotation0 = updatefield.Value.FloatValue;
  94. }
  95. break;
  96. }
  97. case "GAMEOBJECT_ROTATION_1":
  98. {
  99. gameobjectspawn.rotation1 = updatefield.Value.FloatValue;
  100. break;
  101. }
  102. case "GAMEOBJECT_ROTATION_2":
  103. {
  104. gameobjectspawn.rotation2 = updatefield.Value.FloatValue;
  105. break;
  106. }
  107. case "GAMEOBJECT_ROTATION_3":
  108. {
  109. gameobjectspawn.rotation3 = updatefield.Value.FloatValue;
  110. break;
  111. }
  112. case "GAMEOBJECT_PARENTROTATION":
  113. {
  114. gameobjectspawn.parentrotation0 = updatefield.Value.FloatValue;
  115. break;
  116. }
  117. case "GAMEOBJECT_PARENTROTATION_1":
  118. {
  119. gameobjectspawn.parentrotation1 = updatefield.Value.FloatValue;
  120. break;
  121. }
  122. case "GAMEOBJECT_PARENTROTATION_2":
  123. {
  124. gameobjectspawn.parentrotation2 = updatefield.Value.FloatValue;
  125. break;
  126. }
  127. case "GAMEOBJECT_PARENTROTATION_3":
  128. {
  129. gameobjectspawn.parentrotation3 = updatefield.Value.FloatValue;
  130. break;
  131. }
  132. }
  133. if (gameobjectspawn.animprogress == 100)
  134. {
  135. gameobjectspawn.parentrotation0 = null;
  136. gameobjectspawn.parentrotation1 = null;
  137. gameobjectspawn.parentrotation2 = null;
  138. gameobjectspawn.parentrotation3 = null;
  139. }
  140. if (!shouldcommit) break;
  141. }
  142. if (shouldcommit)
  143. GameObjectSpawnList.Add(key, gameobjectspawn);
  144. }
  145. }
  146. }
  147. public static string DumpToSQLFile()
  148. {
  149. var file = "GameObjectSpawnLog_" + DateTime.Now.ToString("MM-dd-yyyy-hh-mm-ss") + ".sql";
  150. var items = MaximusParserX.Dump.SQL.GameObjectSpawnHandler.GameObjectSpawnList.OrderByDescending(t => t.Key);
  151. using (var sw = new System.IO.StreamWriter(file))
  152. {
  153. uint id = 0;
  154. foreach (var item in items)
  155. {
  156. id++;
  157. item.Value.id = id;
  158. sw.WriteLine(item.Value.GetInsertCommand());
  159. }
  160. }
  161. GameObjectSpawnList.Clear();
  162. return file;
  163. }
  164. }
  165. }