using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LethalNetworkAPI;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SubspaceTripmineLC")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SubspaceTripmineLC")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6c3baabd-c9bd-4f77-8857-837773407878")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SubspaceTripmineLC;
[BepInPlugin("funfoxrr.SubspaceTripmine", "Subspace Tripmine", "0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class STPlugin : BaseUnityPlugin
{
public const string GUID = "funfoxrr.SubspaceTripmine";
public const string NAME = "Subspace Tripmine";
public const string VERSION = "0.0.0";
private readonly Harmony harmony = new Harmony("funfoxrr.SubspaceTripmine");
internal static ManualLogSource Log;
public static string assemblyLocation;
public static AssetBundle assets;
public static ConfigEntry<bool> enableExplosion;
public static ConfigEntry<bool> instantlyKillPlayer;
public static ConfigEntry<int> damageDone;
public static ConfigEntry<float> plantedTransparency;
public static ConfigEntry<bool> destroyAfterExplosion;
public static STPlugin Instance { get; private set; }
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Log = Logger.CreateLogSource("funfoxrr.SubspaceTripmine");
Log.LogInfo((object)"funfoxrr.SubspaceTripmine has loaded!");
assemblyLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
assets = AssetBundle.LoadFromFile(Path.Combine(assemblyLocation, "funfoxrr__subspacetripmine"));
if ((Object)(object)assets == (Object)null)
{
Log.LogError((object)"Failed to load custom assets.");
return;
}
enableExplosion = ((BaseUnityPlugin)this).Config.Bind<bool>("Functionality", "Enable Explosion Audio", true, "If the subspace plays the explosion sfx.");
instantlyKillPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("Functionality", "Instantly kill player", true, "Kills the player on contact. Adjust damage with 'Damage' Setting.");
damageDone = ((BaseUnityPlugin)this).Config.Bind<int>("Functionality", "Damage", 90, "The amount of damage done.");
plantedTransparency = ((BaseUnityPlugin)this).Config.Bind<float>("Functionality", "Planted Transparency", 0.05f, "How transparent the mine is when placed. Best used below 0.15");
destroyAfterExplosion = ((BaseUnityPlugin)this).Config.Bind<bool>("Functionality", "Destroy after explosion", true, "If the mine disappears when someone steps on it.");
ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "Spawn Rate", 50, "The spawn rate. The higher, the more will spawn. Requires restart if using configuration mods");
ConfigEntry<bool> val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Shop", "Can Buy", true, "If it shows up in the shop. Requires restart if using configuration mods");
ConfigEntry<int> val3 = ((BaseUnityPlugin)this).Config.Bind<int>("Shop", "Price", 100, "The price of the item. Requires restart if using configuration mods");
int value = val.Value;
Item val4 = assets.LoadAsset<Item>("SubspaceTripmineItem.asset");
if ((Object)(object)val4 == (Object)null)
{
Log.LogError((object)"Failed to load SubspaceTripmineItem asset.");
return;
}
GameObject spawnPrefab = val4.spawnPrefab;
SubspaceTripmine subspaceTripmine = spawnPrefab.AddComponent<SubspaceTripmine>();
((GrabbableObject)subspaceTripmine).grabbable = true;
((GrabbableObject)subspaceTripmine).grabbableToEnemies = true;
((GrabbableObject)subspaceTripmine).itemProperties = val4;
NetworkPrefabs.RegisterNetworkPrefab(val4.spawnPrefab);
Items.RegisterScrap(val4, value, (LevelTypes)(-1));
if (val2.Value)
{
int value2 = val3.Value;
TerminalNode val5 = assets.LoadAsset<TerminalNode>("iTerminalNode.asset");
if ((Object)(object)val5 == (Object)null)
{
Log.LogError((object)"Failed to load iTerminalNode asset.");
}
else
{
Items.RegisterShopItem(val4, (TerminalNode)null, (TerminalNode)null, val5, value2);
}
}
}
}
internal class SubspaceTripmine : PhysicsProp
{
public LNetworkVariable<bool> isPlanted;
private Coroutine fadeOut;
public LNetworkMessage<NetworkObjectReference> explode;
public LNetworkEvent plant;
public LNetworkEvent unplant;
public LNetworkMessage<int> plsDie;
public void Plant(bool changeVar = true)
{
STPlugin.Log.LogInfo((object)"Subspace Tripmine has been planted.");
isPlanted.Value = true;
}
public void Unplant(bool changeVar = true)
{
STPlugin.Log.LogInfo((object)"Subspace Tripmine has been unplanted.");
isPlanted.Value = false;
}
public override void Start()
{
((GrabbableObject)this).Start();
ulong id = ((NetworkBehaviour)this).NetworkObject.NetworkObjectId;
STPlugin.Log.LogInfo((object)("Initalizing networks for Subspace #" + id));
explode = LNetworkMessage<NetworkObjectReference>.Connect("explode" + id, (Action<NetworkObjectReference, ulong>)null, (Action<NetworkObjectReference>)null, (Action<NetworkObjectReference, ulong>)null);
isPlanted = LNetworkVariable<bool>.Connect("isPlanted" + id, false, (LNetworkVariableWritePerms)0, (Action<bool, bool>)null);
plsDie = LNetworkMessage<int>.Connect("plsdie" + id, (Action<int, ulong>)null, (Action<int>)null, (Action<int, ulong>)null);
plant = LNetworkEvent.Connect("plant" + id, (Action<ulong>)null, (Action)null, (Action<ulong>)null);
unplant = LNetworkEvent.Connect("unplant" + id, (Action<ulong>)null, (Action)null, (Action<ulong>)null);
plant.OnServerReceived += delegate
{
Plant();
};
unplant.OnServerReceived += delegate
{
Unplant();
};
explode.OnClientReceived += delegate(NetworkObjectReference _obj)
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
NetworkObject networkObject = ((NetworkBehaviour)this).GetNetworkObject(((NetworkObjectReference)(ref _obj)).NetworkObjectId);
PlayerControllerB component = ((Component)networkObject).gameObject.GetComponent<PlayerControllerB>();
Light component2 = ((Component)((Component)this).transform.Find("ExplosionLight")).gameObject.GetComponent<Light>();
if ((Object)(object)component2 == (Object)null)
{
STPlugin.Log.LogInfo((object)"why.");
}
STPlugin.Log.LogDebug((object)component.playerUsername);
if (((NetworkBehaviour)component).NetworkObject.NetworkObjectId == ((NetworkObjectReference)(ref _obj)).NetworkObjectId)
{
if (STPlugin.instantlyKillPlayer.Value)
{
component.KillPlayer(Vector3.up * 100f, true, (CauseOfDeath)3, 0, default(Vector3));
}
else
{
component.DamagePlayer(STPlugin.damageDone.Value, true, true, (CauseOfDeath)3, 0, false, default(Vector3));
}
}
AudioClip clip = STPlugin.assets.LoadAsset<AudioClip>("subspace-tripmine-explosion");
((Component)component2).gameObject.SetActive(true);
component2.intensity = 600f;
if (STPlugin.enableExplosion.Value)
{
((Component)this).gameObject.GetComponent<AudioSource>().clip = clip;
((Component)this).gameObject.GetComponent<AudioSource>().Play();
}
((MonoBehaviour)this).StartCoroutine("FadeOutLight", (object)component2);
if (STPlugin.destroyAfterExplosion.Value)
{
((Component)((Component)this).transform.Find("InnerStar")).gameObject.SetActive(false);
((Component)((Component)this).transform.Find("OuterBlock")).gameObject.SetActive(false);
((Component)((Component)this).transform.Find("Trigger")).gameObject.SetActive(false);
Object.Destroy((Object)(object)((Component)this).gameObject.GetComponent<BoxCollider>());
}
};
plsDie.OnClientReceived += delegate(int damage)
{
PlayerControllerB localPlayerController = StartOfRound.Instance.localPlayerController;
if (damage < 100)
{
}
};
isPlanted.Value = false;
isPlanted.OnValueChanged += delegate(bool prev, bool newval)
{
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
STPlugin.Log.LogDebug((object)("isPlanted changed for subspace #" + id));
if (newval)
{
fadeOut = ((MonoBehaviour)this).StartCoroutine("FadeOutObject", (object)((Component)this).gameObject);
}
else if (fadeOut == null || fadeOut == null)
{
STPlugin.Log.LogDebug((object)"fadeOut is bugged, saving a NRE.");
}
else
{
if (fadeOut != null)
{
((MonoBehaviour)this).StopCoroutine(fadeOut);
}
MeshRenderer val = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>()[0];
MeshRenderer val2 = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>()[1];
Color color = ((Renderer)val).materials[0].color;
Color color2 = ((Renderer)val2).materials[0].color;
color.a = 1f;
color2.a = 1f;
((Renderer)val).materials[0].color = color;
((Renderer)val2).materials[0].color = color2;
}
};
plant.InvokeServer();
((Component)((Component)this).GetComponentInChildren<Rigidbody>()).gameObject.AddComponent<GrabbableObjectPhysicsTrigger>();
((Component)this).GetComponentInChildren<GrabbableObjectPhysicsTrigger>().itemScript = (GrabbableObject)(object)this;
}
public override void ActivatePhysicsTrigger(Collider other)
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
((GrabbableObject)this).ActivatePhysicsTrigger(other);
STPlugin.Log.LogInfo((object)other);
if (((Component)other).tag == "Player" && isPlanted.Value && StartOfRound.Instance.shipHasLanded)
{
PlayerControllerB componentInParent = ((Component)other).gameObject.GetComponentInParent<PlayerControllerB>();
NetworkObjectReference val = default(NetworkObjectReference);
((NetworkObjectReference)(ref val))..ctor(((NetworkBehaviour)componentInParent).NetworkObject);
explode.SendClients(val);
}
}
private IEnumerator FadeOutLight(Light light)
{
for (float i = 0f; i < 1f; i += Time.deltaTime / 100f)
{
light.intensity = Mathf.Lerp(light.intensity, 0f, i);
yield return null;
}
STPlugin.Log.LogInfo((object)"Finished fading");
}
private IEnumerator FadeOutObject(GameObject objToFade)
{
MeshRenderer mr1 = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>()[0];
MeshRenderer mr2 = ((Component)this).gameObject.GetComponentsInChildren<MeshRenderer>()[1];
Color newColor1 = ((Renderer)mr1).materials[0].color;
Color newColor2 = ((Renderer)mr2).materials[0].color;
for (float i = 0f; i < 1f; i += Time.deltaTime / 75f)
{
newColor1.a = Mathf.Lerp(newColor1.a, STPlugin.plantedTransparency.Value, i);
newColor2.a = Mathf.Lerp(newColor2.a, STPlugin.plantedTransparency.Value, i);
((Renderer)mr1).materials[0].color = newColor1;
((Renderer)mr2).materials[0].color = newColor2;
yield return null;
}
}
public override void GrabItem()
{
if (((NetworkBehaviour)this).IsClient)
{
if (unplant == null)
{
STPlugin.Log.LogError((object)"Plant is null. uh oh :[");
return;
}
unplant.InvokeServer();
((GrabbableObject)this).GrabItem();
}
}
public override void DiscardItem()
{
if (((NetworkBehaviour)this).IsClient)
{
if (plant == null)
{
STPlugin.Log.LogError((object)"Plant is null. uh oh :[");
return;
}
plant.InvokeServer();
((GrabbableObject)this).DiscardItem();
}
}
}