From 97712089bd09f29de82e3471438429b8810d219e Mon Sep 17 00:00:00 2001 From: Warmist Date: Fri, 19 Aug 2011 18:09:00 +0300 Subject: [PATCH] Added dfusion thready flag to spawn another thread --- plugins/Dfusion/CMakeLists.txt | 1 + plugins/Dfusion/dfusion.cpp | 31 ++++++++++++++++++++-------- plugins/Dfusion/luafiles/offsets.lua | 4 +++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/plugins/Dfusion/CMakeLists.txt b/plugins/Dfusion/CMakeLists.txt index d17e66a23..7b6724dde 100644 --- a/plugins/Dfusion/CMakeLists.txt +++ b/plugins/Dfusion/CMakeLists.txt @@ -4,6 +4,7 @@ FILE(GLOB DFUSION_CPPS src/*.c*) set( DFUSION_CPPS_ALL dfusion.cpp + ${dfhack_SOURCE_DIR}/library/depends/tthread/tinythread.cpp ${DFUSION_CPPS} ) DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} LINK_LIBRARIES lua) diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index f75ce69b2..2495f1a25 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -24,6 +24,7 @@ using std::string; using namespace DFHack; static tthread::mutex* mymutex=0; +static tthread::thread* thread_dfusion=0; uint64_t timeLast=0; DFhackCExport command_result dfusion (Core * c, vector & parameters); @@ -43,9 +44,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector lua::RegisterHexsearch(lua::glua::Get()); lua::RegisterMisc(lua::glua::Get()); lua::RegisterVersionInfo(lua::glua::Get()); - commands.push_back(PluginCommand("dfusion","Init dfusion system.",dfusion)); - commands.push_back(PluginCommand("lua", "Run interactive interpreter.\ -\n Options: = run instead",lua_run)); + commands.push_back(PluginCommand("dfusion","Init dfusion system. Use 'dfusion thready' to spawn a different thread.",dfusion)); + commands.push_back(PluginCommand("lua", "Run interactive interpreter. Use 'lua ' to run instead.",lua_run)); mymutex=new tthread::mutex; return CR_OK; @@ -55,11 +55,13 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) { // shutdown stuff + if(thread_dfusion) + delete thread_dfusion; delete mymutex; return CR_OK; } -DFhackCExport command_result plugin_onupdate ( Core * c ) +DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c ) { uint64_t time2 = GetTimeMs64(); uint64_t delta = time2-timeLast; @@ -137,13 +139,12 @@ DFhackCExport command_result lua_run (Core * c, vector & parameters) mymutex->unlock(); return CR_OK; } -DFhackCExport command_result dfusion (Core * c, vector & parameters) +void RunDfusion(void *p) { - - Console &con=c->con; + Console &con=static_cast(p)->con; mymutex->lock(); + lua::state s=lua::glua::Get(); - try{ s.loadfile("dfusion/init.lua"); //load script s.pcall(0,0);// run it @@ -151,9 +152,21 @@ DFhackCExport command_result dfusion (Core * c, vector & parameters) catch(lua::exception &e) { con.printerr("Error:%s\n",e.what()); - c->con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); + con.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str()); } s.settop(0);// clean up mymutex->unlock(); +} +DFhackCExport command_result dfusion (Core * c, vector & parameters) +{ + if(thread_dfusion==0) + thread_dfusion=new tthread::thread(RunDfusion,c); + if(parameters[0]!="thready") + { + thread_dfusion->join(); + delete thread_dfusion; + thread_dfusion=0; + } + return CR_OK; } diff --git a/plugins/Dfusion/luafiles/offsets.lua b/plugins/Dfusion/luafiles/offsets.lua index 9d684b62a..e15f5b7e9 100644 --- a/plugins/Dfusion/luafiles/offsets.lua +++ b/plugins/Dfusion/luafiles/offsets.lua @@ -1,7 +1,9 @@ function f_dwarves() - pos_=offsets.findall(0,0x24,0x14,0x07,0,0,0) --search pattern + //mov DWORD PTR [ESP+14],7 + //jmp +0x08 + pos_=offsets.findall(0,0x24,0x14,0x07,0,0,0) --search pattern for _,v in pairs(pos_) do print(string.format("Possible hit:%x",v)) end