using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("PeakSeededLoot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakSeededLoot")]
[assembly: AssemblyTitle("PeakSeededLoot")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 PeakSeededLoot
{
[BepInPlugin("Totomas15.peakseededloot", "PeakSeededLoot", "0.5.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<bool> UseMapSeed;
internal static ConfigEntry<int> Seed;
internal static ConfigEntry<string> BannedItems;
internal static ConfigEntry<bool> DisableGenerosity;
internal static ConfigEntry<bool> NoCampfireLoot;
internal static ConfigEntry<bool> NoBackpacks;
internal static ConfigEntry<KeyCode> MenuKey;
internal static ConfigEntry<bool> NoCampfireLuggage;
internal static ConfigEntry<bool> NoStatueRevive;
private static readonly string[] PhaseNames = new string[4] { "Phase 1", "Phase 3", "Phase 4", "Finale" };
private static readonly bool[][] PhaseValues = new bool[4][]
{
new bool[6] { true, true, false, false, false, false },
new bool[6] { true, true, false, false, false, true },
new bool[6] { true, true, true, true, true, false },
new bool[6] { true, true, false, false, false, false }
};
private bool _showMenu;
private Rect _rect = new Rect(20f, 20f, 400f, 220f);
internal static ManualLogSource Log;
internal static Random Current;
private static PropertyInfo _masterSeedProp;
private static bool _seedLookedUp;
private static ConfigEntry<bool>[] Flags()
{
return new ConfigEntry<bool>[6] { Enabled, DisableGenerosity, NoCampfireLoot, NoCampfireLuggage, NoBackpacks, NoStatueRevive };
}
internal static void ApplyPhase(int index)
{
ConfigEntry<bool>[] array = Flags();
for (int i = 0; i < array.Length; i++)
{
array[i].Value = PhaseValues[index][i];
}
Log.LogInfo((object)("Preset applique : " + PhaseNames[index]));
}
internal static string CurrentPhase()
{
ConfigEntry<bool>[] array = Flags();
List<string> list = new List<string>();
for (int i = 0; i < PhaseValues.Length; i++)
{
bool flag = true;
for (int j = 0; j < array.Length; j++)
{
if (array[j].Value != PhaseValues[i][j])
{
flag = false;
break;
}
}
if (flag)
{
list.Add(PhaseNames[i]);
}
}
return (list.Count == 0) ? "Personnalise" : string.Join(" / ", list.ToArray());
}
internal static string SettingsCode()
{
string text = string.Join("", (from x in Flags()
select x.Value ? "1" : "0").ToArray());
return text + "-" + (UseMapSeed.Value ? "1" : "0") + "-" + Seed.Value;
}
internal static HashSet<string> GetBanned()
{
HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (BannedItems == null || string.IsNullOrEmpty(BannedItems.Value))
{
return hashSet;
}
string[] array = BannedItems.Value.Split(',');
foreach (string text in array)
{
string text2 = text.Trim();
if (text2.Length > 0)
{
hashSet.Add(text2);
}
}
return hashSet;
}
private void Awake()
{
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0163: Expected O, but got Unknown
DisableGenerosity = ((BaseUnityPlugin)this).Config.Bind<bool>("Amulets", "DisableGenerosity", true, "Empêche l'apparition de l'amulette de générosité");
Log = ((BaseUnityPlugin)this).Logger;
Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Active le loot deterministe");
UseMapSeed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "UseMapSeed", true, "Utilise la seed de Terrain Randomiser si disponible");
Seed = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Seed", 12345, "Seed de secours (identique pour tous les joueurs)");
BannedItems = ((BaseUnityPlugin)this).Config.Bind<string>("General", "BannedItems", "", "Noms d'objets interdits dans le loot, separes par des virgules (ex: Flare,Jetpack)");
NoCampfireLoot = ((BaseUnityPlugin)this).Config.Bind<bool>("Campfire", "NoCampfireLoot", true, "Desactive le loot autour des feux de camp (nourriture, guimauves...)");
NoBackpacks = ((BaseUnityPlugin)this).Config.Bind<bool>("Campfire", "NoBackpacks", true, "Desactive les sacs a dos poses sur la map");
MenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Menu", "MenuKey", (KeyCode)289, "Touche pour ouvrir le menu en jeu");
NoCampfireLuggage = ((BaseUnityPlugin)this).Config.Bind<bool>("Campfire", "NoCampfireLuggage", true, "Desactive les valises posees autour des feux de camp");
NoStatueRevive = ((BaseUnityPlugin)this).Config.Bind<bool>("Statues", "NoStatueRevive", false, "Empeche de ressusciter les allies avec la statue");
Harmony val = new Harmony("Totomas15.peakseededloot");
val.PatchAll();
BackpackPatch.Apply(val);
PatchRandomSelection(val);
((BaseUnityPlugin)this).Logger.LogInfo((object)"PeakSeededLoot charge");
}
private void LateUpdate()
{
if (_showMenu)
{
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = true;
}
}
private void OnGUI()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
Event current = Event.current;
if (current != null && (int)current.type == 4 && current.keyCode == MenuKey.Value)
{
_showMenu = !_showMenu;
current.Use();
}
if (_showMenu)
{
_rect = GUILayout.Window(94021, _rect, new WindowFunction(DrawWindow), "PeakSeededLoot (" + ((object)MenuKey.Value/*cast due to .constrained prefix*/).ToString() + " pour fermer)", Array.Empty<GUILayoutOption>());
}
}
private void DrawWindow(int id)
{
GUILayout.Label("Phase detectee : " + CurrentPhase(), Array.Empty<GUILayoutOption>());
GUILayout.Label("Code de reglages : " + SettingsCode(), Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
for (int i = 0; i < PhaseNames.Length; i++)
{
if (GUILayout.Button(PhaseNames[i], Array.Empty<GUILayoutOption>()))
{
ApplyPhase(i);
}
}
GUILayout.EndHorizontal();
GUILayout.Space(8f);
ToggleEntry(Enabled, "Loot deterministe (valises, buissons...)");
ToggleEntry(DisableGenerosity, "Bloquer l'amulette de generosite");
ToggleEntry(NoCampfireLoot, "Pas de loot autour des feux de camp");
ToggleEntry(NoCampfireLuggage, "Pas de valises autour des feux de camp");
ToggleEntry(NoBackpacks, "Pas de sacs a dos");
ToggleEntry(NoStatueRevive, "Pas de resurrection via les statues");
GUI.DragWindow();
}
private static void ToggleEntry(ConfigEntry<bool> entry, string label)
{
bool flag = GUILayout.Toggle(entry.Value, label, Array.Empty<GUILayoutOption>());
if (flag != entry.Value)
{
entry.Value = flag;
}
}
private static void PatchRandomSelection(Harmony harmony)
{
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Expected O, but got Unknown
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Expected O, but got Unknown
try
{
MethodInfo methodInfo = null;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
string name = assembly.GetName().Name;
if (!name.StartsWith("Assembly-CSharp") && !name.StartsWith("Zorro"))
{
continue;
}
Type[] array;
try
{
array = assembly.GetTypes();
}
catch (ReflectionTypeLoadException ex)
{
array = ex.Types.Where((Type x) => x != null).ToArray();
}
Type[] array2 = array;
foreach (Type type in array2)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo2 in methods)
{
if (methodInfo2.Name == "RandomSelection" && methodInfo2.IsGenericMethodDefinition && methodInfo2.GetParameters().Length == 2)
{
Log.LogInfo((object)("RandomSelection trouvee : " + type.FullName + " (" + name + ")"));
methodInfo = methodInfo2;
}
}
}
}
if (methodInfo == null)
{
Log.LogWarning((object)"RandomSelection introuvable !");
return;
}
MethodInfo methodInfo3 = methodInfo.MakeGenericMethod(typeof(KeyValuePair<ushort, int>));
harmony.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(RandomSel).GetMethod("PrefixKvp", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MethodInfo methodInfo4 = methodInfo.MakeGenericMethod(typeof(WeightedSpawnPointEntry));
harmony.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(RandomSel).GetMethod("PrefixSpot", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"RandomSelection patchee (2 variantes)");
}
catch (Exception ex2)
{
Log.LogWarning((object)("Patch RandomSelection echoue : " + ex2));
}
}
internal static int GetMapSeed()
{
try
{
if (!_seedLookedUp)
{
_seedLookedUp = true;
Type type = Type.GetType("TerrainRandomiser.Plugin, TerrainRandomiser");
if (type != null)
{
_masterSeedProp = type.GetProperty("masterSeed", BindingFlags.Static | BindingFlags.Public);
}
Log.LogInfo((object)((_masterSeedProp != null) ? "Terrain Randomiser detecte, seed de map utilisee" : "Terrain Randomiser introuvable, seed de config utilisee"));
}
if (_masterSeedProp != null)
{
return (int)_masterSeedProp.GetValue(null, null);
}
}
catch (Exception)
{
}
return -1;
}
internal static int ComputeSeed(Spawner s)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
int num = Seed.Value;
if (UseMapSeed.Value)
{
int mapSeed = GetMapSeed();
if (mapSeed >= 0)
{
num = mapSeed;
}
}
Vector3 position = ((Component)s).transform.position;
int num2 = 17;
num2 = num2 * 31 + num;
num2 = num2 * 31 + Mathf.RoundToInt(position.x * 100f);
num2 = num2 * 31 + Mathf.RoundToInt(position.y * 100f);
num2 = num2 * 31 + Mathf.RoundToInt(position.z * 100f);
string text = ((Object)((Component)s).gameObject).name ?? "";
for (int i = 0; i < text.Length; i++)
{
num2 = num2 * 31 + text[i];
}
return num2;
}
}
internal static class RandomSel
{
private static T Pick<T>(IEnumerable<T> enumerable, Func<T, int> weightFunc, Random rng)
{
int num = 0;
T result = default(T);
foreach (T item in enumerable)
{
int num2 = weightFunc(item);
if (rng.Next(num + num2) >= num)
{
result = item;
}
num += num2;
}
return result;
}
private static bool PrefixKvp(IEnumerable<KeyValuePair<ushort, int>> __0, Func<KeyValuePair<ushort, int>, int> __1, ref KeyValuePair<ushort, int> __result)
{
Random current = Plugin.Current;
if (current == null)
{
return true;
}
__result = Pick(__0, __1, current);
return false;
}
private static bool PrefixSpot(IEnumerable<WeightedSpawnPointEntry> __0, Func<WeightedSpawnPointEntry, int> __1, ref WeightedSpawnPointEntry __result)
{
Random current = Plugin.Current;
if (current == null)
{
return true;
}
__result = Pick(__0, __1, current);
return false;
}
}
internal struct SavedRandom
{
public State Unity;
public Random Sys;
}
[HarmonyPatch(typeof(RespawnChest), "RespawnAllPlayersHere")]
internal static class StatueRevivePatch
{
[HarmonyPrefix]
private static bool Prefix()
{
if (!Plugin.NoStatueRevive.Value)
{
return true;
}
Plugin.Log.LogInfo((object)"[STATUE] resurrection bloquee");
return false;
}
}
[HarmonyPatch(typeof(MapHandler), "SpawnCampfireItems")]
internal static class CampfireLootPatch
{
[HarmonyPrefix]
private static bool Prefix(GameObject campfireRoot)
{
if (Plugin.NoCampfireLuggage.Value && (Object)(object)campfireRoot != (Object)null)
{
Luggage[] componentsInChildren = campfireRoot.GetComponentsInChildren<Luggage>(true);
foreach (Luggage val in componentsInChildren)
{
if (!(val is RespawnChest) && ((Component)val).gameObject.activeSelf)
{
Plugin.Log.LogInfo((object)("[CAMPFIRE] valise desactivee : " + ((Object)((Component)val).gameObject).name));
((Component)val).gameObject.SetActive(false);
}
}
}
return !Plugin.NoCampfireLoot.Value;
}
}
internal static class BackpackPatch
{
internal static void Apply(Harmony harmony)
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
try
{
Type type = AccessTools.TypeByName("SingleItemSpawner");
MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "TrySpawnItems", (Type[])null, (Type[])null));
if (methodInfo == null)
{
Plugin.Log.LogWarning((object)"SingleItemSpawner.TrySpawnItems introuvable : sacs a dos non geres");
return;
}
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(BackpackPatch).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Plugin.Log.LogInfo((object)"SingleItemSpawner patche");
}
catch (Exception ex)
{
Plugin.Log.LogWarning((object)("Patch sacs a dos echoue : " + ex.Message));
}
}
private static bool Prefix(object __instance, ref List<PhotonView> __result)
{
if (!Plugin.NoBackpacks.Value)
{
return true;
}
Component val = (Component)((__instance is Component) ? __instance : null);
if ((Object)(object)val == (Object)null || ((Object)val.gameObject).name.IndexOf("Backpack", StringComparison.OrdinalIgnoreCase) < 0)
{
return true;
}
__result = new List<PhotonView>();
Plugin.Log.LogInfo((object)("[BACKPACK] bloque : " + ((Object)val.gameObject).name));
return false;
}
}
[HarmonyPatch]
internal static class AmuletPatches
{
private static MethodBase TargetMethod()
{
Type type = AccessTools.TypeByName("Peak.PropSpawner_AmuletStatues");
return (type == null) ? null : AccessTools.Method(type, "GetPropToSpawn", (Type[])null, (Type[])null);
}
private static bool Prepare()
{
return TargetMethod() != null;
}
private static void Postfix(object __instance, ref GameObject __result)
{
if (!Plugin.DisableGenerosity.Value || (Object)(object)__result == (Object)null)
{
return;
}
GameObject[] value = Traverse.Create(__instance).Field("props").GetValue<GameObject[]>();
if (value == null || value.Length < 4 || (Object)(object)value[3] == (Object)null)
{
return;
}
GameObject generosity = value[3];
if (!(((Object)__result).name != ((Object)generosity).name))
{
List<GameObject> list = value.Where((GameObject p) => (Object)(object)p != (Object)null && ((Object)p).name != ((Object)generosity).name).ToList();
if (list.Count == 0)
{
Plugin.Log.LogWarning((object)"[AMULETS] Aucune amulette alternative disponible !");
return;
}
int index = ((Plugin.Current != null) ? Plugin.Current.Next(list.Count) : Random.Range(0, list.Count));
__result = list[index];
Plugin.Log.LogInfo((object)("[AMULETS] Generosity bloquée ! Remplacée par : " + ((Object)__result).name));
}
}
}
[HarmonyPatch]
internal static class SpawnerPatches
{
private static void Begin(Spawner s, out SavedRandom saved)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
saved = default(SavedRandom);
saved.Unity = Random.state;
saved.Sys = Plugin.Current;
if (Plugin.Enabled.Value)
{
int num = Plugin.ComputeSeed(s);
Random.InitState(num);
Plugin.Current = new Random(num);
}
}
private static void End(SavedRandom saved)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
Random.state = saved.Unity;
Plugin.Current = saved.Sys;
}
[HarmonyPatch(typeof(Spawner), "TrySpawnItems")]
[HarmonyPrefix]
private static void TryPre(Spawner __instance, out SavedRandom __state)
{
Begin(__instance, out __state);
}
[HarmonyPatch(typeof(Spawner), "TrySpawnItems")]
[HarmonyFinalizer]
private static void TryFin(SavedRandom __state)
{
End(__state);
}
[HarmonyPatch(typeof(Spawner), "GetSpawnSpots")]
[HarmonyPrefix]
private static void SpotsPre(Spawner __instance, out SavedRandom __state)
{
Begin(__instance, out __state);
}
[HarmonyPatch(typeof(Spawner), "GetSpawnSpots")]
[HarmonyFinalizer]
private static void SpotsFin(SavedRandom __state)
{
End(__state);
}
[HarmonyPatch(typeof(Spawner), "SpawnItems")]
[HarmonyPrefix]
private static void ItemsPre(Spawner __instance, out SavedRandom __state)
{
Begin(__instance, out __state);
}
[HarmonyPatch(typeof(Spawner), "SpawnItems")]
[HarmonyFinalizer]
private static void ItemsFin(SavedRandom __state)
{
End(__state);
}
}
}