using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Obeliskial_Essentials;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TheChosenOnes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TheChosenOnes")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ed3050ba-b23a-4aa5-a306-bd1a8508543d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TheChosenOnes;
public class GameConfig
{
public const string DefaultLootId = "thechosenshop";
public bool IsModEnabled => EnabledEntry?.Value ?? true;
public string InitialLootId => InitialLootIdEntry?.Value ?? "thechosenshop";
private ConfigEntry<string> InitialLootIdEntry { get; set; } = null;
private ConfigEntry<bool> EnabledEntry { get; set; } = null;
public GameConfig(ConfigEntry<string> initialLootIdEntry, ConfigEntry<bool> enabledEntry)
{
InitialLootIdEntry = initialLootIdEntry;
EnabledEntry = enabledEntry;
}
public GameConfig(ConfigFile config)
{
EnabledEntry = config.Bind<bool>("General", "EnableMod", true, "Enable or disable the mod");
InitialLootIdEntry = config.Bind<string>("General", "InitialLootIdx", "thechosenshop", "The loot list ID to have displayed once the game starts");
}
}
public static class ReflectionExtensions
{
public static void CopyPropertiesAndFields<T>(this T source, T destination)
{
if (source == null || destination == null)
{
return;
}
Type typeFromHandle = typeof(T);
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
PropertyInfo[] properties = typeFromHandle.GetProperties(bindingAttr);
PropertyInfo[] array = properties;
foreach (PropertyInfo propertyInfo in array)
{
if (propertyInfo.CanWrite)
{
object value = propertyInfo.GetValue(source, null);
propertyInfo.SetValue(destination, value, null);
}
}
FieldInfo[] fields = typeFromHandle.GetFields(bindingAttr);
FieldInfo[] array2 = fields;
foreach (FieldInfo fieldInfo in array2)
{
object value2 = fieldInfo.GetValue(source);
fieldInfo.SetValue(destination, value2);
}
}
}
public class OpenSpecialEquipmentLootPanelUseCase
{
private bool equipsWereGiven = false;
public void Open()
{
if (GameProvider.Config.IsModEnabled && !((Object)(object)MapManager.Instance == (Object)null) && !((Object)(object)AtOManager.Instance == (Object)null) && !((Object)(object)GameManager.Instance == (Object)null))
{
if (AtOManager.Instance.currentMapNode != "sen_0")
{
GameProvider.Log.LogInfo((object)"reset initial equips for next gameplay");
equipsWereGiven = false;
}
else if (!equipsWereGiven)
{
equipsWereGiven = true;
ProvideDisclaimerForMultiplayer();
GameProvider.Log.LogInfo((object)"opening loot rewards!");
((MonoBehaviour)GameProvider.Plugin).StartCoroutine(InitiateLootScene());
}
}
}
private static IEnumerator InitiateLootScene()
{
Type typeFromHandle = typeof(MapManager);
MethodInfo method = typeFromHandle.GetMethod("DoLoot", BindingFlags.Instance | BindingFlags.NonPublic);
object[] parameters = new object[1] { GameProvider.Config.InitialLootId };
return (IEnumerator)method.Invoke(MapManager.Instance, parameters);
}
private static void ProvideDisclaimerForMultiplayer()
{
if (GameManager.Instance.IsMultiplayer())
{
int count = Globals.Instance.CardListByClass[(CardClass)8].Count;
GameProvider.Log.LogWarning((object)"For multiplayer games, you and other players must have same checksum.");
GameProvider.Log.LogWarning((object)"This mod only requires you and the others to have the same loots");
GameProvider.Log.LogWarning((object)$"You have {count} loots available. Check with your friends whether they have the same quantity");
GameProvider.Log.LogWarning((object)"(in case you need to clean up your resources, look for the folder 'Obeliskial_importing' in your computer)");
}
}
}
public static class GameProvider
{
public static ManualLogSource Log { get; set; }
public static GameConfig Config { get; set; }
public static BaseUnityPlugin Plugin { get; set; }
}
[BepInPlugin("scotilen.thechosenones", "TheChosenOnes", "1.0.15")]
public class TheChosenOnesPlugin : BaseUnityPlugin
{
private void Awake()
{
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
GameProvider.Plugin = (BaseUnityPlugin)(object)this;
GameProvider.Config = new GameConfig(((BaseUnityPlugin)this).Config);
GameProvider.Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"TheChosenOnes loaded");
Essentials.RegisterMod("TheChosenOnes", "Scotilen", "TheChosenOnes", "1.0.15", 20251228, "https://github.com/miguelcjalmeida/TheChosenOnes", (string[])null, "TheChosenOnes", 100, (string[])null, "", true);
new Harmony("scotilen.thechosenones").PatchAll();
}
}
[HarmonyPatch(typeof(MapManager), "Start")]
public static class MapManagerStartPatch
{
private static OpenSpecialEquipmentLootPanelUseCase useCase = new OpenSpecialEquipmentLootPanelUseCase();
public static void Postfix()
{
useCase.Open();
}
}
[HarmonyPatch(typeof(AtOManager), "FinishObeliskDraft")]
public static class AtOManagerPatch
{
public static UseSpecialEquipmentInObeliskUseCase useCase = new UseSpecialEquipmentInObeliskUseCase();
public static void Prefix()
{
useCase.PretendItIsWeeklyChallenge();
}
public static void Postfix()
{
useCase.StopPretending();
}
}
[HarmonyPatch(typeof(AtOManager), "DoLoot")]
public static class AtOManagerDoLootPatch
{
public static void Prefix(ref string _lootListId)
{
if (_lootListId != null)
{
string nextLootList = AtOManagerPatch.useCase.getNextLootList(_lootListId);
_lootListId = nextLootList;
}
}
}
public class UseSpecialEquipmentInObeliskUseCase
{
private bool isPretendingToBeInWeeklyChallenge = false;
public void PretendItIsWeeklyChallenge()
{
if (!IsNotLoaded())
{
isPretendingToBeInWeeklyChallenge = true;
GameProvider.Log.LogInfo((object)"It is pretending to be in fake weekly challenge with legendary prizes");
}
}
public void StopPretending()
{
if (isPretendingToBeInWeeklyChallenge)
{
isPretendingToBeInWeeklyChallenge = false;
GameProvider.Log.LogInfo((object)"Stopped pretending to be in fake weekly challenge");
}
}
public string getNextLootList(string originalLootListId)
{
if (isPretendingToBeInWeeklyChallenge)
{
return GameProvider.Config.InitialLootId;
}
return originalLootListId;
}
private bool IsNotLoaded()
{
if ((Object)(object)GameManager.Instance == (Object)null)
{
return true;
}
if ((Object)(object)Globals.Instance == (Object)null)
{
return false;
}
return false;
}
}
public class Versioning
{
public const string ModIdentifier = "scotilen.thechosenones";
public const string ModName = "TheChosenOnes";
public const string WebsiteUrl = "https://github.com/miguelcjalmeida/TheChosenOnes";
public const string Description = "Have your heroes starting the game with an unique equipment to show how legendary they are.";
public const string Author = "Scotilen";
public const string SemanticVersion = "1.0.15";
public const int LastUpdateDate = 20251228;
public static IList<string> Dependencies = DetermineDependencies();
private static IList<string> DetermineDependencies()
{
List<string> list = new List<string>();
list.Add("BepInEx-BepInExPack_AcrossTheObelisk-5.4.23");
list.Add("meds-Obeliskial_Essentials-1.6.0");
list.Add("meds-Obeliskial_Content-1.7.0");
return list;
}
}