using System; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading.Tasks; using BepInEx.Logging; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.ResourceManagement.ResourceLocations; using UnityEngine.ResourceManagement.ResourceProviders; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("AngryLevelLoader.AssetBundleProviders")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+437c42fa89e37e50e83774b93dfe7cda8199323b")] [assembly: AssemblyProduct("AngryLevelLoader.AssetBundleProviders")] [assembly: AssemblyTitle("AngryLevelLoader.AssetBundleProviders")] [assembly: AssemblyVersion("1.0.0.0")] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } } namespace AngryLevelLoader.AssetBundleProviders { internal class ZippedAssetBundleResource : IAssetBundleResource { private ProvideHandle handle; private string zipPath; private string entryName; private AssetBundleCreateRequest assetBundleOp; private AssetBundle assetBundle; public AssetBundle GetAssetBundle() { return assetBundle; } public ZippedAssetBundleResource(ProvideHandle handle, string zipPath, string entryName) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) this.handle = handle; this.zipPath = zipPath; this.entryName = entryName; } public void Start() { ZipArchive archive = null; Stream bundleStream = null; try { archive = new ZipArchive(File.Open(zipPath, FileMode.Open, FileAccess.Read, FileShare.Read), ZipArchiveMode.Read); ZipArchiveEntry entry = archive.GetEntry(entryName); if (entry == null) { CompleteWithError(new Exception("Could not locate entry '" + entryName + "' at zip file '" + zipPath + "'")); return; } byte[] bundleBinary = new byte[entry.Length]; bundleStream = entry.Open(); Task readZipTask = bundleStream.ReadAsync(bundleBinary).AsTask(); readZipTask.ContinueWith(delegate { if (readZipTask.Exception != null) { CompleteWithError(readZipTask.Exception); } else { assetBundleOp = AssetBundle.LoadFromMemoryAsync(bundleBinary); if (((AsyncOperation)assetBundleOp).isDone) { OnCompletion(); } else { ((AsyncOperation)assetBundleOp).completed += delegate { OnCompletion(); }; } } }, TaskScheduler.FromCurrentSynchronizationContext()); } catch (Exception ex) { CompleteWithError(ex); } void CompleteOperation() { ((ProvideHandle)(ref handle)).Complete(this, true, (Exception)null); DisposeResources(); } void CompleteWithError(Exception ex2) { ZippedAssetBundleProvider.LogError(ex2); ((ProvideHandle)(ref handle)).Complete((ZippedAssetBundleResource)null, false, ex2); DisposeResources(); } void DisposeResources() { if (bundleStream != null) { try { bundleStream.Close(); } catch (Exception o) { ZippedAssetBundleProvider.LogError(o); } try { bundleStream.Dispose(); } catch (Exception o2) { ZippedAssetBundleProvider.LogError(o2); } } if (archive != null) { try { archive.Dispose(); } catch (Exception o3) { ZippedAssetBundleProvider.LogError(o3); } } } void OnCompletion() { assetBundle = assetBundleOp.assetBundle; if ((Object)(object)assetBundle == (Object)null) { CompleteWithError(new Exception("Failed to load asset bundle '" + entryName + "'")); } else { CompleteOperation(); } } } public bool Unload(out AssetBundleUnloadOperation unloadOp) { unloadOp = null; if ((Object)(object)assetBundle != (Object)null) { unloadOp = assetBundle.UnloadAsync(true); assetBundle = null; } assetBundleOp = null; return unloadOp != null; } } [DisplayName("Zipped AssetBundle Provider")] public class ZippedAssetBundleProvider : ResourceProviderBase { public static Func ResolveBundleGuidToZipFilePath; public static ManualLogSource logger; internal static void Log(object o) { if (logger != null) { logger.LogInfo((object)string.Format("{0} : {1}", "ZippedAssetBundleProvider", o)); } } internal static void LogError(object o) { if (logger != null) { logger.LogError((object)string.Format("{0} : {1}", "ZippedAssetBundleProvider", o)); } } public override void Provide(ProvideHandle providerInterface) { //IL_00d3: Unknown result type (might be due to invalid IL or missing references) string internalId = ((ProvideHandle)(ref providerInterface)).Location.InternalId; if (internalId.Length < 33) { LogError("Zipped bundle has invalid internal id '" + internalId + "'"); ((ProvideHandle)(ref providerInterface)).Complete((ZippedAssetBundleProvider)null, false, new Exception("Zipped bundle has invalid internal id '" + internalId + "'")); return; } string arg = internalId.Substring(0, 32); string entryName = internalId.Substring(33); if (ResolveBundleGuidToZipFilePath == null) { LogError("Delegate for resolving bundle guid is not provided"); ((ProvideHandle)(ref providerInterface)).Complete((ZippedAssetBundleProvider)null, false, new Exception("Delegate for resolving bundle guid is not provided")); return; } string text = ResolveBundleGuidToZipFilePath(arg); if (string.IsNullOrEmpty(text) || !File.Exists(text)) { LogError("Could not locate zip file for bundle '" + internalId + "'"); ((ProvideHandle)(ref providerInterface)).Complete((ZippedAssetBundleProvider)null, false, (Exception)new IOException("Could not locate zip file for bundle '" + internalId + "'")); } else { new ZippedAssetBundleResource(providerInterface, text, entryName).Start(); } } public override Type GetDefaultType(IResourceLocation location) { return typeof(IAssetBundleResource); } public override void Release(IResourceLocation location, object asset) { if (location == null) { throw new ArgumentNullException("location"); } if (asset != null && asset is ZippedAssetBundleResource zippedAssetBundleResource) { zippedAssetBundleResource.Unload(out AssetBundleUnloadOperation _); } } } }