merged input injection patch by belal

develop
Petr Mrázek 2009-12-12 19:52:30 +00:00
parent 2a2a60723a
commit 337d42e15a
10 changed files with 1660 additions and 33 deletions

@ -79,13 +79,16 @@ CONFIGURE_FILE( ${CMAKE_SOURCE_DIR}/library/config.h.cmake ${CMAKE_SOURCE_DIR}/l
IF(UNIX)
add_definitions(-DLINUX_BUILD)
add_definitions(-DUSE_CONFIG_H)
find_library(X11_LIBRARY X11)
find_library(XTEST_LIBRARY Xtst)
SET(PROJECT_LIBS ${X11_LIBRARY} ${XTEST_LIBRARY})
ELSE(UNIX)
SET(PROJECT_LIBS psapi)
ENDIF(UNIX)
ADD_LIBRARY(dfhack SHARED ${PROJECT_SRCS})
SET_TARGET_PROPERTIES( dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
SET_TARGET_PROPERTIES(dfhack PROPERTIES DEBUG_POSTFIX "-debug" )
TARGET_LINK_LIBRARIES(dfhack ${PROJECT_LIBS})

@ -62,7 +62,11 @@ using namespace std;
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <X11/Xlib.h> //need for X11 functions
#include <X11/extensions/XTest.h> //need for Xtest
#include <X11/Xatom.h> //for the atom stuff
#else
#define _WIN32_WINNT 0x0500 // needed for INPUT struct
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

File diff suppressed because it is too large Load Diff

@ -28,6 +28,7 @@ distribution.
#include "Export.h"
#include <string>
#include <vector>
#include <map>
#include "integers.h"
#include "DFTileTypes.h"
@ -45,6 +46,14 @@ namespace DFHack
bool Attach();
bool Detach();
bool isAttached();
void TypeStr(const char *lpszString,int delay = 0,bool useShift = false); //Capitals are shifted automatically, other keys !@# ect need to have useShift set for them
void TypeSpecial(t_special command,int count=1,int delay = 0);
bool ReadPauseState(); //true if paused, false if not
bool ReadViewScreen(t_viewscreen &);
// stop DF from executing
bool Suspend();
@ -163,6 +172,8 @@ namespace DFHack
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z);
bool getCurrentCursorCreatures(vector<uint32_t> &addresses); // This returns false if there is nothing under the cursor, it puts the addresses in a the vector if there is
bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height);
bool setWindowSize(const int32_t & width, const int32_t & height);
@ -177,10 +188,12 @@ namespace DFHack
vector<t_trait> getTraits(const uint32_t &index);
vector<t_labor> getLabors(const uint32_t &index);
*/
void InitReadNameTables();
void InitReadNameTables(map< string, vector< string > > & nameTable);
void FinishReadNameTables();
string TranslateName(const t_lastname & last, const map< string, vector< string > > &nameTable,const string & language="GENERIC");
string TranslateName(const t_squadname & squad, const map< string, vector< string > > &nameTable,const string & language="GENERIC");
uint32_t InitReadItems();
bool ReadItem(const uint32_t &index, t_item & item);
void FinishReadItems();

@ -478,6 +478,7 @@ struct t_job
#define NUM_CREATURE_LABORS 102
struct t_creature
{
uint32_t origin;
uint16_t x;
uint16_t y;
uint16_t z;
@ -641,4 +642,63 @@ union t_occupancy
} unibits;
};
enum t_special
{
ENTER,
SPACE,
BACK_SPACE,
TAB,
CAPS_LOCK,
LEFT_SHIFT,
RIGHT_SHIFT,
LEFT_CONTROL,
RIGHT_CONTROL,
ALT,
WAIT,
ESCAPE,
UP,
DOWN,
LEFT,
RIGHT,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
PAGE_UP,
PAGE_DOWN,
INSERT,
KEY_DELETE, // DELETE is already defined in winnt.h, so can't redefine it here
HOME,
END,
KEYPAD_DIVIDE,
KEYPAD_MULTIPLY,
KEYPAD_SUBTRACT,
KEYPAD_ADD,
KEYPAD_ENTER,
KEYPAD_0,
KEYPAD_1,
KEYPAD_2,
KEYPAD_3,
KEYPAD_4,
KEYPAD_5,
KEYPAD_6,
KEYPAD_7,
KEYPAD_8,
KEYPAD_9,
KEYPAD_DECIMAL_POINT
};
struct t_viewscreen
{
int32_t type;
//There is more info in these objects, but I don't know what it is yet
};
#endif // TYPES_H_INCLUDED

@ -924,8 +924,11 @@
<String name="md5">59ab29021aca9f3c66b1ab102fb3ceea</String>
<!-- map_data = 0x01601D84 -->
<!-- door: 0x8e15d4, no VTable rebase needed -->
<Address name="items">15BDF50</Address>
<Address name="current_cursor_creature">0x01757F38</Address>
<Address name="items">0x15BDF50</Address>
<Offset name="item_materials">0x68</Offset>
<Address name="pause_state">0x13DC2EB</Address>
<Address name="view_screen">0x013EF970</Address>
<VTable>
<class vtable="0x008E04D4" name="item_liquid_misc" />
<class vtable="0x008E07AC" name="item_remains" />
@ -1016,6 +1019,77 @@
<class vtable="0x0091A25C" name="item_trapparts" />
<class vtable="0x0091A534" name="item_trapcomp" />
</VTable>
<VTable>
<class vtable="0x008E6428" name="viewscreen_conversation" />
<class vtable="0x008ED474" name="viewscreen_option" />
<class vtable="0x008ED4A0" name="viewscreen_loadgame" />
<class vtable="0x008ED4CC" name="viewscreen_savegame" />
<class vtable="0x008ED4F8" name="viewscreen_customize_unit" />
<class vtable="0x008ED524" name="viewscreen_unit" />
<class vtable="0x008ED614" name="viewscreen_layer" />
<class vtable="0x008ED640" name="viewscreen_layer_workshop_profile" />
<class vtable="0x008ED66C" name="viewscreen_layer_unit_relationship" />
<class vtable="0x008ED698" name="viewscreen_layer_musicsound" />
<class vtable="0x008ED6C4" name="viewscreen_layer_export_play_map" />
<class vtable="0x008ED7B8" name="viewscreen_layer_world_gen_param" />
<class vtable="0x008ED7E4" name="viewscreen_layer_world_gen_param_preset" />
<class vtable="0x008ED810" name="viewscreen_layer_stockpile" />
<class vtable="0x008F01C0" name="viewscreen_dungeonmode" />
<class vtable="0x008F01EC" name="viewscreen_adventure_travel" />
<class vtable="0x008F0218" name="viewscreen_adventure_log" />
<class vtable="0x008F0244" name="viewscreen_dungeon_wrestle" />
<class vtable="0x008F0270" name="viewscreen_dungeon_monsterstatus" />
<class vtable="0x008F029C" name="viewscreen_dungeon_announce" />
<class vtable="0x008F02C8" name="viewscreen_setupadventure" />
<class vtable="0x008F0674" name="viewscreen_dwarfmode" />
<class vtable="0x008F06A4" name="viewscreen_selectitem" />
<class vtable="0x0090080C" name="viewscreen_export_graphical_map" />
<class vtable="0x00900838" name="viewscreen_export_region" />
<class vtable="0x00900864" name="viewscreen_new_region" />
<class vtable="0x00900890" name="viewscreen_legends" />
<class vtable="0x009008BC" name="viewscreen_title" />
<class vtable="0x009008E8" name="viewscreen_game_cleaner" />
<class vtable="0x00900914" name="viewscreen_announcelist" />
<class vtable="0x00900940" name="viewscreen_kitchenpref" />
<class vtable="0x0090096C" name="viewscreen_pet" />
<class vtable="0x00900998" name="viewscreen_price" />
<class vtable="0x009009C4" name="viewscreen_justice" />
<class vtable="0x009009F0" name="viewscreen_overallstatus" />
<class vtable="0x00900A1C" name="viewscreen_stores" />
<class vtable="0x00900A48" name="viewscreen_wages" />
<class vtable="0x00900A74" name="viewscreen_jobmanagement" />
<class vtable="0x00900AA0" name="viewscreen_createquota" />
<class vtable="0x00900ACC" name="viewscreen_unitjobs" />
<class vtable="0x00900AF8" name="viewscreen_treasurelist" />
<class vtable="0x00900B24" name="viewscreen_entity" />
<class vtable="0x00900B50" name="viewscreen_civlist" />
<class vtable="0x00900B7C" name="viewscreen_squad" />
<class vtable="0x00900BA8" name="viewscreen_commandchain" />
<class vtable="0x00900BD4" name="viewscreen_buildinglist" />
<class vtable="0x00900C00" name="viewscreen_noble" />
<class vtable="0x00900C2C" name="viewscreen_item" />
<class vtable="0x00900C58" name="viewscreen_building" />
<class vtable="0x00900C84" name="viewscreen_job" />
<class vtable="0x00900CB0" name="viewscreen_layer_noblelist" />
<class vtable="0x00900CDC" name="viewscreen_layer_stone_restriction" />
<class vtable="0x00900D08" name="viewscreen_layer_reaction" />
<class vtable="0x00900D34" name="viewscreen_layer_currency" />
<class vtable="0x00910A14" name="viewscreen_movieplayer" />
<class vtable="0x0092A1A8" name="viewscreen_keybindings" />
<class vtable="0x0092E984" name="viewscreen_textviewer" />
<class vtable="0x0092E9B0" name="viewscreen_tradelist" />
<class vtable="0x0092E9DC" name="viewscreen_tradegoods" />
<class vtable="0x0092EA08" name="viewscreen_barter" />
<class vtable="0x0092EA34" name="viewscreen_meeting" />
<class vtable="0x0092EA60" name="viewscreen_topicmeeting" />
<class vtable="0x0092EA8C" name="viewscreen_topicmeeting_takerequests" />
<class vtable="0x0092EAB8" name="viewscreen_tradeagreement" />
<class vtable="0x0092EAE4" name="viewscreen_requestagreement" />
<class vtable="0x0092EB10" name="viewscreen_layer_assigntrade" />
<class vtable="0x00935174" name="viewscreen_choose_start_site" />
<class vtable="0x009351A0" name="viewscreen_setupdwarfgame" />
<class vtable="0x009351CC" name="viewscreen_layer_choose_language_name" />
</VTable>
</Entry>
.-"""-.
@ -1297,6 +1371,173 @@
<String name="md5">022b933926e08da49c6df8649295f2b7</String>
<!-- map_data = 0x8F9ABDC -->
<!--<class vtable="0x086c78c8" name="door"/>-->
<Address name="current_cursor_creature">0x91ab420</Address>
<Address name="items">0x8F5A2EC</Address>
<Offset name="item_materials">0x50</Offset>
<Address name="pause_state">0x8F35800</Address>
<Address name="view_screen">0x878493c</Address>
<VTable>
<class vtable="0x086CA668" name="viewscreen_conversation" />
<class vtable="0x086D52A8" name="viewscreen_setupadventure" />
<class vtable="0x086D53A8" name="viewscreen_dungeon_announce" />
<class vtable="0x086D52E8" name="viewscreen_dungeon_monsterstatus" />
<class vtable="0x086D5328" name="viewscreen_dungeon_wrestle" />
<class vtable="0x086D5368" name="viewscreen_adventure_log" />
<class vtable="0x086D5428" name="viewscreen_adventure_travel" />
<class vtable="0x086D53E8" name="viewscreen_dungeonmode" />
<class vtable="0x086D6828" name="viewscreen_selectitem" />
<class vtable="0x086D6868" name="viewscreen_dwarfmode" />
<class vtable="0x086DC8C8" name="viewscreen_layer_stockpile" />
<class vtable="0x086DC888" name="viewscreen_layer_world_gen_param_preset" />
<class vtable="0x086DC848" name="viewscreen_layer_world_gen_param" />
<class vtable="0x086DC808" name="viewscreen_layer_export_play_map" />
<class vtable="0x086DC7C8" name="viewscreen_layer_musicsound" />
<class vtable="0x086DC788" name="viewscreen_layer_unit_relationship" />
<class vtable="0x086DC748" name="viewscreen_layer_workshop_profile" />
<class vtable="0x086DCA08" name="viewscreen_layer" />
<class vtable="0x086DCAE8" name="viewscreen_unit" />
<class vtable="0x086DCB28" name="viewscreen_customize_unit" />
<class vtable="0x086DCB68" name="viewscreen_savegame" />
<class vtable="0x086DCAA8" name="viewscreen_loadgame" />
<class vtable="0x086DCCA8" name="viewscreen_option" />
<class vtable="0x086E80E8" name="viewscreen_layer_currency" />
<class vtable="0x086E8128" name="viewscreen_layer_reaction" />
<class vtable="0x086E8168" name="viewscreen_layer_stone_restriction" />
<class vtable="0x086E80A8" name="viewscreen_layer_noblelist" />
<class vtable="0x086E7F68" name="viewscreen_job" />
<class vtable="0x086E7FA8" name="viewscreen_building" />
<class vtable="0x086E7FE8" name="viewscreen_item" />
<class vtable="0x086E8068" name="viewscreen_noble" />
<class vtable="0x086E81A8" name="viewscreen_buildinglist" />
<class vtable="0x086E8228" name="viewscreen_commandchain" />
<class vtable="0x086E8268" name="viewscreen_squad" />
<class vtable="0x086E82A8" name="viewscreen_civlist" />
<class vtable="0x086E82E8" name="viewscreen_entity" />
<class vtable="0x086E8328" name="viewscreen_treasurelist" />
<class vtable="0x086E8368" name="viewscreen_unitjobs" />
<class vtable="0x086E83A8" name="viewscreen_createquota" />
<class vtable="0x086E83E8" name="viewscreen_jobmanagement" />
<class vtable="0x086E8428" name="viewscreen_wages" />
<class vtable="0x086E8028" name="viewscreen_stores" />
<class vtable="0x086E81E8" name="viewscreen_overallstatus" />
<class vtable="0x086E84A8" name="viewscreen_justice" />
<class vtable="0x086E8468" name="viewscreen_price" />
<class vtable="0x086E84E8" name="viewscreen_pet" />
<class vtable="0x086E8528" name="viewscreen_kitchenpref" />
<class vtable="0x086E8568" name="viewscreen_announcelist" />
<class vtable="0x086E85E8" name="viewscreen_game_cleaner" />
<class vtable="0x086E85A8" name="viewscreen_title" />
<class vtable="0x086E86E8" name="viewscreen_legends" />
<class vtable="0x086E8628" name="viewscreen_new_region" />
<class vtable="0x086E8668" name="viewscreen_export_region" />
<class vtable="0x086E86A8" name="viewscreen_export_graphical_map" />
<class vtable="0x08709C28" name="viewscreen_layer_assigntrade" />
<class vtable="0x08709AE8" name="viewscreen_requestagreement" />
<class vtable="0x08709A28" name="viewscreen_tradeagreement" />
<class vtable="0x08709A68" name="viewscreen_topicmeeting_takerequests" />
<class vtable="0x08709AA8" name="viewscreen_topicmeeting" />
<class vtable="0x08709B28" name="viewscreen_meeting" />
<class vtable="0x08709BA8" name="viewscreen_barter" />
<class vtable="0x08709B68" name="viewscreen_tradegoods" />
<class vtable="0x08709BE8" name="viewscreen_tradelist" />
<class vtable="0x087099E8" name="viewscreen_textviewer" />
<class vtable="0x08713228" name="viewscreen_layer_choose_language_name" />
<class vtable="0x087131E8" name="viewscreen_setupdwarfgame" />
<class vtable="0x08713268" name="viewscreen_choose_start_site" />
</VTable>
<VTable>
<class vtable="0x086F5A08" name="item_coin" />
<class vtable="0x086F9C28" name="item_trapcomp" />
<class vtable="0x086F9F08" name="item_siegeammo" />
<class vtable="0x086F5FC8" name="item_quiver" />
<class vtable="0x086F62A8" name="item_backpack" />
<class vtable="0x086FA1E8" name="item_pants" />
<class vtable="0x086F8528" name="item_totem" />
<class vtable="0x086F33E8" name="item_anvil" />
<class vtable="0x086F6588" name="item_gem" />
<class vtable="0x086F6868" name="item_bracelet" />
<class vtable="0x086F6B48" name="item_earring" />
<class vtable="0x086F6E28" name="item_ring" />
<class vtable="0x086F7108" name="item_crown" />
<class vtable="0x086FA7A8" name="item_ammo" />
<class vtable="0x086F73E8" name="item_scepter" />
<class vtable="0x086F76C8" name="item_amulet" />
<class vtable="0x086F79A8" name="item_figurine" />
<class vtable="0x086F9668" name="item_bin" />
<class vtable="0x086F9388" name="item_box" />
<class vtable="0x086FAA88" name="item_gloves" />
<class vtable="0x086FAD68" name="item_helm" />
<class vtable="0x086FB048" name="item_shield" />
<class vtable="0x086FB328" name="item_shoes" />
<class vtable="0x086FB608" name="item_armor" />
<class vtable="0x086FB8E8" name="item_weapon" />
<class vtable="0x086FC748" name="item_animaltrap" />
<class vtable="0x086F9948" name="item_barrel" />
<class vtable="0x086FC468" name="item_cage" />
<class vtable="0x086FBBC8" name="item_toy" />
<class vtable="0x086FBEA8" name="item_instrument" />
<class vtable="0x086F7C88" name="item_goblet" />
<class vtable="0x086FCD08" name="item_flask" />
<class vtable="0x086F7F68" name="item_chain" />
<class vtable="0x086FE128" name="item_hatch_cover" />
<class vtable="0x086FDE48" name="item_floodgate" />
<class vtable="0x086FE408" name="item_door" />
<class vtable="0x086F8248" name="item_cloth" />
<class vtable="0x086D8A08" name="item_constructed" />
<class vtable="0x086FA4C8" name="item_food" />
<class vtable="0x086F3F68" name="item_crafted" />
<class vtable="0x086F90A8" name="item_thread" />
<class vtable="0x086F4AE8" name="item_cheese" />
<class vtable="0x086FCA28" name="item_ballistaarrowhead" />
<class vtable="0x086FCFE8" name="item_shell" />
<class vtable="0x086FD2C8" name="item_skull" />
<class vtable="0x086FE9C8" name="item_bones" />
<class vtable="0x086FD5A8" name="item_skin_tanned" />
<class vtable="0x086FD888" name="item_skin_raw" />
<class vtable="0x086FF828" name="item_pet" />
<class vtable="0x086FFB08" name="item_vermin" />
<class vtable="0x086F4248" name="item_fish_raw" />
<class vtable="0x086F4528" name="item_fish" />
<class vtable="0x086FEF88" name="item_meat" />
<class vtable="0x086FDB68" name="item_remains" />
<class vtable="0x086F5448" name="item_corpsepiece" />
<class vtable="0x086FECA8" name="item_glob" />
<class vtable="0x086FE6E8" name="item_liquid_misc" />
<class vtable="0x086F5CE8" name="item_powder_misc" />
<class vtable="0x086F4808" name="item_drink" />
<class vtable="0x086F4DC8" name="item_extract" />
<class vtable="0x086FF548" name="item_liquipowder" />
<class vtable="0x086F5728" name="item_corpse" />
<class vtable="0x086F36C8" name="item_wood" />
<class vtable="0x086F3C88" name="item_stone" />
<class vtable="0x086F39A8" name="item_rough" />
<class vtable="0x086F8808" name="item_blocks" />
<class vtable="0x086F8AE8" name="item_smallgem" />
<class vtable="0x086F8DC8" name="item_bar" />
<class vtable="0x086FC188" name="item_actual" />
<class vtable="0x087006E8" name="item_rock" />
<class vtable="0x087009E8" name="item_grate" />
<class vtable="0x08700CE8" name="item_window" />
<class vtable="0x08700FE8" name="item_bucket" />
<class vtable="0x087012E8" name="item_coffin" />
<class vtable="0x087015E8" name="item_statue" />
<class vtable="0x087018E8" name="item_quern" />
<class vtable="0x08701BE8" name="item_millstone" />
<class vtable="0x08701EE8" name="item_armorstand" />
<class vtable="0x087021E8" name="item_weaponrack" />
<class vtable="0x087024E8" name="item_cabinet" />
<class vtable="0x087027E8" name="item_catapultparts" />
<class vtable="0x08702AE8" name="item_ballistaparts" />
<class vtable="0x08702DE8" name="item_trapparts" />
<class vtable="0x087030E8" name="item_potion" />
<class vtable="0x087033E8" name="item_pipe_section" />
<class vtable="0x08713B48" name="item_leaves" />
<class vtable="0x087132A8" name="item_plant" />
<class vtable="0x08714108" name="item_seeds" />
<class vtable="0x0870038C" name="item_critter" />
<class vtable="0x087004A8" name="item_powder" />
<class vtable="0x08700484" name="item_liquid" />
</VTable>
</Entry>
</MemoryDescriptors>
<!-- Windows logo by M$, spiderweb by jgs -->

@ -57,6 +57,10 @@ TARGET_LINK_LIBRARIES(dfsuspend dfhack)
ADD_EXECUTABLE(dfitemdump dfitemdump.cpp)
TARGET_LINK_LIBRARIES(dfitemdump dfhack)
# customCtreatureNameProf - change the custom names and professions of creatures, sends keys to df directly
ADD_EXECUTABLE(dfcustomCreatureNameProf customCreatureNameProf.cpp)
TARGET_LINK_LIBRARIES(dfcustomCreatureNameProf dfhack)
IF(UNIX)
install(TARGETS
dfexpbench

@ -41,12 +41,14 @@ int main (void)
return 1;
}
map<string, vector<string> > names;
DF.InitReadNameTables(names);
uint32_t numCreatures = DF.InitReadCreatures();
for(uint32_t i = 0; i < numCreatures; i++)
{
t_creature temp;
DF.ReadCreature(i, temp);
cout << "creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
cout << "address: " << temp.origin << " creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
bool addendl = false;
if(temp.first_name[0])
{
@ -58,6 +60,12 @@ int main (void)
cout << ", nick name: " << temp.nick_name;
addendl = true;
}
string transName = DF.TranslateName(temp.last_name,names,creaturestypes[temp.type].id);
if(!transName.empty()){
cout << ", trans name: " << transName;
addendl=true;
}
//cout << ", generic name: " << DF.TranslateName(temp.last_name,names,"GENERIC");
/*
if(!temp.trans_name.empty()){
cout << ", trans name: " << temp.trans_name;

@ -0,0 +1,312 @@
// Creature dump
#include <iostream>
#include <sstream>
#include <climits>
#include <integers.h>
#include <vector>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
template <typename T>
void print_bits ( T val, std::ostream& out )
{
T n_bits = sizeof ( val ) * CHAR_BIT;
for ( unsigned i = 0; i < n_bits; ++i ) {
out<< !!( val & 1 ) << " ";
val >>= 1;
}
}
vector <string> buildingtypes;
map<string, vector<string> > names;
uint32_t numCreatures;
vector<t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF)
{
int dwarfCounter = 0;
for(uint32_t i = 0; i < numCreatures; i++)
{
t_creature temp;
DF.ReadCreature(i, temp);
string type = creaturestypes[temp.type].id;
if(type == "DWARF" && !temp.flags1.bits.dead && !temp.flags2.bits.killed){
cout << i << ":";
if(temp.nick_name[0])
{
cout << temp.nick_name;
}
else{
cout << temp.first_name;
}
string transName = DF.TranslateName(temp.last_name,names,creaturestypes[temp.type].id);
cout << " " << temp.custom_profession; //transName;
if(dwarfCounter%3 != 2){
cout << '\t';
}
else{
cout << endl;
}
dwarfCounter++;
}
}
}
bool getDwarfSelection(DFHack::API & DF, t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName)
{
DF.ForceResume();
static string lastText;
bool dwarfSuccess = false;
while(!dwarfSuccess)
{
string input;
cout << "\nSelect Dwarf to Change or q to Quit" << endl;
getline (cin, input);
if(input == "q")
{
return false;
}
else if(input == "r")
{
DF.Suspend();
printDwarves(DF);
DF.Resume();
}
else if(!input.empty())
{
int num;
stringstream(input) >> num;//= atol(input.c_str());
DF.Suspend();
dwarfSuccess = DF.ReadCreature(num,toChange);
DF.Resume();
string type = creaturestypes[toChange.type].id;
if(type != "DWARF"){
dwarfSuccess = false;
}
else
{
dwarfNum = num;
}
}
}
bool changeType = false;
while(!changeType)
{
string input;
cout << "\n(n)ickname or (p)rofession?" << endl;
getline(cin, input);
if(input == "q"){
return false;
}
if(input == "n"){
commandString = "pzyn";
eraseAmount = string(toChange.nick_name).length();
changeType = true;
isName = true;
}
else if(input == "p"){
commandString = "pzyp";
eraseAmount = string(toChange.custom_profession).length();
changeType = true;
isName = false;
}
}
bool changeValue = false;
while(!changeValue)
{
string input;
cout << "value to change to?" << endl;
getline(cin, input);
if(input == "q"){
return false;
}
if(!lastText.empty() && input.empty()){
changeValue = true;
}
else if( !input.empty()){
lastText = input;
changeValue = true;
}
}
changeString = lastText;
return true;
}
bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, bool isName)
{
DF.Suspend();
t_creature testCre;
DF.ReadCreature(creatureToCheck,testCre);
int tryCount = 0;
if(isName)
{
while(testCre.nick_name != changeValue && tryCount <50)
{
DF.TypeSpecial(WAIT,1,100);
DF.Suspend();
DF.ReadCreature(creatureToCheck,testCre);
tryCount++;
}
}
else
{
while(testCre.custom_profession != changeValue && tryCount < 50)
{
DF.TypeSpecial(WAIT,1,100);
DF.Suspend();
DF.ReadCreature(creatureToCheck,testCre);
tryCount++;
}
}
if(tryCount >= 50){
cerr << "Something went wrong, make sure that DF is at the correct screen";
return false;
}
return true;
}
bool waitTillScreenState(DFHack::API &DF, string screenState)
{
t_viewscreen current;
DF.Suspend();
DF.ReadViewScreen(current);
int tryCount = 0;
while(buildingtypes[current.type] != screenState && tryCount < 50){
DF.TypeSpecial(WAIT,1,100);
DF.Suspend();
DF.ReadViewScreen(current);
tryCount++;
}
if(tryCount >= 50){
cerr << "Something went wrong, DF at " << buildingtypes[current.type] << endl;
return false;
}
return true;
}
bool waitTillCursorState(DFHack::API &DF, bool On)
{
int32_t x,y,z;
int tryCount = 0;
DF.Suspend();
bool cursorResult = DF.getCursorCoords(x,y,z);
while(tryCount < 50 && On && !cursorResult || !On && cursorResult)
{
DF.TypeSpecial(WAIT,1,100);
tryCount++;
DF.Suspend();
cursorResult = DF.getCursorCoords(x,y,z);
}
if(tryCount >= 50)
{
cerr << "Something went wrong, cursor at x: " << x << " y: " << y << " z: " << z << endl;
return false;
}
return true;
}
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
//Need buildingtypes for the viewscreen vtables, this really should not be just buildings, as viewscreen and items both use the same interface
uint32_t numBuildings = DF.InitReadBuildings(buildingtypes);
DFHack::memory_info mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
}
DF.InitReadNameTables(names);
numCreatures = DF.InitReadCreatures();
DF.InitViewAndCursor();
DF.Suspend();
printDwarves(DF);
t_creature toChange;
string changeString,commandString;
int eraseAmount;
int toChangeNum;
bool isName;
while(getDwarfSelection(DF,toChange,changeString,commandString,eraseAmount,toChangeNum,isName))
{
bool completed = false;
int32_t x,y,z;
DF.Suspend();
DF.getCursorCoords(x,y,z);
if(x == -30000)// cursor not displayed
{
DF.TypeStr("v");
}
if(waitTillCursorState(DF,true))
{
DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
vector<uint32_t> underCursor;
while(!DF.getCurrentCursorCreatures(underCursor))
{
DF.TypeSpecial(WAIT,1,100);
DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
}
//CurrentCursorCreatures gives the creatures in the order that you see them with the 'k' cursor.
//The 'v' cursor displays them in the order of last, then first,second,third and so on
//Pretty weird, but it works
//The only place that seems to display which creature is currently selected is on the stack, whose location is likely not static, so not usable
if(underCursor[underCursor.size()-1] != toChange.origin)
{
for(int i = 0;i<underCursor.size()-1;i++)
{
DF.TypeStr("v",100);
if(underCursor[i] == toChange.origin)
{
break;
}
}
}
DF.Resume();
DF.TypeStr(commandString.c_str());
if(waitTillScreenState(DF,"viewscreen_customize_unit"))
{
DF.TypeSpecial(BACK_SPACE,eraseAmount);
if(waitTillChanged(DF,toChangeNum,"",isName))
{
DF.TypeStr(changeString.c_str());
if(waitTillChanged(DF,toChangeNum,changeString,isName))
{
DF.TypeSpecial(ENTER);
DF.TypeSpecial(SPACE); // should take you to unit screen if everything worked
if(waitTillScreenState(DF,"viewscreen_unit"))
{
DF.TypeSpecial(SPACE);
if(waitTillScreenState(DF,"viewscreen_dwarfmode"))
{
DF.TypeSpecial(SPACE);
if(waitTillCursorState(DF,false))
{
completed = true;
}
}
}
}
}
}
}
if(!completed){
cerr << "Something went wrong, please reset DF to its original state, then press any key to continue" << endl;
string line;
DF.Resume();
getline(cin, line);
}
DF.Suspend();
printDwarves(DF);
}
return 0;
}

@ -68,7 +68,8 @@ int main ()
cerr << "DF not found" << endl;
return 1;
}
matGlosses mat;
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);