Decompiled source of NewLife v0.3.0
plugins/Revolution-Exclusive-sod-api/SodApi/SodApi.Analyzers.CodeFixes.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeFixes; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.Text; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("Revolution")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("© 2026 Revolution")] [assembly: AssemblyFileVersion("0.8.0.0")] [assembly: AssemblyInformationalVersion("0.8.0+9941f93accb40382a30d004fc2f1cdb4984b4bd3")] [assembly: AssemblyProduct("SOD API")] [assembly: AssemblyTitle("SodApi.Analyzers.CodeFixes")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.8.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SodApi.Analyzers { [ExportCodeFixProvider("C#", new string[] { }, Name = "AddDependencyFix")] [Shared] public sealed class AddDependencyFix : CodeFixProvider { public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create("SOD0001"); public override FixAllProvider GetFixAllProvider() { return WellKnownFixAllProviders.BatchFixer; } public override async Task RegisterCodeFixesAsync(CodeFixContext context) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SyntaxNode val = await ((CodeFixContext)(ref context)).Document.GetSyntaxRootAsync(((CodeFixContext)(ref context)).CancellationToken).ConfigureAwait(continueOnCapturedContext: false); object obj; if (val == null) { obj = null; } else { TextSpan span = ((CodeFixContext)(ref context)).Span; SyntaxToken val2 = val.FindToken(((TextSpan)(ref span)).Start, false); SyntaxNode parent = ((SyntaxToken)(ref val2)).Parent; obj = ((parent != null) ? parent.AncestorsAndSelf(true).OfType<ClassDeclarationSyntax>().FirstOrDefault() : null); } ClassDeclarationSyntax decl = (ClassDeclarationSyntax)obj; if (decl != null) { ((CodeFixContext)(ref context)).RegisterCodeFix(CodeAction.Create("Add [BepInDependency(SodApiInfo.Guid)]", (Func<CancellationToken, Task<Document>>)((CancellationToken ct) => Apply(((CodeFixContext)(ref context)).Document, decl, ct)), "AddDependencyFix"), ((CodeFixContext)(ref context)).Diagnostics); } } private static async Task<Document> Apply(Document doc, ClassDeclarationSyntax decl, CancellationToken ct) { SyntaxNode root = await doc.GetSyntaxRootAsync(ct).ConfigureAwait(continueOnCapturedContext: false); SemanticModel val = await doc.GetSemanticModelAsync(ct).ConfigureAwait(continueOnCapturedContext: false); int num = -1; for (int i = 0; i < ((MemberDeclarationSyntax)decl).AttributeLists.Count; i++) { Enumerator<AttributeSyntax> enumerator = ((MemberDeclarationSyntax)decl).AttributeLists[i].Attributes.GetEnumerator(); while (enumerator.MoveNext()) { AttributeSyntax current = enumerator.Current; SymbolInfo symbolInfo = CSharpExtensions.GetSymbolInfo(val, current, ct); ISymbol symbol = ((SymbolInfo)(ref symbolInfo)).Symbol; ISymbol obj = ((symbol is IMethodSymbol) ? symbol : null); object obj2; if (obj == null) { obj2 = null; } else { INamedTypeSymbol containingType = obj.ContainingType; obj2 = ((containingType != null) ? ((ISymbol)containingType).ToDisplayString((SymbolDisplayFormat)null) : null); } if ((string?)obj2 == "BepInEx.BepInPlugin") { num = i; } } } AttributeSyntax obj3 = SyntaxFactory.Attribute(AnnotationExtensions.WithAdditionalAnnotations<NameSyntax>(SyntaxFactory.ParseName("BepInEx.BepInDependency", 0, true), (SyntaxAnnotation[])(object)new SyntaxAnnotation[1] { Simplifier.Annotation }), SyntaxFactory.AttributeArgumentList(SyntaxFactory.SingletonSeparatedList<AttributeArgumentSyntax>(SyntaxFactory.AttributeArgument(AnnotationExtensions.WithAdditionalAnnotations<ExpressionSyntax>(SyntaxFactory.ParseExpression("SodApi.SodApiInfo.Guid", 0, (ParseOptions)null, true), (SyntaxAnnotation[])(object)new SyntaxAnnotation[1] { Simplifier.Annotation }))))); SyntaxTriviaList val2 = SyntaxFactory.TriviaList(); SyntaxTriviaList val3 = SyntaxFactory.TriviaList(SyntaxFactory.ElasticCarriageReturnLineFeed); AttributeListSyntax val4 = ((num >= 0) ? ((MemberDeclarationSyntax)decl).AttributeLists[num] : ((MemberDeclarationSyntax)decl).AttributeLists.FirstOrDefault()); if (val4 != null) { SyntaxTriviaList leadingTrivia = ((CSharpSyntaxNode)val4).GetLeadingTrivia(); if (((SyntaxTriviaList)(ref leadingTrivia)).Count > 0 && CSharpExtensions.IsKind(((SyntaxTriviaList)(ref leadingTrivia))[((SyntaxTriviaList)(ref leadingTrivia)).Count - 1], (SyntaxKind)8540)) { val2 = SyntaxFactory.TriviaList(((SyntaxTriviaList)(ref leadingTrivia))[((SyntaxTriviaList)(ref leadingTrivia)).Count - 1]); } List<SyntaxTrivia> list = ((IEnumerable<SyntaxTrivia>)(object)((CSharpSyntaxNode)val4).GetTrailingTrivia()).Where((SyntaxTrivia t) => CSharpExtensions.IsKind(t, (SyntaxKind)8539)).ToList(); if (list.Count > 0) { val3 = SyntaxFactory.TriviaList(list[0]); } } AttributeListSyntax val5 = SyntaxNodeExtensions.WithTrailingTrivia<AttributeListSyntax>(SyntaxNodeExtensions.WithLeadingTrivia<AttributeListSyntax>(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList<AttributeSyntax>(obj3)), val2), val3); int num2 = ((num >= 0) ? (num + 1) : ((MemberDeclarationSyntax)decl).AttributeLists.Count); ClassDeclarationSyntax val6 = decl.WithAttributeLists(((MemberDeclarationSyntax)decl).AttributeLists.Insert(num2, val5)); return await Simplifier.ReduceAsync(doc.WithSyntaxRoot(SyntaxNodeExtensions.ReplaceNode<SyntaxNode>(root, (SyntaxNode)(object)decl, (SyntaxNode)(object)val6)), Simplifier.Annotation, (OptionSet)null, ct).ConfigureAwait(continueOnCapturedContext: false); } } [ExportCodeFixProvider("C#", new string[] { }, Name = "ClockSeedFix")] [Shared] public sealed class ClockSeedFix : CodeFixProvider { public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create("SOD0007"); public override FixAllProvider GetFixAllProvider() { return WellKnownFixAllProviders.BatchFixer; } public override async Task RegisterCodeFixesAsync(CodeFixContext context) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SyntaxNode root = await ((CodeFixContext)(ref context)).Document.GetSyntaxRootAsync(((CodeFixContext)(ref context)).CancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (root == null) { return; } ImmutableArray<Diagnostic>.Enumerator enumerator = ((CodeFixContext)(ref context)).Diagnostics.GetEnumerator(); while (enumerator.MoveNext()) { Diagnostic current = enumerator.Current; if (!current.Properties.TryGetValue("kind", out var value) || value != "ctor") { continue; } SyntaxNode val = root.FindNode(current.Location.SourceSpan, false, true); BaseObjectCreationExpressionSyntax creation = val.AncestorsAndSelf(true).OfType<BaseObjectCreationExpressionSyntax>().FirstOrDefault(); BaseObjectCreationExpressionSyntax obj = creation; if (((obj != null) ? obj.ArgumentList : null) != null && ((BaseArgumentListSyntax)creation.ArgumentList).Arguments.Count == 1) { Document doc = ((CodeFixContext)(ref context)).Document; ((CodeFixContext)(ref context)).RegisterCodeFix(CodeAction.Create("Seed from the OS instead of the clock", (Func<CancellationToken, Task<Document>>)((CancellationToken ct) => Task.FromResult<Document>(doc.WithSyntaxRoot(SyntaxNodeExtensions.ReplaceNode<SyntaxNode>(root, (SyntaxNode)(object)creation.ArgumentList, (SyntaxNode)(object)creation.ArgumentList.WithArguments(SyntaxFactory.SeparatedList<ArgumentSyntax>()))))), "SOD0007.entropy"), current); } } } } [ExportCodeFixProvider("C#", new string[] { }, Name = "InteropCastFix")] [Shared] public sealed class InteropCastFix : CodeFixProvider { public override ImmutableArray<string> FixableDiagnosticIds => ImmutableArray.Create("SOD0002"); public override FixAllProvider GetFixAllProvider() { return WellKnownFixAllProviders.BatchFixer; } public override async Task RegisterCodeFixesAsync(CodeFixContext context) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) SyntaxNode val = await ((CodeFixContext)(ref context)).Document.GetSyntaxRootAsync(((CodeFixContext)(ref context)).CancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (val == null) { return; } ImmutableArray<Diagnostic>.Enumerator enumerator = ((CodeFixContext)(ref context)).Diagnostics.GetEnumerator(); while (enumerator.MoveNext()) { Diagnostic current = enumerator.Current; if (!current.Properties.TryGetValue("kind", out var value)) { continue; } SyntaxNode val2 = val.FindNode(current.Location.SourceSpan, false, true); switch (value) { case "as": { BinaryExpressionSyntax val4 = val2.FirstAncestorOrSelf<BinaryExpressionSyntax>((Func<BinaryExpressionSyntax, bool>)((BinaryExpressionSyntax b) => CSharpExtensions.IsKind((SyntaxNode)(object)b, (SyntaxKind)8687)), true); if (val4 != null) { ExpressionSyntax right = val4.Right; TypeSyntax val5 = (TypeSyntax)(object)((right is TypeSyntax) ? right : null); if (val5 != null) { Register(context, current, (ExpressionSyntax)(object)val4, val4.Left, "As", val5, needsSodApi: true); } } break; } case "is": { BinaryExpressionSyntax val6 = val2.FirstAncestorOrSelf<BinaryExpressionSyntax>((Func<BinaryExpressionSyntax, bool>)((BinaryExpressionSyntax b) => CSharpExtensions.IsKind((SyntaxNode)(object)b, (SyntaxKind)8686)), true); if (val6 != null) { ExpressionSyntax right2 = val6.Right; TypeSyntax val7 = (TypeSyntax)(object)((right2 is TypeSyntax) ? right2 : null); if (val7 != null) { Register(context, current, (ExpressionSyntax)(object)val6, val6.Left, "Is", val7, needsSodApi: true); } } break; } case "cast": { CastExpressionSyntax val3 = val2.FirstAncestorOrSelf<CastExpressionSyntax>((Func<CastExpressionSyntax, bool>)null, true); if (val3 != null) { Register(context, current, (ExpressionSyntax)(object)val3, val3.Expression, "As", val3.Type, needsSodApi: true); Register(context, current, (ExpressionSyntax)(object)val3, val3.Expression, "Cast", val3.Type, needsSodApi: false); } break; } case "pattern": { IsPatternExpressionSyntax isPattern = val2.FirstAncestorOrSelf<IsPatternExpressionSyntax>((Func<IsPatternExpressionSyntax, bool>)null, true); TypeSyntax type = PatternType(val2); if (isPattern != null && type != null && Directly(isPattern.Pattern, val2)) { ((CodeFixContext)(ref context)).RegisterCodeFix(CodeAction.Create($"Use .As<{type}>() before the pattern", (Func<CancellationToken, Task<Document>>)((CancellationToken ct) => Replace(((CodeFixContext)(ref context)).Document, (SyntaxNode)(object)isPattern.Expression, (SyntaxNode)(object)SyntaxNodeExtensions.WithTriviaFrom<InvocationExpressionSyntax>(Call(isPattern.Expression, "As", type), (SyntaxNode)(object)isPattern.Expression), needsSodApi: true, ct)), "SOD0002.pattern"), current); } break; } } } } private static void Register(CodeFixContext context, Diagnostic d, ExpressionSyntax whole, ExpressionSyntax value, string method, TypeSyntax type, bool needsSodApi) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) ((CodeFixContext)(ref context)).RegisterCodeFix(CodeAction.Create($"Use .{method}<{type}>()", (Func<CancellationToken, Task<Document>>)((CancellationToken ct) => Replace(((CodeFixContext)(ref context)).Document, (SyntaxNode)(object)whole, (SyntaxNode)(object)SyntaxNodeExtensions.WithTriviaFrom<InvocationExpressionSyntax>(Call(value, method, type), (SyntaxNode)(object)whole), needsSodApi, ct)), "SOD0002." + method), d); } private static InvocationExpressionSyntax Call(ExpressionSyntax value, string method, TypeSyntax type) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) ExpressionSyntax val = SyntaxNodeExtensions.WithoutTrivia<ExpressionSyntax>(value); if (NeedsParentheses(val)) { val = (ExpressionSyntax)(object)SyntaxFactory.ParenthesizedExpression(val); } GenericNameSyntax val2 = SyntaxFactory.GenericName(SyntaxFactory.Identifier(method), SyntaxFactory.TypeArgumentList(SyntaxFactory.SingletonSeparatedList<TypeSyntax>(SyntaxNodeExtensions.WithoutTrivia<TypeSyntax>(type)))); return SyntaxFactory.InvocationExpression((ExpressionSyntax)(object)SyntaxFactory.MemberAccessExpression((SyntaxKind)8689, val, (SimpleNameSyntax)(object)val2)); } private static bool NeedsParentheses(ExpressionSyntax e) { if (!(e is IdentifierNameSyntax) && !(e is GenericNameSyntax) && !(e is MemberAccessExpressionSyntax) && !(e is InvocationExpressionSyntax) && !(e is ElementAccessExpressionSyntax) && !(e is ParenthesizedExpressionSyntax) && !(e is ThisExpressionSyntax)) { return !(e is BaseExpressionSyntax); } return false; } private static TypeSyntax PatternType(SyntaxNode node) { DeclarationPatternSyntax val = (DeclarationPatternSyntax)(object)((node is DeclarationPatternSyntax) ? node : null); if (val == null) { TypePatternSyntax val2 = (TypePatternSyntax)(object)((node is TypePatternSyntax) ? node : null); if (val2 == null) { RecursivePatternSyntax val3 = (RecursivePatternSyntax)(object)((node is RecursivePatternSyntax) ? node : null); if (val3 != null) { return val3.Type; } return null; } return val2.Type; } return val.Type; } private static bool Directly(PatternSyntax top, SyntaxNode node) { while (true) { UnaryPatternSyntax val = (UnaryPatternSyntax)(object)((top is UnaryPatternSyntax) ? top : null); if (val == null) { break; } top = val.Pattern; } while (true) { ParenthesizedPatternSyntax val2 = (ParenthesizedPatternSyntax)(object)((top is ParenthesizedPatternSyntax) ? top : null); if (val2 == null) { break; } top = val2.Pattern; } return (object)top == node; } private static async Task<Document> Replace(Document doc, SyntaxNode old, SyntaxNode replacement, bool needsSodApi, CancellationToken ct) { SyntaxNode val = SyntaxNodeExtensions.ReplaceNode<SyntaxNode>(await doc.GetSyntaxRootAsync(ct).ConfigureAwait(continueOnCapturedContext: false), old, replacement); if (needsSodApi) { CompilationUnitSyntax val2 = (CompilationUnitSyntax)(object)((val is CompilationUnitSyntax) ? val : null); if (val2 != null && !ImportsSodApi(val2, old)) { val = (SyntaxNode)(object)AddUsing(val2); } } return doc.WithSyntaxRoot(val); } private static bool ImportsSodApi(CompilationUnitSyntax cu, SyntaxNode at) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) if (((IEnumerable<UsingDirectiveSyntax>)(object)cu.Usings).Any((UsingDirectiveSyntax u) => ((object)u.Name).ToString() == "SodApi" && u.Alias == null)) { return true; } foreach (BaseNamespaceDeclarationSyntax item in at.Ancestors(true).OfType<BaseNamespaceDeclarationSyntax>()) { string text = ((object)item.Name).ToString(); if (text == "SodApi" || text.StartsWith("SodApi.")) { return true; } if (((IEnumerable<UsingDirectiveSyntax>)(object)item.Usings).Any((UsingDirectiveSyntax u) => ((object)u.Name).ToString() == "SodApi" && u.Alias == null)) { return true; } } return false; } private static CompilationUnitSyntax AddUsing(CompilationUnitSyntax cu) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) SyntaxTrivia val = ((SyntaxNode)cu).DescendantTrivia((Func<SyntaxNode, bool>)null, false).FirstOrDefault((Func<SyntaxTrivia, bool>)((SyntaxTrivia t) => CSharpExtensions.IsKind(t, (SyntaxKind)8539))); SyntaxTrivia val2 = (CSharpExtensions.IsKind(val, (SyntaxKind)8539) ? val : SyntaxFactory.CarriageReturnLineFeed); UsingDirectiveSyntax val3 = SyntaxNodeExtensions.WithTrailingTrivia<UsingDirectiveSyntax>(SyntaxNodeExtensions.NormalizeWhitespace<UsingDirectiveSyntax>(SyntaxFactory.UsingDirective((NameSyntax)(object)SyntaxFactory.IdentifierName("SodApi")), " ", "\r\n", false), (SyntaxTrivia[])(object)new SyntaxTrivia[1] { val2 }); return cu.AddUsings((UsingDirectiveSyntax[])(object)new UsingDirectiveSyntax[1] { val3 }); } } }
plugins/Revolution-Exclusive-sod-api/SodApi/SodApi.Analyzers.dll
Decompiled a day agousing System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Operations; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")] [assembly: AssemblyCompany("Revolution")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("© 2026 Revolution")] [assembly: AssemblyFileVersion("0.8.0.0")] [assembly: AssemblyInformationalVersion("0.8.0+9941f93accb40382a30d004fc2f1cdb4984b4bd3")] [assembly: AssemblyProduct("SOD API")] [assembly: AssemblyTitle("SodApi.Analyzers")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.8.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SodApi.Analyzers { [DiagnosticAnalyzer("C#", new string[] { })] public sealed class ClockSeedAnalyzer : DiagnosticAnalyzer { public const string KindKey = "kind"; public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.ClockSeed); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; INamedTypeSymbol random = compilation.GetTypeByMetadataName("System.Random"); INamedTypeSymbol unityRandom = compilation.GetTypeByMetadataName("UnityEngine.Random"); INamedTypeSymbol typeByMetadataName = compilation.GetTypeByMetadataName("System.DateTime"); INamedTypeSymbol typeByMetadataName2 = compilation.GetTypeByMetadataName("System.DateTimeOffset"); INamedTypeSymbol typeByMetadataName3 = compilation.GetTypeByMetadataName("System.Environment"); INamedTypeSymbol typeByMetadataName4 = compilation.GetTypeByMetadataName("System.Diagnostics.Stopwatch"); INamedTypeSymbol[] clocks = (INamedTypeSymbol[])(object)new INamedTypeSymbol[4] { typeByMetadataName, typeByMetadataName2, typeByMetadataName3, typeByMetadataName4 }; start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown IObjectCreationOperation val = (IObjectCreationOperation)((OperationAnalysisContext)(ref op)).Operation; if (Known.Same((ISymbol)(object)((IOperation)val).Type, (ISymbol)(object)random) && val.Arguments.Length == 1) { string text = Clock(val.Arguments[0].Value, clocks); if (text != null) { ((OperationAnalysisContext)(ref op)).ReportDiagnostic(Diagnostic.Create(Rules.ClockSeed, ((IOperation)val).Syntax.GetLocation(), ImmutableDictionary<string, string>.Empty.Add("kind", "ctor"), new object[2] { "new System.Random", text })); } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)36 }); if (unityRandom != null) { start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; if (Known.Same((ISymbol)(object)((ISymbol)val.TargetMethod).ContainingType, (ISymbol)(object)unityRandom) && !(((ISymbol)val.TargetMethod).Name != "InitState") && val.Arguments.Length == 1) { string text = Clock(val.Arguments[0].Value, clocks); if (text != null) { ((OperationAnalysisContext)(ref op)).ReportDiagnostic(Diagnostic.Create(Rules.ClockSeed, ((IOperation)val).Syntax.GetLocation(), ImmutableDictionary<string, string>.Empty.Add("kind", "initstate"), new object[2] { "UnityEngine.Random.InitState (the game's own generator)", text })); } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); } }); } private static string Clock(IOperation seed, INamedTypeSymbol[] clocks) { if (seed == null) { return null; } ISymbol val = null; IPropertyReferenceOperation val2 = (IPropertyReferenceOperation)(object)((seed is IPropertyReferenceOperation) ? seed : null); if (val2 == null || ((IMemberReferenceOperation)val2).Instance != null) { IInvocationOperation val3 = (IInvocationOperation)(object)((seed is IInvocationOperation) ? seed : null); if (val3 != null && val3.Instance == null) { val = (ISymbol)(object)val3.TargetMethod; } } else { val = (ISymbol)(object)val2.Property; } if (val != null) { foreach (INamedTypeSymbol b in clocks) { if (Known.Same((ISymbol)(object)val.ContainingType, (ISymbol)(object)b) && IsClockMember(val.Name)) { return ((ISymbol)val.ContainingType).Name + "." + val.Name; } } } foreach (IOperation child in seed.Children) { string text = Clock(child, clocks); if (text != null) { return text; } } return null; } private static bool IsClockMember(string name) { switch (name) { default: return name == "GetTimestamp"; case "Now": case "UtcNow": case "Today": case "TickCount": case "TickCount64": return true; } } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class GameObjectPayloadAnalyzer : DiagnosticAnalyzer { private static readonly (string type, string suggestion)[] RefFor = new(string, string)[11] { ("Human", "a CitizenRef"), ("NewRoom", "a RoomRef"), ("NewAddress", "an AddressRef"), ("NewGameLocation", "an AddressRef"), ("NewBuilding", "a BuildingRef"), ("NewFloor", "a FloorRef"), ("StreetController", "a StreetRef"), ("DistrictController", "a DistrictRef"), ("Company", "a CompanyRef"), ("NewDoor", "a DoorRef"), ("Interactable", "an InteractableRef") }; public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.GameObjectPayload); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; INamedTypeSymbol il2cpp = compilation.GetTypeByMetadataName("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"); INamedTypeSymbol save = compilation.GetTypeByMetadataName("SodApi.ModSave"); INamedTypeSymbol net = compilation.GetTypeByMetadataName("SodApi.ModNet"); INamedTypeSymbol jsonIgnore = compilation.GetTypeByMetadataName("System.Text.Json.Serialization.JsonIgnoreAttribute"); if (il2cpp != null && (save != null || net != null)) { start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Unknown result type (might be due to invalid IL or missing references) IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; IMethodSymbol targetMethod = val.TargetMethod; string text; if (Known.Same((ISymbol)(object)((ISymbol)targetMethod).ContainingType, (ISymbol)(object)save) && ((ISymbol)targetMethod).Name == "Slot") { text = "Save slot"; } else { if (!Known.Same((ISymbol)(object)((ISymbol)targetMethod).ContainingType, (ISymbol)(object)net)) { return; } switch (((ISymbol)targetMethod).Name) { default: return; case "Message": text = "Net message"; break; case "Command": text = "Net command"; break; case "Var": case "Set": case "Map": text = "Net " + ((ISymbol)targetMethod).Name.ToLowerInvariant(); break; } } string text2 = null; ImmutableArray<IArgumentOperation>.Enumerator enumerator = val.Arguments.GetEnumerator(); while (enumerator.MoveNext()) { IArgumentOperation current = enumerator.Current; if (current.Parameter != null && (((ISymbol)current.Parameter).Name == "key" || ((ISymbol)current.Parameter).Name == "name") && current.Value.ConstantValue.HasValue) { text2 = current.Value.ConstantValue.Value as string; } } string text3 = ((text2 != null) ? (text + " '" + text2 + "'") : text); ImmutableArray<ITypeSymbol>.Enumerator enumerator2 = targetMethod.TypeArguments.GetEnumerator(); while (enumerator2.MoveNext()) { ITypeSymbol current2 = enumerator2.Current; string path = null; ITypeSymbol val2 = Find(current2, il2cpp, jsonIgnore, new HashSet<ITypeSymbol>((IEqualityComparer<ITypeSymbol>?)SymbolEqualityComparer.Default), 0, ref path); if (val2 != null) { string text4 = ((path == null) ? "" : (" (in " + path + ")")); ((OperationAnalysisContext)(ref op)).ReportDiagnostic(Diagnostic.Create(Rules.GameObjectPayload, ((IOperation)val).Syntax.GetLocation(), new object[4] { text3, ((ISymbol)val2).ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat), text4, Suggest(val2) })); break; } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); } }); } private static ITypeSymbol Find(ITypeSymbol t, INamedTypeSymbol il2cpp, INamedTypeSymbol jsonIgnore, HashSet<ITypeSymbol> seen, int depth, ref string path) { //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Invalid comparison between Unknown and I4 //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Invalid comparison between Unknown and I4 //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Invalid comparison between Unknown and I4 if (t == null || depth > 4 || !seen.Add(t)) { return null; } if (Known.IsInterop(t, il2cpp)) { return t; } IArrayTypeSymbol val = (IArrayTypeSymbol)(object)((t is IArrayTypeSymbol) ? t : null); if (val != null) { return Find(val.ElementType, il2cpp, jsonIgnore, seen, depth + 1, ref path); } INamedTypeSymbol val2 = (INamedTypeSymbol)(object)((t is INamedTypeSymbol) ? t : null); if (val2 == null) { return null; } ImmutableArray<ITypeSymbol>.Enumerator enumerator = val2.TypeArguments.GetEnumerator(); while (enumerator.MoveNext()) { ITypeSymbol val3 = Find(enumerator.Current, il2cpp, jsonIgnore, seen, depth + 1, ref path); if (val3 != null) { return val3; } } if (!((ISymbol)val2).Locations.IsEmpty && ((ISymbol)val2).Locations[0].IsInSource && ((int)((ITypeSymbol)val2).TypeKind == 2 || (int)((ITypeSymbol)val2).TypeKind == 10)) { ImmutableArray<ISymbol>.Enumerator enumerator2 = ((INamespaceOrTypeSymbol)val2).GetMembers().GetEnumerator(); while (enumerator2.MoveNext()) { ISymbol current = enumerator2.Current; if (current.IsStatic || (int)current.DeclaredAccessibility != 6 || IsIgnored(current, jsonIgnore)) { continue; } IPropertySymbol val4 = (IPropertySymbol)(object)((current is IPropertySymbol) ? current : null); object obj; if (val4 == null || val4.GetMethod == null || !val4.Parameters.IsEmpty) { IFieldSymbol val5 = (IFieldSymbol)(object)((current is IFieldSymbol) ? current : null); obj = ((val5 != null && !val5.IsConst) ? val5.Type : null); } else { obj = val4.Type; } ITypeSymbol val6 = (ITypeSymbol)obj; if (val6 == null) { continue; } ITypeSymbol val7 = Find(val6, il2cpp, jsonIgnore, seen, depth + 1, ref path); if (val7 != null) { if (path == null) { path = ((ISymbol)val2).Name + "." + current.Name; } return val7; } } } return null; } private static bool IsIgnored(ISymbol member, INamedTypeSymbol jsonIgnore) { if (jsonIgnore == null) { return false; } ImmutableArray<AttributeData>.Enumerator enumerator = member.GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { if (Known.Same((ISymbol)(object)enumerator.Current.AttributeClass, (ISymbol)(object)jsonIgnore)) { return true; } } return false; } private static string Suggest(ITypeSymbol bad) { for (ITypeSymbol val = bad; val != null; val = (ITypeSymbol)(object)val.BaseType) { (string, string)[] refFor = RefFor; for (int i = 0; i < refFor.Length; i++) { var (text, result) = refFor[i]; if (((ISymbol)val).Name == text && ((ISymbol)val).ContainingNamespace != null && ((ISymbol)val).ContainingNamespace.IsGlobalNamespace) { return result; } } } return "an id or a SOD API ref (CitizenRef, RoomRef, InteractableRef, ...)"; } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class InteropCastAnalyzer : DiagnosticAnalyzer { public const string KindKey = "kind"; public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.InteropCast); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { INamedTypeSymbol il2cpp = start.Compilation.GetTypeByMetadataName("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"); if (il2cpp != null) { start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) IConversionOperation val = (IConversionOperation)((OperationAnalysisContext)(ref op)).Operation; if (!((IOperation)val).IsImplicit) { string text = (val.IsTryCast ? "as" : ((((IOperation)val).Syntax is CastExpressionSyntax) ? "cast" : null)); if (text != null) { Action<Diagnostic> report = ((OperationAnalysisContext)(object)op).ReportDiagnostic; INamedTypeSymbol il2cpp2 = il2cpp; IOperation operand = val.Operand; Check(report, il2cpp2, (operand != null) ? operand.Type : null, ((IOperation)val).Type, ((IOperation)val).Syntax, text); } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)21 }); start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) IIsTypeOperation val = (IIsTypeOperation)((OperationAnalysisContext)(ref op)).Operation; if (!val.IsNegated) { Action<Diagnostic> report = ((OperationAnalysisContext)(object)op).ReportDiagnostic; INamedTypeSymbol il2cpp2 = il2cpp; IOperation valueOperand = val.ValueOperand; Check(report, il2cpp2, (valueOperand != null) ? valueOperand.Type : null, val.TypeOperand, ((IOperation)val).Syntax, "is"); } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)40 }); Action<OperationAnalysisContext> obj = delegate(OperationAnalysisContext op) { //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_0057: Unknown result type (might be due to invalid IL or missing references) ITypeSymbol to = null; IOperation operation = ((OperationAnalysisContext)(ref op)).Operation; IDeclarationPatternOperation val = (IDeclarationPatternOperation)(object)((operation is IDeclarationPatternOperation) ? operation : null); if (val == null) { ITypePatternOperation val2 = (ITypePatternOperation)(object)((operation is ITypePatternOperation) ? operation : null); if (val2 == null) { IRecursivePatternOperation val3 = (IRecursivePatternOperation)(object)((operation is IRecursivePatternOperation) ? operation : null); if (val3 != null) { to = val3.MatchedType; } } else { to = val2.MatchedType; } } else { to = val.MatchedType; } IPatternOperation val4 = (IPatternOperation)((OperationAnalysisContext)(ref op)).Operation; Check((Action<Diagnostic>)((OperationAnalysisContext)(object)op).ReportDiagnostic, il2cpp, val4.InputType, to, ((IOperation)val4).Syntax, "pattern"); }; OperationKind[] array = new OperationKind[3]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); start.RegisterOperationAction(obj, (OperationKind[])(object)array); start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) IOperation operation = ((OperationAnalysisContext)(ref op)).Operation; IForEachLoopOperation val = (IForEachLoopOperation)(object)((operation is IForEachLoopOperation) ? operation : null); if (val != null) { SyntaxNode syntax = ((IOperation)val).Syntax; ForEachStatementSyntax val2 = (ForEachStatementSyntax)(object)((syntax is ForEachStatementSyntax) ? syntax : null); if (val2 != null) { SemanticModel semanticModel = ((IOperation)val).SemanticModel; ForEachStatementInfo val3 = (ForEachStatementInfo)((semanticModel != null) ? CSharpExtensions.GetForEachStatementInfo(semanticModel, val2) : default(ForEachStatementInfo)); Conversion elementConversion = ((ForEachStatementInfo)(ref val3)).ElementConversion; if (((Conversion)(ref elementConversion)).IsExplicit) { TypeInfo typeInfo = CSharpExtensions.GetTypeInfo(((IOperation)val).SemanticModel, (ExpressionSyntax)(object)val2.Type, default(CancellationToken)); ITypeSymbol type = ((TypeInfo)(ref typeInfo)).Type; Check((Action<Diagnostic>)((OperationAnalysisContext)(object)op).ReportDiagnostic, il2cpp, ((ForEachStatementInfo)(ref val3)).ElementType, type, (SyntaxNode)(object)val2.Type, "foreach"); } } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)5 }); } }); } private static void Check(Action<Diagnostic> report, INamedTypeSymbol il2cpp, ITypeSymbol from, ITypeSymbol to, SyntaxNode syntax, string kind) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown if (from != null && to != null && !Known.Same((ISymbol)(object)from, (ISymbol)(object)to) && Known.IsInterop(from, il2cpp) && Known.IsInterop(to, il2cpp) && Known.DerivesFrom(to, (INamedTypeSymbol)from.OriginalDefinition)) { string text = ((ISymbol)to).ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); string text2; string text3; switch (kind) { case "as": text2 = "'as'"; text3 = ".As<" + text + ">()"; break; case "is": text2 = "'is'"; text3 = ".Is<" + text + ">()"; break; case "cast": text2 = "A cast"; text3 = ".As<" + text + ">() (null when it is not one) or .Cast<" + text + ">()"; break; case "foreach": text2 = "The foreach cast"; text3 = "a loop over the declared element type and .As<" + text + ">()"; break; default: text2 = "A type pattern"; text3 = ".As<" + text + ">() and a null check"; break; } ImmutableDictionary<string, string> immutableDictionary = ImmutableDictionary<string, string>.Empty.Add("kind", kind); report(Diagnostic.Create(Rules.InteropCast, syntax.GetLocation(), immutableDictionary, new object[4] { text2, ((ISymbol)from).ToDisplayString((SymbolDisplayFormat)null), ((ISymbol)to).ToDisplayString((SymbolDisplayFormat)null), text3 })); } } } internal static class Known { internal const string Il2CppObjectBase = "Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"; internal const string SodApiGuid = "sodapi.core"; internal static bool Same(ISymbol a, ISymbol b) { if (a != null && b != null) { return SymbolEqualityComparer.Default.Equals(a.OriginalDefinition, b.OriginalDefinition); } return false; } internal static bool DerivesFrom(ITypeSymbol type, INamedTypeSymbol baseType) { if (type == null || baseType == null) { return false; } for (ITypeSymbol val = type; val != null; val = (ITypeSymbol)(object)val.BaseType) { if (Same((ISymbol)(object)val, (ISymbol)(object)baseType)) { return true; } } return false; } internal static bool IsInterop(ITypeSymbol type, INamedTypeSymbol il2cppBase) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Invalid comparison between Unknown and I4 if (type != null && (int)type.TypeKind == 2) { return DerivesFrom(type, il2cppBase); } return false; } internal static bool IsGameAssembly(IAssemblySymbol a) { string text = ((a != null) ? ((ISymbol)a).Name : null); if (text != null) { if (!text.Equals("Assembly-CSharp", StringComparison.Ordinal)) { return text.Equals("Assembly-CSharp-firstpass", StringComparison.Ordinal); } return true; } return false; } internal static bool IsUnityAssembly(IAssemblySymbol a) { string text = ((a != null) ? ((ISymbol)a).Name : null); if (text != null) { if (!text.StartsWith("UnityEngine", StringComparison.Ordinal)) { return text.StartsWith("Unity.", StringComparison.Ordinal); } return true; } return false; } internal static IOperation Unwrap(IOperation op) { while (true) { IOperation val = op; IConversionOperation val2 = (IConversionOperation)(object)((val is IConversionOperation) ? val : null); if (val2 == null || !((IOperation)val2).IsImplicit) { IDelegateCreationOperation val3 = (IDelegateCreationOperation)(object)((val is IDelegateCreationOperation) ? val : null); if (val3 == null) { IParenthesizedOperation val4 = (IParenthesizedOperation)(object)((val is IParenthesizedOperation) ? val : null); if (val4 == null) { break; } op = val4.Operand; } else { op = val3.Target; } } else { op = val2.Operand; } } return op; } internal static IInvocationOperation InvocationTaking(IAnonymousFunctionOperation lambda, out IParameterSymbol parameter) { parameter = null; IOperation parent = ((IOperation)lambda).Parent; while (true) { if (!(parent is IDelegateCreationOperation)) { IConversionOperation val = (IConversionOperation)(object)((parent is IConversionOperation) ? parent : null); if (val == null || !((IOperation)val).IsImplicit) { break; } } parent = parent.Parent; } IArgumentOperation val2 = (IArgumentOperation)(object)((parent is IArgumentOperation) ? parent : null); if (val2 != null) { IOperation parent2 = ((IOperation)val2).Parent; IInvocationOperation val3 = (IInvocationOperation)(object)((parent2 is IInvocationOperation) ? parent2 : null); if (val3 != null) { parameter = val2.Parameter; return val3; } } return null; } internal static bool IsConstant(IFieldReferenceOperation f) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) if (!f.Field.IsConst) { return ((IOperation)f).ConstantValue.HasValue; } return true; } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class MissingDependencyAnalyzer : DiagnosticAnalyzer { public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.MissingDependency); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; INamedTypeSymbol plugin = compilation.GetTypeByMetadataName("BepInEx.BepInPlugin"); INamedTypeSymbol dependency = compilation.GetTypeByMetadataName("BepInEx.BepInDependency"); INamedTypeSymbol sodPlugin = compilation.GetTypeByMetadataName("SodApi.SodPlugin"); INamedTypeSymbol sod = compilation.GetTypeByMetadataName("SodApi.Sod"); if (plugin != null && dependency != null && (sodPlugin != null || sod != null)) { start.RegisterSymbolStartAction((Action<SymbolStartAnalysisContext>)delegate(SymbolStartAnalysisContext symbolStart) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 INamedTypeSymbol type = (INamedTypeSymbol)symbolStart.Symbol; if ((int)((ITypeSymbol)type).TypeKind == 2 && !((ISymbol)type).IsAbstract && Has(type, plugin) && !DependsOnSodApi(type, dependency)) { if (Known.DerivesFrom((ITypeSymbol)(object)((ITypeSymbol)type).BaseType, sodPlugin)) { symbolStart.RegisterSymbolEndAction((Action<SymbolAnalysisContext>)delegate(SymbolAnalysisContext end) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Report((Action<Diagnostic>)((SymbolAnalysisContext)(object)end).ReportDiagnostic, type); }); } else if (sod != null) { int registers = 0; symbolStart.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; if (((ISymbol)val.TargetMethod).Name == "Register" && Known.Same((ISymbol)(object)((ISymbol)val.TargetMethod).ContainingType, (ISymbol)(object)sod)) { Interlocked.Exchange(ref registers, 1); } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); symbolStart.RegisterSymbolEndAction((Action<SymbolAnalysisContext>)delegate(SymbolAnalysisContext end) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) if (Volatile.Read(in registers) != 0) { Report((Action<Diagnostic>)((SymbolAnalysisContext)(object)end).ReportDiagnostic, type); } }); } } }, (SymbolKind)11); } }); } private static void Report(Action<Diagnostic> report, INamedTypeSymbol type) { if (((ISymbol)type).Locations.Length != 0 && ((ISymbol)type).Locations[0].IsInSource) { report(Diagnostic.Create(Rules.MissingDependency, ((ISymbol)type).Locations[0], new object[1] { ((ISymbol)type).Name })); } } private static bool Has(INamedTypeSymbol type, INamedTypeSymbol attribute) { ImmutableArray<AttributeData>.Enumerator enumerator = ((ISymbol)type).GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { if (Known.Same((ISymbol)(object)enumerator.Current.AttributeClass, (ISymbol)(object)attribute)) { return true; } } return false; } private static bool DependsOnSodApi(INamedTypeSymbol type, INamedTypeSymbol dependency) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) ImmutableArray<AttributeData>.Enumerator enumerator = ((ISymbol)type).GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { AttributeData current = enumerator.Current; if (Known.Same((ISymbol)(object)current.AttributeClass, (ISymbol)(object)dependency) && current.ConstructorArguments.Length != 0) { TypedConstant val = current.ConstructorArguments[0]; if (((TypedConstant)(ref val)).Value is string a && string.Equals(a, "sodapi.core", StringComparison.OrdinalIgnoreCase)) { return true; } } } return false; } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class OffMainThreadAnalyzer : DiagnosticAnalyzer { private sealed class Types { public INamedTypeSymbol Il2Cpp; public INamedTypeSymbol Background; public INamedTypeSymbol MainThread; public INamedTypeSymbol Game; public INamedTypeSymbol Task; public INamedTypeSymbol TaskFactory; public INamedTypeSymbol ThreadPool; public INamedTypeSymbol Thread; public INamedTypeSymbol Parallel; public INamedTypeSymbol UnityDebug; } public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.OffMainThread); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; Types t = new Types { Il2Cpp = compilation.GetTypeByMetadataName("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"), Background = compilation.GetTypeByMetadataName("SodApi.Sod+Background"), MainThread = compilation.GetTypeByMetadataName("SodApi.Sod+MainThread"), Game = compilation.GetTypeByMetadataName("SodApi.Sod+Game"), Task = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task"), TaskFactory = compilation.GetTypeByMetadataName("System.Threading.Tasks.TaskFactory"), ThreadPool = compilation.GetTypeByMetadataName("System.Threading.ThreadPool"), Thread = compilation.GetTypeByMetadataName("System.Threading.Thread"), Parallel = compilation.GetTypeByMetadataName("System.Threading.Tasks.Parallel"), UnityDebug = compilation.GetTypeByMetadataName("UnityEngine.Debug") }; if (t.Il2Cpp != null) { start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_003d: Unknown result type (might be due to invalid IL or missing references) IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; string text = Starter(t, val.TargetMethod); if (text != null) { ImmutableArray<IArgumentOperation>.Enumerator enumerator = val.Arguments.GetEnumerator(); while (enumerator.MoveNext()) { IArgumentOperation current = enumerator.Current; Scan((Action<Diagnostic>)((OperationAnalysisContext)(object)op).ReportDiagnostic, t, current.Value, text); } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) IObjectCreationOperation val = (IObjectCreationOperation)((OperationAnalysisContext)(ref op)).Operation; if (Known.Same((ISymbol)(object)((IOperation)val).Type, (ISymbol)(object)t.Thread)) { ImmutableArray<IArgumentOperation>.Enumerator enumerator = val.Arguments.GetEnumerator(); while (enumerator.MoveNext()) { IArgumentOperation current = enumerator.Current; Scan((Action<Diagnostic>)((OperationAnalysisContext)(object)op).ReportDiagnostic, t, current.Value, "a new Thread"); } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)36 }); } }); } private static string Starter(Types t, IMethodSymbol m) { INamedTypeSymbol containingType = ((ISymbol)m).ContainingType; if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.Background) && ((ISymbol)m).Name == "Run") { return "Sod.Background.Run"; } if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.Task) && ((ISymbol)m).Name == "Run") { return "Task.Run"; } if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.TaskFactory) && ((ISymbol)m).Name == "StartNew") { return "Task.Factory.StartNew"; } if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.ThreadPool) && (((ISymbol)m).Name == "QueueUserWorkItem" || ((ISymbol)m).Name == "UnsafeQueueUserWorkItem")) { return "ThreadPool." + ((ISymbol)m).Name; } if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.Parallel) && (((ISymbol)m).Name == "For" || ((ISymbol)m).Name == "ForEach" || ((ISymbol)m).Name == "Invoke")) { return "Parallel." + ((ISymbol)m).Name; } return null; } private static void Scan(Action<Diagnostic> report, Types t, IOperation value, string where) { IOperation obj = Known.Unwrap(value); IAnonymousFunctionOperation val = (IAnonymousFunctionOperation)(object)((obj is IAnonymousFunctionOperation) ? obj : null); if (val != null) { bool attached = where == "Sod.Background.Run"; HashSet<IOperation> flagged = new HashSet<IOperation>(); Walk((IOperation)(object)val.Body, report, t, where, attached, flagged); } } private static void Walk(IOperation op, Action<Diagnostic> report, Types t, string where, bool attached, HashSet<IOperation> flagged) { //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0274: Invalid comparison between Unknown and I4 if (op == null) { return; } IAnonymousFunctionOperation val = (IAnonymousFunctionOperation)(object)((op is IAnonymousFunctionOperation) ? op : null); if (val != null && RunsElsewhere(t, val)) { return; } IInvocationOperation val2 = (IInvocationOperation)(object)((op is IInvocationOperation) ? op : null); if (val2 != null && Starter(t, val2.TargetMethod) != null) { return; } if (!attached) { IUsingOperation val3 = (IUsingOperation)(object)((op is IUsingOperation) ? op : null); if (val3 != null && Attaches(t, val3.Resources)) { Walk(val3.Resources, report, t, where, attached: false, flagged); Walk(val3.Body, report, t, where, attached: true, flagged); return; } } if (!attached) { IBlockOperation val4 = (IBlockOperation)(object)((op is IBlockOperation) ? op : null); if (val4 != null) { bool attached2 = false; ImmutableArray<IOperation>.Enumerator enumerator = val4.Operations.GetEnumerator(); while (enumerator.MoveNext()) { IOperation current = enumerator.Current; Walk(current, report, t, where, attached2, flagged); IUsingDeclarationOperation val5 = (IUsingDeclarationOperation)(object)((current is IUsingDeclarationOperation) ? current : null); if (val5 != null && Attaches(t, (IOperation)(object)val5.DeclarationGroup)) { attached2 = true; } } return; } } foreach (IOperation child in op.Children) { Walk(child, report, t, where, attached, flagged); } ISymbol val6 = null; ITypeSymbol val7 = null; IOperation val8 = null; IInvocationOperation val9 = (IInvocationOperation)(object)((op is IInvocationOperation) ? op : null); if (val9 == null) { IPropertyReferenceOperation val10 = (IPropertyReferenceOperation)(object)((op is IPropertyReferenceOperation) ? op : null); if (val10 == null) { IFieldReferenceOperation val11 = (IFieldReferenceOperation)(object)((op is IFieldReferenceOperation) ? op : null); if (val11 == null || Known.IsConstant(val11)) { IEventReferenceOperation val12 = (IEventReferenceOperation)(object)((op is IEventReferenceOperation) ? op : null); if (val12 == null) { IObjectCreationOperation val13 = (IObjectCreationOperation)(object)((op is IObjectCreationOperation) ? op : null); if (val13 != null) { val6 = (ISymbol)(object)val13.Constructor; val7 = ((IOperation)val13).Type; } } else { val6 = (ISymbol)(object)val12.Event; val7 = (ITypeSymbol)(object)((ISymbol)val12.Event).ContainingType; val8 = ((IMemberReferenceOperation)val12).Instance; } } else { val6 = (ISymbol)(object)val11.Field; val7 = (ITypeSymbol)(object)((ISymbol)val11.Field).ContainingType; val8 = ((IMemberReferenceOperation)val11).Instance; } } else { val6 = (ISymbol)(object)val10.Property; val7 = (ITypeSymbol)(object)((ISymbol)val10.Property).ContainingType; val8 = ((IMemberReferenceOperation)val10).Instance; } } else { val6 = (ISymbol)(object)val9.TargetMethod; val7 = (ITypeSymbol)(object)((ISymbol)val9.TargetMethod).ContainingType; val8 = val9.Instance; } if (val6 == null) { return; } if (val8 != null && flagged.Contains(Strip(val8))) { flagged.Add(op); return; } string text = Kind(t, val7, attached); if (text != null) { flagged.Add(op); string text2 = ((text == "an IL2CPP object") ? "run the work with Sod.Background.Run, which attaches its thread to IL2CPP" : "copy the values you need on the main thread first, or move this into Sod.MainThread.Post"); IMethodSymbol val14 = (IMethodSymbol)(object)((val6 is IMethodSymbol) ? val6 : null); string text3 = ((val14 != null && (int)val14.MethodKind == 1) ? ("new " + ((ISymbol)val7).ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat)) : (((ISymbol)val7).Name + "." + val6.Name)); report(Diagnostic.Create(Rules.OffMainThread, op.Syntax.GetLocation(), new object[4] { text3, text, where, text2 })); } } private static bool Attaches(Types t, IOperation resources) { if (resources == null) { return false; } IInvocationOperation val = (IInvocationOperation)(object)((resources is IInvocationOperation) ? resources : null); if (val != null && Known.Same((ISymbol)(object)((ISymbol)val.TargetMethod).ContainingType, (ISymbol)(object)t.Background) && ((ISymbol)val.TargetMethod).Name == "AttachThread") { return true; } foreach (IOperation child in resources.Children) { if (Attaches(t, child)) { return true; } } return false; } private static IOperation Strip(IOperation op) { while (true) { IConversionOperation val = (IConversionOperation)(object)((op is IConversionOperation) ? op : null); if (val == null || !((IOperation)val).IsImplicit) { break; } op = val.Operand; } return op; } private static string Kind(Types t, ITypeSymbol owner, bool attached) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Invalid comparison between Unknown and I4 if (owner == null || owner.IsValueType || (int)owner.TypeKind == 5) { return null; } IAssemblySymbol containingAssembly = ((ISymbol)owner).ContainingAssembly; if (Known.IsGameAssembly(containingAssembly)) { return "a game API"; } if (Known.IsUnityAssembly(containingAssembly)) { if (!Known.Same((ISymbol)(object)owner, (ISymbol)(object)t.UnityDebug)) { return "a Unity API"; } return null; } if (!attached && Known.DerivesFrom(owner, t.Il2Cpp)) { return "an IL2CPP object"; } return null; } private static bool RunsElsewhere(Types t, IAnonymousFunctionOperation lambda) { IParameterSymbol parameter; IInvocationOperation val = Known.InvocationTaking(lambda, out parameter); if (val == null) { return false; } INamedTypeSymbol containingType = ((ISymbol)val.TargetMethod).ContainingType; if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.MainThread)) { return true; } if (Known.Same((ISymbol)(object)containingType, (ISymbol)(object)t.Game) && ((ISymbol)val.TargetMethod).Name == "WhenWorldReady") { return true; } return Starter(t, val.TargetMethod) != null; } } public static class Rules { public const string HelpBase = "https://github.com/Revolution2577/SodApi/blob/main/docs/en/guides/analyzers.md#"; public const string MissingDependencyId = "SOD0001"; public const string InteropCastId = "SOD0002"; public const string OffMainThreadId = "SOD0003"; public const string GameObjectPayloadId = "SOD0004"; public const string SubscribeInTickId = "SOD0005"; public const string UnsafePatchTargetId = "SOD0006"; public const string ClockSeedId = "SOD0007"; public static readonly DiagnosticDescriptor MissingDependency = Make("SOD0001", "SOD API plugin without [BepInDependency(SodApiInfo.Guid)]", "Plugin '{0}' uses SOD API but has no [BepInDependency(SodApiInfo.Guid)]; BepInEx may load it before SOD API", "SodApi.Usage", "Without the dependency BepInEx can load the plugin before SOD API, and every SOD API call in OnLoad then fails."); public static readonly DiagnosticDescriptor InteropCast = Make("SOD0002", "C# cast or type test on an IL2CPP object", "{0} from '{1}' to '{2}' checks the C# wrapper, not the real IL2CPP object, and fails for objects handed out under a base type; use {3}", "SodApi.IL2CPP", "An interop wrapper's C# type is the type the value was declared with. 'as' returns null, 'is' is false and a cast throws even when the native object really is of the target type."); public static readonly DiagnosticDescriptor OffMainThread = Make("SOD0003", "Unity or game object used on a worker thread", "'{0}' is {1} used inside {2}, which runs on a worker thread; {3}", "SodApi.Threading", "Unity and game objects may only be touched on the main thread. Copy plain values on the main thread, compute on the worker, apply the result with Sod.MainThread.Post."); public static readonly DiagnosticDescriptor GameObjectPayload = Make("SOD0004", "Game object stored in save data or sent over the network", "{0} holds '{1}'{2}, a game object; SOD API refuses to save or send game objects: store {3} instead", "SodApi.Coop", "Game objects live only on this machine while the world is loaded. Save slots and network payloads throw NotSupportedException for them at run time."); public static readonly DiagnosticDescriptor SubscribeInTick = Make("SOD0005", "Subscription or tick created inside a repeating callback", "{0} inside the '{1}' callback adds a new {2} every time it runs; register it once (in OnLoad or behind a stored handle)", "SodApi.Usage", "Code in Mod.Ticks.Update/LateUpdate/Every and Sod.Time.Every runs again and again. A subscription or tick created there piles up: handlers run many times and memory grows."); public static readonly DiagnosticDescriptor UnsafePatchTarget = Make("SOD0006", "Patch target that is unsafe on IL2CPP", "Patching '{0}' is unsafe on IL2CPP: {1}; patch a caller of it instead", "SodApi.IL2CPP", "A Harmony detour on a method with a ref/out parameter of a reference type makes the IL2CPP trampoline return default values, and an async method is only a stub whose real body lives in its state machine."); public static readonly DiagnosticDescriptor ClockSeed = Make("SOD0007", "Random generator seeded from the clock", "{0} is seeded from the clock ('{1}'): generators made close together repeat each other and every co-op machine rolls differently; use Sod.Random (Create(), Create(seed), Shared(key) or Mod.Random)", "SodApi.Coop", "A clock seed has few distinct values, repeats for generators created in the same tick and is different on every machine. Sod.Random gives entropy, fixed, co-op-shared or saved streams."); private static DiagnosticDescriptor Make(string id, string title, string message, string category, string description) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown return new DiagnosticDescriptor(id, title, message, category, (DiagnosticSeverity)2, true, description, "https://github.com/Revolution2577/SodApi/blob/main/docs/en/guides/analyzers.md#" + id.ToLowerInvariant(), Array.Empty<string>()); } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class SubscribeInTickAnalyzer : DiagnosticAnalyzer { private sealed class Types { public INamedTypeSymbol Event; public INamedTypeSymbol Ticks; public INamedTypeSymbol Time; public INamedTypeSymbol Patcher; } private sealed class Found { public ISymbol Method; public Location Location; public string What; public string Adds; } public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.SubscribeInTick); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; Types t = new Types { Event = compilation.GetTypeByMetadataName("SodApi.SodEvent`1"), Ticks = compilation.GetTypeByMetadataName("SodApi.ModTicks"), Time = compilation.GetTypeByMetadataName("SodApi.Sod+Time"), Patcher = compilation.GetTypeByMetadataName("SodApi.ModPatcher") }; if (t.Ticks != null || t.Time != null) { start.RegisterSymbolStartAction((Action<SymbolStartAnalysisContext>)delegate(SymbolStartAnalysisContext symbolStart) { ConcurrentDictionary<ISymbol, string> tickMethods = new ConcurrentDictionary<ISymbol, string>((IEqualityComparer<ISymbol>?)SymbolEqualityComparer.Default); ConcurrentBag<Found> pending = new ConcurrentBag<Found>(); symbolStart.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; string text = TickName(t, val.TargetMethod); if (text != null) { ImmutableArray<IArgumentOperation>.Enumerator enumerator = val.Arguments.GetEnumerator(); while (enumerator.MoveNext()) { IOperation obj = Known.Unwrap(enumerator.Current.Value); IMethodReferenceOperation val2 = (IMethodReferenceOperation)(object)((obj is IMethodReferenceOperation) ? obj : null); if (val2 != null) { tickMethods.TryAdd((ISymbol)(object)val2.Method.OriginalDefinition, text); } } } Consider(op, (IOperation)(object)val, t, pending); }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); symbolStart.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) Consider(op, ((OperationAnalysisContext)(ref op)).Operation, t, pending); }, (OperationKind[])(object)new OperationKind[2] { (OperationKind)43, (OperationKind)45 }); symbolStart.RegisterSymbolEndAction((Action<SymbolAnalysisContext>)delegate(SymbolAnalysisContext end) { foreach (Found item in pending) { if (item.Method != null && tickMethods.TryGetValue(item.Method.OriginalDefinition, out var value)) { ((SymbolAnalysisContext)(ref end)).ReportDiagnostic(Diagnostic.Create(Rules.SubscribeInTick, item.Location, new object[3] { item.What, value, item.Adds })); } } }); }, (SymbolKind)11); } }); } private static void Consider(OperationAnalysisContext ctx, IOperation op, Types t, ConcurrentBag<Found> pending) { if (!Describe(op, t, out var what, out var adds)) { return; } ISymbol method = ((OperationAnalysisContext)(ref ctx)).ContainingSymbol; bool flag = false; for (IOperation parent = op.Parent; parent != null; parent = parent.Parent) { IAnonymousFunctionOperation val = (IAnonymousFunctionOperation)(object)((parent is IAnonymousFunctionOperation) ? parent : null); if (val != null) { flag = true; IParameterSymbol parameter; IInvocationOperation val2 = Known.InvocationTaking(val, out parameter); string text = ((val2 == null) ? null : TickName(t, val2.TargetMethod)); if (text != null) { ((OperationAnalysisContext)(ref ctx)).ReportDiagnostic(Diagnostic.Create(Rules.SubscribeInTick, op.Syntax.GetLocation(), new object[3] { what, text, adds })); return; } } else { ILocalFunctionOperation val3 = (ILocalFunctionOperation)(object)((parent is ILocalFunctionOperation) ? parent : null); if (val3 != null && !flag) { method = (ISymbol)(object)val3.Symbol; break; } } } if (!flag) { pending.Add(new Found { Method = method, Location = op.Syntax.GetLocation(), What = what, Adds = adds }); } } private static bool Describe(IOperation op, Types t, out string what, out string adds) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Invalid comparison between Unknown and I4 what = (adds = null); ICompoundAssignmentOperation val = (ICompoundAssignmentOperation)(object)((op is ICompoundAssignmentOperation) ? op : null); if (val == null || (int)val.OperatorKind != 1 || val.OperatorMethod == null || !Known.Same((ISymbol)(object)((ISymbol)val.OperatorMethod).ContainingType, (ISymbol)(object)t.Event)) { IEventAssignmentOperation val2 = (IEventAssignmentOperation)(object)((op is IEventAssignmentOperation) ? op : null); if (val2 == null || !val2.Adds) { IInvocationOperation val3 = (IInvocationOperation)(object)((op is IInvocationOperation) ? op : null); if (val3 != null) { if (!(((IOperation)val3).Parent is IExpressionStatementOperation)) { return false; } IMethodSymbol targetMethod = val3.TargetMethod; if (Known.Same((ISymbol)(object)((ISymbol)targetMethod).ContainingType, (ISymbol)(object)t.Event) && (((ISymbol)targetMethod).Name == "Subscribe" || ((ISymbol)targetMethod).Name == "Once")) { what = ((ISymbol)targetMethod).Name + " on " + Name(val3.Instance); adds = "subscription"; return true; } string text = TickName(t, targetMethod); if (text != null) { what = text; adds = "repeating callback"; return true; } if (Known.Same((ISymbol)(object)((ISymbol)targetMethod).ContainingType, (ISymbol)(object)t.Patcher) && (((ISymbol)targetMethod).Name == "Before" || ((ISymbol)targetMethod).Name == "After")) { what = "Mod.Patch." + ((ISymbol)targetMethod).Name; adds = "hook"; return true; } return false; } return false; } what = "'+=' on event " + Name(val2.EventReference); adds = "handler"; return true; } what = "'+=' on " + Name(((IAssignmentOperation)val).Target); adds = "handler"; return true; } private static string TickName(Types t, IMethodSymbol m) { if (Known.Same((ISymbol)(object)((ISymbol)m).ContainingType, (ISymbol)(object)t.Ticks) && (((ISymbol)m).Name == "Update" || ((ISymbol)m).Name == "LateUpdate" || ((ISymbol)m).Name == "Every")) { return "Mod.Ticks." + ((ISymbol)m).Name; } if (Known.Same((ISymbol)(object)((ISymbol)m).ContainingType, (ISymbol)(object)t.Time) && ((ISymbol)m).Name == "Every") { return "Sod.Time.Every"; } return null; } private static string Name(IOperation target) { IPropertyReferenceOperation val = (IPropertyReferenceOperation)(object)((target is IPropertyReferenceOperation) ? target : null); if (val == null) { IFieldReferenceOperation val2 = (IFieldReferenceOperation)(object)((target is IFieldReferenceOperation) ? target : null); if (val2 == null) { IEventReferenceOperation val3 = (IEventReferenceOperation)(object)((target is IEventReferenceOperation) ? target : null); if (val3 == null) { ILocalReferenceOperation val4 = (ILocalReferenceOperation)(object)((target is ILocalReferenceOperation) ? target : null); if (val4 != null) { return ((ISymbol)val4.Local).Name; } return "an event"; } return ((ISymbol)val3.Event).Name; } return ((ISymbol)val2.Field).Name; } return ((ISymbol)((ISymbol)val.Property).ContainingType).Name + "." + ((ISymbol)val.Property).Name; } } [DiagnosticAnalyzer("C#", new string[] { })] public sealed class UnsafePatchTargetAnalyzer : DiagnosticAnalyzer { private sealed class Target { public INamedTypeSymbol Type; public string Name; public ITypeSymbol[] Args; public bool NotNormal; public AttributeData Source; public Target With(Target over) { return new Target { Type = (over.Type ?? Type), Name = (over.Name ?? Name), Args = (over.Args ?? Args), NotNormal = (over.NotNormal || NotNormal), Source = (over.Source ?? Source) }; } } private const int AllowByRef = 1; private const int AllowAsyncStub = 2; public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create<DiagnosticDescriptor>(Rules.UnsafePatchTarget); public override void Initialize(AnalysisContext context) { context.ConfigureGeneratedCodeAnalysis((GeneratedCodeAnalysisFlags)0); context.EnableConcurrentExecution(); context.RegisterCompilationStartAction((Action<CompilationStartAnalysisContext>)delegate(CompilationStartAnalysisContext start) { Compilation compilation = start.Compilation; INamedTypeSymbol il2cpp = compilation.GetTypeByMetadataName("Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase"); INamedTypeSymbol harmonyPatch = compilation.GetTypeByMetadataName("HarmonyLib.HarmonyPatch"); INamedTypeSymbol patcher = compilation.GetTypeByMetadataName("SodApi.ModPatcher"); INamedTypeSymbol options = compilation.GetTypeByMetadataName("SodApi.SodPatchOptionsAttribute"); INamedTypeSymbol asyncAttr = compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.AsyncStateMachineAttribute"); if (il2cpp != null) { if (harmonyPatch != null) { start.RegisterSymbolAction((Action<SymbolAnalysisContext>)delegate(SymbolAnalysisContext sym) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) CheckPatchClass(sym, harmonyPatch, options, il2cpp, asyncAttr); }, (SymbolKind[])(object)new SymbolKind[1] { (SymbolKind)11 }); } if (patcher != null) { start.RegisterOperationAction((Action<OperationAnalysisContext>)delegate(OperationAnalysisContext op) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) IInvocationOperation val = (IInvocationOperation)((OperationAnalysisContext)(ref op)).Operation; IMethodSymbol targetMethod = val.TargetMethod; if (Known.Same((ISymbol)(object)((ISymbol)targetMethod).ContainingType, (ISymbol)(object)patcher) && (!(((ISymbol)targetMethod).Name != "Before") || !(((ISymbol)targetMethod).Name != "After"))) { INamedTypeSymbol val2 = null; string text = null; List<string> withParams = new List<string>(); ImmutableArray<IArgumentOperation>.Enumerator enumerator = val.Arguments.GetEnumerator(); while (enumerator.MoveNext()) { IArgumentOperation current = enumerator.Current; if (current.Parameter != null) { if (((ISymbol)current.Parameter).Name == "type") { IOperation obj = Known.Unwrap(current.Value); ITypeOfOperation val3 = (ITypeOfOperation)(object)((obj is ITypeOfOperation) ? obj : null); if (val3 != null) { ITypeSymbol typeOperand = val3.TypeOperand; val2 = (INamedTypeSymbol)(object)((typeOperand is INamedTypeSymbol) ? typeOperand : null); continue; } } if (((ISymbol)current.Parameter).Name == "method" && current.Value.ConstantValue.HasValue) { text = current.Value.ConstantValue.Value as string; } else if (((ISymbol)current.Parameter).Name == "withParams") { IOperation value = current.Value; IArrayCreationOperation val4 = (IArrayCreationOperation)(object)((value is IArrayCreationOperation) ? value : null); if (val4 != null && val4.Initializer != null) { ImmutableArray<IOperation>.Enumerator enumerator2 = val4.Initializer.ElementValues.GetEnumerator(); while (enumerator2.MoveNext()) { IOperation current2 = enumerator2.Current; if (current2.ConstantValue.HasValue && current2.ConstantValue.Value is string item) { withParams.Add(item); } } } } } } if (val2 != null && text != null && IsGameSide(val2, il2cpp)) { string text2 = Verdict((from x in Methods(val2, text) where withParams.All((string p) => x.Parameters.Any((IParameterSymbol q) => ((ISymbol)q).Name == p)) select x).ToList(), 0, asyncAttr); if (text2 != null) { ((OperationAnalysisContext)(ref op)).ReportDiagnostic(Diagnostic.Create(Rules.UnsafePatchTarget, ((IOperation)val).Syntax.GetLocation(), new object[2] { ((ISymbol)val2).Name + "." + text, text2 })); } } } }, (OperationKind[])(object)new OperationKind[1] { (OperationKind)22 }); } } }); } private static void CheckPatchClass(SymbolAnalysisContext ctx, INamedTypeSymbol harmonyPatch, INamedTypeSymbol options, INamedTypeSymbol il2cpp, INamedTypeSymbol asyncAttr) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown INamedTypeSymbol val = (INamedTypeSymbol)((SymbolAnalysisContext)(ref ctx)).Symbol; if (((INamespaceOrTypeSymbol)val).GetMembers("TargetMethod").Length > 0 || ((INamespaceOrTypeSymbol)val).GetMembers("TargetMethods").Length > 0) { return; } Target target = new Target(); bool flag = false; ImmutableArray<AttributeData>.Enumerator enumerator = ((ISymbol)val).GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { AttributeData current = enumerator.Current; if (Known.Same((ISymbol)(object)current.AttributeClass, (ISymbol)(object)harmonyPatch)) { target = target.With(Parse(current)); flag = true; } } int relaxed = Relaxed(val, options); List<Target> list = new List<Target>(); foreach (IMethodSymbol item in ((INamespaceOrTypeSymbol)val).GetMembers().OfType<IMethodSymbol>()) { Target target2 = null; enumerator = ((ISymbol)item).GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { AttributeData current3 = enumerator.Current; if (Known.Same((ISymbol)(object)current3.AttributeClass, (ISymbol)(object)harmonyPatch)) { target2 = (target2 ?? new Target()).With(Parse(current3)); } } if (target2 != null) { list.Add(target.With(target2)); } } if (list.Count == 0 && flag) { list.Add(target); } HashSet<string> hashSet = new HashSet<string>(); foreach (Target t in list) { if (t.NotNormal || t.Type == null || t.Name == null || !IsGameSide(t.Type, il2cpp)) { continue; } string text = Verdict((from m in Methods(t.Type, t.Name) where t.Args == null || Matches(m, t.Args) select m).ToList(), relaxed, asyncAttr); if (text != null && hashSet.Add(((ISymbol)t.Type).Name + "." + t.Name)) { AttributeData source = t.Source; object obj; if (source == null) { obj = null; } else { SyntaxReference applicationSyntaxReference = source.ApplicationSyntaxReference; obj = ((applicationSyntaxReference != null) ? applicationSyntaxReference.GetSyntax(((SymbolAnalysisContext)(ref ctx)).CancellationToken).GetLocation() : null); } if (obj == null) { obj = ((ISymbol)val).Locations.FirstOrDefault(); } Location val2 = (Location)obj; if (val2 != (Location)null && val2.IsInSource) { ((SymbolAnalysisContext)(ref ctx)).ReportDiagnostic(Diagnostic.Create(Rules.UnsafePatchTarget, val2, new object[2] { ((ISymbol)t.Type).Name + "." + t.Name, text })); } } } } private static Target Parse(AttributeData a) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected I4, but got Unknown Target target = new Target { Source = a }; if (a.ConstructorArguments.Count((TypedConstant x) => (int)((TypedConstant)(ref x)).Kind == 1 && ((TypedConstant)(ref x)).Value is string) > 1) { return new Target { NotNormal = true, Source = a }; } ImmutableArray<TypedConstant>.Enumerator enumerator = a.ConstructorArguments.GetEnumerator(); while (enumerator.MoveNext()) { TypedConstant current = enumerator.Current; TypedConstantKind kind = ((TypedConstant)(ref current)).Kind; switch (kind - 1) { case 2: if (target.Type == null) { ref INamedTypeSymbol type2 = ref target.Type; object value = ((TypedConstant)(ref current)).Value; type2 = (INamedTypeSymbol)((value is INamedTypeSymbol) ? value : null); } break; case 0: if (((TypedConstant)(ref current)).Value is string name && target.Name == null) { target.Name = name; } break; case 1: { ITypeSymbol type3 = ((TypedConstant)(ref current)).Type; if (((type3 != null) ? ((ISymbol)type3).Name : null) == "MethodType") { target.NotNormal = Convert.ToInt32(((TypedConstant)(ref current)).Value) != 0; } break; } case 3: { ITypeSymbol type = ((TypedConstant)(ref current)).Type; IArrayTypeSymbol val = (IArrayTypeSymbol)(object)((type is IArrayTypeSymbol) ? type : null); if (val != null && ((ISymbol)val.ElementType).Name == "Type" && !((TypedConstant)(ref current)).IsNull) { target.Args = ((TypedConstant)(ref current)).Values.Select(delegate(TypedConstant v) { object value2 = ((TypedConstant)(ref v)).Value; return (ITypeSymbol)((value2 is ITypeSymbol) ? value2 : null); }).ToArray(); } break; } } } return target; } private static bool IsGameSide(INamedTypeSymbol type, INamedTypeSymbol il2cpp) { if (!Known.DerivesFrom((ITypeSymbol)(object)type, il2cpp) && !Known.IsGameAssembly(((ISymbol)type).ContainingAssembly)) { return Known.IsUnityAssembly(((ISymbol)type).ContainingAssembly); } return true; } private static int Relaxed(INamedTypeSymbol type, INamedTypeSymbol options) { //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) if (options == null) { return 0; } ImmutableArray<AttributeData>.Enumerator enumerator = ((ISymbol)type).GetAttributes().GetEnumerator(); while (enumerator.MoveNext()) { AttributeData current = enumerator.Current; if (Known.Same((ISymbol)(object)current.AttributeClass, (ISymbol)(object)options) && current.ConstructorArguments.Length == 1) { TypedConstant val = current.ConstructorArguments[0]; if (((TypedConstant)(ref val)).Value != null) { val = current.ConstructorArguments[0]; return Convert.ToInt32(((TypedConstant)(ref val)).Value); } } } return 0; } private static IEnumerable<IMethodSymbol> Methods(INamedTypeSymbol type, string name) { return from m in ((INamespaceOrTypeSymbol)type).GetMembers(name).OfType<IMethodSymbol>() where (int)m.MethodKind == 10 select m; } private static bool Matches(IMethodSymbol m, ITypeSymbol[] args) { if (m.Parameters.Length != args.Length) { return false; } for (int i = 0; i < args.Length; i++) { if (args[i] != null && !SymbolEqualityComparer.Default.Equals((ISymbol)(object)m.Parameters[i].Type, (ISymbol)(object)args[i])) { return false; } } return true; } private static string Verdict(List<IMethodSymbol> candidates, int relaxed, INamedTypeSymbol asyncAttr) { if (candidates.Count == 0) { return null; } string text = null; foreach (IMethodSymbol candidate in candidates) { string text2 = Why(candidate, relaxed, asyncAttr); if (text2 == null) { return null; } if (text == null) { text = text2; } } return text; } private static string Why(IMethodSymbol m, int relaxed, INamedTypeSymbol asyncAttr) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) if ((relaxed & 1) == 0) { ImmutableArray<IParameterSymbol>.Enumerator enumerator = m.Parameters.GetEnumerator(); while (enumerator.MoveNext()) { IParameterSymbol current = enumerator.Current; if ((int)current.RefKind != 0 && !current.Type.IsValueType) { return "parameter '" + ((ISymbol)current).Name + "' is '" + Keyword(current.RefKind) + " " + ((ISymbol)current.Type).ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat) + "', and the IL2CPP trampoline returns default values for ref/out parameters of reference types"; } } } if ((relaxed & 2) == 0 && IsAsyncStub(m, asyncAttr)) { return "it is an async method stub whose real body runs in its state machine, so a patch fires at the first await or never"; } return null; } private static string Keyword(RefKind k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Invalid comparison between Unknown and I4 if ((int)k != 2) { if ((int)k != 3) { return "ref"; } return "in"; } return "out"; } private static bool IsAsyncStub(IMethodSymbol m, INamedTypeSymbol asyncAttr) { if (asyncAttr != null && ((ISymbol)m).GetAttributes().Any((AttributeData a) => Known.Same((ISymbol)(object)a.AttributeClass, (ISymbol)(object)asyncAttr))) { return true; } ImmutableArray<INamedTypeSymbol>.Enumerator enumerator = ((INamespaceOrTypeSymbol)((ISymbol)m).ContainingType).GetTypeMembers().GetEnumerator(); while (enumerator.MoveNext()) { INamedTypeSymbol current = enumerator.Current; if (((ISymbol)current).Name.StartsWith("_" + ((ISymbol)m).Name + "_d__", StringComparison.Ordinal) || ((ISymbol)current).Name.StartsWith("<" + ((ISymbol)m).Name + ">d__", StringComparison.Ordinal)) { bool num = ((INamespaceOrTypeSymbol)current).GetMembers("__2__current").Length > 0 || ((INamespaceOrTypeSymbol)current).GetMembers("<>2__current").Length > 0; bool flag = ((INamespaceOrTypeSymbol)current).GetMembers("__t__builder").Length > 0 || ((INamespaceOrTypeSymbol)current).GetMembers("<>t__builder").Length > 0; if (!num || flag) { return true; } } } return false; } } }
plugins/Revolution-Exclusive-sod-api/SodApi/SodApi.Net.Abstractions.dll
Decompiled a day agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Revolution")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("© 2026 Revolution")] [assembly: AssemblyDescription("Frozen network contract between SodApi and a co-op transport (SOD MP).")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("0.8.0+9941f93accb40382a30d004fc2f1cdb4984b4bd3")] [assembly: AssemblyProduct("SOD API")] [assembly: AssemblyTitle("SodApi.Net.Abstractions")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SodApi.Net.Abstractions { public enum NetRole : byte { Offline, Host, Client } public enum Delivery : byte { ReliableOrdered, ReliableUnordered, Sequenced, Unreliable } public enum Target : byte { Host, Others, All, Player } [Flags] public enum FrameFlags : byte { None = 0, Session = 1, Perishable = 2 } public readonly struct FrameInfo { public readonly ushort Sender; public readonly Delivery Delivery; public FrameInfo(ushort sender, Delivery delivery) { Sender = sender; Delivery = delivery; } } public delegate void FrameHandler(in FrameInfo info, ReadOnlySpan<byte> payload); public interface INetProvider { int ContractVersion { get; } string Name { get; } NetRole Role { get; } ushort LocalPlayerId { get; } bool IsConnected { get; } bool IsWorldLive { get; } IReadOnlyList<ushort> Players { get; } bool IsApplyingRemote { get; } ushort ApplyingSender { get; } event FrameHandler FrameReceived; event Action<NetRole> SessionStarted; event Action SessionEnded; event Action<ushort> PlayerJoined; event Action<ushort> PlayerWorldReady; event Action<ushort> PlayerLeft; string GetPlayerName(ushort player); object GetPlayerAvatar(ushort player); bool Send(ReadOnlySpan<byte> payload, Target to, ushort player, Delivery delivery, FrameFlags flags); IDisposable BeginApplyRemote(ushort sender); } public sealed class ModEntry { public string Id { get; set; } = ""; public string Name { get; set; } = ""; public string Version { get; set; } = ""; public byte Coop { get; set; } } public interface ICoopSession { IReadOnlyCollection<string> EnabledMods { get; } event Action EnabledModsChanged; event Action<string> RuleChanged; event Action<ushort, string, bool, int> CaseJudged; bool SetRule(string key, string value); string GetRule(string key); } public interface ICoopWorld { bool ReplicateSpawn(object interactable); bool ReplicateDestroy(int interactableId); bool ResyncSideJob(int jobId); bool PushTime(); int LocalIdOf(int hostId); int HostIdOf(int localId); } public interface ICoopPlayers { event Action BoardGroupsChanged; bool SetNameTagVisible(ushort player, bool visible); bool SetNameTagText(ushort player, string text, uint rgba); bool SetMapMarkerVisible(ushort player, bool visible); bool SetMapMarkerColor(ushort player, uint rgba); bool SetAvatarVisible(ushort player, bool visible); bool SendMessage(string text, ushort toPlayer); bool Kick(ushort player, string reason); int GetPing(ushort player); bool SetRoomTag(string text); bool SetBoardGroup(ushort player, int group); int GetBoardGroup(ushort player); string GetAccountId(ushort player) { return null; } } public static class ModCatalog { public static Func<IReadOnlyList<ModEntry>> Provider { get; set; } public static IReadOnlyList<ModEntry> Installed() { try { return Provider?.Invoke() ?? Array.Empty<ModEntry>(); } catch { return Array.Empty<ModEntry>(); } } } public static class NetProviders { private static INetProvider _current; public static INetProvider Current => _current; public static event Action<INetProvider> Changed; public static void Register(INetProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } _current = provider; NetProviders.Changed?.Invoke(provider); } public static void Unregister(INetProvider provider) { if (_current == provider) { _current = null; NetProviders.Changed?.Invoke(null); } } } }
plugins/CustomBuildings/CustomBuildings.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Text.Json.Nodes; using System.Text.Json.Serialization; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using CustomBuildings.Shared; using HarmonyLib; using Il2CppInterop.Runtime; using Il2CppInterop.Runtime.InteropTypes; using Il2CppInterop.Runtime.InteropTypes.Arrays; using Il2CppSystem; using Il2CppSystem.Collections.Generic; using Il2CppSystem.Reflection; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Experimental.Rendering; using UnityEngine.Rendering; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("CustomBuildings")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("CustomBuildings")] [assembly: AssemblyTitle("CustomBuildings")] [assembly: AssemblyVersion("1.1.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CustomBuildings { public static class Api { public const int ApiVersion = 1; public static bool RegisterWithGame(ScriptableObject preset) { //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Expected O, but got Unknown try { Toolbox instance = Toolbox.Instance; if ((Object)(object)instance == (Object)null || (Object)(object)preset == (Object)null) { return false; } instance.ProcessLoadedScriptableObject(preset); Plugin.Verbose($"[api] {((Object)preset).name} ({((MemberInfo)((Object)preset).GetIl2CppType()).Name}) registered with the game's preset cache"); return true; } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[api] RegisterWithGame: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } l.LogWarning(val); return false; } } public static bool IsCustomBuilding(BuildingPreset preset) { try { return (SoCustomComparison)(object)preset != (SoCustomComparison)null && ContentLoader.IsOurBuilding(((SoCustomComparison)preset).presetName); } catch { return false; } } public static string GetReservedPlace(NewAddress address) { try { return Places.ReservationFor(address, log: false)?.Place; } catch { return null; } } public static bool IsReservedFor(NewAddress address, string placeName) { string reservedPlace = GetReservedPlace(address); if (reservedPlace != null) { return string.Equals(reservedPlace, placeName, StringComparison.Ordinal); } return false; } public static string[] BuildingsReserving(string placeName) { try { return ContentLoader.Definitions.SelectMany((BuildingDef d) => from r in d.ReservedPlaces ?? new List<ReservedPlace>() where r.Place == placeName select $"{d.Id} / {r.Floor} / {r.Address}").ToArray(); } catch { return Array.Empty<string>(); } } } [HarmonyPatch(typeof(SessionData), "Update")] internal static class BorderProbe { private static int _frames; private static string _cityDone; private static bool InBorder(int x, int y) { if (x >= 3 && x <= 17 && y >= 3) { return y > 17; } return true; } private static void Postfix() { //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Expected O, but got Unknown //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) try { if (++_frames % 300 != 0) { return; } CityData instance = CityData.Instance; if ((Object)(object)instance == (Object)null || !PierBuilder.CityReady()) { return; } string text = instance.cityName + "|" + ((object)instance.citySize/*cast due to .constrained prefix*/).ToString(); if (!(text == _cityDone)) { List<NewAddress> list = (from o in (IEnumerable<Object>)Object.FindObjectsOfType(Il2CppType.Of<NewAddress>()) select (o == null) ? null : ((Il2CppObjectBase)o).TryCast<NewAddress>() into a where (Object)(object)a != (Object)null select a).ToList(); if (list.Count != 0) { _cityDone = text; Report(list); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(11, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[border] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.GetType().Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } l.LogWarning(val); } } private static Dictionary<(int, int), string> PlanBorder(string buildingId, string floorName) { Dictionary<(int, int), string> dictionary = new Dictionary<(int, int), string>(); string text = ContentLoader.DirOf(buildingId); if (text == null) { return dictionary; } string path = Path.Combine(text, "floors", floorName + ".json"); if (!File.Exists(path)) { return dictionary; } foreach (JsonNode item in JsonNode.Parse(File.ReadAllText(path))?["a_d"]?.AsArray() ?? new JsonArray()) { string text2 = (string?)item?["p_n"]; if (text2 == "Outside") { continue; } JsonArray jsonArray = item?["vs"]?.AsArray(); if (jsonArray == null || jsonArray.Count == 0) { continue; } foreach (JsonNode item2 in jsonArray[0]?["r_d"]?.AsArray() ?? new JsonArray()) { foreach (JsonNode item3 in item2?["n_d"]?.AsArray() ?? new JsonArray()) { int num = (int)Math.Round((double)item3["f_c"]["x"]); int num2 = (int)Math.Round((double)item3["f_c"]["y"]); if (InBorder(num, num2)) { dictionary[(num, num2)] = text2 + "/" + (string?)item2["l"]; } } } } return dictionary; } private static void Report(List<NewAddress> addresses) { //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder(); foreach (IGrouping<IntPtr, NewAddress> item in from a in addresses where (Object)(object)((NewGameLocation)a).floor != (Object)null group a by ((Il2CppObjectBase)((NewGameLocation)a).floor).Pointer) { NewFloor floor = ((NewGameLocation)item.First()).floor; NewBuilding building = floor.building; BuildingPreset val = ((building != null) ? building.preset : null); if ((SoCustomComparison)(object)val == (SoCustomComparison)null || !ContentLoader.IsOurBuilding(((SoCustomComparison)val).presetName)) { continue; } Dictionary<(int, int), string> dictionary = PlanBorder(((SoCustomComparison)val).presetName, floor.floorName); if (dictionary.Count == 0) { continue; } Dictionary<(int, int), string> dictionary2 = new Dictionary<(int, int), string>(); foreach (NewAddress item2 in item) { if (((NewGameLocation)item2).rooms == null) { continue; } Enumerator<NewRoom> enumerator3 = ((NewGameLocation)item2).rooms.GetEnumerator(); while (enumerator3.MoveNext()) { NewRoom current3 = enumerator3.Current; if (((current3 != null) ? current3.nodes : null) == null) { continue; } Enumerator<NewNode> enumerator4 = current3.nodes.GetEnumerator(); while (enumerator4.MoveNext()) { NewNode current4 = enumerator4.Current; if (current4 != null) { Vector2Int floorCoord = current4.floorCoord; int x = ((Vector2Int)(ref floorCoord)).x; floorCoord = current4.floorCoord; (int, int) tuple = (x, ((Vector2Int)(ref floorCoord)).y); if (dictionary.ContainsKey(tuple)) { string value = ((current4.tile == null) ? "no tile" : $"tile edge {current4.tile.isEdge} outside {current4.tile.isOutside}"); (int, int) key = tuple; DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(62, 7); LayoutConfiguration preset = item2.preset; defaultInterpolatedStringHandler.AppendFormatted((preset != null) ? ((Object)preset).name : null); defaultInterpolatedStringHandler.AppendLiteral("/"); RoomConfiguration preset2 = current3.preset; defaultInterpolatedStringHandler.AppendFormatted((preset2 != null) ? ((Object)preset2).name : null); defaultInterpolatedStringHandler.AppendLiteral(" (node outside "); defaultInterpolatedStringHandler.AppendFormatted(current4.isOutside); defaultInterpolatedStringHandler.AppendLiteral(", floor type "); defaultInterpolatedStringHandler.AppendFormatted<FloorTileType>(current4.floorType); defaultInterpolatedStringHandler.AppendLiteral(", floor built "); defaultInterpolatedStringHandler.AppendFormatted((Object)(object)current4.spawnedFloor != (Object)null); defaultInterpolatedStringHandler.AppendLiteral(", "); defaultInterpolatedStringHandler.AppendFormatted(value); defaultInterpolatedStringHandler.AppendLiteral(", room geometry "); defaultInterpolatedStringHandler.AppendFormatted(current3.geometryLoaded); defaultInterpolatedStringHandler.AppendLiteral(")"); dictionary2[key] = defaultInterpolatedStringHandler.ToStringAndClear(); } } } } } StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(69, 5, stringBuilder2); handler.AppendLiteral(" "); handler.AppendFormatted(((SoCustomComparison)val).presetName); handler.AppendLiteral(" storey "); handler.AppendFormatted(floor.floor); handler.AppendLiteral(" '"); handler.AppendFormatted(floor.floorName); handler.AppendLiteral("': "); handler.AppendFormatted(dictionary.Count); handler.AppendLiteral(" cell(s) of rooms in the border, the game has "); handler.AppendFormatted(dictionary2.Count); handler.AppendLiteral(" of them"); stringBuilder3.AppendLine(ref handler); foreach (KeyValuePair<(int, int), string> item3 in (from k in dictionary orderby k.Key.Item2, k.Key.Item1 select k).Take(12)) { stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(21, 4, stringBuilder2); handler.AppendLiteral(" ("); handler.AppendFormatted(item3.Key.Item1); handler.AppendLiteral(","); handler.AppendFormatted(item3.Key.Item2); handler.AppendLiteral(") plan "); handler.AppendFormatted(item3.Value); handler.AppendLiteral(" → game "); handler.AppendFormatted(dictionary2.TryGetValue(item3.Key, out var value2) ? value2 : "nothing there"); stringBuilder4.AppendLine(ref handler); } } if (stringBuilder.Length > 0) { Plugin.L.LogInfo((object)("[border] rooms in the border around buildings:\n" + stringBuilder.ToString().TrimEnd())); } } } internal static class BuildingNames { private static readonly HashSet<string> Logged = new HashSet<string>(); public static void Apply(string from) { //IL_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Expected O, but got Unknown bool flag = default(bool); try { if (Strings.stringTable == null) { return; } int num = 0; foreach (BuildingDef definition in ContentLoader.Definitions) { if (string.IsNullOrEmpty(definition.BasePreset) || string.IsNullOrEmpty(definition.Id)) { continue; } int num2 = AddTo(Strings.stringTable, definition) + AddTo(Strings.stringTableENG, definition); num += num2; if (num2 > 0 && Logged.Add(definition.Id + "|ok")) { ManualLogSource l = Plugin.L; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] Named "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(definition.Id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" \""); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(definition.GameName()); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\" ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" text entr"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((num2 == 1) ? "y" : "ies"); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")."); } l.LogInfo(val); } else if (num2 == 0 && !HasName(Strings.stringTable, definition) && Strings.textFilesLoaded && Logged.Add(definition.Id + "|none")) { Plugin.L.LogWarning((object)($"[{from}] Couldn't find a name entry for '{definition.BasePreset}' to copy, so {definition.Id} may show without a name. " + "Turn on VerboseLogging and send the log.")); } } if (num > 0) { Plugin.Verbose($"[{from}] Added {num} name entr{((num == 1) ? "y" : "ies")}."); } } catch (Exception ex) { if (Logged.Add("error")) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Couldn't add building names: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } l2.LogWarning(val2); } } } private static bool HasName(Dictionary<string, Dictionary<string, DisplayString>> table, BuildingDef def) { if (table == null) { return false; } Enumerator<string, Dictionary<string, DisplayString>> enumerator = table.GetEnumerator(); while (enumerator.MoveNext()) { Enumerator<string, DisplayString> enumerator2 = enumerator.Current.Value.GetEnumerator(); while (enumerator2.MoveNext()) { if (MatchKey(enumerator2.Current.Key, def.Id) != null) { return true; } } } return false; } private static int AddTo(Dictionary<string, Dictionary<string, DisplayString>> table, BuildingDef def) { //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown if (table == null) { return 0; } int num = 0; string text = def.GameName(); Enumerator<string, Dictionary<string, DisplayString>> enumerator = table.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, Dictionary<string, DisplayString>> current = enumerator.Current; Dictionary<string, DisplayString> value = current.Value; if (value == null) { continue; } List<string> list = new List<string>(); Enumerator<string, DisplayString> enumerator2 = value.GetEnumerator(); while (enumerator2.MoveNext()) { KeyValuePair<string, DisplayString> current2 = enumerator2.Current; string text2 = ((MatchKey(current2.Key, def.BasePreset) != null) ? Replace(current2.Key, def.BasePreset, def.Id) : null); if (text2 != null && !value.ContainsKey(text2)) { list.Add(text2); } } foreach (string item in list) { DisplayString val = new DisplayString { displayStr = text, alternateStr = text }; value[item] = val; num++; Plugin.Verbose($" name: [{current.Key}] {item} = {text}"); } } return num; } private static string MatchKey(string key, string preset) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(preset)) { return null; } int num = key.IndexOf(preset, StringComparison.OrdinalIgnoreCase); if (num < 0) { return null; } bool num2 = num == 0 || IsSep(key[num - 1]); int num3 = num + preset.Length; bool flag = num3 == key.Length || IsSep(key[num3]); if (!(num2 && flag)) { return null; } return key; } private static bool IsSep(char c) { if (c != '_' && c != '.' && c != '-') { return c == ' '; } return true; } private static string Replace(string key, string basePreset, string id) { int num = key.IndexOf(basePreset, StringComparison.OrdinalIgnoreCase); string text = key.Substring(num, basePreset.Length); string text2 = ((text == text.ToLowerInvariant()) ? id.ToLowerInvariant() : ((text == text.ToUpperInvariant()) ? id.ToUpperInvariant() : id)); return key.Substring(0, num) + text2 + key.Substring(num + basePreset.Length); } } [HarmonyPatch(typeof(SessionData), "Update")] internal static class CityEditor { private static bool _switched; private static bool _reported; private static int _frames; private static void Postfix() { //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_016b: Expected O, but got Unknown try { if (Plugin.CityEditorEnable == null || !Plugin.CityEditorEnable.Value) { return; } if (!_switched && (Object)(object)Game.Instance != (Object)null) { bool enableCityEditor = Game.Instance.enableCityEditor; Game.Instance.enableCityEditor = true; _switched = true; Plugin.Verbose($"[city editor] Game.enableCityEditor was {enableCityEditor}, now on."); } bool flag = Plugin.VerboseLogging != null && Plugin.VerboseLogging.Value; if (flag && !_reported && ++_frames > 120) { _reported = true; Report("start"); } bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305); bool flag2 = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303); if (num && flag2) { if (flag && Input.GetKeyDown((KeyCode)114)) { Report("Ctrl+Shift+R"); } if (Input.GetKeyDown((KeyCode)101)) { Open(); } if (Input.GetKeyDown((KeyCode)115)) { SetStreetKind("street"); } if (Input.GetKeyDown((KeyCode)97)) { SetStreetKind("alley"); } if (Input.GetKeyDown((KeyCode)98)) { SetStreetKind("backstreet"); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag3 = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(16, 2, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[city editor] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.GetType().Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message); } l.LogWarning(val); } } private static void SetStreetKind(string kind) { //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Expected O, but got Unknown //IL_0198: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown CityEditorStreetEdit val = ((IEnumerable<CityEditorStreetEdit>)All<CityEditorStreetEdit>()).FirstOrDefault((Func<CityEditorStreetEdit, bool>)((CityEditorStreetEdit e) => ((Behaviour)e).isActiveAndEnabled)); StreetController val2 = ((val != null) ? val.currentlySelectedStreet : null); bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val3; if ((Object)(object)val2 == (Object)null) { ManualLogSource l = Plugin.L; val3 = new BepInExInfoLogInterpolatedStringHandler(87, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[city editor] Ctrl+Shift+"); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<char>(char.ToUpper(kind[0])); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": open Street Edit in the city editor and pick a street first."); } l.LogInfo(val3); return; } SessionData instance = SessionData.Instance; if ((Object)(object)instance != (Object)null && instance.startedGame && !instance.isCityEdit) { return; } string text = (val2.isAlley ? "alley" : (val2.isBackstreet ? "backstreet" : "street")); if (!(kind == "alley")) { if (kind == "backstreet") { val2.SetAsBackstreet(); } else { val2.SetAsStreet(); } } else { val2.SetAsAlley(); } val2.isAlley = kind == "alley"; val2.isBackstreet = kind == "backstreet"; try { val2.Redecorate(); } catch (Exception ex) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(36, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[city editor] redecorating "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((Object)val2).name); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" failed: "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message); } l2.LogWarning(val4); } try { val.RepopulateStreetList(); val.SetSelectedStreet(val2); } catch { } ManualLogSource l3 = Plugin.L; val3 = new BepInExInfoLogInterpolatedStringHandler(42, 5, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[city editor] "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((Object)val2).name); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" → "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(kind); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" (alley "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(val2.isAlley); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", backstreet "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<bool>(val2.isBackstreet); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(")."); } l3.LogInfo(val3); } private static void Report(string when) { StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(24, 1, stringBuilder2); handler.AppendLiteral("[city editor] report ("); handler.AppendFormatted(when); handler.AppendLiteral("):"); stringBuilder3.AppendLine(ref handler); try { stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(38, 2, stringBuilder2); handler.AppendLiteral(" Game.enableCityEditor = "); Game instance = Game.Instance; handler.AppendFormatted((instance != null) ? new bool?(instance.enableCityEditor) : ((bool?)null)); handler.AppendLiteral(", devMode = "); Game instance2 = Game.Instance; handler.AppendFormatted((instance2 != null) ? new bool?(instance2.devMode) : ((bool?)null)); stringBuilder4.AppendLine(ref handler); } catch (Exception ex) { stringBuilder.AppendLine(" Game: " + ex.Message); } try { stringBuilder2 = stringBuilder; StringBuilder stringBuilder5 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(27, 1, stringBuilder2); handler.AppendLiteral(" SessionData.isCityEdit = "); SessionData instance3 = SessionData.Instance; handler.AppendFormatted((instance3 != null) ? new bool?(instance3.isCityEdit) : ((bool?)null)); stringBuilder5.AppendLine(ref handler); } catch (Exception ex2) { stringBuilder.AppendLine(" SessionData: " + ex2.Message); } try { if ((Object)(object)CityConstructor.Instance != (Object)null) { stringBuilder2 = stringBuilder; StringBuilder stringBuilder6 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(40, 1, stringBuilder2); handler.AppendLiteral(" CityConstructor.IsUsingCityEditor() = "); handler.AppendFormatted(CityConstructor.Instance.IsUsingCityEditor()); stringBuilder6.AppendLine(ref handler); } } catch (Exception ex3) { stringBuilder.AppendLine(" CityConstructor: " + ex3.Message); } Parts<PrototypeDebugPanel>(stringBuilder); Parts<CityEditorController>(stringBuilder); Parts<CityEditorBuildingEdit>(stringBuilder); Parts<CityEditorStreetEdit>(stringBuilder); Parts<CityEditorInputController>(stringBuilder); Parts<CityEditorStreetsEditListElement>(stringBuilder); CityEditorBuildingEdit[] array = All<CityEditorBuildingEdit>(); foreach (CityEditorBuildingEdit obj in array) { try { object obj2 = typeof(CityEditorBuildingEdit).GetProperty("buildingPresets")?.GetValue(obj); List<string> list = new List<string>(); if (obj2 != null) { int num = (int)(obj2.GetType().GetProperty("Count")?.GetValue(obj2) ?? ((object)0)); PropertyInfo property = obj2.GetType().GetProperty("Item"); for (int j = 0; j < num; j++) { if (!(property != null)) { break; } object? value = property.GetValue(obj2, new object[1] { j }); object? obj3 = ((value is Object) ? value : null); list.Add(((obj3 != null) ? ((Object)obj3).name : null) ?? "?"); } } List<string> list2 = list.Where((string n) => ContentLoader.Buildings.ContainsKey(n)).ToList(); stringBuilder2 = stringBuilder; StringBuilder stringBuilder7 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(48, 2, stringBuilder2); handler.AppendLiteral(" building types in the editor's list: "); handler.AppendFormatted(list.Count); handler.AppendLiteral(" (ours: "); handler.AppendFormatted((list2.Count == 0) ? "none" : string.Join(", ", list2)); handler.AppendLiteral(")"); stringBuilder7.AppendLine(ref handler); } catch (Exception ex4) { stringBuilder.AppendLine(" building list: " + ex4.Message); } } Plugin.L.LogInfo((object)stringBuilder.ToString().TrimEnd()); } private static void Open() { //IL_017d: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[city editor] Ctrl+Shift+E, opening:\n"); try { SessionData instance = SessionData.Instance; if ((Object)(object)instance != (Object)null && instance.startedGame && !instance.isCityEdit) { Plugin.L.LogInfo((object)"[city editor] Ctrl+Shift+E: not in a city you're playing in. Open it in the main menu, then generate a new city."); return; } PrototypeDebugPanel[] array = All<PrototypeDebugPanel>(); foreach (PrototypeDebugPanel val in array) { Transform val2 = ((Component)val).transform; while ((Object)(object)val2 != (Object)null) { if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2); handler.AppendLiteral(" switched on "); handler.AppendFormatted(Path(val2)); stringBuilder3.AppendLine(ref handler); } val2 = val2.parent; } ((Behaviour)val).enabled = true; } CityEditorController[] array2 = All<CityEditorController>(); foreach (CityEditorController val3 in array2) { StringBuilder stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler; if (!((Component)val3).gameObject.activeSelf) { ((Component)val3).gameObject.SetActive(true); stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2); handler.AppendLiteral(" switched on "); handler.AppendFormatted(Path(((Component)val3).transform)); stringBuilder4.AppendLine(ref handler); } val3.SetCityEditor(true); stringBuilder2 = stringBuilder; StringBuilder stringBuilder5 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(49, 3, stringBuilder2); handler.AppendLiteral(" SetCityEditor(true) on "); handler.AppendFormatted(Path(((Component)val3).transform)); handler.AppendLiteral(": mode "); handler.AppendFormatted<CityEditorMode>(val3.currentMode); handler.AppendLiteral(", data generated "); handler.AppendFormatted(val3.dataGenerated); stringBuilder5.AppendLine(ref handler); } } catch (Exception value) { StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder6 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(10, 1, stringBuilder2); handler.AppendLiteral(" failed: "); handler.AppendFormatted(value); stringBuilder6.AppendLine(ref handler); } Plugin.L.LogInfo((object)stringBuilder.ToString().TrimEnd()); } private static void Parts<T>(StringBuilder sb) where T : Component { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) T[] array = All<T>(); if (array.Length == 0) { StringBuilder stringBuilder = sb; StringBuilder stringBuilder2 = stringBuilder; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(13, 1, stringBuilder); handler.AppendLiteral(" "); handler.AppendFormatted(typeof(T).Name); handler.AppendLiteral(": not found"); stringBuilder2.AppendLine(ref handler); return; } T[] array2 = array; foreach (T val in array2) { Scene scene = ((Component)val).gameObject.scene; bool flag = ((Scene)(ref scene)).IsValid(); StringBuilder stringBuilder = sb; StringBuilder stringBuilder3 = stringBuilder; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(9, 5, stringBuilder); handler.AppendLiteral(" "); handler.AppendFormatted(typeof(T).Name); handler.AppendLiteral(": "); handler.AppendFormatted(Path(((Component)val).transform)); handler.AppendLiteral(" ("); object value; if (!flag) { value = "prefab/asset"; } else { scene = ((Component)val).gameObject.scene; value = "in scene " + ((Scene)(ref scene)).name; } handler.AppendFormatted((string?)value); handler.AppendLiteral(", "); handler.AppendFormatted(((Component)val).gameObject.activeInHierarchy ? "active" : "inactive"); object obj = val; Behaviour val2 = (Behaviour)((obj is Behaviour) ? obj : null); handler.AppendFormatted((val2 != null && !val2.enabled) ? ", disabled" : ""); handler.AppendLiteral(")"); stringBuilder3.AppendLine(ref handler); } } private static T[] All<T>() where T : Object { return (from o in (IEnumerable<Object>)Resources.FindObjectsOfTypeAll(Il2CppType.Of<T>()) select (o == null) ? default(T) : ((Il2CppObjectBase)o).TryCast<T>() into t where (Object)(object)t != (Object)null select t).ToArray(); } private static string Path(Transform t) { string text = ((Object)t).name; Transform parent = t.parent; while ((Object)(object)parent != (Object)null) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } return text; } } [HarmonyPatch(typeof(SessionData), "Update")] internal static class CityEditorProbe { private static bool _switched; private static bool _reported; private static int _frames; private static void Postfix() { //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown bool flag = default(bool); try { if (Plugin.CityEditorEnable == null || !Plugin.CityEditorEnable.Value) { return; } if (!_switched && (Object)(object)Game.Instance != (Object)null) { bool enableCityEditor = Game.Instance.enableCityEditor; Game.Instance.enableCityEditor = true; _switched = true; ManualLogSource l = Plugin.L; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(49, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[city editor] Game.enableCityEditor was "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(enableCityEditor); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", now on."); } l.LogInfo(val); } if (!_reported && ++_frames > 120) { _reported = true; Report("start"); } bool num = Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305); bool flag2 = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303); if (num && flag2) { if (Input.GetKeyDown((KeyCode)114)) { Report("Ctrl+Shift+R"); } if (Input.GetKeyDown((KeyCode)101)) { Open(); } } } catch (Exception ex) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(16, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[city editor] "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.GetType().Name); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } l2.LogWarning(val2); } } private static void Report(string when) { StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(24, 1, stringBuilder2); handler.AppendLiteral("[city editor] report ("); handler.AppendFormatted(when); handler.AppendLiteral("):"); stringBuilder3.AppendLine(ref handler); try { stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(38, 2, stringBuilder2); handler.AppendLiteral(" Game.enableCityEditor = "); Game instance = Game.Instance; handler.AppendFormatted((instance != null) ? new bool?(instance.enableCityEditor) : ((bool?)null)); handler.AppendLiteral(", devMode = "); Game instance2 = Game.Instance; handler.AppendFormatted((instance2 != null) ? new bool?(instance2.devMode) : ((bool?)null)); stringBuilder4.AppendLine(ref handler); } catch (Exception ex) { stringBuilder.AppendLine(" Game: " + ex.Message); } try { stringBuilder2 = stringBuilder; StringBuilder stringBuilder5 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(27, 1, stringBuilder2); handler.AppendLiteral(" SessionData.isCityEdit = "); SessionData instance3 = SessionData.Instance; handler.AppendFormatted((instance3 != null) ? new bool?(instance3.isCityEdit) : ((bool?)null)); stringBuilder5.AppendLine(ref handler); } catch (Exception ex2) { stringBuilder.AppendLine(" SessionData: " + ex2.Message); } try { if ((Object)(object)CityConstructor.Instance != (Object)null) { stringBuilder2 = stringBuilder; StringBuilder stringBuilder6 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(40, 1, stringBuilder2); handler.AppendLiteral(" CityConstructor.IsUsingCityEditor() = "); handler.AppendFormatted(CityConstructor.Instance.IsUsingCityEditor()); stringBuilder6.AppendLine(ref handler); } } catch (Exception ex3) { stringBuilder.AppendLine(" CityConstructor: " + ex3.Message); } Parts<PrototypeDebugPanel>(stringBuilder); Parts<CityEditorController>(stringBuilder); Parts<CityEditorBuildingEdit>(stringBuilder); Parts<CityEditorStreetEdit>(stringBuilder); Parts<CityEditorInputController>(stringBuilder); Parts<CityEditorStreetsEditListElement>(stringBuilder); CityEditorBuildingEdit[] array = All<CityEditorBuildingEdit>(); foreach (CityEditorBuildingEdit obj in array) { try { object obj2 = typeof(CityEditorBuildingEdit).GetProperty("buildingPresets")?.GetValue(obj); List<string> list = new List<string>(); if (obj2 != null) { int num = (int)(obj2.GetType().GetProperty("Count")?.GetValue(obj2) ?? ((object)0)); PropertyInfo property = obj2.GetType().GetProperty("Item"); for (int j = 0; j < num; j++) { if (!(property != null)) { break; } object? value = property.GetValue(obj2, new object[1] { j }); object? obj3 = ((value is Object) ? value : null); list.Add(((obj3 != null) ? ((Object)obj3).name : null) ?? "?"); } } List<string> list2 = list.Where((string n) => ContentLoader.Buildings.ContainsKey(n)).ToList(); stringBuilder2 = stringBuilder; StringBuilder stringBuilder7 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(48, 2, stringBuilder2); handler.AppendLiteral(" building types in the editor's list: "); handler.AppendFormatted(list.Count); handler.AppendLiteral(" (ours: "); handler.AppendFormatted((list2.Count == 0) ? "none" : string.Join(", ", list2)); handler.AppendLiteral(")"); stringBuilder7.AppendLine(ref handler); } catch (Exception ex4) { stringBuilder.AppendLine(" building list: " + ex4.Message); } } Plugin.L.LogInfo((object)stringBuilder.ToString().TrimEnd()); } private static void Open() { //IL_017d: Unknown result type (might be due to invalid IL or missing references) StringBuilder stringBuilder = new StringBuilder("[city editor] Ctrl+Shift+E, opening:\n"); try { SessionData instance = SessionData.Instance; if ((Object)(object)instance != (Object)null && instance.startedGame && !instance.isCityEdit) { Plugin.L.LogInfo((object)"[city editor] Ctrl+Shift+E: not in a city you're playing in. Open it in the main menu, then generate a new city."); return; } PrototypeDebugPanel[] array = All<PrototypeDebugPanel>(); foreach (PrototypeDebugPanel val in array) { Transform val2 = ((Component)val).transform; while ((Object)(object)val2 != (Object)null) { if (!((Component)val2).gameObject.activeSelf) { ((Component)val2).gameObject.SetActive(true); StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder3 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2); handler.AppendLiteral(" switched on "); handler.AppendFormatted(Path(val2)); stringBuilder3.AppendLine(ref handler); } val2 = val2.parent; } ((Behaviour)val).enabled = true; } CityEditorController[] array2 = All<CityEditorController>(); foreach (CityEditorController val3 in array2) { StringBuilder stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler; if (!((Component)val3).gameObject.activeSelf) { ((Component)val3).gameObject.SetActive(true); stringBuilder2 = stringBuilder; StringBuilder stringBuilder4 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(14, 1, stringBuilder2); handler.AppendLiteral(" switched on "); handler.AppendFormatted(Path(((Component)val3).transform)); stringBuilder4.AppendLine(ref handler); } val3.SetCityEditor(true); stringBuilder2 = stringBuilder; StringBuilder stringBuilder5 = stringBuilder2; handler = new StringBuilder.AppendInterpolatedStringHandler(49, 3, stringBuilder2); handler.AppendLiteral(" SetCityEditor(true) on "); handler.AppendFormatted(Path(((Component)val3).transform)); handler.AppendLiteral(": mode "); handler.AppendFormatted<CityEditorMode>(val3.currentMode); handler.AppendLiteral(", data generated "); handler.AppendFormatted(val3.dataGenerated); stringBuilder5.AppendLine(ref handler); } } catch (Exception value) { StringBuilder stringBuilder2 = stringBuilder; StringBuilder stringBuilder6 = stringBuilder2; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(10, 1, stringBuilder2); handler.AppendLiteral(" failed: "); handler.AppendFormatted(value); stringBuilder6.AppendLine(ref handler); } Plugin.L.LogInfo((object)stringBuilder.ToString().TrimEnd()); } private static void Parts<T>(StringBuilder sb) where T : Component { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) T[] array = All<T>(); if (array.Length == 0) { StringBuilder stringBuilder = sb; StringBuilder stringBuilder2 = stringBuilder; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(13, 1, stringBuilder); handler.AppendLiteral(" "); handler.AppendFormatted(typeof(T).Name); handler.AppendLiteral(": not found"); stringBuilder2.AppendLine(ref handler); return; } T[] array2 = array; foreach (T val in array2) { Scene scene = ((Component)val).gameObject.scene; bool flag = ((Scene)(ref scene)).IsValid(); StringBuilder stringBuilder = sb; StringBuilder stringBuilder3 = stringBuilder; StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(9, 5, stringBuilder); handler.AppendLiteral(" "); handler.AppendFormatted(typeof(T).Name); handler.AppendLiteral(": "); handler.AppendFormatted(Path(((Component)val).transform)); handler.AppendLiteral(" ("); object value; if (!flag) { value = "prefab/asset"; } else { scene = ((Component)val).gameObject.scene; value = "in scene " + ((Scene)(ref scene)).name; } handler.AppendFormatted((string?)value); handler.AppendLiteral(", "); handler.AppendFormatted(((Component)val).gameObject.activeInHierarchy ? "active" : "inactive"); object obj = val; Behaviour val2 = (Behaviour)((obj is Behaviour) ? obj : null); handler.AppendFormatted((val2 != null && !val2.enabled) ? ", disabled" : ""); handler.AppendLiteral(")"); stringBuilder3.AppendLine(ref handler); } } private static T[] All<T>() where T : Object { return (from o in (IEnumerable<Object>)Resources.FindObjectsOfTypeAll(Il2CppType.Of<T>()) select (o == null) ? default(T) : ((Il2CppObjectBase)o).TryCast<T>() into t where (Object)(object)t != (Object)null select t).ToArray(); } private static string Path(Transform t) { string text = ((Object)t).name; Transform parent = t.parent; while ((Object)(object)parent != (Object)null) { text = ((Object)parent).name + "/" + text; parent = parent.parent; } return text; } } internal static class ContentLoader { private class FloorFile { public string Name; public string Json; public string Source; } private static readonly List<BuildingDef> Defs = new List<BuildingDef>(); private static readonly Dictionary<string, string> DefDirs = new Dictionary<string, string>(StringComparer.Ordinal); private static readonly SortedDictionary<string, FloorFile> Floors = new SortedDictionary<string, FloorFile>(StringComparer.Ordinal); internal static readonly Dictionary<string, TextAsset> FloorAssets = new Dictionary<string, TextAsset>(StringComparer.Ordinal); internal static readonly Dictionary<string, BuildingPreset> Buildings = new Dictionary<string, BuildingPreset>(StringComparer.Ordinal); internal static readonly Dictionary<string, BuildingPreset> BaseOf = new Dictionary<string, BuildingPreset>(StringComparer.Ordinal); private static readonly HashSet<string> WarnedMissingBase = new HashSet<string>(); public static bool FloorDataParsed; private static readonly HashSet<string> CacheLogged = new HashSet<string>(StringComparer.Ordinal); internal static IReadOnlyList<BuildingDef> Definitions => Defs; public static string ContentHash { get; private set; } = ""; internal static string DirOf(string id) { if (!DefDirs.TryGetValue(id, out var value)) { return null; } return value; } internal static BuildingPreset FindOurPreset(string id) { if (!Buildings.TryGetValue(id, out var value) || !((SoCustomComparison)(object)value != (SoCustomComparison)null) || ((Il2CppObjectBase)value).WasCollected) { return null; } return value; } public static bool IsOurFloor(string name) { if (name != null) { return Floors.ContainsKey(name); } return false; } public static bool IsOurBuilding(string name) { if (name != null) { return Defs.Any((BuildingDef d) => d.Id == name); } return false; } public static void ReadFiles() { //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Expected O, but got Unknown //IL_02d2: Unknown result type (might be due to invalid IL or missing references) //IL_02d9: Expected O, but got Unknown //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014e: Expected O, but got Unknown //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019d: Expected O, but got Unknown //IL_047e: Unknown result type (might be due to invalid IL or missing references) //IL_0484: Expected O, but got Unknown //IL_04f6: Unknown result type (might be due to invalid IL or missing references) //IL_04fd: Expected O, but got Unknown Defs.Clear(); DefDirs.Clear(); Floors.Clear(); string text = Path.Combine(Plugin.ModDir, "Buildings"); bool flag = default(bool); foreach (string item in EdgeStore.Migrate(Plugin.ModDir)) { ManualLogSource l = Plugin.L; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(7, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[edge] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item); } l.LogInfo(val); } foreach (string item2 in Directory.GetDirectories(text).OrderBy<string, string>((string d) => d, StringComparer.Ordinal)) { string text2 = Path.Combine(item2, "building.json"); if (File.Exists(text2)) { try { byte[] bytes = File.ReadAllBytes(text2); BuildingDef def = JsonSerializer.Deserialize<BuildingDef>(Encoding.UTF8.GetString(bytes).TrimStart('\ufeff'), Json.Options); if (def == null || string.IsNullOrWhiteSpace(def.Id)) { ManualLogSource l2 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text2); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": missing Id, skipped."); } l2.LogError(val2); } else if (Defs.Any((BuildingDef d) => d.Id == def.Id)) { ManualLogSource l3 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(31, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text2); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": Id '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' is used twice, skipped."); } l3.LogError(val2); } else { Defs.Add(def); DefDirs[def.Id] = item2; } } catch (Exception ex) { ManualLogSource l4 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(2, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text2); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message); } l4.LogError(val2); } } string path = Path.Combine(item2, "floors"); if (!Directory.Exists(path)) { continue; } foreach (string item3 in Directory.GetFiles(path, "*.json").OrderBy<string, string>((string f) => f, StringComparer.Ordinal)) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item3); if (Floors.TryGetValue(fileNameWithoutExtension, out var value)) { ManualLogSource l5 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(85, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Floor '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(fileNameWithoutExtension); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' exists twice ("); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(value.Source); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" and "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item3); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("). Floor names must be unique; the second one is skipped."); } l5.LogError(val2); continue; } try { byte[] bytes2 = File.ReadAllBytes(item3); string json = FixFloorName(Encoding.UTF8.GetString(bytes2).TrimStart('\ufeff'), fileNameWithoutExtension, item3); Floors[fileNameWithoutExtension] = new FloorFile { Name = fileNameWithoutExtension, Json = json, Source = item3 }; } catch (Exception ex2) { ManualLogSource l6 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(2, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item3); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message); } l6.LogError(val2); } } } foreach (var item4 in EdgeStore.LoadPieces(EdgeStore.Root(Plugin.ModDir), delegate(string err) { Plugin.L.LogError((object)("[edge] " + err)); })) { var (piece, value2) = item4; if (!piece.Enabled) { ManualLogSource l7 = Plugin.L; BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[edge] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(piece.Id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is switched off"); } l7.LogInfo(val); } else if (GameEdgePieces.All.Contains(piece.Id) || Defs.Any((BuildingDef d) => d.Id == piece.Id)) { ManualLogSource l8 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(70, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[edge] "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(piece.Id); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": that Id is already used (by the game or a building); skipped."); } l8.LogError(val2); } else { BuildingDef buildingDef = piece.ToBuildingDef(); Defs.Add(buildingDef); DefDirs[buildingDef.Id] = value2; } } Defs.Sort((BuildingDef a, BuildingDef b) => string.CompareOrdinal(a.Id, b.Id)); CustomPlaceMaker.ReadFiles(); StreetModels.ReadFiles(); StreetPropsApply.ReadFile(); PropModels.ReadFiles(); ContentHash = CustomBuildings.Shared.ContentHash.Compute(text); Plugin.L.LogInfo((object)($"Read {Defs.Count} building(s) and {Floors.Count} floor(s). Content hash {ContentHash} " + "(every player in a multiplayer game must show the same hash).")); } private static string FixFloorName(string json, string name, string file) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Expected O, but got Unknown if (!(JsonNode.Parse(json) is JsonObject jsonObject)) { throw new Exception("not a JSON object"); } string text = jsonObject["floorName"]?.GetValue<string>(); bool flag = false; bool flag2 = default(bool); if (text != name) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 3, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(file); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": floorName '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' does not match the file name; using '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'."); } l.LogWarning(val); jsonObject["floorName"] = name; flag = true; } List<string> list = FloorCheck.Repair(jsonObject); if (list.Count > 0) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(52, 2, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(file); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join("; ", list)); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (open and save it in the editor to fix the file)."); } l2.LogWarning(val); flag = true; } if (!flag) { return json; } return jsonObject.ToJsonString(); } public static void RegisterAll(string from) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown try { RegisterFloors(from); RegisterBuildings(from); CustomPlaceMaker.Make(from); StreetModels.Register(from); PropModels.Register(from); StreetPropsApply.Apply(from); BuildingNames.Apply(from); FrontageFix.Apply(from); } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(40, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Registering custom buildings ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex); } l.LogError(val); } } public static void RegisterFloors(string from) { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Expected O, but got Unknown AssetLoader instance = AssetLoader.Instance; CityData instance2 = CityData.Instance; bool flag3 = default(bool); foreach (FloorFile value2 in Floors.Values) { if (!FloorAssets.TryGetValue(value2.Name, out var value) || (Object)(object)value == (Object)null || ((Il2CppObjectBase)value).WasCollected) { value = new TextAsset(value2.Json); ((Object)value).name = value2.Name; ((Object)value).hideFlags = (HideFlags)32; FloorAssets[value2.Name] = value; } if (instance != null && instance.allFloorData != null) { bool flag = false; bool flag2 = false; Enumerator<TextAsset> enumerator2 = instance.allFloorData.GetEnumerator(); while (enumerator2.MoveNext()) { TextAsset current2 = enumerator2.Current; if (!((Object)(object)current2 == (Object)null) && !(((Object)current2).name != value2.Name)) { if (((Il2CppObjectBase)current2).Pointer == ((Il2CppObjectBase)value).Pointer) { flag = true; } else { flag2 = true; } } } if (flag2) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(74, 1, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Floor '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value2.Name); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' already exists in the game; rename yours (use a prefix like cb_)."); } l.LogWarning(val); } else if (!flag) { instance.allFloorData.Add(value); Plugin.Verbose($"[{from}] floor asset {value2.Name} added"); } } if (!FloorDataParsed || !((Object)(object)instance2 != (Object)null) || instance2.floorData == null || instance2.floorData.ContainsKey(value2.Name)) { continue; } Object obj = JsonUtility.FromJson(value2.Json, Il2CppType.Of<FloorSaveData>()); FloorSaveData val2 = ((obj != null) ? ((Il2CppObjectBase)obj).TryCast<FloorSaveData>() : null); if (val2 == null) { ManualLogSource l2 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(71, 1, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Floor '"); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(value2.Name); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' could not be parsed by the game. Check the file in the editor."); } l2.LogError(val3); } else { val2.floorName = value2.Name; instance2.floorData.Add(value2.Name, val2); Plugin.Verbose($"[{from}] floor data {value2.Name} added"); } } } public static void RegisterBuildings(string from) { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Expected O, but got Unknown //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_0376: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Expected O, but got Unknown AssetLoader instance = AssetLoader.Instance; if (instance == null || instance.allBuildingData == null) { return; } bool flag = default(bool); foreach (BuildingDef def in Defs) { if (Buildings.TryGetValue(def.Id, out var value) && (SoCustomComparison)(object)value != (SoCustomComparison)null && !((Il2CppObjectBase)value).WasCollected) { EnsureInList(instance, value); EnsureCached(value, from); continue; } BuildingPreset val = FindVanillaPreset(def.BasePreset); if ((SoCustomComparison)(object)val == (SoCustomComparison)null) { if (WarnedMissingBase.Add(def.Id)) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(48, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("] "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": base building '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(def.BasePreset); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' not found yet; will retry."); } l.LogWarning(val2); } continue; } BuildingPreset val3 = ((Il2CppObjectBase)Object.Instantiate<BuildingPreset>(val)).Cast<BuildingPreset>(); ((Object)val3).name = def.Id; ((SoCustomComparison)val3).presetName = def.Id; ((Object)val3).hideFlags = (HideFlags)32; BepInExInfoLogInterpolatedStringHandler val5; if (def.ReplaceFloorLayouts && def.FloorLayouts.Count > 0) { val3.floorLayouts = BuildLayouts(def, def.FloorLayouts, val3.floorLayouts, "floor"); Vector2 controlRoomRange = val3.controlRoomRange; Vector2 val4 = controlRoomRange; val4 = default(Vector2); if (!((Vector2)(ref controlRoomRange)).Equals(val4)) { ManualLogSource l2 = Plugin.L; val5 = new BepInExInfoLogInterpolatedStringHandler(77, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": no control room (the base building has one on storeys "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<Vector2>(controlRoomRange); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(", in its own floors)."); } l2.LogInfo(val5); val3.controlRoomRange = val4; } } if (def.ReplaceBasementLayouts) { val3.basementLayouts = BuildLayouts(def, def.BasementLayouts, val3.basementLayouts, "basement"); } ApplyOverrides(val3, def.Overrides); string value2; bool flag2 = DefDirs.TryGetValue(def.Id, out value2) && ExteriorLoader.Apply(val3, val, def, value2); Buildings[def.Id] = val3; BaseOf[def.Id] = val; EnsureInList(instance, val3); EnsureCached(val3, from); Places.ShareLimits(val, val3); int num = 0; int num2 = 0; Enumerator<InteriorFloorSetting> enumerator2 = val3.floorLayouts.GetEnumerator(); while (enumerator2.MoveNext()) { InteriorFloorSetting current2 = enumerator2.Current; num += current2.floorsWithThisSetting; } enumerator2 = val.floorLayouts.GetEnumerator(); while (enumerator2.MoveNext()) { InteriorFloorSetting current3 = enumerator2.Current; num2 += current3.floorsWithThisSetting; } if (!flag2 && num != num2) { Plugin.L.LogWarning((object)($"{def.Id}: layouts cover {num} storey(s) but '{def.BasePreset}' uses {num2}. " + "Windows and floors may not line up.")); } ManualLogSource l3 = Plugin.L; val5 = new BepInExInfoLogInterpolatedStringHandler(36, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("] Registered building "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" (based on "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(def.BasePreset); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(")."); } l3.LogInfo(val5); if (def.Edge != null) { EdgePieces.OnRegistered(def, val3, val); } } } internal static void EnsureCached(BuildingPreset preset, string from) { //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Expected O, but got Unknown //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Expected O, but got Unknown Toolbox instance = Toolbox.Instance; if ((Object)(object)instance == (Object)null || (SoCustomComparison)(object)preset == (SoCustomComparison)null) { return; } string text = "?"; bool flag3 = default(bool); try { BuildingPreset val = Find(instance, ((SoCustomComparison)preset).presetName); if (val != null && ((Il2CppObjectBase)val).Pointer == ((Il2CppObjectBase)preset).Pointer) { return; } bool flag = false; try { flag = instance.TryReplaceInResourcesCache((ScriptableObject)(object)preset); } catch (Exception ex) { text = "replace failed: " + ex.Message; } BuildingPreset val2 = Find(instance, ((SoCustomComparison)preset).presetName); if (val2 == null || !(((Il2CppObjectBase)val2).Pointer == ((Il2CppObjectBase)preset).Pointer)) { instance.ProcessLoadedScriptableObject((ScriptableObject)(object)preset); text = (flag ? "replaced, then added" : "added"); } else { text = "replaced"; } BuildingPreset val3 = Find(instance, ((SoCustomComparison)preset).presetName); bool flag2 = val3 != null && ((Il2CppObjectBase)val3).Pointer == ((Il2CppObjectBase)preset).Pointer; if (CacheLogged.Add(((SoCustomComparison)preset).presetName + text)) { ManualLogSource l = Plugin.L; BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(39, 4, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("] "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(((SoCustomComparison)preset).presetName); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": put in the game's preset cache ("); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(")"); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(flag2 ? "" : " – but the game still can't find it by name"); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("."); } l.LogInfo(val4); } } catch (Exception ex2) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val5 = new BepInExWarningLogInterpolatedStringHandler(54, 5, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("["); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("] "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(((SoCustomComparison)preset).presetName); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": couldn't put it in the game's preset cache ("); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("): "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex2.GetType().Name); ((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(ex2.Message); } l2.LogWarning(val5); } } internal static BuildingPreset Find(Toolbox tb, string name) { try { BuildingPreset val = default(BuildingPreset); return tb.LoadDataFromResources<BuildingPreset>(name, ref val) ? val : null; } catch { return null; } } internal static void EnsureAllCached(string from) { foreach (BuildingPreset value in Buildings.Values) { if ((SoCustomComparison)(object)value != (SoCustomComparison)null && !((Il2CppObjectBase)value).WasCollected) { EnsureCached(value, from); } } } private static void EnsureInList(AssetLoader loader, BuildingPreset preset) { BuildingPreset val = null; Enumerator<BuildingPreset> enumerator = loader.allBuildingData.GetEnumerator(); while (enumerator.MoveNext()) { BuildingPreset current = enumerator.Current; if (!((SoCustomComparison)(object)current == (SoCustomComparison)null) && !(((SoCustomComparison)current).presetName != ((SoCustomComparison)preset).presetName)) { if (((Il2CppObjectBase)current).Pointer == ((Il2CppObjectBase)preset).Pointer) { return; } val = current; } } if ((SoCustomComparison)(object)val != (SoCustomComparison)null) { loader.allBuildingData.Remove(val); } loader.allBuildingData.Add(preset); } private static BuildingPreset FindVanillaPreset(string name) { if (string.IsNullOrEmpty(name)) { return null; } AssetLoader instance = AssetLoader.Instance; if (instance != null && instance.allBuildingData != null) { Enumerator<BuildingPreset> enumerator = instance.allBuildingData.GetEnumerator(); while (enumerator.MoveNext()) { BuildingPreset current = enumerator.Current; if ((SoCustomComparison)(object)current != (SoCustomComparison)null && (((SoCustomComparison)current).presetName == name || ((Object)current).name == name) && !IsOurBuilding(((SoCustomComparison)current).presetName)) { return current; } } } foreach (Object item in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.Of<BuildingPreset>())) { BuildingPreset val = ((item != null) ? ((Il2CppObjectBase)item).TryCast<BuildingPreset>() : null); if ((SoCustomComparison)(object)val != (SoCustomComparison)null && (((SoCustomComparison)val).presetName == name || ((Object)val).name == name) && !IsOurBuilding(((SoCustomComparison)val).presetName)) { return val; } } return null; } private static List<InteriorFloorSetting> BuildLayouts(BuildingDef def, List<FloorLayoutDef> defs, List<InteriorFloorSetting> templates, string what) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Expected O, but got Unknown //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Expected O, but got Unknown //IL_02a6: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Expected O, but got Unknown List<InteriorFloorSetting> list = new List<InteriorFloorSetting>(); if (templates != null) { Enumerator<InteriorFloorSetting> enumerator = templates.GetEnumerator(); while (enumerator.MoveNext()) { InteriorFloorSetting current = enumerator.Current; list.Add(current); } } List<InteriorFloorSetting> val = new List<InteriorFloorSetting>(); bool flag = default(bool); for (int i = 0; i < defs.Count; i++) { FloorLayoutDef floorLayoutDef = defs[i]; InteriorFloorSetting val2 = ((list.Count == 0) ? null : list[Math.Min(i, list.Count - 1)]); InteriorFloorSetting val3 = new InteriorFloorSetting(); if (val2 != null) { val3.airVentMaximumExtrusion = val2.airVentMaximumExtrusion; val3.controlRoomVariants = new List<TextAsset>(); if (val2.controlRoomVariants != null && val2.controlRoomVariants.Count > 0) { ManualLogSource l = Plugin.L; BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(106, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(what); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" layout "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(i + 1); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(": left out "); ((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val2.controlRoomVariants.Count); ((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" control room variant(s) of the base building (its own floors, they don't fit yours)."); } l.LogInfo(val4); } val3.forceShowModel = val2.forceShowModel; val3.forceHideModels = val2.forceHideModels; val3.forceHideModelsInRooms = val2.forceHideModelsInRooms; val3.forceHideModelsOutside = val2.forceHideModelsOutside; val3.overrideCeilingHeight = val2.overrideCeilingHeight; val3.newCeilingHeight = val2.newCeilingHeight; } else { val3.controlRoomVariants = new List<TextAsset>(); val3.forceHideModels = new List<string>(); val3.forceHideModelsOutside = new List<string>(); } val3.floorsWithThisSetting = Math.Max(1, floorLayoutDef.Floors); val3.blueprints = new List<TextAsset>(); foreach (string blueprint in floorLayoutDef.Blueprints) { TextAsset val5 = ResolveFloor(blueprint); if ((Object)(object)val5 != (Object)null) { val3.blueprints.Add(val5); continue; } ManualLogSource l2 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(46, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(what); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" layout "); ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(i + 1); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" uses floor '"); ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(blueprint); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("', which doesn't exist."); } l2.LogError(val6); } if (val3.blueprints.Count == 0) { ManualLogSource l3 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val6 = new BepInExErrorLogInterpolatedStringHandler(63, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(def.Id); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(what); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" layout "); ((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<int>(i + 1); ((BepInExLogInterpolatedStringHandler)val6).AppendLiteral(" has no usable floors; the game may fail to build it."); } l3.LogError(val6); } val.Add(val3); } return val; } private static TextAsset ResolveFloor(string name) { if (FloorAssets.TryGetValue(name, out var value) && (Object)(object)value != (Object)null) { return value; } AssetLoader instance = AssetLoader.Instance; if (((instance != null) ? instance.allFloorData : null) != null) { Enumerator<TextAsset> enumerator = instance.allFloorData.GetEnumerator(); while (enumerator.MoveNext()) { TextAsset current = enumerator.Current; if ((Object)(object)current != (Object)null && ((Object)current).name == name) { return current; } } } return null; } private static void ApplyOverrides(BuildingPreset p, BuildingOverrides o) { //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Expected O, but got Unknown if (o == null) { return; } if (o.Disable.HasValue) { p.disable = o.Disable.Value; } if (o.Zone.HasValue) { p.displayedZone = (ZoneType)o.Zone.Value; } if (o.DensityMinimum.HasValue) { p.densityMinimum = (Density)o.DensityMinimum.Value; } if (o.DensityMaximum.HasValue) { p.densityMaximum = (Density)o.DensityMaximum.Value; } if (o.LandValueMinimum.HasValue) { p.landValueMinimum = (LandValue)o.LandValueMinimum.Value; } if (o.LandValueMaximum.HasValue) { p.landValueMaximum = (LandValue)o.LandValueMaximum.Value; } if (o.Minimum.HasValue) { p.minimum = o.Minimum.Value; } if (o.HardLimit.HasValue) { p.hardLimit = o.HardLimit.Value; } if (o.DesiredRatio.HasValue) { p.desiredRatio = o.DesiredRatio.Value; } if (o.FeatureImportance.HasValue) { p.featureImportance = o.FeatureImportance.Value; } if (o.AllowedInAllDistricts.HasValue) { p.allowedInAllDistricts = o.AllowedInAllDistricts.Value; } if (!string.IsNullOrWhiteSpace(o.StairsFrom)) { BuildingPreset val = FindVanillaPreset(o.StairsFrom.Trim()); bool flag = default(bool); if ((SoCustomComparison)(object)val == (SoCustomComparison)null) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(74, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((SoCustomComparison)p).presetName); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": StairsFrom '"); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(o.StairsFrom); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' isn't a game building; keeping the base building's stairs."); } l.LogWarning(val2); } else { p.stairwellRegular = val.stairwellRegular; p.stairwellLarge = val.stairwellLarge; ManualLogSource l2 = Plugin.L; BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(26, 4, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((SoCustomComparison)p).presetName); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(": stairs from "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(o.StairsFrom); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" ("); StairwellPreset stairwellRegular = val.stairwellRegular; ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>((stairwellRegular != null) ? ((Object)stairwellRegular).name : null); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(", lift: "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(((SoCustomComparison)(object)val.stairwellRegular != (SoCustomComparison)null && val.stairwellRegular.featuresElevator) ? "yes" : "no"); ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(")."); } l2.LogInfo(val3); } } if (o.PossibleNames == null || o.PossibleNames.Count <= 0) { return; } List<string> val4 = new List<string>(); foreach (string possibleName in o.PossibleNames) { val4.Add(possibleName); } p.possibleNames = val4; p.overrideNaming = true; } } internal static class CustomPlaceMaker { private static readonly List<RoomTypeDef> RoomDefs = new List<RoomTypeDef>(); private static readonly List<PlaceDef> PlaceDefs = new List<PlaceDef>(); private static readonly Dictionary<string, RoomConfiguration> Rooms = new Dictionary<string, RoomConfiguration>(StringComparer.Ordinal); private static readonly Dictionary<string, AddressPreset> Places = new Dictionary<string, AddressPreset>(StringComparer.Ordinal); private static bool _reported; internal static bool IsOurPlace(string name) { if (name != null) { return PlaceDefs.Any((PlaceDef p) => p.Id == name); } return false; } internal static bool IsOurRoom(string name) { if (name != null) { return RoomDefs.Any((RoomTypeDef r) => r.Id == name); } return false; } internal static void ReadFiles() { //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0325: Expected O, but got Unknown //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Expected O, but got Unknown //IL_0203: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Expected O, but got Unknown //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_0264: Expected O, but got Unknown RoomDefs.Clear(); PlaceDefs.Clear(); bool flag = default(bool); foreach (var (placesFile, text) in PlacesStore.LoadAll(Plugin.ModDir, delegate(string e) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown ManualLogSource l6 = Plugin.L; bool flag2 = default(bool); BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(9, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[places] "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(e); } l6.LogError(val3); })) { foreach (RoomTypeDef r in placesFile.RoomTypes ?? new List<RoomTypeDef>()) { if (string.IsNullOrWhiteSpace(r?.Id) || string.IsNullOrWhiteSpace(r.BasedOn)) { ManualLogSource l = Plugin.L; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(54, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[places] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": a room type without Id or BasedOn, skipped."); } l.LogError(val); } else if (RoomDefs.Any((RoomTypeDef x) => x.Id == r.Id)) { ManualLogSource l2 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(65, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[places] room type '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(r.Id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' exists twice; the second one ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") is skipped."); } l2.LogError(val); } else { RoomDefs.Add(r); } } foreach (PlaceDef p in placesFile.Places ?? new List<PlaceDef>()) { if (string.IsNullOrWhiteSpace(p?.Id) || string.IsNullOrWhiteSpace(p.BasedOn)) { ManualLogSource l3 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(50, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[places] "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": a place without Id or BasedOn, skipped."); } l3.LogError(val); } else if (PlaceDefs.Any((PlaceDef x) => x.Id == p.Id)) { ManualLogSource l4 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(61, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[places] place '"); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(p.Id); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' exists twice; the second one ("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") is skipped."); } l4.LogError(val); } else { PlaceDefs.Add(p); } } } if (RoomDefs.Count + PlaceDefs.Count <= 0) { return; } ManualLogSource l5 = Plugin.L; BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(46, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Read "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(PlaceDefs.Count); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" place(s) and "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(RoomDefs.Count); ((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" room type(s) of your own: "); ((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(string.Join(", ", PlaceDefs.Select((PlaceDef placeDef) => placeDef.Id).Concat(RoomDefs.Select((RoomTypeDef roomTypeDef) => roomTypeDef.Id)))); } l5.LogInfo(val2); } internal static void Make(string from) { //IL_0bcf: Unknown result type (might be due to invalid IL or missing references) //IL_0bd6: Expected O, but got Unknown //IL_09c5: Unknown result type (might be due to invalid IL or missing references) //IL_09cc: Expected O, but got Unknown //IL_0b0a: Unknown result type (might be due to invalid IL or missing references) //IL_0b11: Expected O, but got Unknown //IL_0b81: Unknown result type (might be due to invalid IL or missing references) //IL_0b88: Expected O, but got Unknown if (RoomDefs.Count + PlaceDefs.Count == 0) { return; } Toolbox instance = Toolbox.Instance; if (((instance != null) ? instance.allAddressPresets : null) == null || instance.allAddressPresets.Count == 0) { return; } bool flag2 = default(bool); try { List<string> list = new List<string>(); int num = 0; int num2 = 0; for (int i = 0; i < 4; i++) { foreach (RoomTypeDef roomDef in RoomDefs) { if (Rooms.TryGetValue(roomDef.Id, out var value) && (SoCustomComparison)(object)value != (SoCustomComparison)null && !((Il2CppObjectBase)value).WasCollected) { continue; } RoomConfiguration value2; RoomConfiguration val = ((Rooms.TryGetValue(roomDef.BasedOn, out value2) && (SoCustomComparison)(object)value2 != (SoCustomComparison)null && !((Il2CppObjectBase)value2).WasCollected) ? value2 : Find<RoomConfiguration>(roomDef.BasedOn)); if ((SoCustomComparison)(object)val == (SoCustomComparison)null) { if (i == 3 && from == "load start") { list.Add($"room type {roomDef.Id}: no room type '{roomDef.BasedOn}' to copy"); } continue; } RoomConfiguration val2 = Object.Instantiate<RoomConfiguration>(val); ((Object)val2).name = roomDef.Id; ((SoCustomComparison)val2).presetName = roomDef.Id; ((Object)val2).hideFlags = (HideFlags)32; if (!string.IsNullOrWhiteSpace(roomDef.GoesInto)) { RoomTypePreset val3 = Find<RoomTypePreset>(roomDef.GoesInto); if ((SoCustomComparison)(object)val3 != (SoCustomComparison)null) { val2.roomType = val3; } else { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(37, 3); defaultInterpolatedStringHandler.AppendLiteral("room type "); defaultInterpolatedStringHandler.AppendFormatted(roomDef.Id); defaultInterpolatedStringHandler.AppendLiteral(": no kind of room '"); defaultInterpolatedStringHandler.AppendFormatted(roomDef.GoesInto); defaultInterpolatedStringHandler.AppendLiteral("', kept "); RoomTypePreset roomType = val.roomType; defaultInterpolatedStringHandler.AppendFormatted((roomType != null) ? ((Object)roomType).name : null); list.Add(defaultInterpolatedStringHandler.ToStringAndClear()); } } if (roomDef.WellLit.HasValue) { val2.wellLit = roomDef.WellLit.Value; } if (roomDef.LightsOnAtStart.HasValue) { val2.lightsOnAtStart = roomDef.LightsOnAtStart.Value; } if (roomDef.Cleanness.HasValue) { val2.cleanness = Math.Clamp(roomDef.Cleanness.Value, 0, 10); } if (roomDef.Public.HasValue) { val2.forbidden = (Forbidden)((!roomDef.Public.Value) ? 1 : 2); } Rooms[roomDef.Id] = val2; num++; } } bool flag = from == "load start"; foreach (PlaceDef def in PlaceDefs) { if ((!flag && !AllThere(def, instance)) || (Places.TryGetValue(def.Id, out var value3) && (SoCustomComparison)(object)value3 != (SoCustomComparison)null && !((Il2CppObjectBase)value3).WasCollected)) { continue; } AddressPreset val4 = ((IEnumerable<AddressPreset>)instance.allAddressPresets.ToArray()).FirstOrDefault((Func<AddressPreset, bool>)((AddressPreset a) => (SoCustomComparison)(object)a != (SoCustomComparison)null && (((Object)a).name == def.BasedOn || ((SoCustomComparison)a).presetName == def.BasedOn))) ?? Find<AddressPreset>(def.BasedOn); if ((SoCustomComparison)(object)val4 == (SoCustomComparison)null) { list.Add($"place {def.Id}: no place '{def.BasedOn}' to copy"); continue; } AddressPreset val5 = Object.Instantiate<AddressPreset>(val4); ((Object)val5).name = def.Id; ((SoCustomComparison)val5).presetName = def.Id; ((Object)val5).hideFlags = (HideFlags)32; List<RoomConfiguration> val6 = new List<RoomConfiguration>(); HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal); List<RoomConfiguration> list2 = new List<RoomConfiguration>(); foreach (PlaceRoom item in def.Rooms ?? new List<PlaceRoom>()) { if (string.IsNullOrWhiteSpace(item?.Room)) { continue; } RoomConfiguration value4; RoomConfiguration val7 = ((Rooms.TryGetValue(item.Room, out value4) && (SoCustomComparison)(object)value4 != (SoCustomComparison)null && !((Il2CppObjectBase)value4).WasCollected) ? value4 : Find<RoomConfiguration>(item.Room)); if ((SoCustomComparison)(object)val7 == (SoCustomComparison)null) { list.Add($"place {def.Id}: no room type '{item.Room}'"); continue; } object obj; if (!string.IsNullOrWhiteSpace(item.Kind)) { obj = item.Kind.Trim(); } else { RoomTypePreset roomType2 = val7.roomType; obj = ((roomType2 != null) ? ((Object)roomType2).name : null); } string text = (string)obj; if ((SoCustomComparison)(object)val7.roomType != (SoCustomComparison)null && text != ((Object)val7.roomType).name) { list.Add($"place {def.Id}: room type {item.Room} goes into {((Object)val7.roomType).name} rooms, not {text} (set its 'Goes into')"); } if (text != null) { hashSet.Add(text); } RoomTypePreset roomType3 = val7.roomType; if (((roomType3 != null) ? ((Object)roomType3).name : null) != null) { hashSet.Add(((Object)val7.roomType).name); } list2.Add(val7); } if (val4.roomConfig != null) { Enumerator<RoomConfiguration> enumerator4 = val4.roomConfig.GetEnumerator(); while (enumerator4.MoveNext()) { RoomConfiguration current3 = enumerator4.Current; if ((SoCustomComparison)(object)current3 != (SoCustomComparison)null) { RoomTypePreset roomType4 = current3.roomType; if (!hashSet.Contains(((roomType4 != null) ? ((Object)roomType4).name : null) ?? "")) { val6.Add(current3); } } } } foreach (RoomConfiguration item2 in list2) { val6.Add(item2); } val5.roomConfig = val6; List<string> list3 = def.FitsList().ToList(); if (list3.Count > 0) { List<LayoutConfiguration> val8 = new List<LayoutConfiguration>(); foreach (string item3 in list3) { LayoutConfiguration val9 = Find<LayoutConfiguration>(item3); if ((SoCustomComparison)(object)val9 != (SoCustomComparison)null) { val8.Add(val9); continue; } list.Add($"place {def.Id}: no address type '{item3}'"); } val5.compatible = val8; } if (def.OnlyReserved) { val5.baseScore = -1000000; val5.forcePick = false; } Places[def.Id] = val5; num2++; } foreach (RoomConfiguration value5 in Rooms.Values) { if ((SoCustomComparison)(object)value5 != (SoCustomComparison)null && !((Il2CppObjectBase)value5).WasCollected && !InCache<RoomConfiguration>(((Object)value5).name)) { instance.ProcessLoadedScriptableObject((ScriptableObject)(object)value5); } } foreach (AddressPreset value6 in Places.Values) { if (!((SoCustomComparison)(object)value6 == (SoCustomComparison)null) && !((Il2CppObjectBase)value6).WasCollected) { if (!InCache<AddressPreset>(((Object)value6).name)) { instance.ProcessLoadedScriptableObject((ScriptableObject)(object)value6); } if (!instance.allAddressPresets.Contains(value6)) { instance.allAddressPresets.Add(value6); } } } if (num + num2 <= 0 && (_reported || list.Count <= 0)) { return; } _reported = true; BepInExInfoLogInterpolatedStringHandler val10; foreach (AddressPreset item4 in Places.Values.Where((AddressPreset a) => (SoCustomComparison)(object)a != (SoCustomComparison)null && !((Il2CppObjectBase)a).WasCollected)) { ManualLogSource l = Plugin.L; val10 = new BepInExInfoLogInterpolatedStringHandler(35, 3, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("[places] your place "); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(((Object)item4).name); ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral(": rooms "); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(string.Join(", ", ((IEnumerable<RoomConfiguration>)item4.roomConfig.ToArray()).Where((RoomConfiguration r) => (SoCustomComparison)(object)r != (SoCustomComparison)null).Select(delegate(RoomConfiguration r) { RoomTypePreset roomType5 = r.roomType; return ((roomType5 != null) ? ((Object)roomType5).name : null) + " → " + ((Object)r).name; }))); ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("; fits "); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(string.Join(", ", (from val13 in (IEnumerable<LayoutConfiguration>)item4.compatible?.ToArray() where (SoCustomComparison)(object)val13 != (SoCustomComparison)null select ((Object)val13).name) ?? Array.Empty<string>())); } l.LogInfo(val10); } ManualLogSource l2 = Plugin.L; val10 = new BepInExInfoLogInterpolatedStringHandler(57, 3, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral("[places] ("); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<string>(from); ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral(") made "); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<int>(num); ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral(" room type(s) and "); ((BepInExLogInterpolatedStringHandler)val10).AppendFormatted<int>(num2); ((BepInExLogInterpolatedStringHandler)val10).AppendLiteral(" place(s) of your own."); } l2.LogInfo(val10); foreach (string item5 in list) { ManualLogSource l3 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val11 = new BepInExWarningLogInterpolatedStringHandler(9, 1, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val11).AppendLiteral("[places] "); ((BepInExLogInterpolatedStringHandler)val11).AppendFormatted<string>(item5); } l3.LogWarning(val11); } } catch (Exception ex) { ManualLogSource l4 = Plugin.L; BepInExErrorLogInterpolatedStringHandler val12 = new BepInExErrorLogInterpolatedStringHandler(54, 2, ref flag2); if (