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 BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Doctor in my pepper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("FS72727")]
[assembly: AssemblyProduct("Doctor in my pepper")]
[assembly: AssemblyCopyright("Copyright © FS72727 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("81f7217f-65ab-492a-b72f-fc5dff0ba256")]
[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 DrPepperReskin;
[BepInPlugin("Applebox", "Dr Pepper Reskin", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <ReskinAfterLoad>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public Plugin <>4__this;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <ReskinAfterLoad>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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 = (object)new WaitForSeconds(0.2f);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>4__this.ApplyToAllRenderers();
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();
}
}
internal static ManualLogSource Log;
internal static Texture2D DrPepperTex;
internal static Texture2D IconTex;
private readonly HashSet<int> processedMats = new HashSet<int>();
private void Awake()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
LoadTextures();
new Harmony("com.yourname.drpepperreskin").PatchAll();
SceneManager.sceneLoaded += delegate
{
((MonoBehaviour)this).StartCoroutine(ReskinAfterLoad());
};
}
private void LoadTextures()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Expected O, but got Unknown
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string text = Path.Combine(directoryName, "DrPepper.png");
if (File.Exists(text))
{
byte[] array = File.ReadAllBytes(text);
DrPepperTex = new Texture2D(2, 2, (TextureFormat)4, true);
ImageConversion.LoadImage(DrPepperTex, array);
((Texture)DrPepperTex).wrapMode = (TextureWrapMode)1;
((Texture)DrPepperTex).filterMode = (FilterMode)1;
Log.LogInfo((object)$"Loaded Dr Pepper bottle texture ({((Texture)DrPepperTex).width}x{((Texture)DrPepperTex).height})");
}
else
{
Log.LogError((object)("Bottle texture not found: " + text));
}
string text2 = Path.Combine(directoryName, "DrPepperIcon.png");
if (File.Exists(text2))
{
byte[] array2 = File.ReadAllBytes(text2);
IconTex = new Texture2D(2, 2, (TextureFormat)4, true);
ImageConversion.LoadImage(IconTex, array2);
((Texture)IconTex).wrapMode = (TextureWrapMode)1;
((Texture)IconTex).filterMode = (FilterMode)1;
Log.LogInfo((object)$"Loaded Dr Pepper icon texture ({((Texture)IconTex).width}x{((Texture)IconTex).height})");
}
else
{
Log.LogWarning((object)("Icon texture not found: " + text2));
}
}
[IteratorStateMachine(typeof(<ReskinAfterLoad>d__6))]
private IEnumerator ReskinAfterLoad()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <ReskinAfterLoad>d__6(0)
{
<>4__this = this
};
}
private void ApplyToAllRenderers()
{
if (!((Object)(object)DrPepperTex == (Object)null))
{
Renderer[] array = Resources.FindObjectsOfTypeAll<Renderer>();
foreach (Renderer renderer in array)
{
TryReplaceTexture(renderer);
}
}
}
internal static void TryReplaceTexture(Renderer renderer)
{
if ((Object)(object)renderer == (Object)null || (Object)(object)DrPepperTex == (Object)null)
{
return;
}
Material[] sharedMaterials = renderer.sharedMaterials;
foreach (Material val in sharedMaterials)
{
if (!((Object)(object)val == (Object)null) && ((Object)val).name.StartsWith("M_SportsDrink", StringComparison.Ordinal) && val.HasProperty("_BaseTexture"))
{
val.SetTexture("_BaseTexture", (Texture)(object)DrPepperTex);
ManualLogSource log = Log;
if (log != null)
{
log.LogInfo((object)("Replaced _BaseTexture on " + ((Object)val).name));
}
}
}
}
internal static void TryReplaceTextureIfRenderer(Object obj)
{
Renderer val = (Renderer)(object)((obj is Renderer) ? obj : null);
if (val != null)
{
TryReplaceTexture(val);
return;
}
GameObject val2 = (GameObject)(object)((obj is GameObject) ? obj : null);
if (val2 != null)
{
Renderer[] componentsInChildren = val2.GetComponentsInChildren<Renderer>(true);
foreach (Renderer renderer in componentsInChildren)
{
TryReplaceTexture(renderer);
}
}
}
}
[HarmonyPatch(typeof(Object), "Instantiate", new Type[] { typeof(Object) })]
internal static class PatchInstantiate1
{
private static void Postfix(Object __result)
{
Plugin.TryReplaceTextureIfRenderer(__result);
}
}
[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
{
typeof(Object),
typeof(Transform),
typeof(bool)
})]
internal static class PatchInstantiate2
{
private static void Postfix(Object __result)
{
Plugin.TryReplaceTextureIfRenderer(__result);
}
}
[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
{
typeof(Object),
typeof(Vector3),
typeof(Quaternion)
})]
internal static class PatchInstantiate3
{
private static void Postfix(Object __result)
{
Plugin.TryReplaceTextureIfRenderer(__result);
}
}
[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
{
typeof(Object),
typeof(Vector3),
typeof(Quaternion),
typeof(Transform)
})]
internal static class PatchInstantiate4
{
private static void Postfix(Object __result)
{
Plugin.TryReplaceTextureIfRenderer(__result);
}
}
[HarmonyPatch(typeof(RawImage), "set_texture")]
internal static class Patch_RawImage_set_texture
{
private static void Prefix(ref Texture __0)
{
if (!((Object)(object)__0 == (Object)null) && !((Object)(object)Plugin.IconTex == (Object)null) && ((Object)__0).name == "Sports Drink")
{
__0 = (Texture)(object)Plugin.IconTex;
Plugin.Log.LogInfo((object)"Replaced RawImage texture for Sports Drink icon");
}
}
}
internal static class TextReplacementHelper
{
private const string OldName = "SPORTS DRINK";
private const string NewName = "Dr Pepper";
internal static void ReplaceText(ref string text)
{
if (!string.IsNullOrWhiteSpace(text) && text.Trim().Equals("SPORTS DRINK", StringComparison.OrdinalIgnoreCase))
{
text = "Dr Pepper";
}
}
}
[HarmonyPatch(typeof(TMP_Text), "SetText", new Type[] { typeof(string) })]
internal static class Patch_TMP_SetText1
{
private static void Prefix(ref string __0)
{
TextReplacementHelper.ReplaceText(ref __0);
}
}
[HarmonyPatch(typeof(TMP_Text), "SetText", new Type[]
{
typeof(string),
typeof(bool)
})]
internal static class Patch_TMP_SetText2
{
private static void Prefix(ref string __0)
{
TextReplacementHelper.ReplaceText(ref __0);
}
}
[HarmonyPatch(typeof(TMP_Text), "set_text")]
internal static class Patch_TMP_set_text
{
private static void Prefix(ref string __0)
{
TextReplacementHelper.ReplaceText(ref __0);
}
}
[HarmonyPatch(typeof(Text), "set_text")]
internal static class Patch_UIText_set_text
{
private static void Prefix(ref string __0)
{
TextReplacementHelper.ReplaceText(ref __0);
}
}