Format Style Fixes

This commit is contained in:
sp-tarkov-bot
2025-08-21 11:40:02 +00:00
parent 18b34acd45
commit bd41cf4061
@@ -17,7 +17,9 @@ public class JsonExtensionDataPatch : IPatcher
public void Patch(AssemblyDefinition assembly) public void Patch(AssemblyDefinition assembly)
{ {
_dictionaryStringObjectReference ??= assembly.MainModule.ImportReference(typeof(Dictionary<string, object>)); _dictionaryStringObjectReference ??= assembly.MainModule.ImportReference(typeof(Dictionary<string, object>));
_dictionaryStringObjectCtorReference ??= assembly.MainModule.ImportReference(typeof(Dictionary<string, object>).GetConstructor(Type.EmptyTypes)); _dictionaryStringObjectCtorReference ??= assembly.MainModule.ImportReference(
typeof(Dictionary<string, object>).GetConstructor(Type.EmptyTypes)
);
if (_jsonExtensionDataAttributeReference is null) if (_jsonExtensionDataAttributeReference is null)
{ {
@@ -38,22 +40,24 @@ public class JsonExtensionDataPatch : IPatcher
_jsonIgnoreAttributeReference = assembly.MainModule.ImportReference(jsonIgnoreConstructorReference); _jsonIgnoreAttributeReference = assembly.MainModule.ImportReference(jsonIgnoreConstructorReference);
} }
var isExternalInitType = assembly.MainModule.ImportReference( var isExternalInitType = assembly.MainModule.ImportReference(typeof(System.Runtime.CompilerServices.IsExternalInit));
typeof(System.Runtime.CompilerServices.IsExternalInit)
);
var compilerGenerated = assembly.MainModule.ImportReference( var compilerGenerated = assembly.MainModule.ImportReference(
assembly.MainModule.ImportReference( assembly.MainModule.ImportReference(
typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute).GetConstructor(Type.EmptyTypes))); typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute).GetConstructor(Type.EmptyTypes)
)
);
var processed = new HashSet<string>(); var processed = new HashSet<string>();
foreach (var typeDefinition in assembly.MainModule.Types) foreach (var typeDefinition in assembly.MainModule.Types)
{ {
if (!typeDefinition.Namespace.Contains("SPTarkov.Server.Core.Models") || if (
typeDefinition.IsInterface || !typeDefinition.Namespace.Contains("SPTarkov.Server.Core.Models")
typeDefinition.IsEnum || || typeDefinition.IsInterface
IsStaticClass(typeDefinition) || || typeDefinition.IsEnum
processed.Contains(typeDefinition.FullName)) || IsStaticClass(typeDefinition)
|| processed.Contains(typeDefinition.FullName)
)
{ {
continue; continue;
} }
@@ -62,9 +66,11 @@ public class JsonExtensionDataPatch : IPatcher
propertyDefinition.CustomAttributes.Add(new CustomAttribute(_jsonExtensionDataAttributeReference)); propertyDefinition.CustomAttributes.Add(new CustomAttribute(_jsonExtensionDataAttributeReference));
// Add backing field // Add backing field
var field = new FieldDefinition("<ExtensionData>k__BackingField", var field = new FieldDefinition(
"<ExtensionData>k__BackingField",
FieldAttributes.Private | FieldAttributes.InitOnly, FieldAttributes.Private | FieldAttributes.InitOnly,
_dictionaryStringObjectReference); _dictionaryStringObjectReference
);
field.CustomAttributes.Add(new CustomAttribute(compilerGenerated)); field.CustomAttributes.Add(new CustomAttribute(compilerGenerated));
typeDefinition.Fields.Add(field); typeDefinition.Fields.Add(field);
@@ -72,7 +78,8 @@ public class JsonExtensionDataPatch : IPatcher
var get = new MethodDefinition( var get = new MethodDefinition(
"get_ExtensionData", "get_ExtensionData",
MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig, MethodAttributes.Public | MethodAttributes.SpecialName | MethodAttributes.HideBySig,
_dictionaryStringObjectReference); _dictionaryStringObjectReference
);
get.CustomAttributes.Add(new CustomAttribute(compilerGenerated)); get.CustomAttributes.Add(new CustomAttribute(compilerGenerated));
get.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0)); get.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
get.Body.Instructions.Add(Instruction.Create(OpCodes.Ldfld, field)); get.Body.Instructions.Add(Instruction.Create(OpCodes.Ldfld, field));
@@ -129,9 +136,7 @@ public class JsonExtensionDataPatch : IPatcher
private bool IsStaticClass(TypeDefinition type) private bool IsStaticClass(TypeDefinition type)
{ {
return type.IsClass && return type.IsClass && type.IsAbstract && type.IsSealed;
type.IsAbstract &&
type.IsSealed;
} }
public string Name public string Name