using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 HutongGames.PlayMaker;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.blueraja.double_rosaries")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyInformationalVersion("1.4.0+f83cd5b0175296b8a399eb484cbdf5479f6085c6")]
[assembly: AssemblyProduct("Double Rosaries")]
[assembly: AssemblyTitle("com.blueraja.double_rosaries")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.4.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 double_rosaries
{
[BepInPlugin("com.blueraja.double_rosaries", "Double Rosaries", "1.4.0")]
[BepInProcess("Hollow Knight Silksong.exe")]
public class Plugin : BaseUnityPlugin
{
private static ConfigEntry<float> _rosaryMultiplier;
private static ManualLogSource Logger;
private const int DEFAULT_ROSARY_STRING_MACHINE_COST = 80;
private static readonly Random Random = new Random();
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
_rosaryMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Cheats", "RosaryMultiplier", 2f, "The multiplier for collecting rosaries. Fractional values work by randomly rounding up/down to get the desired multiplier on average.");
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin com.blueraja.double_rosaries is loaded!");
}
[HarmonyPatch(typeof(PlayerData), "AddGeo")]
[HarmonyPrefix]
private static void AddGeoPrefix(PlayerData __instance, ref int amount)
{
amount = RoundRandomly((float)amount * _rosaryMultiplier.Value);
}
[HarmonyPatch(typeof(HeroController), "CocoonBroken", new Type[]
{
typeof(bool),
typeof(bool)
})]
[HarmonyPrefix]
private static void CocoonBrokenPrefix(ref bool doAirPause, ref bool forceCanBind, HeroController __instance)
{
__instance.playerData.HeroCorpseMoneyPool = (int)Math.Round((float)__instance.playerData.HeroCorpseMoneyPool / _rosaryMultiplier.Value);
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void CostPostfix(ShopItem __instance, ref int __result)
{
string value = Traverse.Create((object)__instance).Field("displayName").Field<string>("Key")
.Value;
if (value.StartsWith("INV_NAME_COIN_SET"))
{
__result = (int)Math.Round((float)__result * _rosaryMultiplier.Value);
Logger.LogInfo((object)$"Set cost of {value} to {__result}");
}
}
[HarmonyPatch(typeof(PlayMakerNPC), "SendEvent")]
[HarmonyPrefix]
private static void OnStartDialoguePrefix(PlayMakerNPC __instance, ref string eventName)
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
if (((Object)__instance).name == "rosary_string_machine" && eventName == "INTERACT")
{
FsmObject val = ((IEnumerable<FsmObject>)Traverse.Create((object)__instance).Field<PlayMakerFSM>("dialogueFsm").Value.FsmVariables.ObjectVariables).FirstOrDefault((Func<FsmObject, bool>)((FsmObject o) => o.Value is CostReference));
if (val != null)
{
CostReference val2 = (CostReference)val.Value;
int num = (int)Math.Round(80f * _rosaryMultiplier.Value);
Traverse.Create((object)val2).Field<int>("value").Value = num;
Logger.LogInfo((object)$"Set cost of rosary string machine to {num}");
}
else
{
Logger.LogError((object)"Could not find cost reference for rosary_string_machine");
}
}
}
private static int RoundRandomly(float roundMe)
{
int num = (int)Math.Floor(roundMe);
float num2 = roundMe - (float)num;
if (!(num2 > 0f) || !((double)num2 > Random.NextDouble()))
{
return num;
}
return num + 1;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.blueraja.double_rosaries";
public const string PLUGIN_NAME = "Double Rosaries";
public const string PLUGIN_VERSION = "1.4.0";
}
}