using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using I2.Loc;
using Microsoft.CodeAnalysis;
using MonsterLove.StateMachine;
using NineSolsAPI.Utils;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.Timeline;
[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("TopTenReasons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("TopTenReasons Mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e5543fcb5b6229e8e580d20b38c8376b8338930f")]
[assembly: AssemblyProduct("TopTenReasons")]
[assembly: AssemblyTitle("TopTenReasons")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 TopTenReasons
{
internal static class Log
{
private static ManualLogSource? logSource;
internal static void Init(ManualLogSource logSource)
{
Log.logSource = logSource;
}
internal static void Debug(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogDebug(data);
}
}
internal static void Error(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogError(data);
}
}
internal static void Fatal(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogFatal(data);
}
}
internal static void Info(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogInfo(data);
}
}
internal static void Message(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogMessage(data);
}
}
internal static void Warning(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogWarning(data);
}
}
internal static void Exception(Exception exception, string? messsage = null)
{
if (messsage != null)
{
Error(exception.Message + ". Message: " + messsage + " \n" + exception.StackTrace);
}
else
{
Error(exception.Message + ". \n" + exception.StackTrace);
}
}
}
[HarmonyPatch(typeof(MonsterBase))]
internal static class MonsterBasePatches
{
internal static event Action<MonsterBase>? OnCheckInitPostfix;
[HarmonyPatch("CheckInit")]
[HarmonyPostfix]
private static void CheckInitPostfix(MonsterBase __instance)
{
try
{
MonsterBasePatches.OnCheckInitPostfix?.Invoke(__instance);
}
catch (Exception ex)
{
Log.Error($"Failed in MonsterBase.CheckInit postfix: {ex}. \n {ex.StackTrace}");
}
}
}
internal static class MonsterStatesHelper
{
public static void SubscibeOnStateUpdateOnce(StateMapping<States> stateMapping, Action action)
{
StateMapping<States> stateMapping2 = stateMapping;
Action action2 = action;
StateMapping<States> obj = stateMapping2;
((StateMapping)obj).Update = (Action)Delegate.Combine(((StateMapping)obj).Update, new Action(OnStateUpdate));
StateMapping<States> obj2 = stateMapping2;
((StateMapping)obj2).ExitCall = (Action)Delegate.Combine(((StateMapping)obj2).ExitCall, new Action(OnStateExit));
void OnStateExit()
{
StateMapping<States> obj3 = stateMapping2;
((StateMapping)obj3).Update = (Action)Delegate.Remove(((StateMapping)obj3).Update, new Action(OnStateUpdate));
StateMapping<States> obj4 = stateMapping2;
((StateMapping)obj4).ExitCall = (Action)Delegate.Remove(((StateMapping)obj4).ExitCall, new Action(OnStateExit));
}
void OnStateUpdate()
{
action2?.Invoke();
}
}
}
[HarmonyPatch(typeof(TimelineMurmur))]
internal static class TimelineMurmurPatches
{
private static FieldInfo timelineFieldInfo = AccessTools.Field(typeof(TimelineMurmur), "timeline");
private static FieldInfo isPlayingFieldInfo = AccessTools.Field(typeof(TimelineMurmur), "isPlaying");
private static readonly MethodInfo replacementInstance = AccessTools.Method(typeof(TimelineMurmurPatches), "PlayBubbleTimeline_Replacement", new Type[1] { typeof(TimelineMurmur) }, (Type[])null);
private static void PlayBubbleTimeline_Replacement(TimelineMurmur __instance)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
PlayableDirector val = (PlayableDirector)timelineFieldInfo.GetValue(__instance);
bool flag = (bool)isPlayingFieldInfo.GetValue(__instance);
if ((Object)(object)__instance.isPlayed == (Object)null || !__instance.isPlayed.FlagValue)
{
if (!flag)
{
isPlayingFieldInfo.SetValue(__instance, true);
val.Play();
}
}
else
{
__instance.isPlayed.FlagValue = true;
}
}
[HarmonyPatch("PlayBubbleTimeline")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler_PlayBubbleTimeline(IEnumerable<CodeInstruction> instructions)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
return new List<CodeInstruction>
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Callvirt, (object)replacementInstance),
new CodeInstruction(OpCodes.Ret, (object)null)
};
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("TopTenReasons", "TopTenReasons", "1.0.0")]
public class TopTenReasons : BaseUnityPlugin
{
public const string MURMUR_PREFAB_NAME = "a0_s1_intro_morning/gamelevel/room1/[timeline]a0_s1_npcdialogues/[timeline]murmurbubble00.prefab";
public const string ASSET_BUNDLE_EMBEDDED_PATH = "TopTenReasons.Resources.nkvbundle.bundle";
public const string YI_GUNG_NAME = "Boss_Yi Gung";
public const string TRUE_ENDING_SCENE_NAME = "A11_S0_Boss_YiGung";
public const string ENDING_SCENE_NAME = "A11_S0_Boss_YiGung_回蓬萊";
public const string MURMUR_LINE = "Eigong/ReasonsPresent/TopTen";
public const string MURMUR_LINE_CONTENT = "Top 10 reasons eigongs talisman is fair and you're stupid";
private static readonly Dictionary<string, string> Languages = new Dictionary<string, string>
{
{ "zh-TW", "繁體中文 (Traditional Chinese) [zh-TW]" },
{ "zh-CN", "简体中文 (Simplified Chinese) [zh-CN]" },
{ "en-US", "English" },
{ "ko", "한국어 (Korean) [ko]" },
{ "ja", "日本語 (Japanese) [ja]" },
{ "es-US", "Spanish (Latin Americas)" },
{ "de-DE", "German (Germany)" },
{ "fr-FR", "French (France)" },
{ "ru", "Russian" },
{ "uk", "Ukrainian" },
{ "pt-BR", "Português - Brasil [pt-BR]" },
{ "pl", "Polski (Polish)" },
{ "es-ES", "Español - España (Spanish - Spain)" }
};
internal static TopTenReasons Instance = null;
internal GameObject? BubblePrefab;
internal TimelineMurmur? MurmurTimeLine;
private Harmony harmony;
private float _explosionTime = 1.8f;
private void Awake()
{
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
try
{
Instance = this;
Log.Init(((BaseUnityPlugin)this).Logger);
RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
harmony = Harmony.CreateAndPatchAll(typeof(TopTenReasons).Assembly, (string)null);
AssetBundle embeddedAssetBundle = AssemblyUtils.GetEmbeddedAssetBundle("TopTenReasons.Resources.nkvbundle.bundle");
BubblePrefab = (GameObject)((embeddedAssetBundle != null) ? embeddedAssetBundle.LoadAsset("a0_s1_intro_morning/gamelevel/room1/[timeline]a0_s1_npcdialogues/[timeline]murmurbubble00.prefab") : null);
if ((Object)(object)BubblePrefab != (Object)null)
{
BubblePrefab.SetActive(false);
BubblePrefab.transform.localPosition = Vector3.zero;
Object.Destroy((Object)(object)BubblePrefab.GetComponent<RCGCullingGroup>());
BubblePrefab.GetComponent<TimelineMurmur>().isPlayed = null;
}
AddLocalization();
MonsterBasePatches.OnCheckInitPostfix += HandleMurmurCreation;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TopTenReasons is loaded!");
}
catch (Exception exception)
{
Log.Exception(exception);
}
}
private void HandleMurmurCreation(MonsterBase monster)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
MonsterBase monster2 = monster;
StateMapping<States> chargeFooMapping;
StateMapping<States> quickFooMapping;
bool played;
try
{
Scene scene = ((Component)monster2).gameObject.scene;
if (!(((Scene)(ref scene)).name != "A11_S0_Boss_YiGung") || !(((Scene)(ref scene)).name != "A11_S0_Boss_YiGung_回蓬萊") || !(((Object)monster2).name != "Boss_Yi Gung"))
{
InitMurmur(((Component)monster2).gameObject);
Dictionary<States, StateMapping<States>> dictionary = (Dictionary<States, StateMapping<States>>)AccessTools.Field(typeof(StateMachine<States>), "stateLookup").GetValue(monster2.fsm);
chargeFooMapping = dictionary[(States)161];
quickFooMapping = dictionary[(States)207];
played = false;
monster2.fsm.Changed += HandleStateChange;
}
}
catch (Exception exception)
{
Log.Exception(exception);
}
void HandleFooStateUpdate(float stateTimer)
{
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
if (!played && !(stateTimer < _explosionTime) && !((Object)(object)MurmurTimeLine == (Object)null) && Player.i.CurrentStateType == ((PlayerBaseState)Player.i.PlayerDeadState).stateType)
{
((Component)MurmurTimeLine).gameObject.SetActive(true);
MurmurTimeLine.PlayBubbleTimeline();
played = true;
}
}
void HandleStateChange(States state)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Invalid comparison between Unknown and I4
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Invalid comparison between Unknown and I4
if ((int)state == 161)
{
MonsterState monsterState2 = monster2.FindState((States)161);
MonsterStatesHelper.SubscibeOnStateUpdateOnce(chargeFooMapping, delegate
{
HandleFooStateUpdate(((MappingState)monsterState2).statusTimer);
});
}
else if ((int)state == 207)
{
MonsterState monsterState = monster2.FindState((States)207);
MonsterStatesHelper.SubscibeOnStateUpdateOnce(quickFooMapping, delegate
{
HandleFooStateUpdate(((MappingState)monsterState).statusTimer);
});
}
}
}
private void InitMurmur(GameObject gameObject)
{
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
GameObject val = Object.Instantiate<GameObject>(BubblePrefab, gameObject.transform);
AutoAttributeManager.AutoReferenceAllChildren(val);
if (!((Object)(object)val == (Object)null))
{
val.SetActive(true);
val.transform.localPosition = new Vector3(0.2f, 51f, 0f);
TimelineMurmur component = val.GetComponent<TimelineMurmur>();
PlayableDirector componentInChildren = val.GetComponentInChildren<PlayableDirector>();
val.GetComponentInChildren<Localize>().SetTerm("Eigong/ReasonsPresent/TopTen");
TimelineClip[] obj = (TimelineClip[])((TrackAsset)(AnimationTrack)((TimelineAsset)componentInChildren.playableAsset).GetRootTrack(1)).GetClips();
if (obj.Length < 2)
{
throw new InvalidOperationException("Murmur timeline does not have enough clips");
}
obj[1].start = 1.5;
MurmurTimeLine = component;
}
}
private void AddLocalization()
{
//IL_0005: 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_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
GameObject val = new GameObject("TopTenReasons_LanguageSource")
{
hideFlags = (HideFlags)61
};
LanguageSourceData val2 = new LanguageSourceData();
val.AddComponent<LanguageSource>().mSource = val2;
foreach (var (text3, text4) in Languages)
{
val2.AddLanguage(text4, text3);
}
TermData val3 = val2.AddTerm("Eigong/ReasonsPresent/TopTen");
for (int i = 0; i < Languages.Count; i++)
{
val3.SetTranslation(i, "Top 10 reasons eigongs talisman is fair and you're stupid", (string)null);
}
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TopTenReasons";
public const string PLUGIN_NAME = "TopTenReasons";
public const string PLUGIN_VERSION = "1.0.0";
}
}