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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalLevelLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using XLScrap.NetcodePatcher;
[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: AssemblyCompany("Henit3")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds example XL Scrap")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+023968e3e57d966b850da18a4aece9cc2cc3cdee")]
[assembly: AssemblyProduct("XL Scrap")]
[assembly: AssemblyTitle("XLScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 XlScrap
{
public class ConfigValues
{
public ConfigEntry<string> CrtTvSpawnWeight { get; private set; }
public ConfigEntry<string> CouchSpawnWeight { get; private set; }
public ConfigEntry<string> LCouchSpawnWeight { get; private set; }
public ConfigValues(ConfigFile configFile)
{
CrtTvSpawnWeight = configFile.Bind<string>("Spawn Weights", "CRT TV", "Vanilla:50, Custom:50", "Spawn Weight of CRT TV specified as comma-separated \"key:weight\" pairs");
CouchSpawnWeight = configFile.Bind<string>("Spawn Weights", "Couch", "Vanilla:50, Custom:50", "Spawn Weight of Couch specified as comma-separated \"key:weight\" pairs");
LCouchSpawnWeight = configFile.Bind<string>("Spawn Weights", "L Couch", "Vanilla:0, Custom:0", "Spawn Weight of L Couch (UNFINISHED) specified as comma-separated \"key:weight\" pairs");
ClearUnusedEntries(configFile);
}
private void ClearUnusedEntries(ConfigFile configFile)
{
PropertyInfo property = ((object)configFile).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(configFile, null);
dictionary.Clear();
configFile.Save();
}
}
[BepInPlugin("XLScrap", "XL Scrap", "0.1.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ConfigValues Config;
internal static ManualLogSource Logger;
private static readonly Harmony Harmony = new Harmony("XLScrap");
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin XLScrap (0.1.1) is loading...");
Config = new ConfigValues(((BaseUnityPlugin)this).Config);
AssetBundleLoader.AddOnExtendedModLoadedListener((Action<ExtendedMod>)OnExtendedModRegistered, (string)null, "XlScrap");
AssetBundleLoader.AddOnLethalBundleLoadedListener((Action<AssetBundle>)OnLethalBundleLoaded, "xl_scrap.lethalbundle");
NetcodePatcher();
Logger.LogInfo((object)"Patching...");
Harmony.PatchAll();
Logger.LogInfo((object)"Patching complete!");
Logger.LogInfo((object)"Plugin XLScrap (0.1.1) is loaded!");
}
private static void NetcodePatcher()
{
Type[] array;
try
{
array = Assembly.GetExecutingAssembly().GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
array = ex.Types.Where((Type t) => t != null).ToArray();
}
Type[] array2 = array;
foreach (Type type in array2)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array3 = methods;
foreach (MethodInfo methodInfo in array3)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
private static void OnExtendedModRegistered(ExtendedMod extendedMod)
{
if ((Object)(object)extendedMod == (Object)null)
{
return;
}
Logger.LogInfo((object)"OnExtendedModRegistered");
foreach (ExtendedItem extendedItem in extendedMod.ExtendedItems)
{
string configValueForItem = GetConfigValueForItem(extendedItem.Item.itemName);
if (!string.IsNullOrEmpty(configValueForItem))
{
List<StringWithRarity> collection = ConfigParsing(configValueForItem);
extendedItem.LevelMatchingProperties.levelTags.AddRange(collection);
extendedItem.LevelMatchingProperties.planetNames.AddRange(collection);
Logger.LogInfo((object)$"Updated matching properties for {extendedItem.Item}.");
}
}
}
private static string GetConfigValueForItem(string itemName)
{
switch (itemName)
{
case "CRT TV":
return Config.CrtTvSpawnWeight.Value;
case "Couch":
return Config.CouchSpawnWeight.Value;
case "L Couch":
return Config.LCouchSpawnWeight.Value;
case "XL Holder":
return null;
default:
Logger.LogInfo((object)("No configuration found for item type: " + itemName));
return null;
}
}
private static List<StringWithRarity> ConfigParsing(string configMoonRarity)
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Expected O, but got Unknown
List<StringWithRarity> list = new List<StringWithRarity>();
string[] array = configMoonRarity?.Split(",") ?? Array.Empty<string>();
foreach (string text in array)
{
string[] array2 = text.Trim().Split(":");
if (array2.Length == 2)
{
string text2 = array2[0];
if (int.TryParse(array2[1], out var result))
{
list.Add(new StringWithRarity(text2, result));
Logger.LogInfo((object)$"Registered spawn rate for {text2} to {result}");
}
}
}
return list;
}
private static void OnLethalBundleLoaded(AssetBundle assetBundle)
{
_ = (Object)(object)assetBundle == (Object)null;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "XLScrap";
public const string PLUGIN_NAME = "XL Scrap";
public const string PLUGIN_VERSION = "0.1.1";
}
}
namespace XLScrap.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}