using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Atomicrops.Core.Loot;
using Atomicrops.Core.SoDb2;
using Atomicrops.Core.Upgrades;
using Atomicrops.Crops;
using Atomicrops.Game.Data;
using Atomicrops.Game.ParamsSystem;
using Atomicrops.Game.Upgrades;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using CustomParams;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SharedLib;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("CustomTimeCapsule")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomTimeCapsule")]
[assembly: AssemblyTitle("CustomTimeCapsule")]
[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 Template
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CustomTimeCapsule";
public const string PLUGIN_NAME = "CustomTimeCapsule";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace CustomTimeCapsule
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "pauli.plugin.customtimecapsule";
public const string PLUGIN_NAME = "CustomTimeCapsule";
public const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("pauli.plugin.customtimecapsule", "CustomTimeCapsule", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource Log;
private void Awake()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin pauli.plugin.customtimecapsule is loaded!");
new Harmony("pauli.plugin.customtimecapsule").PatchAll();
}
}
[HarmonyPatch(typeof(MetaPrevRunRewardUtils), "GenerateRewardModelAndClearPorfileFlag")]
public static class MetaPrevRunRewardUtilsPatch
{
public static Dictionary<string, UpgradeDef> DisplayNameToUpgradeDef = new Dictionary<string, UpgradeDef>();
public static List<string> ModdedUpgradeNames;
private static readonly string DllDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
private static bool _wroteModded = false;
public static void WriteVanillaUpgradeFile()
{
string path = Path.Combine(DllDir, "all_upgrade_names.txt");
string[] contents = DisplayNameToUpgradeDef.Keys.ToArray();
File.WriteAllLines(path, contents);
}
public static void WriteModdedUpgradeFile()
{
if (ModdedUpgradeNames.Count != 0)
{
string path = Path.Combine(DllDir, "modded_upgrade_names.txt");
File.WriteAllLines(path, ModdedUpgradeNames);
_wroteModded = true;
}
}
public static List<UpgradeDef> GetUpgradeDefs(List<string> upgradeNames)
{
List<UpgradeDef> list = new List<UpgradeDef>();
if (upgradeNames == null || upgradeNames.Count == 0)
{
return list;
}
foreach (string upgradeName in upgradeNames)
{
if (!DisplayNameToUpgradeDef.TryGetValue(upgradeName, out var value) || (Object)(object)value == (Object)null)
{
Plugin.Log.LogWarning((object)("Upgrade not found for display name: \"" + upgradeName + "\""));
continue;
}
list.Add(value);
RemoveFromLootPools(value);
}
return list;
}
public static void RemoveFromLootPools(UpgradeDef def)
{
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
int id = ((SoDb2Item)def).GetId();
if (id != 0)
{
if (SingletonScriptableObject<GameData>.I.MainLootCollection.Contains(id))
{
SingletonScriptableObject<GameData>.I.MainLootCollection.Remove(id);
}
else if (SingletonScriptableObject<GameData>.I.SpecialLootCollection.Contains(id))
{
SingletonScriptableObject<GameData>.I.SpecialLootCollection.Remove(id);
}
else if (SingletonScriptableObject<GameData>.I.DeerShopLootCollection.Contains(id))
{
SingletonScriptableObject<GameData>.I.DeerShopLootCollection.Remove(id);
}
else if (SingletonScriptableObject<GameData>.I.GoldenChestLootCollection.Contains(id))
{
SingletonScriptableObject<GameData>.I.GoldenChestLootCollection.Remove(id);
}
else if (!LiveParams.Meta.IsCrow && SingletonScriptableObject<GameData>.I.TreeUpgradeCollection.Contains(id))
{
SingletonScriptableObject<GameData>.I.TreeUpgradeCollection.Remove(id);
}
return;
}
List<int> list = (from i in Enumerable.Range(0, Upgrade.AllUpgradeDefs.Count)
where (Object)(object)Upgrade.AllUpgradeDefs[i] == (Object)(object)def
select i).ToList();
List<LootCollectionIdsEnum> lootPools = Upgrade.LootPools;
foreach (int item in list)
{
LootCollection lootCollectionFromEnum = GetLootCollectionFromEnum(lootPools[item]);
List<ILootDef> lootCollection = lootCollectionFromEnum.GetLootCollection();
lootCollection.Remove((ILootDef)(object)def);
}
}
public static LootCollection GetLootCollectionFromEnum(LootCollectionIdsEnum lootEnum)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected I4, but got Unknown
GameData i = SingletonScriptableObject<GameData>.I;
return (LootCollection)((int)lootEnum switch
{
0 => i.MainLootCollection,
1 => i.SpecialLootCollection,
2 => i.GoldenChestLootCollection,
3 => i.DeerShopLootCollection,
4 => i.CrowLootCollection,
5 => i.CrowOreganoLootCollection,
9 => i.CrowCropLevelingLootCollection,
6 => i.PowerSowLootCollection,
7 => i.GardenBedLootCollection,
8 => i.TreeUpgradeCollection,
_ => null,
});
}
[HarmonyPriority(200)]
private static bool Prefix(ref MetaPrevRunRewardsModel __result)
{
//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Expected O, but got Unknown
if (DisplayNameToUpgradeDef.Count == 0)
{
foreach (UpgradeDef item2 in UpgradeDefLoader.GetAll())
{
if (item2.LootProperties.DisplayName != null && !DisplayNameToUpgradeDef.ContainsKey(item2.LootProperties.DisplayName))
{
DisplayNameToUpgradeDef.Add(item2.LootProperties.DisplayName, item2);
}
}
}
if (Chainloader.PluginInfos.ContainsKey("pauli.plugin.CustomParams"))
{
ModdedUpgradeNames = new List<string>();
if (Upgrade.AllUpgradeDefs.Count > 0)
{
foreach (UpgradeDef allUpgradeDef in Upgrade.AllUpgradeDefs)
{
if (!DisplayNameToUpgradeDef.ContainsKey(allUpgradeDef.LootProperties.DisplayName) && !ModdedUpgradeNames.Contains(allUpgradeDef.LootProperties.DisplayName))
{
DisplayNameToUpgradeDef.Add(allUpgradeDef.LootProperties.DisplayName, allUpgradeDef);
ModdedUpgradeNames.Add(allUpgradeDef.LootProperties.DisplayName);
}
}
if (!_wroteModded)
{
WriteModdedUpgradeFile();
}
}
}
else if (!_wroteModded)
{
string path = Path.Combine(DllDir, "modded_upgrade_names.txt");
if (File.Exists(path))
{
File.WriteAllText(path, string.Empty);
_wroteModded = true;
}
}
ProfileModel val = SingletonSceneScopeAutoLoad<ProfileModelController>.I.Get();
MetaPrevRunRewardsModel val2 = new MetaPrevRunRewardsModel();
List<string> list = new List<string>();
string path2 = Path.Combine(DllDir, "desired_time_capsule.txt");
if (File.Exists(path2))
{
string[] array = File.ReadAllLines(path2);
string[] array2 = array;
foreach (string text in array2)
{
string item = text.Trim();
list.Add(item);
}
}
else
{
File.WriteAllText(path2, string.Empty);
}
List<UpgradeDef> upgradeDefs = GetUpgradeDefs(list);
if (Chainloader.PluginInfos.ContainsKey("pauli.plugin.CustomParams") && Upgrade.DebugPresent)
{
foreach (Upgrade allUpgrade in Upgrade.AllUpgrades)
{
if (allUpgrade.DoDebug)
{
upgradeDefs.Add(allUpgrade._upgradeDef);
}
}
}
val2.Upgrades = upgradeDefs;
val2.HeartPieces = LiveParams.Meta.TimeCapSummerHeartPieces;
val2.Friends = new List<FriendDef>();
List<FriendDef> farmAnimalsLevel = SingletonScriptableObject<ConfigGame>.I.Friends.FarmAnimalsLevel1;
val2.Friends.Add(farmAnimalsLevel[Random.Range(0, farmAnimalsLevel.Count)]);
val2.Fertilizer = 30;
val2.Seeds = new List<CropDef>();
int num = 10;
for (int j = 0; j < num; j++)
{
List<CropDef> cropsByValue = CropDefLoader.GetCropsByValue((ValueTierEnum)0);
val2.Seeds.Add(cropsByValue[Random.Range(0, cropsByValue.Count)]);
}
val.SeasonReachedOnPreviousRun = 0;
val.PreviousUpgrades = null;
SingletonSceneScopeAutoLoad<ProfileModelController>.I.SetDirty();
__result = val2;
return false;
}
}
}