Decompiled source of PrefabScaler v1.0.0

PrefabScaler.dll

Decompiled 5 days ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PrefabScaler")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PrefabScaler")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("58686aa9-8e24-41c9-926c-cd721f0e2963")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PrefabScaler;

[BepInPlugin("Verluer.PrefabScaler", "PrefabScaler", "1.0.0")]
public class PrefabScaler : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	public ConfigEntry<string> ScalePrefab;

	public static string PrefabList { get; private set; }

	private void Awake()
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		Log = Logger.CreateLogSource("Verluer.EntityScaler");
		ScalePrefab = ((BaseUnityPlugin)this).Config.Bind<string>("Scale Settings", "Scale Prefabs", "None", "Change the size of an entity. Use the following format:\n{PrefabID}:{multiplier},{PrefabID2}:{multiplier},...\nExample:\nbonfire:5 - increases the 'bonfire' entity 5 times\nbonfire:0.5 - decreases the 'bonfire' entity by half");
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		PrefabList = Path.Combine(directoryName, "PrefabList.txt");
		try
		{
			File.WriteAllText(PrefabList, $"=== Start {DateTime.Now:yyyy-MM-dd HH:mm:ss} ==={Environment.NewLine}");
		}
		catch (Exception arg)
		{
			Log.LogError((object)$"Error: {arg}");
		}
		new Harmony("Verluer.ScaleAreaSpawner").PatchAll();
	}
}
[HarmonyPatch(typeof(ZNetScene), "Awake")]
public static class ScalePrebaf
{
	private static void Postfix(ZNetScene __instance)
	{
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine($"m_prefabs count: {__instance.m_prefabs.Count}");
			foreach (GameObject prefab in __instance.m_prefabs)
			{
				if ((Object)(object)prefab != (Object)null)
				{
					stringBuilder.AppendLine(((Object)prefab).name);
				}
			}
			File.AppendAllText(PrefabScaler.PrefabList, stringBuilder.ToString());
			PrefabScaler.Log.LogInfo((object)("Prefabs dumped to: " + PrefabScaler.PrefabList));
			PrefabScaler component = Chainloader.ManagerObject.GetComponent<PrefabScaler>();
			string[] array = component.ScalePrefab.Value.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { ':' });
				string text = array2[0];
				string s = array2[1];
				foreach (GameObject prefab2 in __instance.m_prefabs)
				{
					if (!((Object)(object)prefab2 == (Object)null) && ((Object)prefab2).name == text)
					{
						prefab2.transform.localScale = Vector3.one * float.Parse(s, CultureInfo.InvariantCulture);
						PrefabScaler.Log.LogInfo((object)(text + " scale changed!"));
					}
				}
			}
		}
		catch (Exception ex)
		{
			PrefabScaler.Log.LogWarning((object)ex);
		}
	}
}