Fixes to memory.xml, name reading

develop
Petr Mrázek 2010-03-08 18:27:19 +01:00
parent b1a15b6fb3
commit 1c499121e6
4 changed files with 134 additions and 172 deletions

@ -8,10 +8,21 @@ using namespace std;
#include <DFTypes.h> #include <DFTypes.h>
#include <DFHackAPI.h> #include <DFHackAPI.h>
#include <stdio.h>
void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords) void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords)
{ {
cout << "First name: " << settlement.name.first_name << endl << "Nickname: " << settlement.name.nickname << endl;
cout << settlement.name.words[0] << " " << settlement.name.words[1] << " " << settlement.name.words[2] << " "
<< settlement.name.words[3] << " " << settlement.name.words[4] << " " << settlement.name.words[5] << " "
<< settlement.name.words[6] << " " << settlement.name.words[7] << endl;
cout << settlement.name.parts_of_speech[0] << " " << settlement.name.parts_of_speech[1] << " " << settlement.name.parts_of_speech[2] << " "
<< settlement.name.parts_of_speech[3] << " " << settlement.name.parts_of_speech[4] << " " << settlement.name.parts_of_speech[5] << " "
<< settlement.name.parts_of_speech[6] << " " << settlement.name.parts_of_speech[7] << endl;
printf("Origin: 0x%x\n",settlement.origin);
string genericName = DF.TranslateName(settlement.name,englishWords,foreignWords,true); string genericName = DF.TranslateName(settlement.name,englishWords,foreignWords,true);
string dwarfName = DF.TranslateName(settlement.name,englishWords,foreignWords,false); string dwarfName = DF.TranslateName(settlement.name,englishWords,foreignWords,false);
cout << dwarfName << " " << genericName << " " << "world x: " << settlement.world_x << " world y: " << settlement.world_y cout << dwarfName << " " << genericName << " " << "world x: " << settlement.world_x << " world y: " << settlement.world_y

@ -38,6 +38,8 @@ public:
{} {}
void readName(t_name & name, uint32_t address); void readName(t_name & name, uint32_t address);
// get the name offsets
bool InitReadNames();
uint32_t * block; uint32_t * block;
uint32_t x_block_count, y_block_count, z_block_count; uint32_t x_block_count, y_block_count, z_block_count;
@ -124,6 +126,7 @@ public:
bool viewSizeInited; bool viewSizeInited;
bool itemsInited; bool itemsInited;
bool notesInited; bool notesInited;
bool namesInited;
bool hotkeyInited; bool hotkeyInited;
bool settlementsInited; bool settlementsInited;
bool nameTablesInited; bool nameTablesInited;
@ -139,6 +142,23 @@ public:
DfVector *p_current_settlement; DfVector *p_current_settlement;
}; };
// FIXME: flesh it out
bool API::Private::InitReadNames()
{
name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname");
name_words_offset = offset_descriptor->getOffset("name_words");
return true;
}
void API::Private::readName(t_name & name, uint32_t address)
{
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128);
g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128);
g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words);
}
API::API (const string path_to_xml) API::API (const string path_to_xml)
: d (new Private()) : d (new Private())
{ {
@ -871,9 +891,7 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
try try
{ {
memory_info * minfo = d->offset_descriptor; memory_info * minfo = d->offset_descriptor;
d->name_firstname_offset = minfo->getOffset("name_firstname"); d->InitReadNames();
d->name_nickname_offset = minfo->getOffset("name_nickname");
d->name_words_offset = minfo->getOffset("name_words");
int creatures = d->offset_descriptor->getAddress ("creatures"); int creatures = d->offset_descriptor->getAddress ("creatures");
d->creature_pos_offset = minfo->getOffset ("creature_position"); d->creature_pos_offset = minfo->getOffset ("creature_position");
d->creature_type_offset = minfo->getOffset ("creature_race"); d->creature_type_offset = minfo->getOffset ("creature_race");
@ -952,6 +970,7 @@ bool API::InitReadSettlements( uint32_t & numsettlements )
{ {
try try
{ {
d->InitReadNames();
memory_info * minfo = d->offset_descriptor; memory_info * minfo = d->offset_descriptor;
int allSettlements = minfo->getAddress ("settlements"); int allSettlements = minfo->getAddress ("settlements");
int currentSettlement = minfo->getAddress("settlement_current"); int currentSettlement = minfo->getAddress("settlement_current");
@ -1107,13 +1126,6 @@ bool API::getItemIndexesInBox(vector<uint32_t> &indexes,
return true; return true;
} }
void API::Private::readName(t_name & name, uint32_t address)
{
g_pProcess->readSTLString(address + name_firstname_offset , name.first_name, 128);
g_pProcess->readSTLString(address + name_nickname_offset , name.nickname, 128);
g_pProcess->read(address + name_words_offset ,48, (uint8_t *) name.words);
}
bool API::ReadCreature (const int32_t index, t_creature & furball) bool API::ReadCreature (const int32_t index, t_creature & furball)
{ {
if(!d->creaturesInited) return false; if(!d->creaturesInited) return false;
@ -1199,6 +1211,7 @@ bool API::InitReadNameTables(vector<vector<string> > & translations , vector<vec
int genericAddress = d->offset_descriptor->getAddress ("language_vector"); int genericAddress = d->offset_descriptor->getAddress ("language_vector");
int transAddress = d->offset_descriptor->getAddress ("translation_vector"); int transAddress = d->offset_descriptor->getAddress ("translation_vector");
int word_table_offset = d->offset_descriptor->getOffset ("word_table"); int word_table_offset = d->offset_descriptor->getOffset ("word_table");
int sizeof_string = d->offset_descriptor->getHexValue ("sizeof_string");
DfVector genericVec (d->p->readVector (genericAddress, 4)); DfVector genericVec (d->p->readVector (genericAddress, 4));
DfVector transVec (d->p->readVector (transAddress, 4)); DfVector transVec (d->p->readVector (transAddress, 4));
@ -1209,7 +1222,7 @@ bool API::InitReadNameTables(vector<vector<string> > & translations , vector<vec
uint32_t genericNamePtr = * (uint32_t *) genericVec.at (i); uint32_t genericNamePtr = * (uint32_t *) genericVec.at (i);
for(int i=0; i<10;i++) for(int i=0; i<10;i++)
{ {
string word = d->p->readSTLString (genericNamePtr + i * sizeof(string)); string word = d->p->readSTLString (genericNamePtr + i * sizeof_string);
translations[i].push_back (word); translations[i].push_back (word);
} }
} }
@ -1309,75 +1322,6 @@ string API::TranslateName(const DFHack::t_name &name,const std::vector< std::vec
return out; return out;
} }
/*
string API::TranslateName (const int names[], int size, const map<string, vector<string> > & nameTable, const string & language)
{
string trans;
assert (d->nameTablesInited);
map<string, vector<string> >::const_iterator it;
it = nameTable.find (language);
if (it != nameTable.end())
{
for (int i = 0;i < size;i++)
{
if (names[i] == -1)
{
break;
}
trans.append (it->second[names[i]]);
}
}
return (trans);
}
string API::TranslateName (const t_lastname & last, const map<string, vector<string> > & nameTable, const string & language)
{
string trans_last;
assert (d->nameTablesInited);
map<string, vector<string> >::const_iterator it;
it = nameTable.find (language);
if (it != nameTable.end())
{
for (int i = 0;i < 7;i++)
{
if (last.names[i] == -1)
{
break;
}
trans_last.append (it->second[last.names[i]]);
}
}
return (trans_last);
}
string API::TranslateName (const t_squadname & squad, const map<string, vector<string> > & nameTable, const string & language)
{
string trans_squad;
assert (d->nameTablesInited);
map<string, vector<string> >::const_iterator it;
it = nameTable.find (language);
if (it != nameTable.end())
{
for (int i = 0;i < 7;i++)
{
if (squad.names[i] == -1)
{
continue;
}
if (squad.names[i] == 0)
{
break;
}
if (i == 4)
{
trans_squad.append (" ");
}
trans_squad.append (it->second[squad.names[i]]);
}
}
return (trans_squad);
}*/
void API::FinishReadNameTables() void API::FinishReadNameTables()
{ {
d->nameTablesInited = false; d->nameTablesInited = false;

@ -484,14 +484,14 @@ struct t_trait
CREATURE CREATURE
*/ */
//#pragma pack(push,4)
struct t_name struct t_name
{ {
char first_name[128]; char first_name[128];
char nickname[128]; char nickname[128];
int words[7]; int32_t words[7];
short parts_of_speech[7]; uint16_t parts_of_speech[7];
int language; uint32_t language;
bool has_name; bool has_name;
}; };
@ -514,6 +514,8 @@ struct t_like
t_matglossPair material; t_matglossPair material;
bool active; bool active;
}; };
//#pragma pack(pop)
#define NUM_CREATURE_TRAITS 30 #define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102 #define NUM_CREATURE_LABORS 102
struct t_creature struct t_creature

@ -838,7 +838,7 @@
<!-- Windows 40d## sub-versions, should inherit only vtable from 40d --> <!-- Windows 40d## sub-versions, should inherit only vtable from 40d -->
<Entry version="v0.28.181.40d2" os ="windows" id="40d2win" base="40dwin"> <Entry version="v0.28.181.40d2" os ="windows" id="40d2win" base="40dwin">
<HexValue name="pe_timestamp">0x4953556c</HexValue> <HexValue name="pe_timestamp">0x4953556c</HexValue>
<String name="md5">B1A8CA1F91734EB492B7F54F6823CDDB</String> <String name="md5">b1a8ca1f91734eb492b7f54f6823cddb</String>
<Address name="buildings">0x014d1db0</Address> <Address name="buildings">0x014d1db0</Address>
<Address name="constructions">0x014bda18</Address> <Address name="constructions">0x014bda18</Address>
<Address name="creatures">0x014d1404</Address> <Address name="creatures">0x014d1404</Address>
@ -875,6 +875,7 @@
<Offset name="name_firstname">0x0</Offset> <Offset name="name_firstname">0x0</Offset>
<Offset name="name_nickname">0x1C</Offset> <Offset name="name_nickname">0x1C</Offset>
<Offset name="name_words">0x38</Offset> <Offset name="name_words">0x38</Offset>
<HexValue name="sizeof_string">0x1C</HexValue> <!-- TEST! Missing in 40d! -->
<!-- creature offsets --> <!-- creature offsets -->
<Offset name="creature_flags1">0xFC</Offset> <Offset name="creature_flags1">0xFC</Offset>
@ -955,7 +956,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d3" os ="windows" id="40d3win" base="40d2win" rebase="0x2018"> <Entry version="v0.28.181.40d3" os ="windows" id="40d3win" base="40d2win" rebase="0x2018">
<HexValue name="pe_timestamp">0x4957716f</HexValue> <HexValue name="pe_timestamp">0x4957716f</HexValue>
<String name="md5">9B6DA355562A4CDD345EA3046290499B</String> <String name="md5">9b6da355562a4cdd345ea3046290499b</String>
<Address name="cursor_xyz">0x0094d27c</Address> <Address name="cursor_xyz">0x0094d27c</Address>
<Address name="pause_state">0x012d0fbf</Address> <Address name="pause_state">0x012d0fbf</Address>
<Address name="window_x">0x00c9533c</Address> <Address name="window_x">0x00c9533c</Address>
@ -964,11 +965,11 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d4" os ="windows" id="40d4win" base="40d3win" rebase="0x0"> <Entry version="v0.28.181.40d4" os ="windows" id="40d4win" base="40d3win" rebase="0x0">
<HexValue name="pe_timestamp">0x4957a0a2</HexValue> <HexValue name="pe_timestamp">0x4957a0a2</HexValue>
<String name="md5">B77759DB7A6DD787BF98953FC5749D81</String> <String name="md5">b77759db7a6dd787bf98953fc5749d81</String>
</Entry> </Entry>
<Entry version="v0.28.181.40d5" os ="windows" id="40d5win" base="40d4win" rebase="0x2018"> <Entry version="v0.28.181.40d5" os ="windows" id="40d5win" base="40d4win" rebase="0x2018">
<HexValue name="pe_timestamp">0x495991c3</HexValue> <HexValue name="pe_timestamp">0x495991c3</HexValue>
<String name="md5">A0792B81E5B8EC1DBDD627643E93B40D</String> <String name="md5">a0792b81e5b8ec1dbdd627643e93b40d</String>
<Address name="cursor_xyz">0x0094f27c</Address> <Address name="cursor_xyz">0x0094f27c</Address>
<Address name="pause_state">0x012d2fbb</Address> <Address name="pause_state">0x012d2fbb</Address>
<Address name="window_x">0x00c97334</Address> <Address name="window_x">0x00c97334</Address>
@ -977,7 +978,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d6" os ="windows" id="40d6win" base="40d5win" rebase="0x18a08"> <Entry version="v0.28.181.40d6" os ="windows" id="40d6win" base="40d5win" rebase="0x18a08">
<HexValue name="pe_timestamp">0x495cafd2</HexValue> <HexValue name="pe_timestamp">0x495cafd2</HexValue>
<String name="md5">D09E88A32FE57DE5973F78EF213271B6</String> <String name="md5">d09e88a32fe57de5973f78ef213271b6</String>
<Address name="cursor_xyz">0x009662a4</Address> <Address name="cursor_xyz">0x009662a4</Address>
<Address name="pause_state">0x012e9fef</Address> <Address name="pause_state">0x012e9fef</Address>
<Address name="window_x">0x00cae368</Address> <Address name="window_x">0x00cae368</Address>
@ -986,7 +987,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d7" os ="windows" id="40d7win" base="40d6win" rebase="0x190"> <Entry version="v0.28.181.40d7" os ="windows" id="40d7win" base="40d6win" rebase="0x190">
<HexValue name="pe_timestamp">0x495fcfef</HexValue> <HexValue name="pe_timestamp">0x495fcfef</HexValue>
<String name="md5">8E8E2A83D421E356A8047DC8830A7426</String> <String name="md5">8e8e2a83d421e356a8047dc8830a7426</String>
<Address name="cursor_xyz">0x009662a4</Address> <Address name="cursor_xyz">0x009662a4</Address>
<Address name="pause_state">0x012e9fef</Address> <Address name="pause_state">0x012e9fef</Address>
<Address name="window_x">0x00cae368</Address> <Address name="window_x">0x00cae368</Address>
@ -995,15 +996,15 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d8" os ="windows" id="40d8win" base="40d7win" rebase="0x0"> <Entry version="v0.28.181.40d8" os ="windows" id="40d8win" base="40d7win" rebase="0x0">
<HexValue name="pe_timestamp">0x4963c928</HexValue> <HexValue name="pe_timestamp">0x4963c928</HexValue>
<String name="md5">32253BEE114DD25EBBAA50D90B5C0A2A</String> <String name="md5">32253bee114dd25ebbaa50d90b5c0a2a</String>
</Entry> </Entry>
<Entry version="v0.28.181.40d9" os ="windows" id="40d9win" base="40d8win" rebase="0x0"> <Entry version="v0.28.181.40d9" os ="windows" id="40d9win" base="40d8win" rebase="0x0">
<HexValue name="pe_timestamp">0x4967c2e0</HexValue> <HexValue name="pe_timestamp">0x4967c2e0</HexValue>
<String name="md5">AEA5A207B8B1CDA942502F97A429F6C3</String> <String name="md5">aea5a207b8b1cda942502f97a429f6c3</String>
</Entry> </Entry>
<Entry version="v0.28.181.40d10" os ="windows" id="40d10win" base="40d9win"> <Entry version="v0.28.181.40d10" os ="windows" id="40d10win" base="40d9win">
<HexValue name="pe_timestamp">0x49c59b94</HexValue> <HexValue name="pe_timestamp">0x49c59b94</HexValue>
<String name="md5">193193D8624F2F3F6D9D556FAB09B122</String> <String name="md5">193193d8624f2f3f6d9d556fab09b122</String>
<Address name="buildings">0x0151bd00</Address> <Address name="buildings">0x0151bd00</Address>
<Address name="constructions">0x01507968</Address> <Address name="constructions">0x01507968</Address>
<Address name="creatures">0x0151b354</Address> <Address name="creatures">0x0151b354</Address>
@ -1040,7 +1041,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d12" os="windows" id="40d12win" base="40d11win"> <Entry version="v0.28.181.40d12" os="windows" id="40d12win" base="40d11win">
<HexValue name="pe_timestamp">0x4a3ccb7f</HexValue> <HexValue name="pe_timestamp">0x4a3ccb7f</HexValue>
<String name="md5">6EA1DE36AF8E1666BD6478736E298C4C</String> <String name="md5">6ea1de36af8e1666bd6478736e298c4c</String>
<Address name="buildings">0x015b7750</Address> <Address name="buildings">0x015b7750</Address>
<Address name="constructions">0x015a33b8</Address> <Address name="constructions">0x015a33b8</Address>
<Address name="creatures">0x015b6da4</Address> <Address name="creatures">0x015b6da4</Address>
@ -1073,7 +1074,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d13" os="windows" id="40d13win" base="40d12win" rebase="0x5090"> <Entry version="v0.28.181.40d13" os="windows" id="40d13win" base="40d12win" rebase="0x5090">
<HexValue name="pe_timestamp">0x4a51c26e</HexValue> <HexValue name="pe_timestamp">0x4a51c26e</HexValue>
<String name="md5">04A8D8CE311D8AC75E4241BEF68D3147</String> <String name="md5">04a8d8ce311d8ac75e4241bef68d3147</String>
<Address name="current_menu_state">0x00964430</Address> <Address name="current_menu_state">0x00964430</Address>
<Address name="cursor_xyz">0x009642b4</Address> <Address name="cursor_xyz">0x009642b4</Address>
<Address name="pause_state">0x013da2bf</Address> <Address name="pause_state">0x013da2bf</Address>
@ -1083,7 +1084,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d14" os="windows" id="40d14win" base="40d13win" rebase="0x2010"> <Entry version="v0.28.181.40d14" os="windows" id="40d14win" base="40d13win" rebase="0x2010">
<HexValue name="pe_timestamp">0x4a8623d2</HexValue> <HexValue name="pe_timestamp">0x4a8623d2</HexValue>
<String name="md5">781A2E51BE4056A7320108F8F0DF8A13</String> <String name="md5">781a2e51be4056a7320108f8f0df8a13</String>
<Address name="current_menu_state">0x00966430</Address> <Address name="current_menu_state">0x00966430</Address>
<Address name="cursor_xyz">0x009662b4</Address> <Address name="cursor_xyz">0x009662b4</Address>
<Address name="pause_state">0x013dc2c7</Address> <Address name="pause_state">0x013dc2c7</Address>
@ -1093,7 +1094,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d15" os="windows" id="40d15win" base="40d14win"> <Entry version="v0.28.181.40d15" os="windows" id="40d15win" base="40d14win">
<HexValue name="pe_timestamp">0x4a9a6090</HexValue> <HexValue name="pe_timestamp">0x4a9a6090</HexValue>
<String name="md5">12CC4A3DBB6E6DFD7BC7AEE458B9471A</String> <String name="md5">12cc4a3dbb6e6dfd7bc7aee458b9471a</String>
<Address name="buildings">0x015be808</Address> <Address name="buildings">0x015be808</Address>
<Address name="constructions">0x015aa470</Address> <Address name="constructions">0x015aa470</Address>
<Address name="creatures">0x015bde5c</Address> <Address name="creatures">0x015bde5c</Address>
@ -1126,11 +1127,11 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d16" os="windows" id="40d16win" base="40d15win" rebase="0x0"> <Entry version="v0.28.181.40d16" os="windows" id="40d16win" base="40d15win" rebase="0x0">
<HexValue name="pe_timestamp">0x4a9b1a72</HexValue> <HexValue name="pe_timestamp">0x4a9b1a72</HexValue>
<String name="md5">59AB29021ACA9F3C66B1AB102FB3CEEA</String> <String name="md5">59ab29021aca9f3c66b1ab102fb3ceea</String>
</Entry> </Entry>
<Entry version="v0.28.181.40d17" os="windows" base="40d16win" id="40d17win"> <Entry version="v0.28.181.40d17" os="windows" base="40d16win" id="40d17win">
<HexValue name="pe_timestamp">0x4b6b7879</HexValue> <HexValue name="pe_timestamp">0x4b6b7879</HexValue>
<String name="md5">DE66405F54D98297303D439B3B7AA30E</String> <String name="md5">de66405f54d98297303d439b3b7aa30e</String>
<Address name="buildings">0x015f3260</Address> <Address name="buildings">0x015f3260</Address>
<Address name="constructions">0x015deec8</Address> <Address name="constructions">0x015deec8</Address>
<Address name="creatures">0x015f28b4</Address> <Address name="creatures">0x015f28b4</Address>
@ -1176,7 +1177,7 @@
</Entry> </Entry>
<Entry version="v0.28.181.40d19" os="windows" base="40d18win" id="40d19win"> <Entry version="v0.28.181.40d19" os="windows" base="40d18win" id="40d19win">
<HexValue name="pe_timestamp">0x4b90268a</HexValue> <HexValue name="pe_timestamp">0x4b90268a</HexValue>
<String name="md5">13640A273D90AF39425B798AE9823757</String> <String name="md5">13640a273D90af39425b798ae9823757</String>
<Address name="buildings">0x01512898</Address> <Address name="buildings">0x01512898</Address>
<Address name="constructions">0x014fe500</Address> <Address name="constructions">0x014fe500</Address>
<Address name="creatures">0x01511eec</Address> <Address name="creatures">0x01511eec</Address>
@ -1258,6 +1259,12 @@
<Address name="language_vector">0x09374F90</Address> <Address name="language_vector">0x09374F90</Address>
<Offset name="word_table">0x1C</Offset> <Offset name="word_table">0x1C</Offset>
<!-- name struct -->
<Offset name="name_firstname">0x0</Offset>
<Offset name="name_nickname">0x4</Offset>
<Offset name="name_words">0x8</Offset>
<HexValue name="sizeof_string">0x4</HexValue>
<!-- view screen for things like telnet fortress --> <!-- view screen for things like telnet fortress -->
<Address name="view_screen">0x91631f0</Address> <Address name="view_screen">0x91631f0</Address>
@ -1265,9 +1272,7 @@
<Offset name="current_job_id">0x08</Offset> <Offset name="current_job_id">0x08</Offset>
<!-- creature offsets --> <!-- creature offsets -->
<Offset name="creature_first_name">0x00</Offset> <Offset name="creature_name">0x00</Offset>
<Offset name="creature_nick_name">0x04</Offset>
<Offset name="creature_last_name">0x08</Offset>
<Offset name="creature_position">0x4C</Offset> <Offset name="creature_position">0x4C</Offset>
<Offset name="creature_race">0x44</Offset> <Offset name="creature_race">0x44</Offset>
<Offset name="creature_flags1">0x90</Offset> <Offset name="creature_flags1">0x90</Offset>
@ -1345,7 +1350,7 @@
<Address name="settlement_current">0x09374BCC</Address> <Address name="settlement_current">0x09374BCC</Address>
<Address name="settlements">0x09374B60</Address> <Address name="settlements">0x09374B60</Address>
<Offset name="settlement_name">0x08</Offset> <Offset name="settlement_name">0x00</Offset>
<Offset name="settlement_world_xy">0x4a</Offset> <Offset name="settlement_world_xy">0x4a</Offset>
<Offset name="settlement_local_xy">0x94</Offset> <Offset name="settlement_local_xy">0x94</Offset>