diff --git a/Il2CppDumper/Il2CppCSharpDumper.cs b/Il2CppDumper/Il2CppCSharpDumper.cs index 46644fb..c49e9d3 100644 --- a/Il2CppDumper/Il2CppCSharpDumper.cs +++ b/Il2CppDumper/Il2CppCSharpDumper.cs @@ -257,7 +257,7 @@ namespace Il2CppInspector var setAccess = (prop.SetMethod?.Attributes ?? 0) & MethodAttributes.MemberAccessMask; var primary = getAccess >= setAccess ? prop.GetMethod : prop.SetMethod; - sb.Append($"{prefix}\t{primary.GetModifierString(scope)}{prop.PropertyType.GetScopedCSharpName(scope)} "); + sb.Append($"{prefix}\t{primary.GetModifierString()}{prop.PropertyType.GetScopedCSharpName(scope)} "); // Non-indexer if ((!prop.CanRead || !prop.GetMethod.DeclaredParameters.Any()) && (!prop.CanWrite || prop.SetMethod.DeclaredParameters.Count == 1)) @@ -293,7 +293,7 @@ namespace Il2CppInspector sb.Append(evt.CustomAttributes.OrderBy(a => a.AttributeType.Name) .ToString(scope, prefix + "\t", emitPointer: !SuppressMetadata, mustCompile: MustCompile)); - string modifiers = evt.AddMethod?.GetModifierString(scope); + string modifiers = evt.AddMethod?.GetModifierString(); sb.Append($"{prefix}\t{modifiers}event {evt.EventHandlerType.GetScopedCSharpName(scope)} {evt.Name}"); if (!MustCompile) { @@ -323,7 +323,7 @@ namespace Il2CppInspector sb.Append(method.CustomAttributes.OrderBy(a => a.AttributeType.Name) .ToString(scope, prefix + "\t", emitPointer: !SuppressMetadata, mustCompile: MustCompile)); - sb.Append($"{prefix}\t{method.GetModifierString(scope)}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}("); + sb.Append($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}("); sb.Append(method.GetParametersString(scope, !SuppressMetadata) + ")" + (method.IsAbstract? ";" : @" {}")); sb.Append((!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n"); } @@ -417,7 +417,7 @@ namespace Il2CppInspector // IL2CPP doesn't seem to retain return type attributes //writer.Append(method.ReturnType.CustomAttributes.ToString(prefix + "\t", "return: ", emitPointer: !SuppressMetadata)); - writer.Append($"{prefix}\t{method.GetModifierString(scope)}"); + writer.Append($"{prefix}\t{method.GetModifierString()}"); // Finalizers become destructors if (method.Name == "Finalize" && method.IsVirtual && method.ReturnType.FullName == "System.Void" && method.IsFamily) diff --git a/Il2CppInspector/FileFormatReaders/UBReader.cs b/Il2CppInspector/FileFormatReaders/UBReader.cs index c2db743..58fe4b6 100644 --- a/Il2CppInspector/FileFormatReaders/UBReader.cs +++ b/Il2CppInspector/FileFormatReaders/UBReader.cs @@ -37,7 +37,8 @@ namespace Il2CppInspector Position = arch.Offset; Endianness = Endianness.Little; - var s = new MemoryStream(ReadBytes((int) arch.Size)); + + using var s = new MemoryStream(ReadBytes((int) arch.Size)); return (IFileFormatReader) MachOReader32.Load(s) ?? MachOReader64.Load(s); } } diff --git a/Il2CppInspector/Reflection/MethodBase.cs b/Il2CppInspector/Reflection/MethodBase.cs index 977919f..3a872ba 100644 --- a/Il2CppInspector/Reflection/MethodBase.cs +++ b/Il2CppInspector/Reflection/MethodBase.cs @@ -150,7 +150,7 @@ namespace Il2CppInspector.Reflection _ => "" }; - public string GetModifierString(Scope usingScope) { + public string GetModifierString() { // Interface methods and properties have no visible modifiers (they are always declared 'public abstract') if (DeclaringType.IsInterface) return string.Empty; @@ -176,7 +176,7 @@ namespace Il2CppInspector.Reflection if ((DeclaringType.BaseType?.GetAllMethods().Any(m => m.GetSignatureString() == GetSignatureString() && m.IsHideBySig) ?? false) && (((Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.ReuseSlot && !IsVirtual) || (Attributes & MethodAttributes.VtableLayoutMask) == MethodAttributes.NewSlot)) - modifiers.Append($"new "); + modifiers.Append("new "); if (Name == "op_Implicit") modifiers.Append("implicit "); diff --git a/Il2CppInspector/Reflection/TypeInfo.cs b/Il2CppInspector/Reflection/TypeInfo.cs index e9b5817..cfe1ede 100644 --- a/Il2CppInspector/Reflection/TypeInfo.cs +++ b/Il2CppInspector/Reflection/TypeInfo.cs @@ -90,7 +90,7 @@ namespace Il2CppInspector.Reflection { public List DeclaredMethods { get; } = new List(); - private int[] declaredNestedTypes; + private readonly int[] declaredNestedTypes; public IEnumerable DeclaredNestedTypes => declaredNestedTypes.Select(x => Assembly.Model.TypesByDefinitionIndex[x]); public List DeclaredProperties { get; } = new List(); @@ -191,8 +191,8 @@ namespace Il2CppInspector.Reflection { && usingScope.Substring(0, usingScope.IndexOf('.', diff)) == declaringScope.Substring(0, declaringScope.IndexOf('.', diff))) diff = usingScope.IndexOf('.', diff) + 1; - usingScope = usingScope.Substring(0, usingScope.Length - 1); - declaringScope = declaringScope.Substring(0, declaringScope.Length - 1); + usingScope = usingScope.Remove(usingScope.Length - 1); + declaringScope = declaringScope.Remove(declaringScope.Length - 1); // This is the mutual root namespace and optionally nested types that the two scopes share var mutualRootScope = usingScope.Substring(0, diff - 1); @@ -656,9 +656,8 @@ namespace Il2CppInspector.Reflection { } // Initialize a type that is a generic parameter of a generic method - public TypeInfo(MethodBase declaringMethod, Il2CppGenericParameter param) : this(declaringMethod.DeclaringType, param) { - DeclaringMethod = declaringMethod; - } + public TypeInfo(MethodBase declaringMethod, Il2CppGenericParameter param) : this(declaringMethod.DeclaringType, param) + => DeclaringMethod = declaringMethod; // Get all the other types directly referenced by this type (single level depth; no recursion) public List GetAllTypeReferences() {