Skip to content

Commit e4f5322

Browse files
committed
fix: namespace bugs
1 parent 4ff997f commit e4f5322

File tree

4 files changed

+18
-74
lines changed

4 files changed

+18
-74
lines changed

src/OTAPI.UnifiedServerProcess/Core/Patching/PatchingCommon.cs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,77 +15,6 @@ namespace OTAPI.UnifiedServerProcess.Core.Patching
1515
{
1616
public static class PatchingCommon
1717
{
18-
public static Mono.Cecil.Cil.MethodBody? Clone(this Mono.Cecil.Cil.MethodBody? bo, MethodDefinition m) {
19-
Mono.Cecil.Cil.MethodBody bo2 = bo;
20-
Helpers.ThrowIfArgumentNull(m, "m");
21-
if (bo2 == null) {
22-
return null;
23-
}
24-
Mono.Cecil.Cil.MethodBody bc = new Mono.Cecil.Cil.MethodBody(m);
25-
bc.MaxStackSize = bo2.MaxStackSize;
26-
bc.InitLocals = bo2.InitLocals;
27-
bc.LocalVarToken = bo2.LocalVarToken;
28-
bc.Instructions.AddRange(bo2.Instructions.Select(delegate (Instruction o) {
29-
Instruction instruction = Instruction.Create(Mono.Cecil.Cil.OpCodes.Nop);
30-
instruction.OpCode = o.OpCode;
31-
instruction.Operand = o.Operand;
32-
instruction.Offset = o.Offset;
33-
return instruction;
34-
}));
35-
bc.ExceptionHandlers.AddRange(bo2.ExceptionHandlers.Select((ExceptionHandler o) => new ExceptionHandler(o.HandlerType) {
36-
TryStart = ((o.TryStart == null) ? null : bc.Instructions[bo2.Instructions.IndexOf(o.TryStart)]),
37-
TryEnd = ((o.TryEnd == null) ? null : bc.Instructions[bo2.Instructions.IndexOf(o.TryEnd)]),
38-
FilterStart = ((o.FilterStart == null) ? null : bc.Instructions[bo2.Instructions.IndexOf(o.FilterStart)]),
39-
HandlerStart = ((o.HandlerStart == null) ? null : bc.Instructions[bo2.Instructions.IndexOf(o.HandlerStart)]),
40-
HandlerEnd = ((o.HandlerEnd == null) ? null : bc.Instructions[bo2.Instructions.IndexOf(o.HandlerEnd)]),
41-
CatchType = o.CatchType
42-
}));
43-
bc.Variables.AddRange(bo2.Variables.Select((VariableDefinition o) => new VariableDefinition(o.VariableType)));
44-
m.CustomDebugInformations.AddRange(bo2.Method.CustomDebugInformations.Select(delegate (CustomDebugInformation o) {
45-
if (o is AsyncMethodBodyDebugInformation asyncMethodBodyDebugInformation) {
46-
AsyncMethodBodyDebugInformation asyncMethodBodyDebugInformation2 = new AsyncMethodBodyDebugInformation();
47-
if (asyncMethodBodyDebugInformation.CatchHandler.Offset >= 0) {
48-
asyncMethodBodyDebugInformation2.CatchHandler = (asyncMethodBodyDebugInformation.CatchHandler.IsEndOfMethod ? default(InstructionOffset) : new InstructionOffset(ResolveInstrOff(asyncMethodBodyDebugInformation.CatchHandler.Offset)));
49-
}
50-
asyncMethodBodyDebugInformation2.Yields.AddRange(asyncMethodBodyDebugInformation.Yields.Select((InstructionOffset off) => (!off.IsEndOfMethod) ? new InstructionOffset(ResolveInstrOff(off.Offset)) : default(InstructionOffset)));
51-
asyncMethodBodyDebugInformation2.Resumes.AddRange(asyncMethodBodyDebugInformation.Resumes.Select((InstructionOffset off) => (!off.IsEndOfMethod) ? new InstructionOffset(ResolveInstrOff(off.Offset)) : default(InstructionOffset)));
52-
asyncMethodBodyDebugInformation2.ResumeMethods.AddRange(asyncMethodBodyDebugInformation.ResumeMethods);
53-
return asyncMethodBodyDebugInformation2;
54-
}
55-
if (o is StateMachineScopeDebugInformation stateMachineScopeDebugInformation) {
56-
StateMachineScopeDebugInformation stateMachineScopeDebugInformation2 = new StateMachineScopeDebugInformation();
57-
stateMachineScopeDebugInformation2.Scopes.AddRange(stateMachineScopeDebugInformation.Scopes.Select((StateMachineScope s) => new StateMachineScope(ResolveInstrOff(s.Start.Offset), s.End.IsEndOfMethod ? null : ResolveInstrOff(s.End.Offset))));
58-
return stateMachineScopeDebugInformation2;
59-
}
60-
return o;
61-
}));
62-
m.DebugInformation.SequencePoints.AddRange(bo2.Method.DebugInformation.SequencePoints.Select((SequencePoint o) => new SequencePoint(ResolveInstrOff(o.Offset), o.Document) {
63-
StartLine = o.StartLine,
64-
StartColumn = o.StartColumn,
65-
EndLine = o.EndLine,
66-
EndColumn = o.EndColumn
67-
}));
68-
foreach (Instruction instruction2 in bc.Instructions) {
69-
if (instruction2.Operand is Instruction item) {
70-
instruction2.Operand = bc.Instructions[bo2.Instructions.IndexOf(item)];
71-
}
72-
else if (instruction2.Operand is Instruction[] source) {
73-
instruction2.Operand = source.Select((Instruction i) => bc.Instructions[bo2.Instructions.IndexOf(i)]).ToArray();
74-
}
75-
else if (instruction2.Operand is VariableDefinition variableDefinition) {
76-
instruction2.Operand = bc.Variables[variableDefinition.Index];
77-
}
78-
}
79-
return bc;
80-
Instruction ResolveInstrOff(int off) {
81-
for (int j = 0; j < bo2.Instructions.Count; j++) {
82-
if (bo2.Instructions[j].Offset == off) {
83-
return bc.Instructions[j];
84-
}
85-
}
86-
throw new ArgumentException($"Invalid instruction offset {off}");
87-
}
88-
}
8918
public static MethodDefinition CreateInstanceConvdMethod(MethodDefinition staticMethod, ContextTypeData instanceConvdType, ImmutableDictionary<string, FieldDefinition> instanceConvdFieldOrgiMap) {
9019
if (!staticMethod.IsStatic) {
9120
throw new ArgumentException("Method must be static", nameof(staticMethod));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace TrProtocol.Attributes
6+
{
7+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface)]
8+
public class ExplicitImportTypeAttribute(Type type) : Attribute
9+
{
10+
public Type Type = type;
11+
}
12+
}

src/TrProtocol.Shared/TrProtocol.Shared.projitems

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<SharedGUID>768417b4-d342-4006-b196-5f7178582209</SharedGUID>
77
</PropertyGroup>
88
<PropertyGroup Label="Configuration">
9-
<Import_RootNamespace>TrProtocol.Shared</Import_RootNamespace>
9+
<Import_RootNamespace>TrProtocol</Import_RootNamespace>
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ArraySizeAttribute.cs" />
@@ -20,6 +20,7 @@
2020
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ConditionLessThanAttribute.cs" />
2121
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ConditionLookupMatchAttribute.cs" />
2222
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ConditionNotEqualAttribute.cs" />
23+
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ExplicitImportTypeAttribute.cs" />
2324
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ExternalMemberAttribute.cs" />
2425
<Compile Include="$(MSBuildThisFileDirectory)Attributes\ExternalMemberValueSetterAttribute.cs" />
2526
<Compile Include="$(MSBuildThisFileDirectory)Attributes\IgnoreSerializeAttribute.cs" />

src/TrProtocol/Models/SectionData.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System.IO.Compression;
1+
using System.Buffers;
2+
using System.IO.Compression;
23
using TrProtocol.Attributes;
34
using TrProtocol.Interfaces;
45
using TrProtocol.Models.TileEntities;
56

67
namespace TrProtocol.Models;
78

9+
[ExplicitImportType(typeof(ArrayPool<byte>))]
810
[Compress(CompressionLevel.SmallestSize, 1024 * 128)]
911
public partial struct SectionData : IAutoSerializable, ILengthAware
1012
{
@@ -13,7 +15,7 @@ public partial struct SectionData : IAutoSerializable, ILengthAware
1315
public short Width;
1416
public short Height;
1517

16-
public int ComplexTileCount => Width * Height;
18+
public readonly int ComplexTileCount => Width * Height;
1719

1820
[ArraySize(nameof(ComplexTileCount))]
1921
public ComplexTileData[] Tiles;

0 commit comments

Comments
 (0)