artemis/core/adb_handlers/log.py

83 lines
2.3 KiB
Python
Raw Normal View History

2023-08-20 23:55:26 +00:00
from typing import Final, List
2024-03-22 16:22:07 +00:00
from construct import Int8sl, Padding, Struct
from .base import *
2024-03-22 16:22:07 +00:00
2023-08-20 23:55:26 +00:00
NUM_LOGS: Final[int] = 20
NUM_LEN_LOG_EX: Final[int] = 48
2024-03-22 16:22:07 +00:00
2023-08-20 23:55:26 +00:00
class AmLogEx:
def __init__(self, data: bytes) -> None:
2024-03-22 16:22:07 +00:00
(
self.aime_id,
status,
self.user_id,
self.credit_ct,
self.bet_ct,
self.won_ct,
self.local_time,
self.tseq,
self.place_id,
) = struct.unpack("<IIQiii4xQiI", data)
2023-08-20 23:55:26 +00:00
self.status = LogStatus(status)
2024-03-22 16:22:07 +00:00
class ADBStatusLogRequest(ADBBaseRequest):
def __init__(self, data: bytes) -> None:
super().__init__(data)
self.aime_id, status = struct.unpack_from("<II", data, 0x20)
self.status = LogStatus(status)
2024-03-22 16:22:07 +00:00
class ADBLogRequest(ADBBaseRequest):
def __init__(self, data: bytes) -> None:
super().__init__(data)
2024-03-22 16:22:07 +00:00
self.aime_id, status, self.user_id, self.credit_ct, self.bet_ct, self.won_ct = (
struct.unpack_from("<IIQiii", data, 0x20)
)
self.status = LogStatus(status)
2024-03-22 16:22:07 +00:00
class ADBLogExRequest(ADBBaseRequest):
def __init__(self, data: bytes) -> None:
super().__init__(data)
2023-08-20 23:55:26 +00:00
self.logs: List[AmLogEx] = []
for x in range(NUM_LOGS):
2024-03-22 16:22:07 +00:00
self.logs.append(
AmLogEx(data[0x20 + (NUM_LEN_LOG_EX * x) : 0x50 + (NUM_LEN_LOG_EX * x)])
)
2023-08-20 23:55:26 +00:00
self.num_logs = struct.unpack_from("<I", data, 0x03E0)[0]
2024-03-22 16:22:07 +00:00
2023-08-20 23:55:26 +00:00
class ADBLogExResponse(ADBBaseResponse):
2024-03-22 16:22:07 +00:00
def __init__(
self,
game_id: str = "SXXX",
store_id: int = 1,
keychip_id: str = "A69E01A8888",
protocol_ver: int = 12423,
code: int = 20,
length: int = 64,
status: int = 1,
) -> None:
super().__init__(
code, length, status, game_id, store_id, keychip_id, protocol_ver
)
2023-08-20 23:55:26 +00:00
@classmethod
def from_req(cls, req: ADBHeader) -> "ADBLogExResponse":
c = cls(req.game_id, req.store_id, req.keychip_id, req.protocol_ver)
return c
2024-03-22 16:22:07 +00:00
2023-08-20 23:55:26 +00:00
def make(self) -> bytes:
2024-03-22 16:22:07 +00:00
resp_struct = Struct("log_result" / Int8sl[NUM_LOGS], Padding(12))
2023-08-20 23:55:26 +00:00
2024-03-22 16:22:07 +00:00
body = resp_struct.build(dict(log_result=[1] * NUM_LOGS))
2023-08-20 23:55:26 +00:00
self.head.length = HEADER_SIZE + len(body)
return self.head.make() + body