using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameplayEntities;
using HarmonyLib;
using LLGUI;
using LLScreen;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("com.github.daioutzu.saxoptions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SaxOptions")]
[assembly: AssemblyTitle("com.github.daioutzu.saxoptions")]
[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 SaxOptions
{
[BepInPlugin("com.github.daioutzu.saxoptions", "SaxOptions", "1.0.0")]
[BepInProcess("LLBlaze.exe")]
public class SaxOptions : BaseUnityPlugin
{
internal enum SaxActivation
{
ON,
STRIKE_MOVES,
BIG_HITS,
OFF
}
internal static ManualLogSource Logger;
internal ConfigEntry<SaxActivation> configSaxAvtivation;
internal static SaxOptions Instance { get; private set; }
internal static Harmony Harmony { get; private set; } = new Harmony("com.github.daioutzu.saxoptions");
private void Awake()
{
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
SetUpConfig();
Harmony.PatchAll(typeof(SaxPatches));
Logger.LogInfo((object)"Plugin com.github.daioutzu.saxoptions is loaded!");
((Behaviour)this).enabled = false;
}
private void SetUpConfig()
{
configSaxAvtivation = ((BaseUnityPlugin)this).Config.Bind<SaxActivation>("General", "Sax Activation", SaxActivation.ON, "Set when candyman's saxphone plays a sound");
}
}
internal class SaxPatches
{
private static OptionsBar saxOptionsBar;
[HarmonyPatch(typeof(HGFCCNMEEEF), "KKCLGMLJFCG")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AddSaxOptionsBarBeforeDefault(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.SearchForward((Func<CodeInstruction, bool>)((CodeInstruction il) => il.opcode == OpCodes.Ldstr && il.operand as string == "BT_USE_DEFAULTS")).ThrowIfNotMatch("Didn't find default button", (CodeMatch[])(object)new CodeMatch[0]).Advance(-2);
FieldInfo fieldInfo = val.Operand as FieldInfo;
val.Advance(-1).Insert((CodeInstruction[])(object)new CodeInstruction[3]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo),
Transpilers.EmitDelegate<Action<ScreenOptions>>((Action<ScreenOptions>)AddSaxOptionsBar)
});
return val.InstructionEnumeration();
}
private static void AddSaxOptionsBar(ScreenOptions screenOptions)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
OptionsBar obj = screenOptions.AddBar((OptionsBarType)6, "Sax Activation", (HNEDEAGADKO)0, new List<string> { "On", "Strike Moves", "Big Hits", "Off" });
obj.onChange = new BarDelegate(OnSaxSettingChange);
obj.enumSize = 4;
obj.curValue = (int)SaxOptions.Instance.configSaxAvtivation.Value;
obj.UpdateLooks();
saxOptionsBar = obj;
}
[HarmonyPatch(typeof(OptionsBar), "ResetToDefault")]
[HarmonyPrefix]
private static void ResetSaxOptions(OptionsBar __instance)
{
if (!((Object)(object)saxOptionsBar == (Object)null) && !((Object)(object)__instance != (Object)(object)saxOptionsBar))
{
saxOptionsBar.curValue = (int)((ConfigEntryBase)SaxOptions.Instance.configSaxAvtivation).DefaultValue;
if (saxOptionsBar.onChange != null)
{
saxOptionsBar.onChange.Invoke(saxOptionsBar.curValue);
}
saxOptionsBar.UpdateLooks();
}
}
private static void OnSaxSettingChange(int val)
{
SaxOptions.Instance.configSaxAvtivation.Value = (SaxOptions.SaxActivation)val;
}
[HarmonyPatch(typeof(MovableEntity), "MaybeSax")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> AddsNewConditionToIf(IEnumerable<CodeInstruction> instructions)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Expected O, but got Unknown
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ea: Expected O, but got Unknown
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[3]
{
new CodeMatch((OpCode?)OpCodes.Ldfld, (object)typeof(MovableEntity).GetField("variant"), (string)null),
new CodeMatch((OpCode?)OpCodes.Ldc_I4_S, (object)(sbyte)12, (string)null),
new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
}).ThrowIfNotMatch("Didn't find If condition for Model_alt4", (CodeMatch[])(object)new CodeMatch[0]);
Label label = (Label)val.Operand;
val.Advance(1).SetAndAdvance(OpCodes.Ldloc_0, (object)null).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
{
Transpilers.EmitDelegate<Func<PlayerEntity, bool>>((Func<PlayerEntity, bool>)MaybePlaySax),
new CodeInstruction(OpCodes.Brfalse, (object)label),
new CodeInstruction(OpCodes.Ldc_I4_S, (object)(sbyte)95)
});
return val.InstructionEnumeration();
}
private static bool MaybePlaySax(PlayerEntity playerEntity)
{
SaxOptions.SaxActivation value = SaxOptions.Instance.configSaxAvtivation.Value;
string abilityState = ((MovableData)((AttackingEntity)playerEntity).attackingData).abilityState;
switch (value)
{
case SaxOptions.SaxActivation.ON:
return true;
case SaxOptions.SaxActivation.STRIKE_MOVES:
switch (abilityState)
{
default:
return abilityState == "DOWN_AIR_HIT";
case "SWING_HIT":
case "SMASH_OVERHEAD_HIT":
case "SMASH_FRONT_HIT":
return true;
}
case SaxOptions.SaxActivation.BIG_HITS:
if (!(abilityState == "SMASH_OVERHEAD_HIT") && !(abilityState == "SMASH_FRONT_HIT"))
{
return abilityState == "SWING_FULLCHARGE_HIT";
}
return true;
case SaxOptions.SaxActivation.OFF:
return false;
default:
return true;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.github.daioutzu.saxoptions";
public const string PLUGIN_NAME = "SaxOptions";
public const string PLUGIN_VERSION = "1.0.0";
}
}