From 9c49a4f54aa543d3e0bbe24f2e26a372aaefe34a Mon Sep 17 00:00:00 2001 From: Hay1tsme Date: Tue, 14 Nov 2023 21:07:58 -0500 Subject: [PATCH] sao: fix get_m_res_earn_campaign_shops --- titles/sao/base.py | 22 ++++++++++++-- titles/sao/handlers/base.py | 18 +++++++++++ titles/sao/handlers/helpers.py | 55 ++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/titles/sao/base.py b/titles/sao/base.py index 8d8cfb0..3cec6d2 100644 --- a/titles/sao/base.py +++ b/titles/sao/base.py @@ -939,9 +939,27 @@ class SaoBase: resp.data_list.append(tmp) - self.logger.debug(f"Load {len(resp.data_list)} Yui Medal Shop Items") + self.logger.debug(f"Load {len(resp.data_list)} Gasha Medal Shops") return resp.make() def handle_d604(self, header: SaoRequestHeader, request: bytes) -> bytes: # master_data_2/get_m_res_earn_campaign_shops - return SaoNoopResponse(header.cmd + 1).make() \ No newline at end of file + req = GetMResEarnCampaignShopsRequest(header, request) + resp = GetMResEarnCampaignShopsResponse(header.cmd + 1) + + shops = self.load_data_csv("ResEarnCampaignShops") + for shop in shops: + tmp = ResEarnCampaignShop.from_args(shop['ResEarnCampaignShopId'], shop['ResEarnCampaignApplicationId'], shop['Name']) + tmp.selling_yui_medal = shop['SellingYuiMedal'] + tmp.selling_col = shop['SellingCol'] + tmp.selling_event_item_id = shop['SellingEventItemId'] + tmp.selling_event_item_num = shop['SellingEventItemNum'] + tmp.purchase_limit = shop['PurchaseLimit'] + tmp.get_application_point = shop['GetApplicationPoint'] + + tmp.sales_end_date = datetime(2100, 1, 1, 0, 0, 0, 0) # always open + + resp.data_list.append(tmp) + + self.logger.debug(f"Load {len(resp.data_list)} Res Earn Campaign Shops") + return resp.make() diff --git a/titles/sao/handlers/base.py b/titles/sao/handlers/base.py index 3b7e17a..4178640 100644 --- a/titles/sao/handlers/base.py +++ b/titles/sao/handlers/base.py @@ -3212,3 +3212,21 @@ class GetMGashaMedalShopsResponse(SaoBaseResponse): self.header.length = len(ret) return super().make() + ret + +class GetMResEarnCampaignShopsRequest(SaoBaseRequest): + def __init__(self, header: SaoRequestHeader, data: bytes) -> None: + super().__init__(header, data) + self.dummy = decode_byte(data, 0) + +class GetMResEarnCampaignShopsResponse(SaoBaseResponse): + def __init__(self, cmd_id: int) -> None: + super().__init__(cmd_id) + self.result = 1 # byte + self.data_list: List[ResEarnCampaignShop] = [] + + def make(self) -> bytes: + ret = encode_byte(self.result) + ret += encode_arr_cls(self.data_list) + + self.header.length = len(ret) + return super().make() + ret diff --git a/titles/sao/handlers/helpers.py b/titles/sao/handlers/helpers.py index 74f8926..6e11146 100644 --- a/titles/sao/handlers/helpers.py +++ b/titles/sao/handlers/helpers.py @@ -816,6 +816,61 @@ class YuiMedalShopItemData(BaseHelper): ret += encode_int(self.property4_value2) return ret +class ResEarnCampaignShop(BaseHelper): + def __init__(self, data: bytes, offset: int) -> None: + super().__init__(data, offset) + self.res_earn_campaign_shop_id = decode_int(data, offset + self._sz) + self._sz += INT_OFF + self.res_earn_campaign_application_id = decode_int(data, offset + self._sz) + self._sz += INT_OFF + + name = decode_str(data, offset + self._sz) + self.name = name[0] + self._sz += name[1] + + self.selling_yui_medal = decode_short(data, offset + self._sz) + self._sz += SHORT_OFF + self.selling_col = decode_int(data, offset + self._sz) + self._sz += INT_OFF + self.selling_event_item_id = decode_int(data, offset + self._sz) + self._sz += INT_OFF + self.selling_event_item_num = decode_int(data, offset + self._sz) + self._sz += INT_OFF + self.purchase_limit = decode_short(data, offset + self._sz) + self._sz += SHORT_OFF + self.get_application_point = decode_short(data, offset + self._sz) + self._sz += SHORT_OFF + + sales_start_date = decode_str(data, offset + self._sz) + self.sales_start_date = prs_dt(sales_start_date[0]) + self._sz += sales_start_date[1] + + sales_end_date = decode_str(data, offset + self._sz) + self.sales_end_date = prs_dt(sales_end_date[0]) + self._sz += sales_end_date[1] + + @classmethod + def from_args(cls, shop_id: int = 0, app_id: int = 0, name: str = "") -> "ResEarnCampaignShop": + ret = cls(b"\x00" * 26, 0) + ret.res_earn_campaign_shop_id = shop_id + ret.res_earn_campaign_application_id = app_id + ret.name = name + return ret + + def make(self) -> bytes: + ret = encode_int(self.res_earn_campaign_shop_id) + ret = encode_int(self.res_earn_campaign_application_id) + ret += encode_str(self.name) + ret += encode_short(self.selling_yui_medal) + ret += encode_int(self.selling_col) + ret += encode_int(self.selling_event_item_id) + ret += encode_int(self.selling_event_item_num) + ret += encode_short(self.purchase_limit) + ret += encode_short(self.get_application_point) + ret += encode_str(fmt_dt(self.sales_start_date)) + ret += encode_str(fmt_dt(self.sales_end_date)) + return ret + class GashaMedalShop(BaseHelper): def __init__(self, data: bytes, offset: int) -> None: super().__init__(data, offset)