Skip to content

Commit c2dfabf

Browse files
committed
feat: More precise selection of context-related variables
1 parent 9d8c72c commit c2dfabf

File tree

48 files changed

+1016
-911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1016
-911
lines changed

src/OTAPI.UnifiedServerProcess.GlobalNetwork/Network/NetworkPatcher.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ private static void Modified_StartServer(On.Terraria.NetplaySystemContext.orig_S
2323

2424
var Main = server.Main;
2525

26-
Main.rand ??= new UnifiedRandom((int)DateTime.Now.Ticks);
27-
Main.myPlayer = 255;
26+
Terraria.Main.rand ??= new UnifiedRandom((int)DateTime.Now.Ticks);
2827
self.ServerIP = IPAddress.Any;
2928
Main.menuMode = 14;
3029
Main.statusText = Lang.menu[8].Value;
31-
Main.netMode = 2;
3230
self.Disconnect = false;
3331

3432
self.Clients = Router.globalClients;

src/OTAPI.UnifiedServerProcess.GlobalNetwork/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static void Main(string[] args) {
2626
AppDomain.CurrentDomain.AssemblyResolve += ResolveHelpers.ResolveAssembly;
2727
Terraria.Program.SavePath = Platform.Get<IPathService>().GetStoragePath("Terraria");
2828
Terraria.Main.SkipAssemblyLoad = true;
29+
Terraria.Main.rand = new((int)DateTime.Now.Ticks);
2930
GlobalInitializer.Initialize();
3031
});
3132

src/OTAPI.UnifiedServerProcess.GlobalNetwork/SynchronizedGuard.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public static class SynchronizedGuard
77

88
static SynchronizedGuard() {
99
On.Terraria.Localization.LanguageManager.LoadFilesForCulture
10-
+= (orig, self, root, culture)
11-
=> { lock (cultureFileLock) { orig(self, root, culture); } };
10+
+= (orig, self, culture)
11+
=> { lock (cultureFileLock) { orig(self, culture); } };
1212
On.Terraria.GameContent.Creative.CreativeItemSacrificesCatalog.Initialize
1313
+= (orig, self) => { lock (creativeSacrificesLock) { orig(self); } };
1414
}

src/OTAPI.UnifiedServerProcess/Commons/IL.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static partial class MonoModCommon
1111
public static class IL
1212
{
1313
/// <summary>
14-
/// The name of the "this" TrackingParameter is an empty string rather than "this".
14+
/// The name of the "this" Parameter is an empty string rather than "this".
1515
/// </summary>
1616
public const string ThisParameterName = "";
1717
public static Instruction BuildParameterLoad(MethodDefinition method, MethodBody body, ParameterDefinition parameter) {
@@ -32,7 +32,7 @@ public static Instruction BuildParameterLoad(MethodDefinition method, MethodBody
3232
}
3333
public static Instruction BuildParameterSet(MethodDefinition method, MethodBody body, ParameterDefinition parameter) {
3434
if (method.HasThis && ((body is not null && body.ThisParameter == parameter) || parameter.Name == "")) {
35-
throw new ArgumentException("Cannot set \"this\" TrackingParameter", nameof(parameter));
35+
throw new ArgumentException("Cannot set \"this\" TracingParameter", nameof(parameter));
3636
}
3737
else {
3838
var index = method.Parameters.IndexOf(parameter) + (method.HasThis ? 1 : 0);
@@ -107,7 +107,7 @@ Code.Starg_S or
107107
}
108108
var param = method.Parameters[paramIndex];
109109
if (tmpCheck is not null && tmpCheck.Name != param.Name) {
110-
throw new InvalidOperationException("Operand TrackingParameter is invalid");
110+
throw new InvalidOperationException("Operand TracingParameter is invalid");
111111
}
112112
return param;
113113
}
@@ -143,7 +143,7 @@ Code.Starg_S or
143143
var paramIndex = paramInnerIndex - (method.HasThis ? 1 : 0);
144144
parameter = method.Parameters[paramIndex];
145145
if (tmpCheck is not null && tmpCheck.Name != parameter.Name) {
146-
throw new InvalidOperationException("Operand TrackingParameter is invalid");
146+
throw new InvalidOperationException("Operand TracingParameter is invalid");
147147
}
148148
}
149149
return true;

src/OTAPI.UnifiedServerProcess/Commons/Stack.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private static IEnumerable<Instruction> GetNextInstructions(Instruction current)
173173
}
174174
}
175175

176-
// linear backtracking
176+
// linear backtracing
177177
if (current.Previous != null) {
178178
if (!IsTerminatorInstruction(current.Previous)) {
179179
workStack.Push((current.Previous, newerBalance, visited));
@@ -240,7 +240,7 @@ public static StackTopTypePath[] AnalyzeStackTopTypeAllPaths(MethodDefinition ca
240240
}
241241
}
242242

243-
// linear backtracking
243+
// linear backtracing
244244
if (current.Previous != null) {
245245
if (!IsTerminatorInstruction(current.Previous)) {
246246
workStack.Push((new(path), current.Previous, newerBalance, visited));
@@ -724,11 +724,11 @@ public class InstructionArgsSource(int index) : ArgumentSource
724724
public override string ToString() => $"[{Index}] (inst: {Instructions.Length})";
725725
}
726726
/// <summary>
727-
/// Analyzes TrackingParameter sources considering control flow and multiple execution paths
727+
/// Analyzes Parameter sources considering control flow and multiple execution paths
728728
/// </summary>
729729
/// <param name="caller">Containing method</param>
730730
/// <param name="target">Method call/newobj instruction</param>
731-
/// <returns>Array of possible TrackingParameter flow paths</returns>
731+
/// <returns>Array of possible Parameter flow paths</returns>
732732
public static FlowPath<ParameterSource>[] AnalyzeParametersSources(MethodDefinition caller, Instruction target, Dictionary<Instruction, List<Instruction>>? cachedJumpSitess = null) {
733733

734734
cachedJumpSitess ??= BuildJumpSitesMap(caller);
@@ -753,7 +753,7 @@ public static FlowPath<ParameterSource>[] AnalyzeParametersSources(MethodDefinit
753753
));
754754

755755
List<FlowPath<ParameterSource>> paths = new();
756-
// var visited = new HashSet<(Instruction, int)>(); // Track visited (offset, stackBalance)
756+
// var visited = new HashSet<(Instruction, int)>(); // Trace visited (offset, stackBalance)
757757

758758
while (workStack.Count > 0) {
759759
var ctx = workStack.Pop();
@@ -802,7 +802,7 @@ public static FlowPath<ParameterSource>[] AnalyzeParametersSources(MethodDefinit
802802
}
803803
}
804804

805-
// Linear backtracking
805+
// Linear backtracing
806806
if (ctx.Previous != null) {
807807
if (!IsTerminatorInstruction(ctx.Previous)) {
808808
workStack.Push(new ReverseAnalysisContext(
@@ -923,7 +923,7 @@ public static FlowPath<InstructionArgsSource>[] AnalyzeInstructionArgsSources(Me
923923
}
924924
}
925925

926-
// Linear backtracking
926+
// Linear backtracing
927927
if (ctx.Previous != null) {
928928
if (!IsTerminatorInstruction(ctx.Previous)) {
929929
workStack.Push(new ReverseAnalysisContext(

src/OTAPI.UnifiedServerProcess/Commons/Structure.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static string GenerateKeyForGenericParameter(GenericParameter param) {
3434
return param.DeclaringType.Resolve().FullName + ":" + param.Position;
3535
}
3636
else {
37-
throw new InvalidOperationException("Unknown generic TrackingParameter");
37+
throw new InvalidOperationException("Unknown generic TracingParameter");
3838
}
3939
}
4040
public readonly struct MapOption
@@ -127,7 +127,7 @@ public static TypeReference DeepMapGenericParameter(GenericParameter param, MapO
127127
copiedGenericParam = elementTypeRef.GenericParameters[param.Position];
128128
}
129129
else {
130-
throw new InvalidOperationException("Unknown generic TrackingParameter");
130+
throw new InvalidOperationException("Unknown generic TracingParameter");
131131
}
132132
return copiedGenericParam;
133133
}

src/OTAPI.UnifiedServerProcess/Core/Analysis/DelegateInvocationAnalysis/DelegateInvocationData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public bool AddCombinedFrom(DelegateInvocationData other) {
4545
var datasFromOther = combinedFromMap[other.invocations];
4646

4747
// Make sure the invocations are pointing to the same dictionary instance
48-
// so that modifications to one will naturally affect the other
48+
// so that Mutations to one will naturally affect the other
4949
foreach (var oldData in datasFromMe) {
5050

5151
if (datasFromOther.Add(oldData)) {

src/OTAPI.UnifiedServerProcess/Core/Analysis/DelegateInvocationAnalysis/DelegateInvocationGraph.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ private void ProcessMethod(ModuleDefinition module, MethodInheritanceGraph metho
315315
for (var i = 0; i < length; i++) {
316316
var paramIndex = i;
317317

318-
// skip 'this' TrackingParameter load
318+
// skip 'this' Parameter load
319319
if (!callingMethod.IsStatic && !isNewObj) {
320320
paramIndex -= 1;
321321
}

0 commit comments

Comments
 (0)