using System;
using System.Collections.Generic;
using System.Diagnostics;
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 JLL.Components;
using JLLConfigurator.Modules;
using JLLConfigurator.Patches;
using JLLConfigurator.Utils;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("Tomatobird.JLLConfigurator")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+987f5271c313ec1e8838e19ec65fa5832c997a62")]
[assembly: AssemblyProduct("JLLConfigurator")]
[assembly: AssemblyTitle("Tomatobird.JLLConfigurator")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 JLLConfigurator
{
[BepInPlugin("Tomatobird.JLLConfigurator", "JLLConfigurator", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class JLLConfigurator : BaseUnityPlugin
{
internal static JRandomPropPlacerModule jRandomPropPlacerModule;
internal static ConfigFile config;
public static JLLConfigurator Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
internal static Harmony? Harmony { get; set; }
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
config = ((BaseUnityPlugin)this).Config;
jRandomPropPlacerModule = new JRandomPropPlacerModule(((BaseUnityPlugin)this).Config);
Patch();
Logger.LogInfo((object)"Tomatobird.JLLConfigurator v0.1.0 has loaded!");
}
internal static void Patch()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
if (Harmony == null)
{
Harmony = new Harmony("Tomatobird.JLLConfigurator");
}
Logger.LogDebug((object)"Patching...");
jRandomPropPlacerModule.TryPatch(Harmony, typeof(JRandomPropPlacerPatcher));
Logger.LogDebug((object)"Finished patching!");
}
internal static void Unpatch()
{
Logger.LogDebug((object)"Unpatching...");
Harmony? harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogDebug((object)"Finished unpatching!");
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Tomatobird.JLLConfigurator";
public const string PLUGIN_NAME = "JLLConfigurator";
public const string PLUGIN_VERSION = "0.1.0";
}
}
namespace JLLConfigurator.Utils
{
internal class CurveUtil
{
internal static AnimationCurve CreateCurve(string s)
{
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Expected O, but got Unknown
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
string[] array = s.Split(';');
if (array.Length == 1 && float.TryParse(array[0], out var result))
{
return AnimationCurve.Constant(0f, 1f, result);
}
List<Keyframe> list = new List<Keyframe>();
string[] array2 = array;
foreach (string text in array2)
{
string[] array3 = text.Split(",");
if (array3.Length == 2)
{
string s2 = array3[0].Trim();
string s3 = array3[1].Trim();
if (float.TryParse(s2, out var result2) && float.TryParse(s3, out var result3))
{
list.Add(new Keyframe(result2, result3));
}
}
else if (array3.Length == 6)
{
string s4 = array3[0].Trim();
string s5 = array3[1].Trim();
string s6 = array3[2].Trim();
string s7 = array3[3].Trim();
string s8 = array3[4].Trim();
string s9 = array3[5].Trim();
if (float.TryParse(s4, out var result4) && float.TryParse(s5, out var result5) && float.TryParse(s6, out var result6) && float.TryParse(s7, out var result7) && float.TryParse(s8, out var result8) && float.TryParse(s9, out var result9))
{
list.Add(new Keyframe(result4, result5, result6, result7, result8, result9));
}
}
}
return new AnimationCurve(list.ToArray());
}
internal static string CurveToString(AnimationCurve curve)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
List<string> list = new List<string>();
if (curve == null || curve.length == 0)
{
return "";
}
Keyframe[] keys = curve.keys;
for (int i = 0; i < keys.Length; i++)
{
Keyframe val = keys[i];
string item = $"{((Keyframe)(ref val)).time},{((Keyframe)(ref val)).value},{((Keyframe)(ref val)).inTangent},{((Keyframe)(ref val)).outTangent},{((Keyframe)(ref val)).inWeight},{((Keyframe)(ref val)).outWeight};";
list.Add(item);
}
string text = "";
foreach (string item2 in list)
{
text += item2;
}
return text.TrimEnd(';');
}
}
}
namespace JLLConfigurator.Patches
{
[HarmonyPatch(typeof(JRandomPropPlacer))]
internal class JRandomPropPlacerPatcher
{
[HarmonyPatch("SpawnProps")]
[HarmonyPrefix]
internal static bool SpawnProps_Prefix(JRandomPropPlacer __instance)
{
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
if (JLLConfigurator.jRandomPropPlacerModule.DisableSpawning.Value)
{
JLLConfigurator.Logger.LogInfo((object)"JRandomPropPlacer blocked from spawnning props.");
return false;
}
if (__instance.spawnableProps == null)
{
return true;
}
SpawnableProp[] spawnableProps = __instance.spawnableProps;
foreach (SpawnableProp val in spawnableProps)
{
if (val != null && !((Object)(object)val.prefabToSpawn == (Object)null))
{
if (!JRandomPropPlacerModule.ConfigCache.TryGetValue(((Object)val.prefabToSpawn).name, out JRandomPropPlacerModule.PropSetSettings value))
{
JLLConfigurator.Logger.LogDebug((object)("Generating configs for " + ((Object)val.prefabToSpawn).name));
value = new JRandomPropPlacerModule.PropSetSettings(JLLConfigurator.config, val);
JRandomPropPlacerModule.ConfigCache.Add(((Object)val.prefabToSpawn).name, value);
}
val.randomAmount = CurveUtil.CreateCurve(value.randomAmount.Value);
val.prefabWidth = value.prefabWidth.Value;
val.spawnRotation = value.spawnRotation.Value;
val.spawnFlushAgainstWall = value.spawnFlushAgainstWall.Value;
val.distanceFromEntrances = value.distanceFromEntrances.Value;
val.distanceBetweenSpawns = value.distanceBetweenSpawns.Value;
val.randomSpawnRange = value.randomSpawnRange.Value;
}
}
return true;
}
}
}
namespace JLLConfigurator.Modules
{
internal abstract class ConfigModule
{
public ConfigEntry<bool> Enabled;
public string Name { get; }
internal ConfigModule(ConfigFile config, string moduleName)
{
Name = moduleName;
Enabled = config.Bind<bool>("General", "Enable" + moduleName + "Config", true, "Enable configuration of " + moduleName + "?");
BindSettings(config);
}
internal abstract void BindSettings(ConfigFile config);
public void TryPatch(Harmony harmony, Type patchClass)
{
if (Enabled.Value)
{
JLLConfigurator.Logger.LogDebug((object)("Patching " + patchClass.Name));
harmony.PatchAll(patchClass);
}
}
}
internal class JRandomPropPlacerModule : ConfigModule
{
internal class PropSetSettings
{
public ConfigEntry<string> randomAmount;
public ConfigEntry<float> prefabWidth;
public ConfigEntry<SpawnRotation> spawnRotation;
public ConfigEntry<bool> spawnFlushAgainstWall;
public ConfigEntry<float> distanceFromEntrances;
public ConfigEntry<float> distanceBetweenSpawns;
public ConfigEntry<float> randomSpawnRange;
public PropSetSettings(ConfigFile config, SpawnableProp prop)
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
string text = "JRandomPropPlacer.Prop." + ((Object)prop.prefabToSpawn).name;
randomAmount = config.Bind<string>(text, "RandomAmount", CurveUtil.CurveToString(prop.randomAmount), "The randomizer curve used to randomize how many props should spawn. Values are evaluated from 0 to 1. Ex: 0,5 ; 0.5,5 ; 1,10 for a curve with first half flat at value 5 then linear increase to value 15 on other half. You can type in a single constant value as well. Ex: 10 You can also define in/out tangets and weights for each key like so: 0.4,0.2,1.1,2,0.4,0.6 (Check Keyframe declaration in unity documentation!)");
prefabWidth = config.Bind<float>(text, "PrefabWidth", prop.prefabWidth, "Define width of the prefab.");
spawnRotation = config.Bind<SpawnRotation>(text, "SpawnRotation", prop.spawnRotation, "Define spawn rotation.");
spawnFlushAgainstWall = config.Bind<bool>(text, "SpawnFlushAgainstWall", prop.spawnFlushAgainstWall, "Should prop spawn flush against wall?");
distanceFromEntrances = config.Bind<float>(text, "DistanceFromEntrances", prop.distanceFromEntrances, "Define distance from entrances.");
distanceBetweenSpawns = config.Bind<float>(text, "DistanceBetweenSpawns", prop.distanceBetweenSpawns, "Define distance between sapawns.");
randomSpawnRange = config.Bind<float>(text, "RandomSpawnRange", prop.randomSpawnRange, "Define random spawn range.");
}
}
public static Dictionary<string, PropSetSettings> ConfigCache = new Dictionary<string, PropSetSettings>();
public ConfigEntry<bool> DisableSpawning { get; private set; } = null;
public JRandomPropPlacerModule(ConfigFile config)
: base(config, "JRandomPropPlacer")
{
}
internal override void BindSettings(ConfigFile config)
{
DisableSpawning = config.Bind<bool>(base.Name, "DisableSpawning", false, "Should JRandomPropPlacer be allowed to spawn objects? Setting this on effectively disables JRandomPropPlacer.");
}
}
}