|
|
@ -174,6 +174,8 @@ void fIOthread(void * iodata)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
string first = parts[0];
|
|
|
|
string first = parts[0];
|
|
|
|
parts.erase(parts.begin());
|
|
|
|
parts.erase(parts.begin());
|
|
|
|
|
|
|
|
cerr << "Invoking: " << command << endl;
|
|
|
|
|
|
|
|
|
|
|
|
// let's see what we actually got
|
|
|
|
// let's see what we actually got
|
|
|
|
if(first=="help" || first == "?")
|
|
|
|
if(first=="help" || first == "?")
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -351,7 +353,7 @@ void fIOthread(void * iodata)
|
|
|
|
command_result res = plug_mgr->InvokeCommand(first, parts);
|
|
|
|
command_result res = plug_mgr->InvokeCommand(first, parts);
|
|
|
|
if(res == CR_NOT_IMPLEMENTED)
|
|
|
|
if(res == CR_NOT_IMPLEMENTED)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
con.printerr("Invalid command.\n");
|
|
|
|
con.printerr("%s is not a recognized command.\n", first.c_str());
|
|
|
|
clueless_counter ++;
|
|
|
|
clueless_counter ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -393,6 +395,23 @@ Core::Core()
|
|
|
|
misc_data_mutex=0;
|
|
|
|
misc_data_mutex=0;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Core::fatal (std::string output, bool deactivate)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
stringstream out;
|
|
|
|
|
|
|
|
out << output ;
|
|
|
|
|
|
|
|
if(deactivate)
|
|
|
|
|
|
|
|
out << "DFHack will now deactivate.\n";
|
|
|
|
|
|
|
|
if(con.isInited())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
con.printerr("%s", out.str().c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%s\n", out.str().c_str());
|
|
|
|
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
|
|
|
|
out << "Check file stderr.log for details\n";
|
|
|
|
|
|
|
|
MessageBox(0,out.str().c_str(),"DFHack error!", MB_OK | MB_ICONERROR);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Core::Init()
|
|
|
|
bool Core::Init()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if(started)
|
|
|
|
if(started)
|
|
|
@ -406,30 +425,48 @@ bool Core::Init()
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
const char * path = "hack\\Memory.xml";
|
|
|
|
const char * path = "hack\\Memory.xml";
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
vif = new DFHack::VersionInfoFactory(path);
|
|
|
|
vif = new DFHack::VersionInfoFactory();
|
|
|
|
|
|
|
|
cerr << "Identifying DF version.\n";
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
vif->loadFile(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch(Error::All & err)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::stringstream out;
|
|
|
|
|
|
|
|
out << "Error while reading Memory.xml:\n";
|
|
|
|
|
|
|
|
out << err.what() << std::endl;
|
|
|
|
|
|
|
|
delete vif;
|
|
|
|
|
|
|
|
vif = nullptr;
|
|
|
|
|
|
|
|
errorstate = true;
|
|
|
|
|
|
|
|
fatal(out.str(), true);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
p = new DFHack::Process(vif);
|
|
|
|
p = new DFHack::Process(vif);
|
|
|
|
vinfo = p->getDescriptor();
|
|
|
|
vinfo = p->getDescriptor();
|
|
|
|
|
|
|
|
|
|
|
|
if(!vinfo || !p->isIdentified())
|
|
|
|
if(!vinfo || !p->isIdentified())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
cerr << "Not a known DF version. DFHack will now deactivate.\n";
|
|
|
|
fatal ("Not a known DF version.\n", true);
|
|
|
|
errorstate = true;
|
|
|
|
errorstate = true;
|
|
|
|
delete p;
|
|
|
|
delete p;
|
|
|
|
p = NULL;
|
|
|
|
p = NULL;
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cerr << "Version: " << vinfo->getVersion() << endl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cerr << "Initializing Console.\n";
|
|
|
|
// init the console.
|
|
|
|
// init the console.
|
|
|
|
Gui * g = getGui();
|
|
|
|
Gui * g = getGui();
|
|
|
|
if(g->init)
|
|
|
|
bool is_text_mode = false;
|
|
|
|
{
|
|
|
|
if(g->init && g->init->graphics.flags.is_set(GRAPHICS_TEXT))
|
|
|
|
if(g->init->graphics.flags.is_set(GRAPHICS_TEXT))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
con.init(true);
|
|
|
|
is_text_mode = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else con.init(false);
|
|
|
|
if(con.init(is_text_mode))
|
|
|
|
}
|
|
|
|
cerr << "Console is running.\n";
|
|
|
|
else con.init(false);
|
|
|
|
else
|
|
|
|
|
|
|
|
fatal ("Console has failed to initialize!\n", false);
|
|
|
|
|
|
|
|
|
|
|
|
// dump offsets to a file
|
|
|
|
// dump offsets to a file
|
|
|
|
std::ofstream dump("offsets.log");
|
|
|
|
std::ofstream dump("offsets.log");
|
|
|
@ -444,18 +481,22 @@ bool Core::Init()
|
|
|
|
AccessMutex = new mutex();
|
|
|
|
AccessMutex = new mutex();
|
|
|
|
misc_data_mutex=new mutex();
|
|
|
|
misc_data_mutex=new mutex();
|
|
|
|
core_cond = new Core::Cond();
|
|
|
|
core_cond = new Core::Cond();
|
|
|
|
|
|
|
|
cerr << "Initializing Plugins.\n";
|
|
|
|
// create plugin manager
|
|
|
|
// create plugin manager
|
|
|
|
plug_mgr = new PluginManager(this);
|
|
|
|
plug_mgr = new PluginManager(this);
|
|
|
|
|
|
|
|
cerr << "Starting IO thread.\n";
|
|
|
|
// create IO thread
|
|
|
|
// create IO thread
|
|
|
|
IODATA *temp = new IODATA;
|
|
|
|
IODATA *temp = new IODATA;
|
|
|
|
temp->core = this;
|
|
|
|
temp->core = this;
|
|
|
|
temp->plug_mgr = plug_mgr;
|
|
|
|
temp->plug_mgr = plug_mgr;
|
|
|
|
thread * IO = new thread(fIOthread, (void *) temp);
|
|
|
|
thread * IO = new thread(fIOthread, (void *) temp);
|
|
|
|
|
|
|
|
cerr << "Starting DF input capture thread.\n";
|
|
|
|
// set up hotkey capture
|
|
|
|
// set up hotkey capture
|
|
|
|
HotkeyMutex = new mutex();
|
|
|
|
HotkeyMutex = new mutex();
|
|
|
|
HotkeyCond = new condition_variable();
|
|
|
|
HotkeyCond = new condition_variable();
|
|
|
|
thread * HK = new thread(fHKthread, (void *) temp);
|
|
|
|
thread * HK = new thread(fHKthread, (void *) temp);
|
|
|
|
started = true;
|
|
|
|
started = true;
|
|
|
|
|
|
|
|
cerr << "DFHack is running.\n";
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// sets the current hotkey command
|
|
|
|
/// sets the current hotkey command
|
|
|
@ -565,6 +606,8 @@ int Core::Update()
|
|
|
|
// FIXME: needs to terminate the IO threads and properly dismantle all the machinery involved.
|
|
|
|
// FIXME: needs to terminate the IO threads and properly dismantle all the machinery involved.
|
|
|
|
int Core::Shutdown ( void )
|
|
|
|
int Core::Shutdown ( void )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if(errorstate)
|
|
|
|
|
|
|
|
return true;
|
|
|
|
errorstate = 1;
|
|
|
|
errorstate = 1;
|
|
|
|
if(plug_mgr)
|
|
|
|
if(plug_mgr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|