Creature likes (at least the structures are back), malloc wrapper that sets memory to 0xCC.

develop
Petr Mrázek 2011-09-25 01:29:55 +02:00
parent bb919e8462
commit 83ae8d6c12
4 changed files with 66 additions and 6 deletions

@ -6,6 +6,7 @@ OPTION(BUILD_DEVEL "Install/package files required for development (For SDK)." O
OPTION(BUILD_DOXYGEN "Create/install/package doxygen documentation for DFHack (For SDK)." OFF) OPTION(BUILD_DOXYGEN "Create/install/package doxygen documentation for DFHack (For SDK)." OFF)
IF(UNIX) IF(UNIX)
OPTION(CONSOLE_NO_CATCH "Make the console not catch 'CTRL+C' events for easier debugging." OFF) OPTION(CONSOLE_NO_CATCH "Make the console not catch 'CTRL+C' events for easier debugging." OFF)
OPTION(MALLOC_FILL "Make malloc calls fill the allocated memory with 0xCC values." OFF)
ENDIF() ENDIF()
include_directories (include) include_directories (include)
@ -124,6 +125,9 @@ IF(UNIX)
IF(CONSOLE_NO_CATCH) IF(CONSOLE_NO_CATCH)
ADD_DEFINITIONS(-DCONSOLE_NO_CATCH) ADD_DEFINITIONS(-DCONSOLE_NO_CATCH)
ENDIF() ENDIF()
IF(MALLOC_FILL)
ADD_DEFINITIONS(-DMALLOC_FILL)
ENDIF()
ENDIF() ENDIF()
IF(UNIX) IF(UNIX)

@ -155,3 +155,24 @@ DFhackCExport int SDL_Init(uint32_t flags)
int ret = _SDL_Init(flags); int ret = _SDL_Init(flags);
return ret; return ret;
} }
#ifdef MALLOC_FILL
DFhackCExport void * malloc(size_t size)
{
static void* (*real_malloc)(size_t) = NULL;
if (!real_malloc)
real_malloc = (void * (*)( size_t )) dlsym(RTLD_NEXT, "malloc");
// check if we got them
if(!real_malloc)
{
// bail, this would be a disaster otherwise
exit(1);
}
void * ret = real_malloc(size);
if(ret)
{
memset(ret, 0xCC, size);
}
return ret;
}
#endif

@ -260,7 +260,6 @@ namespace DFHack
/** /**
* \ingroup grp_creatures * \ingroup grp_creatures
*/ */
/*
struct t_like struct t_like
{ {
int16_t type; int16_t type;
@ -268,8 +267,8 @@ namespace DFHack
int16_t itemIndex; int16_t itemIndex;
t_matglossPair material; t_matglossPair material;
bool active; bool active;
uint32_t mystery;
}; };
*/
// FIXME: THIS IS VERY, VERY BAD. // FIXME: THIS IS VERY, VERY BAD.
#define NUM_CREATURE_LABORS 96 #define NUM_CREATURE_LABORS 96
@ -369,7 +368,7 @@ namespace DFHack
uint32_t unk_18; uint32_t unk_18;
}; };
/** /**
* Creature skil descriptor * Creature skill descriptor
* \ingroup grp_creatures * \ingroup grp_creatures
*/ */
struct df_skill struct df_skill
@ -383,13 +382,27 @@ namespace DFHack
uint32_t unk_18; uint32_t unk_18;
uint32_t unk_1c; uint32_t unk_1c;
}; };
/**
* Creature like descriptor
* \ingroup grp_creatures
*/
struct df_like
{
int16_t type;
int16_t itemClass;
int16_t itemIndex;
int16_t material_type;
int32_t material_index;
bool active;
uint32_t mystery;
};
/** /**
* A creature's soul, as it appears in DF memory * A creature's soul, as it appears in DF memory
* \ingroup grp_creatures * \ingroup grp_creatures
*/ */
struct df_soul struct df_soul
{ {
uint32_t unk_0; uint32_t creature_id;
df_name name; // 4 df_name name; // 4
uint32_t unk_70; uint32_t unk_70;
uint16_t unk_74; uint16_t unk_74;
@ -400,7 +413,7 @@ namespace DFHack
int32_t unk_84; int32_t unk_84;
df_attrib mental[NUM_CREATURE_MENTAL_ATTRIBUTES]; // 88..1f3 df_attrib mental[NUM_CREATURE_MENTAL_ATTRIBUTES]; // 88..1f3
std::vector<df_skill*> skills; // 1f4; std::vector<df_skill*> skills; // 1f4;
std::vector<void*> unk_204; // pointers to 14 0x14-byte structures ... likes? std::vector<df_like*> likes; // pointers to 14 0x14-byte structures ... likes?
uint16_t traits[NUM_CREATURE_TRAITS]; // 214 uint16_t traits[NUM_CREATURE_TRAITS]; // 214
std::vector<int16_t*> unk_250; // 1 pointer to 2 shorts std::vector<int16_t*> unk_250; // 1 pointer to 2 shorts
uint32_t unk_260; uint32_t unk_260;

@ -330,7 +330,29 @@ command_result creat_job (Core * c, vector< string >& parameters)
df_creature * unit = *iter; df_creature * unit = *iter;
if(cx == unit->x && cy == unit->y && cz == unit->z) if(cx == unit->x && cy == unit->y && cz == unit->z)
{ {
c->con.print("%d:%s - address 0x%x - job 0x%x\n", unit->id, unit->name.first_name.c_str(), unit, uint32_t(unit) + offsetof(df_creature,current_job)); c->con.print("%d:%s - address 0x%x - job 0x%x\n"
"Soul: 0x%x, likes: 0x%x\n",
unit->id,
unit->name.first_name.c_str(),
unit,
uint32_t(unit) + offsetof(df_creature,current_job),
uint32_t(unit) + offsetof(df_creature,current_soul),
uint32_t(unit->current_soul) + offsetof(df_soul,likes)
);
df_soul * s = unit->current_soul;
if(s)
{
c->con.print("LIKES:\n");
int idx = 1;
auto iter = s->likes.begin();
while(iter != s->likes.end())
{
df_like * l = *iter;
c->con.print("%3d: %f\n", idx, float(l->mystery));
iter++;
idx++;
}
}
} }
iter++; iter++;
} }