Name translation for real

develop
Petr Mrázek 2010-04-07 01:17:03 +02:00
parent 216cfa74e6
commit 5ee584b372
10 changed files with 64 additions and 21 deletions

@ -11,6 +11,7 @@
#include "modules/Maps.h"
#include "modules/Materials.h"
#include "modules/Position.h"
#include "modules/Translation.h"
#include "modules/Gui.h"
using namespace DFHack;
@ -23,6 +24,7 @@ APIPrivate::APIPrivate()
position = 0;
gui = 0;
materials = 0;
translation = 0;
}
APIPrivate::~APIPrivate()
@ -32,6 +34,7 @@ APIPrivate::~APIPrivate()
if(position) delete position;
if(gui) delete gui;
if(materials) delete materials;
if(translation) delete translation;
}
bool APIPrivate::InitReadNames()

@ -40,6 +40,7 @@ distribution.
#include "modules/Position.h"
#include "modules/Gui.h"
#include "modules/Creatures.h"
#include "modules/Translation.h"
using namespace DFHack;
@ -201,6 +202,13 @@ Materials * API::getMaterials()
return d->materials;
}
Translation * API::getTranslation()
{
if(!d->translation)
d->translation = new Translation(d);
return d->translation;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadBuildings ( uint32_t& numbuildings )

@ -37,6 +37,7 @@ distribution.
namespace DFHack
{
class APIPrivate;
class memory_info;
class Process;
@ -47,6 +48,7 @@ namespace DFHack
class Position;
class Gui;
class Materials;
class Translation;
class DFHACK_EXPORT API
{
@ -89,6 +91,7 @@ namespace DFHack
Gui * getGui();
Position * getPosition();
Materials * getMaterials();
Translation * getTranslation();
/*
* Constructions (costructed walls, floors, ramps, etc...)

@ -1,5 +1,5 @@
#ifndef CL_MOD_POSITION
#define CL_MOD_POSITION
#ifndef CL_MOD_TRANSLATION
#define CL_MOD_TRANSLATION
/*
* DF translation tables and name translation
*/

@ -67,6 +67,7 @@ Creatures::Creatures(APIPrivate* _d)
creatures.creature_vector = minfo->getAddress ("creature_vector");
creatures.creature_pos_offset = minfo->getOffset ("creature_position");
creatures.creature_profession_offset = minfo->getOffset ("creature_profession");
creatures.creature_custom_profession_offset = minfo->getOffset ("creature_custom_profession");
creatures.creature_race_offset = minfo->getOffset ("creature_race");
creatures.creature_flags1_offset = minfo->getOffset ("creature_flags1");
creatures.creature_flags2_offset = minfo->getOffset ("creature_flags2");
@ -153,7 +154,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
//d->readName(furball.squad_name, temp + offs.creature_squad_name_offset);
d->d->readName(furball.artifact_name, temp + offs.creature_artifact_name_offset);
// custom profession
//fill_char_buf (furball.custom_profession, d->p->readSTLString (temp + offs.creature_custom_profession_offset));
fill_char_buf (furball.custom_profession, g_pProcess->readSTLString (temp + offs.creature_custom_profession_offset));
// labors
g_pProcess->read (temp + offs.creature_labors_offset, NUM_CREATURE_LABORS, furball.labors);

@ -54,10 +54,10 @@ Translation::Translation(APIPrivate * d_)
d->d = d_;
d->Inited = d->Started = false;
memory_info * mem = d->d->offset_descriptor;
int genericAddress = mem->getAddress ("language_vector");
int transAddress = mem->getAddress ("translation_vector");
int word_table_offset = mem->getOffset ("word_table");
int sizeof_string = mem->getHexValue ("sizeof_string");
d->genericAddress = mem->getAddress ("language_vector");
d->transAddress = mem->getAddress ("translation_vector");
d->word_table_offset = mem->getOffset ("word_table");
d->sizeof_string = mem->getHexValue ("sizeof_string");
d->Inited = true;
}
@ -75,8 +75,8 @@ bool Translation::Start()
Process * p = d->d->p;
DfVector genericVec (p, d->genericAddress, 4);
DfVector transVec (p, d->transAddress, 4);
DFDict translations = d->dicts.translations;
DFDict foreign_languages = d->dicts.foreign_languages;
DFDict & translations = d->dicts.translations;
DFDict & foreign_languages = d->dicts.foreign_languages;
translations.resize(10);
for (uint32_t i = 0;i < genericVec.getSize();i++)

@ -36,6 +36,7 @@ namespace DFHack
class Position;
class Maps;
class Creatures;
class Translation;
class ProcessEnumerator;
class Process;
class memory_info;
@ -67,6 +68,7 @@ namespace DFHack
Position * position;
Gui * gui;
Materials * materials;
Translation * translation;
/*
uint32_t item_material_offset;

@ -37,6 +37,7 @@ typedef struct
uint32_t creature_vector;
uint32_t creature_pos_offset;
uint32_t creature_profession_offset;
uint32_t creature_custom_profession_offset;
uint32_t creature_race_offset;
uint32_t creature_flags1_offset;
uint32_t creature_flags2_offset;

@ -12,6 +12,7 @@ using namespace std;
#include <DFMemInfo.h>
#include <modules/Materials.h>
#include <modules/Creatures.h>
#include <modules/Translation.h>
template <typename T>
void print_bits ( T val, std::ostream& out )
@ -165,14 +166,16 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << ", nick name: " << creature.name.nickname;
addendl = true;
}
/*
string transName = DF.TranslateName(creature.name,englishWords,foreignWords,false);
DFHack::Translation *Tran = DF.getTranslation();
string transName = Tran->TranslateName(creature.name,false);
if(!transName.empty())
{
cout << ", trans name: " << transName;
addendl=true;
}
*/
/*
cout << ", likes: ";
for(uint32_t i = 0;i<creature.numLikes; i++)
@ -189,11 +192,12 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
addendl = false;
}
cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")";
/*
if(creature.custom_profession[0])
{
cout << ", custom profession: " << creature.custom_profession;
}
/*
if(creature.current_job.active)
{
cout << ", current job: " << mem->getJob(creature.current_job.jobId);
@ -297,6 +301,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << "from the underworld, ";
}
cout << endl;
#include <modules/Translation.h>
/*
if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) )
{
@ -325,6 +330,7 @@ int main (void)
DFHack::Creatures * Creatures = DF.getCreatures();
DFHack::Materials * Materials = DF.getMaterials();
DFHack::Translation * Tran = DF.getTranslation();
uint32_t numCreatures;
if(!Creatures->Start(numCreatures))
@ -358,19 +364,19 @@ int main (void)
cerr << "Can't get the creature types." << endl;
return 1;
}
/*
if(!DF.InitReadNameTables(englishWords,foreignWords))
if(!Tran->Start())
{
cerr << "Can't get name tables" << endl;
return 1;
}
*/
//DF.InitViewAndCursor();
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
Creatures->ReadCreature(i,temp);
//if(string(creaturestypes[temp.type].id) == "DWARF")
if(string(creaturestypes[temp.type].id) == "DWARF")
{
cout << "index " << i << " ";
printCreature(DF,temp);

@ -2962,6 +2962,7 @@ map_data_1b60_offset 0x1B9c
=========
<Address name="creature_vector">0x0166ecc4</Address>
<Offset name="creature_name">0x0</Offset>
<Offset name="creature_custom_profession">0x6c</Offset>
<Offset name="creature_profession">0x88</Offset>
<Offset name="creature_race">0x8C</Offset>
<Offset name="creature_position">0x90</Offset>
@ -2972,6 +2973,7 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_artifact_name">0x6D0</Offset>
<Offset name="creature_labors">0x770</Offset>
<Offset name="creature_happiness">0x830</Offset>
<Offset name="creature_skills">0x1FC</Offset>
<!-- from DT -->
<Address name="dwarf_race_index">0x01470fbc</Address>DWORD, OK
@ -3018,15 +3020,32 @@ map_data_1b60_offset 0x1B9c
<!--<Address name="mat_creature_types2">0x16AEE08</Address>-->
<!-- possible constructions -->
Constructions
=============
<Address name="construction_vector">0x165b290</Address>
<Offset name="sizeof_construction">0x14</Offset>
Translations
============
<Address name="language_vector">0x016B0008</Address>
<Address name="translation_vector">0x016AFFD8</Address>
<Offset name="word_table">0x58</Offset>
<Address name="language_vector">0x016AFFD8</Address>
<Address name="translation_vector">0x016B0008</Address>
<Offset name="word_table">0x4C</Offset>
Vegetation
==========
:(
Buildings
=========
:(
Effects
=======
:(
<!--
addresses from belal: vectors might need 8 subtracted from them