using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;
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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ReplaceMachine;
[BepInPlugin("BuildingReplacement_RenBenBuYi.1", "BuildingReplacement_RenBenBuYi", "0.1.0")]
public class ReplaceMachineMod : BaseUnityPlugin
{
internal static ManualLogSource log;
internal static ConfigEntry<KeyboardShortcut> hotkey;
private bool uiVisible = false;
private bool rebinding = false;
private int entityId = -1;
private Vector2 scrollPos;
private List<ItemProto> machines;
private bool listReady = false;
private Dictionary<string, List<ItemProto>> categories = new Dictionary<string, List<ItemProto>>();
private Dictionary<string, bool> categoryOpen = new Dictionary<string, bool>();
private List<string> categoryOrder = new List<string>();
private GameObject blockerCanvas;
private static readonly (string category, string[] keywords)[] CategoryRules = new(string, string[])[8]
{
("采矿", new string[4] { "miner", "collector", "drill", "excavator" }),
("冶炼", new string[2] { "smelter", "furnace" }),
("研究", new string[2] { "lab", "matrix" }),
("制造", new string[6] { "assembler", "fractionator", "sprayer", "crafter", "manufactory", "replicator" }),
("电力", new string[9] { "power", "generator", "accumulator", "battery", "turbine", "reactor", "wire", "pole", "exchange" }),
("物流", new string[10] { "belt", "inserter", "sorter", "cargo", "station", "silo", "tank", "logistic", "conveyor", "splitter" }),
("仓储", new string[3] { "storage", "box", "chest" }),
("防御", new string[4] { "turret", "defense", "gun", "shield" })
};
private void Awake()
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
log = ((BaseUnityPlugin)this).Logger;
hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "Hotkey", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "打开/关闭替换界面");
((BaseUnityPlugin)this).Logger.LogInfo((object)"BuildingReplacement_RenBenBuYi 已加载");
}
private void Start()
{
BuildMachineList();
EnsureBlocker();
}
private void EnsureBlocker()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
//IL_009f: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: 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)
if (!((Object)(object)blockerCanvas != (Object)null))
{
blockerCanvas = new GameObject("BuildingReplacement_Blocker");
Object.DontDestroyOnLoad((Object)(object)blockerCanvas);
Canvas val = blockerCanvas.AddComponent<Canvas>();
val.renderMode = (RenderMode)0;
val.sortingOrder = 30000;
blockerCanvas.AddComponent<GraphicRaycaster>();
GameObject val2 = new GameObject("BlockerImage");
val2.transform.SetParent(blockerCanvas.transform, false);
Image val3 = val2.AddComponent<Image>();
((Graphic)val3).color = new Color(0f, 0f, 0f, 0.001f);
((Graphic)val3).raycastTarget = true;
RectTransform rectTransform = ((Graphic)val3).rectTransform;
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
blockerCanvas.SetActive(false);
}
}
private void SetBlocker(bool active)
{
EnsureBlocker();
blockerCanvas.SetActive(active);
}
private void BuildMachineList()
{
machines = new List<ItemProto>();
if ((Object)(object)LDB.items == (Object)null)
{
return;
}
IEnumerable<ItemProto> items = GetItems(LDB.items);
if (items == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("无法枚举物品表,类型: " + ((object)LDB.items).GetType().FullName));
return;
}
foreach (ItemProto item in items)
{
if (item != null && item.CanBuild)
{
machines.Add(item);
}
}
categories.Clear();
categoryOpen.Clear();
categoryOrder = CategoryRules.Select(((string category, string[] keywords) r) => r.category).ToList();
if (!categoryOrder.Contains("其他"))
{
categoryOrder.Add("其他");
}
foreach (ItemProto machine in machines)
{
string category = GetCategory(machine);
if (!categories.ContainsKey(category))
{
categories[category] = new List<ItemProto>();
categoryOpen[category] = true;
if (!categoryOrder.Contains(category))
{
categoryOrder.Add(category);
}
}
categories[category].Add(machine);
}
((BaseUnityPlugin)this).Logger.LogInfo((object)("已加载可建造物数量: " + machines.Count));
}
private string GetCategory(ItemProto proto)
{
if (proto == null)
{
return "其他";
}
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
try
{
object obj = ((object)proto).GetType().GetProperty("prefabDesc", bindingAttr)?.GetValue(proto);
if (obj != null)
{
FieldInfo[] fields = obj.GetType().GetFields(bindingAttr);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.FieldType != typeof(bool))
{
continue;
}
bool flag;
try
{
flag = (bool)fieldInfo.GetValue(obj);
}
catch
{
continue;
}
if (!flag)
{
continue;
}
string text = fieldInfo.Name.ToLower();
(string, string[])[] categoryRules = CategoryRules;
for (int j = 0; j < categoryRules.Length; j++)
{
(string, string[]) tuple = categoryRules[j];
string[] item = tuple.Item2;
foreach (string value in item)
{
if (text.Contains(value))
{
return tuple.Item1;
}
}
}
}
}
}
catch
{
}
try
{
PropertyInfo propertyInfo = ((object)proto).GetType().GetProperty("BuildType", bindingAttr) ?? ((object)proto).GetType().GetProperty("buildType", bindingAttr);
if (propertyInfo != null)
{
string text2 = (propertyInfo.GetValue(proto)?.ToString() ?? "").ToLower();
(string, string[])[] categoryRules2 = CategoryRules;
for (int l = 0; l < categoryRules2.Length; l++)
{
(string, string[]) tuple2 = categoryRules2[l];
string[] item2 = tuple2.Item2;
foreach (string value2 in item2)
{
if (text2.Contains(value2))
{
return tuple2.Item1;
}
}
}
}
}
catch
{
}
string name = ((Proto)proto).Name;
if (name.Contains("矿"))
{
return "采矿";
}
if (name.Contains("熔") || name.Contains("冶炼"))
{
return "冶炼";
}
if (name.Contains("研究") || name.Contains("矩阵"))
{
return "研究";
}
if (name.Contains("制造") || name.Contains("组装"))
{
return "制造";
}
if (name.Contains("电"))
{
return "电力";
}
if (name.Contains("传送") || name.Contains("分拣") || name.Contains("物流") || name.Contains("塔"))
{
return "物流";
}
if (name.Contains("箱"))
{
return "仓储";
}
return "其他";
}
private static IEnumerable<ItemProto> GetItems(object set)
{
if (set == null)
{
return null;
}
Type type = set.GetType();
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo[] fields = type.GetFields(bindingAttr);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.FieldType == typeof(ItemProto[]) && fieldInfo.GetValue(set) is ItemProto[] source)
{
return source.Where((ItemProto x) => x != null);
}
}
PropertyInfo[] properties = type.GetProperties(bindingAttr);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.PropertyType == typeof(ItemProto[]) && propertyInfo.GetValue(set) is ItemProto[] source2)
{
return source2.Where((ItemProto x) => x != null);
}
}
FieldInfo[] fields2 = type.GetFields(bindingAttr);
foreach (FieldInfo fieldInfo2 in fields2)
{
if (typeof(IList).IsAssignableFrom(fieldInfo2.FieldType) && fieldInfo2.GetValue(set) is IList { Count: >0 } list && list[0] is ItemProto)
{
return list.Cast<ItemProto>();
}
}
PropertyInfo[] properties2 = type.GetProperties(bindingAttr);
foreach (PropertyInfo propertyInfo2 in properties2)
{
if (typeof(IList).IsAssignableFrom(propertyInfo2.PropertyType) && propertyInfo2.GetValue(set) is IList { Count: >0 } list2 && list2[0] is ItemProto)
{
return list2.Cast<ItemProto>();
}
}
PropertyInfo propertyInfo3 = type.GetProperty("Count") ?? type.GetProperty("Length") ?? type.GetProperty("length");
PropertyInfo property = type.GetProperty("Item");
if (propertyInfo3 != null && property != null)
{
try
{
int num4 = Convert.ToInt32(propertyInfo3.GetValue(set));
List<ItemProto> list3 = new List<ItemProto>();
for (int num5 = 0; num5 < num4; num5++)
{
object? value = property.GetValue(set, new object[1] { num5 });
ItemProto val = (ItemProto)((value is ItemProto) ? value : null);
if (val != null && val != null)
{
list3.Add(val);
}
}
if (list3.Count > 0)
{
return list3;
}
}
catch
{
}
}
return null;
}
private void Update()
{
//IL_001e: 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)
try
{
if (rebinding)
{
CaptureNewHotkey();
return;
}
KeyboardShortcut value = hotkey.Value;
if (!((KeyboardShortcut)(ref value)).IsDown())
{
return;
}
if (!uiVisible)
{
int entityUnderCursor = GetEntityUnderCursor();
((BaseUnityPlugin)this).Logger.LogInfo((object)("鼠标指向实体ID: " + entityUnderCursor));
entityId = entityUnderCursor;
if (!listReady)
{
BuildMachineList();
listReady = true;
}
uiVisible = true;
SetBlocker(active: true);
}
else
{
CloseUI();
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Update 异常: " + ex));
}
}
private void CaptureNewHotkey()
{
//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_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Invalid comparison between Unknown and I4
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Invalid comparison between Unknown and I4
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Invalid comparison between Unknown and I4
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Invalid comparison between Unknown and I4
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Invalid comparison between Unknown and I4
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Invalid comparison between Unknown and I4
if (Input.GetKeyDown((KeyCode)27))
{
rebinding = false;
return;
}
foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
{
if (!Input.GetKeyDown(value) || (int)value == 304 || (int)value == 303 || (int)value == 306 || (int)value == 305 || (int)value == 308 || (int)value == 307)
{
continue;
}
hotkey.Value = new KeyboardShortcut(value, Array.Empty<KeyCode>());
((BaseUnityPlugin)this).Config.Save();
((BaseUnityPlugin)this).Logger.LogInfo((object)("快捷键已改为: " + ((object)value/*cast due to .constrained prefix*/).ToString()));
rebinding = false;
break;
}
}
private void CloseUI()
{
uiVisible = false;
rebinding = false;
SetBlocker(active: false);
}
private int GetEntityUnderCursor()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
try
{
Player mainPlayer = GameMain.mainPlayer;
if (mainPlayer != null)
{
object fieldByPartName = GetFieldByPartName(mainPlayer, "gizmo");
if (fieldByPartName != null)
{
int intFieldValue = GetIntFieldValue(fieldByPartName, "mouseOverTargetId");
if (intFieldValue > 0)
{
return intFieldValue;
}
}
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("gizmo检测异常: " + ex.Message));
}
try
{
Ray val = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] source = Physics.RaycastAll(val, 1000f, -5, (QueryTriggerInteraction)2);
foreach (RaycastHit item in source.OrderBy((RaycastHit h) => ((RaycastHit)(ref h)).distance))
{
RaycastHit current = item;
Component[] componentsInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentsInParent<Component>(true);
foreach (Component obj in componentsInParent)
{
int num2 = FindEntityId(obj);
if (num2 > 0)
{
return num2;
}
}
}
}
catch
{
}
return -1;
}
private static object GetFieldByPartName(object obj, string part)
{
if (obj == null)
{
return null;
}
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo[] fields = obj.GetType().GetFields(bindingAttr);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.Name.ToLower().Contains(part.ToLower()))
{
return fieldInfo.GetValue(obj);
}
}
return null;
}
private static int GetIntFieldValue(object obj, string fieldName)
{
if (obj == null)
{
return -1;
}
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo field = obj.GetType().GetField(fieldName, bindingAttr);
if (field != null && field.FieldType == typeof(int))
{
try
{
return (int)field.GetValue(obj);
}
catch
{
}
}
return -1;
}
private static int FindEntityId(object obj)
{
if (obj == null)
{
return -1;
}
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
FieldInfo[] fields = obj.GetType().GetFields(bindingAttr);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo.FieldType != typeof(int))
{
continue;
}
string text = fieldInfo.Name.ToLower();
if (text.Contains("entity") || text.Contains("cursor") || text == "objectid")
{
int num = (int)fieldInfo.GetValue(obj);
if (num > 0)
{
return num;
}
}
}
PropertyInfo[] properties = obj.GetType().GetProperties(bindingAttr);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo.PropertyType != typeof(int))
{
continue;
}
string text2 = propertyInfo.Name.ToLower();
if (!text2.Contains("entity") && !text2.Contains("cursor") && !(text2 == "objectid"))
{
continue;
}
try
{
int num2 = (int)propertyInfo.GetValue(obj);
if (num2 > 0)
{
return num2;
}
}
catch
{
}
}
return -1;
}
private void OnGUI()
{
//IL_0044: 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_005b: Expected O, but got Unknown
//IL_0056: 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 (!uiVisible)
{
return;
}
TechSkin.Ensure();
GUISkin skin = GUI.skin;
GUI.skin = TechSkin.Skin;
try
{
Rect val = default(Rect);
((Rect)(ref val))..ctor(80f, 80f, 520f, 660f);
val = GUI.Window(0, val, new WindowFunction(DrawWindow), "替 换 机 器");
}
finally
{
GUI.skin = skin;
}
}
private void DrawWindow(int id)
{
//IL_0001: 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_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0389: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018a: Unknown result type (might be due to invalid IL or missing references)
//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
//IL_03e8: Unknown result type (might be due to invalid IL or missing references)
Color color = GUI.color;
float num = 0.5f + 0.5f * Mathf.Sin(Time.time * 3f);
GUI.color = new Color(0f, 0.9f, 1f, 0.35f + 0.45f * num);
GUILayout.Box("", TechSkin.Line, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(2f) });
GUI.color = color;
GUILayout.Space(4f);
PlanetFactory factory = GameMain.mainPlayer.factory;
if (factory == null || entityId < 0 || entityId >= factory.entityPool.Length)
{
GUILayout.Label("当前建筑实体ID: " + entityId, TechSkin.DimLabel, Array.Empty<GUILayoutOption>());
GUILayout.Label("未选中机器(此时仍可修改快捷键)", TechSkin.DimLabel, Array.Empty<GUILayoutOption>());
}
else
{
int protoId = factory.entityPool[entityId].protoId;
ItemProto itemProto = GetItemProto(protoId);
GUILayout.Label("当前建筑: " + ((itemProto != null) ? ((Proto)itemProto).Name : "未知") + " (ID:" + entityId + ")", TechSkin.Title, Array.Empty<GUILayoutOption>());
GUILayout.Space(3f);
scrollPos = GUILayout.BeginScrollView(scrollPos, TechSkin.ScrollView);
foreach (string item in categoryOrder)
{
if (!categories.ContainsKey(item) || categories[item].Count == 0)
{
continue;
}
bool flag = categoryOpen[item];
if (GUILayout.Button((flag ? "▼ " : "▶ ") + item + " (" + categories[item].Count + ")", TechSkin.CatHeader, Array.Empty<GUILayoutOption>()))
{
categoryOpen[item] = !flag;
}
if (!flag)
{
continue;
}
foreach (ItemProto item2 in categories[item])
{
if (item2 == null || ((Proto)item2).ID == protoId || !GUILayout.Button(" " + ((Proto)item2).Name + " (ID:" + ((Proto)item2).ID + ")", TechSkin.ItemButton, Array.Empty<GUILayoutOption>()))
{
continue;
}
ReplaceMachine(entityId, ((Proto)item2).ID);
break;
}
GUILayout.Space(3f);
}
GUILayout.EndScrollView();
}
GUILayout.Space(6f);
GUI.color = new Color(0f, 0.9f, 1f, 0.45f);
GUILayout.Box("", TechSkin.Line, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(1f) });
GUI.color = color;
GUILayout.Space(4f);
if (!rebinding)
{
if (GUILayout.Button("◈ 修改快捷键 (当前: " + ((object)hotkey.Value/*cast due to .constrained prefix*/).ToString() + ")", TechSkin.ItemButton, Array.Empty<GUILayoutOption>()))
{
rebinding = true;
}
}
else
{
GUILayout.Label("请按下新快捷键... (Esc 取消)", TechSkin.DimLabel, Array.Empty<GUILayoutOption>());
if (Input.GetKeyDown((KeyCode)27))
{
rebinding = false;
}
}
if (GUILayout.Button("✕ 取消", TechSkin.ItemButton, Array.Empty<GUILayoutOption>()))
{
CloseUI();
}
}
private void ReplaceMachine(int entityId, int newProtoId)
{
PlanetFactory factory = GameMain.mainPlayer.factory;
if (factory == null)
{
CloseUI();
return;
}
ItemProto itemProto = GetItemProto(newProtoId);
if (itemProto == null)
{
((BaseUnityPlugin)this).Logger.LogError((object)("找不到 ItemProto: " + newProtoId));
CloseUI();
return;
}
try
{
MethodInfo method = typeof(PlanetFactory).GetMethod("UpgradeEntityWithComponents", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method != null)
{
method.Invoke(factory, new object[2] { entityId, itemProto });
((BaseUnityPlugin)this).Logger.LogInfo((object)("替换成功: " + ((Proto)itemProto).Name));
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("替换异常: " + ((ex.InnerException != null) ? ex.InnerException.Message : ex.Message)));
}
CloseUI();
}
private static ItemProto GetItemProto(int protoId)
{
ItemProtoSet items = LDB.items;
if ((Object)(object)items == (Object)null)
{
return null;
}
Type type = ((object)items).GetType();
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
MethodInfo method = type.GetMethod("Select", bindingAttr);
if (method != null)
{
object? obj = method.Invoke(items, new object[1] { protoId });
return (ItemProto)((obj is ItemProto) ? obj : null);
}
method = type.GetMethod("Get", bindingAttr);
if (method != null)
{
object? obj2 = method.Invoke(items, new object[1] { protoId });
return (ItemProto)((obj2 is ItemProto) ? obj2 : null);
}
PropertyInfo property = type.GetProperty("Item", bindingAttr);
if (property != null)
{
object? value = property.GetValue(items, new object[1] { protoId });
return (ItemProto)((value is ItemProto) ? value : null);
}
return null;
}
}
public static class TechSkin
{
private static bool initialized;
private static readonly Color PanelTop = new Color(0.04f, 0.065f, 0.095f, 0.96f);
private static readonly Color PanelBottom = new Color(0.02f, 0.04f, 0.06f, 0.96f);
private static readonly Color BorderCyan = new Color(0f, 0.85f, 1f, 0.75f);
private static readonly Color Accent = new Color(0.2f, 0.85f, 1f, 1f);
private static readonly Color TextLight = new Color(0.82f, 0.93f, 1f, 1f);
private static readonly Color TextDim = new Color(0.55f, 0.72f, 0.85f, 1f);
public static GUISkin Skin { get; private set; }
public static GUIStyle Title { get; private set; }
public static GUIStyle Label { get; private set; }
public static GUIStyle DimLabel { get; private set; }
public static GUIStyle ItemButton { get; private set; }
public static GUIStyle CatHeader { get; private set; }
public static GUIStyle Line { get; private set; }
public static GUIStyle ScrollView { get; private set; }
public static void Ensure()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: 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_00e1: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: 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_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: 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_0194: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Expected O, but got Unknown
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Expected O, but got Unknown
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0200: Expected O, but got Unknown
//IL_0230: Unknown result type (might be due to invalid IL or missing references)
//IL_023b: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Expected O, but got Unknown
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_0285: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Expected O, but got Unknown
//IL_029a: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Expected O, but got Unknown
//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
//IL_02f7: Expected O, but got Unknown
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_030b: Expected O, but got Unknown
//IL_033b: Unknown result type (might be due to invalid IL or missing references)
//IL_0350: Unknown result type (might be due to invalid IL or missing references)
//IL_0365: Unknown result type (might be due to invalid IL or missing references)
//IL_0375: Unknown result type (might be due to invalid IL or missing references)
//IL_037f: Expected O, but got Unknown
//IL_0397: Unknown result type (might be due to invalid IL or missing references)
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
//IL_03cb: Expected O, but got Unknown
//IL_03cc: Unknown result type (might be due to invalid IL or missing references)
//IL_03d6: Expected O, but got Unknown
//IL_03f5: Unknown result type (might be due to invalid IL or missing references)
//IL_03ff: Expected O, but got Unknown
//IL_0409: Unknown result type (might be due to invalid IL or missing references)
//IL_0413: Expected O, but got Unknown
if (!initialized)
{
initialized = true;
Font font = LoadFont();
Texture2D background = MakePanel(24, 24, PanelTop, PanelBottom, BorderCyan, 2);
Texture2D background2 = MakePanel(8, 8, new Color(0.05f, 0.09f, 0.13f, 0.95f), new Color(0.03f, 0.06f, 0.09f, 0.95f), new Color(0f, 0.55f, 0.75f, 0.55f), 1);
Texture2D background3 = MakePanel(8, 8, new Color(0.06f, 0.12f, 0.16f, 1f), new Color(0.04f, 0.08f, 0.12f, 1f), BorderCyan, 1);
Texture2D background4 = MakePanel(8, 8, new Color(0.02f, 0.35f, 0.45f, 1f), new Color(0.01f, 0.2f, 0.3f, 1f), BorderCyan, 1);
Texture2D background5 = MakeSolid(new Color(0f, 0.9f, 1f, 1f));
Texture2D track = MakeSolid(new Color(0.03f, 0.05f, 0.08f, 0.8f));
Texture2D thumb = MakePanel(4, 8, new Color(0.2f, 0.8f, 1f, 0.9f), new Color(0.1f, 0.5f, 0.7f, 0.9f), BorderCyan, 1);
GUIStyle val = new GUIStyle();
val.normal.background = background;
val.border = new RectOffset(6, 6, 6, 6);
val.padding = new RectOffset(10, 10, 10, 10);
val.alignment = (TextAnchor)4;
val.fontSize = 16;
val.richText = true;
val.normal.textColor = Accent;
Title = new GUIStyle();
Title.alignment = (TextAnchor)3;
Title.fontSize = 15;
Title.richText = true;
Title.normal.textColor = Accent;
Label = new GUIStyle();
Label.alignment = (TextAnchor)3;
Label.fontSize = 13;
Label.richText = true;
Label.normal.textColor = TextLight;
DimLabel = new GUIStyle(Label);
DimLabel.normal.textColor = TextDim;
ItemButton = new GUIStyle();
ItemButton.normal.background = background2;
ItemButton.hover.background = background3;
ItemButton.active.background = background4;
ItemButton.border = new RectOffset(3, 3, 3, 3);
ItemButton.padding = new RectOffset(8, 8, 4, 4);
ItemButton.alignment = (TextAnchor)3;
ItemButton.fontSize = 13;
ItemButton.richText = true;
ItemButton.normal.textColor = TextLight;
ItemButton.hover.textColor = Color.white;
ItemButton.active.textColor = Color.white;
CatHeader = new GUIStyle(ItemButton);
CatHeader.fontSize = 14;
CatHeader.normal.textColor = Accent;
CatHeader.hover.textColor = Color.white;
CatHeader.padding = new RectOffset(10, 8, 6, 6);
Line = new GUIStyle();
Line.normal.background = background5;
Line.stretchWidth = true;
ScrollView = new GUIStyle();
ScrollView.padding = new RectOffset(2, 2, 2, 2);
Skin = Object.Instantiate<GUISkin>(GUI.skin);
Skin.font = font;
Skin.window = val;
Skin.label = Label;
Skin.button = ItemButton;
Skin.verticalScrollbar = MakeScrollbar(track, thumb, vertical: true);
Skin.verticalScrollbarThumb = MakeThumb(thumb);
Skin.horizontalScrollbar = MakeScrollbar(track, thumb, vertical: false);
Skin.horizontalScrollbarThumb = MakeThumb(thumb);
}
}
private static Font LoadFont()
{
string[] array = new string[4] { "Microsoft YaHei", "微软雅黑", "SimHei", "Arial" };
string[] array2 = array;
foreach (string text in array2)
{
try
{
Font val = Font.CreateDynamicFontFromOSFont(text, 14);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
catch
{
}
}
return GUI.skin.font;
}
private static Texture2D MakeSolid(Color c)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
val.SetPixel(0, 0, c);
val.Apply();
return val;
}
private static Texture2D MakePanel(int w, int h, Color top, Color bottom, Color border, int borderSize)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: 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_0046: 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)
Texture2D val = new Texture2D(w, h, (TextureFormat)4, false);
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
Color val2 = Color.Lerp(top, bottom, (float)i / (float)h);
if (j < borderSize || i < borderSize || j >= w - borderSize || i >= h - borderSize)
{
val2 = border;
}
val.SetPixel(j, i, val2);
}
}
val.Apply();
((Texture)val).wrapMode = (TextureWrapMode)1;
return val;
}
private static GUIStyle MakeScrollbar(Texture2D track, Texture2D thumb, bool vertical)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
GUIStyle val = new GUIStyle();
val.normal.background = track;
val.border = new RectOffset(1, 1, 1, 1);
val.fixedWidth = (vertical ? 8f : 0f);
val.fixedHeight = (vertical ? 0f : 8f);
return val;
}
private static GUIStyle MakeThumb(Texture2D thumb)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
GUIStyle val = new GUIStyle();
val.normal.background = thumb;
val.border = new RectOffset(2, 2, 2, 2);
return val;
}
}