summaryrefslogtreecommitdiff
path: root/library/include
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-18 11:48:07 +0400
committerAlexander Gavrilov2012-08-18 11:48:07 +0400
commit01ba2a31fc2dd7597ab6e2db3f1496b123e10720 (patch)
tree60de15f2bd50bca0bb9e68f82dc77c1d85014934 /library/include
parent236ffd578b66805fa45d65df79e099d00156bfff (diff)
downloaddfhack-01ba2a31fc2dd7597ab6e2db3f1496b123e10720.tar.gz
dfhack-01ba2a31fc2dd7597ab6e2db3f1496b123e10720.tar.bz2
dfhack-01ba2a31fc2dd7597ab6e2db3f1496b123e10720.tar.xz
Tweak the interpose API, and fix a couple of bugs.
Diffstat (limited to 'library/include')
-rw-r--r--library/include/VTableInterpose.h20
1 files changed, 16 insertions, 4 deletions
diff --git a/library/include/VTableInterpose.h b/library/include/VTableInterpose.h
index 59a5c283..5eaeaed8 100644
--- a/library/include/VTableInterpose.h
+++ b/library/include/VTableInterpose.h
@@ -81,12 +81,18 @@ namespace DFHack
return addr_to_method_pointer<P>(identity.get_vmethod_ptr(idx));
}
- /* VMethod interpose API
+ /* VMethod interpose API.
+
+ This API allows replacing an entry in the original vtable
+ with code defined by DFHack, while retaining ability to
+ call the original code. The API can be safely used from
+ plugins, and multiple hooks for the same vmethod are
+ automatically chained in undefined order.
Usage:
- struct my_hack : public someclass {
- typedef someclass interpose_base;
+ struct my_hack : df::someclass {
+ typedef df::someclass interpose_base;
DEFINE_VMETHOD_INTERPOSE(void, foo, (int arg)) {
...
@@ -98,7 +104,12 @@ namespace DFHack
IMPLEMENT_VMETHOD_INTERPOSE(my_hack, foo);
void init() {
- my_hack::interpose_foo.apply()
+ if (!INTERPOSE_HOOK(my_hack, foo).apply())
+ error();
+ }
+
+ void shutdown() {
+ INTERPOSE_HOOK(my_hack, foo).remove();
}
*/
@@ -112,6 +123,7 @@ namespace DFHack
class::interpose_##name(&class::interpose_base::name, &class::interpose_fn_##name);
#define INTERPOSE_NEXT(name) (this->*interpose_##name.chain)
+#define INTERPOSE_HOOK(class, name) (class::interpose_##name)
class DFHACK_EXPORT VMethodInterposeLinkBase {
/*