Core/DataStores: Added somewhat generic db2 hotfix generator

This commit is contained in:
Shauren
2018-01-09 21:37:26 +01:00
parent d15afd2ffd
commit 208ae9e69f
5 changed files with 111 additions and 2 deletions

View File

@@ -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));
}

View File

@@ -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);
}
}

View File

@@ -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__

View File

@@ -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);

View File

@@ -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()