206 lines
12 KiB
Python
206 lines
12 KiB
Python
"""Transform the reviewed 6838 release's store, promotion UI."""
|
|
|
|
import hashlib
|
|
import re
|
|
|
|
|
|
PREFIX = "interface/addons/"
|
|
STORE = "blizzard_storeui/blizzard_shared_"
|
|
CATALOG = "blizzard_catalogshop/blizzard_catalogshop"
|
|
CHECKOUT = "blizzard_simplecheckout/blizzard_simplecheckout"
|
|
SUB = "blizzard_subscriptioninterstitialui/blizzard_subscriptioninterstitialui.lua"
|
|
PROMO = "blizzard_gluexml/promotionframe.lua"
|
|
LOBBY = "blizzard_gluexml/wowlabs/plunderstormlobby"
|
|
UTIL = "blizzard_sharedxml/interfaceutil.lua"
|
|
|
|
|
|
def replace(text, old, new, count=1):
|
|
if text.count(old) != count:
|
|
raise ValueError(f"Expected {count} occurrence(s) of {old!r}")
|
|
return text.replace(old, new)
|
|
|
|
|
|
def match_replace(text, pattern, replacement, count=1):
|
|
matches = list(re.finditer(pattern, text, re.MULTILINE | re.DOTALL))
|
|
if len(matches) != count:
|
|
raise ValueError(f"Expected {count} matches of {pattern!r}, got {len(matches)}")
|
|
return re.sub(pattern, replacement, text, flags=re.MULTILINE | re.DOTALL)
|
|
|
|
|
|
def body(text, name, new):
|
|
pattern = r"^(function " + re.escape(name) + r"\([^\n]*\)\n).*?^end\b"
|
|
return match_replace(text, pattern, lambda m: m[1] + new + "end")
|
|
|
|
|
|
def local_error(text):
|
|
# The stock else branch already has the correct one-button layout and ack.
|
|
return match_replace(text, r"^\tif \( urlIndex \) then\n.*?^\telse\n(.*?)^\tend\n",
|
|
lambda m: re.sub(r"^\t", "", m[1], flags=re.MULTILINE))
|
|
|
|
|
|
# These widgets accept URL-index WoW links and SimpleHTML anchors. Keep labels,
|
|
# inline layout and unrelated built-in link types. Strip link-only label color.
|
|
PLAIN = '''function StoreFrame_WebText(text)
|
|
if not text then return text end
|
|
local function plainLabel(label)
|
|
return (label:gsub("|c%x%x%x%x%x%x%x%x(.-)|r", "%1"))
|
|
end
|
|
text = text:gsub("|H[Uu][Rr][Ll][Ii][Nn][Dd][Ee][Xx]:[^|]*|h(.-)|h", plainLabel)
|
|
text = text:gsub("<[Aa]%s+[^>]*>(.-)</[Aa]%s*>", plainLabel)
|
|
return text
|
|
end
|
|
|
|
'''
|
|
|
|
|
|
def rewrite(path, text):
|
|
if path == UTIL:
|
|
helper = '''function StoreInterfaceUtil.HasSubscriptionProduct()
|
|
return C_CatalogShop.IsShop2Enabled()
|
|
or C_StorePublic.DoesGroupHavePurchaseableProducts(WOW_SUBSCRIPTION_CATEGORY_ID)
|
|
or C_StorePublic.DoesGroupHavePurchaseableProducts(WOW_GAME_TIME_CATEGORY_ID);
|
|
end
|
|
|
|
'''
|
|
text = replace(text, "-- Returns true if there is a subscription product", helper + "-- Returns true if there is a subscription product")
|
|
return replace(text, "\tPlaySound(SOUNDKIT.GS_LOGIN_NEW_ACCOUNT);\n\tLoadURLIndex(22);\n", "")
|
|
|
|
if path == SUB:
|
|
text = replace(text, "\t\tself:SetInterstitialType(interstitialType);", ''' if not StoreInterfaceUtil.HasSubscriptionProduct() then
|
|
SendSubscriptionInterstitialResponse(Enum.SubscriptionInterstitialResponseType.Closed);
|
|
return;
|
|
end
|
|
self:SetInterstitialType(interstitialType);''')
|
|
# A product may disappear after display. Report the usual closed response once.
|
|
return replace(text, "Enum.SubscriptionInterstitialResponseType.WebRedirect", "Enum.SubscriptionInterstitialResponseType.Closed")
|
|
|
|
if path == PROMO:
|
|
# The banner and its default upsell have no client operation. Keep the
|
|
# externally referenced frame functions and release any waiting overlay.
|
|
text = replace(text, "local DELAYED_PROMO_INFO;\n\n", "")
|
|
for name in ("OnLoad", "OnEvent"):
|
|
text = body(text, "PromotionFrame_" + name, "")
|
|
for name in ("AwaitingPromotion", "ReceivePromotion", "LaunchUpgradeURL"):
|
|
text = body(text, "PromotionFrame_" + name, "\tPromotionFrame_Hide();\n")
|
|
return text
|
|
|
|
if path == "blizzard_gluexml/promotionframe.xml":
|
|
return match_replace(text, r'^([ \t]*)<Button parentKey="UpgradeButton">.*?^\1</Button>\n', "")
|
|
|
|
if path == LOBBY + ".lua":
|
|
return body(text, "WoWLabsSubscribeButtonMixin:OnClick", "")
|
|
if path == LOBBY + ".xml":
|
|
return match_replace(text, r'^([ \t]*)<Button parentKey="SuscribeButton".*?^\1</Button>\n', "")
|
|
|
|
if path == CHECKOUT + ".lua":
|
|
# Register to consume native requests and use the client's normal decline
|
|
# callback, including requests while a store/housing panel is visible.
|
|
return body(body(text, "SimpleCheckoutMixin:OnExternalLink", ""),
|
|
"SimpleCheckoutMixin:OnEvent", ''' if event == "STORE_OPEN_SIMPLE_CHECKOUT" or event == "CATALOG_SHOP_OPEN_SIMPLE_CHECKOUT" then
|
|
self:CancelOpenCheckout();
|
|
elseif event == "UI_SCALE_CHANGED" or event == "DISPLAY_SIZE_CHANGED" then
|
|
self:CalculateDesiredSize();
|
|
self:RecalculateSize();
|
|
end
|
|
''')
|
|
if path == CHECKOUT + ".xml":
|
|
return replace(text, '\t\t\t\t<OnExternalLink method="OnExternalLink"/>\n', "")
|
|
|
|
if path == STORE + "storeuisecure.lua":
|
|
text = replace(text, '\t\telse\n\t\t\tPlaySound(SOUNDKIT.GS_LOGIN_NEW_ACCOUNT);\n\t\t\tLoadURLIndex(2);\n', '')
|
|
text = local_error(text)
|
|
text = replace(text, "local ActiveURLIndex = nil;\n", "")
|
|
text = replace(text, "\tActiveURLIndex = nil;\n", "")
|
|
text = body(text, "StoreFrameErrorWebsiteButton_OnClick", "")
|
|
for target, expression in (
|
|
("self.NoticeFrame.Notice", "notice"),
|
|
("self.LicenseAcceptText", "info.licenseAcceptText"),
|
|
("self.ProductInstructions", "HTML_START..self.productInfo.sharedData.instructions..HTML_END"),
|
|
("self.Disclaimer", 'HTML_START_CENTERED..string.format(vasDisclaimerData[VASServiceType].disclaimer, envTable["VAS_QUEUE_"..VasQueueStatusToString[queueTime]])..HTML_END'),
|
|
("frame", "HTML_START..text..HTML_END"),
|
|
):
|
|
text = replace(text, f"{target}:SetText({expression}", f"{target}:SetText(StoreFrame_WebText({expression})")
|
|
return text
|
|
|
|
if path == STORE + "storeui.xml":
|
|
return match_replace(text, r'^([ \t]*)<Scripts>\n\s*<OnHyperlinkClick function="GetURLIndexAndLoadURL" />\n\1</Scripts>\n', "", 5)
|
|
|
|
if path == STORE + "productcardtemplates.lua":
|
|
text = match_replace(text, r'^local function GetFaqNydusLink\(entryInfo\).*?^end\n\n', "")
|
|
text = match_replace(text, r'^\tif IsShiftKeyDown\(\) then\n\t\tlocal vasFaqUrl.*?^\tend\n\n', "")
|
|
return match_replace(text, r'^\tif self:CanBuyHere\(entryInfo\) then\n\t\t-- Check if we have a FAQ URL.*?^\telse\n', '\tif not self:CanBuyHere(entryInfo) then\n')
|
|
|
|
if path == STORE + "productcardbuybuttonmixin.lua":
|
|
return body(text, "StoreNydusLinkButtonMixin:OnClick", "")
|
|
if path == STORE + "productcardtemplates.xml":
|
|
return replace(text, 'parentKey="NydusLinkButton" inherits="NydusLinkButtonTemplate"', 'parentKey="NydusLinkButton" inherits="NydusLinkButtonTemplate" hidden="true"')
|
|
if path == STORE + "storeuitemplates.lua":
|
|
text = match_replace(text, r"^function StoreBulletPointMixin:OnHyperlinkClick\(link\)\n.*?^end",
|
|
"function StoreBulletPointMixin:SetContent(content)\n\tBulletPointWithTextureMixin.SetContent(self, StoreFrame_WebText(content));\nend")
|
|
return replace(text, "StoreBulletPointMixin = {};", PLAIN + "StoreBulletPointMixin = {};")
|
|
if path == STORE + "storeuitemplates.xml":
|
|
text = replace(text, 'mixin="StoreBulletPointMixin" hyperlinksEnabled="true"', 'mixin="StoreBulletPointMixin" hyperlinksEnabled="false"')
|
|
return match_replace(text, r'^\s*<OnHyperlink(?:Enter|Leave|Click) method="OnHyperlink(?:Enter|Leave|Click)"/>\n', '', 3)
|
|
|
|
if path in (CATALOG + ".lua", CATALOG + "_details.lua"):
|
|
return match_replace(text, r'^\tlocal function onHyperlinkClicked\(frame, link, text, button\)\n\t\tC_CatalogShop\.OnLegalDisclaimerClicked[^\n]*\n\tend\n\t[^\n]*:SetScript\("OnHyperlinkClick", onHyperlinkClicked\);\n', '')
|
|
if path in (CATALOG + ".xml", CATALOG + "_elements.xml"):
|
|
# Retain the enUS material restrictions sentence verbatim.
|
|
field = 'text="CATALOG_SHOP_DISCLAIMER_ALL_PRODUCTS"'
|
|
text = replace(text, field, 'text="Certain restrictions apply."')
|
|
frame = "CatalogShopDetailsFrame" if path == CATALOG + ".xml" else "ProductsHeader"
|
|
return match_replace(text, rf'(<Frame parentKey="{frame}"[^\n>]*?)hyperlinksEnabled="true"', r'\1hyperlinksEnabled="false"')
|
|
|
|
if path == CATALOG + "_elements.lua":
|
|
return local_error(text)
|
|
if path == CATALOG + "_gamepad.lua":
|
|
text = match_replace(text, r'^\tlocal function OpenBnetLink\(\).*?^\tlocal openBnet = [^\n]*\n\n', '')
|
|
return replace(text, '\tdata.detailsFooter:AddPromptedBinding(openBnet);\n', '')
|
|
if path == CATALOG + "_productcards.lua":
|
|
text = body(text, "CatalogShopSectionHeaderOptOutLinkMixin:OnLoad", "\tself.Help:Hide();\n")
|
|
return body(text, "CatalogShopSectionHeaderOptOutLinkMixin:OnInfoButton_OnClick", "")
|
|
|
|
raise ValueError(f"Unknown store input: {path}")
|
|
|
|
|
|
def transform(files):
|
|
modified = {}
|
|
for path, expected in PINS.items():
|
|
data = files[path]
|
|
if hashlib.sha256(data).hexdigest() != expected:
|
|
raise ValueError(f"Unexpected 6838 release bytes: {path}")
|
|
text = data.decode("utf-8")
|
|
newline = "\r\n" if "\r\n" in text else "\n"
|
|
output = rewrite(path[len(PREFIX):], text.replace("\r\n", "\n")).replace("\n", newline).encode("utf-8")
|
|
if output == data:
|
|
raise ValueError(f"Store transform did not change {path}")
|
|
modified[path] = output
|
|
return modified
|
|
|
|
|
|
# SHA-256 of the decoded named enUS inputs from the signed 6838 manifest.
|
|
PINS = {
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop.lua": "3f755e5923a896d0115e78040a1d606dd4f99d6c24647443edc475b1b6b29889",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop.xml": "546f641e38304d7d1f0cf3239c67efd8987b458d8496c21550c4d69f29daef3e",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop_details.lua": "3c3a8b8747e0fe81b4868c77278f5d9bfea152b7e3fae71b36141aa8ea56a2c0",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop_elements.lua": "71cb808cbb95041a91a41ffbe9e8f51dc6cde66a9056e554cfeba347cbdfbfe1",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop_elements.xml": "905a1e46b86b60f25874c6206a205c67a65282537408aa2f0d1e3b4b26a7d688",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop_gamepad.lua": "b679bb1c00b0e5b4250e12451eb210c750b9686837164e939a6a185912ac61f6",
|
|
"interface/addons/blizzard_catalogshop/blizzard_catalogshop_productcards.lua": "adb2576123131ba68b63879ef1184938d95715743d47906a13872e0d9e185ab2",
|
|
"interface/addons/blizzard_gluexml/promotionframe.xml": "39475bcf3396eaedbb0c570c6888dd6eb3eae992e1003d94f21cc439f8eb605d",
|
|
"interface/addons/blizzard_gluexml/promotionframe.lua": "33ecaae90f6e64a7f5d1ffdff821112b94205a0621ff4c6e5395397dbdc0522e",
|
|
"interface/addons/blizzard_gluexml/wowlabs/plunderstormlobby.lua": "1bd5deac9026650bc69d316432a75e33890ed2307c972fab4519723f7e763d25",
|
|
"interface/addons/blizzard_gluexml/wowlabs/plunderstormlobby.xml": "0c99c36549f54b0201894f55ff0f143ab7aa830f2345a7b3a6dfda0f5c0c03d1",
|
|
"interface/addons/blizzard_sharedxml/interfaceutil.lua": "f814e46bb898b375de5c0af57bb666ea2dabce672989f821422d58ea4ee8aaf9",
|
|
"interface/addons/blizzard_simplecheckout/blizzard_simplecheckout.lua": "4825e763b471b1a0cd944d9a08f6612621a9013292fd4419da7b1ab81914e56c",
|
|
"interface/addons/blizzard_simplecheckout/blizzard_simplecheckout.xml": "875ef755d16a4de8976cbcc527da6fc59174470ff9c1b2c36fec63079d6f480d",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_productcardbuybuttonmixin.lua": "2e7fd922ce098c33b0005a70884a85f76d23a6f72d80ba90e63d8b3ab204290d",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_productcardtemplates.lua": "0caea701c4b686dffcf7ad802841a424a5d1b4b4eb2e6b54962791e2d3eb436d",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_productcardtemplates.xml": "4605f3510101f5d8903bb5c31c6352a96fd3f8ca2ed7cecf2d5c9dfe7d325b58",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_storeui.xml": "0f883299027596d743a74301931cff9a3216f9b325e7f883caa3f92e0f315c76",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_storeuisecure.lua": "e81e6135d734c75be2a902ed7b38967bfb8bec1aa409c0fbbcb79601a44b6adb",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_storeuitemplates.lua": "242e86e31b9bd80294c77ba0612b99846788c2e604fa97fd7dc598aea8c02ff5",
|
|
"interface/addons/blizzard_storeui/blizzard_shared_storeuitemplates.xml": "2dd249835e1467f41dd3fd3771c909d91ab75f4652fe6967d1999595e3e49621",
|
|
"interface/addons/blizzard_subscriptioninterstitialui/blizzard_subscriptioninterstitialui.lua": "47c76ef882b0ef8aaba66b6601c73aa805a2e59ea5dbe3b4b0db76294d83fa74",
|
|
}
|