From bae7b88be03bf39bf159d82a1ea15284923174d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 13 Aug 2010 21:44:17 +0200 Subject: [PATCH 1/5] Make sure the compatible memory.xml is used. --- library/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index d66f0af51..57f78725f 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -188,7 +188,7 @@ if(MSVC) ) else(MSVC) # Just put the file in the output directory on Linux and Mac - configure_file(${CMAKE_SOURCE_DIR}/data/Memory-ng.xml ${DATA_OUTPUT_PATH}/Memory.xml COPYONLY) + configure_file(${CMAKE_SOURCE_DIR}/data/Memory.xml ${DATA_OUTPUT_PATH}/Memory.xml COPYONLY) endif(MSVC) IF(UNIX) From 7fbdd6c69af8d2e62dcce602bd08e959d5b8b526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 13 Aug 2010 23:25:14 +0200 Subject: [PATCH 2/5] Cleartask tool, updated docs. --- README.rst | 4 ++ Readme.html | 53 +++++++++++++----------- library/CMakeLists.txt | 8 ++++ tools/supported/CMakeLists.txt | 6 +++ tools/supported/cleartask.cpp | 73 ++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 24 deletions(-) create mode 100644 tools/supported/cleartask.cpp diff --git a/README.rst b/README.rst index e7184bd03..ff93b49f3 100644 --- a/README.rst +++ b/README.rst @@ -120,6 +120,10 @@ dfdoffsets ========== Dumps the offsets for the currently running DF version into the terminal. +dfcleartask +=========== +Solves the problem of unusable items after reclaim by clearing the 'in_job' bit of all items. + Your tool here ============== Write one ;) diff --git a/Readme.html b/Readme.html index bebf7241f..98eb64c8a 100644 --- a/Readme.html +++ b/Readme.html @@ -346,26 +346,27 @@ allow for easier development of new tools.

  • dfsuspend
  • dfexpbench
  • dfdoffsets
  • -
  • Your tool here
  • +
  • dfcleartask
  • +
  • Your tool here
  • -
  • Using the library as a developer
      -
    • Contributing to DFHack
        -
      • Coding style
      • -
      • How to get new code into DFHack
      • -
      • Layout for tools
      • -
      • Modules - what are they?
      • -
      • Dependencies @@ -468,13 +469,17 @@ flows.

        dfdoffsets

        Dumps the offsets for the currently running DF version into the terminal.

        +
        +

        dfcleartask

        +

        Solves the problem of unusable items after reclaim by clearing the 'in_job' bit of all items.

        +
        -

        Using the library as a developer

        +

        Using the library as a developer

        The library is compilable under Linux with GCC and under Windows with MinGW32 and MSVC compilers. It is using the cmake build system. See COMPILE for details.

        @@ -485,17 +490,17 @@ the dfhack repository is welcome and the right thing to do :)

        code does have a lot of comments though (and getting better all the time).

        -

        Contributing to DFHack

        +

        Contributing to DFHack

        Several things should be kept in mind when contributing to DFHack.

        -

        Coding style

        +

        Coding style

        DFhack uses ANSI formatting and four spaces as indentation. Line endings are UNIX. The files use UTF-8 encoding. Code not following this won't make me happy, because I'll have to fix it. There's a good chance I'll make you fix it ;)

        -

        How to get new code into DFHack

        +

        How to get new code into DFHack

        You can send patches or make a clone of the github repo and ask me on the IRC channel to pull your code in. I'll review it and see if there are any problems. I'll fix them if they are minor.

        @@ -505,7 +510,7 @@ this is also a good place to dump new ideas and/or bugs that need fixing.

        -

        Layout for tools

        +

        Layout for tools

        Tools live in the tools/ folder. There, they are split into three categories.

        @@ -526,7 +531,7 @@ nasty business.
        -

        Modules - what are they?

        +

        Modules - what are they?

        DFHack uses modules to partition sets of features into manageable chunks. A module can have both client and server side.

        Client side is the part that goes into the main library and is @@ -543,7 +548,7 @@ server, it allows accelerating the reading of map blocks.

        pretty fast, but needs quite a bit of care to not break.

        -

        Dependencies

        +

        Dependencies

        Internal
        either part of the codebase or statically linked.
        @@ -555,7 +560,7 @@ dependencies for core dfhack should be either public domain or require attribution at most. External dependencies for tools can be either that, or any Free Software licenses.

        -

        Current internal dependencies

        +

        Current internal dependencies

        tinyxml
        used by core dfhack to read offset definitions from Memory.xml
        @@ -567,7 +572,7 @@ DF binaries on Linux.
        -

        Current external dependencies

        +

        Current external dependencies

        wide-character ncurses
        used for the veinlook tool on Linux.
        @@ -576,7 +581,7 @@ DF binaries on Linux.
        -

        Build-time dependencies

        +

        Build-time dependencies

        cmake
        you need cmake to generate the build system and some configuration @@ -587,7 +592,7 @@ headers
        -

        Memory offset definitions

        +

        Memory offset definitions

        The files with memory offset definitions used by dfhack can be found in the data folder.

        diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 57f78725f..8e09a2203 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -186,9 +186,17 @@ if(MSVC) ADD_CUSTOM_COMMAND(TARGET dfhack POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/data/Memory.xml $(TargetDir)/Memory.xml ) + ADD_CUSTOM_COMMAND(TARGET dfhack POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Compile.html $(TargetDir)/Compile.html + ) + ADD_CUSTOM_COMMAND(TARGET dfhack POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/Readme.html $(TargetDir)/Readme.html + ) else(MSVC) # Just put the file in the output directory on Linux and Mac configure_file(${CMAKE_SOURCE_DIR}/data/Memory.xml ${DATA_OUTPUT_PATH}/Memory.xml COPYONLY) + configure_file(${CMAKE_SOURCE_DIR}/Compile.html ${DATA_OUTPUT_PATH}/Compile.html COPYONLY) + configure_file(${CMAKE_SOURCE_DIR}/Readme.html ${DATA_OUTPUT_PATH}/Readme.html COPYONLY) endif(MSVC) IF(UNIX) diff --git a/tools/supported/CMakeLists.txt b/tools/supported/CMakeLists.txt index 0a0d93f68..f7006aeb2 100644 --- a/tools/supported/CMakeLists.txt +++ b/tools/supported/CMakeLists.txt @@ -51,6 +51,11 @@ TARGET_LINK_LIBRARIES(dfflows dfhack) ADD_EXECUTABLE(dfliquids liquids.cpp) TARGET_LINK_LIBRARIES(dfliquids dfhack) +# Solves the problem of unusable items after reclaim by clearing the 'in_job' bit of all items. +# Original author: Quietust +ADD_EXECUTABLE(dfcleartask cleartask.cpp) +TARGET_LINK_LIBRARIES(dfcleartask dfhack) + # position - check the DF window and cursor parameters ADD_EXECUTABLE(dfposition position.cpp) TARGET_LINK_LIBRARIES(dfposition dfhack) @@ -104,6 +109,7 @@ dfunstuck dfprobe dfdoffsets dfattachtest +dfcleartask dfexpbench dfsuspend dfflows diff --git a/tools/supported/cleartask.cpp b/tools/supported/cleartask.cpp new file mode 100644 index 000000000..267a686ff --- /dev/null +++ b/tools/supported/cleartask.cpp @@ -0,0 +1,73 @@ +// clears the "tasked" flag on all items +// original code by Quietust (http://www.bay12forums.com/smf/index.php?action=profile;u=18111) +#include +#include +#include +#include +#include +#include +using namespace std; + +#include +#include +#include + +int main () +{ + DFHack::Process * p; + unsigned int i; + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context * DF; + try + { + DF = DFMgr.getSingleContext(); + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; +#ifndef LINUX_BUILD + cin.ignore(); +#endif + return 1; + } + + DFHack::memory_info * mem = DF->getMemoryInfo(); + p = DF->getProcess(); + uint32_t item_vec_offset = 0; + try + { + item_vec_offset = p->getDescriptor()->getAddress ("items_vector"); + } + catch(DFHack::Error::MissingMemoryDefinition & e) + { + cerr << "missing offset for the item vector, exiting :(" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + DFHack::DfVector p_items (p, item_vec_offset); + uint32_t size = p_items.size(); + + int numtasked = 0; + for (i=0;ireadDWord(p_items[i] + 0x0C); + if (flags.bits.in_job) + { + flags.bits.in_job = 0; + p->writeDWord(p_items[i] + 0x0C, flags.whole); + numtasked++; + } + } + cout << "Found and untasked " << numtasked << " items." << endl; + +#ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); +#endif + return 0; +} \ No newline at end of file From a159707250a0e34fc651b3d0b1b16250c79848a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 14 Aug 2010 01:25:18 +0200 Subject: [PATCH 3/5] Fix memleak with Context not cleaning up. --- README.rst | 4 ++++ library/DFContext.cpp | 2 ++ library/DFProcess-linux-SHM.cpp | 5 +---- library/DFProcess-linux-wine.cpp | 2 +- library/DFProcess-linux.cpp | 2 +- library/DFProcess-windows-SHM.cpp | 5 +---- library/DFProcess-windows.cpp | 5 +---- library/include/dfhack/DFModule.h | 2 +- library/modules/Maps.cpp | 2 ++ tools/examples/processenum.cpp | 11 +++++++++++ 10 files changed, 25 insertions(+), 15 deletions(-) diff --git a/README.rst b/README.rst index ff93b49f3..1e479d107 100644 --- a/README.rst +++ b/README.rst @@ -84,6 +84,10 @@ dfprospector ============ Lists all available minerals on the map and how much of them there is. +dfprobe +============ +Can be used to determine tile properties. + dfreveal ======== Reveals the whole map, waits for input and hides it again. If you close diff --git a/library/DFContext.cpp b/library/DFContext.cpp index 15939dee9..1499f566d 100644 --- a/library/DFContext.cpp +++ b/library/DFContext.cpp @@ -59,6 +59,7 @@ Context::Context (Process* p) : d (new DFContextShared()) Context::~Context() { + cerr << "called Context destructor" << endl; Detach(); delete d; } @@ -88,6 +89,7 @@ bool Context::Detach() { if (!d->p->detach()) { + cerr << "Context::Detach failed!" << endl; return false; } d->shm_start = 0; diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index 9c8d9aab1..acf519ecf 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -569,10 +569,7 @@ bool SHMProcess::attach() bool SHMProcess::detach() { - if(!d->attached) - { - return false; - } + if(!d->attached) return true; if(d->locked) { resume(); diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index 6f288a078..b71e2266f 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -331,7 +331,7 @@ bool WineProcess::attach() bool WineProcess::detach() { - if(!d->attached) return false; + if(!d->attached) return true; if(!d->suspended) suspend(); int result = 0; // close /proc/PID/mem diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index 2402609e1..25dfa0d8c 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -318,7 +318,7 @@ bool NormalProcess::attach() bool NormalProcess::detach() { - if(!d->attached) return false; + if(!d->attached) return true; if(!d->suspended) suspend(); int result = 0; // close /proc/PID/mem diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index f9a7cad26..5bb100e34 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -632,10 +632,7 @@ bool SHMProcess::attach() bool SHMProcess::detach() { - if(!d->attached) - { - return false; - } + if(!d->attached) return true; //cerr << "detach" << endl;// FIXME: throw if(d->locked) { diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index da44a0f32..dad67b135 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -249,10 +249,7 @@ bool NormalProcess::attach() bool NormalProcess::detach() { - if(!d->attached) - { - return false; - } + if(!d->attached) return true; resume(); d->attached = false; return true; diff --git a/library/include/dfhack/DFModule.h b/library/include/dfhack/DFModule.h index d4c840b64..7ed3e6738 100644 --- a/library/include/dfhack/DFModule.h +++ b/library/include/dfhack/DFModule.h @@ -33,7 +33,7 @@ namespace DFHack class DFHACK_EXPORT Module { public: - ~Module(){}; + virtual ~Module(){}; virtual bool Start(){return true;};// default start... virtual bool Finish() = 0;// everything should have a Finish() // should Context call Finish when Resume is called? diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index e7d43a2a5..17c6c2034 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -123,8 +123,10 @@ Maps::Maps(DFContextShared* _d) Maps::~Maps() { + cerr << "called Maps destructor" << endl; if(d->Started) Finish(); + delete d; } /*-----------------------------------* diff --git a/tools/examples/processenum.cpp b/tools/examples/processenum.cpp index 50b0df0a1..728736b65 100644 --- a/tools/examples/processenum.cpp +++ b/tools/examples/processenum.cpp @@ -102,6 +102,17 @@ int main (void) Cman.Refresh(&inval); int nCont = Cman.size(); int nInval = inval.size(); + DFHack::Context * cont = Cman.getSingleContext(); + if(cont) + { + if(cont->Attach()) + cont->getMaps(); + bool result = cont->Detach(); + if(!result) + { + cerr << "Something went horribly wrong during detach" << endl; + } + } cout << "Contexts:" << endl; for(int i = 0; i < nCont; i++) From 94872b8abd5f50f31d6b5f292ae0a8741a9064d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 14 Aug 2010 18:32:38 +0200 Subject: [PATCH 4/5] A bit of checking in some places. --- library/DFContext.cpp | 1 - library/modules/Maps.cpp | 1 - tools/examples/processenum.cpp | 8 +++++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/library/DFContext.cpp b/library/DFContext.cpp index 1499f566d..d46302426 100644 --- a/library/DFContext.cpp +++ b/library/DFContext.cpp @@ -59,7 +59,6 @@ Context::Context (Process* p) : d (new DFContextShared()) Context::~Context() { - cerr << "called Context destructor" << endl; Detach(); delete d; } diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 17c6c2034..0cf3588a1 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -123,7 +123,6 @@ Maps::Maps(DFContextShared* _d) Maps::~Maps() { - cerr << "called Maps destructor" << endl; if(d->Started) Finish(); delete d; diff --git a/tools/examples/processenum.cpp b/tools/examples/processenum.cpp index 728736b65..745e94371 100644 --- a/tools/examples/processenum.cpp +++ b/tools/examples/processenum.cpp @@ -106,7 +106,13 @@ int main (void) if(cont) { if(cont->Attach()) - cont->getMaps(); + { + DFHack::Maps * mapz = cont->getMaps(); + cont->Suspend(); + mapz->Start(); + cont->Resume(); + } + bool result = cont->Detach(); if(!result) { From 891c4542561113751d2997e63de7abab84e731aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 14 Aug 2010 20:22:59 +0200 Subject: [PATCH 5/5] Fix build of offset editor skeleton, make it optional and disabled by default. --- CMakeLists.txt | 7 ++++++- offsetedit/CMakeLists.txt | 1 + offsetedit/src/CMakeLists.txt | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 160b71a6f..a03f7d6cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ OPTION(BUILD_DFHACK_DOCUMENTATION "Create doxygen documentation for developers" OPTION(BUILD_DFHACK_EXAMPLES "Build example tools" OFF) OPTION(BUILD_DFHACK_PLAYGROUND "Build tools from the playground folder" OFF) OPTION(BUILD_DFHACK_C_BINDIGS "Build the C portion of the library" ON) +OPTION(BUILD_OFFSET_EDITOR "Build the Offset GUI editor (not ready for use)." OFF) include_directories (${CMAKE_SOURCE_DIR}/library/include/) include_directories (${CMAKE_SOURCE_DIR}/library/shm/) @@ -33,7 +34,11 @@ include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/) include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/) add_subdirectory (library) -add_subdirectory (offsetedit) + +IF(BUILD_OFFSET_EDITOR) + add_subdirectory (offsetedit) +ENDIF(BUILD_OFFSET_EDITOR) + add_subdirectory (library/shm) add_subdirectory (tools/examples) add_subdirectory (tools/playground) diff --git a/offsetedit/CMakeLists.txt b/offsetedit/CMakeLists.txt index 246f3ba3d..f8065bc4c 100644 --- a/offsetedit/CMakeLists.txt +++ b/offsetedit/CMakeLists.txt @@ -1,3 +1,4 @@ + project(dfoffsetedit) cmake_minimum_required(VERSION 2.6) find_package(Qt4 QUIET) diff --git a/offsetedit/src/CMakeLists.txt b/offsetedit/src/CMakeLists.txt index 0804dd66e..9a2218413 100644 --- a/offsetedit/src/CMakeLists.txt +++ b/offsetedit/src/CMakeLists.txt @@ -18,7 +18,7 @@ SET( dfoffsetedit_RCS # in result dfoffsetedit_RC_SRCS variable will contain paths to files produced by rcc QT4_ADD_RESOURCES( dfoffsetedit_RC_SRCS ${dfoffsetedit_RCS} ) -QT4_WRAP_UI(dfoffsetedit_UI_h ${dfedit_UI}) +QT4_WRAP_UI(dfoffsetedit_UI_h ${dfoffsetedit_UI}) qt4_automoc(${dfoffsetedit_SRCS}) add_executable(dfoffsetedit ${dfoffsetedit_SRCS} ${dfoffsetedit_RC_SRCS} ${dfoffsetedit_UI_h})