Decompiled source of RRIceBoxModLib v1.0.0

BepInEx/plugins/IceBoxModLib.dll

Decompiled 2 days ago
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 BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Fusion;
using I2.Loc;
using IceBoxModLib.Runtime;
using IceBoxModLib.UI;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Store;
using Store.UI;
using UnityEngine;
using UnityEngine.UI;
using WallyBox;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("IceBoxModLib")]
[assembly: AssemblyDescription("Shared mod library for Roadside Research by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("IceBoxModLib")]
[assembly: AssemblyCopyright("Copyright © 2026 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f01ee749-b2b7-4189-b681-4f4983c38ca9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace IceBoxModLib
{
	[BepInPlugin("IceBoxStudio.RoadsideResearch.ModLib", "IceBoxModLib", "1.0.0")]
	public class IceBoxModLib : BasePlugin
	{
		private static bool _initialized;

		public static IceBoxModLib Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		public override void Load()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Instance = this;
			Log = ((BasePlugin)this).Log;
			if (!_initialized)
			{
				Il2CppTypeRegistry.RegisterType<ModNotificationBehaviour>();
				_initialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("IceBoxModLib");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded!");
				}
				log.LogInfo(val);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.RoadsideResearch.ModLib";

		public const string PLUGIN_NAME = "IceBoxModLib";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace IceBoxModLib.Utilities
{
	public static class ImageLoader
	{
		public static Sprite LoadSpriteFromFile(string absoluteImagePath, float pixelsPerUnit = 100f, float pivotX = 0.5f, float pivotY = 0.5f, FilterMode filterMode = 1)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0028: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!File.Exists(absoluteImagePath))
			{
				return null;
			}
			try
			{
				byte[] array = File.ReadAllBytes(absoluteImagePath);
				Texture2D val = new Texture2D(2, 2);
				ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(array));
				((Texture)val).filterMode = filterMode;
				Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(pivotX, pivotY), pixelsPerUnit, 0u, (SpriteMeshType)1, Vector4.zero);
				((Object)val).hideFlags = (HideFlags)61;
				((Object)obj).hideFlags = (HideFlags)61;
				Object.DontDestroyOnLoad((Object)(object)val);
				Object.DontDestroyOnLoad((Object)(object)obj);
				return obj;
			}
			catch
			{
				return null;
			}
		}

		public static bool ReplaceImageBySpriteName(Transform rootTransform, string originalSpriteName, Sprite newSprite, bool resetColorToWhite = true)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rootTransform == (Object)null || string.IsNullOrEmpty(originalSpriteName) || (Object)(object)newSprite == (Object)null)
			{
				return false;
			}
			Image[] array = Il2CppArrayBase<Image>.op_Implicit(((Component)rootTransform).GetComponentsInChildren<Image>(true));
			foreach (Image val in array)
			{
				if ((Object)(object)val.sprite != (Object)null && ((Object)val.sprite).name.Contains(originalSpriteName))
				{
					val.sprite = newSprite;
					if (resetColorToWhite)
					{
						((Graphic)val).color = Color.white;
					}
					return true;
				}
			}
			return false;
		}
	}
	public static class ItemContainerRefreshHelper
	{
		private static ItemAmountInItemContainerLabel[] _cachedLabels;

		private static float _lastCacheTime;

		private const float CacheLifetime = 2f;

		public static void Refresh(ItemContainer container, Item changedItem = null)
		{
			if (!((Object)(object)container == (Object)null))
			{
				Item item = changedItem ?? container.Item;
				try
				{
					((NetworkBehaviour)container).CopyStateToBackingFields();
				}
				catch (Exception)
				{
				}
				try
				{
					container.UpdateItemVisuals(container);
				}
				catch (Exception)
				{
				}
				RefreshAmountLabels(container);
				try
				{
					container.OnNetworkChangedAmount();
				}
				catch (Exception)
				{
				}
				RefreshStockLabels(item);
			}
		}

		private static ItemAmountInItemContainerLabel[] GetLabels()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			if (_cachedLabels == null || realtimeSinceStartup - _lastCacheTime > 2f)
			{
				_cachedLabels = Il2CppArrayBase<ItemAmountInItemContainerLabel>.op_Implicit(Resources.FindObjectsOfTypeAll<ItemAmountInItemContainerLabel>());
				_lastCacheTime = realtimeSinceStartup;
			}
			return _cachedLabels;
		}

		public static void InvalidateCache()
		{
			_cachedLabels = null;
		}

		private static void RefreshAmountLabels(ItemContainer container)
		{
			ItemAmountInItemContainerLabel[] labels = GetLabels();
			foreach (ItemAmountInItemContainerLabel val in labels)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					ItemContainer currentData = ((DataDisplay<ItemContainer>)(object)val).CurrentData;
					if ((Object)(object)currentData != (Object)null && ((Il2CppObjectBase)currentData).Pointer == ((Il2CppObjectBase)container).Pointer)
					{
						((DataDisplay<ItemContainer>)(object)val).HandleNewData(container);
					}
				}
				catch (Exception)
				{
				}
			}
		}

		private static void RefreshStockLabels(Item item)
		{
			Action val = default(Action);
			if (!((Object)(object)item == (Object)null) && !((Object)(object)SingletonNetworkBehaviour<StoreManager>.Instance == (Object)null) && SingletonNetworkBehaviour<StoreManager>.Instance._onStockTotalChanged != null && SingletonNetworkBehaviour<StoreManager>.Instance._onStockTotalChanged.TryGetValue(item, ref val) && !((Delegate)(object)val == (Delegate)null))
			{
				val.Invoke();
			}
		}
	}
}
namespace IceBoxModLib.UI
{
	public static class ModNotification
	{
		private const string NotificationObjectName = "RoadsideResearch.SharedModNotification";

		private static GameObject _notificationObj;

		public static void Show(string message, float duration = 5f, Color? textColor = null)
		{
			//IL_0014: 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_0019: 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)
			try
			{
				Color textColor2 = (Color)(((??)textColor) ?? Color.white);
				ModNotificationBehaviour orCreateBehaviour = GetOrCreateBehaviour();
				if ((Object)(object)orCreateBehaviour != (Object)null)
				{
					orCreateBehaviour.ShowNotification(message, duration, textColor2);
				}
			}
			catch (Exception ex)
			{
				Debug.LogError(Object.op_Implicit("[ModNotification] 通知创建失败: " + ex.Message));
			}
		}

		public static void Dismiss()
		{
			ModNotificationBehaviour existingBehaviour = GetExistingBehaviour();
			if ((Object)(object)existingBehaviour != (Object)null)
			{
				existingBehaviour.HideNotification();
			}
		}

		private static ModNotificationBehaviour GetOrCreateBehaviour()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			ModNotificationBehaviour existingBehaviour = GetExistingBehaviour();
			if ((Object)(object)existingBehaviour != (Object)null)
			{
				return existingBehaviour;
			}
			_notificationObj = FindExistingNotificationObject();
			if ((Object)(object)_notificationObj == (Object)null)
			{
				_notificationObj = new GameObject("RoadsideResearch.SharedModNotification");
				Object.DontDestroyOnLoad((Object)(object)_notificationObj);
			}
			existingBehaviour = _notificationObj.GetComponent<ModNotificationBehaviour>();
			if ((Object)(object)existingBehaviour == (Object)null)
			{
				existingBehaviour = _notificationObj.AddComponent<ModNotificationBehaviour>();
			}
			return existingBehaviour;
		}

		private static ModNotificationBehaviour GetExistingBehaviour()
		{
			if ((Object)(object)_notificationObj == (Object)null)
			{
				_notificationObj = FindExistingNotificationObject();
			}
			if ((Object)(object)_notificationObj == (Object)null)
			{
				return null;
			}
			return _notificationObj.GetComponent<ModNotificationBehaviour>();
		}

		private static GameObject FindExistingNotificationObject()
		{
			GameObject[] array = Il2CppArrayBase<GameObject>.op_Implicit(Resources.FindObjectsOfTypeAll<GameObject>());
			foreach (GameObject val in array)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == "RoadsideResearch.SharedModNotification")
				{
					return val;
				}
			}
			return null;
		}
	}
	public class ModNotificationBehaviour : MonoBehaviour
	{
		private string _message;

		private float _duration;

		private float _startTime;

		private Color _textColor;

		private GUIStyle _textStyle;

		private GUIStyle _shadowStyle;

		private Texture2D _bgTexture;

		private bool _initialized;

		private bool _visible;

		private const float FadeInTime = 0.4f;

		private const float FadeOutTime = 0.6f;

		private const float SlideDistance = 30f;

		public ModNotificationBehaviour(IntPtr ptr)
			: base(ptr)
		{
		}

		[HideFromIl2Cpp]
		public void ShowNotification(string message, float duration, Color textColor)
		{
			//IL_000f: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			_message = message;
			_duration = duration;
			_textColor = textColor;
			_startTime = Time.time;
			_visible = true;
			if (_textStyle != null)
			{
				_textStyle.normal.textColor = _textColor;
			}
		}

		[HideFromIl2Cpp]
		public void HideNotification()
		{
			_visible = false;
			_message = null;
		}

		[HideFromIl2Cpp]
		private void InitStyles()
		{
			//IL_002e: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				_initialized = true;
				_bgTexture = CreateRoundedRectTexture(512, 64, 16, new Color(0.1f, 0.1f, 0.1f, 0.5f));
				_textStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 24,
					fontStyle = (FontStyle)0,
					alignment = (TextAnchor)4,
					wordWrap = true
				};
				_textStyle.normal.textColor = _textColor;
				_textStyle.padding = new RectOffset(20, 20, 8, 8);
				_shadowStyle = new GUIStyle(_textStyle);
				_shadowStyle.normal.textColor = new Color(0f, 0f, 0f, 0.6f);
			}
		}

		private void OnGUI()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			if (!_visible || string.IsNullOrEmpty(_message))
			{
				return;
			}
			float num = Time.time - _startTime;
			if (num > _duration)
			{
				HideNotification();
				return;
			}
			InitStyles();
			float num4;
			float num3;
			if (num < 0.4f)
			{
				float num2 = num / 0.4f;
				num2 = 1f - (1f - num2) * (1f - num2);
				num3 = num2;
				num4 = 30f * (1f - num2);
			}
			else if (num > _duration - 0.6f)
			{
				float num5 = (_duration - num) / 0.6f;
				num5 *= num5;
				num3 = num5;
				num4 = 30f * (1f - num5);
			}
			else
			{
				num3 = 1f;
				num4 = 0f;
			}
			num3 = Mathf.Clamp01(num3);
			float num6 = Mathf.Min((float)Screen.width * 0.75f, 800f);
			float num7 = 40f;
			GUIContent val = new GUIContent(_message);
			float num8 = _textStyle.CalcHeight(val, num6 - num7);
			float num9 = num6;
			float num10 = num8 + 24f;
			float num11 = ((float)Screen.width - num9) / 2f;
			float num12 = (float)Screen.height - num10 - 140f + num4;
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, num3);
			GUI.DrawTexture(new Rect(num11, num12, num9, num10), (Texture)(object)_bgTexture);
			GUI.Label(new Rect(num11 + 1f, num12 + 1f, num9, num10), _message, _shadowStyle);
			GUI.Label(new Rect(num11, num12, num9, num10), _message, _textStyle);
			GUI.color = color;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_bgTexture != (Object)null)
			{
				Object.Destroy((Object)(object)_bgTexture);
				_bgTexture = null;
			}
		}

		[HideFromIl2Cpp]
		private static Texture2D CreateRoundedRectTexture(int width, int height, int radius, Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0f, 0f, 0f, 0f);
			for (int i = 0; i < width; i++)
			{
				for (int j = 0; j < height; j++)
				{
					bool flag = true;
					if (i < radius && j < radius)
					{
						flag = (radius - i) * (radius - i) + (radius - j) * (radius - j) <= radius * radius;
					}
					else if (i > width - radius - 1 && j < radius)
					{
						int num = i - (width - radius - 1);
						flag = num * num + (radius - j) * (radius - j) <= radius * radius;
					}
					else if (i < radius && j > height - radius - 1)
					{
						int num2 = j - (height - radius - 1);
						flag = (radius - i) * (radius - i) + num2 * num2 <= radius * radius;
					}
					else if (i > width - radius - 1 && j > height - radius - 1)
					{
						int num3 = i - (width - radius - 1);
						int num4 = j - (height - radius - 1);
						flag = num3 * num3 + num4 * num4 <= radius * radius;
					}
					val.SetPixel(i, j, flag ? color : val2);
				}
			}
			val.Apply();
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			return val;
		}
	}
}
namespace IceBoxModLib.Runtime
{
	public static class Il2CppTypeRegistry
	{
		private static readonly HashSet<string> RegisteredTypes = new HashSet<string>();

		public static void RegisterType<T>() where T : class
		{
			string item = typeof(T).FullName ?? typeof(T).Name;
			if (!RegisteredTypes.Contains(item))
			{
				ClassInjector.RegisterTypeInIl2Cpp<T>();
				RegisteredTypes.Add(item);
			}
		}
	}
}
namespace IceBoxModLib.Localization
{
	public class ModLocalizationService
	{
		private readonly Dictionary<string, Dictionary<string, string>> _localizations = new Dictionary<string, Dictionary<string, string>>();

		private readonly HashSet<string> _supportedLanguages;

		private readonly string _fallbackLanguage;

		private string _currentLanguage;

		public string CurrentLanguage => _currentLanguage;

		public ModLocalizationService(IEnumerable<string> supportedLanguages, string fallbackLanguage = "English")
		{
			_fallbackLanguage = fallbackLanguage;
			_currentLanguage = fallbackLanguage;
			_supportedLanguages = new HashSet<string>(supportedLanguages);
			LocalizationManager.OnLocalizeEvent += OnLocalizeCallback.op_Implicit((Action)OnGameLanguageChanged);
			UpdateCurrentLanguage();
		}

		public void AddTranslations(string language, Dictionary<string, string> translations)
		{
			if (!string.IsNullOrEmpty(language) && translations != null && translations.Count != 0)
			{
				_localizations[language] = translations;
			}
		}

		public string GetText(string key, params object[] args)
		{
			if (string.IsNullOrEmpty(_currentLanguage) || !_localizations.ContainsKey(_currentLanguage))
			{
				_currentLanguage = _fallbackLanguage;
			}
			if (_localizations.TryGetValue(_currentLanguage, out var value) && value.TryGetValue(key, out var value2))
			{
				if (args.Length == 0)
				{
					return value2;
				}
				return string.Format(value2, args);
			}
			if (_currentLanguage != _fallbackLanguage && _localizations.TryGetValue(_fallbackLanguage, out var value3) && value3.TryGetValue(key, out var value4))
			{
				if (args.Length == 0)
				{
					return value4;
				}
				return string.Format(value4, args);
			}
			return key;
		}

		private void OnGameLanguageChanged()
		{
			UpdateCurrentLanguage();
		}

		private void UpdateCurrentLanguage()
		{
			try
			{
				string currentLanguage = LocalizationManager.CurrentLanguage;
				if (!string.IsNullOrEmpty(currentLanguage) && _supportedLanguages.Contains(currentLanguage))
				{
					_currentLanguage = currentLanguage;
					return;
				}
			}
			catch
			{
			}
			_currentLanguage = _fallbackLanguage;
		}
	}
}
namespace IceBoxModLib.Config
{
	public abstract class ModConfigBase
	{
		protected readonly ConfigFile ConfigFile;

		protected ModConfigBase(ConfigFile configFile)
		{
			ConfigFile = configFile;
		}

		protected ConfigEntry<bool> RegisterBool(string section, string key, string description, bool defaultValue)
		{
			return ConfigFile.Bind<bool>(section, key, defaultValue, description);
		}

		protected ConfigEntry<string> RegisterString(string section, string key, string description, string defaultValue)
		{
			return ConfigFile.Bind<string>(section, key, defaultValue, description);
		}

		protected ConfigEntry<KeyCode> RegisterKeyCode(string section, string key, string description, KeyCode defaultValue)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return ConfigFile.Bind<KeyCode>(section, key, defaultValue, description);
		}

		protected ConfigEntry<int> RegisterInt(string section, string key, string description, int defaultValue)
		{
			return ConfigFile.Bind<int>(section, key, defaultValue, description);
		}

		protected ConfigEntry<int> RegisterIntRange(string section, string key, string description, int defaultValue, int minValue, int maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return ConfigFile.Bind<int>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(minValue, maxValue), Array.Empty<object>()));
		}

		protected ConfigEntry<float> RegisterFloat(string section, string key, string description, float defaultValue)
		{
			return ConfigFile.Bind<float>(section, key, defaultValue, description);
		}

		protected ConfigEntry<float> RegisterFloatRange(string section, string key, string description, float defaultValue, float minValue, float maxValue)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			return ConfigFile.Bind<float>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(minValue, maxValue), Array.Empty<object>()));
		}
	}
}