Decompiled source of PepeTheTaxman v1.0.5

PepeTaxman.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PepeManagerFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PepeManagerFix")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ab624f24-4109-462d-a9d9-0cedaecf24e2")]
[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")]
namespace PepeTaxman;

[BepInPlugin("rebecca.repo.pepetaxman", "Pepe Taxman Combined", "1.0.5")]
public class PepeTaxmanPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "rebecca.repo.pepetaxman";

	public const string PluginName = "Pepe Taxman Combined";

	public const string PluginVersion = "1.0.5";

	public const string NewTaxmanName = "\n\n<color=#203d15><b>PepeTaxman:</b></color>\n";

	internal static byte[] EmojisBytes;

	internal static byte[] TruckBytes;

	private void Awake()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		EmojisBytes = TryReadNextToDll("emojis.png");
		TruckBytes = TryReadNextToDll("HurryTruckPepe.png");
		new Harmony("rebecca.repo.pepetaxman").PatchAll();
		GameObject val = new GameObject("PepeTaxman_Runtime");
		Object.DontDestroyOnLoad((Object)(object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<PepeTaxmanTextureRuntime>();
	}

	private static byte[] TryReadNextToDll(string fileName)
	{
		try
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				return null;
			}
			string path = Path.Combine(directoryName, fileName);
			return File.Exists(path) ? File.ReadAllBytes(path) : null;
		}
		catch
		{
			return null;
		}
	}
}
[HarmonyPatch]
internal static class TruckScreenTextPatch
{
	private static MethodBase TargetMethod()
	{
		Type type = AccessTools.TypeByName("TruckScreenText");
		return AccessTools.Method(type, "Awake", (Type[])null, (Type[])null) ?? AccessTools.Method(type, "Start", (Type[])null, (Type[])null);
	}

	private static void Postfix(object __instance)
	{
		if (__instance != null)
		{
			AccessTools.Field(__instance.GetType(), "nicknameTaxman")?.SetValue(__instance, "\n\n<color=#203d15><b>PepeTaxman:</b></color>\n");
		}
	}
}
internal sealed class PepeTaxmanTextureRuntime : MonoBehaviour
{
	[CompilerGenerated]
	private sealed class <>c__DisplayClass14_0
	{
		public int changed;

		internal void <ApplyForAWhile>b__0(int changedOut)
		{
			changed = changedOut;
		}
	}

	[CompilerGenerated]
	private sealed class <ApplyForAWhile>d__14 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public PepeTaxmanTextureRuntime <>4__this;

		private float <endTime>5__1;

		private int <stablePasses>5__2;

		private <>c__DisplayClass14_0 <>8__3;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ApplyForAWhile>d__14(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>8__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<>2__current = null;
				<>1__state = 2;
				return true;
			case 2:
				<>1__state = -1;
				<endTime>5__1 = Time.realtimeSinceStartup + 10f;
				<stablePasses>5__2 = 0;
				break;
			case 3:
				<>1__state = -1;
				if (<>8__3.changed == 0)
				{
					<stablePasses>5__2++;
				}
				else
				{
					<stablePasses>5__2 = 0;
				}
				if (<stablePasses>5__2 >= 3)
				{
					return false;
				}
				<>2__current = (object)new WaitForSecondsRealtime(0.5f);
				<>1__state = 4;
				return true;
			case 4:
				<>1__state = -1;
				<>8__3 = null;
				break;
			}
			if (Time.realtimeSinceStartup < <endTime>5__1)
			{
				<>8__3 = new <>c__DisplayClass14_0();
				<>8__3.changed = 0;
				<>2__current = <>4__this.ApplyOnceCo(delegate(int changedOut)
				{
					<>8__3.changed = changedOut;
				});
				<>1__state = 3;
				return true;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <ApplyOnceCo>d__15 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Action<int> changedOut;

		public PepeTaxmanTextureRuntime <>4__this;

		private int <changed>5__1;

		private Material[] <mats>5__2;

		private int <m>5__3;

		private Material <mat>5__4;

		private int <propCount>5__5;

		private int <i>5__6;

		private string <propName>5__7;

		private Texture <current>5__8;

		private string <texName>5__9;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ApplyOnceCo>d__15(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<mats>5__2 = null;
			<mat>5__4 = null;
			<propName>5__7 = null;
			<current>5__8 = null;
			<texName>5__9 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Invalid comparison between Unknown and I4
			int num = <>1__state;
			if (num != 0)
			{
				if (num != 1)
				{
					return false;
				}
				<>1__state = -1;
				goto IL_03b5;
			}
			<>1__state = -1;
			<changed>5__1 = 0;
			if ((Object)(object)<>4__this._emojisSheetReplacement == (Object)null && (Object)(object)<>4__this._truckReplacement == (Object)null && (Object)(object)<>4__this._taxmanReplacement64 == (Object)null)
			{
				changedOut?.Invoke(0);
				return false;
			}
			try
			{
				<mats>5__2 = Resources.FindObjectsOfTypeAll<Material>();
			}
			catch
			{
				changedOut?.Invoke(0);
				return false;
			}
			<m>5__3 = 0;
			goto IL_03cf;
			IL_03cf:
			if (<m>5__3 < <mats>5__2.Length)
			{
				<mat>5__4 = <mats>5__2[<m>5__3];
				if ((Object)(object)<mat>5__4 == (Object)null || (Object)(object)<mat>5__4.shader == (Object)null)
				{
					goto IL_03bd;
				}
				try
				{
					<propCount>5__5 = <mat>5__4.shader.GetPropertyCount();
				}
				catch
				{
					goto IL_03bd;
				}
				for (<i>5__6 = 0; <i>5__6 < <propCount>5__5; <i>5__6++)
				{
					if ((int)<mat>5__4.shader.GetPropertyType(<i>5__6) != 4)
					{
						continue;
					}
					<propName>5__7 = <mat>5__4.shader.GetPropertyName(<i>5__6);
					try
					{
						<current>5__8 = <mat>5__4.GetTexture(<propName>5__7);
					}
					catch
					{
						continue;
					}
					if (!((Object)(object)<current>5__8 == (Object)null))
					{
						<texName>5__9 = ((Object)<current>5__8).name ?? "";
						if ((Object)(object)<>4__this._taxmanReplacement64 != (Object)null && <texName>5__9.Equals("taxman_grossup", StringComparison.OrdinalIgnoreCase) && (Object)(object)<current>5__8 != (Object)(object)<>4__this._taxmanReplacement64)
						{
							<mat>5__4.SetTexture(<propName>5__7, (Texture)(object)<>4__this._taxmanReplacement64);
							<changed>5__1++;
						}
						else if ((Object)(object)<>4__this._emojisSheetReplacement != (Object)null && (<texName>5__9.Equals("emojis", StringComparison.OrdinalIgnoreCase) || <texName>5__9.Equals("emojis extraction point", StringComparison.OrdinalIgnoreCase)) && (Object)(object)<current>5__8 != (Object)(object)<>4__this._emojisSheetReplacement)
						{
							<mat>5__4.SetTexture(<propName>5__7, (Texture)(object)<>4__this._emojisSheetReplacement);
							<changed>5__1++;
						}
						else if ((Object)(object)<>4__this._truckReplacement != (Object)null && <texName>5__9.IndexOf("truck interior", StringComparison.OrdinalIgnoreCase) >= 0 && <texName>5__9.IndexOf("DefaultMaterial_Emissive", StringComparison.OrdinalIgnoreCase) >= 0 && (Object)(object)<current>5__8 != (Object)(object)<>4__this._truckReplacement)
						{
							<mat>5__4.SetTexture(<propName>5__7, (Texture)(object)<>4__this._truckReplacement);
							<changed>5__1++;
						}
						else
						{
							<propName>5__7 = null;
							<current>5__8 = null;
							<texName>5__9 = null;
						}
					}
				}
				if (<m>5__3 % 80 == 0)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				goto IL_03b5;
			}
			changedOut?.Invoke(<changed>5__1);
			return false;
			IL_03b5:
			<mat>5__4 = null;
			goto IL_03bd;
			IL_03bd:
			<m>5__3++;
			goto IL_03cf;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private const int CellSize = 64;

	private const int TaxmanTileCol = 6;

	private const int TaxmanTileRow = 4;

	private const int MaterialsPerFrame = 80;

	private const float RetryWindowSeconds = 10f;

	private const float RetryIntervalSeconds = 0.5f;

	private Texture2D _emojisSheetReplacement;

	private Texture2D _taxmanReplacement64;

	private Texture2D _truckReplacement;

	private Coroutine _retryRoutine;

	private void Awake()
	{
		BuildReplacementTextures();
		SceneManager.sceneLoaded += delegate
		{
			RestartRetryWindow();
		};
		SceneManager.activeSceneChanged += delegate
		{
			RestartRetryWindow();
		};
		RestartRetryWindow();
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= delegate
		{
			RestartRetryWindow();
		};
		SceneManager.activeSceneChanged -= delegate
		{
			RestartRetryWindow();
		};
	}

	private void RestartRetryWindow()
	{
		if (_retryRoutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_retryRoutine);
		}
		_retryRoutine = ((MonoBehaviour)this).StartCoroutine(ApplyForAWhile());
	}

	private void BuildReplacementTextures()
	{
		//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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		if (PepeTaxmanPlugin.EmojisBytes != null)
		{
			_emojisSheetReplacement = new Texture2D(2, 2, (TextureFormat)4, false, false)
			{
				name = "emojis_modded_sheet",
				filterMode = (FilterMode)0
			};
			if (ImageConversion.LoadImage(_emojisSheetReplacement, PepeTaxmanPlugin.EmojisBytes))
			{
				int num = 384;
				int num2 = ((Texture)_emojisSheetReplacement).height - 320;
				_taxmanReplacement64 = new Texture2D(64, 64, (TextureFormat)4, false, false)
				{
					name = "taxman_grossup_modded",
					filterMode = (FilterMode)0
				};
				_taxmanReplacement64.SetPixels(_emojisSheetReplacement.GetPixels(num, num2, 64, 64));
				_taxmanReplacement64.Apply(false, false);
			}
			else
			{
				_emojisSheetReplacement = null;
			}
		}
		if (PepeTaxmanPlugin.TruckBytes != null)
		{
			_truckReplacement = new Texture2D(2, 2, (TextureFormat)4, false, false)
			{
				name = "HurryTruckPepe_Runtime",
				filterMode = (FilterMode)0
			};
			if (!ImageConversion.LoadImage(_truckReplacement, PepeTaxmanPlugin.TruckBytes))
			{
				_truckReplacement = null;
			}
		}
	}

	[IteratorStateMachine(typeof(<ApplyForAWhile>d__14))]
	private IEnumerator ApplyForAWhile()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ApplyForAWhile>d__14(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<ApplyOnceCo>d__15))]
	private IEnumerator ApplyOnceCo(Action<int> changedOut)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ApplyOnceCo>d__15(0)
		{
			<>4__this = this,
			changedOut = changedOut
		};
	}
}