Little cleanup

This commit is contained in:
hondacrx
2019-11-07 14:32:35 -05:00
parent 191e2c7a67
commit c35c32270b
2 changed files with 19 additions and 23 deletions
@@ -22,36 +22,32 @@ namespace Game.DataStorage
{ {
public class BitReader public class BitReader
{ {
private byte[] m_data; public int Position { get; set; }
private int m_bitPosition; public int Offset { get; set; }
private int m_offset; public byte[] Data { get; set; }
public int Position { get => m_bitPosition; set => m_bitPosition = value; }
public int Offset { get => m_offset; set => m_offset = value; }
public byte[] Data { get => m_data; set => m_data = value; }
public BitReader(byte[] data) public BitReader(byte[] data)
{ {
m_data = data; Data = data;
} }
public BitReader(byte[] data, int offset) public BitReader(byte[] data, int offset)
{ {
m_data = data; Data = data;
m_offset = offset; Offset = offset;
} }
public T Read<T>(int numBits) where T : unmanaged public T Read<T>(int numBits) where T : unmanaged
{ {
ulong result = Unsafe.As<byte, ulong>(ref m_data[m_offset + (m_bitPosition >> 3)]) << (64 - numBits - (m_bitPosition & 7)) >> (64 - numBits); ulong result = Unsafe.As<byte, ulong>(ref Data[Offset + (Position >> 3)]) << (64 - numBits - (Position & 7)) >> (64 - numBits);
m_bitPosition += numBits; Position += numBits;
return Unsafe.As<ulong, T>(ref result); return Unsafe.As<ulong, T>(ref result);
} }
public T ReadSigned<T>(int numBits) where T : unmanaged public T ReadSigned<T>(int numBits) where T : unmanaged
{ {
ulong result = Unsafe.As<byte, ulong>(ref m_data[m_offset + (m_bitPosition >> 3)]) << (64 - numBits - (m_bitPosition & 7)) >> (64 - numBits); ulong result = Unsafe.As<byte, ulong>(ref Data[Offset + (Position >> 3)]) << (64 - numBits - (Position & 7)) >> (64 - numBits);
m_bitPosition += numBits; Position += numBits;
ulong signedShift = (1UL << (numBits - 1)); ulong signedShift = (1UL << (numBits - 1));
result = (signedShift ^ result) - signedShift; result = (signedShift ^ result) - signedShift;
return Unsafe.As<ulong, T>(ref result); return Unsafe.As<ulong, T>(ref result);
@@ -59,13 +55,13 @@ namespace Game.DataStorage
public string ReadCString() public string ReadCString()
{ {
int start = m_bitPosition; int start = Position;
while (m_data[m_offset + (m_bitPosition >> 3)] != 0) while (Data[Offset + (Position >> 3)] != 0)
m_bitPosition += 8; Position += 8;
string result = Encoding.UTF8.GetString(m_data, m_offset + (start >> 3), (m_bitPosition - start) >> 3); string result = Encoding.UTF8.GetString(Data, Offset + (start >> 3), (Position - start) >> 3);
m_bitPosition += 8; Position += 8;
return result; return result;
} }
} }
@@ -639,8 +639,8 @@ namespace Game.Entities
public class UnlockedAzeriteEssence public class UnlockedAzeriteEssence
{ {
uint AzeriteEssenceID; public uint AzeriteEssenceID;
uint Rank; public uint Rank;
public void WriteCreate(WorldPacket data, Item owner, Player receiver) public void WriteCreate(WorldPacket data, Item owner, Player receiver)
{ {
@@ -916,8 +916,8 @@ namespace Game.Entities
public class PassiveSpellHistory public class PassiveSpellHistory
{ {
int SpellID; public int SpellID;
int AuraSpellID; public int AuraSpellID;
public void WriteCreate(WorldPacket data, Unit owner, Player receiver) public void WriteCreate(WorldPacket data, Unit owner, Player receiver)
{ {