Merge branch 'master' of http://github.com/doomchild/dfhack
commit
9bd6bb5b2d
@ -0,0 +1,367 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||
|
||||
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 "Tranquility.h"
|
||||
#include "Export.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "integers.h"
|
||||
#include "DFTileTypes.h"
|
||||
#include "DFTypes.h"
|
||||
#include "DFWindow.h"
|
||||
#include "DFContextManager.h"
|
||||
#include "DFContext.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace DFHack;
|
||||
|
||||
#include "DFContext_C.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DFHackObject* ContextManager_Alloc(const char* path_to_xml)
|
||||
{
|
||||
DFHack::ContextManager* contextMgr = new DFHack::ContextManager(std::string(path_to_xml));
|
||||
return (DFHackObject*)contextMgr;
|
||||
}
|
||||
|
||||
//FIXME: X:\dfhack\DFHackContext_C.cpp:56: warning: deleting `DFHackObject* ' is undefined
|
||||
//DC: Yeah, I forgot that trying to delete a void pointer might be a bad idea. This works now.
|
||||
void ContextManager_Free(DFHackObject* contextMgr)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
DFHack::ContextManager* a = (DFHack::ContextManager*)contextMgr;
|
||||
delete a;
|
||||
|
||||
contextMgr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int ContextManager_Refresh(DFHackObject* contextMgr)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
return ((DFHack::ContextManager*)contextMgr)->Refresh();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ContextManager_size(DFHackObject* contextMgr, uint32_t* size)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
uint32_t result = ((DFHack::ContextManager*)contextMgr)->size();
|
||||
|
||||
*size = result;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ContextManager_purge(DFHackObject* contextMgr)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
((DFHack::ContextManager*)contextMgr)->purge();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
DFHackObject* ContextManager_getContext(DFHackObject* contextMgr, uint32_t index)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
DFHack::ContextManager* mgr = ((DFHack::ContextManager*)contextMgr);
|
||||
|
||||
if(index >= mgr->size())
|
||||
return NULL;
|
||||
|
||||
return (DFHackObject*)((DFHack::Context*)((*mgr)[index]));
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* ContextManager_getSingleContext(DFHackObject* contextMgr)
|
||||
{
|
||||
if(contextMgr != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::ContextManager*)contextMgr)->getSingleContext();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Context_Free(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
DFHack::Context* c = (DFHack::Context*)context;
|
||||
delete c;
|
||||
|
||||
context = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int Context_Attach(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->Attach();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_Detach(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->Detach();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_isAttached(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->isAttached();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_Suspend(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->Suspend();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_Resume(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->Resume();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_isSuspended(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->isSuspended();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_ForceResume(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->ForceResume();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Context_AsyncSuspend(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return ((DFHack::Context*)context)->AsyncSuspend();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//module getters
|
||||
|
||||
DFHackObject* Context_getMemoryInfo(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getMemoryInfo();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getProcess(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getProcess();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getWindow(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getWindow();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getCreatures(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getCreatures();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getMaps(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getMaps();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getGui(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getGui();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getPosition(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getPosition();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getMaterials(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getMaterials();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getTranslation(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getTranslation();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getVegetation(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getVegetation();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getBuildings(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getBuildings();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getConstructions(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getConstructions();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DFHackObject* Context_getItems(DFHackObject* context)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
return (DFHackObject*)((DFHack::Context*)context)->getItems();
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
((DFHack::Context*)context)->ReadRaw(offset, size, target);
|
||||
}
|
||||
}
|
||||
|
||||
void Context_WriteRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* source)
|
||||
{
|
||||
if(context != NULL)
|
||||
{
|
||||
((DFHack::Context*)context)->WriteRaw(offset, size, source);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,82 @@
|
||||
/*
|
||||
www.sourceforge.net/projects/dfhack
|
||||
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild
|
||||
|
||||
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 DFHACK_C_CONTEXT
|
||||
#define DFHACK_C_CONTEXT
|
||||
|
||||
#include "Export.h"
|
||||
#include "integers.h"
|
||||
|
||||
typedef void DFHackObject;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DFHACK_EXPORT DFHackObject* ContextManager_Alloc(const char* path_to_xml);
|
||||
DFHACK_EXPORT void ContextManager_Free(DFHackObject* contextMgr);
|
||||
|
||||
DFHACK_EXPORT int ContextManager_Refresh(DFHackObject* contextMgr);
|
||||
DFHACK_EXPORT int ContextManager_size(DFHackObject* contextMgr, uint32_t* size);
|
||||
DFHACK_EXPORT int ContextManager_purge(DFHackObject* contextMgr);
|
||||
|
||||
DFHACK_EXPORT DFHackObject* ContextManager_getContext(DFHackObject* contextMgr, uint32_t index);
|
||||
DFHACK_EXPORT DFHackObject* ContextManager_getSingleContext(DFHackObject* contextMgr);
|
||||
|
||||
DFHACK_EXPORT void Context_Free(DFHackObject* context);
|
||||
|
||||
DFHACK_EXPORT int Context_Attach(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_Detach(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_isAttached(DFHackObject* context);
|
||||
|
||||
DFHACK_EXPORT int Context_Suspend(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_Resume(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_isSuspended(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_ForceResume(DFHackObject* context);
|
||||
DFHACK_EXPORT int Context_AsyncSuspend(DFHackObject* context);
|
||||
|
||||
DFHACK_EXPORT DFHackObject* Context_getMemoryInfo(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getProcess(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getWindow(DFHackObject* context);
|
||||
|
||||
DFHACK_EXPORT DFHackObject* Context_getCreatures(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getMaps(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getGui(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getPosition(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getMaterials(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getTranslation(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getVegetation(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getBuildings(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getConstructions(DFHackObject* context);
|
||||
DFHACK_EXPORT DFHackObject* Context_getItems(DFHackObject* context);
|
||||
|
||||
//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc
|
||||
DFHACK_EXPORT void Context_ReadRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* target);
|
||||
DFHACK_EXPORT void Context_WriteRaw(DFHackObject* context, const uint32_t offset, const uint32_t size, uint8_t* source);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,195 @@
|
||||
from ctypes import *
|
||||
from pydftypes import *
|
||||
|
||||
libdfhack.ContextManager_Alloc.restype = c_void_p
|
||||
libdfhack.ContextManager_Free.argtypes = [ c_void_p ]
|
||||
|
||||
libdfhack.ContextManager_getContext.restype = c_void_p
|
||||
libdfhack.ContextManager_getSingleContext.restype = c_void_p
|
||||
|
||||
libdfhack.Context_Free.argtypes = [ c_void_p ]
|
||||
|
||||
libdfhack.Context_getMemoryInfo.restype = c_void_p
|
||||
libdfhack.Context_getProcess.restype = c_void_p
|
||||
libdfhack.Context_getWindow.restype = c_void_p
|
||||
|
||||
libdfhack.Context_getCreatures.restype = c_void_p
|
||||
libdfhack.Context_getMaps.restype = c_void_p
|
||||
libdfhack.Context_getGui.restype = c_void_p
|
||||
libdfhack.Context_getPosition.restype = c_void_p
|
||||
libdfhack.Context_getMaterials.restype = c_void_p
|
||||
libdfhack.Context_getTranslation.restype = c_void_p
|
||||
libdfhack.Context_getVegetation.restype = c_void_p
|
||||
libdfhack.Context_getBuildings.restype = c_void_p
|
||||
libdfhack.Context_getConstructions.restype = c_void_p
|
||||
libdfhack.Context_getItems.restype = c_void_p
|
||||
|
||||
class ContextManager(object):
|
||||
def __init__(self, memory_path):
|
||||
self._cm_ptr = libdfhack.ContextManager_Alloc(create_string_buffer(memory_path))
|
||||
|
||||
def __del__(self):
|
||||
libdfhack.ContextManager_Free(self._cm_ptr)
|
||||
|
||||
def refresh(self):
|
||||
return libdfhack.ContextManager_Refresh(self._cm_ptr) > 0
|
||||
|
||||
def purge(self):
|
||||
libdfhack.ContextManager_purge(self._cm_ptr)
|
||||
|
||||
def get_context(self, index):
|
||||
p = libdfhack.ContextManager_getContext(self._cm_ptr, index)
|
||||
|
||||
if p:
|
||||
return Context(p)
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_single_context(self):
|
||||
p = libdfhack.ContextManager_getSingleContext(self._cm_ptr)
|
||||
|
||||
if p:
|
||||
return Context(p)
|
||||
else:
|
||||
return None
|
||||
|
||||
class Context(object):
|
||||
def __init__(self, ptr):
|
||||
self._c_ptr = ptr
|
||||
|
||||
self._pos_obj = None
|
||||
self._mat_obj = None
|
||||
self._map_obj = None
|
||||
self._veg_obj = None
|
||||
self._build_obj = None
|
||||
self._con_obj = None
|
||||
self._gui_obj = None
|
||||
self._tran_obj = None
|
||||
self._item_obj = None
|
||||
self._creature_obj = None
|
||||
|
||||
def __del__(self):
|
||||
libdfhack.Context_Free(self._c_ptr)
|
||||
|
||||
def attach(self):
|
||||
return libdfhack.Context_Attach(self._c_ptr) > 0
|
||||
|
||||
def detach(self):
|
||||
return libdfhack.Context_Detach(self._c_ptr) > 0
|
||||
|
||||
def suspend(self):
|
||||
return libdfhack.Context_Suspend(self._c_ptr) > 0
|
||||
|
||||
def resume(self):
|
||||
return libdfhack.Context_Resume(self._c_ptr) > 0
|
||||
|
||||
def force_resume(self):
|
||||
return libdfhack.Context_ForceResume(self._c_ptr) > 0
|
||||
|
||||
def async_suspend(self):
|
||||
return libdfhack.Context_AsyncSuspend(self._c_ptr) > 0
|
||||
|
||||
@property
|
||||
def is_attached(self):
|
||||
return libdfhack.Context_isAttached(self._c_ptr) > 0
|
||||
|
||||
@property
|
||||
def is_suspended(self):
|
||||
return libdfhack.Context_isSuspended(self._c_ptr) > 0
|
||||
|
||||
@property
|
||||
def position(self):
|
||||
import position
|
||||
if self._pos_obj is None:
|
||||
self._pos_obj = position.Position(libdfhack.Context_getPosition(self._c_ptr))
|
||||
|
||||
return self._pos_obj
|
||||
|
||||
@property
|
||||
def materials(self):
|
||||
import materials
|
||||
if self._mat_obj is None:
|
||||
self._mat_obj = materials.Materials(libdfhack.Context_getMaterials(self._c_ptr))
|
||||
|
||||
return self._mat_obj
|
||||
|
||||
@property
|
||||
def maps(self):
|
||||
import maps
|
||||
if self._map_obj is None:
|
||||
self._map_obj = maps.Maps(libdfhack.Context_getMaps(self._c_ptr))
|
||||
|
||||
return self._map_obj
|
||||
|
||||
@property
|
||||
def vegetation(self):
|
||||
import vegetation
|
||||
if self._veg_obj is None:
|
||||
self._veg_obj = vegetation.Vegetation(libdfhack.Context_getVegetation(self._c_ptr))
|
||||
|
||||
return self._veg_obj
|
||||
|
||||
@property
|
||||
def buildings(self):
|
||||
import buildings
|
||||
if self._build_obj is None:
|
||||
self._build_obj = buildings.Buildings(libdfhack.Context_getBuildings(self._c_ptr))
|
||||
|
||||
return self._build_obj
|
||||
|
||||
@property
|
||||
def creatures(self):
|
||||
import creatures
|
||||
if self._creature_obj is None:
|
||||
self._creature_obj = creatures.Creatures(libdfhack.Context_getCreatures(self._c_ptr))
|
||||
|
||||
return self._creature_obj
|
||||
|
||||
@property
|
||||
def gui(self):
|
||||
import gui
|
||||
if self._gui_obj is None:
|
||||
self._gui_obj = gui.Gui(libdfhack.Context_getGui(self._c_ptr))
|
||||
|
||||
return self._gui_obj
|
||||
|
||||
@property
|
||||
def items(self):
|
||||
import items
|
||||
if self._item_obj is None:
|
||||
self._item_obj = items.Items(libdfhack.Context_getItems(self._c_ptr))
|
||||
|
||||
return self._item_obj
|
||||
|
||||
@property
|
||||
def translation(self):
|
||||
import translation
|
||||
if self._tran_obj is None:
|
||||
self._tran_obj = translation.Translation(libdfhack.Context_getTranslation(self._c_ptr))
|
||||
|
||||
return self._tran_obj
|
||||
|
||||
def reveal():
|
||||
df = API("Memory.xml")
|
||||
df.attach()
|
||||
|
||||
m = df.maps
|
||||
|
||||
m.start()
|
||||
|
||||
m_x, m_y, m_z = m.size
|
||||
|
||||
for x in xrange(m_x):
|
||||
for y in xrange(m_y):
|
||||
for z in xrange(m_z):
|
||||
if m.is_valid_block(x, y, z):
|
||||
d = m.read_designations(x, y, z)
|
||||
|
||||
for i in d:
|
||||
for j in i:
|
||||
j.bits.hidden = 0
|
||||
|
||||
m.write_designations(x, y, z, d)
|
||||
|
||||
m.finish()
|
||||
df.detach()
|
Loading…
Reference in New Issue