using System.Diagnostics;
using System.IO;
using System.Linq;
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 HarmonyLib;
using Unity.Netcode;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("LaserTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LaserTweaks")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4963e0ea-7a99-4390-9cae-a4bdd01b6b43")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace GroanTubeScrap
{
public class Assets
{
public static AssetBundle MainAssetBundle;
public static Item Item;
internal static Stream GetEmbededResource(string name)
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("GroanTubeScrap." + name);
}
public static void Init()
{
MainAssetBundle = AssetBundle.LoadFromStream(GetEmbededResource("groantube.bundle"));
Item = MainAssetBundle.LoadAsset<Item>("Assets/Mods/GroanTubeScrap/GroanTube.asset");
}
}
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).isSendingItemRPC = ((GrabbableObject)this).isSendingItemRPC + 1;
((GrabbableObject)this).ActivateItemServerRpc(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;
}
}
}
[BepInPlugin("Kittenji.GroanTubeScrap", "Groan Tube Scrap", "1.0.4")]
public class Loader : BaseUnityPlugin
{
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPatch()
{
((Component)GameNetworkManager.Instance).GetComponent<NetworkManager>().AddNetworkPrefab(Assets.Item.spawnPrefab);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void AwakePatch(ref StartOfRound __instance)
{
//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_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: 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)Assets.Item))
{
continue;
}
int num = SpawnRateOverride.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
{
spawnableItem = Assets.Item,
rarity = num
};
val.spawnableScrap.Add(item);
}
if (!__instance.allItemsList.itemsList.Contains(Assets.Item))
{
__instance.allItemsList.itemsList.Add(Assets.Item);
}
}
}
private const string modGUID = "Kittenji.GroanTubeScrap";
private readonly Harmony harmony = new Harmony("Kittenji.GroanTubeScrap");
private static ConfigEntry<int> SpawnRateOverride;
private const string ItemReferenceName = "RobotToy";
private void Awake()
{
Assets.Init();
SpawnRateOverride = ((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();
}
}
}