using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("MonoStages")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MonoStages")]
[assembly: AssemblyTitle("MonoStages")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MonoStages;
internal static class Dump
{
public static string Write(string dir, string stage, GameObject root, TextureGreyer tex, Options opt)
{
//IL_0295: Unknown result type (might be due to invalid IL or missing references)
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_030f: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_04f1: Unknown result type (might be due to invalid IL or missing references)
//IL_050d: Unknown result type (might be due to invalid IL or missing references)
//IL_0512: Unknown result type (might be due to invalid IL or missing references)
//IL_056d: Unknown result type (might be due to invalid IL or missing references)
//IL_0572: Unknown result type (might be due to invalid IL or missing references)
//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
//IL_0623: Unknown result type (might be due to invalid IL or missing references)
//IL_0628: Unknown result type (might be due to invalid IL or missing references)
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("MonoStages dump - stage " + stage + " - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
stringBuilder.AppendLine("Stage root: " + Path(root.transform) + (root.activeInHierarchy ? " (visible)" : " (hidden)"));
stringBuilder.AppendLine();
HashSet<int> hashSet = new HashSet<int>();
Dictionary<string, int> dictionary = new Dictionary<string, int>();
stringBuilder.AppendLine("== Materials");
Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
foreach (Renderer val in componentsInChildren)
{
Material[] sharedMaterials = val.sharedMaterials;
foreach (Material val2 in sharedMaterials)
{
if ((Object)(object)val2 == (Object)null || !hashSet.Add(((Object)val2).GetInstanceID()))
{
continue;
}
string text = (((Object)(object)val2.shader != (Object)null) ? ((Object)val2.shader).name : "?");
dictionary.TryGetValue(text, out var value);
dictionary[text] = value + 1;
stringBuilder.AppendLine(((Object)val2).name + " [" + text + "] on " + Path(((Component)val).transform));
string[] array = null;
try
{
array = Filters.TexturePropertyNames(val2);
}
catch
{
}
if (array == null)
{
array = opt.FallbackTexProps.ToArray();
}
string[] array2 = array;
foreach (string text2 in array2)
{
Texture val3 = null;
try
{
val3 = val2.GetTexture(text2);
}
catch
{
}
if (!((Object)(object)val3 == (Object)null))
{
Texture2D val4 = (Texture2D)(object)((val3 is Texture2D) ? val3 : null);
string text3 = (tex.IsOutput(val3) ? "MONO" : (((Object)(object)val4 == (Object)null) ? ("left alone: " + ((object)val3).GetType().Name) : ((!Filters.IsDataName(text2) && !opt.SkipTexProps.Contains(text2)) ? ("left alone: " + (tex.SkipReason(val4) ?? "not processed")) : "left alone: data slot")));
stringBuilder.AppendLine(" tex " + text2 + " = " + ((Object)val3).name + " " + val3.width + "x" + val3.height + (((Object)(object)val4 != (Object)null) ? (" " + ((object)val4.format/*cast due to .constrained prefix*/).ToString()) : "") + " -> " + text3);
}
}
foreach (string colorProp in opt.ColorProps)
{
if (val2.HasProperty(colorProp))
{
stringBuilder.AppendLine(" col " + colorProp + " = " + ((object)val2.GetColor(colorProp)/*cast due to .constrained prefix*/).ToString());
}
}
}
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("== Shaders (material count)");
foreach (KeyValuePair<string, int> item in dictionary)
{
stringBuilder.AppendLine(" " + item.Value + " " + item.Key);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("== Stage scripts");
Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
MonoBehaviour[] componentsInChildren2 = root.GetComponentsInChildren<MonoBehaviour>(true);
foreach (MonoBehaviour val5 in componentsInChildren2)
{
if (!((Object)(object)val5 == (Object)null))
{
string fullName = ((object)val5).GetType().FullName;
dictionary2.TryGetValue(fullName, out var value2);
dictionary2[fullName] = value2 + 1;
}
}
foreach (KeyValuePair<string, int> item2 in dictionary2)
{
stringBuilder.AppendLine(" " + item2.Value + " " + item2.Key);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("== Lights");
Light[] array3 = Object.FindObjectsOfType<Light>();
foreach (Light val6 in array3)
{
stringBuilder.AppendLine(" " + Path(((Component)val6).transform) + " " + ((object)val6.type/*cast due to .constrained prefix*/).ToString() + " " + ((object)val6.color/*cast due to .constrained prefix*/).ToString() + " x" + val6.intensity);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("== Scene roots (anything coloured outside the stage root would be here)");
Scene scene = root.scene;
GameObject[] rootGameObjects = ((Scene)(ref scene)).GetRootGameObjects();
foreach (GameObject val7 in rootGameObjects)
{
stringBuilder.AppendLine(" " + ((Object)val7).name + " renderers: " + val7.GetComponentsInChildren<Renderer>(true).Length);
}
stringBuilder.AppendLine();
stringBuilder.AppendLine("== Environment");
stringBuilder.AppendLine(" ambient " + ((object)RenderSettings.ambientLight/*cast due to .constrained prefix*/).ToString() + " fog " + RenderSettings.fog + " " + ((object)RenderSettings.fogColor/*cast due to .constrained prefix*/).ToString());
stringBuilder.AppendLine(" skybox " + (((Object)(object)RenderSettings.skybox != (Object)null) ? ((Object)RenderSettings.skybox).name : "none"));
string text4 = System.IO.Path.Combine(dir, "MonoStages_dump_" + Safe(stage) + ".txt");
File.WriteAllText(text4, stringBuilder.ToString());
return text4;
}
private static string Path(Transform t)
{
List<string> list = new List<string>();
int num = 0;
while ((Object)(object)t != (Object)null && num < 12)
{
list.Insert(0, ((Object)t).name);
num++;
t = t.parent;
}
return string.Join("/", list.ToArray());
}
private static string Safe(string s)
{
StringBuilder stringBuilder = new StringBuilder();
string text = s ?? "stage";
foreach (char c in text)
{
stringBuilder.Append((char.IsLetterOrDigit(c) || c == '_') ? c : '_');
}
return stringBuilder.ToString();
}
}
internal sealed class LlbStage
{
private readonly FieldInfo _instance;
private readonly FieldInfo _curStage;
public readonly Assembly GameAssembly;
public readonly string Problem;
public bool Ok => Problem == null;
public LlbStage()
{
Type type = Type.GetType("StageBackground.BG, Assembly-CSharp");
if ((object)type == null)
{
Problem = "StageBackground.BG not found in Assembly-CSharp";
return;
}
GameAssembly = type.Assembly;
_instance = type.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if ((object)_instance == null)
{
Problem = "StageBackground.BG.instance not found";
}
Type type2 = GameAssembly.GetType("LLHandlers.StageHandler");
if ((object)type2 != null)
{
_curStage = type2.GetField("curStage", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
}
public MonoBehaviour Current()
{
if ((object)_instance == null)
{
return null;
}
object? value = _instance.GetValue(null);
MonoBehaviour val = (MonoBehaviour)((value is MonoBehaviour) ? value : null);
if (!((Object)(object)val == (Object)null))
{
return val;
}
return null;
}
public string StageName()
{
try
{
return ((object)_curStage == null) ? "?" : Convert.ToString(_curStage.GetValue(null));
}
catch
{
return "?";
}
}
}
public sealed class MonoLook
{
public float Brightness = 0.85f;
public float Contrast = 1.1f;
public float TintR = 0.54509807f;
public float TintG = 0.36078432f;
public float TintB = 82f / 85f;
public float TintStrength = 0.2f;
public float Saturation;
private readonly byte[] _lr = new byte[256];
private readonly byte[] _lg = new byte[256];
private readonly byte[] _lb = new byte[256];
private bool _built;
public static readonly string[] PresetNames = new string[5] { "Mono", "Greyscale", "Noir", "Muted", "Custom" };
public bool ApplyPreset(string name)
{
switch ((name ?? "").Trim().ToLowerInvariant())
{
case "mono":
Set(0.85f, 1.1f, 0.2f, 0f);
SetTint(139, 92, 246);
return true;
case "greyscale":
case "grayscale":
Set(1f, 1f, 0f, 0f);
return true;
case "noir":
Set(0.65f, 1.3f, 0f, 0f);
return true;
case "muted":
Set(0.85f, 1f, 0.12f, 0.25f);
SetTint(139, 92, 246);
return true;
default:
return false;
}
}
private void Set(float brightness, float contrast, float tintStrength, float saturation)
{
Brightness = brightness;
Contrast = contrast;
TintStrength = tintStrength;
Saturation = saturation;
_built = false;
}
public void SetTint(int r, int g, int b)
{
TintR = (float)r / 255f;
TintG = (float)g / 255f;
TintB = (float)b / 255f;
_built = false;
}
public bool SetTint(string hex)
{
if (hex == null)
{
return false;
}
string text = hex.Trim().TrimStart(new char[1] { '#' });
if (text.Length != 6)
{
return false;
}
try
{
SetTint(Convert.ToInt32(text.Substring(0, 2), 16), Convert.ToInt32(text.Substring(2, 2), 16), Convert.ToInt32(text.Substring(4, 2), 16));
return true;
}
catch (FormatException)
{
return false;
}
}
public string Signature()
{
return string.Format(CultureInfo.InvariantCulture, "{0:0.###}|{1:0.###}|{2:0.###},{3:0.###},{4:0.###}|{5:0.###}|{6:0.###}", Brightness, Contrast, TintR, TintG, TintB, TintStrength, Saturation);
}
public static float Luma(float r, float g, float b)
{
return 0.299f * r + 0.587f * g + 0.114f * b;
}
public void MapLuma(float y, out float r, out float g, out float b)
{
float num = Clamp01((y - 0.5f) * Contrast + 0.5f);
float num2 = num * Brightness;
float num3 = Luma(TintR, TintG, TintB);
float num4 = 1f;
float num5 = 1f;
float num6 = 1f;
if (num3 > 0.001f)
{
num4 = TintR / num3;
num5 = TintG / num3;
num6 = TintB / num3;
}
float num7 = TintStrength * (1f - SmoothStep(0.55f, 1f, num));
r = Clamp01(num2 * (1f + (num4 - 1f) * num7));
g = Clamp01(num2 * (1f + (num5 - 1f) * num7));
b = Clamp01(num2 * (1f + (num6 - 1f) * num7));
}
public void Map(ref float r, ref float g, ref float b)
{
float num = Math.Max(1f, Math.Max(r, Math.Max(g, b)));
float num2 = r / num;
float num3 = g / num;
float num4 = b / num;
float num5 = Luma(num2, num3, num4);
MapLuma(num5, out var r2, out var g2, out var b2);
if (Saturation > 0f)
{
r2 = Clamp01(r2 + (num2 - num5) * Saturation);
g2 = Clamp01(g2 + (num3 - num5) * Saturation);
b2 = Clamp01(b2 + (num4 - num5) * Saturation);
}
r = r2 * num;
g = g2 * num;
b = b2 * num;
}
public void Build()
{
for (int i = 0; i < 256; i++)
{
MapLuma((float)i / 255f, out var r, out var g, out var b);
_lr[i] = ToByte(r);
_lg[i] = ToByte(g);
_lb[i] = ToByte(b);
}
_built = true;
}
public void MapBytes(ref byte r, ref byte g, ref byte b)
{
if (!_built)
{
Build();
}
int num = 77 * r + 150 * g + 29 * b + 128 >> 8;
if (Saturation > 0f)
{
float saturation = Saturation;
int v = _lr[num] + (int)((float)(r - num) * saturation);
int v2 = _lg[num] + (int)((float)(g - num) * saturation);
int v3 = _lb[num] + (int)((float)(b - num) * saturation);
r = ClampByte(v);
g = ClampByte(v2);
b = ClampByte(v3);
}
else
{
r = _lr[num];
g = _lg[num];
b = _lb[num];
}
}
public static void Grey(ref float r, ref float g, ref float b)
{
float num = Luma(r, g, b);
r = (g = (b = num));
}
public static void GreyBytes(ref byte r, ref byte g, ref byte b)
{
byte b2 = (byte)(77 * r + 150 * g + 29 * b + 128 >> 8);
r = (g = (b = b2));
}
private static float Clamp01(float v)
{
if (!(v < 0f))
{
if (!(v > 1f))
{
return v;
}
return 1f;
}
return 0f;
}
private static byte ToByte(float v)
{
return (byte)Math.Round(Clamp01(v) * 255f);
}
private static byte ClampByte(int v)
{
return (byte)((v >= 0) ? ((v > 255) ? 255u : ((uint)v)) : 0u);
}
private static float SmoothStep(float a, float b, float x)
{
float num = Clamp01((x - a) / (b - a));
return num * num * (3f - 2f * num);
}
}
[BepInPlugin("MonoStages", "MonoStages", "1.0.0")]
public sealed class MonoStagesPlugin : BaseUnityPlugin
{
public const string Guid = "MonoStages";
public const string PluginName = "MonoStages";
public const string Version = "1.0.0";
internal static ManualLogSource Log;
private Settings _cfg;
private readonly MonoLook _look = new MonoLook();
private readonly Options _opt = new Options();
private TextureGreyer _tex;
private StageMono _mono;
private LlbStage _llb;
private bool _ready;
private bool _on;
private bool _dirty;
private bool _skipStage;
private bool _wasVisible;
private MonoBehaviour _bg;
private string _stage = "?";
private float _nextScan;
private int _errors;
private int _warnings;
private void Awake()
{
//IL_0113: 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_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)
Log = ((BaseUnityPlugin)this).Logger;
try
{
_cfg = new Settings(((BaseUnityPlugin)this).Config);
_tex = new TextureGreyer(_look);
_mono = new StageMono(_look, _tex, _opt, Warn);
_llb = new LlbStage();
if (!_llb.Ok)
{
Log.LogError((object)("MonoStages: " + _llb.Problem + ". Is this Lethal League Blaze?"));
((Behaviour)this).enabled = false;
return;
}
ApplyConfig();
_on = _cfg.Enabled.Value;
((BaseUnityPlugin)this).Config.SettingChanged += delegate
{
_dirty = true;
};
_ready = true;
Log.LogInfo((object)("MonoStages 1.0.0 loaded (" + _cfg.Preset.Value + "). " + ((object)_cfg.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " toggles, Shift+" + ((object)_cfg.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " dumps the stage."));
}
catch (Exception ex)
{
Log.LogError((object)("MonoStages failed to start: " + ex));
((Behaviour)this).enabled = false;
}
}
private void ApplyConfig()
{
_cfg.ApplyTo(_look);
_cfg.ApplyTo(_opt, _tex);
}
private void LateUpdate()
{
if (!_ready)
{
return;
}
try
{
Keys();
MonoBehaviour val = _llb.Current();
if (val != _bg)
{
StageChanged(val);
}
if (_dirty && _on && (Object)(object)_bg != (Object)null)
{
Rebuild("settings changed");
}
_dirty = false;
if (!((Object)(object)_bg == (Object)null) && _on && !_skipStage)
{
bool activeInHierarchy = ((Component)_bg).gameObject.activeInHierarchy;
float unscaledTime = Time.unscaledTime;
if ((activeInHierarchy && !_wasVisible) || unscaledTime >= _nextScan)
{
_mono.Pass();
_nextScan = unscaledTime + _cfg.RescanSeconds.Value;
}
_wasVisible = activeInHierarchy;
_mono.Enforce();
}
}
catch (Exception ex)
{
if (_errors++ < 5)
{
Log.LogError((object)("MonoStages: " + ex));
}
}
}
private void Keys()
{
//IL_000b: 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)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
KeyCode value = _cfg.ToggleKey.Value;
if ((int)value == 0 || !Input.GetKeyDown(value))
{
return;
}
if (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))
{
DoDump();
return;
}
_on = !_on;
if (_on)
{
((BaseUnityPlugin)this).Config.Reload();
string text = _look.Signature();
ApplyConfig();
if (_look.Signature() != text)
{
_tex.Clear();
}
if ((Object)(object)_bg != (Object)null)
{
RecolourStage(_bg, "on");
}
}
else if (_mono.Active)
{
_mono.Undo();
Log.LogInfo((object)"MonoStages: off (original colours restored)");
}
_dirty = false;
}
private void StageChanged(MonoBehaviour bg)
{
if (_mono.Active)
{
_mono.Undo();
}
_bg = bg;
_wasVisible = false;
if (!((Object)(object)bg == (Object)null))
{
_stage = _llb.StageName();
_skipStage = _cfg.IsSkipped(_stage);
if (_skipStage)
{
Log.LogInfo((object)("MonoStages: " + _stage + " is in SkipStages, leaving it in colour"));
}
else if (_on)
{
RecolourStage(bg, "loaded");
}
}
}
private void Rebuild(string why)
{
string text = _look.Signature();
ApplyConfig();
if (_mono.Active)
{
_mono.Undo();
}
if (_look.Signature() != text)
{
_tex.Clear();
}
_skipStage = _cfg.IsSkipped(_stage);
if (!_skipStage)
{
RecolourStage(_bg, why);
}
}
private void RecolourStage(MonoBehaviour bg, string why)
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
_tex.BeginPass();
_mono.Begin(((Component)bg).gameObject, _llb.GameAssembly);
_mono.Pass();
_mono.Environment();
_mono.Enforce();
int num = _tex.PurgeUnused();
_nextScan = Time.unscaledTime + _cfg.RescanSeconds.Value;
float num2 = Time.realtimeSinceStartup - realtimeSinceStartup;
Log.LogInfo((object)string.Format("{0}: {1} ({2}) -> {3} materials, {4} textures converted, {5} reused, {6} left alone, {7} stage scripts, {8} particle systems in {9:0.00}s (textures {10:0.00}s){11}", "MonoStages", _stage, why, _mono.Materials, _tex.Converted, _tex.Reused, _tex.SkippedCount, _mono.Components, _mono.Particles, num2, _tex.Seconds, (num > 0) ? (", freed " + num + " from the previous stage") : ""));
}
private void DoDump()
{
if ((Object)(object)_bg == (Object)null)
{
Log.LogInfo((object)"MonoStages: no stage loaded, nothing to dump");
return;
}
try
{
string text = Dump.Write(Paths.BepInExRootPath, _stage, ((Component)_bg).gameObject, _tex, _opt);
Log.LogInfo((object)("MonoStages: stage dump written to " + text));
}
catch (Exception ex)
{
Log.LogError((object)("MonoStages: dump failed: " + ex));
}
}
private void Warn(string msg)
{
if (_warnings++ < 20)
{
Log.LogWarning((object)("MonoStages: " + msg));
}
}
private void OnDestroy()
{
try
{
if (_mono != null && _mono.Active)
{
_mono.Undo();
}
}
catch
{
}
}
}
internal sealed class Settings
{
public readonly ConfigEntry<bool> Enabled;
public readonly ConfigEntry<string> Preset;
public readonly ConfigEntry<KeyCode> ToggleKey;
public readonly ConfigEntry<string> SkipStages;
public readonly ConfigEntry<float> Brightness;
public readonly ConfigEntry<float> Contrast;
public readonly ConfigEntry<float> TintStrength;
public readonly ConfigEntry<float> Saturation;
public readonly ConfigEntry<string> TintColor;
public readonly ConfigEntry<bool> Lights;
public readonly ConfigEntry<bool> FogAndAmbient;
public readonly ConfigEntry<bool> Particles;
public readonly ConfigEntry<bool> VertexColors;
public readonly ConfigEntry<bool> Lightmaps;
public readonly ConfigEntry<bool> StageScripts;
public readonly ConfigEntry<bool> Sprites;
public readonly ConfigEntry<bool> CompressTextures;
public readonly ConfigEntry<int> MaxTextureSize;
public readonly ConfigEntry<float> RescanSeconds;
public readonly ConfigEntry<string> ExtraColorProperties;
public readonly ConfigEntry<string> SkipTextureProperties;
public Settings(ConfigFile cfg)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Expected O, but got Unknown
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Expected O, but got Unknown
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Expected O, but got Unknown
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Expected O, but got Unknown
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_019a: Expected O, but got Unknown
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02d4: Expected O, but got Unknown
Enabled = cfg.Bind<bool>("General", "Enabled", true, "Turn stages mono. The toggle key flips this while playing.");
Preset = cfg.Bind<string>("General", "Preset", "Mono", new ConfigDescription("Mono = black & white with a hint of purple (matches NeonHUD). Greyscale = plain black & white. Noir = darker, higher contrast (players and ball pop the most). Muted = mostly grey with a little colour left. Custom = use the [Custom look] numbers.", (AcceptableValueBase)(object)new AcceptableValueList<string>(MonoLook.PresetNames), new object[0]));
ToggleKey = cfg.Bind<KeyCode>("General", "ToggleKey", (KeyCode)285, "Toggle mono stages on/off (also reloads this file). Shift + this key writes a diagnostic dump of the current stage.");
SkipStages = cfg.Bind<string>("General", "SkipStages", "", "Comma-separated stages to leave in colour, e.g. \"STADIUM, ROOM21_2D\". Names: OUTSKIRTS, SEWERS, JUNKTOWN, CONSTRUCTION, FACTORY, SUBWAY, STADIUM, STREETS, POOL, ROOM21, BALLROOM, and the *_2D versions.");
Brightness = cfg.Bind<float>("Custom look", "Brightness", 0.85f, new ConfigDescription("Overall stage brightness. Below 1 pushes the stage back so players and the ball stand out.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1.5f), new object[0]));
Contrast = cfg.Bind<float>("Custom look", "Contrast", 1.1f, new ConfigDescription("1 = unchanged.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 2f), new object[0]));
TintColor = cfg.Bind<string>("Custom look", "TintColor", "#8B5CF6", "Hex colour of the tint (#8B5CF6 = NeonHUD purple).");
TintStrength = cfg.Bind<float>("Custom look", "TintStrength", 0.2f, new ConfigDescription("0 = pure grey. The tint fades out toward white so highlights stay clean.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
Saturation = cfg.Bind<float>("Custom look", "Saturation", 0f, new ConfigDescription("How much of the original colour to keep. 0 = fully mono.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
Lights = cfg.Bind<bool>("What to recolour", "Lights", true, "Make the stage's lights white/grey. Characters are lit by these, so this also removes coloured light from them.");
FogAndAmbient = cfg.Bind<bool>("What to recolour", "FogAndAmbient", true, "Grey fog, ambient light and camera background colour.");
Particles = cfg.Bind<bool>("What to recolour", "Particles", true, "Stage particle effects (dust, steam, sparks).");
VertexColors = cfg.Bind<bool>("What to recolour", "VertexColors", true, "Colours painted into stage meshes (only where the game allows reading the mesh).");
Lightmaps = cfg.Bind<bool>("What to recolour", "Lightmaps", true, "Baked stage lighting.");
StageScripts = cfg.Bind<bool>("What to recolour", "StageScripts", true, "Colours stored in the stage's own scripts (eclipse tints, blinking signs, texture cycles, 2D stage frames).");
Sprites = cfg.Bind<bool>("What to recolour", "Sprites", true, "Sprite-based stage decorations.");
CompressTextures = cfg.Bind<bool>("Performance", "CompressTextures", true, "Compress the mono textures (about 4x less memory, slightly longer stage load).");
MaxTextureSize = cfg.Bind<int>("Performance", "MaxTextureSize", 4096, "Textures larger than this are left alone.");
RescanSeconds = cfg.Bind<float>("Performance", "RescanSeconds", 1f, new ConfigDescription("How often to look for stage objects created after load.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 10f), new object[0]));
ExtraColorProperties = cfg.Bind<string>("Advanced", "ExtraColorProperties", "", "Extra material colour properties to recolour (comma-separated, e.g. \"_Color4,_WindowColor\"). The diagnostic dump lists shaders on the current stage.");
SkipTextureProperties = cfg.Bind<string>("Advanced", "SkipTextureProperties", "", "Material texture slots to leave alone (comma-separated), if something looks wrong.");
}
public void ApplyTo(MonoLook look)
{
if (!look.ApplyPreset(Preset.Value))
{
look.Brightness = Brightness.Value;
look.Contrast = Contrast.Value;
look.TintStrength = TintStrength.Value;
look.Saturation = Saturation.Value;
look.SetTint(TintColor.Value);
}
look.Build();
}
public void ApplyTo(Options opt, TextureGreyer tex)
{
opt.Lights = Lights.Value;
opt.Fog = FogAndAmbient.Value;
opt.Particles = Particles.Value;
opt.VertexColors = VertexColors.Value;
opt.Lightmaps = Lightmaps.Value;
opt.ScriptFields = StageScripts.Value;
opt.Sprites = Sprites.Value;
foreach (string item in Split(ExtraColorProperties.Value))
{
if (!opt.ColorProps.Contains(item))
{
opt.ColorProps.Add(item);
}
}
opt.SkipTexProps.Clear();
opt.SkipTexProps.AddRange(Split(SkipTextureProperties.Value));
tex.Compress = CompressTextures.Value;
tex.MaxSize = MaxTextureSize.Value;
}
public bool IsSkipped(string stage)
{
foreach (string item in Split(SkipStages.Value))
{
if (string.Equals(item, stage, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
private static List<string> Split(string v)
{
List<string> list = new List<string>();
if (string.IsNullOrEmpty(v))
{
return list;
}
string[] array = v.Split(new char[1] { ',' });
for (int i = 0; i < array.Length; i++)
{
string text = array[i].Trim();
if (text.Length > 0)
{
list.Add(text);
}
}
return list;
}
}
internal sealed class Options
{
public bool Lights = true;
public bool Fog = true;
public bool Particles = true;
public bool VertexColors = true;
public bool Lightmaps = true;
public bool ScriptFields = true;
public bool Sprites = true;
public readonly List<string> ColorProps = new List<string>
{
"_Color", "_LitColor", "_ShadowColor", "_EffectColor", "_OutlineColor", "_EmissionColor", "_TintColor", "_RimColor", "_SpecColor", "_BaseColor",
"_MainColor", "_Color1", "_Color2", "_Color3", "_ColorA", "_ColorB", "_TopColor", "_BottomColor", "_SkyTint", "_GroundColor",
"_HighlightColor", "_GlowColor", "_AmbientColor", "_SecondaryColor", "_FogColor", "_ReflectColor", "_EdgeColor", "_LineColor", "_FresnelColor"
};
public readonly List<string> FallbackTexProps = new List<string>
{
"_MainTex", "_DetailAlbedoMap", "_EmissionMap", "_AlbedoMap", "_PaternTex", "_Ramp", "_RampTex", "_ShadowTex", "_LitTex", "_Tex",
"_MatCap", "_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex"
};
public readonly List<string> SkipTexProps = new List<string>();
}
internal sealed class StageMono
{
private sealed class RefEq : IEqualityComparer<object>
{
public static readonly RefEq Instance = new RefEq();
public new bool Equals(object a, object b)
{
return a == b;
}
public int GetHashCode(object o)
{
return RuntimeHelpers.GetHashCode(o);
}
}
private readonly MonoLook _look;
private readonly TextureGreyer _tex;
private readonly Options _opt;
private readonly Action<string> _warn;
private readonly List<Action> _undo = new List<Action>();
private readonly HashSet<int> _doneObjects = new HashSet<int>();
private readonly Dictionary<string, Dictionary<string, Color[]>> _matColors = new Dictionary<string, Dictionary<string, Color[]>>();
private readonly HashSet<object> _doneRefs = new HashSet<object>(RefEq.Instance);
private readonly Dictionary<int, Mesh> _meshCopies = new Dictionary<int, Mesh>();
private readonly List<Light> _lights = new List<Light>();
private readonly Dictionary<int, Color> _lightOrig = new Dictionary<int, Color>();
private readonly Dictionary<int, Color> _camOrig = new Dictionary<int, Color>();
private readonly Dictionary<Type, FieldInfo[]> _fieldCache = new Dictionary<Type, FieldInfo[]>();
private Color _ambient;
private Color _sky;
private Color _equator;
private Color _ground;
private Color _fog;
private bool _envSaved;
private Texture _fogTexOrig;
private Assembly _gameAsm;
private bool _texPropApiMissing;
public int Materials;
public int Components;
public int Particles;
public int Meshes;
public GameObject Root { get; private set; }
public bool Active => Root != null;
public StageMono(MonoLook look, TextureGreyer tex, Options opt, Action<string> warn)
{
_look = look;
_tex = tex;
_opt = opt;
_warn = warn;
}
public void Begin(GameObject root, Assembly gameAsm)
{
Root = root;
_gameAsm = gameAsm;
Materials = (Components = (Particles = (Meshes = 0)));
}
public void Pass()
{
if ((Object)(object)Root == (Object)null)
{
return;
}
Renderer[] componentsInChildren = Root.GetComponentsInChildren<Renderer>(true);
foreach (Renderer r in componentsInChildren)
{
ProcessRenderer(r);
}
if (_opt.ScriptFields)
{
MonoBehaviour[] componentsInChildren2 = Root.GetComponentsInChildren<MonoBehaviour>(true);
foreach (MonoBehaviour mb in componentsInChildren2)
{
ProcessScript(mb);
}
}
if (_opt.Lights)
{
Light[] componentsInChildren3 = Root.GetComponentsInChildren<Light>(true);
foreach (Light l in componentsInChildren3)
{
AddLight(l);
}
}
if (_opt.Particles)
{
ParticleSystem[] componentsInChildren4 = Root.GetComponentsInChildren<ParticleSystem>(true);
foreach (ParticleSystem ps in componentsInChildren4)
{
ProcessParticles(ps);
}
}
}
public void Environment()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)RenderSettings.skybox != (Object)null)
{
ProcessMaterial(RenderSettings.skybox);
}
if (_opt.Lights && (Object)(object)Root != (Object)null)
{
Light[] array = Object.FindObjectsOfType<Light>();
foreach (Light val in array)
{
if ((Object)(object)val != (Object)null && ((Component)val).gameObject.scene == Root.scene)
{
AddLight(val);
}
}
}
if (!_opt.Lightmaps)
{
return;
}
LightmapData[] lightmaps = LightmapSettings.lightmaps;
if (lightmaps == null || lightmaps.Length == 0)
{
return;
}
Texture2D[] orig = (Texture2D[])(object)new Texture2D[lightmaps.Length];
bool flag = false;
for (int j = 0; j < lightmaps.Length; j++)
{
if (lightmaps[j] != null)
{
orig[j] = lightmaps[j].lightmapColor;
Texture2D val2 = _tex.Get(orig[j], TextureGreyer.Kind.Plain);
if ((Object)(object)val2 != (Object)null && (Object)(object)val2 != (Object)(object)orig[j])
{
lightmaps[j].lightmapColor = val2;
flag = true;
}
}
}
if (!flag)
{
return;
}
LightmapSettings.lightmaps = lightmaps;
_undo.Add(delegate
{
LightmapData[] lightmaps2 = LightmapSettings.lightmaps;
for (int k = 0; k < lightmaps2.Length && k < orig.Length; k++)
{
if (lightmaps2[k] != null && (Object)(object)orig[k] != (Object)null)
{
lightmaps2[k].lightmapColor = orig[k];
}
}
LightmapSettings.lightmaps = lightmaps2;
});
}
public void Enforce()
{
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: 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: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: 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_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
if (_opt.Fog)
{
if (!_envSaved)
{
_ambient = RenderSettings.ambientLight;
_sky = RenderSettings.ambientSkyColor;
_equator = RenderSettings.ambientEquatorColor;
_ground = RenderSettings.ambientGroundColor;
_fog = RenderSettings.fogColor;
_envSaved = true;
_fogTexOrig = Shader.GetGlobalTexture("_FogTexture");
}
RenderSettings.ambientLight = Grey(RenderSettings.ambientLight);
RenderSettings.ambientSkyColor = Grey(RenderSettings.ambientSkyColor);
RenderSettings.ambientEquatorColor = Grey(RenderSettings.ambientEquatorColor);
RenderSettings.ambientGroundColor = Grey(RenderSettings.ambientGroundColor);
RenderSettings.fogColor = Grey(RenderSettings.fogColor);
Texture globalTexture = Shader.GetGlobalTexture("_FogTexture");
Texture2D val = (Texture2D)(object)((globalTexture is Texture2D) ? globalTexture : null);
if ((Object)(object)val != (Object)null && !_tex.IsOutput((Texture)(object)val))
{
Texture2D val2 = _tex.Get(val, TextureGreyer.Kind.Plain);
if ((Object)(object)val2 != (Object)null)
{
Shader.SetGlobalTexture("_FogTexture", (Texture)(object)val2);
}
}
}
if (_opt.Lights)
{
for (int num = _lights.Count - 1; num >= 0; num--)
{
Light val3 = _lights[num];
if ((Object)(object)val3 == (Object)null)
{
_lights.RemoveAt(num);
}
else
{
Color color = val3.color;
if (!IsGrey(color))
{
val3.color = Grey(color);
}
}
}
}
if (!_opt.Fog)
{
return;
}
Camera[] allCameras = Camera.allCameras;
foreach (Camera val4 in allCameras)
{
if ((Object)(object)val4 == (Object)null)
{
continue;
}
Color backgroundColor = val4.backgroundColor;
if (!IsGrey(backgroundColor))
{
int instanceID = ((Object)val4).GetInstanceID();
if (!_camOrig.ContainsKey(instanceID))
{
_camOrig[instanceID] = backgroundColor;
}
val4.backgroundColor = Grey(backgroundColor);
}
}
}
public void Undo()
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011b: 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)
for (int num = _undo.Count - 1; num >= 0; num--)
{
try
{
_undo[num]();
}
catch
{
}
}
_undo.Clear();
foreach (Light light in _lights)
{
if ((Object)(object)light != (Object)null && _lightOrig.TryGetValue(((Object)light).GetInstanceID(), out var value))
{
light.color = value;
}
}
if (_camOrig.Count > 0)
{
Camera[] allCameras = Camera.allCameras;
foreach (Camera val in allCameras)
{
if ((Object)(object)val != (Object)null && _camOrig.TryGetValue(((Object)val).GetInstanceID(), out var value2))
{
val.backgroundColor = value2;
}
}
}
if (_envSaved)
{
RenderSettings.ambientLight = _ambient;
RenderSettings.ambientSkyColor = _sky;
RenderSettings.ambientEquatorColor = _equator;
RenderSettings.ambientGroundColor = _ground;
RenderSettings.fogColor = _fog;
if ((Object)(object)_fogTexOrig != (Object)null)
{
Shader.SetGlobalTexture("_FogTexture", _fogTexOrig);
}
}
foreach (Mesh value3 in _meshCopies.Values)
{
if ((Object)(object)value3 != (Object)null)
{
Object.Destroy((Object)(object)value3);
}
}
_meshCopies.Clear();
_lights.Clear();
_lightOrig.Clear();
_camOrig.Clear();
_doneObjects.Clear();
_matColors.Clear();
_doneRefs.Clear();
_envSaved = false;
_fogTexOrig = null;
Root = null;
}
private void ProcessRenderer(Renderer r)
{
if ((Object)(object)r == (Object)null)
{
return;
}
bool flag = _doneObjects.Add(((Object)r).GetInstanceID());
Material[] sharedMaterials = r.sharedMaterials;
if (sharedMaterials != null)
{
Material[] array = sharedMaterials;
foreach (Material m in array)
{
ProcessMaterial(m);
}
}
ParticleSystemRenderer val = (ParticleSystemRenderer)(object)((r is ParticleSystemRenderer) ? r : null);
if ((Object)(object)val != (Object)null && (Object)(object)val.trailMaterial != (Object)null)
{
ProcessMaterial(val.trailMaterial);
}
if (!flag)
{
return;
}
if (_opt.Sprites)
{
SpriteRenderer val2 = (SpriteRenderer)(object)((r is SpriteRenderer) ? r : null);
if ((Object)(object)val2 != (Object)null)
{
ProcessSprite(val2);
}
}
if (!_opt.VertexColors)
{
return;
}
SkinnedMeshRenderer smr = (SkinnedMeshRenderer)(object)((r is SkinnedMeshRenderer) ? r : null);
if ((Object)(object)smr != (Object)null)
{
Mesh val3 = MeshCopy(smr.sharedMesh);
if ((Object)(object)val3 != (Object)null)
{
Mesh orig = smr.sharedMesh;
smr.sharedMesh = val3;
_undo.Add(delegate
{
smr.sharedMesh = orig;
});
}
}
else
{
if (!(r is MeshRenderer))
{
return;
}
MeshFilter mf = ((Component)r).GetComponent<MeshFilter>();
if (!((Object)(object)mf != (Object)null))
{
return;
}
Mesh val4 = MeshCopy(mf.sharedMesh);
if ((Object)(object)val4 != (Object)null)
{
Mesh orig2 = mf.sharedMesh;
mf.sharedMesh = val4;
_undo.Add(delegate
{
mf.sharedMesh = orig2;
});
}
}
}
public void ProcessMaterial(Material m)
{
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
//IL_02de: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0314: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0306: Unknown result type (might be due to invalid IL or missing references)
//IL_0308: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_027d: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
//IL_029e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)m == (Object)null || !_doneObjects.Add(((Object)m).GetInstanceID()))
{
return;
}
Materials++;
string text = Filters.StripInstance(((Object)m).name);
Dictionary<string, Color[]> value = null;
bool flag = ((Object)m).name != text && _matColors.TryGetValue(text, out value);
if (!flag)
{
value = new Dictionary<string, Color[]>();
_matColors[text] = value;
}
foreach (string item in TextureProps(m))
{
if (Filters.IsDataName(item) || _opt.SkipTexProps.Contains(item))
{
continue;
}
Texture texture;
try
{
texture = m.GetTexture(item);
}
catch
{
continue;
}
Texture2D t2 = (Texture2D)(object)((texture is Texture2D) ? texture : null);
if ((Object)(object)t2 == (Object)null)
{
continue;
}
Texture2D val = _tex.Get(t2, TextureGreyer.Kind.Look);
if ((Object)(object)val == (Object)null)
{
continue;
}
string p = item;
if ((Object)(object)val == (Object)(object)t2)
{
Texture2D src = _tex.SourceOf((Texture)(object)t2);
if ((Object)(object)src != (Object)null)
{
_undo.Add(delegate
{
m.SetTexture(p, (Texture)(object)src);
});
}
}
else
{
m.SetTexture(item, (Texture)(object)val);
_undo.Add(delegate
{
m.SetTexture(p, (Texture)(object)t2);
});
}
}
foreach (string colorProp in _opt.ColorProps)
{
if (!m.HasProperty(colorProp))
{
continue;
}
Color c = m.GetColor(colorProp);
string p2 = colorProp;
if (flag && value.TryGetValue(colorProp, out var value2))
{
if (Same(c, value2[1]))
{
Color orig = value2[0];
_undo.Add(delegate
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
m.SetColor(p2, orig);
});
continue;
}
if (!Same(c, value2[0]))
{
continue;
}
}
Color val2 = Map(c);
if (!flag)
{
value[colorProp] = (Color[])(object)new Color[2] { c, val2 };
}
if (!Same(c, val2))
{
m.SetColor(colorProp, val2);
_undo.Add(delegate
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
m.SetColor(p2, c);
});
}
}
}
private IEnumerable<string> TextureProps(Material m)
{
if (!_texPropApiMissing)
{
string[] array = null;
try
{
array = Filters.TexturePropertyNames(m);
}
catch (MissingMethodException)
{
_texPropApiMissing = true;
}
if (array != null)
{
return array;
}
}
return _opt.FallbackTexProps;
}
private void ProcessSprite(SpriteRenderer sr)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: 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_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: 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_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: 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_015e: Unknown result type (might be due to invalid IL or missing references)
//IL_016f: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
Color c = sr.color;
Color val = Map(c);
if (!Same(c, val))
{
sr.color = val;
_undo.Add(delegate
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
sr.color = c;
});
}
Sprite s = sr.sprite;
if ((Object)(object)s == (Object)null || (Object)(object)s.texture == (Object)null)
{
return;
}
Texture2D val2 = _tex.Get(s.texture, TextureGreyer.Kind.Look);
if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)s.texture)
{
return;
}
try
{
Rect val3 = (s.packed ? s.textureRect : s.rect);
float x = s.pivot.x;
Rect rect = s.rect;
float num = x / ((Rect)(ref rect)).width;
float y = s.pivot.y;
rect = s.rect;
Vector2 val4 = default(Vector2);
((Vector2)(ref val4))..ctor(num, y / ((Rect)(ref rect)).height);
Sprite ns = Sprite.Create(val2, val3, val4, s.pixelsPerUnit, 0u, (SpriteMeshType)0, s.border);
((Object)ns).name = ((Object)s).name + " [mono]";
sr.sprite = ns;
_undo.Add(delegate
{
sr.sprite = s;
Object.Destroy((Object)(object)ns);
});
}
catch (Exception ex)
{
_warn("sprite " + ((Object)s).name + ": " + ex.Message);
}
}
private Mesh MeshCopy(Mesh mesh)
{
if ((Object)(object)mesh == (Object)null || !mesh.isReadable)
{
return null;
}
int instanceID = ((Object)mesh).GetInstanceID();
if (_meshCopies.TryGetValue(instanceID, out var value))
{
return value;
}
if (_meshCopies.ContainsValue(mesh))
{
return null;
}
Color32[] colors = mesh.colors32;
if (colors == null || colors.Length == 0)
{
_meshCopies[instanceID] = null;
return null;
}
value = Object.Instantiate<Mesh>(mesh);
((Object)value).name = ((Object)mesh).name + " [mono]";
for (int i = 0; i < colors.Length; i++)
{
_look.MapBytes(ref colors[i].r, ref colors[i].g, ref colors[i].b);
}
value.colors32 = colors;
_meshCopies[instanceID] = value;
Meshes++;
return value;
}
private void ProcessParticles(ParticleSystem ps)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: 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_011f: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)ps == (Object)null || !_doneObjects.Add(((Object)ps).GetInstanceID()))
{
return;
}
Particles++;
MainModule main = ps.main;
MinMaxGradient start = ((MainModule)(ref main)).startColor;
((MainModule)(ref main)).startColor = MapGradient(start);
_undo.Add(delegate
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
MainModule main2 = ps.main;
((MainModule)(ref main2)).startColor = start;
});
ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime;
if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
{
MinMaxGradient c0 = ((ColorOverLifetimeModule)(ref colorOverLifetime)).color;
((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MapGradient(c0);
_undo.Add(delegate
{
//IL_000b: 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)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
ColorOverLifetimeModule colorOverLifetime2 = ps.colorOverLifetime;
((ColorOverLifetimeModule)(ref colorOverLifetime2)).color = c0;
});
}
ColorBySpeedModule colorBySpeed = ps.colorBySpeed;
if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
{
MinMaxGradient c1 = ((ColorBySpeedModule)(ref colorBySpeed)).color;
((ColorBySpeedModule)(ref colorBySpeed)).color = MapGradient(c1);
_undo.Add(delegate
{
//IL_000b: 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)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
ColorBySpeedModule colorBySpeed2 = ps.colorBySpeed;
((ColorBySpeedModule)(ref colorBySpeed2)).color = c1;
});
}
}
private MinMaxGradient MapGradient(MinMaxGradient g)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Expected I4, but got Unknown
//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_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: 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_003f: 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)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: 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)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
ParticleSystemGradientMode mode = ((MinMaxGradient)(ref g)).mode;
switch ((int)mode)
{
case 0:
return new MinMaxGradient(Map(((MinMaxGradient)(ref g)).color));
case 2:
return new MinMaxGradient(Map(((MinMaxGradient)(ref g)).colorMin), Map(((MinMaxGradient)(ref g)).colorMax));
case 3:
return new MinMaxGradient(MappedGradient(((MinMaxGradient)(ref g)).gradientMin), MappedGradient(((MinMaxGradient)(ref g)).gradientMax));
case 4:
{
MinMaxGradient result = default(MinMaxGradient);
((MinMaxGradient)(ref result))..ctor(MappedGradient(((MinMaxGradient)(ref g)).gradient));
((MinMaxGradient)(ref result)).mode = (ParticleSystemGradientMode)4;
return result;
}
default:
return new MinMaxGradient(MappedGradient(((MinMaxGradient)(ref g)).gradient));
}
}
private Gradient MappedGradient(Gradient g)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0025: 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_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
if (g == null)
{
return null;
}
Gradient val = new Gradient();
GradientColorKey[] colorKeys = g.colorKeys;
for (int i = 0; i < colorKeys.Length; i++)
{
colorKeys[i].color = Map(colorKeys[i].color);
}
val.SetKeys(colorKeys, g.alphaKeys);
val.mode = g.mode;
return val;
}
private void AddLight(Light l)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)l == (Object)null) && _doneObjects.Add(((Object)l).GetInstanceID()))
{
_lights.Add(l);
_lightOrig[((Object)l).GetInstanceID()] = l.color;
}
}
private void ProcessScript(MonoBehaviour mb)
{
if ((Object)(object)mb == (Object)null)
{
return;
}
Type type = ((object)mb).GetType();
if ((object)type.Assembly != _gameAsm)
{
return;
}
string text = type.Namespace ?? "";
if (text.StartsWith("GameplayEntities") || text.StartsWith("LLScreen") || text.StartsWith("LLGUI") || text.StartsWith("LLHandlers"))
{
return;
}
bool flag = _doneObjects.Add(((Object)mb).GetInstanceID());
if (flag)
{
Components++;
}
try
{
Fields(mb, type, 0, !flag);
}
catch (Exception ex)
{
_warn(type.Name + ": " + ex.Message);
}
}
private FieldInfo[] FieldsOf(Type t)
{
if (_fieldCache.TryGetValue(t, out var value))
{
return value;
}
List<FieldInfo> list = new List<FieldInfo>();
Type type = t;
while ((object)type != null && (object)type.Assembly == _gameAsm)
{
FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
if (Relevant(fieldInfo.FieldType))
{
list.Add(fieldInfo);
}
}
type = type.BaseType;
}
value = list.ToArray();
_fieldCache[t] = value;
return value;
}
private bool Relevant(Type ft)
{
if (ft.IsPrimitive || ft.IsEnum || (object)ft == typeof(string))
{
return false;
}
if (ft.IsArray)
{
return Relevant(ft.GetElementType());
}
if ((object)ft == typeof(Color) || (object)ft == typeof(Color32) || (object)ft == typeof(Gradient))
{
return true;
}
if (typeof(Texture).IsAssignableFrom(ft) || typeof(Material).IsAssignableFrom(ft) || typeof(Renderer).IsAssignableFrom(ft) || typeof(Light).IsAssignableFrom(ft))
{
return true;
}
if ((object)ft.Assembly == _gameAsm && !typeof(Object).IsAssignableFrom(ft))
{
return true;
}
return false;
}
private void Fields(object target, Type t, int depth, bool refsOnly)
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: 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_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_031d: Expected O, but got Unknown
//IL_020c: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
//IL_06c2: Expected O, but got Unknown
//IL_0380: Unknown result type (might be due to invalid IL or missing references)
//IL_0385: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_071b: Unknown result type (might be due to invalid IL or missing references)
//IL_0725: Expected O, but got Unknown
//IL_07ba: Unknown result type (might be due to invalid IL or missing references)
//IL_07c4: Expected O, but got Unknown
FieldInfo[] array = FieldsOf(t);
Texture2D tex2 = default(Texture2D);
foreach (FieldInfo f in array)
{
Type fieldType = f.FieldType;
object value = f.GetValue(target);
if (value == null || (refsOnly && (fieldType.IsValueType || (!fieldType.IsArray && (object)fieldType.Assembly == _gameAsm))))
{
continue;
}
if ((object)fieldType == typeof(Color))
{
Color c = (Color)value;
Color val = Map(c);
if (!Same(c, val))
{
f.SetValue(target, val);
_undo.Add(delegate
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
f.SetValue(target, c);
});
}
}
else if ((object)fieldType == typeof(Color32))
{
Color32 c2 = (Color32)value;
Color32 val2 = Map32(c2);
f.SetValue(target, val2);
_undo.Add(delegate
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
f.SetValue(target, c2);
});
}
else if ((object)fieldType == typeof(Color[]))
{
Color[] a = (Color[])value;
if (_doneRefs.Add(a))
{
Color[] orig = (Color[])a.Clone();
for (int num = 0; num < a.Length; num++)
{
a[num] = Map(a[num]);
}
_undo.Add(delegate
{
Array.Copy(orig, a, Math.Min(orig.Length, a.Length));
});
}
}
else if ((object)fieldType == typeof(Color32[]))
{
Color32[] a2 = (Color32[])value;
if (_doneRefs.Add(a2))
{
Color32[] orig2 = (Color32[])a2.Clone();
for (int num2 = 0; num2 < a2.Length; num2++)
{
a2[num2] = Map32(a2[num2]);
}
_undo.Add(delegate
{
Array.Copy(orig2, a2, Math.Min(orig2.Length, a2.Length));
});
}
}
else if ((object)fieldType == typeof(Gradient))
{
Gradient g = (Gradient)value;
if (_doneRefs.Add(g))
{
GradientColorKey[] colorKeys = g.colorKeys;
GradientColorKey[] orig3 = (GradientColorKey[])colorKeys.Clone();
GradientAlphaKey[] alpha = g.alphaKeys;
for (int num3 = 0; num3 < colorKeys.Length; num3++)
{
colorKeys[num3].color = Map(colorKeys[num3].color);
}
g.SetKeys(colorKeys, alpha);
_undo.Add(delegate
{
g.SetKeys(orig3, alpha);
});
}
}
else if (typeof(Texture).IsAssignableFrom(fieldType))
{
Texture2D tex = (Texture2D)((value is Texture2D) ? value : null);
if ((Object)(object)tex == (Object)null || Filters.IsDataName(f.Name))
{
continue;
}
Texture2D val3 = _tex.Get(tex, TextureGreyer.Kind.Readable);
if ((Object)(object)val3 == (Object)null || !fieldType.IsInstanceOfType(val3))
{
continue;
}
if ((Object)(object)val3 == (Object)(object)tex)
{
if (refsOnly)
{
continue;
}
Texture2D src = _tex.SourceOf((Texture)(object)tex);
if ((Object)(object)src != (Object)null)
{
_undo.Add(delegate
{
f.SetValue(target, src);
});
}
}
else
{
f.SetValue(target, val3);
_undo.Add(delegate
{
f.SetValue(target, tex);
});
}
}
else if (fieldType.IsArray && typeof(Texture).IsAssignableFrom(fieldType.GetElementType()))
{
Array a3 = (Array)value;
if (Filters.IsDataName(f.Name) || !_doneRefs.Add(a3))
{
continue;
}
for (int num4 = 0; num4 < a3.Length; num4++)
{
ref Texture2D reference = ref tex2;
object? value2 = a3.GetValue(num4);
reference = (Texture2D)((value2 is Texture2D) ? value2 : null);
if ((Object)(object)tex2 == (Object)null)
{
continue;
}
Texture2D val4 = _tex.Get(tex2, TextureGreyer.Kind.Readable);
if ((Object)(object)val4 == (Object)null)
{
continue;
}
int idx = num4;
if ((Object)(object)val4 == (Object)(object)tex2)
{
Texture2D src2 = _tex.SourceOf((Texture)(object)tex2);
if ((Object)(object)src2 != (Object)null)
{
_undo.Add(delegate
{
a3.SetValue(src2, idx);
});
}
}
else
{
a3.SetValue(val4, num4);
_undo.Add(delegate
{
a3.SetValue(tex2, idx);
});
}
}
}
else if (typeof(Material).IsAssignableFrom(fieldType))
{
ProcessMaterial((Material)value);
}
else if ((object)fieldType == typeof(Material[]))
{
Material[] array2 = (Material[])value;
foreach (Material m in array2)
{
ProcessMaterial(m);
}
}
else if (typeof(Renderer).IsAssignableFrom(fieldType))
{
ProcessRenderer((Renderer)value);
}
else if (fieldType.IsArray && typeof(Renderer).IsAssignableFrom(fieldType.GetElementType()))
{
foreach (object item in (Array)value)
{
ProcessRenderer((Renderer)((item is Renderer) ? item : null));
}
}
else if (typeof(Light).IsAssignableFrom(fieldType))
{
if (_opt.Lights)
{
AddLight((Light)value);
}
}
else if (fieldType.IsArray && typeof(Light).IsAssignableFrom(fieldType.GetElementType()))
{
if (!_opt.Lights)
{
continue;
}
foreach (object item2 in (Array)value)
{
AddLight((Light)((item2 is Light) ? item2 : null));
}
}
else if (depth < 3 && fieldType.IsValueType)
{
object before = f.GetValue(target);
Fields(value, fieldType, depth + 1, refsOnly: false);
f.SetValue(target, value);
_undo.Add(delegate
{
f.SetValue(target, before);
});
}
else if (depth < 3 && fieldType.IsArray && fieldType.GetElementType().IsValueType && (object)fieldType.GetElementType().Assembly == _gameAsm)
{
Array a4 = (Array)value;
if (!_doneRefs.Add(a4))
{
continue;
}
Type elementType = fieldType.GetElementType();
for (int num6 = 0; num6 < a4.Length; num6++)
{
object before2 = a4.GetValue(num6);
object value3 = a4.GetValue(num6);
Fields(value3, elementType, depth + 1, refsOnly: false);
a4.SetValue(value3, num6);
int idx2 = num6;
_undo.Add(delegate
{
a4.SetValue(before2, idx2);
});
}
}
else if (depth < 3 && !fieldType.IsValueType && !fieldType.IsArray && (object)fieldType.Assembly == _gameAsm && _doneRefs.Add(value))
{
Fields(value, value.GetType(), depth + 1, refsOnly: false);
}
}
}
private Color Map(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
float r = c.r;
float g = c.g;
float b = c.b;
_look.Map(ref r, ref g, ref b);
return new Color(r, g, b, c.a);
}
private Color32 Map32(Color32 c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
byte r = c.r;
byte g = c.g;
byte b = c.b;
_look.MapBytes(ref r, ref g, ref b);
return new Color32(r, g, b, c.a);
}
private static Color Grey(Color c)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: 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_0023: 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)
float r = c.r;
float g = c.g;
float b = c.b;
MonoLook.Grey(ref r, ref g, ref b);
return new Color(r, g, b, c.a);
}
private static bool IsGrey(Color c)
{
//IL_0000: 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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
if (Math.Abs(c.r - c.g) < 0.0001f)
{
return Math.Abs(c.g - c.b) < 0.0001f;
}
return false;
}
private static bool Same(Color a, Color b)
{
//IL_0000: 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_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: 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)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (Math.Abs(a.r - b.r) < 1E-05f && Math.Abs(a.g - b.g) < 1E-05f && Math.Abs(a.b - b.b) < 1E-05f)
{
return Math.Abs(a.a - b.a) < 1E-05f;
}
return false;
}
}
internal sealed class TextureGreyer
{
public enum Kind
{
Look,
Readable,
Plain
}
private readonly MonoLook _look;
private readonly Dictionary<long, Texture2D> _cache = new Dictionary<long, Texture2D>();
private readonly HashSet<int> _outputs = new HashSet<int>();
private readonly Dictionary<int, long> _outputKey = new Dictionary<int, long>();
private readonly Dictionary<int, Texture2D> _outputSrc = new Dictionary<int, Texture2D>();
private readonly HashSet<long> _usedThisPass = new HashSet<long>();
private readonly Dictionary<int, string> _skipped = new Dictionary<int, string>();
public bool Compress = true;
public int CompressMinSize = 256;
public int MaxSize = 4096;
public int Converted;
public int Reused;
public int SkippedCount;
public double Seconds;
public int CacheCount => _cache.Count;
public TextureGreyer(MonoLook look)
{
_look = look;
}
public bool IsOutput(Texture t)
{
if ((Object)(object)t != (Object)null)
{
return _outputs.Contains(((Object)t).GetInstanceID());
}
return false;
}
public Texture2D SourceOf(Texture t)
{
if (!((Object)(object)t != (Object)null) || !_outputSrc.TryGetValue(((Object)t).GetInstanceID(), out var value))
{
return null;
}
return value;
}
public string SkipReason(Texture2D t)
{
if (!((Object)(object)t != (Object)null) || !_skipped.TryGetValue(((Object)t).GetInstanceID(), out var value))
{
return null;
}
return value;
}
public void BeginPass()
{
_usedThisPass.Clear();
Converted = (Reused = (SkippedCount = 0));
Seconds = 0.0;
}
public Texture2D Get(Texture2D src, Kind kind)
{
if ((Object)(object)src == (Object)null)
{
return null;
}
int instanceID = ((Object)src).GetInstanceID();
if (_outputKey.TryGetValue(instanceID, out var value))
{
_usedThisPass.Add(value);
return src;
}
long num = ((long)instanceID << 2) | (long)kind;
if (_cache.TryGetValue(num, out var value2) && (Object)(object)value2 != (Object)null)
{
_usedThisPass.Add(num);
Reused++;
return value2;
}
if (_skipped.ContainsKey(instanceID))
{
SkippedCount++;
return null;
}
string text = WhySkip(src);
if (text != null)
{
_skipped[instanceID] = text;
SkippedCount++;
return null;
}
float realtimeSinceStartup = Time.realtimeSinceStartup;
Texture2D val = null;
try
{
val = Convert(src, kind);
}
catch (Exception ex)
{
_skipped[instanceID] = "conversion failed: " + ex.Message;
SkippedCount++;
return null;
}
finally
{
Seconds += Time.realtimeSinceStartup - realtimeSinceStartup;
}
if ((Object)(object)val == (Object)null)
{
_skipped[instanceID] = "conversion failed";
SkippedCount++;
return null;
}
_cache[num] = val;
_outputs.Add(((Object)val).GetInstanceID());
_outputKey[((Object)val).GetInstanceID()] = num;
_outputSrc[((Object)val).GetInstanceID()] = src;
_usedThisPass.Add(num);
Converted++;
return val;
}
private string WhySkip(Texture2D t)
{
//IL_0035: 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)
int width = ((Texture)t).width;
int height = ((Texture)t).height;
if (width <= 0 || height <= 0)
{
return "empty";
}
if (width > MaxSize || height > MaxSize)
{
return "larger than MaxTextureSize";
}
string text = ((object)t.format/*cast due to .constrained prefix*/).ToString();
switch (text)
{
default:
if (!text.StartsWith("BC4") && !text.StartsWith("BC5") && !text.StartsWith("BC6H") && !text.StartsWith("EAC_R") && !text.Contains("Half") && !text.Contains("Float"))
{
if (Filters.IsDataName(((Object)t).name))
{
return "looks like a data texture (" + ((Object)t).name + ")";
}
return null;
}
goto case "Alpha8";
case "Alpha8":
case "R8":
case "R16":
case "RHalf":
case "RFloat":
case "RG16":
case "RGHalf":
case "RGFloat":
return "data/HDR format " + text;
}
}
private Texture2D Convert(Texture2D src, Kind kind)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Expected O, but got Unknown
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: 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)
int width = ((Texture)src).width;
int height = ((Texture)src).height;
bool flag = src.mipmapCount > 1;
RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
RenderTexture active = RenderTexture.active;
Texture2D val;
try
{
Graphics.Blit((Texture)(object)src, temporary);
RenderTexture.active = temporary;
val = new Texture2D(width, height, (TextureFormat)4, flag);
val.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0, false);
}
finally
{
RenderTexture.active = active;
RenderTexture.ReleaseTemporary(temporary);
}
Color32[] pixels = val.GetPixels32();
if (kind == Kind.Plain)
{
for (int i = 0; i < pixels.Length; i++)
{
MonoLook.GreyBytes(ref pixels[i].r, ref pixels[i].g, ref pixels[i].b);
}
}
else
{
for (int j = 0; j < pixels.Length; j++)
{
_look.MapBytes(ref pixels[j].r, ref pixels[j].g, ref pixels[j].b);
}
}
val.SetPixels32(pixels);
((Object)val).name = ((Object)src).name + " [mono]";
((Texture)val).wrapModeU = ((Texture)src).wrapModeU;
((Texture)val).wrapModeV = ((Texture)src).wrapModeV;
((Texture)val).filterMode = ((Texture)src).filterMode;
((Texture)val).anisoLevel = ((Texture)src).anisoLevel;
((Texture)val).mipMapBias = ((Texture)src).mipMapBias;
((Object)val).hideFlags = (HideFlags)32;
bool flag2 = kind == Kind.Readable;
if (!flag2 && Compress && width >= CompressMinSize && height >= CompressMinSize && width % 4 == 0 && height % 4 == 0)
{
val.Apply(flag, false);
val.Compress(false);
val.Apply(false, true);
}
else
{
val.Apply(flag, !flag2);
}
return val;
}
public int PurgeUnused()
{
List<long> list = new List<long>();
foreach (KeyValuePair<long, Texture2D> item in _cache)
{
if (!_usedThisPass.Contains(item.Key))
{
list.Add(item.Key);
}
}
foreach (long item2 in list)
{
Texture2D val = _cache[item2];
_cache.Remove(item2);
if ((Object)(object)val != (Object)null)
{
int instanceID = ((Object)val).GetInstanceID();
_outputs.Remove(instanceID);
_outputKey.Remove(instanceID);
_outputSrc.Remove(instanceID);
Object.Destroy((Object)(object)val);
}
}
return list.Count;
}
public void Clear()
{
foreach (Texture2D value in _cache.Values)
{
if ((Object)(object)value != (Object)null)
{
Object.Destroy((Object)(object)value);
}
}
_cache.Clear();
_outputs.Clear();
_outputKey.Clear();
_outputSrc.Clear();
_usedThisPass.Clear();
_skipped.Clear();
}
}
internal static class Filters
{
private static readonly string[] DataWords = new string[23]
{
"bump", "normal", "nrm", "mask", "noise", "flow", "disp", "height", "parallax", "occlusion",
"metallic", "gloss", "rough", "dissolve", "distort", "cutout", "depth", "lightmap", "shadowmask", "blink",
"alpha", "grab", "camera"
};
public static bool IsDataName(string name)
{
if (string.IsNullOrEmpty(name))
{
return false;
}
string text = name.ToLowerInvariant();
string[] dataWords = DataWords;
foreach (string value in dataWords)
{
if (text.Contains(value))
{
return true;
}
}
if (!text.EndsWith("_n"))
{
return text.EndsWith("_nm");
}
return true;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static string[] TexturePropertyNames(Material m)
{
return m.GetTexturePropertyNames();
}
public static string StripInstance(string name)
{
if (name == null)
{
return "";
}
while (name.EndsWith(" (Instance)"))
{
name = name.Substring(0, name.Length - " (Instance)".Length);
}
return name;
}
}