using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GlobalEnums;
using HarmonyLib;
using TeamCherry.Localization;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Silk_SomeMOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Silk_SomeMOD")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0292e531-7a75-4dc7-ae07-72cb20b3f50a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Silk_SomeMOD;
[BepInPlugin("com.Xiaohai.ReBack", "ReBack", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource logger;
private Harmony harmony;
public static ConfigEntry<int> countdownTime;
public static ConfigEntry<KeyCode> cancelKey;
public static ConfigEntry<KeyCode> suicideKey;
private void Awake()
{
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
logger.LogInfo((object)"重新返回MOD插件已加载!");
countdownTime = ((BaseUnityPlugin)this).Config.Bind<int>("传送设置", "倒计时时间", 5, "传送前的倒计时时间(秒) / Countdown time before teleportation (seconds)");
cancelKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("传送设置", "取消按键", (KeyCode)110, "取消传送的按键 / Key to cancel teleportation");
suicideKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("传送设置", "自杀按键", (KeyCode)286, "紧急自杀按键,用于解决传送异常状态 / Emergency suicide key to resolve teleportation issues");
harmony = new Harmony("com.example.silk_somemod");
try
{
harmony.PatchAll();
logger.LogInfo((object)"Harmony补丁应用成功!");
}
catch (Exception arg)
{
logger.LogError((object)$"应用Harmony补丁失败: {arg}");
}
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(suicideKey.Value))
{
PerformSuicide();
}
}
private void PerformSuicide()
{
//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_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Invalid comparison between Unknown and I4
try
{
bool flag = false;
try
{
LanguageCode currentLanguage = FontManager.CurrentLanguage;
flag = (int)currentLanguage == 199;
}
catch
{
flag = false;
}
HeroController instance = HeroController.instance;
if ((Object)(object)instance != (Object)null && !instance.cState.dead)
{
instance.TakeDamage(((Component)instance).gameObject, (CollisionSide)4, 50, (HazardType)3, (DamagePropertyFlags)0);
}
}
catch (Exception arg)
{
logger.LogError((object)$"执行自杀时出错 / Error during suicide execution: {arg}");
}
}
}
[HarmonyPatch(typeof(HeroController), "TakeDamage")]
public class TakeDamagePatch
{
private static void Prefix(HeroController __instance, GameObject go, CollisionSide damageSide, int damageAmount, HazardType hazardType, DamagePropertyFlags damagePropertyFlags = 0)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
try
{
PlayerData playerData = __instance.playerData;
if (playerData != null && playerData.health <= damageAmount)
{
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
Vector3 position = __instance.transform.position;
PlayerDataManager.Instance.SaveSafePosition(position, name);
}
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"TakeDamage补丁错误: {arg}");
}
}
}
[HarmonyPatch(typeof(GameManager), "FinishedEnteringScene")]
public class FinishedEnteringScenePatch
{
[CompilerGenerated]
private sealed class <>c__DisplayClass3_0
{
public bool shouldCancel;
internal void <TeleportBackToDeathLocation>b__0(bool cancel)
{
shouldCancel = cancel;
}
}
[CompilerGenerated]
private sealed class <CheckTeleportSafetyAfterDelay>d__5 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Vector3 originalPosition;
private HeroController <heroController>5__1;
private Collider2D <heroCollider>5__2;
private int <groundLayerMask>5__3;
private Collider2D <overlapping>5__4;
private Vector3 <safePosition>5__5;
private Exception <ex>5__6;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <CheckTeleportSafetyAfterDelay>d__5(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<heroController>5__1 = null;
<heroCollider>5__2 = null;
<overlapping>5__4 = null;
<ex>5__6 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
try
{
<heroController>5__1 = HeroController.instance;
if ((Object)(object)<heroController>5__1 == (Object)null)
{
return false;
}
<heroCollider>5__2 = ((Component)<heroController>5__1).GetComponent<Collider2D>();
if ((Object)(object)<heroCollider>5__2 == (Object)null)
{
return false;
}
<groundLayerMask>5__3 = LayerMask.GetMask(new string[1] { "Terrain" });
Bounds bounds = <heroCollider>5__2.bounds;
Vector2 val = Vector2.op_Implicit(((Bounds)(ref bounds)).center);
bounds = <heroCollider>5__2.bounds;
<overlapping>5__4 = Physics2D.OverlapBox(val, Vector2.op_Implicit(((Bounds)(ref bounds)).size), 0f, <groundLayerMask>5__3);
if ((Object)(object)<overlapping>5__4 != (Object)null)
{
<safePosition>5__5 = PlayerDataManager.Instance.FindSafePositionNearby(originalPosition);
if (<safePosition>5__5 != Vector3.zero)
{
<heroController>5__1.transform.position = <safePosition>5__5;
}
}
<heroController>5__1 = null;
<heroCollider>5__2 = null;
<overlapping>5__4 = null;
}
catch (Exception ex)
{
<ex>5__6 = ex;
Plugin.logger.LogError((object)("传送安全检查错误: " + <ex>5__6.Message));
}
finally
{
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <ShowCountdownUI>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Action<bool> onComplete;
private int <countdown>5__1;
private KeyCode <cancelKeyCode>5__2;
private bool <isChinese>5__3;
private Font <damageFont>5__4;
private GameObject <canvasGO>5__5;
private Canvas <canvas>5__6;
private CanvasScaler <scaler>5__7;
private GameObject <bgGO>5__8;
private Image <bgImage>5__9;
private RectTransform <bgRect>5__10;
private GameObject <textGO>5__11;
private Text <countdownText>5__12;
private Shadow <shadow>5__13;
private RectTransform <rectTransform>5__14;
private bool <cancelled>5__15;
private LanguageCode <currentLang>5__16;
private Font[] <allFonts>5__17;
private Exception <ex>5__18;
private int <i>5__19;
private float <timer>5__20;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ShowCountdownUI>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<damageFont>5__4 = null;
<canvasGO>5__5 = null;
<canvas>5__6 = null;
<scaler>5__7 = null;
<bgGO>5__8 = null;
<bgImage>5__9 = null;
<bgRect>5__10 = null;
<textGO>5__11 = null;
<countdownText>5__12 = null;
<shadow>5__13 = null;
<rectTransform>5__14 = null;
<allFonts>5__17 = null;
<ex>5__18 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Expected O, but got Unknown
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Expected O, but got Unknown
//IL_0260: Unknown result type (might be due to invalid IL or missing references)
//IL_0282: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: Expected O, but got Unknown
//IL_0324: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: 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)
//IL_039b: Unknown result type (might be due to invalid IL or missing references)
//IL_036b: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Invalid comparison between Unknown and I4
//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
//IL_040f: Unknown result type (might be due to invalid IL or missing references)
//IL_042a: Unknown result type (might be due to invalid IL or missing references)
//IL_043b: Unknown result type (might be due to invalid IL or missing references)
//IL_0456: Unknown result type (might be due to invalid IL or missing references)
//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
//IL_049c: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -1;
goto IL_0544;
}
<>1__state = -1;
<countdown>5__1 = Plugin.countdownTime.Value;
<cancelKeyCode>5__2 = Plugin.cancelKey.Value;
<isChinese>5__3 = false;
try
{
<currentLang>5__16 = FontManager.CurrentLanguage;
<isChinese>5__3 = (int)<currentLang>5__16 == 199;
}
catch
{
<isChinese>5__3 = false;
}
<damageFont>5__4 = null;
try
{
<allFonts>5__17 = Resources.FindObjectsOfTypeAll<Font>();
<damageFont>5__4 = ((IEnumerable<Font>)<allFonts>5__17).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.Contains("TrajanPro-Regular"))) ?? ((IEnumerable<Font>)<allFonts>5__17).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.Contains("Trajan"))) ?? ((IEnumerable<Font>)<allFonts>5__17).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name.Contains("Arial"))) ?? Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
<allFonts>5__17 = null;
}
catch (Exception ex)
{
<ex>5__18 = ex;
Plugin.logger.LogError((object)("字体加载失败: " + <ex>5__18.Message));
<damageFont>5__4 = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
}
<canvasGO>5__5 = new GameObject("CountdownCanvas");
<canvas>5__6 = <canvasGO>5__5.AddComponent<Canvas>();
<canvas>5__6.renderMode = (RenderMode)0;
<canvas>5__6.sortingOrder = 32767;
<canvas>5__6.overrideSorting = true;
<scaler>5__7 = <canvasGO>5__5.AddComponent<CanvasScaler>();
<scaler>5__7.uiScaleMode = (ScaleMode)1;
<scaler>5__7.referenceResolution = new Vector2(1920f, 1080f);
<canvasGO>5__5.AddComponent<GraphicRaycaster>();
Object.DontDestroyOnLoad((Object)(object)<canvasGO>5__5);
<bgGO>5__8 = new GameObject("Background");
<bgGO>5__8.transform.SetParent(<canvasGO>5__5.transform, false);
<bgImage>5__9 = <bgGO>5__8.AddComponent<Image>();
((Graphic)<bgImage>5__9).color = new Color(0f, 0f, 0f, 0.5f);
<bgRect>5__10 = <bgGO>5__8.GetComponent<RectTransform>();
<bgRect>5__10.anchorMin = Vector2.zero;
<bgRect>5__10.anchorMax = Vector2.one;
<bgRect>5__10.offsetMin = Vector2.zero;
<bgRect>5__10.offsetMax = Vector2.zero;
<textGO>5__11 = new GameObject("CountdownText");
<textGO>5__11.transform.SetParent(<canvasGO>5__5.transform, false);
<countdownText>5__12 = <textGO>5__11.AddComponent<Text>();
<countdownText>5__12.font = <damageFont>5__4;
<countdownText>5__12.fontSize = 65;
((Graphic)<countdownText>5__12).color = Color.white;
<countdownText>5__12.alignment = (TextAnchor)4;
<countdownText>5__12.supportRichText = true;
if (<isChinese>5__3)
{
<countdownText>5__12.text = $"{<countdown>5__1}秒后回到原地\n按{<cancelKeyCode>5__2}或手柄B键取消";
}
else
{
<countdownText>5__12.text = $"Teleporting back in {<countdown>5__1} seconds\nPress {<cancelKeyCode>5__2} or Gamepad B to cancel";
}
<shadow>5__13 = <textGO>5__11.AddComponent<Shadow>();
<shadow>5__13.effectColor = Color.black;
<shadow>5__13.effectDistance = new Vector2(2f, -2f);
<rectTransform>5__14 = <textGO>5__11.GetComponent<RectTransform>();
<rectTransform>5__14.anchorMin = new Vector2(0.5f, 0.5f);
<rectTransform>5__14.anchorMax = new Vector2(0.5f, 0.5f);
<rectTransform>5__14.anchoredPosition = Vector2.zero;
<rectTransform>5__14.sizeDelta = new Vector2(1200f, 500f);
<cancelled>5__15 = false;
<i>5__19 = <countdown>5__1;
goto IL_0578;
IL_0544:
if (<timer>5__20 < 1f)
{
if (!Input.GetKeyDown(<cancelKeyCode>5__2) && !Input.GetKeyDown((KeyCode)331))
{
<timer>5__20 += Time.deltaTime;
<>2__current = null;
<>1__state = 1;
return true;
}
<cancelled>5__15 = true;
}
if (<cancelled>5__15)
{
goto IL_058d;
}
<i>5__19--;
goto IL_0578;
IL_0578:
if (<i>5__19 >= 1)
{
if (<isChinese>5__3)
{
<countdownText>5__12.text = $"<color=red><b>{<i>5__19}</b></color>秒后回到原地\n按{<cancelKeyCode>5__2}或手柄B键取消";
}
else
{
<countdownText>5__12.text = $"Teleporting back in <color=red><b>{<i>5__19}</b></color> seconds\nPress {<cancelKeyCode>5__2} or Gamepad B to cancel";
}
<timer>5__20 = 0f;
goto IL_0544;
}
goto IL_058d;
IL_058d:
Object.Destroy((Object)(object)<canvasGO>5__5);
onComplete?.Invoke(<cancelled>5__15);
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <TeleportBackToDeathLocation>d__3 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public GameManager gm;
private <>c__DisplayClass3_0 <>8__1;
private HeroController <heroController>5__2;
private int <waitCount>5__3;
private Vector3 <lastPosition>5__4;
private string <lastScene>5__5;
private bool <hasValidPosition>5__6;
private Exception <ex>5__7;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <TeleportBackToDeathLocation>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>8__1 = null;
<heroController>5__2 = null;
<lastScene>5__5 = null;
<ex>5__7 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Expected O, but got Unknown
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Expected O, but got Unknown
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01bc: Expected O, but got Unknown
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_0224: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>8__1 = new <>c__DisplayClass3_0();
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>8__1.shouldCancel = false;
<>2__current = ((MonoBehaviour)gm).StartCoroutine(ShowCountdownUI(delegate(bool cancel)
{
<>8__1.shouldCancel = cancel;
}));
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
if (<>8__1.shouldCancel)
{
PlayerDataManager.Instance.ClearSafePosition();
return false;
}
goto IL_0101;
case 3:
<>1__state = -1;
goto IL_0101;
case 4:
<>1__state = -1;
<heroController>5__2 = HeroController.instance;
<waitCount>5__3++;
goto IL_0161;
case 5:
<>1__state = -1;
<waitCount>5__3++;
goto IL_01dd;
case 6:
{
<>1__state = -1;
try
{
if ((Object)(object)<heroController>5__2 != (Object)null)
{
(<lastPosition>5__4, <lastScene>5__5, <hasValidPosition>5__6) = PlayerDataManager.Instance.GetLastSafePosition();
if (<hasValidPosition>5__6)
{
gm.BeginSceneTransition(new SceneLoadInfo
{
SceneName = <lastScene>5__5,
HeroLeaveDirection = (GatePosition)5,
EntryGateName = "",
EntryDelay = 0f,
Visualization = (SceneLoadVisualizations)0,
AlwaysUnloadUnusedAssets = false
});
}
else
{
PlayerDataManager.Instance.ClearSafePosition();
}
<lastScene>5__5 = null;
}
else
{
PlayerDataManager.Instance.ClearSafePosition();
}
}
catch (Exception ex)
{
<ex>5__7 = ex;
Plugin.logger.LogError((object)$"传送过程中出错: {<ex>5__7}");
PlayerDataManager.Instance.ClearSafePosition();
}
return false;
}
IL_01dd:
if ((<heroController>5__2.cState.dead || <heroController>5__2.cState.transitioning) && <waitCount>5__3 < 100)
{
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 5;
return true;
}
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 6;
return true;
IL_0101:
if (gm.IsInSceneTransition)
{
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 3;
return true;
}
<heroController>5__2 = HeroController.instance;
<waitCount>5__3 = 0;
goto IL_0161;
IL_0161:
if ((Object)(object)<heroController>5__2 == (Object)null && <waitCount>5__3 < 50)
{
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 4;
return true;
}
if ((Object)(object)<heroController>5__2 == (Object)null)
{
PlayerDataManager.Instance.ClearSafePosition();
return false;
}
<waitCount>5__3 = 0;
goto IL_01dd;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
[CompilerGenerated]
private sealed class <WaitForPlayerRespawnAndSetPosition>d__4 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public GameManager gm;
private HeroController <heroController>5__1;
private int <waitCount>5__2;
private Vector3 <finalTargetPosition>5__3;
private HeroController <hero>5__4;
private Exception <ex>5__5;
private Vector3 <lastPosition>5__6;
private string <lastScene>5__7;
private bool <hasValidPosition>5__8;
private Vector3 <targetPosition>5__9;
private Vector3 <safePosition>5__10;
private Exception <ex>5__11;
private Exception <ex>5__12;
private CameraController <cameraController>5__13;
private Exception <ex>5__14;
private CameraController <cameraController>5__15;
private GameManager <gameManager>5__16;
private HeroController <heroCtrl>5__17;
private Exception <ex>5__18;
private GameManager <gameManager>5__19;
private HeroController <heroCtrl2>5__20;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <WaitForPlayerRespawnAndSetPosition>d__4(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<heroController>5__1 = null;
<hero>5__4 = null;
<ex>5__5 = null;
<lastScene>5__7 = null;
<ex>5__11 = null;
<ex>5__12 = null;
<cameraController>5__13 = null;
<ex>5__14 = null;
<cameraController>5__15 = null;
<gameManager>5__16 = null;
<heroCtrl>5__17 = null;
<ex>5__18 = null;
<gameManager>5__19 = null;
<heroCtrl2>5__20 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e1: Expected O, but got Unknown
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_034a: Unknown result type (might be due to invalid IL or missing references)
//IL_0354: Expected O, but got Unknown
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_0543: Unknown result type (might be due to invalid IL or missing references)
//IL_0548: Unknown result type (might be due to invalid IL or missing references)
//IL_021b: Unknown result type (might be due to invalid IL or missing references)
//IL_0220: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0560: Unknown result type (might be due to invalid IL or missing references)
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Unknown result type (might be due to invalid IL or missing references)
//IL_0298: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_024b: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_025b: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Expected O, but got Unknown
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Expected O, but got Unknown
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
goto IL_00a5;
case 2:
<>1__state = -1;
goto IL_00a5;
case 3:
<>1__state = -1;
<heroController>5__1 = HeroController.instance;
<waitCount>5__2++;
goto IL_0118;
case 4:
<>1__state = -1;
if (<heroController>5__1.cState.transitioning)
{
try
{
<heroController>5__1.FinishedEnteringScene(true, false);
}
catch (Exception ex)
{
<ex>5__5 = ex;
Plugin.logger.LogError((object)$"调用FinishedEnteringScene时出错: {<ex>5__5}");
}
}
<finalTargetPosition>5__3 = Vector3.zero;
try
{
(<lastPosition>5__6, <lastScene>5__7, <hasValidPosition>5__8) = PlayerDataManager.Instance.GetLastSafePosition();
if (<hasValidPosition>5__8)
{
<targetPosition>5__9 = <lastPosition>5__6;
if (!PlayerDataManager.Instance.IsPositionSafe(<lastPosition>5__6))
{
<safePosition>5__10 = PlayerDataManager.Instance.FindSafePositionNearby(<lastPosition>5__6);
if (<safePosition>5__10 != Vector3.zero)
{
<targetPosition>5__9 = <safePosition>5__10;
}
}
<heroController>5__1.transform.position = <targetPosition>5__9;
<finalTargetPosition>5__3 = <targetPosition>5__9;
}
<lastScene>5__7 = null;
}
catch (Exception ex)
{
<ex>5__11 = ex;
Plugin.logger.LogError((object)$"设置玩家位置时出错: {<ex>5__11}");
}
<>2__current = (object)new WaitForSeconds(0.2f);
<>1__state = 5;
return true;
case 5:
<>1__state = -1;
<hero>5__4 = HeroController.instance;
if ((Object)(object)<hero>5__4 != (Object)null)
{
try
{
<hero>5__4.isHeroInPosition = false;
}
catch (Exception ex)
{
<ex>5__12 = ex;
Plugin.logger.LogError((object)$"重置英雄位置状态时出错: {<ex>5__12}");
}
}
<>2__current = (object)new WaitForEndOfFrame();
<>1__state = 6;
return true;
case 6:
<>1__state = -1;
if ((Object)(object)<hero>5__4 != (Object)null)
{
try
{
<hero>5__4.SendHeroInPosition(false);
<cameraController>5__13 = GameCameras.instance?.cameraController;
if ((Object)(object)<cameraController>5__13 != (Object)null)
{
<cameraController>5__13.PositionToHero(false);
}
<cameraController>5__13 = null;
}
catch (Exception ex)
{
<ex>5__14 = ex;
Plugin.logger.LogError((object)$"相机定位时出错: {<ex>5__14}");
<cameraController>5__15 = GameCameras.instance?.cameraController;
if ((Object)(object)<cameraController>5__15 != (Object)null)
{
<cameraController>5__15.PositionToHero(false);
}
<cameraController>5__15 = null;
}
}
<>2__current = null;
<>1__state = 7;
return true;
case 7:
<>1__state = -1;
try
{
<gameManager>5__16 = GameManager.instance;
if ((Object)(object)<gameManager>5__16 != (Object)null)
{
<gameManager>5__16.FadeSceneIn();
}
<heroCtrl>5__17 = HeroController.instance;
if ((Object)(object)<heroCtrl>5__17 != (Object)null)
{
<heroCtrl>5__17.RegainControl();
}
<gameManager>5__16 = null;
<heroCtrl>5__17 = null;
}
catch (Exception ex)
{
<ex>5__18 = ex;
Plugin.logger.LogError((object)$"屏幕恢复时出错: {<ex>5__18}");
<gameManager>5__19 = GameManager.instance;
if ((Object)(object)<gameManager>5__19 != (Object)null)
{
<gameManager>5__19.FadeSceneIn();
}
<heroCtrl2>5__20 = HeroController.instance;
if ((Object)(object)<heroCtrl2>5__20 != (Object)null)
{
<heroCtrl2>5__20.RegainControl();
}
<gameManager>5__19 = null;
<heroCtrl2>5__20 = null;
}
if (<finalTargetPosition>5__3 != Vector3.zero)
{
<>2__current = ((MonoBehaviour)GameManager.instance).StartCoroutine(CheckTeleportSafetyAfterDelay(<finalTargetPosition>5__3));
<>1__state = 8;
return true;
}
PlayerDataManager.Instance.ClearSafePosition();
break;
case 8:
{
<>1__state = -1;
PlayerDataManager.Instance.ClearSafePosition();
break;
}
IL_0118:
if ((Object)(object)<heroController>5__1 == (Object)null && <waitCount>5__2 < 50)
{
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 3;
return true;
}
if ((Object)(object)<heroController>5__1 == (Object)null)
{
PlayerDataManager.Instance.ClearSafePosition();
return false;
}
<>2__current = (object)new WaitForSeconds(2f);
<>1__state = 4;
return true;
IL_00a5:
if (gm.IsInSceneTransition || !gm.HasFinishedEnteringScene)
{
<>2__current = (object)new WaitForSeconds(0.1f);
<>1__state = 2;
return true;
}
<heroController>5__1 = HeroController.instance;
<waitCount>5__2 = 0;
goto IL_0118;
}
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static float lastTeleportTime = 0f;
private static readonly float cooldownTime = 3f;
private static void Postfix(GameManager __instance)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
try
{
PlayerDataManager instance = PlayerDataManager.Instance;
(Vector3 position, string scene, bool isValid) lastSafePosition = instance.GetLastSafePosition();
var (val, text, _) = lastSafePosition;
if (!lastSafePosition.isValid)
{
return;
}
float time = Time.time;
if (!(time - lastTeleportTime < cooldownTime))
{
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
lastTeleportTime = time;
if (name != text)
{
((MonoBehaviour)__instance).StartCoroutine(TeleportBackToDeathLocation(__instance));
}
else
{
((MonoBehaviour)__instance).StartCoroutine(WaitForPlayerRespawnAndSetPosition(__instance));
}
}
}
catch (Exception arg)
{
Plugin.logger.LogError((object)$"FinishedEnteringScene补丁错误: {arg}");
}
}
[IteratorStateMachine(typeof(<TeleportBackToDeathLocation>d__3))]
private static IEnumerator TeleportBackToDeathLocation(GameManager gm)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <TeleportBackToDeathLocation>d__3(0)
{
gm = gm
};
}
[IteratorStateMachine(typeof(<WaitForPlayerRespawnAndSetPosition>d__4))]
private static IEnumerator WaitForPlayerRespawnAndSetPosition(GameManager gm)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WaitForPlayerRespawnAndSetPosition>d__4(0)
{
gm = gm
};
}
[IteratorStateMachine(typeof(<CheckTeleportSafetyAfterDelay>d__5))]
private static IEnumerator CheckTeleportSafetyAfterDelay(Vector3 originalPosition)
{
//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)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <CheckTeleportSafetyAfterDelay>d__5(0)
{
originalPosition = originalPosition
};
}
[IteratorStateMachine(typeof(<ShowCountdownUI>d__6))]
private static IEnumerator ShowCountdownUI(Action<bool> onComplete)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ShowCountdownUI>d__6(0)
{
onComplete = onComplete
};
}
}
public class PlayerDataManager : MonoBehaviour
{
private static PlayerDataManager _instance;
[Header("传送位置信息")]
public Vector3 lastSafePosition = Vector3.zero;
public string lastSafeScene = "";
public bool hasValidPosition = false;
private ManualLogSource logger;
public static PlayerDataManager Instance
{
get
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
if ((Object)(object)_instance == (Object)null)
{
_instance = Object.FindFirstObjectByType<PlayerDataManager>();
if ((Object)(object)_instance == (Object)null)
{
GameObject val = new GameObject("PlayerDataManager");
_instance = val.AddComponent<PlayerDataManager>();
Object.DontDestroyOnLoad((Object)(object)val);
}
}
return _instance;
}
}
private void Awake()
{
if ((Object)(object)_instance != (Object)null && (Object)(object)_instance != (Object)(object)this)
{
Object.Destroy((Object)(object)((Component)this).gameObject);
return;
}
_instance = this;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
logger = Logger.CreateLogSource("PlayerDataManager");
logger.LogInfo((object)"PlayerDataManager initialized");
}
public void SaveSafePosition(Vector3 position, string sceneName)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
lastSafePosition = position;
lastSafeScene = sceneName;
hasValidPosition = true;
logger.LogInfo((object)$"Saved safe position: {position} in scene: {sceneName}");
}
public (Vector3 position, string scene, bool isValid) GetLastSafePosition()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return (lastSafePosition, lastSafeScene, hasValidPosition);
}
public void ClearSafePosition()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
lastSafePosition = Vector3.zero;
lastSafeScene = "";
hasValidPosition = false;
logger.LogInfo((object)"Cleared safe position data");
}
public bool IsPositionSafe(Vector3 position)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
try
{
HeroController instance = HeroController.instance;
Collider2D val = (((Object)(object)instance != (Object)null) ? ((Component)instance).GetComponent<Collider2D>() : null);
if ((Object)(object)val == (Object)null)
{
return true;
}
int mask = LayerMask.GetMask(new string[1] { "Terrain" });
Vector2 val2 = Vector2.op_Implicit(position);
Bounds bounds = val.bounds;
Collider2D val3 = Physics2D.OverlapBox(val2, Vector2.op_Implicit(((Bounds)(ref bounds)).size), 0f, mask);
bool flag = (Object)(object)val3 == (Object)null;
logger.LogInfo((object)string.Format("位置安全检查: {0} -> {1}", position, flag ? "安全" : "不安全"));
return flag;
}
catch (Exception ex)
{
logger.LogInfo((object)("检查位置安全性时发生错误: " + ex.Message));
return true;
}
}
public Vector3 FindSafePositionNearby(Vector3 originalPosition)
{
//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: 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)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0103: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0139: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
try
{
HeroController instance = HeroController.instance;
Collider2D val = (((Object)(object)instance != (Object)null) ? ((Component)instance).GetComponent<Collider2D>() : null);
if ((Object)(object)val == (Object)null)
{
return originalPosition;
}
int mask = LayerMask.GetMask(new string[1] { "Terrain" });
Vector3[] array = (Vector3[])(object)new Vector3[8]
{
new Vector3(0f, 1f, 0f),
new Vector3(0f, -1f, 0f),
new Vector3(-1f, 0f, 0f),
new Vector3(1f, 0f, 0f),
new Vector3(-1f, 1f, 0f),
new Vector3(1f, 1f, 0f),
new Vector3(-1f, -1f, 0f),
new Vector3(1f, -1f, 0f)
};
Vector3[] array2 = array;
foreach (Vector3 val2 in array2)
{
Vector3 val3 = originalPosition + val2;
Vector2 val4 = Vector2.op_Implicit(val3);
Bounds bounds = val.bounds;
Collider2D val5 = Physics2D.OverlapBox(val4, Vector2.op_Implicit(((Bounds)(ref bounds)).size), 0f, mask);
if ((Object)(object)val5 == (Object)null)
{
logger.LogInfo((object)$"找到安全位置: {originalPosition} -> {val3}");
return val3;
}
}
logger.LogInfo((object)$"在位置 {originalPosition} 附近未找到安全位置");
return Vector3.zero;
}
catch (Exception ex)
{
logger.LogInfo((object)("寻找安全位置时发生错误: " + ex.Message));
return Vector3.zero;
}
}
public void OnGameReset()
{
ClearSafePosition();
logger.LogInfo((object)"Player data reset for new game/save");
}
private void OnDestroy()
{
if ((Object)(object)_instance == (Object)(object)this)
{
_instance = null;
}
}
}