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:
@@ -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); }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user