130 lines
11 KiB
Python
130 lines
11 KiB
Python
"""Narrow Source mode in the original 70334 Blizzard Store native Lua assets.
|
|
|
|
The original forbidden frame, category tree, product-card templates/pools and
|
|
confirmation frame remain. Inbound data crosses original attributes; outbound
|
|
requests cross original securecall. No global C_StoreSecure API is replaced.
|
|
"""
|
|
from pathlib import Path
|
|
import argparse, hashlib, json
|
|
ROOT=Path(__file__).resolve().parents[1]
|
|
STORE='interface/addons/blizzard_storeui/'
|
|
MICRO='interface/addons/blizzard_micromenu/mainline/mainmenubarmicrobuttons.lua'
|
|
MODEL_PREVIEW='interface/addons/blizzard_sharedxml/modelpreviewframe.lua'
|
|
|
|
def insert(s, signature, body):
|
|
needle=signature+'\r\n'
|
|
if s.count(needle)!=1:raise ValueError('Original Store signature changed: '+signature)
|
|
return s.replace(needle,needle+body.replace('\n','\r\n')+'\r\n',1)
|
|
|
|
def adapt(original, parser, art, provider, secure_helpers):
|
|
files={k:v.decode() for k,v in original.items()}
|
|
def store(name):return STORE+'blizzard_shared_'+name+'.lua'
|
|
sec=store('storeuisecure');inbound=store('storeuiinbound');outbound=store('storeuioutbound');toggle=store('storeuitoggle');cards=store('productcardtemplates');templates=store('storeuitemplates');magnifier=store('productcardmagnifiertemplates')
|
|
# Only catalogue readers are substituted, inside original secure assets.
|
|
# The wrappers retain the retail call when Source mode is inactive/glue.
|
|
for file in (sec,cards,templates,magnifier):
|
|
for method in ('GetEntryInfo','GetProducts','GetProductGroups','GetProductGroupInfo'):
|
|
files[file]=files[file].replace('C_StoreSecure.'+method+'(', 'SourceStore_'+method+'(')
|
|
# Source entries have no retail C_StoreSecure entry. Keep the original
|
|
# magnifier/card/preview callback and use the same secure catalogue wrapper.
|
|
needle='\tStoreFrame_ShowPreviews(entryInfo.sharedData.cards);'
|
|
if files[magnifier].count(needle)!=1:raise ValueError('Original magnifier dispatch changed')
|
|
files[magnifier]=files[magnifier].replace(needle,'\tif SourceStore_IsActive() and not entryInfo then return end;\r\n'+needle,1)
|
|
branches={
|
|
'function StoreFrame_OnLoad(self)':'return SourceStore_OnLoad(self)',
|
|
'function StoreFrame_OnShow(self)':'return SourceStore_OnShow(self)',
|
|
'function StoreFrame_OnHide(self)':'return SourceStore_OnHide(self)',
|
|
'function StoreFrame_OnEvent(self, event, ...)':'if event == "GET_ITEM_INFO_RECEIVED" then SourceStore_OnItemInfoReceived(...) end; return',
|
|
'function StoreFrame_SetCategory(forceModelUpdate)':'SourceStore_BeforeSetCategory()',
|
|
'function StoreFrame_ShowPreviews(displayInfoEntries)':'return SourceStore_ShowInternalPreview(displayInfoEntries)',
|
|
'function StoreFrame_OnAttributeChanged(self, name, value)':'return SourceStore_OnAttribute(self,name,value)',
|
|
'function StoreFrame_CurrencyInfo()':'return SourceStore_CurrencyInfo()',
|
|
'function StoreFrame_UpdateActivePanel(self, fromVASPurchaseCompletion)':'return SourceStore_Refresh()',
|
|
'function StoreFrame_UpdateBuyButton()':'return SourceStore_UpdateBuyButton()',
|
|
'function StoreFrame_FilterEntries(entries)':'return entries',
|
|
'function StoreFrame_IsProductGroupDisabled(groupID)':'return false',
|
|
'function StoreFrame_GetDefaultCategory()':'local groups=SourceStore_GetProductGroups(); return groups[1] and groups[1].groupID',
|
|
'function StoreFrame_GetProductPriceText(entryInfo, currencyFormat)':'return tostring(entryInfo.sharedData.sourcePriceTokens).." Tokens"',
|
|
'function StoreFrame_IsCompletelyOwned(entryInfo)':'return false',
|
|
'function StoreFrame_IsPartiallyOwned(entryInfo)':'return false',
|
|
'function StoreFrame_BeginPurchase(entryID)':'return SourceStore_BeginPurchase(entryID)',
|
|
'function StoreConfirmationFinalBuy_OnClick(self)':'return SourceStore_FinalBuy()',
|
|
'function StoreConfirmationFrame_Cancel(self)':'return SourceStore_CancelConfirmation()',
|
|
'function StoreConfirmationFrame_OnHide(self)':'StoreFrame_UpdateCoverState(); return',
|
|
'function StoreConfirmationFrame_OnEvent(self, event, ...)':'return',
|
|
}
|
|
for signature,body in branches.items():files[sec]=insert(files[sec],signature,'\tif SourceStore_IsActive() then '+body+' end')
|
|
for signature,body in {
|
|
'function StoreCardMixin:UpdateCard(entryID, forceModelUpdate)':'return SourceStore_CardUpdate(self,entryID)',
|
|
'function StoreCardMixin:OnClick()':'return SourceStore_CardClick(self)',
|
|
'function StoreCardMixin:ShowTooltip()':'return SourceStore_CardTooltip(self)',
|
|
'function StoreCardMixin:ShouldShowMagnifyingGlass()':'return SourceStore_CanPreview(self)',
|
|
}.items():files[cards]=insert(files[cards],signature,'\tif SourceStore_IsActive() then '+body+' end')
|
|
for file in (sec,templates):
|
|
files[file]=files[file].replace('if IsTrialAccount() and','if not SourceStore_IsActive() and IsTrialAccount() and').replace('elseif IsVeteranTrialAccount() and','elseif not SourceStore_IsActive() and IsVeteranTrialAccount() and')
|
|
files[templates]=files[templates].replace("local validCategory = (#StoreFrame_FilterEntries(", "local validCategory = SourceStore_IsActive() or (#StoreFrame_FilterEntries(",1)
|
|
# Inline private copies instead of importing addon-owned globals into the
|
|
# secure environment. All actual UI scripts remain original native assets.
|
|
# Source supplies catalogue data only. Original native frames/cards/artwork
|
|
# remain; the old addon artwork map is no longer a runtime dependency.
|
|
prelude='local SourceStoreWire = (function()\nlocal TurtleDonationShop = {}\n'+parser+'\nreturn TurtleDonationShop\nend)()\nlocal SourceStoreProvider = (function()\n'+provider+'\nend)()\n'
|
|
files[sec]=prelude.replace('\n','\r\n')+files[sec]+'\r\n'+secure_helpers.replace('\n','\r\n')
|
|
# Inbound remains in its original global environment and sends only scalar
|
|
# strings into the forbidden frame, never references to addon tables.
|
|
files[inbound]=files[inbound].replace('if wasShown ~= shown then','if C_Glue.IsOnGlueScreen() and wasShown ~= shown then',1)
|
|
files[inbound]+='''\r\nlocal sourceShopReceiver = CreateFrame("Frame")
|
|
sourceShopReceiver:RegisterEvent("CHAT_MSG_ADDON")
|
|
C_ChatInfo.RegisterAddonMessagePrefix("TW_SHOP")
|
|
sourceShopReceiver:SetScript("OnEvent",function(_,event,prefix,message,distribution)
|
|
if event == "CHAT_MSG_ADDON" and prefix == "TW_SHOP" and distribution == "GUILD" and type(message)=="string" and #message<=4096 and StoreFrame then
|
|
StoreFrame:SetAttribute("sourceshopmessage",nil)
|
|
StoreFrame:SetAttribute("sourceshopmessage",message)
|
|
end
|
|
end)
|
|
function SourceStoreGlobalSend(payload)
|
|
if type(payload)~="string" or #payload>255 then return false end
|
|
if payload~="Categories" and payload~="Balance" and not payload:match("^Entries:%d+$") and not payload:match("^Buy:%d+$") then return false end
|
|
local name=UnitName("player");if not name or name=="" then return false end
|
|
C_ChatInfo.SendAddonMessage("TW_SHOP",payload,"WHISPER",name)
|
|
return true
|
|
end
|
|
'''.replace('\n','\r\n')
|
|
files[outbound]+='\r\nfunction StoreOutbound.SourceShopSend(payload)\r\n\treturn securecall("SourceStoreGlobalSend",payload);\r\nend\r\n'
|
|
files[toggle]=insert(files[toggle],'local function ToggleActiveStoreUI(contextKey)','\tif not C_Glue.IsOnGlueScreen() then\n\t\tlocal shown=StoreFrame_IsShown(); if not shown then CloseAllUIPanels(); end\n\t\tStoreFrame_SetShown(not shown,contextKey); return;\n\tend')
|
|
files[toggle]=insert(files[toggle],'local function ActiveStoreEscapePressed()','\tif not C_Glue.IsOnGlueScreen() then return StoreFrame_EscapePressed(); end')
|
|
# Keep the prior source addon fallback installed, but the original button
|
|
# opens the actual original StoreFrame once this native asset is loaded.
|
|
files[MICRO]=insert(files[MICRO],'function StoreMicroButtonMixin:OnClick()','\tif not C_Glue.IsOnGlueScreen() and not Kiosk.IsEnabled() then ToggleStoreUI(self:GetButtonContext()); return; end')
|
|
files[MICRO]=insert(files[MICRO],'function StoreMicroButtonMixin:UpdateMicroButton()','\tif not C_Glue.IsOnGlueScreen() and not Kiosk.IsEnabled() then\n\t\tself.tooltipText="OctoShop";self.disabledTooltip=nil;self:Enable();self:Show();self:SetNormal();self:SetHasNotification(false);return;\n\tend')
|
|
files[MICRO]+='\r\nSLASH_SOURCE_NATIVE_STORE1="/shop"; SLASH_SOURCE_NATIVE_STORE2="/donateshop";\r\nSlashCmdList.SOURCE_NATIVE_STORE=function() if not C_Glue.IsOnGlueScreen() then ToggleStoreUI(); end end\r\n'
|
|
# Original Classic mount scene4 has unwrapped, not the retail item actor.
|
|
needle='local actor = display.ModelScene:GetActorByTag("item");'
|
|
if files[MODEL_PREVIEW].count(needle)!=1:raise ValueError('Original model preview actor lookup changed')
|
|
files[MODEL_PREVIEW]=files[MODEL_PREVIEW].replace(needle, 'local actor = display.ModelScene:GetActorByTag(modelSceneID == 4 and "unwrapped" or "item");',1)
|
|
# Actual shown native preview inherited MEDIUM/1 after SetParent despite
|
|
# original XML declaring FULLSCREEN_DIALOG/5. Restore those exact values.
|
|
needle='\tself:SetParent(GetAppropriateTopLevelParent());'
|
|
if files[MODEL_PREVIEW].count(needle)!=1:raise ValueError('Original preview parent assignment changed')
|
|
files[MODEL_PREVIEW]=files[MODEL_PREVIEW].replace(needle,needle+'\r\n\tself:SetFrameStrata("FULLSCREEN_DIALOG");\r\n\tself:SetFrameLevel(5);',1)
|
|
# Like original UIPanelManager presentation, bring this existing top-level
|
|
# frame above siblings at its original FULLSCREEN_DIALOG strata.
|
|
needle='\tModelPreviewFrame_SetCarouselIndex(self, 1, allowZoom, forceUpdate);'
|
|
if files[MODEL_PREVIEW].count(needle)!=1:raise ValueError('Original preview presentation changed')
|
|
files[MODEL_PREVIEW]=files[MODEL_PREVIEW].replace(needle,needle+'\r\n\tself:Raise();',1)
|
|
return {k:v.encode() for k,v in files.items()}
|
|
|
|
def paths():
|
|
return [STORE+'blizzard_shared_'+n+'.lua' for n in ('storeuisecure','storeuiinbound','storeuioutbound','storeuitoggle','productcardtemplates','storeuitemplates','productcardmagnifiertemplates')]+[MICRO,MODEL_PREVIEW]
|
|
|
|
def main():
|
|
a=argparse.ArgumentParser(description=__doc__);a.add_argument('original',type=Path);a.add_argument('output',type=Path);args=a.parse_args()
|
|
inputs={p:(args.original/p).read_bytes() for p in paths()}
|
|
result=adapt(inputs,(ROOT/'ops/data/source_shop/ShopData.lua').read_text(),'',(ROOT/'ops/source_shop_store_provider.lua').read_text(),(ROOT/'ops/native_source_store_secure.lua').read_text())
|
|
pins=[]
|
|
for path,data in result.items():
|
|
out=args.output/path;out.parent.mkdir(parents=True,exist_ok=True);out.write_bytes(data)
|
|
pins.append(dict(path=path,original_sha256=hashlib.sha256(inputs[path]).hexdigest(),sha256=hashlib.sha256(data).hexdigest(),bytes=len(data)))
|
|
(args.output/'manifest.private.json').write_text(json.dumps(dict(state='PREPARED_NOT_INSTALLED',children=pins),indent=2)+'\n')
|
|
print('Prepared original native Store/model-preview Lua children; no runtime build or install.')
|
|
if __name__=='__main__':main()
|