From 9ec16382b49fd46b3d3b15b91bdd85275867bc0d Mon Sep 17 00:00:00 2001 From: Cleroth Date: Wed, 7 Oct 2026 12:31:53 +0800 Subject: [PATCH 1/2] fix(config): give headless default values the field's type The Mono.Cecil reflection provider read integer defaults straight from the IL constant, so byte, ushort and uint entries got int defaults. Editors that compare the default with a typed value (MaiChartManager's config save) saw every such entry as changed and wrote it out uncommented, e.g. GameSystem.Sound.BitsPerSample = 32. Defaults are now cast to the field type. --- .../MonoCecilAssemblyReflectionProvider.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs b/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs index efa5957e..a7e9a67c 100644 --- a/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs +++ b/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs @@ -136,6 +136,25 @@ private static object GetFieldDefaultValue(TypeDefinition cType, FieldDefinition { defaultValue = Convert.ToBoolean(loadOperand); } + else if (loadOperand is int or long && fieldType.IsPrimitive) + { + // IL pushes integer constants as int32 (int64 after conv.i8) whatever the field's type. Without the cast, + // a ushort default reads as int, never Equals the typed value, and editors write it out as changed. + // Unchecked: the constant holds the field's bits (uint 3000000000 is pushed as -1294967296). + var bits = Convert.ToInt64(loadOperand); + defaultValue = Type.GetTypeCode(fieldType) switch + { + TypeCode.SByte => (object)unchecked((sbyte)bits), + TypeCode.Byte => unchecked((byte)bits), + TypeCode.Int16 => unchecked((short)bits), + TypeCode.UInt16 => unchecked((ushort)bits), + TypeCode.Int32 => unchecked((int)bits), + TypeCode.UInt32 => unchecked((uint)bits), + TypeCode.Int64 => bits, + TypeCode.UInt64 => unchecked((ulong)bits), + _ => loadOperand, + }; + } else { defaultValue = loadOperand; From cf36638cf6562d6dbd3a1b9f0f8f60479b6005af Mon Sep 17 00:00:00 2001 From: Cleroth <4611301+Cleroth@users.noreply.github.com> Date: Fri, 9 Oct 2026 02:42:13 +0800 Subject: [PATCH 2/2] Apply suggestion from @cubic-dev-ai[bot] Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs b/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs index a7e9a67c..00250791 100644 --- a/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs +++ b/AquaMai.Config/Reflection/MonoCecilAssemblyReflectionProvider.cs @@ -152,6 +152,7 @@ private static object GetFieldDefaultValue(TypeDefinition cType, FieldDefinition TypeCode.UInt32 => unchecked((uint)bits), TypeCode.Int64 => bits, TypeCode.UInt64 => unchecked((ulong)bits), + TypeCode.Char => unchecked((char)bits), _ => loadOperand, }; }