2010-05-25 19:22:17 -06:00
|
|
|
// Dwarf fortress names are a complicated beast, in objects they are displayed
|
|
|
|
// as indexes into the language vectors
|
|
|
|
//
|
|
|
|
// use this tool if you are trying to find what the indexes are for a displayed
|
|
|
|
// name, so you can then search for it in your object
|
2010-02-18 18:13:53 -07:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
2010-02-19 08:36:54 -07:00
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
2010-02-18 18:13:53 -07:00
|
|
|
using namespace std;
|
|
|
|
|
2011-03-21 14:29:54 -06:00
|
|
|
#include <DFHack.h>
|
2010-02-18 18:13:53 -07:00
|
|
|
|
2010-02-19 08:36:54 -07:00
|
|
|
// returns a lower case version of the string
|
|
|
|
string tolower (const string & s)
|
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
string d (s);
|
2010-02-19 08:36:54 -07:00
|
|
|
|
2010-03-26 06:01:46 -06:00
|
|
|
transform (d.begin (), d.end (), d.begin (), (int(*)(int)) tolower);
|
|
|
|
return d;
|
2010-02-19 08:36:54 -07:00
|
|
|
}
|
|
|
|
string groupBy2(const string & s)
|
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
string d;
|
|
|
|
for(int i =2;i<s.length();i++){
|
|
|
|
if(i%2==0)
|
|
|
|
{
|
|
|
|
d+= s.substr(i-2,2) + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
d+=s.substr(s.length()-2,2);
|
|
|
|
return(d);
|
2010-02-19 08:36:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t endian_swap(uint32_t x)
|
|
|
|
{
|
|
|
|
x = (x>>24) |
|
|
|
|
((x<<8) & 0x00FF0000) |
|
|
|
|
((x>>8) & 0x0000FF00) |
|
|
|
|
(x<<24);
|
2010-03-26 06:01:46 -06:00
|
|
|
return x;
|
2010-02-19 08:36:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-02-18 18:13:53 -07:00
|
|
|
int main (void)
|
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DF("Memory.xml");
|
2011-03-21 14:29:54 -06:00
|
|
|
DFHack::Context * C;
|
|
|
|
DFHack::Translation * Tran;
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
|
|
|
{
|
2011-03-21 14:29:54 -06:00
|
|
|
C = DF.getSingleContext();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
2010-02-18 18:13:53 -07:00
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
cerr << e.what() << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2010-02-18 18:13:53 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2011-03-21 14:29:54 -06:00
|
|
|
|
|
|
|
Tran = C->getTranslation();
|
|
|
|
|
|
|
|
if(!Tran->Start())
|
2010-03-26 06:01:46 -06:00
|
|
|
{
|
|
|
|
cerr << "Could not get Names" << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2011-03-21 14:29:54 -06:00
|
|
|
DFHack::Dicts dicts = *(Tran->getDicts());
|
|
|
|
DFHack::DFDict & englishWords = dicts.translations;
|
|
|
|
DFHack::DFDict & foreignWords = dicts.foreign_languages;
|
|
|
|
|
|
|
|
C->Detach();
|
2010-03-26 06:01:46 -06:00
|
|
|
string input;
|
2011-03-21 14:29:54 -06:00
|
|
|
|
2010-02-18 18:13:53 -07:00
|
|
|
cout << "\nSelect Name to search or q to Quit" << endl;
|
|
|
|
getline (cin, input);
|
2010-03-26 06:01:46 -06:00
|
|
|
while(input != "q"){
|
2010-03-15 16:18:05 -06:00
|
|
|
for( uint32_t i = 0; i < englishWords.size();i++){
|
|
|
|
for( uint32_t j = 0;j < englishWords[i].size();j++){
|
|
|
|
if(englishWords[i][j] != ""){
|
2010-03-26 06:01:46 -06:00
|
|
|
uint32_t found = tolower(input).find(tolower(englishWords[i][j]));
|
|
|
|
if(found != string::npos){
|
|
|
|
stringstream value;
|
|
|
|
value << setfill('0') << setw(8) << hex << endian_swap(j);
|
|
|
|
cout << englishWords[i][j] << " " << groupBy2(value.str()) << endl;
|
2010-03-15 16:18:05 -06:00
|
|
|
}
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-15 16:18:05 -06:00
|
|
|
for( uint32_t i = 0; i < foreignWords.size();i++){
|
|
|
|
for( uint32_t j = 0;j < foreignWords[i].size();j++){
|
2010-03-26 06:01:46 -06:00
|
|
|
uint32_t found = tolower(input).find(tolower(foreignWords[i][j]));
|
|
|
|
if(found != string::npos){
|
|
|
|
stringstream value;
|
|
|
|
value << setfill('0') << setw(8) << hex << endian_swap(j);
|
|
|
|
cout << foreignWords[i][j] << " " << groupBy2(value.str()) << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getline(cin,input);
|
|
|
|
}
|
2010-02-18 18:13:53 -07:00
|
|
|
#ifndef LINUX_BUILD
|
2011-03-21 14:29:54 -06:00
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
2010-02-18 18:13:53 -07:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|