Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Upgrade FishNet & Unity (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry authored Jan 30, 2024
2 parents 290f9c8 + fb9d193 commit ba8c179
Showing 278 changed files with 8,630 additions and 4,212 deletions.
4 changes: 2 additions & 2 deletions unity/tanks-fishnet/Assets/DefaultPrefabObjects.asset
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -41,7 +41,6 @@ public static MethodReference GetMethodReferenceInBase(this TypeDefinition td, C
if (baseMd == null)
return null;


MethodReference baseMr;
TypeReference baseTr = td.BaseType;
if (baseTr.CachedResolve(session).HasGenericParameters)
Original file line number Diff line number Diff line change
@@ -33,14 +33,6 @@ public static string GetFullnameWithoutBrackets(this TypeReference tr)
return str;
}

/// <summary>
/// Returns a method in the next base class.
/// </summary>
public static MethodReference GetMethodInBase(this TypeReference tr, CodegenSession session, string methodName)
{
return tr.CachedResolve(session).GetMethodInBase(session, methodName);
}

/// <summary>
/// Makes a GenericInstanceType.
/// </summary>
Original file line number Diff line number Diff line change
@@ -31,13 +31,8 @@ public override bool ImportReferences()
TargetRpcAttribute_FullName = typeof(TargetRpcAttribute).FullName;
SyncVarAttribute_FullName = typeof(SyncVarAttribute).FullName;
SyncObjectAttribute_FullName = typeof(SyncObjectAttribute).FullName;
#if !PREDICTION_V2
ReplicateAttribute_FullName = typeof(ReplicateAttribute).FullName;
ReconcileAttribute_FullName = typeof(ReconcileAttribute).FullName;
#else
ReplicateAttribute_FullName = typeof(ReplicateV2Attribute).FullName;
ReconcileAttribute_FullName = typeof(ReconcileV2Attribute).FullName;
#endif
return true;
}

Original file line number Diff line number Diff line change
@@ -400,6 +400,8 @@ public static FieldReference GetFieldReference(this TypeDefinition typeDef, stri
/// <returns></returns>
public static bool ImplementsInterface<TInterface>(this TypeDefinition typeDef)
{
if (typeDef.Interfaces == null)
return false;
for (int i = 0; i < typeDef.Interfaces.Count; i++)
{
if (typeDef.Interfaces[i].InterfaceType.Is<TInterface>())
Original file line number Diff line number Diff line change
@@ -23,17 +23,11 @@ internal class NetworkBehaviourHelper : CodegenBase
internal string FullName;
//Prediction.
public string ClearReplicateCache_MethodName = nameof(NetworkBehaviour.ClearReplicateCache_Virtual);
#if PREDICTION_V2
public string Reconcile_Client_Start_MethodName = nameof(NetworkBehaviour.Reconcile_Client_Start);
public string Replicate_Replay_Start_MethodName = nameof(NetworkBehaviour.Replicate_Replay_Start);
#endif
public MethodReference Replicate_NonOwner_MethodRef;
public MethodReference Replicate_Owner_MethodRef;
public MethodReference Replicate_Reader_MethodRef;
#if !PREDICTION_V2
public MethodReference Replicate_ExitEarly_A_MethodRef;
public MethodReference Reconcile_ExitEarly_A_MethodRef;
#endif
public MethodReference Reconcile_Server_MethodRef;
public FieldReference UsesPrediction_FieldRef;
public MethodReference Replicate_Replay_Start_MethodRef;
@@ -56,9 +50,9 @@ internal class NetworkBehaviourHelper : CodegenBase
public MethodReference ServerRpcDelegate_Ctor_MethodRef;
public MethodReference ClientRpcDelegate_Ctor_MethodRef;
//Is checks.
public MethodReference IsClient_MethodRef;
public MethodReference IsClientInitialized_MethodRef;
public MethodReference IsOwner_MethodRef;
public MethodReference IsServer_MethodRef;
public MethodReference IsServerInitialized_MethodRef;
public MethodReference IsHost_MethodRef;
public MethodReference IsNetworked_MethodRef;
//Misc.
@@ -116,37 +110,22 @@ public override bool ImportReferences()
else if (mi.Name == nameof(NetworkBehaviour.SendTargetRpc))
SendTargetRpc_MethodRef = base.ImportReference(mi);
//Prediction.
#if !PREDICTION_V2
else if (mi.Name == nameof(NetworkBehaviour.Replicate_ExitEarly_A))
Replicate_ExitEarly_A_MethodRef = base.ImportReference(mi);
#endif
else if (mi.Name == nameof(NetworkBehaviour.Replicate_NonOwner))
Replicate_NonOwner_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Reader))
Replicate_Reader_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Reader))
Reconcile_Reader_MethodRef = base.ImportReference(mi);
#if PREDICTION_V2
else if (mi.Name == Replicate_Replay_Start_MethodName)
Replicate_Replay_Start_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Replay))
Replicate_Replay_MethodRef = base.ImportReference(mi);
#endif
#if !PREDICTION_V2
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_ExitEarly_A))
Reconcile_ExitEarly_A_MethodRef = base.ImportReference(mi);
#endif
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Server))
Reconcile_Server_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Owner))
Replicate_Owner_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Client))
Reconcile_Client_MethodRef = base.ImportReference(mi);
//#if PREDICTION_V2
// else if (mi.Name == nameof(NetworkBehaviour.Replicate_Server_SendToSpectators_Internal))
// Replicate_Server_SendToSpectators_MethodRef = base.ImportReference(mi);
//#endif
//Misc.
else if (mi.Name == nameof(NetworkBehaviour.OwnerMatches))
OwnerMatches_MethodRef = base.ImportReference(mi);
else if (mi.Name == nameof(NetworkBehaviour.RegisterSyncVarRead))
@@ -160,10 +139,10 @@ public override bool ImportReferences()
foreach (PropertyInfo pi in networkBehaviourType.GetProperties((BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)))
{
//Server/Client states.
if (pi.Name == nameof(NetworkBehaviour.IsClient))
IsClient_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsServer))
IsServer_MethodRef = base.ImportReference(pi.GetMethod);
if (pi.Name == nameof(NetworkBehaviour.IsClientInitialized))
IsClientInitialized_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsServerInitialized))
IsServerInitialized_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsHost))
IsHost_MethodRef = base.ImportReference(pi.GetMethod);
else if (pi.Name == nameof(NetworkBehaviour.IsOwner))
@@ -180,17 +159,6 @@ public override bool ImportReferences()
TimeManager_MethodRef = base.ImportReference(pi.GetMethod);
}

#if PREDICTION_V2
foreach (FieldInfo fi in networkBehaviourType.GetFields((BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)))
{
if (fi.Name == nameof(NetworkBehaviour.UsesPrediction))
{
UsesPrediction_FieldRef = base.ImportReference(fi);
break;
}
}
#endif

return true;
}

@@ -358,9 +326,7 @@ internal Instruction CreateRemoteClientIsOwnerCheck(ILProcessor processor, Param
/// <summary>
/// Creates exit method condition if not client.
/// </summary>
/// <param name="processor"></param>
/// <param name="retInstruction"></param>
/// <param name="warn"></param>
/// <param name="useStatic">When true InstanceFinder.IsClient is used, when false base.IsClientInitialized is used.</param>
internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggingType, bool useStatic, bool insertFirst, bool checkIsNetworked)
{
/* This is placed after the if check.
@@ -379,18 +345,18 @@ internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggin
{
instructions.Add(processor.Create(OpCodes.Ldarg_0)); //argument: this
//If (!base.IsClient)
instructions.Add(processor.Create(OpCodes.Call, IsClient_MethodRef));
instructions.Add(processor.Create(OpCodes.Call, IsClientInitialized_MethodRef));
}
//Checking instanceFinder.
else
{
{
instructions.Add(processor.Create(OpCodes.Call, base.GetClass<ObjectHelper>().InstanceFinder_IsClient_MethodRef));
}
instructions.Add(processor.Create(OpCodes.Brtrue, endIf));
//If warning then also append warning text.
if (loggingType != LoggingType.Off)
{
string msg = $"Cannot complete action because client is not active. This may also occur if the object is not yet initialized or if it does not contain a NetworkObject component. {DISABLE_LOGGING_TEXT}.";
string msg = $"Cannot complete action because client is not active. This may also occur if the object is not yet initialized, has deinitialized, or if it does not contain a NetworkObject component.";
instructions.AddRange(base.GetClass<GeneralHelper>().LogMessage(methodDef, msg, loggingType));
}
//Add return.
@@ -412,8 +378,7 @@ internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggin
/// <summary>
/// Creates exit method condition if not server.
/// </summary>
/// <param name="processor"></param>
/// <param name="warn"></param>
/// <param name="useStatic">When true InstanceFinder.IsServer is used, when false base.IsServerInitialized is used.</param>
internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggingType, bool useStatic, bool insertFirst, bool checkIsNetworked)
{
/* This is placed after the if check.
@@ -431,7 +396,7 @@ internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggin
{
instructions.Add(processor.Create(OpCodes.Ldarg_0)); //argument: this
//If (!base.IsServer)
instructions.Add(processor.Create(OpCodes.Call, IsServer_MethodRef));
instructions.Add(processor.Create(OpCodes.Call, IsServerInitialized_MethodRef));
}
//Checking instanceFinder.
else
@@ -442,7 +407,7 @@ internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggin
//If warning then also append warning text.
if (loggingType != LoggingType.Off)
{
string msg = $"Cannot complete action because server is not active. This may also occur if the object is not yet initialized or if it does not contain a NetworkObject component. {DISABLE_LOGGING_TEXT}";
string msg = $"Cannot complete action because server is not active. This may also occur if the object is not yet initialized, has deinitialized, or if it does not contain a NetworkObject component.";
instructions.AddRange(base.GetClass<GeneralHelper>().LogMessage(methodDef, msg, loggingType));
}
//Add return.
Original file line number Diff line number Diff line change
@@ -14,23 +14,29 @@ internal class ObjectHelper : CodegenBase
{
#region Reflection references.
//Fullnames.
public string SyncList_Name;
public string SyncDictionary_Name;
public string SyncHashSet_Name;
public string SyncVar_Name { get; private set; }
public string SyncList_Name { get; private set; }
public string SyncDictionary_Name { get; private set; }
public string SyncHashSet_Name { get; private set; }
//Is checks.
public MethodReference InstanceFinder_IsServer_MethodRef;
public MethodReference InstanceFinder_IsClient_MethodRef;
public MethodReference InstanceFinder_IsServer_MethodRef { get; private set; }
public MethodReference InstanceFinder_IsClient_MethodRef { get; private set; }
//Misc.
public TypeReference NetworkBehaviour_TypeRef;
public MethodReference NetworkConnection_IsValid_MethodRef;
public MethodReference NetworkConnection_IsActive_MethodRef;
public MethodReference Dictionary_Add_UShort_SyncBase_MethodRef;
public MethodReference NetworkConnection_GetIsLocalClient_MethodRef;
public TypeReference NetworkBehaviour_TypeRef { get; private set; }
public MethodReference NetworkConnection_IsValid_MethodRef { get; private set; }
public MethodReference NetworkConnection_IsActive_MethodRef { get; private set; }
public MethodReference Dictionary_Add_UShort_SyncBase_MethodRef { get; private set; }
public MethodReference NetworkConnection_GetIsLocalClient_MethodRef { get; private set; }
#endregion

public override bool ImportReferences()
{
Type tmpType;
/* SyncVar names. */
//SyncVar.
tmpType = typeof(SyncVar<>);
base.ImportReference(tmpType);
SyncVar_Name = tmpType.Name;
/* SyncObject names. */
//SyncList.
tmpType = typeof(SyncList<>);
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ internal class CreatedSyncVar
public readonly MethodReference SetSyncIndexMr;
public readonly MethodReference ConstructorMr;
public readonly GenericInstanceType SyncVarGit;
public FieldDefinition SyncVarClassFd { get; private set; }

public MethodReference HookMr;
public CreatedSyncVar(GenericInstanceType syncVarGit, TypeDefinition variableTd, MethodReference getValueMr, MethodReference setValueMr, MethodReference setSyncIndexMr,MethodReference hookMr, MethodReference constructorMr)
{
@@ -24,6 +26,11 @@ public CreatedSyncVar(GenericInstanceType syncVarGit, TypeDefinition variableTd,
HookMr = hookMr;
ConstructorMr = constructorMr;
}

public void SetSyncVarClassField(FieldDefinition fd)
{
SyncVarClassFd = fd;
}
}


Original file line number Diff line number Diff line change
@@ -88,10 +88,12 @@ public SerializerType GetSerializerType(TypeReference objectTr, bool writer, out
{
return SerializerType.List;
}
else if (objectTd.Is(typeof(ListCache<>)))
#pragma warning disable CS0618 // Type or member is obsolete
else if (objectTd.Is(typeof(ListCache<>))) //Remove on 2024/01/01
{
return SerializerType.ListCache;
}
#pragma warning restore CS0618 // Type or member is obsolete
else if (objectTd.InheritsFrom<NetworkBehaviour>(base.Session))
{
return SerializerType.NetworkBehaviour;
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using Unity.CompilationPipeline.Common.ILPostProcessing;

Loading

0 comments on commit ba8c179

Please sign in to comment.