2009-09-13 18:02:46 -06:00
|
|
|
/*
|
|
|
|
www.sourceforge.net/projects/dfhack
|
|
|
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
|
|
|
*/
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <map>
|
|
|
|
using namespace std;
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2010-05-25 22:48:23 -06:00
|
|
|
#include "dfhack/DFError.h"
|
|
|
|
#include "dfhack/DFProcess.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
using namespace DFHack;
|
2010-04-04 16:48:19 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
//Inital amount of space in levels vector (since we usually know the number, efficient!)
|
2010-06-10 09:53:25 -06:00
|
|
|
#define NUM_RESERVE_LVLS 20
|
2010-06-17 18:17:19 -06:00
|
|
|
#define NUM_RESERVE_MOODS 6
|
2009-11-13 20:46:56 -07:00
|
|
|
|
2011-03-24 19:31:27 -06:00
|
|
|
//FIXME: put those in some shared file
|
|
|
|
template<template <typename> class P = std::less >
|
|
|
|
struct compare_pair_first
|
|
|
|
{
|
|
|
|
template<class T1, class T2>
|
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T1>()(left.first, right.first);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<template <typename> class P = std::less >
|
|
|
|
struct compare_pair_second
|
|
|
|
{
|
|
|
|
template<class T1, class T2>
|
|
|
|
bool operator()(const std::pair<T1, T2>& left, const std::pair<T1, T2>& right)
|
|
|
|
{
|
|
|
|
return P<T2>()(left.second, right.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-04 16:02:02 -06:00
|
|
|
/*
|
|
|
|
* Common data types
|
|
|
|
*/
|
|
|
|
namespace DFHack
|
|
|
|
{
|
|
|
|
struct t_type
|
|
|
|
{
|
|
|
|
t_type(uint32_t assign, uint32_t type, std::string classname)
|
|
|
|
:classname(classname),assign(assign),type(type){};
|
|
|
|
std::string classname;
|
|
|
|
uint32_t assign;
|
|
|
|
uint32_t type;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct t_class
|
|
|
|
{
|
|
|
|
t_class(const t_class &old)
|
|
|
|
{
|
|
|
|
classname = old.classname;
|
|
|
|
vtable = old.vtable;
|
|
|
|
assign = old.assign;
|
|
|
|
type_offset = old.type_offset;
|
|
|
|
for(uint32_t i = 0; i < old.subs.size();i++)
|
|
|
|
{
|
|
|
|
t_type * t = new t_type (*old.subs[i]);
|
|
|
|
subs.push_back(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t_class ()
|
|
|
|
{
|
|
|
|
vtable = 0;
|
|
|
|
assign = 0;
|
|
|
|
type_offset = 0;
|
|
|
|
}
|
|
|
|
~t_class()
|
|
|
|
{
|
|
|
|
for(uint32_t i = 0; i < subs.size();i++)
|
|
|
|
{
|
|
|
|
delete subs[i];
|
|
|
|
}
|
|
|
|
subs.clear();
|
|
|
|
}
|
|
|
|
std::string classname;
|
|
|
|
uint32_t vtable;
|
|
|
|
uint32_t assign;// index to typeclass array if multiclass. return value if not.
|
|
|
|
uint32_t type_offset; // offset of type data for multiclass
|
|
|
|
std::vector<t_type *> subs;
|
|
|
|
};
|
2010-08-28 04:47:33 -06:00
|
|
|
class indentr
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend std::basic_ostream<char>& operator <<(std::basic_ostream<char>&, const indentr &);
|
|
|
|
indentr(int ns = 0, int size = 4)
|
|
|
|
{
|
|
|
|
numspaces = ns;
|
|
|
|
step = size;
|
|
|
|
}
|
|
|
|
void indent ()
|
|
|
|
{
|
|
|
|
numspaces += step;
|
|
|
|
if (numspaces < 0) numspaces = 0;
|
|
|
|
}
|
|
|
|
void unindent ()
|
|
|
|
{
|
|
|
|
numspaces -= step;
|
|
|
|
if (numspaces < 0) numspaces = 0;
|
|
|
|
}
|
|
|
|
int get ()
|
|
|
|
{
|
|
|
|
return numspaces;
|
|
|
|
}
|
|
|
|
void set (int ns)
|
|
|
|
{
|
|
|
|
numspaces = ns;
|
|
|
|
if (numspaces < 0) numspaces = 0;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
int step;
|
|
|
|
int numspaces;
|
|
|
|
};
|
|
|
|
std::basic_ostream<char>& operator<< (std::basic_ostream<char>& os, const indentr & idtr)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < idtr.numspaces ;i++)
|
|
|
|
{
|
|
|
|
os << ' ';
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
};
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
/*
|
|
|
|
* Private data
|
|
|
|
*/
|
|
|
|
namespace DFHack
|
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
typedef pair <INVAL_TYPE, uint32_t> nullableUint32;
|
2010-08-27 19:57:56 -06:00
|
|
|
typedef map <string, nullableUint32 >::iterator uint32_Iter;
|
2010-11-07 16:10:59 -07:00
|
|
|
typedef pair <INVAL_TYPE, int32_t> nullableInt32;
|
2010-08-27 19:57:56 -06:00
|
|
|
typedef map <string, nullableInt32 >::iterator int32_Iter;
|
2010-11-07 16:10:59 -07:00
|
|
|
typedef pair <INVAL_TYPE, string> nullableString;
|
2010-08-27 19:57:56 -06:00
|
|
|
typedef map <string, nullableString >::iterator strings_Iter;
|
|
|
|
typedef map <string, OffsetGroup *>::iterator groups_Iter;
|
2010-08-23 11:28:53 -06:00
|
|
|
class OffsetGroupPrivate
|
|
|
|
{
|
|
|
|
public:
|
2010-08-27 19:57:56 -06:00
|
|
|
map <string, nullableUint32 > addresses;
|
|
|
|
map <string, nullableUint32 > hexvals;
|
|
|
|
map <string, nullableInt32 > offsets;
|
|
|
|
map <string, nullableString > strings;
|
|
|
|
map <string, OffsetGroup *> groups;
|
2010-08-27 22:31:44 -06:00
|
|
|
std::string name;
|
|
|
|
OffsetGroup * parent;
|
2010-08-23 11:28:53 -06:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
void OffsetGroup::createOffset(const string & key)
|
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
OGd->offsets[key] = nullableInt32(NOT_SET, 0);
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffsetGroup::createAddress(const string & key)
|
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
OGd->addresses[key] = nullableUint32(NOT_SET, 0);
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffsetGroup::createHexValue(const string & key)
|
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
OGd->hexvals[key] = nullableUint32(NOT_SET, 0);
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void OffsetGroup::createString(const string & key)
|
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
OGd->strings[key] = nullableString(NOT_SET, std::string());
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-11-07 16:10:59 -07:00
|
|
|
void OffsetGroup::setOffset (const string & key, const string & value, const INVAL_TYPE inval)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 20:39:03 -06:00
|
|
|
int32_Iter it = OGd->offsets.find(key);
|
|
|
|
if(it != OGd->offsets.end())
|
2010-08-27 19:57:56 -06:00
|
|
|
{
|
|
|
|
int32_t offset = strtol(value.c_str(), NULL, 16);
|
2011-03-03 09:50:17 -07:00
|
|
|
// REPORT pointless rewrites
|
2011-03-03 15:54:44 -07:00
|
|
|
if((*it).second.second == offset && (*it).second.first != NOT_SET )
|
2011-03-03 09:50:17 -07:00
|
|
|
std::cout << "Pointless offset setting: " << this->getFullName() + key << endl;
|
2010-08-27 19:57:56 -06:00
|
|
|
(*it).second.second = offset;
|
2010-11-07 16:10:59 -07:00
|
|
|
if(inval != NOT_SET)
|
|
|
|
(*it).second.first = inval;
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
else throw Error::MissingMemoryDefinition("offset", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:48:06 -07:00
|
|
|
void OffsetGroup::setOffsetValidity (const string & key, const INVAL_TYPE inval)
|
|
|
|
{
|
|
|
|
if(inval != NOT_SET)
|
|
|
|
{
|
|
|
|
int32_Iter it = OGd->offsets.find(key);
|
|
|
|
if(it != OGd->offsets.end())
|
|
|
|
{
|
|
|
|
(*it).second.first = inval;
|
|
|
|
}
|
|
|
|
else throw Error::MissingMemoryDefinition("offset", getFullName() + key);
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-11-07 16:10:59 -07:00
|
|
|
void OffsetGroup::setAddress (const string & key, const string & value, const INVAL_TYPE inval)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 20:39:03 -06:00
|
|
|
uint32_Iter it = OGd->addresses.find(key);
|
|
|
|
if(it != OGd->addresses.end())
|
2010-08-27 19:57:56 -06:00
|
|
|
{
|
|
|
|
int32_t address = strtol(value.c_str(), NULL, 16);
|
2011-03-03 15:54:44 -07:00
|
|
|
if((*it).second.second == address)
|
|
|
|
std::cout << "Pointless address setting: " << this->getFullName() + key << endl;
|
2010-08-27 19:57:56 -06:00
|
|
|
(*it).second.second = address;
|
2010-11-07 16:10:59 -07:00
|
|
|
if(inval != NOT_SET)
|
|
|
|
(*it).second.first = inval;
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
else throw Error::MissingMemoryDefinition("address", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:48:06 -07:00
|
|
|
void OffsetGroup::setAddressValidity (const string & key, const INVAL_TYPE inval)
|
|
|
|
{
|
|
|
|
if(inval != NOT_SET)
|
|
|
|
{
|
|
|
|
uint32_Iter it = OGd->addresses.find(key);
|
|
|
|
if(it != OGd->addresses.end())
|
|
|
|
{
|
|
|
|
(*it).second.first = inval;
|
|
|
|
}
|
|
|
|
else throw Error::MissingMemoryDefinition("address", getFullName() + key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-11-07 16:10:59 -07:00
|
|
|
void OffsetGroup::setHexValue (const string & key, const string & value, const INVAL_TYPE inval)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 20:39:03 -06:00
|
|
|
uint32_Iter it = OGd->hexvals.find(key);
|
|
|
|
if(it != OGd->hexvals.end())
|
2010-08-27 19:57:56 -06:00
|
|
|
{
|
|
|
|
(*it).second.second = strtol(value.c_str(), NULL, 16);
|
2010-11-07 16:10:59 -07:00
|
|
|
if(inval != NOT_SET)
|
|
|
|
(*it).second.first = inval;
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
else throw Error::MissingMemoryDefinition("hexvalue", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:48:06 -07:00
|
|
|
void OffsetGroup::setHexValueValidity (const string & key, const INVAL_TYPE inval)
|
|
|
|
{
|
|
|
|
if(inval != NOT_SET)
|
|
|
|
{
|
|
|
|
uint32_Iter it = OGd->hexvals.find(key);
|
|
|
|
if(it != OGd->hexvals.end())
|
|
|
|
{
|
|
|
|
(*it).second.first = inval;
|
|
|
|
}
|
|
|
|
else throw Error::MissingMemoryDefinition("hexvalue", getFullName() + key);
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-11-07 16:10:59 -07:00
|
|
|
void OffsetGroup::setString (const string & key, const string & value, const INVAL_TYPE inval)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 20:39:03 -06:00
|
|
|
strings_Iter it = OGd->strings.find(key);
|
|
|
|
if(it != OGd->strings.end())
|
2010-08-27 19:57:56 -06:00
|
|
|
{
|
|
|
|
(*it).second.second = value;
|
2010-11-07 16:10:59 -07:00
|
|
|
if(inval != NOT_SET)
|
|
|
|
(*it).second.first = inval;
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
else throw Error::MissingMemoryDefinition("string", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-11-16 20:48:06 -07:00
|
|
|
void OffsetGroup::setStringValidity (const string & key, const INVAL_TYPE inval)
|
|
|
|
{
|
|
|
|
if(inval != NOT_SET)
|
|
|
|
{
|
|
|
|
strings_Iter it = OGd->strings.find(key);
|
|
|
|
if(it != OGd->strings.end())
|
|
|
|
{
|
|
|
|
(*it).second.first = inval;
|
|
|
|
}
|
|
|
|
else throw Error::MissingMemoryDefinition("string", getFullName() + key);
|
|
|
|
}
|
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
|
|
|
// Get named address
|
2010-08-27 19:57:56 -06:00
|
|
|
uint32_t OffsetGroup::getAddress (const string & key)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
uint32_Iter iter = OGd->addresses.find(key);
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
if(iter != OGd->addresses.end())
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_VALID)
|
2010-08-27 19:57:56 -06:00
|
|
|
return (*iter).second.second;
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_INVALID)
|
|
|
|
throw Error::InvalidMemoryDefinition("address", getFullName() + key);
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::UnsetMemoryDefinition("address", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::MissingMemoryDefinition("address", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2011-04-11 14:13:06 -06:00
|
|
|
// Get named offset, return bool instead of throwing exceptions
|
|
|
|
bool OffsetGroup::getSafeAddress (const string & key, uint32_t & out)
|
|
|
|
{
|
|
|
|
uint32_Iter iter = OGd->addresses.find(key);
|
|
|
|
if(iter != OGd->addresses.end() && (*iter).second.first == IS_VALID)
|
|
|
|
{
|
|
|
|
out = (*iter).second.second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
|
|
|
// Get named offset
|
2010-08-27 19:57:56 -06:00
|
|
|
int32_t OffsetGroup::getOffset (const string & key)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
int32_Iter iter = OGd->offsets.find(key);
|
|
|
|
if(iter != OGd->offsets.end())
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_VALID)
|
2010-08-27 19:57:56 -06:00
|
|
|
return (*iter).second.second;
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_INVALID)
|
|
|
|
throw Error::InvalidMemoryDefinition("offset", getFullName() + key);
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::UnsetMemoryDefinition("offset", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::MissingMemoryDefinition("offset", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2011-04-11 14:13:06 -06:00
|
|
|
// Get named offset, return bool instead of throwing exceptions
|
|
|
|
bool OffsetGroup::getSafeOffset (const string & key, int32_t & out)
|
|
|
|
{
|
|
|
|
int32_Iter iter = OGd->offsets.find(key);
|
|
|
|
if(iter != OGd->offsets.end() && (*iter).second.first == IS_VALID)
|
|
|
|
{
|
|
|
|
out = (*iter).second.second;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
|
|
|
|
// Get named numerical value
|
2010-08-27 19:57:56 -06:00
|
|
|
uint32_t OffsetGroup::getHexValue (const string & key)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
uint32_Iter iter = OGd->hexvals.find(key);
|
|
|
|
if(iter != OGd->hexvals.end())
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_VALID)
|
2010-08-27 19:57:56 -06:00
|
|
|
return (*iter).second.second;
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_INVALID)
|
|
|
|
throw Error::InvalidMemoryDefinition("hexvalue", getFullName() + key);
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::UnsetMemoryDefinition("hexvalue", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::MissingMemoryDefinition("hexvalue", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
// Get named string
|
|
|
|
std::string OffsetGroup::getString (const string &key)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
strings_Iter iter = OGd->strings.find(key);
|
|
|
|
if(iter != OGd->strings.end())
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_VALID)
|
2010-08-27 19:57:56 -06:00
|
|
|
return (*iter).second.second;
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_INVALID)
|
|
|
|
throw Error::InvalidMemoryDefinition("string", getFullName() + key);
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::UnsetMemoryDefinition("string", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
2010-08-27 22:31:44 -06:00
|
|
|
throw Error::MissingMemoryDefinition("string", getFullName() + key);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup * OffsetGroup::getGroup(const std::string &name)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
groups_Iter iter = OGd->groups.find(name);
|
|
|
|
if(iter != OGd->groups.end())
|
|
|
|
return ((*iter).second);
|
|
|
|
return 0;
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup * OffsetGroup::createGroup(const std::string &name)
|
|
|
|
{
|
|
|
|
OffsetGroup * ret = getGroup(name);
|
|
|
|
if(ret)
|
|
|
|
return ret;
|
2010-08-27 22:31:44 -06:00
|
|
|
ret = new OffsetGroup(name, this);
|
2010-08-27 19:57:56 -06:00
|
|
|
OGd->groups[name] = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
void OffsetGroup::RebaseAddresses(int32_t offset)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
for(uint32_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
|
|
|
|
{
|
|
|
|
if(iter->second.first)
|
|
|
|
OGd->addresses[iter->first].second = iter->second.second + offset;
|
|
|
|
}
|
|
|
|
for(groups_Iter iter = OGd->groups.begin(); iter != OGd->groups.end(); iter++)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
(*iter).second->RebaseAddresses(offset);
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup::OffsetGroup()
|
|
|
|
{
|
|
|
|
OGd = new OffsetGroupPrivate();
|
2010-08-28 06:06:18 -06:00
|
|
|
OGd->name = "";
|
2010-08-27 22:31:44 -06:00
|
|
|
OGd->parent = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
OffsetGroup::OffsetGroup(const std::string & name, OffsetGroup * parent)
|
|
|
|
{
|
|
|
|
OGd = new OffsetGroupPrivate();
|
|
|
|
OGd->name = name;
|
|
|
|
OGd->parent = parent;
|
2010-08-27 19:57:56 -06:00
|
|
|
}
|
2010-08-23 11:28:53 -06:00
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup::~OffsetGroup()
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
for(groups_Iter it = OGd->groups.begin();it != OGd->groups.end();it++)
|
2010-08-23 11:28:53 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
delete (*it).second;
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
2010-08-27 19:57:56 -06:00
|
|
|
OGd->groups.clear();
|
|
|
|
delete OGd;
|
2010-08-23 11:28:53 -06:00
|
|
|
}
|
|
|
|
|
2010-08-27 22:31:44 -06:00
|
|
|
std::string OffsetGroup::getName()
|
|
|
|
{
|
|
|
|
return OGd->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
OffsetGroup * OffsetGroup::getParent()
|
|
|
|
{
|
|
|
|
return OGd->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string OffsetGroup::getFullName()
|
|
|
|
{
|
|
|
|
string temp, accum;
|
|
|
|
OffsetGroup * curr = this;
|
|
|
|
while(curr)
|
|
|
|
{
|
|
|
|
temp = curr->getName() + string("/") + accum;
|
|
|
|
accum = temp;
|
|
|
|
curr = curr->getParent();
|
|
|
|
}
|
|
|
|
return accum;
|
|
|
|
}
|
|
|
|
|
2010-08-28 04:47:33 -06:00
|
|
|
std::string OffsetGroup::PrintOffsets(int indentation)
|
2010-08-27 22:31:44 -06:00
|
|
|
{
|
|
|
|
uint32_Iter iter;
|
|
|
|
ostringstream ss;
|
2010-08-28 04:47:33 -06:00
|
|
|
indentr i(indentation);
|
2011-03-24 19:31:27 -06:00
|
|
|
typedef pair <uint32_t, pair< string, nullableUint32 > > horrible;
|
|
|
|
vector < horrible > addrsorter;
|
2010-08-27 22:31:44 -06:00
|
|
|
for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
|
|
|
|
{
|
2010-08-28 06:06:18 -06:00
|
|
|
if(!(*iter).second.first)
|
2011-03-24 19:31:27 -06:00
|
|
|
addrsorter.push_back( make_pair( 0, *iter ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
addrsorter.push_back( make_pair( (*iter).second.second, *iter ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(addrsorter.begin(), addrsorter.end(), compare_pair_first<>());
|
|
|
|
for(int idx = 0; idx < addrsorter.size();idx++)
|
|
|
|
{
|
|
|
|
horrible & h = addrsorter[idx];
|
|
|
|
ss << i << "<Address name=\"" << h.second.first << "\"";
|
|
|
|
if(h.second.second.first)
|
|
|
|
ss << " value=\"" << hex << "0x" << h.first << "\"";
|
|
|
|
if(h.second.second.first == IS_INVALID)
|
|
|
|
ss << " valid=\"false\"";
|
|
|
|
ss << " />";
|
|
|
|
if(h.second.second.first == NOT_SET)
|
|
|
|
ss << " NOT SET!";
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << endl;
|
2010-08-27 22:31:44 -06:00
|
|
|
}
|
2011-03-24 19:31:27 -06:00
|
|
|
|
|
|
|
typedef pair <int32_t, pair< string, nullableInt32 > > terrible;
|
|
|
|
vector < terrible > offsorter;
|
2010-08-27 22:31:44 -06:00
|
|
|
int32_Iter iter2;
|
|
|
|
for(iter2 = OGd->offsets.begin(); iter2 != OGd->offsets.end(); iter2++)
|
|
|
|
{
|
2010-08-28 06:06:18 -06:00
|
|
|
if(!(*iter2).second.first)
|
2011-03-24 19:31:27 -06:00
|
|
|
offsorter.push_back( make_pair( 0, *iter2 ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
offsorter.push_back( make_pair( (*iter2).second.second, *iter2 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::sort(offsorter.begin(), offsorter.end(), compare_pair_first<>());
|
|
|
|
for(int idx = 0; idx < offsorter.size();idx++)
|
|
|
|
{
|
|
|
|
terrible & h = offsorter[idx];
|
|
|
|
ss << i << "<Offset name=\"" << h.second.first << "\"";
|
|
|
|
if(h.second.second.first)
|
|
|
|
ss << " value=\"" << hex << "0x" << h.first << "\"";
|
|
|
|
if(h.second.second.first == IS_INVALID)
|
|
|
|
ss << " valid=\"false\"";
|
|
|
|
ss << " />";
|
|
|
|
if(h.second.second.first == NOT_SET)
|
|
|
|
ss << " NOT SET!";
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << endl;
|
2010-08-27 22:31:44 -06:00
|
|
|
}
|
2011-03-24 19:31:27 -06:00
|
|
|
|
2010-08-27 22:31:44 -06:00
|
|
|
for(iter = OGd->hexvals.begin(); iter != OGd->hexvals.end(); iter++)
|
|
|
|
{
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << i << "<HexValue name=\"" << (*iter).first << "\"";
|
2010-08-27 22:31:44 -06:00
|
|
|
if((*iter).second.first)
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << " value=\"" << hex << "0x" << (*iter).second.second << "\"";
|
|
|
|
ss << " />";
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter).second.first == IS_INVALID)
|
|
|
|
ss << " INVALID!";
|
2010-08-28 06:06:18 -06:00
|
|
|
if(!(*iter).second.first)
|
|
|
|
ss << " MISSING!";
|
|
|
|
ss << endl;
|
2010-08-27 22:31:44 -06:00
|
|
|
}
|
|
|
|
strings_Iter iter3;
|
|
|
|
for(iter3 = OGd->strings.begin(); iter3 != OGd->strings.end(); iter3++)
|
|
|
|
{
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << i << "<HexValue name=\"" << (*iter3).first << "\"";
|
2010-08-27 22:31:44 -06:00
|
|
|
if((*iter3).second.first)
|
2010-08-28 06:06:18 -06:00
|
|
|
ss << " value=\"" << (*iter3).second.second << "\"";
|
|
|
|
ss << " />";
|
2010-11-07 16:10:59 -07:00
|
|
|
if((*iter3).second.first == IS_INVALID)
|
|
|
|
ss << " INVALID!";
|
2010-08-28 06:06:18 -06:00
|
|
|
if(!(*iter3).second.first)
|
|
|
|
ss << " MISSING!";
|
|
|
|
ss << endl;
|
2010-08-27 22:31:44 -06:00
|
|
|
}
|
|
|
|
groups_Iter iter4;
|
|
|
|
for(iter4 = OGd->groups.begin(); iter4 != OGd->groups.end(); iter4++)
|
|
|
|
{
|
2010-08-28 04:47:33 -06:00
|
|
|
ss << i << "<Group name=\"" << (*iter4).first << "\">" << endl;
|
|
|
|
i.indent();
|
|
|
|
ss <<(*iter4).second->PrintOffsets(i.get());
|
|
|
|
i.unindent();
|
|
|
|
ss << i << "</Group>" << endl;
|
2010-08-27 22:31:44 -06:00
|
|
|
}
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2010-11-07 16:10:59 -07:00
|
|
|
// the big ugly method behind the curtain...
|
|
|
|
void OffsetGroup::setInvalid(INVAL_TYPE invalidity)
|
|
|
|
{
|
|
|
|
if(invalidity == NOT_SET)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint32_Iter iter;
|
|
|
|
for(iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++)
|
|
|
|
{
|
|
|
|
if((*iter).second.first)
|
|
|
|
(*iter).second.first = invalidity;
|
|
|
|
}
|
|
|
|
int32_Iter iter2;
|
|
|
|
for(iter2 = OGd->offsets.begin(); iter2 != OGd->offsets.end(); iter2++)
|
|
|
|
{
|
|
|
|
if((*iter2).second.first)
|
|
|
|
(*iter2).second.first = invalidity;
|
|
|
|
}
|
|
|
|
for(iter = OGd->hexvals.begin(); iter != OGd->hexvals.end(); iter++)
|
|
|
|
{
|
|
|
|
if((*iter).second.first)
|
|
|
|
(*iter).second.first = invalidity;
|
|
|
|
}
|
|
|
|
strings_Iter iter3;
|
|
|
|
for(iter3 = OGd->strings.begin(); iter3 != OGd->strings.end(); iter3++)
|
|
|
|
{
|
|
|
|
if((*iter3).second.first)
|
|
|
|
(*iter3).second.first = invalidity;
|
|
|
|
}
|
|
|
|
groups_Iter iter4;
|
|
|
|
for(iter4 = OGd->groups.begin(); iter4 != OGd->groups.end(); iter4++)
|
|
|
|
{
|
|
|
|
(*iter4).second->setInvalid(invalidity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-22 15:34:20 -07:00
|
|
|
/*
|
|
|
|
* Private data
|
|
|
|
*/
|
2010-08-23 11:28:53 -06:00
|
|
|
namespace DFHack
|
2010-02-22 15:34:20 -07:00
|
|
|
{
|
2010-08-23 11:28:53 -06:00
|
|
|
class VersionInfoPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
vector<string> professions;
|
|
|
|
vector<string> jobs;
|
|
|
|
vector<string> skills;
|
|
|
|
vector<DFHack::t_level> levels;
|
|
|
|
vector< vector<string> > traits;
|
|
|
|
vector<string> moods;
|
|
|
|
map <uint32_t, string> labors;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
// storage for class and multiclass
|
|
|
|
vector<t_class *> classes;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
// cache for faster name lookup, indexed by classID
|
|
|
|
vector<string> classnames;
|
|
|
|
// map between vptr and class id, needs further type id lookup for multi-classes, not inherited
|
|
|
|
map<uint32_t, t_class *> classIDs;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
// index for the next added class
|
|
|
|
uint32_t classindex;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
int32_t base;
|
|
|
|
Process * p; // the process this belongs to
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-08-23 11:28:53 -06:00
|
|
|
string version;
|
2011-02-08 14:55:40 -07:00
|
|
|
OSType OS;
|
2010-08-23 11:28:53 -06:00
|
|
|
std::string md5;
|
2011-03-30 21:39:12 -06:00
|
|
|
bool has_md5;
|
2010-08-23 11:28:53 -06:00
|
|
|
uint32_t PE_timestamp;
|
2011-03-30 21:39:12 -06:00
|
|
|
bool has_timestamp;
|
2010-08-23 11:28:53 -06:00
|
|
|
};
|
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
// normal constructor
|
2010-08-20 06:10:05 -06:00
|
|
|
VersionInfo::VersionInfo()
|
2010-08-23 11:28:53 -06:00
|
|
|
:d(new VersionInfoPrivate)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->base = 0;
|
2010-04-18 13:30:02 -06:00
|
|
|
d->p = 0;
|
2010-02-22 15:34:20 -07:00
|
|
|
d->classindex = 0;
|
2010-08-20 06:10:05 -06:00
|
|
|
d->levels.reserve(NUM_RESERVE_LVLS);
|
|
|
|
d->moods.reserve(NUM_RESERVE_MOODS);
|
2011-03-30 21:39:12 -06:00
|
|
|
d->has_md5 = false;
|
|
|
|
d->has_timestamp = false;
|
2010-08-27 22:31:44 -06:00
|
|
|
OffsetGroup();
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
// copy constructor
|
2010-08-20 06:10:05 -06:00
|
|
|
VersionInfo::VersionInfo(const VersionInfo &old)
|
2010-08-23 11:28:53 -06:00
|
|
|
:d(new VersionInfoPrivate)
|
2010-02-25 05:41:57 -07:00
|
|
|
{
|
2010-08-22 17:29:55 -06:00
|
|
|
copy(&old);
|
|
|
|
}
|
|
|
|
|
2010-08-27 19:57:56 -06:00
|
|
|
void OffsetGroup::copy(const OffsetGroup * old)
|
|
|
|
{
|
|
|
|
OGd->addresses = old->OGd->addresses;
|
|
|
|
OGd->offsets = old->OGd->offsets;
|
|
|
|
OGd->hexvals = old->OGd->hexvals;
|
|
|
|
OGd->strings = old->OGd->strings;
|
|
|
|
for(groups_Iter it = old->OGd->groups.begin(); it != old->OGd->groups.end(); it++)
|
|
|
|
{
|
2010-08-27 22:31:44 -06:00
|
|
|
OffsetGroup * ogn = new OffsetGroup((*it).first, this);
|
2010-08-27 19:57:56 -06:00
|
|
|
ogn->copy((*it).second);
|
|
|
|
OGd->groups[(*it).first] = ogn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-22 17:29:55 -06:00
|
|
|
void VersionInfo::copy(const VersionInfo * old)
|
|
|
|
{
|
|
|
|
d->version = old->d->version;
|
|
|
|
d->OS = old->d->OS;
|
|
|
|
d->md5 = old->d->md5;
|
2011-03-30 21:39:12 -06:00
|
|
|
d->has_md5 = old->d->has_md5;
|
2010-08-22 17:29:55 -06:00
|
|
|
d->PE_timestamp = old->d->PE_timestamp;
|
2011-03-30 21:39:12 -06:00
|
|
|
d->has_timestamp = old->d->has_timestamp;
|
2010-08-22 17:29:55 -06:00
|
|
|
d->base = old->d->base;
|
2010-02-25 09:37:40 -07:00
|
|
|
//d->classes = old.d->classes;
|
2010-08-22 17:29:55 -06:00
|
|
|
for(uint32_t i = 0; i < old->d->classes.size(); i++)
|
2010-02-25 09:37:40 -07:00
|
|
|
{
|
2010-08-22 17:29:55 -06:00
|
|
|
t_class * copy = new t_class(*old->d->classes[i]);
|
2010-02-25 09:37:40 -07:00
|
|
|
d->classes.push_back(copy);
|
|
|
|
}
|
2010-08-22 17:29:55 -06:00
|
|
|
d->classnames = old->d->classnames;
|
|
|
|
d->classindex = old->d->classindex;
|
|
|
|
d->professions = old->d->professions;
|
|
|
|
d->jobs = old->d->jobs;
|
|
|
|
d->skills = old->d->skills;
|
|
|
|
d->traits = old->d->traits;
|
|
|
|
d->labors = old->d->labors;
|
|
|
|
d->levels = old->d->levels;
|
|
|
|
d->moods = old->d->moods;
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup::copy(reinterpret_cast<const OffsetGroup *>(old));
|
2010-02-25 05:41:57 -07:00
|
|
|
}
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setParentProcess(Process * _p)
|
2010-04-18 13:30:02 -06:00
|
|
|
{
|
|
|
|
d->p = _p;
|
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
// destructor
|
2010-08-20 06:10:05 -06:00
|
|
|
VersionInfo::~VersionInfo()
|
2010-02-25 05:41:57 -07:00
|
|
|
{
|
|
|
|
// delete the vtables
|
2010-02-25 09:37:40 -07:00
|
|
|
for(uint32_t i = 0; i < d->classes.size();i++)
|
2010-02-25 05:41:57 -07:00
|
|
|
{
|
|
|
|
delete d->classes[i];
|
|
|
|
}
|
|
|
|
// delete our data
|
|
|
|
delete d;
|
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setVersion(const char * v)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->version = v;
|
2011-03-03 15:54:44 -07:00
|
|
|
OGd->name = v;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setVersion(const string &v)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->version = v;
|
2011-03-03 15:54:44 -07:00
|
|
|
OGd->name = v;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
string VersionInfo::getVersion()
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->version;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
2010-08-22 17:29:55 -06:00
|
|
|
void VersionInfo::setMD5(const string &v)
|
|
|
|
{
|
|
|
|
d->md5 = v;
|
2011-03-30 21:39:12 -06:00
|
|
|
d->has_md5 = true;
|
2010-08-22 17:29:55 -06:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:39:12 -06:00
|
|
|
bool VersionInfo::getMD5( string & output )
|
2010-08-22 17:29:55 -06:00
|
|
|
{
|
2011-03-30 21:39:12 -06:00
|
|
|
if(!d->has_md5) return false;
|
|
|
|
output = d->md5;
|
|
|
|
return true;
|
2010-08-22 17:29:55 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void VersionInfo::setPE(uint32_t v)
|
|
|
|
{
|
|
|
|
d->PE_timestamp = v;
|
2011-03-30 21:39:12 -06:00
|
|
|
d->has_timestamp = true;
|
2010-08-22 17:29:55 -06:00
|
|
|
}
|
|
|
|
|
2011-03-30 21:39:12 -06:00
|
|
|
bool VersionInfo::getPE(uint32_t & output)
|
2010-08-22 17:29:55 -06:00
|
|
|
{
|
2011-03-30 21:39:12 -06:00
|
|
|
if(!d->has_timestamp) return false;
|
|
|
|
output = d->PE_timestamp;
|
|
|
|
return true;
|
2010-08-22 17:29:55 -06:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setOS(const char *os)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
string oss = os;
|
|
|
|
if(oss == "windows")
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_WINDOWS;
|
2009-09-13 18:02:46 -06:00
|
|
|
else if(oss == "linux")
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_LINUX;
|
2010-08-22 17:29:55 -06:00
|
|
|
else if(oss == "apple")
|
|
|
|
d->OS = OS_APPLE;
|
2009-09-13 18:02:46 -06:00
|
|
|
else
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_BAD;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setOS(const string &os)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
if(os == "windows")
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_WINDOWS;
|
2009-09-13 18:02:46 -06:00
|
|
|
else if(os == "linux")
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_LINUX;
|
2010-08-22 17:29:55 -06:00
|
|
|
else if(os == "apple")
|
|
|
|
d->OS = OS_APPLE;
|
2009-09-13 18:02:46 -06:00
|
|
|
else
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_BAD;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setOS(OSType os)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
|
|
|
if(os >= OS_WINDOWS && os < OS_BAD)
|
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = os;
|
2009-09-13 18:02:46 -06:00
|
|
|
return;
|
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
d->OS = OS_BAD;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-08 14:55:40 -07:00
|
|
|
OSType VersionInfo::getOS() const
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->OS;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
uint32_t VersionInfo::getBase () const
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->base;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setBase (const string &s)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->base = strtol(s.c_str(), NULL, 16);
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setBase (const uint32_t b)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->base = b;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setLabor(const string & key, const string & value)
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
|
|
|
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
|
2010-02-22 15:34:20 -07:00
|
|
|
d->labors[keyInt] = value;
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2009-11-13 20:46:56 -07:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setProfession (const string & key, const string & value)
|
2009-11-07 14:05:10 -07:00
|
|
|
{
|
2009-11-09 16:18:20 -07:00
|
|
|
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->professions.size() <= keyInt)
|
2009-11-13 20:46:56 -07:00
|
|
|
{
|
2010-04-24 08:36:41 -06:00
|
|
|
d->professions.resize(keyInt+1,"");
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
d->professions[keyInt] = value;
|
2009-11-07 14:05:10 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setJob (const string & key, const string & value)
|
2009-11-07 14:05:10 -07:00
|
|
|
{
|
2009-11-09 16:18:20 -07:00
|
|
|
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->jobs.size() <= keyInt)
|
2009-11-13 20:46:56 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->jobs.resize(keyInt+1);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
d->jobs[keyInt] = value;
|
2009-11-07 14:05:10 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setSkill (const string & key, const string & value)
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
|
|
|
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->skills.size() <= keyInt){
|
|
|
|
d->skills.resize(keyInt+1);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
d->skills[keyInt] = value;
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setLevel(const std::string &nLevel,
|
|
|
|
const std::string &nName,
|
|
|
|
const std::string &nXp)
|
2010-06-10 09:53:25 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
uint32_t keyInt = strtol(nLevel.c_str(), NULL, 10);
|
|
|
|
|
|
|
|
if(d->levels.size() <= keyInt)
|
|
|
|
d->levels.resize(keyInt+1);
|
|
|
|
|
|
|
|
d->levels[keyInt].level = keyInt;
|
|
|
|
d->levels[keyInt].name = nName;
|
|
|
|
d->levels[keyInt].xpNxtLvl = strtol(nXp.c_str(), NULL, 10);
|
2010-06-10 09:53:25 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setMood(const std::string &id, const std::string &mood)
|
2010-06-17 18:17:19 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
uint32_t keyInt = strtol(id.c_str(), NULL, 10);
|
|
|
|
|
|
|
|
if(d->moods.size() <= keyInt)
|
|
|
|
d->moods.resize(keyInt+1);
|
2010-06-17 18:17:19 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
d->moods[keyInt] = mood;
|
2010-06-17 18:17:19 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
void VersionInfo::setTrait(const string & key,
|
2009-11-22 07:43:53 -07:00
|
|
|
const string & value,
|
|
|
|
const string & zero,
|
|
|
|
const string & one,
|
|
|
|
const string & two,
|
|
|
|
const string & three,
|
|
|
|
const string & four,
|
|
|
|
const string & five)
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
2009-11-13 20:46:56 -07:00
|
|
|
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->traits.size() <= keyInt)
|
2009-11-13 20:46:56 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
d->traits.resize(keyInt+1);
|
2009-11-13 20:46:56 -07:00
|
|
|
}
|
2010-02-22 15:34:20 -07:00
|
|
|
d->traits[keyInt].push_back(zero);
|
|
|
|
d->traits[keyInt].push_back(one);
|
|
|
|
d->traits[keyInt].push_back(two);
|
|
|
|
d->traits[keyInt].push_back(three);
|
|
|
|
d->traits[keyInt].push_back(four);
|
|
|
|
d->traits[keyInt].push_back(five);
|
|
|
|
d->traits[keyInt].push_back(value);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2009-09-13 18:02:46 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
// FIXME: next three methods should use some kind of custom container so it doesn't have to search so much.
|
2010-08-20 06:10:05 -06:00
|
|
|
t_class * VersionInfo::setClass (const char * name, uint32_t vtable, uint32_t typeoffset)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
if(name == 0)
|
|
|
|
return 0;
|
2010-02-22 15:34:20 -07:00
|
|
|
for (uint32_t i=0; i<d->classes.size(); i++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
if(d->classes[i]->classname == name)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
if(vtable != 0)
|
|
|
|
d->classes[i]->vtable = vtable;
|
|
|
|
if(typeoffset != 0)
|
|
|
|
d->classes[i]->type_offset = typeoffset;
|
|
|
|
return d->classes[i];
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
t_class *cls = new t_class();
|
|
|
|
// get an unique ID and add ourselves to the index
|
|
|
|
cls->assign = d->classindex;
|
|
|
|
cls->classname = name;
|
|
|
|
d->classnames.push_back(name);
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
// vtables no longer a requirement
|
|
|
|
cls->vtable = vtable;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
// multi class yes/no
|
|
|
|
cls->type_offset = typeoffset;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-22 15:34:20 -07:00
|
|
|
d->classes.push_back(cls);
|
|
|
|
d->classindex++;
|
2010-02-25 05:41:57 -07:00
|
|
|
return cls;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::setClassChild (t_class * parent, const char * name, const char * type)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
vector <t_type *>& vec = parent->subs;
|
2009-09-13 18:02:46 -06:00
|
|
|
for (uint32_t i=0; i<vec.size(); i++)
|
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
if(vec[i]->classname == name)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
vec[i]->type = strtol(type, NULL, 16);
|
2009-09-13 18:02:46 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// new multiclass child
|
2010-02-25 05:41:57 -07:00
|
|
|
t_type *mcc = new t_type(d->classindex,strtol(type, NULL, 16),name);
|
|
|
|
d->classnames.push_back(name);
|
2009-09-13 18:02:46 -06:00
|
|
|
vec.push_back(mcc);
|
2010-02-22 15:34:20 -07:00
|
|
|
d->classindex++;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-25 06:59:29 -07:00
|
|
|
//cout << " classtype " << name << ", assign " << mcc->assign << ", vtable " << mcc->type << endl;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-03-14 15:58:28 -06:00
|
|
|
// FIXME: stupid. we need a better container
|
2010-08-20 06:10:05 -06:00
|
|
|
bool VersionInfo::resolveObjectToClassID(const uint32_t address, int32_t & classid)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-04-18 13:30:02 -06:00
|
|
|
uint32_t vtable = d->p->readDWord(address);
|
2010-03-14 15:58:28 -06:00
|
|
|
// try to find the vtable in our cache
|
|
|
|
map<uint32_t, t_class *>::iterator it;
|
|
|
|
it = d->classIDs.find(vtable);
|
|
|
|
t_class * cl;
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-03-14 15:58:28 -06:00
|
|
|
// class found in cache?
|
|
|
|
if(it != d->classIDs.end())
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-03-14 15:58:28 -06:00
|
|
|
cl = (*it).second;
|
|
|
|
}
|
|
|
|
else// couldn't find?
|
|
|
|
{
|
|
|
|
// we set up the class for the first time
|
2010-04-18 13:30:02 -06:00
|
|
|
string classname = d->p->readClassName(vtable);
|
2010-03-14 15:58:28 -06:00
|
|
|
d->classIDs[vtable] = cl = setClass(classname.c_str(),vtable);
|
|
|
|
}
|
|
|
|
// and isn't a multi-class
|
|
|
|
if(!cl->type_offset)
|
|
|
|
{
|
|
|
|
// return
|
|
|
|
classid = cl->assign;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// and is a multiclass
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// find the type
|
|
|
|
vector <t_type*>& vec = cl->subs;
|
2010-04-18 13:30:02 -06:00
|
|
|
uint32_t type = d->p->readWord(address + cl->type_offset);
|
2010-03-14 15:58:28 -06:00
|
|
|
// return typed building if successful
|
|
|
|
//FIXME: the vector should map directly to the type IDs here, so we don't have to mess with O(n) search
|
|
|
|
for (uint32_t k = 0; k < vec.size();k++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-03-14 15:58:28 -06:00
|
|
|
if(vec[k]->type == type)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-03-14 15:58:28 -06:00
|
|
|
//cout << " multi " << address + classes[i].type_offset << " " << vec[k].classname << endl;
|
|
|
|
classid = vec[k]->assign;
|
|
|
|
return true;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
2010-03-14 15:58:28 -06:00
|
|
|
// couldn't find the type... now what do we do here? throw?
|
|
|
|
// this is a case where it might be a good idea, because it uncovers some deeper problems
|
|
|
|
// we return the parent class instead, it doesn't change the API semantics and sort-of makes sense
|
|
|
|
classid = cl->assign;
|
|
|
|
return true;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2010-02-20 21:51:29 -07:00
|
|
|
//ALERT: doesn't care about multiclasses
|
2010-08-20 06:10:05 -06:00
|
|
|
bool VersionInfo::resolveClassnameToVPtr(const string classname, uint32_t & vptr)
|
2010-02-20 21:51:29 -07:00
|
|
|
{
|
|
|
|
// FIXME: another stupid search.
|
2010-02-22 15:34:20 -07:00
|
|
|
for(uint32_t i = 0;i< d->classes.size();i++)
|
2010-02-20 21:51:29 -07:00
|
|
|
{
|
|
|
|
//if(classes[i].)
|
2010-02-25 05:41:57 -07:00
|
|
|
if(d->classes[i]->classname == classname) // got class
|
2010-02-20 21:51:29 -07:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
vptr = d->classes[i]->vtable;
|
|
|
|
return true;
|
2010-02-20 21:51:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// we failed to find anything that would match
|
2010-02-25 05:41:57 -07:00
|
|
|
return false;
|
2010-02-20 21:51:29 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
bool VersionInfo::resolveClassnameToClassID (const string classname, int32_t & classID)
|
2010-04-12 16:03:29 -06:00
|
|
|
{
|
|
|
|
// FIXME: another stupid search.
|
|
|
|
classID = -1;
|
|
|
|
for(uint32_t i = 0;i< d->classnames.size();i++)
|
|
|
|
{
|
|
|
|
if(d->classnames[i] == classname)
|
|
|
|
{
|
|
|
|
classID = i;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// we failed to find anything that would match
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
bool VersionInfo::resolveClassIDToClassname (const int32_t classID, string & classname)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-04-09 19:49:37 -06:00
|
|
|
if (classID >=0 && (uint32_t)classID < d->classnames.size())
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
classname = d->classnames[classID];
|
|
|
|
return true;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return pointer to our internal classID -> className mapping
|
2010-08-20 06:10:05 -06:00
|
|
|
const vector<string> * VersionInfo::getClassIDMapping()
|
2010-02-25 05:41:57 -07:00
|
|
|
{
|
|
|
|
return &d->classnames;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 21:25:00 -07:00
|
|
|
// change base of all addresses
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::RebaseAddresses(const int32_t new_base)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-08-27 19:57:56 -06:00
|
|
|
OffsetGroup::RebaseAddresses(- (int32_t)d->base + new_base);
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-14 21:25:00 -07:00
|
|
|
// change base of all addresses *and* vtable entries
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::RebaseAll(int32_t new_base)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-08-22 17:29:55 -06:00
|
|
|
RebaseAddresses(new_base);
|
2010-02-22 15:34:20 -07:00
|
|
|
int32_t rebase = - (int32_t)d->base + new_base;
|
2009-09-13 18:02:46 -06:00
|
|
|
RebaseVTable(rebase);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// change all vtable entries by offset
|
2010-08-20 06:10:05 -06:00
|
|
|
void VersionInfo::RebaseVTable(int32_t offset)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
vector<t_class *>::iterator iter;
|
2010-02-22 15:34:20 -07:00
|
|
|
for(iter = d->classes.begin(); iter != d->classes.end(); iter++)
|
2009-09-13 18:02:46 -06:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
(*iter)->vtable += offset;
|
2009-09-13 18:02:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2009-11-07 14:05:10 -07:00
|
|
|
// Get Profession
|
2010-08-20 06:10:05 -06:00
|
|
|
string VersionInfo::getProfession (const uint32_t key) const
|
2009-11-07 14:05:10 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->professions.size() > key)
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->professions[key];
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("profession", key);
|
2009-11-07 14:05:10 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2009-11-07 14:05:10 -07:00
|
|
|
// Get Job
|
2010-08-20 06:10:05 -06:00
|
|
|
string VersionInfo::getJob (const uint32_t key) const
|
2009-11-07 14:05:10 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->jobs.size() > key)
|
2010-06-22 20:32:33 -06:00
|
|
|
|
2009-11-22 07:43:53 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->jobs[key];
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("job", key);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
string VersionInfo::getSkill (const uint32_t key) const
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->skills.size() > key)
|
2009-11-22 07:43:53 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->skills[key];
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("skill", key);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
DFHack::t_level VersionInfo::getLevelInfo(const uint32_t level) const
|
2010-06-10 09:53:25 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
if(d->levels.size() > level)
|
2010-06-10 09:53:25 -06:00
|
|
|
{
|
|
|
|
return d->levels[level];
|
|
|
|
}
|
|
|
|
throw Error::MissingMemoryDefinition("Level", level);
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
2009-11-13 06:35:44 -07:00
|
|
|
// FIXME: ugly hack that needs to die
|
|
|
|
int absolute (int number)
|
|
|
|
{
|
|
|
|
if (number < 0)
|
|
|
|
return -number;
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
string VersionInfo::getTrait (const uint32_t traitIdx, const uint32_t traitValue) const
|
2009-11-13 06:35:44 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->traits.size() > traitIdx)
|
2009-11-13 06:35:44 -07:00
|
|
|
{
|
|
|
|
int diff = absolute(traitValue-50);
|
|
|
|
if(diff < 10)
|
|
|
|
{
|
|
|
|
return string("");
|
|
|
|
}
|
|
|
|
if (traitValue >= 91)
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][5];
|
2009-11-13 06:35:44 -07:00
|
|
|
else if (traitValue >= 76)
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][4];
|
2009-11-13 06:35:44 -07:00
|
|
|
else if (traitValue >= 61)
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][3];
|
2009-11-13 06:35:44 -07:00
|
|
|
else if (traitValue >= 25)
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][2];
|
2009-11-13 06:35:44 -07:00
|
|
|
else if (traitValue >= 10)
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][1];
|
2009-11-13 06:35:44 -07:00
|
|
|
else
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][0];
|
2009-11-13 06:35:44 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("trait", traitIdx);
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
string VersionInfo::getTraitName(const uint32_t traitIdx) const
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->traits.size() > traitIdx)
|
2009-11-13 06:35:44 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->traits[traitIdx][d->traits[traitIdx].size()-1];
|
2009-11-13 06:35:44 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("traitname", traitIdx);
|
2009-11-07 14:05:10 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
std::vector< std::vector<std::string> > const& VersionInfo::getAllTraits()
|
2010-06-16 13:47:05 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
return d->traits;
|
2010-06-16 13:47:05 -06:00
|
|
|
}
|
|
|
|
|
2010-08-23 08:16:58 -06:00
|
|
|
std:: map<uint32_t, std::string> const& VersionInfo::getAllLabours()
|
2010-08-10 15:28:53 -06:00
|
|
|
{
|
2010-08-23 08:16:58 -06:00
|
|
|
return d->labors;
|
2010-08-10 15:28:53 -06:00
|
|
|
}
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
string VersionInfo::getLabor (const uint32_t laborIdx)
|
2009-11-09 16:18:20 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
if(d->labors.count(laborIdx))
|
2009-11-13 06:35:44 -07:00
|
|
|
{
|
2010-02-22 15:34:20 -07:00
|
|
|
return d->labors[laborIdx];
|
2009-11-09 16:18:20 -07:00
|
|
|
}
|
2010-02-27 19:34:54 -07:00
|
|
|
throw Error::MissingMemoryDefinition("labor", laborIdx);
|
2010-05-01 18:38:18 -06:00
|
|
|
}
|
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
|
|
|
|
std::string VersionInfo::getMood(const uint32_t moodID)
|
2010-06-17 18:17:19 -06:00
|
|
|
{
|
2010-08-20 06:10:05 -06:00
|
|
|
if(d->moods.size() > moodID)
|
|
|
|
{
|
|
|
|
return d->moods[moodID];
|
|
|
|
}
|
|
|
|
throw Error::MissingMemoryDefinition("Mood", moodID);
|
2010-06-17 18:17:19 -06:00
|
|
|
}
|
2010-06-19 18:50:37 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
std::string VersionInfo::PrintOffsets()
|
2010-06-19 18:50:37 -06:00
|
|
|
{
|
|
|
|
ostringstream ss;
|
2011-03-30 21:39:12 -06:00
|
|
|
string md5;
|
|
|
|
uint32_t PE;
|
2010-08-28 04:47:33 -06:00
|
|
|
indentr i;
|
|
|
|
ss << i << "<Version name=\"" << getVersion() << "\">" << endl;
|
|
|
|
i.indent();
|
2010-06-20 11:20:10 -06:00
|
|
|
switch (getOS())
|
|
|
|
{
|
|
|
|
case OS_WINDOWS:
|
2011-03-30 21:39:12 -06:00
|
|
|
if(getPE(PE))
|
|
|
|
ss << i << "<PETimeStamp value=\"" << hex << "0x" << PE << "\" />" << endl;
|
|
|
|
case OS_LINUX:
|
|
|
|
if(getMD5(md5))
|
|
|
|
ss << i << "<MD5 value=\"" << md5 << "\" />" << endl;
|
2010-06-20 11:20:10 -06:00
|
|
|
break;
|
|
|
|
default:
|
2010-08-28 04:47:33 -06:00
|
|
|
ss << i << " UNKNOWN" << endl;
|
2010-06-20 11:20:10 -06:00
|
|
|
}
|
2010-08-28 04:47:33 -06:00
|
|
|
ss << i << "<Offsets>" << endl;
|
|
|
|
i.indent();
|
|
|
|
ss << OffsetGroup::PrintOffsets(i.get());
|
|
|
|
i.unindent();
|
|
|
|
ss << i << "</Offsets>" << endl;
|
|
|
|
i.unindent();
|
|
|
|
ss << i << "</Version>" << endl;
|
|
|
|
ss << endl;
|
2010-06-19 18:50:37 -06:00
|
|
|
return ss.str();
|
|
|
|
}
|