dfhack/library/include/VersionInfo.h

222 lines
7.6 KiB
C

/*
https://github.com/peterix/dfhack
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
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.
*/
#pragma once
#ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED
2011-12-31 04:48:42 -07:00
#include "Pragma.h"
#include "Export.h"
#include "Types.h"
#include <map>
2010-08-22 17:29:55 -06:00
#include <sys/types.h>
#include <vector>
2010-06-10 09:53:25 -06:00
2009-11-13 20:46:56 -07:00
namespace DFHack
{
2010-04-18 13:30:02 -06:00
/*
* Stubs
*/
class Process;
2010-08-28 04:47:33 -06:00
class XMLPP;
2010-06-04 16:02:02 -06:00
struct t_class;
2010-08-22 17:29:55 -06:00
class VersionInfoPrivate;
class OffsetGroupPrivate;
2010-11-07 16:10:59 -07:00
enum INVAL_TYPE
{
NOT_SET,
IS_INVALID,
IS_VALID
};
enum KEY_TYPE
{
IS_OFFSET,
IS_ADDRESS,
IS_HEX_VAL,
IS_STRING,
IS_GROUP
};
struct OffsetKey
{
std::string key;
INVAL_TYPE inval;
KEY_TYPE keytype;
};
/*
* Offset Group
*/
2010-08-22 17:29:55 -06:00
class DFHACK_EXPORT OffsetGroup
{
2010-08-23 11:28:53 -06:00
protected:
OffsetGroupPrivate * OGd;
2010-08-22 17:29:55 -06:00
public:
OffsetGroup();
OffsetGroup(const std::string & _name, OffsetGroup * parent = 0);
~OffsetGroup();
void copy(const OffsetGroup * old); // recursive
void RebaseAddresses( int32_t offset ); // recursive
void createOffset (const std::string & key);
void createAddress (const std::string & key);
void createHexValue (const std::string & key);
void createString (const std::string & key);
OffsetGroup * createGroup ( const std::string & name );
int32_t getOffset (const std::string & key);
uint32_t getAddress (const std::string & key);
uint32_t getHexValue (const std::string & key);
std::string getString (const std::string & key);
OffsetGroup * getGroup ( const std::string & name );
bool getSafeOffset (const std::string & key, int32_t & out);
bool getSafeAddress (const std::string & key, uint32_t & out);
2010-11-07 16:10:59 -07:00
void setOffset (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-16 20:48:06 -07:00
void setOffsetValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-07 16:10:59 -07:00
void setAddress (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-16 20:48:06 -07:00
void setAddressValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-07 16:10:59 -07:00
void setHexValue (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-16 20:48:06 -07:00
void setHexValueValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-07 16:10:59 -07:00
void setString (const std::string& key, const std::string& value, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-11-16 20:48:06 -07:00
void setStringValidity(const std::string& key, const DFHack::INVAL_TYPE inval = IS_VALID);
2010-08-28 04:47:33 -06:00
std::string PrintOffsets(int indentation);
std::string getName();
std::string getFullName();
OffsetGroup * getParent();
2010-11-07 16:10:59 -07:00
void setInvalid(INVAL_TYPE arg1);
std::vector<OffsetKey> getKeys() const;
2010-08-22 17:29:55 -06:00
};
/*
* Version Info
*/
2011-02-08 14:55:40 -07:00
enum OSType
{
OS_WINDOWS,
OS_LINUX,
OS_APPLE,
OS_BAD
};
2010-08-23 11:28:53 -06:00
class DFHACK_EXPORT VersionInfo : public OffsetGroup
{
private:
2010-08-22 17:29:55 -06:00
VersionInfoPrivate * d;
2009-11-13 20:46:56 -07:00
public:
VersionInfo();
VersionInfo(const VersionInfo&);
2010-08-22 17:29:55 -06:00
void copy(const DFHack::VersionInfo* old);
~VersionInfo();
2009-11-13 20:46:56 -07:00
2009-11-22 07:43:53 -07:00
void RebaseAddresses(const int32_t new_base);
void RebaseAll(const int32_t new_base);
uint32_t getBase () const;
2010-05-25 22:48:23 -06:00
void setBase (const std::string&);
2009-11-22 07:43:53 -07:00
void setBase (const uint32_t);
2010-08-22 17:29:55 -06:00
void setMD5 (const std::string & _md5);
bool getMD5(std::string & output);
2010-08-22 17:29:55 -06:00
void setPE (uint32_t PE_);
bool getPE(uint32_t & output);
2010-08-22 17:29:55 -06:00
std::string getMood(const uint32_t moodID);
2010-05-25 22:48:23 -06:00
std::string getString (const std::string&);
std::string getProfession(const uint32_t) const;
std::string getJob(const uint32_t) const;
std::string getSkill (const uint32_t) const;
std::string getTrait (const uint32_t, const uint32_t) const;
std::string getTraitName(const uint32_t) const;
std::string getLabor (const uint32_t);
std::vector< std::vector<std::string> > const& getAllTraits();
std::map<uint32_t, std::string> const& getAllLabours();
2009-11-13 20:46:56 -07:00
DFHack::t_level getLevelInfo(const uint32_t level) const;
2010-06-10 09:53:25 -06:00
2009-11-13 20:46:56 -07:00
void setVersion(const char *);
2010-05-25 22:48:23 -06:00
void setVersion(const std::string&);
std::string getVersion();
2009-11-13 20:46:56 -07:00
void setOS(const char *);
2010-05-25 22:48:23 -06:00
void setOS(const std::string&);
2009-11-22 07:43:53 -07:00
void setOS(const OSType);
OSType getOS() const;
2010-08-22 17:29:55 -06:00
void setProfession(const std::string & id, const std::string & name);
2010-05-25 22:48:23 -06:00
void setJob(const std::string &, const std::string &);
void setSkill(const std::string &, const std::string &);
2010-06-10 09:53:25 -06:00
void setTrait(const std::string &, const std::string &, const std::string &,
const std::string &, const std::string &,
const std::string &, const std::string &, const std::string &);
2010-05-25 22:48:23 -06:00
void setLabor(const std::string &, const std::string &);
void setLevel(const std::string &nLevel, const std::string &nName,
const std::string &nXp);
void setMood(const std::string &id, const std::string &mood);
2009-11-22 07:43:53 -07:00
void RebaseVTable(const int32_t offset);
2010-04-18 13:30:02 -06:00
void setParentProcess(Process * _p);
t_class * setClass (const char * classname, uint32_t vptr = 0, uint32_t typeoffset = 0);
void setClassChild (t_class * parent, const char * classname, const char * type);
/**
* Get a classID from an address. The address has to point to the start of a virtual object (one with a virtual base class)
* uses memory reading directly, needs suspend. input = address of the object
* fails if it's unable to read from memory
*/
bool resolveObjectToClassID (const uint32_t address, int32_t & classID);
/**
2010-04-12 16:03:29 -06:00
* Get a ClassID when you know the classname. can fail if the class is not in the cache
*/
2010-05-25 22:48:23 -06:00
bool resolveClassnameToClassID (const std::string classname, int32_t & classID);
/**
* Get a vptr from a classname. Can fail if the type is not in the cache
* limited to normal classes, variable-dependent types will resolve to the base class
*/
bool resolveClassnameToVPtr ( const std::string classname, void * & vptr );
/**
* Get a classname from a previous classID. Can fail if the type is not in the cache (you use bogus classID)
*/
2010-05-25 22:48:23 -06:00
bool resolveClassIDToClassname (const int32_t classID, std::string & classname);
/**
* Get the internal classID->classname mapping (for speed). DO NOT MANIPULATE THE VECTOR!
*/
2010-06-04 16:02:02 -06:00
const std::vector<std::string> * getClassIDMapping();
/**
* Get a string with all addresses and offsets
*/
std::string PrintOffsets();
};
2009-11-13 20:46:56 -07:00
}
#endif // MEMINFO_H_INCLUDED