/// <summary> /// オフラインプロセス開始イベント /// </summary> /// <returns>コルーチン</returns> protected override System.Collections.IEnumerator OnStartedOfflineProcess() { if (m_DownloadWork.request != null) { if (!m_DownloadWork.request.isNetworkError && !m_DownloadWork.request.isHttpError) { m_DownloadWork.request.Dispose(); m_DownloadWork.request = null; } } var cryptoHash = AssetBundleCrypto.GetCryptoHash(manager.catalog, nameWithVariant); FileStream cryptoFile = null; try { cryptoFile = File.Open(m_DownloadWork.fullPath, FileMode.Open, FileAccess.Read, FileShare.Read); } catch { m_ErrorCode = AssetBundleErrorCode.DecryptDataNotFound; } if (cryptoFile != null) { var decryptoStream = new AssetBundleDecryptStream(cryptoFile, cryptoHash); m_DownloadWork.createRequest = AssetBundle.LoadFromStreamAsync(decryptoStream, m_DownloadWork.crc); yield return(m_DownloadWork.createRequest); try { var assetBundle = m_DownloadWork.createRequest.assetBundle; if (assetBundle != null) { m_AssetBundle = assetBundle; } else { m_ErrorCode = AssetBundleErrorCode.DecryptFailed; } } catch { m_ErrorCode = AssetBundleErrorCode.DecryptFailed; } } if (m_ErrorCode != AssetBundleErrorCode.Null) { //エラー発生 manager.RemoveDeliveryStreamingAssetCache(nameWithVariant); } yield return(base.OnStartedOfflineProcess()); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="source">元データ</param> /// <param name="cryptoHash">暗号化ハッシュ</param> public AssetBundleDecryptStream(Stream source, int cryptoHash) { m_Source = source; m_FastForwardBuffer = new byte[kFastForwardBufferSize]; var key = AssetBundleCrypto.GetCryptoKey(cryptoHash); var iv = new byte[AssetBundleCrypto.kIVSize]; source.Read(iv, 0, iv.Length); source.Read(m_FastForwardBuffer, 0, kFileSizeBytesSize); m_CreateDecryptoStream = () => { m_Source.Position = kCryptoHeaderSize; return(AssetBundleCrypto.GetDecryptStream(m_Source, key, iv)); }; ResetDecryptoStream(); }