Skip to content

Commit 226a04c

Browse files
committed
Improved logs, make it work for INetworkSerializable and INetworkMessage
1 parent 911d490 commit 226a04c

File tree

2 files changed

+55
-13
lines changed

2 files changed

+55
-13
lines changed

NetcodePatcher/CodeGen/ILPostProcessorFromFile.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ public static ILPostProcessResult NetworkBehaviourProcess(ICompiledAssembly asse
2020
NetworkBehaviourILPP ilpp = new NetworkBehaviourILPP();
2121
if (ilpp.WillProcess(assembly))
2222
{
23-
//Debug.Log("Will Process: " + assembly.Name);
2423

2524
// process it like Unity would
2625
ILPostProcessResult result = ilpp.Process(assembly);
2726

27+
2828
// handle the error messages like Unity would
29+
2930
foreach (DiagnosticMessage message in result.Diagnostics)
3031
{
3132
if (message.DiagnosticType == DiagnosticType.Warning)
3233
{
33-
OnWarning(message.MessageData);
34+
// console output
35+
OnWarning(message.MessageData + $"{message.File}:{message.Line}");
3436
}
3537
else if (message.DiagnosticType == DiagnosticType.Error)
3638
{
@@ -58,7 +60,7 @@ public static ILPostProcessResult INetworkMessageProcess(ICompiledAssembly assem
5860
{
5961
if (message.DiagnosticType == DiagnosticType.Warning)
6062
{
61-
OnWarning(message.MessageData);
63+
OnWarning(message.MessageData + $"{message.File}:{message.Line}");
6264
}
6365
else if (message.DiagnosticType == DiagnosticType.Error)
6466
{
@@ -86,7 +88,7 @@ public static ILPostProcessResult INetworkSerializableProcess(ICompiledAssembly
8688
{
8789
if (message.DiagnosticType == DiagnosticType.Warning)
8890
{
89-
OnWarning(message.MessageData);
91+
OnWarning(message.MessageData + $"{message.File}:{message.Line}");
9092
}
9193
else if (message.DiagnosticType == DiagnosticType.Error)
9294
{
@@ -108,21 +110,27 @@ public static void ILPostProcessFile(string assemblyPath, string[] references, A
108110

109111
var result = NetworkBehaviourProcess(assembly, OnWarning, OnError);
110112

111-
/*if (result != null)
113+
if (result != null)
112114
{
113-
assembly = new CompiledAssemblyFromInMemoryAssembly(result.InMemoryAssembly, assembly.Name);
115+
var newAssembly = new CompiledAssemblyFromInMemoryAssembly(result.InMemoryAssembly, assembly.Name);
116+
newAssembly.References = references;
117+
118+
assembly = newAssembly;
114119
}
115120

116121
result = INetworkMessageProcess(assembly, OnWarning, OnError);
117-
118-
122+
123+
119124
if (result != null)
120125
{
121-
assembly = new CompiledAssemblyFromInMemoryAssembly(result.InMemoryAssembly, assembly.Name);
126+
var newAssembly = new CompiledAssemblyFromInMemoryAssembly(result.InMemoryAssembly, assembly.Name);
127+
newAssembly.References = references;
128+
129+
assembly = newAssembly;
122130
}
123131

124132
result = INetworkSerializableProcess(assembly, OnWarning, OnError);
125-
*/
133+
126134

127135
// save the weaved assembly to file.
128136
// some tests open it and check for certain IL code.

NetcodePatcher/Main.cs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,26 +121,60 @@ public static void Patch(string pluginPath, string managedPath)
121121
managedPath + "\\Unity.Networking.Transport.dll",
122122
};
123123

124+
List<string> blackList = new List<string>()
125+
{
126+
"Unity.Netcode.Runtime",
127+
"UnityEngine.CoreModule",
128+
"Unity.Netcode.Components",
129+
"Unity.Networking.Transport",
130+
"Assembly-CSharp"
131+
};
132+
124133
foreach (string text3 in Directory.GetFiles(pluginPath, "*.dll", SearchOption.AllDirectories))
125134
{
126135
string fileName = Path.GetFileName(text3);
127136
if (!fileName.ToLower().Contains("mmhook"))
128137
{
138+
//Patcher.Logger.LogMessage("Checking : " + fileName);
139+
var found = false;
140+
129141
foreach (TypeDefinition typeDefinition in AssemblyDefinition.ReadAssembly(text3).MainModule.Types)
130142
{
131143

132144

133145
if (typeDefinition.BaseType != null)
134146
{
135-
; // check if subclass of NetworkBehaviour
147+
// check if subclass of NetworkBehaviour
136148
if (typeDefinition.IsSubclassOf(typeof(NetworkBehaviour).FullName))
137149
{
138-
150+
var skip = false;
151+
// check if contains blacklisted phrases
152+
foreach (string blacklisted in blackList)
153+
{
154+
if (fileName.ToLowerInvariant().Contains(blacklisted.ToLowerInvariant()))
155+
{
156+
skip = true;
157+
}
158+
}
159+
160+
if (skip)
161+
{
162+
break;
163+
}
164+
165+
found = true;
139166
hashSet.Add(text3);
167+
Patcher.Logger.LogMessage($"Found NetworkBehaviour({typeof(NetworkBehaviour).FullName}) in : " + fileName);
140168
break;
141169
}
142170
}
143171
}
172+
173+
/*if (!found)
174+
{
175+
Patcher.Logger.LogWarning("Did not find any NetworkBehaviours in : " + fileName);
176+
}
177+
*/
144178
}
145179
}
146180
foreach (string text4 in hashSet)
@@ -168,7 +202,7 @@ public static void Patch(string pluginPath, string managedPath)
168202
catch (Exception exception)
169203
{
170204
// error
171-
Patcher.Logger.LogWarning($"Did not patch ({Path.GetFileName(text4)}): {exception.Message} (Already patched?)");
205+
Patcher.Logger.LogWarning($"Failed to patch ({Path.GetFileName(text4)}): {exception}");
172206
success = false;
173207
}
174208

0 commit comments

Comments
 (0)