Common base for all modules

develop
Petr Mrázek 2010-06-25 07:11:26 +02:00
parent 3c458f4701
commit ec35663b62
25 changed files with 951 additions and 840 deletions

@ -3,7 +3,7 @@ INCLUDE(CPack)
PROJECT (dfhack) PROJECT (dfhack)
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules) SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/CMake/Modules)
SET ( DFHACK_VERSION "0.4.0.2" ) SET ( DFHACK_VERSION "0.4.0.3-dev" )
# disable warning, autosearch # disable warning, autosearch
if(COMMAND cmake_policy) if(COMMAND cmake_policy)
@ -30,6 +30,7 @@ include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/)
include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/) include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/)
add_subdirectory (library) add_subdirectory (library)
add_subdirectory (library/shm)
#add_subdirectory (dfhack/python) #add_subdirectory (dfhack/python)
add_subdirectory (tools/examples) add_subdirectory (tools/examples)
add_subdirectory (tools/playground) add_subdirectory (tools/playground)

@ -168,61 +168,3 @@ IF(UNIX)
install(TARGETS dfhack LIBRARY DESTINATION lib) install(TARGETS dfhack LIBRARY DESTINATION lib)
install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack) install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack)
ENDIF(UNIX) ENDIF(UNIX)
################################################################################
# DFCONNECT
###
SET(DFCONNECT_HDRS
shm/shms.h
shm/mod-core.h
shm/mod-maps.h
)
SET(PROJECT_SRCS
shm/mod-core.cpp
shm/mod-maps.cpp
#mod-creature40d.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
)
SET(PROJECT_SRCS_LINUX
shm/shms-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
shm/shms-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
#IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
SET(PROJECT_LIBS rt)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS})
ELSE(UNIX)
# SET(PROJECT_LIBS psapi)
ADD_LIBRARY(SDL SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(SDL ${PROJECT_LIBS})
ENDIF(UNIX)
#ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)

@ -24,33 +24,18 @@ using namespace DFHack;
DFContextShared::DFContextShared() DFContextShared::DFContextShared()
{ {
// init modules // init modules
creatures = 0; allModules.clear();
maps = 0; memset(&(s_mods), 0, sizeof(s_mods));
position = 0;
gui = 0;
world = 0;
materials = 0;
translation = 0;
vegetation = 0;
buildings = 0;
constructions = 0;
items = 0;
windowio = 0;
} }
DFContextShared::~DFContextShared() DFContextShared::~DFContextShared()
{ {
if(creatures) delete creatures; // invalidate all modules
if(maps) delete maps; for(int i = 0 ; i < allModules.size(); i++)
if(position) delete position; {
if(gui) delete gui; delete allModules[i];
if(materials) delete materials; }
if(translation) delete translation; allModules.clear();
if(vegetation) delete vegetation;
if(buildings) delete buildings;
if(constructions) delete constructions;
if(world) delete world;
if(windowio) delete windowio;
} }
bool DFContextShared::InitReadNames() bool DFContextShared::InitReadNames()

@ -27,7 +27,6 @@ distribution.
#include "dfhack/DFProcess.h" #include "dfhack/DFProcess.h"
#include "dfhack/DFProcessEnumerator.h" #include "dfhack/DFProcessEnumerator.h"
#include "dfhack/DFContext.h" #include "dfhack/DFContext.h"
#include "dfhack/DFContext.h"
#include "dfhack/DFError.h" #include "dfhack/DFError.h"
#include <shms.h> #include <shms.h>
@ -93,6 +92,13 @@ bool Context::Detach()
} }
d->shm_start = 0; d->shm_start = 0;
// invalidate all modules // invalidate all modules
for(int i = 0 ; i < d->allModules.size(); i++)
{
delete d->allModules[i];
}
d->allModules.clear();
memset(&(d->s_mods), 0, sizeof(d->s_mods));
/*
if(d->creatures) if(d->creatures)
{ {
delete d->creatures; delete d->creatures;
@ -147,7 +153,7 @@ bool Context::Detach()
{ {
delete d->translation; delete d->translation;
d->translation = 0; d->translation = 0;
} }*/
return true; return true;
} }
@ -201,13 +207,39 @@ Process * Context::getProcess()
/******************************************************************************* /*******************************************************************************
M O D U L E S M O D U L E S
*******************************************************************************/ *******************************************************************************/
#define MODULE_GETTER(TYPE) \
TYPE * Context::get##TYPE() \
{ \
if(!d->s_mods.p##TYPE)\
{\
d->s_mods.p##TYPE = new TYPE(d);\
d->allModules.push_back(d->s_mods.p##TYPE);\
}\
return d->s_mods.p##TYPE;\
}
MODULE_GETTER(Creatures);
MODULE_GETTER(Maps);
MODULE_GETTER(Gui);
MODULE_GETTER(WindowIO);
MODULE_GETTER(World);
MODULE_GETTER(Position);
MODULE_GETTER(Materials);
MODULE_GETTER(Items);
MODULE_GETTER(Translation);
MODULE_GETTER(Vegetation);
MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions);
/*
Creatures * Context::getCreatures() Creatures * Context::getCreatures()
{ {
if(!d->creatures) if(!d->creatures)
d->creatures = new Creatures(d); d->creatures = new Creatures(d);
return d->creatures; return d->creatures;
} }
*/
/*
Maps * Context::getMaps() Maps * Context::getMaps()
{ {
if(!d->maps) if(!d->maps)
@ -284,7 +316,7 @@ Constructions * Context::getConstructions()
d->constructions = new Constructions(d); d->constructions = new Constructions(d);
return d->constructions; return d->constructions;
} }
*/
/* /*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name // returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name

@ -240,7 +240,7 @@ DFHackObject* Context_getWindow(DFHackObject* context)
{ {
if(context != NULL) if(context != NULL)
{ {
return (DFHackObject*)((DFHack::Context*)context)->getWindow(); return (DFHackObject*)((DFHack::Context*)context)->getWindowIO();
} }
return NULL; return NULL;

@ -1,6 +1,16 @@
#ifndef DFHACK_API_H #ifndef DFHACK_API_H
#define DFHACK_API_H #define DFHACK_API_H
// Defines
#ifdef __GNUC__
#define DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif
// DFHack core classes and types // DFHack core classes and types
#include "dfhack/DFIntegers.h" #include "dfhack/DFIntegers.h"
#include "dfhack/DFGlobal.h" #include "dfhack/DFGlobal.h"

@ -113,7 +113,7 @@ namespace DFHack
Constructions * getConstructions(); Constructions * getConstructions();
/// get the Window management and I/O module /// get the Window management and I/O module
WindowIO * getWindow(); WindowIO * getWindowIO();
// DEAD CODE, WAITING TO BE UPDATED TO DF2010 // DEAD CODE, WAITING TO BE UPDATED TO DF2010
/* /*

@ -0,0 +1,45 @@
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef MODULE_H_INCLUDED
#define MODULE_H_INCLUDED
#include "DFExport.h"
namespace DFHack
{
class Context;
class DFHACK_EXPORT Module
{
public:
~Module(){};
virtual bool Start(){return true;};// default start...
virtual bool Finish() = 0;// everything should have a Finish()
virtual bool doFinishOnResume(){return true;}; // should Context call Finish when Resume is called?
virtual bool doFinishOnMapChange(){return false;}; // Finish when map change is detected?
virtual bool doFinishOnDetach(){return false;}; // Finish in Context::Detach?
};
}
#endif //MODULE_H_INCLUDED

@ -4,6 +4,7 @@
* Buildings - also includes zones and stockpiles * Buildings - also includes zones and stockpiles
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
struct t_building struct t_building
@ -26,7 +27,7 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT Buildings class DFHACK_EXPORT Buildings : public Module
{ {
public: public:
Buildings(DFContextShared * d); Buildings(DFContextShared * d);

@ -4,6 +4,7 @@
* DF constructions * DF constructions
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
// type of item the construction is made of // type of item the construction is made of
@ -40,7 +41,7 @@ namespace DFHack
}; };
#pragma pack (pop) #pragma pack (pop)
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT Constructions class DFHACK_EXPORT Constructions : public Module
{ {
public: public:
Constructions(DFContextShared * d); Constructions(DFContextShared * d);

@ -4,397 +4,398 @@
* Creatures * Creatures
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
/* /*
bits: bits:
0 Can the dwarf move or are they waiting for their movement timer 0 Can the dwarf move or are they waiting for their movement timer
1 Dead (might also be set for incoming/leaving critters that are alive) 1 Dead (might also be set for incoming/leaving critters that are alive)
2 Currently in mood 2 Currently in mood
3 Had a mood 3 Had a mood
4 "marauder" -- wide class of invader/inside creature attackers 4 "marauder" -- wide class of invader/inside creature attackers
5 Drowning 5 Drowning
6 Active merchant 6 Active merchant
7 "forest" (used for units no longer linked to merchant/diplomacy, they just try to leave mostly) 7 "forest" (used for units no longer linked to merchant/diplomacy, they just try to leave mostly)
8 Left (left the map) 8 Left (left the map)
9 Rider 9 Rider
10 Incoming 10 Incoming
11 Diplomat 11 Diplomat
12 Zombie 12 Zombie
13 Skeleton 13 Skeleton
14 Can swap tiles during movement (prevents multiple swaps) 14 Can swap tiles during movement (prevents multiple swaps)
15 On the ground (can be conscious) 15 On the ground (can be conscious)
16 Projectile 16 Projectile
17 Active invader (for organized ones) 17 Active invader (for organized ones)
18 Hidden in ambush 18 Hidden in ambush
19 Invader origin (could be inactive and fleeing) 19 Invader origin (could be inactive and fleeing)
20 Will flee if invasion turns around 20 Will flee if invasion turns around
21 Active marauder/invader moving inward 21 Active marauder/invader moving inward
22 Marauder resident/invader moving in all the way 22 Marauder resident/invader moving in all the way
23 Check against flows next time you get a chance 23 Check against flows next time you get a chance
24 Ridden 24 Ridden
25 Caged 25 Caged
26 Tame 26 Tame
27 Chained 27 Chained
28 Royal guard 28 Royal guard
29 Fortress guard 29 Fortress guard
30 Suppress wield for beatings/etc 30 Suppress wield for beatings/etc
31 Is an important historical figure 31 Is an important historical figure
*/ */
struct naked_creaturflags1 struct naked_creaturflags1
{ {
unsigned int move_state : 1; // Can the dwarf move or are they waiting for their movement timer unsigned int move_state : 1; // Can the dwarf move or are they waiting for their movement timer
unsigned int dead : 1; // might also be set for incoming/leaving critters that are alive unsigned int dead : 1; // might also be set for incoming/leaving critters that are alive
unsigned int has_mood : 1; // Currently in mood unsigned int has_mood : 1; // Currently in mood
unsigned int had_mood : 1; // Had a mood unsigned int had_mood : 1; // Had a mood
unsigned int marauder : 1; // wide class of invader/inside creature attackers unsigned int marauder : 1; // wide class of invader/inside creature attackers
unsigned int drowning : 1; unsigned int drowning : 1;
unsigned int merchant : 1; // active merchant unsigned int merchant : 1; // active merchant
unsigned int forest : 1; // used for units no longer linked to merchant/diplomacy, they just try to leave mostly unsigned int forest : 1; // used for units no longer linked to merchant/diplomacy, they just try to leave mostly
unsigned int left : 1; // left the map unsigned int left : 1; // left the map
unsigned int rider : 1; unsigned int rider : 1;
unsigned int incoming : 1; unsigned int incoming : 1;
unsigned int diplomat : 1; unsigned int diplomat : 1;
unsigned int zombie : 1; unsigned int zombie : 1;
unsigned int skeleton : 1; unsigned int skeleton : 1;
unsigned int can_swap : 1; // Can swap tiles during movement (prevents multiple swaps) unsigned int can_swap : 1; // Can swap tiles during movement (prevents multiple swaps)
unsigned int on_ground : 1; // can be conscious unsigned int on_ground : 1; // can be conscious
unsigned int projectile : 1; unsigned int projectile : 1;
unsigned int active_invader : 1; // for organized ones unsigned int active_invader : 1; // for organized ones
unsigned int hidden_in_ambush : 1; unsigned int hidden_in_ambush : 1;
unsigned int invader_origin : 1; // could be inactive and fleeing unsigned int invader_origin : 1; // could be inactive and fleeing
unsigned int coward : 1; // Will flee if invasion turns around unsigned int coward : 1; // Will flee if invasion turns around
unsigned int hidden_ambusher : 1; // maybe unsigned int hidden_ambusher : 1; // maybe
unsigned int invades : 1; // Active marauder/invader moving inward unsigned int invades : 1; // Active marauder/invader moving inward
unsigned int check_flows : 1; // Check against flows next time you get a chance unsigned int check_flows : 1; // Check against flows next time you get a chance
// 0100 0000 - 8000 0000 // 0100 0000 - 8000 0000
unsigned int ridden : 1; unsigned int ridden : 1;
unsigned int caged : 1; unsigned int caged : 1;
unsigned int tame : 1; unsigned int tame : 1;
unsigned int chained : 1; unsigned int chained : 1;
unsigned int royal_guard : 1; unsigned int royal_guard : 1;
unsigned int fortress_guard : 1; unsigned int fortress_guard : 1;
unsigned int suppress_wield : 1; // Suppress wield for beatings/etc unsigned int suppress_wield : 1; // Suppress wield for beatings/etc
unsigned int important_historical_figure : 1; // Is an important historical figure unsigned int important_historical_figure : 1; // Is an important historical figure
}; };
union t_creaturflags1 union t_creaturflags1
{ {
uint32_t whole; uint32_t whole;
naked_creaturflags1 bits; naked_creaturflags1 bits;
}; };
/* /*
bits: bits:
0 Swimming 0 Swimming
1 Play combat for sparring 1 Play combat for sparring
2 Do not notify about level gains (for embark etc) 2 Do not notify about level gains (for embark etc)
3 Unused 3 Unused
4 Nerves calculated 4 Nerves calculated
5 Body part info calculated 5 Body part info calculated
6 Is important historical figure (slight variation) 6 Is important historical figure (slight variation)
7 Has been killed by kill function (slightly different from dead, not necessarily violent death) 7 Has been killed by kill function (slightly different from dead, not necessarily violent death)
8 Must be forgotten by forget function (just cleanup) 8 Must be forgotten by forget function (just cleanup)
9 Must be deleted (cleanup) 9 Must be deleted (cleanup)
10 Recently forgotten (cleanup) 10 Recently forgotten (cleanup)
11 Offered for trade 11 Offered for trade
12 Trade resolved 12 Trade resolved
13 Has breaks 13 Has breaks
14 Gutted 14 Gutted
15 Circulatory spray 15 Circulatory spray
16 Locked in for trading (it's a projectile on the other set of flags, might be what the flying was) 16 Locked in for trading (it's a projectile on the other set of flags, might be what the flying was)
17 Marked for slaughter 17 Marked for slaughter
18 Underworld creature 18 Underworld creature
19 Current resident 19 Current resident
20 Marked for special cleanup as unused load from unit block on disk 20 Marked for special cleanup as unused load from unit block on disk
21 Insulation from clothing calculated 21 Insulation from clothing calculated
22 Uninvited guest 22 Uninvited guest
23 Visitor 23 Visitor
24 Inventory order calculated 24 Inventory order calculated
25 Vision -- have good part 25 Vision -- have good part
26 Vision -- have damaged part 26 Vision -- have damaged part
27 Vision -- have missing part 27 Vision -- have missing part
28 Breathing -- have good part 28 Breathing -- have good part
29 Breathing -- having a problem 29 Breathing -- having a problem
30 Roaming wilderness population source 30 Roaming wilderness population source
31 Roaming wilderness population source -- not a map feature 31 Roaming wilderness population source -- not a map feature
*/ */
struct naked_creaturflags2 struct naked_creaturflags2
{ {
unsigned int swimming : 1; unsigned int swimming : 1;
unsigned int sparring : 1; unsigned int sparring : 1;
unsigned int no_notify : 1; // Do not notify about level gains (for embark etc) unsigned int no_notify : 1; // Do not notify about level gains (for embark etc)
unsigned int unused : 1; unsigned int unused : 1;
unsigned int calculated_nerves : 1; unsigned int calculated_nerves : 1;
unsigned int calculated_bodyparts : 1; unsigned int calculated_bodyparts : 1;
unsigned int important_historical_figure : 1; // slight variation unsigned int important_historical_figure : 1; // slight variation
unsigned int killed : 1; // killed by kill() function unsigned int killed : 1; // killed by kill() function
unsigned int cleanup_1 : 1; // Must be forgotten by forget function (just cleanup) unsigned int cleanup_1 : 1; // Must be forgotten by forget function (just cleanup)
unsigned int cleanup_2 : 1; // Must be deleted (cleanup) unsigned int cleanup_2 : 1; // Must be deleted (cleanup)
unsigned int cleanup_3 : 1; // Recently forgotten (cleanup) unsigned int cleanup_3 : 1; // Recently forgotten (cleanup)
unsigned int for_trade : 1; // Offered for trade unsigned int for_trade : 1; // Offered for trade
unsigned int trade_resolved : 1; unsigned int trade_resolved : 1;
unsigned int has_breaks : 1; unsigned int has_breaks : 1;
unsigned int gutted : 1; unsigned int gutted : 1;
unsigned int circulatory_spray : 1; unsigned int circulatory_spray : 1;
unsigned int locked_in_for_trading : 1; unsigned int locked_in_for_trading : 1;
unsigned int slaughter : 1; // marked for slaughter unsigned int slaughter : 1; // marked for slaughter
unsigned int underworld : 1; // Underworld creature unsigned int underworld : 1; // Underworld creature
unsigned int resident : 1; // Current resident unsigned int resident : 1; // Current resident
unsigned int cleanup_4 : 1; // Marked for special cleanup as unused load from unit block on disk unsigned int cleanup_4 : 1; // Marked for special cleanup as unused load from unit block on disk
unsigned int calculated_insulation : 1; // Insulation from clothing calculated unsigned int calculated_insulation : 1; // Insulation from clothing calculated
unsigned int visitor_uninvited : 1; // Uninvited guest unsigned int visitor_uninvited : 1; // Uninvited guest
unsigned int visitor : 1; // visitor unsigned int visitor : 1; // visitor
unsigned int calculated_inventory : 1; // Inventory order calculated unsigned int calculated_inventory : 1; // Inventory order calculated
unsigned int vision_good : 1; // Vision -- have good part unsigned int vision_good : 1; // Vision -- have good part
unsigned int vision_damaged : 1; // Vision -- have damaged part unsigned int vision_damaged : 1; // Vision -- have damaged part
unsigned int vision_missing : 1; // Vision -- have missing part unsigned int vision_missing : 1; // Vision -- have missing part
unsigned int breathing_good : 1; // Breathing -- have good part unsigned int breathing_good : 1; // Breathing -- have good part
unsigned int breathing_problem : 1; // Breathing -- having a problem unsigned int breathing_problem : 1; // Breathing -- having a problem
unsigned int roaming_wilderness_population_source : 1; unsigned int roaming_wilderness_population_source : 1;
unsigned int roaming_wilderness_population_source_not_a_map_feature : 1; unsigned int roaming_wilderness_population_source_not_a_map_feature : 1;
}; };
union t_creaturflags2 union t_creaturflags2
{ {
uint32_t whole; uint32_t whole;
naked_creaturflags2 bits; naked_creaturflags2 bits;
}; };
/* /*
struct t_labor struct t_labor
{ {
string name; string name;
uint8_t value; uint8_t value;
t_labor() { t_labor() {
value =0; value =0;
} }
t_labor(const t_labor & b){ t_labor(const t_labor & b){
name=b.name; name=b.name;
value=b.value; value=b.value;
} }
t_labor & operator=(const t_labor &b){ t_labor & operator=(const t_labor &b){
name=b.name; name=b.name;
value=b.value; value=b.value;
return *this; return *this;
} }
}; };
struct t_skill struct t_skill
{ {
string name; string name;
uint16_t id; uint16_t id;
uint32_t experience; uint32_t experience;
uint16_t rating; uint16_t rating;
t_skill(){ t_skill(){
id=rating=0; id=rating=0;
experience=0; experience=0;
} }
t_skill(const t_skill & b) t_skill(const t_skill & b)
{ {
name=b.name; name=b.name;
id=b.id; id=b.id;
experience=b.experience; experience=b.experience;
rating=b.rating; rating=b.rating;
} }
t_skill & operator=(const t_skill &b) t_skill & operator=(const t_skill &b)
{ {
name=b.name; name=b.name;
id=b.id; id=b.id;
experience=b.experience; experience=b.experience;
rating=b.rating; rating=b.rating;
return *this; return *this;
} }
}; };
struct t_trait struct t_trait
{ {
uint16_t value; uint16_t value;
string displayTxt; string displayTxt;
string name; string name;
t_trait(){ t_trait(){
value=0; value=0;
} }
t_trait(const t_trait &b) t_trait(const t_trait &b)
{ {
name=b.name; name=b.name;
displayTxt=b.displayTxt; displayTxt=b.displayTxt;
value=b.value; value=b.value;
} }
t_trait & operator=(const t_trait &b) t_trait & operator=(const t_trait &b)
{ {
name=b.name; name=b.name;
displayTxt=b.displayTxt; displayTxt=b.displayTxt;
value=b.value; value=b.value;
return *this; return *this;
} }
}; };
*/ */
struct t_skill struct t_skill
{ {
uint32_t id; uint32_t id;
uint32_t rating; uint32_t rating;
uint32_t experience; uint32_t experience;
}; };
struct t_job struct t_job
{ {
bool active; bool active;
uint32_t jobId; uint32_t jobId;
uint8_t jobType; uint8_t jobType;
uint32_t occupationPtr; uint32_t occupationPtr;
}; };
struct t_like struct t_like
{ {
int16_t type; int16_t type;
int16_t itemClass; int16_t itemClass;
int16_t itemIndex; int16_t itemIndex;
t_matglossPair material; t_matglossPair material;
bool active; bool active;
}; };
// FIXME: define in Memory.xml instead? // FIXME: define in Memory.xml instead?
#define NUM_CREATURE_TRAITS 30 #define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102 #define NUM_CREATURE_LABORS 102
#define NUM_CREATURE_MENTAL_ATTRIBUTES 13 #define NUM_CREATURE_MENTAL_ATTRIBUTES 13
#define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6 #define NUM_CREATURE_PHYSICAL_ATTRIBUTES 6
struct t_soul struct t_soul
{ {
uint8_t numSkills; uint8_t numSkills;
t_skill skills[256]; t_skill skills[256];
/* /*
uint8_t numLikes; uint8_t numLikes;
t_like likes[32]; t_like likes[32];
*/ */
uint16_t traits[NUM_CREATURE_TRAITS]; uint16_t traits[NUM_CREATURE_TRAITS];
t_attrib analytical_ability; t_attrib analytical_ability;
t_attrib focus; t_attrib focus;
t_attrib willpower; t_attrib willpower;
t_attrib creativity; t_attrib creativity;
t_attrib intuition; t_attrib intuition;
t_attrib patience; t_attrib patience;
t_attrib memory; t_attrib memory;
t_attrib linguistic_ability; t_attrib linguistic_ability;
t_attrib spatial_sense; t_attrib spatial_sense;
t_attrib musicality; t_attrib musicality;
t_attrib kinesthetic_sense; t_attrib kinesthetic_sense;
t_attrib empathy; t_attrib empathy;
t_attrib social_awareness; t_attrib social_awareness;
}; };
#define MAX_COLORS 15 #define MAX_COLORS 15
struct t_creature struct t_creature
{ {
uint32_t origin; uint32_t origin;
uint16_t x; uint16_t x;
uint16_t y; uint16_t y;
uint16_t z; uint16_t z;
uint32_t race; uint32_t race;
int32_t civ; int32_t civ;
t_creaturflags1 flags1; t_creaturflags1 flags1;
t_creaturflags2 flags2; t_creaturflags2 flags2;
t_name name; t_name name;
int16_t mood; int16_t mood;
int16_t mood_skill; int16_t mood_skill;
t_name artifact_name; t_name artifact_name;
uint8_t profession; uint8_t profession;
char custom_profession[128]; char custom_profession[128];
// enabled labors // enabled labors
uint8_t labors[NUM_CREATURE_LABORS]; uint8_t labors[NUM_CREATURE_LABORS];
t_job current_job; t_job current_job;
uint32_t happiness; uint32_t happiness;
uint32_t id; uint32_t id;
t_attrib strength; t_attrib strength;
t_attrib agility; t_attrib agility;
t_attrib toughness; t_attrib toughness;
t_attrib endurance; t_attrib endurance;
t_attrib recuperation; t_attrib recuperation;
t_attrib disease_resistance; t_attrib disease_resistance;
int32_t squad_leader_id; int32_t squad_leader_id;
uint8_t sex; uint8_t sex;
uint16_t caste; uint16_t caste;
uint32_t pregnancy_timer; //Countdown timer to giving birth uint32_t pregnancy_timer; //Countdown timer to giving birth
bool has_default_soul; bool has_default_soul;
t_soul defaultSoul; t_soul defaultSoul;
uint32_t nbcolors; uint32_t nbcolors;
uint32_t color[MAX_COLORS]; uint32_t color[MAX_COLORS];
uint32_t birth_year; uint32_t birth_year;
uint32_t birth_time; uint32_t birth_time;
}; };
class DFContextShared; class DFContextShared;
struct t_creature; struct t_creature;
class DFHACK_EXPORT Creatures class DFHACK_EXPORT Creatures : public Module
{ {
public: public:
Creatures(DFHack::DFContextShared * d); Creatures(DFHack::DFContextShared * d);
~Creatures(); ~Creatures();
bool Start( uint32_t & numCreatures); bool Start( uint32_t & numCreatures );
bool Finish(); bool Finish();
/* Read Functions */ /* Read Functions */
// Read creatures in a box, starting with index. Returns -1 if no more creatures // Read creatures in a box, starting with index. Returns -1 if no more creatures
// found. Call repeatedly do get all creatures in a specified box (uses tile coords) // found. Call repeatedly do get all creatures in a specified box (uses tile coords)
int32_t ReadCreatureInBox(const int32_t index, t_creature & furball, int32_t ReadCreatureInBox(const int32_t index, t_creature & furball,
const uint16_t x1, const uint16_t y1,const uint16_t z1, const uint16_t x1, const uint16_t y1,const uint16_t z1,
const uint16_t x2, const uint16_t y2,const uint16_t z2); const uint16_t x2, const uint16_t y2,const uint16_t z2);
bool ReadCreature(const int32_t index, t_creature & furball); bool ReadCreature(const int32_t index, t_creature & furball);
bool ReadJob(const t_creature * furball, std::vector<t_material> & mat); bool ReadJob(const t_creature * furball, std::vector<t_material> & mat);
/* Getters */ /* Getters */
uint32_t GetDwarfRaceIndex ( void ); uint32_t GetDwarfRaceIndex ( void );
int32_t GetDwarfCivId ( void ); int32_t GetDwarfCivId ( void );
/* Write Functions */ /* Write Functions */
// write labors of a creature (for Dwarf Therapist) // write labors of a creature (for Dwarf Therapist)
bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]); bool WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LABORS]);
bool WriteHappiness(const uint32_t index, const uint32_t happinessValue); bool WriteHappiness(const uint32_t index, const uint32_t happinessValue);
bool WriteFlags(const uint32_t index, const uint32_t flags1, const uint32_t flags2); bool WriteFlags(const uint32_t index, const uint32_t flags1, const uint32_t flags2);
bool WriteSkills(const uint32_t index, const t_soul &soul); bool WriteSkills(const uint32_t index, const t_soul &soul);
bool WriteAttributes(const uint32_t index, const t_creature &creature); bool WriteAttributes(const uint32_t index, const t_creature &creature);
bool WriteSex(const uint32_t index, const uint8_t sex); bool WriteSex(const uint32_t index, const uint8_t sex);
bool WriteTraits(const uint32_t index, const t_soul &soul); bool WriteTraits(const uint32_t index, const t_soul &soul);
bool WriteMood(const uint32_t index, const uint16_t mood); bool WriteMood(const uint32_t index, const uint16_t mood);
bool WriteMoodSkill(const uint32_t index, const uint16_t moodSkill); bool WriteMoodSkill(const uint32_t index, const uint16_t moodSkill);
bool WritePos(const uint32_t index, const t_creature &creature); bool WritePos(const uint32_t index, const t_creature &creature);
bool WriteCiv(const uint32_t index, const int32_t civ); bool WriteCiv(const uint32_t index, const int32_t civ);
private: private:
struct Private; struct Private;
Private *d; Private *d;
}; };
} }
#endif #endif

@ -5,12 +5,13 @@
* Gui: Query the DF's GUI state * Gui: Query the DF's GUI state
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
struct t_viewscreen; struct t_viewscreen;
class DFHACK_EXPORT Gui class DFHACK_EXPORT Gui: public Module
{ {
public: public:

@ -4,89 +4,39 @@
* Creatures * Creatures
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class Context; class Context;
class DFContextShared; class DFContextShared;
enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
class DFHACK_EXPORT Accessor
{
private:
accessor_type type;
int32_t constant;
uint32_t offset1;
uint32_t offset2;
Process * p;
uint32_t dataWidth;
public:
Accessor(uint32_t function, Process * p);
Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p);
int32_t getValue(uint32_t objectPtr);
bool isConstant();
};
struct t_item struct t_item
{ {
t_material matdesc; t_material matdesc;
int32_t quantity; int32_t quantity;
int32_t quality; int32_t quality;
}; };
struct t_improvement struct t_improvement
{ {
t_material matdesc; t_material matdesc;
int32_t quality; int32_t quality;
};
class DFHACK_EXPORT ItemImprovementDesc
{
private:
Accessor * AType;
Process * p;
public:
ItemImprovementDesc(uint32_t VTable, Process * p);
bool getImprovement(uint32_t descptr, t_improvement & imp);
uint32_t vtable;
uint32_t maintype;
};
class DFHACK_EXPORT ItemDesc
{
private:
Accessor * AMainType;
Accessor * ASubType;
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
Process * p;
bool hasDecoration;
public:
ItemDesc(uint32_t VTable, Process * p);
bool getItem(uint32_t itemptr, t_item & item);
std::string className;
uint32_t vtable;
uint32_t mainType;
std::vector<ItemImprovementDesc> improvement;
}; };
class DFHACK_EXPORT Items class DFHACK_EXPORT Items : public Module
{ {
public: public:
Items(DFContextShared * _d); Items(DFContextShared * _d);
~Items(); ~Items();
std::string getItemDescription(uint32_t itemptr, Materials * Materials); bool Start();
std::string getItemClass(int32_t index); bool Finish();
bool getItemData(uint32_t itemptr, t_item & item); std::string getItemDescription(uint32_t itemptr, Materials * Materials);
std::string getItemClass(int32_t index);
bool getItemData(uint32_t itemptr, t_item & item);
private: private:
class Private; class Private;
Private* d; Private* d;
std::map<int32_t, ItemDesc *> descType;
std::map<uint32_t, ItemDesc *> descVTable;
}; };
} }
#endif #endif

@ -6,6 +6,7 @@
#define CL_MOD_MAPS #define CL_MOD_MAPS
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
/*************************************************************************** /***************************************************************************
@ -304,10 +305,10 @@ namespace DFHack
/*************************************************************************** /***************************************************************************
C L I E N T M O D U L E C L I E N T M O D U L E
***************************************************************************/ ***************************************************************************/
#ifndef BUILD_SHM
class DFContextShared; class DFContextShared;
struct t_viewscreen; struct t_viewscreen;
class DFHACK_EXPORT Maps class DFHACK_EXPORT Maps : public Module
{ {
public: public:
@ -422,5 +423,6 @@ namespace DFHack
struct Private; struct Private;
Private *d; Private *d;
}; };
#endif
} }
#endif #endif

@ -1,9 +1,10 @@
#ifndef CL_MOD_MATERIALS #ifndef CL_MOD_MATERIALS
#define CL_MOD_MATERIALS #define CL_MOD_MATERIALS
/* /*
* Creatures * Materials
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
@ -116,11 +117,12 @@ namespace DFHack
uint32_t flags; uint32_t flags;
}; };
class DFHACK_EXPORT Materials class DFHACK_EXPORT Materials : public Module
{ {
public: public:
Materials(DFHack::DFContextShared * _d); Materials(DFHack::DFContextShared * _d);
~Materials(); ~Materials();
bool Finish();
std::vector<t_matgloss> inorganic; std::vector<t_matgloss> inorganic;
std::vector<t_matgloss> organic; std::vector<t_matgloss> organic;

@ -4,6 +4,7 @@
* View position and size and cursor position * View position and size and cursor position
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
#define NUM_HOTKEYS 16 #define NUM_HOTKEYS 16
@ -17,12 +18,13 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT Position class DFHACK_EXPORT Position : public Module
{ {
public: public:
Position(DFContextShared * d); Position(DFContextShared * d);
~Position(); ~Position();
bool Finish(){return true;};
/* /*
* Cursor and window coords * Cursor and window coords
*/ */

@ -4,6 +4,7 @@
* DF translation tables and name translation * DF translation tables and name translation
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
@ -14,7 +15,7 @@ namespace DFHack
DFDict foreign_languages; DFDict foreign_languages;
} Dicts; } Dicts;
class DFHACK_EXPORT Translation class DFHACK_EXPORT Translation : public Module
{ {
public: public:
Translation(DFContextShared * d); Translation(DFContextShared * d);

@ -4,6 +4,7 @@
* DF vegetation - stuff that grows and gets cut down or trampled by dwarves * DF vegetation - stuff that grows and gets cut down or trampled by dwarves
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
/* /*
@ -28,7 +29,7 @@ namespace DFHack
}; };
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT Vegetation class DFHACK_EXPORT Vegetation : public Module
{ {
public: public:
Vegetation(DFContextShared * d); Vegetation(DFContextShared * d);

@ -27,6 +27,7 @@ distribution.
#include "dfhack/DFPragma.h" #include "dfhack/DFPragma.h"
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
@ -88,12 +89,13 @@ enum t_special
NUM_SPECIALS NUM_SPECIALS
}; };
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT WindowIO class DFHACK_EXPORT WindowIO : public Module
{ {
class Private; class Private;
private: private:
Private * d; Private * d;
public: public:
bool Finish(){return true;};
WindowIO(DFHack::DFContextShared * d); WindowIO(DFHack::DFContextShared * d);
~WindowIO(); ~WindowIO();
void TypeStr (const char *input, int delay = 0, bool useShift = false); void TypeStr (const char *input, int delay = 0, bool useShift = false);

@ -5,11 +5,12 @@
* World: all kind of stuff related to the current world state * World: all kind of stuff related to the current world state
*/ */
#include "dfhack/DFExport.h" #include "dfhack/DFExport.h"
#include "dfhack/DFModule.h"
namespace DFHack namespace DFHack
{ {
class DFContextShared; class DFContextShared;
class DFHACK_EXPORT World class DFHACK_EXPORT World : public Module
{ {
public: public:

@ -33,235 +33,294 @@ distribution.
using namespace DFHack; using namespace DFHack;
class Items::Private enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT};
/* this is used to store data about the way accessors work */
class DFHACK_EXPORT Accessor
{ {
public: private:
DFContextShared *d; accessor_type type;
Process * owner; int32_t constant;
/* uint32_t offset1;
bool Inited; uint32_t offset2;
bool Started; Process * p;
*/ uint32_t dataWidth;
public:
Accessor(uint32_t function, Process * p);
Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p);
int32_t getValue(uint32_t objectPtr);
bool isConstant();
}; };
class DFHACK_EXPORT ItemImprovementDesc
Items::Items(DFContextShared * d_)
{ {
d = new Private; private:
d->d = d_; Accessor * AType;
d->owner = d_->p; Process * p;
} public:
Items::~Items() ItemImprovementDesc(uint32_t VTable, Process * p);
bool getImprovement(uint32_t descptr, t_improvement & imp);
uint32_t vtable;
uint32_t maintype;
};
class DFHACK_EXPORT ItemDesc
{ {
delete d; private:
/* TODO : delete all item descs */ Accessor * AMainType;
} Accessor * ASubType;
Accessor * ASubIndex;
Accessor * AIndex;
Accessor * AQuality;
Process * p;
bool hasDecoration;
public:
ItemDesc(uint32_t VTable, Process * p);
bool getItem(uint32_t itemptr, t_item & item);
std::string className;
uint32_t vtable;
uint32_t mainType;
std::vector<ItemImprovementDesc> improvement;
};
// FIXME: this is crazy
Accessor::Accessor(uint32_t function, Process *p) Accessor::Accessor(uint32_t function, Process *p)
{ {
this->p = p; this->p = p;
this->constant = 0; this->constant = 0;
this->offset1 = 0; this->offset1 = 0;
this->offset2 = 0; this->offset2 = 0;
this->type = ACCESSOR_CONSTANT; this->type = ACCESSOR_CONSTANT;
this->dataWidth = 2; this->dataWidth = 2;
uint64_t funcText = p->readQuad(function); uint64_t funcText = p->readQuad(function);
if( funcText == 0xCCCCCCCCCCC3C033LL ) if( funcText == 0xCCCCCCCCCCC3C033LL )
{ {
return; return;
} }
if( funcText == 0xCCCCCCCCC3FFC883LL ) if( funcText == 0xCCCCCCCCC3FFC883LL )
{ {
/* or eax,-1; ret; */ /* or eax,-1; ret; */
this->constant = -1; this->constant = -1;
return; return;
} }
if( (funcText&0xFFFFFFFFFF0000FFLL) == 0xCCCCC300000000B8LL ) if( (funcText&0xFFFFFFFFFF0000FFLL) == 0xCCCCC300000000B8LL )
{ {
/* mov eax, xx; ret; */ /* mov eax, xx; ret; */
this->constant = (funcText>>8) & 0xffff; this->constant = (funcText>>8) & 0xffff;
return; return;
} }
if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC300000000818B66LL ) if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC300000000818B66LL )
{ {
/* mov ax, [ecx+xx]; ret; */ /* mov ax, [ecx+xx]; ret; */
this->type = ACCESSOR_INDIRECT; this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>24) & 0xffff; this->offset1 = (funcText>>24) & 0xffff;
return; return;
} }
if( (funcText&0xFFFFFFFF0000FFFFLL) == 0x8B6600000000818BLL ) if( (funcText&0xFFFFFFFF0000FFFFLL) == 0x8B6600000000818BLL )
{ {
uint64_t funcText2 = p->readQuad(function+8); uint64_t funcText2 = p->readQuad(function+8);
if( (funcText2&0xFFFFFFFFFFFF00FFLL) == 0xCCCCCCCCCCC30040LL ) if( (funcText2&0xFFFFFFFFFFFF00FFLL) == 0xCCCCCCCCCCC30040LL )
{ {
this->type = ACCESSOR_DOUBLE_INDIRECT; this->type = ACCESSOR_DOUBLE_INDIRECT;
this->offset1 = (funcText>>16) & 0xffff; this->offset1 = (funcText>>16) & 0xffff;
this->offset2 = (funcText2>>8) & 0xff; this->offset2 = (funcText2>>8) & 0xff;
return; return;
} }
} }
if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC30000000081BF0FLL ) if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC30000000081BF0FLL )
{ {
/* movsx eax, word ptr [ecx+xx]; ret */ /* movsx eax, word ptr [ecx+xx]; ret */
this->type = ACCESSOR_INDIRECT; this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>24) & 0xffff; this->offset1 = (funcText>>24) & 0xffff;
return; return;
} }
if( (funcText&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL ) if( (funcText&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL )
{ {
/* mov eax, [ecx+xx]; ret; */ /* mov eax, [ecx+xx]; ret; */
this->type = ACCESSOR_INDIRECT; this->type = ACCESSOR_INDIRECT;
this->offset1 = (funcText>>16) & 0xffff; this->offset1 = (funcText>>16) & 0xffff;
this->dataWidth = 4; this->dataWidth = 4;
return; return;
} }
printf("bad accessor @0x%x\n", function); printf("bad accessor @0x%x\n", function);
} }
bool Accessor::isConstant() bool Accessor::isConstant()
{ {
if(this->type == ACCESSOR_CONSTANT) if(this->type == ACCESSOR_CONSTANT)
return true; return true;
else else
return false; return false;
} }
int32_t Accessor::getValue(uint32_t objectPtr) int32_t Accessor::getValue(uint32_t objectPtr)
{ {
switch(this->type) switch(this->type)
{ {
case ACCESSOR_CONSTANT: case ACCESSOR_CONSTANT:
return this->constant; return this->constant;
break; break;
case ACCESSOR_INDIRECT: case ACCESSOR_INDIRECT:
switch(this->dataWidth) switch(this->dataWidth)
{ {
case 2: case 2:
return (int16_t) p->readWord(objectPtr + this->offset1); return (int16_t) p->readWord(objectPtr + this->offset1);
case 4: case 4:
return p->readDWord(objectPtr + this->offset1); return p->readDWord(objectPtr + this->offset1);
default: default:
return -1; return -1;
} }
break; break;
case ACCESSOR_DOUBLE_INDIRECT: case ACCESSOR_DOUBLE_INDIRECT:
switch(this->dataWidth) switch(this->dataWidth)
{ {
case 2: case 2:
return (int16_t) p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2); return (int16_t) p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2);
case 4: case 4:
return p->readDWord(p->readDWord(objectPtr + this->offset1) + this->offset2); return p->readDWord(p->readDWord(objectPtr + this->offset1) + this->offset2);
default: default:
return -1; return -1;
} }
break; break;
default: default:
return -1; return -1;
} }
} }
ItemDesc::ItemDesc(uint32_t VTable, Process *p) ItemDesc::ItemDesc(uint32_t VTable, Process *p)
{ {
uint32_t funcOffsetA = p->getDescriptor()->getOffset("item_type_accessor"); uint32_t funcOffsetA = p->getDescriptor()->getOffset("item_type_accessor");
uint32_t funcOffsetB = p->getDescriptor()->getOffset("item_subtype_accessor"); uint32_t funcOffsetB = p->getDescriptor()->getOffset("item_subtype_accessor");
uint32_t funcOffsetC = p->getDescriptor()->getOffset("item_subindex_accessor"); uint32_t funcOffsetC = p->getDescriptor()->getOffset("item_subindex_accessor");
uint32_t funcOffsetD = p->getDescriptor()->getOffset("item_index_accessor"); uint32_t funcOffsetD = p->getDescriptor()->getOffset("item_index_accessor");
uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor"); uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor");
this->vtable = VTable; this->vtable = VTable;
this->p = p; this->p = p;
this->className = p->readClassName(VTable).substr(5); this->className = p->readClassName(VTable).substr(5);
this->className.resize(this->className.size()-2); this->className.resize(this->className.size()-2);
this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p); this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p);
this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p); this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p);
this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p); this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p);
this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p); this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p);
this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p); this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p);
this->hasDecoration = false; this->hasDecoration = false;
if(this->AMainType->isConstant()) if(this->AMainType->isConstant())
this->mainType = this->AMainType->getValue(0); this->mainType = this->AMainType->getValue(0);
else else
{ {
fprintf(stderr, "Bad item main type at function %p\n", (void*) p->readDWord( VTable + funcOffsetA )); fprintf(stderr, "Bad item main type at function %p\n", (void*) p->readDWord( VTable + funcOffsetA ));
this->mainType = 0; this->mainType = 0;
} }
} }
bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item)
{ {
item.matdesc.itemType = this->AMainType->getValue(itemptr); item.matdesc.itemType = this->AMainType->getValue(itemptr);
item.matdesc.subType = this->ASubType->getValue(itemptr); item.matdesc.subType = this->ASubType->getValue(itemptr);
item.matdesc.subIndex = this->ASubIndex->getValue(itemptr); item.matdesc.subIndex = this->ASubIndex->getValue(itemptr);
item.matdesc.index = this->AIndex->getValue(itemptr); item.matdesc.index = this->AIndex->getValue(itemptr);
item.quality = this->AQuality->getValue(itemptr); item.quality = this->AQuality->getValue(itemptr);
item.quantity = 1; /* TODO */ item.quantity = 1; /* TODO */
return true; return true;
}
class Items::Private
{
public:
DFContextShared *d;
Process * owner;
std::map<int32_t, ItemDesc *> descType;
std::map<uint32_t, ItemDesc *> descVTable;
};
Items::Items(DFContextShared * d_)
{
d = new Private;
d->d = d_;
d->owner = d_->p;
}
bool Items::Start(){return true;}
bool Items::Finish(){return true;}
Items::~Items()
{
Finish();
std::map<uint32_t, ItemDesc *>::iterator it;
it = d->descVTable.begin();
while (it != d->descVTable.end())
{
delete (*it).second;
}
d->descType.clear();
d->descVTable.clear();
delete d;
} }
bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item) bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item)
{ {
std::map<uint32_t, ItemDesc *>::iterator it; std::map<uint32_t, ItemDesc *>::iterator it;
Process * p = d->owner; Process * p = d->owner;
ItemDesc * desc; ItemDesc * desc;
it = this->descVTable.find(itemptr); it = d->descVTable.find(itemptr);
if(it==descVTable.end()) if(it==d->descVTable.end())
{ {
uint32_t vtable = p->readDWord(itemptr); uint32_t vtable = p->readDWord(itemptr);
desc = new ItemDesc(vtable, p); desc = new ItemDesc(vtable, p);
this->descVTable[vtable] = desc; d->descVTable[vtable] = desc;
this->descType[desc->mainType] = desc; d->descType[desc->mainType] = desc;
} }
else else
desc = it->second; desc = it->second;
return desc->getItem(itemptr, item); return desc->getItem(itemptr, item);
} }
std::string Items::getItemClass(int32_t index) std::string Items::getItemClass(int32_t index)
{ {
std::map<int32_t, ItemDesc *>::iterator it; std::map<int32_t, ItemDesc *>::iterator it;
std::string out; std::string out;
it = this->descType.find(index); it = d->descType.find(index);
if(it==this->descType.end()) if(it==d->descType.end())
{ {
/* these are dummy values for mood decoding */ /* these are dummy values for mood decoding */
switch(index) switch(index)
{ {
case 0: return "bar"; case 0: return "bar";
case 1: return "cut gem"; case 1: return "cut gem";
case 2: return "block"; case 2: return "block";
case 3: return "raw gem"; case 3: return "raw gem";
case 4: return "raw stone"; case 4: return "raw stone";
case 5: return "log"; case 5: return "log";
case 54: return "leather"; case 54: return "leather";
case 57: return "cloth"; case 57: return "cloth";
case -1: return "probably bone or shell, but I really don't know"; case -1: return "probably bone or shell, but I really don't know";
default: return "unknown"; default: return "unknown";
} }
} }
out = it->second->className; out = it->second->className;
return out; return out;
} }
std::string Items::getItemDescription(uint32_t itemptr, Materials * Materials) std::string Items::getItemDescription(uint32_t itemptr, Materials * Materials)
{ {
DFHack::t_item item; DFHack::t_item item;
std::string out; std::string out;
if(!this->getItemData(itemptr, item)) if(!this->getItemData(itemptr, item))
return "??"; return "??";
switch(item.quality) switch(item.quality)
{ {
case 0: break; case 0: break;
case 1: out.append("Well crafted "); break; case 1: out.append("Well crafted "); break;
case 2: out.append("Finely crafted "); break; case 2: out.append("Finely crafted "); break;
case 3: out.append("Superior quality "); break; case 3: out.append("Superior quality "); break;
case 4: out.append("Exceptionnal "); break; case 4: out.append("Exceptionnal "); break;
case 5: out.append("Masterful "); break; case 5: out.append("Masterful "); break;
default: out.append("Crazy quality "); break; default: out.append("Crazy quality "); break;
} }
out.append(Materials->getDescription(item.matdesc)); out.append(Materials->getDescription(item.matdesc));
out.append(" "); out.append(" ");
out.append(this->getItemClass(item.matdesc.itemType)); out.append(this->getItemClass(item.matdesc.itemType));
return out; return out;
} }

@ -90,7 +90,6 @@ Maps::Maps(DFContextShared* _d)
off.region_y_offset = mem->getAddress ("region_y"); off.region_y_offset = mem->getAddress ("region_y");
off.region_z_offset = mem->getAddress ("region_z"); off.region_z_offset = mem->getAddress ("region_z");
off.world_regions = mem->getAddress ("ptr2_region_array"); off.world_regions = mem->getAddress ("ptr2_region_array");
off.region_size = mem->getHexValue ("region_size"); off.region_size = mem->getHexValue ("region_size");
off.region_geo_index_offset = mem->getOffset ("region_geo_index_off"); off.region_geo_index_offset = mem->getOffset ("region_geo_index_off");
@ -137,8 +136,10 @@ bool Maps::Start()
return false; return false;
if(d->Started) if(d->Started)
Finish(); Finish();
Process *p = d->owner; Process *p = d->owner;
Server::Maps::maps_offsets &off = d->offsets; Server::Maps::maps_offsets &off = d->offsets;
// get the map pointer // get the map pointer
uint32_t x_array_loc = p->readDWord (off.map_offset); uint32_t x_array_loc = p->readDWord (off.map_offset);
if (!x_array_loc) if (!x_array_loc)
@ -292,7 +293,7 @@ bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buf
} }
/* /*
* Dirty flags * Dirty bit
*/ */
bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit) bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
@ -326,7 +327,9 @@ bool Maps::WriteDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool dirtybit)
return false; return false;
} }
/// read/write the block flags /*
* Block flags
*/
bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags) bool Maps::ReadBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags &blockflags)
{ {
MAPS_GUARD MAPS_GUARD
@ -357,7 +360,6 @@ bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags bloc
/* /*
* Designations * Designations
*/ */
bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer) bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{ {
MAPS_GUARD MAPS_GUARD
@ -385,7 +387,6 @@ bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40
/* /*
* Occupancies * Occupancies
*/ */
bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer) bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
{ {
MAPS_GUARD MAPS_GUARD
@ -735,26 +736,20 @@ bool Maps::ReadLocalFeatures( std::map <planecoord, std::vector<t_feature *> > &
for(uint32_t blockX = 0; blockX < d->x_block_count; blockX ++) for(uint32_t blockX = 0; blockX < d->x_block_count; blockX ++)
for(uint32_t blockY = 0; blockY < d->x_block_count; blockY ++) for(uint32_t blockY = 0; blockY < d->x_block_count; blockY ++)
{ {
//uint64_t block48_x = blockX / 3 + d->regionX; // region X coord (48x48 tiles)
//uint16_t region_x_plus8 = ( block48_x + 8 ) / 16; uint16_t region_x_local = ( (blockX / 3) + d->regionX ) / 16;
// region Y coord (48x48 tiles)
// region X coord offset by 8 big blocks (48x48 tiles)
uint16_t region_x_plus8 = ( (blockX / 3 ) + d->regionX /*+ 8*/ ) / 16;
//((BYTE4(region_x_local) & 0xF) + (_DWORD)region_x_local) >> 4;
//int16_t region_x_local = (blockX / 3) + d->regionX;
//int16_t region_x_plus8 = ((region_x_local & 0xF) + region_x_local) >> 4;
// plain region Y coord
uint64_t region_y_local = ( (blockY / 3) + d->regionY ) / 16; uint64_t region_y_local = ( (blockY / 3) + d->regionY ) / 16;
// this is just a few pointers to arrays of 16B (4 DWORD) structs // this is just a few pointers to arrays of 16B (4 DWORD) structs
uint32_t array_elem = p->readDWord(base + (region_x_plus8 / 16) * 4); uint32_t array_elem = p->readDWord(base + (region_x_local / 16) * 4);
// 16B structs, second DWORD of the struct is a pointer // 16B structs, second DWORD of the struct is a pointer
uint32_t wtf = p->readDWord(array_elem + ( sizeof_elem * ( (uint32_t)region_y_local/16)) + offset_elem); uint32_t wtf = p->readDWord(array_elem + ( sizeof_elem * ( (uint32_t)region_y_local/16)) + offset_elem);
if(wtf) if(wtf)
{ {
// wtf + sizeof(vector<ptr>) * crap; // wtf + sizeof(vector<ptr>) * crap;
uint32_t feat_vector = wtf + sizeof_vec * (16 * (region_x_plus8 % 16) + (region_y_local % 16)); uint32_t feat_vector = wtf + sizeof_vec * (16 * (region_x_local % 16) + (region_y_local % 16));
DfVector<uint32_t> p_features(p, feat_vector); DfVector<uint32_t> p_features(p, feat_vector);
uint32_t size = p_features.size(); uint32_t size = p_features.size();
planecoord pc; planecoord pc;

@ -53,6 +53,21 @@ Materials::~Materials()
{ {
delete d; delete d;
} }
bool Materials::Finish()
{
inorganic.clear();
organic.clear();
tree.clear();
plant.clear();
race.clear();
raceEx.clear();
color.clear();
other.clear();
alldesc.clear();
return true;
}
/* /*
{ {
LABEL_53: LABEL_53:
@ -401,10 +416,10 @@ void Materials::ReadAllMaterials(void)
std::string Materials::getDescription(t_material & mat) std::string Materials::getDescription(t_material & mat)
{ {
std::string out; std::string out;
int32_t typeC; int32_t typeC;
if ( (mat.subIndex<419) || (mat.subIndex>618) ) if ( (mat.subIndex<419) || (mat.subIndex>618) )
{ {
if ( (mat.subIndex<19) || (mat.subIndex>218) ) if ( (mat.subIndex<19) || (mat.subIndex>218) )
{ {
@ -414,13 +429,13 @@ std::string Materials::getDescription(t_material & mat)
else else
{ {
if (mat.subIndex>=this->other.size()) if (mat.subIndex>=this->other.size())
{ {
if(mat.subIndex<0) if(mat.subIndex<0)
return "any"; return "any";
if(mat.subIndex>=this->raceEx.size()) if(mat.subIndex>=this->raceEx.size())
return "stuff"; return "stuff";
return this->raceEx[mat.subIndex].rawname; return this->raceEx[mat.subIndex].rawname;
} }
else else
{ {
if (mat.index==-1) if (mat.index==-1)
@ -430,17 +445,17 @@ std::string Materials::getDescription(t_material & mat)
} }
} }
else else
if(mat.index<0) if(mat.index<0)
return "any inorganic"; return "any inorganic";
else else
return this->inorganic[mat.index].id; return this->inorganic[mat.index].id;
} }
else else
{ {
if (mat.index>=this->raceEx.size()) if (mat.index>=this->raceEx.size())
return "unknown race"; return "unknown race";
typeC = mat.subIndex; typeC = mat.subIndex;
typeC -=19; typeC -=19;
if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size())) if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size()))
{ {
return string(this->raceEx[mat.index].rawname).append(" extract"); return string(this->raceEx[mat.index].rawname).append(" extract");
@ -452,6 +467,6 @@ std::string Materials::getDescription(t_material & mat)
{ {
return this->organic[mat.index].id; return this->organic[mat.index].id;
} }
return out; return out;
} }

@ -31,20 +31,23 @@ distribution.
namespace DFHack namespace DFHack
{ {
class Materials; class Module;
class Creatures;
class Maps;
class Position;
class Gui; class Gui;
class World; class World;
class Position; class Materials;
class Maps;
class Creatures;
class Items; class Items;
class Translation; class Translation;
class Vegetation;
class Buildings; class Buildings;
class Constructions;
class WindowIO;
class ProcessEnumerator; class ProcessEnumerator;
class Process; class Process;
class WindowIO;
class Vegetation;
class Constructions;
class memory_info; class memory_info;
struct t_name; struct t_name;
class DFContextShared class DFContextShared
@ -69,19 +72,22 @@ namespace DFHack
string xml; string xml;
// Modules // Modules
Creatures * creatures; struct
Maps * maps; {
Position * position; Creatures * pCreatures;
Gui * gui; Maps * pMaps;
World * world; Position * pPosition;
Materials * materials; Gui * pGui;
Items * items; World * pWorld;
Translation * translation; Materials * pMaterials;
Vegetation * vegetation; Items * pItems;
Buildings * buildings; Translation * pTranslation;
Constructions * constructions; Vegetation * pVegetation;
WindowIO * windowio; Buildings * pBuildings;
Constructions * pConstructions;
WindowIO * pWindowIO;
} s_mods;
std::vector <Module *> allModules;
/* /*
uint32_t item_material_offset; uint32_t item_material_offset;

@ -0,0 +1,56 @@
################################################################################
# DFCONNECT
###
SET(DFCONNECT_HDRS
shms.h
mod-core.h
mod-maps.h
)
SET(PROJECT_SRCS
mod-core.cpp
mod-maps.cpp
#mod-creature40d.cpp
)
SET(PROJECT_HDRS_LINUX
)
SET(PROJECT_HDRS_WINDOWS
)
SET(PROJECT_SRCS_LINUX
shms-linux.cpp
)
SET(PROJECT_SRCS_WINDOWS
shms-windows.cpp
)
IF(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_LINUX})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_LINUX})
ELSE(UNIX)
LIST(APPEND PROJECT_HDRS ${PROJECT_HDRS_WINDOWS})
LIST(APPEND PROJECT_SRCS ${PROJECT_SRCS_WINDOWS})
ENDIF(UNIX)
SET_SOURCE_FILES_PROPERTIES( ${PROJECT_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE )
LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS})
#IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_definitions(-DBUILD_SHM)
IF(UNIX)
add_definitions(-DLINUX_BUILD)
SET(PROJECT_LIBS rt)
SET(CMAKE_CXX_FLAGS "-fvisibility=hidden")
ADD_LIBRARY(dfconnect SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(dfconnect ${PROJECT_LIBS})
ELSE(UNIX)
# SET(PROJECT_LIBS psapi)
ADD_LIBRARY(SDL SHARED ${PROJECT_SRCS})
TARGET_LINK_LIBRARIES(SDL ${PROJECT_LIBS})
ENDIF(UNIX)
#ENDIF(CMAKE_SIZEOF_VOID_P EQUAL 4)