Perhaps something like this:
importctypes, numpyaddr=0x401000# exampleaddr_type=ctypes.POINTER(ctypes.c_int*101) # examplepObj=ctypes.cast(addr, addr_type)
obj=pObj.contentsmv=memoryview(obj)
# Optional fix:mv=mv.cast("B", (mv.nbytes,)).cast("i", mv.shape) # because python is being annoying by inserting a unreadable '<' in the formatNow this mv object can be passed to for example numpy to create a by-reference interface to the memory.
arr=numpy.frombuffer(mv2, dtype='int32')
Sourcehold should provide a layerdata_to_matrix(data) -> matrix function for both 400x400 and 800x800
The data argument can be a memoryview, or anything that implements the __buffer__ interface, like a io.BytesIO or a bytearray.
It should work well with the three possible interaction modes:
- File manipulation
- Memory manipulation externally
- Embedded
The snippet above is for embedded use cases, e.g. a game memory pointer is cast.
Since external memory manipulation uses read/write function calls, the with logic should be used for that situation.
layer=shc.getMapLayer(1003) # Returns a ExternalMapLayer objectlayer=game.getMapLayer(1003) # Gets a EmbeddedMapLayerlayer=map.getMapLayer(1003) # Gets a FileMapLayerwithlayer:
m=layer.as_matrix() # Does a read internally via __enter__# do stuff with the 400x400 matrix here# __enter__ and __leave__ are used to do the read and write for ExternalMapLayer
Perhaps something like this:
Now this
mvobject can be passed to for examplenumpyto create a by-reference interface to the memory.Sourcehold should provide a
layerdata_to_matrix(data) -> matrixfunction for both 400x400 and 800x800The
dataargument can be a memoryview, or anything that implements the__buffer__interface, like aio.BytesIOor abytearray.It should work well with the three possible interaction modes:
The snippet above is for embedded use cases, e.g. a game memory pointer is cast.
Since external memory manipulation uses read/write function calls, the
withlogic should be used for that situation.