So using those links that Putnam gave, I have started to play with Interposing the vmethod. So far I have
static void handle_syndrome_test(color_ostream &out,df::creature_interaction_effect*,void p1, void p2, int32_t i1, int32_t i2, int16_t i3, int16_t i4, int32_t i5)
DEFINE_LUA_EVENT_8(onSyndromeTest, handle_syndrome_test, df::creature_interaction_effect*,void p1, void p2, int32_t i1, int32_t i2, int16_t i3, int16_t i4, int32_t i5)
DFHACK_PLUGIN_LUA_EVENTS {
DFHACK_LUA_EVENT(onSyndromeTest),
DFHACK_LUA_END
};
struct syn_test : df::creature_interaction_effect{
typedef df::creature_interaction_effect interpose_base;
DEFINE_VMETHOD_INTERPOSE(
void,vmethod_name,
(void p1, void p2, int32_t i1, int32_t i2,
int16_t i3, int16_t i4, int32_t i5)
) {
CoreSuspendClaimer suspend;
color_ostream_proxy out(Core::getinstance().getConsole());
onSyndromeTest(out,this,p1,p2,i1,i2,i3,i4,i5);
INTERPOSE_NEXT(vmethod_name)(p1,p2,i1,i2,i3,i4,i5)
}
};
IMPLEMENT_VMETHOD_INTERPOSE(syn_test, vmethod_name);
static void enable_hooks(bool enable)
{
INTERPOSE_HOOD(syn_test,vmethod_name).apply(enable)
}
DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event)
{
switch (event) {
case SC_WORLD_LOADED:
world_specific_hooks(out,true);
break;
case SC_WORLD_UNLOADED:
world_specific_hooks(out,false);
break;
default:
break;
}
return CR_OK;
}
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
if (Core::getInstance().isWorldLoaded())
plugin_onstatechange(out, SC_WORLD_LOADED);
enable_hooks(true);
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
disable_all_hooks(out);
return CR_OK;
}
Which I got by copying the eventful.cpp and readjusting it for the vmethod I am interested in. The only problem I am having now is the bolded parts in the code, namely;
1. I don't know how to reference the specific vmethod I am interested in. The eventful.cpp ones all have names for their vmethods, and the one I am interested in does not.
2. Similarly, I am unsure what the proper way to reference a pointer is without knowing what it is pointing to. The eventful.cpp ones have things like df::unit*, but again, I do not know anything about the pointers.
Any thoughts? I may move this question over to the DFHack main thread, since it is getting far from the point of this thread, but I figured I would ask here first since we have already been talking about it.