using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Audio;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("REPO_HealDrone")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("微软中国")]
[assembly: AssemblyProduct("REPO_HealDrone")]
[assembly: AssemblyCopyright("Copyright © 微软中国 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("44b14dc1-b09e-4b1b-95de-83be0c54122d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace REPO_HealDrone;
[BepInPlugin("com.Xiaohai.REPO.HealDrone", "REPO_HealDrone", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
public static Item item;
public ConfigEntry<int> healAmount;
public ConfigEntry<int> healSecond;
public ConfigEntry<float> batteryDrain;
public ConfigEntry<string> itemName;
public ConfigEntry<bool> healEffect;
public ConfigEntry<bool> firstLevelSpawn;
public static ManualLogSource logger;
public static Plugin instance;
public static AudioMixerGroup[] groups;
public void Awake()
{
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
instance = this;
logger = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"repo_healdrone插件加载成功!");
itemName = ((BaseUnityPlugin)this).Config.Bind<string>("HealDrone", "Item UI Name", "治疗无人机", "UI显示物品名字,方便不同语种用户/Display item names in the UI to support multilingual users.");
healSecond = ((BaseUnityPlugin)this).Config.Bind<int>("HealDrone", "Treatment Interval", 5, "治疗的时间间隔 / Treatment Interval");
healAmount = ((BaseUnityPlugin)this).Config.Bind<int>("HealDrone", "healAmount", 1, "每次恢复生命值量 / Heal Amount Per Interval Second");
batteryDrain = ((BaseUnityPlugin)this).Config.Bind<float>("HealDrone", "BatteryDrainRate", 0.5f, "每秒电量消耗量(最大值为100) / Battery Drain Amount Per Second (Max 100)");
healEffect = ((BaseUnityPlugin)this).Config.Bind<bool>("HealDrone", "HealEffect", false, "是否播放治疗特效(间隔小于5时不建议开启,间隔大于5时可以增加沉浸感) / Enable healing effects (Not recommended when interval < 5; enhances immersion when interval> 5)");
firstLevelSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("HealDrone", "FirstLevelSpawn", true, "是否在第一关时默认生成? (在卡车内)/ Should it spawn by default on the first-level's truck?");
string location = Assembly.GetExecutingAssembly().Location;
string directoryName = Path.GetDirectoryName(location);
string text = Path.Combine(directoryName, "repo_healdrone");
AssetBundle val = AssetBundle.LoadFromFile(text);
item = val.LoadAsset<Item>("Item Drone Heal");
if ((Object)(object)item != (Object)null)
{
item.itemName = itemName.Value;
Items.RegisterItem(item);
((BaseUnityPlugin)this).Logger.LogInfo((object)("加载预制体成功!" + item.itemName));
item.prefab.AddComponent<HealDrone>();
new Harmony("com.XiaohaiMod.REPO.HealDrone").PatchAll();
}
else
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"加载预制体失败!");
}
}
}
[HarmonyPatch(typeof(LoadingUI))]
internal static class LoadingUIPatch
{
[HarmonyPatch("LevelAnimationStart")]
[HarmonyPostfix]
private static void Patch(LoadingUI __instance)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
Plugin.logger.LogInfo((object)$"当前关卡:{((Object)RunManager.instance.levelCurrent).name}第{RunManager.instance.levelsCompleted}关");
if (!Plugin.instance.firstLevelSpawn.Value || RunManager.instance.levelsCompleted != 0)
{
return;
}
Vector3 val = Vector3.zero;
List<LevelPoint> list = new List<LevelPoint>();
foreach (LevelPoint levelPathPoint in LevelGenerator.Instance.LevelPathPoints)
{
if (levelPathPoint.Room.Truck)
{
val = ((Component)levelPathPoint).transform.position;
break;
}
}
if (val == Vector3.zero)
{
Plugin.logger.LogInfo((object)"未找到卡车位置,生成在大门口");
}
Quaternion identity = Quaternion.identity;
if (SemiFunc.IsMultiplayer())
{
PhotonNetwork.InstantiateRoomObject("Items/Item Drone Heal", val, identity, (byte)0, (object[])null);
}
else
{
Object.Instantiate<GameObject>(Plugin.item.prefab, val, identity);
}
}
}
public class HealDrone : MonoBehaviour
{
public AudioClip[] healDroneClips;
public Sound healDroneSound;
public bool healPlayer = true;
public int healAmount = 5;
public int healSecond = 1;
public float batteryDrain = 0.5f;
private ItemDrone itemDrone;
private PhysGrabObject myPhysGrabObject;
private ItemEquippable itemEquippable;
private ItemBattery itemBattery;
private float healTimer = 0f;
private void Start()
{
itemDrone = ((Component)this).GetComponent<ItemDrone>();
myPhysGrabObject = ((Component)this).GetComponent<PhysGrabObject>();
itemEquippable = ((Component)this).GetComponent<ItemEquippable>();
itemBattery = ((Component)this).GetComponent<ItemBattery>();
healAmount = Plugin.instance.healAmount.Value;
healSecond = Plugin.instance.healSecond.Value;
batteryDrain = Plugin.instance.batteryDrain.Value;
itemBattery.batteryDrainRate = batteryDrain;
Plugin.logger.LogInfo((object)("根对象:" + ((Object)FindPrefabRoot(((Component)this).gameObject)).name));
}
private GameObject FindPrefabRoot(GameObject obj)
{
Transform val = obj.transform;
while ((Object)(object)val.parent != (Object)null)
{
val = val.parent;
}
return ((Component)val).gameObject;
}
private void FixedUpdate()
{
if (itemEquippable.isEquipped || (GameManager.instance.gameMode == 1 && !SemiFunc.IsMasterClient()) || !itemDrone.itemActivated)
{
return;
}
myPhysGrabObject.OverrideZeroGravity(0.1f);
myPhysGrabObject.OverrideDrag(1f, 0.1f);
myPhysGrabObject.OverrideAngularDrag(10f, 0.1f);
if (healPlayer && itemDrone.itemActivated && itemDrone.magnetActive && (Object)(object)itemDrone.playerAvatarTarget != (Object)null)
{
healTimer += Time.fixedDeltaTime;
PlayerHealth playerHealth = itemDrone.playerAvatarTarget.playerHealth;
if (!(healTimer >= (float)healSecond))
{
return;
}
if (playerHealth.health < playerHealth.maxHealth)
{
if ((Object)(object)itemDrone.playerAvatarTarget == (Object)(object)SemiFunc.PlayerAvatarLocal())
{
playerHealth.Heal(healAmount, Plugin.instance.healEffect.Value);
}
else
{
playerHealth.HealOther(healAmount, Plugin.instance.healEffect.Value);
}
}
healTimer = 0f;
}
else
{
healTimer = 0f;
}
}
}