From bf6d126f8a8809bcda127f5850a53a7b8f9a0829 Mon Sep 17 00:00:00 2001 From: Midorica Date: Tue, 30 May 2023 18:03:52 -0400 Subject: [PATCH] Equipments saving for SAO now completed --- readme.md | 3 ++ titles/sao/base.py | 26 ++++++++--- titles/sao/data/EquipmentLevel.csv | Bin 0 -> 1211 bytes titles/sao/handlers/base.py | 68 ++++++++++++++++++++++------- titles/sao/schema/item.py | 67 +++++++++++++++++++++++++++- titles/sao/schema/static.py | 8 ++++ 6 files changed, 150 insertions(+), 22 deletions(-) create mode 100644 titles/sao/data/EquipmentLevel.csv diff --git a/readme.md b/readme.md index ee407cd..f16010e 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,9 @@ Games listed below have been tested and confirmed working. Only game versions ol + POKKÉN TOURNAMENT + Final Online ++ Sword Art Online Arcade (partial support) + + Final + ## Requirements - python 3 (tested working with 3.9 and 3.10, other versions YMMV) - pip diff --git a/titles/sao/base.py b/titles/sao/base.py index 62fa367..543f488 100644 --- a/titles/sao/base.py +++ b/titles/sao/base.py @@ -81,6 +81,9 @@ class SaoBase: self.game_data.item.put_hero_log(user_id, 102000010, 1, 0, 103000006, 0, 30086, 1001, 1002, 1003, 1005) self.game_data.item.put_hero_log(user_id, 103000010, 1, 0, 112000009, 0, 30086, 1001, 1002, 1003, 1005) self.game_data.item.put_hero_party(user_id, 0, 101000010, 102000010, 103000010) + self.game_data.item.put_equipment_data(user_id, 101000016, 1, 200, 0, 0, 0) + self.game_data.item.put_equipment_data(user_id, 103000006, 1, 200, 0, 0, 0) + self.game_data.item.put_equipment_data(user_id, 112000009, 1, 200, 0, 0, 0) self.logger.info(f"User Authenticated: { access_code } | { user_id }") @@ -145,9 +148,19 @@ class SaoBase: def handle_c602(self, request: Any) -> bytes: #have_object/get_equipment_user_data_list - equipmentIdsData = self.game_data.static.get_equipment_ids(0, True) - - resp = SaoGetEquipmentUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, equipmentIdsData) + req = bytes.fromhex(request)[24:] + req_struct = Struct( + Padding(16), + "user_id_size" / Rebuild(Int32ub, len_(this.user_id) * 2), # calculates the length of the user_id + "user_id" / PaddedString(this.user_id_size, "utf_16_le"), # user_id is a (zero) padded string + + ) + req_data = req_struct.parse(req) + user_id = req_data.user_id + + equipment_data = self.game_data.item.get_user_equipments(user_id) + + resp = SaoGetEquipmentUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, equipment_data) return resp.make() def handle_c604(self, request: Any) -> bytes: @@ -510,10 +523,11 @@ class SaoBase: randomized_unanalyzed_id = choice(data_unanalyzed) heroList = self.game_data.static.get_hero_id(randomized_unanalyzed_id['CommonRewardId']) + equipmentList = self.game_data.static.get_equipment_id(randomized_unanalyzed_id['CommonRewardId']) if heroList: self.game_data.item.put_hero_log(req_data.user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 0, 101000016, 0, 30086, 1001, 1002, 0, 0) - - # Item and Equipments saving will be done later here + if equipmentList: + self.game_data.item.put_equipment_data(req_data.user_id, randomized_unanalyzed_id['CommonRewardId'], 1, 200, 0, 0, 0) # Send response @@ -532,4 +546,4 @@ class SaoBase: def handle_c90a(self, request: Any) -> bytes: #should be tweaked for proper item unlock #quest/episode_play_end_unanalyzed_log_fixed resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) - return resp.make() \ No newline at end of file + return resp.make() diff --git a/titles/sao/data/EquipmentLevel.csv b/titles/sao/data/EquipmentLevel.csv new file mode 100644 index 0000000000000000000000000000000000000000..803bf7ecc486d9815da867869925ceaa34b35706 GIT binary patch literal 1211 zcmX|>OKucF5C!)>%UjepKL_vviIvYlFOUEk1c>AFDj$?LU6YEb=-S%u-@iWJ zetvv@KVLq4!rQ~ikLUHz`%A}Y4KD-hTqf*X7UEnsdOKG`FUZl03iQGfy|~`aCImZo zE3yxaLi@xhwl5698&j}h3U*AvfhjmK3m)y<7k3^VtKh*qEqF|1@Bftxb^N_6}|^o#qY^gePJ)I^bICd!_A1QxS3HMH$$rA zW=gd*I=C?%Mu%z|9m;8RsHf4Pphky^8XZb%bf~G(p{PcOsyZFKWjdS=b#*!v*6C1L zr$cF-4z+bU6xZocU8h5NoeuR4I`}f^2s%_a=uqOILydzDMGiVtIp|R4phKO54uuXn zR66NU>ZC)hlMcmBI#fI9Q0}Bdy^{_FPdZdQ=}_{dL(N%_G0z{5SEJ^=K(sO_kQ4^zaRbrs$1IY literal 0 HcmV?d00001 diff --git a/titles/sao/handlers/base.py b/titles/sao/handlers/base.py index 0c74182..8ed8ba0 100644 --- a/titles/sao/handlers/base.py +++ b/titles/sao/handlers/base.py @@ -660,19 +660,57 @@ class SaoGetEquipmentUserDataListRequest(SaoBaseRequest): super().__init__(data) class SaoGetEquipmentUserDataListResponse(SaoBaseResponse): - def __init__(self, cmd, equipmentIdsData) -> None: + def __init__(self, cmd, equipment_data) -> None: super().__init__(cmd) self.result = 1 + + self.user_equipment_id = [] + self.enhancement_value = [] + self.max_enhancement_value_extended_num = [] + self.enhancement_exp = [] + self.awakening_stage = [] + self.awakening_exp = [] + self.possible_awakening_flag = [] + equipment_level = 0 + + for i in range(len(equipment_data)): + + # Calculate level based off experience and the CSV list + with open(r'titles/sao/data/EquipmentLevel.csv') as csv_file: + csv_reader = csv.reader(csv_file, delimiter=',') + line_count = 0 + data = [] + rowf = False + for row in csv_reader: + if rowf==False: + rowf=True + else: + data.append(row) + + exp = equipment_data[i][4] + + for e in range(0,len(data)): + if exp>=int(data[e][1]) and exp Optional[int]: + sql = insert(equipment_data).values( + user=user_id, + equipment_id=equipment_id, + enhancement_value=enhancement_value, + enhancement_exp=enhancement_exp, + awakening_exp=awakening_exp, + awakening_stage=awakening_stage, + possible_awakening_flag=possible_awakening_flag, + ) + + conflict = sql.on_duplicate_key_update( + enhancement_value=enhancement_value, + enhancement_exp=enhancement_exp, + awakening_exp=awakening_exp, + awakening_stage=awakening_stage, + possible_awakening_flag=possible_awakening_flag, + ) + + result = self.execute(conflict) + if result is None: + self.logger.error( + f"{__name__} failed to insert equipment! user: {user_id}, equipment_id: {equipment_id}" + ) + return None + + return result.lastrowid def put_hero_log(self, user_id: int, user_hero_log_id: int, log_level: int, log_exp: int, main_weapon: int, sub_equipment: int, skill_slot1_skill_id: int, skill_slot2_skill_id: int, skill_slot3_skill_id: int, skill_slot4_skill_id: int, skill_slot5_skill_id: int) -> Optional[int]: sql = insert(hero_log_data).values( @@ -144,6 +192,23 @@ class SaoItemData(BaseData): return None return result.lastrowid + + def get_user_equipments( + self, user_id: int + ) -> Optional[List[Row]]: + """ + A catch-all equipments lookup given a profile + """ + sql = equipment_data.select( + and_( + equipment_data.c.user == user_id, + ) + ) + + result = self.execute(sql) + if result is None: + return None + return result.fetchall() def get_hero_log( self, user_id: int, user_hero_log_id: int = None @@ -167,7 +232,7 @@ class SaoItemData(BaseData): self, user_id: int ) -> Optional[List[Row]]: """ - A catch-all hero lookup given a profile and user_party_team_id and ID specifiers + A catch-all hero lookup given a profile """ sql = hero_log_data.select( and_( diff --git a/titles/sao/schema/static.py b/titles/sao/schema/static.py index ca000b8..2635b5f 100644 --- a/titles/sao/schema/static.py +++ b/titles/sao/schema/static.py @@ -264,6 +264,14 @@ class SaoStaticData(BaseData): return None return [list[2] for list in result.fetchall()] + def get_equipment_id(self, equipmentId: int) -> Optional[Dict]: + sql = equipment.select(equipment.c.equipmentId == equipmentId) + + result = self.execute(sql) + if result is None: + return None + return result.fetchone() + def get_equipment_ids(self, version: int, enabled: bool) -> Optional[List[Dict]]: sql = equipment.select(equipment.c.version == version and equipment.c.enabled == enabled).order_by( equipment.c.equipmentId.asc()