using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Drone;
using IL.EntityStates.Drone;
using IL.RoR2.Hologram;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2;
using R2API;
using RoR2;
using RoR2.Hologram;
using RoR2BepInExPack.GameAssetPathsBetter;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityHotReloadNS;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DroneRepairBeacon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f780b2975b74dd6b513d6333dac2d631340cf77c")]
[assembly: AssemblyProduct("DroneRepairBeacon")]
[assembly: AssemblyTitle("DroneRepairBeacon")]
[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 DroneRepairBeacon
{
public class deadDroneTracker : MonoBehaviour, IHologramContentProvider
{
[CompilerGenerated]
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private static GameObject <hologramContentPrefab>k__BackingField;
private static GameObject hologramContentPrefab
{
get
{
if (!Object.op_Implicit((Object)(object)<hologramContentPrefab>k__BackingField))
{
<hologramContentPrefab>k__BackingField = PrefabAPI.InstantiateClone(DroneRepairBeacon.DroneIndicatorVFX, "Drone Repair Beacon Hologram", false);
}
int num = Run.instance.runRNG.RangeInt(0, DroneRepairBeacon.droneIndicatorSprites.Count);
SpriteRenderer component = <hologramContentPrefab>k__BackingField.GetComponent<SpriteRenderer>();
component.sprite = DroneRepairBeacon.droneIndicatorSprites[num];
((Renderer)component).SetMaterial(DroneRepairBeacon.droneIndicatorMaterials[num]);
return <hologramContentPrefab>k__BackingField;
}
}
public void Start()
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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)
((Component)this).gameObject.transform.localScale = new Vector3(DroneRepairBeacon.helpScale.Value, DroneRepairBeacon.helpScale.Value, DroneRepairBeacon.helpScale.Value);
Vector3 position = ((Component)this).gameObject.transform.position;
position.y += 4f * DroneRepairBeacon.helpScale.Value;
((Component)this).gameObject.transform.position = position;
}
GameObject IHologramContentProvider.GetHologramContentPrefab()
{
return hologramContentPrefab;
}
public void UpdateHologramContent(GameObject hologramContentObject, Transform viewerBody)
{
}
bool IHologramContentProvider.ShouldDisplayHologram(GameObject viewer)
{
//IL_0019: 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)
if (!Object.op_Implicit((Object)(object)viewer))
{
return false;
}
float num = Vector3.Distance(viewer.transform.position, ((Component)this).gameObject.transform.position);
return num <= DroneRepairBeacon.displayDistance.Value;
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("icebro.DroneRepairBeacon", "DroneRepairBeacon", "1.0.0")]
public class DroneRepairBeacon : BaseUnityPlugin
{
private const string PluginGUID = "icebro.DroneRepairBeacon";
private const string PluginAuthor = "icebro";
private const string PluginName = "DroneRepairBeacon";
private const string PluginVersion = "1.0.0";
private static GameObject DroneIndicatorHologram;
public static GameObject DroneIndicatorVFX;
public static List<Sprite> droneIndicatorSprites = new List<Sprite>();
public static Material[] droneIndicatorMaterials = Array.Empty<Material>();
public static ConfigEntry<float> displayDistance;
public static ConfigEntry<float> helpScale;
private static ConfigEntry<string> DeathTokenConfigs;
private static ConfigEntry<string> DroneSpecificDeathTokenConfigs;
private static ConfigEntry<string> droneSprites;
private static ConfigEntry<bool> customDroneSprites;
private static ConfigEntry<bool> alwaysShowHelp;
private static ConfigEntry<bool> alwaysShowHelpAllowTurrets;
private static AssetBundle assetbundle;
private static Material baseMat;
private static bool UHRInstalled => Chainloader.PluginInfos.ContainsKey("iDeathHD.UnityHotReload");
public void Awake()
{
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
Log.Init(((BaseUnityPlugin)this).Logger);
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "dronevisibilitybundle");
assetbundle = AssetBundle.LoadFromFileAsync(text).assetBundle;
DroneIndicatorHologram = assetbundle.LoadAsset<GameObject>("DroneIndicatorHologram");
DroneIndicatorVFX = assetbundle.LoadAsset<GameObject>("DroneIndicatorVFX");
baseMat = assetbundle.LoadAsset<Material>("HGStandard");
Material[] array = assetbundle.LoadAllAssets<Material>();
foreach (Material val in array)
{
if (!(((Object)val).name != "HGStandard"))
{
val.shader = Addressables.LoadAssetAsync<Shader>((object)RoR2_Base_Shaders.HGStandard_shader).WaitForCompletion();
Log.Debug("swapped drone notif shader !");
}
}
DeathTokenConfigs = ((BaseUnityPlugin)this).Config.Bind<string>("drone repair beacon", "silly death strings ! split with /, ...,., set to nothing to disable !", "res me twin....,,./,HELP HELP MEEE HEEEEEELP/,ough ,.,.../,babe its {TIME},,, time for your drone reviving session,.,.,.,/,im not broken! im just.... napping... indefinitely..../,REQUESTING HELP.../,LOST CONNECTION.../,YOUR WARRANTY IS 3 DAYS EXPIRED./,oof ouch my bo lts..,", "byeah !");
DroneSpecificDeathTokenConfigs = ((BaseUnityPlugin)this).Config.Bind<string>("drone repair beacon", "specific drone death strings! formatting like (drone internal name);;(string,string);;!", "Drone1Body;;do your own DPS instead... im done...;'.;/,pls revive i had raygun;;Drone2Body;;ill,,.,., miss you \ud83e\udd7a/,please don't leave me here.,.,./,I MISS_YOU ALREADY;", "you can get them from debugtoolkit or wiki (wiki ones are missing body sometimes though ! like .,., Drone1Body = gunnerdrone ,.,. Drone2Body = healing drone .,.,,..");
displayDistance = ((BaseUnityPlugin)this).Config.Bind<float>("drone repair beacon", "how far should help be visible !!", 90f, "byeah !");
helpScale = ((BaseUnityPlugin)this).Config.Bind<float>("drone repair beacon", "how big help should be ! 1 equals 1x ,.,.,.", 1f, "byeah !");
alwaysShowHelp = ((BaseUnityPlugin)this).Config.Bind<bool>("drone repair beacon", "always show help ,.., like on unpurchased drones !!", false, "byeah !");
alwaysShowHelpAllowTurrets = ((BaseUnityPlugin)this).Config.Bind<bool>("drone repair beacon", "always show help allow turrets to be helped too !!", false, "byeah !");
droneSprites = ((BaseUnityPlugin)this).Config.Bind<string>("drone repair beacon", "what message sprites to use! randomizes with multiple ,..,. options in config desc !! seperate by , NEEDS RESTART !!", "BeaconVFXbrokenheart,BeaconVFXCog,BeaconVFXexplain,BeaconVFXowww,BeaconVFXplead,BeaconVFXresmetwin,BeaconVFXAnar,BeaconVFXLukas", "BeaconVFXbrokenheart,BeaconVFXCog,BeaconVFXexplain,BeaconVFXowww,BeaconVFXplead,BeaconVFXresmetwin,BeaconVFXAnar,BeaconVFXAnarColor,BeaconVFXLukas,BeaconVFXLukasColor");
customDroneSprites = ((BaseUnityPlugin)this).Config.Bind<bool>("drone repair beacon", "if you have any custom images you wants to use !!! NEEDS RESTART !!", false, "should be in bepin config directory in DroneBeacon folder .,,. just add there and will appear in rotation !! ,.,., must end in .png !!!!!!!!!!!!!");
ChangeSprites();
Hook();
}
private void ChangeSprites()
{
string[] array = droneSprites.Value.Split(",");
foreach (string text in array)
{
if (assetbundle.Contains(text.Trim()))
{
droneIndicatorSprites.Add(assetbundle.LoadAsset<Sprite>(text.Trim()));
}
else
{
Log.Error("couldnt find sprite " + text.Trim() + " in asset bundle !!");
}
}
if (customDroneSprites.Value)
{
string text2 = Path.Combine(Path.GetDirectoryName(Paths.ConfigPath), "config", "DroneBeacon");
if (!Directory.Exists(text2))
{
Directory.CreateDirectory(text2);
}
string[] files = Directory.GetFiles(text2);
string[] array2 = files;
foreach (string text3 in array2)
{
string text4 = Path.Combine(text2, text3.Trim());
if (!text4.EndsWith(".png"))
{
if (!text4.EndsWith(".psd"))
{
Log.Debug("file " + text4 + " does not end in png ,..,,. skipping !!");
}
continue;
}
Sprite val = LoadSpriteFromFile(text4);
if ((Object)(object)val != (Object)null)
{
droneIndicatorSprites.Add(val);
}
else
{
Log.Error("couldnt find sprite " + text4.Trim() + " in files !!");
}
}
}
droneIndicatorMaterials = (Material[])(object)new Material[droneIndicatorSprites.Count];
for (int k = 0; k < droneIndicatorMaterials.Length; k++)
{
droneIndicatorMaterials[k] = Object.Instantiate<Material>(baseMat);
((Object)droneIndicatorMaterials[k]).name = ((Object)droneIndicatorSprites[k]).name;
droneIndicatorMaterials[k].SetTexture("_EmTex", (Texture)(object)droneIndicatorSprites[k].texture);
}
}
private Sprite LoadSpriteFromFile(string path)
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
return null;
}
int num = 100;
int num2 = 100;
byte[] array = File.ReadAllBytes(path);
Texture2D val = new Texture2D(num, num2, (TextureFormat)3, false);
ImageConversion.LoadImage(val, array);
return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
}
private void Hook()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
SummonMasterBehavior.OnEnable += new hook_OnEnable(SummonMasterBehaviorOnOnEnable);
DeathState.OnImpactServer += new Manipulator(DeathStateOnOnImpactServer);
HologramProjector.UpdateForViewer += new Manipulator(HologramProjectorOnUpdateForViewer);
}
private void SummonMasterBehaviorOnOnEnable(orig_OnEnable orig, SummonMasterBehavior self)
{
orig.Invoke(self);
if (alwaysShowHelp.Value && (alwaysShowHelpAllowTurrets.Value || !((Object)((Component)self).gameObject).name.Contains("Turret")))
{
GameObject val = Object.Instantiate<GameObject>(DroneIndicatorHologram, ((Component)self).transform);
HologramProjector component = val.GetComponent<HologramProjector>();
component.contentProvider = (IHologramContentProvider)(object)val.AddComponent<deadDroneTracker>();
component.displayDistance = displayDistance.Value;
}
}
private void HologramProjectorOnUpdateForViewer(ILContext il)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Expected O, but got Unknown
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
Log.Debug("tryings il hook hologram updater ,,.");
ILCursor val = new ILCursor(il);
if (!val.TryGotoNext(new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchRet(x),
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchCall<HologramProjector>(x, "DestroyHologram")
}))
{
return;
}
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<HologramProjector>>((Action<HologramProjector>)delegate(HologramProjector hologramProjector)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
if (((Object)hologramProjector).name == "DroneIndicatorHologram(Clone)")
{
Transform child = ((Component)hologramProjector).transform.GetChild(0).GetChild(0);
if ((Object)(object)child != (Object)null)
{
Quaternion rotation = Quaternion.Euler(new Vector3(0f, child.eulerAngles.y, 0f));
rotation.x = 0f;
rotation.z = 0f;
((Component)child).transform.rotation = rotation;
}
}
});
Log.Debug("added il hook to hologram updater !!");
}
private void DeathStateOnOnImpactServer(ILContext il)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Expected O, but got Unknown
//IL_008b: 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)
Log.Debug("tryings il hook dead drone ,,.");
ILCursor val = new ILCursor(il);
if (!val.TryGotoNext(new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchStfld<DeathState>(x, "spawnedRepairObject")
}))
{
return;
}
val.Emit(OpCodes.Ldarg_0);
val.Emit(OpCodes.Ldloc_S, (byte)4);
val.EmitDelegate<Action<DeathState, GameObject>>((Action<DeathState, GameObject>)delegate(DeathState deathState, GameObject deadDrone)
{
//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0225: Expected O, but got Unknown
if (!alwaysShowHelp.Value)
{
GameObject val2 = Object.Instantiate<GameObject>(DroneIndicatorHologram, deadDrone.transform);
HologramProjector component = val2.GetComponent<HologramProjector>();
component.contentProvider = (IHologramContentProvider)(object)val2.AddComponent<deadDroneTracker>();
component.displayDistance = displayDistance.Value;
}
if (NetworkServer.active && !(DeathTokenConfigs.Value == ""))
{
List<string> list = DeathTokenConfigs.Value.Split("/,").ToList();
string[] array = DroneSpecificDeathTokenConfigs.Value.Split(";;");
for (int i = 0; i < array.Length; i++)
{
if (!(array[i].Trim().Replace("Body", "") != ((Object)((EntityState)deathState).characterBody).name.Replace("Body", "").Replace("(Clone)", "")))
{
string[] collection = array[i + 1].Split("/,");
list.AddRange(collection);
}
}
Log.Debug("drone name = " + ((Object)((EntityState)deathState).characterBody).name);
string text = list[Run.instance.runRNG.RangeInt(0, list.Count)];
if (text.Contains("{TIME}"))
{
string text2 = DateTime.Now.ToString("hh") + DateTime.Now.ToString("tt");
if (text2.StartsWith("0"))
{
text2 = text2.Substring(1, text2.Length - 1);
}
text = text.Replace("{TIME}", text2.ToLower());
}
text = text.Trim();
Chat.SendBroadcastChat((ChatMessageBase)new SimpleChatMessage
{
baseToken = Language.GetStringFormatted(((EntityState)deathState).characterBody.baseNameToken, Array.Empty<object>()) + ": " + text
});
}
});
Log.Debug("added tracker to dead drones !!");
}
private void Update()
{
if (Input.GetKeyUp((KeyCode)286))
{
if (UHRInstalled)
{
UHRSupport.hotReload(typeof(DroneRepairBeacon).Assembly, Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "DroneRepairBeacon.dll"));
}
else
{
Log.Debug("couldnt finds unity hot reload !!");
}
}
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
internal static class UHRSupport
{
internal static void hotReload(Assembly assembly, string path)
{
UnityHotReload.LoadNewAssemblyVersion(assembly, path);
}
}
}