From 83ae8d6c12289023002de39b3040089133ff11ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 25 Sep 2011 01:29:55 +0200 Subject: [PATCH] Creature likes (at least the structures are back), malloc wrapper that sets memory to 0xCC. --- library/CMakeLists.txt | 4 ++++ library/FakeSDL-linux.cpp | 21 +++++++++++++++++++ library/include/dfhack/modules/Creatures.h | 23 ++++++++++++++++----- plugins/devel/kittens.cpp | 24 +++++++++++++++++++++- 4 files changed, 66 insertions(+), 6 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index ba796d8a5..98d2dd027 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -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) IF(UNIX) 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() include_directories (include) @@ -124,6 +125,9 @@ IF(UNIX) IF(CONSOLE_NO_CATCH) ADD_DEFINITIONS(-DCONSOLE_NO_CATCH) ENDIF() + IF(MALLOC_FILL) + ADD_DEFINITIONS(-DMALLOC_FILL) + ENDIF() ENDIF() IF(UNIX) diff --git a/library/FakeSDL-linux.cpp b/library/FakeSDL-linux.cpp index 4f1fde0ad..a5f34e5f2 100644 --- a/library/FakeSDL-linux.cpp +++ b/library/FakeSDL-linux.cpp @@ -155,3 +155,24 @@ DFhackCExport int SDL_Init(uint32_t flags) int ret = _SDL_Init(flags); 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 diff --git a/library/include/dfhack/modules/Creatures.h b/library/include/dfhack/modules/Creatures.h index f83f00c03..f6d6d0c95 100644 --- a/library/include/dfhack/modules/Creatures.h +++ b/library/include/dfhack/modules/Creatures.h @@ -260,7 +260,6 @@ namespace DFHack /** * \ingroup grp_creatures */ - /* struct t_like { int16_t type; @@ -268,8 +267,8 @@ namespace DFHack int16_t itemIndex; t_matglossPair material; bool active; + uint32_t mystery; }; - */ // FIXME: THIS IS VERY, VERY BAD. #define NUM_CREATURE_LABORS 96 @@ -369,7 +368,7 @@ namespace DFHack uint32_t unk_18; }; /** - * Creature skil descriptor + * Creature skill descriptor * \ingroup grp_creatures */ struct df_skill @@ -383,13 +382,27 @@ namespace DFHack uint32_t unk_18; 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 * \ingroup grp_creatures */ struct df_soul { - uint32_t unk_0; + uint32_t creature_id; df_name name; // 4 uint32_t unk_70; uint16_t unk_74; @@ -400,7 +413,7 @@ namespace DFHack int32_t unk_84; df_attrib mental[NUM_CREATURE_MENTAL_ATTRIBUTES]; // 88..1f3 std::vector skills; // 1f4; - std::vector unk_204; // pointers to 14 0x14-byte structures ... likes? + std::vector likes; // pointers to 14 0x14-byte structures ... likes? uint16_t traits[NUM_CREATURE_TRAITS]; // 214 std::vector unk_250; // 1 pointer to 2 shorts uint32_t unk_260; diff --git a/plugins/devel/kittens.cpp b/plugins/devel/kittens.cpp index 8ec0c11e4..9d1daa36f 100644 --- a/plugins/devel/kittens.cpp +++ b/plugins/devel/kittens.cpp @@ -330,7 +330,29 @@ command_result creat_job (Core * c, vector< string >& parameters) df_creature * unit = *iter; 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++; }