Updated to 8.2.0.31429 (scripts disabled atm, they still need updated)

Code Port from TrinityCore https://github.com/TrinityCore/TrinityCore
Casc from WoW-Tools https://github.com/WoW-Tools/CASCExplorer
This commit is contained in:
hondacrx
2019-08-14 11:20:42 -04:00
parent e4d500f4b5
commit 125e3b3ac7
232 changed files with 12268 additions and 14670 deletions
@@ -56,13 +56,13 @@ namespace Game.Entities
if (buffer.WriteBit(!outOfRangeGUIDs.Empty()))
{
buffer.WriteUInt16(0); // object limit to instantly destroy - objects before this index on m_outOfRangeGUIDs list get "smoothly phased out"
buffer.WriteUInt32(outOfRangeGUIDs.Count);
buffer.WriteInt32(outOfRangeGUIDs.Count);
foreach (var guid in outOfRangeGUIDs)
buffer.WritePackedGuid(guid);
}
var bytes = data.GetData();
buffer.WriteUInt32(bytes.Length);
buffer.WriteInt32(bytes.Length);
buffer.WriteBytes(bytes);
packet.Data = buffer.GetData();
@@ -0,0 +1,453 @@
/*
* Copyright (C) 2012-2019 CypherCore <http://github.com/CypherCore>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Framework.Constants;
using Game.Network;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
namespace Game.Entities
{
public class UpdateFieldHolder
{
public UpdateFieldHolder(WorldObject owner) { _owner = owner; }
public BaseUpdateData<T> ModifyValue<T>(BaseUpdateData<T> updateData)
{
_changesMask.Set(updateData.Bit);
return updateData;
}
public void ClearChangesMask<T>(BaseUpdateData<T> updateData)
{
_changesMask.Reset(updateData.Bit);
}
public void ClearChangesMask<T, U>(BaseUpdateData<T> updateData, ref UpdateField<U> updateField) where T : new() where U : new()
{
_changesMask.Reset(updateData.Bit);
IHasChangesMask hasChangesMask = (IHasChangesMask)updateField._value;
if (hasChangesMask != null)
hasChangesMask.ClearChangesMask();
}
public uint GetChangedObjectTypeMask()
{
return _changesMask.GetBlock(0);
}
public bool HasChanged(TypeId index)
{
return _changesMask[(int)index];
}
UpdateMask _changesMask = new UpdateMask((int)TypeId.Max);
WorldObject _owner;
}
public interface IUpdateField<T>
{
void SetValue(T value);
T GetValue();
}
public class UpdateField<T> : IUpdateField<T> where T : new()
{
public T _value;
public int BlockBit;
public int Bit;
public UpdateField(int blockBit, int bit)
{
BlockBit = blockBit;
Bit = bit;
_value = new T();
}
public static implicit operator T(UpdateField<T> updateField)
{
return updateField._value;
}
public void SetValue(T value) { _value = value; }
public T GetValue() { return _value; }
}
public class UpdateFieldArray<T> where T : new()
{
public T[] _values;
public int FirstElementBit;
public int Bit;
public UpdateFieldArray(uint size, int bit, int firstElementBit)
{
_values = new T[size];
for (var i = 0; i < size; ++i)
_values[i] = new T();
Bit = bit;
FirstElementBit = firstElementBit;
}
public T this[int index]
{
get
{
return _values[index];
}
set
{
_values[index] = value;
}
}
public int GetSize() { return _values.Length; }
public IEnumerator<T> GetEnumerator()
{
foreach (var obj in _values)
yield return obj;
}
}
public class DynamicUpdateField<T> where T : new()
{
public List<T> _values;
public List<uint> _updateMask;
public int BlockBit;
public int Bit;
public DynamicUpdateField()
{
_values = new List<T>();
_updateMask = new List<uint>();
BlockBit = -1;
Bit = -1;
}
public DynamicUpdateField(int blockBit, int bit)
{
_values = new List<T>();
_updateMask = new List<uint>();
BlockBit = blockBit;
Bit = bit;
}
public int FindIndex(T value)
{
return _values.IndexOf(value);
}
public bool HasChanged(int index)
{
return (_updateMask[index / 32] & (1 << (index % 32))) != 0;
}
public void WriteUpdateMask(WorldPacket data)
{
data.WriteBits(_values.Count, 32);
if (_values.Count > 32)
{
if (data.HasUnfinishedBitPack())
for (int block = 0; block < _values.Count / 32; ++block)
data.WriteBits(_updateMask[block], 32);
else
for (int block = 0; block < _values.Count / 32; ++block)
data.WriteUInt32(_updateMask[block]);
}
if ((_values.Count % 32) != 0)
data.WriteBits(_updateMask.Last(), _values.Count % 32);
}
public void ClearChangesMask()
{
for (var i = 0; i < _updateMask.Count; ++i)
_updateMask[i] = 0;
}
public void AddValue(T value)
{
MarkChanged(_values.Count);
if (value is IHasChangesMask)
{
IHasChangesMask hasChanges = (IHasChangesMask)value;
if (hasChanges != null)
hasChanges.GetUpdateMask().SetAll();
}
_values.Add(value);
}
public void InsertValue(int index, T value)
{
_values.Insert(index, value);
for (int i = index; i < _values.Count; ++i)
{
MarkChanged(i);
// also mark all fields of value as changed
IHasChangesMask hasChangesMask = (IHasChangesMask)_values[i];
if (hasChangesMask != null)
hasChangesMask.GetUpdateMask().SetAll();
}
}
public void RemoveValue(int index)
{
// remove by shifting entire container - client might rely on values being sorted for certain fields
_values.RemoveAt(index);
for (int i = index; i < _values.Count; ++i)
{
MarkChanged(i);
// also mark all fields of value as changed
IHasChangesMask hasChanges = (IHasChangesMask)_values[i];
if (hasChanges != null)
hasChanges.GetUpdateMask().SetAll();
}
if ((_values.Count % 32) != 0)
_updateMask[UpdateMask.GetBlockIndex(_values.Count)] &= (uint)~UpdateMask.GetBlockFlag(_values.Count);
else
_updateMask.RemoveAt(_updateMask.Count - 1);
}
public void Clear()
{
_values.Clear();
_updateMask.Clear();
}
public void MarkChanged(int index)
{
int block = UpdateMask.GetBlockIndex(index);
if (block >= _updateMask.Count)
_updateMask.Add(0);
_updateMask[block] |= (uint)UpdateMask.GetBlockFlag(index);
}
public void ClearChanged(int index)
{
int block = UpdateMask.GetBlockIndex(index);
if (block >= _updateMask.Count)
_updateMask.Add(0);
_updateMask[block] &= ~(uint)UpdateMask.GetBlockFlag(index);
}
public int Size()
{
return _values.Count;
}
public T this[int index]
{
get
{
if (_values.Count <= index)
_values.Add(new T());
return _values[index];
}
set
{
_values[index] = value;
}
}
public static implicit operator List<T>(DynamicUpdateField<T> updateField)
{
return updateField._values;
}
public IEnumerator<T> GetEnumerator()
{
foreach (var obj in _values)
yield return obj;
}
}
public interface IHasChangesMask
{
void ClearChangesMask();
UpdateMask GetUpdateMask();
}
public abstract class BaseUpdateData<T> : IHasChangesMask
{
public UpdateMask _changesMask;
public int _blockBit;
public int Bit;
public BaseUpdateData(int blockBit, TypeId bit, int changeMask)
{
_blockBit = blockBit;
Bit = (int)bit;
_changesMask = new UpdateMask(changeMask);
}
public BaseUpdateData(int changeMask)
{
_changesMask = new UpdateMask(changeMask);
}
public abstract void WriteCreate(WorldPacket data, UpdateFieldFlag fieldVisibilityFlags, T owner, Player receiver);
public abstract void WriteUpdate(WorldPacket data, UpdateFieldFlag fieldVisibilityFlags, T owner, Player receiver);
public abstract void ClearChangesMask();
public UpdateMask GetUpdateMask()
{
return _changesMask;
}
public void ClearChanged<U>(UpdateField<U> updateField) where U : new()
{
_changesMask.Reset(updateField.Bit);
}
public void ClearChanged<U>(UpdateFieldArray<U> updateField, int index) where U : new()
{
_changesMask.Reset(updateField.Bit);
_changesMask.Reset(updateField.FirstElementBit + index);
}
public void ClearChanged<U>(DynamicUpdateField<U> updateField, int index) where U : new()
{
_changesMask.Reset(Bit);
updateField.ClearChanged(index);
}
public void ClearChangesMask<U>(UpdateField<U> updateField) where U : new()
{
if (typeof(U).BaseType == typeof(IHasChangesMask))
((IHasChangesMask)updateField._value).ClearChangesMask();
}
public void ClearChangesMask<U>(UpdateFieldArray<U> updateField) where U : new()
{
if (typeof(U).BaseType == typeof(IHasChangesMask))
{
for (int i = 0; i < updateField.GetSize(); ++i)
((IHasChangesMask)updateField[i]).ClearChangesMask();
}
}
public void ClearChangesMask<U>(DynamicUpdateField<U> updateField) where U : new()
{
if (typeof(U).BaseType == typeof(IHasChangesMask))
{
for (int i = 0; i < updateField.Size(); ++i)
((IHasChangesMask)updateField[i]).ClearChangesMask();
updateField.ClearChangesMask();
}
}
public UpdateField<UU> ModifyValue<U, UU>(Expression<Func<U, UpdateField<UU>>> expression) where UU : new()
{
var fieldInfo = ((MemberExpression)expression.Body).Member as FieldInfo;
if (fieldInfo == null)
throw new ArgumentException("The lambda expression 'property' should point to a valid Property");
var updateField = (UpdateField<UU>)fieldInfo.GetValue(this);
_changesMask.Set(updateField.BlockBit);
_changesMask.Set(updateField.Bit);
return updateField;
}
public ref UU ModifyValue<U, UU>(Expression<Func<U, UpdateFieldArray<UU>>> expression, int index) where UU : new()
{
var fieldInfo = ((MemberExpression)expression.Body).Member as FieldInfo;
if (fieldInfo == null)
throw new ArgumentException("The lambda expression 'property' should point to a valid Property");
var updateFieldArray = (UpdateFieldArray<UU>)fieldInfo.GetValue(this);
_changesMask.Set(updateFieldArray.Bit);
_changesMask.Set(updateFieldArray.FirstElementBit + index);
return ref updateFieldArray._values[index];
}
public UpdateField<U> ModifyValue<U>(UpdateField<U> updateField) where U : new()
{
_changesMask.Set(updateField.BlockBit);
_changesMask.Set(updateField.Bit);
return updateField;
}
public ref U ModifyValue<U>(UpdateFieldArray<U> updateField, int index) where U : new()
{
_changesMask.Set(updateField.Bit);
_changesMask.Set(updateField.FirstElementBit + index);
return ref updateField._values[index];
}
public DynamicUpdateField<U> ModifyValue<U>(DynamicUpdateField<U> updateField) where U : new()
{
_changesMask.Set(updateField.BlockBit);
_changesMask.Set(updateField.Bit);
return updateField;
}
public DynamicUpdateFieldSetter<U> ModifyValue<U>(DynamicUpdateField<U> updateField, int index) where U : new()
{
if (index >= updateField._values.Count)
{
// fill with zeros until reaching desired slot
updateField._values.Resize((uint)index + 1);
updateField._updateMask.Resize((uint)(updateField._values.Count + 31) / 32);
}
_changesMask.Set(updateField.BlockBit);
_changesMask.Set(updateField.Bit);
updateField.MarkChanged(index);
return new DynamicUpdateFieldSetter<U>(updateField, index);
}
}
public class DynamicUpdateFieldSetter<T> : IUpdateField<T> where T : new()
{
public DynamicUpdateFieldSetter(DynamicUpdateField<T> dynamicUpdateField, int index)
{
_dynamicUpdateField = dynamicUpdateField;
_index = index;
}
public void SetValue(T value)
{
_dynamicUpdateField[_index] = value;
}
public T GetValue() { return _dynamicUpdateField[_index]; }
public static implicit operator T(DynamicUpdateFieldSetter<T> dynamicUpdateFieldSetter)
{
return dynamicUpdateFieldSetter.GetValue();
}
DynamicUpdateField<T> _dynamicUpdateField;
int _index;
}
}
File diff suppressed because it is too large Load Diff
@@ -24,88 +24,127 @@ namespace Game.Entities
{
public class UpdateMask
{
public UpdateMask(uint valuesCount = 0)
{
_fieldCount = valuesCount;
_blockCount = (valuesCount + 32 - 1) / 32;
int _blockCount;
int _blocksMaskCount;
uint[] _blocks;
uint[] _blocksMask;
_mask = new BitArray((int)valuesCount, false);
public UpdateMask(int bits, uint[] input = null)
{
_blockCount = (bits + 31) / 32;
_blocksMaskCount = (_blockCount + 31) / 32;
_blocks = new uint[_blockCount];
_blocksMask = new uint[_blocksMaskCount];
if (input != null)
{
int block = 0;
for (; block < input.Length; ++block)
if ((_blocks[block] = input[block]) != 0)
_blocksMask[GetBlockIndex(block)] |= (uint)GetBlockFlag(block);
for (; block < _blockCount; ++block)
_blocks[block] = 0;
}
}
public void SetCount(int valuesCount)
public uint GetBlocksMask(uint index)
{
_fieldCount = (uint)valuesCount;
_blockCount = (uint)(valuesCount + 32 - 1) / 32;
_mask = new BitArray((int)valuesCount, false);
return _blocksMask[index];
}
public uint GetCount() { return _fieldCount; }
public virtual void AppendToPacket(ByteBuffer data)
public uint GetBlock(uint index)
{
data.WriteUInt8(_blockCount);
var maskArray = new byte[_blockCount << 2];
_mask.CopyTo(maskArray, 0);
data.WriteBytes(maskArray);
return _blocks[index];
}
public bool GetBit(int index)
public bool this[int index]
{
return _mask.Get(index);
get
{
return (_blocks[index / 32] & (1 << (index % 32))) != 0;
}
}
public void SetBit(int index)
public void Reset(int index)
{
_mask.Set(index, true);
int blockIndex = GetBlockIndex(index);
if ((_blocks[blockIndex] &= ~(uint)GetBlockFlag(index)) == 0)
_blocksMask[GetBlockIndex(blockIndex)] &= ~(uint)GetBlockFlag(blockIndex);
}
void UnsetBit(int index)
public void ResetAll()
{
_mask.Set(index, false);
Array.Clear(_blocks, 0, _blocks.Length);
Array.Clear(_blocksMask, 0, _blocksMask.Length);
}
public void Clear()
public void Set(int index)
{
_mask.SetAll(false);
int blockIndex = GetBlockIndex(index);
_blocks[blockIndex] |= (uint)GetBlockFlag(index);
_blocksMask[GetBlockIndex(blockIndex)] |= (uint)GetBlockFlag(blockIndex);
}
protected uint _fieldCount;
protected uint _blockCount;
protected BitArray _mask;
}
public class DynamicUpdateMask : UpdateMask
{
public DynamicUpdateMask(uint valuesCount) : base(valuesCount) { }
public void EncodeDynamicFieldChangeType(DynamicFieldChangeType changeType, UpdateType updateType)
public void SetAll()
{
_updateType = updateType;
DynamicFieldChangeType = (uint)(_blockCount | ((uint)(changeType & Entities.DynamicFieldChangeType.ValueAndSizeChanged) * ((3 - (int)updateType /*this part evaluates to 0 if update type is not VALUES*/) / 3)));
for (int i = 0; i < _blocksMaskCount; ++i)
_blocksMask[i] = 0xFFFFFFFF;
for (int i = 0; i < _blockCount; ++i)
_blocks[i] = 0xFFFFFFFF;
if ((_blocksMaskCount % 32) != 0)
{
int unused = 32 - (_blocksMaskCount % 32);
_blocksMask[_blocksMaskCount - 1] &= (0xFFFFFFFF >> unused);
}
if ((_blockCount % 32) != 0)
{
int unused = 32 - (_blockCount % 32);
_blocks[_blockCount - 1] &= (0xFFFFFFFF >> unused);
}
}
public override void AppendToPacket(ByteBuffer data)
public void AND(UpdateMask right)
{
data.WriteUInt16(DynamicFieldChangeType);
if (DynamicFieldChangeType.HasAnyFlag((uint)Entities.DynamicFieldChangeType.ValueAndSizeChanged) && _updateType == UpdateType.Values)
data.WriteUInt32(_fieldCount);
for (int i = 0; i < _blocksMaskCount; ++i)
_blocksMask[i] &= right._blocksMask[i];
var maskArray = new byte[_blockCount << 2];
_mask.CopyTo(maskArray, 0);
data.WriteBytes(maskArray);
for (int i = 0; i < _blockCount; ++i)
{
if (!Convert.ToBoolean(_blocks[i] &= right._blocks[i]))
_blocksMask[GetBlockIndex(i)] &= ~(uint)GetBlockFlag(i);
}
}
public uint DynamicFieldChangeType;
public UpdateType _updateType;
}
public void OR(UpdateMask right)
{
for (int i = 0; i < _blocksMaskCount; ++i)
_blocksMask[i] |= right._blocksMask[i];
public enum DynamicFieldChangeType
{
Unchanged = 0,
ValueChanged = 0x7FFF,
ValueAndSizeChanged = 0x8000
for (int i = 0; i < _blockCount; ++i)
_blocks[i] |= right._blocks[i];
}
public static UpdateMask operator &(UpdateMask left, UpdateMask right)
{
UpdateMask result = left;
result.AND(right);
return result;
}
public static UpdateMask operator |(UpdateMask left, UpdateMask right)
{
UpdateMask result = left;
result.OR(right);
return result;
}
//helpers
public static int GetBlockIndex(int bit) { return bit / 32; }
public static int GetBlockFlag(int bit) { return 1 << (bit % 32); }
}
}