Decompiled source of RandomSizePlayer v0.0.9

RandomSizePlayer.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
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("ScalePlayer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ScalePlayer")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("67d1b2eb-c706-4d88-bebf-a2edf2daaa4d")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[Serializable]
public class SerializableVector3
{
	public float x;

	public float y;

	public float z;

	public SerializableVector3(float x, float y, float z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public Vector3 ToVector3()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(x, y, z);
	}

	public static SerializableVector3 FromVector3(Vector3 vector)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		return new SerializableVector3(vector.x, vector.y, vector.z);
	}
}
namespace RandomSizePlayer;

[BepInPlugin("nexor.RandomSizePlayer", "RandomSizePlayer", "0.0.9")]
public class RandomSizePlayer : BaseUnityPlugin
{
	private const string modGUID = "nexor.RandomSizePlayer";

	private const string modName = "RandomSizePlayer";

	private const string modVersion = "0.0.9";

	private readonly Harmony harmony = new Harmony("nexor.RandomSizePlayer");

	public ConfigEntry<float> k1;

	public ConfigEntry<float> k2;

	public ConfigEntry<float> k3;

	public ConfigEntry<float> player_sharpness;

	public ConfigEntry<float> c1;

	public ConfigEntry<float> c2;

	public ConfigEntry<float> c3;

	public ConfigEntry<float> furniture_sharpness;

	public ConfigEntry<string> load_file_name;

	public ConfigEntry<string> save_file_name;

	public static RandomSizePlayer Instance;

	public static ManualLogSource Logger;

	public ConfigEntry<bool> change_player_size;

	public ConfigEntry<bool> player_random;

	public ConfigEntry<bool> hide_your_visor;

	public ConfigEntry<bool> lock_player_portion;

	public ConfigEntry<bool> load_preset;

	public ConfigEntry<bool> lock_furniture_portion;

	public ConfigEntry<bool> furniture_random;

	public bool ship = false;

	private Dictionary<string, SerializableVector3> size_original_dict;

	private Dictionary<string, SerializableVector3> size_preset_dict;

	private void Load_Dict()
	{
		if (File.Exists(Application.persistentDataPath + "/size_preset_dict" + load_file_name.Value + ".dat"))
		{
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			FileStream fileStream = File.Open(Application.persistentDataPath + "/size_preset_dict" + load_file_name.Value + ".dat", FileMode.Open);
			size_preset_dict = (Dictionary<string, SerializableVector3>)binaryFormatter.Deserialize(fileStream);
			fileStream.Close();
		}
		else
		{
			size_preset_dict = new Dictionary<string, SerializableVector3>();
		}
		size_original_dict = new Dictionary<string, SerializableVector3>();
	}

	private void Save_Preset_Dict()
	{
		BinaryFormatter binaryFormatter = new BinaryFormatter();
		FileStream fileStream = File.Create(Application.persistentDataPath + "/size_preset_dict" + save_file_name.Value + ".dat");
		binaryFormatter.Serialize(fileStream, size_preset_dict);
		fileStream.Close();
	}

	public bool in_preset_dict(NetworkObject networkObject)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		string name = ((Object)networkObject).name;
		if (Instance.size_preset_dict.ContainsKey(name))
		{
			Vector3 val = size_preset_dict[name].ToVector3();
			return true;
		}
		return false;
	}

	public Vector3 get_preset_from_preset_dict(NetworkObject networkObject)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		string name = ((Object)networkObject).name;
		if (Instance.size_preset_dict.ContainsKey(name))
		{
			return size_preset_dict[name].ToVector3();
		}
		return new Vector3(1f, 1f, 1f);
	}

	public void Update_size_original_dict(NetworkObject networkObject)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		string name = ((Object)networkObject).name;
		if (!size_original_dict.ContainsKey(name))
		{
			size_original_dict.Add(name, SerializableVector3.FromVector3(((Component)networkObject).transform.localScale));
		}
	}

	public Vector3 Update_size_preset_dict(NetworkObject networkObject, float x, float y, float z)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		string name = ((Object)networkObject).name;
		Vector3 val = size_original_dict[((Object)networkObject).name].ToVector3();
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(val.x * x, val.y * y, val.z * z);
		size_preset_dict[((Object)networkObject).name] = SerializableVector3.FromVector3(val2);
		Save_Preset_Dict();
		return val2;
	}

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		change_player_size = ((BaseUnityPlugin)this).Config.Bind<bool>("Player Size(玩家大小调整)", "change player size? 是否改变玩家大小", true, "If false, all config in Player Size will be ignored 如果是false,则会忽略Player Size(玩家大小调整)中的所有变量");
		k1 = ((BaseUnityPlugin)this).Config.Bind<float>("Player Size(玩家大小调整)", "width 宽", 1f, "if you want everybody to be the exact same size 如果你想让所有玩家都一个大小的话");
		k2 = ((BaseUnityPlugin)this).Config.Bind<float>("Player Size(玩家大小调整)", "height 高", 1f, "if you want everybody to be the exact same size 如果你想让所有玩家都一个大小的话");
		k3 = ((BaseUnityPlugin)this).Config.Bind<float>("Player Size(玩家大小调整)", "thickness 厚", 1f, "if you want everybody to be the exact same size 如果你想让所有玩家都一个大小的话");
		player_random = ((BaseUnityPlugin)this).Config.Bind<bool>("Player Size(玩家大小调整)", "random size? 是否采用随机大小", false, "If a random size is used, the three fixed scale values customized above are ignored 如果采用随机大小,则会忽视上面自定义的三个固定比例值");
		lock_player_portion = ((BaseUnityPlugin)this).Config.Bind<bool>("Player Size(玩家大小调整)", "lock portion? 锁定随机比例?", false, "Whether the random player size changes in proportion 随机玩家大小时是否同比例变化");
		player_sharpness = ((BaseUnityPlugin)this).Config.Bind<float>("Player Size(玩家大小调整)", "the sharpness of the random player size s curve? 随机玩家大小的概率曲线的陡峭程度", 1f, "The larger the value, the more likely extreme values are to occur, while the smaller the value, the more likely intermediate values are to occur越大越容易出现极端值, 越小越容易出现中间值");
		load_preset = ((BaseUnityPlugin)this).Config.Bind<bool>("Furniture Size(船上设施大小调整)", "load preset size file? 是否加载预设文件", true, "Load your size preset files for furniture whenever you host the game. 每当你开房时都可以为家具加载你的大小预设文件");
		c1 = ((BaseUnityPlugin)this).Config.Bind<float>("Furniture Size(船上设施大小调整)", "width 宽", 1f, "Affects the size of your newly placed furniture, the guest machine can only see the size of the furniture at the time it entered the room, and it will regain its size after recycling to the terminal and taking it out again 影响你新放置的家具的大小,客机只能看到其进房间时的家具的大小,并且回收到终端再拿出后客机会恢复大小");
		c2 = ((BaseUnityPlugin)this).Config.Bind<float>("Furniture Size(船上设施大小调整)", "height 高", 1f, "the same as above 同上");
		c3 = ((BaseUnityPlugin)this).Config.Bind<float>("Furniture Size(船上设施大小调整)", "thickness 厚", 1f, "the same as above 同上");
		load_file_name = ((BaseUnityPlugin)this).Config.Bind<string>("Furniture Size(船上设施大小调整)", "load size-preset-file s name 加载预设文件的名字", "_default", "if load size preset file, load file named with xxx. 如果加载预设文件的话,加载名为xxx的预设文件");
		save_file_name = ((BaseUnityPlugin)this).Config.Bind<string>("Furniture Size(船上设施大小调整)", "save size-preset-file s name 保存预设文件的名字", "_default", "Whenever you place a furniture, its size is recorded and written to a preset file called xxx 每当你放置一个家具时,其就会记录该家具的大小并写入名为xxx的预设文件");
		hide_your_visor = ((BaseUnityPlugin)this).Config.Bind<bool>("Other(其他)", "hide you visor? 是否隐藏面罩", false, "hide visor only work on you. 隐藏面罩只对自己生效");
		Logger = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
		Logger.LogInfo((object)"RandomSizePlayer 0.0.9 loaded.");
		Load_Dict();
	}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerB_Awake_Patch
{
	[HarmonyPatch("Awake")]
	[HarmonyPostfix]
	private static void postfix(PlayerControllerB __instance)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		if (RandomSizePlayer.Instance.hide_your_visor.Value)
		{
			__instance.localVisorTargetPoint.position = new Vector3(0f, 0f, 1000f);
		}
		if (!RandomSizePlayer.Instance.change_player_size.Value)
		{
			return;
		}
		NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
		if (!networkManager.IsServer)
		{
			return;
		}
		float value = RandomSizePlayer.Instance.k1.Value;
		float value2 = RandomSizePlayer.Instance.k2.Value;
		float value3 = RandomSizePlayer.Instance.k3.Value;
		if (!RandomSizePlayer.Instance.player_random.Value)
		{
			((Component)__instance).transform.localScale = new Vector3(value, value2, value3);
			return;
		}
		float num = Random.Range(-1f, 1f);
		float num2 = Random.Range(-1f, 1f);
		float num3 = Random.Range(-1f, 1f);
		value = (1f / (1f + Mathf.Exp(-4f * num * RandomSizePlayer.Instance.player_sharpness.Value)) - 0.5f) * 2f * 1.55f;
		value2 = 1f / (1f + Mathf.Exp(-2f * num2 * RandomSizePlayer.Instance.player_sharpness.Value)) * 1.75f;
		value3 = 1f / (1f + Mathf.Exp(-4f * num3 * RandomSizePlayer.Instance.player_sharpness.Value)) * 1.6f;
		if (RandomSizePlayer.Instance.lock_player_portion.Value)
		{
			((Component)__instance).transform.localScale = new Vector3(value2, value2, value2);
			return;
		}
		((Component)__instance).transform.localScale = new Vector3(value, value2, value3);
		ManualLogSource logger = RandomSizePlayer.Logger;
		Vector3 val = new Vector3(value, value2, value3);
		logger.LogInfo((object)("applied " + ((object)(Vector3)(ref val)).ToString() + " to " + __instance.playerUsername));
	}
}
[HarmonyPatch(typeof(ShipBuildModeManager))]
internal class ShipBuildModeManager_Patch
{
	[HarmonyPatch("PlaceShipObjectServerRpc")]
	[HarmonyPrefix]
	private static void prefix(ShipBuildModeManager __instance, Vector3 newPosition, Vector3 newRotation, NetworkObjectReference objectRef, int playerWhoMoved)
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
		if (networkManager.IsServer && playerWhoMoved == (int)StartOfRound.Instance.localPlayerController.playerClientId)
		{
			NetworkObject val = default(NetworkObject);
			((NetworkObjectReference)(ref objectRef)).TryGet(ref val, (NetworkManager)null);
			float value = RandomSizePlayer.Instance.c1.Value;
			float value2 = RandomSizePlayer.Instance.c2.Value;
			float value3 = RandomSizePlayer.Instance.c3.Value;
			RandomSizePlayer.Instance.Update_size_original_dict(val);
			Vector3 localScale = RandomSizePlayer.Instance.Update_size_preset_dict(val, value, value2, value3);
			((Component)val).transform.localScale = localScale;
			RandomSizePlayer.Logger.LogInfo((object)"changed!");
		}
	}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRound_Patch
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	private static void postfix(StartOfRound __instance)
	{
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager networkManager = ((NetworkBehaviour)__instance).NetworkManager;
		if (!networkManager.IsServer)
		{
			return;
		}
		foreach (NetworkObject value in NetworkManager.Singleton.SpawnManager.SpawnedObjects.Values)
		{
			if (!RandomSizePlayer.Instance.load_preset.Value)
			{
				break;
			}
			if (RandomSizePlayer.Instance.in_preset_dict(value))
			{
				RandomSizePlayer.Instance.Update_size_original_dict(value);
				Vector3 localScale = RandomSizePlayer.Instance.get_preset_from_preset_dict(value);
				((Component)value).transform.localScale = localScale;
			}
		}
	}
}