CatFlag.dll

Decompiled 14 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CatFlag")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CatFlag")]
[assembly: AssemblyTitle("CatFlag")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CatFlag
{
	[BepInPlugin("com.pigpooteamelf.catflag", "CatFlag", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigEntry<float> _imageSize;

		private ConfigEntry<bool> _flipHorizontally;

		private ConfigEntry<bool> _includeGolfCartFlags;

		private Texture2D _head;

		private readonly Dictionary<Texture, Texture2D> _done = new Dictionary<Texture, Texture2D>();

		private float _nextCheck;

		private void Awake()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_imageSize = ((BaseUnityPlugin)this).Config.Bind<float>("Flag", "ImageSize", 0.8f, new ConfigDescription("How much of the flag the picture covers (0.1 to 1).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1f), Array.Empty<object>()));
			_flipHorizontally = ((BaseUnityPlugin)this).Config.Bind<bool>("Flag", "FlipHorizontally", false, "Turn on if the picture appears back to front.");
			_includeGolfCartFlags = ((BaseUnityPlugin)this).Config.Bind<bool>("Flag", "IncludeGolfCartFlags", true, "Also put the picture on golf cart flags.");
			string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "CatHead.png");
			if (!File.Exists(text))
			{
				Log.LogError((object)("CatHead.png not found at " + text));
				return;
			}
			_head = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(_head, File.ReadAllBytes(text)))
			{
				Log.LogError((object)"Couldn't read CatHead.png");
				_head = null;
			}
			else
			{
				Log.LogInfo((object)$"Loaded flag picture ({((Texture)_head).width}x{((Texture)_head).height}).");
			}
		}

		private void Update()
		{
			if ((Object)(object)_head == (Object)null || Time.unscaledTime < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.unscaledTime + 2f;
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				if ((Object)(object)val == (Object)null || !IsFlagMaterial(((Object)val).name))
				{
					continue;
				}
				string[] texturePropertyNames = val.GetTexturePropertyNames();
				foreach (string text in texturePropertyNames)
				{
					Texture texture = val.GetTexture(text);
					if ((Object)(object)texture == (Object)null || (!((Object)texture).name.StartsWith("Flag_albe", StringComparison.OrdinalIgnoreCase) && !_done.ContainsValue((Texture2D)(object)((texture is Texture2D) ? texture : null))) || _done.ContainsValue((Texture2D)(object)((texture is Texture2D) ? texture : null)))
					{
						continue;
					}
					if (!_done.TryGetValue(texture, out var value))
					{
						value = Compose(texture);
						if ((Object)(object)value == (Object)null)
						{
							continue;
						}
						_done[texture] = value;
						Log.LogInfo((object)$"Made cat flag from '{((Object)texture).name}' ({texture.width}x{texture.height}).");
					}
					val.SetTexture(text, (Texture)(object)value);
					Log.LogInfo((object)("Cat flag applied to material '" + ((Object)val).name + "' (" + text + ")."));
				}
			}
		}

		private bool IsFlagMaterial(string name)
		{
			if (name.IndexOf("pole", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (name.StartsWith("Flag", StringComparison.OrdinalIgnoreCase))
			{
				return true;
			}
			if (_includeGolfCartFlags.Value)
			{
				return name.IndexOf("Cart_Flag", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return false;
		}

		private Texture2D Compose(Texture original)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			int width = original.width;
			int height = original.height;
			RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)2);
			RenderTexture active = RenderTexture.active;
			Graphics.Blit(original, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, true);
			val.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			Color32[] pixels = val.GetPixels32();
			int num = Mathf.RoundToInt((float)Mathf.Min(width, height) * _imageSize.Value);
			int num2 = (width - num) / 2;
			int num3 = (height - num) / 2;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					float num4 = ((float)j + 0.5f) / (float)num;
					float num5 = ((float)i + 0.5f) / (float)num;
					if (_flipHorizontally.Value)
					{
						num4 = 1f - num4;
					}
					Color pixelBilinear = _head.GetPixelBilinear(num4, num5);
					if (!(pixelBilinear.a <= 0.01f))
					{
						int num6 = (num3 + i) * width + (num2 + j);
						Color val2 = Color32.op_Implicit(pixels[num6]);
						Color val3 = Color.Lerp(val2, pixelBilinear, pixelBilinear.a);
						val3.a = val2.a;
						pixels[num6] = Color32.op_Implicit(val3);
					}
				}
			}
			val.SetPixels32(pixels);
			((Object)val).name = "CatFlag";
			val.Apply(true, false);
			return val;
		}
	}
}

FreeCam.dll

Decompiled 14 minutes ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FreeCam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreeCam")]
[assembly: AssemblyTitle("FreeCam")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 FreeCam
{
	[BepInPlugin("com.pigpooteamelf.freecam", "FreeCam", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private ConfigEntry<Key> toggleKey;

		private ConfigEntry<float> speed;

		private ConfigEntry<float> lookSpeed;

		private bool active;

		private Vector3 pos;

		private float yaw;

		private float pitch;

		private float speedMul = 1f;

		private void Awake()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			toggleKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "ToggleKey", (Key)17, "Key that switches free camera on and off.");
			speed = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "Speed", 15f, "Flying speed in metres per second (Shift = 4x).");
			lookSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Controls", "MouseSensitivity", 0.12f, "Degrees turned per pixel of mouse movement.");
			RenderPipelineManager.beginCameraRendering += OnBeginCamera;
			Log.LogInfo((object)$"FreeCam ready: press {toggleKey.Value}.");
		}

		private void OnDestroy()
		{
			RenderPipelineManager.beginCameraRendering -= OnBeginCamera;
		}

		private void Update()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: 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)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			Keyboard current = Keyboard.current;
			if (current == null)
			{
				return;
			}
			if (((ButtonControl)current[toggleKey.Value]).wasPressedThisFrame && !IsTyping())
			{
				if (active)
				{
					Stop();
				}
				else
				{
					Start_();
				}
			}
			if (!active)
			{
				return;
			}
			if ((Object)(object)Camera.main == (Object)null)
			{
				Stop();
				return;
			}
			Mouse current2 = Mouse.current;
			if (current2 != null)
			{
				Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current2).delta).ReadValue();
				yaw += val.x * lookSpeed.Value;
				pitch = Mathf.Clamp(pitch - val.y * lookSpeed.Value, -89f, 89f);
				float y = ((InputControl<Vector2>)(object)current2.scroll).ReadValue().y;
				if (y != 0f)
				{
					speedMul = Mathf.Clamp(speedMul * ((y > 0f) ? 1.2f : (5f / 6f)), 0.05f, 20f);
				}
			}
			Quaternion val2 = Quaternion.Euler(pitch, yaw, 0f);
			Vector3 val3 = Vector3.zero;
			if (((ButtonControl)current.wKey).isPressed)
			{
				val3 += val2 * Vector3.forward;
			}
			if (((ButtonControl)current.sKey).isPressed)
			{
				val3 -= val2 * Vector3.forward;
			}
			if (((ButtonControl)current.dKey).isPressed)
			{
				val3 += val2 * Vector3.right;
			}
			if (((ButtonControl)current.aKey).isPressed)
			{
				val3 -= val2 * Vector3.right;
			}
			if (((ButtonControl)current.spaceKey).isPressed || ((ButtonControl)current.eKey).isPressed)
			{
				val3 += Vector3.up;
			}
			if (((ButtonControl)current.leftCtrlKey).isPressed || ((ButtonControl)current.qKey).isPressed)
			{
				val3 -= Vector3.up;
			}
			float num = speed.Value * speedMul * (((ButtonControl)current.leftShiftKey).isPressed ? 4f : 1f);
			pos += ((Vector3)(ref val3)).normalized * num * Time.unscaledDeltaTime;
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
		}

		private void OnBeginCamera(ScriptableRenderContext ctx, Camera cam)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (active && !((Object)(object)cam != (Object)(object)Camera.main))
			{
				((Component)cam).transform.SetPositionAndRotation(pos, Quaternion.Euler(pitch, yaw, 0f));
			}
		}

		private void Start_()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				pos = ((Component)main).transform.position;
				Vector3 eulerAngles = ((Component)main).transform.eulerAngles;
				yaw = eulerAngles.y;
				pitch = ((eulerAngles.x > 180f) ? (eulerAngles.x - 360f) : eulerAngles.x);
				active = true;
				SetGameInput(on: false);
				Log.LogInfo((object)"Free camera on.");
			}
		}

		private void Stop()
		{
			if (active)
			{
				active = false;
				SetGameInput(on: true);
				Log.LogInfo((object)"Free camera off.");
			}
		}

		private static void SetGameInput(bool on)
		{
			try
			{
				if (on)
				{
					InputManager.DisableMode((InputMode)4096);
				}
				else
				{
					InputManager.EnableMode((InputMode)4096);
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Couldn't switch game input: " + ex.Message));
			}
		}

		private static bool IsTyping()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			try
			{
				return (InputManager.CurrentMode & 0x3E0) > 0;
			}
			catch
			{
				return false;
			}
		}
	}
}

AreYaAvinALaff.dll

Decompiled 14 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FMOD;
using FMODUnity;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AreYaAvinALaff")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AreYaAvinALaff")]
[assembly: AssemblyTitle("AreYaAvinALaff")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 AreYaAvinALaff
{
	[BepInPlugin("com.pigpooteamelf.areyaavinalaff", "AreYaAvinALaff", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.pigpooteamelf.areyaavinalaff";

		public const string PluginName = "AreYaAvinALaff";

		public const string PluginVersion = "1.0.1";

		internal static ManualLogSource Log;

		private static string _soundPath;

		private static float _lastPlayTime = -10f;

		private static ConfigEntry<string> _targetClass;

		private static ConfigEntry<string> _targetMethod;

		private static ConfigEntry<float> _volume;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			_targetClass = ((BaseUnityPlugin)this).Config.Bind<string>("Hook", "TargetClass", "Hittable", "Full name of the game class whose method runs when you hit the ball.");
			_targetMethod = ((BaseUnityPlugin)this).Config.Bind<string>("Hook", "TargetMethod", "HitWithGolfSwing", "Name of the method in TargetClass that runs when you hit the ball.");
			_volume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Volume", 1f, new ConfigDescription("Hit sound volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			_soundPath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "HitSound.wav");
			if (File.Exists(_soundPath))
			{
				Log.LogInfo((object)("Found hit sound at " + _soundPath));
			}
			else
			{
				Log.LogError((object)("HitSound.wav not found next to the mod at: " + _soundPath));
			}
			_harmony = new Harmony("com.pigpooteamelf.areyaavinalaff");
			PatchHitMethod();
		}

		public static void PlayHitSound()
		{
			if (!(Time.unscaledTime - _lastPlayTime < 0.15f))
			{
				_lastPlayTime = Time.unscaledTime;
				FmodPlayer.Play(_soundPath, _volume.Value);
			}
		}

		private void PatchHitMethod()
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(_targetClass.Value) || string.IsNullOrWhiteSpace(_targetMethod.Value))
			{
				Log.LogWarning((object)"No hit method set yet. Fill in [Hook] TargetClass and TargetMethod in the config file.");
				return;
			}
			Type type = AccessTools.TypeByName(_targetClass.Value.Trim());
			if (type == null)
			{
				Log.LogError((object)("Class '" + _targetClass.Value + "' not found in the game."));
				return;
			}
			string name = _targetMethod.Value.Trim();
			List<MethodInfo> list = (from m in AccessTools.GetDeclaredMethods(type)
				where m.Name == name && !m.IsAbstract
				select m).ToList();
			if (list.Count == 0)
			{
				Log.LogError((object)("Method '" + name + "' not found in class '" + type.FullName + "'."));
				return;
			}
			foreach (MethodInfo item in list)
			{
				_harmony.Patch((MethodBase)item, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "PlayHitSound", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)("Hit sound hooked to " + type.FullName + "." + item.Name));
			}
		}
	}
	internal static class FmodPlayer
	{
		private static Sound _sound;

		private static bool _loaded;

		private static bool _failed;

		public static void Play(string path, float volume)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (_failed)
			{
				return;
			}
			try
			{
				System coreSystem = RuntimeManager.CoreSystem;
				if (!_loaded)
				{
					RESULT val = ((System)(ref coreSystem)).createSound(path, (MODE)256, ref _sound);
					if ((int)val != 0)
					{
						Plugin.Log.LogError((object)$"FMOD couldn't load the hit sound: {val}");
						_failed = true;
						return;
					}
					_loaded = true;
					uint num = default(uint);
					((Sound)(ref _sound)).getLength(ref num, (TIMEUNIT)1);
					Plugin.Log.LogInfo((object)$"Hit sound loaded into FMOD ({(float)num / 1000f:0.00}s).");
				}
				ChannelGroup val2 = default(ChannelGroup);
				((System)(ref coreSystem)).getMasterChannelGroup(ref val2);
				Channel val4 = default(Channel);
				RESULT val3 = ((System)(ref coreSystem)).playSound(_sound, val2, true, ref val4);
				if ((int)val3 != 0)
				{
					Plugin.Log.LogError((object)$"FMOD couldn't play the hit sound: {val3}");
					return;
				}
				((Channel)(ref val4)).setVolume(volume);
				((Channel)(ref val4)).setPaused(false);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Hit sound error: {arg}");
				_failed = true;
			}
		}
	}
}

CatTakeover.dll

Decompiled 14 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FMOD;
using FMODUnity;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CatTakeover")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CatTakeover")]
[assembly: AssemblyTitle("CatTakeover")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 CatTakeover
{
	[BepInPlugin("com.pigpooteamelf.cattakeover", "CatTakeover", "1.2.2")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static Plugin Instance;

		internal static ConfigEntry<float> Volume;

		internal static ConfigEntry<float> PopupSeconds;

		internal static ConfigEntry<float> PopupSize;

		internal static ConfigEntry<bool> ReplaceScoreSound;

		internal static ConfigEntry<bool> ShowPopup;

		internal static ConfigEntry<bool> ReplaceFlash;

		internal static ConfigEntry<string> TvImage;

		internal static string Dir;

		private Overlay overlay;

		private void Awake()
		{
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Dir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			ReplaceScoreSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Holed", "ReplaceSound", true, "Play PuttSound.mp3 instead of the game's sound when a ball drops into the cup.");
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Holed", "Volume", 1f, "Volume of PuttSound.mp3 (0 to 1).");
			ShowPopup = ((BaseUnityPlugin)this).Config.Bind<bool>("Holed", "ShowPicture", true, "Pop PuttCat.jpg up in the middle of the screen when a ball drops into the cup.");
			PopupSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Holed", "PictureSeconds", 2.5f, "How long the picture stays up.");
			PopupSize = ((BaseUnityPlugin)this).Config.Bind<float>("Holed", "PictureSize", 0.35f, "Picture height as a share of the screen height (0.35 = about a third).");
			ReplaceFlash = ((BaseUnityPlugin)this).Config.Bind<bool>("Flash", "ReplaceCameraFlash", true, "Show FlashCat.jpg instead of the camera flash's white-out.");
			TvImage = ((BaseUnityPlugin)this).Config.Bind<string>("TV", "ImageOnTV", "", "Picture shown on the driving range TV instead of the camera footage. A PNG, JPG or GIF (GIFs play). Easiest: name it TV (e.g. TV.gif) and put it in this mod's folder, leaving this empty. Or here: either a full path, or just the file name of a picture put in this mod's folder (BepInEx/plugins/CatTakeover). Empty and no TV picture in the folder = normal camera footage. Only your own game shows it.");
			TvImage.SettingChanged += delegate
			{
				TvScreen.Reload();
			};
			overlay = Overlay.Create();
			new Harmony("com.pigpooteamelf.cattakeover").PatchAll();
			Log.LogInfo((object)"CatTakeover ready.");
		}

		internal static void OnHoled()
		{
			if (ReplaceScoreSound.Value)
			{
				FmodPlayer.Play(Path.Combine(Dir, "PuttSound.mp3"), Mathf.Clamp01(Volume.Value));
			}
			if (ShowPopup.Value)
			{
				Overlay.Instance?.ShowPopup(PopupSeconds.Value);
			}
		}
	}
	internal class Overlay : MonoBehaviour
	{
		internal static Overlay Instance;

		private RawImage popup;

		private RawImage flashBack;

		private RawImage flashCat;

		private float popupStart = -100f;

		private float popupLength;

		internal bool flashOn;

		internal float flashIntensity;

		internal static Overlay Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0010: 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)
			GameObject val = new GameObject("CatTakeover overlay");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32000;
			Instance = val.AddComponent<Overlay>();
			Instance.Build();
			return Instance;
		}

		private void Build()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			flashBack = MakeImage("Flash backdrop", null);
			((Graphic)flashBack).color = new Color(0f, 0f, 0f, 0f);
			Stretch(((Graphic)flashBack).rectTransform);
			flashCat = MakeImage("Flash cat", LoadTexture("FlashCat.jpg"));
			Stretch(((Graphic)flashCat).rectTransform);
			popup = MakeImage("Holed cat", LoadTexture("PuttCat.jpg"));
			Centre(((Graphic)popup).rectTransform);
			SetAlpha((Graphic)(object)flashCat, 0f);
			SetAlpha((Graphic)(object)popup, 0f);
		}

		private RawImage MakeImage(string name, Texture2D tex)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(((Component)this).transform, false);
			RawImage val2 = val.AddComponent<RawImage>();
			((Graphic)val2).raycastTarget = false;
			if ((Object)(object)tex != (Object)null)
			{
				val2.texture = (Texture)(object)tex;
			}
			return val2;
		}

		private static void Stretch(RectTransform r)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_001d: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			r.anchorMin = Vector2.zero;
			r.anchorMax = Vector2.one;
			Vector2 offsetMin = (r.offsetMax = Vector2.zero);
			r.offsetMin = offsetMin;
		}

		private static void Centre(RectTransform r)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0.5f);
			r.pivot = val;
			Vector2 anchorMin = (r.anchorMax = val);
			r.anchorMin = anchorMin;
			r.anchoredPosition = Vector2.zero;
		}

		private static void SetAlpha(Graphic g, float a)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Color color = g.color;
			color.a = a;
			g.color = color;
			((Behaviour)g).enabled = a > 0.001f;
		}

		private static Texture2D LoadTexture(string file)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			string text = Path.Combine(Plugin.Dir, file);
			if (!File.Exists(text))
			{
				Plugin.Log.LogError((object)("Missing " + text));
				return null;
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(text)))
			{
				Plugin.Log.LogError((object)("Couldn't read " + file));
				return null;
			}
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		private static void SizeToHeight(RawImage img, float height)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Texture texture = img.texture;
			if (!((Object)(object)texture == (Object)null))
			{
				float num = height * (float)texture.width / (float)texture.height;
				if (num > (float)Screen.width * 0.95f)
				{
					num = (float)Screen.width * 0.95f;
					height = num * (float)texture.height / (float)texture.width;
				}
				((Graphic)img).rectTransform.sizeDelta = new Vector2(num, height);
			}
		}

		private static void Cover(RawImage img)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Texture texture = img.texture;
			if (!((Object)(object)texture == (Object)null) && Screen.height != 0)
			{
				float num = (float)Screen.width / (float)Screen.height;
				float num2 = (float)texture.width / (float)texture.height;
				img.uvRect = ((num > num2) ? new Rect(0f, (1f - num2 / num) / 2f, 1f, num2 / num) : new Rect((1f - num / num2) / 2f, 0f, num / num2, 1f));
			}
		}

		internal void ShowPopup(float seconds)
		{
			popupStart = Time.unscaledTime;
			popupLength = Mathf.Max(0.5f, seconds);
		}

		private void Update()
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			TvScreen.Tick();
			float num = Time.unscaledTime - popupStart;
			if (num >= 0f && num < popupLength)
			{
				float num2 = ((num < 0.25f) ? (Mathf.Sin(num / 0.25f * MathF.PI * 0.5f) * 1.12f) : Mathf.Lerp(1.12f, 1f, Mathf.Clamp01((num - 0.25f) / 0.15f)));
				float a = Mathf.Clamp01((popupLength - num) / 0.4f);
				SizeToHeight(popup, (float)Screen.height * Mathf.Clamp(Plugin.PopupSize.Value, 0.05f, 1f));
				((Transform)((Graphic)popup).rectTransform).localScale = Vector3.one * num2;
				SetAlpha((Graphic)(object)popup, a);
			}
			else if (((Behaviour)popup).enabled)
			{
				SetAlpha((Graphic)(object)popup, 0f);
			}
			float num3 = ((flashOn && Plugin.ReplaceFlash.Value) ? Mathf.Clamp01(flashIntensity) : 0f);
			if (num3 > 0.001f)
			{
				Cover(flashCat);
			}
			SetAlpha((Graphic)(object)flashCat, num3);
			SetAlpha((Graphic)(object)flashBack, 0f);
		}
	}
	[HarmonyPatch(typeof(GolfHole), "PlayScoredSoundInternal")]
	internal static class ScoredSoundPatch
	{
		private static bool Prefix()
		{
			try
			{
				Plugin.OnHoled();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Holed effect failed: {arg}");
				return true;
			}
			return !Plugin.ReplaceScoreSound.Value;
		}
	}
	[HarmonyPatch(typeof(FlashFrameController), "SetFlashFrameEnabled")]
	internal static class FlashEnabledPatch
	{
		private static void Prefix(bool __0)
		{
			if ((Object)(object)Overlay.Instance != (Object)null)
			{
				Overlay.Instance.flashOn = __0;
			}
		}
	}
	[HarmonyPatch(typeof(FlashFrameController), "SetFlashFrameIntensity")]
	internal static class FlashIntensityPatch
	{
		private static void Prefix(ref float __0)
		{
			if ((Object)(object)Overlay.Instance != (Object)null)
			{
				Overlay.Instance.flashIntensity = __0;
			}
			if (Plugin.ReplaceFlash.Value)
			{
				__0 = 0f;
			}
		}
	}
	internal static class FmodPlayer
	{
		private static Sound sound;

		private static bool loaded;

		private static bool failed;

		public static void Play(string path, float volume)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (failed)
			{
				return;
			}
			try
			{
				System coreSystem = RuntimeManager.CoreSystem;
				if (!loaded)
				{
					RESULT val = ((System)(ref coreSystem)).createSound(path, (MODE)256, ref sound);
					if ((int)val != 0)
					{
						Plugin.Log.LogError((object)$"FMOD couldn't load {path}: {val}");
						failed = true;
						return;
					}
					loaded = true;
					uint num = default(uint);
					((Sound)(ref sound)).getLength(ref num, (TIMEUNIT)1);
					Plugin.Log.LogInfo((object)$"Holed sound loaded ({(float)num / 1000f:0.00}s).");
				}
				ChannelGroup val2 = default(ChannelGroup);
				((System)(ref coreSystem)).getMasterChannelGroup(ref val2);
				Channel val3 = default(Channel);
				if ((int)((System)(ref coreSystem)).playSound(sound, val2, true, ref val3) == 0)
				{
					((Channel)(ref val3)).setVolume(volume);
					((Channel)(ref val3)).setPaused(false);
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Sound error: {arg}");
				failed = true;
			}
		}
	}
	internal static class TvScreen
	{
		private static Texture2D tex;

		private static bool loaded;

		private static Renderer appliedTo;

		private static List<Color32[]> frames;

		private static List<float> delays;

		private static int frame;

		private static float timer;

		internal static Texture2D Picture
		{
			get
			{
				//IL_0220: Unknown result type (might be due to invalid IL or missing references)
				//IL_0226: Expected O, but got Unknown
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Unknown result type (might be due to invalid IL or missing references)
				//IL_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Expected O, but got Unknown
				if (!loaded)
				{
					loaded = true;
					string text = (Plugin.TvImage.Value ?? "").Trim().Trim('"');
					string text2;
					if (text.Length == 0)
					{
						text2 = Directory.GetFiles(Plugin.Dir).FirstOrDefault((string f) => Path.GetFileNameWithoutExtension(f).Equals("TV", StringComparison.OrdinalIgnoreCase) && new string[4] { ".gif", ".png", ".jpg", ".jpeg" }.Contains(Path.GetExtension(f).ToLowerInvariant()));
						if (text2 == null)
						{
							return tex = null;
						}
					}
					else
					{
						text2 = (Path.IsPathRooted(text) ? text : Path.Combine(Plugin.Dir, text));
					}
					if (!File.Exists(text2))
					{
						Plugin.Log.LogWarning((object)("TV picture not found: " + text2));
						return tex = null;
					}
					byte[] array = File.ReadAllBytes(text2);
					frames = null;
					delays = null;
					frame = 0;
					timer = 0f;
					if (array.Length > 6 && array[0] == 71 && array[1] == 73 && array[2] == 70)
					{
						Stopwatch stopwatch = Stopwatch.StartNew();
						try
						{
							GifDecoder.Gif gif = GifDecoder.Decode(array);
							frames = gif.Frames;
							delays = gif.Delays;
							Texture2D val = new Texture2D(gif.Width, gif.Height, (TextureFormat)4, false);
							val.SetPixels32(frames[0]);
							val.Apply(false);
							((Texture)val).wrapMode = (TextureWrapMode)1;
							((Object)val).hideFlags = (HideFlags)32;
							tex = val;
							Plugin.Log.LogInfo((object)$"TV GIF loaded: {text2} ({gif.Width}x{gif.Height}, {frames.Count} frames, {delays.Sum():0.0}s, read in {stopwatch.ElapsedMilliseconds} ms)");
							if (frames.Count < 2)
							{
								frames = null;
							}
							return tex;
						}
						catch (Exception ex)
						{
							Plugin.Log.LogWarning((object)("Couldn't read the GIF " + text2 + ": " + ex.Message));
							return tex = null;
						}
					}
					Texture2D val2 = new Texture2D(2, 2, (TextureFormat)4, true);
					if (!ImageConversion.LoadImage(val2, array))
					{
						Plugin.Log.LogWarning((object)("TV picture isn't a PNG, JPG or GIF: " + text2));
						return tex = null;
					}
					((Texture)val2).wrapMode = (TextureWrapMode)1;
					((Object)val2).hideFlags = (HideFlags)32;
					tex = val2;
					Plugin.Log.LogInfo((object)$"TV picture loaded: {text2} ({((Texture)val2).width}x{((Texture)val2).height})");
				}
				return tex;
			}
		}

		internal static void Tick()
		{
			if (frames == null || (Object)(object)tex == (Object)null || (Object)(object)appliedTo == (Object)null)
			{
				return;
			}
			timer += Time.unscaledDeltaTime;
			if (!(timer < delays[frame]))
			{
				int num = 0;
				while (timer >= delays[frame] && num++ < frames.Count)
				{
					timer -= delays[frame];
					frame = (frame + 1) % frames.Count;
				}
				if (timer > 1f)
				{
					timer = 0f;
				}
				tex.SetPixels32(frames[frame]);
				tex.Apply(false);
			}
		}

		internal static void Reload()
		{
			loaded = false;
			appliedTo = null;
		}

		internal static void Apply(Renderer screen)
		{
			if ((Object)(object)screen == (Object)null || (Object)(object)screen == (Object)(object)appliedTo || (Object)(object)Picture == (Object)null)
			{
				return;
			}
			appliedTo = screen;
			int num = 0;
			Material[] materials = screen.materials;
			foreach (Material val in materials)
			{
				int[] texturePropertyNameIDs = val.GetTexturePropertyNameIDs();
				foreach (int num2 in texturePropertyNameIDs)
				{
					if (val.GetTexture(num2) is RenderTexture)
					{
						val.SetTexture(num2, (Texture)(object)Picture);
						num++;
					}
				}
				if (num == 0 && val.HasProperty("_BaseMap"))
				{
					val.SetTexture("_BaseMap", (Texture)(object)Picture);
					num++;
				}
				if (num == 0 && val.HasProperty("_MainTex"))
				{
					val.SetTexture("_MainTex", (Texture)(object)Picture);
					num++;
				}
			}
			Plugin.Log.LogInfo((object)($"TV picture put on '{((Object)screen).name}' ({num} texture slot(s): " + string.Join(", ", from x in screen.sharedMaterials
				where (Object)(object)x != (Object)null
				select ((Object)x).name + " [" + ((Object)x.shader).name + "]") + ")."));
		}
	}
	[HarmonyPatch(typeof(DrivingRangeStaticCameraManager), "OnLateBUpdate")]
	internal static class TvScreenPatch
	{
		private static void Postfix(DrivingRangeStaticCameraManager __instance)
		{
			try
			{
				TvScreen.Apply(Traverse.Create((object)__instance).Field("screenRenderer").GetValue<Renderer>());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("TV picture failed: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(DrivingRangeStaticCamera), "SetCameraRendering")]
	internal static class TvCameraOffPatch
	{
		private static void Prefix(ref bool __0)
		{
			if ((Object)(object)TvScreen.Picture != (Object)null)
			{
				__0 = false;
			}
		}
	}
	internal static class GifDecoder
	{
		internal class Gif
		{
			public int Width;

			public int Height;

			public List<Color32[]> Frames = new List<Color32[]>();

			public List<float> Delays = new List<float>();
		}

		private const long MaxBytes = 419430400L;

		internal static Gif Decode(byte[] b)
		{
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			int p = 6;
			Gif gif = new Gif
			{
				Width = U(),
				Height = U()
			};
			int width = gif.Width;
			int height = gif.Height;
			if (width <= 0 || height <= 0)
			{
				throw new Exception("bad size");
			}
			int num = b[p++];
			p += 2;
			Color32[] array = null;
			if ((num & 0x80) != 0)
			{
				array = ReadTable(b, ref p, 2 << (num & 7));
			}
			Color32[] array2 = (Color32[])(object)new Color32[width * height];
			int num2 = 0;
			int num3 = -1;
			float item = 0.1f;
			while (p < b.Length)
			{
				switch (b[p++])
				{
				case 33:
					if (b[p++] == 249 && b[p] >= 4)
					{
						byte num14 = b[p + 1];
						num2 = (num14 >> 2) & 7;
						int num15 = b[p + 2] | (b[p + 3] << 8);
						item = ((num15 < 2) ? 0.1f : ((float)num15 / 100f));
						num3 = (((num14 & 1) != 0) ? b[p + 4] : (-1));
					}
					SkipSubBlocks(b, ref p);
					continue;
				case 44:
				{
					int num4 = U();
					int num5 = U();
					int num6 = U();
					int num7 = U();
					int num8 = b[p++];
					Color32[] array3 = (((num8 & 0x80) != 0) ? ReadTable(b, ref p, 2 << (num8 & 7)) : array);
					bool flag = (num8 & 0x40) != 0;
					int minCode = b[p++];
					MemoryStream memoryStream = new MemoryStream();
					int num9;
					for (; p < b.Length; p += num9)
					{
						num9 = b[p++];
						if (num9 == 0)
						{
							break;
						}
						memoryStream.Write(b, p, num9);
					}
					byte[] array4 = Lzw(memoryStream.ToArray(), minCode, num6 * num7);
					Color32[] array5 = ((num2 == 3) ? ((Color32[])array2.Clone()) : null);
					for (int i = 0; i < num7; i++)
					{
						int num10 = (flag ? InterlacedRow(i, num7) : i);
						int num11 = num5 + num10;
						if (num11 < 0 || num11 >= height)
						{
							continue;
						}
						for (int j = 0; j < num6; j++)
						{
							int num12 = num4 + j;
							int num13 = array4[i * num6 + j];
							if (num12 >= 0 && num12 < width && num13 != num3 && array3 != null && num13 < array3.Length)
							{
								array2[num11 * width + num12] = array3[num13];
							}
						}
					}
					Color32[] array6 = (Color32[])(object)new Color32[width * height];
					for (int k = 0; k < height; k++)
					{
						Array.Copy(array2, k * width, array6, (height - 1 - k) * width, width);
					}
					gif.Frames.Add(array6);
					gif.Delays.Add(item);
					if ((long)gif.Frames.Count * (long)width * height * 4 > 419430400)
					{
						break;
					}
					switch (num2)
					{
					case 2:
					{
						for (int l = Math.Max(0, num5); l < Math.Min(height, num5 + num7); l++)
						{
							for (int m = Math.Max(0, num4); m < Math.Min(width, num4 + num6); m++)
							{
								array2[l * width + m] = new Color32((byte)0, (byte)0, (byte)0, (byte)0);
							}
						}
						break;
					}
					case 3:
						array2 = array5;
						break;
					}
					num2 = 0;
					num3 = -1;
					item = 0.1f;
					continue;
				}
				}
				break;
			}
			if (gif.Frames.Count == 0)
			{
				throw new Exception("no frames");
			}
			return gif;
			int U()
			{
				int result = b[p] | (b[p + 1] << 8);
				p += 2;
				return result;
			}
		}

		private static Color32[] ReadTable(byte[] b, ref int p, int n)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[n];
			int num = 0;
			while (num < n)
			{
				array[num] = new Color32(b[p], b[p + 1], b[p + 2], byte.MaxValue);
				num++;
				p += 3;
			}
			return array;
		}

		private static void SkipSubBlocks(byte[] b, ref int p)
		{
			while (p < b.Length)
			{
				int num = b[p++];
				if (num != 0)
				{
					p += num;
					continue;
				}
				break;
			}
		}

		private static int InterlacedRow(int r, int h)
		{
			int[] array = new int[4] { 0, 4, 2, 1 };
			int[] array2 = new int[4] { 8, 8, 4, 2 };
			for (int i = 0; i < 4; i++)
			{
				int num = (h - array[i] + array2[i] - 1) / array2[i];
				if (num < 0)
				{
					num = 0;
				}
				if (r < num)
				{
					return array[i] + r * array2[i];
				}
				r -= num;
			}
			return 0;
		}

		private static byte[] Lzw(byte[] data, int minCode, int npix)
		{
			byte[] array = new byte[npix];
			short[] array2 = new short[4096];
			byte[] array3 = new byte[4096];
			byte[] array4 = new byte[4097];
			int num = 1 << minCode;
			int num2 = num + 1;
			int num3 = num + 2;
			int num4 = -1;
			int num5 = minCode + 1;
			int num6 = (1 << num5) - 1;
			for (int i = 0; i < num; i++)
			{
				array3[i] = (byte)i;
			}
			int num7 = 0;
			int num8 = 0;
			int num9 = 0;
			int num10 = 0;
			int num11 = 0;
			int num12 = 0;
			while (num11 < npix)
			{
				if (num10 == 0)
				{
					if (num8 < num5)
					{
						if (num12 >= data.Length)
						{
							break;
						}
						num7 |= data[num12++] << num8;
						num8 += 8;
						continue;
					}
					int num13 = num7 & num6;
					num7 >>= num5;
					num8 -= num5;
					if (num13 == num2 || num13 > num3)
					{
						break;
					}
					if (num13 == num)
					{
						num5 = minCode + 1;
						num6 = (1 << num5) - 1;
						num3 = num + 2;
						num4 = -1;
						continue;
					}
					if (num4 == -1)
					{
						array4[num10++] = array3[num13];
						num4 = num13;
						num9 = num13;
						continue;
					}
					int num14 = num13;
					if (num13 == num3)
					{
						array4[num10++] = (byte)num9;
						num13 = num4;
					}
					while (num13 > num)
					{
						array4[num10++] = array3[num13];
						num13 = array2[num13];
					}
					num9 = array3[num13];
					array4[num10++] = (byte)num9;
					if (num3 < 4096)
					{
						array2[num3] = (short)num4;
						array3[num3] = (byte)num9;
						num3++;
						if ((num3 & num6) == 0 && num3 < 4096)
						{
							num5++;
							num6 += num3;
						}
					}
					num4 = num14;
				}
				array[num11++] = array4[--num10];
			}
			return array;
		}
	}
}