sao: begin implementing request helpers

This commit is contained in:
Hay1tsme 2023-11-09 23:29:06 -05:00
parent 3d62b9d372
commit 44755d4d0f
4 changed files with 232 additions and 257 deletions

View File

@ -22,71 +22,51 @@ class SaoBase:
self.version = 0 self.version = 0
self.logger = logging.getLogger("sao") self.logger = logging.getLogger("sao")
def handle_noop(self, request: Any) -> bytes: def handle_noop(self, header: SaoRequestHeader, request: bytes) -> bytes:
sao_request = request self.logger.info(f"Using Generic handler")
resp_thing = SaoNoopResponse(header.cmd + 1)
return resp_thing.make()
sao_id = int(sao_request[:4],16) + 1 def handle_c122(self, header: SaoRequestHeader, request: bytes) -> bytes:
ret = struct.pack("!HHIIIIIIb", sao_id, 0, 0, 5, 1, 1, 5, 0x01000000, 0).hex()
return bytes.fromhex(ret)
def handle_c122(self, request: Any) -> bytes:
#common/get_maintenance_info #common/get_maintenance_info
resp = SaoGetMaintResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetMaintResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c12e(self, request: Any) -> bytes: def handle_c12e(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/ac_cabinet_boot_notification #common/ac_cabinet_boot_notification
resp = SaoCommonAcCabinetBootNotificationResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCommonAcCabinetBootNotificationResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c100(self, request: Any) -> bytes: def handle_c100(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/get_app_versions #common/get_app_versions
resp = SaoCommonGetAppVersionsRequest(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCommonGetAppVersionsRequest(header.cmd +1)
return resp.make() return resp.make()
def handle_c102(self, request: Any) -> bytes: def handle_c102(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/master_data_version_check #common/master_data_version_check
resp = SaoMasterDataVersionCheckResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoMasterDataVersionCheckResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c10a(self, request: Any) -> bytes: def handle_c10a(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/paying_play_start #common/paying_play_start
resp = SaoCommonPayingPlayStartRequest(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCommonPayingPlayStartRequest(header.cmd +1)
return resp.make() return resp.make()
def handle_ca02(self, request: Any) -> bytes: def handle_ca02(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest_multi_play_room/get_quest_scene_multi_play_photon_server #quest_multi_play_room/get_quest_scene_multi_play_photon_server
resp = SaoGetQuestSceneMultiPlayPhotonServerResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetQuestSceneMultiPlayPhotonServerResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c11e(self, request: Any) -> bytes: def handle_c11e(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/get_auth_card_data #common/get_auth_card_data
req = bytes.fromhex(request)[24:] req = SaoGetAuthCardDataRequest(header, request)
req_struct = Struct(
Padding(16),
"cabinet_type" / Int8ub, # cabinet_type is a byte
"auth_type" / Int8ub, # auth_type is a byte
"store_id_size" / Rebuild(Int32ub, len_(this.store_id) * 2), # calculates the length of the store_id
"store_id" / PaddedString(this.store_id_size, "utf_16_le"), # store_id is a (zero) padded string
"serial_no_size" / Rebuild(Int32ub, len_(this.serial_no) * 2), # calculates the length of the serial_no
"serial_no" / PaddedString(this.serial_no_size, "utf_16_le"), # serial_no is a (zero) padded string
"access_code_size" / Rebuild(Int32ub, len_(this.access_code) * 2), # calculates the length of the access_code
"access_code" / PaddedString(this.access_code_size, "utf_16_le"), # access_code is a (zero) padded string
"chip_id_size" / Rebuild(Int32ub, len_(this.chip_id) * 2), # calculates the length of the chip_id
"chip_id" / PaddedString(this.chip_id_size, "utf_16_le"), # chip_id is a (zero) padded string
)
req_data = req_struct.parse(req)
access_code = req_data.access_code
#Check authentication #Check authentication
user_id = self.core_data.card.get_user_id_from_card( access_code ) user_id = self.core_data.card.get_user_id_from_card( req.access_code )
if not user_id: if not user_id:
user_id = self.core_data.user.create_user() #works user_id = self.core_data.user.create_user() #works
card_id = self.core_data.card.create_card(user_id, access_code) card_id = self.core_data.card.create_card(user_id, req.access_code)
if card_id is None: if card_id is None:
user_id = -1 user_id = -1
@ -106,7 +86,7 @@ class SaoBase:
# Force the tutorial stage to be completed due to potential crash in-game # Force the tutorial stage to be completed due to potential crash in-game
self.logger.info(f"User Authenticated: { access_code } | { user_id }") self.logger.info(f"User Authenticated: { req.access_code } | { user_id }")
#Grab values from profile #Grab values from profile
profile_data = self.game_data.profile.get_profile(user_id) profile_data = self.game_data.profile.get_profile(user_id)
@ -127,270 +107,168 @@ class SaoBase:
profile_data = self.game_data.profile.get_profile(user_id) profile_data = self.game_data.profile.get_profile(user_id)
resp = SaoGetAuthCardDataResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data) resp = SaoGetAuthCardDataResponse(header.cmd +1, profile_data)
return resp.make() return resp.make()
def handle_c40c(self, request: Any) -> bytes: def handle_c40c(self, header: SaoRequestHeader, request: bytes) -> bytes:
#home/check_ac_login_bonus #home/check_ac_login_bonus
resp = SaoHomeCheckAcLoginBonusResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoHomeCheckAcLoginBonusResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c104(self, request: Any) -> bytes: def handle_c104(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/login #common/login
req = bytes.fromhex(request)[24:] req = SaoCommonLoginRequest(header, request)
req_struct = Struct( user_id = self.core_data.card.get_user_id_from_card( req.access_code )
Padding(16),
"cabinet_type" / Int8ub, # cabinet_type is a byte
"auth_type" / Int8ub, # auth_type is a byte
"store_id_size" / Rebuild(Int32ub, len_(this.store_id) * 2), # calculates the length of the store_id
"store_id" / PaddedString(this.store_id_size, "utf_16_le"), # store_id is a (zero) padded string
"store_name_size" / Rebuild(Int32ub, len_(this.store_name) * 2), # calculates the length of the store_name
"store_name" / PaddedString(this.store_name_size, "utf_16_le"), # store_name is a (zero) padded string
"serial_no_size" / Rebuild(Int32ub, len_(this.serial_no) * 2), # calculates the length of the serial_no
"serial_no" / PaddedString(this.serial_no_size, "utf_16_le"), # serial_no is a (zero) padded string
"access_code_size" / Rebuild(Int32ub, len_(this.access_code) * 2), # calculates the length of the access_code
"access_code" / PaddedString(this.access_code_size, "utf_16_le"), # access_code is a (zero) padded string
"chip_id_size" / Rebuild(Int32ub, len_(this.chip_id) * 2), # calculates the length of the chip_id
"chip_id" / PaddedString(this.chip_id_size, "utf_16_le"), # chip_id is a (zero) padded string
"free_ticket_distribution_target_flag" / Int8ub, # free_ticket_distribution_target_flag is a byte
)
req_data = req_struct.parse(req)
access_code = req_data.access_code
user_id = self.core_data.card.get_user_id_from_card( access_code )
profile_data = self.game_data.profile.get_profile(user_id) profile_data = self.game_data.profile.get_profile(user_id)
resp = SaoCommonLoginResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data) resp = SaoCommonLoginResponse(header.cmd +1, profile_data)
return resp.make() return resp.make()
def handle_c404(self, request: Any) -> bytes: def handle_c404(self, header: SaoRequestHeader, request: bytes) -> bytes:
#home/check_comeback_event #home/check_comeback_event
resp = SaoCheckComebackEventRequest(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCheckComebackEventRequest(header.cmd +1)
return resp.make() return resp.make()
def handle_c000(self, request: Any) -> bytes: def handle_c000(self, header: SaoRequestHeader, request: bytes) -> bytes:
#ticket/ticket #ticket/ticket
resp = SaoTicketResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoTicketResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c500(self, request: Any) -> bytes: def handle_c500(self, header: SaoRequestHeader, request: bytes) -> bytes:
#user_info/get_user_basic_data #user_info/get_user_basic_data
req = bytes.fromhex(request)[24:] req = SaoGetUserBasicDataRequest(header, request)
req_struct = Struct( profile_data = self.game_data.profile.get_profile(req.user_id)
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) resp = SaoGetUserBasicDataResponse(header.cmd +1, profile_data)
user_id = req_data.user_id
profile_data = self.game_data.profile.get_profile(user_id)
resp = SaoGetUserBasicDataResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data)
return resp.make() return resp.make()
def handle_c600(self, request: Any) -> bytes: def handle_c600(self, header: SaoRequestHeader, request: bytes) -> bytes:
#have_object/get_hero_log_user_data_list #have_object/get_hero_log_user_data_list
req = bytes.fromhex(request)[24:] req = SaoGetHeroLogUserDataListRequest(header, request)
req_struct = Struct( hero_data = self.game_data.item.get_hero_logs(req.user_id)
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
) resp = SaoGetHeroLogUserDataListResponse(header.cmd +1, hero_data)
req_data = req_struct.parse(req)
user_id = req_data.user_id
hero_data = self.game_data.item.get_hero_logs(user_id)
resp = SaoGetHeroLogUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, hero_data)
return resp.make() return resp.make()
def handle_c602(self, request: Any) -> bytes: def handle_c602(self, header: SaoRequestHeader, request: bytes) -> bytes:
#have_object/get_equipment_user_data_list #have_object/get_equipment_user_data_list
req = bytes.fromhex(request)[24:] req = SaoGetEquipmentUserDataListRequest(header, request)
req_struct = Struct( equipment_data = self.game_data.item.get_user_equipments(req.user_id)
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
) resp = SaoGetEquipmentUserDataListResponse(header.cmd +1, equipment_data)
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() return resp.make()
def handle_c604(self, request: Any) -> bytes: def handle_c604(self, header: SaoRequestHeader, request: bytes) -> bytes:
#have_object/get_item_user_data_list #have_object/get_item_user_data_list
req = bytes.fromhex(request)[24:] req = SaoGetItemUserDataListRequest(header, request)
req_struct = Struct( item_data = self.game_data.item.get_user_items(req.user_id)
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
) resp = SaoGetItemUserDataListResponse(header.cmd +1, item_data)
req_data = req_struct.parse(req)
user_id = req_data.user_id
item_data = self.game_data.item.get_user_items(user_id)
resp = SaoGetItemUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, item_data)
return resp.make() return resp.make()
def handle_c606(self, request: Any) -> bytes: def handle_c606(self, header: SaoRequestHeader, request: bytes) -> bytes:
#have_object/get_support_log_user_data_list #have_object/get_support_log_user_data_list
supportIdsData = self.game_data.static.get_support_log_ids(0, True) supportIdsData = self.game_data.static.get_support_log_ids(0, True)
resp = SaoGetSupportLogUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, supportIdsData) resp = SaoGetSupportLogUserDataListResponse(header.cmd +1, supportIdsData)
return resp.make() return resp.make()
def handle_c800(self, request: Any) -> bytes: def handle_c800(self, header: SaoRequestHeader, request: bytes) -> bytes:
#custom/get_title_user_data_list #custom/get_title_user_data_list
titleIdsData = self.game_data.static.get_title_ids(0, True) titleIdsData = self.game_data.static.get_title_ids(0, True)
resp = SaoGetTitleUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, titleIdsData) resp = SaoGetTitleUserDataListResponse(header.cmd +1, titleIdsData)
return resp.make() return resp.make()
def handle_c608(self, request: Any) -> bytes: def handle_c608(self, header: SaoRequestHeader, request: bytes) -> bytes:
#have_object/get_episode_append_data_list #have_object/get_episode_append_data_list
req = bytes.fromhex(request)[24:] req = SaoGetEpisodeAppendDataListRequest(header, request)
req_struct = Struct( profile_data = self.game_data.profile.get_profile(req.user_id)
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) resp = SaoGetEpisodeAppendDataListResponse(header.cmd +1, profile_data)
user_id = req_data.user_id
profile_data = self.game_data.profile.get_profile(user_id)
resp = SaoGetEpisodeAppendDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data)
return resp.make() return resp.make()
def handle_c804(self, request: Any) -> bytes: def handle_c804(self, header: SaoRequestHeader, request: bytes) -> bytes:
#custom/get_party_data_list #custom/get_party_data_list
req = bytes.fromhex(request)[24:] req = SaoGetPartyDataListRequest(header, request)
req_struct = Struct( hero_party = self.game_data.item.get_hero_party(req.user_id, 0)
Padding(16), hero1_data = self.game_data.item.get_hero_log(req.user_id, hero_party[3])
"user_id_size" / Rebuild(Int32ub, len_(this.user_id) * 2), # calculates the length of the user_id hero2_data = self.game_data.item.get_hero_log(req.user_id, hero_party[4])
"user_id" / PaddedString(this.user_id_size, "utf_16_le"), # user_id is a (zero) padded string hero3_data = self.game_data.item.get_hero_log(req.user_id, hero_party[5])
) resp = SaoGetPartyDataListResponse(header.cmd +1, hero1_data, hero2_data, hero3_data)
req_data = req_struct.parse(req)
user_id = req_data.user_id
hero_party = self.game_data.item.get_hero_party(user_id, 0)
hero1_data = self.game_data.item.get_hero_log(user_id, hero_party[3])
hero2_data = self.game_data.item.get_hero_log(user_id, hero_party[4])
hero3_data = self.game_data.item.get_hero_log(user_id, hero_party[5])
resp = SaoGetPartyDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, hero1_data, hero2_data, hero3_data)
return resp.make() return resp.make()
def handle_c902(self, request: Any) -> bytes: # for whatever reason, having all entries empty or filled changes nothing def handle_c902(self, header: SaoRequestHeader, request: bytes) -> bytes: # for whatever reason, having all entries empty or filled changes nothing
#quest/get_quest_scene_prev_scan_profile_card #quest/get_quest_scene_prev_scan_profile_card
resp = SaoGetQuestScenePrevScanProfileCardResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetQuestScenePrevScanProfileCardResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c124(self, request: Any) -> bytes: def handle_c124(self, header: SaoRequestHeader, request: bytes) -> bytes:
#common/get_resource_path_info #common/get_resource_path_info
resp = SaoGetResourcePathInfoResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetResourcePathInfoResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c900(self, request: Any) -> bytes: def handle_c900(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest/get_quest_scene_user_data_list // QuestScene.csv #quest/get_quest_scene_user_data_list // QuestScene.csv
req = bytes.fromhex(request)[24:] req = SaoGetQuestSceneUserDataListRequest(header, request)
req_struct = Struct( quest_data = self.game_data.item.get_quest_logs(req.user_id)
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
) resp = SaoGetQuestSceneUserDataListResponse(header.cmd +1, quest_data)
req_data = req_struct.parse(req)
user_id = req_data.user_id
quest_data = self.game_data.item.get_quest_logs(user_id)
resp = SaoGetQuestSceneUserDataListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, quest_data)
return resp.make() return resp.make()
def handle_c400(self, request: Any) -> bytes: def handle_c400(self, header: SaoRequestHeader, request: bytes) -> bytes:
#home/check_yui_medal_get_condition #home/check_yui_medal_get_condition
resp = SaoCheckYuiMedalGetConditionResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCheckYuiMedalGetConditionResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c402(self, request: Any) -> bytes: def handle_c402(self, header: SaoRequestHeader, request: bytes) -> bytes:
#home/get_yui_medal_bonus_user_data #home/get_yui_medal_bonus_user_data
resp = SaoGetYuiMedalBonusUserDataResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetYuiMedalBonusUserDataResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c40a(self, request: Any) -> bytes: def handle_c40a(self, header: SaoRequestHeader, request: bytes) -> bytes:
#home/check_profile_card_used_reward #home/check_profile_card_used_reward
resp = SaoCheckProfileCardUsedRewardResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoCheckProfileCardUsedRewardResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c814(self, request: Any) -> bytes: def handle_c814(self, header: SaoRequestHeader, request: bytes) -> bytes:
#custom/synthesize_enhancement_hero_log #custom/synthesize_enhancement_hero_log
req = bytes.fromhex(request)[24:] req = SaoSynthesizeEnhancementHeroLogRequest(header, request)
req_struct = Struct( synthesize_hero_log_data = self.game_data.item.get_hero_log(req.user_id, req.origin_user_hero_log_id)
Padding(20),
"ticket_id" / Bytes(1), # needs to be parsed as an int
Padding(1),
"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
"origin_user_hero_log_id_size" / Rebuild(Int32ub, len_(this.origin_user_hero_log_id) * 2), # calculates the length of the origin_user_hero_log_id
"origin_user_hero_log_id" / PaddedString(this.origin_user_hero_log_id_size, "utf_16_le"), # origin_user_hero_log_id is a (zero) padded string
Padding(3),
"material_common_reward_user_data_list_length" / Rebuild(Int8ub, len_(this.material_common_reward_user_data_list)), # material_common_reward_user_data_list is a byte,
"material_common_reward_user_data_list" / Array(this.material_common_reward_user_data_list_length, Struct(
"common_reward_type" / Int16ub, # team_no is a byte
"user_common_reward_id_size" / Rebuild(Int32ub, len_(this.user_common_reward_id) * 2), # calculates the length of the user_common_reward_id
"user_common_reward_id" / PaddedString(this.user_common_reward_id_size, "utf_16_le"), # user_common_reward_id is a (zero) padded string
)),
)
req_data = req_struct.parse(req) for i in range(req.material_common_reward_user_data_count):
user_id = req_data.user_id
synthesize_hero_log_data = self.game_data.item.get_hero_log(req_data.user_id, req_data.origin_user_hero_log_id)
for i in range(0,req_data.material_common_reward_user_data_list_length): itemList = self.game_data.static.get_item_id(req.material_common_reward_user_data_list[i].user_common_reward_id)
heroList = self.game_data.static.get_hero_id(req.material_common_reward_user_data_list[i].user_common_reward_id)
itemList = self.game_data.static.get_item_id(req_data.material_common_reward_user_data_list[i].user_common_reward_id) equipmentList = self.game_data.static.get_equipment_id(req.material_common_reward_user_data_list[i].user_common_reward_id)
heroList = self.game_data.static.get_hero_id(req_data.material_common_reward_user_data_list[i].user_common_reward_id)
equipmentList = self.game_data.static.get_equipment_id(req_data.material_common_reward_user_data_list[i].user_common_reward_id)
if itemList: if itemList:
hero_exp = 2000 + int(synthesize_hero_log_data["log_exp"]) hero_exp = 2000 + int(synthesize_hero_log_data["log_exp"])
self.game_data.item.remove_item(req_data.user_id, req_data.material_common_reward_user_data_list[i].user_common_reward_id) self.game_data.item.remove_item(req.user_id, req.material_common_reward_user_data_list[i].user_common_reward_id)
if equipmentList: if equipmentList:
equipment_data = self.game_data.item.get_user_equipment(req_data.user_id, req_data.material_common_reward_user_data_list[i].user_common_reward_id) equipment_data = self.game_data.item.get_user_equipment(req.user_id, req.material_common_reward_user_data_list[i].user_common_reward_id)
hero_exp = int(equipment_data["enhancement_exp"]) + int(synthesize_hero_log_data["log_exp"]) hero_exp = int(equipment_data["enhancement_exp"]) + int(synthesize_hero_log_data["log_exp"])
self.game_data.item.remove_equipment(req_data.user_id, req_data.material_common_reward_user_data_list[i].user_common_reward_id) self.game_data.item.remove_equipment(req.user_id, req.material_common_reward_user_data_list[i].user_common_reward_id)
if heroList: if heroList:
hero_data = self.game_data.item.get_hero_log(req_data.user_id, req_data.material_common_reward_user_data_list[i].user_common_reward_id) hero_data = self.game_data.item.get_hero_log(req.user_id, req.material_common_reward_user_data_list[i].user_common_reward_id)
hero_exp = int(hero_data["log_exp"]) + int(synthesize_hero_log_data["log_exp"]) hero_exp = int(hero_data["log_exp"]) + int(synthesize_hero_log_data["log_exp"])
self.game_data.item.remove_hero_log(req_data.user_id, req_data.material_common_reward_user_data_list[i].user_common_reward_id) self.game_data.item.remove_hero_log(req.user_id, req.material_common_reward_user_data_list[i].user_common_reward_id)
self.game_data.item.put_hero_log( self.game_data.item.put_hero_log(
user_id, req.user_id,
int(req_data.origin_user_hero_log_id), int(req.origin_user_hero_log_id),
synthesize_hero_log_data["log_level"], synthesize_hero_log_data["log_level"],
hero_exp, hero_exp,
synthesize_hero_log_data["main_weapon"], synthesize_hero_log_data["main_weapon"],
@ -402,13 +280,13 @@ class SaoBase:
synthesize_hero_log_data["skill_slot5_skill_id"] synthesize_hero_log_data["skill_slot5_skill_id"]
) )
profile = self.game_data.profile.get_profile(req_data.user_id) profile = self.game_data.profile.get_profile(req.user_id)
new_col = int(profile["own_col"]) - 100 new_col = int(profile["own_col"]) - 100
# Update profile # Update profile
self.game_data.profile.put_profile( self.game_data.profile.put_profile(
req_data.user_id, req.user_id,
profile["user_type"], profile["user_type"],
profile["nick_name"], profile["nick_name"],
profile["rank_num"], profile["rank_num"],
@ -420,12 +298,12 @@ class SaoBase:
) )
# Load the item again to push to the response handler # Load the item again to push to the response handler
synthesize_hero_log_data = self.game_data.item.get_hero_log(req_data.user_id, req_data.origin_user_hero_log_id) synthesize_hero_log_data = self.game_data.item.get_hero_log(req.user_id, req.origin_user_hero_log_id)
resp = SaoSynthesizeEnhancementHeroLogResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, synthesize_hero_log_data) resp = SaoSynthesizeEnhancementHeroLogResponse(header.cmd +1, synthesize_hero_log_data)
return resp.make() return resp.make()
def handle_c816(self, request: Any) -> bytes: def handle_c816(self, header: SaoRequestHeader, request: bytes) -> bytes:
#custom/synthesize_enhancement_equipment #custom/synthesize_enhancement_equipment
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -493,10 +371,10 @@ class SaoBase:
# Load the item again to push to the response handler # Load the item again to push to the response handler
synthesize_equipment_data = self.game_data.item.get_user_equipment(req_data.user_id, req_data.origin_user_equipment_id) synthesize_equipment_data = self.game_data.item.get_user_equipment(req_data.user_id, req_data.origin_user_equipment_id)
resp = SaoSynthesizeEnhancementEquipmentResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, synthesize_equipment_data) resp = SaoSynthesizeEnhancementEquipmentResponse(header.cmd +1, synthesize_equipment_data)
return resp.make() return resp.make()
def handle_c806(self, request: Any) -> bytes: def handle_c806(self, header: SaoRequestHeader, request: bytes) -> bytes:
#custom/change_party #custom/change_party
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -566,10 +444,10 @@ class SaoBase:
self.game_data.item.put_hero_party(user_id, req_data.party_data_list[0].party_team_data_list[0].user_party_team_id, party_hero_list[0], party_hero_list[1], party_hero_list[2]) self.game_data.item.put_hero_party(user_id, req_data.party_data_list[0].party_team_data_list[0].user_party_team_id, party_hero_list[0], party_hero_list[1], party_hero_list[2])
resp = SaoNoopResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoNoopResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c904(self, request: Any) -> bytes: def handle_c904(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest/episode_play_start #quest/episode_play_start
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -608,10 +486,10 @@ class SaoBase:
req_data.play_start_request_data[0].quest_drop_boost_apply_flag req_data.play_start_request_data[0].quest_drop_boost_apply_flag
) )
resp = SaoEpisodePlayStartResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data) resp = SaoEpisodePlayStartResponse(header.cmd +1, profile_data)
return resp.make() return resp.make()
def handle_c908(self, request: Any) -> bytes: # Level calculation missing for the profile and heroes def handle_c908(self, header: SaoRequestHeader, request: bytes) -> bytes: # Level calculation missing for the profile and heroes
#quest/episode_play_end #quest/episode_play_end
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -859,10 +737,10 @@ class SaoBase:
self.game_data.item.create_end_session(user_id, episode_id, quest_clear_flag, json_data["data"]) self.game_data.item.create_end_session(user_id, episode_id, quest_clear_flag, json_data["data"])
resp = SaoEpisodePlayEndResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoEpisodePlayEndResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c914(self, request: Any) -> bytes: def handle_c914(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest/trial_tower_play_start #quest/trial_tower_play_start
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -901,10 +779,10 @@ class SaoBase:
req_data.play_start_request_data[0].quest_drop_boost_apply_flag req_data.play_start_request_data[0].quest_drop_boost_apply_flag
) )
resp = SaoEpisodePlayStartResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, profile_data) resp = SaoEpisodePlayStartResponse(header.cmd +1, profile_data)
return resp.make() return resp.make()
def handle_c918(self, request: Any) -> bytes: def handle_c918(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest/trial_tower_play_end #quest/trial_tower_play_end
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -1169,10 +1047,10 @@ class SaoBase:
self.game_data.item.create_end_session(user_id, trial_tower_id, quest_clear_flag, json_data["data"]) self.game_data.item.create_end_session(user_id, trial_tower_id, quest_clear_flag, json_data["data"])
resp = SaoTrialTowerPlayEndResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoTrialTowerPlayEndResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c90a(self, request: Any) -> bytes: def handle_c90a(self, header: SaoRequestHeader, request: bytes) -> bytes:
#quest/episode_play_end_unanalyzed_log_fixed #quest/episode_play_end_unanalyzed_log_fixed
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -1190,10 +1068,10 @@ class SaoBase:
end_session_data = self.game_data.item.get_end_session(user_id) end_session_data = self.game_data.item.get_end_session(user_id)
resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, end_session_data[4]) resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(header.cmd +1, end_session_data[4])
return resp.make() return resp.make()
def handle_c91a(self, request: Any) -> bytes: # handler is identical to the episode def handle_c91a(self, header: SaoRequestHeader, request: bytes) -> bytes: # handler is identical to the episode
#quest/trial_tower_play_end_unanalyzed_log_fixed #quest/trial_tower_play_end_unanalyzed_log_fixed
req = bytes.fromhex(request)[24:] req = bytes.fromhex(request)[24:]
@ -1210,35 +1088,35 @@ class SaoBase:
end_session_data = self.game_data.item.get_end_session(user_id) end_session_data = self.game_data.item.get_end_session(user_id)
resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1, end_session_data[4]) resp = SaoEpisodePlayEndUnanalyzedLogFixedResponse(header.cmd +1, end_session_data[4])
return resp.make() return resp.make()
def handle_cd00(self, request: Any) -> bytes: def handle_cd00(self, header: SaoRequestHeader, request: bytes) -> bytes:
#defrag_match/get_defrag_match_basic_data #defrag_match/get_defrag_match_basic_data
resp = SaoGetDefragMatchBasicDataResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetDefragMatchBasicDataResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_cd02(self, request: Any) -> bytes: def handle_cd02(self, header: SaoRequestHeader, request: bytes) -> bytes:
#defrag_match/get_defrag_match_ranking_user_data #defrag_match/get_defrag_match_ranking_user_data
resp = SaoGetDefragMatchRankingUserDataResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetDefragMatchRankingUserDataResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_cd04(self, request: Any) -> bytes: def handle_cd04(self, header: SaoRequestHeader, request: bytes) -> bytes:
#defrag_match/get_defrag_match_league_point_ranking_list #defrag_match/get_defrag_match_league_point_ranking_list
resp = SaoGetDefragMatchLeaguePointRankingListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetDefragMatchLeaguePointRankingListResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_cd06(self, request: Any) -> bytes: def handle_cd06(self, header: SaoRequestHeader, request: bytes) -> bytes:
#defrag_match/get_defrag_match_league_score_ranking_list #defrag_match/get_defrag_match_league_score_ranking_list
resp = SaoGetDefragMatchLeagueScoreRankingListResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoGetDefragMatchLeagueScoreRankingListResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_d404(self, request: Any) -> bytes: def handle_d404(self, header: SaoRequestHeader, request: bytes) -> bytes:
#other/bnid_serial_code_check #other/bnid_serial_code_check
resp = SaoBnidSerialCodeCheckResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoBnidSerialCodeCheckResponse(header.cmd +1)
return resp.make() return resp.make()
def handle_c306(self, request: Any) -> bytes: def handle_c306(self, header: SaoRequestHeader, request: bytes) -> bytes:
#card/scan_qr_quest_profile_card #card/scan_qr_quest_profile_card
resp = SaoScanQrQuestProfileCardResponse(int.from_bytes(bytes.fromhex(request[:4]), "big")+1) resp = SaoScanQrQuestProfileCardResponse(header.cmd +1)
return resp.make() return resp.make()

View File

@ -1,5 +1,6 @@
import struct import struct
from datetime import datetime from datetime import datetime
from typing import List
from construct import * from construct import *
from .helpers import * from .helpers import *
import csv import csv
@ -202,6 +203,28 @@ class SaoCommonPayingPlayStartRequest(SaoBaseResponse):
class SaoGetAuthCardDataRequest(SaoBaseRequest): class SaoGetAuthCardDataRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
off = 0
self.cabinet_type = decode_byte(data, off)
off += BYTE_OFF
self.auth_type = decode_byte(data, off)
off += BYTE_OFF
store_id = decode_str(data, off)
self.store_id = store_id[0]
off += store_id[1]
serial_no = decode_str(data, off)
self.serial_no = serial_no[0]
off += serial_no[1]
access_code = decode_str(data, off)
self.access_code = access_code[0]
off += access_code[1]
chip_id = decode_str(data, off)
self.chip_id = chip_id[0]
off += chip_id[1]
class SaoGetAuthCardDataResponse(SaoBaseResponse): #GssSite.dll / GssSiteSystem / GameConnectProt / public class get_auth_card_data_R : GameConnect.GssProtocolBase class SaoGetAuthCardDataResponse(SaoBaseResponse): #GssSite.dll / GssSiteSystem / GameConnectProt / public class get_auth_card_data_R : GameConnect.GssProtocolBase
def __init__(self, cmd, profile_data) -> None: def __init__(self, cmd, profile_data) -> None:
@ -339,6 +362,35 @@ class SaoTicketResponse(SaoBaseResponse):
class SaoCommonLoginRequest(SaoBaseRequest): class SaoCommonLoginRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
off = 0
self.cabinet_type = decode_byte(data, off)
off += BYTE_OFF
self.auth_type = decode_byte(data, off)
off += BYTE_OFF
store_id = decode_str(data, off)
self.store_id = store_id[0]
off += store_id[1]
store_name = decode_str(data, off)
self.store_name = store_name[0]
off += store_name[1]
serial_no = decode_str(data, off)
self.serial_no = serial_no[0]
off += serial_no[1]
access_code = decode_str(data, off)
self.access_code = access_code[0]
off += access_code[1]
chip_id = decode_str(data, off)
self.chip_id = chip_id[0]
off += chip_id[1]
self.free_ticket_distribution_target_flag = decode_byte(data, off)
off += BYTE_OFF
class SaoCommonLoginResponse(SaoBaseResponse): class SaoCommonLoginResponse(SaoBaseResponse):
def __init__(self, cmd, profile_data) -> None: def __init__(self, cmd, profile_data) -> None:
@ -413,6 +465,7 @@ class SaoCheckComebackEventRequest(SaoBaseResponse):
class SaoGetUserBasicDataRequest(SaoBaseRequest): class SaoGetUserBasicDataRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetUserBasicDataResponse(SaoBaseResponse): class SaoGetUserBasicDataResponse(SaoBaseResponse):
def __init__(self, cmd, profile_data) -> None: def __init__(self, cmd, profile_data) -> None:
@ -497,6 +550,7 @@ class SaoGetUserBasicDataResponse(SaoBaseResponse):
class SaoGetHeroLogUserDataListRequest(SaoBaseRequest): class SaoGetHeroLogUserDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetHeroLogUserDataListResponse(SaoBaseResponse): class SaoGetHeroLogUserDataListResponse(SaoBaseResponse):
def __init__(self, cmd, hero_data) -> None: def __init__(self, cmd, hero_data) -> None:
@ -675,6 +729,7 @@ class SaoGetHeroLogUserDataListResponse(SaoBaseResponse):
class SaoGetEquipmentUserDataListRequest(SaoBaseRequest): class SaoGetEquipmentUserDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetEquipmentUserDataListResponse(SaoBaseResponse): class SaoGetEquipmentUserDataListResponse(SaoBaseResponse):
def __init__(self, cmd, equipment_data) -> None: def __init__(self, cmd, equipment_data) -> None:
@ -831,6 +886,7 @@ class SaoGetEquipmentUserDataListResponse(SaoBaseResponse):
class SaoGetItemUserDataListRequest(SaoBaseRequest): class SaoGetItemUserDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetItemUserDataListResponse(SaoBaseResponse): class SaoGetItemUserDataListResponse(SaoBaseResponse):
def __init__(self, cmd, item_data) -> None: def __init__(self, cmd, item_data) -> None:
@ -1014,6 +1070,7 @@ class SaoGetTitleUserDataListResponse(SaoBaseResponse):
class SaoGetEpisodeAppendDataListRequest(SaoBaseRequest): class SaoGetEpisodeAppendDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetEpisodeAppendDataListResponse(SaoBaseResponse): class SaoGetEpisodeAppendDataListResponse(SaoBaseResponse):
def __init__(self, cmd, profile_data) -> None: def __init__(self, cmd, profile_data) -> None:
@ -1072,6 +1129,7 @@ class SaoGetEpisodeAppendDataListResponse(SaoBaseResponse):
class SaoGetPartyDataListRequest(SaoBaseRequest): class SaoGetPartyDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetPartyDataListResponse(SaoBaseResponse): # Default party class SaoGetPartyDataListResponse(SaoBaseResponse): # Default party
def __init__(self, cmd, hero1_data, hero2_data, hero3_data) -> None: def __init__(self, cmd, hero1_data, hero2_data, hero3_data) -> None:
@ -1756,6 +1814,7 @@ class SaoEpisodePlayEndUnanalyzedLogFixedResponse(SaoBaseResponse):
class SaoGetQuestSceneUserDataListRequest(SaoBaseRequest): class SaoGetQuestSceneUserDataListRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
self.user_id = decode_str(data, 0)[0]
class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse): class SaoGetQuestSceneUserDataListResponse(SaoBaseResponse):
def __init__(self, cmd, quest_data) -> None: def __init__(self, cmd, quest_data) -> None:
@ -1973,6 +2032,34 @@ class SaoCheckProfileCardUsedRewardResponse(SaoBaseResponse):
class SaoSynthesizeEnhancementHeroLogRequest(SaoBaseRequest): class SaoSynthesizeEnhancementHeroLogRequest(SaoBaseRequest):
def __init__(self, header: SaoRequestHeader, data: bytes) -> None: def __init__(self, header: SaoRequestHeader, data: bytes) -> None:
super().__init__(header, data) super().__init__(header, data)
off = 0
ticket_id = decode_str(data, 0)
self.ticket_id = ticket_id[0]
off += ticket_id[1]
user_id = decode_str(data, 0)
self.user_id = user_id[0]
off += user_id[1]
origin_user_hero_log_id = decode_str(data, 0)
self.origin_user_hero_log_id = origin_user_hero_log_id[0]
off += origin_user_hero_log_id[1]
self.material_common_reward_user_data_list: List[MaterialCommonRewardUserData]
if len(data) <= off:
self.material_common_reward_user_data_count = 0
return
self.material_common_reward_user_data_count = decode_int(data, off)
off += INT_OFF
for _ in range(self.material_common_reward_user_data_count):
mat = MaterialCommonRewardUserData(data, off)
off += mat.get_size()
self.material_common_reward_user_data_list.append(mat)
class SaoSynthesizeEnhancementHeroLogResponse(SaoBaseResponse): class SaoSynthesizeEnhancementHeroLogResponse(SaoBaseResponse):
def __init__(self, cmd, hero_data) -> None: def __init__(self, cmd, hero_data) -> None:

View File

@ -48,3 +48,20 @@ def encode_str(s: str) -> bytes:
except: except:
logging.getLogger('sao').error(f"Failed to encode {s} as bytes!") logging.getLogger('sao').error(f"Failed to encode {s} as bytes!")
return b"" return b""
class BaseHelper:
def __init__(self, data: bytes, offset: int) -> None:
pass
def get_size(self) -> int:
return 0
class MaterialCommonRewardUserData(BaseHelper):
def __init__(self, data: bytes, offset: int) -> None:
self.common_reward_type = decode_short(data, offset)
offset += SHORT_OFF
self.user_common_reward_id = decode_short(data, offset)
def get_size(self) -> int:
return SHORT_OFF + SHORT_OFF

View File

@ -113,17 +113,10 @@ class SaoServlet(BaseServlet):
else: else:
req_data = req_raw[40:] req_data = req_raw[40:]
handler = getattr(self.base, f"handle_{cmd_str}", None) handler = getattr(self.base, f"handle_{cmd_str}", self.base.handle_noop)
if handler is None: self.logger.info(f"{endpoint} - {cmd_str} request")
self.logger.info(f"Generic Handler for {endpoint} - {cmd_str}")
self.logger.debug(f"Request: {req_raw.hex()}") self.logger.debug(f"Request: {req_raw.hex()}")
resp_thing = SaoNoopResponse(req_header.cmd + 1) resp = handler(req_header, req_data)
resp = resp_thing.make()
else:
self.logger.info(f"Handler {endpoint} - {cmd_str} request")
self.logger.debug(f"Request: {req_raw.hex()}")
resp = handler(sao_request)
self.logger.debug(f"Response: {resp.hex()}") self.logger.debug(f"Response: {resp.hex()}")