using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OddsAndEndsTrue;
using Severon.OddsAndEnds;
using UnityEngine;
[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("CustomEndlessOddsCompat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+d2d0ce7359494b4389d1ef1ff58e09d73dcf8e22")]
[assembly: AssemblyProduct("CustomEndlessOddsCompat")]
[assembly: AssemblyTitle("CustomEndlessOddsCompat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace CustomEndlessOddsCompat
{
[BepInPlugin("com.craft.customendlessoddscompat", "Custom Endless & Odds And Ends Compatibility", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance { get; private set; }
public static ManualLogSource Log { get; private set; }
private void Awake()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("com.craft.customendlessoddscompat").PatchAll();
Log.LogInfo((object)"Custom Endless & Odds And Ends Compatibility v1.0.1 initialized successfully. Custom Endless & Odds And Ends are now synchronized!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.craft.customendlessoddscompat";
public const string PLUGIN_NAME = "Custom Endless & Odds And Ends Compatibility";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace CustomEndlessOddsCompat.Patches
{
[HarmonyPatch(typeof(EndlessSettings), "RegisterAllSettings")]
public static class EndlessSettingsMenuPatch
{
[HarmonyPostfix]
public static void Postfix(EndlessSettings __instance)
{
MenuSettingsManager value = Traverse.Create((object)__instance).Field("menuSettingsManager").GetValue<MenuSettingsManager>();
if ((Object)(object)value == (Object)null)
{
Plugin.Log.LogWarning((object)"[SettingsMenuPatch] MenuSettingsManager not found on EndlessSettings.");
return;
}
string menuTag = __instance.menuTag;
value.Register(menuTag, "Awakened Amalgamator", "item_amalgamator", (SettingType)0, "0", "STARTING ITEMS");
value.Register(menuTag, "Pestle", "item_pestle", (SettingType)0, "0", "STARTING ITEMS");
value.Register(menuTag, "Demalgamator", "item_demalgamator", (SettingType)0, "0", "STARTING ITEMS");
value.Register(menuTag, "Stoner Rock", "item_stoner_rock", (SettingType)0, "0", "STARTING ITEMS");
value.Register(menuTag, "Time Reagent", "item_reagent_time", (SettingType)0, "0", "REAGENTS");
value.Register(menuTag, "Power Reagent", "item_reagent_power", (SettingType)0, "0", "REAGENTS");
value.Register(menuTag, "Magic Reagent", "item_reagent_magic", (SettingType)0, "0", "REAGENTS");
value.Register(menuTag, "Body Reagent", "item_reagent_body", (SettingType)0, "0", "REAGENTS");
value.Register(menuTag, "Soul Reagent", "item_reagent_soul", (SettingType)0, "0", "REAGENTS");
Plugin.Log.LogInfo((object)"[SettingsMenuPatch] Injected Odds and Ends items & reagents into Custom Endless menu.");
}
}
[HarmonyPatch(typeof(EndlessConfiguration), "GiveStartingItems")]
public static class EndlessStartingItemsPatch
{
private static readonly (string settingKey, string prefabName)[] ItemMappings = new(string, string)[9]
{
("item_amalgamator", "Awakened_Amalgamator"),
("item_pestle", "Item_Amalgamate_Pestle"),
("item_demalgamator", "Item_Demalgamator"),
("item_stoner_rock", "Item_Stoner_Rock"),
("item_reagent_time", "Item_Time_Reagent"),
("item_reagent_power", "Item_Power_Reagent"),
("item_reagent_magic", "Item_Magic_Reagent"),
("item_reagent_body", "Item_Body_Reagent"),
("item_reagent_soul", "Item_Soul_Reagent")
};
[HarmonyPostfix]
public static void Postfix()
{
if ((Object)(object)Inventory.instance == (Object)null)
{
return;
}
bool flag = false;
(string, string)[] itemMappings = ItemMappings;
for (int i = 0; i < itemMappings.Length; i++)
{
(string, string) tuple = itemMappings[i];
string item = tuple.Item1;
string item2 = tuple.Item2;
int countState = CustomUIManager.GetCountState(item, 0);
if (countState > 0)
{
GiveItem(item2, countState);
Plugin.Log.LogInfo((object)$"[StartingItemsPatch] Granted {countState}x {item2} to player.");
if (item == "item_amalgamator" || item == "item_pestle")
{
flag = true;
}
}
}
if (flag)
{
EnsureStudentNote();
}
}
private static void GiveItem(string prefabName, int count)
{
for (int i = 0; i < count; i++)
{
Item_Object itemObjectPrefab = CL_AssetManager.GetItemObjectPrefab(prefabName, "");
if ((Object)(object)itemObjectPrefab != (Object)null && itemObjectPrefab.itemData != null)
{
Item clone = itemObjectPrefab.itemData.GetClone((Item)null, false);
Inventory.instance.AddItemToInventoryCenter(clone);
}
else
{
Plugin.Log.LogWarning((object)("[StartingItemsPatch] Could not find prefab for '" + prefabName + "'."));
}
}
}
private static void EnsureStudentNote()
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Expected O, but got Unknown
if ((Object)(object)Inventory.instance == (Object)null || Inventory.instance.bagItems == null)
{
return;
}
foreach (Item bagItem in Inventory.instance.bagItems)
{
if (bagItem != null && bagItem.data != null && bagItem.data.Contains("AwakenedStudentNote=1"))
{
return;
}
}
Item_Object itemObjectPrefab = CL_AssetManager.GetItemObjectPrefab("Item_Note_01", "");
if ((Object)(object)itemObjectPrefab != (Object)null && itemObjectPrefab.itemData != null)
{
Item clone = itemObjectPrefab.itemData.GetClone((Item)null, false);
clone.dataModules = new List<Item_Data> { (Item_Data)new Item_Data_Text_Random
{
strings = new List<string> { "\r\nReagents:\r\nTime\r\nPower\r\nMagic\r\nBody\r\n\r\nSoul?\r\n ", "\r\nThe Pestle can do more than \r\ndeconstruct items into Reagents\r\n " }
} };
if (clone.data == null)
{
clone.data = new List<string>();
}
clone.data.Add("AwakenedStudentNote=1");
Inventory.instance.AddItemToInventoryCenter(clone);
}
}
}
[HarmonyPatch(typeof(CL_Initializer), "Awake")]
public static class GamemodeIntegrationPatch
{
[HarmonyPostfix]
public static void Postfix()
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)EndlessConfiguration.EndlessMode == (Object)null))
{
M_Gamemode endlessMode = EndlessConfiguration.EndlessMode;
if (endlessMode.gamemodeSettings != null)
{
endlessMode.gamemodeSettings = new List<GamemodeSetting>(endlessMode.gamemodeSettings);
}
else
{
endlessMode.gamemodeSettings = new List<GamemodeSetting>();
}
if (!endlessMode.gamemodeSettings.Exists((GamemodeSetting s) => (Object)(object)s != (Object)null && s.id == "EnemyWaves"))
{
GamemodeSetting val = ScriptableObject.CreateInstance<GamemodeSetting>();
val.id = "EnemyWaves";
val.title = "Enemy Waves";
val.description = "Spawn enemy waves as you climb.";
val.color = Color.red;
val.exclusiveSettings = new List<string>();
val.unlock = ScriptableObject.CreateInstance<ProgressionUnlock>();
val.unlock.unlockRequirements = new List<UnlockRequirement>();
val.unlock.state = true;
endlessMode.gamemodeSettings.Add(val);
Plugin.Log.LogInfo((object)"[GamemodeIntegration] Injected EnemyWaves setting into Custom Endless.");
}
}
}
}
[HarmonyPatch(typeof(EndlessSettings), "get_startingPerkTitles")]
public static class PerkRegistrationSafeguardPatch
{
[HarmonyPrefix]
public static bool Prefix(ref Dictionary<string, string> __result)
{
try
{
StudentPerks.EnsureRegistered();
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("[PerkSafeguard] Error ensuring StudentPerks registered: " + ex.Message));
}
List<Perk> source = CL_AssetManager.GetFullCombinedAssetDatabase()?.perkAssets ?? new List<Perk>();
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (Perk item in from p in source
where (Object)(object)p != (Object)null && !string.IsNullOrEmpty(p.id)
orderby p.title
select p)
{
if (!dictionary.ContainsKey(item.id))
{
dictionary.Add(item.id, item.title ?? item.id);
}
}
__result = dictionary;
return false;
}
}
}