From 417ce7953ea217e584b5e4a33c2db40e87a1cb27 Mon Sep 17 00:00:00 2001 From: doomchild Date: Mon, 3 May 2010 15:50:43 -0500 Subject: [PATCH 1/5] fixed void pointer delete bug --- dfhack/DFHackAPI_C.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp index b9ebb76a9..e7bf624b0 100644 --- a/dfhack/DFHackAPI_C.cpp +++ b/dfhack/DFHackAPI_C.cpp @@ -49,11 +49,14 @@ DFHackObject* API_Alloc(const char* path_to_xml) } //FIXME: X:\dfhack\DFHackAPI_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 API_Free(DFHackObject* api) { if(api != NULL) { - delete api; + DFHack::API* a = (DFHack::API*)api; + delete a; + api = NULL; } } From 7d0ecfe5b820941c0199af044fd3a756e6a94890 Mon Sep 17 00:00:00 2001 From: doomchild Date: Mon, 3 May 2010 15:54:13 -0500 Subject: [PATCH 2/5] first commit, attaching/detaching/suspending/resuming works --- dfhack/python/dfhack_api_ctypes.py | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 dfhack/python/dfhack_api_ctypes.py diff --git a/dfhack/python/dfhack_api_ctypes.py b/dfhack/python/dfhack_api_ctypes.py new file mode 100644 index 000000000..d9f460ba8 --- /dev/null +++ b/dfhack/python/dfhack_api_ctypes.py @@ -0,0 +1,41 @@ +from ctypes import * + +int_ptr = POINTER(c_int) +uint_ptr = POINTER(c_uint) + +libdfhack = cdll.libdfhack +libdfhack.API_Alloc.restype = c_void_p +libdfhack.API_Free.argtypes = [ c_void_p ] + +class API(object): + def __init__(self, memory_path): + self._api_ptr = libdfhack.API_Alloc(create_string_buffer(memory_path)) + + def __del__(self): + libdfhack.API_Free(self._api_ptr) + + def Attach(self): + return libdfhack.API_Attach(self._api_ptr) > 0 + + def Detach(self): + return libdfhack.API_Detach(self._api_ptr) > 0 + + def Suspend(self): + return libdfhack.API_Suspend(self._api_ptr) > 0 + + def Resume(self): + return libdfhack.API_Resume(self._api_ptr) > 0 + + def Force_Resume(self): + return libdfhack.API_ForceResume(self._api_ptr) > 0 + + def Async_Suspend(self): + return libdfhack.API_AsyncSuspend(self._api_ptr) > 0 + + @property + def is_attached(self): + return libdfhack.API_isAttached(self._api_ptr) > 0 + + @property + def is_suspended(self): + return libdfhack.API_isSuspended(self._api_ptr) > 0 From ad14eb855fde60b7f160093284858408c71d2b19 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 4 May 2010 10:52:28 -0500 Subject: [PATCH 3/5] added module getters --- dfhack/DFHackAPI_C.cpp | 122 +++++++++++++++++++++++++++++++++++ dfhack/include/DFHackAPI_C.h | 15 +++++ 2 files changed, 137 insertions(+) diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp index e7bf624b0..fb6f7c932 100644 --- a/dfhack/DFHackAPI_C.cpp +++ b/dfhack/DFHackAPI_C.cpp @@ -140,6 +140,128 @@ int API_AsyncSuspend(DFHackObject* api) return -1; } +//module getters + +DFHackObject* API_getMemoryInfo(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getMemoryInfo(); + } + + return NULL; +} + +DFHackObject* API_getProcess(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getProcess(); + } + + return NULL; +} + +DFHackObject* API_getWindow(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getWindow(); + } + + return NULL; +} + +DFHackObject* API_getCreatures(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getCreatures(); + } + + return NULL; +} + +DFHackObject* API_getMaps(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getMaps(); + } + + return NULL; +} + +DFHackObject* API_getGui(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getGui(); + } + + return NULL; +} + +DFHackObject* API_getPosition(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getPosition(); + } + + return NULL; +} + +DFHackObject* API_getMaterials(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getMaterials(); + } + + return NULL; +} + +DFHackObject* API_getTranslation(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getTranslation(); + } + + return NULL; +} + +DFHackObject* API_getVegetation(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getVegetation(); + } + + return NULL; +} + +DFHackObject* API_getBuildings(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getBuildings(); + } + + return NULL; +} + +DFHackObject* API_getConstructions(DFHackObject* api) +{ + if(api != NULL) + { + return (DFHackObject*)((DFHack::API*)api)->getConstructions(); + } + + return NULL; +} + void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target) { if(api != NULL) diff --git a/dfhack/include/DFHackAPI_C.h b/dfhack/include/DFHackAPI_C.h index 88e7a3f2e..6c49aa35a 100644 --- a/dfhack/include/DFHackAPI_C.h +++ b/dfhack/include/DFHackAPI_C.h @@ -47,6 +47,21 @@ DFHACK_EXPORT int API_isSuspended(DFHackObject* api); DFHACK_EXPORT int API_ForceResume(DFHackObject* api); DFHACK_EXPORT int API_AsyncSuspend(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getMemoryInfo(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getProcess(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getWindow(DFHackObject* api); + +DFHACK_EXPORT DFHackObject* API_getCreatures(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getMaps(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getGui(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getPosition(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getMaterials(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getTranslation(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getVegetation(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getBuildings(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_getConstructions(DFHackObject* api); + +//these are DANGEROUS...can crash/segfault DF, turn the seas to blood, call up the Antichrist, etc DFHACK_EXPORT void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target); DFHACK_EXPORT void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source); From 5dd2a6753a6e33314018e05a226cd573a1086e44 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 4 May 2010 16:23:34 -0500 Subject: [PATCH 4/5] first commit --- dfhack/include/modules/Gui_C.h | 49 ++++++++++++++++++++ dfhack/modules/Gui_C.cpp | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 dfhack/include/modules/Gui_C.h create mode 100644 dfhack/modules/Gui_C.cpp diff --git a/dfhack/include/modules/Gui_C.h b/dfhack/include/modules/Gui_C.h new file mode 100644 index 000000000..cccde45fe --- /dev/null +++ b/dfhack/include/modules/Gui_C.h @@ -0,0 +1,49 @@ +/* +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 GUI_C_API +#define GUI_C_API + +#include "Export.h" +#include "integers.h" +#include "DFTypes.h" +#include "DFHackAPI_C.h" + +using namespace DFHack; + +#ifdef __cplusplus +extern "C" { +#endif + +DFHACK_EXPORT int Gui_Start(DFHackObject* gui); +DFHACK_EXPORT int Gui_Finish(DFHackObject* gui); + +DFHACK_EXPORT int Gui_ReadPauseState(DFHackObject* gui); +DFHACK_EXPORT int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/dfhack/modules/Gui_C.cpp b/dfhack/modules/Gui_C.cpp new file mode 100644 index 000000000..8a8dc185d --- /dev/null +++ b/dfhack/modules/Gui_C.cpp @@ -0,0 +1,81 @@ +/* +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 "modules/Gui_C.h" +#include "integers.h" + +#include "DFCommonInternal.h" +#include "modules/Gui.h" + +using namespace DFHack; + +#ifdef __cplusplus +extern "C" { +#endif + +int Gui_Start(DFHackObject* gui) +{ + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->Start(); + } + + return -1; +} + +int Gui_Finish(DFHackObject* gui) +{ + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->Finish(); + } + + return -1; +} + +int Gui_ReadPauseState(DFHackObject* gui) +{ + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->ReadPauseState(); + } + + return -1; +} + +int Gui_ReadViewScreen(DFHackObject* gui, t_viewscreen* viewscreen) +{ + int result; + + if(gui != NULL) + { + return ((DFHack::Gui*)gui)->ReadViewScreen(*viewscreen); + } + + return -1; +} + +#ifdef __cplusplus +} +#endif From fdd33ad7c2577c677984da254bd4aadbe8e3cb46 Mon Sep 17 00:00:00 2001 From: doomchild Date: Tue, 4 May 2010 16:24:12 -0500 Subject: [PATCH 5/5] added Gui_C stuff --- dfhack/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index c00d3218e..42965c3f4 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -45,6 +45,7 @@ modules/Buildings.cpp modules/Constructions.cpp modules/Position_C.cpp +modules/Gui_C.cpp ) SET(PROJECT_HDRS_LINUX