2010-05-26 04:24:45 -06:00
|
|
|
#include "Internal.h"
|
2011-04-10 02:19:15 -06:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <cstring>
|
|
|
|
using namespace std;
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
#include "private/ContextShared.h"
|
2010-08-20 06:10:05 -06:00
|
|
|
#include "dfhack/VersionInfo.h"
|
2011-06-12 15:17:40 -06:00
|
|
|
#include "dfhack/Process.h"
|
|
|
|
#include "dfhack/Module.h"
|
2010-04-04 16:48:19 -06:00
|
|
|
using namespace DFHack;
|
2010-04-02 19:52:46 -06:00
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
DFContextShared::DFContextShared()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2010-04-04 16:48:19 -06:00
|
|
|
// init modules
|
2010-06-24 23:11:26 -06:00
|
|
|
allModules.clear();
|
|
|
|
memset(&(s_mods), 0, sizeof(s_mods));
|
2011-05-14 16:26:44 -06:00
|
|
|
namesInited = false;
|
|
|
|
namesFailed = false;
|
2010-04-04 16:48:19 -06:00
|
|
|
}
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
DFContextShared::~DFContextShared()
|
2010-04-04 16:48:19 -06:00
|
|
|
{
|
2010-06-24 23:11:26 -06:00
|
|
|
// invalidate all modules
|
2010-11-17 12:50:50 -07:00
|
|
|
for(unsigned int i = 0 ; i < allModules.size(); i++)
|
2010-06-24 23:11:26 -06:00
|
|
|
{
|
|
|
|
delete allModules[i];
|
|
|
|
}
|
|
|
|
allModules.clear();
|
2010-04-02 19:52:46 -06:00
|
|
|
}
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
bool DFContextShared::InitReadNames()
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-05-14 16:26:44 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
OffsetGroup * OG = offset_descriptor->getGroup("name");
|
|
|
|
name_firstname_offset = OG->getOffset("first");
|
|
|
|
name_nickname_offset = OG->getOffset("nick");
|
|
|
|
name_words_offset = OG->getOffset("second_words");
|
|
|
|
name_parts_offset = OG->getOffset("parts_of_speech");
|
|
|
|
name_language_offset = OG->getOffset("language");
|
|
|
|
name_set_offset = OG->getOffset("has_name");
|
|
|
|
}
|
2011-05-14 21:19:51 -06:00
|
|
|
catch(exception &)
|
2011-05-14 16:26:44 -06:00
|
|
|
{
|
|
|
|
namesFailed = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
namesInited = true;
|
2010-04-02 19:52:46 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-26 04:24:45 -06:00
|
|
|
void DFContextShared::readName(t_name & name, uint32_t address)
|
2010-04-02 19:52:46 -06:00
|
|
|
{
|
2011-05-14 16:26:44 -06:00
|
|
|
if(namesFailed)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!namesInited)
|
|
|
|
{
|
|
|
|
if(!InitReadNames()) return;
|
|
|
|
}
|
2010-04-18 13:30:02 -06:00
|
|
|
p->readSTLString(address + name_firstname_offset , name.first_name, 128);
|
|
|
|
p->readSTLString(address + name_nickname_offset , name.nickname, 128);
|
2011-04-13 10:36:10 -06:00
|
|
|
p->read(address + name_words_offset, 7*4, (uint8_t *)name.words);
|
|
|
|
p->read(address + name_parts_offset, 7*2, (uint8_t *)name.parts_of_speech);
|
|
|
|
name.language = p->readDWord(address + name_language_offset);
|
|
|
|
name.has_name = p->readByte(address + name_set_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DFContextShared::copyName(uint32_t address, uint32_t target)
|
|
|
|
{
|
|
|
|
uint8_t buf[28];
|
|
|
|
|
|
|
|
if (address == target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->copySTLString(address + name_firstname_offset, target + name_firstname_offset);
|
|
|
|
p->copySTLString(address + name_nickname_offset, target + name_nickname_offset);
|
|
|
|
p->read(address + name_words_offset, 7*4, buf);
|
|
|
|
p->write(target + name_words_offset, 7*4, buf);
|
|
|
|
p->read(address + name_parts_offset, 7*2, buf);
|
|
|
|
p->write(target + name_parts_offset, 7*2, buf);
|
|
|
|
p->writeDWord(target + name_language_offset, p->readDWord(address + name_language_offset));
|
|
|
|
p->writeByte(target + name_set_offset, p->readByte(address + name_set_offset));
|
2010-04-28 09:40:27 -06:00
|
|
|
}
|