using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;
[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MoreScraps")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MoreScraps")]
[assembly: AssemblyTitle("MoreScraps")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
}
namespace MoreScrapsRandom
{
[BepInPlugin("com.example.morescrapsrandom", "More Scraps Random Mod", "1.0.0")]
public class MoreScrapsPlugin : BaseUnityPlugin
{
private bool sceneLoadedOnce = false;
private void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"[MoreScrapsRandom] Plugin loaded. Waiting for the game scene...");
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Invalid comparison between Unknown and I4
if (!sceneLoadedOnce && (int)mode == 0)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)("[MoreScrapsRandom] First scene loaded: " + ((Scene)(ref scene)).name));
sceneLoadedOnce = true;
StartLogging();
AddTemporarySceneAndObject();
}
}
private void StartLogging()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
GameObject val = new GameObject("MoreScrapsRandomObject");
val.AddComponent<MoreScrapsBehaviour>();
Object.DontDestroyOnLoad((Object)(object)val);
}
private void AddTemporarySceneAndObject()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
SceneManager.CreateScene("TemporaryScene");
GameObject val = new GameObject("TemporaryObject");
val.AddComponent<MoreScrapsBehaviour>();
SceneManager.MoveGameObjectToScene(val, SceneManager.GetSceneByName("TemporaryScene"));
Object.DontDestroyOnLoad((Object)(object)val);
((BaseUnityPlugin)this).Logger.LogInfo((object)"[MoreScrapsRandom] Temporary scene and object added.");
}
}
public class MoreScrapsBehaviour : MonoBehaviour
{
private float timer = 0f;
private bool objectFound = false;
private string[] targetObjectNames = new string[6] { "BirthdayCake", "CardBoardBox", "Chainsaw", "Typewriter", "CoolGlasses", "GardenGnome" };
private void Update()
{
timer += Time.deltaTime;
if (timer >= 5f && !objectFound)
{
Debug.Log((object)"[MoreScrapsRandom] Plugin is running...");
FindAndModifyObjects();
timer = 0f;
}
}
private void FindAndModifyObjects()
{
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
GameObject[] array2 = array;
foreach (GameObject val in array2)
{
string[] array3 = targetObjectNames;
foreach (string text in array3)
{
if (!(((Object)val).name == text))
{
continue;
}
Debug.Log((object)("[MoreScrapsRandom] Found target object: " + ((Object)val).name));
foreach (Transform item in val.transform)
{
Transform val2 = item;
if ((Object)(object)((Component)val2).GetComponent<SkinnedMeshRenderer>() != (Object)null && (Object)(object)((Component)val2).GetComponent<ObjectModifier>() == (Object)null)
{
Debug.Log((object)("[MoreScrapsRandom] Found SkinnedMeshRenderer in child: " + ((Object)val2).name));
((Component)val2).gameObject.AddComponent<ObjectModifier>();
Debug.Log((object)("[MoreScrapsRandom] Added ObjectModifier to " + ((Object)val2).name + "."));
break;
}
}
objectFound = true;
break;
}
}
}
}
public class ObjectModifier : MonoBehaviour
{
private void OnEnable()
{
Debug.Log((object)"[ObjectModifier] Object is now active.");
SkinnedMeshRenderer component = ((Component)this).GetComponent<SkinnedMeshRenderer>();
if ((Object)(object)component != (Object)null)
{
Debug.Log((object)$"[ObjectModifier] Found {((Renderer)component).materials.Length} materials.");
Material[] materials = ((Renderer)component).materials;
if (materials.Length != 0)
{
Material val = materials[Random.Range(0, materials.Length)];
Debug.Log((object)("[ObjectModifier] Selected material: " + ((Object)val).name));
((Renderer)component).materials = (Material[])(object)new Material[1] { val };
Debug.Log((object)"[ObjectModifier] Materials updated. Only the selected material is now assigned.");
}
else
{
Debug.LogWarning((object)"[ObjectModifier] No materials found on the SkinnedMeshRenderer.");
}
}
else
{
Debug.LogWarning((object)"[ObjectModifier] No SkinnedMeshRenderer found on this object.");
}
}
}
}