|
|
@ -6,16 +6,11 @@
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "tinythread.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "luamain.h"
|
|
|
|
#include "luamain.h"
|
|
|
|
#include "lua_Process.h"
|
|
|
|
#include "lua_Process.h"
|
|
|
|
#include "lua_Hexsearch.h"
|
|
|
|
#include "lua_Hexsearch.h"
|
|
|
|
#include "lua_Misc.h"
|
|
|
|
#include "lua_Misc.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "LuaTools.h"
|
|
|
|
#include "LuaTools.h"
|
|
|
|
|
|
|
|
|
|
|
@ -23,112 +18,51 @@ using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
|
|
|
static tthread::mutex* mymutex=0;
|
|
|
|
|
|
|
|
static tthread::thread* thread_dfusion=0;
|
|
|
|
|
|
|
|
uint64_t timeLast=0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("dfusion")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
command_result dfusion (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
DFHACK_PLUGIN("dfusion")
|
|
|
|
command_result dfuse (color_ostream &out, std::vector <std::string> ¶meters);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return "dfusion";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
static int loadObjectFile(lua_State* L)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua::state st=lua::glua::Get();
|
|
|
|
std::string path;
|
|
|
|
|
|
|
|
|
|
|
|
//maybe remake it to run automatically
|
|
|
|
path=luaL_checkstring(L,1);
|
|
|
|
Lua::Open(out, st);
|
|
|
|
|
|
|
|
|
|
|
|
OutFile::File f(path);
|
|
|
|
lua::RegisterProcess(st);
|
|
|
|
lua_newtable(L);
|
|
|
|
lua::RegisterHexsearch(st);
|
|
|
|
int table_pos=lua_gettop(L);
|
|
|
|
lua::RegisterMisc(st);
|
|
|
|
size_t size=f.GetTextSize();
|
|
|
|
|
|
|
|
Lua::Push(L,size);
|
|
|
|
#ifdef LINUX_BUILD
|
|
|
|
lua_setfield(L,table_pos,"data_size");
|
|
|
|
st.push(1);
|
|
|
|
char* buf=new char[size];
|
|
|
|
st.setglobal("LINUX");
|
|
|
|
f.GetText(buf);
|
|
|
|
#else
|
|
|
|
|
|
|
|
st.push(1);
|
|
|
|
//Lua::PushDFObject(L,DFHack::,buf);
|
|
|
|
st.setglobal("WINDOWS");
|
|
|
|
//Lua::Push(L,buf);
|
|
|
|
#endif
|
|
|
|
lua_pushlightuserdata(L,buf);
|
|
|
|
|
|
|
|
lua_setfield(L,table_pos,"data");
|
|
|
|
commands.push_back(PluginCommand("dfusion","Run dfusion system (interactive i.e. can input further commands).",dfusion,true));
|
|
|
|
OutFile::vSymbol& symbols=f.GetSymbols();
|
|
|
|
commands.push_back(PluginCommand("dfuse","Init dfusion system (not interactive).",dfuse,false));
|
|
|
|
lua_newtable(L);
|
|
|
|
mymutex=new tthread::mutex;
|
|
|
|
for(size_t i=0;i<symbols.size();i++)
|
|
|
|
return CR_OK;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Lua::Push(L,i);
|
|
|
|
|
|
|
|
lua_newtable(L);
|
|
|
|
|
|
|
|
Lua::Push(L,symbols[i].name);
|
|
|
|
|
|
|
|
lua_setfield(L,-2,"name");
|
|
|
|
|
|
|
|
Lua::Push(L,symbols[i].pos);
|
|
|
|
|
|
|
|
lua_setfield(L,-2,"pos");
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// shutdown stuff
|
|
|
|
lua_settable(L,-3);
|
|
|
|
if(thread_dfusion)
|
|
|
|
|
|
|
|
delete thread_dfusion;
|
|
|
|
|
|
|
|
delete mymutex;
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onupdate_DISABLED ( Core * c )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
uint64_t time2 = GetTimeMs64();
|
|
|
|
|
|
|
|
uint64_t delta = time2-timeLast;
|
|
|
|
|
|
|
|
if(delta<100)
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
timeLast = time2;
|
|
|
|
|
|
|
|
mymutex->lock();
|
|
|
|
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
|
|
|
s.getglobal("OnTick");
|
|
|
|
|
|
|
|
if(s.is<lua::function>())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
s.pcall();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(lua::exception &e)
|
|
|
|
lua_setfield(L,table_pos,"symbols");
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
c->getConsole().printerr("Error OnTick:%s\n",e.what());
|
|
|
|
|
|
|
|
c->getConsole().printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
|
|
|
|
c->getConsole().msleep(1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s.settop(0);
|
|
|
|
|
|
|
|
mymutex->unlock();
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunDfusion(color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
mymutex->lock();
|
|
|
|
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
s.loadfile("dfusion/init.lua"); //load script
|
|
|
|
|
|
|
|
for(size_t i=0;i<parameters.size();i++)
|
|
|
|
|
|
|
|
s.push(parameters[i]);
|
|
|
|
|
|
|
|
Lua::SafeCall(out, s, parameters.size(),0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(lua::exception &e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.printerr("Error:%s\n",e.what());
|
|
|
|
|
|
|
|
out.printerr("%s\n",lua::DebugDump(lua::glua::Get()).c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s.settop(0);// clean up
|
|
|
|
|
|
|
|
mymutex->unlock();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
command_result dfuse(color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
|
|
|
s.push(1);
|
|
|
|
|
|
|
|
s.setglobal("INIT");
|
|
|
|
|
|
|
|
RunDfusion(out,parameters);
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_result dfusion (color_ostream &out, std::vector <std::string> ¶meters)
|
|
|
|
DFHACK_PLUGIN_LUA_COMMANDS {
|
|
|
|
|
|
|
|
DFHACK_LUA_COMMAND(loadObjectFile),
|
|
|
|
|
|
|
|
DFHACK_LUA_END
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
lua::state s=lua::glua::Get();
|
|
|
|
|
|
|
|
s.push();
|
|
|
|
|
|
|
|
s.setglobal("INIT");
|
|
|
|
|
|
|
|
RunDfusion(out,parameters);
|
|
|
|
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|