Merge branch 'master' of http://github.com/peterix/dfhack
commit
4dd5718c06
@ -0,0 +1,485 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
#include "Internal.h"
|
||||||
|
#include "SHMProcess.h"
|
||||||
|
#include "ProcessFactory.h"
|
||||||
|
#include "dfhack/VersionInfo.h"
|
||||||
|
#include "dfhack/DFError.h"
|
||||||
|
#include "shms.h"
|
||||||
|
#include "mod-core.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
Process* DFHack::createSHMProcess(uint32_t pid, vector <VersionInfo *> & known_versions)
|
||||||
|
{
|
||||||
|
return new SHMProcess(pid, known_versions);
|
||||||
|
}
|
||||||
|
|
||||||
|
SHMProcess::SHMProcess(uint32_t PID, vector <VersionInfo *> & known_versions)
|
||||||
|
: d(new Private(this))
|
||||||
|
{
|
||||||
|
d->process_ID = PID;
|
||||||
|
// attach the SHM
|
||||||
|
if(!attach())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Test bridge version, get PID, sync Yield
|
||||||
|
bool bridgeOK;
|
||||||
|
if(!d->Aux_Core_Attach(bridgeOK,d->process_ID))
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
throw Error::SHMAttachFailure();
|
||||||
|
}
|
||||||
|
else if(!bridgeOK)
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
throw Error::SHMVersionMismatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to identify the DF version (md5 the binary, compare with known versions)
|
||||||
|
d->validate(known_versions);
|
||||||
|
// at this point, DF is attached and suspended, make it run
|
||||||
|
detach();
|
||||||
|
}
|
||||||
|
|
||||||
|
SHMProcess::~SHMProcess()
|
||||||
|
{
|
||||||
|
if(d->attached)
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
}
|
||||||
|
// destroy data model. this is assigned by processmanager
|
||||||
|
if(d->memdescriptor)
|
||||||
|
delete d->memdescriptor;
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionInfo * SHMProcess::getDescriptor()
|
||||||
|
{
|
||||||
|
return d->memdescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SHMProcess::getPID()
|
||||||
|
{
|
||||||
|
return d->process_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SHMProcess::isSuspended()
|
||||||
|
{
|
||||||
|
return d->locked;
|
||||||
|
}
|
||||||
|
bool SHMProcess::isAttached()
|
||||||
|
{
|
||||||
|
return d->attached;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHMProcess::isIdentified()
|
||||||
|
{
|
||||||
|
return d->identified;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHMProcess::suspend()
|
||||||
|
{
|
||||||
|
if(!d->attached)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(d->locked)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//cerr << "suspend" << endl;// FIXME: throw
|
||||||
|
// FIXME: this should be controlled on the server side
|
||||||
|
// FIXME: IF server got CORE_RUN in this frame, interpret CORE_SUSPEND as CORE_STEP
|
||||||
|
// did we just resume a moment ago?
|
||||||
|
if(D_SHMCMD == CORE_RUN)
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"%d invokes step\n",attachmentIdx);
|
||||||
|
// wait for the next window
|
||||||
|
/*
|
||||||
|
if(!d->SetAndWait(CORE_STEP))
|
||||||
|
{
|
||||||
|
throw Error::SHMLockingError("if(!d->SetAndWait(CORE_STEP))");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
D_SHMCMD = CORE_STEP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//fprintf(stderr,"%d invokes suspend\n",attachmentIdx);
|
||||||
|
// lock now
|
||||||
|
/*
|
||||||
|
if(!d->SetAndWait(CORE_SUSPEND))
|
||||||
|
{
|
||||||
|
throw Error::SHMLockingError("if(!d->SetAndWait(CORE_SUSPEND))");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
D_SHMCMD = CORE_SUSPEND;
|
||||||
|
}
|
||||||
|
//fprintf(stderr,"waiting for lock\n");
|
||||||
|
// we wait for the server to give up our suspend lock (held by default)
|
||||||
|
if(acquireSuspendLock())
|
||||||
|
{
|
||||||
|
d->locked = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: needs a good think-through
|
||||||
|
bool SHMProcess::asyncSuspend()
|
||||||
|
{
|
||||||
|
if(!d->attached)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(d->locked)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//cerr << "async suspend" << endl;// FIXME: throw
|
||||||
|
uint32_t cmd = D_SHMCMD;
|
||||||
|
if(cmd == CORE_SUSPENDED)
|
||||||
|
{
|
||||||
|
// we have to hold the lock to be really suspended
|
||||||
|
if(acquireSuspendLock())
|
||||||
|
{
|
||||||
|
d->locked = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// did we just resume a moment ago?
|
||||||
|
if(cmd == CORE_STEP)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if(cmd == CORE_RUN)
|
||||||
|
{
|
||||||
|
D_SHMCMD = CORE_STEP;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
D_SHMCMD = CORE_SUSPEND;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHMProcess::forceresume()
|
||||||
|
{
|
||||||
|
return resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: wait for the server to advance a step!
|
||||||
|
bool SHMProcess::resume()
|
||||||
|
{
|
||||||
|
if(!d->attached)
|
||||||
|
return false;
|
||||||
|
if(!d->locked)
|
||||||
|
return true;
|
||||||
|
//cerr << "resume" << endl;// FIXME: throw
|
||||||
|
// unlock the suspend lock
|
||||||
|
if(releaseSuspendLock())
|
||||||
|
{
|
||||||
|
d->locked = false;
|
||||||
|
if(d->SetAndWait(CORE_RUN)) // we have to make sure the server responds!
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw Error::SHMLockingError("if(d->SetAndWait(CORE_RUN))");
|
||||||
|
}
|
||||||
|
throw Error::SHMLockingError("if(releaseSuspendLock())");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get module index by name and version. bool 0 = error
|
||||||
|
bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
modulelookup * payload = D_SHMDATA(modulelookup);
|
||||||
|
payload->version = version;
|
||||||
|
|
||||||
|
strncpy(payload->name,name,255);
|
||||||
|
payload->name[255] = 0;
|
||||||
|
|
||||||
|
if(!SetAndWait(CORE_ACQUIRE_MODULE))
|
||||||
|
{
|
||||||
|
return false; // FIXME: throw a fatal exception instead
|
||||||
|
}
|
||||||
|
if(D_SHMHDR->error)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//fprintf(stderr,"%s v%d : %d\n", name, version, D_SHMHDR->value);
|
||||||
|
OUTPUT = D_SHMHDR->value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SHMProcess::Private::Aux_Core_Attach(bool & versionOK, pid_t & PID)
|
||||||
|
{
|
||||||
|
if(!locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
SHMDATA(coreattach)->cl_affinity = OS_getAffinity();
|
||||||
|
if(!SetAndWait(CORE_ATTACH)) return false;
|
||||||
|
/*
|
||||||
|
cerr <<"CORE_VERSION" << CORE_VERSION << endl;
|
||||||
|
cerr <<"server CORE_VERSION" << SHMDATA(coreattach)->sv_version << endl;
|
||||||
|
*/
|
||||||
|
versionOK =( SHMDATA(coreattach)->sv_version == CORE_VERSION );
|
||||||
|
PID = SHMDATA(coreattach)->sv_PID;
|
||||||
|
useYield = SHMDATA(coreattach)->sv_useYield;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if(useYield) cerr << "Using Yield!" << endl;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::read (uint32_t src_address, uint32_t size, uint8_t *target_buffer)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
// normal read under 1MB
|
||||||
|
if(size <= SHM_BODY)
|
||||||
|
{
|
||||||
|
D_SHMHDR->address = src_address;
|
||||||
|
D_SHMHDR->length = size;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ);
|
||||||
|
memcpy (target_buffer, D_SHMDATA(void),size);
|
||||||
|
}
|
||||||
|
// a big read, we pull data over the shm in iterations
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// first read equals the size of the SHM window
|
||||||
|
uint32_t to_read = SHM_BODY;
|
||||||
|
while (size)
|
||||||
|
{
|
||||||
|
// read to_read bytes from src_cursor
|
||||||
|
D_SHMHDR->address = src_address;
|
||||||
|
D_SHMHDR->length = to_read;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ);
|
||||||
|
memcpy (target_buffer, D_SHMDATA(void) ,to_read);
|
||||||
|
// decrease size by bytes read
|
||||||
|
size -= to_read;
|
||||||
|
// move the cursors
|
||||||
|
src_address += to_read;
|
||||||
|
target_buffer += to_read;
|
||||||
|
// check how much to write in the next iteration
|
||||||
|
to_read = min(size, (uint32_t) SHM_BODY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::readByte (const uint32_t offset, uint8_t &val )
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_BYTE);
|
||||||
|
val = D_SHMHDR->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::readWord (const uint32_t offset, uint16_t &val)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_WORD);
|
||||||
|
val = D_SHMHDR->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::readDWord (const uint32_t offset, uint32_t &val)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_DWORD);
|
||||||
|
val = D_SHMHDR->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::readQuad (const uint32_t offset, uint64_t &val)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_QUAD);
|
||||||
|
val = D_SHMHDR->Qvalue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::readFloat (const uint32_t offset, float &val)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_DWORD);
|
||||||
|
val = reinterpret_cast<float&> (D_SHMHDR->value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WRITING
|
||||||
|
*/
|
||||||
|
|
||||||
|
void SHMProcess::writeQuad (uint32_t offset, uint64_t data)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
D_SHMHDR->Qvalue = data;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE_QUAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::writeDWord (uint32_t offset, uint32_t data)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
D_SHMHDR->value = data;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE_DWORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// using these is expensive.
|
||||||
|
void SHMProcess::writeWord (uint32_t offset, uint16_t data)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
D_SHMHDR->value = data;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE_WORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::writeByte (uint32_t offset, uint8_t data)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
D_SHMHDR->value = data;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE_BYTE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::write (uint32_t dst_address, uint32_t size, uint8_t *source_buffer)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
// normal write under 1MB
|
||||||
|
if(size <= SHM_BODY)
|
||||||
|
{
|
||||||
|
D_SHMHDR->address = dst_address;
|
||||||
|
D_SHMHDR->length = size;
|
||||||
|
memcpy(D_SHMDATA(void),source_buffer, size);
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE);
|
||||||
|
}
|
||||||
|
// a big write, we push this over the shm in iterations
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// first write equals the size of the SHM window
|
||||||
|
uint32_t to_write = SHM_BODY;
|
||||||
|
while (size)
|
||||||
|
{
|
||||||
|
// write to_write bytes to dst_cursor
|
||||||
|
D_SHMHDR->address = dst_address;
|
||||||
|
D_SHMHDR->length = to_write;
|
||||||
|
memcpy(D_SHMDATA(void),source_buffer, to_write);
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE);
|
||||||
|
// decrease size by bytes written
|
||||||
|
size -= to_write;
|
||||||
|
// move the cursors
|
||||||
|
source_buffer += to_write;
|
||||||
|
dst_address += to_write;
|
||||||
|
// check how much to write in the next iteration
|
||||||
|
to_write = min(size, (uint32_t) SHM_BODY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: butt-fugly
|
||||||
|
const std::string SHMProcess::readCString (uint32_t offset)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
std::string temp;
|
||||||
|
char temp_c[256];
|
||||||
|
int counter = 0;
|
||||||
|
char r;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
r = Process::readByte(offset+counter);
|
||||||
|
temp_c[counter] = r;
|
||||||
|
counter++;
|
||||||
|
} while (r && counter < 255);
|
||||||
|
temp_c[counter] = 0;
|
||||||
|
temp = temp_c;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string SHMProcess::readSTLString(uint32_t offset)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_STL_STRING);
|
||||||
|
return(string( D_SHMDATA(char) ));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t SHMProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = offset;
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_READ_STL_STRING);
|
||||||
|
size_t length = D_SHMHDR->value;
|
||||||
|
size_t fit = min(bufcapacity - 1, length);
|
||||||
|
strncpy(buffer,D_SHMDATA(char),fit);
|
||||||
|
buffer[fit] = 0;
|
||||||
|
return fit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SHMProcess::writeSTLString(const uint32_t address, const std::string writeString)
|
||||||
|
{
|
||||||
|
if(!d->locked) throw Error::MemoryAccessDenied();
|
||||||
|
|
||||||
|
D_SHMHDR->address = address;
|
||||||
|
strncpy(D_SHMDATA(char),writeString.c_str(),writeString.length()+1); // length + 1 for the null terminator
|
||||||
|
full_barrier
|
||||||
|
d->SetAndWait(CORE_WRITE_STL_STRING);
|
||||||
|
}
|
@ -0,0 +1,432 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
#include "Internal.h"
|
||||||
|
#include "LinuxProcess.h"
|
||||||
|
#include "dfhack/VersionInfo.h"
|
||||||
|
#include "dfhack/DFError.h"
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/ptrace.h>
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
LinuxProcessBase::LinuxProcessBase(uint32_t pid)
|
||||||
|
: my_pid(pid)
|
||||||
|
{
|
||||||
|
my_descriptor = NULL;
|
||||||
|
attached = false;
|
||||||
|
suspended = false;
|
||||||
|
memFileHandle = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::isSuspended()
|
||||||
|
{
|
||||||
|
return suspended;
|
||||||
|
}
|
||||||
|
bool LinuxProcessBase::isAttached()
|
||||||
|
{
|
||||||
|
return attached;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::isIdentified()
|
||||||
|
{
|
||||||
|
return identified;
|
||||||
|
}
|
||||||
|
|
||||||
|
LinuxProcessBase::~LinuxProcessBase()
|
||||||
|
{
|
||||||
|
if(attached)
|
||||||
|
{
|
||||||
|
detach();
|
||||||
|
}
|
||||||
|
// destroy our copy of the memory descriptor
|
||||||
|
if(my_descriptor)
|
||||||
|
delete my_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
VersionInfo * LinuxProcessBase::getDescriptor()
|
||||||
|
{
|
||||||
|
return my_descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LinuxProcessBase::getPID()
|
||||||
|
{
|
||||||
|
return my_pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: implement
|
||||||
|
bool LinuxProcessBase::getThreadIDs(vector<uint32_t> & threads )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//FIXME: cross-reference with ELF segment entries?
|
||||||
|
void LinuxProcessBase::getMemRanges( vector<t_memrange> & ranges )
|
||||||
|
{
|
||||||
|
char buffer[1024];
|
||||||
|
char permissions[5]; // r/-, w/-, x/-, p/s, 0
|
||||||
|
|
||||||
|
sprintf(buffer, "/proc/%lu/maps", my_pid);
|
||||||
|
FILE *mapFile = ::fopen(buffer, "r");
|
||||||
|
uint64_t offset, device1, device2, node;
|
||||||
|
|
||||||
|
while (fgets(buffer, 1024, mapFile))
|
||||||
|
{
|
||||||
|
t_memrange temp;
|
||||||
|
temp.name[0] = 0;
|
||||||
|
sscanf(buffer, "%llx-%llx %s %llx %2llu:%2llu %llu %s",
|
||||||
|
&temp.start,
|
||||||
|
&temp.end,
|
||||||
|
(char*)&permissions,
|
||||||
|
&offset, &device1, &device2, &node,
|
||||||
|
(char*)&temp.name);
|
||||||
|
temp.read = permissions[0] == 'r';
|
||||||
|
temp.write = permissions[1] == 'w';
|
||||||
|
temp.execute = permissions[2] == 'x';
|
||||||
|
temp.valid = true;
|
||||||
|
ranges.push_back(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::asyncSuspend()
|
||||||
|
{
|
||||||
|
return suspend();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::suspend()
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
if(!attached)
|
||||||
|
return false;
|
||||||
|
if(suspended)
|
||||||
|
return true;
|
||||||
|
if (kill(my_pid, SIGSTOP) == -1)
|
||||||
|
{
|
||||||
|
// no, we got an error
|
||||||
|
perror("kill SIGSTOP error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// we wait on the pid
|
||||||
|
pid_t w = waitpid(my_pid, &status, 0);
|
||||||
|
if (w == -1)
|
||||||
|
{
|
||||||
|
// child died
|
||||||
|
perror("DF exited during suspend call");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// stopped -> let's continue
|
||||||
|
if (WIFSTOPPED(status))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suspended = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::forceresume()
|
||||||
|
{
|
||||||
|
return resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::resume()
|
||||||
|
{
|
||||||
|
if(!attached)
|
||||||
|
return false;
|
||||||
|
if(!suspended)
|
||||||
|
return true;
|
||||||
|
if (ptrace(PTRACE_CONT, my_pid, NULL, NULL) == -1)
|
||||||
|
{
|
||||||
|
// no, we got an error
|
||||||
|
perror("ptrace resume error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
suspended = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool LinuxProcessBase::attach()
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
if(attached)
|
||||||
|
{
|
||||||
|
if(!suspended)
|
||||||
|
return suspend();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// can we attach?
|
||||||
|
if (ptrace(PTRACE_ATTACH , my_pid, NULL, NULL) == -1)
|
||||||
|
{
|
||||||
|
// no, we got an error
|
||||||
|
perror("ptrace attach error");
|
||||||
|
cerr << "attach failed on pid " << my_pid << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// we wait on the pid
|
||||||
|
pid_t w = waitpid(my_pid, &status, 0);
|
||||||
|
if (w == -1)
|
||||||
|
{
|
||||||
|
// child died
|
||||||
|
perror("wait inside attach()");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// stopped -> let's continue
|
||||||
|
if (WIFSTOPPED(status))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
suspended = true;
|
||||||
|
|
||||||
|
int proc_pid_mem = open(memFile.c_str(),O_RDONLY);
|
||||||
|
if(proc_pid_mem == -1)
|
||||||
|
{
|
||||||
|
ptrace(PTRACE_DETACH, my_pid, NULL, NULL);
|
||||||
|
cerr << memFile << endl;
|
||||||
|
cerr << "couldn't open /proc/" << my_pid << "/mem" << endl;
|
||||||
|
perror("open(memFile.c_str(),O_RDONLY)");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
attached = true;
|
||||||
|
|
||||||
|
memFileHandle = proc_pid_mem;
|
||||||
|
return true; // we are attached
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LinuxProcessBase::detach()
|
||||||
|
{
|
||||||
|
if(!attached) return true;
|
||||||
|
if(!suspended) suspend();
|
||||||
|
int result = 0;
|
||||||
|
// close /proc/PID/mem
|
||||||
|
result = close(memFileHandle);
|
||||||
|
if(result == -1)
|
||||||
|
{
|
||||||
|
cerr << "couldn't close /proc/"<< my_pid <<"/mem" << endl;
|
||||||
|
perror("mem file close");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// detach
|
||||||
|
result = ptrace(PTRACE_DETACH, my_pid, NULL, NULL);
|
||||||
|
if(result == -1)
|
||||||
|
{
|
||||||
|
cerr << "couldn't detach from process pid" << my_pid << endl;
|
||||||
|
perror("ptrace detach");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
attached = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LinuxProcessBase::read (const uint32_t offset, const uint32_t size, uint8_t *target)
|
||||||
|
{
|
||||||
|
if(size == 0) return;
|
||||||
|
|
||||||
|
ssize_t result;
|
||||||
|
ssize_t total = 0;
|
||||||
|
ssize_t remaining = size;
|
||||||
|
while (total != size)
|
||||||
|
{
|
||||||
|
result = pread(memFileHandle, target + total ,remaining,offset + total);
|
||||||
|
if(result == -1)
|
||||||
|
{
|
||||||
|
cerr << "pread failed: can't read " << size << " bytes at addres " << offset << endl;
|
||||||
|
cerr << "errno: " << errno << endl;
|
||||||
|
errno = 0;
|
||||||
|
throw Error::MemoryAccessDenied();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total += result;
|
||||||
|
remaining -= result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::readByte (const uint32_t offset, uint8_t &val )
|
||||||
|
{
|
||||||
|
read(offset, 1, &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::readWord (const uint32_t offset, uint16_t &val)
|
||||||
|
{
|
||||||
|
read(offset, 2, (uint8_t *) &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::readDWord (const uint32_t offset, uint32_t &val)
|
||||||
|
{
|
||||||
|
read(offset, 4, (uint8_t *) &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::readFloat (const uint32_t offset, float &val)
|
||||||
|
{
|
||||||
|
read(offset, 4, (uint8_t *) &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::readQuad (const uint32_t offset, uint64_t &val)
|
||||||
|
{
|
||||||
|
read(offset, 8, (uint8_t *) &val);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WRITING
|
||||||
|
*/
|
||||||
|
|
||||||
|
void LinuxProcessBase::writeQuad (uint32_t offset, const uint64_t data)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_64_BIT
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, data);
|
||||||
|
#else
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, (uint32_t) data);
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset+4, (uint32_t) (data >> 32));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::writeDWord (uint32_t offset, uint32_t data)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_64_BIT
|
||||||
|
uint64_t orig = Process::readQuad(offset);
|
||||||
|
orig &= 0xFFFFFFFF00000000;
|
||||||
|
orig |= data;
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, orig);
|
||||||
|
#else
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, data);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// using these is expensive.
|
||||||
|
void LinuxProcessBase::writeWord (uint32_t offset, uint16_t data)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_64_BIT
|
||||||
|
uint64_t orig = Process::readQuad(offset);
|
||||||
|
orig &= 0xFFFFFFFFFFFF0000;
|
||||||
|
orig |= data;
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, orig);
|
||||||
|
#else
|
||||||
|
uint32_t orig = Process::readDWord(offset);
|
||||||
|
orig &= 0xFFFF0000;
|
||||||
|
orig |= data;
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, orig);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void LinuxProcessBase::writeByte (uint32_t offset, uint8_t data)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_64_BIT
|
||||||
|
uint64_t orig = Process::readQuad(offset);
|
||||||
|
orig &= 0xFFFFFFFFFFFFFF00;
|
||||||
|
orig |= data;
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, orig);
|
||||||
|
#else
|
||||||
|
uint32_t orig = Process::readDWord(offset);
|
||||||
|
orig &= 0xFFFFFF00;
|
||||||
|
orig |= data;
|
||||||
|
ptrace(PTRACE_POKEDATA,my_pid, offset, orig);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS
|
||||||
|
void LinuxProcessBase::write (uint32_t offset, uint32_t size, uint8_t *source)
|
||||||
|
{
|
||||||
|
uint32_t indexptr = 0;
|
||||||
|
while (size > 0)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_64_BIT
|
||||||
|
// quad!
|
||||||
|
if(size >= 8)
|
||||||
|
{
|
||||||
|
writeQuad(offset, *(uint64_t *) (source + indexptr));
|
||||||
|
offset +=8;
|
||||||
|
indexptr +=8;
|
||||||
|
size -=8;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
// default: we push 4 bytes
|
||||||
|
if(size >= 4)
|
||||||
|
{
|
||||||
|
writeDWord(offset, *(uint32_t *) (source + indexptr));
|
||||||
|
offset +=4;
|
||||||
|
indexptr +=4;
|
||||||
|
size -=4;
|
||||||
|
}
|
||||||
|
// last is either three or 2 bytes
|
||||||
|
else if(size >= 2)
|
||||||
|
{
|
||||||
|
writeWord(offset, *(uint16_t *) (source + indexptr));
|
||||||
|
offset +=2;
|
||||||
|
indexptr +=2;
|
||||||
|
size -=2;
|
||||||
|
}
|
||||||
|
// finishing move
|
||||||
|
else if(size == 1)
|
||||||
|
{
|
||||||
|
writeByte(offset, *(uint8_t *) (source + indexptr));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string LinuxProcessBase::readCString (uint32_t offset)
|
||||||
|
{
|
||||||
|
std::string temp;
|
||||||
|
char temp_c[256];
|
||||||
|
int counter = 0;
|
||||||
|
char r;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
r = Process::readByte(offset+counter);
|
||||||
|
temp_c[counter] = r;
|
||||||
|
counter++;
|
||||||
|
} while (r && counter < 255);
|
||||||
|
temp_c[counter] = 0;
|
||||||
|
temp = temp_c;
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
string LinuxProcessBase::getPath()
|
||||||
|
{
|
||||||
|
char cwd_name[256];
|
||||||
|
char target_name[1024];
|
||||||
|
int target_result;
|
||||||
|
|
||||||
|
sprintf(cwd_name,"/proc/%d/cwd", getPID());
|
||||||
|
// resolve /proc/PID/exe link
|
||||||
|
target_result = readlink(cwd_name, target_name, sizeof(target_name));
|
||||||
|
target_name[target_result] = '\0';
|
||||||
|
return(string(target_name));
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
// vim: sts=4 sta et shiftwidth=4:
|
||||||
|
#include "dfhack/DFIntegers.h"
|
||||||
|
#include "dfhack/DFTileTypes.h"
|
||||||
|
#include "dfhack/DFExport.h"
|
||||||
|
|
||||||
|
namespace DFHack {
|
||||||
|
//set tile class string lookup table (e.g. for printing to user)
|
||||||
|
#define X(name,comment) #name,
|
||||||
|
const char * TileClassString[tileclass_count+1] = {
|
||||||
|
TILECLASS_MACRO
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
//string lookup table (e.g. for printing to user)
|
||||||
|
#define X(name,comment) #name,
|
||||||
|
const char * TileMaterialString[tilematerial_count+1] = {
|
||||||
|
TILEMATERIAL_MACRO
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
//string lookup table (e.g. for printing to user)
|
||||||
|
#define X(name,comment) #name,
|
||||||
|
const char * TileSpecialString[tilespecial_count+1] = {
|
||||||
|
TILESPECIAL_MACRO
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#undef X
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Internal.h"
|
||||||
|
#include "MicrosoftSTL.h"
|
||||||
|
#include "dfhack/DFProcess.h"
|
||||||
|
#include "dfhack/VersionInfo.h"
|
||||||
|
#include <string>
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
void MicrosoftSTL::init(Process* self)
|
||||||
|
{
|
||||||
|
p = self;
|
||||||
|
OffsetGroup * strGrp = p->getDescriptor()->getGroup("string")->getGroup("MSVC");
|
||||||
|
STLSTR_buf_off = strGrp->getOffset("buffer");
|
||||||
|
STLSTR_size_off = strGrp->getOffset("size");
|
||||||
|
STLSTR_cap_off = strGrp->getOffset("capacity");
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t MicrosoftSTL::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity)
|
||||||
|
{
|
||||||
|
uint32_t start_offset = offset + STLSTR_buf_off;
|
||||||
|
size_t length = p->readDWord(offset + STLSTR_size_off);
|
||||||
|
size_t capacity = p->readDWord(offset + STLSTR_cap_off);
|
||||||
|
|
||||||
|
size_t read_real = min(length, bufcapacity-1);// keep space for null termination
|
||||||
|
|
||||||
|
// read data from inside the string structure
|
||||||
|
if(capacity < 16)
|
||||||
|
{
|
||||||
|
p->read(start_offset, read_real , (uint8_t *)buffer);
|
||||||
|
}
|
||||||
|
else // read data from what the offset + 4 dword points to
|
||||||
|
{
|
||||||
|
start_offset = p->readDWord(start_offset);// dereference the start offset
|
||||||
|
p->read(start_offset, read_real, (uint8_t *)buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[read_real] = 0;
|
||||||
|
return read_real;
|
||||||
|
}
|
||||||
|
|
||||||
|
const string MicrosoftSTL::readSTLString (uint32_t offset)
|
||||||
|
{
|
||||||
|
uint32_t start_offset = offset + STLSTR_buf_off;
|
||||||
|
size_t length = p->readDWord(offset + STLSTR_size_off);
|
||||||
|
size_t capacity = p->readDWord(offset + STLSTR_cap_off);
|
||||||
|
|
||||||
|
char * temp = new char[capacity+1];
|
||||||
|
|
||||||
|
// read data from inside the string structure
|
||||||
|
if(capacity < 16)
|
||||||
|
{
|
||||||
|
p->read(start_offset, capacity, (uint8_t *)temp);
|
||||||
|
}
|
||||||
|
else // read data from what the offset + 4 dword points to
|
||||||
|
{
|
||||||
|
start_offset = p->readDWord(start_offset);// dereference the start offset
|
||||||
|
p->read(start_offset, capacity, (uint8_t *)temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp[length] = 0;
|
||||||
|
string ret = temp;
|
||||||
|
delete temp;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
string MicrosoftSTL::readClassName (uint32_t vptr)
|
||||||
|
{
|
||||||
|
int rtti = p->readDWord(vptr - 0x4);
|
||||||
|
int typeinfo = p->readDWord(rtti + 0xC);
|
||||||
|
string raw = p->readCString(typeinfo + 0xC); // skips the .?AV
|
||||||
|
raw.resize(raw.length() - 2);// trim @@ from end
|
||||||
|
return raw;
|
||||||
|
}
|
Binary file not shown.
@ -0,0 +1,170 @@
|
|||||||
|
// This is just a graveyard of old 40d code. Things in here COULD be turned into modules, but it requires research.
|
||||||
|
|
||||||
|
bool API::InitReadEffects ( uint32_t & numeffects )
|
||||||
|
{
|
||||||
|
if(d->effectsInited)
|
||||||
|
FinishReadEffects();
|
||||||
|
int effects = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
effects = d->offset_descriptor->getAddress ("effects_vector");
|
||||||
|
}
|
||||||
|
catch(Error::AllMemdef)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
d->effectsInited = true;
|
||||||
|
d->p_effect = new DfVector (d->p, effects);
|
||||||
|
numeffects = d->p_effect->getSize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool API::ReadEffect(const uint32_t index, t_effect_df40d & effect)
|
||||||
|
{
|
||||||
|
if(!d->effectsInited)
|
||||||
|
return false;
|
||||||
|
if(index >= d->p_effect->getSize())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// read pointer from vector at position
|
||||||
|
uint32_t temp = d->p_effect->at (index);
|
||||||
|
//read effect from memory
|
||||||
|
d->p->read (temp, sizeof (t_effect_df40d), (uint8_t *) &effect);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use with care!
|
||||||
|
bool API::WriteEffect(const uint32_t index, const t_effect_df40d & effect)
|
||||||
|
{
|
||||||
|
if(!d->effectsInited)
|
||||||
|
return false;
|
||||||
|
if(index >= d->p_effect->getSize())
|
||||||
|
return false;
|
||||||
|
// read pointer from vector at position
|
||||||
|
uint32_t temp = d->p_effect->at (index);
|
||||||
|
// write effect to memory
|
||||||
|
d->p->write(temp,sizeof(t_effect_df40d), (uint8_t *) &effect);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void API::FinishReadEffects()
|
||||||
|
{
|
||||||
|
if(d->p_effect)
|
||||||
|
{
|
||||||
|
delete d->p_effect;
|
||||||
|
d->p_effect = NULL;
|
||||||
|
}
|
||||||
|
d->effectsInited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool API::InitReadNotes( uint32_t &numnotes )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
memory_info * minfo = d->offset_descriptor;
|
||||||
|
int notes = minfo->getAddress ("notes");
|
||||||
|
d->note_foreground_offset = minfo->getOffset ("note_foreground");
|
||||||
|
d->note_background_offset = minfo->getOffset ("note_background");
|
||||||
|
d->note_name_offset = minfo->getOffset ("note_name");
|
||||||
|
d->note_xyz_offset = minfo->getOffset ("note_xyz");
|
||||||
|
|
||||||
|
d->p_notes = new DfVector (d->p, notes);
|
||||||
|
d->notesInited = true;
|
||||||
|
numnotes = d->p_notes->getSize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Error::AllMemdef&)
|
||||||
|
{
|
||||||
|
d->notesInited = false;
|
||||||
|
numnotes = 0;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool API::ReadNote (const int32_t index, t_note & note)
|
||||||
|
{
|
||||||
|
if(!d->notesInited) return false;
|
||||||
|
// read pointer from vector at position
|
||||||
|
uint32_t temp = d->p_notes->at (index);
|
||||||
|
note.symbol = d->p->readByte(temp);
|
||||||
|
note.foreground = d->p->readWord(temp + d->note_foreground_offset);
|
||||||
|
note.background = d->p->readWord(temp + d->note_background_offset);
|
||||||
|
d->p->readSTLString (temp + d->note_name_offset, note.name, 128);
|
||||||
|
d->p->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) ¬e.x);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool API::InitReadSettlements( uint32_t & numsettlements )
|
||||||
|
{
|
||||||
|
if(!d->InitReadNames()) return false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
memory_info * minfo = d->offset_descriptor;
|
||||||
|
int allSettlements = minfo->getAddress ("settlements");
|
||||||
|
int currentSettlement = minfo->getAddress("settlement_current");
|
||||||
|
d->settlement_name_offset = minfo->getOffset ("settlement_name");
|
||||||
|
d->settlement_world_xy_offset = minfo->getOffset ("settlement_world_xy");
|
||||||
|
d->settlement_local_xy_offset = minfo->getOffset ("settlement_local_xy");
|
||||||
|
|
||||||
|
d->p_settlements = new DfVector (d->p, allSettlements);
|
||||||
|
d->p_current_settlement = new DfVector(d->p, currentSettlement);
|
||||||
|
d->settlementsInited = true;
|
||||||
|
numsettlements = d->p_settlements->getSize();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Error::AllMemdef&)
|
||||||
|
{
|
||||||
|
d->settlementsInited = false;
|
||||||
|
numsettlements = 0;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool API::ReadSettlement(const int32_t index, t_settlement & settlement)
|
||||||
|
{
|
||||||
|
if(!d->settlementsInited) return false;
|
||||||
|
if(!d->p_settlements->getSize()) return false;
|
||||||
|
|
||||||
|
// read pointer from vector at position
|
||||||
|
uint32_t temp = d->p_settlements->at (index);
|
||||||
|
settlement.origin = temp;
|
||||||
|
d->readName(settlement.name, temp + d->settlement_name_offset);
|
||||||
|
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
|
||||||
|
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool API::ReadCurrentSettlement(t_settlement & settlement)
|
||||||
|
{
|
||||||
|
if(!d->settlementsInited) return false;
|
||||||
|
if(!d->p_current_settlement->getSize()) return false;
|
||||||
|
|
||||||
|
uint32_t temp = d->p_current_settlement->at(0);
|
||||||
|
settlement.origin = temp;
|
||||||
|
d->readName(settlement.name, temp + d->settlement_name_offset);
|
||||||
|
d->p->read(temp + d->settlement_world_xy_offset, 2 * sizeof(int16_t), (uint8_t *) &settlement.world_x);
|
||||||
|
d->p->read(temp + d->settlement_local_xy_offset, 4 * sizeof(int16_t), (uint8_t *) &settlement.local_x1);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void API::FinishReadSettlements()
|
||||||
|
{
|
||||||
|
if(d->p_settlements)
|
||||||
|
{
|
||||||
|
delete d->p_settlements;
|
||||||
|
d->p_settlements = NULL;
|
||||||
|
}
|
||||||
|
if(d->p_current_settlement)
|
||||||
|
{
|
||||||
|
delete d->p_current_settlement;
|
||||||
|
d->p_current_settlement = NULL;
|
||||||
|
}
|
||||||
|
d->settlementsInited = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void API::FinishReadNotes()
|
||||||
|
{
|
||||||
|
if(d->p_notes)
|
||||||
|
{
|
||||||
|
delete d->p_notes;
|
||||||
|
d->p_notes = 0;
|
||||||
|
}
|
||||||
|
d->notesInited = false;
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LINUX_PROCESS_H_INCLUDED
|
||||||
|
#define LINUX_PROCESS_H_INCLUDED
|
||||||
|
|
||||||
|
#ifdef LINUX_BUILD
|
||||||
|
|
||||||
|
#include "dfhack/DFProcess.h"
|
||||||
|
|
||||||
|
namespace DFHack
|
||||||
|
{
|
||||||
|
class LinuxProcessBase : public Process
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
VersionInfo * my_descriptor;
|
||||||
|
pid_t my_pid;
|
||||||
|
string memFile;
|
||||||
|
int memFileHandle;
|
||||||
|
bool attached;
|
||||||
|
bool suspended;
|
||||||
|
bool identified;
|
||||||
|
public:
|
||||||
|
LinuxProcessBase(uint32_t pid);
|
||||||
|
~LinuxProcessBase();
|
||||||
|
|
||||||
|
bool attach();
|
||||||
|
bool detach();
|
||||||
|
|
||||||
|
bool suspend();
|
||||||
|
bool asyncSuspend();
|
||||||
|
bool resume();
|
||||||
|
bool forceresume();
|
||||||
|
|
||||||
|
void readQuad(const uint32_t address, uint64_t & value);
|
||||||
|
void writeQuad(const uint32_t address, const uint64_t value);
|
||||||
|
|
||||||
|
void readDWord(const uint32_t address, uint32_t & value);
|
||||||
|
void writeDWord(const uint32_t address, const uint32_t value);
|
||||||
|
|
||||||
|
void readFloat(const uint32_t address, float & value);
|
||||||
|
|
||||||
|
void readWord(const uint32_t address, uint16_t & value);
|
||||||
|
void writeWord(const uint32_t address, const uint16_t value);
|
||||||
|
|
||||||
|
void readByte(const uint32_t address, uint8_t & value);
|
||||||
|
void writeByte(const uint32_t address, const uint8_t value);
|
||||||
|
|
||||||
|
void read( uint32_t address, uint32_t length, uint8_t* buffer);
|
||||||
|
void write(uint32_t address, uint32_t length, uint8_t* buffer);
|
||||||
|
|
||||||
|
const std::string readCString (uint32_t offset);
|
||||||
|
|
||||||
|
bool isSuspended();
|
||||||
|
bool isAttached();
|
||||||
|
bool isIdentified();
|
||||||
|
|
||||||
|
VersionInfo *getDescriptor();
|
||||||
|
int getPID();
|
||||||
|
std::string getPath();
|
||||||
|
|
||||||
|
bool getThreadIDs(std::vector<uint32_t> & threads );
|
||||||
|
void getMemRanges(std::vector<t_memrange> & ranges );
|
||||||
|
// get module index by name and version. bool 1 = error
|
||||||
|
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
|
||||||
|
// get the SHM start if available
|
||||||
|
char * getSHMStart (void){return 0;};
|
||||||
|
// set a SHM command and wait for a response
|
||||||
|
bool SetAndWait (uint32_t state){return false;};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace DFHack {
|
||||||
|
class Process;
|
||||||
|
class MicrosoftSTL
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
uint32_t STLSTR_buf_off;
|
||||||
|
uint32_t STLSTR_size_off;
|
||||||
|
uint32_t STLSTR_cap_off;
|
||||||
|
|
||||||
|
Process* p;
|
||||||
|
public:
|
||||||
|
void init(Process* p);
|
||||||
|
|
||||||
|
const std::string readSTLString (uint32_t offset);
|
||||||
|
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
|
||||||
|
void writeSTLString(const uint32_t address, const std::string writeString){};
|
||||||
|
// get class name of an object with rtti/type info
|
||||||
|
std::string readClassName(uint32_t vptr);
|
||||||
|
};
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PROCESS_FACTORY_H_INCLUDED
|
||||||
|
#define PROCESS_FACTORY_H_INCLUDED
|
||||||
|
|
||||||
|
#include "dfhack/DFProcess.h"
|
||||||
|
|
||||||
|
namespace DFHack
|
||||||
|
{
|
||||||
|
Process* createNormalProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
|
||||||
|
Process* createSHMProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
|
||||||
|
#ifdef LINUX_BUILD
|
||||||
|
Process* createWineProcess(uint32_t pid, std::vector <VersionInfo *> & known_versions);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
www.sourceforge.net/projects/dfhack
|
||||||
|
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any
|
||||||
|
damages arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any
|
||||||
|
purpose, including commercial applications, and to alter it and
|
||||||
|
redistribute it freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must
|
||||||
|
not claim that you wrote the original software. If you use this
|
||||||
|
software in a product, an acknowledgment in the product documentation
|
||||||
|
would be appreciated but is not required.
|
||||||
|
|
||||||
|
2. Altered source versions must be plainly marked as such, and
|
||||||
|
must not be misrepresented as being the original software.
|
||||||
|
|
||||||
|
3. This notice may not be removed or altered from any source
|
||||||
|
distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SHM_PROCESS_H_INCLUDED
|
||||||
|
#define SHM_PROCESS_H_INCLUDED
|
||||||
|
|
||||||
|
#include "dfhack/DFProcess.h"
|
||||||
|
#include "dfhack/DFIntegers.h"
|
||||||
|
|
||||||
|
namespace DFHack
|
||||||
|
{
|
||||||
|
class DFHACK_EXPORT SHMProcess : public Process
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
class Private;
|
||||||
|
Private * const d;
|
||||||
|
|
||||||
|
public:
|
||||||
|
SHMProcess(uint32_t PID, std::vector <VersionInfo *> & known_versions);
|
||||||
|
~SHMProcess();
|
||||||
|
// Set up stuff so we can read memory
|
||||||
|
bool attach();
|
||||||
|
bool detach();
|
||||||
|
|
||||||
|
bool suspend();
|
||||||
|
bool asyncSuspend();
|
||||||
|
bool resume();
|
||||||
|
bool forceresume();
|
||||||
|
|
||||||
|
void readQuad(const uint32_t address, uint64_t & value);
|
||||||
|
void writeQuad(const uint32_t address, const uint64_t value);
|
||||||
|
|
||||||
|
void readDWord(const uint32_t address, uint32_t & value);
|
||||||
|
void writeDWord(const uint32_t address, const uint32_t value);
|
||||||
|
|
||||||
|
void readFloat(const uint32_t address, float & value);
|
||||||
|
|
||||||
|
void readWord(const uint32_t address, uint16_t & value);
|
||||||
|
void writeWord(const uint32_t address, const uint16_t value);
|
||||||
|
|
||||||
|
void readByte(const uint32_t address, uint8_t & value);
|
||||||
|
void writeByte(const uint32_t address, const uint8_t value);
|
||||||
|
|
||||||
|
void read( uint32_t address, uint32_t length, uint8_t* buffer);
|
||||||
|
void write(uint32_t address, uint32_t length, uint8_t* buffer);
|
||||||
|
|
||||||
|
const std::string readSTLString (uint32_t offset);
|
||||||
|
size_t readSTLString (uint32_t offset, char * buffer, size_t bufcapacity);
|
||||||
|
void writeSTLString(const uint32_t address, const std::string writeString);
|
||||||
|
// get class name of an object with rtti/type info
|
||||||
|
std::string readClassName(uint32_t vptr);
|
||||||
|
|
||||||
|
const std::string readCString (uint32_t offset);
|
||||||
|
|
||||||
|
bool isSuspended();
|
||||||
|
bool isAttached();
|
||||||
|
bool isIdentified();
|
||||||
|
|
||||||
|
bool getThreadIDs(std::vector<uint32_t> & threads );
|
||||||
|
void getMemRanges(std::vector<t_memrange> & ranges );
|
||||||
|
VersionInfo *getDescriptor();
|
||||||
|
int getPID();
|
||||||
|
std::string getPath();
|
||||||
|
// get module index by name and version. bool 1 = error
|
||||||
|
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT);
|
||||||
|
// get the SHM start if available
|
||||||
|
char * getSHMStart (void);
|
||||||
|
bool SetAndWait (uint32_t state);
|
||||||
|
private:
|
||||||
|
bool acquireSuspendLock();
|
||||||
|
bool releaseSuspendLock();
|
||||||
|
};
|
||||||
|
|
||||||
|
class SHMProcess::Private
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Private(SHMProcess * self_);
|
||||||
|
~Private(){}
|
||||||
|
VersionInfo * memdescriptor;
|
||||||
|
SHMProcess * self;
|
||||||
|
char *shm_addr;
|
||||||
|
int attachmentIdx;
|
||||||
|
|
||||||
|
bool attached;
|
||||||
|
bool locked;
|
||||||
|
bool identified;
|
||||||
|
bool useYield;
|
||||||
|
|
||||||
|
#ifdef LINUX_BUILD
|
||||||
|
pid_t process_ID;
|
||||||
|
int shm_ID;
|
||||||
|
int server_lock;
|
||||||
|
int client_lock;
|
||||||
|
int suspend_lock;
|
||||||
|
#else
|
||||||
|
typedef uint32_t pid_t;
|
||||||
|
uint32_t process_ID;
|
||||||
|
HANDLE DFSVMutex;
|
||||||
|
HANDLE DFCLMutex;
|
||||||
|
HANDLE DFCLSuspendMutex;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool validate(std::vector< VersionInfo* >& known_versions);
|
||||||
|
|
||||||
|
bool Aux_Core_Attach(bool & versionOK, pid_t& PID);
|
||||||
|
bool SetAndWait (uint32_t state);
|
||||||
|
bool GetLocks();
|
||||||
|
bool AreLocksOk();
|
||||||
|
void FreeLocks();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// some helpful macros to keep the code bloat in check
|
||||||
|
#define SHMCMD ( (uint32_t *) shm_addr)[attachmentIdx]
|
||||||
|
#define D_SHMCMD ( (uint32_t *) (d->shm_addr))[d->attachmentIdx]
|
||||||
|
|
||||||
|
#define SHMHDR ((shm_core_hdr *)shm_addr)
|
||||||
|
#define D_SHMHDR ((shm_core_hdr *)(d->shm_addr))
|
||||||
|
|
||||||
|
#define SHMDATA(type) ((type *)(shm_addr + SHM_HEADER))
|
||||||
|
#define D_SHMDATA(type) ((type *)(d->shm_addr + SHM_HEADER))
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,137 @@
|
|||||||
|
// De-ramp. All ramps marked for removal are replaced with given tile (presently, normal floor).
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <DFHack.h>
|
||||||
|
#include <dfhack/DFTileTypes.h>
|
||||||
|
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
uint32_t x_max,y_max,z_max;
|
||||||
|
uint32_t num_blocks = 0;
|
||||||
|
uint32_t bytes_read = 0;
|
||||||
|
DFHack::designations40d designations;
|
||||||
|
DFHack::tiletypes40d tiles;
|
||||||
|
DFHack::tiletypes40d tilesAbove;
|
||||||
|
|
||||||
|
//DFHack::TileRow *ptile;
|
||||||
|
int32_t oldT, newT;
|
||||||
|
int16_t t;
|
||||||
|
|
||||||
|
int dirty=0, count=0;
|
||||||
|
|
||||||
|
DFHack::ContextManager DFMgr("Memory.xml");
|
||||||
|
DFHack::Context *DF = DFMgr.getSingleContext();
|
||||||
|
|
||||||
|
//sanity check
|
||||||
|
assert( sizeof(designations) == (16*16*sizeof(DFHack::t_designation)) );
|
||||||
|
|
||||||
|
//Init
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DF->Attach();
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
DFHack::Maps *Mapz = DF->getMaps();
|
||||||
|
|
||||||
|
// init the map
|
||||||
|
if (!Mapz->Start())
|
||||||
|
{
|
||||||
|
cerr << "Can't init map." << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mapz->getSize(x_max,y_max,z_max);
|
||||||
|
|
||||||
|
uint8_t zeroes [16][16] = {0};
|
||||||
|
|
||||||
|
// walk the map
|
||||||
|
for (uint32_t x = 0; x< x_max;x++)
|
||||||
|
{
|
||||||
|
for (uint32_t y = 0; y< y_max;y++)
|
||||||
|
{
|
||||||
|
for (uint32_t z = 0; z< z_max;z++)
|
||||||
|
{
|
||||||
|
if (Mapz->isValidBlock(x,y,z))
|
||||||
|
{
|
||||||
|
dirty=0;
|
||||||
|
Mapz->ReadDesignations(x,y,z, &designations);
|
||||||
|
Mapz->ReadTileTypes(x,y,z, &tiles);
|
||||||
|
if (Mapz->isValidBlock(x,y,z+1))
|
||||||
|
{
|
||||||
|
Mapz->ReadTileTypes(x,y,z+1, &tilesAbove);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(&tilesAbove,0,sizeof(tilesAbove));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint32_t ty=0;ty<16;++ty)
|
||||||
|
{
|
||||||
|
for (uint32_t tx=0;tx<16;++tx)
|
||||||
|
{
|
||||||
|
//Only the remove ramp designation (ignore channel designation, etc)
|
||||||
|
oldT = tiles[tx][ty];
|
||||||
|
if ( DFHack::designation_default == designations[tx][ty].bits.dig
|
||||||
|
&& DFHack::RAMP==DFHack::tileTypeTable[oldT].c)
|
||||||
|
{
|
||||||
|
//Current tile is a ramp.
|
||||||
|
//Set current tile, as accurately as can be expected
|
||||||
|
newT = DFHack::findSimilarTileType(oldT,DFHack::FLOOR);
|
||||||
|
|
||||||
|
//If no change, skip it (couldn't find a good tile type)
|
||||||
|
if ( oldT == newT) continue;
|
||||||
|
//Set new tile type, clear designation
|
||||||
|
tiles[tx][ty] = newT;
|
||||||
|
designations[tx][ty].bits.dig = DFHack::designation_no;
|
||||||
|
|
||||||
|
//Check the tile above this one, in case a downward slope needs to be removed.
|
||||||
|
if ( DFHack::RAMP_TOP == DFHack::tileTypeTable[tilesAbove[tx][ty]].c )
|
||||||
|
{
|
||||||
|
tilesAbove[tx][ty] = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
dirty=-1;
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//If anything was changed, write it all.
|
||||||
|
if (dirty)
|
||||||
|
{
|
||||||
|
Mapz->WriteDesignations(x,y,z, &designations);
|
||||||
|
Mapz->WriteTileTypes(x,y,z, &tiles);
|
||||||
|
if (Mapz->isValidBlock(x,y,z+1))
|
||||||
|
{
|
||||||
|
Mapz->WriteTileTypes(x,y,z+1, &tilesAbove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DF->Detach();
|
||||||
|
cout << "Found and changed " << count << " tiles." << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cout << "Done. Press any key to continue" << endl;
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <DFHack.h>
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
DFHack::ContextManager DFMgr("Memory.xml");
|
||||||
|
DFHack::Context *DF = DFMgr.getSingleContext();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DF->Attach();
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
DFHack::Process * Process = DF->getProcess();
|
||||||
|
DFHack::Gui * gui = DF->getGui();
|
||||||
|
cout << Process->getPath() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cout << "Done. Press any key to continue" << endl;
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <climits>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstdio>
|
||||||
|
using namespace std;
|
||||||
|
std::string teststr1;
|
||||||
|
std::string * teststr2;
|
||||||
|
std::string teststr3("test");
|
||||||
|
int main (int numargs, const char ** args)
|
||||||
|
{
|
||||||
|
printf("std::string E : 0x%x\n", &teststr1);
|
||||||
|
teststr1 = "This is a fairly long string, much longer than the one made by default constructor.";
|
||||||
|
cin.ignore();
|
||||||
|
printf("std::string L : 0x%x\n", &teststr1);
|
||||||
|
teststr1 = "This one is shorter";
|
||||||
|
cin.ignore();
|
||||||
|
printf("std::string S : 0x%x\n", &teststr1);
|
||||||
|
cin.ignore();
|
||||||
|
teststr2 = new string();
|
||||||
|
printf("std::string * : 0x%x\n", &teststr2);
|
||||||
|
printf("std::string(\"test\") : 0x%x\n", &teststr3);
|
||||||
|
cin.ignore();
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,100 @@
|
|||||||
|
// Prints all the Tile Types known by DFHack.
|
||||||
|
// File is both fixed-field and CSV parsable.
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <assert.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <DFHack.h>
|
||||||
|
#include <dfhack/DFTileTypes.h>
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
int main (int argc, char **argv)
|
||||||
|
{
|
||||||
|
FILE *f=stdout;
|
||||||
|
const int Columns = 7;
|
||||||
|
const char * Headings[Columns] = {"TileTypeID","Class","Material","V","Special","Direction","Description"};
|
||||||
|
size_t Size[ Columns ] = {};
|
||||||
|
int i;
|
||||||
|
|
||||||
|
//First, figure out column widths.
|
||||||
|
for(i=0;i<Columns;++i)
|
||||||
|
{
|
||||||
|
Size[i]=strlen(Headings[i])+1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Classes
|
||||||
|
fprintf(f,"\nTile Type Classes:\n");
|
||||||
|
for(i=0;i<tileclass_count;++i)
|
||||||
|
{
|
||||||
|
Size[1]=max<size_t>(Size[1],strlen(TileClassString[i]));
|
||||||
|
fprintf(f,"%4i ; %s\n", i, TileClassString[i] ,0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Materials
|
||||||
|
fprintf(f,"\nTile Type Materials:\n");
|
||||||
|
for(i=0;i<tilematerial_count;++i)
|
||||||
|
{
|
||||||
|
Size[2]=max<size_t>(Size[2],strlen(TileMaterialString[i]));
|
||||||
|
fprintf(f,"%4i ; %s\n", i, TileMaterialString[i] ,0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
//Specials
|
||||||
|
fprintf(f,"\nTile Type Specials:\n");
|
||||||
|
for(i=0;i<tilespecial_count;++i)
|
||||||
|
{
|
||||||
|
Size[4]=max<size_t>(Size[4],strlen(TileSpecialString[i]));
|
||||||
|
fprintf(f,"%4i ; %s\n", i, TileSpecialString[i] ,0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* - Not needed for now -
|
||||||
|
//Direction is tricky
|
||||||
|
for(i=0;i<TILE_TYPE_ARRAY_LENGTH;++i)
|
||||||
|
Size[5]=max(Size[5], tileTypeTable[i].d.sum()+1 );
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Print the headings first.
|
||||||
|
fprintf(f,"\nTile Types:\n");
|
||||||
|
for(i=0;i<Columns;++i)
|
||||||
|
{
|
||||||
|
if(i) putc(';',f);
|
||||||
|
fprintf(f," %-*s ",Size[i],Headings[i],0);
|
||||||
|
}
|
||||||
|
fprintf(f,"\n");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Process the whole array.
|
||||||
|
//A macro should be used for making the strings safe, but they are left in naked ? blocks
|
||||||
|
//to illustrate the array references more clearly.
|
||||||
|
for(i=0;i<TILE_TYPE_ARRAY_LENGTH;++i)
|
||||||
|
{
|
||||||
|
fprintf(f," %*i ; %-*s ; %-*s ; %*c ; %-*s ; %-*s ; %s\n",
|
||||||
|
Size[0], i,
|
||||||
|
Size[1], ( tileTypeTable[i].name ? TileClassString[ tileTypeTable[i].c ] : "" ),
|
||||||
|
Size[2], ( tileTypeTable[i].name ? TileMaterialString[ tileTypeTable[i].m ] : "" ),
|
||||||
|
Size[3], ( tileTypeTable[i].v ? '0'+tileTypeTable[i].v : ' ' ),
|
||||||
|
Size[4], ( tileTypeTable[i].s ? TileSpecialString[ tileTypeTable[i].s ] : "" ),
|
||||||
|
Size[5], ( tileTypeTable[i].d.whole ? tileTypeTable[i].d.getStr() : "" ),
|
||||||
|
( tileTypeTable[i].name ? tileTypeTable[i].name : "" ),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
fprintf(f,"\n");
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
if( 1== argc)
|
||||||
|
{
|
||||||
|
cout << "Done. Press any key to continue" << endl;
|
||||||
|
cin.ignore();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,782 @@
|
|||||||
|
// this is an incremental search tool. It only works on Linux.
|
||||||
|
// here be dragons... and ugly code :P
|
||||||
|
#include <iostream>
|
||||||
|
#include <climits>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <list>
|
||||||
|
#include <ctime>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <algorithm>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
#define WINVER 0x0500
|
||||||
|
// this one prevents windows from infecting the global namespace with filth
|
||||||
|
#define NOMINMAX
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <DFHack.h>
|
||||||
|
#include "SegmentedFinder.h"
|
||||||
|
class Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Token(uint64_t _offset)
|
||||||
|
{
|
||||||
|
offset = _offset;
|
||||||
|
offset_valid = 1;
|
||||||
|
value_valid = 0;
|
||||||
|
parent = 0;
|
||||||
|
}
|
||||||
|
Token(const std::string & offsetn)
|
||||||
|
{
|
||||||
|
full_offset_name = offsetn;
|
||||||
|
offset_valid = 0;
|
||||||
|
value_valid = 0;
|
||||||
|
parent = 0;
|
||||||
|
}
|
||||||
|
Token()
|
||||||
|
{
|
||||||
|
offset_valid = 0;
|
||||||
|
value_valid = 0;
|
||||||
|
parent = 0;
|
||||||
|
}
|
||||||
|
virtual ~Token(){};
|
||||||
|
virtual bool LoadData(SegmentedFinder * s) = 0;
|
||||||
|
virtual void EmptyData()
|
||||||
|
{
|
||||||
|
value_valid = false;
|
||||||
|
};
|
||||||
|
virtual bool Match(SegmentedFinder * s, uint64_t offset) = 0;
|
||||||
|
virtual void EmptyOffset()
|
||||||
|
{
|
||||||
|
offset_valid = false;
|
||||||
|
};
|
||||||
|
virtual bool AcquireOffset(DFHack::VersionInfo * vinfo)
|
||||||
|
{
|
||||||
|
vinfo->getOffset(full_offset_name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
virtual uint32_t Length() = 0;
|
||||||
|
virtual uint64_t getAbsolute(){if(parent) return parent->getAbsolute() + offset; else return offset;};
|
||||||
|
void setParent( Token *par )
|
||||||
|
{
|
||||||
|
par = parent;
|
||||||
|
}
|
||||||
|
protected:
|
||||||
|
uint64_t offset;// offset from the start of the parent token
|
||||||
|
std::string full_offset_name;
|
||||||
|
Token * parent;
|
||||||
|
bool offset_valid :1;
|
||||||
|
bool value_valid :1;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Byte: virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Byte(uint64_t _offset):Token(_offset){};
|
||||||
|
Byte():Token(){};
|
||||||
|
~Byte();
|
||||||
|
virtual bool LoadData(SegmentedFinder * s)
|
||||||
|
{
|
||||||
|
if(offset_valid)
|
||||||
|
{
|
||||||
|
char * ptr = s->Translate<char>(getAbsolute());
|
||||||
|
if(ptr)
|
||||||
|
{
|
||||||
|
value = *ptr;
|
||||||
|
value_valid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// is the loaded data same as data at offset? yes -> set our offset to that.
|
||||||
|
virtual bool Match(SegmentedFinder * s, uint64_t offs)
|
||||||
|
{
|
||||||
|
if(value_valid && (*s->Translate<char>(parent->getAbsolute() + offset)) == value )
|
||||||
|
{
|
||||||
|
if(parent)
|
||||||
|
offset = offs - parent->getAbsolute();
|
||||||
|
else
|
||||||
|
offset = offs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
virtual uint32_t Length()
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
char value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Short: virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Short(uint64_t _offset):Token(_offset){};
|
||||||
|
Short():Token(){};
|
||||||
|
~Short();
|
||||||
|
virtual bool LoadData(SegmentedFinder * s)
|
||||||
|
{
|
||||||
|
if(offset_valid)
|
||||||
|
{
|
||||||
|
uint16_t * ptr = s->Translate<uint16_t>(getAbsolute());
|
||||||
|
if(ptr)
|
||||||
|
{
|
||||||
|
value = *ptr;
|
||||||
|
value_valid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// is the loaded data same as data at offset? yes -> set our offset to that.
|
||||||
|
virtual bool Match(SegmentedFinder * s, uint64_t offs)
|
||||||
|
{
|
||||||
|
if(value_valid && (*s->Translate<uint16_t>(parent->getAbsolute() + offset)) == value )
|
||||||
|
{
|
||||||
|
if(parent)
|
||||||
|
offset = offs - parent->getAbsolute();
|
||||||
|
else
|
||||||
|
offset = offs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
virtual uint32_t Length()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
uint16_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Long: virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Long(uint64_t _offset):Token(_offset){};
|
||||||
|
Long():Token(){};
|
||||||
|
~Long();
|
||||||
|
virtual bool LoadData(SegmentedFinder * s)
|
||||||
|
{
|
||||||
|
if(offset_valid)
|
||||||
|
{
|
||||||
|
uint32_t * ptr = s->Translate<uint32_t>(getAbsolute());
|
||||||
|
if(ptr)
|
||||||
|
{
|
||||||
|
value = *ptr;
|
||||||
|
value_valid = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
// is the loaded data same as data at offset? yes -> set our offset to that.
|
||||||
|
virtual bool Match(SegmentedFinder * s, uint64_t offs)
|
||||||
|
{
|
||||||
|
if(value_valid && (*s->Translate<uint32_t>(offs)) == value )
|
||||||
|
{
|
||||||
|
if(parent)
|
||||||
|
offset = offs - parent->getAbsolute();
|
||||||
|
else
|
||||||
|
offset = offs;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
};
|
||||||
|
virtual uint32_t Length(){return 4;};
|
||||||
|
private:
|
||||||
|
uint32_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class PtrVector : virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PtrVector(uint64_t _offset):Token(_offset){};
|
||||||
|
PtrVector():Token(){};
|
||||||
|
~PtrVector();
|
||||||
|
virtual uint32_t Length(){return 12;};
|
||||||
|
private:
|
||||||
|
vector <uint64_t> value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Pointer: virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Pointer(uint64_t _offset):Token(_offset){};
|
||||||
|
Pointer():Token(){};
|
||||||
|
~Pointer();
|
||||||
|
virtual uint32_t Length(){return 4;};
|
||||||
|
private:
|
||||||
|
uint64_t value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class String: virtual public Token
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
string value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Struct: virtual public Token
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Struct(uint64_t _offset):Token(_offset){};
|
||||||
|
Struct():Token(){};
|
||||||
|
~Struct(){};
|
||||||
|
void Add( Token * t ){members.push_back(t);};
|
||||||
|
virtual uint32_t Length(){return 0;}; // FIXME: temporary solution, should be the minimal length of all the contents combined
|
||||||
|
virtual bool LoadData(SegmentedFinder* s)
|
||||||
|
{
|
||||||
|
bool OK = true;
|
||||||
|
for(int i = 0; i < members.size() && OK; i++)
|
||||||
|
OK &= members[i]->LoadData(s);
|
||||||
|
return OK;
|
||||||
|
};
|
||||||
|
// TODO: IMPLEMENT!
|
||||||
|
virtual bool Match(SegmentedFinder* s, uint64_t offset)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
vector<Token*> members;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LinuxString: virtual public String
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LinuxString(uint64_t _offset):Token(_offset){};
|
||||||
|
LinuxString():Token(){};
|
||||||
|
~LinuxString(){};
|
||||||
|
virtual uint32_t Length(){return 4;};
|
||||||
|
virtual bool LoadData(SegmentedFinder* s)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool Match(SegmentedFinder* s, uint64_t offset)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
// read string pointer, translate to local scheme
|
||||||
|
char *str = sf->Translate<char>(*offset);
|
||||||
|
// verify
|
||||||
|
if(!str)
|
||||||
|
return false;
|
||||||
|
uint32_t length = *(uint32_t *)(offset - 12);
|
||||||
|
uint32_t capacity = *(uint32_t *)(offset - 8);
|
||||||
|
if(length > capacity)
|
||||||
|
return false;
|
||||||
|
//char * temp = new char[length+1];
|
||||||
|
// read data from inside the string structure
|
||||||
|
//memcpy(temp, str,length + 1);
|
||||||
|
output = str;
|
||||||
|
return true;
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
||||||
|
class WindowsString: virtual public String
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
WindowsString(uint64_t _offset):Token(_offset){};
|
||||||
|
WindowsString():Token(){};
|
||||||
|
~WindowsString(){};
|
||||||
|
virtual uint32_t Length(){return 0x1C;}; // FIXME: pouzivat Memory.xml?
|
||||||
|
virtual bool LoadData(SegmentedFinder* s)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual bool Match(SegmentedFinder* s, uint64_t offset)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string rdWinString( char * offset, SegmentedFinder & sf )
|
||||||
|
{
|
||||||
|
char * start_offset = offset + 4; // FIXME: pouzivat Memory.xml?
|
||||||
|
uint32_t length = *(uint32_t *)(offset + 20); // FIXME: pouzivat Memory.xml?
|
||||||
|
uint32_t capacity = *(uint32_t *)(offset + 24); // FIXME: pouzivat Memory.xml?
|
||||||
|
char * temp = new char[capacity+1];
|
||||||
|
|
||||||
|
// read data from inside the string structure
|
||||||
|
if(capacity < 16)
|
||||||
|
{
|
||||||
|
memcpy(temp, start_offset,capacity);
|
||||||
|
//read(start_offset, capacity, (uint8_t *)temp);
|
||||||
|
}
|
||||||
|
else // read data from what the offset + 4 dword points to
|
||||||
|
{
|
||||||
|
start_offset = sf.Translate<char>(*(uint32_t*)start_offset);
|
||||||
|
memcpy(temp, start_offset,capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
temp[length] = 0;
|
||||||
|
string ret = temp;
|
||||||
|
delete temp;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline void printRange(DFHack::t_memrange * tpr)
|
||||||
|
{
|
||||||
|
std::cout << std::hex << tpr->start << " - " << tpr->end << "|" << (tpr->read ? "r" : "-") << (tpr->write ? "w" : "-") << (tpr->execute ? "x" : "-") << "|" << tpr->name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getRanges(DFHack::Process * p, vector <DFHack::t_memrange>& selected_ranges)
|
||||||
|
{
|
||||||
|
vector <DFHack::t_memrange> ranges;
|
||||||
|
selected_ranges.clear();
|
||||||
|
p->getMemRanges(ranges);
|
||||||
|
cout << "Which range to search? (default is 1-4)" << endl;
|
||||||
|
for(int i = 0; i< ranges.size();i++)
|
||||||
|
{
|
||||||
|
cout << dec << "(" << i << ") ";
|
||||||
|
printRange(&(ranges[i]));
|
||||||
|
}
|
||||||
|
int start, end;
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
string select;
|
||||||
|
cout << ">>";
|
||||||
|
std::getline(cin, select);
|
||||||
|
if(select.empty())
|
||||||
|
{
|
||||||
|
// empty input, assume default. observe the length of the memory range vector
|
||||||
|
// these are hardcoded values, intended for my convenience only
|
||||||
|
if(p->getDescriptor()->getOS() == DFHack::OS_WINDOWS)
|
||||||
|
{
|
||||||
|
start = min(11, (int)ranges.size());
|
||||||
|
end = min(14, (int)ranges.size());
|
||||||
|
}
|
||||||
|
else if(p->getDescriptor()->getOS() == DFHack::OS_LINUX)
|
||||||
|
{
|
||||||
|
start = min(2, (int)ranges.size());
|
||||||
|
end = min(4, (int)ranges.size());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
start = 1;
|
||||||
|
end = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// I like the C variants here. much less object clutter
|
||||||
|
else if(sscanf(select.c_str(), "%d-%d", &start, &end) == 2)
|
||||||
|
{
|
||||||
|
start = min(start, (int)ranges.size());
|
||||||
|
end = min(end, (int)ranges.size());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
end++;
|
||||||
|
cout << "selected ranges:" <<endl;
|
||||||
|
vector <DFHack::t_memrange>::iterator it;
|
||||||
|
it = ranges.begin() + start;
|
||||||
|
while (it != ranges.begin() + end)
|
||||||
|
{
|
||||||
|
// check if readable
|
||||||
|
if((*it).read)
|
||||||
|
{
|
||||||
|
selected_ranges.push_back(*it);
|
||||||
|
printRange(&*it);
|
||||||
|
}
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getNumber (string prompt, int & output, int def, bool pdef = true)
|
||||||
|
{
|
||||||
|
cout << prompt;
|
||||||
|
if(pdef)
|
||||||
|
cout << " default=" << def << endl;
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
string select;
|
||||||
|
cout << ">>";
|
||||||
|
std::getline(cin, select);
|
||||||
|
if(select.empty())
|
||||||
|
{
|
||||||
|
output = def;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if( sscanf(select.c_str(), "%d", &output) == 1 )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool getString (string prompt, string & output)
|
||||||
|
{
|
||||||
|
cout << prompt;
|
||||||
|
cout << ">>";
|
||||||
|
string select;
|
||||||
|
std::getline(cin, select);
|
||||||
|
if(select.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = select;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// meh
|
||||||
|
#pragma pack(1)
|
||||||
|
struct tilecolors
|
||||||
|
{
|
||||||
|
uint16_t fore;
|
||||||
|
uint16_t back;
|
||||||
|
uint16_t bright;
|
||||||
|
};
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
|
void printFound(vector <uint64_t> &found, const char * what)
|
||||||
|
{
|
||||||
|
cout << what << ":" << endl;
|
||||||
|
for(int i = 0; i < found.size();i++)
|
||||||
|
{
|
||||||
|
cout << hex << "0x" << found[i] << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void printFoundStrVec(vector <uint64_t> &found, const char * what, SegmentedFinder & s)
|
||||||
|
{
|
||||||
|
cout << what << ":" << endl;
|
||||||
|
for(int i = 0; i < found.size();i++)
|
||||||
|
{
|
||||||
|
cout << hex << "0x" << found[i] << endl;
|
||||||
|
cout << "--------------------------" << endl;
|
||||||
|
vecTriplet * vt = s.Translate<vecTriplet>(found[i]);
|
||||||
|
if(vt)
|
||||||
|
{
|
||||||
|
int j = 0;
|
||||||
|
for(uint32_t idx = vt->start; idx < vt->finish; idx += sizeof(uint32_t))
|
||||||
|
{
|
||||||
|
uint32_t object_ptr;
|
||||||
|
// deref ptr idx, get ptr to object
|
||||||
|
if(!s.Read(idx,object_ptr))
|
||||||
|
{
|
||||||
|
cout << "BAD!" << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// deref ptr to first object, get ptr to string
|
||||||
|
uint32_t string_ptr;
|
||||||
|
if(!s.Read(object_ptr,string_ptr))
|
||||||
|
{
|
||||||
|
cout << "BAD!" << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// get string location in our local cache
|
||||||
|
char * str = s.Translate<char>(string_ptr);
|
||||||
|
if(!str)
|
||||||
|
{
|
||||||
|
cout << "BAD!" << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout << dec << j << ":" << hex << "0x" << object_ptr << " : " << str << endl;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout << "BAD!" << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cout << "--------------------------" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TokenFactory
|
||||||
|
{
|
||||||
|
DFHack::OSType platform;
|
||||||
|
public:
|
||||||
|
TokenFactory(DFHack::OSType platform_in)
|
||||||
|
{
|
||||||
|
platform = platform_in;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
T * Build()
|
||||||
|
{
|
||||||
|
return new T;
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
T * Build(uint64_t offset)
|
||||||
|
{
|
||||||
|
return new T(offset);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
String * TokenFactory::Build()
|
||||||
|
{
|
||||||
|
switch(platform)
|
||||||
|
{
|
||||||
|
case DFHack::OS_WINDOWS:
|
||||||
|
return new WindowsString();
|
||||||
|
case DFHack::OS_LINUX:
|
||||||
|
case DFHack::OS_APPLE:
|
||||||
|
return new LinuxString();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
template <>
|
||||||
|
String * TokenFactory::Build(uint64_t offset)
|
||||||
|
{
|
||||||
|
switch(platform)
|
||||||
|
{
|
||||||
|
case DFHack::OS_WINDOWS:
|
||||||
|
return new WindowsString(offset);
|
||||||
|
case DFHack::OS_LINUX:
|
||||||
|
case DFHack::OS_APPLE:
|
||||||
|
return new LinuxString(offset);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
void autoSearch(DFHack::Context * DF, vector <DFHack::t_memrange>& ranges, DFHack::OSType platform)
|
||||||
|
{
|
||||||
|
cout << "stealing memory..." << endl;
|
||||||
|
SegmentedFinder sf(ranges, DF);
|
||||||
|
TokenFactory tf(platform);
|
||||||
|
cout << "done!" << endl;
|
||||||
|
Struct maps;
|
||||||
|
maps.Add(tf.Build<String>());
|
||||||
|
maps.Add(tf.Build<String>());
|
||||||
|
/*
|
||||||
|
vector <uint64_t> allVectors;
|
||||||
|
vector <uint64_t> filtVectors;
|
||||||
|
vector <uint64_t> to_filter;
|
||||||
|
|
||||||
|
cout << "stealing memory..." << endl;
|
||||||
|
SegmentedFinder sf(ranges, DF);
|
||||||
|
cout << "looking for vectors..." << endl;
|
||||||
|
sf.Find<int ,vecTriplet>(0,4,allVectors, vectorAll);
|
||||||
|
|
||||||
|
filtVectors = allVectors;
|
||||||
|
cout << "-------------------" << endl;
|
||||||
|
cout << "!!LANGUAGE TABLES!!" << endl;
|
||||||
|
cout << "-------------------" << endl;
|
||||||
|
|
||||||
|
uint64_t kulet_vector;
|
||||||
|
uint64_t word_table_offset;
|
||||||
|
uint64_t DWARF_vector;
|
||||||
|
uint64_t DWARF_object;
|
||||||
|
|
||||||
|
// find lang vector (neutral word table)
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<const char * ,vecTriplet>("ABBEY",to_filter, vectorStringFirst);
|
||||||
|
uint64_t lang_addr = to_filter[0];
|
||||||
|
|
||||||
|
// find dwarven language word table
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<const char * ,vecTriplet>("kulet",to_filter, vectorStringFirst);
|
||||||
|
kulet_vector = to_filter[0];
|
||||||
|
|
||||||
|
// find vector of languages
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<const char * ,vecTriplet>("DWARF",to_filter, vectorStringFirst);
|
||||||
|
|
||||||
|
// verify
|
||||||
|
for(int i = 0; i < to_filter.size(); i++)
|
||||||
|
{
|
||||||
|
vecTriplet * vec = sf.Translate<vecTriplet>(to_filter[i]);
|
||||||
|
if(((vec->finish - vec->start) / 4) == 4) // verified
|
||||||
|
{
|
||||||
|
DWARF_vector = to_filter[i];
|
||||||
|
DWARF_object = sf.Read<uint32_t>(vec->start);
|
||||||
|
// compute word table offset from dwarf word table and dwarf language object addresses
|
||||||
|
word_table_offset = kulet_vector - DWARF_object;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << "translation vector: " << hex << "0x" << DWARF_vector << endl;
|
||||||
|
cout << "lang vector: " << hex << "0x" << lang_addr << endl;
|
||||||
|
cout << "word table offset: " << hex << "0x" << word_table_offset << endl;
|
||||||
|
|
||||||
|
cout << "-------------" << endl;
|
||||||
|
cout << "!!MATERIALS!!" << endl;
|
||||||
|
cout << "-------------" << endl;
|
||||||
|
// inorganics vector
|
||||||
|
to_filter = filtVectors;
|
||||||
|
//sf.Find<uint32_t,vecTriplet>(257 * 4,4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("IRON",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("ONYX",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("RAW_ADAMANTINE",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("BLOODSTONE",to_filter, vectorString);
|
||||||
|
printFound(to_filter,"inorganics");
|
||||||
|
|
||||||
|
// organics vector
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<uint32_t,vecTriplet>(52 * 4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("MUSHROOM_HELMET_PLUMP",to_filter, vectorStringFirst);
|
||||||
|
printFound(to_filter,"organics");
|
||||||
|
|
||||||
|
// tree vector
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<uint32_t,vecTriplet>(31 * 4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("MANGROVE",to_filter, vectorStringFirst);
|
||||||
|
printFound(to_filter,"trees");
|
||||||
|
|
||||||
|
// plant vector
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<uint32_t,vecTriplet>(21 * 4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("MUSHROOM_HELMET_PLUMP",to_filter, vectorStringFirst);
|
||||||
|
printFound(to_filter,"plants");
|
||||||
|
|
||||||
|
// color descriptors
|
||||||
|
//AMBER, 112
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<uint32_t,vecTriplet>(112 * 4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("AMBER",to_filter, vectorStringFirst);
|
||||||
|
printFound(to_filter,"color descriptors");
|
||||||
|
if(!to_filter.empty())
|
||||||
|
{
|
||||||
|
uint64_t vec = to_filter[0];
|
||||||
|
vecTriplet *vtColors = sf.Translate<vecTriplet>(vec);
|
||||||
|
uint32_t colorObj = sf.Read<uint32_t>(vtColors->start);
|
||||||
|
cout << "Amber color:" << hex << "0x" << colorObj << endl;
|
||||||
|
// TODO: find string 'amber', the floats
|
||||||
|
}
|
||||||
|
|
||||||
|
// all descriptors
|
||||||
|
//AMBER, 338
|
||||||
|
to_filter = filtVectors;
|
||||||
|
sf.Filter<uint32_t,vecTriplet>(338 * 4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("AMBER",to_filter, vectorStringFirst);
|
||||||
|
printFound(to_filter,"all descriptors");
|
||||||
|
|
||||||
|
// creature type
|
||||||
|
//ELEPHANT, ?? (demons abound)
|
||||||
|
to_filter = filtVectors;
|
||||||
|
//sf.Find<uint32_t,vecTriplet>(338 * 4,4,to_filter,vectorLength<uint32_t>);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("ELEPHANT",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("CAT",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("DWARF",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("WAMBLER_FLUFFY",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("TOAD",to_filter, vectorString);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("DEMON_1",to_filter, vectorString);
|
||||||
|
|
||||||
|
vector <uint64_t> toad_first = to_filter;
|
||||||
|
vector <uint64_t> elephant_first = to_filter;
|
||||||
|
sf.Filter<const char * ,vecTriplet>("TOAD",toad_first, vectorStringFirst);
|
||||||
|
sf.Filter<const char * ,vecTriplet>("ELEPHANT",elephant_first, vectorStringFirst);
|
||||||
|
printFoundStrVec(toad_first,"toad-first creature types",sf);
|
||||||
|
printFound(elephant_first,"elephant-first creature types");
|
||||||
|
printFound(to_filter,"all creature types");
|
||||||
|
|
||||||
|
uint64_t to_use = 0;
|
||||||
|
if(!elephant_first.empty())
|
||||||
|
{
|
||||||
|
to_use = elephant_first[0];
|
||||||
|
vecTriplet *vtCretypes = sf.Translate<vecTriplet>(to_use);
|
||||||
|
uint32_t elephant = sf.Read<uint32_t>(vtCretypes->start);
|
||||||
|
uint64_t Eoffset;
|
||||||
|
cout << "Elephant: 0x" << hex << elephant << endl;
|
||||||
|
cout << "Elephant: rawname = 0x0" << endl;
|
||||||
|
uint8_t letter_E = 'E';
|
||||||
|
Eoffset = sf.FindInRange<uint8_t,uint8_t> (letter_E,equalityP<uint8_t>, elephant, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Elephant: big E = 0x" << hex << Eoffset - elephant << endl;
|
||||||
|
}
|
||||||
|
Eoffset = sf.FindInRange<const char *,vecTriplet> ("FEMALE",vectorStringFirst, elephant, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Elephant: caste vector = 0x" << hex << Eoffset - elephant << endl;
|
||||||
|
}
|
||||||
|
Eoffset = sf.FindInRange<const char *,vecTriplet> ("SKIN",vectorStringFirst, elephant, 0x2000 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Elephant: extract? vector = 0x" << hex << Eoffset - elephant << endl;
|
||||||
|
}
|
||||||
|
tilecolors eletc = {7,0,0};
|
||||||
|
Bytestream bs_eletc(&eletc, sizeof(tilecolors));
|
||||||
|
cout << bs_eletc;
|
||||||
|
Eoffset = sf.FindInRange<Bytestream,tilecolors> (bs_eletc, findBytestream, elephant, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Elephant: colors = 0x" << hex << Eoffset - elephant << endl;
|
||||||
|
}
|
||||||
|
//cout << "Amber color:" << hex << "0x" << colorObj << endl;
|
||||||
|
// TODO: find string 'amber', the floats
|
||||||
|
}
|
||||||
|
if(!toad_first.empty())
|
||||||
|
{
|
||||||
|
to_use = toad_first[0];
|
||||||
|
vecTriplet *vtCretypes = sf.Translate<vecTriplet>(to_use);
|
||||||
|
uint32_t toad = sf.Read<uint32_t>(vtCretypes->start);
|
||||||
|
uint64_t Eoffset;
|
||||||
|
cout << "Toad: 0x" << hex << toad << endl;
|
||||||
|
cout << "Toad: rawname = 0x0" << endl;
|
||||||
|
Eoffset = sf.FindInRange<uint8_t,uint8_t> (0xF9,equalityP<uint8_t>, toad, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Toad: character (not reliable) = 0x" << hex << Eoffset - toad << endl;
|
||||||
|
}
|
||||||
|
Eoffset = sf.FindInRange<const char *,vecTriplet> ("FEMALE",vectorStringFirst, toad, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Toad: caste vector = 0x" << hex << Eoffset - toad << endl;
|
||||||
|
}
|
||||||
|
Eoffset = sf.FindInRange<const char *,vecTriplet> ("SKIN",vectorStringFirst, toad, 0x2000 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Toad: extract? vector = 0x" << hex << Eoffset - toad << endl;
|
||||||
|
}
|
||||||
|
tilecolors toadtc = {2,0,0};
|
||||||
|
Bytestream bs_toadc(&toadtc, sizeof(tilecolors));
|
||||||
|
Eoffset = sf.FindInRange<Bytestream,tilecolors> (bs_toadc, findBytestream, toad, 0x300 );
|
||||||
|
if(Eoffset)
|
||||||
|
{
|
||||||
|
cout << "Toad: colors = 0x" << hex << Eoffset - toad << endl;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
string select;
|
||||||
|
DFHack::ContextManager DFMgr("Memory.xml");
|
||||||
|
DFHack::Context * DF = DFMgr.getSingleContext();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DF->Attach();
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
DFHack::Process * p = DF->getProcess();
|
||||||
|
vector <DFHack::t_memrange> selected_ranges;
|
||||||
|
getRanges(p,selected_ranges);
|
||||||
|
|
||||||
|
DFHack::VersionInfo *minfo = DF->getMemoryInfo();
|
||||||
|
autoSearch(DF,selected_ranges, minfo->getOS());
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cout << "Done. Press any key to continue" << endl;
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
// This forces the game to pause.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <DFHack.h>
|
||||||
|
#include <dfhack/modules/Gui.h>
|
||||||
|
|
||||||
|
int main (int argc, char** argv)
|
||||||
|
{
|
||||||
|
bool quiet = false;
|
||||||
|
for(int i = 1; i < argc; i++)
|
||||||
|
{
|
||||||
|
string test = argv[i];
|
||||||
|
if(test == "-q")
|
||||||
|
{
|
||||||
|
quiet = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DFHack::ContextManager DFMgr("Memory.xml");
|
||||||
|
DFHack::Context *DF;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DF = DFMgr.getSingleContext();
|
||||||
|
DF->Attach();
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
if(!quiet) cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFHack::Gui *Gui =DF->getGui();
|
||||||
|
cout << "Pausing..." << endl;
|
||||||
|
|
||||||
|
Gui->SetPauseState(true);
|
||||||
|
DF->Resume();
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cout << "Done. The current game frame will have to finish first. This can take some time on bugged maps." << endl;
|
||||||
|
if (!quiet) cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue