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.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using DS1Catacombs.Content;
using HG.Reflection;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.ContentManagement;
using UnityEngine;
using UnityEngine.AddressableAssets;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("RoR2_Catacombs")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RoR2_Catacombs")]
[assembly: AssemblyTitle("RoR2_Catacombs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace DS1Catacombs
{
[BepInPlugin("Viliger.DS1CatacombsPlugin", "DS1CatacombsPlugin", "0.9.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class DS1CatacombsPlugin : BaseUnityPlugin
{
public const string Author = "Viliger";
public const string Name = "DS1CatacombsPlugin";
public const string Version = "0.9.3";
public const string GUID = "Viliger.DS1CatacombsPlugin";
public static ConfigEntry<bool> EnableShitpostMusic;
public static DS1CatacombsPlugin instance;
public static PluginInfo PluginInfo;
private void Awake()
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Expected O, but got Unknown
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
EnableShitpostMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Catacombs", "Enable shitpost music", false, "Enables shitpost music.");
instance = this;
PluginInfo = ((BaseUnityPlugin)this).Info;
Log.Init(((BaseUnityPlugin)this).Logger);
MusicController.Start += new hook_Start(MusicController_Start);
ContentManager.collectContentPackProviders += new CollectContentPackProvidersDelegate(GiveToRoR2OurContentPackProviders);
Language.collectLanguageRootFolders += CollectLanguageRootFolders;
}
private void MusicController_Start(orig_Start orig, MusicController self)
{
orig.Invoke(self);
AkSoundEngine.PostEvent("DS1_Play_Music_System", ((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"));
}
}
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);
}
}
}
namespace DS1Catacombs.Content
{
public class ContentProvider : IContentPackProvider
{
private readonly ContentPack _contentPack = new ContentPack();
public static string assetDirectory;
public string identifier => "Viliger.DS1CatacombsPlugin.ContentProvider";
public IEnumerator LoadStaticContentAsync(LoadStaticContentAsyncArgs args)
{
_contentPack.identifier = identifier;
string assetsFolderFullPath = (assetDirectory = Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "assetbundles"));
string musicFolderFullPath = Path.Combine(Path.GetDirectoryName(typeof(ContentProvider).Assembly.Location), "Soundbanks");
DS1CatacombsContent.LoadSoundBank(musicFolderFullPath);
AssetBundle scenesAssetBundle = null;
yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "catacombsstage"), args.progressReceiver, delegate(AssetBundle assetBundle)
{
scenesAssetBundle = assetBundle;
});
AssetBundle assetsAssetBundle = null;
yield return LoadAssetBundle(Path.Combine(assetsFolderFullPath, "catacombsassets"), args.progressReceiver, delegate(AssetBundle assetBundle)
{
assetsAssetBundle = assetBundle;
});
yield return DS1CatacombsContent.LoadAssetBundlesAsync(scenesAssetBundle, assetsAssetBundle, args.progressReceiver, _contentPack, musicFolderFullPath);
}
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 DS1CatacombsContent
{
internal const string ScenesAssetBundleFileName = "catacombsstage";
internal const string AssetsAssetBundleFileName = "catacombsassets";
internal const string SoundBankFileName = "DS1CatacombsMusic.bnk";
internal const string InitSoundBankFileName = "DS1CatacombsInit.bnk";
private static AssetBundle _scenesAssetBundle;
private static AssetBundle _assetsAssetBundle;
internal static UnlockableDef[] UnlockableDefs;
internal static SceneDef[] SceneDefs;
public static SceneDef DS1SceneDef;
internal static Sprite DS1ScenePreviewSprite;
internal static Material DS1BazaarSeer;
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" },
{ "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 void LoadSoundBank(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_00a4: 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("DS1CatacombsInit.bnk", ref num);
if ((int)val == 1)
{
Log.Info("Added bank : DS1CatacombsInit.bnk");
}
else
{
Log.Error("Error loading bank : DS1CatacombsInit.bnk " + $"Error code : {val}");
}
val = AkSoundEngine.LoadBank("DS1CatacombsMusic.bnk", ref num);
if ((int)val == 1)
{
Log.Info("Added bank : DS1CatacombsMusic.bnk");
}
else
{
Log.Error("Error loading bank : DS1CatacombsMusic.bnk " + $"Error code : {val}");
}
}
internal static IEnumerator LoadAssetBundlesAsync(AssetBundle scenesAssetBundle, AssetBundle assetsAssetBundle, IProgress<float> progress, ContentPack contentPack, string musicFolderFullPath)
{
_scenesAssetBundle = scenesAssetBundle;
_assetsAssetBundle = assetsAssetBundle;
Log.Debug("Asset bundles 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<Sprite>(_assetsAssetBundle, progress, (Action<Sprite[]>)delegate(Sprite[] assets)
{
DS1ScenePreviewSprite = assets.First((Sprite a) => ((Object)a).name == "texCatacombsPreview");
});
yield return LoadAllAssetsAsync<SceneDef>(_assetsAssetBundle, progress, (Action<SceneDef[]>)delegate(SceneDef[] assets)
{
SceneDefs = assets;
DS1SceneDef = SceneDefs.First((SceneDef sd) => sd.cachedName == "catacombs_DS1_Catacombs");
Log.Debug(DS1SceneDef.nameToken);
contentPack.sceneDefs.Add(assets);
});
DS1BazaarSeer = StageRegistration.MakeBazaarSeerMaterial(DS1ScenePreviewSprite.texture);
DS1SceneDef.previewTexture = (Texture)(object)DS1ScenePreviewSprite.texture;
DS1SceneDef.portalMaterial = DS1BazaarSeer;
SetupMusic();
StageRegistration.RegisterSceneDefToLoop(DS1SceneDef);
Log.Debug(DS1SceneDef.destinationsGroup);
}
private static void SetupMusic()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
CustomMusicTrackDef val = ScriptableObject.CreateInstance<CustomMusicTrackDef>();
((MusicTrackDef)val).cachedName = "DS1CustomMainMusic";
val.CustomStates = new List<CustomState>();
CustomState item = default(CustomState);
item.GroupId = 487602916u;
if (DS1CatacombsPlugin.EnableShitpostMusic.Value)
{
item.StateId = 145640315u;
}
else
{
item.StateId = 2254536284u;
}
val.CustomStates.Add(item);
CustomState item2 = default(CustomState);
item2.GroupId = 792781730u;
item2.StateId = 89505537u;
val.CustomStates.Add(item2);
DS1SceneDef.mainTrack = (MusicTrackDef)(object)val;
CustomMusicTrackDef val2 = ScriptableObject.CreateInstance<CustomMusicTrackDef>();
((MusicTrackDef)val2).cachedName = "DS1CustomBossMusic";
val2.CustomStates = new List<CustomState>();
CustomState item3 = default(CustomState);
item3.GroupId = 487602916u;
if (DS1CatacombsPlugin.EnableShitpostMusic.Value)
{
item3.StateId = 3403129731u;
}
else
{
item3.StateId = 3699353111u;
}
val2.CustomStates.Add(item3);
CustomState item4 = default(CustomState);
item4.GroupId = 792781730u;
item4.StateId = 580146960u;
val2.CustomStates.Add(item4);
DS1SceneDef.bossTrack = (MusicTrackDef)(object)val2;
}
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());
}
}
}