forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfhack_api_ctypes.py
More file actions
152 lines (113 loc) · 3.98 KB
/
Copy pathdfhack_api_ctypes.py
File metadata and controls
152 lines (113 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from ctypes import *
from pydftypes import *
libdfhack.API_Alloc.restype = c_void_p
libdfhack.API_Free.argtypes = [ c_void_p ]
libdfhack.API_getMemoryInfo.restype = c_void_p
libdfhack.API_getProcess.restype = c_void_p
libdfhack.API_getWindow.restype = c_void_p
libdfhack.API_getCreatures.restype = c_void_p
libdfhack.API_getMaps.restype = c_void_p
libdfhack.API_getGui.restype = c_void_p
libdfhack.API_getMaterials.restype = c_void_p
libdfhack.API_getTranslation.restype = c_void_p
libdfhack.API_getVegetation.restype = c_void_p
libdfhack.API_getBuildings.restype = c_void_p
libdfhack.API_getConstructions.restype = c_void_p
libdfhack.API_getItems.restype = c_void_p
class API(object):
def __init__(self, memory_path):
self._api_ptr = libdfhack.API_Alloc(create_string_buffer(memory_path))
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.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
@property
def materials(self):
import materials
if self._mat_obj is None:
self._mat_obj = materials.Materials(libdfhack.API_getMaterials(self._api_ptr))
return self._mat_obj
@property
def maps(self):
import maps
if self._map_obj is None:
self._map_obj = maps.Maps(libdfhack.API_getMaps(self._api_ptr))
return self._map_obj
@property
def vegetation(self):
import vegetation
if self._veg_obj is None:
self._veg_obj = vegetation.Vegetation(libdfhack.API_getVegetation(self._api_ptr))
return self._veg_obj
@property
def buildings(self):
import buildings
if self._build_obj is None:
self._build_obj = buildings.Buildings(libdfhack.API_getBuildings(self._api_ptr))
return self._build_obj
@property
def creatures(self):
import creatures
if self._creature_obj is None:
self._creature_obj = creatures.Creatures(libdfhack.API_getCreatures(self._api_ptr))
return self._creature_obj
@property
def gui(self):
import gui
if self._gui_obj is None:
self._gui_obj = gui.Gui(libdfhack.API_getGui(self._api_ptr))
return self._gui_obj
@property
def items(self):
import items
if self._item_obj is None:
self._item_obj = items.Items(libdfhack.API_getItems(self._api_ptr))
return self._item_obj
@property
def translation(self):
import translation
if self._tran_obj is None:
self._tran_obj = translation.Translation(libdfhack.API_getTranslation(self._api_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()