// // library to be preloaded into Dwarf Fortress (linux) // Yoann Guillot, 10/2010 // // gcc -W -Wall -o dfclone.so dfclone.c -shared -fPIC // LD_PRELOAD=./dfclone.so libs/Dwarf_Fortress // // load your save, then create a 'reveal_now' file in the current directory // // uses hardcoded offsets for the v0.31.16 linux version // #include #include static void dfclone(void) __attribute__((constructor)); static int cloneloop(void*); #ifdef USE_CLONE // XXX this makes DF segfault during startup in some pthread function #define _GNU_SOURCE #include static void dfclone(void) { static char clone_stack[4096*16]; void *stackptr = clone_stack + sizeof(clone_stack) - 4; clone(cloneloop, stackptr, CLONE_VM, 0); } #else #include static void dfclone(void) { pthread_t fu; pthread_create(&fu, 0, (void*(*)(void*))cloneloop, 0); } #endif static void cloneloop_poll(void); static void reveal(void); static int cloneloop(void* arg) { (void)arg; // unused argument blablabla for (;;) { sleep(1); cloneloop_poll(); } _exit(0); } static void cloneloop_poll(void) { int *caret = (int*)0x8b33550; // display game cursor position printf("%d %d %d\n", caret[0], caret[1], caret[2]); // TODO more useful stuff here, like read the name of a .so in the file, dlopen it, and call some function in it if (unlink("reveal_now") == 0) reveal(); } static void reveal(void) { // XXX dont know how to find all the map_data structures, this seems to work (top row only) // but 'bi' used to be a 'xi'+'yi', now when trying to access other bi game crashes // also why do z start at 14 ? struct map_data { char foo[0x26c]; int flags[16*16]; }; struct map_data ***md = *(void**)(0x933f320); int bi, z, xi, yi; for (bi=0 ; bi<12 ; bi++) { printf("b=%d %p\n", bi, md[bi]); if (!md[bi]) continue; for (z=14 ; z<160 ; z++) { // looks like all z-level are already allocated if (!md[bi][z]) continue; int *flags = md[bi][z]->flags; for (xi=0 ; xi<16 ; xi++) for (yi=0 ; yi<16 ; yi++) // remove 'hidden from view' flag flags[16*xi+yi] &= ~0x200; } } }