using System;
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.Configuration;
using GroanTubeScrap.NetcodePatcher;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Kittenji")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("GroanTubeScrap")]
[assembly: AssemblyTitle("GroanTubeScrap")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 GroanTubeScrap
{
internal class GroanTubeItem : NoisemakerProp
{
private bool localState;
[Header("Horrible Color Sync")]
[Tooltip("Seekers made me do this. Look at implementation of (Item.materialVariants)")]
public Material[] altMaterials;
public int altSelect = -1;
public override int GetItemDataToSave()
{
return altSelect;
}
public override void LoadItemSaveData(int saveData)
{
altSelect = Mathf.Clamp(saveData, 0, altMaterials.Length - 1);
Material sharedMaterial = altMaterials[altSelect];
((Renderer)((GrabbableObject)this).mainObjectRenderer).sharedMaterial = sharedMaterial;
}
public override void Start()
{
((NoisemakerProp)this).Start();
if (((NetworkBehaviour)this).IsOwner && altMaterials.Length != 0)
{
if (altSelect < 0)
{
altSelect = Random.Range(0, altMaterials.Length);
}
((GrabbableObject)this).SyncBatteryServerRpc(altSelect);
}
}
public override void ChargeBatteries()
{
if (!(((GrabbableObject)this).insertedBattery.charge < 0f))
{
int num = Mathf.RoundToInt(((GrabbableObject)this).insertedBattery.charge * 100f);
num = Mathf.Clamp(num, 0, altMaterials.Length - 1);
((GrabbableObject)this).LoadItemSaveData(num);
((GrabbableObject)this).insertedBattery.charge = -1f;
}
}
public override void ItemActivate(bool used, bool buttonDown = true)
{
if (!((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
{
if (((NetworkBehaviour)this).IsOwner)
{
buttonDown = !localState;
((GrabbableObject)this).ActivateItemRpc(false, buttonDown);
}
OnItemUseLocal(buttonDown);
}
}
private void OnItemUseLocal(bool state)
{
localState = state;
base.triggerAnimator.SetTrigger("Spin");
PlayAudio((!state) ? 1 : 0);
}
private void PlayAudio(int index)
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
AudioClip val = base.noiseSFX[index];
float num = (float)base.noisemakerRandom.Next((int)(base.minLoudness * 100f), (int)(base.maxLoudness * 100f)) / 100f;
float pitch = (float)base.noisemakerRandom.Next((int)(base.minPitch * 100f), (int)(base.maxPitch * 100f)) / 100f;
base.noiseAudio.pitch = pitch;
base.noiseAudio.PlayOneShot(val, num);
WalkieTalkie.TransmitOneShotAudio(base.noiseAudio, val, num);
RoundManager.Instance.PlayAudibleNoise(((Component)this).transform.position, base.noiseRange, num, 0, ((GrabbableObject)this).isInElevator && StartOfRound.Instance.hangarDoorsClosed, 0);
if (base.minLoudness >= 0.6f && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
{
((GrabbableObject)this).playerHeldBy.timeSinceMakingLoudNoise = 0f;
}
}
protected override void __initializeVariables()
{
((NoisemakerProp)this).__initializeVariables();
}
protected override void __initializeRpcs()
{
((NoisemakerProp)this).__initializeRpcs();
}
protected internal override string __getTypeName()
{
return "GroanTubeItem";
}
}
[BepInPlugin("Kittenji.GroanTubeScrap", "Groan Tube Scrap", "1.0.5")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch()
{
((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().AddNetworkPrefab(itemEntry.spawnPrefab);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void AwakePatch(ref StartOfRound __instance)
{
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Expected O, but got Unknown
SelectableLevel[] levels = __instance.levels;
foreach (SelectableLevel val in levels)
{
if (val.spawnableScrap.Any((SpawnableItemWithRarity x) => (Object)(object)x.spawnableItem == (Object)(object)itemEntry))
{
continue;
}
int num = spawnRate.Value;
if (num < 1)
{
SpawnableItemWithRarity val2 = val.spawnableScrap.Find((SpawnableItemWithRarity s) => Object.op_Implicit((Object)(object)s.spawnableItem) && Object.op_Implicit((Object)(object)s.spawnableItem.spawnPrefab) && ((Object)s.spawnableItem.spawnPrefab).name == "RobotToy");
if (val2 != null)
{
num = val2.rarity;
}
else if (val.spawnableScrap.Count > 0)
{
int num2 = int.MaxValue;
foreach (SpawnableItemWithRarity item2 in val.spawnableScrap)
{
if (item2.rarity < num2)
{
num2 = item2.rarity;
}
}
num = num2;
}
}
num = Mathf.Clamp(num, 1, 100);
SpawnableItemWithRarity item = new SpawnableItemWithRarity(itemEntry, num);
val.spawnableScrap.Add(item);
}
if (!__instance.allItemsList.itemsList.Contains(itemEntry))
{
__instance.allItemsList.itemsList.Add(itemEntry);
}
}
}
public const string pluginGUID = "Kittenji.GroanTubeScrap";
public const string pluginName = "Groan Tube Scrap";
public const string pluginVersion = "1.0.5";
public static readonly Harmony harmony = new Harmony("Kittenji.GroanTubeScrap");
public static readonly Assets assets = new Assets();
public static Item itemEntry;
public static ConfigEntry<int> spawnRate;
private const string ItemReferenceName = "RobotToy";
private void Awake()
{
itemEntry = assets.LoadByName<Item>("GroanTube.asset", nameOnly: false);
spawnRate = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Spawn Rate Override", -1, "Override the spawn rate for this item, this affects all moons. By default, it uses the spawn rate of the Toy Cube item so it spawns in coordination with other toys.");
harmony.PatchAll();
InitNetcode();
}
private static void InitNetcode()
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
for (int i = 0; i < types.Length; i++)
{
MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
public static class ResourceUtils
{
public static Stream Get(string name)
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
if (manifestResourceNames.Length == 0)
{
throw new FileNotFoundException("Assembly does not contain any resource stream names.");
}
string text = manifestResourceNames.FirstOrDefault((string n) => n.EndsWith(name));
if (string.IsNullOrEmpty(text))
{
throw new FileNotFoundException("Assembly does not contain a resource stream ending with '" + name + "'");
}
return executingAssembly.GetManifestResourceStream(text);
}
public static string GetString(string name)
{
using Stream stream = Get(name);
using StreamReader streamReader = new StreamReader(stream);
return streamReader.ReadToEnd();
}
}
public class Assets
{
private readonly AssetBundle mainAssetBundle;
private readonly string[] allAssetNames;
public Assets(string name = ".bundle")
{
mainAssetBundle = AssetBundle.LoadFromStream(ResourceUtils.Get(name));
allAssetNames = mainAssetBundle.GetAllAssetNames();
}
public T Load<T>(string name) where T : Object
{
if (name == null)
{
return default(T);
}
return mainAssetBundle.LoadAsset<T>(name);
}
public T LoadByName<T>(string name, bool nameOnly = false) where T : Object
{
string name2 = allAssetNames.FirstOrDefault((string x) => (nameOnly ? Path.GetFileNameWithoutExtension(x) : Path.GetFileName(x)).Equals(name, StringComparison.OrdinalIgnoreCase));
return Load<T>(name2);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace __GEN
{
internal class NetworkVariableSerializationHelper
{
[RuntimeInitializeOnLoadMethod]
internal static void InitializeSerialization()
{
}
}
}
namespace GroanTubeScrap.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}