Skip to content

Commit

Permalink
fix: #2579 (no writer found): Weaver rollback to september 19, 2020
Browse files Browse the repository at this point in the history
before 6cfdd64 "Simplify type lookup in weaver (#2258)"
=> adjusted for requireAuthority double negative already
=> adjusted for weaver.Emit already
  • Loading branch information
miwarnec committed Mar 22, 2021
1 parent b7c63c3 commit 79a67d7
Show file tree
Hide file tree
Showing 122 changed files with 3,241 additions and 1,682 deletions.
8 changes: 8 additions & 0 deletions Assets/Mirror/Authenticators/BasicAuthenticator.cs
Expand Up @@ -21,12 +21,20 @@ public struct AuthRequestMessage : NetworkMessage
// for example, you might want to pass the accessToken if using oauth
public string authUsername;
public string authPassword;

// weaver populates (de)serialize automatically
public void Deserialize(NetworkReader reader) {}
public void Serialize(NetworkWriter writer) {}
}

public struct AuthResponseMessage : NetworkMessage
{
public byte code;
public string message;

// weaver populates (de)serialize automatically
public void Deserialize(NetworkReader reader) {}
public void Serialize(NetworkWriter writer) {}
}

#endregion
Expand Down
16 changes: 9 additions & 7 deletions Assets/Mirror/Components/Discovery/NetworkDiscoveryBase.cs
Expand Up @@ -18,8 +18,8 @@ namespace Mirror.Discovery
[DisallowMultipleComponent]
[HelpURL("https://mirror-networking.com/docs/Articles/Components/NetworkDiscovery.html")]
public abstract class NetworkDiscoveryBase<Request, Response> : MonoBehaviour
where Request : NetworkMessage
where Response : NetworkMessage
where Request : NetworkMessage, new()
where Response : NetworkMessage, new()
{
public static bool SupportedOnThisPlatform { get { return Application.platform != RuntimePlatform.WebGLPlayer; } }

Expand Down Expand Up @@ -169,7 +169,8 @@ async Task ReceiveRequestAsync(UdpClient udpClient)
throw new ProtocolViolationException("Invalid handshake");
}

Request request = networkReader.Read<Request>();
Request request = new Request();
request.Deserialize(networkReader);

ProcessClientRequest(request, udpReceiveResult.RemoteEndPoint);
}
Expand All @@ -182,7 +183,7 @@ async Task ReceiveRequestAsync(UdpClient udpClient)
/// Override if you wish to ignore server requests based on
/// custom criteria such as language, full server game mode or difficulty
/// </remarks>
/// <param name="request">Request coming from client</param>
/// <param name="request">Request comming from client</param>
/// <param name="endpoint">Address of the client that sent the request</param>
protected virtual void ProcessClientRequest(Request request, IPEndPoint endpoint)
{
Expand All @@ -197,7 +198,7 @@ protected virtual void ProcessClientRequest(Request request, IPEndPoint endpoint
{
writer.WriteInt64(secretHandshake);

writer.Write(info);
info.Serialize(writer);

ArraySegment<byte> data = writer.ToArraySegment();
// signature matches
Expand Down Expand Up @@ -308,7 +309,7 @@ public void BroadcastDiscoveryRequest()
{
Request request = GetRequest();

writer.Write(request);
request.Serialize(writer);

ArraySegment<byte> data = writer.ToArraySegment();

Expand Down Expand Up @@ -342,7 +343,8 @@ async Task ReceiveGameBroadcastAsync(UdpClient udpClient)
if (networkReader.ReadInt64() != secretHandshake)
return;

Response response = networkReader.Read<Response>();
Response response = new Response();
response.Deserialize(networkReader);

ProcessResponse(response, udpReceiveResult.RemoteEndPoint);
}
Expand Down
7 changes: 6 additions & 1 deletion Assets/Mirror/Components/Discovery/ServerRequest.cs
@@ -1,4 +1,9 @@
namespace Mirror.Discovery
{
public struct ServerRequest : NetworkMessage {}
public struct ServerRequest : NetworkMessage
{
// weaver populates (de)serialize automatically
public void Deserialize(NetworkReader reader) {}
public void Serialize(NetworkWriter writer) {}
}
}
6 changes: 5 additions & 1 deletion Assets/Mirror/Components/Discovery/ServerResponse.cs
Expand Up @@ -14,5 +14,9 @@ public struct ServerResponse : NetworkMessage

// Prevent duplicate server appearance when a connection can be made via LAN on multiple NICs
public long serverId;

// weaver populates (de)serialize automatically
public void Deserialize(NetworkReader reader) {}
public void Serialize(NetworkWriter writer) {}
}
}
}
38 changes: 24 additions & 14 deletions Assets/Mirror/Editor/Weaver/CompilationFinishedHook.cs
Expand Up @@ -14,14 +14,22 @@ public static class CompilationFinishedHook
const string MirrorRuntimeAssemblyName = "Mirror";
const string MirrorWeaverAssemblyName = "Mirror.Weaver";

// delegate for subscription to Weaver debug messages
public static Action<string> OnWeaverMessage;
// delegate for subscription to Weaver warning messages
public static Action<string> OnWeaverWarning;
// delete for subscription to Weaver error messages
public static Action<string> OnWeaverError;

// controls whether we weave any assemblies when CompilationPipeline delegates are invoked
public static bool WeaverEnabled { get; set; }
// controls weather Weaver errors are reported direct to the Unity console (tests enable this)
public static bool UnityLogEnabled = true;

// holds the result status of our latest Weave operation
// NOTE: WeaveFailed is critical to unit tests, but isn't used for anything else.
public static bool WeaveFailed { get; private set; }

// warning message handler that also calls OnWarningMethod delegate
static void HandleWarning(string msg)
{
Expand Down Expand Up @@ -134,34 +142,36 @@ static void OnCompilationFinished(string assemblyPath, CompilerMessage[] message
}

HashSet<string> dependencyPaths = GetDependecyPaths(assemblyPath);
dependencyPaths.Add(Path.GetDirectoryName(mirrorRuntimeDll));
dependencyPaths.Add(Path.GetDirectoryName(unityEngineCoreModuleDLL));
Log.Warning = HandleWarning;
Log.Error = HandleError;

if (!Weaver.WeaveAssembly(assemblyPath, dependencyPaths.ToArray()))
// passing null in the outputDirectory param will do an in-place update of the assembly
if (Weaver.Process(unityEngineCoreModuleDLL, mirrorRuntimeDll, null, new[] { assemblyPath }, dependencyPaths.ToArray(), HandleWarning, HandleError))
{
// NOTE: WeaveFailed is critical for unit tests but isn't used elsewhere
WeaveFailed = false;
}
else
{
// Set false...will be checked in \Editor\EnterPlayModeSettingsCheck.CheckSuccessfulWeave()
SessionState.SetBool("MIRROR_WEAVE_SUCCESS", false);

WeaveFailed = true;
if (UnityLogEnabled) Debug.LogError("Weaving failed for: " + assemblyPath);
}
}

static HashSet<string> GetDependecyPaths(string assemblyPath)
{
// build directory list for later asm/symbol resolving using CompilationPipeline refs
HashSet<string> dependencyPaths = new HashSet<string>
{
Path.GetDirectoryName(assemblyPath)
};
HashSet<string> dependencyPaths = new HashSet<string>();
dependencyPaths.Add(Path.GetDirectoryName(assemblyPath));
foreach (UnityAssembly unityAsm in CompilationPipeline.GetAssemblies())
{
if (unityAsm.outputPath == assemblyPath)
if (unityAsm.outputPath != assemblyPath)
continue;

foreach (string unityAsmRef in unityAsm.compiledAssemblyReferences)
{
foreach (string unityAsmRef in unityAsm.compiledAssemblyReferences)
{
dependencyPaths.Add(Path.GetDirectoryName(unityAsmRef));
}
dependencyPaths.Add(Path.GetDirectoryName(unityAsmRef));
}
}

Expand Down

0 comments on commit 79a67d7

Please sign in to comment.