Decompiled source of BattleImprovements v1.4.3
plugins/battle_improve/BattleImprove.dll
Decompiled 2 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Net; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using BattleImprove.Components; using BattleImprove.Components.QOL; using BattleImprove.Patcher.QOL; using BattleImprove.Patcher.TakeHitPatcher; using BattleImprove.Transpiler; using BattleImprove.UI.InGame; using BattleImprove.Utils; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using PerfectRandom.Sulfur.Core; using PerfectRandom.Sulfur.Core.DevTools; using PerfectRandom.Sulfur.Core.Input; using PerfectRandom.Sulfur.Core.Items; using PerfectRandom.Sulfur.Core.Stats; using PerfectRandom.Sulfur.Core.Units; using PerfectRandom.Sulfur.Core.Weapons; using PerfectRandom.Sulfur.Core.World; using PerfectRandom.Sulfur.Gameplay; using TMPro; using UnityEngine; using UnityEngine.Rendering.Universal; using UnityEngine.UI; using UrGUI.UWindow; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyCompany("Cmmmmmm")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("GPL-3.0 license")] [assembly: AssemblyFileVersion("1.4.3.0")] [assembly: AssemblyInformationalVersion("1.4.3+09214d22758c6d14b4c2ff561b7d2fb8dd710aee")] [assembly: AssemblyProduct("Battle Improvements")] [assembly: AssemblyTitle("BattleImprove")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/CmmmmmmLau/SulFur_Battle_improvement")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.4.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } public class HitSoundEffect : MonoBehaviour { public AudioClip[] hitClose; public AudioClip[] hitFar; public AudioClip[] hitCrit; public void PlayHitSound(Vector3 position, bool isCrit, bool isFar = false, float volume = 1f) { //IL_0018: 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) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (isCrit) { AudioSource.PlayClipAtPoint(hitCrit[Random.Range(0, hitCrit.Length)], position, volume); } else if (isFar) { AudioSource.PlayClipAtPoint(hitFar[Random.Range(0, hitFar.Length)], position, volume); } else { AudioSource.PlayClipAtPoint(hitClose[Random.Range(0, hitClose.Length)], position, volume); } } } public class BF5MessageController : MessageController { public KillStreakController headshotStreak; public KillStreakController killStreak; protected override GameObject GetDamageInfo(string type, int damage, GameObject placeholder) { //IL_001e: 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) GameObject damageInfo = base.GetDamageInfo(type, damage, placeholder); damageInfo.transform.localPosition = new Vector3(0f, 0f, 0f); damageInfo.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 0.5f); TMP_Text component = damageInfo.GetComponent<TMP_Text>(); component.alignment = (TextAlignmentOptions)514; component.fontSize = 15f; return damageInfo; } public override void OnEnemyKill(string enemyName, string weaponName, string exp, bool isHeadShot, bool isFar = false) { base.OnEnemyKill(enemyName, weaponName, exp, isHeadShot, isFar); if (isHeadShot) { headshotStreak.AddKillStreak(); } else { killStreak.AddKillStreak(); } headshotStreak.ResetTimer(); killStreak.ResetTimer(); } } public class DamageSource : MonoBehaviour { public string damageType; public int damage; public TMP_Text message; private float timer; private GameObject placeholder; private void Start() { timer = 0f; message = ((Component)this).GetComponent<TMP_Text>(); } private void Update() { //IL_000c: 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_002c: Unknown result type (might be due to invalid IL or missing references) ((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, placeholder.transform.position, 200f * Time.deltaTime); timer += Time.deltaTime; if (timer > 5f) { Object.Destroy((Object)(object)placeholder); Object.Destroy((Object)(object)((Component)this).gameObject); } } public void InitMessage(string type, int damage, GameObject placeholder) { //IL_0015: 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) ((Component)this).transform.localPosition = new Vector3(0f, 0f, 0f); ((Component)this).transform.position = placeholder.transform.position; damageType = type; this.damage = damage; message.text = damageType + " " + damage; this.placeholder = placeholder; Reset(); } public void Reset() { timer = 0f; message.text = damageType + " " + damage; } } public class KillStreakController : MonoBehaviour { public GameObject FirstStreak; public TMP_Text streakCounter; public GameObject iconPrefab; public GameObject container; private float timer; private int streakCount; private void Start() { streakCounter.text = ""; timer = 0f; } private void Update() { if (!Object.op_Implicit((Object)(object)FirstStreak)) { return; } timer += Time.deltaTime; if (timer > 6f) { StreakIcon[] componentsInChildren = container.GetComponentsInChildren<StreakIcon>(); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].Fade(); } timer = 0f; streakCount = 0; streakCounter.text = ""; } } public void ResetTimer() { timer = 0f; } public void AddKillStreak() { GameObject placeholder = GetPlaceholder(); LayoutRebuilder.ForceRebuildLayoutImmediate(((Component)this).GetComponent<RectTransform>()); GameObject val = Object.Instantiate<GameObject>(iconPrefab, container.transform, false); val.GetComponent<StreakIcon>().InitStrekIcon(placeholder, this); streakCount++; if (!Object.op_Implicit((Object)(object)FirstStreak)) { FirstStreak = val; } if (streakCount % 5 == 0) { ((Component)streakCounter).gameObject.SetActive(true); StreakIcon[] componentsInChildren = container.GetComponentsInChildren<StreakIcon>(); foreach (StreakIcon streakIcon in componentsInChildren) { if ((Object)(object)((Component)streakIcon).gameObject != (Object)(object)FirstStreak && !streakIcon.NeedDestroyWhenOnPosition) { streakIcon.TargetPosition = FirstStreak; streakIcon.NeedDestroyWhenOnPosition = true; } } streakCounter.text = "×" + streakCount; } timer = 0f; } protected virtual GameObject GetPlaceholder() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown GameObject val = new GameObject("Placeholder", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(((Component)this).transform); val.transform.SetAsFirstSibling(); val.GetComponent<RectTransform>().sizeDelta = new Vector2(25f, 25f); return val; } } public class MessageController : MonoBehaviour { private GameObject banner; private TMP_Text tmpEnemyName; private TMP_Text tmpWeaponName; private TMP_Text tmpExp; private Animator bannerAnim; private bool isShowing; public AudioClip killSound; public AudioClip headShotKillSound; private AudioSource audioSource; private GameObject gameobjectTotalDamage; private TMP_Text tmpTotalDamage; private float timer; private int totalDamage; private int currentDamage; private GameObject damageInfoPlaceholder; private GameObject damageInfoContainer; private GameObject firstMessage; public GameObject damageSourcePrefab; internal PluginData.AttackFeedback data; private void Awake() { isShowing = false; InitBanner(); InitDamageInfo(); ResetDamageCounter(); } protected virtual GameObject InitDamageInfo() { GameObject gameObject = ((Component)((Component)this).transform.Find("Damage")).gameObject; gameobjectTotalDamage = ((Component)gameObject.transform.Find("Total")).gameObject; tmpTotalDamage = gameobjectTotalDamage.GetComponent<TMP_Text>(); damageInfoPlaceholder = ((Component)gameObject.transform.Find("Placeholder")).gameObject; damageInfoContainer = ((Component)gameObject.transform.Find("Container")).gameObject; return gameObject; } protected virtual GameObject InitBanner() { banner = ((Component)((Component)this).transform.Find("Banner")).gameObject; tmpEnemyName = ((Component)FindChild(banner.transform, "Enemy")).GetComponent<TMP_Text>(); tmpWeaponName = ((Component)FindChild(banner.transform, "Weapon")).GetComponent<TMP_Text>(); tmpExp = ((Component)FindChild(banner.transform, "Exp")).GetComponent<TMP_Text>(); bannerAnim = banner.GetComponent<Animator>(); audioSource = banner.GetComponent<AudioSource>(); return banner; } protected virtual void Start() { data = PluginData.DataDict["AttackFeedback"] as PluginData.AttackFeedback; } protected void Update() { UpdateTotalDamage(); if (isShowing && (timer += Time.deltaTime) > 5f) { ResetDamageCounter(); HideMessage(); } } public virtual void OnEnemyKill(string enemyName, string weaponName, string exp, bool isHeadShot, bool isFar = false) { tmpEnemyName.text = enemyName; tmpWeaponName.text = weaponName; tmpExp.text = exp; ((MonoBehaviour)this).StartCoroutine(ShowMessage()); PlayKillAudio(isHeadShot, isFar); } public void OnEnemyHit(string type, int damage) { gameobjectTotalDamage.SetActive(true); totalDamage += damage; if ((Object)(object)firstMessage != (Object)null && (Object)(object)damageInfoContainer != (Object)null) { DamageSource[] componentsInChildren = damageInfoContainer.GetComponentsInChildren<DamageSource>(); foreach (DamageSource damageSource in componentsInChildren) { if (damageSource.damageType == type) { damageSource.damage += damage; damageSource.Reset(); return; } } } AddDamageInfo(type, damage); } private static Transform FindChild(Transform parent, string name) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown foreach (Transform item in parent) { Transform val = item; if (((Object)val).name == name) { return val; } Transform val2 = FindChild(val, name); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } public void HideMessage() { isShowing = false; bannerAnim.SetTrigger("Fade"); } private void ResetDamageCounter() { gameobjectTotalDamage.SetActive(false); totalDamage = 0; currentDamage = 0; timer = 0f; } private IEnumerator ShowMessage() { if (!isShowing) { isShowing = true; bannerAnim.SetTrigger("Pop"); } yield return (object)new WaitForEndOfFrame(); Transform transform = banner.transform; LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)(object)((transform is RectTransform) ? transform : null)); } private void UpdateTotalDamage() { if (currentDamage < totalDamage) { timer = 0f; int num = Mathf.Max(1, (totalDamage - currentDamage) / 100); currentDamage += num; tmpTotalDamage.text = currentDamage.ToString(); } } protected virtual GameObject AddDamageInfo(string type, int damage) { GameObject placeholder = GetPlaceholder(); LayoutRebuilder.ForceRebuildLayoutImmediate(damageInfoPlaceholder.GetComponent<RectTransform>()); firstMessage = GetDamageInfo(type, damage, placeholder); return firstMessage; } protected virtual GameObject GetPlaceholder() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown GameObject val = new GameObject("Placeholder", new Type[1] { typeof(RectTransform) }); val.transform.SetParent(damageInfoPlaceholder.transform); val.transform.SetAsFirstSibling(); val.GetComponent<RectTransform>().sizeDelta = new Vector2(25f, 25f); return val; } protected virtual GameObject GetDamageInfo(string type, int damage, GameObject placeholder) { GameObject obj = Object.Instantiate<GameObject>(damageSourcePrefab, damageInfoContainer.transform); obj.GetComponent<DamageSource>().InitMessage(type, damage, placeholder); return obj; } protected virtual void PlayKillAudio(bool isHeadShot, bool isFar) { audioSource.PlayOneShot(isFar ? headShotKillSound : killSound, data.messageVolume); } } public class StreakIcon : MonoBehaviour { private Animator animator; private KillStreakController controller; private GameObject targetPosition; private bool needDestroyWhenOnPosition; public GameObject TargetPosition { get { if (!((Object)(object)targetPosition == (Object)null)) { return targetPosition; } return controller.FirstStreak; } set { if (Object.op_Implicit((Object)(object)targetPosition)) { Object.Destroy((Object)(object)targetPosition); } targetPosition = value; } } public bool NeedDestroyWhenOnPosition { get { return needDestroyWhenOnPosition; } set { if (value) { needDestroyWhenOnPosition = value; ((MonoBehaviour)this).StartCoroutine(DestroyWhenOnPosition()); } } } private void Start() { animator = ((Component)this).GetComponent<Animator>(); } private void Update() { //IL_0019: 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_0039: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)TargetPosition)) { ((Component)this).transform.position = Vector3.MoveTowards(((Component)this).transform.position, TargetPosition.transform.position, 200f * Time.deltaTime); } } public void InitStrekIcon(GameObject placeholder, KillStreakController controller) { //IL_0015: 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) ((Component)this).transform.localPosition = new Vector3(0f, 0f, 0f); ((Component)this).transform.position = placeholder.transform.position; targetPosition = placeholder; needDestroyWhenOnPosition = false; this.controller = controller; } public void Destroy(float delay = 0f) { Object.Destroy((Object)(object)targetPosition.gameObject, delay); Object.Destroy((Object)(object)((Component)this).gameObject, delay); } private IEnumerator DestroyWhenOnPosition() { while (((Component)this).transform.position != targetPosition.transform.position) { yield return (object)new WaitForEndOfFrame(); } Object.Destroy((Object)(object)((Component)this).gameObject); } public void Fade() { animator.SetTrigger("Fade"); Destroy(0.25f); } } public class xCrossHair : MonoBehaviour { public Animator crossHairAnim; private PluginData.AttackFeedback data; private Image[] images; private void Start() { if (data == null) { data = PluginData.DataDict["AttackFeedback"] as PluginData.AttackFeedback; } images = ((Component)this).GetComponentsInChildren<Image>(); } public void StartTrigger(string type) { if (!(type == "Hit")) { if (type == "Kill") { KillTrigger(); } } else { HitTrigger(); } } private void HitTrigger() { crossHairAnim.SetTrigger("Hit"); SetHitColor(); } private void KillTrigger() { crossHairAnim.SetTrigger("Kill"); SetKillColor(); } private void SetHitColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) Image[] array = images; for (int i = 0; i < array.Length; i++) { ((Graphic)array[i]).color = data.hitColor; } } private void SetKillColor() { //IL_0014: Unknown result type (might be due to invalid IL or missing references) Image[] array = images; for (int i = 0; i < array.Length; i++) { ((Graphic)array[i]).color = data.killColor; } } } public class LootDropVFX : MonoBehaviour { public ParticleSystem[] systems; private GameObject parentObject; private bool isScaling; private void Start() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) ((Component)this).transform.localPosition = new Vector3(0f, 0.1f, 0f); isScaling = true; ((MonoBehaviour)this).StartCoroutine(StopScale()); } private void Update() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: 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_008b: 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_009e: Unknown result type (might be due to invalid IL or missing references) bool mouseButton = Input.GetMouseButton(1); ParticleSystem[] array = systems; for (int i = 0; i < array.Length; i++) { ((Component)array[i]).gameObject.SetActive(!mouseButton); } if (isScaling) { ((Component)this).gameObject.transform.localScale = parentObject.transform.localScale; array = systems; foreach (ParticleSystem obj in array) { Vector3 localScale = parentObject.transform.localScale; ((Component)obj).transform.localScale = new Vector3(1f / localScale.x, 1f / localScale.y, 1f / localScale.z); } } } private IEnumerator StopScale() { yield return (object)new WaitForSeconds(3f); isScaling = false; } public void SetParent(GameObject parent) { parentObject = parent; } } namespace BattleImprove { [BepInPlugin("BattleImprove", "Battle Improvements", "1.4.3")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Logger; internal static Plugin instance; internal static LocalizationManager i18n; internal static bool firstLaunch; internal static Harmony harmony; private bool debugMode; internal static bool needUpdate => UpdateChecker.CheckForUpdate(); public void Awake() { instance = this; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Logger = ((BaseUnityPlugin)this).Logger; Logger.LogInfo((object)"Plugin BattleImprove 1.4.3 is loading!"); Config.InitConifg(((BaseUnityPlugin)this).Config); Patching(); ((MonoBehaviour)this).StartCoroutine(Prefab.LoadAssetBundle()); Logger.LogInfo((object)"Plugin BattleImprove is loaded!"); } private void Start() { LoggingInfo("Plugin is starting..."); ((MonoBehaviour)this).StartCoroutine(Init()); } private void OnDestroy() { harmony.UnpatchSelf(); } private IEnumerator Init() { LoggingInfo("Waiting for game boost...", needDebug: true); yield return (object)new WaitForSeconds(10f); LoggingInfo("Start Init!", needDebug: true); StaticInstance.InitGameObject(); } private void Patching() { harmony = Harmony.CreateAndPatchAll(typeof(StaticInstance), (string)null); if (Config.EnableExpShare.Value) { harmony.PatchAll(typeof(ExpSharePatch)); } if (Config.EnableHealthBar.Value) { harmony.PatchAll(typeof(HealthBarPatch)); } if (Config.EnableLoopDropVFX.Value) { harmony.PatchAll(typeof(LootDropPatch)); } if (Config.EnableDeadUnitCollision.Value) { harmony.PatchAll(typeof(RemoveDeadBodyCollisionTranspiler)); } if (Config.EnableDeadProtection.Value) { harmony.PatchAll(typeof(DeadProtection)); } if (Config.ReverseMouseScroll.Value) { harmony.PatchAll(typeof(MouseScrollTranspiler)); } if (Config.EnableSoundFeedback.Value) { harmony.PatchAll(typeof(SoundPatch)); } if (Config.EnableDamageMessage.Value) { harmony.PatchAll(typeof(DamageInfoPatch)); harmony.PatchAll(typeof(KillMessagePatch)); } if (Config.EnableXCrossHair.Value) { harmony.PatchAll(typeof(CrossHairPatch)); } } public void LoggingInfo(string info, bool needDebug = false) { if (needDebug) { if (debugMode) { Logger.LogInfo((object)("Debug info: " + info)); } } else { Logger.LogInfo((object)info); } } } public class Config { internal static ConfigEntry<bool> EnableHealthBar; internal static ConfigEntry<bool> EnableExpShare; internal static ConfigEntry<bool> EnableSoundFeedback; internal static ConfigEntry<bool> EnableDeadUnitCollision; internal static ConfigEntry<bool> EnableXCrossHair; internal static ConfigEntry<bool> EnableDamageMessage; internal static ConfigEntry<bool> EnableLoopDropVFX; internal static ConfigEntry<bool> EnableDeadProtection; internal static ConfigEntry<bool> ReverseMouseScroll; internal static ConfigEntry<float> Proportion; public static void InitConifg(ConfigFile cfg) { ToggleConfigInit(cfg); ExpShareConfigInit(cfg); OtherConfigInit(cfg); } private static void ToggleConfigInit(ConfigFile cfg) { EnableExpShare = cfg.Bind<bool>("Toggle/开关", "EnableExpShare", true, "Enable experience share/是否开启经验共享"); EnableHealthBar = cfg.Bind<bool>("Toggle/开关", "EnableHealthBar", true, "Enable health bar/是否开启血条"); EnableXCrossHair = cfg.Bind<bool>("Toggle/开关", "EnableHitFeedback", true, "Enable xCrossHair feedback/是否开启击中准心反馈"); EnableSoundFeedback = cfg.Bind<bool>("Toggle/开关", "EnableSoundFeedback", true, "Enable hit sound feedback on enemies/是否开启敌人受击声音反馈"); EnableDamageMessage = cfg.Bind<bool>("Toggle/开关", "EnableDamageMessage", true, "Enable damage and kill message/是否开启伤害与击杀信息"); EnableDeadUnitCollision = cfg.Bind<bool>("Toggle/开关", "EnableDeadUnitCollision", true, "Allowing bullets to pass through deadbody/是否使子弹能穿过尸体"); EnableLoopDropVFX = cfg.Bind<bool>("Toggle/开关", "EnableLoopDropVFX", true, "Enable loot drop VFX/是否开启掉落特效"); EnableDeadProtection = cfg.Bind<bool>("Toggle/开关", "EnableDeadProtection", true, "Enable dead protection/是否开启死亡保护"); } private static void ExpShareConfigInit(ConfigFile cfg) { Proportion = cfg.Bind<float>("ExpShare/经验共享", "Proportion", 0.5f, "The proportion of experience shared to second weapon/共享给第二把武器的经验比例"); } private static void OtherConfigInit(ConfigFile cfg) { ReverseMouseScroll = cfg.Bind<bool>("Other/其他", "ReverseMouseScroll", true, "Reverse mouse scroll direction/反转鼠标滚轮方向"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "BattleImprove"; public const string PLUGIN_NAME = "Battle Improvements"; public const string PLUGIN_VERSION = "1.4.3"; } } namespace BattleImprove.Utils { public class LocalizationManager { public enum SupportedLanguages { English, ChineseSimplified } private static Dictionary<string, string> localizationText = new Dictionary<string, string>(); private static SystemLanguage currentLanguage; public void LoadLocalization(SystemLanguage language) { //IL_002d: 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_0024: 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) if (Enum.GetNames(typeof(SupportedLanguages)).Contains<string>(((object)(SystemLanguage)(ref language)).ToString())) { currentLanguage = language; } else { currentLanguage = (SystemLanguage)10; } localizationText.Clear(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); string text = $"BattleImprove.Lang.{currentLanguage}.lang"; using Stream stream = executingAssembly.GetManifestResourceStream(text); if (stream == null) { Debug.LogError((object)("Failed to load localization file: " + text)); return; } using StreamReader streamReader = new StreamReader(stream); string[] array = streamReader.ReadToEnd().Split('\n'); foreach (string text2 in array) { if (!string.IsNullOrWhiteSpace(text2) && !text2.StartsWith("#")) { string[] array2 = text2.Split('=', 2); if (array2.Length == 2) { localizationText[array2[0].Trim()] = array2[1].Trim(); } } } } public string GetText(string key) { if (!localizationText.ContainsKey(key)) { return key; } return localizationText[key]; } } [Serializable] public class PluginData { public class Version : PluginData { public KeyCode menuKey = (KeyCode)282; public string version => "1.4.3"; } public class AttackFeedback : PluginData { public float indicatorVolume = 0.5f; public float indicatorDistance = 0.5f; public float indicatorDistanceFar = 0.5f; public float indicatorDistanceHeadShoot = 0.5f; public Color hitColor = Color.white; public Color killColor = Color.red; public int messageStyle; public float messageVolume = 0.5f; } public class DeadProtection : PluginData { public List<InventoryData> weapons = new List<InventoryData>(); public float weaponDurability = 0.3f; public float attachmentChance = 0.3f; public float enchantmentChance = 0.3f; } [NonSerialized] internal static Dictionary<string, PluginData> DataDict; [NonSerialized] public static Dictionary<int, string> KillMessageStyle = new Dictionary<int, string> { { 0, "Battlefield 1" }, { 1, "Battlefield 5" } }; public static bool SetupData() { try { if (SulfurSave.KeyExists("CmPlugin")) { Plugin.instance.LoggingInfo("Save data found, loading...", needDebug: true); DataDict = SulfurSave.Load<Dictionary<string, PluginData>>("CmPlugin", new Dictionary<string, PluginData>()); VerifyData(); return false; } Plugin.instance.LoggingInfo("Save data not found, creating new one...", needDebug: true); LoadDefaults(); Plugin.instance.LoggingInfo("Save data created!", needDebug: true); } catch (Exception value) { Console.WriteLine(value); Plugin.instance.LoggingInfo("Failed to load save data, creating new one...", needDebug: true); LoadDefaults(); throw; } return true; } private static void LoadDefaults() { DataDict = new Dictionary<string, PluginData> { { "BattleImprove", new Version() }, { "AttackFeedback", new AttackFeedback() }, { "DeadProtection", new DeadProtection() } }; SaveData(); } private static void VerifyData() { if (!DataDict.ContainsKey("BattleImprove")) { Plugin.instance.LoggingInfo("Save data missing BattleImprove, adding...", needDebug: true); DataDict.Add("BattleImprove", new Version()); } if (!DataDict.ContainsKey("AttackFeedback")) { Plugin.instance.LoggingInfo("Save data missing AttackFeedback, adding...", needDebug: true); DataDict.Add("AttackFeedback", new AttackFeedback()); } if (!DataDict.ContainsKey("DeadProtection")) { Plugin.instance.LoggingInfo("Save data missing DeadProtection, adding...", needDebug: true); DataDict.Add("DeadProtection", new DeadProtection()); } } private static void RemoveData() { DataDict = new Dictionary<string, PluginData>(); SaveData(); } public static void SaveData() { SulfurSave.SaveToDisk<Dictionary<string, PluginData>>("CmPlugin", DataDict); } } public class Prefab { internal static AssetBundle AssetBundle; public static Dictionary<string, GameObject> Prefabs = new Dictionary<string, GameObject>(); public static IEnumerator LoadAssetBundle() { Plugin.instance.LoggingInfo("Loading Asset Bundle...", needDebug: true); AssetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("BattleImprove.Assets.battle_improve")); if ((Object)(object)AssetBundle == (Object)null) { Plugin.instance.LoggingInfo("Failed to load custom assets."); yield break; } AssetBundleRequest request3 = AssetBundle.LoadAssetAsync<GameObject>("AttackFeedback"); yield return request3; Dictionary<string, GameObject> prefabs = Prefabs; Object asset = request3.asset; prefabs.Add("AttackFeedback", (GameObject)(object)((asset is GameObject) ? asset : null)); foreach (string style in PluginData.KillMessageStyle.Values) { request3 = AssetBundle.LoadAssetAsync<GameObject>(style); yield return request3; Dictionary<string, GameObject> prefabs2 = Prefabs; Object asset2 = request3.asset; prefabs2.Add(style, (GameObject)(object)((asset2 is GameObject) ? asset2 : null)); } for (int i = 1; i <= 5; i++) { request3 = AssetBundle.LoadAssetAsync<GameObject>("LoopDropTier" + i); yield return request3; Dictionary<string, GameObject> prefabs3 = Prefabs; string key = "LoopDropTier" + i; Object asset3 = request3.asset; prefabs3.Add(key, (GameObject)(object)((asset3 is GameObject) ? asset3 : null)); } } public static GameObject LoadPrefab(string name, GameObject parent) { Plugin.instance.LoggingInfo("Loading " + name + " Prefab...", needDebug: true); return Object.Instantiate<GameObject>(Prefabs[name], parent.transform, true); } } public class StaticInstance { internal static GameObject PluginGameObject; internal static GameObject IndicatorGameObject; internal static Npc[] Enemies; internal static List<Unit> KilledEnemies; internal static HitSoundEffect HitSoundClips; internal static xCrossHair CrossHair; internal static MessageController KillMessage; internal static LootSpawnHelper LootSpawnHelper; public static void InitGameObject() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown //IL_0044: 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_0076: Unknown result type (might be due to invalid IL or missing references) GameObject val = GameObject.Find("CmPlugin"); if ((Object)(object)val == (Object)null) { PluginGameObject = new GameObject("CmPlugin"); Object.DontDestroyOnLoad((Object)(object)PluginGameObject); } else { PluginGameObject = val; } Plugin.i18n = new LocalizationManager(); Plugin.i18n.LoadLocalization(Application.systemLanguage); Plugin.firstLaunch = PluginData.SetupData(); LoadPrefab(); LootSpawnHelper = PluginGameObject.AddComponent<LootSpawnHelper>(); GameObject val2 = new GameObject("Menu"); val2.transform.parent = PluginGameObject.transform; val2.AddComponent<MenuController>(); } internal static void LoadPrefab() { IndicatorGameObject = Prefab.LoadPrefab("AttackFeedback", PluginGameObject); HitSoundClips = PluginGameObject.GetComponentInChildren<HitSoundEffect>(); CrossHair = PluginGameObject.GetComponentInChildren<xCrossHair>(); PluginData.AttackFeedback attackFeedback = PluginData.DataDict["AttackFeedback"] as PluginData.AttackFeedback; LoadKillMessageStyle(PluginData.KillMessageStyle[attackFeedback.messageStyle]); } internal static void LoadKillMessageStyle(string style = "Battlefield 1") { if ((Object)(object)KillMessage != (Object)null) { Object.Destroy((Object)(object)((Component)KillMessage).gameObject); } KillMessage = Prefab.LoadPrefab(style, IndicatorGameObject).GetComponentInChildren<MessageController>(); } [HarmonyPrefix] [HarmonyPriority(800)] [HarmonyPatch(typeof(InputReader), "LoadingContinue")] private static void AddFrame() { Enemies = StaticInstance<UnitManager>.Instance.GetAllEnemies(); KilledEnemies = new List<Unit>(); } } public class UpdateChecker { private const string UPDATE_URL = "https://api.github.com/repos/CmmmmmmLau/SulFur_Battle_improvement/releases/latest"; public static bool CheckForUpdate() { using WebClient webClient = new WebClient(); webClient.Headers.Add("User-Agent", "UnityModUpdater"); try { string json = webClient.DownloadString("https://api.github.com/repos/CmmmmmmLau/SulFur_Battle_improvement/releases/latest"); string current = "1.4.3"; string text = ExtractVersionFromJson(json); if (CheckUpdate(current, text)) { Plugin.Logger.LogInfo((object)("New version available: " + text)); return true; } Plugin.Logger.LogInfo((object)"No new version available."); return false; } catch (WebException ex) { Plugin.Logger.LogError((object)("Failed to check for update: " + ex.Message)); return false; } } private static bool CheckUpdate(string current, string latest) { Version version = new Version(current); return new Version(latest) > version; } private static string ExtractVersionFromJson(string json) { int num = json.IndexOf("\"tag_name\":\"") + 12; int num2 = json.IndexOf("\",", num); return json.Substring(num, num2 - num).Replace("v", ""); } } } namespace BattleImprove.UI.InGame { public class WindowAttackFeedback : WindowBase { private PluginData.AttackFeedback data; private WLabel label; private string resourcePack { get { if (!((Object)(object)StaticInstance.IndicatorGameObject == (Object)null)) { return i18n.GetText("AttackFeedback.resource.loaded"); } return i18n.GetText("AttackFeedback.resource.missed"); } } protected override void Init() { //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) data = PluginData.DataDict["AttackFeedback"] as PluginData.AttackFeedback; window = UWindow.Begin("Attack Feedback", 200f, 10f, 22f, 5f, true, true, true); UWindow obj = window; obj.Width += 50f; StartPosition(310, 100); label = window.Label(i18n.GetText("AttackFeedback.resource") + ":" + resourcePack); window.Button("Reload", (Action)ReloadPrefab); window.Space(); window.Label(i18n.GetText("AttackFeedback.indicator")); window.Slider(i18n.GetText("AttackFeedback.volume"), (Action<float>)SetIndicatorVolume, data.indicatorVolume, 0f, 1f, true, "0.##"); window.Slider(i18n.GetText("AttackFeedback.distance"), (Action<float>)SetIndicatorDistance, data.indicatorDistance, 0f, 1f, true, "0.##"); window.Slider(i18n.GetText("AttackFeedback.distance.far"), (Action<float>)SetIndicatorDistanceFar, data.indicatorDistanceFar, 0f, 1f, true, "0.##"); window.Slider(i18n.GetText("AttackFeedback.distance.headshot"), (Action<float>)SetIndicatorDistanceHeadshoot, data.indicatorDistanceHeadShoot, 0f, 1f, true, "0.##"); window.Space(); window.Label(i18n.GetText("AttackFeedback.cross")); window.ColorPicker(i18n.GetText("AttackFeedback.hitcolor"), (Action<Color>)SetHitColor, data.hitColor); window.ColorPicker(i18n.GetText("AttackFeedback.killcolor"), (Action<Color>)SetChangeKillColor, data.killColor); window.Space(); window.Label(i18n.GetText("AttackFeedback.message")); window.DropDown(i18n.GetText("AttackFeedback.style"), (Action<int>)SetKillMessageStyle, data.messageStyle, PluginData.KillMessageStyle); window.Slider(i18n.GetText("AttackFeedback.volume"), (Action<float>)SetKillMessageVolume, data.messageVolume, 0f, 1f, true, "0.##"); window.Button(i18n.GetText("AttackFeedback.test"), (Action)TestKillMessage); window.Space(); base.Init(); } private void ReloadPrefab() { if ((Object)(object)StaticInstance.IndicatorGameObject == (Object)null) { StaticInstance.LoadPrefab(); } FieldInfo field = typeof(WLabel).GetField("DisplayedString", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(label, i18n.GetText("AttackFeedback.resource") + ":" + resourcePack); } } private void SetIndicatorVolume(float value) { data.indicatorVolume = value; } private void SetIndicatorDistance(float value) { data.indicatorDistance = value; } private void SetIndicatorDistanceFar(float value) { data.indicatorDistanceFar = value; } private void SetIndicatorDistanceHeadshoot(float value) { data.indicatorDistanceHeadShoot = value; } private void SetHitColor(Color color) { //IL_0006: 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) data.hitColor = color; } private void SetChangeKillColor(Color color) { //IL_0006: 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) data.killColor = color; } private void SetKillMessageStyle(int value) { data.messageStyle = value; StaticInstance.LoadKillMessageStyle(PluginData.KillMessageStyle[value]); } private void SetKillMessageVolume(float value) { data.messageVolume = value; } private void TestKillMessage() { StaticInstance.KillMessage.OnEnemyKill("Enemy Name#" + Random.RandomRangeInt(0, 10), "Weapon Name#" + Random.RandomRangeInt(0, 10), Random.RandomRangeInt(0, 10).ToString(), Random.RandomRangeInt(0, 10) < 5, Random.RandomRangeInt(0, 10) < 5); StaticInstance.KillMessage.OnEnemyHit("Bullet Damage Type#" + Random.RandomRangeInt(0, 10), Random.RandomRangeInt(0, 100)); } } public class WindowBase : MonoBehaviour { public UWindow window; internal MenuController controller; protected LocalizationManager i18n = Plugin.i18n; protected virtual void Start() { Init(); } public void Destroy() { Object.Destroy((Object)(object)this); } public virtual void Toggle() { window.IsDrawing = !window.IsDrawing; } internal WindowBase StartPosition(int x, int y) { window.X = x; window.Y = y; return this; } internal WindowBase SetController(MenuController controller) { this.controller = controller; return this; } protected virtual void Init() { window.Space(); window.Button("Close", (Action)Close); window.IsDrawing = false; } protected virtual void Close() { controller.SaveData(); window.IsDrawing = false; } } public class WindowDeadProtection : WindowBase { private PluginData.DeadProtection data; protected override void Init() { data = PluginData.DataDict["DeadProtection"] as PluginData.DeadProtection; window = UWindow.Begin("Dead Protection", 200f, 10f, 22f, 5f, true, true, true); UWindow obj = window; obj.Width += 50f; StartPosition(310, 100); window.Label(i18n.GetText("DeadProtection.durability")); window.Slider("", (Action<float>)OnDurabilityChange, data.weaponDurability, 0f, 1f, true, "0.##"); window.Label(i18n.GetText("DeadProtection.attachment")); window.Slider("", (Action<float>)OnAttachmentChange, data.attachmentChance, 0f, 1f, true, "0.##"); window.Label(i18n.GetText("DeadProtection.enchantment")); window.Slider("", (Action<float>)OnEnchantmentChange, data.enchantmentChance, 0f, 1f, true, "0.##"); base.Init(); } private void OnDurabilityChange(float value) { data.weaponDurability = value; } private void OnAttachmentChange(float value) { data.attachmentChance = value; } private void OnEnchantmentChange(float value) { data.enchantmentChance = value; } } public class WindowHotkey : WindowBase { private WLabel label; private bool needInput; private KeyCode key; protected override void Init() { window = UWindow.Begin(i18n.GetText("Hotkey.title"), 200f, 10f, 22f, 5f, true, true, true); PluginData.Version version = PluginData.DataDict["BattleImprove"] as PluginData.Version; label = window.Label(i18n.GetText("Hotkey.current") + " " + ((object)(KeyCode)(ref version.menuKey)).ToString()); StartPosition(350, 350); base.Init(); } public override void Toggle() { base.Toggle(); needInput = window.IsDrawing; } private void Update() { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) if (!needInput) { return; } Event current = Event.current; if (current.isKey) { key = current.keyCode; FieldInfo field = typeof(WLabel).GetField("DisplayedString", BindingFlags.Instance | BindingFlags.NonPublic); if (field != null) { field.SetValue(label, i18n.GetText("Hotkey.current") + " " + ((object)(KeyCode)(ref key)).ToString()); } } } protected override void Close() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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) (PluginData.DataDict["BattleImprove"] as PluginData.Version).menuKey = (KeyCode)(((int)key == 0) ? 282 : ((int)key)); PluginData.SaveData(); base.Close(); } } public class WindowMenu : WindowBase { protected override void Init() { window = UWindow.Begin("Battle Improvement", 200f, 10f, 22f, 5f, true, true, true); StartPosition(100, 100); window.Button(i18n.GetText("AttackFeedback"), (Action)delegate { OpenSubMenu("AttackFeedback"); }); window.Button(i18n.GetText("DeadProtection"), (Action)delegate { OpenSubMenu("DeadProtection"); }); window.Button(i18n.GetText("Settings"), (Action)delegate { OpenSubMenu("Setting"); }); base.Init(); } protected override void Close() { base.Close(); controller.CloseSubWindow(); controller.Pause(state: false); } private void OpenSubMenu(string name) { controller.OpenSubWindow(name); } } public class WindowSetting : WindowBase { protected override void Init() { window = UWindow.Begin(i18n.GetText("Settings"), 200f, 10f, 22f, 5f, true, true, true); UWindow obj = window; obj.Width += 50f; StartPosition(310, 100); window.Button(i18n.GetText("Reset"), (Action)Reset); window.Button(i18n.GetText("Hotkey"), (Action)ChangeMenuKey); base.Init(); } private void Reset() { controller.ResetWindow(); } private void ChangeMenuKey() { controller.OpenSubWindow("Hotkey", closeCurrent: false); } } public class WindowUpdateCheck : WindowBase { protected override void Start() { if (Plugin.needUpdate) { Init(); } else { Object.Destroy((Object)(object)this); } } protected override void Init() { window = UWindow.Begin("Update Check", 200f, 10f, 22f, 5f, true, true, true); StartPosition(0, 0); window.Space(); window.Label(Plugin.i18n.GetText("NeedUpdate")); window.Label(Plugin.i18n.GetText("NeedUpdate.Current") + "1.4.3"); window.Label(Plugin.i18n.GetText("NeedUpdate.Text")); base.Init(); window.IsDrawing = true; ((MonoBehaviour)this).StartCoroutine(AutoClose()); } private IEnumerator AutoClose() { yield return (object)new WaitForSeconds(5f); Close(); Destroy(); } } } namespace BattleImprove.Transpiler { public class MouseScrollTranspiler { [HarmonyTranspiler] [HarmonyPatch(typeof(InputReader), "SelectByScroll")] private static IEnumerable<CodeInstruction> ProjectileTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase original) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) CodeMatcher obj = new CodeMatcher(instructions, (ILGenerator)null).Start(); CodeInstruction val = obj.Instructions()[4]; if (val.opcode == OpCodes.Ble_Un_S || val.opcode == OpCodes.Ble_Un) { val.opcode = OpCodes.Bge_Un_S; } return obj.InstructionEnumeration(); } } public class RemoveDeadBodyCollisionTranspiler { [HarmonyTranspiler] [HarmonyPatch(typeof(Projectile), "HandleHit")] private static IEnumerable<CodeInstruction> ProjectileTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase original) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected O, but got Unknown //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Expected O, but got Unknown CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).End(); Label label = generator.DefineLabel(); val.Instructions()[val.Instructions().Count - 2].labels.Add(label); val.MatchBack(true, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(Projectile), "remainingBounceHits"), (string)null) }).ThrowIfInvalid("Failed to find the target code in Projectile.HandleHit"); if (val.IsValid) { CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_2, (object)null), Transpilers.EmitDelegate<Func<Hitbox, bool>>((Func<Hitbox, bool>)CheckHitboxAlive), new CodeInstruction(OpCodes.Brfalse_S, (object)label) }; val.Advance(3).InsertAndAdvance(array); } else { Plugin.instance.LoggingInfo("Failed to find the target code in Projectile.HandleHit"); } Plugin.instance.LoggingInfo("ProjectileTranspiler Transpiler is working", needDebug: true); return val.InstructionEnumeration(); } [HarmonyTranspiler] [HarmonyPatch(typeof(ProjectileSystem), "ProcessSortedHits")] private static IEnumerable<CodeInstruction> ProjectileSystemTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase original) { //IL_0009: 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_0049: Expected O, but got Unknown //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Expected O, but got Unknown //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Expected O, but got Unknown //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_016d: Expected O, but got Unknown //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Expected O, but got Unknown //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Expected O, but got Unknown //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01bd: Expected O, but got Unknown //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Expected O, but got Unknown //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Expected O, but got Unknown byte b = Convert.ToByte(2); CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).End(); Label label = generator.DefineLabel(); CodeMatch[] array = (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldarg_1), (string)null), new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => i.opcode == OpCodes.Ldc_R4 && i.operand.Equals(0f)), (string)null) }; CodeInstructionExtensions.WithLabels(val.MatchBack(false, array).ThrowIfInvalid("Failed to find the target code in in Line: 226 -> ptr.displacement = 0f;").Instruction, new Label[1] { label }); array = (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null) }; CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldloc_S, (object)b), Transpilers.EmitDelegate<Func<Hitbox, bool>>((Func<Hitbox, bool>)CheckHitboxAlive), new CodeInstruction(OpCodes.Brfalse_S, (object)label) }; val.MatchBack(false, array).ThrowIfInvalid("Failed to find the target code in Line: 225 -> ptr.velocity = Vector3.Reflect(ptr.velocity, raycastHit.normal) * num4;").Insert(array2); Label label2 = generator.DefineLabel(); array = (CodeMatch[])(object)new CodeMatch[6] { new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldloca_S, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldarg_2, (object)null, (string)null) }; CodeInstructionExtensions.WithLabels(val.MatchBack(true, array).ThrowIfInvalid("Failed to find the target code in Line: 182 -> ptr.position = raycastHit.point;").Instruction, new Label[1] { label2 }); array2 = (CodeInstruction[])(object)new CodeInstruction[3] { CodeInstructionExtensions.MoveLabelsFrom(new CodeInstruction(OpCodes.Ldloc_S, (object)b), val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[1] { array[0] }).Instruction), Transpilers.EmitDelegate<Func<Hitbox, bool>>((Func<Hitbox, bool>)CheckHitboxAlive), new CodeInstruction(OpCodes.Brfalse_S, (object)label2) }; val.Insert(array2); Plugin.instance.LoggingInfo("ProjectileSystemTranspiler Transpiler is working", needDebug: true); return val.InstructionEnumeration(); } private static bool CheckHitboxAlive(Hitbox hitbox) { if ((Object)(object)hitbox == (Object)null) { return true; } bool flag = !hitbox.GetOwner().isNpc || hitbox.GetOwner().IsAlive; Plugin.instance.LoggingInfo($"Checks whether to take over the bullet behavior: {flag}", needDebug: true); return flag; } } } namespace BattleImprove.Patcher.TakeHitPatcher { public class AttackFeedbackPatch { protected static bool TargetCheck(DamageSourceData source, Hitbox instance) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (!source.sourceUnit.isPlayer) { return false; } if (instance.Owner is Breakable || instance.Owner.isPlayer) { return false; } return true; } } [HarmonyWrapSafe] [HarmonyPatch(typeof(Hitbox), "TakeHit", new Type[] { typeof(float), typeof(DamageType), typeof(DamageSourceData), typeof(Vector3) })] public class CrossHairPatch : AttackFeedbackPatch { private static void Prefix(Hitbox __instance, out bool __state) { //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_000c: 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_0010: Invalid comparison between Unknown and I4 UnitState unitState = __instance.Owner.UnitState; bool flag = unitState - 1 <= 1; __state = flag; } private static void Postfix(Hitbox __instance, ref DamageSourceData source, bool __state) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)StaticInstance.CrossHair == (Object)null) && AttackFeedbackPatch.TargetCheck(source, __instance) && __state) { PlayHitAnimation(__instance.Owner); } } private static bool PlayHitAnimation(Unit unit) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 UnitState unitState = unit.UnitState; bool flag = unitState - 1 <= 1; bool flag2 = flag; if (Config.EnableXCrossHair.Value && flag2) { StaticInstance.CrossHair.StartTrigger("Hit"); } else { StaticInstance.CrossHair.StartTrigger("Kill"); } return flag2; } } [HarmonyWrapSafe] [HarmonyPatch(typeof(Hitbox), "TakeHit", new Type[] { typeof(float), typeof(DamageType), typeof(DamageSourceData), typeof(Vector3) })] public class DamageInfoPatch : AttackFeedbackPatch { private static void Prefix(Hitbox __instance, out float __state) { __state = __instance.Owner.GetCurrentHealth(); } private static void Postfix(Hitbox __instance, DamageType damageType, ref DamageSourceData source, Vector3 collisionPoint, float __state) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)StaticInstance.KillMessage == (Object)null || !AttackFeedbackPatch.TargetCheck(source, __instance) || !Config.EnableDamageMessage.Value) { return; } float num = __state - __instance.Owner.GetCurrentHealth(); if (num > 0f) { string text = ""; if (source.sourceWeapon.IsMelee) { text += ((ItemDefinition)source.sourceWeapon.weaponDefinition).displayName; } else { string[] obj = new string[6] { text, damageType.shortLabel, " ", source.sourceProjectile.CurrentCaliber.label, " ", null }; ProjectileTypes projectileType = source.sourceProjectile.projectileType; obj[5] = ((object)(ProjectileTypes)(ref projectileType)).ToString(); text = string.Concat(obj); } StaticInstance.KillMessage.OnEnemyHit(text, Convert.ToInt32(num)); } } } [HarmonyWrapSafe] [HarmonyPatch(typeof(Hitbox), "TakeHit", new Type[] { typeof(float), typeof(DamageType), typeof(DamageSourceData), typeof(Vector3) })] public class KillMessagePatch : AttackFeedbackPatch { private static void Prefix(Hitbox __instance, out float __state) { __state = __instance.Owner.GetCurrentHealth(); } private static void Postfix(Hitbox __instance, ref DamageSourceData source, Vector3 collisionPoint) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //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) //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_004e: 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_0053: Invalid comparison between Unknown and I4 if (!((Object)(object)StaticInstance.KillMessage == (Object)null) && AttackFeedbackPatch.TargetCheck(source, __instance) && !IsAlive(__instance.Owner)) { float num = Vector3.Distance(StaticInstance<GameManager>.Instance.GetPlayerUnit().EyesPosition, collisionPoint); HoldableWeightClass holdableWeightClass = ((Holdable)source.sourceWeapon).holdableWeightClass; bool flag = holdableWeightClass - 3 <= 1; bool flag2 = flag; string sourceName = __instance.Owner.SourceName; string displayName = ((ItemDefinition)source.sourceWeapon.weaponDefinition).displayName; string exp = Convert.ToString(__instance.Owner.ExperienceOnKill); StaticInstance.KillMessage.OnEnemyKill(sourceName, displayName, exp, __instance.bodyPart.label == "Head", num > 20f && flag2); } } private static bool IsAlive(Unit unit) { //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_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) UnitState unitState = unit.UnitState; if (unitState - 1 <= 1) { return true; } if (StaticInstance.KilledEnemies.Contains(unit) || !unit.LastDamagedBy.sourceUnit.isPlayer) { return true; } StaticInstance.KilledEnemies.Add(unit); return false; } } [HarmonyWrapSafe] [HarmonyPatch(typeof(Hitbox), "TakeHit", new Type[] { typeof(float), typeof(DamageType), typeof(DamageSourceData), typeof(Vector3) })] public class SoundPatch { private static PluginData.AttackFeedback data; private static void Postfix(Hitbox __instance, DamageType damageType, Vector3 collisionPoint) { //IL_005b: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Invalid comparison between Unknown and I4 //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: 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_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: 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_0149: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: 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) if ((Object)(object)StaticInstance.HitSoundClips == (Object)null) { return; } if (data == null) { data = PluginData.DataDict["AttackFeedback"] as PluginData.AttackFeedback; } if (__instance.Owner is Breakable || __instance.Owner.isPlayer) { return; } Npc component = ((Component)__instance.GetOwner()).gameObject.GetComponent<Npc>(); if ((int)((Unit)component).UnitState != 0 && StaticInstance.Enemies.Contains(component)) { float num = Vector3.Distance(StaticInstance<GameManager>.Instance.GetPlayerUnit().EyesPosition, ((Component)component).transform.position); GameObject player = StaticInstance<GameManager>.Instance.GetPlayer(); if ((int)damageType.id == 1 || __instance.bodyPart.label == "Head") { Vector3 position = Vector3.LerpUnclamped(player.transform.position, collisionPoint, data.indicatorDistanceHeadShoot); StaticInstance.HitSoundClips.PlayHitSound(position, isCrit: true, isFar: false, data.indicatorVolume); } else if (num < 20f) { Vector3 position2 = Vector3.LerpUnclamped(player.transform.position, collisionPoint, data.indicatorDistance); StaticInstance.HitSoundClips.PlayHitSound(position2, isCrit: false, isFar: false, data.indicatorVolume); } else { Vector3 position3 = Vector3.LerpUnclamped(player.transform.position, collisionPoint, data.indicatorDistanceFar); StaticInstance.HitSoundClips.PlayHitSound(position3, isCrit: false, isFar: true, data.indicatorVolume); } } } } } namespace BattleImprove.Patcher.QOL { public class DeadProtection { [HarmonyWrapSafe] [HarmonyPrefix] [HarmonyPatch(typeof(LootManager), "AddToChurchCollection")] private static void SavePlayerEquipment() { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Invalid comparison between Unknown and I4 //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_013b: 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_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_0188: 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_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown Plugin.instance.LoggingInfo("Player died, saving weapon! Quick!!!"); PluginData.DeadProtection deadProtection = PluginData.DataDict["DeadProtection"] as PluginData.DeadProtection; List<InventoryData> weapons = deadProtection.weapons; weapons.Clear(); foreach (InventoryItem item3 in ((Component)StaticInstance<GameManager>.Instance.GetPlayerUnit()).GetComponent<EquipmentManager>().EquippedHoldables.Select((KeyValuePair<InventorySlot, InventoryItem> item) => item.Value)) { if ((int)item3.SlotType == 7) { ItemDefinition itemDefinition = item3.itemDefinition; WeaponSO val = (WeaponSO)(object)((itemDefinition is WeaponSO) ? itemDefinition : null); Plugin.instance.LoggingInfo("Saved item: " + ((ItemDefinition)val).LocalizedDisplayName); Plugin.instance.LoggingInfo("Durability Current: " + item3.DurabilityCurrent); item3.ModifyDurability((float)(-item3.DurabilityCurrent) * (1f - deadProtection.weaponDurability)); Plugin.instance.LoggingInfo("Durability Modified: " + item3.DurabilityCurrent); Plugin.instance.LoggingInfo("Grabbing item data..."); string identifier = ((ItemDefinition)val).identifier; Vector2Int val2 = item3.gridPosition; int x = ((Vector2Int)(ref val2)).x; val2 = item3.gridPosition; int y = ((Vector2Int)(ref val2)).y; int quantity = item3.quantity; int currentAmmo = item3.currentAmmo; string identifier2 = val.caliber.identifier; ItemAttributeCollectionData obj = item3.stats.SerializedAttributeData(); string[] serializedAttachments = item3.GetSerializedAttachments(); string[] serializedEnchantments = item3.GetSerializedEnchantments(); val2 = item3.InventorySize; int x2 = ((Vector2Int)(ref val2)).x; val2 = item3.InventorySize; InventoryData item2 = new InventoryData(identifier, x, y, quantity, currentAmmo, identifier2, obj, serializedAttachments, serializedEnchantments, x2, ((Vector2Int)(ref val2)).y, false, false); Plugin.instance.LoggingInfo("Saving item data..."); weapons.Add(item2); } } PluginData.SaveData(); } [HarmonyWrapSafe] [HarmonyPostfix] [HarmonyPatch(typeof(ChurchCollectionLootable), "Loot")] private static void ReturnPlayerEquipment(ChurchCollectionLootable __instance) { Plugin.instance.LoggingInfo("Donation box opened, popping equipment back!"); Transform val = Traverse.Create((object)__instance).Field("lootSpawnTransform").GetValue<Transform>(); if ((Object)(object)val == (Object)null) { val = ((Component)__instance).transform; } PluginData.DeadProtection keptItems = PluginData.DataDict["DeadProtection"] as PluginData.DeadProtection; StaticInstance.LootSpawnHelper.SpawnItems(keptItems, val); } } public class ExpSharePatch { [HarmonyWrapSafe] [HarmonyPostfix] [HarmonyPatch(typeof(Npc), "GiveExperience")] private static void GiveExperiencePrePatch(Npc __instance) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 //IL_001b: 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_004f: Unknown result type (might be due to invalid IL or missing references) InventorySlot key = (InventorySlot)(((int)((Holdable)StaticInstance<GameManager>.Instance.GetPlayerUnit().lastUsedWeapon).inventorySlot == 4) ? 5 : 4); Dictionary<InventorySlot, InventoryItem> equippedHoldables = ((Component)StaticInstance<GameManager>.Instance.GetPlayerUnit()).GetComponent<EquipmentManager>().EquippedHoldables; float num = ((Unit)__instance).ExperienceOnKill; float value = Config.Proportion.Value; if (equippedHoldables.ContainsKey(key)) { equippedHoldables[key].AddExperience(num * value); } } } public class HealthBarPatch { [HarmonyWrapSafe] [HarmonyPrefix] [HarmonyPatch(typeof(UnitDebugFrame), "Update")] private static bool UpdateHPBar(UnitDebugFrame __instance) { if (StaticInstance<DevToolsManager>.Instance.shouldShow) { return true; } ((Component)__instance).transform.LookAt(((Component)StaticInstance<GameManager>.Instance.currentCamera).transform); HealthBar component = ((Component)__instance.owner).GetComponent<HealthBar>(); if (component.UpdateValue()) { Traverse.Create((object)__instance).Method("UpdateValues", Array.Empty<object>()).GetValue(); } if (__instance.owner.IsAlive) { return false; } ((Behaviour)component).enabled = false; ((Component)__instance).gameObject.SetActive(false); return false; } [HarmonyPostfix] [HarmonyPatch(typeof(Npc), "Start")] private static void AddDebugFrame(Player __instance) { ((Component)__instance).gameObject.AddComponent<HealthBar>(); } } public class LootDropPatch { [HarmonyWrapSafe] [HarmonyPostfix] [HarmonyPatch(typeof(Pickup), "Spawn")] private static void Postfix(Pickup __instance) { //IL_0046: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Expected I4, but got Unknown Plugin.instance.LoggingInfo("LootParticle Postfix", needDebug: true); GameObject gameObject = ((Component)((Component)__instance).transform.Find("Shadow")).gameObject; Object.Destroy((Object)(object)gameObject.GetComponent<DecalProjector>()); ItemQuality itemQuality = Traverse.Create((object)__instance).Field("item").GetValue<ItemDefinition>() .itemQuality; ((GameObject)((int)itemQuality switch { 0 => Prefab.LoadPrefab("LoopDropTier1", ((Component)__instance).gameObject), 1 => Prefab.LoadPrefab("LoopDropTier2", ((Component)__instance).gameObject), 2 => Prefab.LoadPrefab("LoopDropTier3", ((Component)__instance).gameObject), 3 => Prefab.LoadPrefab("LoopDropTier4", ((Component)__instance).gameObject), 4 => Prefab.LoadPrefab("LoopDropTier5", ((Component)__instance).gameObject), _ => Prefab.LoadPrefab("LoopDropTier1", ((Component)__instance).gameObject), })).GetComponent<LootDropVFX>().SetParent(gameObject); } } } namespace BattleImprove.Components { public class MenuController : MonoBehaviour { protected Dictionary<string, WindowBase> windos = new Dictionary<string, WindowBase>(); protected WindowBase currentWindow; protected WindowBase menu; protected KeyCode menuKey => (PluginData.DataDict["BattleImprove"] as PluginData.Version).menuKey; private void Start() { ((Component)this).gameObject.AddComponent<WindowUpdateCheck>().SetController(this); InitWindow(); } public void Update() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (Input.GetKeyDown(menuKey)) { ToggleMenu(); } } public void ResetWindow() { ToggleMenu(); foreach (KeyValuePair<string, WindowBase> windo in windos) { windo.Value.Destroy(); } windos.Clear(); InitWindow(); } private void InitWindow() { menu = ((Component)this).gameObject.AddComponent<WindowMenu>().SetController(this); windos.Add("Menu", menu); WindowBase value = ((Component)this).gameObject.AddComponent<WindowAttackFeedback>().SetController(this); windos.Add("AttackFeedback", value); WindowBase value2 = ((Component)this).gameObject.AddComponent<WindowDeadProtection>().SetController(this); windos.Add("DeadProtection", value2); WindowBase value3 = ((Component)this).gameObject.AddComponent<WindowSetting>().SetController(this); windos.Add("Setting", value3); WindowBase value4 = ((Component)this).gameObject.AddComponent<WindowHotkey>().SetController(this); windos.Add("Hotkey", value4); } public void ToggleMenu() { if ((Object)(object)menu.window.ActiveSkin == (Object)null) { UWindow.RestoreGlobalDefaultSkin(); } menu.Toggle(); if (menu.window.IsDrawing) { if ((Object)(object)currentWindow != (Object)null) { currentWindow.Toggle(); } Pause(state: true); } else { CloseSubWindow(); Pause(state: false); } SaveData(); } public void SaveData() { PluginData.SaveData(); } public void Pause(bool state) { GameManager instance = StaticInstance<GameManager>.Instance; if (!((Object)(object)instance == (Object)null)) { instance.ModifyCursorState((ControllerLockState)4, state); instance.ModifyControllerLock((ControllerLockState)4, state); } } public void OpenSubWindow(string name, bool closeCurrent = true) { if ((Object)(object)currentWindow != (Object)null && (Object)(object)currentWindow != (Object)(object)windos[name] && currentWindow.window.IsDrawing && closeCurrent) { currentWindow.Toggle(); } if (closeCurrent) { currentWindow = windos[name]; currentWindow.Toggle(); } else { windos[name].Toggle(); } } public void CloseSubWindow() { foreach (KeyValuePair<string, WindowBase> windo in windos) { windo.Value.window.IsDrawing = false; } } } } namespace BattleImprove.Components.QOL { public class HealthBar : MonoBehaviour { private Camera camera; private bool isInitialized; private Npc npc; private float timer; private void Start() { npc = ((Component)this).gameObject.GetComponent<Npc>(); if (((Unit)npc).IsProtectedNpc) { Object.Destroy((Object)(object)this); return; } isInitialized = false; ((MonoBehaviour)this).StartCoroutine(Initialize()); } private void Update() { //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_0045: Unknown result type (might be due to invalid IL or missing references) if (isInitialized && ((Unit)npc).IsAlive) { Vector3 eyesPosition = ((Unit)npc).EyesPosition; timer += Time.deltaTime; ((Component)((Unit)npc).debugFrame).gameObject.SetActive(CheckVisible(eyesPosition)); } } private IEnumerator Initialize() { yield return (object)new WaitForSeconds(3f); StaticInstance<DevToolsManager>.Instance.AddDebugFrameToUnit((Unit)(object)npc); camera = StaticInstance<GameManager>.Instance.currentCamera; isInitialized = true; } private bool CheckVisible(Vector3 position) { //IL_0006: 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_000c: 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) //IL_001a: 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_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) try { Vector3 val = camera.WorldToViewportPoint(position); int result; if (val.z > 0f) { float x = val.x; if (x > 0f && x < 1f) { float y = val.y; if (y > 0f && y < 1f) { result = ((Vector3.Distance(position, ((Component)camera).transform.position) < 15f) ? 1 : 0); goto IL_0068; } } } result = 0; goto IL_0068; IL_0068: return (byte)result != 0; } catch { Plugin.Logger.LogInfo((object)"Player camera lost, trying to find it again"); camera = StaticInstance<GameManager>.Instance.currentCamera; StaticInstance<DevToolsManager>.Instance.AddDebugFrameToUnit((Unit)(object)npc); } return false; } public bool UpdateValue() { if (!(timer > 0.25f)) { return false; } timer = 0f; return true; } } public class LootSpawnHelper : MonoBehaviour { private PluginData.DeadProtection data; private void Start() { data = PluginData.DataDict["DeadProtection"] as PluginData.DeadProtection; } public void SpawnItems(PluginData.DeadProtection keptItems, Transform transform) { ((MonoBehaviour)this).StartCoroutine(SpawnWeapon(keptItems.weapons, transform)); } private IEnumerator SpawnWeapon(List<InventoryData> weapons, Transform transform) { foreach (InventoryData weapon in weapons) { ItemDefinition item = StaticInstance<LootManager>.Instance.GetItem(weapon.identifier); weapon.attachments = RandomDeleteElement(weapon.attachments, data.attachmentChance); weapon.enchantments = RandomDeleteElement(weapon.enchantments, data.enchantmentChance); Pickup obj = StaticInstance<LootManager>.Instance.SpawnItem(item, new Vector3(transform.position.x, transform.position.y, transform.position.z + 0.08f), (LootSpawnBehaviour)0, false); Traverse.Create((object)obj).Field("inventoryData").SetValue((object)weapon); obj.SetAliveTimerMinBeforePickups(0.75f); yield return (object)new WaitForSeconds(1f); } weapons.Clear(); PluginData.SaveData(); } private string[] RandomDeleteElement(string[] array, float chance) { List<string> list = new List<string>(array); foreach (string item in list.ToList()) { float num = Random.Range(0f, 1f); Plugin.instance.LoggingInfo("Rolling for " + item + " with chance " + chance + " got " + num); if (num < chance) { list.Remove(item); } } return list.ToArray(); } } }
plugins/battle_improve/UrGUI.dll
Decompiled 2 months agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using UnityEngine; using UrGUI.UWindow.Utils; using UrGUI.Utils; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("UrGUI")] [assembly: AssemblyDescription("Easy to use extension for Unity IMGUI system. https://github.com/Hirashi3630/UrGUI")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("UrGUI")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("9f3e6286-13be-456c-90f4-31b1dda6dc28")] [assembly: AssemblyFileVersion("1.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")] [assembly: AssemblyVersion("1.1.8841.27572")] namespace UrGUI.UWindow { public class UWindow { public string WinGuid; public string WindowTitle; public float X; public float Y; public float Width; public float Height; public bool IsDraggable; public bool DynamicHeight; private float _startX; private float _startY; private float _margin; private float _controlHeight; private float _controlSpace; private float _sameLineOffset; private List<float> _nextLineRatios = new List<float>(0); private bool _isDragging; private float _nextControlY; private List<WControl> _controls; public GUISkin ActiveSkin { get; internal set; } = null; public bool IsDrawing { get; set; } private protected UWindow() { } public static UWindow Begin(string windowTitle = "a Title", float startWidth = 200f, float margin = 10f, float controlHeight = 22f, float controlSpace = 5f, bool isEnabled = true, bool isDraggable = true, bool dynamicHeight = true) { //IL_000a: 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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) int num = 400; Vector2 dynamicWindowPos = UWindowManager.GetDynamicWindowPos(startWidth); return Begin(windowTitle, dynamicWindowPos.x, dynamicWindowPos.y, startWidth, num, margin, controlHeight, controlSpace, isEnabled, isDraggable, dynamicHeight); } public static UWindow Begin(string windowTitle, float startX, float startY, float startWidth, float startHeight, float margin = 10f, float controlHeight = 22f, float controlSpace = 5f, bool isDrawing = true, bool isDraggable = true, bool dynamicHeight = false) { UWindow uWindow = new UWindow { IsDrawing = isDrawing, WindowTitle = windowTitle, X = startX, Y = startY, Width = startWidth, Height = startHeight, _margin = margin, _controlHeight = controlHeight, _controlSpace = controlSpace, IsDraggable = isDraggable, DynamicHeight = dynamicHeight, _controls = new List<WControl>() }; uWindow._startX = startX; uWindow._startY = startY; UWindowManager.Register(uWindow); return uWindow; } internal void Draw() { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_024e: 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_0108: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Invalid comparison between Unknown and I4 //IL_0126: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Invalid comparison between Unknown and I4 //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_0146: 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) if (!IsDrawing) { return; } if ((Object)(object)ActiveSkin != (Object)null) { GUI.skin = ActiveSkin; } if (UWindowManager.AllWindowsDisabled) { GUI.enabled = false; } Event current = Event.current; Rect val; if ((int)current.type == 0) { val = new Rect(X, Y, Width, Height); if (((Rect)(ref val)).Contains(current.mousePosition)) { UWindowManager.BringUWindowToFront(this); } } if (IsDraggable && (!UWindowManager.AnyWindowDragging || _isDragging)) { if ((int)current.type == 0) { val = new Rect(X, Y, Width, _controlHeight * 1.25f); if (((Rect)(ref val)).Contains(current.mousePosition)) { _isDragging = true; UWindowManager.AnyWindowDragging = true; goto IL_0125; } } if ((int)current.type == 1) { _isDragging = false; UWindowManager.AnyWindowDragging = false; } goto IL_0125; } goto IL_0171; IL_0125: if ((int)current.type == 3 && _isDragging) { X += current.delta.x; Y += current.delta.y; } goto IL_0171; IL_0171: if (X < 0f) { X = 0f; } if (Y < 0f) { Y = 0f; } if (X + Width > (float)Screen.width) { X = (float)Screen.width - Width; } if (Y + Height > (float)Screen.height) { Y = (float)Screen.height - Height; } _nextControlY = Y + _controlHeight + _margin; if (_isDragging) { GUI.enabled = false; } GUI.Box(new Rect(X, Y, Width, Height), ""); GUI.Box(new Rect(X, Y, Width, 25f), WindowTitle); if ((Object)(object)ActiveSkin != (Object)null) { GUI.skin = ActiveSkin; } foreach (WControl control in _controls) { control.Draw(NextControlRect(control.SameLineRatio)); } GUI.enabled = true; } public void ResetPosition() { X = _startX; Y = _startY; } public bool SaveCfg(string absolutePath) { try { INIParser iNIParser = new INIParser(); iNIParser.Open(absolutePath); string sectionName = "UWindow." + WindowTitle; iNIParser.WriteValue(sectionName, "windowTitle", WindowTitle); iNIParser.WriteValue(sectionName, "x", X); iNIParser.WriteValue(sectionName, "y", Y); iNIParser.WriteValue(sectionName, "width", Width); iNIParser.WriteValue(sectionName, "height", Height); iNIParser.WriteValue(sectionName, "margin", _margin); iNIParser.WriteValue(sectionName, "controlHeight", _controlHeight); iNIParser.WriteValue(sectionName, "controlSpace", _controlSpace); for (int i = 0; i < _controls.Count; i++) { _controls[i].ExportData(i, sectionName, $"Control{i}.", iNIParser); } iNIParser.Close(); return true; } catch { return false; } } public bool LoadCfg(string absolutePath) { if (!File.Exists(absolutePath)) { return false; } try { INIParser iNIParser = new INIParser(); iNIParser.Open(absolutePath); string sectionName = "UWindow." + WindowTitle; WindowTitle = iNIParser.ReadValue(sectionName, "windowTitle", WindowTitle); X = iNIParser.ReadValue(sectionName, "x", X); Y = iNIParser.ReadValue(sectionName, "y", Y); Width = iNIParser.ReadValue(sectionName, "width", Width); Height = iNIParser.ReadValue(sectionName, "height", Height); _margin = iNIParser.ReadValue(sectionName, "margin", _margin); _controlHeight = iNIParser.ReadValue(sectionName, "controlHeight", _controlHeight); _controlSpace = iNIParser.ReadValue(sectionName, "controlSpace", _controlSpace); for (int i = 0; i < _controls.Count; i++) { _controls[i].ImportData(i, sectionName, $"Control{i}.", iNIParser); } iNIParser.Close(); return true; } catch { return false; } } public bool LoadSkin(GUISkin mainSkin) { if ((Object)(object)mainSkin == (Object)null) { return false; } ActiveSkin = mainSkin; return true; } public bool LoadSkinFromAssetBundle(string absolutePathAssetBundle, string mainSkinName) { AssetBundle assetBundle = AssetBundle.LoadFromFile(absolutePathAssetBundle); return LoadSkinFromAssetBundle(assetBundle, mainSkinName); } public bool LoadSkinFromAssetBundle(Stream assetFromStream, string mainSkinName) { AssetBundle assetBundle = AssetBundle.LoadFromStream(assetFromStream); return LoadSkinFromAssetBundle(assetBundle, mainSkinName); } public bool LoadSkinFromAssetBundle(byte[] assetFromMemory, string mainSkinName) { AssetBundle assetBundle = AssetBundle.LoadFromMemory(assetFromMemory); return LoadSkinFromAssetBundle(assetBundle, mainSkinName); } public bool LoadSkinFromAssetBundle(AssetBundle assetBundle, string mainSkinName) { if ((Object)(object)assetBundle == (Object)null) { return false; } LoadSkin(assetBundle.LoadAsset<GUISkin>(mainSkinName)); return true; } public bool RestoreDefaultSkin() { if ((Object)(object)UWindowManager.DefaultSkin == (Object)null) { return false; } ActiveSkin = UWindowManager.DefaultSkin; return true; } public static bool RestoreGlobalDefaultSkin() { return UWindowManager.LoadGlobalSkin_internal(UWindowManager.DefaultSkin); } public static bool LoadGlobalSkin(GUISkin skin) { return UWindowManager.LoadGlobalSkin_internal(skin); } private Rect NextControlRect(float sameLineRatio) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) float num = Width - _margin * 2f; Rect result = default(Rect); ((Rect)(ref result))..ctor(X + _margin + _sameLineOffset, _nextControlY, num, _controlHeight); if (sameLineRatio.Equals(1f)) { _nextControlY += _controlHeight + _controlSpace; } else { ((Rect)(ref result)).width = ((Rect)(ref result)).width * sameLineRatio; _sameLineOffset += ((Rect)(ref result)).width; if (_sameLineOffset.Equals(num)) { _nextControlY += _controlHeight + _controlSpace; _sameLineOffset = 0f; } } return result; } public void Add(WControl c) { _controls.Add(c); if (_nextLineRatios.Count > 0) { c.SameLineRatio = _nextLineRatios[0]; _nextLineRatios.RemoveAt(0); } if (!DynamicHeight) { return; } float num = 25f + _margin; float num2 = _controlHeight + _controlSpace; int num3 = 0; float num4 = 1f; foreach (WControl control in _controls) { if (control.SameLineRatio.Equals(1f) || num4 < 0.05f) { num3++; num4 = 1f; continue; } num4 -= control.SameLineRatio; if (num4 < 0.05f) { num3++; } } Height = num + num2 * (float)num3; } public bool SameLine(int ratio1 = 1, int ratio2 = 1, int ratio3 = -1, int ratio4 = -1, int ratio5 = -1) { if (_nextLineRatios.Count > 0) { return false; } if (ratio1 <= 0 || ratio2 <= 0) { return false; } List<int> list = new List<int> { ratio1, ratio2 }; if (ratio3 > 0) { list.Add(ratio3); if (ratio4 > 0) { list.Add(ratio4); if (ratio5 > 0) { list.Add(ratio5); } } } int num = list.Min(); List<float> list2 = new List<float>(); foreach (int item in list) { list2.Add((float)item / (float)num); } float num2 = list2.Sum(); list2.Clear(); foreach (int item2 in list) { list2.Add((float)item2 / num2); } _nextLineRatios = list2; return true; } public UWindowControls.WSpace Space() { UWindowControls.WSpace wSpace = new UWindowControls.WSpace(); Add(wSpace); return wSpace; } public UWindowControls.WLabel Label(string text) { UWindowControls.WLabel wLabel = new UWindowControls.WLabel(text); Add(wLabel); return wLabel; } public UWindowControls.WButton Button(string text, Action onPressed) { UWindowControls.WButton wButton = new UWindowControls.WButton(onPressed, text); Add(wButton); return wButton; } public UWindowControls.WToggle Toggle(string text, Action<bool> onValueChanged, bool value = false) { UWindowControls.WToggle wToggle = new UWindowControls.WToggle(onValueChanged, value, text); Add(wToggle); return wToggle; } public UWindowControls.WSlider Slider(string text, Action<float> onValueChanged, float value, float min, float max, bool numberIndicator = false, string numberIndicatorFormat = "0.##") { UWindowControls.WSlider wSlider = new UWindowControls.WSlider(onValueChanged, value, min, max, numberIndicator, numberIndicatorFormat, text); Add(wSlider); return wSlider; } public UWindowControls.WTextField TextField(string text, Action<string> onValueChanged, string value, int maxSymbolLength = int.MaxValue, string regexReplace = "") { UWindowControls.WTextField wTextField = new UWindowControls.WTextField(onValueChanged, value, maxSymbolLength, regexReplace, text); Add(wTextField); return wTextField; } public UWindowControls.WIntField IntField(string text, Action<int> onValueChanged, int value, int maxSymbolLength = int.MaxValue) { UWindowControls.WIntField wIntField = new UWindowControls.WIntField(onValueChanged, value, maxSymbolLength, text); Add(wIntField); return wIntField; } public UWindowControls.WFloatField FloatField(string text, Action<float> onValueChanged, float value, int maxSymbolLength = int.MaxValue) { UWindowControls.WFloatField wFloatField = new UWindowControls.WFloatField(onValueChanged, value, maxSymbolLength, text); Add(wFloatField); return wFloatField; } public UWindowControls.WColorPicker ColorPicker(string text, Action<Color> onValueChanged, Color value) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) UWindowControls.WColorPicker wColorPicker = new UWindowControls.WColorPicker(onValueChanged, value, text, _controlHeight); Add(wColorPicker); return wColorPicker; } public UWindowControls.WDropDown DropDown(string text, Action<int> onValueChanged, int value, Dictionary<int, string> list) { UWindowControls.WDropDown wDropDown = new UWindowControls.WDropDown(onValueChanged, value, list, text); Add(wDropDown); return wDropDown; } public UWindowControls.WSeparator Separator(Color lineColor = default(Color), float lineThickness = 2f) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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) if (lineColor == default(Color)) { ((Color)(ref lineColor))..ctor(1f, 1f, 1f, 0.9f); } UWindowControls.WSeparator wSeparator = new UWindowControls.WSeparator(lineColor, lineThickness); Add(wSeparator); return wSeparator; } } public static class UWindowControls { public class WLabel : WControl { private Rect _rect = default(Rect); internal WLabel(string displayedString) : base(displayedString) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (displayedString == null || string.IsNullOrEmpty(displayedString) || string.IsNullOrWhiteSpace(displayedString)) { Logger.war("Label is null or empty! Are you sure you don't want to use Space control instead?"); } } internal override void Draw(Rect r) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: 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_003d: 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) _rect = r; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(((Rect)(ref _rect)).x, ((Rect)(ref _rect)).y); ((Rect)(ref _rect)).x = val.x; ((Rect)(ref _rect)).y = val.y; GUI.Label(_rect, DisplayedString); } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); } } public class WButton : WControl { private readonly Action _onPressed; internal WButton(Action onPressed, string displayedString) : base(displayedString) { _onPressed = onPressed; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if (UGUI.Button(r, DisplayedString)) { _onPressed(); } } } public class WToggle : WControl { public readonly Action<bool> OnValueChanged; public bool Value; private GUIStyle _toggleStyle = null; internal WToggle(Action<bool> onValueChanged, bool value, string displayedString) : base(displayedString) { Value = value; OnValueChanged = onValueChanged; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: 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_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown Rect val = r; if (_toggleStyle == null) { _toggleStyle = new GUIStyle(GUI.skin.toggle); } int num = Mathf.RoundToInt(((Rect)(ref r)).width - ((Rect)(ref r)).height); _toggleStyle.overflow.left = -num; _toggleStyle.overflow.right = num; bool flag = GUI.Toggle(val, Value, string.Empty, _toggleStyle); if (flag != Value) { OnValueChanged(flag); } Value = flag; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WSlider : WControl { public readonly Action<float> OnValueChanged; public float Value; private float _min; private float _max; private bool _numberIndicator; private bool _labelOnLeft; private string _numberIndicatorFormat; internal WSlider(Action<float> onValueChanged, float value, float min, float max, bool numberIndicator, string numberIndicatorFormat, string displayedString, bool labelOnLeft = true) : base(displayedString) { OnValueChanged = onValueChanged; Value = value; _min = min; _max = max; _numberIndicator = numberIndicator; _numberIndicatorFormat = numberIndicatorFormat; _labelOnLeft = labelOnLeft; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) float num = UControls.LabelSlider(r, DisplayedString, Value, _min, _max, _numberIndicator, _numberIndicatorFormat, _labelOnLeft); if (!num.Equals(Value)) { OnValueChanged(num); } Value = num; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WTextField : WControl { public readonly Action<string> OnValueChanged; public string Value; private string _regexReplace; private int _maxSymbolLength; private bool _labelOnLeft; internal WTextField(Action<string> onValueChanged, string value, int maxSymbolLength, string regexReplace, string displayedString, bool labelOnLeft = true) : base(displayedString) { OnValueChanged = onValueChanged; Value = value; _regexReplace = regexReplace; _maxSymbolLength = maxSymbolLength; _labelOnLeft = labelOnLeft; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) string text = UControls.LabelTextField(r, DisplayedString, Value, _maxSymbolLength, _regexReplace, _labelOnLeft); if (_regexReplace != string.Empty) { text = Regex.Replace(text, _regexReplace, ""); } if (text != Value) { OnValueChanged(text); } Value = text; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WIntField : WControl { public readonly Action<int> OnValueChanged; public int Value; private string _regexReplace; private int _maxSymbolLength; private bool _labelOnLeft; internal WIntField(Action<int> onValueChanged, int value, int maxSymbolLength, string displayedString, bool labelOnLeft = true) : base(displayedString) { OnValueChanged = onValueChanged; Value = value; _regexReplace = "[^0-9]"; _maxSymbolLength = maxSymbolLength; _labelOnLeft = labelOnLeft; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) string text = UControls.LabelTextField(r, DisplayedString, Value.ToString(), _maxSymbolLength, _regexReplace, _labelOnLeft); if (_regexReplace != string.Empty) { text = Regex.Replace(text, _regexReplace, ""); } long.TryParse(text, out var result); int num = (int)((result > int.MaxValue) ? int.MaxValue : result); if (!result.Equals(Value)) { OnValueChanged(num); } Value = num; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WFloatField : WControl { public readonly Action<float> OnValueChanged; public float Value; private string _regexReplace; private int _maxSymbolLength; private bool _labelOnLeft; internal WFloatField(Action<float> onValueChanged, float value, int maxSymbolLength, string displayedString, bool labelOnLeft = true) : base(displayedString) { OnValueChanged = onValueChanged; Value = value; _regexReplace = "[^0-9.,]"; _maxSymbolLength = maxSymbolLength; _labelOnLeft = labelOnLeft; } internal override void Draw(Rect r) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) string text = UControls.LabelTextField(r, DisplayedString, Value.ToString(), _maxSymbolLength, _regexReplace, _labelOnLeft); if (_regexReplace != string.Empty) { text = Regex.Replace(text, _regexReplace, ""); } text = text.Replace(',', '.'); double.TryParse(text, out var result); float num = (float)result; if (!num.Equals(Value)) { OnValueChanged(num); } Value = num; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WColorPicker : WControl { public Color CurrentColor; private readonly Action<Color> _onValueChanged; private bool _isPickerOpen = false; private Rect _rect; private readonly float _controlHeight; private Color _revertColor; private readonly GUIStyle _whiteButtonGUIStyle = new GUIStyle { normal = new GUIStyleState { background = Texture2D.whiteTexture } }; private bool IsPickerOpen { get { return _isPickerOpen; } set { //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) _isPickerOpen = value; UWindowManager.AllWindowsDisabled = value; if (value) { UWindowManager.ActiveOptionMenu = DrawPicker; _revertColor = CurrentColor; } else { UWindowManager.ActiveOptionMenu = null; } } } internal WColorPicker(Action<Color> onValueChanged, Color clr, string displayedString, float controlHeight) : base(displayedString) { //IL_0008: 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) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002a: Expected O, but got Unknown //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_003c: 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_0050: Unknown result type (might be due to invalid IL or missing references) _onValueChanged = onValueChanged; CurrentColor = clr; _controlHeight = controlHeight; _revertColor = CurrentColor; } internal override void Draw(Rect r) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: 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_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) _rect = r; bool flag = !string.IsNullOrEmpty(DisplayedString); Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.666f, ((Rect)(ref r)).height); Rect bounds = default(Rect); ((Rect)(ref bounds))..ctor(((Rect)(ref val)).x + ((Rect)(ref val)).width, ((Rect)(ref r)).y, ((Rect)(ref r)).width - ((Rect)(ref val)).width, ((Rect)(ref r)).height); if (!flag) { ((Rect)(ref bounds))..ctor(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 2f, ((Rect)(ref r)).height); } if (UWindowManager.AllWindowsDisabled && IsPickerOpen) { GUI.enabled = true; } if (flag) { GUI.Label(val, DisplayedString); } Color color = GUI.color; GUI.color = CurrentColor; if (UGUI.Button(bounds, string.Empty, _whiteButtonGUIStyle)) { IsPickerOpen = !IsPickerOpen; } if (UWindowManager.AllWindowsDisabled && IsPickerOpen) { GUI.enabled = false; } GUI.color = color; } internal void DrawPicker() { //IL_0008: 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) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: 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_0094: 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) float num = 200f; Color color = CurrentColor; if (UControls.ColorPicker(new Vector2(((Rect)(ref _rect)).x + ((Rect)(ref _rect)).width - num, ((Rect)(ref _rect)).y + ((Rect)(ref _rect)).height), ref color, mainBoxColoredTexture: true, num, _controlHeight)) { color = _revertColor; IsPickerOpen = false; } if (color != CurrentColor) { _onValueChanged(color); } CurrentColor = color; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "color", CurrentColor); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) base.ImportData(id, sectionName, keyBaseName, ini); CurrentColor = ini.ReadValue(sectionName, keyBaseName + "color", CurrentColor); } } public class WDropDown : WControl { public readonly Action<int> OnValueChanged; public readonly Dictionary<int, string> ValuesList; public int Value; private bool _isDropDownOpen = false; private Vector2 _scrollPos; private Rect _selectedRect; private static GUIStyle _dropDownOptionGUIStyle; private bool IsDropDownOpen { get { return _isDropDownOpen; } set { _isDropDownOpen = value; UWindowManager.AllWindowsDisabled = value; if (value) { UWindowManager.ActiveOptionMenu = DrawDropDown; } else { UWindowManager.ActiveOptionMenu = null; } } } internal WDropDown(Action<int> onValueChanged, int value, Dictionary<int, string> valuesList, string displayedString) : base(displayedString) { OnValueChanged = onValueChanged; Value = value; ValuesList = valuesList; } internal override void Draw(Rect r) { //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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Expected O, but got Unknown //IL_002c: 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_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_0112: Unknown result type (might be due to invalid IL or missing references) if (_dropDownOptionGUIStyle == null) { _dropDownOptionGUIStyle = new GUIStyle(GUI.skin.label); _dropDownOptionGUIStyle.hover.textColor = Color.gray; _dropDownOptionGUIStyle.onHover.textColor = Color.gray; } float num = 5f; string text = ValuesList[Value]; Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width * 0.5f, ((Rect)(ref r)).height); _selectedRect = new Rect(((Rect)(ref r)).x + ((Rect)(ref val)).width + num, ((Rect)(ref r)).y, ((Rect)(ref r)).width - ((Rect)(ref val)).width - num, ((Rect)(ref r)).height); if (string.IsNullOrEmpty(DisplayedString)) { _selectedRect = r; } if (UWindowManager.AllWindowsDisabled && IsDropDownOpen) { GUI.enabled = true; } if (!string.IsNullOrEmpty(DisplayedString)) { GUI.Label(val, DisplayedString); } if (UGUI.Button(_selectedRect, text)) { IsDropDownOpen = !IsDropDownOpen; } if (UWindowManager.AllWindowsDisabled && IsDropDownOpen) { GUI.enabled = false; } } internal void DrawDropDown() { //IL_0023: 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) bool isOpen; int num = UControls.DropDown(new Vector2(((Rect)(ref _selectedRect)).x, ((Rect)(ref _selectedRect)).y + ((Rect)(ref _selectedRect)).height), ValuesList, _scrollPos, out _scrollPos, out isOpen, _dropDownOptionGUIStyle, mainBoxColoredTexture: true, ((Rect)(ref _selectedRect)).width); if ((num >= 0) & (num != Value)) { OnValueChanged(num); } if (num >= 0) { Value = num; } IsDropDownOpen = isOpen; } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ExportData(id, sectionName, keyBaseName, ini); ini.WriteValue(sectionName, keyBaseName + "value", Value); } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { base.ImportData(id, sectionName, keyBaseName, ini); Value = ini.ReadValue(sectionName, keyBaseName + "value", Value); } } public class WSeparator : WControl { private Color _lineColor; private float _lineThickness; public WSeparator(Color lineColor, float lineThickness) : base(string.Empty) { //IL_000e: 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) _lineColor = lineColor; _lineThickness = lineThickness; } internal override void Draw(Rect r) { //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_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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) Color color = _lineColor; if (!GUI.enabled) { color = _lineColor * new Color(1f, 1f, 1f, 0.5f); } Rect r2 = default(Rect); ((Rect)(ref r2))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).y + ((Rect)(ref r)).height / 2f - _lineThickness / 2f, ((Rect)(ref r)).width, _lineThickness); UControls.ColoredBox(r2, color); } } public class WSpace : WControl { internal WSpace() : base(string.Empty) { } internal override void Draw(Rect r) { } internal override void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { } internal override void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { } } } public abstract class WControl { internal float SameLineRatio = 1f; internal string DisplayedString = null; internal WControl(string displayedString) { DisplayedString = displayedString; } internal abstract void Draw(Rect r); internal virtual void ExportData(int id, string sectionName, string keyBaseName, INIParser ini) { ini.WriteValue(sectionName, keyBaseName + "displayString", DisplayedString); } internal virtual void ImportData(int id, string sectionName, string keyBaseName, INIParser ini) { DisplayedString = ini.ReadValue(sectionName, keyBaseName + "displayString", DisplayedString); } } internal static class UWindowManager { public static GameObject BManagerG = null; public static UWindowManagerBehaviour BManager = null; public static bool AllWindowsDisabled = false; public static bool AnyWindowDragging = false; public static Action ActiveOptionMenu = null; public static readonly Vector2 DynamicWindowsMargin = Vector2.one * 10f; private static Vector2 _dynamicWindowsNext = Vector2.one * 10f; public static List<UWindow> Windows { get; private set; } public static bool IsDrawing { get; set; } = true; public static GUISkin DefaultSkin { get; internal set; } = null; internal static void Register(UWindow win) { if (Windows == null) { Windows = new List<UWindow>(); } if ((Object)(object)BManager == (Object)null || (Object)(object)BManagerG == (Object)null) { InitializeManager(); } string winGuid = Guid.NewGuid().ToString(); win.WinGuid = winGuid; Windows.Add(win); } internal static bool LoadGlobalSkin_internal(GUISkin skin) { if ((Object)(object)skin == (Object)null) { return false; } foreach (UWindow window in Windows) { window.LoadSkin(skin); } return true; } public static Vector2 GetDynamicWindowPos(float currentWidth) { //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_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: 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) Vector2 dynamicWindowsNext = _dynamicWindowsNext; _dynamicWindowsNext.x += currentWidth + DynamicWindowsMargin.x; return dynamicWindowsNext; } internal static void BringUWindowToFront(UWindow win) { Windows.Remove(win); Windows.Add(win); } private static int GetIndexByGuid(string guid) { return Windows.FindIndex((UWindow win) => win.WinGuid == guid); } private static UWindow GetUWinByGuid(string guid) { return Windows.FirstOrDefault((UWindow w) => w.WinGuid == guid); } internal static void OnBehaviourGUI() { if (!IsDrawing) { return; } foreach (UWindow item in Windows.ToList()) { item.Draw(); } if (ActiveOptionMenu != null) { ActiveOptionMenu(); } } private static void InitializeManager() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown BManagerG = new GameObject("UrGUI Manager"); BManager = BManagerG.AddComponent<UWindowManagerBehaviour>(); UWindowManagerBehaviour.Instance.LoadDefaultSkin(); } } internal class UWindowManagerBehaviour : MonoBehaviour { public static UWindowManagerBehaviour Instance { get; private set; } private void Awake() { if ((Object)(object)Instance != (Object)null) { Object.Destroy((Object)(object)((Component)this).gameObject); } Instance = this; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); } private void Start() { } private void OnEnable() { } private void OnGUI() { UWindowManager.OnBehaviourGUI(); } public void LoadDefaultSkin() { ((MonoBehaviour)this).StartCoroutine(m_LoadDefaultSkin()); } private IEnumerator m_LoadDefaultSkin() { Assembly a = Assembly.GetExecutingAssembly(); byte[] ba = null; int nOfB = 0; using (Stream resFilestream = a.GetManifestResourceStream("UrGUI.Skins.main")) { if (resFilestream == null) { Debug.LogWarning((object)"Couldn't load default skin! Filestream is null"); yield break; } ba = new byte[resFilestream.Length]; nOfB = resFilestream.Read(ba, 0, ba.Length); } if (ba.Length != nOfB) { Debug.LogError((object)"Stream didn't ready all of available bytes!"); } AssetBundleCreateRequest assetBundleReq = AssetBundle.LoadFromMemoryAsync(ba); while (!((AsyncOperation)assetBundleReq).isDone) { Logger.log($"Loading skin asset-bundle from memory... {((AsyncOperation)assetBundleReq).progress * 100f:0.##}%"); yield return null; } Logger.log("AssetBundle loaded!"); AssetBundleRequest skinReq = assetBundleReq.assetBundle.LoadAssetAsync<GUISkin>("main"); while (!((AsyncOperation)skinReq).isDone) { Logger.log($"Loading skin from asset-bundle... {((AsyncOperation)skinReq).progress * 100f:0.##}%"); yield return null; } Logger.log("Skin loaded!"); UWindowManager.DefaultSkin = (GUISkin)skinReq.asset; UWindowManager.LoadGlobalSkin_internal(UWindowManager.DefaultSkin); yield return null; } } } namespace UrGUI.UWindow.Utils { public static class UControls { public static float LabelSlider(Rect rect, string label, float value, float min, float max, bool numberIndicator = false, string numberIndicatorFormat = "0.##", bool labelOnLeft = true, float offsetX = 5f) { //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_0039: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: 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) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) Vector2 contentStringSize = GUIFormatting.GetContentStringSize(label); Rect val = default(Rect); if (labelOnLeft) { ((Rect)(ref val))..ctor(0f, 0f, contentStringSize.x, ((Rect)(ref rect)).height); } else { ((Rect)(ref val))..ctor(((Rect)(ref rect)).width - contentStringSize.x + offsetX, 0f, contentStringSize.x, ((Rect)(ref rect)).height); } Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(labelOnLeft ? (((Rect)(ref val)).width + offsetX) : 0f, 0f, ((Rect)(ref rect)).width - ((Rect)(ref val)).width - offsetX, ((Rect)(ref rect)).height); Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(((Rect)(ref val2)).x + ((Rect)(ref val2)).width / 2f - 30f, 0f, ((Rect)(ref val2)).width / 2f, ((Rect)(ref rect)).height); GUI.BeginGroup(rect); GUI.Label(val, label); float result = GUI.HorizontalSlider(val2, value, min, max); if (numberIndicator) { GUI.Label(val3, value.ToString(numberIndicatorFormat)); } GUI.EndGroup(); return result; } public static string LabelTextField(Rect rect, string label, string value, int maxSymbolLength, string regexReplace = "", bool labelOnLeft = true, float offsetX = 5f) { //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_0039: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) Vector2 contentStringSize = GUIFormatting.GetContentStringSize(label); Rect val = default(Rect); if (labelOnLeft) { ((Rect)(ref val))..ctor(0f, 0f, contentStringSize.x, ((Rect)(ref rect)).height); } else { ((Rect)(ref val))..ctor(((Rect)(ref rect)).width - contentStringSize.x + offsetX, 0f, contentStringSize.x, ((Rect)(ref rect)).height); } Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(labelOnLeft ? (((Rect)(ref val)).width + offsetX) : 0f, 0f, ((Rect)(ref rect)).width - ((Rect)(ref val)).width - offsetX, ((Rect)(ref rect)).height); GUI.BeginGroup(rect); GUI.Label(val, label); string text = GUI.TextField(val2, value, maxSymbolLength); GUI.EndGroup(); if (!string.IsNullOrEmpty(regexReplace)) { text = Regex.Replace(text, regexReplace, string.Empty); } return text; } public static Vector3 LabelVector3Field(Rect rect, string label, Vector3 value, Vector3 min, Vector3 max) { throw new NotImplementedException(); } public static bool ColorPicker(Vector2 leftTopCorner, ref Color color, bool mainBoxColoredTexture = false, float sliderWidth = 200f, float controlHeight = 12f, float offsetY = 5f, float margin = 5f) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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_004c: 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_008c: Unknown result type (might be due to invalid IL or missing references) //IL_007e: 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_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: 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_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) float x = GUIFormatting.GetContentStringSize("X: ").x; Rect val = default(Rect); ((Rect)(ref val))..ctor(leftTopCorner.x, leftTopCorner.y, x + sliderWidth + margin * 2f, controlHeight * 4f + offsetY * 3f + margin * 2f); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(leftTopCorner.x + margin, leftTopCorner.y + margin, x + sliderWidth, controlHeight * 4f + offsetY * 3f); if (mainBoxColoredTexture) { ColoredBox(val, Color.black); } else { GUI.Box(val, ""); } Rect bounds = default(Rect); ((Rect)(ref bounds))..ctor(((Rect)(ref val)).x, ((Rect)(ref val)).y - controlHeight, ((Rect)(ref val)).width / 3f, controlHeight); if (UGUI.Button(bounds, "Cancel")) { return true; } GUI.BeginGroup(val2); Color val3 = color; val3.r = LabelSlider(new Rect(0f, controlHeight * 0f + offsetY * 0f, ((Rect)(ref val2)).width, controlHeight), "R: ", color.r, 0f, 1f); val3.g = LabelSlider(new Rect(0f, controlHeight * 1f + offsetY * 1f, ((Rect)(ref val2)).width, controlHeight), "G: ", color.g, 0f, 1f); val3.b = LabelSlider(new Rect(0f, controlHeight * 2f + offsetY * 2f, ((Rect)(ref val2)).width, controlHeight), "B: ", color.b, 0f, 1f); val3.a = LabelSlider(new Rect(0f, controlHeight * 3f + offsetY * 3f, ((Rect)(ref val2)).width, controlHeight), "A: ", color.a, 0f, 1f); GUI.EndGroup(); color = val3; return false; } public static int DropDown(Vector2 leftTopCorner, Dictionary<int, string> list, Vector2 scrollPos, out Vector2 scrollPosNew, out bool isOpen, GUIStyle optionGUIStyle, bool mainBoxColoredTexture = false, float width = 0f, int optionCountShown = 4, float optionHeight = 22f) { //IL_000b: 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_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_008e: 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_00b8: Unknown result type (might be due to invalid IL or missing references) int num = 4; int result = -1; isOpen = true; Rect val = default(Rect); ((Rect)(ref val))..ctor(leftTopCorner.x, leftTopCorner.y, width + 15f, optionHeight * (float)optionCountShown); if (mainBoxColoredTexture) { ColoredBox(val, Color.black); } else { GUI.Box(val, string.Empty); } GUI.BeginGroup(val); scrollPosNew = GUI.BeginScrollView(new Rect(0f, 0f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), scrollPos, new Rect(0f, 0f, 0f, (float)list.Count * optionHeight)); for (int i = 0; i < list.Count; i++) { if (UGUI.Button(new Rect((float)num, (float)i * optionHeight, ((Rect)(ref val)).width - (float)num - 15f, optionHeight), list[i], optionGUIStyle)) { result = i; isOpen = false; } } GUI.EndScrollView(); GUI.EndGroup(); return result; } public static void ColoredBox(Rect r, Color color) { //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_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_001a: Unknown result type (might be due to invalid IL or missing references) Color color2 = GUI.color; GUI.color = color; GUI.DrawTexture(r, (Texture)(object)Texture2D.whiteTexture); GUI.color = color2; } } public static class GUIFormatting { public static GUIStyle StringStyle { get; set; } = new GUIStyle(GUI.skin.label); public static Vector2 GetContentStringSize(string text) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: 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) GUIContent val = new GUIContent(text); return StringStyle.CalcSize(val); } } } namespace UrGUI.Utils { internal static class UGUI { private static int highestDepthID = 0; private static Vector2 touchBeganPosition = Vector2.zero; private static EventType lastEventType = (EventType)8; private static bool wasDragging = false; private static int frame = 0; private static int lastEventFrame = 0; public static bool Button(string text, params GUILayoutOption[] options) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) GUIContent val = new GUIContent(text); return Button(GUILayoutUtility.GetRect(val, GUI.skin.button, options), val, GUI.skin.button); } public static bool Button(string text, GUIStyle style = null, params GUILayoutOption[] options) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_000b: Unknown result type (might be due to invalid IL or missing references) GUIContent val = new GUIContent(text); return Button(GUILayoutUtility.GetRect(val, style, options), val, style); } public static bool Button(Texture image, params GUILayoutOption[] options) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) GUIContent val = new GUIContent(image); return Button(GUILayoutUtility.GetRect(val, GUI.skin.button, options), val, GUI.skin.button); } public static bool Button(Texture image, GUIStyle style = null, params GUILayoutOption[] options) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_000b: Unknown result type (might be due to invalid IL or missing references) GUIContent val = new GUIContent(image); return Button(GUILayoutUtility.GetRect(val, style, options), val, style); } public static bool Button(GUIContent content, params GUILayoutOption[] options) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return Button(GUILayoutUtility.GetRect(content, GUI.skin.button, options), content, GUI.skin.button); } public static bool Button(GUIContent content, GUIStyle style = null, params GUILayoutOption[] options) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) return Button(GUILayoutUtility.GetRect(content, style, options), content, style); } public static bool Button(Rect bounds, string text, GUIStyle style = null) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0008: Unknown result type (might be due to invalid IL or missing references) GUIContent content = new GUIContent(text); return Button(bounds, content, style); } public static bool Button(Rect bounds, Texture image, GUIStyle style = null) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0008: Unknown result type (might be due to invalid IL or missing references) GUIContent content = new GUIContent(image); return Button(bounds, content, style); } private static bool Button(Rect bounds, GUIContent content, GUIStyle style = null) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Invalid comparison between Unknown and I4 //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Invalid comparison between Unknown and I4 //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Invalid comparison between Unknown and I4 //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_0119: 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_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0126: Invalid comparison between Unknown and I4 int controlID = GUIUtility.GetControlID(((object)(Rect)(ref bounds)).GetHashCode(), (FocusType)2); bool flag = ((Rect)(ref bounds)).Contains(Event.current.mousePosition); int num = (1000 - GUI.depth) * 1000 + controlID; if (flag && num > highestDepthID) { highestDepthID = num; } bool flag2 = highestDepthID == num; bool flag3 = flag2; if (style == null) { style = GUI.skin.FindStyle("button"); } if ((int)Event.current.type == 8 && (int)lastEventType != 8) { highestDepthID = 0; frame++; } lastEventType = Event.current.type; if ((int)Event.current.type == 7) { bool flag4 = GUIUtility.hotControl == controlID; style.Draw(bounds, content, flag3, flag4, false, false); } if (frame <= 1 + lastEventFrame) { return false; } EventType typeForControl = Event.current.GetTypeForControl(controlID); EventType val = typeForControl; if ((int)val != 0) { if ((int)val == 1 && flag2 && !wasDragging) { GUIUtility.hotControl = 0; lastEventFrame = frame; return true; } } else if (flag2 && !wasDragging) { GUIUtility.hotControl = controlID; } return false; } } public static class Logger { [Flags] public enum PrintType { None = 0, Error = 1, Warnings = 2, Info = 4 } public static readonly Action<object, PrintType> OnLoggerPrint = delegate { }; private static PrintType _debugFilter = PrintType.Error | PrintType.Warnings | PrintType.Info; public static PrintType DebugFilter { get { return _debugFilter; } set { _debugFilter = value; } } internal static void log(object msg) { if (_debugFilter.HasFlag(PrintType.Info)) { Debug.Log(msg); if (OnLoggerPrint != null) { OnLoggerPrint(msg, PrintType.Info); } } } internal static void war(object msg) { if (_debugFilter.HasFlag(PrintType.Warnings)) { Debug.LogWarning(msg); if (OnLoggerPrint != null) { OnLoggerPrint(msg, PrintType.Warnings); } } } internal static void err(object msg) { if (_debugFilter.HasFlag(PrintType.Error)) { Debug.LogError(msg); if (OnLoggerPrint != null) { OnLoggerPrint(msg, PrintType.Error); } } } } public class INIParser { public int error = 0; private object m_Lock = new object(); private string m_FileName = null; private string m_iniString = null; private bool m_AutoFlush = false; private Dictionary<string, Dictionary<string, string>> m_Sections = new Dictionary<string, Dictionary<string, string>>(); private Dictionary<string, Dictionary<string, string>> m_Modified = new Dictionary<string, Dictionary<string, string>>(); private bool m_CacheModified = false; public string FileName => m_FileName; public string iniString => m_iniString; public void Open(string path) { m_FileName = path; if (File.Exists(m_FileName)) { m_iniString = File.ReadAllText(m_FileName); } else { FileStream fileStream = File.Create(m_FileName); fileStream.Close(); m_iniString = ""; } Initialize(m_iniString, AutoFlush: false); } public void Open(TextAsset name) { if ((Object)(object)name == (Object)null) { error = 1; m_iniString = ""; m_FileName = null; Initialize(m_iniString, AutoFlush: false); return; } m_FileName = Application.persistentDataPath + ((Object)name).name; if (File.Exists(m_FileName)) { m_iniString = File.ReadAllText(m_FileName); } else { m_iniString = name.text; } Initialize(m_iniString, AutoFlush: false); } public void OpenFromString(string str) { m_FileName = null; Initialize(str, AutoFlush: false); } public override string ToString() { return m_iniString; } private void Initialize(string iniString, bool AutoFlush) { m_iniString = iniString; m_AutoFlush = AutoFlush; Refresh(); } public void Close() { lock (m_Lock) { PerformFlush(); m_FileName = null; m_iniString = null; } } private string ParseSectionName(string Line) { if (!Line.StartsWith("[")) { return null; } if (!Line.EndsWith("]")) { return null; } if (Line.Length < 3) { return null; } return Line.Substring(1, Line.Length - 2); } private bool ParseKeyValuePair(string Line, ref string Key, ref string Value) { int num; if ((num = Line.IndexOf('=')) <= 0) { return false; } int num2 = Line.Length - num - 1; Key = Line.Substring(0, num).Trim(); if (Key.Length <= 0) { return false; } Value = ((num2 > 0) ? Line.Substring(num + 1, num2).Trim() : ""); return true; } private bool isComment(string Line) { string Key = null; string Value = null; if (ParseSectionName(Line) != null) { return false; } if (ParseKeyValuePair(Line, ref Key, ref Value)) { return false; } return true; } private void Refresh() { lock (m_Lock) { StringReader stringReader = null; try { m_Sections.Clear(); m_Modified.Clear(); stringReader = new StringReader(m_iniString); Dictionary<string, string> dictionary = null; string Key = null; string Value = null; string text; while ((text = stringReader.ReadLine()) != null) { text = text.Trim(); string text2 = ParseSectionName(text); if (text2 != null) { if (m_Sections.ContainsKey(text2)) { dictionary = null; continue; } dictionary = new Dictionary<string, string>(); m_Sections.Add(text2, dictionary); } else if (dictionary != null && ParseKeyValuePair(text, ref Key, ref Value) && !dictionary.ContainsKey(Key)) { dictionary.Add(Key, Value); } } } finally { stringReader?.Close(); stringReader = null; } } } private void PerformFlush() { if (!m_CacheModified) { return; } m_CacheModified = false; StringWriter stringWriter = new StringWriter(); try { Dictionary<string, string> value = null; Dictionary<string, string> value2 = null; StringReader stringReader = null; try { stringReader = new StringReader(m_iniString); string Key = null; string value3 = null; bool flag = true; bool flag2 = false; string Key2 = null; string Value = null; while (flag) { string text = stringReader.ReadLine(); flag = text != null; bool flag3; string text2; if (flag) { flag3 = true; text = text.Trim(); text2 = ParseSectionName(text); } else { flag3 = false; text2 = null; } if (text2 != null || !flag) { if (value != null && value.Count > 0) { StringBuilder stringBuilder = stringWriter.GetStringBuilder(); while (stringBuilder[stringBuilder.Length - 1] == '\n' || stringBuilder[stringBuilder.Length - 1] == '\r') { stringBuilder.Length--; } stringWriter.WriteLine(); foreach (string key in value.Keys) { if (value.TryGetValue(key, out value3)) { stringWriter.Write(key); stringWriter.Write('='); stringWriter.WriteLine(value3); } } stringWriter.WriteLine(); value.Clear(); } if (flag && !m_Modified.TryGetValue(text2, out value)) { value = null; } } else if (value != null && ParseKeyValuePair(text, ref Key, ref value3) && value.TryGetValue(Key, out value3)) { flag3 = false; value.Remove(Key); stringWriter.Write(Key); stringWriter.Write('='); stringWriter.WriteLine(value3); } if (flag3) { if (text2 != null) { if (!m_Sections.ContainsKey(text2)) { flag2 = true; value2 = null; } else { flag2 = false; m_Sections.TryGetValue(text2, out value2); } } else if (value2 != null && ParseKeyValuePair(text, ref Key2, ref Value)) { flag2 = ((!value2.ContainsKey(Key2)) ? true : false); } } if (flag3) { if (isComment(text)) { stringWriter.WriteLine(text); } else if (!flag2) { stringWriter.WriteLine(text); } } } stringReader.Close(); stringReader = null; } finally { stringReader?.Close(); stringReader = null; } foreach (KeyValuePair<string, Dictionary<string, string>> item in m_Modified) { value = item.Value; if (value.Count <= 0) { continue; } stringWriter.WriteLine(); stringWriter.Write('['); stringWriter.Write(item.Key); stringWriter.WriteLine(']'); foreach (KeyValuePair<string, string> item2 in value) { stringWriter.Write(item2.Key); stringWriter.Write('='); stringWriter.WriteLine(item2.Value); } value.Clear(); } m_Modified.Clear(); m_iniString = stringWriter.ToString(); stringWriter.Close(); stringWriter = null; if (m_FileName != null) { File.WriteAllText(m_FileName, m_iniString); } } finally { stringWriter?.Close(); stringWriter = null; } } public bool IsSectionExists(string SectionName) { return m_Sections.ContainsKey(SectionName); } public bool IsKeyExists(string SectionName, string Key) { if (m_Sections.ContainsKey(SectionName)) { m_Sections.TryGetValue(SectionName, out var value); return value.ContainsKey(Key); } return false; } public void SectionDelete(string SectionName) { if (!IsSectionExists(SectionName)) { return; } lock (m_Lock) { m_CacheModified = true; m_Sections.Remove(SectionName); m_Modified.Remove(SectionName); if (m_AutoFlush) { PerformFlush(); } } } public void KeyDelete(string SectionName, string Key) { if (!IsKeyExists(SectionName, Key)) { return; } lock (m_Lock) { m_CacheModified = true; m_Sections.TryGetValue(SectionName, out var value); value.Remove(Key); if (m_Modified.TryGetValue(SectionName, out value)) { value.Remove(SectionName); } if (m_AutoFlush) { PerformFlush(); } } } public string ReadValue(string SectionName, string Key, string DefaultValue) { lock (m_Lock) { if (!m_Sections.TryGetValue(SectionName, out var value)) { return DefaultValue; } if (!value.TryGetValue(Key, out var value2)) { return DefaultValue; } return value2; } } public void WriteValue(string SectionName, string Key, string Value) { lock (m_Lock) { m_CacheModified = true; if (!m_Sections.TryGetValue(SectionName, out var value)) { value = new Dictionary<string, string>(); m_Sections.Add(SectionName, value); } if (value.ContainsKey(Key)) { value.Remove(Key); } value.Add(Key, Value); if (!m_Modified.TryGetValue(SectionName, out value)) { value = new Dictionary<string, string>(); m_Modified.Add(SectionName, value); } if (value.ContainsKey(Key)) { value.Remove(Key); } value.Add(Key, Value); if (m_AutoFlush) { PerformFlush(); } } } private string EncodeByteArray(byte[] Value) { if (Value == null) { return null; } StringBuilder stringBuilder = new StringBuilder(); foreach (byte b in Value) { string text = Convert.ToString(b, 16); int length = text.Length; if (length > 2) { stringBuilder.Append(text.Substring(length - 2, 2)); continue; } if (length < 2) { stringBuilder.Append("0"); } stringBuilder.Append(text); } return stringBuilder.ToString(); } private byte[] DecodeByteArray(string Value) { if (Value == null) { return null; } int length = Value.Length; if (length < 2) { return new byte[0]; } length /= 2; byte[] array = new byte[length]; for (int i = 0; i < length; i++) { array[i] = Convert.ToByte(Value.Substring(i * 2, 2), 16); } return array; } public bool ReadValue(string SectionName, string Key, bool DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (int.TryParse(s, out var result)) { return result != 0; } return DefaultValue; } public int ReadValue(string SectionName, string Key, int DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (int.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { return result; } return DefaultValue; } public long ReadValue(string SectionName, string Key, long DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (long.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { return result; } return DefaultValue; } public double ReadValue(string SectionName, string Key, double DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { return result; } return DefaultValue; } public float ReadValue(string SectionName, string Key, float DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (float.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out var result)) { return result; } return DefaultValue; } public byte[] ReadValue(string SectionName, string Key, byte[] DefaultValue) { string value = ReadValue(SectionName, Key, EncodeByteArray(DefaultValue)); try { return DecodeByteArray(value); } catch (FormatException) { return DefaultValue; } } public DateTime ReadValue(string SectionName, string Key, DateTime DefaultValue) { string s = ReadValue(SectionName, Key, DefaultValue.ToString(CultureInfo.InvariantCulture)); if (DateTime.TryParse(s, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.NoCurrentDateDefault | DateTimeStyles.AssumeLocal, out var result)) { return result; } return DefaultValue; } public Color ReadValue(string SectionName, string Key, Color DefaultValue) { //IL_0009: 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_002b: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) string text = ReadValue(SectionName, Key, "#" + ColorUtility.ToHtmlStringRGB(DefaultValue)); Color result = default(Color); if (ColorUtility.TryParseHtmlString(text, ref result)) { return result; } return DefaultValue; } public void WriteValue(string SectionName, string Key, bool Value) { WriteValue(SectionName, Key, Value ? "1" : "0"); } public void WriteValue(string SectionName, string Key, int Value) { WriteValue(SectionName, Key, Value.ToString(CultureInfo.InvariantCulture)); } public void WriteValue(string SectionName, string Key, long Value) { WriteValue(SectionName, Key, Value.ToString(CultureInfo.InvariantCulture)); } public void WriteValue(string SectionName, string Key, double Value) { WriteValue(SectionName, Key, Value.ToString(CultureInfo.InvariantCulture)); } public void WriteValue(string SectionName, string Key, float Value) { WriteValue(SectionName, Key, Value.ToString(CultureInfo.InvariantCulture)); } public void WriteValue(string SectionName, string Key, byte[] Value) { WriteValue(SectionName, Key, EncodeByteArray(Value)); } public void WriteValue(string SectionName, string Key, DateTime Value) { WriteValue(SectionName, Key, Value.ToString(CultureInfo.InvariantCulture)); } public void WriteValue(string SectionName, string Key, Color Value) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) WriteValue(SectionName, Key, "#" + ColorUtility.ToHtmlStringRGB(Value)); } } }