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 BepInEx;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("com.yourname.mymonstermod", "My Monster Mod", "1.0.0")]
public class MyMonsterMod : BaseUnityPlugin
{
private void Awake()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
((BaseUnityPlugin)this).Logger.LogInfo((object)"My Monster Mod loading...");
new Harmony("com.yourname.mymonstermod").PatchAll();
}
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
[HarmonyPostfix]
private static void SpawnMonsterAfterGameStart()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new GameObject("MonsterSpawnHelper").AddComponent<MonsterSpawner>();
}
}
public class MonsterSpawner : MonoBehaviour
{
[CompilerGenerated]
private sealed class <SpawnMonsterCoroutine>d__1 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public MonsterSpawner <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SpawnMonsterCoroutine>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Expected O, but got Unknown
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Unknown result type (might be due to invalid IL or missing references)
int num = <>1__state;
MonsterSpawner monsterSpawner = <>4__this;
switch (num)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(3f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
try
{
string path = Path.Combine(Paths.BepInExRootPath, "plugins", "MyMonsterMod");
string text = Path.Combine(path, "monster.jpg");
if (!File.Exists(text))
{
Debug.LogError((object)("Image not found at: " + text));
return false;
}
Texture2D val = new Texture2D(1, 1);
val.SetPixel(0, 0, Color.red);
Debug.Log((object)"Using default texture for testing - image loading skipped");
AudioClip val2 = null;
string path2 = Path.Combine(path, "monster.wav");
if (File.Exists(path2))
{
val2 = WavUtility.ToAudioClip(File.ReadAllBytes(path2), "MonsterSound");
}
GameObject val3 = new GameObject("MyCustomMonster");
SpriteRenderer obj = val3.AddComponent<SpriteRenderer>();
obj.sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
obj.color = Color.magenta;
if ((Object)(object)val2 != (Object)null)
{
AudioSource obj2 = val3.AddComponent<AudioSource>();
obj2.clip = val2;
obj2.loop = true;
obj2.spatialBlend = 1f;
obj2.Play();
}
else
{
val3.AddComponent<AudioSource>();
}
SphereCollider obj3 = val3.AddComponent<SphereCollider>();
obj3.radius = 1f;
((Collider)obj3).isTrigger = true;
val3.AddComponent<CustomMonsterAI>();
val3.transform.position = new Vector3(10f, 0f, 10f);
Debug.Log((object)"Custom monster spawned successfully! (Default texture used)");
Object.Destroy((Object)(object)((Component)monsterSpawner).gameObject);
}
catch (Exception arg)
{
Debug.LogError((object)$"Error spawning monster: {arg}");
Object.Destroy((Object)(object)((Component)monsterSpawner).gameObject);
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private void Start()
{
((MonoBehaviour)this).StartCoroutine(SpawnMonsterCoroutine());
}
[IteratorStateMachine(typeof(<SpawnMonsterCoroutine>d__1))]
private IEnumerator SpawnMonsterCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SpawnMonsterCoroutine>d__1(0)
{
<>4__this = this
};
}
}
public class CustomMonsterAI : MonoBehaviour
{
public float speed = 1.5f;
private Transform player;
private AudioSource audioSource;
private void Start()
{
audioSource = ((Component)this).GetComponent<AudioSource>();
FindPlayer();
}
private void Update()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player == (Object)null)
{
FindPlayer();
return;
}
Vector3 val = player.position - ((Component)this).transform.position;
Vector3 normalized = ((Vector3)(ref val)).normalized;
Transform transform = ((Component)this).transform;
transform.position += normalized * speed * Time.deltaTime;
if ((Object)(object)audioSource != (Object)null && (Object)(object)audioSource.clip != (Object)null)
{
float num = Vector3.Distance(((Component)this).transform.position, player.position);
audioSource.volume = Mathf.Clamp(1f - num / 10f, 0f, 1f);
}
if (Vector3.Distance(((Component)this).transform.position, player.position) < 2f)
{
AttackPlayer();
}
}
private void FindPlayer()
{
GameObject val = GameObject.FindWithTag("Player");
if ((Object)(object)val != (Object)null)
{
player = val.transform;
}
}
private void AttackPlayer()
{
Debug.Log((object)"Monster attacking player!");
}
}
public static class WavUtility
{
public static AudioClip ToAudioClip(byte[] wavFile, string clipName)
{
if (wavFile == null || wavFile.Length < 44)
{
return null;
}
try
{
int num = BitConverter.ToInt16(wavFile, 22);
int num2 = BitConverter.ToInt32(wavFile, 24);
int num3 = BitConverter.ToInt16(wavFile, 34);
int num4 = 0;
int num5 = 44;
for (int i = 0; i < wavFile.Length - 4; i++)
{
if (wavFile[i] == 100 && wavFile[i + 1] == 97 && wavFile[i + 2] == 116 && wavFile[i + 3] == 97)
{
num4 = BitConverter.ToInt32(wavFile, i + 4);
num5 = i + 8;
break;
}
}
if (num4 == 0)
{
return null;
}
int num6 = num3 / 8;
int num7 = num4 / num6;
float[] array = new float[num7];
for (int j = 0; j < num7; j++)
{
int num8 = num5 + j * num6;
switch (num3)
{
case 16:
{
short num9 = BitConverter.ToInt16(wavFile, num8);
array[j] = (float)num9 / 32768f;
break;
}
case 8:
{
sbyte b = (sbyte)wavFile[num8];
array[j] = (float)b / 128f;
break;
}
default:
return null;
}
}
AudioClip obj = AudioClip.Create(clipName, num7, num, num2, false);
obj.SetData(array, 0);
return obj;
}
catch (Exception arg)
{
Debug.LogError((object)$"Error loading WAV file: {arg}");
return null;
}
}
}