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

Commit ba8c179

Browse files
authored
Upgrade FishNet & Unity (#16)
2 parents 290f9c8 + fb9d193 commit ba8c179

File tree

278 files changed

+8630
-4212
lines changed

Some content is hidden

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

278 files changed

+8630
-4212
lines changed
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:0ec6dda91297b14469f6c4db7345bdd39169c0748f03d40727509af175f6f17a
3-
size 1384
2+
oid sha256:b2da32cdb514a012a5a953f736a9142f4470131b31cc60298713c51cc4d29e4d
3+
size 1633

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Extension/TypeDefinitionExtensions.cs

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public static MethodReference GetMethodReferenceInBase(this TypeDefinition td, C
4141
if (baseMd == null)
4242
return null;
4343

44-
4544
MethodReference baseMr;
4645
TypeReference baseTr = td.BaseType;
4746
if (baseTr.CachedResolve(session).HasGenericParameters)

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Extension/TypeReferenceExtensions.cs

-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ public static string GetFullnameWithoutBrackets(this TypeReference tr)
3333
return str;
3434
}
3535

36-
/// <summary>
37-
/// Returns a method in the next base class.
38-
/// </summary>
39-
public static MethodReference GetMethodInBase(this TypeReference tr, CodegenSession session, string methodName)
40-
{
41-
return tr.CachedResolve(session).GetMethodInBase(session, methodName);
42-
}
43-
4436
/// <summary>
4537
/// Makes a GenericInstanceType.
4638
/// </summary>

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/AttributeHelper.cs

-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,8 @@ public override bool ImportReferences()
3131
TargetRpcAttribute_FullName = typeof(TargetRpcAttribute).FullName;
3232
SyncVarAttribute_FullName = typeof(SyncVarAttribute).FullName;
3333
SyncObjectAttribute_FullName = typeof(SyncObjectAttribute).FullName;
34-
#if !PREDICTION_V2
3534
ReplicateAttribute_FullName = typeof(ReplicateAttribute).FullName;
3635
ReconcileAttribute_FullName = typeof(ReconcileAttribute).FullName;
37-
#else
38-
ReplicateAttribute_FullName = typeof(ReplicateV2Attribute).FullName;
39-
ReconcileAttribute_FullName = typeof(ReconcileV2Attribute).FullName;
40-
#endif
4136
return true;
4237
}
4338

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/Extension/TypeDefinitionExtensions.cs

+2
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ public static FieldReference GetFieldReference(this TypeDefinition typeDef, stri
400400
/// <returns></returns>
401401
public static bool ImplementsInterface<TInterface>(this TypeDefinition typeDef)
402402
{
403+
if (typeDef.Interfaces == null)
404+
return false;
403405
for (int i = 0; i < typeDef.Interfaces.Count; i++)
404406
{
405407
if (typeDef.Interfaces[i].InterfaceType.Is<TInterface>())

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/NetworkBehaviourHelper.cs

+13-48
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,11 @@ internal class NetworkBehaviourHelper : CodegenBase
2323
internal string FullName;
2424
//Prediction.
2525
public string ClearReplicateCache_MethodName = nameof(NetworkBehaviour.ClearReplicateCache_Virtual);
26-
#if PREDICTION_V2
27-
public string Reconcile_Client_Start_MethodName = nameof(NetworkBehaviour.Reconcile_Client_Start);
28-
public string Replicate_Replay_Start_MethodName = nameof(NetworkBehaviour.Replicate_Replay_Start);
29-
#endif
3026
public MethodReference Replicate_NonOwner_MethodRef;
3127
public MethodReference Replicate_Owner_MethodRef;
3228
public MethodReference Replicate_Reader_MethodRef;
33-
#if !PREDICTION_V2
3429
public MethodReference Replicate_ExitEarly_A_MethodRef;
3530
public MethodReference Reconcile_ExitEarly_A_MethodRef;
36-
#endif
3731
public MethodReference Reconcile_Server_MethodRef;
3832
public FieldReference UsesPrediction_FieldRef;
3933
public MethodReference Replicate_Replay_Start_MethodRef;
@@ -56,9 +50,9 @@ internal class NetworkBehaviourHelper : CodegenBase
5650
public MethodReference ServerRpcDelegate_Ctor_MethodRef;
5751
public MethodReference ClientRpcDelegate_Ctor_MethodRef;
5852
//Is checks.
59-
public MethodReference IsClient_MethodRef;
53+
public MethodReference IsClientInitialized_MethodRef;
6054
public MethodReference IsOwner_MethodRef;
61-
public MethodReference IsServer_MethodRef;
55+
public MethodReference IsServerInitialized_MethodRef;
6256
public MethodReference IsHost_MethodRef;
6357
public MethodReference IsNetworked_MethodRef;
6458
//Misc.
@@ -116,37 +110,22 @@ public override bool ImportReferences()
116110
else if (mi.Name == nameof(NetworkBehaviour.SendTargetRpc))
117111
SendTargetRpc_MethodRef = base.ImportReference(mi);
118112
//Prediction.
119-
#if !PREDICTION_V2
120113
else if (mi.Name == nameof(NetworkBehaviour.Replicate_ExitEarly_A))
121114
Replicate_ExitEarly_A_MethodRef = base.ImportReference(mi);
122-
#endif
123115
else if (mi.Name == nameof(NetworkBehaviour.Replicate_NonOwner))
124116
Replicate_NonOwner_MethodRef = base.ImportReference(mi);
125117
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Reader))
126118
Replicate_Reader_MethodRef = base.ImportReference(mi);
127119
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Reader))
128120
Reconcile_Reader_MethodRef = base.ImportReference(mi);
129-
#if PREDICTION_V2
130-
else if (mi.Name == Replicate_Replay_Start_MethodName)
131-
Replicate_Replay_Start_MethodRef = base.ImportReference(mi);
132-
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Replay))
133-
Replicate_Replay_MethodRef = base.ImportReference(mi);
134-
#endif
135-
#if !PREDICTION_V2
136121
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_ExitEarly_A))
137122
Reconcile_ExitEarly_A_MethodRef = base.ImportReference(mi);
138-
#endif
139123
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Server))
140124
Reconcile_Server_MethodRef = base.ImportReference(mi);
141125
else if (mi.Name == nameof(NetworkBehaviour.Replicate_Owner))
142126
Replicate_Owner_MethodRef = base.ImportReference(mi);
143127
else if (mi.Name == nameof(NetworkBehaviour.Reconcile_Client))
144128
Reconcile_Client_MethodRef = base.ImportReference(mi);
145-
//#if PREDICTION_V2
146-
// else if (mi.Name == nameof(NetworkBehaviour.Replicate_Server_SendToSpectators_Internal))
147-
// Replicate_Server_SendToSpectators_MethodRef = base.ImportReference(mi);
148-
//#endif
149-
//Misc.
150129
else if (mi.Name == nameof(NetworkBehaviour.OwnerMatches))
151130
OwnerMatches_MethodRef = base.ImportReference(mi);
152131
else if (mi.Name == nameof(NetworkBehaviour.RegisterSyncVarRead))
@@ -160,10 +139,10 @@ public override bool ImportReferences()
160139
foreach (PropertyInfo pi in networkBehaviourType.GetProperties((BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)))
161140
{
162141
//Server/Client states.
163-
if (pi.Name == nameof(NetworkBehaviour.IsClient))
164-
IsClient_MethodRef = base.ImportReference(pi.GetMethod);
165-
else if (pi.Name == nameof(NetworkBehaviour.IsServer))
166-
IsServer_MethodRef = base.ImportReference(pi.GetMethod);
142+
if (pi.Name == nameof(NetworkBehaviour.IsClientInitialized))
143+
IsClientInitialized_MethodRef = base.ImportReference(pi.GetMethod);
144+
else if (pi.Name == nameof(NetworkBehaviour.IsServerInitialized))
145+
IsServerInitialized_MethodRef = base.ImportReference(pi.GetMethod);
167146
else if (pi.Name == nameof(NetworkBehaviour.IsHost))
168147
IsHost_MethodRef = base.ImportReference(pi.GetMethod);
169148
else if (pi.Name == nameof(NetworkBehaviour.IsOwner))
@@ -180,17 +159,6 @@ public override bool ImportReferences()
180159
TimeManager_MethodRef = base.ImportReference(pi.GetMethod);
181160
}
182161

183-
#if PREDICTION_V2
184-
foreach (FieldInfo fi in networkBehaviourType.GetFields((BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic)))
185-
{
186-
if (fi.Name == nameof(NetworkBehaviour.UsesPrediction))
187-
{
188-
UsesPrediction_FieldRef = base.ImportReference(fi);
189-
break;
190-
}
191-
}
192-
#endif
193-
194162
return true;
195163
}
196164

@@ -358,9 +326,7 @@ internal Instruction CreateRemoteClientIsOwnerCheck(ILProcessor processor, Param
358326
/// <summary>
359327
/// Creates exit method condition if not client.
360328
/// </summary>
361-
/// <param name="processor"></param>
362-
/// <param name="retInstruction"></param>
363-
/// <param name="warn"></param>
329+
/// <param name="useStatic">When true InstanceFinder.IsClient is used, when false base.IsClientInitialized is used.</param>
364330
internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggingType, bool useStatic, bool insertFirst, bool checkIsNetworked)
365331
{
366332
/* This is placed after the if check.
@@ -379,18 +345,18 @@ internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggin
379345
{
380346
instructions.Add(processor.Create(OpCodes.Ldarg_0)); //argument: this
381347
//If (!base.IsClient)
382-
instructions.Add(processor.Create(OpCodes.Call, IsClient_MethodRef));
348+
instructions.Add(processor.Create(OpCodes.Call, IsClientInitialized_MethodRef));
383349
}
384350
//Checking instanceFinder.
385351
else
386-
{
352+
{
387353
instructions.Add(processor.Create(OpCodes.Call, base.GetClass<ObjectHelper>().InstanceFinder_IsClient_MethodRef));
388354
}
389355
instructions.Add(processor.Create(OpCodes.Brtrue, endIf));
390356
//If warning then also append warning text.
391357
if (loggingType != LoggingType.Off)
392358
{
393-
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}.";
359+
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.";
394360
instructions.AddRange(base.GetClass<GeneralHelper>().LogMessage(methodDef, msg, loggingType));
395361
}
396362
//Add return.
@@ -412,8 +378,7 @@ internal void CreateIsClientCheck(MethodDefinition methodDef, LoggingType loggin
412378
/// <summary>
413379
/// Creates exit method condition if not server.
414380
/// </summary>
415-
/// <param name="processor"></param>
416-
/// <param name="warn"></param>
381+
/// <param name="useStatic">When true InstanceFinder.IsServer is used, when false base.IsServerInitialized is used.</param>
417382
internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggingType, bool useStatic, bool insertFirst, bool checkIsNetworked)
418383
{
419384
/* This is placed after the if check.
@@ -431,7 +396,7 @@ internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggin
431396
{
432397
instructions.Add(processor.Create(OpCodes.Ldarg_0)); //argument: this
433398
//If (!base.IsServer)
434-
instructions.Add(processor.Create(OpCodes.Call, IsServer_MethodRef));
399+
instructions.Add(processor.Create(OpCodes.Call, IsServerInitialized_MethodRef));
435400
}
436401
//Checking instanceFinder.
437402
else
@@ -442,7 +407,7 @@ internal void CreateIsServerCheck(MethodDefinition methodDef, LoggingType loggin
442407
//If warning then also append warning text.
443408
if (loggingType != LoggingType.Off)
444409
{
445-
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}";
410+
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.";
446411
instructions.AddRange(base.GetClass<GeneralHelper>().LogMessage(methodDef, msg, loggingType));
447412
}
448413
//Add return.

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/ObjectHelper.cs

+16-10
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@ internal class ObjectHelper : CodegenBase
1414
{
1515
#region Reflection references.
1616
//Fullnames.
17-
public string SyncList_Name;
18-
public string SyncDictionary_Name;
19-
public string SyncHashSet_Name;
17+
public string SyncVar_Name { get; private set; }
18+
public string SyncList_Name { get; private set; }
19+
public string SyncDictionary_Name { get; private set; }
20+
public string SyncHashSet_Name { get; private set; }
2021
//Is checks.
21-
public MethodReference InstanceFinder_IsServer_MethodRef;
22-
public MethodReference InstanceFinder_IsClient_MethodRef;
22+
public MethodReference InstanceFinder_IsServer_MethodRef { get; private set; }
23+
public MethodReference InstanceFinder_IsClient_MethodRef { get; private set; }
2324
//Misc.
24-
public TypeReference NetworkBehaviour_TypeRef;
25-
public MethodReference NetworkConnection_IsValid_MethodRef;
26-
public MethodReference NetworkConnection_IsActive_MethodRef;
27-
public MethodReference Dictionary_Add_UShort_SyncBase_MethodRef;
28-
public MethodReference NetworkConnection_GetIsLocalClient_MethodRef;
25+
public TypeReference NetworkBehaviour_TypeRef { get; private set; }
26+
public MethodReference NetworkConnection_IsValid_MethodRef { get; private set; }
27+
public MethodReference NetworkConnection_IsActive_MethodRef { get; private set; }
28+
public MethodReference Dictionary_Add_UShort_SyncBase_MethodRef { get; private set; }
29+
public MethodReference NetworkConnection_GetIsLocalClient_MethodRef { get; private set; }
2930
#endregion
3031

3132
public override bool ImportReferences()
3233
{
3334
Type tmpType;
35+
/* SyncVar names. */
36+
//SyncVar.
37+
tmpType = typeof(SyncVar<>);
38+
base.ImportReference(tmpType);
39+
SyncVar_Name = tmpType.Name;
3440
/* SyncObject names. */
3541
//SyncList.
3642
tmpType = typeof(SyncList<>);

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/Typed/CreatedSyncType.cs

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ internal class CreatedSyncVar
1313
public readonly MethodReference SetSyncIndexMr;
1414
public readonly MethodReference ConstructorMr;
1515
public readonly GenericInstanceType SyncVarGit;
16+
public FieldDefinition SyncVarClassFd { get; private set; }
17+
1618
public MethodReference HookMr;
1719
public CreatedSyncVar(GenericInstanceType syncVarGit, TypeDefinition variableTd, MethodReference getValueMr, MethodReference setValueMr, MethodReference setSyncIndexMr,MethodReference hookMr, MethodReference constructorMr)
1820
{
@@ -24,6 +26,11 @@ public CreatedSyncVar(GenericInstanceType syncVarGit, TypeDefinition variableTd,
2426
HookMr = hookMr;
2527
ConstructorMr = constructorMr;
2628
}
29+
30+
public void SetSyncVarClassField(FieldDefinition fd)
31+
{
32+
SyncVarClassFd = fd;
33+
}
2734
}
2835

2936

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/Helpers/Typed/GeneratorHelper.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ public SerializerType GetSerializerType(TypeReference objectTr, bool writer, out
8888
{
8989
return SerializerType.List;
9090
}
91-
else if (objectTd.Is(typeof(ListCache<>)))
91+
#pragma warning disable CS0618 // Type or member is obsolete
92+
else if (objectTd.Is(typeof(ListCache<>))) //Remove on 2024/01/01
9293
{
9394
return SerializerType.ListCache;
9495
}
96+
#pragma warning restore CS0618 // Type or member is obsolete
9597
else if (objectTd.InheritsFrom<NetworkBehaviour>(base.Session))
9698
{
9799
return SerializerType.NetworkBehaviour;

Diff for: unity/tanks-fishnet/Assets/FishNet/CodeGenerating/ILCore/FishNetILPP.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Generic;
1212
using System.IO;
1313
using System.Linq;
14+
using System.Runtime.CompilerServices;
1415
using System.Text;
1516
using Unity.CompilationPipeline.Common.ILPostProcessing;
1617

0 commit comments

Comments
 (0)