Decompiled source of HostOnlyTruckStart v1.0.0

plugins/HostOnlyTruckStart.dll

Decompiled 9 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Photon.Pun;
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("HostOnlyTruckStart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HostOnlyTruckStart")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2a7b7ee0-4b86-4fc7-8b98-2be32fc6c5f6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HostOnlyTruckStart;

[BepInPlugin("repo.hostonlytruckstart", "Host Only Truck Start", "1.3.0")]
public class Plugin : BaseUnityPlugin
{
	private Harmony harmony;

	internal static FieldInfo IsDisabledField;

	internal static PropertyInfo IsDisabledProperty;

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		harmony = new Harmony("repo.hostonlytruckstart");
		harmony.PatchAll();
		IsDisabledField = typeof(PlayerAvatar).GetField("isDisabled", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		IsDisabledProperty = typeof(PlayerAvatar).GetProperty("isDisabled", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Host Only Truck Start loaded.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"isDisabled field found: {IsDisabledField != null}");
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"isDisabled property found: {IsDisabledProperty != null}");
	}

	internal static bool GetIsDisabled(PlayerAvatar player)
	{
		if ((Object)(object)player == (Object)null)
		{
			return false;
		}
		try
		{
			if (IsDisabledField != null && IsDisabledField.GetValue(player) is bool result)
			{
				return result;
			}
			if (IsDisabledProperty != null)
			{
				object value = IsDisabledProperty.GetValue(player, null);
				if (value is bool)
				{
					bool result2 = (bool)value;
					if (true)
					{
						return result2;
					}
				}
			}
		}
		catch
		{
		}
		return false;
	}

	internal static bool HostIsDeadOrDisabled()
	{
		if (!GameManager.Multiplayer())
		{
			return false;
		}
		foreach (PlayerAvatar item in SemiFunc.PlayerGetList())
		{
			if ((Object)(object)item == (Object)null || (Object)(object)item.photonView == (Object)null || item.photonView.Owner != PhotonNetwork.MasterClient)
			{
				continue;
			}
			return GetIsDisabled(item);
		}
		return false;
	}
}
[HarmonyPatch(typeof(TruckScreenText), "ChatMessageSend")]
public static class Patch_ChatMessageSend
{
	private static bool Prefix(string playerName)
	{
		if (!GameManager.Multiplayer())
		{
			return true;
		}
		PlayerAvatar val = SemiFunc.PlayerGetFromName(playerName);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		if ((Object)(object)val.photonView == (Object)null)
		{
			return false;
		}
		if (val.photonView.Owner == PhotonNetwork.MasterClient)
		{
			return true;
		}
		return Plugin.HostIsDeadOrDisabled();
	}
}
[HarmonyPatch(typeof(TruckScreenText), "GotoNextLevel")]
public static class Patch_GotoNextLevel
{
	private static bool Prefix()
	{
		if (!GameManager.Multiplayer())
		{
			return true;
		}
		if (PhotonNetwork.IsMasterClient)
		{
			return true;
		}
		return Plugin.HostIsDeadOrDisabled();
	}
}