Merge remote branch 'upstream/master'

develop
doomchild 2010-08-16 13:41:33 -05:00
commit e57be44cde
17 changed files with 158 additions and 42 deletions

@ -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)

@ -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
@ -120,6 +124,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 ;)

@ -346,26 +346,27 @@ allow for easier development of new tools.</p>
<li><a class="reference internal" href="#dfsuspend" id="id17">dfsuspend</a></li>
<li><a class="reference internal" href="#dfexpbench" id="id18">dfexpbench</a></li>
<li><a class="reference internal" href="#dfdoffsets" id="id19">dfdoffsets</a></li>
<li><a class="reference internal" href="#your-tool-here" id="id20">Your tool here</a></li>
<li><a class="reference internal" href="#dfcleartask" id="id20">dfcleartask</a></li>
<li><a class="reference internal" href="#your-tool-here" id="id21">Your tool here</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-the-library-as-a-developer" id="id21">Using the library as a developer</a><ul>
<li><a class="reference internal" href="#contributing-to-dfhack" id="id22">Contributing to DFHack</a><ul>
<li><a class="reference internal" href="#coding-style" id="id23">Coding style</a></li>
<li><a class="reference internal" href="#how-to-get-new-code-into-dfhack" id="id24">How to get new code into DFHack</a></li>
<li><a class="reference internal" href="#layout-for-tools" id="id25">Layout for tools</a></li>
<li><a class="reference internal" href="#modules-what-are-they" id="id26">Modules - what are they?</a></li>
<li><a class="reference internal" href="#dependencies" id="id27">Dependencies</a><ul>
<li><a class="reference internal" href="#current-internal-dependencies" id="id28">Current internal dependencies</a></li>
<li><a class="reference internal" href="#current-external-dependencies" id="id29">Current external dependencies</a></li>
<li><a class="reference internal" href="#build-time-dependencies" id="id30">Build-time dependencies</a></li>
<li><a class="reference internal" href="#using-the-library-as-a-developer" id="id22">Using the library as a developer</a><ul>
<li><a class="reference internal" href="#contributing-to-dfhack" id="id23">Contributing to DFHack</a><ul>
<li><a class="reference internal" href="#coding-style" id="id24">Coding style</a></li>
<li><a class="reference internal" href="#how-to-get-new-code-into-dfhack" id="id25">How to get new code into DFHack</a></li>
<li><a class="reference internal" href="#layout-for-tools" id="id26">Layout for tools</a></li>
<li><a class="reference internal" href="#modules-what-are-they" id="id27">Modules - what are they?</a></li>
<li><a class="reference internal" href="#dependencies" id="id28">Dependencies</a><ul>
<li><a class="reference internal" href="#current-internal-dependencies" id="id29">Current internal dependencies</a></li>
<li><a class="reference internal" href="#current-external-dependencies" id="id30">Current external dependencies</a></li>
<li><a class="reference internal" href="#build-time-dependencies" id="id31">Build-time dependencies</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#memory-offset-definitions" id="id31">Memory offset definitions</a></li>
<li><a class="reference internal" href="#memory-offset-definitions" id="id32">Memory offset definitions</a></li>
</ul>
</div>
</div>
@ -468,13 +469,17 @@ flows.</p>
<h2><a class="toc-backref" href="#id19">dfdoffsets</a></h2>
<p>Dumps the offsets for the currently running DF version into the terminal.</p>
</div>
<div class="section" id="dfcleartask">
<h2><a class="toc-backref" href="#id20">dfcleartask</a></h2>
<p>Solves the problem of unusable items after reclaim by clearing the 'in_job' bit of all items.</p>
</div>
<div class="section" id="your-tool-here">
<h2><a class="toc-backref" href="#id20">Your tool here</a></h2>
<h2><a class="toc-backref" href="#id21">Your tool here</a></h2>
<p>Write one ;)</p>
</div>
</div>
<div class="section" id="using-the-library-as-a-developer">
<h1><a class="toc-backref" href="#id21">Using the library as a developer</a></h1>
<h1><a class="toc-backref" href="#id22">Using the library as a developer</a></h1>
<p>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.</p>
@ -485,17 +490,17 @@ the dfhack repository is welcome and the right thing to do :)</p>
code does have a lot of comments though (and getting better all the
time).</p>
<div class="section" id="contributing-to-dfhack">
<h2><a class="toc-backref" href="#id22">Contributing to DFHack</a></h2>
<h2><a class="toc-backref" href="#id23">Contributing to DFHack</a></h2>
<p>Several things should be kept in mind when contributing to DFHack.</p>
<div class="section" id="coding-style">
<h3><a class="toc-backref" href="#id23">Coding style</a></h3>
<h3><a class="toc-backref" href="#id24">Coding style</a></h3>
<p>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 <em>you</em> fix it ;)</p>
</div>
<div class="section" id="how-to-get-new-code-into-dfhack">
<h3><a class="toc-backref" href="#id24">How to get new code into DFHack</a></h3>
<h3><a class="toc-backref" href="#id25">How to get new code into DFHack</a></h3>
<p>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.</p>
@ -505,7 +510,7 @@ this is also a good place to dump new ideas and/or bugs that need
fixing.</p>
</div>
<div class="section" id="layout-for-tools">
<h3><a class="toc-backref" href="#id25">Layout for tools</a></h3>
<h3><a class="toc-backref" href="#id26">Layout for tools</a></h3>
<p>Tools live in the tools/ folder. There, they are split into three
categories.</p>
<dl class="docutils">
@ -526,7 +531,7 @@ nasty business.</dd>
</dl>
</div>
<div class="section" id="modules-what-are-they">
<h3><a class="toc-backref" href="#id26">Modules - what are they?</a></h3>
<h3><a class="toc-backref" href="#id27">Modules - what are they?</a></h3>
<p>DFHack uses modules to partition sets of features into manageable
chunks. A module can have both client and server side.</p>
<p>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.</p>
pretty fast, but needs quite a bit of care to not break.</p>
</div>
<div class="section" id="dependencies">
<h3><a class="toc-backref" href="#id27">Dependencies</a></h3>
<h3><a class="toc-backref" href="#id28">Dependencies</a></h3>
<dl class="docutils">
<dt>Internal</dt>
<dd>either part of the codebase or statically linked.</dd>
@ -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.</p>
<div class="section" id="current-internal-dependencies">
<h4><a class="toc-backref" href="#id28">Current internal dependencies</a></h4>
<h4><a class="toc-backref" href="#id29">Current internal dependencies</a></h4>
<dl class="docutils">
<dt>tinyxml</dt>
<dd>used by core dfhack to read offset definitions from Memory.xml</dd>
@ -567,7 +572,7 @@ DF binaries on Linux.</dd>
</dl>
</div>
<div class="section" id="current-external-dependencies">
<h4><a class="toc-backref" href="#id29">Current external dependencies</a></h4>
<h4><a class="toc-backref" href="#id30">Current external dependencies</a></h4>
<dl class="docutils">
<dt>wide-character ncurses</dt>
<dd>used for the veinlook tool on Linux.</dd>
@ -576,7 +581,7 @@ DF binaries on Linux.</dd>
</dl>
</div>
<div class="section" id="build-time-dependencies">
<h4><a class="toc-backref" href="#id30">Build-time dependencies</a></h4>
<h4><a class="toc-backref" href="#id31">Build-time dependencies</a></h4>
<dl class="docutils">
<dt>cmake</dt>
<dd>you need cmake to generate the build system and some configuration
@ -587,7 +592,7 @@ headers</dd>
</div>
</div>
<div class="section" id="memory-offset-definitions">
<h1><a class="toc-backref" href="#id31">Memory offset definitions</a></h1>
<h1><a class="toc-backref" href="#id32">Memory offset definitions</a></h1>
<p>The files with memory offset definitions used by dfhack can be found in the
data folder.</p>
</div>

@ -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-ng.xml ${DATA_OUTPUT_PATH}/Memory.xml COPYONLY)
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)

@ -88,6 +88,7 @@ bool Context::Detach()
{
if (!d->p->detach())
{
cerr << "Context::Detach failed!" << endl;
return false;
}
d->shm_start = 0;

@ -569,10 +569,7 @@ bool SHMProcess::attach()
bool SHMProcess::detach()
{
if(!d->attached)
{
return false;
}
if(!d->attached) return true;
if(d->locked)
{
resume();

@ -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

@ -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

@ -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)
{

@ -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;

@ -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?

@ -125,6 +125,7 @@ Maps::~Maps()
{
if(d->Started)
Finish();
delete d;
}
/*-----------------------------------*

@ -1,3 +1,4 @@
project(dfoffsetedit)
cmake_minimum_required(VERSION 2.6)
find_package(Qt4 QUIET)

@ -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})

@ -102,6 +102,23 @@ int main (void)
Cman.Refresh(&inval);
int nCont = Cman.size();
int nInval = inval.size();
DFHack::Context * cont = Cman.getSingleContext();
if(cont)
{
if(cont->Attach())
{
DFHack::Maps * mapz = cont->getMaps();
cont->Suspend();
mapz->Start();
cont->Resume();
}
bool result = cont->Detach();
if(!result)
{
cerr << "Something went horribly wrong during detach" << endl;
}
}
cout << "Contexts:" << endl;
for(int i = 0; i < nCont; i++)

@ -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

@ -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 <stdio.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
using namespace std;
#include <DFHack.h>
#include <dfhack/DFVector.h>
#include <dfhack/DFTypes.h>
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 <uint32_t> p_items (p, item_vec_offset);
uint32_t size = p_items.size();
int numtasked = 0;
for (i=0;i<size;i++)
{
DFHack::t_itemflags flags;
flags.whole = p->readDWord(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;
}