using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HG.Reflection;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using RoR2.ExpansionManagement;
using Snowtime.Content;
using UnityEngine;
using UnityEngine.AddressableAssets;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Snowtime
{
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("SnowySnowtime.SnowtimeStage", "SnowtimeStage", "0.6.0")]
public class SnowtimeStage : BaseUnityPlugin
{
public const string Author = "SnowySnowtime";
public const string Name = "SnowtimeStage";
public const string Version = "0.6.0";
public const string GUID = "SnowySnowtime.SnowtimeStage";
public static SnowtimeStage instance;
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
instance = this;
Log.Init(((BaseUnityPlugin)this).Logger);
RegisterHooks();
ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(GiveToRoR2OurContentPackProviders);
Language.collectLanguageRootFolders += CollectLanguageRootFolders;
}
private void RegisterHooks()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
MusicController.StartIntroMusic += new hook_StartIntroMusic(MusicController_StartIntroMusic);
}
private void MusicController_StartIntroMusic(orig_StartIntroMusic orig, MusicController self)
{
orig.Invoke(self);
AkSoundEngine.PostEvent("Play_Music_SystemST", ((Component)self).gameObject);
}
private void Destroy()
{
Language.collectLanguageRootFolders -= CollectLanguageRootFolders;
}
private void GiveToRoR2OurContentPackProviders(AddContentPackProviderDelegate addContentPackProvider)
{
addContentPackProvider.Invoke((IContentPackProvider)(object)new ContentProvider());
}
public void CollectLanguageRootFolders(List<string> folders)
{
folders.Add(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "Language"));
}
}
}
namespace Snowtime.Content
{
public class ContentProvider : IContentPackProvider
{
private readonly ContentPack _contentPack = new ContentPack();
public static string assetDirectory;
public string identifier => "SnowySnowtime.SnowtimeStage.ContentProvider";
public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
{
_contentPack.identifier = identifier;
string assetsFolderFullPath = (assetDirectory = Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "assetbundles"));
SnowtimeContent.LoadSoundBanks(Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "audio"));
AssetBundle scenesAssetBundle = null;
yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "snowtimestages"), args.progressReceiver, delegate(AssetBundle assetBundle)
{
scenesAssetBundle = assetBundle;
});
AssetBundle assetsAssetBundle = null;
yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "snowtimeassets"), args.progressReceiver, delegate(AssetBundle assetBundle)
{
assetsAssetBundle = assetBundle;
});
yield return SnowtimeContent.LoadAssetBundlesAsync(scenesAssetBundle, assetsAssetBundle, args.progressReceiver, _contentPack);
}
private IEnumerator LoadAssetBundle(string assetBundleFullPath, IProgress<float> progress, Action<AssetBundle> onAssetBundleLoaded)
{
AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(assetBundleFullPath);
while (!((AsyncOperation)assetBundleCreateRequest).isDone)
{
progress.Report(((AsyncOperation)assetBundleCreateRequest).progress);
yield return null;
}
onAssetBundleLoaded(assetBundleCreateRequest.assetBundle);
}
public IEnumerator GenerateContentPackAsync(GetContentPackAsyncArgs args)
{
ContentPack.Copy(_contentPack, args.output);
args.ReportProgress(1f);
yield break;
}
public IEnumerator FinalizeAsync(FinalizeAsyncArgs args)
{
args.ReportProgress(1f);
yield break;
}
}
public static class SnowtimeContent
{
internal const string ScenesAssetBundleFileName = "snowtimestages";
internal const string AssetsAssetBundleFileName = "snowtimeassets";
internal const string MusicSoundBankFileName = "SnowtimeStagesMusic.bnk";
internal const string SndSoundBankFileName = "SnowtimeStagesSounds.bnk";
internal const string InitSoundBankFileName = "SnowtimeStagesInit.bnk";
private static AssetBundle _scenesAssetBundle;
private static AssetBundle _assetsAssetBundle;
internal static UnlockableDef[] UnlockableDefs;
internal static SceneDef[] SceneDefs;
internal static ExpansionDef[] expansionDefs;
internal static ExpansionDef ExpansionDefSTHalo;
internal static SceneDef STSceneDef;
internal static SceneDef STIFSceneDef;
internal static SceneDef STBGSceneDef;
internal static SceneDef STGPHSceneDef;
internal static SceneDef STHSceneDef;
internal static SceneDef STH2SceneDef;
internal static SceneDef STShrineSceneDef;
internal static Sprite STSceneDefPreviewSprite;
internal static Sprite STIFSceneDefPreviewSprite;
internal static Sprite STBGSceneDefPreviewSprite;
internal static Sprite STGPHSceneDefPreviewSprite;
internal static Sprite STHSceneDefPreviewSprite;
internal static Sprite STH2SceneDefPreviewSprite;
internal static Sprite STShrineSceneDefPreviewSprite;
internal static Material STBazaarSeer;
internal static Material STIFBazaarSeer;
internal static Material STBGBazaarSeer;
internal static Material STGPHBazaarSeer;
internal static Material STHBazaarSeer;
internal static Material STH2BazaarSeer;
internal static Material STShrineBazaarSeer;
public static List<Material> SwappedMaterials = new List<Material>();
public static Dictionary<string, string> ShaderLookup = new Dictionary<string, string>
{
{ "stubbedror2/base/shaders/hgstandard", "RoR2/Base/Shaders/HGStandard.shader" },
{ "stubbedror2/base/shaders/hgsnowtopped", "RoR2/Base/Shaders/HGSnowTopped.shader" },
{ "stubbedror2/base/shaders/hgtriplanarterrainblend", "RoR2/Base/Shaders/HGTriplanarTerrainBlend.shader" },
{ "stubbedror2/base/shaders/hgintersectioncloudremap", "RoR2/Base/Shaders/HGIntersectionCloudRemap.shader" },
{ "stubbedror2/base/shaders/hgcloudremap", "RoR2/Base/Shaders/HGCloudRemap.shader" },
{ "stubbedror2/base/shaders/hgdistortion", "RoR2/Base/Shaders/HGDistortion.shader" },
{ "stubbedror2/base/shaders/speedtreecustom", "RoR2/Base/Shaders/SpeedTreeCustom.shader" },
{ "stubbedcalm water/calmwater - dx11 - doublesided", "Calm Water/CalmWater - DX11 - DoubleSided.shader" },
{ "stubbedcalm water/calmwater - dx11", "Calm Water/CalmWater - DX11.shader" },
{ "stubbednature/speedtree", "RoR2/Base/Shaders/SpeedTreeCustom.shader" }
};
internal static IEnumerator LoadAssetBundlesAsync(AssetBundle scenesAssetBundle, AssetBundle assetsAssetBundle, IProgress<float> progress, ContentPack contentPack)
{
_scenesAssetBundle = scenesAssetBundle;
_assetsAssetBundle = assetsAssetBundle;
Log.Debug("Snowtime Stages found. Loading asset bundles...");
yield return LoadAllAssetsAsync<Material>(_assetsAssetBundle, progress, (Action<Material[]>)delegate(Material[] assets)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
if (assets != null)
{
Material[] array = assets;
foreach (Material val in array)
{
if (((Object)val.shader).name.StartsWith("Stubbed"))
{
Shader val2 = Addressables.LoadAssetAsync<Shader>((object)ShaderLookup[((Object)val.shader).name.ToLower()]).WaitForCompletion();
if (Object.op_Implicit((Object)(object)val2))
{
val.shader = val2;
SwappedMaterials.Add(val);
}
}
}
}
});
yield return LoadAllAssetsAsync<UnlockableDef>(_assetsAssetBundle, progress, (Action<UnlockableDef[]>)delegate(UnlockableDef[] assets)
{
UnlockableDefs = assets;
contentPack.unlockableDefs.Add(assets);
});
yield return LoadAllAssetsAsync<ExpansionDef>(_assetsAssetBundle, progress, (Action<ExpansionDef[]>)delegate(ExpansionDef[] assets)
{
expansionDefs = assets;
ExpansionDefSTHalo = assets.First((ExpansionDef a) => ((Object)a).name == "snowtimestageshalo_expdef");
Log.Debug("SnowtimeStages:Halo Expansion Definition Added");
contentPack.expansionDefs.Add(assets);
});
yield return LoadAllAssetsAsync<Sprite>(_assetsAssetBundle, progress, (Action<Sprite[]>)delegate(Sprite[] assets)
{
STSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTScenePreview");
STIFSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTIFScenePreview");
STBGSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTBGScenePreview");
STGPHSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTGPHScenePreview");
STHSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTHaloScenePreview");
STH2SceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTHaloScenePreview");
STShrineSceneDefPreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texSTShrineScenePreview");
});
yield return LoadAllAssetsAsync<SceneDef>(_assetsAssetBundle, progress, (Action<SceneDef[]>)delegate(SceneDef[] assets)
{
SceneDefs = assets;
STSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_deathisland");
STIFSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_icefields");
STBGSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_bloodgulch");
STGPHSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_gephyrophobia");
STHSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_halo");
STH2SceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_halo2");
STShrineSceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "snowtime_sandtrap");
Log.Debug(STSceneDef.nameToken);
Log.Debug(STIFSceneDef.nameToken);
Log.Debug(STBGSceneDef.nameToken);
Log.Debug(STGPHSceneDef.nameToken);
Log.Debug(STShrineSceneDef.nameToken);
Log.Debug(STHSceneDef.nameToken);
Log.Debug(STH2SceneDef.nameToken);
contentPack.sceneDefs.Add(assets);
});
yield return LoadAllAssetsAsync<MusicTrackDef>(_assetsAssetBundle, progress, (Action<MusicTrackDef[]>)delegate(MusicTrackDef[] assets)
{
contentPack.musicTrackDefs.Add(assets);
Log.Debug("loaded musicDefs for SnowtimeStages");
});
STBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STSceneDefPreviewSprite.texture);
STIFBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STIFSceneDefPreviewSprite.texture);
STBGBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STBGSceneDefPreviewSprite.texture);
STGPHBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STGPHSceneDefPreviewSprite.texture);
STHBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STHSceneDefPreviewSprite.texture);
STH2BazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STH2SceneDefPreviewSprite.texture);
STShrineBazaarSeer = StageRegistration.MakeBazaarSeerMaterial(STShrineSceneDefPreviewSprite.texture);
STSceneDef.previewTexture = (Texture)(object)STSceneDefPreviewSprite.texture;
STIFSceneDef.previewTexture = (Texture)(object)STIFSceneDefPreviewSprite.texture;
STBGSceneDef.previewTexture = (Texture)(object)STBGSceneDefPreviewSprite.texture;
STGPHSceneDef.previewTexture = (Texture)(object)STGPHSceneDefPreviewSprite.texture;
STHSceneDef.previewTexture = (Texture)(object)STHSceneDefPreviewSprite.texture;
STH2SceneDef.previewTexture = (Texture)(object)STH2SceneDefPreviewSprite.texture;
STShrineSceneDef.previewTexture = (Texture)(object)STShrineSceneDefPreviewSprite.texture;
STSceneDef.portalMaterial = STBazaarSeer;
STIFSceneDef.portalMaterial = STIFBazaarSeer;
STBGSceneDef.portalMaterial = STBGBazaarSeer;
STGPHSceneDef.portalMaterial = STGPHBazaarSeer;
STHSceneDef.portalMaterial = STHBazaarSeer;
STH2SceneDef.portalMaterial = STH2BazaarSeer;
STShrineSceneDef.portalMaterial = STShrineBazaarSeer;
StageRegistration.RegisterSceneDefToLoop(STSceneDef);
StageRegistration.RegisterSceneDefToLoop(STIFSceneDef);
StageRegistration.RegisterSceneDefToLoop(STBGSceneDef);
StageRegistration.RegisterSceneDefToLoop(STGPHSceneDef);
StageRegistration.RegisterSceneDefToLoop(STShrineSceneDef);
StageRegistration.RegisterSceneDefToLoop(STHSceneDef);
StageRegistration.RegisterSceneDefToLoop(STH2SceneDef);
Log.Debug(STSceneDef.destinationsGroup);
Log.Debug(STIFSceneDef.destinationsGroup);
Log.Debug(STBGSceneDef.destinationsGroup);
Log.Debug(STGPHSceneDef.destinationsGroup);
Log.Debug(STHSceneDef.destinationsGroup);
Log.Debug(STH2SceneDef.destinationsGroup);
Log.Debug(STShrineSceneDef.destinationsGroup);
}
private static IEnumerator LoadAllAssetsAsync<T>(AssetBundle assetBundle, IProgress<float> progress, Action<T[]> onAssetsLoaded) where T : Object
{
AssetBundleRequest sceneDefsRequest = assetBundle.LoadAllAssetsAsync<T>();
while (!((AsyncOperation)sceneDefsRequest).isDone)
{
progress.Report(((AsyncOperation)sceneDefsRequest).progress);
yield return null;
}
onAssetsLoaded(sceneDefsRequest.allAssets.Cast<T>().ToArray());
}
internal static void LoadSoundBanks(string soundbanksFolderPath)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Invalid comparison between Unknown and I4
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Invalid comparison between Unknown and I4
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Invalid comparison between Unknown and I4
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
AKRESULT val = AkSoundEngine.AddBasePath(soundbanksFolderPath);
if ((int)val == 1)
{
Log.Info("Added bank base path : " + soundbanksFolderPath);
}
else
{
Log.Error("Error adding base path : " + soundbanksFolderPath + " " + $"Error code : {val}");
}
uint num = default(uint);
val = AkSoundEngine.LoadBank("SnowtimeStagesInit.bnk", ref num);
if ((int)val == 1)
{
Log.Info("Added bank : SnowtimeStagesInit.bnk");
}
else
{
Log.Error("Error loading bank : SnowtimeStagesInit.bnk " + $"Error code : {val}");
}
val = AkSoundEngine.LoadBank("SnowtimeStagesMusic.bnk", ref num);
if ((int)val == 1)
{
Log.Info("Added bank : SnowtimeStagesMusic.bnk");
}
else
{
Log.Error("Error loading bank : SnowtimeStagesMusic.bnk " + $"Error code : {val}");
}
val = AkSoundEngine.LoadBank("SnowtimeStagesSounds.bnk", ref num);
if ((int)val == 1)
{
Log.Info("Added bank : SnowtimeStagesSounds.bnk");
}
else
{
Log.Error("Error loading bank : SnowtimeStagesSounds.bnk " + $"Error code : {val}");
}
}
}
}