using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.Networking;
[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 = "")]
[assembly: AssemblyCompany("MyValuableItem")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A valuable item that randomly screams")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MyValuableItem")]
[assembly: AssemblyTitle("MyValuableItem")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MyValuableItem;
[BepInPlugin("YourName.MyValuableItem", "My Valuable Item - Screaming Object", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class MyValuableItemPlugin : BaseUnityPlugin
{
public static ManualLogSource ModLogger;
private void Awake()
{
ModLogger = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)"My Valuable Item mod loading...");
CreateItem();
}
private void CreateItem()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("ScreamingValuable");
MeshFilter val2 = val.AddComponent<MeshFilter>();
MeshRenderer val3 = val.AddComponent<MeshRenderer>();
val2.mesh = CreateCubeMesh();
BoxCollider val4 = val.AddComponent<BoxCollider>();
val4.size = Vector3.one;
Rigidbody val5 = val.AddComponent<Rigidbody>();
val5.mass = 1f;
val.AddComponent<ValuableItemBehaviour>();
Valuables.RegisterValuable(val);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Item registered successfully!");
}
private Mesh CreateCubeMesh()
{
GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
Mesh result = Object.Instantiate<Mesh>(val.GetComponent<MeshFilter>().sharedMesh);
Object.DestroyImmediate((Object)(object)val);
return result;
}
}
public class ValuableItemBehaviour : MonoBehaviour
{
private AudioSource audioSource;
private List<AudioClip> screamClips = new List<AudioClip>();
private float timer;
private float nextScreamTime;
private void Start()
{
audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
audioSource.spatialBlend = 1f;
audioSource.maxDistance = 30f;
audioSource.rolloffMode = (AudioRolloffMode)1;
audioSource.volume = 0.8f;
((MonoBehaviour)this).StartCoroutine(LoadSounds());
ScheduleNextScream();
}
private void Update()
{
timer += Time.deltaTime;
if (timer >= nextScreamTime && screamClips.Count > 0)
{
PlayRandomScream();
ScheduleNextScream();
}
}
private void ScheduleNextScream()
{
timer = 0f;
nextScreamTime = Random.Range(30f, 180f);
}
private void PlayRandomScream()
{
if ((Object)(object)audioSource != (Object)null && screamClips.Count > 0)
{
audioSource.clip = screamClips[Random.Range(0, screamClips.Count)];
audioSource.Play();
MyValuableItemPlugin.ModLogger.LogInfo((object)"Item screamed!");
}
}
private IEnumerator LoadSounds()
{
string pluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string soundsFolder = Path.Combine(pluginFolder, "Sounds");
if (!Directory.Exists(soundsFolder))
{
MyValuableItemPlugin.ModLogger.LogWarning((object)"Sounds folder not found");
yield break;
}
string[] soundFiles = Directory.GetFiles(soundsFolder, "*.mp3");
string[] array = soundFiles;
foreach (string soundFile in array)
{
yield return ((MonoBehaviour)this).StartCoroutine(LoadAudioClip(soundFile));
}
MyValuableItemPlugin.ModLogger.LogInfo((object)$"Loaded {screamClips.Count} sounds");
}
private IEnumerator LoadAudioClip(string path)
{
string url = "file:///" + path.Replace("\\", "/");
UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(url, (AudioType)13);
try
{
yield return www.SendWebRequest();
if ((int)www.result == 1)
{
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
((Object)clip).name = Path.GetFileNameWithoutExtension(path);
screamClips.Add(clip);
}
}
finally
{
((IDisposable)www)?.Dispose();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "MyValuableItem";
public const string PLUGIN_NAME = "MyValuableItem";
public const string PLUGIN_VERSION = "1.0.0";
}