Advertisement
xConquerPS

Untitled

May 18th, 2025
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 63.26 KB | None | 0 0
  1. local PufferODPakManager = {}
  2. local StringUtil = require("common.string_util")
  3. local PufferConst = require("client.slua.logic.download.puffer_const")
  4. local ModuleManager = require("client.module_framework.ModuleManager")
  5. local Client = _ENV.Client
  6. local PufferDownloader = _ENV.PufferDownloader
  7. local PufferQueue
  8.  
  9. function PufferODPakManager:DefineAndResetData()
  10.   self.ODPaks = {}
  11.   self.PakDatas = {}
  12.   self.itemToPaks = {}
  13.   self.itemToItems = {}
  14.   self.itemToPaths = {}
  15.   self.battleDownloadPaks = {}
  16.   self.BlackListPaks = {}
  17.   self.PauseDontAutoDownloadPaks = {}
  18.   self.ODPaksNameToConHash = {}
  19.   self.needRecoverBattleData = false
  20.   self.battleDeleteFiles = {}
  21.   self._attachmentSkinIDInited = false
  22.   self._attachmentSkinIDMap = nil
  23.   PufferQueue = ModuleManager.GetModule(ModuleManager.CommonModuleConfig.PufferQueue)
  24.   local ScriptHelperEngine = import("ScriptHelperEngine")
  25.   self.isLowMemoryDevice = ScriptHelperEngine.IsLowMemoryDevice()
  26. end
  27.  
  28. function PufferODPakManager:InitODPaks(existPaks)
  29.   local val = HDmpveRemote.HDmpveRemoteConfigGetInt("GEnableBackpackPakCache", 0)
  30.   local minMemorySize = HDmpveRemote.HDmpveRemoteConfigGetInt("GForceDisableBackpackPakCacheMem", 0)
  31.   local ScriptHelperClient = import("ScriptHelperClient")
  32.   local curMemorySize = ScriptHelperClient.GetMemorySize()
  33.   log(bWriteLog and "PufferODPakManager:InitODPaks. size = " .. tostring(curMemorySize) .. " minMemory = " .. tostring(minMemorySize))
  34.   if 0 < minMemorySize and minMemorySize > curMemorySize then
  35.     val = 0
  36.   end
  37.   PufferDownloader.SetEnableBackpackCache(val)
  38.   log("PufferODPakManager:InitODPaks start")
  39.   self:DefineAndResetData()
  40.   local IsDevelopment = Client.IsDevelopment()
  41.   self.enableSaveODPakDataToFile = HDmpveRemote.HDmpveRemoteConfigGetBool("GSaveODPakDataToFile", false)
  42.   local pufferFileList = PufferDownloader.GetPufferFileListJson()
  43.   self:MapContentHashPro(pufferFileList.conhash_list)
  44.   if pufferFileList.ODPaks == nil or next(pufferFileList.ODPaks) == nil then
  45.     log("PufferODPakManager:InitODPaks PufferFileList.json error")
  46.     return
  47.   end
  48.   self:InitUGCExpiredDepends()
  49.   local VirtualBundleCfgs = {}
  50.   local VirtualBundlePaks = {}
  51.   local pakInfoTableList = CDataTable.GetTable("PakInfoTable")
  52.   for _, packCfg in pairs(pakInfoTableList) do
  53.     local id = packCfg.PakID
  54.     local strID = tostring(id)
  55.     local fileList = {}
  56.     local dataCfg = pufferFileList.ODPaks[strID]
  57.     if dataCfg then
  58.       if not packCfg.IsUGC or packCfg.IsUGC == 0 then
  59.         fileList = dataCfg.fileList
  60.       end
  61.     elseif packCfg.depends ~= "" then
  62.       local dependItems = StringUtil.split(packCfg.depends, ";")
  63.       for _, v in pairs(dependItems) do
  64.         local itemID = tonumber(v)
  65.         local Paks
  66.         if itemID then
  67.           if self.UGCExpiredDepends and not self.UGCExpiredDepends[itemID] then
  68.             Paks = self:GetPakNamesByItemID(itemID)
  69.           end
  70.         elseif self.UGCExpiredDepends and not self.UGCExpiredDepends[v] then
  71.           Paks = self:GetPakNamesByFeatureID(v)
  72.         end
  73.         if Paks and next(Paks) then
  74.           local virtualCfg = VirtualBundleCfgs[strID]
  75.           if not virtualCfg then
  76.             virtualCfg = {
  77.               paks = {}
  78.             }
  79.             VirtualBundleCfgs[strID] = virtualCfg
  80.           end
  81.           for PakName, _ in pairs(Paks) do
  82.             if not VirtualBundlePaks[PakName] then
  83.               VirtualBundlePaks[PakName] = 1
  84.               virtualCfg.paks[PakName] = 1
  85.             end
  86.           end
  87.         end
  88.       end
  89.     end
  90.     self:InitODPack(fileList, id)
  91.   end
  92.   for ODPackID, v in pairs(pufferFileList.ODPaks) do
  93.     local id = tonumber(ODPackID)
  94.     if not self.ODPaks[id] then
  95.       local fileList = v.fileList
  96.       self:InitODPack(fileList, id)
  97.     end
  98.   end
  99.   log(bWriteLog and "PufferODPakManager:InitODPaks. handleInitODPack")
  100.   for virtualPakName, _ in pairs(VirtualBundlePaks) do
  101.     local _, packData = self:GetPackDataByPakName(virtualPakName)
  102.     if packData then
  103.       local data = packData.paks[virtualPakName]
  104.       packData.paks[virtualPakName] = nil
  105.       packData.totalCnt = packData.totalCnt - 1
  106.       packData.totalSize = packData.totalSize - data.tSize
  107.       if data.state == PufferConst.ENUM_DownloadState.Done then
  108.         packData.curCnt = packData.curCnt - 1
  109.         packData.curSize = packData.curSize - data.cSize
  110.       end
  111.     end
  112.   end
  113.   for k, v in pairs(VirtualBundleCfgs) do
  114.     self:InitVirtualODPack(k, v.paks)
  115.   end
  116.   log(bWriteLog and "PufferODPakManager:InitODPaks. handleVirtualODPack")
  117.   self:DumpUGCDebugInfo()
  118.   self:UpdatePkgCheckInfo(existPaks)
  119.   self:UpdateExistPaks(existPaks)
  120.   log("PufferODPakManager:InitODPaks end")
  121. end
  122.  
  123. function PufferODPakManager:InitODPack(fileList, id, existPaks)
  124.   if not next(fileList) then
  125.     return
  126.   end
  127.   local data = {}
  128.   self.ODPaks[id] = data
  129.   data.paks = {}
  130.   data.curCnt = 0
  131.   data.totalCnt = #fileList
  132.   data.curSize = 0
  133.   data.totalSize = 0
  134.   local ENUM_DownloadState = PufferConst.ENUM_DownloadState
  135.   data.state = ENUM_DownloadState.Not
  136.   for _, v1 in ipairs(fileList) do
  137.     local TmpPakInfo = StringUtil.split(v1, "|")
  138.     local TmpPakInfoNum = #TmpPakInfo
  139.     local pakName = ""
  140.     if 1 <= TmpPakInfoNum then
  141.       pakName = TmpPakInfo[1]
  142.     end
  143.     local pakNameData = {
  144.       tSize = 0,
  145.       cSize = 0,
  146.       state = ENUM_DownloadState.Not
  147.     }
  148.     data.paks[pakName] = pakNameData
  149.     if self.PakDatas[pakName] then
  150.       log(bWriteLog and "PufferODPakManager:InitODPack. exist pakName: " .. pakName)
  151.     else
  152.       self.PakDatas[pakName] = {packID = id, data = pakNameData}
  153.     end
  154.     local size = 0
  155.     if 2 <= TmpPakInfoNum then
  156.       size = tonumber(TmpPakInfo[2])
  157.     end
  158.     pakNameData.tSize = size / 1024
  159.     local ConOrgHash = "0101010101010101010101010101010101010101"
  160.     if 3 <= TmpPakInfoNum then
  161.       ConOrgHash = TmpPakInfo[3]
  162.     end
  163.     self.ODPaksNameToConHash[pakName] = ConOrgHash
  164.     if existPaks and existPaks[pakName] then
  165.       pakNameData.cSize = pakNameData.tSize
  166.       pakNameData.state = ENUM_DownloadState.Done
  167.       data.curCnt = data.curCnt + 1
  168.     end
  169.     data.totalSize = data.totalSize + pakNameData.tSize
  170.   end
  171.   if existPaks then
  172.     self:_UpdatePackDataState(data)
  173.   end
  174. end
  175.  
  176. function PufferODPakManager:MapContentHashPro(conhash_list)
  177.   local USFEnableUpdatePkgMapType = HDmpveRemote.HDmpveRemoteConfigGetInt("USFEnableUpdatePkgMapType", 0)
  178.   if USFEnableUpdatePkgMapType == 0 then
  179.     log(bWriteLog and "PufferODPakManager:MapContentHashPro return for USFEnableUpdatePkgMapType = " .. tostring(USFEnableUpdatePkgMapType))
  180.     return
  181.   end
  182.   if conhash_list == nil then
  183.     log("PufferODPakManager:MapContentHashPro  return for conhash_list == nil")
  184.     return
  185.   end
  186.   log_tree("PufferODPakManager:MapContentHashPro conhash_list = ", conhash_list)
  187.   for PkgName, ContentHash in pairs(conhash_list) do
  188.     self.ODPaksNameToConHash[PkgName] = ContentHash
  189.   end
  190. end
  191.  
  192. function PufferODPakManager:UFSSUpdatePkgMapType(filestate)
  193.   local USFEnableUpdatePkgMapType = HDmpveRemote.HDmpveRemoteConfigGetInt("USFEnableUpdatePkgMapType", 0)
  194.   if USFEnableUpdatePkgMapType == 0 then
  195.     log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType return for UFSSUpdatePkgMapType = " .. tostring(USFEnableUpdatePkgMapType))
  196.     return
  197.   end
  198.   local IsDiffPkg = false
  199.   local pakName = filestate.filename
  200.   if filestate.diffFilename ~= nil then
  201.     pakName = filestate.diffFilename
  202.     local TmpPath = Client.ProjectSavedDir() .. "Paks/" .. pakName
  203.     log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType TmpPath = " .. tostring(TmpPath))
  204.     local TmpArrayData = {}
  205.     table.insert(TmpArrayData, TmpPath)
  206.     Client.USFSCacheSysContextUpdatePkgBinDiff(TmpArrayData)
  207.   else
  208.     pakName = filestate.filename
  209.     log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType pakName = " .. tostring(pakName))
  210.     if not Client.IsFileExistInCSCWithCheck(pakName) then
  211.       local TmpPath = Client.ProjectSavedDir() .. "Paks/" .. pakName
  212.       log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType TmpPath = " .. tostring(TmpPath))
  213.       local TmpArrayData = {}
  214.       table.insert(TmpArrayData, TmpPath)
  215.       log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType TmpArrayData: " .. tostring(#TmpArrayData))
  216.       Client.USFSCacheSysContextUpdatePkg(TmpArrayData)
  217.     else
  218.       log(bWriteLog and "PufferODPakManager:UFSSUpdatePkgMapType skip for Client.IsFileExistInCSCWithCheck pakName: " .. tostring(pakName))
  219.     end
  220.   end
  221. end
  222.  
  223. function PufferODPakManager:UpdateExistPaks(existPaks)
  224.   existPaks = existPaks or {}
  225.   local ArrayData = Client.GetPkgsFromDir(true, "ODPaks")
  226.   log_tree("ArrayData = ", ArrayData)
  227.   if ArrayData then
  228.     for i, v in ipairs(ArrayData) do
  229.       existPaks[v] = true
  230.     end
  231.   end
  232.   if PufferDownloader.EnableBackpackCache then
  233.     local UBackpackUtils = import("BackpackUtils")
  234.     local startTime = slua.getMiliseconds()
  235.     if UBackpackUtils.SetPaKExistMap then
  236.       UBackpackUtils.SetPaKExistMap(existPaks)
  237.     else
  238.       PufferDownloader.ClearPakPathMap()
  239.       for pakName, _ in pairs(existPaks) do
  240.         log(bWriteLog and "PufferODPakManager:UpdateExistPaks. pakName = " .. tostring(pakName))
  241.         PufferDownloader.SetPakExist(pakName, true)
  242.       end
  243.     end
  244.     local costTimeInSet = slua.getMiliseconds() - startTime
  245.     log(bWriteLog and "PufferODPakManager:UpdateExistPaks. SetPaKExistMap costTime = " .. tostring(costTimeInSet))
  246.   end
  247.   for packID, data in pairs(self.ODPaks) do
  248.     for pakName, pakNameData in pairs(data.paks) do
  249.       if existPaks[pakName] then
  250.         pakNameData.state = PufferConst.ENUM_DownloadState.Done
  251.         pakNameData.cSize = pakNameData.tSize
  252.         data.curSize = data.curSize + pakNameData.tSize
  253.         data.curCnt = data.curCnt + 1
  254.       end
  255.     end
  256.     self:_UpdatePackDataState(data)
  257.   end
  258.   log(bWriteLog and "PufferODPakManager:UpdateExistPaks. End")
  259. end
  260.  
  261. function PufferODPakManager:InitPretechODPaks(jsonODPaks, existPaks)
  262.   log("PufferODPakManager:InitPretechODPaks start")
  263.   if not jsonODPaks then
  264.     return
  265.   end
  266.   for ODPackID, v in pairs(jsonODPaks) do
  267.     self:InitODPack(v.fileList, tonumber(ODPackID), existPaks)
  268.   end
  269.   log("PufferODPakManager:InitPretechODPaks end")
  270. end
  271.  
  272. function PufferODPakManager:InitUGCExpiredDepends()
  273.   log("PufferODPakManager:InitUGCExpiredDepends start")
  274.   local CreativeExpiredAssetConfig = require("GameLua.Mod.CreativeBase.Gameplay.Config.CreativeExpiredAssetConfig")
  275.   local ModuleManager = require("client.module_framework.ModuleManager")
  276.   local PufferUGCPakManager = ModuleManager.GetModule(ModuleManager.CommonModuleConfig.puffer_ugcpak_manager)
  277.   self.UGCExpiredDepends = {}
  278.   for AssetID, _ in pairs(CreativeExpiredAssetConfig.CurVersionExpiredAssetSet) do
  279.     local dependPackArray, minDepends = PufferUGCPakManager:GetDepends(AssetID)
  280.     if next(minDepends) then
  281.       for k, v in pairs(minDepends) do
  282.         self.UGCExpiredDepends[v] = true
  283.         log("PufferODPakManager:InitUGCExpiredDepends  Expired Depend = " .. tostring(v) .. " AssetID = " .. tostring(AssetID))
  284.       end
  285.     end
  286.   end
  287. end
  288.  
  289. function PufferODPakManager:InitVirtualODPack(id, paks)
  290.   id = tonumber(id)
  291.   local packData = {}
  292.   self.ODPaks[id] = packData
  293.   packData.paks = {}
  294.   packData.curCnt = 0
  295.   packData.totalCnt = 0
  296.   packData.curSize = 0
  297.   packData.totalSize = 0
  298.   packData.state = PufferConst.ENUM_DownloadState.Not
  299.   packData.isVirtual = true
  300.   for pakName, _ in pairs(paks) do
  301.     packData.totalCnt = packData.totalCnt + 1
  302.     local pakData = self.PakDatas[pakName]
  303.     if pakData then
  304.       pakData.packID = id
  305.     else
  306.       log(bWriteLog and "PufferODPakManager:InitVirtualODPack. pakName = " .. tostring(pakName))
  307.       pakData = {
  308.         data = {
  309.           tSize = 0,
  310.           state = PufferConst.ENUM_DownloadState.Not,
  311.           cSize = 0
  312.         },
  313.         packID = id
  314.       }
  315.       self.PakDatas[pakName] = pakData
  316.     end
  317.     packData.totalSize = packData.totalSize + pakData.data.tSize
  318.     packData.paks[pakName] = pakData.data
  319.   end
  320. end
  321.  
  322. function PufferODPakManager:_UpdatePackDataState(packData)
  323.   if not packData then
  324.     return
  325.   end
  326.   if packData.curCnt == packData.totalCnt then
  327.     packData.state = PufferConst.ENUM_DownloadState.Done
  328.   elseif packData.curCnt > 0 then
  329.     packData.state = PufferConst.ENUM_DownloadState.Pause
  330.   else
  331.     packData.state = PufferConst.ENUM_DownloadState.Not
  332.   end
  333. end
  334.  
  335. function PufferODPakManager:IsIllegalTimeByODPackID(ODPackID)
  336.   local RecommendHandler = require("client.slua.logic.download.recommend.logic_recommend_handler")
  337.   if not RecommendHandler.PaksDownloadTime or not next(RecommendHandler.PaksDownloadTime) then
  338.     return true
  339.   end
  340.   if not self.ODPaks[ODPackID] then
  341.     return false
  342.   end
  343.   local FBI = require("client.slua.logic.fbi.logic_fbi")
  344.   for pakName, v in pairs(self.ODPaks[ODPackID].paks) do
  345.     if FBI.IsIllegalTime(pakName) then
  346.       return true
  347.     end
  348.   end
  349.   return false
  350. end
  351.  
  352. function PufferODPakManager:JumpODPack(ODPackID)
  353.   local PufferSwitch = require("client.slua.logic.download.puffer_switch")
  354.   local ui_manager = require("client.slua_ui_framework.manager")
  355.   if ui_manager.IsAndroidStackEmpty() and PufferSwitch.ODPackDownloadFinishPopUpSwitch then
  356.     local canPop = true
  357.     if GameStatus.GetGameStatus() == GameStatus.Fighting then
  358.       canPop = false
  359.     end
  360.     local ODPackCfg = CDataTable.GetTableData("PakInfoTable", ODPackID)
  361.     if ODPackCfg and ODPackCfg.DownloadFinishTipsID > 0 and canPop then
  362.       local jumpInfo = {}
  363.       jumpInfo.texturePath = "/Game/UMG/Texture/Lobby_NoAtlas/UnknowPass/Koi/Koi_Tips_icon_Chicken.Koi_Tips_icon_Chicken"
  364.      
  365.       function jumpInfo.callback()
  366.         if ODPackID == PufferConst.EODPackID.SocialLobby then
  367.           local logic_lobby_social_scene = require("client.slua.logic.lobby.Left.logic_lobby_social_scene")
  368.           logic_lobby_social_scene.MoveToPage(ENUM_LobbyPageType.Left)
  369.         else
  370.           GlobalData.JumpUrl(ODPackCfg.JumpURL)
  371.         end
  372.       end
  373.      
  374.       local function cancelCallback()
  375.         PufferSwitch.ODPackDownloadFinishPopUpSwitch = false
  376.       end
  377.      
  378.       jumpInfo.cancelCallback = cancelCallback
  379.       local content = LocUtil.LocalizeResFormat(ODPackCfg.DownloadFinishTipsID)
  380.       local RightPopSystem = require("client.slua.logic.lobby_popui.logic_right_popup")
  381.       RightPopSystem.ShowPopupTip(content, true, false, jumpInfo, 10)
  382.     else
  383.     end
  384.   end
  385. end
  386.  
  387. function PufferODPakManager:GetStateByKeyList(downloadType, keyList, bSkipDepends, bSkipVidepDepends)
  388.   local resultState = PufferConst.ENUM_DownloadState.Done
  389.   if Client.bEditorSkipDownload then
  390.     return resultState
  391.   end
  392.   if not keyList then
  393.     return resultState
  394.   end
  395.   for i, v in pairs(keyList) do
  396.     local state = PufferConst.ENUM_DownloadState.Done
  397.     if downloadType == PufferConst.ENUM_DownloadType.ODPAK then
  398.       local typeV = type(v)
  399.       if typeV == "number" then
  400.         state = self:GetStateByItemID(v)
  401.       elseif typeV == "string" then
  402.         if StringUtil.starts(v, PufferConst.ODPAKS_RELATIVE_DIR) then
  403.           state = self:GetStateByPakName(v)
  404.         elseif self:GetPakNamesByFeatureID(v) then
  405.           local pakName = next(self:GetPakNamesByFeatureID(v))
  406.           state = self:GetStateByPakName(pakName)
  407.         else
  408.           state = self:GetStateByPath(v)
  409.         end
  410.       end
  411.     elseif downloadType == PufferConst.ENUM_DownloadType.ODPACK then
  412.       state = self:GetStateByPackID(v)
  413.     end
  414.     local curPriority = PufferConst.DownloadStatePriority[state]
  415.     local prePriority = PufferConst.DownloadStatePriority[resultState]
  416.     if curPriority and prePriority and curPriority > prePriority then
  417.       resultState = state
  418.     end
  419.   end
  420.   return resultState
  421. end
  422.  
  423. function PufferODPakManager:GetStateByPakName(pakName, skipCache)
  424.   if Client.bEditorSkipDownload then
  425.     return PufferConst.ENUM_DownloadState.Done
  426.   end
  427.   if pakName == nil or pakName == "" then
  428.     return PufferConst.ENUM_DownloadState.Done
  429.   end
  430.   if pakName == PufferConst.CE_LOCK_PAKNAME then
  431.     return PufferConst.ENUM_DownloadState.Done
  432.   end
  433.   if pakName == PufferConst.LOCK_PAKNAME then
  434.     return PufferConst.ENUM_DownloadState.Done
  435.   end
  436.   local state = PufferConst.ENUM_DownloadState.Done
  437.   if not skipCache then
  438.     local pakNameData = self:GetPakDataByPakName(pakName)
  439.     if pakNameData then
  440.       state = pakNameData.state
  441.       if state == PufferConst.ENUM_DownloadState.Done then
  442.         return PufferConst.ENUM_DownloadState.Done
  443.       end
  444.     end
  445.   end
  446.   if PufferQueue:GetDownloadingTask(pakName) then
  447.     return PufferConst.ENUM_DownloadState.Download
  448.   end
  449.   if PufferQueue:GetWaitTask(pakName) then
  450.     return PufferConst.ENUM_DownloadState.Wait
  451.   end
  452.   if state ~= PufferConst.ENUM_DownloadState.Done then
  453.     return state
  454.   end
  455.   local isPakExist = PufferDownloader.GetPakExist(pakName, skipCache)
  456.   if isPakExist then
  457.     return PufferConst.ENUM_DownloadState.Done
  458.   end
  459.   return PufferConst.ENUM_DownloadState.Not
  460. end
  461.  
  462. function PufferODPakManager:GetStateByPath(path)
  463.   if Client.bEditorSkipDownload then
  464.     return PufferConst.ENUM_DownloadState.Done
  465.   end
  466.   if path == nil or path == "" then
  467.     return PufferConst.ENUM_DownloadState.Done
  468.   end
  469.   local PufferManager = require("client.slua.logic.download.puffer.puffer_manager")
  470.   local pakName = PufferManager.GetPakName(path)
  471.   return self:GetStateByPakName(pakName)
  472. end
  473.  
  474. function PufferODPakManager:GetStateByItemID(itemID)
  475.   if Client.bEditorSkipDownload then
  476.     return PufferConst.ENUM_DownloadState.Done
  477.   end
  478.   itemID = tonumber(itemID)
  479.   if not itemID or itemID <= 0 then
  480.     return PufferConst.ENUM_DownloadState.Done
  481.   end
  482.   if self.itemToPaks[itemID] and self.itemToPaks[itemID].state == PufferConst.ENUM_DownloadState.Done then
  483.     return PufferConst.ENUM_DownloadState.Done
  484.   end
  485.   local paks = self:GetPakNamesByItemID(itemID)
  486.   local state = PufferConst.ENUM_DownloadState.Done
  487.   for pakName, _ in pairs(paks) do
  488.     local tempState = self:GetStateByPakName(pakName)
  489.     if PufferConst.DownloadStatePriority[tempState] > PufferConst.DownloadStatePriority[state] then
  490.       state = tempState
  491.     end
  492.     if state == PufferConst.ENUM_DownloadState.Download then
  493.       break
  494.     end
  495.   end
  496.   self.itemToPaks[itemID].state = state
  497.   return state
  498. end
  499.  
  500. function PufferODPakManager:RestStateByItemID(itemID)
  501.   log(bWriteLog and string.format("PufferODPakManager:RestStateByItemID. itemID=%s", tostring(itemID)))
  502.   if not itemID then
  503.     return
  504.   end
  505.   local state = PufferConst.ENUM_DownloadState.Done
  506.   local paks = self:GetPakNamesByItemID(itemID)
  507.   for pakName, _ in pairs(paks) do
  508.     local pakState = self:GetStateByPakName(pakName, true)
  509.     if pakState ~= PufferConst.ENUM_DownloadState.Done then
  510.       state = PufferConst.ENUM_DownloadState.Not
  511.     end
  512.     local pufferPakData = self:GetPakDataByPakName(pakName)
  513.     if pufferPakData then
  514.       pufferPakData.state = pakState
  515.     end
  516.   end
  517.   log(bWriteLog and "PufferODPakManager:RestStateByItemID. fix state = " .. tostring(state))
  518.   self.itemToPaks[itemID].state = state
  519. end
  520.  
  521. function PufferODPakManager:GetStateByPackID(packID)
  522.   if Client.bEditorSkipDownload then
  523.     return PufferConst.ENUM_DownloadState.Done
  524.   end
  525.   local pack = self.ODPaks[packID]
  526.   if not pack then
  527.     if not PufferDownloader.PufferJsonDownloadReturn and not Client.IsEditor() then
  528.       return PufferConst.ENUM_DownloadState.Not
  529.     end
  530.     return PufferConst.ENUM_DownloadState.Done
  531.   end
  532.   if pack.curCnt == pack.totalCnt then
  533.     pack.state = PufferConst.ENUM_DownloadState.Done
  534.   end
  535.   return pack.state
  536. end
  537.  
  538. function PufferODPakManager:GetPakNamesByItemID(itemID)
  539.   if Client.bEditorSkipDownload then
  540.     return {}, {}
  541.   end
  542.   if not itemID or itemID == 0 then
  543.     return {}, {}
  544.   end
  545.   local PufferManager = require("client.slua.logic.download.puffer.puffer_manager")
  546.   if self.itemToPaks[itemID] and self.itemToPaks[itemID].paks then
  547.     return self.itemToPaks[itemID].paks
  548.   end
  549.   self.itemToPaks[itemID] = {}
  550.   self.itemToPaks[itemID].paks = {}
  551.   local list = self:GetBPPathsByItemID(itemID)
  552.   for _, v in pairs(list) do
  553.     local pakName = PufferManager.GetPakName(v)
  554.     if pakName ~= "" then
  555.       self.itemToPaks[itemID].paks[pakName] = true
  556.     end
  557.   end
  558.   if CDataTable.GetTableData("WeaponDIYList", itemID) and self.ODPaks[PufferConst.EODPackID.DIY] then
  559.     for i, v in pairs(self.ODPaks[PufferConst.EODPackID.DIY].paks) do
  560.       self.itemToPaks[itemID].paks[i] = true
  561.       log(bWriteLog and string.format("PufferODPakManager:GetPakNamesByItemID diy pak:%s", i))
  562.     end
  563.   end
  564.   return self.itemToPaks[itemID].paks
  565. end
  566.  
  567. function PufferODPakManager:GetPakNamesByFeatureID(featureID)
  568.   if not featureID or featureID == "" then
  569.     return nil
  570.   end
  571.   local PufferManager = require("client.slua.logic.download.puffer.puffer_manager")
  572.   if self.itemToPaks[featureID] and self.itemToPaks[featureID].paks then
  573.     return self.itemToPaks[featureID].paks
  574.   end
  575.   local FeatureAssetPathTable = CDataTable.GetTableData("FeatureAssetPathTable", featureID)
  576.   if not FeatureAssetPathTable then
  577.     return nil
  578.   end
  579.   local BPPath = FeatureAssetPathTable.Path
  580.   if not BPPath or BPPath == "" then
  581.     return nil
  582.   end
  583.   self.itemToPaks[featureID] = {}
  584.   self.itemToPaks[featureID].paks = {}
  585.   local pakName = ""
  586.   local StringUtil = require("common.string_util")
  587.   if StringUtil.ends(BPPath, ".mp4") then
  588.     pakName = PufferManager.GetPakNameByVideoPath(BPPath)
  589.   else
  590.     pakName = PufferManager.GetPakName(BPPath)
  591.   end
  592.   if pakName ~= "" then
  593.     self.itemToPaks[featureID].paks[pakName] = true
  594.   else
  595.     log(bWriteLog and "pakName is nil, BPPath = " .. BPPath)
  596.   end
  597.   return self.itemToPaks[featureID].paks
  598. end
  599.  
  600. function PufferODPakManager:GetPakNamesByODPakID(ODPackD)
  601.   if not ODPackD or ODPackD == 0 then
  602.     return {}
  603.   end
  604.   if self.ODPaks[ODPackD] and self.ODPaks[ODPackD].paks then
  605.     return self.ODPaks[ODPackD].paks
  606.   end
  607.   return {}
  608. end
  609.  
  610. function PufferODPakManager:GetIconPathsByItemID(itemID, pathList)
  611.   pathList = pathList or {}
  612.   if not itemID or itemID <= 0 then
  613.     return pathList
  614.   end
  615.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  616.   if itemCfg then
  617.     if itemCfg.ItemSmallIcon and itemCfg.ItemSmallIcon ~= "" then
  618.       table.insert(pathList, itemCfg.ItemSmallIcon)
  619.     end
  620.     if itemCfg.ItemSubType == ENUM_ITEM_SUBTYPE.Bubble_Emote then
  621.       local cfg = CDataTable.GetTableData("IngameBubbleCfg", itemID)
  622.       if cfg and cfg.BubbleEffectIcon and cfg.BubbleEffectIcon ~= "" then
  623.         table.insert(pathList, cfg.BubbleEffectIcon)
  624.       end
  625.     end
  626.   end
  627.   local rareCfg = CDataTable.GetTableData("RareItemCfg", itemID)
  628.   if rareCfg then
  629.     if rareCfg.Path and rareCfg.Path ~= "" then
  630.       table.insert(pathList, rareCfg.Path)
  631.     end
  632.     if rareCfg.PathIcon and rareCfg.PathIcon ~= "" then
  633.       table.insert(pathList, rareCfg.PathIcon)
  634.     end
  635.     if rareCfg.CornerPath and rareCfg.CornerPath ~= "" then
  636.       table.insert(pathList, rareCfg.CornerPath)
  637.     end
  638.   end
  639.   local posterCfg = CDataTable.GetTableData("RareItemSharePosterList", itemID)
  640.   if posterCfg and posterCfg.Poster and posterCfg.Poster ~= "" then
  641.     table.insert(pathList, posterCfg.Poster)
  642.   end
  643.   local vehicleAppliqueCfg = CDataTable.GetTableData("VehicleAppliqueCfg", itemID)
  644.   if vehicleAppliqueCfg and vehicleAppliqueCfg.AppliquePath and vehicleAppliqueCfg.AppliquePath ~= "" then
  645.     table.insert(pathList, vehicleAppliqueCfg.AppliquePath)
  646.   end
  647.   return pathList
  648. end
  649.  
  650. function PufferODPakManager:GetBPPathsByItemID(itemID)
  651.   local BPMapping = self:_GetRelatedItems(itemID)
  652.   local list = {}
  653.   for _, v in pairs(BPMapping) do
  654.     local id = tonumber(v)
  655.     local path = self:GetItemBPPathByItemID(id)
  656.     if path and path ~= "" then
  657.       table.insert(list, path)
  658.     end
  659.     local JKPath = self:GetJKItemBPPathByItemID(id)
  660.     if JKPath and JKPath ~= "" then
  661.       table.insert(list, JKPath)
  662.     end
  663.     local lobbyPath = self:_GetItemLobbyPathByBPID(id)
  664.     if lobbyPath and lobbyPath ~= "" then
  665.       table.insert(list, lobbyPath)
  666.     end
  667.     local HighPathList = self:_GetItemHighPathByBPID(id)
  668.     if HighPathList and next(HighPathList) then
  669.       for key, _path in pairs(HighPathList) do
  670.         if _path and _path ~= "" then
  671.           table.insert(list, _path)
  672.         end
  673.       end
  674.     end
  675.     local mapCfg = CDataTable.GetTableData("BPMappingTable", id)
  676.     if mapCfg and mapCfg.ActorMapping and mapCfg.ActorMapping ~= "" then
  677.       local actorIDMap = StringUtil.split(mapCfg.ActorMapping, "|")
  678.       local ActorVoiceSystem = require("client.slua.logic.actor_voice.logic_actor_voice")
  679.       for i, actorIDStr in pairs(actorIDMap) do
  680.         local actorID = tonumber(actorIDStr)
  681.         if actorID and 0 < actorID then
  682.           local bankPath = ActorVoiceSystem.GetBankPathByActorID(actorID)
  683.           if bankPath and bankPath ~= "" then
  684.             table.insert(list, bankPath)
  685.           end
  686.         end
  687.       end
  688.     end
  689.     local fxData = CDataTable.GetTableData("AvatarWeaponHitFXData", id)
  690.     if fxData and fxData.EffectPath ~= "" then
  691.       table.insert(list, fxData.EffectPath)
  692.     end
  693.     list = self:GetIconPathsByItemID(id, list)
  694.   end
  695.   local BPMappingTable = CDataTable.GetTableData("BPMappingTable", itemID)
  696.   if BPMappingTable and BPMappingTable.DependPath and BPMappingTable.DependPath ~= "" then
  697.     local StringUtil = require("common.string_util")
  698.     local arrDependPaths = StringUtil.split(BPMappingTable.DependPath, "|")
  699.     for _, v in pairs(arrDependPaths) do
  700.       if v and v ~= "" then
  701.         table.insert(list, v)
  702.       end
  703.     end
  704.   end
  705.   list = self:GetIconPathsByItemID(itemID, list)
  706.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  707.   if itemCfg and itemCfg.ItemType == ENUM_ITEM_TYPE.Home then
  708.     local cfg = CDataTable.GetTableData("PlanPH_StructureItemCfg", itemID)
  709.     if cfg and cfg.BPPath then
  710.       table.insert(list, cfg.BPPath)
  711.     end
  712.     cfg = CDataTable.GetTableData("PlanPH_DecorateItemCfg", itemID)
  713.     if cfg and cfg.BPPath then
  714.       table.insert(list, cfg.BPPath)
  715.       if cfg.DependBPPath and cfg.DependBPPath ~= "" then
  716.         table.insert(list, cfg.DependBPPath)
  717.       end
  718.     end
  719.     cfg = CDataTable.GetTableData("PlanPH_WallpaperItemCfg", itemID)
  720.     if cfg and cfg.MatPath then
  721.       table.insert(list, cfg.MatPath)
  722.     end
  723.   end
  724.   if itemCfg and itemCfg.ItemType == ENUM_ITEM_TYPE.CYCLE_Memory_Item and itemCfg.ItemSubType == ENUM_ITEM_SUBTYPE.Aid_Gift then
  725.     local logic_send_gift = require("client.slua.logic.gift.logic_send_gift")
  726.     local giftData = logic_send_gift.GetGiftDataByResID(itemID)
  727.     if giftData then
  728.       table.insert(list, giftData.GiftAni)
  729.     end
  730.   end
  731.   return list
  732. end
  733.  
  734. function PufferODPakManager:CheckAutoDownloadByItemID(itemID)
  735.   itemID = tonumber(itemID)
  736.   if not itemID or itemID <= 0 then
  737.     return false
  738.   end
  739.   local paks = self:GetPakNamesByItemID(itemID)
  740.   local isAuto = false
  741.   for pakName, _ in pairs(paks) do
  742.     if self:CheckAutoDownloadByPakName(pakName) then
  743.       isAuto = true
  744.       break
  745.     end
  746.   end
  747.   return isAuto
  748. end
  749.  
  750. function PufferODPakManager:CheckAutoDownloadByPakName(pakName)
  751.   if pakName == "" then
  752.     return false
  753.   end
  754.   if pakName == PufferConst.CE_LOCK_PAKNAME then
  755.     return false
  756.   end
  757.   if pakName == PufferConst.LOCK_PAKNAME then
  758.     return false
  759.   end
  760.   return PufferQueue:CheckAutoDownloadTask(pakName)
  761. end
  762.  
  763. function PufferODPakManager:GetSizeByKeyList(downloadType, keyList, bSkipDepends)
  764.   local curSize = 0
  765.   local totalSize = 0
  766.   if not keyList then
  767.     return curSize, totalSize
  768.   end
  769.   if downloadType == PufferConst.ENUM_DownloadType.ODPAK and 1 < #keyList then
  770.     local bAllItemID = true
  771.     for i, v in pairs(keyList) do
  772.       if type(v) ~= "number" then
  773.         bAllItemID = false
  774.         break
  775.       end
  776.     end
  777.     if bAllItemID then
  778.       return self:GetSizeByItemIDList(keyList)
  779.     end
  780.   end
  781.   for i, v in pairs(keyList) do
  782.     if downloadType == PufferConst.ENUM_DownloadType.ODPAK then
  783.       if type(v) == "number" then
  784.         local cSize, tSize = self:GetSizeByItemID(v)
  785.         curSize = curSize + cSize
  786.         totalSize = totalSize + tSize
  787.       elseif StringUtil.starts(v, PufferConst.ODPAKS_RELATIVE_DIR) then
  788.         local cSize, tSize = self:GetSizeByPakName(v)
  789.         curSize = curSize + cSize
  790.         totalSize = totalSize + tSize
  791.       elseif self:GetPakNamesByFeatureID(v) then
  792.         local pakName = next(self:GetPakNamesByFeatureID(v))
  793.         local cSize, tSize = self:GetSizeByPakName(pakName)
  794.         curSize = curSize + cSize
  795.         totalSize = totalSize + tSize
  796.       else
  797.         local cSize, tSize = self:GetSizeByPath(v)
  798.         curSize = curSize + cSize
  799.         totalSize = totalSize + tSize
  800.       end
  801.     elseif downloadType == PufferConst.ENUM_DownloadType.ODPACK then
  802.       local cSize, tSize = self:GetSizeByPackID(v)
  803.       curSize = curSize + cSize
  804.       totalSize = totalSize + tSize
  805.     end
  806.   end
  807.   return curSize, totalSize
  808. end
  809.  
  810. function PufferODPakManager:GetSizeByItemIDList(itemIDList)
  811.   local cSize = 0
  812.   local tSize = 0
  813.   local allPaks = {}
  814.   for i, v in pairs(itemIDList) do
  815.     local paks = self:GetPakNamesByItemID(v)
  816.     for pakName, _ in pairs(paks) do
  817.       allPaks[pakName] = true
  818.     end
  819.   end
  820.   for pakName, _ in pairs(allPaks) do
  821.     local flag = false
  822.     local pakData = self:GetPakDataByPakName(pakName)
  823.     if pakData then
  824.       flag = true
  825.       cSize = cSize + pakData.cSize * PufferConst.MB
  826.       tSize = tSize + pakData.tSize * PufferConst.MB
  827.     end
  828.     if not flag then
  829.       tSize = tSize + PufferDownloader.GetFileSizeCompressed(GameFrontendHUD, pakName, true)
  830.     end
  831.   end
  832.   return cSize, tSize
  833. end
  834.  
  835. function PufferODPakManager:GetSizeByItemID(itemID)
  836.   local cSize = 0
  837.   local tSize = 0
  838.   local paks = self:GetPakNamesByItemID(itemID)
  839.   for pakName, _ in pairs(paks) do
  840.     local flag = false
  841.     local pakData = self:GetPakDataByPakName(pakName)
  842.     if pakData then
  843.       flag = true
  844.       cSize = cSize + pakData.cSize * PufferConst.MB
  845.       tSize = tSize + pakData.tSize * PufferConst.MB
  846.     end
  847.     if not flag then
  848.       tSize = tSize + PufferDownloader.GetFileSizeCompressed(GameFrontendHUD, pakName, true)
  849.     end
  850.   end
  851.   if self:GetStateByItemID(itemID) == PufferConst.ENUM_DownloadState.Done then
  852.     cSize = tSize
  853.   end
  854.   return cSize, tSize
  855. end
  856.  
  857. function PufferODPakManager:GetSizeByPath(path)
  858.   local PufferManager = require("client.slua.logic.download.puffer.puffer_manager")
  859.   local cSize, tSize = 0, 0
  860.   local pakName = PufferManager.GetPakName(path)
  861.   cSize, tSize = self:GetSizeByPakName(pakName)
  862.   return cSize, tSize
  863. end
  864.  
  865. function PufferODPakManager:GetSizeByPakName(pakName)
  866.   local cSize, tSize = 0, 0
  867.   if pakName == nil or pakName == "" then
  868.     return 0, 0
  869.   end
  870.   local pakNameData = self:GetPakDataByPakName(pakName)
  871.   if pakNameData then
  872.     cSize = pakNameData.cSize * PufferConst.MB
  873.     tSize = pakNameData.tSize * PufferConst.MB
  874.   end
  875.   if tSize == 0 then
  876.     tSize = PufferDownloader.GetFileSizeCompressed(GameFrontendHUD, pakName, true)
  877.     local MinSize = PufferConst.MB * 0.1
  878.     if tSize == 0 then
  879.       tSize = MinSize
  880.     end
  881.   end
  882.   if self:GetStateByPakName(pakName) == PufferConst.ENUM_DownloadState.Done then
  883.     cSize = tSize
  884.   end
  885.   return cSize, tSize
  886. end
  887.  
  888. function PufferODPakManager:GetSizeByPackID(packID)
  889.   local pack = self.ODPaks[packID]
  890.   if not pack then
  891.     return 0, 0
  892.   end
  893.   return pack.curSize, pack.totalSize
  894. end
  895.  
  896. function PufferODPakManager:GetAllODPakCurSize(skipIDs)
  897.   local curSize = 0
  898.   local totalSize = 0
  899.   local state = PufferConst.ENUM_DownloadState.Done
  900.   for packID, v in pairs(self.ODPaks) do
  901.     if not skipIDs or not skipIDs[packID] then
  902.       curSize = curSize + v.curSize
  903.       totalSize = totalSize + v.totalSize
  904.       if v.curSize > v.totalSize then
  905.         log(bWriteLog and "PufferODPakManager:GetAllODPakCurSize. packID = " .. tostring(packID))
  906.       end
  907.       local curPriority = PufferConst.DownloadStatePriority[v.state]
  908.       local prePriority = PufferConst.DownloadStatePriority[state]
  909.       if curPriority and prePriority and curPriority > prePriority then
  910.         state = v.state
  911.       end
  912.     end
  913.   end
  914.   log(bWriteLog and string.format("PufferODPakManager:GetAllODPakCurSize. curSize=%s, totalSize=%s, state=%s", tostring(curSize), tostring(totalSize), tostring(state)))
  915.   return curSize, totalSize, state
  916. end
  917.  
  918. function PufferODPakManager:ResetPakData(pakName)
  919.   local deleteSize = 0
  920.   PufferDownloader.ClearPakCache(pakName)
  921.   if self.needRecoverBattleData then
  922.     self.battleDeleteFiles[pakName] = true
  923.   else
  924.     local ENUM_DownloadState = PufferConst.ENUM_DownloadState
  925.     local packID, packData = self:GetPackDataByPakName(pakName)
  926.     if packID and packData then
  927.       local pakData = packData.paks[pakName]
  928.       if pakData then
  929.         if pakData.state == ENUM_DownloadState.Done then
  930.           if 0 < packData.curCnt then
  931.             packData.curCnt = packData.curCnt - 1
  932.             packData.curSize = packData.curSize - pakData.tSize
  933.             deleteSize = deleteSize + pakData.tSize
  934.           end
  935.           if packData.curCnt == 0 then
  936.             packData.curSize = 0
  937.             packData.state = ENUM_DownloadState.Not
  938.           elseif packData.curCnt < packData.totalCnt then
  939.             packData.state = ENUM_DownloadState.Pause
  940.           end
  941.           pakData.state = ENUM_DownloadState.Not
  942.         end
  943.         pakData.cSize = 0
  944.         pakData.haveDeleted = true
  945.       end
  946.     end
  947.   end
  948.   return deleteSize
  949. end
  950.  
  951. function PufferODPakManager:RemovePakData(pakName)
  952.   log(bWriteLog and string.format("PufferODPakManager:RemovePakData. pakName=%s", tostring(pakName)))
  953.   local packID, packData = self:GetPackDataByPakName(pakName)
  954.   if packID and packData then
  955.     local pakData = packData.paks[pakName]
  956.     if pakData then
  957.       local subFinishCnt = 0
  958.       if pakData.state == PufferConst.ENUM_DownloadState.Done then
  959.         subFinishCnt = 1
  960.       end
  961.       packData.curCnt = packData.curCnt - subFinishCnt
  962.       packData.totalCnt = packData.totalCnt - 1
  963.       packData.curSize = packData.curSize - pakData.cSize
  964.       packData.totalSize = packData.totalSize - pakData.tSize
  965.       log(bWriteLog and "PufferODPakManager:RemovePakData. packData.curCnt = " .. tostring(packData.curCnt))
  966.       log(bWriteLog and "PufferODPakManager:RemovePakData. packData.totalCnt = " .. tostring(packData.totalCnt))
  967.       if packData.curCnt == packData.totalCnt then
  968.         packData.state = PufferConst.ENUM_DownloadState.Done
  969.       end
  970.       self.PakDatas[pakName] = nil
  971.     end
  972.   end
  973. end
  974.  
  975. function PufferODPakManager:GetItemBPPathByItemID(itemID)
  976.   if self.itemToPaths[itemID] and self.itemToPaths[itemID] ~= "" then
  977.     return self.itemToPaths[itemID]
  978.   end
  979.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  980.   if not itemCfg then
  981.     local ActorVoiceSystem = require("client.slua.logic.actor_voice.logic_actor_voice")
  982.     local bankPath = ActorVoiceSystem.GetBankPathByActorID(itemID)
  983.     if bankPath then
  984.       self.itemToPaths[itemID] = bankPath
  985.       return bankPath
  986.     end
  987.     return nil
  988.   end
  989.   local ID = itemID
  990.   if itemCfg.BPID > 0 and itemCfg.BPID ~= itemID then
  991.     ID = itemCfg.BPID
  992.   end
  993.   local bpCfg = CDataTable.GetTableData("AvatarBPTable", ID)
  994.   if bpCfg ~= nil then
  995.     self.itemToPaths[itemID] = bpCfg.AvatarBPPath
  996.     return bpCfg.AvatarBPPath
  997.   end
  998.   bpCfg = CDataTable.GetTableData("WeaponDIYList", ID)
  999.   if bpCfg ~= nil then
  1000.     self.itemToPaths[itemID] = bpCfg.MeshPath
  1001.     return bpCfg.MeshPath
  1002.   end
  1003.   bpCfg = CDataTable.GetTableData("WeaponBPTable", ID)
  1004.   if bpCfg ~= nil then
  1005.     self.itemToPaths[itemID] = bpCfg.Path
  1006.     return bpCfg.Path
  1007.   end
  1008.   bpCfg = CDataTable.GetTableData("PlaneBPTable", ID)
  1009.   if bpCfg ~= nil then
  1010.     self.itemToPaths[itemID] = bpCfg.Path
  1011.     return bpCfg.Path
  1012.   end
  1013.   bpCfg = CDataTable.GetTableData("VehicleBPTable", ID)
  1014.   if bpCfg ~= nil then
  1015.     self.itemToPaths[itemID] = bpCfg.Path
  1016.     return bpCfg.Path
  1017.   end
  1018.   bpCfg = CDataTable.GetTableData("ConsumableBPTable", ID)
  1019.   if bpCfg ~= nil then
  1020.     self.itemToPaths[itemID] = bpCfg.Path
  1021.     return bpCfg.Path
  1022.   end
  1023.   bpCfg = CDataTable.GetTableData("EmoteBPTable", ID)
  1024.   if bpCfg ~= nil then
  1025.     self.itemToPaths[itemID] = bpCfg.Path
  1026.     return bpCfg.Path
  1027.   end
  1028.   bpCfg = CDataTable.GetTableData("PetDressBlueprintTable", ID)
  1029.   if bpCfg ~= nil then
  1030.     self.itemToPaths[itemID] = bpCfg.Path
  1031.     return bpCfg.Path
  1032.   end
  1033.   bpCfg = CDataTable.GetTableData("CareerBPTable", ID)
  1034.   if bpCfg then
  1035.     self.itemToPaths[itemID] = bpCfg.Path
  1036.     return bpCfg.Path
  1037.   end
  1038.   bpCfg = CDataTable.GetTableData("GiftBPTable", ID)
  1039.   if bpCfg ~= nil then
  1040.     self.itemToPaths[itemID] = bpCfg.GiftAniPath
  1041.     return bpCfg.GiftAniPath
  1042.   end
  1043.   bpCfg = CDataTable.GetTableData("HallThemeItem", ID)
  1044.   if bpCfg then
  1045.     self.itemToPaths[itemID] = bpCfg.Path
  1046.     return bpCfg.Path
  1047.   end
  1048.   bpCfg = CDataTable.GetTableData("EffectItemBPTable", ID)
  1049.   if bpCfg ~= nil then
  1050.     self.itemToPaths[itemID] = bpCfg.Path
  1051.     return bpCfg.Path
  1052.   end
  1053.   bpCfg = CDataTable.GetTableData("PetSwitchEffectBPTable", ID)
  1054.   if bpCfg ~= nil then
  1055.     self.itemToPaths[itemID] = bpCfg.Path
  1056.     return bpCfg.Path
  1057.   end
  1058.   bpCfg = CDataTable.GetTableData("3DIconBPTable", ID)
  1059.   if bpCfg ~= nil then
  1060.     self.itemToPaths[itemID] = bpCfg.Path
  1061.     return bpCfg.Path
  1062.   end
  1063.   bpCfg = CDataTable.GetTableData("DecalBPTable", ID)
  1064.   if bpCfg ~= nil then
  1065.     self.itemToPaths[itemID] = bpCfg.Path
  1066.     return bpCfg.Path
  1067.   end
  1068.   if itemCfg.ItemSubType == ENUM_ITEM_SUBTYPE.Voice_Pack or itemCfg.ItemSubType == ENUM_ITEM_SUBTYPE.Electronic_Eecord then
  1069.     local ActorVoiceSystem = require("client.slua.logic.actor_voice.logic_actor_voice")
  1070.     local path = ActorVoiceSystem.GetBankPath(itemID)
  1071.     self.itemToPaths[itemID] = path
  1072.     return path
  1073.   end
  1074.   return nil
  1075. end
  1076.  
  1077. function PufferODPakManager:GetJKItemBPPathByItemID(itemID)
  1078.   local PublishRegionMacros = require("client.slua.config.ClientMacros.PublishRegionMacros")
  1079.   if not PublishRegionMacros.IsJapanOrKorea() then
  1080.     return
  1081.   end
  1082.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  1083.   if not itemCfg then
  1084.     return
  1085.   end
  1086.   local ID = itemCfg.JKBPID
  1087.   if ID == 0 or ID == itemCfg.BPID or ID == nil then
  1088.     return
  1089.   end
  1090.   local bpCfg = CDataTable.GetTableData("AvatarBPTable", ID)
  1091.   if bpCfg ~= nil then
  1092.     return bpCfg.AvatarBPPath
  1093.   end
  1094.   bpCfg = CDataTable.GetTableData("WeaponDIYList", ID)
  1095.   if bpCfg ~= nil then
  1096.     return bpCfg.MeshPath
  1097.   end
  1098.   bpCfg = CDataTable.GetTableData("WeaponBPTable", ID)
  1099.   if bpCfg ~= nil then
  1100.     return bpCfg.Path
  1101.   end
  1102.   bpCfg = CDataTable.GetTableData("PlaneBPTable", ID)
  1103.   if bpCfg ~= nil then
  1104.     return bpCfg.Path
  1105.   end
  1106.   bpCfg = CDataTable.GetTableData("VehicleBPTable", ID)
  1107.   if bpCfg ~= nil then
  1108.     return bpCfg.Path
  1109.   end
  1110.   bpCfg = CDataTable.GetTableData("ConsumableBPTable", ID)
  1111.   if bpCfg ~= nil then
  1112.     return bpCfg.Path
  1113.   end
  1114.   bpCfg = CDataTable.GetTableData("EmoteBPTable", ID)
  1115.   if bpCfg ~= nil then
  1116.     return bpCfg.Path
  1117.   end
  1118.   bpCfg = CDataTable.GetTableData("PetDressBlueprintTable", ID)
  1119.   if bpCfg ~= nil then
  1120.     return bpCfg.Path
  1121.   end
  1122.   bpCfg = CDataTable.GetTableData("CareerBPTable", ID)
  1123.   if bpCfg then
  1124.     return bpCfg.Path
  1125.   end
  1126.   bpCfg = CDataTable.GetTableData("HallThemeItem", ID)
  1127.   if bpCfg then
  1128.     return bpCfg.Path
  1129.   end
  1130.   return nil
  1131. end
  1132.  
  1133. function PufferODPakManager:_InitAttachmentSkinIDListCache()
  1134.   if self._attachmentSkinIDInited then
  1135.     return
  1136.   end
  1137.   log(bWriteLog and "PufferODPakManager:_InitAttachmentSkinIDListCache.")
  1138.   self._attachmentSkinIDMap = {}
  1139.   self._attachmentSkinIDInited = true
  1140.   local cfgs = CDataTable.GetTable("WeaponAttrBPTable")
  1141.   for BPID, cfg in pairs(cfgs) do
  1142.     local list = self:_GetAttachmentSkinIDListByConfig(cfg)
  1143.     self._attachmentSkinIDMap[BPID] = list
  1144.   end
  1145. end
  1146.  
  1147. function PufferODPakManager:_GetAttachmentSkinIDListByConfig(cfg)
  1148.   if cfg == nil then
  1149.     return nil
  1150.   end
  1151.   local idList = {}
  1152.   if cfg.AttachmentSkinIDList and cfg.AttachmentSkinIDList ~= "" then
  1153.     for i, v in pairs(StringUtil.split(cfg.AttachmentSkinIDList, "|")) do
  1154.       local attachmentSkinID = StringUtil.split(v, "-")[2]
  1155.       table.insert(idList, tonumber(attachmentSkinID))
  1156.     end
  1157.   end
  1158.   if cfg.PendantID > 0 then
  1159.     table.insert(idList, cfg.PendantID)
  1160.   end
  1161.   if cfg.DeadInventoryBoxIDs and cfg.DeadInventoryBoxIDs ~= "" then
  1162.     for i, v in pairs(StringUtil.split(cfg.DeadInventoryBoxIDs, "|")) do
  1163.       table.insert(idList, tonumber(v))
  1164.     end
  1165.   end
  1166.   if not next(idList) then
  1167.     idList = nil
  1168.   end
  1169.   return idList
  1170. end
  1171.  
  1172. function PufferODPakManager:_GetAttachmentSkinIDList(BPID)
  1173.   if self.isLowMemoryDevice then
  1174.     local cfg = CDataTable.GetTableData("WeaponAttrBPTable", BPID)
  1175.     return cfg and self:_GetAttachmentSkinIDListByConfig(cfg)
  1176.   else
  1177.     self:_InitAttachmentSkinIDListCache()
  1178.     return self._attachmentSkinIDMap and self._attachmentSkinIDMap[BPID]
  1179.   end
  1180. end
  1181.  
  1182. function PufferODPakManager:_GetRelatedItems(itemID, bNotMapping)
  1183.   if self.itemToItems[itemID] then
  1184.     return self.itemToItems[itemID]
  1185.   end
  1186.   local depend = {}
  1187.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  1188.   if not itemCfg then
  1189.     if CDataTable.GetTableData("VoiceActorCfg", itemID) then
  1190.       self.itemToItems[itemID] = {itemID}
  1191.       return {itemID}
  1192.     end
  1193.     return depend
  1194.   end
  1195.   local ModuleManager = require("client.module_framework.ModuleManager")
  1196.   local ItemUpgradeMgr = ModuleManager.GetModule(ModuleManager.LobbyModuleConfig.ItemUpgradeManager)
  1197.   local upgradeCfgList = ItemUpgradeMgr:GetUpgradeGroupByItemID(itemID)
  1198.   local attachmentSkinIDList = self:_GetAttachmentSkinIDList(itemCfg.BPID)
  1199.   local BackpackMappingCfg = CDataTable.GetTableData("BackpackMapping", itemID)
  1200.   if BackpackMappingCfg then
  1201.     depend[BackpackMappingCfg.SkinItemIDLv1] = true
  1202.     depend[BackpackMappingCfg.SkinItemIDLv2] = true
  1203.     depend[BackpackMappingCfg.SkinItemIDLv3] = true
  1204.     depend[BackpackMappingCfg.LobbyShowItemID] = true
  1205.   elseif upgradeCfgList and next(upgradeCfgList) then
  1206.     local upgradeItemID = 0
  1207.     for _, v in pairs(upgradeCfgList) do
  1208.       if upgradeItemID == 0 then
  1209.         upgradeItemID = v.itemID
  1210.       end
  1211.       depend[v.ItemID] = true
  1212.       local list = self:_GetAttachmentSkinIDList(v.ItemID)
  1213.       if list then
  1214.         for _, vv in pairs(list) do
  1215.           depend[vv] = true
  1216.         end
  1217.       end
  1218.     end
  1219.     local groupID = ItemUpgradeMgr:GetUpgradeCfg(upgradeItemID).GroupID
  1220.     groupID = ItemUpgradeMgr:GetNormalGroupID(groupID)
  1221.     log(bWriteLog and string.format("PufferODPakManager:_GetRelatedItems groupdId=%s", tostring(groupID)))
  1222.     local partIDList = ItemUpgradeMgr:GetPartIDList(groupID)
  1223.     local isCanSetRefitCfg = ItemUpgradeMgr:IsCanSetRefitCfgTableInfo(groupID)
  1224.     for _, partID in pairs(partIDList) do
  1225.       if isCanSetRefitCfg then
  1226.         local diffColorPartID = ItemUpgradeMgr:PartIDSwitch(partID, true)
  1227.         if diffColorPartID ~= partID and diffColorPartID then
  1228.           depend[diffColorPartID] = true
  1229.         end
  1230.       end
  1231.       depend[partID] = true
  1232.     end
  1233.     if isCanSetRefitCfg then
  1234.       local refitCfg = ItemUpgradeMgr:GetRefitCfgData(groupID)
  1235.       if refitCfg and refitCfg.refitGroupID then
  1236.         local refitUpgradeCfgList = ItemUpgradeMgr:GetUpgradeGroupByID(refitCfg.refitGroupID)
  1237.         if refitUpgradeCfgList then
  1238.           for _, v in pairs(refitUpgradeCfgList) do
  1239.             depend[v.ItemID] = true
  1240.             local list = self:_GetAttachmentSkinIDList(v.ItemID)
  1241.             if list then
  1242.               for _, vv in pairs(list) do
  1243.                 depend[vv] = true
  1244.               end
  1245.             end
  1246.           end
  1247.         end
  1248.       end
  1249.     end
  1250.   elseif attachmentSkinIDList then
  1251.     for i, v in pairs(attachmentSkinIDList) do
  1252.       depend[v] = true
  1253.     end
  1254.   end
  1255.   local cfg = CDataTable.GetTableData("WeaponSkinMapping", itemID)
  1256.   if cfg then
  1257.     depend[cfg.WeaponID] = true
  1258.   end
  1259.   cfg = CDataTable.GetTableData("VehiclePlaneSkinMapping", itemID)
  1260.   if cfg then
  1261.     depend[cfg.OrginalID] = true
  1262.   end
  1263.   cfg = CDataTable.GetTableData("AvatarSuitsTable", itemID)
  1264.   if cfg then
  1265.     for _, v in pairs(StringUtil.split(cfg.MaleSuits, "|")) do
  1266.       local id = tonumber(v)
  1267.       if id and 0 < id then
  1268.         depend[id] = true
  1269.       end
  1270.     end
  1271.     for _, v in pairs(StringUtil.split(cfg.FemaleSuits, "|")) do
  1272.       local id = tonumber(v)
  1273.       if id and 0 < id then
  1274.         depend[id] = true
  1275.       end
  1276.     end
  1277.   end
  1278.   local featuresItem = CDataTable.GetTableData("FeaturesItems", itemID)
  1279.   if featuresItem then
  1280.     local VersionUtil = require("client.common.version_util")
  1281.     local versionNum = VersionUtil.GetCurVersionNumber()
  1282.     local features = StringUtil.split(featuresItem.Features, ";")
  1283.     for _, v in ipairs(features) do
  1284.       if v then
  1285.         local featureCfg = CDataTable.GetTableData("FeaturesConfig", tonumber(v))
  1286.         if featureCfg then
  1287.           if featureCfg.ExpressionID and 0 < featureCfg.ExpressionID then
  1288.             depend[featureCfg.ExpressionID] = true
  1289.           end
  1290.           if featureCfg.EnterExpressionID and 0 < featureCfg.EnterExpressionID and featureCfg.EnterExpressionID ~= featureCfg.ExpressionID then
  1291.             depend[featureCfg.EnterExpressionID] = true
  1292.           end
  1293.           if featureCfg.FightExpressionID and 0 < featureCfg.FightExpressionID and featureCfg.FightExpressionID ~= featureCfg.EnterExpressionID then
  1294.             depend[featureCfg.FightExpressionID] = true
  1295.           end
  1296.         end
  1297.       end
  1298.     end
  1299.   end
  1300.   cfg = CDataTable.GetTableData("EmoteBPTable", itemID)
  1301.   if cfg and cfg.LobbyEmoteAdapt ~= "" then
  1302.     for _, v in pairs(StringUtil.split(cfg.LobbyEmoteAdapt, "|")) do
  1303.       local id = tonumber(v)
  1304.       if id and 0 < id then
  1305.         depend[id] = true
  1306.       end
  1307.     end
  1308.   end
  1309.   local LogicGoldenSuit = require("client.slua.logic.golden_suit.logic_golden_suit")
  1310.   local period = LogicGoldenSuit.GetPeriodByItemId(itemID)
  1311.   if period then
  1312.     local goldList = LogicGoldenSuit.GetItemIDListByPeriod(period)
  1313.     for _, v in pairs(goldList) do
  1314.       depend[v] = true
  1315.     end
  1316.     local CallStatueActionIDMap = {
  1317.       [3] = 12219840,
  1318.       [4] = 12219841,
  1319.       [5] = 12219842
  1320.     }
  1321.     local actionID = CallStatueActionIDMap[period]
  1322.     if actionID then
  1323.       depend[actionID] = true
  1324.     end
  1325.   end
  1326.   local SpecialGlideID = LogicGoldenSuit.GetSpecialGlideID(itemID)
  1327.   depend[SpecialGlideID] = true
  1328.   local logic_pet = ModuleManager.GetModule(ModuleManager.CommonModuleConfig.logic_pet)
  1329.   local PetID = logic_pet:GetAssociatedPetID(itemID)
  1330.   if PetID then
  1331.     depend[PetID] = true
  1332.     local petDependRes = logic_pet:GetPetDependResource(PetID)
  1333.     if petDependRes then
  1334.       for _, v in pairs(petDependRes) do
  1335.         depend[v] = true
  1336.       end
  1337.     end
  1338.   end
  1339.   local UpVehicleModule = ModuleManager.GetModule(ModuleManager.LobbyModuleConfig.UpVehicle)
  1340.   local carItemIDS = UpVehicleModule:GetAssociatedCars(itemID)
  1341.   if carItemIDS then
  1342.     for _, v in pairs(carItemIDS) do
  1343.       depend[v] = true
  1344.     end
  1345.   end
  1346.   local ModuleManager = require("client.module_framework.ModuleManager")
  1347.   local LogicMultiItemModule = ModuleManager.GetModule(ModuleManager.LobbyModuleConfig.LogicMultiItemModule)
  1348.   local MultiList = LogicMultiItemModule:GetMultiListByItemID(itemID)
  1349.   for key, value in pairs(MultiList) do
  1350.     if value then
  1351.       depend[value.ItemID] = true
  1352.     end
  1353.   end
  1354.   local VehiclePlateLicenseUtil = require("GameLua.Activity.Commercialize.GamePlay.Vehicle.VehiclePlateLicenseUtil")
  1355.   local vehicleItems = VehiclePlateLicenseUtil.GetDownLoadList(itemID)
  1356.   if vehicleItems then
  1357.     for _, v in pairs(vehicleItems) do
  1358.       depend[v] = true
  1359.     end
  1360.   end
  1361.   local logic_emote = require("GameLua.Mod.Library.GamePlay.Avatar.Emote.logic_emote")
  1362.   local MileStoneDownloadList = logic_emote.GetMileStoneDownloadList(itemID)
  1363.   if MileStoneDownloadList then
  1364.     for ItemID, v in pairs(MileStoneDownloadList) do
  1365.       if ItemID and 0 < ItemID then
  1366.         depend[ItemID] = true
  1367.       end
  1368.     end
  1369.   end
  1370.   local LogicParticleEmote = ModuleManager.GetModule(ModuleManager.LobbyModuleConfig.LogicParticleEmote)
  1371.   if LogicParticleEmote:IsParticleEmote(itemID) then
  1372.     local HighLevelEmoteID = LogicParticleEmote:GetParticleEmoteID(itemID)
  1373.     depend[HighLevelEmoteID] = true
  1374.   elseif LogicParticleEmote:Is2LevelParticleEmote(itemID) then
  1375.     local BaseEmoteID = LogicParticleEmote:GetBaseID(itemID)
  1376.     depend[BaseEmoteID] = true
  1377.   end
  1378.   cfg = CDataTable.GetTableData("VehiclePlaneSkinMapping", itemID)
  1379.   if cfg and cfg.OrginalID then
  1380.     depend[cfg.OrginalID] = true
  1381.   end
  1382.   if not bNotMapping then
  1383.     cfg = CDataTable.GetTableData("BPMappingTable", itemID)
  1384.     if cfg and cfg.BPMapping and cfg.BPMapping ~= "" then
  1385.       local MapList = StringUtil.split(cfg.BPMapping, "|")
  1386.       for i, v in pairs(MapList) do
  1387.         local id = tonumber(v)
  1388.         if id and 0 < id then
  1389.           depend[id] = true
  1390.           local tmpList = self:_GetRelatedItems(id, true)
  1391.           for _, vTmp in pairs(tmpList) do
  1392.             local idTmp = tonumber(vTmp)
  1393.             if idTmp and 0 < idTmp then
  1394.               depend[idTmp] = true
  1395.             end
  1396.           end
  1397.         end
  1398.       end
  1399.     end
  1400.   end
  1401.   depend[itemID] = true
  1402.   local list = {}
  1403.   for i, _ in pairs(depend) do
  1404.     table.insert(list, i)
  1405.   end
  1406.   if not bNotMapping then
  1407.     self.itemToItems[itemID] = list
  1408.   end
  1409.   return list
  1410. end
  1411.  
  1412. function PufferODPakManager:_GetItemLobbyPathByBPID(itemID)
  1413.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  1414.   if not itemCfg then
  1415.     return nil
  1416.   end
  1417.   local ID = itemID
  1418.   if itemCfg.BPID > 0 and itemCfg.BPID ~= itemID then
  1419.     ID = itemCfg.BPID
  1420.   end
  1421.   local bpCfg = CDataTable.GetTableData("AvatarBPTable", ID)
  1422.   if bpCfg ~= nil then
  1423.     return bpCfg.LobbyPath
  1424.   end
  1425.   bpCfg = CDataTable.GetTableData("WeaponBPTable", ID)
  1426.   if bpCfg ~= nil then
  1427.     return bpCfg.LobbyPath
  1428.   end
  1429.   bpCfg = CDataTable.GetTableData("PlaneBPTable", ID)
  1430.   if bpCfg ~= nil then
  1431.     return bpCfg.LobbyPath
  1432.   end
  1433.   bpCfg = CDataTable.GetTableData("VehicleBPTable", ID)
  1434.   if bpCfg ~= nil then
  1435.     return bpCfg.LobbyPath
  1436.   end
  1437.   bpCfg = CDataTable.GetTableData("ConsumableBPTable", ID)
  1438.   if bpCfg ~= nil then
  1439.     return bpCfg.LobbyPath
  1440.   end
  1441.   bpCfg = CDataTable.GetTableData("EmoteBPTable", ID)
  1442.   if bpCfg ~= nil then
  1443.     return bpCfg.LobbyPath
  1444.   end
  1445.   bpCfg = CDataTable.GetTableData("EffectItemBPTable", ID)
  1446.   if bpCfg ~= nil then
  1447.     return bpCfg.LobbyPath
  1448.   end
  1449.   return nil
  1450. end
  1451.  
  1452. function PufferODPakManager:_GetItemHighPathByBPID(itemID)
  1453.   local itemCfg = CDataTable.GetTableData("Item", itemID)
  1454.   if not itemCfg then
  1455.     return nil
  1456.   end
  1457.   local ID = itemID
  1458.   if itemCfg.BPID > 0 and itemCfg.BPID ~= itemID then
  1459.     ID = itemCfg.BPID
  1460.   end
  1461.   local bpCfg = CDataTable.GetTableData("AvatarBPTable", ID)
  1462.   if bpCfg ~= nil and 0 < bpCfg.DeviceLevel then
  1463.     local TCDeviceLevel = Client.GetTCDeviceLevel()
  1464.     if TCDeviceLevel >= bpCfg.DeviceLevel then
  1465.       local list = {}
  1466.       table.insert(list, bpCfg.AvatarBPPathHigh)
  1467.       table.insert(list, bpCfg.LobbyPathHigh)
  1468.       return list
  1469.     end
  1470.   end
  1471.   return {}
  1472. end
  1473.  
  1474. function PufferODPakManager:GetPakIDAndSizeByPakName(pakName)
  1475.   if pakName == nil or pakName == "" then
  1476.     return nil, 0
  1477.   end
  1478.   for k, v in pairs(self.ODPaks) do
  1479.     if v.paks[pakName] then
  1480.       return k, v.paks[pakName].tSize
  1481.     end
  1482.   end
  1483.   return nil, 0
  1484. end
  1485.  
  1486. function PufferODPakManager:DumpUGCDebugInfo()
  1487.   if not bWriteLog then
  1488.     return
  1489.   end
  1490.   local str = ""
  1491.   for packID, v1 in pairs(self.ODPaks) do
  1492.     if v1.isVirtual then
  1493.       str = str .. string.format("PufferODPakManager:DumpUGCDebugInfo begin ---------------- packID:%s,curSize:%.2f,totalSize:%.2f,done:%s\n", tostring(packID), v1.curSize, v1.totalSize, tostring(v1.state == 3))
  1494.       for pakName, v2 in pairs(v1.paks) do
  1495.         str = str .. string.format("PufferODPakManager:DumpUGCDebugInfo packID:%s,pakName:%s,curSize:%.2f,totalSize:%.2f,done:%s\n", tostring(packID), pakName, v2.cSize, v2.tSize, tostring(v2.state == 3))
  1496.       end
  1497.     end
  1498.   end
  1499.   log(str)
  1500.   str = ""
  1501.   for itemID, Paks in pairs(self.itemToPaks) do
  1502.     str = str .. "UGCPAKInfo,ItemID:" .. tostring(itemID) .. " , Paks : {"
  1503.     for pakName, _ in pairs(Paks.paks) do
  1504.       str = str .. pakName .. ","
  1505.     end
  1506.     str = str .. "}\n"
  1507.   end
  1508.   log(str)
  1509.   return str
  1510. end
  1511.  
  1512. function PufferODPakManager:UpdateLocalPkgIntoCSC(existPaks)
  1513.   if not Client.USFSIsNewestVersion() then
  1514.     log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC return for not Client.USFSIsNewestVersion()")
  1515.     return
  1516.   end
  1517.   local UpdateLocalPkgOnceCount = HDmpveRemote.HDmpveRemoteConfigGetInt("UpdateLocalPkgOnceCount", 0)
  1518.   if UpdateLocalPkgOnceCount <= 0 then
  1519.     log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC return for UpdateLocalPkgOnceCount <= 0")
  1520.     return
  1521.   end
  1522.   log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC beg UpdateLocalPkgOnceCount: " .. UpdateLocalPkgOnceCount)
  1523.   existPaks = existPaks or {}
  1524.   local TmpArrayData = {}
  1525.   for pakName, _ in pairs(existPaks) do
  1526.     if string.find(pakName, ".pak") then
  1527.       local FilePath = Client.ProjectSavedDir() .. "Paks/" .. pakName
  1528.       if not Client.IsFileExistInCSCWithCheck(pakName) then
  1529.         log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC collect local FilePath: " .. FilePath)
  1530.         table.insert(TmpArrayData, FilePath)
  1531.       else
  1532.         log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC existPaks pakName: " .. pakName)
  1533.       end
  1534.       if UpdateLocalPkgOnceCount <= #TmpArrayData then
  1535.         break
  1536.       end
  1537.     end
  1538.   end
  1539.   if #TmpArrayData then
  1540.     log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC USFSCacheSysContextUpdatePkg TmpArrayData: " .. tostring(#TmpArrayData))
  1541.     Client.USFSCacheSysContextUpdatePkg(TmpArrayData)
  1542.   end
  1543.   log(bWriteLog and "PufferODPakManager:UpdateLocalPkgIntoCSC end")
  1544. end
  1545.  
  1546. function PufferODPakManager:UpdatePkgCheckInfo(existPaks)
  1547.   local CacheSysContextStartSwitch = HDmpveRemote.HDmpveRemoteConfigGetInt("USFSCacheSysContextStart", 0)
  1548.   if CacheSysContextStartSwitch == 0 then
  1549.     return
  1550.   end
  1551.   log(bWriteLog and "PufferODPakManager:UpdatePkgCheckInfo beg")
  1552.   local PufferODPakDelList = {
  1553.     "ODPaks/fff3aff29028cff62c90d6205d2a9882df19d569.pak",
  1554.   }
  1555.   local USFSKickoutPkgName = HDmpveRemote.HDmpveRemoteConfigGetString("USFSKickoutPkgName", "")
  1556.   local tempList = StringUtil.split(USFSKickoutPkgName, ",")
  1557.   for _, KickPkgInfo in pairs(tempList) do
  1558.     local PkgName = KickPkgInfo
  1559.     if string.find(KickPkgInfo, "/Game/") then
  1560.       PkgName = GCPufferDownloader.GetODPakName(Puffer, KickPkgInfo)
  1561.     else
  1562.       PkgName = "ODPaks/" .. KickPkgInfo .. ".pak"
  1563.     end
  1564.     if self.ODPaksNameToConHash[PkgName] then
  1565.       self.ODPaksNameToConHash[PkgName] = "0202020202020202020202020202020202020202"
  1566.       log("PufferODPakManager:InitODPack Kickout: " .. PkgName .. " " .. self.ODPaksNameToConHash[PkgName])
  1567.     end
  1568.   end
  1569.   local ScriptHelperClient = import("ScriptHelperClient")
  1570.   local data = ScriptHelperClient.LoadFileToArrayByFullPath(Client.ProjectDir() .. "Config/CommCRC.ini")
  1571.   if data then
  1572.     local StringUtil = require("common.string_util")
  1573.     data = StringUtil.split(data, "\n")
  1574.     for _, Info in pairs(data) do
  1575.       local PkgName = string.gsub(Info, "[\n\r]", "")
  1576.       PkgName = "ODPaks/" .. PkgName .. ".pak"
  1577.       if self.ODPaksNameToConHash[PkgName] then
  1578.         self.ODPaksNameToConHash[PkgName] = "0202020202020202020202020202020202020202"
  1579.         log("PufferODPakManager:InitODPack CommCRC.ini Kickout: " .. PkgName .. " " .. self.ODPaksNameToConHash[PkgName])
  1580.       end
  1581.     end
  1582.   end
  1583.   for __, PkgName in pairs(PufferODPakDelList) do
  1584.     self.ODPaksNameToConHash[PkgName] = "0202020202020202020202020202020202020202"
  1585.     log("PufferODPakManager:InitODPack PufferODPakDelList Kickout: " .. PkgName .. " " .. self.ODPaksNameToConHash[PkgName])
  1586.   end
  1587.   local USFSCacheSysContexInit = HDmpveRemote.HDmpveRemoteConfigGetInt("USFSCacheSysContexInit", 1)
  1588.   if USFSCacheSysContexInit == 1 then
  1589.     log(bWriteLog and "PufferODPakManager:UpdatePkgCheckInfo Client.USFSCacheSysContexInit")
  1590.     Client.USFSCacheSysContexInit(self.ODPaksNameToConHash)
  1591.   end
  1592.   self.ODPaksNameToConHash = nil
  1593.   local ArrayData = {}
  1594.   ArrayData[1] = "ShadowTrackerExtra/Content/Paks/res_cachesyspkgdiffmini_obb.pak"
  1595.   Client.USFSCacheSysContextUpdatePkgDiff(ArrayData)
  1596.   self:UpdateLocalPkgIntoCSC(existPaks)
  1597.   log(bWriteLog and "PufferODPakManager:UpdatePkgCheckInfo end")
  1598. end
  1599.  
  1600. function PufferODPakManager:GetPakDataByPakName(pakName)
  1601.   local pakData = self.PakDatas and self.PakDatas[pakName]
  1602.   if pakData then
  1603.     return pakData.data
  1604.   end
  1605.   return nil
  1606. end
  1607.  
  1608. function PufferODPakManager:GetPackDataByPakName(pakName)
  1609.   if not pakName then
  1610.     return
  1611.   end
  1612.   local pakData = self.PakDatas[pakName]
  1613.   if pakData then
  1614.     return pakData.packID, self.ODPaks[pakData.packID]
  1615.   end
  1616.   return nil, nil
  1617. end
  1618.  
  1619. function PufferODPakManager:OnDownloadFinish(task, isSuccess, errorCode, IsUGC)
  1620.   local pakName = task.pakName
  1621.   local ODPackID, packData = self:GetPackDataByPakName(pakName)
  1622.   if ODPackID and packData then
  1623.     local pakData = packData.paks[pakName]
  1624.     if pakData then
  1625.       local PufferTlog = require("client.slua.logic.download.report.puffer_tlog")
  1626.       if isSuccess or errorCode == 1 and not Client.IsDevelopment() then
  1627.         pakData.cSize = pakData.tSize
  1628.         packData.curSize = packData.curSize + pakData.tSize
  1629.         packData.curCnt = packData.curCnt + 1
  1630.         pakData.state = PufferConst.ENUM_DownloadState.Done
  1631.         if pakData.tSize >= 5 then
  1632.           PufferTlog.SendTLog(task.from, PufferTlog.Enum_TLog_Optype.Finish, pakName)
  1633.         end
  1634.         if packData.curCnt >= packData.totalCnt then
  1635.           packData.curCnt = packData.totalCnt
  1636.           packData.curSize = packData.totalSize
  1637.           packData.state = PufferConst.ENUM_DownloadState.Done
  1638.           if not IsUGC then
  1639.             PufferDownloader.SetDownloadKeyRecord(ODPackID, true)
  1640.             PufferTlog.SendTLog(task.from, PufferTlog.Enum_TLog_Optype.Finish, ODPackID, nil, ODPackID == PufferConst.EODPackID.PREFETCH_ODPACKID)
  1641.             local PufferSwitch = require("client.slua.logic.download.puffer_switch")
  1642.             log(bWriteLog and string.format("puffer_odpak_downloader:OnDownloadFinish pakName:%s ODPackID:%s", pakName, ODPackID))
  1643.             local ModuleManager = require("client.module_framework.ModuleManager")
  1644.             local ui_navigation_manager = ModuleManager.GetModule(ModuleManager.CommonModuleConfig.ui_navigation_manager)
  1645.             local keyName = ui_navigation_manager:GetTopUIName()
  1646.             log(bWriteLog and string.format("puffer_odpak_downloader:OnDownloadFinish keyName:%s ODPackDownloadFinishPopUpSwitch:%s", keyName, tostring(PufferSwitch.ODPackDownloadFinishPopUpSwitch)))
  1647.             self:JumpODPack(ODPackID)
  1648.             log(bWriteLog and string.format("puffer_odpak_downloader:OnDownloadFinish ODPack:%s", ODPackID))
  1649.           end
  1650.         end
  1651.       else
  1652.         pakData.state = PufferConst.ENUM_DownloadState.Error
  1653.       end
  1654.     end
  1655.   end
  1656. end
  1657.  
  1658. function PufferODPakManager:HandleEnterFight()
  1659.   log(bWriteLog and "PufferODPakManager:HandleEnterFight. self.enableSaveODPakDataToFile = " .. tostring(self.enableSaveODPakDataToFile))
  1660.   if not self.enableSaveODPakDataToFile then
  1661.     return
  1662.   end
  1663.   self.needRecoverBattleData = true
  1664.   self.battleDeleteFiles = {}
  1665.   xpcall(self.SaveODPakDataToFile, function()
  1666.     log(bWriteLog and "PufferODPakManager:HandleEnterFight. save error")
  1667.     self.needRecoverBattleData = false
  1668.   end, self)
  1669.   if self.needRecoverBattleData then
  1670.     self:ClearBattleMemory()
  1671.   end
  1672. end
  1673.  
  1674. function PufferODPakManager:HandleExitFight()
  1675.   log(bWriteLog and "PufferODPakManager:HandleExitFight. self.enableSaveODPakDataToFile = " .. tostring(self.enableSaveODPakDataToFile))
  1676.   log(bWriteLog and "PufferODPakManager:HandleExitFight. self.needRecoverData = " .. tostring(self.needRecoverBattleData))
  1677.   if not self.enableSaveODPakDataToFile or not self.needRecoverBattleData then
  1678.     return
  1679.   end
  1680.   self.needRecoverBattleData = false
  1681.   local loadComplete = true
  1682.   xpcall(self.LoadODPakDataFromFile, function()
  1683.     log(bWriteLog and "PufferODPakManager:HandleExitFight. load error")
  1684.     loadComplete = false
  1685.   end, self)
  1686.   if loadComplete and next(self.ODPaks) then
  1687.     self:RecoverBattleMemory()
  1688.   else
  1689.     local ret = GCPufferDownloader.ReturnLocalFiles(PufferDownloader.DOWNLOAD_DIR_RELATIVE .. PufferDownloader.DOWNLOAD_ODPAKS_RELATIVE, "")
  1690.     local existPaks = {}
  1691.     for _, filename in pairs(ret) do
  1692.       existPaks[PufferDownloader.DOWNLOAD_ODPAKS_RELATIVE .. filename] = true
  1693.     end
  1694.     self:InitODPaks(existPaks)
  1695.   end
  1696. end
  1697.  
  1698. function PufferODPakManager:GetSaveFilePath()
  1699.   return "ODPakData.txt"
  1700. end
  1701.  
  1702. function PufferODPakManager:SaveODPakDataToFile()
  1703.   log(bWriteLog and "PufferODPakManager:SaveODPakDataToFile.")
  1704.   local json = require("common.json_util")
  1705.   local encode = json.encode(self.ODPaks)
  1706.   Client.SaveStringToFile(encode, self:GetSaveFilePath())
  1707.   self:ClearBattleMemory()
  1708. end
  1709.  
  1710. function PufferODPakManager:LoadODPakDataFromFile()
  1711.   log(bWriteLog and "PufferODPakManager:LoadODPakDataFromFile.")
  1712.   local path = self:GetSaveFilePath()
  1713.   local dataStr = Client.LoadFileToString(path)
  1714.   local json = require("common.json_util")
  1715.   local data = json.decode(dataStr)
  1716.   if not data then
  1717.     log(bWriteLog and "PufferODPakManager:LoadODPakDataFromFile. data is nil")
  1718.     return
  1719.   end
  1720.   log_tree("PufferODPakManager:LoadODPakDataFromFile. data = ", data)
  1721.   for k, v in pairs(data) do
  1722.     self.ODPaks[tonumber(k)] = v
  1723.   end
  1724.   Client.DeleteFile(path)
  1725. end
  1726.  
  1727. function PufferODPakManager:ClearBattleMemory()
  1728.   log(bWriteLog and "PufferODPakManager:ClearBattleMemory.")
  1729.   self.ODPaks = {}
  1730.   self.PakDatas = {}
  1731.   self.itemToPaks = {}
  1732.   self.itemToItems = {}
  1733.   self.itemToPaths = {}
  1734. end
  1735.  
  1736. function PufferODPakManager:RecoverBattleMemory()
  1737.   log(bWriteLog and "PufferODPakManager:RecoverBattleMemory.")
  1738.   local begintime = slua.getMiliseconds()
  1739.   self.PakDatas = {}
  1740.   for packID, v in pairs(self.ODPaks) do
  1741.     for pakName, data in pairs(v.paks) do
  1742.       self.PakDatas[pakName] = {packID = packID, data = data}
  1743.     end
  1744.   end
  1745.   local deleteFiles = self.battleDeleteFiles
  1746.   self.battleDeleteFiles = {}
  1747.   for pakName, v in pairs(deleteFiles) do
  1748.     self:ResetPakData(pakName)
  1749.   end
  1750.   local costTime = slua.getMiliseconds() - begintime
  1751.   log(bWriteLog and "PufferODPakManager:RecoverBattleMemory. costTime = " .. tostring(costTime))
  1752. end
  1753.  
  1754. function PufferODPakManager:OnPostSwitchGameStatus(pre, next)
  1755.   log(bWriteLog and string.format("PufferODPakManager:OnPostSwitchGameStatus. pre=%s, next=%s", tostring(pre), tostring(next)))
  1756.   if GameStatus.InActualFight() then
  1757.     self:HandleEnterFight()
  1758.   end
  1759. end
  1760.  
  1761. function PufferODPakManager:OnPreSwitchGameStatus(pre, next)
  1762.   log(bWriteLog and string.format("PufferODPakManager:OnPreSwitchGameStatus. pre=%s, next=%s", tostring(pre), tostring(next)))
  1763.   if GameStatus.InActualFight() and next ~= GameStatus.Fighting then
  1764.     self:HandleExitFight()
  1765.   end
  1766. end
  1767.  
  1768. local class = require("class")
  1769. local CModuleBase = require("client.module_framework.ModuleBase")
  1770. local CPufferODPakManager = class(CModuleBase, nil, PufferODPakManager)
  1771. return CPufferODPakManager
  1772.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement