first commit
parent
c7217cbdf7
commit
ab0b9f48e9
@ -0,0 +1,688 @@
|
||||
/*
|
||||
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 __DF_MEMINFO__
|
||||
#define __DF_MEMINFO__
|
||||
|
||||
#include "Python.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "Export.h"
|
||||
#include "DFCommonInternal.h"
|
||||
#include "DFMemInfo.h"
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
struct DF_MemInfo
|
||||
{
|
||||
PyObject_HEAD
|
||||
DFHack::memory_info* mem_Ptr;
|
||||
};
|
||||
|
||||
// MemInfo type Allocation, Deallocation, and Initialization
|
||||
|
||||
static PyObject* DF_MemInfo_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
DF_MemInfo* self;
|
||||
|
||||
self = (DF_MemInfo*)type->tp_alloc(type, 0);
|
||||
|
||||
if(self != NULL)
|
||||
{
|
||||
self->mem_Ptr = NULL;
|
||||
}
|
||||
|
||||
return (PyObject*)self;
|
||||
}
|
||||
|
||||
static int DF_MemInfo_init(DF_MemInfo* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
DF_MemInfo* copy = NULL;
|
||||
|
||||
if(self->mem_Ptr == NULL)
|
||||
{
|
||||
PyArg_ParseTuple(args, "|O", ©);
|
||||
|
||||
if(copy != NULL)
|
||||
self->mem_Ptr = new DFHack::memory_info(*(copy->mem_Ptr));
|
||||
else
|
||||
self->mem_Ptr = new DFHack::memory_info();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void DF_MemInfo_dealloc(DF_MemInfo* self)
|
||||
{
|
||||
if(self != NULL)
|
||||
{
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
delete self->mem_Ptr;
|
||||
|
||||
self->mem_Ptr = NULL;
|
||||
}
|
||||
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
}
|
||||
|
||||
// Setters/Getters
|
||||
|
||||
static PyObject* DF_MemInfo_getBase(DF_MemInfo* self)
|
||||
{
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
return PyInt_FromLong(self->mem_Ptr->getBase());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_setBase(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
PyObject* arg = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "O", arg))
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "Bad argument list");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(PyString_Check(arg))
|
||||
self->mem_Ptr->setBase(std::string(PyString_AsString(arg)));
|
||||
else if(PyInt_Check(arg))
|
||||
self->mem_Ptr->setBase((uint32_t)PyInt_AsUnsignedLongMask(arg));
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "Argument must be string or integer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_getVersion(DF_MemInfo* self)
|
||||
{
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
return PyString_FromString(self->mem_Ptr->getVersion().c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_setVersion(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* v = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &v))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setVersion(v);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyGetSetDef DF_MemInfo_getterSetters[] =
|
||||
{
|
||||
{"base", (getter)DF_MemInfo_getBase, (setter)DF_MemInfo_setBase, "base", NULL},
|
||||
{"version", (getter)DF_MemInfo_getVersion, (setter)DF_MemInfo_setVersion, "version", NULL},
|
||||
{NULL} // Sentinel
|
||||
};
|
||||
|
||||
// Member methods
|
||||
|
||||
static PyObject* DF_MemInfo_GetOffset(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &s))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong(self->mem_Ptr->getOffset(s));
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetOffset(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
// const char* s = NULL;
|
||||
// const char* n = NULL;
|
||||
// int32_t i;
|
||||
// PyObject* obj;
|
||||
|
||||
// if(self->mem_Ptr != NULL)
|
||||
// {
|
||||
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||
// return NULL;
|
||||
|
||||
// if(PyString_Check(obj))
|
||||
// {
|
||||
// n = PyString_AsString(obj);
|
||||
// self->mem_Ptr->setOffset(s, n);
|
||||
// }
|
||||
// else if(PyInt_Check(obj))
|
||||
// {
|
||||
// i = (int32_t)PyInt_AsLong(obj);
|
||||
// self->mem_Ptr->setOffset(s, i);
|
||||
// }
|
||||
// }
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetAddress(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &s))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong(self->mem_Ptr->getAddress(s));
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetAddress(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
// const char* s = NULL;
|
||||
// const char* n = NULL;
|
||||
// int32_t i;
|
||||
// PyObject* obj;
|
||||
|
||||
// if(self->mem_Ptr != NULL)
|
||||
// {
|
||||
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||
// return NULL;
|
||||
|
||||
// if(PyString_Check(obj))
|
||||
// {
|
||||
// n = PyString_AsString(obj);
|
||||
// self->mem_Ptr->setAddress(s, n);
|
||||
// }
|
||||
// else if(PyInt_Check(obj))
|
||||
// {
|
||||
// i = (int32_t)PyInt_AsLong(obj);
|
||||
// self->mem_Ptr->setAddress(s, i);
|
||||
// }
|
||||
// }
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetHexValue(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &s))
|
||||
return NULL;
|
||||
|
||||
return PyInt_FromLong(self->mem_Ptr->getHexValue(s));
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetHexValue(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
// const char* s = NULL;
|
||||
// const char* n = NULL;
|
||||
// int32_t i;
|
||||
// PyObject* obj;
|
||||
|
||||
// if(self->mem_Ptr != NULL)
|
||||
// {
|
||||
// if(!PyArg_ParseTuple(args, "sO", &s, &obj))
|
||||
// return NULL;
|
||||
|
||||
// if(PyString_Check(obj))
|
||||
// {
|
||||
// n = PyString_AsString(obj);
|
||||
// self->mem_Ptr->setHexValue(s, n);
|
||||
// }
|
||||
// else if(PyInt_Check(obj))
|
||||
// {
|
||||
// i = (int32_t)PyInt_AsLong(obj);
|
||||
// self->mem_Ptr->setHexValue(s, i);
|
||||
// }
|
||||
// }
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetString(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getString(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetString(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
// const char* s = NULL;
|
||||
// const char* n = NULL;
|
||||
|
||||
// if(self->mem_Ptr != NULL)
|
||||
// {
|
||||
// if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||
// return NULL;
|
||||
|
||||
// self->mem_Ptr->setString(s, n);
|
||||
// }
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetProfession(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "I", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getProfession(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetProfession(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
const char* n = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setProfession(s, n);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetJob(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "I", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getJob(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetJob(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
const char* n = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setJob(s, n);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetSkill(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "I", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getSkill(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetSkill(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
const char* n = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setSkill(s, n);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetTrait(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s, n;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "II", &s, &n))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getTrait(s, n).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
// I have no idea what any of the strings are, so I can't really put meaningful names - doomchild
|
||||
static PyObject* DF_MemInfo_SetTrait(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* a = NULL;
|
||||
const char* b = NULL;
|
||||
const char* c = NULL;
|
||||
const char* d = NULL;
|
||||
const char* e = NULL;
|
||||
const char* f = NULL;
|
||||
const char* g = NULL;
|
||||
const char* h = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "ssssssss", &a, &b, &c, &d, &e, &f, &g, &h))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setTrait(a, b, c, d, e, f, g, h);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetTraitName(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "I", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getTraitName(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_GetLabor(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t s;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "i", &s))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(self->mem_Ptr->getLabor(s).c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_SetLabor(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* s = NULL;
|
||||
const char* n = NULL;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "ss", &s, &n))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->setLabor(s, n);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_RebaseAddresses(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
int32_t base;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "i", &base))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->RebaseAddresses(base);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_RebaseAll(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
int32_t base;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "i", &base))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->RebaseAll(base);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_RebaseVTable(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
int32_t offset;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "i", &offset))
|
||||
return NULL;
|
||||
|
||||
self->mem_Ptr->RebaseVTable(offset);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_ResolveObjectToClassID(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
uint32_t address;
|
||||
int32_t classID;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "I", &address))
|
||||
return NULL;
|
||||
|
||||
if(self->mem_Ptr->resolveObjectToClassID(address, classID))
|
||||
return PyInt_FromLong(classID);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_ResolveClassNameToClassID(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
// const char* name;
|
||||
// int32_t classID;
|
||||
|
||||
// if(self->mem_Ptr != NULL)
|
||||
// {
|
||||
// if(!PyArg_ParseTuple(args, "s", &name))
|
||||
// return NULL;
|
||||
|
||||
// if(self->mem_Ptr->resolveClassnameToClassID(name, classID))
|
||||
// return PyInt_FromLong(classID);
|
||||
// }
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_ResolveClassNameToVPtr(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
const char* n;
|
||||
uint32_t vPtr;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "s", &n))
|
||||
return NULL;
|
||||
|
||||
std::string name(n);
|
||||
|
||||
if(self->mem_Ptr->resolveClassnameToVPtr(name, vPtr))
|
||||
return PyInt_FromLong(vPtr);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject* DF_MemInfo_ResolveClassIDToClassName(DF_MemInfo* self, PyObject* args)
|
||||
{
|
||||
int32_t id;
|
||||
string name;
|
||||
|
||||
if(self->mem_Ptr != NULL)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "i", &id))
|
||||
return NULL;
|
||||
|
||||
if(self->mem_Ptr->resolveClassIDToClassname(id, name))
|
||||
return PyString_FromString(name.c_str());
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef DF_MemInfo_methods[] =
|
||||
{
|
||||
{"Rebase_Addresses", (PyCFunction)DF_MemInfo_RebaseAddresses, METH_VARARGS, ""},
|
||||
{"Rebase_All", (PyCFunction)DF_MemInfo_RebaseAll, METH_VARARGS, ""},
|
||||
{"Rebase_VTable", (PyCFunction)DF_MemInfo_RebaseVTable, METH_VARARGS, ""},
|
||||
{"Get_Offset", (PyCFunction)DF_MemInfo_GetOffset, METH_VARARGS, ""},
|
||||
{"Set_Offset", (PyCFunction)DF_MemInfo_SetOffset, METH_VARARGS, ""},
|
||||
{"Get_Address", (PyCFunction)DF_MemInfo_GetAddress, METH_VARARGS, ""},
|
||||
{"Set_Address", (PyCFunction)DF_MemInfo_SetAddress, METH_VARARGS, ""},
|
||||
{"Get_HexValue", (PyCFunction)DF_MemInfo_GetHexValue, METH_VARARGS, ""},
|
||||
{"Set_HexValue", (PyCFunction)DF_MemInfo_SetHexValue, METH_VARARGS, ""},
|
||||
{"Get_String", (PyCFunction)DF_MemInfo_GetString, METH_VARARGS, ""},
|
||||
{"Set_String", (PyCFunction)DF_MemInfo_SetString, METH_VARARGS, ""},
|
||||
{"Get_Profession", (PyCFunction)DF_MemInfo_GetProfession, METH_VARARGS, ""},
|
||||
{"Set_Profession", (PyCFunction)DF_MemInfo_SetProfession, METH_VARARGS, ""},
|
||||
{"Get_Job", (PyCFunction)DF_MemInfo_GetJob, METH_VARARGS, ""},
|
||||
{"Set_Job", (PyCFunction)DF_MemInfo_SetJob, METH_VARARGS, ""},
|
||||
{"Get_Skill", (PyCFunction)DF_MemInfo_GetSkill, METH_VARARGS, ""},
|
||||
{"Set_Skill", (PyCFunction)DF_MemInfo_SetSkill, METH_VARARGS, ""},
|
||||
{"Get_Trait", (PyCFunction)DF_MemInfo_GetTrait, METH_VARARGS, ""},
|
||||
{"Set_Trait", (PyCFunction)DF_MemInfo_SetTrait, METH_VARARGS, ""},
|
||||
{"Get_Trait_Name", (PyCFunction)DF_MemInfo_GetTraitName, METH_VARARGS, ""},
|
||||
{"Get_Labor", (PyCFunction)DF_MemInfo_GetLabor, METH_VARARGS, ""},
|
||||
{"Set_Labor", (PyCFunction)DF_MemInfo_SetLabor, METH_VARARGS, ""},
|
||||
{"Resolve_Object_To_Class_ID", (PyCFunction)DF_MemInfo_ResolveObjectToClassID, METH_VARARGS, ""},
|
||||
{"Resolve_Classname_To_Class_ID", (PyCFunction)DF_MemInfo_ResolveClassNameToClassID, METH_VARARGS, ""},
|
||||
{"Resolve_Classname_To_VPtr", (PyCFunction)DF_MemInfo_ResolveClassNameToVPtr, METH_VARARGS, ""},
|
||||
{"Resolve_Class_ID_To_Classname", (PyCFunction)DF_MemInfo_ResolveClassIDToClassName, METH_VARARGS, ""},
|
||||
{NULL} //Sentinel
|
||||
};
|
||||
|
||||
static PyTypeObject DF_MemInfo_type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"pydfhack.DF_MemInfo", /*tp_name*/
|
||||
sizeof(DF_MemInfo), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)DF_MemInfo_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"pydfhack DF_MemInfo objects", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
DF_MemInfo_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
DF_MemInfo_getterSetters, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)DF_MemInfo_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
DF_MemInfo_new, /* tp_new */
|
||||
};
|
||||
|
||||
#endif
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
@ -1,215 +0,0 @@
|
||||
/*
|
||||
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 __UNIONBASE__
|
||||
#define __UNIONBASE__
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
struct UnionBase
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int whole;
|
||||
};
|
||||
|
||||
static PyObject* UnionBase_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
UnionBase* self;
|
||||
|
||||
self = (UnionBase*)type->tp_alloc(type, 0);
|
||||
|
||||
if(self != NULL)
|
||||
self->whole = 0;
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return (PyObject*)self;
|
||||
}
|
||||
|
||||
static int UnionBase_init(UnionBase* self, PyObject* args, PyObject* kwds)
|
||||
{
|
||||
if(!PyArg_ParseTuple(args, "|I", &self->whole))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void UnionBase_dealloc(UnionBase* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_GetBitMask(UnionBase* self, PyObject* args)
|
||||
{
|
||||
unsigned int mask;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "I", &mask))
|
||||
Py_RETURN_NONE;
|
||||
|
||||
if((self->whole & mask) != 0)
|
||||
Py_RETURN_TRUE;
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_SetBitMask(UnionBase* self, PyObject* args)
|
||||
{
|
||||
unsigned int mask;
|
||||
int on;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "Ii", &mask, &on))
|
||||
return NULL;
|
||||
|
||||
if(on)
|
||||
self->whole |= mask;
|
||||
else
|
||||
self->whole &= ~mask;
|
||||
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_GetSingleBit(UnionBase* self, PyObject* args)
|
||||
{
|
||||
unsigned int mask;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "I", &mask))
|
||||
Py_RETURN_NONE;
|
||||
|
||||
if((self->whole & (1 << mask)) != 0)
|
||||
Py_RETURN_TRUE;
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_SetSingleBit(UnionBase* self, PyObject* args)
|
||||
{
|
||||
unsigned int mask;
|
||||
int on;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "Ii", &mask, &on))
|
||||
return NULL;
|
||||
|
||||
if(on)
|
||||
self->whole |= (1 << mask);
|
||||
else
|
||||
self->whole &= ~(1 << mask);
|
||||
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_int(PyObject* self)
|
||||
{
|
||||
return PyInt_FromLong(((UnionBase*)self)->whole);
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_long(PyObject* self)
|
||||
{
|
||||
return PyInt_FromLong(((UnionBase*)self)->whole);
|
||||
}
|
||||
|
||||
static PyObject* UnionBase_hex(PyObject* self)
|
||||
{
|
||||
return PyNumber_ToBase(PyInt_FromLong(((UnionBase*)self)->whole), 16);
|
||||
}
|
||||
|
||||
static PyMethodDef UnionBase_methods[] =
|
||||
{
|
||||
{"_get_mask_bit", (PyCFunction)UnionBase_GetSingleBit, METH_VARARGS, "Get mask bit"},
|
||||
{"_set_mask_bit", (PyCFunction)UnionBase_SetSingleBit, METH_VARARGS, "Set mask bit"},
|
||||
{"_get_mask", (PyCFunction)UnionBase_GetBitMask, METH_VARARGS, ""},
|
||||
{"_set_mask", (PyCFunction)UnionBase_SetBitMask, METH_VARARGS, ""},
|
||||
{NULL} //Sentinel
|
||||
};
|
||||
|
||||
static PyNumberMethods UnionBase_as_number[] =
|
||||
{
|
||||
0, // binaryfunc nb_add; /* __add__ */
|
||||
0, // binaryfunc nb_subtract; /* __sub__ */
|
||||
0, // binaryfunc nb_multiply; /* __mul__ */
|
||||
0, // binaryfunc nb_divide; /* __div__ */
|
||||
0, // binaryfunc nb_remainder; /* __mod__ */
|
||||
0, // binaryfunc nb_divmod; /* __divmod__ */
|
||||
0, // ternaryfunc nb_power; /* __pow__ */
|
||||
0, // unaryfunc nb_negative; /* __neg__ */
|
||||
0, // unaryfunc nb_positive; /* __pos__ */
|
||||
0, // unaryfunc nb_absolute; /* __abs__ */
|
||||
0, // inquiry nb_nonzero; /* __nonzero__ */
|
||||
0, // unaryfunc nb_invert; /* __invert__ */
|
||||
0, // binaryfunc nb_lshift; /* __lshift__ */
|
||||
0, // binaryfunc nb_rshift; /* __rshift__ */
|
||||
0, // binaryfunc nb_and; /* __and__ */
|
||||
0, // binaryfunc nb_xor; /* __xor__ */
|
||||
0, // binaryfunc nb_or; /* __or__ */
|
||||
0, // coercion nb_coerce; /* __coerce__ */
|
||||
UnionBase_int, // unaryfunc nb_int; /* __int__ */
|
||||
UnionBase_long, // unaryfunc nb_long; /* __long__ */
|
||||
0, // unaryfunc nb_float; /* __float__ */
|
||||
0, // unaryfunc nb_oct; /* __oct__ */
|
||||
UnionBase_hex, // unaryfunc nb_hex; /* __hex__ */
|
||||
};
|
||||
|
||||
static PyTypeObject UnionBase_type =
|
||||
{
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"pydfhack.UnionBase", /*tp_name*/
|
||||
sizeof(UnionBase), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)UnionBase_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
UnionBase_as_number, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"pydfhack UnionBase objects", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
UnionBase_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)UnionBase_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
UnionBase_new, /* tp_new */
|
||||
};
|
||||
|
||||
#endif
|
@ -1,231 +0,0 @@
|
||||
/*
|
||||
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 __MATGLOSS__
|
||||
#define __MATGLOSS__
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "DFTypes.h"
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
// MatGloss
|
||||
|
||||
struct MatGloss
|
||||
{
|
||||
PyObject_HEAD
|
||||
DFHack::t_matgloss native;
|
||||
};
|
||||
|
||||
static PyObject* MatGloss_new(PyTypeObject* type, PyObject* arg, PyObject* kwds)
|
||||
{
|
||||
MatGloss* self;
|
||||
|
||||
self = (MatGloss*)type->tp_alloc(type, 0);
|
||||
|
||||
self->native->id[0] = '\0';
|
||||
self->native->name[0] = '\0';
|
||||
|
||||
return (PyObject*)self;
|
||||
}
|
||||
|
||||
static void MatGloss_dealloc(MatGloss* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject* MatGloss_GetID(MatGloss* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->id);
|
||||
}
|
||||
|
||||
static int MatGloss_SetID(MatGloss* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->id, temp, 127);
|
||||
self->native->id[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject* MatGloss_GetName(MatGloss* self, PyObject* args, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->name);
|
||||
}
|
||||
|
||||
static PyObject* MatGloss_SetName(MatGloss* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->name, temp, 127);
|
||||
self->native->name[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyGetSetDef MatGloss_getSetters[] =
|
||||
{
|
||||
{"id", (getter)MatGloss_GetID, (setter)MatGloss_SetID, "id", NULL},
|
||||
{"name", (getter)MatGloss_GetName, (setter)MatGloss_SetName, "name", NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
// MatGlossPlant
|
||||
|
||||
struct MatGlossPlant
|
||||
{
|
||||
PyObject_HEAD
|
||||
DFHack::t_matglossPlant native;
|
||||
};
|
||||
|
||||
static PyObject* MatGlossPlant_new(PyTypeObject* type, PyObject* arg, PyObject* kwds)
|
||||
{
|
||||
MatGlossPlant* self;
|
||||
|
||||
self = (MatGlossPlant*)type->tp_alloc(type, 0);
|
||||
|
||||
self->native->id[0] = '\0';
|
||||
self->native->name[0] = '\0';
|
||||
self->native->drink_name[127] = '\0';
|
||||
self->native->food_name[127] = '\0';
|
||||
self->native->extract_name[127] = '\0';
|
||||
|
||||
return (PyObject*)self;
|
||||
}
|
||||
|
||||
static void MatGlossPlant_dealloc(MatGlossPlant* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_GetID(MatGlossPlant* self, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->id);
|
||||
}
|
||||
|
||||
static int MatGlossPlant_SetID(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->id, temp, 127);
|
||||
self->native->id[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_GetName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->name);
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_SetName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->name, temp, 127);
|
||||
self->native->name[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_GetDrinkName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->drink_name);
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_SetDrinkName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->drink_name, temp, 127);
|
||||
self->native->drink_name[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_GetFoodName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->food_name);
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_SetFoodName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->food_name, temp, 127);
|
||||
self->native->food_name[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_GetExtractName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
return PyString_FromString(self->native->extract_name);
|
||||
}
|
||||
|
||||
static PyObject* MatGlossPlant_SetExtractName(MatGlossPlant* self, PyObject* args, void* closure)
|
||||
{
|
||||
char* temp;
|
||||
|
||||
if(!PyArg_ParseTuple(args, "s", &temp))
|
||||
return -1;
|
||||
|
||||
strncpy(self->native->extract_name, temp, 127);
|
||||
self->native->extract_name[127] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyGetSetDef MatGlossPlant_getSetters[] =
|
||||
{
|
||||
{"id", (getter)MatGlossPlant_GetID, (setter)MatGlossPlant_SetID, "id", NULL},
|
||||
{"name", (getter)MatGlossPlant_GetName, (setter)MatGlossPlant_SetName, "name", NULL},
|
||||
{"drink_name", (getter)MatGlossPlant_GetDrinkName, (setter)MatGlossPlant_SetDrinkName, "drink_name", NULL},
|
||||
{"food_name", (getter)MatGlossPlant_GetFoodName, (setter)MatGlossPlant_SetFoodName, "food_name", NULL},
|
||||
{"extract_name", (getter)MatGlossPlant_GetExtractName, (setter)MatGlossPlant_SetExtractName, "extract_name", NULL},
|
||||
{NULL}
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue