WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
RaceInfos.cpp
Go to the documentation of this file.
1#include "RaceInfos.h"
2#include "DB2Table.h"
3#include "Game.h"
4#include "WoWDatabase.h"
5#include "WoWModel.h"
6#include "Logger.h"
7
8#define DEBUG_RACEINFOS 1
9
10std::map<int, RaceInfos> RaceInfos::RACES;
11
13{
14 const DB2Table* chrRaceXChrModel = WOWDB.getTable("ChrRaceXChrModel");
15 const DB2Table* chrRaces = WOWDB.getTable("ChrRaces");
16 const DB2Table* chrModel = WOWDB.getTable("ChrModel");
17 const DB2Table* creatureDisplayInfo = WOWDB.getTable("CreatureDisplayInfo");
18 const DB2Table* creatureModelData = WOWDB.getTable("CreatureModelData");
19
20 if (!chrRaceXChrModel || !chrRaces || !chrModel || !creatureDisplayInfo || !creatureModelData)
21 {
22 LOG_ERROR << "Unable to collect race information from game database";
23 return;
24 }
25
26 for (const auto& xRow : *chrRaceXChrModel)
27 {
28 const uint32_t chrRacesID = xRow.getUInt("ChrRacesID");
29 const uint32_t chrModelID = xRow.getUInt("ChrModelID");
30
31 DB2Row raceRow = chrRaces->getRow(chrRacesID);
32 DB2Row modelRow = chrModel->getRow(chrModelID);
33
34 if (!raceRow || !modelRow)
35 continue;
36
37 const uint32_t displayID = modelRow.getUInt("DisplayID");
38 DB2Row displayRow = creatureDisplayInfo->getRow(displayID);
39 if (!displayRow)
40 continue;
41
42 const uint32_t modelDataID = displayRow.getUInt("ModelID");
43 DB2Row modelDataRow = creatureModelData->getRow(modelDataID);
44 if (!modelDataRow)
45 continue;
46
47 RaceInfos infos;
48 infos.prefix = raceRow.getString("ClientPrefix");
49 infos.raceID = static_cast<int>(raceRow.recordID());
50 infos.barefeet = (static_cast<int>(raceRow.getUInt("Flags")) & 0x2);
51 infos.sexID = static_cast<int>(modelRow.getUInt("Sex"));
52 auto modelfileid = static_cast<int>(modelDataRow.getUInt("FileDataID"));
53 infos.textureLayoutID = static_cast<int>(modelRow.getUInt("CharComponentTextureLayoutID"));
54 if (infos.textureLayoutID <= 0)
55 {
56 LOG_WARNING << "Unexpected textureLayoutID (" << infos.textureLayoutID << ") for raceID " << infos.raceID << ", sexID " << infos.sexID;
57 }
58
59 // Get fallback display race ID (this is mostly for allied races and others that rely on
60 // item display info from other race models):
61 if (infos.sexID == GENDER_MALE)
62 {
63 infos.modelFallbackRaceID = raceRow.getInt("MaleModelFallbackRaceID");
64 infos.modelFallbackSexID = raceRow.getInt("MaleModelFallbackSex");
65 infos.textureFallbackRaceID = raceRow.getInt("MaleTextureFallbackRaceID");
66 infos.textureFallbackSexID = raceRow.getInt("MaleTextureFallbackSex");
67 }
68 else
69 {
70 infos.modelFallbackRaceID = raceRow.getInt("FemaleModelFallbackRaceID");
71 infos.modelFallbackSexID = raceRow.getInt("FemaleModelFallbackSex");
72 infos.textureFallbackRaceID = raceRow.getInt("FemaleTextureFallbackRaceID");
73 infos.textureFallbackSexID = raceRow.getInt("FemaleTextureFallbackSex");
74 }
75
76 infos.ChrModelID.push_back(static_cast<int>(chrModelID));
77
78 infos.isHD = GAMEDIRECTORY.getFile(modelfileid)->fullname().find("_hd") != std::string::npos;
79
80 if (RACES.find(modelfileid) == RACES.end())
81 {
82 RACES[modelfileid] = infos;
83 }
84 else // if a race is already inserted, capture any additional ChrModelID
85 {
86 auto id = static_cast<int>(chrModelID);
87 if (std::find(RACES[modelfileid].ChrModelID.begin(), RACES[modelfileid].ChrModelID.end(), id) == RACES[
88 modelfileid].ChrModelID.end())
89 RACES[modelfileid].ChrModelID.push_back(id);
90 }
91 }
92
93#if DEBUG_RACEINFOS > 0
94 for (const auto& r : RACES)
95 {
96 LOG_INFO << "---------------------------";
97 LOG_INFO << "modelfileid ->" << r.first;
98 LOG_INFO << "infos.prefix =" << r.second.prefix.c_str();
99 LOG_INFO << "infos.textureLayoutID =" << r.second.textureLayoutID;
100 LOG_INFO << "infos.raceID =" << r.second.raceID;
101 LOG_INFO << "infos.sexID =" << r.second.sexID;
102 LOG_INFO << "infos.isHD =" << r.second.isHD;
103 LOG_INFO << "infos.modelFallbackRaceID =" << r.second.modelFallbackRaceID;
104 LOG_INFO << "infos.modelFallbackSexID =" << r.second.modelFallbackSexID;
105 LOG_INFO << "infos.textureFallbackRaceID =" << r.second.textureFallbackRaceID;
106 LOG_INFO << "infos.textureFallbackSexID =" << r.second.textureFallbackSexID;
107 for (const auto& it : r.second.ChrModelID)
108 LOG_INFO << "infos.ChrModelID ->" << it;
109 LOG_INFO << "---------------------------";
110 }
111#endif
112}
113
115{
116 auto result = fileid; // return same file id by default
117
118 const auto it = RACES.find(fileid);
119 if (it != RACES.end() && !it->second.isHD)
120 {
121 const auto raceID = it->second.raceID;
122 const auto sexID = it->second.sexID;
123
124 for (const auto& r : RACES)
125 {
126 if (r.second.raceID == raceID && r.second.sexID == sexID && r.second.isHD)
127 {
128 result = r.first;
129 break;
130 }
131 }
132 }
133 return result;
134}
135
137{
138 const auto raceInfosIt = RaceInfos::RACES.find(fileid);
139
140 if (raceInfosIt != RaceInfos::RACES.end())
141 {
142 infos = raceInfosIt->second;
143 return true;
144 }
145
146 return false;
147}
148
149int RaceInfos::getFileIDForRaceSex(const int& race, const int& sex)
150{
151 for (const auto& r : RACES)
152 {
153 if (r.second.raceID == race && r.second.sexID == sex)
154 return r.first;
155 }
156
157 return -1;
158}
#define GAMEDIRECTORY
Definition Game.h:9
#define LOG_ERROR
Definition Logger.h:11
#define LOG_WARNING
Definition Logger.h:12
#define LOG_INFO
Definition Logger.h:10
#define WOWDB
Definition WoWDatabase.h:65
Lightweight handle to a single row in a DB2Table.
Definition DB2Table.h:27
std::string getString(const std::string &field, unsigned int arrayIndex=0) const
Definition DB2Table.cpp:67
int32_t getInt(const std::string &field, unsigned int arrayIndex=0) const
Definition DB2Table.cpp:26
uint32_t recordID() const
Definition DB2Table.cpp:11
uint32_t getUInt(const std::string &field, unsigned int arrayIndex=0) const
Definition DB2Table.cpp:17
Provides typed, field-name-based access to records in a WDC DB2 file.
Definition DB2Table.h:50
DB2Row getRow(uint32_t id) const
Definition DB2Table.cpp:97
Stores per-race/sex metadata loaded from ChrRaces / ChrModel database tables.
Definition RaceInfos.h:11
std::vector< int > ChrModelID
ChrModel IDs for this race/sex.
Definition RaceInfos.h:23
bool isHD
Whether this is an HD model.
Definition RaceInfos.h:16
int sexID
0 = male, 1 = female.
Definition RaceInfos.h:14
static std::map< int, RaceInfos > RACES
Definition RaceInfos.h:37
static int getHDModelForFileID(int)
Get the HD model file ID for a given file ID.
static int getFileIDForRaceSex(const int &race, const int &sex)
Get the model file ID for a specific race and sex.
static void init()
Initialise the global race info table from the database.
Definition RaceInfos.cpp:12
bool barefeet
Whether the race shows bare feet by default.
Definition RaceInfos.h:17
int textureLayoutID
Texture layout ID for compositing.
Definition RaceInfos.h:15
int modelFallbackSexID
Fallback sex for the model.
Definition RaceInfos.h:20
int textureFallbackSexID
Fallback sex for textures.
Definition RaceInfos.h:22
static bool getRaceInfosForFileID(int, RaceInfos &)
Populate a RaceInfos struct from a model file ID.
std::string prefix
Race name prefix used for file lookups.
Definition RaceInfos.h:18
int raceID
Race ID (-1 = invalid).
Definition RaceInfos.h:13
int textureFallbackRaceID
Fallback race for textures.
Definition RaceInfos.h:21
int modelFallbackRaceID
Fallback race for the model.
Definition RaceInfos.h:19
@ GENDER_MALE
Definition wow_enums.h:341