Fixed DB2 loading and world login!!!!!

This commit is contained in:
hondacrx
2018-12-14 18:43:35 -05:00
parent 8e20114e10
commit f414068883
44 changed files with 779 additions and 852 deletions
+2 -2
View File
@@ -275,6 +275,8 @@ namespace Game.DataStorage
WorldMapOverlayStorage = DBReader.Read<WorldMapOverlayRecord>("WorldMapOverlay.db2", HotfixStatements.SEL_WORLD_MAP_OVERLAY);
WorldSafeLocsStorage = DBReader.Read<WorldSafeLocsRecord>("WorldSafeLocs.db2", HotfixStatements.SEL_WORLD_SAFE_LOCS, HotfixStatements.SEL_WORLD_SAFE_LOCS_LOCALE);
Global.DB2Mgr.LoadStores();
foreach (var entry in TaxiPathStorage.Values)
{
if (!TaxiPathSetBySource.ContainsKey(entry.FromTaxiNode))
@@ -321,8 +323,6 @@ namespace Game.DataStorage
OldContinentsNodesMask[field] |= submask;
}
Global.DB2Mgr.LoadStores();
// Check loaded DB2 files proper version
if (!AreaTableStorage.ContainsKey(10048) || // last area added in 8.0.1 (28153)
!CharTitlesStorage.ContainsKey(633) || // last char title added in 8.0.1 (28153)
@@ -15,72 +15,58 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Framework.IO;
using System;
using System.Runtime.CompilerServices;
using System.Text;
namespace Game.DataStorage
{
public class BitReader
{
private byte[] m_data;
private int m_bitPosition;
private int m_offset;
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)
{
m_array = data;
m_data = data;
}
public BitReader(byte[] data, int offset)
{
m_array = data;
m_readOffset = offset;
m_data = data;
m_offset = offset;
}
public uint ReadUInt32(int numBits)
public T Read<T>(int numBits) where T : unmanaged
{
uint result = BitConverter.ToUInt32(m_array, m_readOffset + (m_readPos >> 3)) << (32 - numBits - (m_readPos & 7)) >> (32 - numBits);
m_readPos += numBits;
ulong result = Unsafe.As<byte, ulong>(ref m_data[m_offset + (m_bitPosition >> 3)]) << (64 - numBits - (m_bitPosition & 7)) >> (64 - numBits);
m_bitPosition += numBits;
return Unsafe.As<ulong, T>(ref result);
}
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);
m_bitPosition += numBits;
ulong signedShift = (1UL << (numBits - 1));
result = (signedShift ^ result) - signedShift;
return Unsafe.As<ulong, T>(ref result);
}
public string ReadCString()
{
int start = m_bitPosition;
while (m_data[m_offset + (m_bitPosition >> 3)] != 0)
m_bitPosition += 8;
string result = Encoding.UTF8.GetString(m_data, m_offset + (start >> 3), (m_bitPosition - start) >> 3);
m_bitPosition += 8;
return result;
}
public ulong ReadUInt64(int bitWidth, int bitOffset)
{
int bitsToRead = bitOffset & 7;
ulong result = BitConverter.ToUInt64(m_array, m_readOffset + (m_readPos >> 3)) << (64 - bitsToRead - bitWidth) >> (64 - bitWidth);
m_readPos += bitWidth;
return result;
}
public byte[] ReadValue(int bitWidth, int bitOffset = 0, bool isSigned = false)
{
ulong result = ReadUInt64(bitWidth, bitOffset);
if (isSigned)
{
ulong mask = 1ul << (bitWidth - 1);
result = (result ^ mask) - mask;
}
var ulongBytes = BitConverter.GetBytes(result);
byte[] data = new byte[NextPow2((bitWidth + 7) / 8)];
Buffer.BlockCopy(ulongBytes, 0, data, 0, data.Length);
return data;
}
private int NextPow2(int v)
{
v--;
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
v |= v >> 16;
v++;
return Math.Max(v, 1);
}
public int Position { get => m_readPos; set => m_readPos = value; }
public int Offset { get => m_readOffset; set => m_readOffset = value; }
private byte[] m_array;
private int m_readPos;
private int m_readOffset;
}
}
@@ -17,6 +17,7 @@
using Framework.Constants;
using Framework.Database;
using Framework.Dynamic;
using Framework.GameMath;
using Framework.IO;
using System;
@@ -37,146 +38,130 @@ namespace Game.DataStorage
[Serializable]
public class DB6Storage<T> : Dictionary<uint, T>, IDB2Storage where T : new()
{
public void LoadData(int indexField, DB6FieldInfo[] helpers, HotfixStatements preparedStatement, HotfixStatements preparedStatementLocale)
public void LoadData(int indexField, HotfixStatements preparedStatement, HotfixStatements preparedStatementLocale)
{
SQLResult result = DB.Hotfix.Query(DB.Hotfix.GetPreparedStatement(preparedStatement));
if (!result.IsEmpty())
{
do
{
var idValue = result.Read<uint>(indexField == -1 ? 0 : indexField);
var id = result.Read<uint>(indexField == -1 ? 0 : indexField);
var obj = new T();
int index = 0;
for (var fieldIndex = 0; fieldIndex < helpers.Length; fieldIndex++)
int dbIndex = 0;
foreach (var f in typeof(T).GetFields())
{
var helper = helpers[fieldIndex];
if (helper.IsArray)
Type type = f.FieldType;
if (type.IsArray)
{
Array array = (Array)helper.Getter(obj);
for (var i = 0; i < array.Length; ++i)
Type arrayElementType = type.GetElementType();
if (arrayElementType.IsEnum)
arrayElementType = arrayElementType.GetEnumUnderlyingType();
Array array = (Array)f.GetValue(obj);
switch (Type.GetTypeCode(arrayElementType))
{
switch (Type.GetTypeCode(helper.FieldType))
{
case TypeCode.SByte:
helper.SetValue(array, result.Read<sbyte>(index++), i);
break;
case TypeCode.Byte:
helper.SetValue(array, result.Read<byte>(index++), i);
break;
case TypeCode.Int16:
helper.SetValue(array, result.Read<short>(index++), i);
break;
case TypeCode.UInt16:
helper.SetValue(array, result.Read<ushort>(index++), i);
break;
case TypeCode.Int32:
helper.SetValue(array, result.Read<int>(index++), i);
break;
case TypeCode.UInt32:
helper.SetValue(array, result.Read<uint>(index++), i);
break;
case TypeCode.Single:
helper.SetValue(array, result.Read<float>(index++), i);
break;
case TypeCode.String:
helper.SetValue(array, result.Read<string>(index++), i);
break;
case TypeCode.Object:
switch (helper.FieldType.Name)
{
case "Vector2":
var vector2 = new Vector2();
vector2.X = result.Read<float>(index++);
vector2.Y = result.Read<float>(index++);
helper.SetValue(array, vector2, i);
break;
case "Vector3":
var vector3 = new Vector3();
vector3.X = result.Read<float>(index++);
vector3.Y = result.Read<float>(index++);
vector3.Z = result.Read<float>(index++);
helper.SetValue(array, vector3, i);
break;
case "LocalizedString":
LocalizedString locString = new LocalizedString();
locString[Global.WorldMgr.GetDefaultDbcLocale()] = result.Read<string>(index++);
helper.SetValue(array, locString, i);
break;
default:
Log.outError(LogFilter.ServerLoading, "Wrong Array Type: {0}", helper.FieldType.Name);
break;
}
break;
default:
Log.outError(LogFilter.ServerLoading, "Wrong Array Type: {0}", helper.FieldType.Name);
break;
}
case TypeCode.SByte:
f.SetValue(obj, ReadArray<sbyte>(result, dbIndex, array.Length));
break;
case TypeCode.Byte:
f.SetValue(obj, ReadArray<byte>(result, dbIndex, array.Length));
break;
case TypeCode.Int16:
f.SetValue(obj, ReadArray<short>(result, dbIndex, array.Length));
break;
case TypeCode.UInt16:
f.SetValue(obj, ReadArray<ushort>(result, dbIndex, array.Length));
break;
case TypeCode.Int32:
f.SetValue(obj, ReadArray<int>(result, dbIndex, array.Length));
break;
case TypeCode.UInt32:
f.SetValue(obj, ReadArray<uint>(result, dbIndex, array.Length));
break;
case TypeCode.Single:
f.SetValue(obj, ReadArray<float>(result, dbIndex, array.Length));
break;
case TypeCode.String:
f.SetValue(obj, ReadArray<string>(result, dbIndex, array.Length));
break;
case TypeCode.Object:
if (arrayElementType == typeof(Vector3))
f.SetValue(obj, new Vector3(ReadArray<float>(result, dbIndex, 3)));
break;
default:
Log.outError(LogFilter.ServerLoading, "Wrong Array Type: {0}", arrayElementType.Name);
break;
}
dbIndex += array.Length;
}
else
{
switch (Type.GetTypeCode(helper.FieldType))
if (type.IsEnum)
type = type.GetEnumUnderlyingType();
switch (Type.GetTypeCode(type))
{
case TypeCode.SByte:
helper.SetValue(obj, result.Read<sbyte>(index++));
f.SetValue(obj, result.Read<sbyte>(dbIndex++));
break;
case TypeCode.Byte:
helper.SetValue(obj, result.Read<byte>(index++));
f.SetValue(obj, result.Read<byte>(dbIndex++));
break;
case TypeCode.Int16:
helper.SetValue(obj, result.Read<short>(index++));
f.SetValue(obj, result.Read<short>(dbIndex++));
break;
case TypeCode.UInt16:
helper.SetValue(obj, result.Read<ushort>(index++));
f.SetValue(obj, result.Read<ushort>(dbIndex++));
break;
case TypeCode.Int32:
helper.SetValue(obj, result.Read<int>(index++));
f.SetValue(obj, result.Read<int>(dbIndex++));
break;
case TypeCode.UInt32:
helper.SetValue(obj, result.Read<uint>(index++));
f.SetValue(obj, result.Read<uint>(dbIndex++));
break;
case TypeCode.Single:
helper.SetValue(obj, result.Read<float>(index++));
f.SetValue(obj, result.Read<float>(dbIndex++));
break;
case TypeCode.String:
string str = result.Read<string>(index++);
helper.SetValue(obj, str);
string str = result.Read<string>(dbIndex++);
f.SetValue(obj, str);
break;
case TypeCode.Object:
switch (helper.FieldType.Name)
if (type == typeof(LocalizedString))
{
case "Vector2":
var vector2 = new Vector2();
vector2.X = result.Read<float>(index++);
vector2.Y = result.Read<float>(index++);
helper.SetValue(obj, vector2);
break;
case "Vector3":
var vector3 = new Vector3();
vector3.X = result.Read<float>(index++);
vector3.Y = result.Read<float>(index++);
vector3.Z = result.Read<float>(index++);
helper.SetValue(obj, vector3);
break;
case "LocalizedString":
LocalizedString locString = new LocalizedString();
locString[Global.WorldMgr.GetDefaultDbcLocale()] = result.Read<string>(index++);
helper.SetValue(obj, locString);
break;
default:
Log.outError(LogFilter.ServerLoading, "Wrong Array Type: {0}", helper.FieldType.Name);
break;
LocalizedString locString = new LocalizedString();
locString[Global.WorldMgr.GetDefaultDbcLocale()] = result.Read<string>(dbIndex++);
f.SetValue(obj, locString);
}
else if (type == typeof(Vector2))
{
f.SetValue(obj, new Vector2(ReadArray<float>(result, dbIndex, 2)));
dbIndex += 2;
}
else if (type == typeof(Vector3))
{
f.SetValue(obj, new Vector3(ReadArray<float>(result, dbIndex, 3)));
dbIndex += 3;
}
else if (type == typeof(FlagArray128))
{
f.SetValue(obj, new FlagArray128(ReadArray<uint>(result, dbIndex, 4)));
dbIndex += 4;
}
break;
default:
Log.outError(LogFilter.ServerLoading, "Wrong Array Type: {0}", helper.FieldType.Name);
Log.outError(LogFilter.ServerLoading, "Wrong Type: {0}", type.Name);
break;
}
}
}
base[idValue] = obj;
base[id] = obj;
}
while (result.NextRow());
}
@@ -202,19 +187,27 @@ namespace Game.DataStorage
if (obj == null)
continue;
for (var i = 0; i < helpers.Length; i++)
foreach (var f in typeof(T).GetFields())
{
var fieldInfo = helpers[i];
if (fieldInfo.FieldType != typeof(LocalizedString))
if (f.FieldType != typeof(LocalizedString))
continue;
LocalizedString locString = (LocalizedString)fieldInfo.Getter(obj);
LocalizedString locString = (LocalizedString)f.GetValue(obj);
locString[locale] = localeResult.Read<string>(index++);
}
} while (localeResult.NextRow());
}
}
TValue[] ReadArray<TValue>(SQLResult result, int dbIndex, int arrayLength)
{
TValue[] values = new TValue[arrayLength];
for (int i = 0; i < arrayLength; ++i)
values[i] = result.Read<TValue>(dbIndex + i);
return values;
}
public bool HasRecord(uint id)
{
return ContainsKey(id);
File diff suppressed because it is too large Load Diff
+4 -4
View File
@@ -164,11 +164,11 @@ namespace Game.DataStorage
foreach (GameObjectDisplayInfoRecord gameObjectDisplayInfo in CliDB.GameObjectDisplayInfoStorage.Values)
{
if (gameObjectDisplayInfo.GeoBoxMax.X < gameObjectDisplayInfo.GeoBoxMin.X)
Extensions.Swap(ref gameObjectDisplayInfo.GeoBoxMax.X, ref gameObjectDisplayInfo.GeoBoxMin.X);
Extensions.Swap(ref gameObjectDisplayInfo.GeoBox[3], ref gameObjectDisplayInfo.GeoBox[0]);
if (gameObjectDisplayInfo.GeoBoxMax.Y < gameObjectDisplayInfo.GeoBoxMin.Y)
Extensions.Swap(ref gameObjectDisplayInfo.GeoBoxMax.Y, ref gameObjectDisplayInfo.GeoBoxMin.Y);
Extensions.Swap(ref gameObjectDisplayInfo.GeoBox[4], ref gameObjectDisplayInfo.GeoBox[1]);
if (gameObjectDisplayInfo.GeoBoxMax.Z < gameObjectDisplayInfo.GeoBoxMin.Z)
Extensions.Swap(ref gameObjectDisplayInfo.GeoBoxMax.Z, ref gameObjectDisplayInfo.GeoBoxMin.Z);
Extensions.Swap(ref gameObjectDisplayInfo.GeoBox[5], ref gameObjectDisplayInfo.GeoBox[2]);
}
foreach (HeirloomRecord heirloom in CliDB.HeirloomStorage.Values)
@@ -1732,7 +1732,7 @@ namespace Game.DataStorage
UiMapAssignmentRecord FindNearestMapAssignment(float x, float y, float z, int mapId, int areaId, int wmoDoodadPlacementId, int wmoGroupId, UiMapSystem system)
{
UiMapAssignmentStatus nearestMapAssignment = null;
UiMapAssignmentStatus nearestMapAssignment = new UiMapAssignmentStatus();
var iterateUiMapAssignments = new Action<MultiMap<int, UiMapAssignmentRecord>, int>((assignments, id) =>
{
foreach (var assignment in assignments.LookupByKey(id))
+3 -3
View File
@@ -173,7 +173,7 @@ namespace Game.DataStorage
public ushort AltHandUICameraID;
public sbyte ForgeAttachmentOverride;
public byte Flags;
public byte ArtifactID;
public uint ArtifactID;
}
public sealed class ArtifactCategoryRecord
@@ -214,7 +214,7 @@ namespace Game.DataStorage
public uint SpellID;
public ushort ItemBonusListID;
public float AuraPointsOverride;
public ushort ArtifactPowerID;
public uint ArtifactPowerID;
}
public sealed class ArtifactQuestXPRecord
@@ -240,7 +240,7 @@ namespace Game.DataStorage
public byte PowerRank;
public ushort ItemBonusListID;
public uint PlayerConditionID;
public byte ArtifactID;
public uint ArtifactID;
}
public sealed class AuctionHouseRecord
+2 -2
View File
@@ -55,7 +55,7 @@ namespace Game.DataStorage
public uint Id;
public byte BattlePetStateID;
public ushort Value;
public byte BattlePetBreedID;
public uint BattlePetBreedID;
}
public sealed class BattlePetSpeciesRecord
@@ -78,7 +78,7 @@ namespace Game.DataStorage
public uint Id;
public byte BattlePetStateID;
public int Value;
public ushort BattlePetSpeciesID;
public uint BattlePetSpeciesID;
}
public sealed class BattlemasterListRecord
+2 -2
View File
@@ -68,7 +68,7 @@ namespace Game.DataStorage
public uint PetDisplayID; // Pet Model ID for starting pet
public byte PetFamilyID; // Pet Family Entry for starting pet
public int[] ItemID = new int[24];
public byte RaceID;
public uint RaceID;
}
public sealed class CharTitlesRecord
@@ -117,7 +117,7 @@ namespace Game.DataStorage
{
public uint Id;
public sbyte PowerType;
public byte ClassID;
public uint ClassID;
}
public sealed class ChrRacesRecord
+1 -1
View File
@@ -45,7 +45,7 @@ namespace Game.DataStorage
public byte ClassId;
public byte SexId;
public uint SoundId;
public ushort EmotesTextId;
public uint EmotesTextId;
}
public sealed class ExpectedStatRecord
+15 -5
View File
@@ -23,12 +23,22 @@ namespace Game.DataStorage
public sealed class GameObjectDisplayInfoRecord
{
public uint Id;
public Vector3 GeoBoxMin;
public Vector3 GeoBoxMax;
public float[] GeoBox = new float[6];
public int FileDataID;
public short ObjectEffectPackageID;
public float OverrideLootEffectScale;
public float OverrideNameScale;
public Vector3 GeoBoxMin
{
get { return new Vector3(GeoBox[0], GeoBox[1], GeoBox[2]); }
set { GeoBox[0] = value.X; GeoBox[1] = value.Y; GeoBox[2] = value.Z; }
}
public Vector3 GeoBoxMax
{
get { return new Vector3(GeoBox[3], GeoBox[4], GeoBox[5]); }
set { GeoBox[3] = value.X; GeoBox[4] = value.Y; GeoBox[5] = value.Z; }
}
}
public sealed class GameObjectsRecord
@@ -151,7 +161,7 @@ namespace Game.DataStorage
public byte OrderIndex;
public byte FactionIndex;
public ushort GarrAbilityID;
public ushort GarrFollowerID;
public uint GarrFollowerID;
}
public sealed class GarrPlotRecord
@@ -215,7 +225,7 @@ namespace Game.DataStorage
{
public uint Id;
public int SpellID;
public short GlyphPropertiesID;
public uint GlyphPropertiesID;
}
public sealed class GlyphPropertiesRecord
@@ -231,7 +241,7 @@ namespace Game.DataStorage
{
public uint Id;
public ushort ChrSpecializationID;
public ushort GlyphPropertiesID;
public uint GlyphPropertiesID;
}
public sealed class GuildColorBackgroundRecord
+5 -5
View File
@@ -119,7 +119,7 @@ namespace Game.DataStorage
public ushort ChildItemBonusTreeID;
public ushort ChildItemBonusListID;
public ushort ChildItemLevelSelectorID;
public ushort ParentItemBonusTreeID;
public uint ParentItemBonusTreeID;
}
public sealed class ItemChildEquipmentRecord
@@ -169,7 +169,7 @@ namespace Game.DataStorage
public ushort MaxLevel;
public ushort SkillRequired;
public sbyte ExpansionID;
public byte Class;
public uint Class;
}
public sealed class ItemEffectRecord
@@ -183,7 +183,7 @@ namespace Game.DataStorage
public ushort SpellCategoryID;
public int SpellID;
public ushort ChrSpecializationID;
public int ParentItemID;
public uint ParentItemID;
}
public sealed class ItemExtendedCostRecord
@@ -213,7 +213,7 @@ namespace Game.DataStorage
public uint Id;
public uint QualityItemBonusListID;
public sbyte Quality;
public short ParentILSQualitySetID;
public uint ParentILSQualitySetID;
}
public sealed class ItemLevelSelectorQualitySetRecord
@@ -306,7 +306,7 @@ namespace Game.DataStorage
public ushort ChrSpecID;
public uint SpellID;
public byte Threshold;
public ushort ItemSetID;
public uint ItemSetID;
}
public sealed class ItemSparseRecord
+1 -1
View File
@@ -103,7 +103,7 @@ namespace Game.DataStorage
public byte MaxPlayers;
public byte ItemContext;
public byte Flags;
public ushort MapID;
public uint MapID;
public uint GetRaidDuration()
{
+2 -2
View File
@@ -30,7 +30,7 @@ namespace Game.DataStorage
{
public uint Id;
public ushort PhaseId;
public ushort PhaseGroupID;
public uint PhaseGroupID;
}
public sealed class PlayerConditionRecord
@@ -163,7 +163,7 @@ namespace Game.DataStorage
public byte RangeIndex;
public byte MinLevel;
public byte MaxLevel;
public ushort MapID;
public uint MapID;
// helpers
public BattlegroundBracketId GetBracketId()
+1 -1
View File
@@ -441,7 +441,7 @@ namespace Game.DataStorage
public SpellProcsPerMinuteModType Type;
public ushort Param;
public float Coeff;
public ushort SpellProcsPerMinuteID;
public uint SpellProcsPerMinuteID;
}
public sealed class SpellRadiusRecord
+1 -1
View File
@@ -65,7 +65,7 @@ namespace Game.DataStorage
public uint Id;
public int PhaseID;
public int UiMapArtID;
public int UiMapID;
public uint UiMapID;
}
public sealed class UnitPowerBarRecord