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.Versioning;
using BepInEx;
using BepInEx.Configuration;
using CommonAPI.Phone;
using HarmonyLib;
using Reptile;
using Reptile.Phone;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TexturePackManager")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TexturePackManager")]
[assembly: AssemblyTitle("TexturePackManager")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TexturePackManager;
public class AppTexturePackManager : CustomApp
{
private static string[] _cachedPackNames;
public static void Initialize()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
Sprite val = null;
string appIconPath = TexturePackManagerPlugin.GetAppIconPath("AppIcon.png");
if (!string.IsNullOrEmpty(appIconPath) && File.Exists(appIconPath))
{
try
{
byte[] array = File.ReadAllBytes(appIconPath);
Texture2D val2 = new Texture2D(2, 2);
if (ImageConversion.LoadImage(val2, array))
{
((Texture)val2).wrapMode = (TextureWrapMode)1;
((Texture)val2).filterMode = (FilterMode)1;
val2.Apply();
val = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
}
}
catch
{
}
}
if ((Object)(object)val != (Object)null)
{
PhoneAPI.RegisterApp<AppTexturePackManager>("Texture Pack Manager", val);
}
else
{
PhoneAPI.RegisterApp<AppTexturePackManager>("Texture Pack Manager", (Sprite)null);
}
}
public override void OnAppInit()
{
((CustomApp)this).OnAppInit();
((CustomApp)this).CreateIconlessTitleBar("Texture Pack Manager", 80f);
base.ScrollView = PhoneScrollView.Create((CustomApp)(object)this, 275f, 1600f);
PopulateButtons();
}
public override void OnAppEnable()
{
((App)this).OnAppEnable();
_cachedPackNames = null;
PopulateButtons();
}
private static string[] GetTexturePackNames()
{
if (_cachedPackNames != null)
{
return _cachedPackNames;
}
List<string> list = new List<string> { "" };
if (!Directory.Exists(TexturePackManagerPlugin.TexturePacksFolder))
{
_cachedPackNames = list.ToArray();
return _cachedPackNames;
}
string[] directories = Directory.GetDirectories(TexturePackManagerPlugin.TexturePacksFolder);
for (int i = 0; i < directories.Length; i++)
{
string fileName = Path.GetFileName(directories[i]);
if (!string.IsNullOrEmpty(fileName))
{
list.Add(fileName);
}
}
_cachedPackNames = list.ToArray();
return _cachedPackNames;
}
private void PopulateButtons()
{
base.ScrollView.RemoveAllButtons();
string[] packs = GetTexturePackNames();
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value ?? "";
string text2 = (string.IsNullOrEmpty(text) ? "Default" : text);
SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Texture Pack: " + text2);
((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
{
if (TexturePackManagerPlugin.SelectedTexturePack != null)
{
int num = Array.IndexOf(packs, TexturePackManagerPlugin.SelectedTexturePack.Value);
num = ((num >= 0) ? (num + 1) : 0) % packs.Length;
TexturePackManagerPlugin.SelectedTexturePack.Value = packs[num];
PopulateButtons();
}
});
base.ScrollView.AddButton((PhoneButton)(object)val);
SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Random Pack");
((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
{
if (TexturePackManagerPlugin.SelectedTexturePack != null)
{
List<string> list = new List<string>();
string[] array = packs;
foreach (string text3 in array)
{
if (!string.IsNullOrEmpty(text3))
{
list.Add(text3);
}
}
if (list.Count > 0)
{
int index = Random.Range(0, list.Count);
TexturePackManagerPlugin.SelectedTexturePack.Value = list[index];
PopulateButtons();
}
}
});
base.ScrollView.AddButton((PhoneButton)(object)val2);
SimplePhoneButton val3 = PhoneUIUtility.CreateSimpleButton("Open Folder");
((PhoneButton)val3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val3).OnConfirm, new Action(OpenTexturePacksFolder));
base.ScrollView.AddButton((PhoneButton)(object)val3);
SimplePhoneButton val4 = PhoneUIUtility.CreateSimpleButton("Show Folder Location");
((PhoneButton)val4).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val4).OnConfirm, new Action(ShowFolderLocation));
base.ScrollView.AddButton((PhoneButton)(object)val4);
SimplePhoneButton val5 = PhoneUIUtility.CreateSimpleButton("Reload Stage");
((PhoneButton)val5).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val5).OnConfirm, new Action(ReloadStage));
base.ScrollView.AddButton((PhoneButton)(object)val5);
SimplePhoneButton val6 = PhoneUIUtility.CreateSimpleButton("Back");
((PhoneButton)val6).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val6).OnConfirm, (Action)delegate
{
((App)this).MyPhone.CloseCurrentApp();
});
base.ScrollView.AddButton((PhoneButton)(object)val6);
}
private void OpenTexturePacksFolder()
{
string texturePacksFolder = TexturePackManagerPlugin.TexturePacksFolder;
if (!Directory.Exists(texturePacksFolder))
{
Directory.CreateDirectory(texturePacksFolder);
}
try
{
Application.OpenURL("file:///" + texturePacksFolder.Replace('\\', '/'));
}
catch
{
}
_cachedPackNames = null;
}
private void ShowFolderLocation()
{
TexturePackChangeMessage.Instance?.ShowMessage(TexturePackManagerPlugin.TexturePacksFolder);
}
private void ReloadStage()
{
Core instance = Core.Instance;
if ((Object)(object)((instance != null) ? instance.BaseModule : null) == (Object)null)
{
return;
}
BaseModule baseModule = instance.BaseModule;
if (baseModule.IsLoading)
{
return;
}
StageManager stageManager = baseModule.StageManager;
if (stageManager != null && baseModule.IsPlayingInStage)
{
if (baseModule.IsInGamePaused)
{
baseModule.UnPauseGame((PauseType)65535);
}
((App)this).MyPhone.TurnOff(true);
stageManager.RestartStage();
}
}
}
internal static class CustomMapDetector
{
public const string MapStationScenePrefix = "mapstation/";
private static string _currentLoadingSceneName;
public static bool IsLoadingCustomMap
{
get
{
if (_currentLoadingSceneName != null)
{
return _currentLoadingSceneName.StartsWith("mapstation/", StringComparison.Ordinal);
}
return false;
}
}
public static void SetCurrentLoadingScene(string sceneName)
{
_currentLoadingSceneName = sceneName ?? "";
}
}
internal static class PathHelper
{
public static HashSet<string> GetPathsFromFolder(string path)
{
HashSet<string> hashSet = new HashSet<string>();
if (!Directory.Exists(path))
{
return hashSet;
}
FileInfo[] files = new DirectoryInfo(path).GetFiles("*", SearchOption.AllDirectories);
foreach (FileInfo fileInfo in files)
{
hashSet.Add(fileInfo.FullName);
}
return hashSet;
}
}
internal static class AssetBundleCache
{
public static AssetBundle FindAlreadyLoaded(string bundleName)
{
foreach (AssetBundle allLoadedAssetBundle in AssetBundle.GetAllLoadedAssetBundles())
{
if ((Object)(object)allLoadedAssetBundle == (Object)null)
{
continue;
}
string name = ((Object)allLoadedAssetBundle).name;
if (!string.IsNullOrEmpty(name))
{
string text = name.Replace('\\', '/');
if (text.EndsWith("/"))
{
text = text.TrimEnd(new char[1] { '/' });
}
if (string.Equals(text.Contains("/") ? text.Substring(text.LastIndexOf('/') + 1) : text, bundleName, StringComparison.OrdinalIgnoreCase) || string.Equals(name, bundleName, StringComparison.OrdinalIgnoreCase))
{
return allLoadedAssetBundle;
}
}
}
return null;
}
}
internal static class PngPackHelper
{
private static string _cachedPackName;
private static Dictionary<string, string> _cachedPngPaths;
private static Dictionary<string, bool> _isPngPackCache;
private static string _lastSelectedPackForCache;
private static Dictionary<string, Texture2D> _textureCache;
private static void InvalidateIfSelectionChanged()
{
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value ?? "";
if (!(text == _lastSelectedPackForCache))
{
_lastSelectedPackForCache = text;
_isPngPackCache = null;
_cachedPackName = null;
_cachedPngPaths = null;
_textureCache = null;
}
}
public static bool IsPngPack(string packName)
{
if (string.IsNullOrEmpty(packName))
{
return false;
}
InvalidateIfSelectionChanged();
if (_isPngPackCache == null)
{
_isPngPackCache = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
}
if (_isPngPackCache.TryGetValue(packName, out var value))
{
return value;
}
string text = Path.Combine(TexturePackManagerPlugin.TexturePacksFolder, packName);
string text2 = Path.Combine(text, "Assets");
string[] obj = new string[2] { text2, text };
bool flag = false;
string[] array = obj;
foreach (string path in array)
{
if (Directory.Exists(path) && Directory.GetFiles(path, "*.png", SearchOption.AllDirectories).Length != 0)
{
flag = true;
break;
}
}
_isPngPackCache[packName] = flag;
return flag;
}
public static string GetPngPath(string assetName)
{
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value;
if (string.IsNullOrEmpty(text))
{
return null;
}
if (!IsPngPack(text))
{
return null;
}
Dictionary<string, string> pngPathMap = GetPngPathMap(text);
if (pngPathMap == null || !pngPathMap.TryGetValue(assetName, out var value))
{
return null;
}
return value;
}
private static Dictionary<string, string> GetPngPathMap(string packName)
{
if (_cachedPackName == packName && _cachedPngPaths != null)
{
return _cachedPngPaths;
}
string text = Path.Combine(TexturePackManagerPlugin.TexturePacksFolder, packName);
string text2 = Path.Combine(text, "Assets");
Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
string[] array = new string[2] { text2, text };
foreach (string path in array)
{
if (!Directory.Exists(path))
{
continue;
}
string[] files = Directory.GetFiles(path, "*.png", SearchOption.AllDirectories);
foreach (string text3 in files)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text3);
if (!string.IsNullOrEmpty(fileNameWithoutExtension) && !dictionary.ContainsKey(fileNameWithoutExtension))
{
dictionary[fileNameWithoutExtension] = text3;
}
}
}
_cachedPackName = packName;
_cachedPngPaths = ((dictionary.Count > 0) ? dictionary : null);
return _cachedPngPaths;
}
internal static Texture2D LoadTextureFromPng(string pngPath)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
if (string.IsNullOrEmpty(pngPath))
{
return null;
}
if (_textureCache == null)
{
_textureCache = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase);
}
if (_textureCache.TryGetValue(pngPath, out var value))
{
return value;
}
byte[] array = File.ReadAllBytes(pngPath);
Texture2D val = new Texture2D(2, 2);
if (!ImageConversion.LoadImage(val, array))
{
return null;
}
((Texture)val).wrapMode = (TextureWrapMode)1;
((Texture)val).filterMode = (FilterMode)1;
val.Apply();
_textureCache[pngPath] = val;
return val;
}
internal static void ApplyPngReplacementsToMaterial(Material mat)
{
if ((Object)(object)mat == (Object)null)
{
return;
}
string[] texturePropertyNames = mat.GetTexturePropertyNames();
if (texturePropertyNames == null || texturePropertyNames.Length == 0)
{
Texture mainTexture = mat.mainTexture;
if (!((Object)(object)mainTexture != (Object)null) || string.IsNullOrEmpty(((Object)mainTexture).name))
{
return;
}
string pngPath = GetPngPath(NormalizeTextureName(((Object)mainTexture).name));
if (pngPath == null || !File.Exists(pngPath))
{
return;
}
try
{
Texture2D val = LoadTextureFromPng(pngPath);
if ((Object)(object)val != (Object)null)
{
mat.mainTexture = (Texture)(object)val;
}
return;
}
catch
{
return;
}
}
string[] array = texturePropertyNames;
foreach (string text in array)
{
Texture texture = mat.GetTexture(text);
if ((Object)(object)texture == (Object)null || string.IsNullOrEmpty(((Object)texture).name))
{
continue;
}
string pngPath2 = GetPngPath(NormalizeTextureName(((Object)texture).name));
if (pngPath2 == null || !File.Exists(pngPath2))
{
continue;
}
try
{
Texture2D val2 = LoadTextureFromPng(pngPath2);
if ((Object)(object)val2 != (Object)null)
{
mat.SetTexture(text, (Texture)(object)val2);
}
}
catch
{
}
}
}
private static string NormalizeTextureName(string name)
{
if (string.IsNullOrEmpty(name))
{
return name;
}
if (name.EndsWith(" (Instance)"))
{
name = name.Substring(0, name.Length - 11);
}
int num = name.LastIndexOfAny(new char[2] { '/', '\\' });
if (num >= 0 && num < name.Length - 1)
{
name = name.Substring(num + 1);
}
return name;
}
internal static void ApplyPngReplacementsToGameObject(GameObject go)
{
if ((Object)(object)go == (Object)null)
{
return;
}
Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
if (val.sharedMaterials == null)
{
continue;
}
Material[] sharedMaterials = val.sharedMaterials;
foreach (Material val2 in sharedMaterials)
{
if ((Object)(object)val2 != (Object)null)
{
ApplyPngReplacementsToMaterial(val2);
}
}
}
}
internal static Object TryReplaceTexture(Object asset)
{
Texture2D val = (Texture2D)(object)((asset is Texture2D) ? asset : null);
if (val != null && !string.IsNullOrEmpty(((Object)val).name))
{
string pngPath = GetPngPath(NormalizeTextureName(((Object)val).name));
if (pngPath != null && File.Exists(pngPath))
{
try
{
Texture2D val2 = LoadTextureFromPng(pngPath);
if ((Object)(object)val2 != (Object)null)
{
return (Object)(object)val2;
}
}
catch
{
}
}
}
return null;
}
internal static void ApplyReplacementsToLoadedAsset(ref Object asset)
{
if (asset == (Object)null)
{
return;
}
Object obj = asset;
Material val = (Material)(object)((obj is Material) ? obj : null);
if (val != null)
{
ApplyPngReplacementsToMaterial(val);
return;
}
Object obj2 = asset;
GameObject val2 = (GameObject)(object)((obj2 is GameObject) ? obj2 : null);
if (val2 != null)
{
ApplyPngReplacementsToGameObject(val2);
}
else if (asset is Texture2D)
{
Object val3 = TryReplaceTexture(asset);
if (val3 != (Object)null)
{
asset = val3;
}
}
}
internal static void ApplyPngReplacementsToSkyboxMaterial(Material mat)
{
if ((Object)(object)mat == (Object)null)
{
return;
}
Texture mainTexture = mat.mainTexture;
if ((Object)(object)mainTexture != (Object)null && !string.IsNullOrEmpty(((Object)mainTexture).name))
{
string pngPath = GetPngPath(NormalizeTextureName(((Object)mainTexture).name));
if (pngPath != null && File.Exists(pngPath))
{
try
{
Texture2D val = LoadTextureFromPng(pngPath);
if ((Object)(object)val != (Object)null)
{
mat.mainTexture = (Texture)(object)val;
}
}
catch
{
}
}
}
string[] array = new string[8] { "_MainTex", "_Tex", "_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex" };
foreach (string text in array)
{
if (mat.HasProperty(text))
{
TryReplaceSkyboxTexture(mat, text);
}
}
string[] texturePropertyNames = mat.GetTexturePropertyNames();
if (texturePropertyNames == null)
{
return;
}
array = texturePropertyNames;
foreach (string text2 in array)
{
if (!string.IsNullOrEmpty(text2))
{
TryReplaceSkyboxTexture(mat, text2);
}
}
}
private static void TryReplaceSkyboxTexture(Material mat, string propName)
{
Texture texture = mat.GetTexture(propName);
if ((Object)(object)texture == (Object)null || string.IsNullOrEmpty(((Object)texture).name))
{
return;
}
string pngPath = GetPngPath(NormalizeTextureName(((Object)texture).name));
if (pngPath == null || !File.Exists(pngPath))
{
return;
}
try
{
Texture2D val = LoadTextureFromPng(pngPath);
if ((Object)(object)val != (Object)null)
{
mat.SetTexture(propName, (Texture)(object)val);
}
}
catch
{
}
}
}
internal static class AssetPathResolver
{
private static Dictionary<string, string> _defaultPathMap;
private static HashSet<string> _defaultPathSet;
private static Dictionary<string, Dictionary<string, string>> _mergedPathMaps;
private static Dictionary<string, HashSet<string>> _mergedPathSets;
private static string _lastSelectedPack;
private static void EnsureDefaultCache()
{
if (_defaultPathMap != null)
{
return;
}
HashSet<string> pathsFromFolder = PathHelper.GetPathsFromFolder(Path.Combine(Application.streamingAssetsPath, "Assets"));
_defaultPathMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (string item in pathsFromFolder)
{
_defaultPathMap[Path.GetFileNameWithoutExtension(item)] = item;
}
_defaultPathSet = new HashSet<string>(_defaultPathMap.Values);
}
private static void InvalidatePackCachesIfNeeded()
{
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value ?? "";
if (!(text == _lastSelectedPack))
{
_lastSelectedPack = text;
_mergedPathMaps = null;
_mergedPathSets = null;
}
}
public static string GetPathFromStreamingAssetsOnly(string bundleName)
{
EnsureDefaultCache();
if (!_defaultPathMap.TryGetValue(bundleName, out var value))
{
return null;
}
return value;
}
public static string GetResolvedPath(string bundleName)
{
EnsureDefaultCache();
InvalidatePackCachesIfNeeded();
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value;
if (string.IsNullOrEmpty(text))
{
if (!_defaultPathMap.TryGetValue(bundleName, out var value))
{
return null;
}
return value;
}
if (!GetOrBuildMergedPathMap(text).TryGetValue(bundleName, out var value2))
{
return null;
}
return value2;
}
public static HashSet<string> GetDefaultPathSet()
{
EnsureDefaultCache();
return _defaultPathSet;
}
public static HashSet<string> GetMergedPathSet(string packName)
{
EnsureDefaultCache();
InvalidatePackCachesIfNeeded();
if (string.IsNullOrEmpty(packName))
{
return _defaultPathSet;
}
if (_mergedPathSets == null)
{
_mergedPathSets = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);
}
if (_mergedPathSets.TryGetValue(packName, out var value))
{
return value;
}
value = new HashSet<string>(GetOrBuildMergedPathMap(packName).Values);
_mergedPathSets[packName] = value;
return value;
}
private static Dictionary<string, string> GetOrBuildMergedPathMap(string packName)
{
if (_mergedPathMaps == null)
{
_mergedPathMaps = new Dictionary<string, Dictionary<string, string>>(StringComparer.OrdinalIgnoreCase);
}
if (_mergedPathMaps.TryGetValue(packName, out var value))
{
return value;
}
value = new Dictionary<string, string>(_defaultPathMap, StringComparer.OrdinalIgnoreCase);
string text = Path.Combine(TexturePackManagerPlugin.TexturePacksFolder, packName);
string text2 = Path.Combine(text, "Assets");
foreach (string item in PathHelper.GetPathsFromFolder(Directory.Exists(text2) ? text2 : text))
{
value[Path.GetFileNameWithoutExtension(item)] = item;
}
_mergedPathMaps[packName] = value;
return value;
}
public static string GetResolvedBundlePath(string bundleName)
{
if (string.IsNullOrEmpty(bundleName))
{
return null;
}
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value;
if (!string.IsNullOrEmpty(text) && PngPackHelper.IsPngPack(text))
{
return GetPathFromStreamingAssetsOnly(bundleName);
}
return GetResolvedPath(bundleName);
}
}
[HarmonyPatch(typeof(Assets), "LoadAssetBundlesForSceneASync")]
internal static class AssetsLoadAssetBundlesForSceneASyncPatch
{
private static void Prefix(string sceneName)
{
CustomMapDetector.SetCurrentLoadingScene(sceneName);
}
}
[HarmonyPatch(typeof(Assets), "GetAssetBundlePathsFromDisk")]
internal static class AssetsGetPathsPatch
{
private static bool Prefix(string pathToBundles, ref HashSet<string> __result)
{
string text = TexturePackManagerPlugin.SelectedTexturePack?.Value;
if (string.IsNullOrEmpty(text))
{
return true;
}
if (PngPackHelper.IsPngPack(text))
{
__result = AssetPathResolver.GetDefaultPathSet();
return false;
}
__result = AssetPathResolver.GetMergedPathSet(text);
return false;
}
}
[HarmonyPatch(typeof(Assets), "LoadBundle")]
internal static class AssetsLoadBundlePatch
{
private static bool Prefix(Bundle bundleToLoad)
{
if (bundleToLoad == null)
{
return true;
}
if (CustomMapDetector.IsLoadingCustomMap)
{
return true;
}
if (!string.IsNullOrEmpty(bundleToLoad.FilePath) && bundleToLoad.FilePath.StartsWith("maps/"))
{
return true;
}
if (bundleToLoad.IsLoaded)
{
return false;
}
if (string.IsNullOrEmpty(bundleToLoad.Name))
{
return true;
}
string resolvedBundlePath = AssetPathResolver.GetResolvedBundlePath(bundleToLoad.Name);
if (resolvedBundlePath == null)
{
return true;
}
AssetBundle val = AssetBundle.LoadFromFile(resolvedBundlePath);
if ((Object)(object)val == (Object)null)
{
val = AssetBundleCache.FindAlreadyLoaded(bundleToLoad.Name);
}
if ((Object)(object)val != (Object)null)
{
bundleToLoad.SetAssetBundle(val);
}
return false;
}
}
[HarmonyPatch(typeof(Assets), "LoadBundleASync")]
internal static class AssetsLoadBundleASyncPatch
{
private static bool Prefix(Assets __instance, Bundle bundleToLoad, ref IEnumerator __result)
{
if (bundleToLoad == null)
{
return true;
}
if (CustomMapDetector.IsLoadingCustomMap)
{
return true;
}
if (!string.IsNullOrEmpty(bundleToLoad.FilePath) && bundleToLoad.FilePath.StartsWith("maps/"))
{
return true;
}
if (bundleToLoad.IsLoaded)
{
__result = LoadBundleASyncNoOp();
return false;
}
if (string.IsNullOrEmpty(bundleToLoad.Name))
{
return true;
}
string resolvedBundlePath = AssetPathResolver.GetResolvedBundlePath(bundleToLoad.Name);
if (resolvedBundlePath == null)
{
return true;
}
__result = LoadBundleASyncReplacement(__instance, bundleToLoad, resolvedBundlePath);
return false;
}
private static IEnumerator LoadBundleASyncNoOp()
{
yield break;
}
private static IEnumerator LoadBundleASyncReplacement(Assets assets, Bundle bundleToLoad, string path)
{
bundleToLoad.InitializeLoad();
AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path);
Traverse.Create((object)assets).Field("currentAssetBundleCreateRequest").SetValue((object)request);
yield return request;
AssetBundle val = request.assetBundle;
if ((Object)(object)val == (Object)null)
{
val = AssetBundleCache.FindAlreadyLoaded(bundleToLoad.Name);
}
if ((Object)(object)val != (Object)null)
{
bundleToLoad.SetAssetBundle(val);
}
else
{
bundleToLoad.ResetLoadState();
}
}
}
[HarmonyPatch(typeof(AssetBundle), "LoadAsset", new Type[]
{
typeof(string),
typeof(Type)
})]
internal static class AssetBundleLoadAssetPatch
{
private static void Postfix(ref Object __result)
{
PngPackHelper.ApplyReplacementsToLoadedAsset(ref __result);
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal static class AssetBundleRequestAssetPatch
{
private static void Postfix(ref Object __result)
{
PngPackHelper.ApplyReplacementsToLoadedAsset(ref __result);
}
}
public class TexturePackChangeMessage : MonoBehaviour
{
private GameObject _canvasGo;
private TextMeshProUGUI _label;
private Coroutine _hideCoroutine;
public static TexturePackChangeMessage Instance { get; private set; }
private void Awake()
{
Instance = this;
}
private void OnDestroy()
{
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
public void EnsureCreated()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Expected O, but got Unknown
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: 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_0136: 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_016b: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_canvasGo != (Object)null))
{
Core instance = Core.Instance;
object obj;
if (instance == null)
{
obj = null;
}
else
{
UIManager uIManager = instance.UIManager;
obj = ((uIManager != null) ? ((Component)uIManager).transform : null);
}
Transform val = (Transform)obj;
if (!((Object)(object)val == (Object)null))
{
_canvasGo = new GameObject("TexturePackManager_MessageCanvas");
_canvasGo.transform.SetParent(val, false);
Canvas obj2 = _canvasGo.AddComponent<Canvas>();
obj2.renderMode = (RenderMode)0;
obj2.sortingOrder = 200;
_canvasGo.AddComponent<CanvasScaler>();
_canvasGo.AddComponent<GraphicRaycaster>();
GameObject val2 = new GameObject("MessageLabel");
val2.transform.SetParent(_canvasGo.transform, false);
_label = val2.AddComponent<TextMeshProUGUI>();
((TMP_Text)_label).text = "";
((TMP_Text)_label).fontSize = 22f;
((Graphic)_label).color = Color.white;
((TMP_Text)_label).alignment = (TextAlignmentOptions)260;
RectTransform component = val2.GetComponent<RectTransform>();
component.anchorMin = new Vector2(1f, 1f);
component.anchorMax = new Vector2(1f, 1f);
component.pivot = new Vector2(1f, 1f);
component.sizeDelta = new Vector2(600f, 80f);
((TMP_Text)_label).enableWordWrapping = true;
component.anchoredPosition = new Vector2(-16f, -10f);
_canvasGo.SetActive(false);
}
}
}
public void ShowMessage()
{
ShowMessage("Restart Your Game To See The Change");
}
public void ShowMessage(string message)
{
EnsureCreated();
if (!((Object)(object)_canvasGo == (Object)null) && !((Object)(object)_label == (Object)null))
{
if (_hideCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(_hideCoroutine);
}
((TMP_Text)_label).text = message;
_canvasGo.SetActive(true);
_hideCoroutine = ((MonoBehaviour)this).StartCoroutine(HideAfterDelay(4f));
}
}
private IEnumerator HideAfterDelay(float seconds)
{
yield return (object)new WaitForSecondsRealtime(seconds);
_hideCoroutine = null;
if ((Object)(object)_canvasGo != (Object)null)
{
_canvasGo.SetActive(false);
}
if ((Object)(object)_label != (Object)null)
{
((TMP_Text)_label).text = "";
}
}
}
[BepInPlugin("com.texturepackmanager", "Texture Pack Manager", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class TexturePackManagerPlugin : BaseUnityPlugin
{
private static string _pluginFolder;
private static TexturePackManagerPlugin _instance;
private Harmony _harmony;
public static string TexturePacksFolder { get; private set; }
public static ConfigEntry<string> SelectedTexturePack { get; private set; }
public static string GetAppIconPath(string filename)
{
if (!string.IsNullOrEmpty(_pluginFolder))
{
return Path.Combine(_pluginFolder, filename);
}
return null;
}
private void Awake()
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Expected O, but got Unknown
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Expected O, but got Unknown
_instance = this;
_pluginFolder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
TexturePacksFolder = Path.Combine(Paths.BepInExRootPath, "TexturePacks");
Directory.CreateDirectory(TexturePacksFolder);
SelectedTexturePack = ((BaseUnityPlugin)this).Config.Bind<string>("Texture Pack", "SelectedTexturePack", "", "");
_harmony = new Harmony("com.texturepackmanager");
_harmony.PatchAll();
SceneManager.sceneLoaded += OnSceneLoaded;
AppTexturePackManager.Initialize();
GameObject val = new GameObject("TexturePackManager_ChangeMessage");
Object.DontDestroyOnLoad((Object)val);
val.AddComponent<TexturePackChangeMessage>();
}
private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
if (CustomMapDetector.IsLoadingCustomMap || string.IsNullOrEmpty(SelectedTexturePack?.Value) || !PngPackHelper.IsPngPack(SelectedTexturePack.Value))
{
return;
}
GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
for (int i = 0; i < rootGameObjects.Length; i++)
{
Renderer[] componentsInChildren = rootGameObjects[i].GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
if (val.sharedMaterials == null)
{
continue;
}
Material[] sharedMaterials = val.sharedMaterials;
foreach (Material val2 in sharedMaterials)
{
if ((Object)(object)val2 != (Object)null)
{
PngPackHelper.ApplyPngReplacementsToMaterial(val2);
}
}
}
}
if ((Object)(object)_instance != (Object)null)
{
((MonoBehaviour)_instance).StartCoroutine(DeferredSkyboxReplacement());
}
}
private static IEnumerator DeferredSkyboxReplacement()
{
yield return null;
if (!string.IsNullOrEmpty(SelectedTexturePack?.Value) && PngPackHelper.IsPngPack(SelectedTexturePack.Value))
{
Material skybox = RenderSettings.skybox;
if ((Object)(object)skybox != (Object)null)
{
PngPackHelper.ApplyPngReplacementsToSkyboxMaterial(skybox);
}
}
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
if ((Object)(object)TexturePackChangeMessage.Instance != (Object)null)
{
Object.Destroy((Object)(object)((Component)TexturePackChangeMessage.Instance).gameObject);
}
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "com.texturepackmanager";
public const string PLUGIN_NAME = "Texture Pack Manager";
public const string PLUGIN_VERSION = "1.0.0";
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TexturePackManager";
public const string PLUGIN_NAME = "TexturePackManager";
public const string PLUGIN_VERSION = "1.0.0";
}