1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* 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 "GameTables.h"
#include "ItemTemplate.h"
#include "Timer.h"
#include "Log.h"
#include "StringConvert.h"
#include "Util.h"
#include <boost/filesystem/path.hpp>
#include <fstream>
#include <sstream>
GameTable<GtArtifactKnowledgeMultiplierEntry> sArtifactKnowledgeMultiplierGameTable;
GameTable<GtArtifactLevelXPEntry> sArtifactLevelXPGameTable;
GameTable<GtBarberShopCostBaseEntry> sBarberShopCostBaseGameTable;
GameTable<GtBaseMPEntry> sBaseMPGameTable;
GameTable<GtBattlePetXPEntry> sBattlePetXPGameTable;
GameTable<GtCombatRatingsEntry> sCombatRatingsGameTable;
GameTable<GtCombatRatingsMultByILvl> sCombatRatingsMultByILvlGameTable;
GameTable<GtHpPerStaEntry> sHpPerStaGameTable;
GameTable<GtItemLevelByLevelEntry> sItemLevelByLevelTable;
GameTable<GtItemSocketCostPerLevelEntry> sItemSocketCostPerLevelGameTable;
GameTable<GtNpcManaCostScalerEntry> sNpcManaCostScalerGameTable;
GameTable<GtSpellScalingEntry> sSpellScalingGameTable;
GameTable<GtStaminaMultByILvl> sStaminaMultByILvlGameTable;
GameTable<GtXpEntry> sXpGameTable;
template<class T>
inline uint32 LoadGameTable(std::vector<std::string>& errors, GameTable<T>& storage, boost::filesystem::path const& path)
{
std::ifstream stream(path.string());
if (!stream)
{
errors.push_back(Trinity::StringFormat("GameTable file {} cannot be opened.", path.string()));
return 0;
}
std::string headers;
if (!std::getline(stream, headers))
{
errors.push_back(Trinity::StringFormat("GameTable file {} is empty.", path.string()));
return 0;
}
std::vector<std::string_view> columnDefs = Trinity::Tokenize(headers, '\t', false);
ASSERT(columnDefs.size() - 1 == sizeof(T) / sizeof(float),
"GameTable '%s' has different count of columns " SZFMTD " than expected by size of C++ structure (" SZFMTD ").",
path.string().c_str(), columnDefs.size() - 1, sizeof(T) / sizeof(float));
std::vector<T> data;
data.emplace_back(); // row id 0, unused
std::string line;
while (std::getline(stream, line))
{
RemoveCRLF(line); // file extracted from client will always have CRLF line endings, on linux opening file in text mode will not work, manually erase \r
std::vector<std::string_view> values = Trinity::Tokenize(line, '\t', true);
if (values.empty())
break;
// make end point just after last nonempty token
auto end = values.begin() + values.size() - 1;
while (end->empty() && end != values.begin())
--end;
if (values.begin() == end)
break;
++end;
ASSERT(std::size_t(std::distance(values.begin(), end)) == columnDefs.size(), SZFMTD " == " SZFMTD, std::size_t(std::distance(values.begin(), end)), columnDefs.size());
// client ignores id column - CombatRatings has copypasted rows for levels > 110
//ASSERT(Trinity::StringTo<int32>(values[0], 10) == data.size(),
// "Unexpected row identifier %d at row " SZFMTD " (expected " SZFMTD ")",
// Trinity::StringTo<int32>(values[0], 10).value_or(0), data.size(), data.size());
data.emplace_back();
float* row = reinterpret_cast<float*>(&data.back());
for (auto itr = values.begin() + 1; itr != end; ++itr)
*row++ = Trinity::StringTo<float>(*itr, 10).value_or(0.0f);
}
storage.SetData(std::move(data));
return 1;
}
void LoadGameTables(std::string const& dataPath)
{
uint32 oldMSTime = getMSTime();
boost::filesystem::path gtPath(dataPath);
gtPath /= "gt";
std::vector<std::string> bad_gt_files;
uint32 gameTableCount = 0, expectedGameTableCount = 0;
auto LOAD_GT = [&]<typename T>(GameTable<T>& gameTable, char const* file)
{
gameTableCount += LoadGameTable(bad_gt_files, gameTable, gtPath / file);
++expectedGameTableCount;
};
LOAD_GT(sArtifactKnowledgeMultiplierGameTable, "ArtifactKnowledgeMultiplier.txt");
LOAD_GT(sArtifactLevelXPGameTable, "ArtifactLevelXP.txt");
LOAD_GT(sBarberShopCostBaseGameTable, "BarberShopCostBase.txt");
LOAD_GT(sBaseMPGameTable, "BaseMp.txt");
LOAD_GT(sBattlePetXPGameTable, "BattlePetXP.txt");
LOAD_GT(sCombatRatingsGameTable, "CombatRatings.txt");
LOAD_GT(sCombatRatingsMultByILvlGameTable, "CombatRatingsMultByILvl.txt");
LOAD_GT(sItemLevelByLevelTable, "ItemLevelByLevel.txt");
LOAD_GT(sItemSocketCostPerLevelGameTable, "ItemSocketCostPerLevel.txt");
LOAD_GT(sHpPerStaGameTable, "HpPerSta.txt");
LOAD_GT(sNpcManaCostScalerGameTable, "NPCManaCostScaler.txt");
LOAD_GT(sSpellScalingGameTable, "SpellScaling.txt");
LOAD_GT(sStaminaMultByILvlGameTable, "StaminaMultByILvl.txt");
LOAD_GT(sXpGameTable, "xp.txt");
#undef LOAD_GT
// error checks
if (gameTableCount != expectedGameTableCount)
{
std::ostringstream str;
for (std::string const& err : bad_gt_files)
str << err << std::endl;
WPFatal(false, "Some required *.txt GameTable files (" SZFMTD ") not found or not compatible:\n%s", bad_gt_files.size(), str.str().c_str());
}
TC_LOG_INFO("server.loading", ">> Initialized {} GameTables in {} ms", gameTableCount, GetMSTimeDiffToNow(oldMSTime));
}
template<class T>
float GetIlvlStatMultiplier(T const* row, InventoryType invType)
{
switch (invType)
{
case INVTYPE_NECK:
case INVTYPE_FINGER:
return row->JewelryMultiplier;
break;
case INVTYPE_TRINKET:
return row->TrinketMultiplier;
break;
case INVTYPE_WEAPON:
case INVTYPE_SHIELD:
case INVTYPE_RANGED:
case INVTYPE_2HWEAPON:
case INVTYPE_WEAPONMAINHAND:
case INVTYPE_WEAPONOFFHAND:
case INVTYPE_HOLDABLE:
case INVTYPE_RANGEDRIGHT:
return row->WeaponMultiplier;
break;
default:
return row->ArmorMultiplier;
break;
}
}
template float GetIlvlStatMultiplier(GtCombatRatingsMultByILvl const* row, InventoryType invType);
template float GetIlvlStatMultiplier(GtStaminaMultByILvl const* row, InventoryType invType);
|