Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/peterix/dfhack
Browse files Browse the repository at this point in the history
  • Loading branch information
warmist committed Feb 15, 2013
2 parents ab6a993 + ac2e45c commit b0528d2
Show file tree
Hide file tree
Showing 36 changed files with 6,018 additions and 500 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ dfhack/python/dist
build/CPack*Config.cmake

/cmakeall.bat

# vim swap files
*.swp
8 changes: 2 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,10 @@ if (NOT EXISTS ${dfhack_SOURCE_DIR}/library/xml/codegen.pl OR NOT EXISTS ${dfhac
endif()

# set up versioning.
set(DF_VERSION_MAJOR "0")
set(DF_VERSION_MINOR "34")
set(DF_VERSION_PATCH "11")
set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}")

set(DF_VERSION "0.34.11")
SET(DFHACK_RELEASE "r2" CACHE STRING "Current release revision.")

set(DFHACK_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}-${DFHACK_RELEASE}")
set(DFHACK_VERSION "${DF_VERSION}-${DFHACK_RELEASE}")
add_definitions(-DDFHACK_VERSION="${DFHACK_VERSION}")

## where to install things (after the build is done, classic 'make install' or package structure)
Expand Down
12 changes: 11 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ DFHack future
Internals:
- support for displaying active keybindings properly.
- support for reusable widgets in lua screen library.
- Maps::canStepBetween: returns whether you can walk between two tiles in one step.
- EventManager: monitors various in game events centrally so that individual plugins don't have to monitor the same things redundantly.
Notable bugfixes:
- autobutcher can be re-enabled again after being stopped.
- stopped Dwarf Manipulator from unmasking vampires.
Expand Down Expand Up @@ -62,7 +64,15 @@ DFHack future
Reworked to make use of lua modules, now all the scripts can be used from other scripts.
New Eventful plugin:
A collection of lua events, that will allow new ways to interact with df world.

Auto syndrome plugin:
A way of automatically applying boiling rock syndromes and calling dfhack commands controlled by raws.
Infinite sky plugin:
Create new z-levels automatically or on request.
True transformation plugin:
A better way of doing permanent transformations that allows later transformations.
Work now plugin:
Makes the game assign jobs every time you pause.

DFHack v0.34.11-r2

Internals:
Expand Down
191 changes: 125 additions & 66 deletions Readme.html

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions Readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,9 @@ directly to the main dwarf mode screen.
Search
======

The search plugin adds search to the Stocks, Trading, Stockpile and Unit List screens.
The search plugin adds search to the Stocks, Animals, Trading, Stockpile,
Noble (assignment candidates), Military (position candidates), Burrows
(unit list), Rooms, Announcements, Job List and Unit List screens.

.. image:: images/search.png

Expand All @@ -2125,8 +2127,9 @@ Leaving any screen automatically clears the filter.

In the Trade screen, the actual trade will always only act on items that
are actually visible in the list; the same effect applies to the Trade
Value numbers displayed by the screen. Because of this, pressing the 't'
key while search is active clears the search instead of executing the trade.
Value numbers displayed by the screen. Because of this, the 't' key is
blocked while search is active, so you have to reset the filters first.
Pressing Alt-C will clear both search strings.

In the stockpile screen the option only appears if the cursor is in the
rightmost list:
Expand Down
3 changes: 3 additions & 0 deletions dfhack.init-example
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ tweak military-training
# write the correct season to gamelog on world load
soundsense-season

# patch the material objects in memory to fix cloth stockpiles
fix/cloth-stockpile enable

#######################################################
# Apply binary patches at runtime #
# #
Expand Down
2 changes: 2 additions & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ include/modules/Burrows.h
include/modules/Constructions.h
include/modules/Units.h
include/modules/Engravings.h
include/modules/EventManager.h
include/modules/Gui.h
include/modules/Items.h
include/modules/Job.h
Expand All @@ -132,6 +133,7 @@ modules/Burrows.cpp
modules/Constructions.cpp
modules/Units.cpp
modules/Engravings.cpp
modules/EventManager.cpp
modules/Gui.cpp
modules/Items.cpp
modules/Job.cpp
Expand Down
6 changes: 6 additions & 0 deletions library/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ using namespace std;
#include "VersionInfo.h"
#include "PluginManager.h"
#include "ModuleFactory.h"
#include "modules/EventManager.h"
#include "modules/Gui.h"
#include "modules/World.h"
#include "modules/Graphic.h"
Expand Down Expand Up @@ -947,6 +948,7 @@ bool Core::Init()
cerr << "Initializing Plugins.\n";
// create plugin manager
plug_mgr = new PluginManager(this);
plug_mgr->init(this);
IODATA *temp = new IODATA;
temp->core = this;
temp->plug_mgr = plug_mgr;
Expand Down Expand Up @@ -1281,6 +1283,8 @@ static int buildings_timer = 0;

void Core::onUpdate(color_ostream &out)
{
EventManager::manageEvents(out);

// convert building reagents
if (buildings_do_onupdate && (++buildings_timer & 1))
buildings_onUpdate(out);
Expand All @@ -1294,6 +1298,8 @@ void Core::onUpdate(color_ostream &out)

void Core::onStateChange(color_ostream &out, state_change_event event)
{
EventManager::onStateChange(out, event);

buildings_onStateChange(out, event);

plug_mgr->OnStateChange(out, event);
Expand Down
36 changes: 22 additions & 14 deletions library/PluginManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ must not be misrepresented as being the original software.
distribution.
*/

#include "modules/EventManager.h"
#include "Internal.h"
#include "Core.h"
#include "MemAccess.h"
Expand Down Expand Up @@ -211,9 +212,10 @@ bool Plugin::load(color_ostream &con)
}
const char ** plug_name =(const char ** ) LookupPlugin(plug, "name");
const char ** plug_version =(const char ** ) LookupPlugin(plug, "version");
if(!plug_name || !plug_version)
Plugin **plug_self = (Plugin**)LookupPlugin(plug, "plugin_self");
if(!plug_name || !plug_version || !plug_self)
{
con.printerr("Plugin %s has no name or version.\n", filename.c_str());
con.printerr("Plugin %s has no name, version or self pointer.\n", filename.c_str());
ClosePlugin(plug);
RefAutolock lock(access);
state = PS_BROKEN;
Expand All @@ -228,6 +230,7 @@ bool Plugin::load(color_ostream &con)
state = PS_BROKEN;
return false;
}
*plug_self = this;
RefAutolock lock(access);
plugin_init = (command_result (*)(color_ostream &, std::vector <PluginCommand> &)) LookupPlugin(plug, "plugin_init");
if(!plugin_init)
Expand Down Expand Up @@ -270,6 +273,7 @@ bool Plugin::unload(color_ostream &con)
// if we are actually loaded
if(state == PS_LOADED)
{
EventManager::unregisterAll(this);
// notify the plugin about an attempt to shutdown
if (plugin_onstatechange &&
plugin_onstatechange(con, SC_BEGIN_UNLOAD) == CR_NOT_FOUND)
Expand Down Expand Up @@ -598,6 +602,22 @@ void Plugin::push_function(lua_State *state, LuaFunction *fn)
}

PluginManager::PluginManager(Core * core)
{
cmdlist_mutex = new mutex();
eval_ruby = NULL;
}

PluginManager::~PluginManager()
{
for(size_t i = 0; i < all_plugins.size();i++)
{
delete all_plugins[i];
}
all_plugins.clear();
delete cmdlist_mutex;
}

void PluginManager::init(Core * core)
{
#ifdef LINUX_BUILD
string path = core->getHackPath() + "plugins/";
Expand All @@ -606,8 +626,6 @@ PluginManager::PluginManager(Core * core)
string path = core->getHackPath() + "plugins\\";
const string searchstr = ".plug.dll";
#endif
cmdlist_mutex = new mutex();
eval_ruby = NULL;
vector <string> filez;
getdir(path, filez);
for(size_t i = 0; i < filez.size();i++)
Expand All @@ -622,16 +640,6 @@ PluginManager::PluginManager(Core * core)
}
}

PluginManager::~PluginManager()
{
for(size_t i = 0; i < all_plugins.size();i++)
{
delete all_plugins[i];
}
all_plugins.clear();
delete cmdlist_mutex;
}

Plugin *PluginManager::getPluginByName (const std::string & name)
{
for(size_t i = 0; i < all_plugins.size(); i++)
Expand Down
55 changes: 52 additions & 3 deletions library/VTableInterpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,54 @@ using namespace DFHack;

/*
* Code for accessing method pointers directly. Very compiler-specific.
*
* Pointers to methods in C++ are conceptually similar to pointers to
* functions, but with some complications. Specifically, the target of
* such pointer can be either:
*
* - An ordinary non-virtual method, in which case the pointer behaves
* not much differently from a simple function pointer.
* - A virtual method, in which case calling the pointer must emulate
* an ordinary call to that method, i.e. fetch the real code address
* from the vtable at the appropriate index.
*
* This means that pointers to virtual methods actually have to encode
* the relevant vtable index value in some way. Also, since these two
* types of pointers cannot be distinguished by data type and differ
* only in value, any sane compiler would ensure that any non-virtual
* method that can potentially be called via a pointer uses the same
* parameter passing rules as an equivalent virtual method, so that
* the same parameter passing code would work with both types of pointer.
*
* This means that with a few small low-level compiler-specific wrappers
* to access the data inside such pointers it is possible to:
*
* - Convert a non-virtual method pointer into a code address that
* can be directly put into a vtable.
* - Convert a pointer taken out of a vtable into a fake non-virtual
* method pointer that can be used to easily call the original
* vmethod body.
* - Extract a vtable index out of a virtual method pointer.
*
* Taken together, these features allow delegating all the difficult
* and fragile tasks like passing parameters and calculating the
* vtable index to the C++ compiler.
*/

#if defined(_MSC_VER)

// MSVC may use up to 3 different representations
// based on context, but adding the /vmg /vmm options
// forces it to stick to this one. It can accomodate
// multiple, but not virtual inheritance.
struct MSVC_MPTR {
void *method;
intptr_t this_shift;
};

// Debug builds sometimes use additional thunks that
// just jump to the real one, presumably to attach some
// additional debug info.
static uint32_t *follow_jmp(void *ptr)
{
uint8_t *p = (uint8_t*)ptr;
Expand All @@ -56,10 +95,10 @@ static uint32_t *follow_jmp(void *ptr)
{
switch (*p)
{
case 0xE9:
case 0xE9: // jmp near rel32
p += 5 + *(int32_t*)(p+1);
break;
case 0xEB:
case 0xEB: // jmp short rel8
p += 2 + *(int8_t*)(p+1);
break;
default:
Expand Down Expand Up @@ -120,8 +159,10 @@ void DFHack::addr_to_method_pointer_(void *pptr, void *addr)

#elif defined(__GXX_ABI_VERSION)

// GCC seems to always use this structure - possibly unless
// virtual inheritance is involved, but that's irrelevant.
struct GCC_MPTR {
intptr_t method;
intptr_t method; // Code pointer or tagged vtable offset
intptr_t this_shift;
};

Expand Down Expand Up @@ -254,6 +295,14 @@ VMethodInterposeLinkBase::VMethodInterposeLinkBase(virtual_identity *host, int v
{
if (vmethod_idx < 0 || interpose_method == NULL)
{
/*
* A failure here almost certainly means a problem in one
* of the pointer-to-method access wrappers above:
*
* - vmethod_idx comes from vmethod_pointer_to_idx_
* - interpose_method comes from method_pointer_to_addr_
*/

fprintf(stderr, "Bad VMethodInterposeLinkBase arguments: %d %08x\n",
vmethod_idx, unsigned(interpose_method));
fflush(stderr);
Expand Down
4 changes: 3 additions & 1 deletion library/include/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ namespace DFHack
friend class Plugin;
PluginManager(Core * core);
~PluginManager();
void init(Core* core);
void OnUpdate(color_ostream &out);
void OnStateChange(color_ostream &out, state_change_event event);
void registerCommands( Plugin * p );
Expand Down Expand Up @@ -246,7 +247,8 @@ namespace DFHack
/// You have to have this in every plugin you write - just once. Ideally on top of the main file.
#define DFHACK_PLUGIN(plugin_name) \
DFhackDataExport const char * version = DFHACK_VERSION;\
DFhackDataExport const char * name = plugin_name;
DFhackDataExport const char * name = plugin_name;\
DFhackDataExport Plugin *plugin_self = NULL;

#define DFHACK_PLUGIN_LUA_COMMANDS \
DFhackCExport const DFHack::CommandReg plugin_lua_commands[] =
Expand Down
Loading

0 comments on commit b0528d2

Please sign in to comment.