Skip to content

Commit e7ac417

Browse files
committed
feat: Patch Collision to pass check results through reference
1 parent 27c6256 commit e7ac417

File tree

11 files changed

+839
-18
lines changed

11 files changed

+839
-18
lines changed

src/OTAPI.UnifiedServerProcess/Core/PatchCollision.cs

Lines changed: 786 additions & 0 deletions
Large diffs are not rendered by default.

src/OTAPI.UnifiedServerProcess/Core/Patching/GeneralPatching/StaticRedirectPatcher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ void ProcessMethod(
331331
if (arguments.ContextTypes.TryGetValue(method.DeclaringType.FullName, out var predefined) && predefined.IsPredefined) {
332332
return;
333333
}
334-
335334
var methodId = method.GetIdentifier();
336335

337336
if (arguments.OriginalToContextType.TryGetValue(method.DeclaringType.FullName, out var contextType)

src/OTAPI.UnifiedServerProcess/Core/PatchingLogic.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public static class PatchingLogic
1414
{
1515
public static void Patch(ILogger logger, ModuleDefinition module) {
1616

17+
PatchLogic.PatchCollision(module);
1718
new NetworkLogicPruner(module).Prune();
1819

1920
var analyzers = new AnalyzerGroups(logger, module);

src/OTAPI.UnifiedServerProcess/ModAssemblyMerger.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,12 @@ static void SetModTypePlaceholder(ModuleDefinition module, Dictionary<string, Ty
301301
SetMemberReplace(module, modType.CustomAttributes, true);
302302
}
303303
foreach (var field in modType.Fields) {
304-
SetMemberReplace(module, field.CustomAttributes, modType.IsEnum);
304+
if (modType.IsEnum && !field.IsStatic) {
305+
SetMemberReplace(module, field.CustomAttributes, false);
306+
}
307+
else {
308+
SetMemberReplace(module, field.CustomAttributes, modType.IsEnum);
309+
}
305310
}
306311
}
307312
foreach (var nested in modType.NestedTypes) {

src/OTAPI.UnifiedServerProcess/OTAPI.UnifiedServerProcess.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<ProjectReference Include="..\TrProtocol\TrProtocol.csproj" />
28+
<ProjectReference Include="..\TrProtocol\TrProtocol.csproj" />
2929
</ItemGroup>
3030

3131
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">

src/TrProtocol.SerializerGenerator/Internal/Models/ProtocolTypeData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ namespace TrProtocol.SerializerGenerator.Internal.Models
66
{
77
public class ProtocolTypeData
88
{
9-
public ProtocolTypeData(TypeDeclarationSyntax classDeclaration, INamedTypeSymbol symbol, string name, string nameSpace, string[] imports, SerializationExpandContext[] members) {
9+
public ProtocolTypeData(TypeDeclarationSyntax classDeclaration, INamedTypeSymbol symbol, string name, string nameSpace, string[] imports, string[] staticImports, SerializationExpandContext[] members) {
1010
DefSyntax = classDeclaration;
1111
DefSymbol = symbol;
1212
TypeName = name;
1313
Members = members;
1414
Namespace = nameSpace;
15-
Imports = new HashSet<string>(imports);
15+
Imports = [.. imports];
16+
StaticImports = [.. staticImports];
1617
}
1718
public readonly INamedTypeSymbol DefSymbol;
1819
public readonly TypeDeclarationSyntax DefSyntax;
1920

2021
public string Namespace;
2122
public HashSet<string> Imports;
23+
public HashSet<string> StaticImports;
2224

2325
public List<(INamedTypeSymbol EnumType, string DiscriminatorName, MemberAccessExpressionSyntax value)> AutoDiscriminators = new();
2426

src/TrProtocol.SerializerGenerator/Internal/Serialization/ProtocolModelBuilder.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.CodeAnalysis;
22
using Microsoft.CodeAnalysis.CSharp;
3+
using Microsoft.CodeAnalysis.CSharp.Syntax;
34
using TrProtocol.Attributes;
45
using TrProtocol.Interfaces;
56
using TrProtocol.SerializerGenerator.Internal.Diagnostics;
@@ -38,12 +39,19 @@ public static ProtocolTypeData BuildProtocolTypeInfo(CompilationContext context,
3839

3940
var Namespace = fullNamespace;
4041
var imports = unit!.Usings
42+
.Where(u => u.StaticKeyword == default && u.GlobalKeyword == default)
43+
.Select(u => u.Name?.ToString())
44+
.Where(u => u is not null)
45+
.OfType<string>()
46+
.ToArray();
47+
var staticImports = unit.Usings
48+
.Where(u => u.StaticKeyword != default && u.GlobalKeyword == default)
4149
.Select(u => u.Name?.ToString())
4250
.Where(u => u is not null)
4351
.OfType<string>()
4452
.ToArray();
4553

46-
if (!context.TryGetTypeSymbol(typeName, out var modelSym, fullNamespace, Array.Empty<string>())) {
54+
if (!context.TryGetTypeSymbol(typeName, out var modelSym, fullNamespace, [])) {
4755
throw new DiagnosticException(
4856
Diagnostic.Create(
4957
new DiagnosticDescriptor(
@@ -56,7 +64,7 @@ public static ProtocolTypeData BuildProtocolTypeInfo(CompilationContext context,
5664
defSyntax.GetLocation(),
5765
typeName));
5866
}
59-
var model = new ProtocolTypeData(defSyntax, modelSym, typeName, Namespace, imports, info.Members);
67+
var model = new ProtocolTypeData(defSyntax, modelSym, typeName, Namespace, imports, staticImports, info.Members);
6068

6169
if (modelSym.IsOrInheritFrom(nameof(INetPacket))) {
6270
model.IsNetPacket = true;

src/TrProtocol.SerializerGenerator/SerializeGenerator.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ private static bool FilterTypes(SyntaxNode syntaxNode, CancellationToken token)
2525
if (syntaxNode is not TypeDeclarationSyntax td/* && td.Keyword.ToString() is not "interface" && td.Keyword.ToString() is not "record" && td.BaseList is not null*/) {
2626
return false;
2727
}
28+
if (td.BaseList is null || td.BaseList.Types.Count == 0) {
29+
return false;
30+
}
2831
td.GetNamespace(out _, out var nameSpace, out _);
2932
if (nameSpace is null) {
3033
return false;
@@ -1663,6 +1666,9 @@ param[0].Type is PointerTypeSyntax pointerType &&
16631666
foreach (var us in model.Imports.Concat(NeccessaryUsings).Distinct()) {
16641667
usingTarget.NewLineAfter($"using {us};");
16651668
}
1669+
foreach (var staticUsing in model.StaticImports) {
1670+
usingTarget.NewLineAfter($"using static {staticUsing};");
1671+
}
16661672
#endregion
16671673

16681674
context.AddSource($"{modelSym.GetFullName()}.seri.g.cs", SourceText.From(file.ToString(), Encoding.UTF8));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Terraria.GameContent.UI
8+
{
9+
public class WiresUI
10+
{
11+
public class Settings
12+
{
13+
public enum MultiToolMode : byte
14+
{
15+
Red = 1,
16+
Green = 2,
17+
Blue = 4,
18+
Yellow = 8,
19+
Actuator = 16,
20+
Cutter = 32
21+
}
22+
}
23+
}
24+
}

src/TrProtocol/ExportedModels/Terraria/GameContent/UI/WiresUI/Settings/MultiToolMode.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)