using System;
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.SceneManagement;
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("com.github.vector-b.PEAK-CTPS")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+43c9ec4c440713c41984d251d2b8c2c7e9811815")]
[assembly: AssemblyProduct("com.github.vector-b.PEAK-CTPS")]
[assembly: AssemblyTitle("PEAK-CTPS")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace CTPS
{
[BepInPlugin("com.github.vector-b.PEAK-CTPS", "PEAK-CTPS", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class RawImageSetTexturePatch
{
private static void Prefix(ref Texture value, RawImage __instance)
{
if (!((Object)(object)PassportIconTex == (Object)null) && !((Object)(object)value == (Object)null) && !(((Object)value).name != "Passport"))
{
Log.LogInfo((object)("[CTPS] RawImage.texture on '" + ((Object)((Component)__instance).gameObject).name + "' using '" + ((Object)value).name + "' -> changing to CTPS card."));
value = (Texture)(object)PassportIconTex;
}
}
}
internal static Texture2D PassportCoverTex = null;
private const string PassportMaterialName = "M_Passport";
private static readonly int BaseTexId = Shader.PropertyToID("_BaseTexture");
internal static Texture2D PassportIconTex = null;
private const string PassportIconTextureName = "Passport";
private static bool _coverAlreadyReplaced = false;
public const string Id = "com.github.vector-b.PEAK-CTPS";
internal static ManualLogSource Log { get; private set; } = null;
public static string Name => "PEAK-CTPS";
public static string Version => "1.0.1";
private void Awake()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
LoadCoverTexture();
LoadIconTexture();
new Harmony("com.github.vector-b.CTPS").PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
Log.LogInfo((object)"[CTPS] Plugin carregado!");
}
private void LoadCoverTexture()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, "assets", "PassportUV_ctps.png");
if (!File.Exists(path))
{
Log.LogError((object)"[CTPS] CTPS cover file not found!");
return;
}
byte[] array = File.ReadAllBytes(path);
PassportCoverTex = new Texture2D(2, 2, (TextureFormat)4, false);
ImageConversion.LoadImage(PassportCoverTex, array);
PassportCoverTex.Apply(true, true);
Log.LogInfo((object)"[CTPS] CTPS cover texture loaded.");
}
private void LoadIconTexture()
{
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string path = Path.Combine(directoryName, "assets", "Passport_Icon.png");
if (!File.Exists(path))
{
Log.LogWarning((object)"[CTPS] CTPS icon file not found; HUD will not be changed.");
return;
}
byte[] array = File.ReadAllBytes(path);
PassportIconTex = new Texture2D(2, 2, (TextureFormat)4, false);
ImageConversion.LoadImage(PassportIconTex, array);
PassportIconTex.Apply(true, true);
Log.LogInfo((object)$"[CTPS] CTPS icon loaded: {((Texture)PassportIconTex).width}x{((Texture)PassportIconTex).height}.");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (_coverAlreadyReplaced)
{
return;
}
if ((Object)(object)PassportCoverTex == (Object)null)
{
Log.LogWarning((object)"[CTPS] PassportCoverTex is null, skipping 3D cover.");
return;
}
Material[] array = Resources.FindObjectsOfTypeAll<Material>();
Material[] array2 = array;
foreach (Material val in array2)
{
if ((Object)(object)val != (Object)null && ((Object)val).name == "M_Passport" && val.HasProperty(BaseTexId))
{
val.SetTexture(BaseTexId, (Texture)(object)PassportCoverTex);
_coverAlreadyReplaced = true;
Log.LogInfo((object)("[CTPS] Applied CTPS to the 3D cover of the material '" + ((Object)val).name + "'."));
break;
}
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}