Decompiled source of EasyCustomTruckPaint v1.0.0

EasyCustomTruckPaint.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("EasyCustomTruckPaint")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("custom truck paint")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e341d6bf3483b79da9a77dede0b6886ef759cc66")]
[assembly: AssemblyProduct("EasyCustomTruckPaint")]
[assembly: AssemblyTitle("EasyCustomTruckPaint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EasyCustomTruckPaint
{
	[BepInPlugin("EasyCustomTruckPaint", "EasyCustomTruckPaint", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		public class sCosmeticAppearancePatch : HarmonyPatch
		{
			private static MethodInfo TargetMethod()
			{
				return typeof(sCosmeticAppearance).GetMethod("SetAppearance", BindingFlags.Instance | BindingFlags.Public);
			}

			private static void Postfix(sCosmeticAppearance __instance)
			{
				if (hasTexture)
				{
					MeshRenderer[] paintSurfaces = __instance.paintSurfaces;
					foreach (MeshRenderer val in paintSurfaces)
					{
						((Renderer)val).material.SetTexture(__instance.paintMapName, (Texture)(object)truckTexture);
					}
				}
			}
		}

		internal static ManualLogSource Log;

		private static string texturePath = Application.streamingAssetsPath + "/CustomTruck/truck.png";

		private static Texture2D truckTexture;

		private static bool hasTexture = false;

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin EasyCustomTruckPaint is loaded!");
			Harmony val = new Harmony("EasyCustomTruckPaint");
			val.PatchAll();
			((MonoBehaviour)this).StartCoroutine(GetTexture());
		}

		private static IEnumerator GetTexture()
		{
			if (File.Exists(texturePath))
			{
				UnityWebRequest uwr = UnityWebRequestTexture.GetTexture("file://" + texturePath);
				try
				{
					yield return uwr.SendWebRequest();
					if ((int)uwr.result != 1)
					{
						Log.LogError((object)uwr.error);
						yield break;
					}
					Texture2D texture = DownloadHandlerTexture.GetContent(uwr);
					truckTexture = texture;
					Log.LogInfo((object)"custom truck texture loaded from file :3");
					hasTexture = true;
				}
				finally
				{
					((IDisposable)uwr)?.Dispose();
				}
			}
			else
			{
				Log.LogError((object)"no custom truck texture at expected path. vanilla cosmetics will be used instead!");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "EasyCustomTruckPaint";

		public const string PLUGIN_NAME = "EasyCustomTruckPaint";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}