Added dfusion thready flag to spawn another thread

develop
Warmist 2011-08-19 18:09:00 +03:00
parent 7898d2b6b2
commit 97712089bd
3 changed files with 26 additions and 10 deletions

@ -4,6 +4,7 @@ FILE(GLOB DFUSION_CPPS src/*.c*)
set( set(
DFUSION_CPPS_ALL DFUSION_CPPS_ALL
dfusion.cpp dfusion.cpp
${dfhack_SOURCE_DIR}/library/depends/tthread/tinythread.cpp
${DFUSION_CPPS} ${DFUSION_CPPS}
) )
DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} LINK_LIBRARIES lua) DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} LINK_LIBRARIES lua)

@ -24,6 +24,7 @@ using std::string;
using namespace DFHack; using namespace DFHack;
static tthread::mutex* mymutex=0; static tthread::mutex* mymutex=0;
static tthread::thread* thread_dfusion=0;
uint64_t timeLast=0; uint64_t timeLast=0;
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters); DFhackCExport command_result dfusion (Core * c, vector <string> & parameters);
@ -43,9 +44,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
lua::RegisterHexsearch(lua::glua::Get()); lua::RegisterHexsearch(lua::glua::Get());
lua::RegisterMisc(lua::glua::Get()); lua::RegisterMisc(lua::glua::Get());
lua::RegisterVersionInfo(lua::glua::Get()); lua::RegisterVersionInfo(lua::glua::Get());
commands.push_back(PluginCommand("dfusion","Init dfusion system.",dfusion)); 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.\ commands.push_back(PluginCommand("lua", "Run interactive interpreter. Use 'lua <filename>' to run <filename> instead.",lua_run));
\n Options: <filename> = run <filename> instead",lua_run));
mymutex=new tthread::mutex; mymutex=new tthread::mutex;
return CR_OK; return CR_OK;
@ -55,11 +55,13 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
{ {
// shutdown stuff // shutdown stuff
if(thread_dfusion)
delete thread_dfusion;
delete mymutex; delete mymutex;
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_onupdate ( Core * c ) DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c )
{ {
uint64_t time2 = GetTimeMs64(); uint64_t time2 = GetTimeMs64();
uint64_t delta = time2-timeLast; uint64_t delta = time2-timeLast;
@ -137,13 +139,12 @@ DFhackCExport command_result lua_run (Core * c, vector <string> & parameters)
mymutex->unlock(); mymutex->unlock();
return CR_OK; return CR_OK;
} }
DFhackCExport command_result dfusion (Core * c, vector <string> & parameters) void RunDfusion(void *p)
{ {
Console &con=static_cast<Core*>(p)->con;
Console &con=c->con;
mymutex->lock(); mymutex->lock();
lua::state s=lua::glua::Get();
lua::state s=lua::glua::Get();
try{ try{
s.loadfile("dfusion/init.lua"); //load script s.loadfile("dfusion/init.lua"); //load script
s.pcall(0,0);// run it s.pcall(0,0);// run it
@ -151,9 +152,21 @@ DFhackCExport command_result dfusion (Core * c, vector <string> & parameters)
catch(lua::exception &e) catch(lua::exception &e)
{ {
con.printerr("Error:%s\n",e.what()); 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 s.settop(0);// clean up
mymutex->unlock(); mymutex->unlock();
}
DFhackCExport command_result dfusion (Core * c, vector <string> & 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; return CR_OK;
} }

@ -1,6 +1,8 @@
function f_dwarves() function f_dwarves()
//mov DWORD PTR [ESP+14],7
//jmp +0x08
pos_=offsets.findall(0,0x24,0x14,0x07,0,0,0) --search pattern pos_=offsets.findall(0,0x24,0x14,0x07,0,0,0) --search pattern
for _,v in pairs(pos_) do for _,v in pairs(pos_) do
print(string.format("Possible hit:%x",v)) print(string.format("Possible hit:%x",v))