Core/Misc: Some cleanups

This commit is contained in:
hondacrx
2018-03-05 12:13:45 -05:00
parent 3fc07b8b37
commit 7de76148b6
9 changed files with 58 additions and 122 deletions
+4 -4
View File
@@ -119,7 +119,7 @@ namespace System.Collections.Generic
public List<TValue> LookupByKey(TKey key) public List<TValue> LookupByKey(TKey key)
{ {
if (_interalStorage.ContainsKey(key)) if (_interalStorage.ContainsKey(key))
return _interalStorage[key].ToList(); return _interalStorage[key];
return new List<TValue>(); return new List<TValue>();
} }
@@ -128,7 +128,7 @@ namespace System.Collections.Generic
{ {
TKey newkey = (TKey)Convert.ChangeType(key, typeof(TKey)); TKey newkey = (TKey)Convert.ChangeType(key, typeof(TKey));
if (_interalStorage.ContainsKey(newkey)) if (_interalStorage.ContainsKey(newkey))
return _interalStorage[newkey].ToList(); return _interalStorage[newkey];
return new List<TValue>(); return new List<TValue>();
} }
@@ -363,7 +363,7 @@ namespace System.Collections.Generic
public List<TValue> LookupByKey(TKey key) public List<TValue> LookupByKey(TKey key)
{ {
if (_interalStorage.ContainsKey(key)) if (_interalStorage.ContainsKey(key))
return _interalStorage[key].ToList(); return _interalStorage[key];
return new List<TValue>(); return new List<TValue>();
} }
@@ -372,7 +372,7 @@ namespace System.Collections.Generic
{ {
TKey newkey = (TKey)Convert.ChangeType(key, typeof(TKey)); TKey newkey = (TKey)Convert.ChangeType(key, typeof(TKey));
if (_interalStorage.ContainsKey(newkey)) if (_interalStorage.ContainsKey(newkey))
return _interalStorage[newkey].ToList(); return _interalStorage[newkey];
return new List<TValue>(); return new List<TValue>();
} }
+2 -2
View File
@@ -61,7 +61,7 @@ public class RealmManager : Singleton<RealmManager>
SQLResult result = DB.Login.Query(stmt); SQLResult result = DB.Login.Query(stmt);
Dictionary<RealmHandle, string> existingRealms = new Dictionary<RealmHandle, string>(); Dictionary<RealmHandle, string> existingRealms = new Dictionary<RealmHandle, string>();
foreach (var p in _realms.ToList()) foreach (var p in _realms)
existingRealms[p.Key] = p.Value.Name; existingRealms[p.Key] = p.Value.Name;
_realms.Clear(); _realms.Clear();
@@ -211,7 +211,7 @@ public class RealmManager : Singleton<RealmManager>
public byte[] GetRealmList(uint build, string subRegion) public byte[] GetRealmList(uint build, string subRegion)
{ {
var realmList = new RealmListUpdates(); var realmList = new RealmListUpdates();
foreach (var realm in _realms.ToList()) foreach (var realm in _realms)
{ {
if (realm.Value.Id.GetSubRegionAddress() != subRegion) if (realm.Value.Id.GetSubRegionAddress() != subRegion)
continue; continue;
+1 -84
View File
@@ -15,17 +15,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
using Framework.IO;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Framework.IO;
namespace System namespace System
{ {
@@ -338,20 +337,6 @@ namespace System
return new string(reader.ReadChars(count)); return new string(reader.ReadChars(count));
} }
public static byte[] ToByteArray(this BinaryReader reader)
{
var data = new byte[reader.BaseStream.Length];
long pos = reader.BaseStream.Position;
reader.BaseStream.Seek(0, SeekOrigin.Begin);
for (int i = 0; i < data.Length; i++)
data[i] = (byte)reader.BaseStream.ReadByte();
reader.BaseStream.Seek(pos, SeekOrigin.Begin);
return data;
}
public static T[] ReadArray<T>(this BinaryReader reader, int size) where T : struct public static T[] ReadArray<T>(this BinaryReader reader, int size) where T : struct
{ {
int numBytes = FastStruct<T>.Size * size; int numBytes = FastStruct<T>.Size * size;
@@ -374,74 +359,6 @@ namespace System
return FastStruct<T>.ArrayToStructure(result); return FastStruct<T>.ArrayToStructure(result);
} }
public static int ReadInt32(this BinaryReader br, int byteCount = 0)
{
if (byteCount == 0)
return br.ReadInt32();
if (byteCount != 4)
{
}
byte[] b = new byte[sizeof(int)];
for (int i = 0; i < byteCount; i++)
b[i] = br.ReadByte();
return BitConverter.ToInt32(b, 0);
}
public static uint ReadUInt32(this BinaryReader br, int byteCount = 0)
{
if (byteCount == 0)
return br.ReadUInt32();
if (byteCount != 4)
{
}
byte[] b = new byte[sizeof(uint)];
for (int i = 0; i < byteCount; i++)
b[i] = br.ReadByte();
return BitConverter.ToUInt32(b, 0);
}
public static long ReadInt64(this BinaryReader br, int byteCount = 0)
{
if (byteCount == 0)
return br.ReadInt64();
if (byteCount != 8)
{
}
byte[] b = new byte[sizeof(long)];
for (int i = 0; i < byteCount; i++)
b[i] = br.ReadByte();
return BitConverter.ToInt64(b, 0);
}
public static ulong ReadUInt64(this BinaryReader br, int byteCount = 0)
{
if (byteCount == 0)
return br.ReadUInt64();
if (byteCount != 8)
{
}
byte[] b = new byte[sizeof(ulong)];
for (int i = 0; i < byteCount; i++)
b[i] = br.ReadByte();
return BitConverter.ToUInt64(b, 0);
}
#endregion #endregion
} }
} }
+2 -2
View File
@@ -191,12 +191,12 @@ namespace Game.DataStorage
// Read header // Read header
M2Header header = m2file.ReadStruct<M2Header>(); M2Header header = m2file.ReadStruct<M2Header>();
var buffer = new BinaryReader(new MemoryStream(m2file.ToByteArray(), 8, (int)(m2file.BaseStream.Length - 8)));
// Get camera(s) - Main header, then dump them. // Get camera(s) - Main header, then dump them.
M2Camera cam = m2file.ReadStruct<M2Camera>(8 + header.ofsCameras); M2Camera cam = m2file.ReadStruct<M2Camera>(8 + header.ofsCameras);
readCamera(cam, (uint)m2file.BaseStream.Length - 8, buffer, cameraEntry); m2file.BaseStream.Position = 8;
readCamera(cam, (uint)m2file.BaseStream.Length - 8, m2file, cameraEntry);
} }
} }
catch (EndOfStreamException) catch (EndOfStreamException)
+11 -11
View File
@@ -301,20 +301,20 @@ namespace Game.Maps
switch (visitor._mask) switch (visitor._mask)
{ {
case GridMapTypeMask.AllGrid: case GridMapTypeMask.AllGrid:
visitor.Visit(_container.gameObjects.ToList()); visitor.Visit(_container.gameObjects);
visitor.Visit(_container.creatures.ToList()); visitor.Visit(_container.creatures);
visitor.Visit(_container.dynamicObjects.ToList()); visitor.Visit(_container.dynamicObjects);
visitor.Visit(_container.corpses.ToList()); visitor.Visit(_container.corpses);
visitor.Visit(_container.areaTriggers.ToList()); visitor.Visit(_container.areaTriggers);
visitor.Visit(_container.conversations.ToList()); visitor.Visit(_container.conversations);
visitor.Visit(_container.worldObjects.ToList()); visitor.Visit(_container.worldObjects);
break; break;
case GridMapTypeMask.AllWorld: case GridMapTypeMask.AllWorld:
visitor.Visit(_objects.players); visitor.Visit(_objects.players);
visitor.Visit(_objects.creatures.ToList()); visitor.Visit(_objects.creatures);
visitor.Visit(_objects.corpses.ToList()); visitor.Visit(_objects.corpses);
visitor.Visit(_objects.dynamicObjects.ToList()); visitor.Visit(_objects.dynamicObjects);
visitor.Visit(_objects.worldObjects.ToList()); visitor.Visit(_objects.worldObjects);
break; break;
default: default:
Log.outError(LogFilter.Server, "{0} called Visit with Unknown Mask {1}.", visitor.ToString(), visitor._mask); Log.outError(LogFilter.Server, "{0} called Visit with Unknown Mask {1}.", visitor.ToString(), visitor._mask);
+31 -13
View File
@@ -86,9 +86,8 @@ namespace Game.Maps
var header = reader.ReadStruct<mapFileHeader>(); var header = reader.ReadStruct<mapFileHeader>();
if (new string(header.mapMagic) != MapConst.MapMagic || new string(header.versionMagic) != MapConst.MapVersionMagic) if (new string(header.mapMagic) != MapConst.MapMagic || new string(header.versionMagic) != MapConst.MapVersionMagic)
{ {
Log.outError(LogFilter.Maps, Log.outError(LogFilter.Maps, "Map file '{0}' is from an incompatible map version ({1}), {2} is expected. Please recreate using the mapextractor.",
"Map file '{0}' is from an incompatible map version ({1}), {2} is expected. Please recreate using the mapextractor.", fileName, new string(header.versionMagic), MapConst.MapVersionMagic);
fileName, Convert.ToString(header.versionMagic), MapConst.MapVersionMagic);
return false; return false;
} }
return true; return true;
@@ -551,10 +550,11 @@ namespace Game.Maps
public virtual void Update(uint diff) public virtual void Update(uint diff)
{ {
_dynamicTree.update(diff); _dynamicTree.update(diff);
// update worldsessions for existing players // update worldsessions for existing players
foreach (Player player in m_activePlayers.ToList()) for (var i = 0; i < m_activePlayers.Count; ++i)
{ {
Player player = m_activePlayers[i];
if (player.IsInWorld) if (player.IsInWorld)
{ {
WorldSession session = player.GetSession(); WorldSession session = player.GetSession();
@@ -562,6 +562,7 @@ namespace Game.Maps
session.Update(diff, updater); session.Update(diff, updater);
} }
} }
// update active cells around players and active objects // update active cells around players and active objects
resetMarkedCells(); resetMarkedCells();
@@ -570,8 +571,9 @@ namespace Game.Maps
var grid_object_update = new Visitor(update, GridMapTypeMask.AllGrid); var grid_object_update = new Visitor(update, GridMapTypeMask.AllGrid);
var world_object_update = new Visitor(update, GridMapTypeMask.AllWorld); var world_object_update = new Visitor(update, GridMapTypeMask.AllWorld);
foreach (Player player in m_activePlayers.ToList()) for (var i = 0; i < m_activePlayers.Count; ++i)
{ {
Player player = m_activePlayers[i];
if (!player.IsInWorld) if (!player.IsInWorld)
continue; continue;
@@ -612,16 +614,18 @@ namespace Game.Maps
} }
} }
foreach (WorldObject obj in m_activeNonPlayers.ToList()) for (var i = 0; i < m_activeNonPlayers.Count; ++i)
{ {
WorldObject obj = m_activeNonPlayers[i];
if (!obj.IsInWorld) if (!obj.IsInWorld)
continue; continue;
VisitNearbyCellsOf(obj, grid_object_update, world_object_update); VisitNearbyCellsOf(obj, grid_object_update, world_object_update);
} }
foreach (Transport transport in _transports.ToList()) for (var i = 0; i < _transports.Count; ++i)
{ {
Transport transport = _transports[i];
if (!transport || !transport.IsInWorld) if (!transport || !transport.IsInWorld)
continue; continue;
@@ -923,6 +927,7 @@ namespace Game.Maps
Cell old_cell = dynObj.GetCurrentCell(); Cell old_cell = dynObj.GetCurrentCell();
Contract.Assert(integrity_check == old_cell); Contract.Assert(integrity_check == old_cell);
Cell new_cell = new Cell(x, y); Cell new_cell = new Cell(x, y);
if (getGrid(new_cell.GetGridX(), new_cell.GetGridY()) == null) if (getGrid(new_cell.GetGridX(), new_cell.GetGridY()) == null)
@@ -947,6 +952,7 @@ namespace Game.Maps
old_cell = dynObj.GetCurrentCell(); old_cell = dynObj.GetCurrentCell();
integrity_check = new Cell(dynObj.GetPositionX(), dynObj.GetPositionY()); integrity_check = new Cell(dynObj.GetPositionX(), dynObj.GetPositionY());
Contract.Assert(integrity_check == old_cell); Contract.Assert(integrity_check == old_cell);
} }
@@ -989,6 +995,7 @@ namespace Game.Maps
if (c._moveState == ObjectCellMoveState.None) if (c._moveState == ObjectCellMoveState.None)
creaturesToMove.Add(c); creaturesToMove.Add(c);
c.SetNewCellPosition(x, y, z, ang); c.SetNewCellPosition(x, y, z, ang);
} }
@@ -1061,8 +1068,10 @@ namespace Game.Maps
void MoveAllCreaturesInMoveList() void MoveAllCreaturesInMoveList()
{ {
_creatureToMoveLock = true; _creatureToMoveLock = true;
foreach (Creature creature in creaturesToMove.ToList())
for (var i = 0; i< creaturesToMove.Count; ++i)
{ {
Creature creature = creaturesToMove[i];
if (creature.GetMap() != this) //pet is teleported to another map if (creature.GetMap() != this) //pet is teleported to another map
continue; continue;
@@ -1104,6 +1113,7 @@ namespace Game.Maps
} }
} }
} }
creaturesToMove.Clear(); creaturesToMove.Clear();
_creatureToMoveLock = false; _creatureToMoveLock = false;
} }
@@ -1111,8 +1121,10 @@ namespace Game.Maps
void MoveAllGameObjectsInMoveList() void MoveAllGameObjectsInMoveList()
{ {
_gameObjectsToMoveLock = true; _gameObjectsToMoveLock = true;
foreach (GameObject go in _gameObjectsToMove)
for (var i = 0; i < _gameObjectsToMove.Count; ++i)
{ {
GameObject go = _gameObjectsToMove[i];
if (go.GetMap() != this) //transport is teleported to another map if (go.GetMap() != this) //transport is teleported to another map
continue; continue;
@@ -1148,6 +1160,7 @@ namespace Game.Maps
} }
} }
} }
_gameObjectsToMove.Clear(); _gameObjectsToMove.Clear();
_gameObjectsToMoveLock = false; _gameObjectsToMoveLock = false;
} }
@@ -1155,8 +1168,10 @@ namespace Game.Maps
void MoveAllDynamicObjectsInMoveList() void MoveAllDynamicObjectsInMoveList()
{ {
_dynamicObjectsToMoveLock = true; _dynamicObjectsToMoveLock = true;
foreach (var dynObj in _dynamicObjectsToMove)
for (var i = 0; i < _dynamicObjectsToMove.Count; ++i)
{ {
DynamicObject dynObj = _dynamicObjectsToMove[i];
if (dynObj.GetMap() != this) //transport is teleported to another map if (dynObj.GetMap() != this) //transport is teleported to another map
continue; continue;
@@ -1188,8 +1203,10 @@ namespace Game.Maps
void MoveAllAreaTriggersInMoveList() void MoveAllAreaTriggersInMoveList()
{ {
_areaTriggersToMoveLock = true; _areaTriggersToMoveLock = true;
foreach (AreaTrigger at in _areaTriggersToMove)
for (var i = 0; i < _areaTriggersToMove.Count; ++i)
{ {
AreaTrigger at = _areaTriggersToMove[i];
if (at.GetMap() != this) //transport is teleported to another map if (at.GetMap() != this) //transport is teleported to another map
continue; continue;
@@ -2095,8 +2112,9 @@ namespace Game.Maps
public virtual void DelayedUpdate(uint diff) public virtual void DelayedUpdate(uint diff)
{ {
foreach (var transport in _transports.ToList()) for (var i = 0; i < _transports.Count; ++i)
{ {
Transport transport = _transports[i];
if (!transport.IsInWorld) if (!transport.IsInWorld)
continue; continue;
+3 -2
View File
@@ -18,6 +18,7 @@
using Framework.Constants; using Framework.Constants;
using Game.Entities; using Game.Entities;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace Game.Maps namespace Game.Maps
{ {
@@ -181,7 +182,7 @@ namespace Game.Maps
{ {
public override void Visit(ICollection<Creature> objs) public override void Visit(ICollection<Creature> objs)
{ {
foreach (var creature in objs) foreach (var creature in objs.ToList())
{ {
// creature in unloading grid can have respawn point in another grid // creature in unloading grid can have respawn point in another grid
// if it will be unloaded then it will not respawn in original grid until unload/load original grid // if it will be unloaded then it will not respawn in original grid until unload/load original grid
@@ -191,7 +192,7 @@ namespace Game.Maps
} }
public override void Visit(ICollection<GameObject> objs) public override void Visit(ICollection<GameObject> objs)
{ {
foreach (var go in objs) foreach (var go in objs.ToList())
{ {
// gameobject in unloading grid can have respawn point in another grid // gameobject in unloading grid can have respawn point in another grid
// if it will be unloaded then it will not respawn in original grid until unload/load original grid // if it will be unloaded then it will not respawn in original grid until unload/load original grid
@@ -760,14 +760,14 @@ namespace Scripts.Northrend.AzjolNerub.AzjolNerub.KrikthirTheGatewatcher
void HandleTargets(List<WorldObject> targetList) void HandleTargets(List<WorldObject> targetList)
{ {
// Remove any Watchers that are already in combat // Remove any Watchers that are already in combat
foreach (var obj in targetList.ToList()) for (var i = 0; i < targetList.Count; ++i)
{ {
Creature creature = obj.ToCreature(); Creature creature = targetList[i].ToCreature();
if (creature) if (creature)
if (creature.IsAlive() && !creature.IsInCombat()) if (creature.IsAlive() && !creature.IsInCombat())
continue; continue;
targetList.Remove(obj); targetList.RemoveAt(i);
} }
// Default to Krik'thir himself if he isn't engaged // Default to Krik'thir himself if he isn't engaged
@@ -573,7 +573,7 @@ namespace Scripts.Northrend.IcecrownCitadel
return; return;
List<Creature> temp = new List<Creature>(); List<Creature> temp = new List<Creature>();
foreach (var guid in summons.ToList()) foreach (var guid in summons)
{ {
Creature cre = ObjectAccessor.GetCreature(me, guid); Creature cre = ObjectAccessor.GetCreature(me, guid);
if (cre) if (cre)