From 2c9a8ea29149f518ad9e1f2fa86d37d2f397de07 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Wed, 15 Jul 2020 14:22:14 -0400 Subject: [PATCH] Core/Hotfixes: Add locales to hotfix_blob Port From (https://github.com/TrinityCore/TrinityCore/commit/590f541019f7630f614110c60ce3653b17ca77e2) --- Source/Game/DataStorage/DB2Manager.cs | 42 ++++++++++++++----- Source/Game/Handlers/HotfixHandler.cs | 2 +- .../master/2020_07_04_00_hotfixes.sql | 6 +++ 3 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 sql/updates/hotfixes/master/2020_07_04_00_hotfixes.sql diff --git a/Source/Game/DataStorage/DB2Manager.cs b/Source/Game/DataStorage/DB2Manager.cs index 20cab88cc..48a4d6f4d 100644 --- a/Source/Game/DataStorage/DB2Manager.cs +++ b/Source/Game/DataStorage/DB2Manager.cs @@ -39,6 +39,9 @@ namespace Game.DataStorage for (uint i = 0; i < (int)Locale.Total + 1; ++i) _nameValidators[i] = new List(); + + for (var i = 0; i < (int)Locale.Total; ++i) + _hotfixBlob[i] = new Dictionary, byte[]>(); } public void LoadStores() @@ -652,10 +655,17 @@ namespace Game.DataStorage uint tableHash = result.Read(1); int recordId = result.Read(2); bool deleted = result.Read(3); - if (!deleted && !_storage.ContainsKey(tableHash) && !_hotfixBlob.ContainsKey(Tuple.Create(tableHash, recordId))) + if (!deleted && !_storage.ContainsKey(tableHash)) { - Log.outError(LogFilter.Sql, $"Table `hotfix_data` references unknown DB2 store by hash 0x{tableHash:X} and has no reference to `hotfix_blob` in hotfix id {id} with RecordID: {recordId}"); - continue; + var key = Tuple.Create(tableHash, recordId); + foreach (var dic in _hotfixBlob) + { + if (!dic.ContainsKey(key)) + { + Log.outError(LogFilter.Sql, $"Table `hotfix_data` references unknown DB2 store by hash 0x{tableHash:X} and has no reference to `hotfix_blob` in hotfix id {id} with RecordID: {recordId}"); + continue; + } + } } HotfixRecord hotfixRecord = new HotfixRecord(); @@ -684,15 +694,15 @@ namespace Game.DataStorage public void LoadHotfixBlob() { uint oldMSTime = Time.GetMSTime(); - _hotfixBlob.Clear(); - SQLResult result = DB.Hotfix.Query("SELECT TableHash, RecordId, `Blob` FROM hotfix_blob ORDER BY TableHash"); + SQLResult result = DB.Hotfix.Query("SELECT TableHash, RecordId, locale, `Blob` FROM hotfix_blob ORDER BY TableHash"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 hotfix blob entries."); return; } + uint hotfixBlobCount = 0; do { uint tableHash = result.Read(0); @@ -704,19 +714,31 @@ namespace Game.DataStorage } int recordId = result.Read(1); - _hotfixBlob[Tuple.Create(tableHash, recordId)] = result.Read(2); + string localeName = result.Read(2); + + Locale locale = localeName.ToEnum(); + if (!SharedConst.IsValidLocale(locale)) + { + Log.outError(LogFilter.ServerLoading, $"`hotfix_blob` contains invalid locale: {localeName} at TableHash: 0x{tableHash:X} and RecordID: {recordId}"); + continue; + } + + _hotfixBlob[(int)locale][Tuple.Create(tableHash, recordId)] = result.Read(2); + hotfixBlobCount++; } while (result.NextRow()); - Log.outInfo(LogFilter.ServerLoading, $"Loaded {_hotfixBlob.Count} hotfix blob records in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); + Log.outInfo(LogFilter.ServerLoading, $"Loaded {hotfixBlobCount} hotfix blob records in {Time.GetMSTimeDiffToNow(oldMSTime)} ms"); } public uint GetHotfixCount() { return (uint)_hotfixData.Count; } public List GetHotfixData() { return _hotfixData; } - public byte[] GetHotfixBlobData(uint tableHash, int recordId) + public byte[] GetHotfixBlobData(uint tableHash, int recordId, Locale locale) { - return _hotfixBlob.LookupByKey(Tuple.Create(tableHash, recordId)); + Cypher.Assert(SharedConst.IsValidLocale(locale), "Locale {locale} is invalid locale"); + + return _hotfixBlob[(int)locale].LookupByKey(Tuple.Create(tableHash, recordId)); } public uint GetEmptyAnimStateID() @@ -2055,7 +2077,7 @@ namespace Game.DataStorage Dictionary _storage = new Dictionary(); List _hotfixData = new List(); - Dictionary, byte[]> _hotfixBlob = new Dictionary, byte[]>(); + Dictionary, byte[]>[] _hotfixBlob = new Dictionary, byte[]>[(int)Locale.Total]; MultiMap _areaGroupMembers = new MultiMap(); MultiMap _artifactPowers = new MultiMap(); diff --git a/Source/Game/Handlers/HotfixHandler.cs b/Source/Game/Handlers/HotfixHandler.cs index 25fcec77e..a8a84cd3d 100644 --- a/Source/Game/Handlers/HotfixHandler.cs +++ b/Source/Game/Handlers/HotfixHandler.cs @@ -84,7 +84,7 @@ namespace Game } else { - byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID); + byte[] blobData = Global.DB2Mgr.GetHotfixBlobData(hotfixRecord.TableHash, hotfixRecord.RecordID, GetSessionDbcLocale()); if (blobData != null) { hotfixData.Size.Set((uint)blobData.Length); diff --git a/sql/updates/hotfixes/master/2020_07_04_00_hotfixes.sql b/sql/updates/hotfixes/master/2020_07_04_00_hotfixes.sql new file mode 100644 index 000000000..064e65f8f --- /dev/null +++ b/sql/updates/hotfixes/master/2020_07_04_00_hotfixes.sql @@ -0,0 +1,6 @@ +ALTER TABLE `hotfix_blob` +ADD COLUMN `locale` VARCHAR(4) NOT NULL COLLATE 'utf8mb4_unicode_ci' AFTER `RecordId`, +DROP PRIMARY KEY, +ADD PRIMARY KEY (`TableHash`, `RecordId`, `locale`); + +UPDATE `hotfix_blob` SET `locale` = "enUS";