Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ColorfulDamage v1.2.0
ColorfulDamage.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("ColorfulDamage")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ColorfulDamage")] [assembly: AssemblyCopyright("Copyright © 2022")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("fbd74ee8-6f2b-49cc-84ec-aece295491e7")] [assembly: AssemblyFileVersion("1.2.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.0.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; } } } namespace ComfyLib { public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry<T>)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } } public static class ObjectExtensions { public static T FirstByNameOrThrow<T>(this T[] unityObjects, string name) where T : Object { foreach (T val in unityObjects) { if (((Object)val).name == name) { return val; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref<T>(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } public static class FontCache { public static readonly string ValheimAveriaSansLibreFont = "Valheim-AveriaSansLibre"; public static readonly Dictionary<string, TMP_FontAsset> FontAssetCache = new Dictionary<string, TMP_FontAsset>(); public static TMP_FontAsset ValheimAveriaSansLibreFontAsset => ((TMP_Text)UnifiedPopup.instance.bodyText).font; public static TMP_FontAsset GetFontAssetByName(string fontAssetName) { if (!FontAssetCache.TryGetValue(fontAssetName, out var value)) { value = ((fontAssetName == ValheimAveriaSansLibreFont) ? ValheimAveriaSansLibreFontAsset : Resources.FindObjectsOfTypeAll<TMP_FontAsset>().FirstByNameOrThrow<TMP_FontAsset>(fontAssetName)); FontAssetCache[fontAssetName] = value; } return value; } } } namespace ColorfulDamage { [BepInPlugin("redseiko.valheim.colorfuldamage", "ColorfulDamage", "1.2.0")] public sealed class ColorfulDamage : BaseUnityPlugin { public const string PluginGuid = "redseiko.valheim.colorfuldamage"; public const string PluginName = "ColorfulDamage"; public const string PluginVersion = "1.2.0"; private void Awake() { PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.colorfuldamage"); } } [HarmonyPatch(typeof(DamageText))] internal static class DamageTextPatch { private static string _localizedMsgTooHard = string.Empty; private static string _localizedMsgBlocked = string.Empty; [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix() { _localizedMsgTooHard = Localization.m_instance.Localize("$msg_toohard"); _localizedMsgBlocked = Localization.m_instance.Localize("$msg_blocked: "); } [HarmonyPrefix] [HarmonyPatch("AddInworldText")] private static bool AddInworldText(ref DamageText __instance, TextType type, Vector3 pos, float distance, string text, bool mySelf) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Expected O, but got Unknown //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0050: 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_005a: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) if (!PluginConfig.IsModEnabled.Value) { return true; } if (text == "0" && __instance.m_worldTexts.Count > 200) { return false; } WorldTextInstance val = new WorldTextInstance(); __instance.m_worldTexts.Add(val); val.m_worldPos = pos + Random.insideUnitSphere * 0.5f; val.m_gui = Object.Instantiate<GameObject>(__instance.m_worldTextBase, ((Component)__instance).transform); val.m_textField = val.m_gui.GetComponent<TMP_Text>(); val.m_textField.text = GetWorldTextText(type, text); ((Graphic)val.m_textField).color = GetWorldTextColor(type, text, mySelf); val.m_textField.font = FontCache.GetFontAssetByName(PluginConfig.DamageTextMessageFont.Value); val.m_textField.fontSize = ((distance > PluginConfig.DamageTextSmallPopupDistance.Value) ? PluginConfig.DamageTextSmallFontSize.Value : PluginConfig.DamageTextLargeFontSize.Value); val.m_timer = 0f; return false; } private static Color GetWorldTextColor(TextType damageTextType, string text, bool isPlayerDamage) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected I4, but got Unknown //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Invalid comparison between Unknown and I4 //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_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_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) //IL_007e: 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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_0098: 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_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_0024: 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) if (isPlayerDamage && (int)damageTextType <= 3) { if (!(text == "0f")) { return PluginConfig.DamageTextPlayerDamageColor.Value; } return PluginConfig.DamageTextPlayerNoDamageColor.Value; } return (Color)((int)damageTextType switch { 0 => PluginConfig.DamageTextNormalColor.Value, 1 => PluginConfig.DamageTextResistantColor.Value, 2 => PluginConfig.DamageTextWeakColor.Value, 3 => PluginConfig.DamageTextImmuneColor.Value, 4 => PluginConfig.DamageTextHealColor.Value, 5 => PluginConfig.DamageTextTooHardColor.Value, 6 => PluginConfig.DamageTextBlockedColor.Value, 7 => PluginConfig.DamageTextBonusColor.Value, _ => Color.white, }); } private static string GetWorldTextText(TextType damageTextType, string text) { //IL_0000: 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_0014: Expected I4, but got Unknown return (damageTextType - 4) switch { 0 => "+" + text, 1 => _localizedMsgTooHard, 2 => _localizedMsgBlocked + text, _ => Localization.m_instance.Localize(text), }; } [HarmonyPrefix] [HarmonyPatch("UpdateWorldTexts")] private static bool UpdateWorldTextsPrefix(ref DamageText __instance, float dt) { //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0104: 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_010c: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) if (!PluginConfig.IsModEnabled.Value) { return true; } Camera mainCamera = Utils.GetMainCamera(); float num = Screen.width; float num2 = Screen.height; float num3 = num / (float)mainCamera.pixelWidth; float num4 = num2 / (float)mainCamera.pixelHeight; for (int num5 = __instance.m_worldTexts.Count - 1; num5 >= 0; num5--) { WorldTextInstance val = __instance.m_worldTexts[num5]; val.m_timer += dt; if (val.m_timer > PluginConfig.DamageTextPopupDuration.Value) { Object.Destroy((Object)(object)val.m_gui); __instance.m_worldTexts[num5] = __instance.m_worldTexts[__instance.m_worldTexts.Count - 1]; __instance.m_worldTexts.RemoveAt(__instance.m_worldTexts.Count - 1); } else { float num6 = val.m_timer / PluginConfig.DamageTextPopupDuration.Value; Vector3 val2 = Vector3.Lerp(val.m_worldPos, val.m_worldPos + PluginConfig.DamageTextPopupLerpPosition.Value, num6); Vector3 val3 = mainCamera.WorldToScreenPoint(val2); val3.x *= num3; val3.y *= num4; if (val3.x < 0f || val3.x > num || val3.y < 0f || val3.y > num2 || val3.z < 0f) { val.m_gui.SetActive(false); } else { Color color = ((Graphic)val.m_textField).color; color.a = 1f - num6 * num6 * num6; ((Graphic)val.m_textField).color = color; val.m_gui.SetActive(true); val.m_gui.transform.position = val3; } } } return false; } [HarmonyTranspiler] [HarmonyPatch("RPC_DamageText")] private static IEnumerable<CodeInstruction> RpcDamageTextTranspiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)AccessTools.Field(typeof(DamageText), "m_maxTextDistance"), (string)null) }).ThrowIfInvalid("Could not patch DamageText.RPC_DamageText()! (max-text-distance") .Advance(2) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(DamageTextPatch), "MaxTextDistanceDelegate", (Type[])null, (Type[])null)) }) .InstructionEnumeration(); } private static float MaxTextDistanceDelegate(float maxTextDistance) { if (!PluginConfig.IsModEnabled.Value) { return maxTextDistance; } return PluginConfig.DamageTextMaxPopupDistance.Value; } } public static class PluginConfig { [HarmonyPatch(typeof(FejdStartup))] private static class FejdStartupPatch { [HarmonyPostfix] [HarmonyPatch("Awake")] private static void AwakePostfix() { while (_lateBindConfigQueue.Count > 0) { _lateBindConfigQueue.Dequeue()?.Invoke(CurrentConfig); } } } private static readonly Queue<Action<ConfigFile>> _lateBindConfigQueue = new Queue<Action<ConfigFile>>(); public static ConfigFile CurrentConfig { get; private set; } public static ConfigEntry<bool> IsModEnabled { get; private set; } public static ConfigEntry<float> DamageTextPopupDuration { get; private set; } public static ConfigEntry<Vector3> DamageTextPopupLerpPosition { get; private set; } public static ConfigEntry<float> DamageTextMaxPopupDistance { get; private set; } public static ConfigEntry<float> DamageTextSmallPopupDistance { get; private set; } public static ConfigEntry<Color> DamageTextPlayerDamageColor { get; private set; } public static ConfigEntry<Color> DamageTextPlayerNoDamageColor { get; private set; } public static ConfigEntry<Color> DamageTextNormalColor { get; private set; } public static ConfigEntry<Color> DamageTextResistantColor { get; private set; } public static ConfigEntry<Color> DamageTextWeakColor { get; private set; } public static ConfigEntry<Color> DamageTextImmuneColor { get; private set; } public static ConfigEntry<Color> DamageTextHealColor { get; private set; } public static ConfigEntry<Color> DamageTextTooHardColor { get; private set; } public static ConfigEntry<Color> DamageTextBlockedColor { get; private set; } public static ConfigEntry<Color> DamageTextBonusColor { get; private set; } public static ConfigEntry<string> DamageTextMessageFont { get; private set; } public static ConfigEntry<int> DamageTextSmallFontSize { get; private set; } public static ConfigEntry<int> DamageTextLargeFontSize { get; private set; } public static void BindConfig(ConfigFile config) { CurrentConfig = config; IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); BindDamageTextPopupConfig(config); BindDamageTextColorConfig(config); _lateBindConfigQueue.Enqueue(BindDamageTextFontConfig); } private static void BindDamageTextPopupConfig(ConfigFile config) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) DamageTextPopupDuration = config.BindInOrder("DamageText.Popup", "popupDuration", 1.5f, "Duration (in seconds) to show DamageText messages.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f)); DamageTextPopupLerpPosition = config.BindInOrder<Vector3>("DamageText.Popup", "popupLerpPosition", new Vector3(0f, 1.5f, 0f), "Position (Vector3) offset to lerp the DamageText message to."); DamageTextMaxPopupDistance = config.BindInOrder("DamageText.Popup", "maxPopupDistance", 30f, "Maximum distance to popup ANY (small/ or large) DamageText messages.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f)); DamageTextSmallPopupDistance = config.BindInOrder("DamageText.Popup", "smallPopupDistance", 10f, "Distance to popup DamageText messages using small (far-away) font size.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f)); } private static void BindDamageTextColorConfig(ConfigFile config) { //IL_000b: 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_0055: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) DamageTextPlayerDamageColor = config.BindInOrder<Color>("DamageText.Color", "playerDamageColor", Color.red, "DamageText.color for damage to player > 0."); DamageTextPlayerNoDamageColor = config.BindInOrder<Color>("DamageText.Color", "playerNoDamageColor", Color.gray, "DamageText.color for damage to player = 0."); DamageTextNormalColor = config.BindInOrder<Color>("DamageText.Color", "normalColor", Color.white, "DamageText.color for TextType.Normal damage."); DamageTextResistantColor = config.BindInOrder<Color>("DamageText.Color", "resistantColor", new Color(0.6f, 0.6f, 0.6f, 1f), "DamageText.color for TextType.Resistant damage."); DamageTextWeakColor = config.BindInOrder<Color>("DamageText.Color", "weakColor", new Color(1f, 1f, 0f, 1f), "DamageText.color for TextType.Weak damage."); DamageTextImmuneColor = config.BindInOrder<Color>("DamageText.Color", "immuneColor", new Color(0.6f, 0.6f, 0.6f, 1f), "DamageText.color for TextType.Immune damage."); DamageTextHealColor = config.BindInOrder<Color>("DamageText.Color", "healColor", new Color(0.5f, 1f, 0.5f, 0.7f), "DamageText.color for TextType.Heal damage."); DamageTextTooHardColor = config.BindInOrder<Color>("DamageText.Color", "tooHardColor", new Color(0.8f, 0.7f, 0.7f, 1f), "DamageText.color for TextType.TooHard damage."); DamageTextBlockedColor = config.BindInOrder<Color>("DamageText.Color", "blockedColor", Color.white, "DamageText.color for TextType.Blocked damage."); DamageTextBonusColor = config.BindInOrder<Color>("DamageText.Color", "bonusColor", new Color(1f, 0.63f, 0.24f, 1f), "DamageText.color for TextType.Bonus damage."); } private static void BindDamageTextFontConfig(ConfigFile config) { DamageTextMessageFont = config.BindInOrder("DamageText.Font", "messageFont", FontCache.ValheimAveriaSansLibreFont, "DamageText.font for all damage messages.", (AcceptableValueBase)(object)new AcceptableValueList<string>(GetSortedFontNames().ToArray())); if (DamageTextSmallFontSize == null) { DamageTextSmallFontSize = config.BindInOrder("DamageText.Font", "smallFontSize", 14, "DamageText.fontSize for small (far-away) damage messages.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 32)); } DamageTextLargeFontSize = config.BindInOrder("DamageText.Font", "largeFontSize", 18, "DamageText.fontSize for large (nearby) damage messages.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 32)); } private static List<string> GetSortedFontNames() { List<string> list = new List<string>(); TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>(); foreach (TMP_FontAsset val in array) { list.Add(((Object)val).name); } list.Sort(StringComparer.Ordinal); return list; } } }