diff --git a/CLre/CLre.cs b/CLre/CLre.cs index 9b54a49..99645d3 100644 --- a/CLre/CLre.cs +++ b/CLre/CLre.cs @@ -39,6 +39,7 @@ namespace CLre // misc LogIPAPlugins(); + Fixes.BugfixAttributeUtility.LogBugfixes(); // Log info API.Utility.Logging.MetaLog($"{Name} init complete."); diff --git a/CLre/Fixes/BugfixAttribute.cs b/CLre/Fixes/BugfixAttribute.cs new file mode 100644 index 0000000..9d48d5a --- /dev/null +++ b/CLre/Fixes/BugfixAttribute.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace CLre.Fixes +{ + [AttributeUsage(AttributeTargets.Class)] + public class BugfixAttribute : Attribute + { + public string name { get; set; } + public string description { get; set; } + public Type target { get; set; } + public string more { get; set; } + public uint id { get; set; } + public BugfixType component { get; set; } + } + + public enum BugfixType : byte + { + Miscellaneous = 0x00, + HarmonyPatch, + Initialiser, + Workaround, + Debug + } + + internal static class BugfixAttributeUtility + { + public static void LogBugfixes() + { + List keys = new List(); + Dictionary fixes = new Dictionary(); + foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) + { + BugfixAttribute b = t.GetCustomAttribute(true); + if (b != null) + { + if (!fixes.ContainsKey(b.id)) + { + BugfixStruct bugfixStruct = new BugfixStruct{id = b.id}; + bugfixStruct.Merge(b); + fixes[b.id] = bugfixStruct; + keys.Add(b.id); + } + else + { + BugfixStruct bugfixStruct = fixes[b.id]; + bugfixStruct.Merge(b); + fixes[b.id] = bugfixStruct; + } + } + } + keys.Sort(); + //keys.Sort((u, u1) => u.CompareTo(u1)); + StringBuilder sb = new StringBuilder(); + sb.AppendFormat("Applying {0} CLre fixes\n", keys.Count); + sb.AppendFormat("-----------------------------\n"); + foreach (uint i in keys) + { + sb.Append(fixes[i].ToString()); + sb.Append("\n"); + } + sb.AppendFormat("-----------------------------\n"); + API.Utility.Logging.Log(sb.ToString()); + } + + private struct BugfixStruct + { + public string name; + public string description; + public Type target; + public string more; + public uint id; + private uint total; + private uint[] bugfixTypeCount; + + public void Merge(BugfixAttribute b) + { + if (name == null && b.name != null) name = b.name; + if (description == null && b.description != null) description = b.description; + if (target == null && b.target != null) target = b.target; + if (more == null && b.more != null) more = b.more; + total++; + if (bugfixTypeCount == null) bugfixTypeCount = new uint[Enum.GetNames(typeof(BugfixType)).Length]; + bugfixTypeCount[(byte) b.component]++; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + sb.AppendFormat(" {0}: ", name); + if (more != null) + { + sb.AppendFormat("[MORE: {0}] ", more); + } + else if (description != null) + { + sb.Append(description); + sb.Append(" "); + } + + if (target != null) + { + sb.AppendFormat("[TARGET: {0}] ", target.FullName); + } + sb.AppendFormat("[ID: {0}] ", id); + sb.AppendFormat("({0}M/{1}P/{2}I/{3}W/{4}D/{5}T)", bugfixTypeCount[(byte) BugfixType.Miscellaneous], bugfixTypeCount[(byte) BugfixType.HarmonyPatch], bugfixTypeCount[(byte) BugfixType.Initialiser], bugfixTypeCount[(byte) BugfixType.Workaround], bugfixTypeCount[(byte) BugfixType.Debug], total); + return sb.ToString(); + } + } + } +} \ No newline at end of file diff --git a/CLre/Fixes/EnchantmentTableFloatParseFix.cs b/CLre/Fixes/EnchantmentTableFloatParseFix.cs index aaac06a..d40cb5a 100644 --- a/CLre/Fixes/EnchantmentTableFloatParseFix.cs +++ b/CLre/Fixes/EnchantmentTableFloatParseFix.cs @@ -10,6 +10,10 @@ namespace CLre.Fixes } + [Bugfix(name = "EnchantmentTableFloatParseFix", + description = "Make all float parsing culture-invariant", + more = "https://trello.com/c/qawBFb7P/1-enchantment-table-fails-to-work", + component = BugfixType.HarmonyPatch, id = 1)] [HarmonyPatch] class Float_TryParse_Patch { @@ -37,6 +41,9 @@ namespace CLre.Fixes } } + [Bugfix(name = "EnchantmentTableFloatParseFix", + description = "Make all float parsing culture-invariant", + component = BugfixType.HarmonyPatch, id = 1)] [HarmonyPatch(typeof(float), "Parse", new Type[] {typeof(string)})] class Float_Parse_Patch { diff --git a/CLre/Fixes/InitLogSooner.cs b/CLre/Fixes/InitLogSooner.cs index 6db1cb6..b6c3b44 100644 --- a/CLre/Fixes/InitLogSooner.cs +++ b/CLre/Fixes/InitLogSooner.cs @@ -7,6 +7,9 @@ using HarmonyLib; namespace CLre.Fixes { + [Bugfix(name = "InitLogSooner", + description = "Start the logger slightly sooner than Cardlife does", + component = BugfixType.Initialiser, id = 0)] public static class InitLogSooner { public static int millisecondsTimeout = 5000; @@ -33,6 +36,9 @@ namespace CLre.Fixes } + [Bugfix(name = "InitLogSooner", + target = typeof(CustomLoggerThread), + component = BugfixType.HarmonyPatch, id = 0)] [HarmonyPatch(typeof(CustomLoggerThread), "CreateGameObject")] class CustomLoggerThread_CreateGameObject_Patch { @@ -44,6 +50,8 @@ namespace CLre.Fixes } } + [Bugfix(name = "InitLogSooner", + component = BugfixType.HarmonyPatch, id = 0)] [HarmonyPatch(typeof(CustomLoggerThread), "StartQueue")] class CustomLoggerThread_StartQueue_Patch {