using System;
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.Timers;
using BepInEx;
using BepInEx.Logging;
using CG;
using CG.Network;
using CG.Space;
using CG.Utils;
using Client.Player.Interactions;
using Gameplay.CompositeWeapons;
using Gameplay.Enhancements;
using Gameplay.Utilities;
using HarmonyLib;
using Photon.Pun;
using ResourceAssets;
using UI.Ping;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreEnhancements")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreEnhancements")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0380985b-49a5-47a5-9d28-f748d33ad81c")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace FrogtownVoidMods;
[BepInPlugin("moreenhancements.frogtown.me", "More Enhancements", "0.1")]
public class MoreEnhancements : BaseUnityPlugin
{
private class VoidManagerPlugin : VoidPlugin
{
public override MultiplayerType MPType => (MultiplayerType)30;
public override string Author => "ToyDragon";
public override string Description => "Adds enhancement panels to guns";
public override string ThunderstoreID => "ToyDragon/MoreEnhancements";
}
public class ME_Enhancement : Enhancement
{
public static HashSet<int> AttachedViews = new HashSet<int>();
public int cellModuleViewId;
public override void OnPhotonInstantiate(PhotonMessageInfo info)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: 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_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Expected O, but got Unknown
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Expected O, but got Unknown
//IL_038c: Unknown result type (might be due to invalid IL or missing references)
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_0394: Unknown result type (might be due to invalid IL or missing references)
//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
//IL_03b6: Expected O, but got Unknown
//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
//IL_03d4: Unknown result type (might be due to invalid IL or missing references)
//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
//IL_03e2: Expected O, but got Unknown
//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_0405: Unknown result type (might be due to invalid IL or missing references)
//IL_040e: Expected O, but got Unknown
//IL_0303: Unknown result type (might be due to invalid IL or missing references)
//IL_030d: Expected O, but got Unknown
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_0336: Expected O, but got Unknown
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
//IL_035f: Expected O, but got Unknown
((MonoBehaviourPunSync)this).OnPhotonInstantiate(info);
Dictionary<byte, object> dictionary = InstantiationDataParser.ParseInstantiationData(info.photonView.InstantiationData);
if (!dictionary.TryGetValue(40, out var value) || !(value is int num))
{
L.LogError((object)"No targetId to attach panel to :(");
return;
}
AttachedViews.Add(num);
CompositeWeaponModule val = ObjectRegistry.FindByPhotonView<CompositeWeaponModule>(num);
if ((Object)(object)val == (Object)null)
{
L.LogError((object)("No weapon with id " + num));
return;
}
cellModuleViewId = num;
((Component)this).transform.SetParent(((Component)val).transform);
((Component)this).transform.position = ((Component)val).transform.position + -1.75f * ((Component)val).transform.forward + 0.85f * ((Component)val).transform.right + 0.1f * ((Component)val).transform.up;
((Component)this).transform.localEulerAngles = new Vector3(-30f, 180f, 0f);
base.contextInfo = (ContextInfo)((AbstractCloneStarObject)val).ContextInfo.source;
Traverse.Create((object)this).Field("targets").SetValue((object)new List<Component> { (Component)(object)val });
L.LogInfo((object)("Instantiated enhancement panel for " + num + ": AmOwner=" + ((MonoBehaviourPun)this).photonView.AmOwner));
ContextInfoProvider component = ((Component)this).GetComponent<ContextInfoProvider>();
Traverse val2 = Traverse.Create((object)component);
val2.Field("contextItem").SetValue((object)this);
val2.Field("contextInfoSource").SetValue((object)val);
((MonoBehaviourPun)this).photonView.ObservedComponents.Clear();
((MonoBehaviourPun)this).photonView.ObservedComponents.Add((Component)(object)this);
DurationTimeDisplayer[] componentsInChildren = ((Component)this).GetComponentsInChildren<DurationTimeDisplayer>(true);
DurationTimeDisplayer[] array = componentsInChildren;
foreach (DurationTimeDisplayer val3 in array)
{
Traverse.Create((object)val3).Field("enhancement").SetValue((object)this);
}
base.AppliedEnhancementEffect = new EnhancementEffectAsset();
base.AppliedEnhancementEffect.ActiveDuration = 30f;
List<StatMod> list = new List<StatMod>();
List<StatMod> list2 = new List<StatMod>();
List<StatMod> list3 = new List<StatMod>();
foreach (KeyValuePair<int, StatBase> stat in ((StatCollection)((OrbitObject)val).Stats).Stats)
{
if (stat.Key <= 10000 && stat.Key != ((Enumeration)StatType.HeatPerShot).Id)
{
bool flag = stat.Key == ((Enumeration)StatType.ReloadTime).Id;
list.Add(new StatMod((PrimitiveModifier)(object)FloatModifier.ScalarModifier(flag ? 0.9090909f : 1.1f), stat.Key));
list2.Add(new StatMod((PrimitiveModifier)(object)FloatModifier.ScalarModifier(flag ? 0.8f : 1.25f), stat.Key));
list3.Add(new StatMod((PrimitiveModifier)(object)FloatModifier.ScalarModifier(flag ? (2f / 3f) : 1.5f), stat.Key));
}
}
base.AppliedEnhancementEffect.SuccessfulEffects = (Effect[])(object)new Effect[3]
{
new Effect
{
grade = new EnhancementGrade
{
RequiredScore = 1f
},
Modifiers = list
},
new Effect
{
grade = new EnhancementGrade
{
RequiredScore = 2f
},
Modifiers = list2
},
new Effect
{
grade = new EnhancementGrade
{
RequiredScore = 3f
},
Modifiers = list3
}
};
PingableItemCollection componentInParent = ((Component)this).GetComponentInParent<PingableItemCollection>();
PingableItem[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<PingableItem>();
PingableItem[] array2 = componentsInChildren2;
foreach (PingableItem val4 in array2)
{
componentInParent.AddPingableItem(val4);
}
((Behaviour)this).enabled = true;
}
public static void CreateIfMissing(CompositeWeaponModule weapon)
{
//IL_006e: 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)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if (((OrbitObject)weapon).AmOwner && !AttachedViews.Contains(((MonoBehaviourPun)weapon).photonView.ViewID))
{
AttachedViews.Add(((MonoBehaviourPun)weapon).photonView.ViewID);
L.LogInfo((object)("Creating enhancement panel for " + ((MonoBehaviourPun)weapon).photonView.ViewID));
GameObject val = ObjectFactory.InstantiateResourceAssetByGUID(GUID_ME_Enhancement_Panel, Vector3.zero, Quaternion.identity, new Dictionary<byte, object> {
{
40,
((MonoBehaviourPun)weapon).photonView.ViewID
} });
}
}
[PunRPC]
private void StateChangePun(EnhancementState newState, float activationGrade, float durationMultiplier)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
typeof(Enhancement).GetMethod("StateChangePun", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, new object[3] { newState, activationGrade, durationMultiplier });
}
}
public class MoreEnhancementsCore
{
public static MoreEnhancementsCore instance;
private static List<CompositeWeaponModule> weaponModules = new List<CompositeWeaponModule>();
private static PlayerShip ship;
private DateTime lastCreateAttempt = DateTime.Now;
private bool initialized = false;
public void TryCreatePrefab()
{
//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
if (initialized || DateTime.Now < lastCreateAttempt.AddSeconds(5.0))
{
return;
}
lastCreateAttempt = DateTime.Now;
CloneStarObjectContainer val = ResourceAssetContainer<CloneStarObjectContainer, AbstractCloneStarObject, CloneStarObjectDef>.Instance;
if ((Object)(object)val == (Object)null)
{
L.LogInfo((object)"RAC not yet initialized");
return;
}
L.LogInfo((object)"Trying to create ME_Enhancement prefab");
if (PhotonNetwork.PrefabPool != null)
{
IPunPrefabPool prefabPool = PhotonNetwork.PrefabPool;
DefaultPool val2 = (DefaultPool)(object)((prefabPool is DefaultPool) ? prefabPool : null);
if (val2 != null)
{
CloneStarObjectDef val3 = null;
try
{
val3 = ((ResourceAssetContainer<CloneStarObjectContainer, AbstractCloneStarObject, CloneStarObjectDef>)(object)val).GetAssetByPath(PATH_Charge_Station);
}
catch (Exception)
{
}
if (val3 == null)
{
L.LogError((object)"RAC doesn't contain charge station definition?");
return;
}
L.LogInfo((object)("Checking for charge station at " + ((ResourceAssetDef<AbstractCloneStarObject>)(object)val3).Path));
GameObject val4 = Resources.Load<GameObject>(((ResourceAssetDef<AbstractCloneStarObject>)(object)val3).Path);
if ((Object)(object)val4 == (Object)null)
{
L.LogError((object)"Unable to find prefab for charge station.");
return;
}
GameObject val5 = Object.Instantiate<GameObject>(val4);
GameObject val6 = Object.Instantiate<GameObject>(((Component)val5.GetComponentInChildren<Enhancement>()).gameObject);
Enhancement component = val6.GetComponent<Enhancement>();
ME_Enhancement mE_Enhancement = val6.AddComponent<ME_Enhancement>();
((Enhancement)mE_Enhancement).AppliedEnhancementEffect = component.AppliedEnhancementEffect;
Traverse.Create((object)val6.GetComponent<EnhancementActivator>()).Field("requiresPower").SetValue((object)false);
List<ContextInfoModifier> list = (List<ContextInfoModifier>)Traverse.Create((object)val6.GetComponent<ContextInfoProvider>()).Field("modifiers").GetValue();
foreach (ContextInfoModifier item in list)
{
EnhancementContextModifier val7 = (EnhancementContextModifier)(object)((item is EnhancementContextModifier) ? item : null);
if (val7 != null)
{
Traverse.Create((object)val7).Field("enhancement").SetValue((object)mE_Enhancement);
}
}
EnhancementCrypticAnimator componentInChildren = val6.GetComponentInChildren<EnhancementCrypticAnimator>();
Traverse.Create((object)componentInChildren).Field("enhancement").SetValue((object)mE_Enhancement);
ContextInfoProvider component2 = val6.GetComponent<ContextInfoProvider>();
Traverse.Create((object)component2).Field("contextItem").SetValue((object)mE_Enhancement);
Object.Destroy((Object)(object)val5);
Object.Destroy((Object)(object)component);
string text = "MoreEnhancements/ME_EnhancementPanel";
L.LogInfo((object)("Created ME_Enhancement prefab called " + ((Object)val6).name + "__" + text + "__" + Path.GetFileName(text)));
ResourcePaths.Instance.SetPath(GUID_ME_Enhancement_Panel, text);
val2.ResourceCache.Add(text, val6);
L.LogInfo((object)"Registered ME_Enhancement prefab");
initialized = true;
return;
}
}
L.LogError((object)"Prefab pool is not a DefaultPool, probably caused by a mod conflict?");
}
public void Update(GameObject go)
{
TryCreatePrefab();
if (!initialized)
{
TryCreatePrefab();
return;
}
if ((Object)(object)ship == (Object)null)
{
ship = Object.FindAnyObjectByType<PlayerShip>();
}
if ((Object)(object)ship == (Object)null)
{
return;
}
weaponModules.Clear();
((Component)ship).GetComponentsInChildren<CompositeWeaponModule>(weaponModules);
foreach (CompositeWeaponModule weaponModule in weaponModules)
{
ME_Enhancement.CreateIfMissing(weaponModule);
}
}
}
public class UnityUpdateShim : MonoBehaviour
{
private static UnityUpdateShim _instance;
private static DateTime _lastRegenAttempt;
private static Timer _timer;
private void Update()
{
MoreEnhancementsCore.instance.Update(((Component)this).gameObject);
}
[Obsolete]
public static void RegenInstance(object sender, ElapsedEventArgs e)
{
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Expected O, but got Unknown
if (!Object.op_Implicit((Object)(object)_instance) && !(_lastRegenAttempt.AddSeconds(5.0) > DateTime.Now))
{
_lastRegenAttempt = DateTime.Now;
GameObject val = new GameObject("More Enhancements");
_instance = val.AddComponent<UnityUpdateShim>();
L.LogInfo((object)"Recreated shim.");
}
}
[Obsolete]
public static void StartRegenThread()
{
_timer = new Timer(100.0);
_timer.Elapsed += RegenInstance;
_timer.AutoReset = true;
_timer.Enabled = true;
L.LogInfo((object)"Started regen thread.");
}
}
public static MoreEnhancements instance;
public const string PLUGIN_GUID = "moreenhancements.frogtown.me";
public const string PLUGIN_NAME = "More Enhancements";
public const string PLUGIN_VERSION = "0.1";
public static string PATH_Charge_Station = "Prefabs/Space Objects/Modules/Buildable/Module_Buildable_ChargeStation_01";
public static GUIDUnion GUID_ME_Enhancement_Panel = new GUIDUnion(40, 40, 40, 0);
private static ManualLogSource L;
[Obsolete]
private void Awake()
{
if (MoreEnhancementsCore.instance == null)
{
L = ((BaseUnityPlugin)this).Logger;
L.LogInfo((object)"Creating core.");
MoreEnhancementsCore.instance = new MoreEnhancementsCore();
UnityUpdateShim.RegenInstance(null, null);
UnityUpdateShim.StartRegenThread();
}
}
}