Fix result issue and add uint32/float reading

This commit is contained in:
Yoshi2 2021-09-16 10:45:03 +02:00
parent f94f231421
commit 95cde0fb31

View file

@ -213,7 +213,7 @@ class Dolphin(object):
size, size,
ctypes.pointer(read)) ctypes.pointer(read))
return result and read == size, buffer return result and read.value == size, buffer
def write_ram(self, offset, data): def write_ram(self, offset, data):
buffer = (ctypes.c_char*len(data))(*data) buffer = (ctypes.c_char*len(data))(*data)
@ -226,7 +226,25 @@ class Dolphin(object):
len(data), len(data),
ctypes.pointer(read)) ctypes.pointer(read))
return result and read == len(data) return result and read.value == len(data)
def read_uint32(self, addr):
assert addr >= 0x80000000
success, value = self.read_ram(addr-0x80000000, 4)
if success:
return struct.unpack(">I", value)[0]
else:
return None
def read_float(self, addr):
assert addr >= 0x80000000
success, value = self.read_ram(addr - 0x80000000, 4)
if success:
return struct.unpack(">f", value)[0]
else:
return None
"""with open("ctypes.txt", "w") as f: """with open("ctypes.txt", "w") as f:
for a in ctypes.__dict__: for a in ctypes.__dict__:
@ -248,10 +266,23 @@ if __name__ == "__main__":
print("We found MEM1 and/or MEM2!", dolphin.address_start, dolphin.mem2_start) print("We found MEM1 and/or MEM2!", dolphin.address_start, dolphin.mem2_start)
else: else:
print("We didn't find it...") print("We didn't find it...")
print(dolphin.write_ram(0, b"GMS")) """print(dolphin.write_ram(0, b"GMS"))
success, result = dolphin.read_ram(0, 8) success, result = dolphin.read_ram(0, 8)
print(result[0:8]) print(result[0:8])
print(dolphin.write_ram(0, b"AWA")) print(dolphin.write_ram(0, b"AWA"))
success, result = dolphin.read_ram(0, 8) success, result = dolphin.read_ram(0, 8)
print(result[0:8]) print(result[0:8])"""
kartctrlPtr = dolphin.read_uint32(0x803CC588)
print(hex(kartctrlPtr))
for i in range(8):
kartPtr = dolphin.read_uint32(kartctrlPtr+0xA0+i*4)
print(hex(kartPtr))
x = dolphin.read_float(kartPtr + 0x23C)
y = dolphin.read_float(kartPtr + 0x240)
z = dolphin.read_float(kartPtr + 0x244)
#self.karts[i].x = x
#self.karts[i].y = y
#self.karts[i].z = z