mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-30 03:32:47 +00:00
update mirror
This commit is contained in:
parent
965fe056c5
commit
c131228ca1
Binary file not shown.
Binary file not shown.
BIN
Mirror/kcp2k.dll
BIN
Mirror/kcp2k.dll
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ namespace Mirror.Weaver
|
||||
NetworkWriter networkWriter = new NetworkWriter();
|
||||
networkWriter.Write(thrusting);
|
||||
networkWriter.WritePackedUInt32((uint)spin);
|
||||
base.SendCommandInternal(cmdName, networkWriter, cmdName);
|
||||
base.SendCommandInternal(cmdName, networkWriter, channel);
|
||||
}
|
||||
|
||||
public void CallCmdThrust(float thrusting, int spin)
|
||||
@ -44,17 +44,14 @@ namespace Mirror.Weaver
|
||||
if (!NetworkBehaviourProcessor.WriteArguments(worker, writers, Log, md, RemoteCallType.Command, ref WeavingFailed))
|
||||
return null;
|
||||
|
||||
string cmdName = md.Name;
|
||||
int channel = commandAttr.GetField("channel", 0);
|
||||
bool requiresAuthority = commandAttr.GetField("requiresAuthority", true);
|
||||
|
||||
// invoke internal send and return
|
||||
// load 'base.' to call the SendCommand function with
|
||||
worker.Emit(OpCodes.Ldarg_0);
|
||||
worker.Emit(OpCodes.Ldtoken, td);
|
||||
// invokerClass
|
||||
worker.Emit(OpCodes.Call, weaverTypes.getTypeFromHandleReference);
|
||||
worker.Emit(OpCodes.Ldstr, cmdName);
|
||||
// pass full function name to avoid ClassA.Func <-> ClassB.Func collisions
|
||||
worker.Emit(OpCodes.Ldstr, md.FullName);
|
||||
// writer
|
||||
worker.Emit(OpCodes.Ldloc_0);
|
||||
worker.Emit(OpCodes.Ldc_I4, channel);
|
||||
|
@ -292,20 +292,20 @@ namespace Mirror.Weaver
|
||||
for (int i = 0; i < commands.Count; ++i)
|
||||
{
|
||||
CmdResult cmdResult = commands[i];
|
||||
GenerateRegisterCommandDelegate(cctorWorker, weaverTypes.registerCommandDelegateReference, commandInvocationFuncs[i], cmdResult);
|
||||
GenerateRegisterCommandDelegate(cctorWorker, weaverTypes.registerCommandReference, commandInvocationFuncs[i], cmdResult);
|
||||
}
|
||||
|
||||
// register all client rpcs in cctor
|
||||
for (int i = 0; i < clientRpcs.Count; ++i)
|
||||
{
|
||||
ClientRpcResult clientRpcResult = clientRpcs[i];
|
||||
GenerateRegisterRemoteDelegate(cctorWorker, weaverTypes.registerRpcDelegateReference, clientRpcInvocationFuncs[i], clientRpcResult.method.Name);
|
||||
GenerateRegisterRemoteDelegate(cctorWorker, weaverTypes.registerRpcReference, clientRpcInvocationFuncs[i], clientRpcResult.method.FullName);
|
||||
}
|
||||
|
||||
// register all target rpcs in cctor
|
||||
for (int i = 0; i < targetRpcs.Count; ++i)
|
||||
{
|
||||
GenerateRegisterRemoteDelegate(cctorWorker, weaverTypes.registerRpcDelegateReference, targetRpcInvocationFuncs[i], targetRpcs[i].Name);
|
||||
GenerateRegisterRemoteDelegate(cctorWorker, weaverTypes.registerRpcReference, targetRpcInvocationFuncs[i], targetRpcs[i].FullName);
|
||||
}
|
||||
|
||||
// add final 'Ret' instruction to cctor
|
||||
@ -358,22 +358,25 @@ namespace Mirror.Weaver
|
||||
// This generates code like:
|
||||
NetworkBehaviour.RegisterCommandDelegate(base.GetType(), "CmdThrust", new NetworkBehaviour.CmdDelegate(ShipControl.InvokeCmdCmdThrust));
|
||||
*/
|
||||
void GenerateRegisterRemoteDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, string cmdName)
|
||||
|
||||
// pass full function name to avoid ClassA.Func <-> ClassB.Func collisions
|
||||
void GenerateRegisterRemoteDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, string functionFullName)
|
||||
{
|
||||
worker.Emit(OpCodes.Ldtoken, netBehaviourSubclass);
|
||||
worker.Emit(OpCodes.Call, weaverTypes.getTypeFromHandleReference);
|
||||
worker.Emit(OpCodes.Ldstr, cmdName);
|
||||
worker.Emit(OpCodes.Ldstr, functionFullName);
|
||||
worker.Emit(OpCodes.Ldnull);
|
||||
worker.Emit(OpCodes.Ldftn, func);
|
||||
|
||||
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor);
|
||||
worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
|
||||
//
|
||||
worker.Emit(OpCodes.Call, registerMethod);
|
||||
}
|
||||
|
||||
void GenerateRegisterCommandDelegate(ILProcessor worker, MethodReference registerMethod, MethodDefinition func, CmdResult cmdResult)
|
||||
{
|
||||
string cmdName = cmdResult.method.Name;
|
||||
// pass full function name to avoid ClassA.Func <-> ClassB.Func collisions
|
||||
string cmdName = cmdResult.method.FullName;
|
||||
bool requiresAuthority = cmdResult.requiresAuthority;
|
||||
|
||||
worker.Emit(OpCodes.Ldtoken, netBehaviourSubclass);
|
||||
@ -382,7 +385,7 @@ namespace Mirror.Weaver
|
||||
worker.Emit(OpCodes.Ldnull);
|
||||
worker.Emit(OpCodes.Ldftn, func);
|
||||
|
||||
worker.Emit(OpCodes.Newobj, weaverTypes.CmdDelegateConstructor);
|
||||
worker.Emit(OpCodes.Newobj, weaverTypes.RemoteCallDelegateConstructor);
|
||||
|
||||
// requiresAuthority ? 1 : 0
|
||||
worker.Emit(requiresAuthority ? OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);
|
||||
@ -1043,7 +1046,6 @@ namespace Mirror.Weaver
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// if not SenderConnection And not TargetRpc NetworkConnection first param
|
||||
if (!isSenderConnection && isNetworkConnection && !(callType == RemoteCallType.TargetRpc && firstParam))
|
||||
{
|
||||
@ -1129,13 +1131,6 @@ namespace Mirror.Weaver
|
||||
return;
|
||||
}
|
||||
|
||||
if (names.Contains(md.Name))
|
||||
{
|
||||
Log.Error($"Duplicate ClientRpc name {md.Name}", md);
|
||||
WeavingFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool includeOwner = clientRpcAttr.GetField("includeOwner", true);
|
||||
|
||||
names.Add(md.Name);
|
||||
@ -1168,12 +1163,6 @@ namespace Mirror.Weaver
|
||||
if (!ValidateRemoteCallAndParameters(md, RemoteCallType.TargetRpc, ref WeavingFailed))
|
||||
return;
|
||||
|
||||
if (names.Contains(md.Name))
|
||||
{
|
||||
Log.Error($"Duplicate Target Rpc name {md.Name}", md);
|
||||
WeavingFailed = true;
|
||||
return;
|
||||
}
|
||||
names.Add(md.Name);
|
||||
targetRpcs.Add(md);
|
||||
|
||||
@ -1198,13 +1187,6 @@ namespace Mirror.Weaver
|
||||
if (!ValidateRemoteCallAndParameters(md, RemoteCallType.Command, ref WeavingFailed))
|
||||
return;
|
||||
|
||||
if (names.Contains(md.Name))
|
||||
{
|
||||
Log.Error($"Duplicate Command name {md.Name}", md);
|
||||
WeavingFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
bool requiresAuthority = commandAttr.GetField("requiresAuthority", true);
|
||||
|
||||
names.Add(md.Name);
|
||||
|
@ -74,17 +74,14 @@ namespace Mirror.Weaver
|
||||
if (!NetworkBehaviourProcessor.WriteArguments(worker, writers, Log, md, RemoteCallType.ClientRpc, ref WeavingFailed))
|
||||
return null;
|
||||
|
||||
string rpcName = md.Name;
|
||||
int channel = clientRpcAttr.GetField("channel", 0);
|
||||
bool includeOwner = clientRpcAttr.GetField("includeOwner", true);
|
||||
|
||||
// invoke SendInternal and return
|
||||
// this
|
||||
worker.Emit(OpCodes.Ldarg_0);
|
||||
worker.Emit(OpCodes.Ldtoken, td);
|
||||
// invokerClass
|
||||
worker.Emit(OpCodes.Call, weaverTypes.getTypeFromHandleReference);
|
||||
worker.Emit(OpCodes.Ldstr, rpcName);
|
||||
// pass full function name to avoid ClassA.Func <-> ClassB.Func collisions
|
||||
worker.Emit(OpCodes.Ldstr, md.FullName);
|
||||
// writer
|
||||
worker.Emit(OpCodes.Ldloc_0);
|
||||
worker.Emit(OpCodes.Ldc_I4, channel);
|
||||
|
@ -105,8 +105,6 @@ namespace Mirror.Weaver
|
||||
if (!NetworkBehaviourProcessor.WriteArguments(worker, writers, Log, md, RemoteCallType.TargetRpc, ref WeavingFailed))
|
||||
return null;
|
||||
|
||||
string rpcName = md.Name;
|
||||
|
||||
// invoke SendInternal and return
|
||||
// this
|
||||
worker.Emit(OpCodes.Ldarg_0);
|
||||
@ -120,10 +118,8 @@ namespace Mirror.Weaver
|
||||
// null
|
||||
worker.Emit(OpCodes.Ldnull);
|
||||
}
|
||||
worker.Emit(OpCodes.Ldtoken, td);
|
||||
// invokerClass
|
||||
worker.Emit(OpCodes.Call, weaverTypes.getTypeFromHandleReference);
|
||||
worker.Emit(OpCodes.Ldstr, rpcName);
|
||||
// pass full function name to avoid ClassA.Func <-> ClassB.Func collisions
|
||||
worker.Emit(OpCodes.Ldstr, md.FullName);
|
||||
// writer
|
||||
worker.Emit(OpCodes.Ldloc_0);
|
||||
worker.Emit(OpCodes.Ldc_I4, targetRpcAttr.GetField("channel", 0));
|
||||
|
@ -21,7 +21,6 @@ namespace Mirror.Weaver
|
||||
|
||||
WeaverTypes weaverTypes;
|
||||
SyncVarAccessLists syncVarAccessLists;
|
||||
IAssemblyResolver Resolver;
|
||||
AssemblyDefinition CurrentAssembly;
|
||||
Writers writers;
|
||||
Readers readers;
|
||||
@ -138,7 +137,6 @@ namespace Mirror.Weaver
|
||||
modified = false;
|
||||
try
|
||||
{
|
||||
Resolver = resolver;
|
||||
CurrentAssembly = assembly;
|
||||
|
||||
// fix "No writer found for ..." error
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Mono.Cecil;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror.Weaver
|
||||
@ -15,7 +16,7 @@ namespace Mirror.Weaver
|
||||
|
||||
public MethodReference NetworkClientConnectionReference;
|
||||
|
||||
public MethodReference CmdDelegateConstructor;
|
||||
public MethodReference RemoteCallDelegateConstructor;
|
||||
|
||||
public MethodReference NetworkServerGetActive;
|
||||
public MethodReference NetworkServerGetLocalClientActive;
|
||||
@ -41,8 +42,8 @@ namespace Mirror.Weaver
|
||||
public MethodReference syncVarNetworkBehaviourEqualReference;
|
||||
public MethodReference setSyncVarNetworkBehaviourReference;
|
||||
public MethodReference getSyncVarNetworkBehaviourReference;
|
||||
public MethodReference registerCommandDelegateReference;
|
||||
public MethodReference registerRpcDelegateReference;
|
||||
public MethodReference registerCommandReference;
|
||||
public MethodReference registerRpcReference;
|
||||
public MethodReference getTypeFromHandleReference;
|
||||
public MethodReference logErrorReference;
|
||||
public MethodReference logWarningReference;
|
||||
@ -77,11 +78,11 @@ namespace Mirror.Weaver
|
||||
TypeReference NetworkClientType = Import(typeof(NetworkClient));
|
||||
NetworkClientGetActive = Resolvers.ResolveMethod(NetworkClientType, assembly, Log, "get_active", ref WeavingFailed);
|
||||
|
||||
TypeReference cmdDelegateReference = Import<RemoteCalls.CmdDelegate>();
|
||||
CmdDelegateConstructor = Resolvers.ResolveMethod(cmdDelegateReference, assembly, Log, ".ctor", ref WeavingFailed);
|
||||
TypeReference RemoteCallDelegateType = Import<RemoteCalls.RemoteCallDelegate>();
|
||||
RemoteCallDelegateConstructor = Resolvers.ResolveMethod(RemoteCallDelegateType, assembly, Log, ".ctor", ref WeavingFailed);
|
||||
|
||||
TypeReference NetworkBehaviourType = Import<NetworkBehaviour>();
|
||||
TypeReference RemoteCallHelperType = Import(typeof(RemoteCalls.RemoteCallHelper));
|
||||
TypeReference RemoteProcedureCallsType = Import(typeof(RemoteCalls.RemoteProcedureCalls));
|
||||
|
||||
TypeReference ScriptableObjectType = Import<UnityEngine.ScriptableObject>();
|
||||
|
||||
@ -112,8 +113,8 @@ namespace Mirror.Weaver
|
||||
setSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, Log, "SetSyncVarNetworkBehaviour", ref WeavingFailed);
|
||||
getSyncVarNetworkBehaviourReference = Resolvers.ResolveMethod(NetworkBehaviourType, assembly, Log, "GetSyncVarNetworkBehaviour", ref WeavingFailed);
|
||||
|
||||
registerCommandDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, assembly, Log, "RegisterCommandDelegate", ref WeavingFailed);
|
||||
registerRpcDelegateReference = Resolvers.ResolveMethod(RemoteCallHelperType, assembly, Log, "RegisterRpcDelegate", ref WeavingFailed);
|
||||
registerCommandReference = Resolvers.ResolveMethod(RemoteProcedureCallsType, assembly, Log, "RegisterCommand", ref WeavingFailed);
|
||||
registerRpcReference = Resolvers.ResolveMethod(RemoteProcedureCallsType, assembly, Log, "RegisterRpc", ref WeavingFailed);
|
||||
|
||||
TypeReference unityDebug = Import(typeof(UnityEngine.Debug));
|
||||
// these have multiple methods with same name, so need to check parameters too
|
||||
@ -145,6 +146,17 @@ namespace Mirror.Weaver
|
||||
}),
|
||||
ref WeavingFailed);
|
||||
|
||||
/*
|
||||
// [InitializeOnLoadMethod]
|
||||
// 'UnityEditor' is not available in builds.
|
||||
// we can only import this attribute if we are in an Editor assembly.
|
||||
if (Helpers.IsEditorAssembly(assembly))
|
||||
{
|
||||
TypeReference initializeOnLoadMethodAttributeRef = Import(typeof(InitializeOnLoadMethodAttribute));
|
||||
initializeOnLoadMethodAttribute = initializeOnLoadMethodAttributeRef.Resolve();
|
||||
}
|
||||
*/
|
||||
|
||||
// [RuntimeInitializeOnLoadMethod]
|
||||
TypeReference runtimeInitializeOnLoadMethodAttributeRef = Import(typeof(RuntimeInitializeOnLoadMethodAttribute));
|
||||
runtimeInitializeOnLoadMethodAttribute = runtimeInitializeOnLoadMethodAttributeRef.Resolve();
|
||||
|
@ -250,7 +250,6 @@ namespace Mirror.Weaver
|
||||
// Find all fields in type and write them
|
||||
bool WriteAllFields(TypeReference variable, ILProcessor worker, ref bool WeavingFailed)
|
||||
{
|
||||
uint fields = 0;
|
||||
foreach (FieldDefinition field in variable.FindAllPublicFields())
|
||||
{
|
||||
MethodReference writeFunc = GetWriteFunc(field.FieldType, ref WeavingFailed);
|
||||
@ -259,7 +258,6 @@ namespace Mirror.Weaver
|
||||
|
||||
FieldReference fieldRef = assembly.MainModule.ImportReference(field);
|
||||
|
||||
fields++;
|
||||
worker.Emit(OpCodes.Ldarg_0);
|
||||
worker.Emit(OpCodes.Ldarg_1);
|
||||
worker.Emit(OpCodes.Ldfld, fieldRef);
|
||||
|
Loading…
x
Reference in New Issue
Block a user