using System;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using LethalLib.Modules;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace LCWildCardMod;
public class WildCardConfig
{
public readonly List<ConfigEntry<bool>> isScrapEnabled = new List<ConfigEntry<bool>>();
public readonly List<ConfigEntry<string>> scrapSpawnWeights = new List<ConfigEntry<string>>();
public WildCardConfig(ConfigFile cfg, List<Item> scrapList)
{
cfg.SaveOnConfigSet = false;
foreach (Item scrap in scrapList)
{
isScrapEnabled.Add(cfg.Bind<bool>("Scrap", "Enable " + scrap.itemName, true, "Whether or not to allow " + scrap.itemName + " to spawn!"));
scrapSpawnWeights.Add(cfg.Bind<string>("Scrap", "Spawn Weights of " + scrap.itemName, "All:20", string.Concat("Set the spawn weight of " + scrap.itemName + " for each moon in the format 'Vanilla:20,Modded:30'", "\nUse 'All:' to set the weight for all moons, 'Vanilla:' for only vanilla moons, or 'Modded:' for only modded moons.", "\nSpecific moons can be referenced by typing the name (without the numbers) followed by 'Level' (this works for modded moons also), for example:", "\n'ExperimentationLevel:20'")));
}
ClearOrphanedEntries(cfg);
cfg.Save();
cfg.SaveOnConfigSet = true;
}
private static void ClearOrphanedEntries(ConfigFile cfg)
{
PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
dictionary.Clear();
}
}
[BepInPlugin("deB.WildCard", "WILDCARD Stuff", "0.0.1")]
public class WildCardMod : BaseUnityPlugin
{
private const string modGUID = "deB.WildCard";
private const string modName = "WILDCARD Stuff";
private const string modVersion = "0.0.1";
private readonly Harmony harmony = new Harmony("deB.WildCard");
private static WildCardMod Instance;
private readonly string[] declaredAssetPaths = new string[2] { "assets/my creations/items", "assets/my creations/enemies" };
internal static WildCardConfig ModConfig { get; private set; }
private void Awake()
{
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "wildcardmod"));
List<Item> list = new List<Item>();
string[] allAssetNames = val.GetAllAssetNames();
foreach (string text in allAssetNames)
{
if (declaredAssetPaths.Contains(text.Substring(0, text.LastIndexOf("/"))))
{
list.Add(val.LoadAsset<Item>(text));
}
else
{
((BaseUnityPlugin)this).Logger.LogDebug((object)("\"" + text + "\" is not a known asset path, skipping."));
}
}
ModConfig = new WildCardConfig(((BaseUnityPlugin)this).Config, list);
for (int j = 0; j < list.Count; j++)
{
if (ModConfig.isScrapEnabled[j].Value)
{
Dictionary<LevelTypes, int> dictionary = new Dictionary<LevelTypes, int>();
Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
string[] array = ModConfig.scrapSpawnWeights[j].Value.Split(",");
bool flag = false;
string[] array2 = array;
foreach (string text2 in array2)
{
if (text2.Contains(":") && int.TryParse(text2.Split(":")[1], out var _))
{
flag = true;
continue;
}
flag = false;
break;
}
if (flag)
{
string[] array3 = array;
foreach (string text3 in array3)
{
if (Enum.TryParse<LevelTypes>(text3.Split(":")[0], out LevelTypes result2))
{
dictionary.Add(result2, int.Parse(text3.Split(":")[1]));
}
else
{
dictionary2.Add(text3, int.Parse(text3.Split(":")[1]));
}
}
Items.RegisterScrap(list[j], (Dictionary<LevelTypes, int>)null, dictionary2);
Items.RegisterScrap(list[j], dictionary, (Dictionary<string, int>)null);
NetworkPrefabs.RegisterNetworkPrefab(list[j].spawnPrefab);
Utilities.FixMixerGroups(list[j].spawnPrefab);
foreach (KeyValuePair<LevelTypes, int> levelRarity in Items.scrapItems.LastOrDefault().levelRarities)
{
((BaseUnityPlugin)this).Logger.LogDebug((object)$"LethalLib Registered Weights {levelRarity}");
}
((BaseUnityPlugin)this).Logger.LogInfo((object)(list[j].itemName + " was loaded!"));
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)(list[j].itemName + " was not loaded as its config was not set up correctly!"));
}
}
else
{
((BaseUnityPlugin)this).Logger.LogInfo((object)(list[j].itemName + " was disabled!"));
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"WILD/CARD Things Successfully Loaded");
}
}