mirror of
https://git.h3cjp.net/H3cJP/citra.git
synced 2024-12-25 04:37:09 +00:00
Merge pull request #4226 from valentinvanelslande/enum
citra.py: use IntEnum for request types
This commit is contained in:
commit
cd20ca0e2a
14
dist/scripting/citra.py
vendored
14
dist/scripting/citra.py
vendored
|
@ -2,12 +2,14 @@ import zmq
|
||||||
import struct
|
import struct
|
||||||
import random
|
import random
|
||||||
import binascii
|
import binascii
|
||||||
|
import enum
|
||||||
|
|
||||||
CURRENT_REQUEST_VERSION = 1
|
CURRENT_REQUEST_VERSION = 1
|
||||||
MAX_REQUEST_DATA_SIZE = 32
|
MAX_REQUEST_DATA_SIZE = 32
|
||||||
|
|
||||||
REQUEST_TYPE_READ_MEMORY = 1
|
class RequestType(enum.IntEnum):
|
||||||
REQUEST_TYPE_WRITE_MEMORY = 2
|
ReadMemory = 1,
|
||||||
|
WriteMemory = 2
|
||||||
|
|
||||||
CITRA_PORT = "45987"
|
CITRA_PORT = "45987"
|
||||||
|
|
||||||
|
@ -42,12 +44,12 @@ class Citra:
|
||||||
while read_size > 0:
|
while read_size > 0:
|
||||||
temp_read_size = min(read_size, MAX_REQUEST_DATA_SIZE)
|
temp_read_size = min(read_size, MAX_REQUEST_DATA_SIZE)
|
||||||
request_data = struct.pack("II", read_address, temp_read_size)
|
request_data = struct.pack("II", read_address, temp_read_size)
|
||||||
request, request_id = self._generate_header(REQUEST_TYPE_READ_MEMORY, len(request_data))
|
request, request_id = self._generate_header(RequestType.ReadMemory, len(request_data))
|
||||||
request += request_data
|
request += request_data
|
||||||
self.socket.send(request)
|
self.socket.send(request)
|
||||||
|
|
||||||
raw_reply = self.socket.recv()
|
raw_reply = self.socket.recv()
|
||||||
reply_data = self._read_and_validate_header(raw_reply, request_id, REQUEST_TYPE_READ_MEMORY)
|
reply_data = self._read_and_validate_header(raw_reply, request_id, RequestType.ReadMemory)
|
||||||
|
|
||||||
if reply_data:
|
if reply_data:
|
||||||
result += reply_data
|
result += reply_data
|
||||||
|
@ -74,12 +76,12 @@ class Citra:
|
||||||
temp_write_size = min(write_size, MAX_REQUEST_DATA_SIZE - 8)
|
temp_write_size = min(write_size, MAX_REQUEST_DATA_SIZE - 8)
|
||||||
request_data = struct.pack("II", write_address, temp_write_size)
|
request_data = struct.pack("II", write_address, temp_write_size)
|
||||||
request_data += write_contents[:temp_write_size]
|
request_data += write_contents[:temp_write_size]
|
||||||
request, request_id = self._generate_header(REQUEST_TYPE_WRITE_MEMORY, len(request_data))
|
request, request_id = self._generate_header(RequestType.WriteMemory, len(request_data))
|
||||||
request += request_data
|
request += request_data
|
||||||
self.socket.send(request)
|
self.socket.send(request)
|
||||||
|
|
||||||
raw_reply = self.socket.recv()
|
raw_reply = self.socket.recv()
|
||||||
reply_data = self._read_and_validate_header(raw_reply, request_id, REQUEST_TYPE_WRITE_MEMORY)
|
reply_data = self._read_and_validate_header(raw_reply, request_id, RequestType.WriteMemory)
|
||||||
|
|
||||||
if None != reply_data:
|
if None != reply_data:
|
||||||
write_address += temp_write_size
|
write_address += temp_write_size
|
||||||
|
|
Loading…
Reference in a new issue