aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2018-01-09 21:37:26 +0100
committerShauren <shauren.trinity@gmail.com>2018-01-09 21:37:26 +0100
commit208ae9e69fe5ca4abcc7fa77a917f34ce3e7330f (patch)
treec1fa3d14660ba4a2f861f9401988a2557689e31d /src
parentd15afd2ffd2f68e55f3b0a721278f757f4245275 (diff)
Core/DataStores: Added somewhat generic db2 hotfix generator
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp10
-rw-r--r--src/server/game/DataStores/DB2HotfixGenerator.cpp41
-rw-r--r--src/server/game/DataStores/DB2HotfixGenerator.h47
-rw-r--r--src/server/game/DataStores/DB2Stores.cpp6
-rw-r--r--src/server/game/DataStores/DB2Stores.h9
5 files changed, 111 insertions, 2 deletions
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 470c91a9f32..32b301d44ab 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -18,6 +18,7 @@
#include "AchievementMgr.h"
#include "AchievementPackets.h"
+#include "DB2HotfixGenerator.h"
#include "DB2Stores.h"
#include "CellImpl.h"
#include "ChatTextBuilder.h"
@@ -1052,9 +1053,14 @@ void AchievementGlobalMgr::LoadAchievementReferenceList()
++count;
}
+ DB2HotfixGenerator<AchievementEntry> hotfixes(sAchievementStore);
+
// Once Bitten, Twice Shy (10 player) - Icecrown Citadel
- if (AchievementEntry const* achievement = sAchievementStore.LookupEntry(4539))
- const_cast<AchievementEntry*>(achievement)->MapID = 631; // Correct map requirement (currently has Ulduar); 6.0.3 note - it STILL has ulduar requirement
+ // Correct map requirement (currently has Ulduar); 6.0.3 note - it STILL has ulduar requirement
+ hotfixes.ApplyHotfix(4539, [](AchievementEntry* achievement)
+ {
+ achievement->MapID = 631;
+ });
TC_LOG_INFO("server.loading", ">> Loaded %u achievement references in %u ms.", count, GetMSTimeDiffToNow(oldMSTime));
}
diff --git a/src/server/game/DataStores/DB2HotfixGenerator.cpp b/src/server/game/DataStores/DB2HotfixGenerator.cpp
new file mode 100644
index 00000000000..4d3e18098ef
--- /dev/null
+++ b/src/server/game/DataStores/DB2HotfixGenerator.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
+ *
+ * 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 2 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/>.
+ */
+
+#include "DB2HotfixGenerator.h"
+#include "DB2Stores.h"
+#include "Log.h"
+
+template<class T>
+void DB2HotfixGenerator<T>::ApplyHotfix(uint32 const* begin, uint32 const* end, void(*fixer)(T*), bool notifyClient)
+{
+ while (begin != end)
+ {
+ uint32 id = *begin++;
+ T const* entry = _storage.LookupEntry(id);
+ if (!entry)
+ {
+ TC_LOG_ERROR("db2.hotfix", "Hotfix specified for %s row which does not exist", _storage.GetFileName().c_str(), id);
+ continue;
+ }
+
+ fixer(const_cast<T*>(entry));
+ ++_count;
+
+ if (notifyClient)
+ sDB2Manager.InsertNewHotfix(_storage.GetTableHash(), id);
+ }
+}
diff --git a/src/server/game/DataStores/DB2HotfixGenerator.h b/src/server/game/DataStores/DB2HotfixGenerator.h
new file mode 100644
index 00000000000..06c986bf9b9
--- /dev/null
+++ b/src/server/game/DataStores/DB2HotfixGenerator.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
+ *
+ * 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 2 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/>.
+ */
+
+#ifndef DB2HotfixGenerator_h__
+#define DB2HotfixGenerator_h__
+
+#include "Define.h"
+
+template<class T>
+class DB2Storage;
+
+template<class T>
+class DB2HotfixGenerator
+{
+public:
+ explicit DB2HotfixGenerator(DB2Storage<T>& storage) : _storage(storage), _count(0) { }
+
+ void ApplyHotfix(uint32 id, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix({ id }, fixer, notifyClient); }
+ void ApplyHotfix(std::initializer_list<uint32> ids, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix(ids.begin(), ids.end(), fixer, notifyClient); }
+
+ template<class I, class = typename std::enable_if<!std::is_void<decltype(*std::begin(std::declval<I>()))>::value>::type>
+ void ApplyHotfix(I const& ids, void(*fixer)(T*), bool notifyClient = false) { ApplyHotfix(std::begin(ids), std::end(ids), fixer, notifyClient); }
+
+ uint32 GetAppliedHotfixesCount() const { return _count; }
+
+private:
+ void ApplyHotfix(uint32 const* begin, uint32 const* end, void(*fixer)(T*), bool notifyClient);
+
+ DB2Storage<T>& _storage;
+ uint32 _count;
+};
+
+#endif // DB2HotfixGenerator_h__
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp
index 165999d732f..afdca6dbbe0 100644
--- a/src/server/game/DataStores/DB2Stores.cpp
+++ b/src/server/game/DataStores/DB2Stores.cpp
@@ -1139,6 +1139,7 @@ void DB2Manager::LoadHotfixData()
continue;
}
+ _maxHotfixId = std::max(_maxHotfixId, id);
_hotfixData[MAKE_PAIR64(id, tableHash)] = recordId;
deletedRecords[std::make_pair(tableHash, recordId)] = deleted;
++count;
@@ -1157,6 +1158,11 @@ std::map<uint64, int32> const& DB2Manager::GetHotfixData() const
return _hotfixData;
}
+void DB2Manager::InsertNewHotfix(uint32 tableHash, uint32 recordId)
+{
+ _hotfixData[MAKE_PAIR64(tableHash, ++_maxHotfixId)] = recordId;
+}
+
std::vector<uint32> DB2Manager::GetAreasForGroup(uint32 areaGroupId) const
{
auto itr = _areaGroupMembers.find(areaGroupId);
diff --git a/src/server/game/DataStores/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h
index 51bedb64d9b..40d2a975660 100644
--- a/src/server/game/DataStores/DB2Stores.h
+++ b/src/server/game/DataStores/DB2Stores.h
@@ -32,6 +32,9 @@
#undef GetClassName
#endif
+template<typename T>
+class DB2HotfixGenerator;
+
TC_GAME_API extern DB2Storage<AchievementEntry> sAchievementStore;
TC_GAME_API extern DB2Storage<AnimKitEntry> sAnimKitStore;
TC_GAME_API extern DB2Storage<AreaTableEntry> sAreaTableStore;
@@ -326,6 +329,12 @@ public:
void Zone2MapCoordinates(uint32 areaId, float& x, float& y) const;
void Map2ZoneCoordinates(uint32 areaId, float& x, float& y) const;
static void DeterminaAlternateMapPosition(uint32 mapId, float x, float y, float z, uint32* newMapId = nullptr, DBCPosition2D* newPos = nullptr);
+
+private:
+ template<typename T>
+ friend class DB2HotfixGenerator;
+ void InsertNewHotfix(uint32 tableHash, uint32 recordId);
+ uint32 _maxHotfixId = 0;
};
#define sDB2Manager DB2Manager::Instance()