using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("RNGConfigurator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Allows the host to override the chance of random events.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RNGConfigurator")]
[assembly: AssemblyTitle("RNGConfigurator")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace RNGConfigurator
{
[BepInPlugin("RNGConfigurator", "RNGConfigurator", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private static readonly Harmony harmony = new Harmony("RNGConfigurator");
private static double sidChance;
private static double meteorChance;
private static double infestationChance;
private static Exception PatchFailedException => new InvalidOperationException("Failed to find matching instructions.");
private void Awake()
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Expected O, but got Unknown
sidChance = ((BaseUnityPlugin)this).Config.Bind<double>("Settings", "SIDChance", 5.2, new ConfigDescription("The chance of any given day being a single item day.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.0, 100.0), Array.Empty<object>())).Value / 100.0;
meteorChance = ((BaseUnityPlugin)this).Config.Bind<double>("Settings", "MeteorChance", 0.7, new ConfigDescription("The chance of a meteor shower occurring on any given day.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.0, 100.0), Array.Empty<object>())).Value / 100.0;
infestationChance = ((BaseUnityPlugin)this).Config.Bind<double>("Settings", "InfestationChance", 9.0, new ConfigDescription("The chance of a hoarding bug infestation occurring on any given day.", (AcceptableValueBase)(object)new AcceptableValueRange<double>(0.0, 100.0), Array.Empty<object>())).Value / 100.0;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Config loaded successfully");
harmony.PatchAll(typeof(Plugin));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patches completed successfully");
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
private static IEnumerable<CodeInstruction> OverrideSidChance(IEnumerable<CodeInstruction> instructions)
{
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Expected O, but got Unknown
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
for (int i = 4; i < list.Count; i++)
{
if (list[i - 4].opcode == OpCodes.Ldc_I4_0 && CodeInstructionExtensions.Is(list[i - 3], OpCodes.Ldc_I4, (object)500) && CodeInstructionExtensions.Calls(list[i - 2], AccessTools.Method(typeof(Random), "Next", new Type[2]
{
typeof(int),
typeof(int)
}, (Type[])null)) && CodeInstructionExtensions.Is(list[i - 1], OpCodes.Ldc_I4_S, (object)25) && list[i].opcode == OpCodes.Bgt)
{
object operand = list[i].operand;
list.RemoveRange(i -= 4, 5);
list.InsertRange(i, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[3]
{
CodeInstruction.Call(typeof(Random), "NextDouble", (Type[])null, (Type[])null),
new CodeInstruction(OpCodes.Ldc_R8, (object)sidChance),
new CodeInstruction(OpCodes.Bge, operand)
}));
return list;
}
}
throw PatchFailedException;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(TimeOfDay), "DecideRandomDayEvents")]
private static IEnumerable<CodeInstruction> OverrideMeteorChance(IEnumerable<CodeInstruction> instructions)
{
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
for (int i = 3; i < list.Count; i++)
{
if (list[i - 3].opcode == OpCodes.Ldc_I4_0 && CodeInstructionExtensions.Is(list[i - 2], OpCodes.Ldc_I4, (object)1000) && CodeInstructionExtensions.Calls(list[i - 1], AccessTools.Method(typeof(Random), "Next", new Type[2]
{
typeof(int),
typeof(int)
}, (Type[])null)) && CodeInstructionExtensions.IsLdloc(list[i], (LocalBuilder)null))
{
list.RemoveRange(i -= 3, 4);
list.InsertRange(i, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[2]
{
CodeInstruction.Call(typeof(Random), "NextDouble", (Type[])null, (Type[])null),
new CodeInstruction(OpCodes.Ldc_R8, (object)meteorChance)
}));
return list;
}
}
throw PatchFailedException;
}
[HarmonyTranspiler]
[HarmonyPatch(typeof(RoundManager), "RefreshEnemiesList")]
private static IEnumerable<CodeInstruction> OverrideInfestationChance(IEnumerable<CodeInstruction> instructions)
{
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
List<CodeInstruction> list = instructions.ToList();
for (int i = 3; i < list.Count; i++)
{
if (list[i - 3].opcode == OpCodes.Ldc_I4_0 && CodeInstructionExtensions.Is(list[i - 2], OpCodes.Ldc_I4_S, (object)100) && CodeInstructionExtensions.Calls(list[i - 1], AccessTools.Method(typeof(Random), "Next", new Type[2]
{
typeof(int),
typeof(int)
}, (Type[])null)) && CodeInstructionExtensions.Is(list[i], OpCodes.Ldc_I4_S, (object)9))
{
list.RemoveRange(i -= 3, 4);
list.InsertRange(i, new <>z__ReadOnlyArray<CodeInstruction>((CodeInstruction[])(object)new CodeInstruction[2]
{
CodeInstruction.Call(typeof(Random), "NextDouble", (Type[])null, (Type[])null),
new CodeInstruction(OpCodes.Ldc_R8, (object)infestationChance)
}));
return list;
}
}
throw PatchFailedException;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "RNGConfigurator";
public const string PLUGIN_NAME = "RNGConfigurator";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
internal sealed class <>z__ReadOnlyArray<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
int ICollection.Count => _items.Length;
bool ICollection.IsSynchronized => false;
object ICollection.SyncRoot => this;
object IList.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
bool IList.IsFixedSize => true;
bool IList.IsReadOnly => true;
int IReadOnlyCollection<T>.Count => _items.Length;
T IReadOnlyList<T>.this[int index] => _items[index];
int ICollection<T>.Count => _items.Length;
bool ICollection<T>.IsReadOnly => true;
T IList<T>.this[int index]
{
get
{
return _items[index];
}
set
{
throw new NotSupportedException();
}
}
public <>z__ReadOnlyArray(T[] items)
{
_items = items;
}
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable)_items).GetEnumerator();
}
void ICollection.CopyTo(Array array, int index)
{
((ICollection)_items).CopyTo(array, index);
}
int IList.Add(object value)
{
throw new NotSupportedException();
}
void IList.Clear()
{
throw new NotSupportedException();
}
bool IList.Contains(object value)
{
return ((IList)_items).Contains(value);
}
int IList.IndexOf(object value)
{
return ((IList)_items).IndexOf(value);
}
void IList.Insert(int index, object value)
{
throw new NotSupportedException();
}
void IList.Remove(object value)
{
throw new NotSupportedException();
}
void IList.RemoveAt(int index)
{
throw new NotSupportedException();
}
IEnumerator<T> IEnumerable<T>.GetEnumerator()
{
return ((IEnumerable<T>)_items).GetEnumerator();
}
void ICollection<T>.Add(T item)
{
throw new NotSupportedException();
}
void ICollection<T>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<T>.Contains(T item)
{
return ((ICollection<T>)_items).Contains(item);
}
void ICollection<T>.CopyTo(T[] array, int arrayIndex)
{
((ICollection<T>)_items).CopyTo(array, arrayIndex);
}
bool ICollection<T>.Remove(T item)
{
throw new NotSupportedException();
}
int IList<T>.IndexOf(T item)
{
return ((IList<T>)_items).IndexOf(item);
}
void IList<T>.Insert(int index, T item)
{
throw new NotSupportedException();
}
void IList<T>.RemoveAt(int index)
{
throw new NotSupportedException();
}
}