using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CSS DOWNLOAD CONTENT MOD")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CSS DOWNLOAD CONTENT MOD")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("71229441-9a33-4100-abca-b9aa0805843f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CSS_DOWNLOAD_CONTENT_MOD;
public class EmoModelMarker : MonoBehaviour
{
}
[BepInPlugin("com.example.CSS_DOWNLOAD_CONTENT_MOD", "CSS_DOWNLOAD_CONTENT_MOD", "1.4.888")]
public class EmoTexturePlugin : BaseUnityPlugin
{
public const string PluginGuid = "com.example.CSS_DOWNLOAD_CONTENT_MOD";
public const string PluginName = "CSS_DOWNLOAD_CONTENT_MOD";
public const string PluginVersion = "1.4.888";
private ConfigFile _settings;
private ConfigEntry<string> _textureFileName;
private ConfigEntry<float> _materialChance;
private ConfigEntry<float> _uiChance;
private ConfigEntry<float> _scanInterval;
private ConfigEntry<string> _textureProperties;
private ConfigEntry<bool> _skipTextMaterials;
private ConfigEntry<bool> _blindingLight;
private ConfigEntry<float> _directionalIntensity;
private ConfigEntry<float> _tilingMultiplier;
private ConfigEntry<string> _bundleFileName;
private ConfigEntry<float> _modelChance;
private ConfigEntry<float> _modelScaleMultiplier;
private ConfigEntry<float> _minObjectSize;
private ConfigEntry<float> _maxObjectSize;
private ConfigEntry<bool> _includeSkinned;
private ConfigEntry<bool> _recolorModels;
private ConfigEntry<string> _modelColorHex;
private ConfigEntry<float> _modelEmission;
private ConfigEntry<bool> _showErrorText;
private ConfigEntry<string> _errorText;
private ConfigEntry<string> _errorFontFileName;
private ConfigEntry<int> _errorFontSize;
private ConfigEntry<float> _errorBlinkInterval;
private Font _errorFont;
private GUIStyle _errorStyle;
private Texture2D _emoTexture;
private Sprite _emoSprite;
private string[] _albedoProperties;
private AssetBundle _bundle;
private readonly List<GameObject> _modelPrefabs = new List<GameObject>();
private readonly HashSet<int> _rolledMaterials = new HashSet<int>();
private readonly HashSet<int> _rolledSpriteRenderers = new HashSet<int>();
private readonly HashSet<int> _rolledUi = new HashSet<int>();
private readonly HashSet<int> _rolledModelRenderers = new HashSet<int>();
private readonly Dictionary<int, bool> _ownModelCache = new Dictionary<int, bool>();
private readonly List<Material> _materialBuffer = new List<Material>();
private Material _darkSkybox;
private float _timer;
private bool _scanRequested = true;
private void Awake()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Expected O, but got Unknown
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Expected O, but got Unknown
//IL_0191: Unknown result type (might be due to invalid IL or missing references)
//IL_019b: Expected O, but got Unknown
//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
//IL_01d9: Expected O, but got Unknown
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_023c: Expected O, but got Unknown
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Expected O, but got Unknown
//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Expected O, but got Unknown
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f6: Expected O, but got Unknown
//IL_0391: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Expected O, but got Unknown
//IL_0433: Unknown result type (might be due to invalid IL or missing references)
//IL_043d: Expected O, but got Unknown
//IL_0471: Unknown result type (might be due to invalid IL or missing references)
//IL_047b: Expected O, but got Unknown
_settings = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.example.CSS_DOWNLOAD_CONTENT_MOD.cfg"), true);
_textureFileName = _settings.Bind<string>("General", "TextureFileName", "emotexture.jpg", "Я не придумал что сюда написать но да.");
_materialChance = _settings.Bind<float>("Chances", "MaterialChance", 0.5f, new ConfigDescription("Chance (0-1) that a scene material gets the texture -- русская рулетка.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
_uiChance = _settings.Bind<float>("Chances", "UiChance", 0.1f, new ConfigDescription("Chance (0-1) that a UI Image / RawImage gets the texture.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
_scanInterval = _settings.Bind<float>("General", "ScanIntervalSeconds", 3f, new ConfigDescription("How often (seconds) to look for new materials / UI elements. Higher = cheaper.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 60f), Array.Empty<object>()));
_textureProperties = _settings.Bind<string>("General", "TextureProperties", "_MainTex,_BaseMap,_BaseColorMap,_BaseTex,_Albedo,_AlbedoMap,_DiffuseMap,_ColorMap", "Короче вся херня");
_skipTextMaterials = _settings.Bind<bool>("General", "SkipTextMaterials", true, "Skip TextMeshPro -- Скип Текстыыыыыы .");
_blindingLight = _settings.Bind<bool>("Lighting", "BlindingLight", true, "Skybox exposure -> 0, all Directional Lights -> white with high intensity.");
_directionalIntensity = _settings.Bind<float>("Lighting", "DirectionalIntensity", 2f, new ConfigDescription("Intensity set on every Directional Light.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>()));
_tilingMultiplier = _settings.Bind<float>("Texture", "TilingMultiplier", 3f, new ConfigDescription("Tiling (X and Y) of the texture is multiplied by this. 3 = emotexture repeats 3x3 times.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 20f), Array.Empty<object>()));
_bundleFileName = _settings.Bind<string>("Models", "BundleFileName", "emomodels", "AssetBundle file (built with Tools > Emo Mod > Build Bundle From Selection). Looked up next to the DLL, then anywhere in BepInEx/plugins.");
_modelChance = _settings.Bind<float>("Models", "ModelChance", 0.1f, new ConfigDescription("Chance (0-1) that a MeshRenderer is replaced by a random model from the bundle.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
_modelScaleMultiplier = _settings.Bind<float>("Models", "ModelScaleMultiplier", 1f, new ConfigDescription("The model is fitted to the size of the original object, then multiplied by this.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 20f), Array.Empty<object>()));
_minObjectSize = _settings.Bind<float>("Models", "MinObjectSize", 0.1f, new ConfigDescription("Objects whose largest side (world units) is smaller than this are never replaced.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
_maxObjectSize = _settings.Bind<float>("Models", "MaxObjectSize", 20f, new ConfigDescription("Objects whose largest side is bigger than this (floors, walls, terrain) are never replaced.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 1000f), Array.Empty<object>()));
_includeSkinned = _settings.Bind<bool>("Models", "IncludeSkinnedMeshes", false, "Also replace SkinnedMeshRenderer. The model is static and just follows the object.");
_recolorModels = _settings.Bind<bool>("Models", "RecolorModels", true, "Recolor every material of the bundle models .");
_modelColorHex = _settings.Bind<string>("Models", "ModelColor", "FF0000", "Hex RGB color applied to bundle models, without '#'.");
_modelEmission = _settings.Bind<float>("Models", "ModelEmission", 5f, new ConfigDescription("Emission color = ModelColor multiplied by this value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>()));
_showErrorText = _settings.Bind<bool>("UI", "ShowErrorText", true, "Show the yellow text in the top-left corner of the screen.");
_errorText = _settings.Bind<string>("UI", "ErrorText", "Something is causing script errors.", "Text shown in the top-left corner.");
_errorFontFileName = _settings.Bind<string>("UI", "FontFileName", "*VCR*OSD*.ttf", " ");
_errorFontSize = _settings.Bind<int>("UI", "FontSize", 24, new ConfigDescription("Font size at 1080p height; scales with screen height. == прикол - https://youtu.be/hyjbDLZd0NU?si=NOJxXRfLrus05S8Y", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 128), Array.Empty<object>()));
_errorBlinkInterval = _settings.Bind<float>("UI", "BlinkIntervalSeconds", 0.5f, new ConfigDescription("The corner text toggles between visible and hidden every this many seconds. 0 = no blinking. == Чо бля ", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
_albedoProperties = _textureProperties.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < _albedoProperties.Length; i++)
{
_albedoProperties[i] = _albedoProperties[i].Trim();
}
if (!LoadTexture())
{
((BaseUnityPlugin)this).Logger.LogError((object)"Texture could not be loaded. (ВЫ ЛОХ)");
((Behaviour)this).enabled = false;
return;
}
LoadModels();
LoadErrorFont();
SceneManager.sceneLoaded += OnSceneLoaded;
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} loaded (materials: {1:P0}, UI: {2:P0}, models: {3:P0} of {4}).", "CSS_DOWNLOAD_CONTENT_MOD", _materialChance.Value, _uiChance.Value, _modelChance.Value, _modelPrefabs.Count));
}
private void OnDestroy()
{
SceneManager.sceneLoaded -= OnSceneLoaded;
if ((Object)(object)_bundle != (Object)null)
{
_bundle.Unload(false);
}
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
_scanRequested = true;
}
private void Update()
{
_timer += Time.unscaledDeltaTime;
if (_scanRequested || !(_timer < _scanInterval.Value))
{
_timer = 0f;
_scanRequested = false;
ScanRenderers();
Ui();
ApplyLighting();
}
}
private void OnGUI()
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Invalid comparison between Unknown and I4
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
if (!_showErrorText.Value || (int)Event.current.type != 7)
{
return;
}
string value = _errorText.Value;
if (string.IsNullOrEmpty(value))
{
return;
}
float value2 = _errorBlinkInterval.Value;
if (value2 > 0f && Mathf.FloorToInt(Time.unscaledTime / value2) % 2 == 1)
{
return;
}
if (_errorStyle == null)
{
_errorStyle = new GUIStyle(GUI.skin.label);
_errorStyle.alignment = (TextAnchor)0;
_errorStyle.wordWrap = false;
_errorStyle.richText = false;
if ((Object)(object)_errorFont != (Object)null)
{
_errorStyle.font = _errorFont;
}
}
_errorStyle.fontSize = Mathf.Max(8, Mathf.RoundToInt((float)(_errorFontSize.Value * Screen.height) / 1080f));
GUI.depth = -1000;
float num = Mathf.Max(6f, (float)Screen.height * 0.01f);
Rect val = default(Rect);
((Rect)(ref val))..ctor(num, num, (float)Screen.width - num * 2f, (float)_errorStyle.fontSize * 2f);
_errorStyle.normal.textColor = Color.black;
GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), value, _errorStyle);
_errorStyle.normal.textColor = Color.yellow;
GUI.Label(val, value, _errorStyle);
}
private void LoadErrorFont()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Expected O, but got Unknown
try
{
string text = FindFile(_errorFontFileName.Value);
if (text != null)
{
_errorFont = new Font(text);
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)ex);
_errorFont = null;
}
}
private void ApplyLighting()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Invalid comparison between Unknown and I4
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
if (!_blindingLight.Value)
{
return;
}
Material skybox = RenderSettings.skybox;
if ((Object)(object)skybox != (Object)null && (Object)(object)skybox != (Object)(object)_darkSkybox)
{
_darkSkybox = new Material(skybox);
((Object)_darkSkybox).name = ((Object)skybox).name + "_dark";
((Object)_darkSkybox).hideFlags = (HideFlags)61;
if (_darkSkybox.HasProperty("_Exposure"))
{
_darkSkybox.SetFloat("_Exposure", 0f);
}
else if (_darkSkybox.HasProperty("_Tint"))
{
_darkSkybox.SetColor("_Tint", Color.black);
}
RenderSettings.skybox = _darkSkybox;
DynamicGI.UpdateEnvironment();
}
Light[] array = Object.FindObjectsOfType<Light>();
foreach (Light val in array)
{
if (!((Object)(object)val == (Object)null) && (int)val.type == 1)
{
val.intensity = _directionalIntensity.Value;
val.color = Color.white;
}
}
}
private void ScanRenderers()
{
Renderer[] array = Object.FindObjectsOfType<Renderer>();
Renderer[] array2 = array;
foreach (Renderer val in array2)
{
if ((Object)(object)val == (Object)null || IsOwnModel(val))
{
continue;
}
SpriteRenderer val2 = (SpriteRenderer)(object)((val is SpriteRenderer) ? val : null);
if ((Object)(object)val2 != (Object)null)
{
if (_rolledSpriteRenderers.Add(((Object)val2).GetInstanceID()) && Roll(_materialChance.Value))
{
val2.sprite = _emoSprite;
}
}
else
{
if (TryReplaceWithModel(val))
{
continue;
}
val.GetSharedMaterials(_materialBuffer);
foreach (Material item in _materialBuffer)
{
if (!((Object)(object)item == (Object)null) && !((Object)(object)item.shader == (Object)null) && _rolledMaterials.Add(((Object)item).GetInstanceID()) && (!_skipTextMaterials.Value || !IsTextMaterial(item)) && Roll(_materialChance.Value))
{
ApplyTexture(item);
}
}
}
}
}
private bool IsOwnModel(Renderer renderer)
{
int instanceID = ((Object)renderer).GetInstanceID();
if (!_ownModelCache.TryGetValue(instanceID, out var value))
{
value = (Object)(object)((Component)renderer).GetComponentInParent<EmoModelMarker>() != (Object)null;
_ownModelCache[instanceID] = value;
}
return value;
}
private bool TryReplaceWithModel(Renderer original)
{
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: 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_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_020e: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0221: Unknown result type (might be due to invalid IL or missing references)
//IL_0226: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
//IL_0239: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
if (_modelPrefabs.Count == 0)
{
return false;
}
bool flag = original is MeshRenderer;
bool flag2 = original is SkinnedMeshRenderer;
if (!flag && (!flag2 || !_includeSkinned.Value))
{
return false;
}
if (!original.enabled)
{
return false;
}
if (!_rolledModelRenderers.Add(((Object)original).GetInstanceID()))
{
return false;
}
if (!Roll(_modelChance.Value))
{
return false;
}
Bounds bounds = original.bounds;
float num = MaxExtent(((Bounds)(ref bounds)).size);
if (num < _minObjectSize.Value || num > _maxObjectSize.Value)
{
return false;
}
GameObject val = _modelPrefabs[Random.Range(0, _modelPrefabs.Count)];
if ((Object)(object)val == (Object)null)
{
return false;
}
GameObject val2 = Object.Instantiate<GameObject>(val, ((Bounds)(ref bounds)).center, ((Component)original).transform.rotation);
((Object)val2).name = ((Object)val).name + "_emo";
val2.AddComponent<EmoModelMarker>();
StripPhysics(val2);
SetLayerRecursively(val2, ((Component)original).gameObject.layer);
if (!TryGetModelBounds(val2, out var bounds2))
{
Object.Destroy((Object)(object)val2);
return false;
}
float num2 = MaxExtent(((Bounds)(ref bounds2)).size);
if (num2 < 0.0001f)
{
Object.Destroy((Object)(object)val2);
return false;
}
float num3 = num / num2 * _modelScaleMultiplier.Value;
Transform transform = val2.transform;
Vector3 position = transform.position;
transform.localScale *= num3;
Vector3 val3 = position + (((Bounds)(ref bounds2)).center - position) * num3;
transform.position += ((Bounds)(ref bounds)).center - val3;
transform.SetParent(((Component)original).transform, true);
original.enabled = false;
return true;
}
private static float MaxExtent(Vector3 size)
{
//IL_0001: 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_000d: Unknown result type (might be due to invalid IL or missing references)
return Mathf.Max(size.x, Mathf.Max(size.y, size.z));
}
private static bool TryGetModelBounds(GameObject root, out Bounds bounds)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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)
bounds = default(Bounds);
bool flag = false;
Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>();
foreach (Renderer val in componentsInChildren)
{
if (val is MeshRenderer || val is SkinnedMeshRenderer)
{
if (!flag)
{
bounds = val.bounds;
flag = true;
}
else
{
((Bounds)(ref bounds)).Encapsulate(val.bounds);
}
}
}
return flag;
}
private static void StripPhysics(GameObject root)
{
Collider[] componentsInChildren = root.GetComponentsInChildren<Collider>(true);
foreach (Collider val in componentsInChildren)
{
Object.Destroy((Object)(object)val);
}
Rigidbody[] componentsInChildren2 = root.GetComponentsInChildren<Rigidbody>(true);
foreach (Rigidbody val2 in componentsInChildren2)
{
Object.Destroy((Object)(object)val2);
}
}
private static void SetLayerRecursively(GameObject root, int layer)
{
Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true);
foreach (Transform val in componentsInChildren)
{
((Component)val).gameObject.layer = layer;
}
}
private bool LoadModels()
{
string text = FindFile(_bundleFileName.Value);
if (text == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Model bundle not found: " + _bundleFileName.Value + " (model replacement disabled)."));
return false;
}
try
{
_bundle = AssetBundle.LoadFromFile(text);
if ((Object)(object)_bundle == (Object)null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("AssetBundle.LoadFromFile returned null. Wrong Unity version / target platform, or a bundle with the same name is already loaded. Game Unity version: " + Application.unityVersion));
return false;
}
GameObject[] array = _bundle.LoadAllAssets<GameObject>();
foreach (GameObject val in array)
{
if ((Object)(object)val != (Object)null && (Object)(object)val.transform.parent == (Object)null)
{
_modelPrefabs.Add(val);
}
}
if (_modelPrefabs.Count == 0)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Bundle loaded, but it contains no GameObject prefabs / models.");
return false;
}
if (_recolorModels.Value)
{
RecolorModels();
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Loaded {_modelPrefabs.Count} model(s) from {text}");
return true;
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)ex);
return false;
}
}
private void RecolorModels()
{
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
Color red = default(Color);
if (!ColorUtility.TryParseHtmlString("#" + _modelColorHex.Value.Trim().TrimStart(new char[1] { '#' }), ref red))
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Invalid ModelColor '" + _modelColorHex.Value + "', using FF0000."));
red = Color.red;
}
float value = _modelEmission.Value;
HashSet<int> hashSet = new HashSet<int>();
int num = 0;
foreach (GameObject modelPrefab in _modelPrefabs)
{
Renderer[] componentsInChildren = modelPrefab.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()))
{
RecolorMaterial(val2, red, value);
num++;
}
}
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Recolored {num} bundle material(s): color #{ColorUtility.ToHtmlStringRGB(red)}, emission x{value}.");
}
private static void RecolorMaterial(Material m, Color color, float emission)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: 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)
if (m.HasProperty("_Color"))
{
m.SetColor("_Color", color);
}
if (m.HasProperty("_BaseColor"))
{
m.SetColor("_BaseColor", color);
}
Color val = default(Color);
((Color)(ref val))..ctor(color.r * emission, color.g * emission, color.b * emission, 1f);
if (m.HasProperty("_EmissionColor"))
{
m.EnableKeyword("_EMISSION");
m.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
m.SetColor("_EmissionColor", val);
if (m.HasProperty("_EmissionMap"))
{
m.SetTexture("_EmissionMap", (Texture)null);
}
}
if (m.HasProperty("_EmissiveColor"))
{
m.SetColor("_EmissiveColor", val);
}
}
private void Ui()
{
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
Image[] array = Object.FindObjectsOfType<Image>();
foreach (Image val in array)
{
if (!((Object)(object)val == (Object)null) && _rolledUi.Add(((Object)val).GetInstanceID()) && Roll(_uiChance.Value))
{
val.sprite = _emoSprite;
}
}
RawImage[] array2 = Object.FindObjectsOfType<RawImage>();
foreach (RawImage val2 in array2)
{
if (!((Object)(object)val2 == (Object)null) && _rolledUi.Add(((Object)val2).GetInstanceID()) && Roll(_uiChance.Value))
{
val2.texture = (Texture)(object)_emoTexture;
float value = _tilingMultiplier.Value;
val2.uvRect = new Rect(0f, 0f, value, value);
}
}
}
private static bool Roll(float chance)
{
return Random.value < chance;
}
private static bool IsTextMaterial(Material material)
{
string name = ((Object)material.shader).name;
return name.IndexOf("TextMeshPro", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Text Shader", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("GUI/Text", StringComparison.OrdinalIgnoreCase) >= 0;
}
private void ApplyTexture(Material material)
{
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: 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_0059: Unknown result type (might be due to invalid IL or missing references)
string[] texturePropertyNames;
try
{
texturePropertyNames = material.GetTexturePropertyNames();
}
catch
{
return;
}
string[] array = texturePropertyNames;
foreach (string text in array)
{
if (Array.IndexOf(_albedoProperties, text) >= 0)
{
material.SetTexture(text, (Texture)(object)_emoTexture);
Vector2 textureScale = material.GetTextureScale(text);
material.SetTextureScale(text, textureScale * _tilingMultiplier.Value);
}
}
}
private bool LoadTexture()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Expected O, but got Unknown
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
string text = FindFile(_textureFileName.Value);
if (text == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("File not found: " + _textureFileName.Value));
return false;
}
try
{
byte[] array = File.ReadAllBytes(text);
Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
if (!ImageConversion.LoadImage(val, array))
{
((BaseUnityPlugin)this).Logger.LogError((object)"LoadImage failed.");
Object.Destroy((Object)(object)val);
return false;
}
((Object)val).name = "emotexture";
((Texture)val).wrapMode = (TextureWrapMode)0;
((Object)val).hideFlags = (HideFlags)61;
_emoTexture = val;
_emoSprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0);
((Object)_emoSprite).name = "emotexture_sprite";
((Object)_emoSprite).hideFlags = (HideFlags)61;
return true;
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)ex);
return false;
}
}
private string FindFile(string fileName)
{
string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
if (directoryName != null && fileName.IndexOfAny(new char[2] { '*', '?' }) < 0)
{
string text = Path.Combine(directoryName, fileName);
if (File.Exists(text))
{
return text;
}
}
string[] files = Directory.GetFiles(Paths.PluginPath, fileName, SearchOption.AllDirectories);
return (files.Length != 0) ? files[0] : null;
}
}