Remove static mutable state from LibCpp2IL#541
Remove static mutable state from LibCpp2IL#541nitrog0d wants to merge 4 commits intoSamboyCoding:developmentfrom
Conversation
Migrate all metadata/binary structures from static LibCpp2IlMain fields to per-instance OwningBinary/OwningMetadata on ReadableClass. Move global mapper state into LibCpp2IlContext. Update Cpp2IL.Core to pass Il2CppBinary explicitly. Legacy static API kept as [Obsolete] wrappers.
|
Hi, did you write all of this yourself? |
| var memoryOp = (IsilMemoryOperand)instruction.Operands[1].Data; | ||
| if (memoryOp.Base == null && memoryOp.Index == null && memoryOp.Scale == 0) | ||
| { | ||
| #pragma warning disable CS0618 // Deprecated static API - TODO: migrate to context-based API when available from Cpp2IL.Core |
Cpp2IL.Core/Utils/MiscUtils.cs
Outdated
| internal static void Init() | ||
| internal static void Init(Il2CppBinary binary) | ||
| { | ||
| _primitiveSizes = new(14) |
There was a problem hiding this comment.
this would also need to become instanced, but im not seeing any references to _primitiveSizes so it could just be removed
Cpp2IL.Core/Utils/Arm64Utils.cs
Outdated
| disassembler.EnableInstructionDetails = true; | ||
| disassembler.EnableSkipDataMode = true; | ||
| disassembler.DisassembleSyntax = DisassembleSyntax.Intel; | ||
| _arm64Disassembler = disassembler; |
There was a problem hiding this comment.
this needs to become instanced too
There was a problem hiding this comment.
boilerplate ahh... primary ctors exist
Cpp2IL.Core/Utils/MiscUtils.cs
Outdated
| } | ||
|
|
||
| public static int GetPointerSizeBytes() | ||
| public static int GetPointerSizeBytes(Il2CppBinary binary) |
There was a problem hiding this comment.
would be better as an instanced method on Il2CppBinary
LibCpp2IL/MetadataUsage.cs
Outdated
| #pragma warning disable CS0618 // Fallback to legacy statics for backwards compatibility | ||
| var effectiveBinary = binary ?? LibCpp2IlMain.Binary!; | ||
| var effectiveMetadata = metadata ?? LibCpp2IlMain.TheMetadata!; | ||
| #pragma warning restore CS0618 | ||
|
|
There was a problem hiding this comment.
don't fallback to static state, params shouldnt be nullable
There was a problem hiding this comment.
tests should not use static state. maybe rull them in parallel to ensure that works
| public ulong CachedClass; /* if present, the Il2CppClass corresponding to the instantiation. */ | ||
|
|
||
| private float EffectiveMetadataVersion => OwningMetadata?.MetadataVersion ?? LibCpp2IlMain.MetadataVersion; | ||
| private float EffectiveMetadataVersion => OwningMetadata?.MetadataVersion ?? MetadataVersion; |
| t.OwningMetadata = OwningMetadata ?? LibCpp2IlMain.TheMetadata; | ||
| t.Il2CppTypeHasNumMods5Bits ??= (OwningMetadata?.MetadataVersion ?? LibCpp2IlMain.MetadataVersion) >= 27.2f; | ||
| t.OwningMetadata = OwningMetadata; | ||
| t.Il2CppTypeHasNumMods5Bits ??= (OwningMetadata?.MetadataVersion ?? MetadataVersion) >= 27.2f; |
There was a problem hiding this comment.
redundant fallback (MetadataVersion)
|
|
||
| public abstract class ReadableClass | ||
| { | ||
| internal float MetadataVersion { get; set; } |
Remove unused _primitiveSizes from MiscUtils. Use primary constructor for UnsupportedInstructionSetException. Remove redundant EffectiveMetadataVersion from Il2CppGenericClass. Make MetadataUsage binary/metadata params non-nullable and remove static fallbacks. Move PointerSizeBytes to Il2CppBinary instance property. Expose LibCpp2IlContext on ApplicationAnalysisContext and migrate MetadataProcessor. Move Arm64 disassembler from static Arm64Utils to ApplicationAnalysisContext. Remove unnecessary OwningBinary/OwningMetadata null checks across metadata structures.
Remove LibCpp2IlGlobalMapper (logic already in LibCpp2IlContext). Remove static fallbacks from LibCpp2IlUtils, Il2CppTypeReflectionData, and MetadataUsage. Remove static VTABLE_OFFSET from Il2CppClassUsefulOffsets. Change X86Utils to take is32Bit param instead of full binary. Move Arm64 disassembler to ApplicationAnalysisContext. Expose LibCpp2IlContext on ApplicationAnalysisContext and migrate MetadataProcessor. Keep legacy static field writes in LibCpp2IlContextBuilder since LibCpp2IlReflection still depends on DefaultContext.
|
clankers... |
|
good attempt lets try it again in like a few months |
OwningBinary/OwningMetadata(viaReadableClassbase) instead of staticLibCpp2IlMainfieldsLibCpp2IlContextholds all state that was previously global: Binary, Metadata, MethodsByPtr, and global mapper collectionsIl2CppBinaryautomatically propagatesOwningBinary/OwningMetadatato anyReadableClassit reads viaOnReadableCreatedIl2CppMetadatasetsOwningMetadataon all structures at construction, and exposesSetOwningBinaryOnAllStructurescalled by the builderIl2CppBinaryas an explicit parameter instead of accessing staticsLibCpp2IlMainmarked[Obsolete]for backwards compatibility