Skip to content

Commit eef15ff

Browse files
author
FirstGearGames
committed
4.6.5
- Fixed instance of Multipass Id not found error. - Fixed rare chance of Observers not removing a disconnected client when using multiple transports and only one is disconnected. - Fixed internal NetworkInitialize methods are now called before OnStartNetwork even if the object is disabled. - Improved SyncVar initial value will not overwrite synchronized value in the condition object receives synchronized value while disabled, and is later enabled for the first time. - Fixed OnStop callbacks not occuring on nested objects when disconnecting the transport socket. - Added TimeManager.HalfRoundTripTime. - Added Beta Recursive Despawns for internal change. - Fixed NetworkTransform.LastObserversRpcTick not resetting. - Improved adaptive interpolation to be more consistent and efficient. - Fixed harmless errors when using DebugManager Validate Rpc Lengths. - Added Tugboat.StopSocketsOnThread to stop local connections using a thread (default/current behavior). - Improved Tugboat now tries to stop the socket if detected as started when starting a new connection. - Fixed unicode strings not writing proper length. - Fixed large replicates not splitting into multiple packets. - Added UniversalTickSmoother.Set/GetAdditionalGraphicalOffsetValues. - Fixed SyncType.ResetState NullReferenceException. - Fixed UniversalTickSmoother interpolation times changing eratically resulting in smoothing pausing. - Fixed RigidbodyPrediction demo 'boostStart' check (#870). - Fixed NewNetworkBehaviour template missing file exception. - Fixed warning when Time/PredictionManager would try to simulate physics with a 0f timescale (#860). - Fixed NetworkTransform stuttering spectated objects as host when using a send interval larger than 1. - Fixed prediction corrupting class instance memory.
1 parent 0ae4579 commit eef15ff

File tree

377 files changed

+1051
-27869
lines changed

Some content is hidden

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

377 files changed

+1051
-27869
lines changed

Assets/FishNet/CodeGenerating/Processing/NetworkBehaviourProcessor.cs

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ internal class NetworkBehaviourProcessor : CodegenBase
2222
#endregion
2323

2424
#region Const.
25-
internal const string EARLY_INITIALIZED_NAME = "NetworkInitializeEarly_";
26-
internal const string LATE_INITIALIZED_NAME = "NetworkInitializeLate_";
2725
internal const string NETWORKINITIALIZE_EARLY_INTERNAL_NAME = "NetworkInitialize___Early";
28-
internal const string NETWORKINITIALIZE_LATE_INTERNAL_NAME = "NetworkInitialize__Late";
26+
internal const string NETWORKINITIALIZE_LATE_INTERNAL_NAME = "NetworkInitialize___Late";
27+
private readonly string[] _networkInitializeMethodNames = new string[] { NETWORKINITIALIZE_EARLY_INTERNAL_NAME, NETWORKINITIALIZE_LATE_INTERNAL_NAME };
2928
#endregion
3029

3130
internal bool ProcessLocal(TypeDefinition typeDef)
@@ -65,10 +64,10 @@ internal bool ProcessLocal(TypeDefinition typeDef)
6564
* multiple times. EG: with this solution if parent had 1 sync type
6665
* and childA had 2 the parent would be index 0, and childA would have 1 and 2.
6766
* But also, if childB inherited childA it would have 3+.
68-
*
67+
*
6968
* Going in reverse also gaurantees the awake method will already be created
70-
* or modified in any class a child inherits. This lets us call it appropriately
71-
* as well error if the awake does not exist, such as could not be created. */
69+
* or modified in any class a child inherits. This lets us call it appropriately
70+
* as well error if the awake does not exist, such as could not be created. */
7271
typeDefs.Reverse();
7372

7473
foreach (TypeDefinition td in typeDefs)
@@ -77,7 +76,7 @@ internal bool ProcessLocal(TypeDefinition typeDef)
7776
* can use it. */
7877
MethodDefinition networkInitializeIfDisabledMd;
7978
CreateNetworkInitializeMethods(td, out networkInitializeIfDisabledMd);
80-
CallNetworkInitializesFromNetworkInitializeIfDisabled(networkInitializeIfDisabledMd);
79+
CallNetworkInitialize(networkInitializeIfDisabledMd);
8180

8281

8382

@@ -111,7 +110,7 @@ internal bool ProcessLocal(TypeDefinition typeDef)
111110
//Copy user logic from awake into a new method.
112111
CopyAwakeUserLogic(td);
113112
/* Create awake method or if already exist make
114-
* it public virtual. */
113+
* it public virtual. */
115114
if (!ModifyAwakeMethod(td, out bool awakeCreated))
116115
{
117116
//This is a hard fail and will break the solution so throw here.
@@ -146,7 +145,6 @@ internal bool ProcessLocal(TypeDefinition typeDef)
146145
/// </summary>
147146
internal string GetAwakeUserLogicMethodDefinition(TypeDefinition td) => $"Awake_UserLogic_{td.FullName}_{base.Module.Name}";
148147

149-
150148
/// <summary>
151149
/// Returns if a class has been processed.
152150
/// </summary>
@@ -207,7 +205,7 @@ internal bool NonNetworkBehaviourHasInvalidAttributes(Collection<TypeDefinition>
207205
private void CallBaseAwake(TypeDefinition td)
208206
{
209207
/* If base is not a class which can be processed then there
210-
* is no need to continue. */
208+
* is no need to continue. */
211209
if (!td.CanProcessBaseType(base.Session))
212210
return;
213211

@@ -221,7 +219,6 @@ private void CallBaseAwake(TypeDefinition td)
221219
processor.Emit(OpCodes.Call, baseAwakeMr);
222220
}
223221

224-
225222
/// <summary>
226223
/// Calls the next awake method if the nested awake was created by codegen.
227224
/// </summary>
@@ -241,7 +238,6 @@ private void CallAwakeUserLogic(TypeDefinition td)
241238
base.GetClass<GeneralHelper>().CallCopiedMethod(awakeMd, userLogicMd);
242239
}
243240

244-
245241
/// <summary>
246242
/// Adds a check to NetworkInitialize to see if it has already run.
247243
/// </summary>
@@ -287,23 +283,22 @@ void AddCheck(string methodName)
287283
/// </summary>
288284
private void CallBaseOnNetworkInitializeMethods(TypeDefinition typeDef)
289285
{
290-
//If base class cannot have a networkinitialize no reason to continue.
291-
if (!typeDef.CanProcessBaseType(base.Session))
286+
//If base is null cannot call base.
287+
if (typeDef.BaseType == null)
292288
return;
293289

294-
string[] initializeMethodNames = new string[] { NETWORKINITIALIZE_EARLY_INTERNAL_NAME, NETWORKINITIALIZE_LATE_INTERNAL_NAME };
295-
foreach (string mdName in initializeMethodNames)
290+
foreach (string mdName in _networkInitializeMethodNames)
296291
{
297-
/* Awake will always exist because it was added previously.
298-
* Get awake for copy and base of copy. */
299-
MethodDefinition thisMd = typeDef.GetMethod(mdName);
300-
ILProcessor processor = thisMd.Body.GetILProcessor();
301-
302-
/* Awake will always exist because it was added previously.
303-
* Get awake for copy and base of copy. */
304292
MethodReference baseMr = typeDef.GetMethodReferenceInBase(base.Session, mdName);
293+
//Not found in base.
294+
if (baseMr == null)
295+
continue;
296+
305297
MethodDefinition baseMd = baseMr.CachedResolve(base.Session);
306298

299+
MethodDefinition thisMd = typeDef.GetMethod(mdName);
300+
ILProcessor processor = thisMd.Body.GetILProcessor();
301+
307302
bool alreadyHasBaseCall = false;
308303
//Check if already calls baseAwake.
309304
foreach (Instruction item in thisMd.Body.Instructions)
@@ -328,11 +323,12 @@ private void CallBaseOnNetworkInitializeMethods(TypeDefinition typeDef)
328323
//Create instructions for base call.
329324
List<Instruction> instructions = new()
330325
{
331-
processor.Create(OpCodes.Ldarg_0), //this.
332-
processor.Create(OpCodes.Call, baseMr)
333-
};
326+
processor.Create(OpCodes.Ldarg_0), //this.
327+
processor.Create(OpCodes.Call, baseMr)
328+
};
334329
processor.InsertFirst(instructions);
335330
}
331+
336332
}
337333
}
338334

@@ -345,8 +341,7 @@ private void AddReturnToAwake(TypeDefinition td)
345341
MethodDefinition awakeMd = td.GetMethod(NetworkBehaviourHelper.AWAKE_METHOD_NAME);
346342
ILProcessor processor = awakeMd.Body.GetILProcessor();
347343
//If no instructions or the last instruction isnt ret.
348-
if (processor.Body.Instructions.Count == 0
349-
|| processor.Body.Instructions[processor.Body.Instructions.Count - 1].OpCode != OpCodes.Ret)
344+
if (processor.Body.Instructions.Count == 0 || processor.Body.Instructions[processor.Body.Instructions.Count - 1].OpCode != OpCodes.Ret)
350345
{
351346
processor.Emit(OpCodes.Ret);
352347
}
@@ -392,22 +387,21 @@ MethodDefinition CreateMethod(string name, MethodDefinition copied = null)
392387
}
393388
}
394389

395-
396390
/// <summary>
397391
/// Creates an 'NetworkInitialize' method which is called by the childmost class to initialize scripts on Awake.
398392
/// </summary>
399-
private void CallNetworkInitializesFromNetworkInitializeIfDisabled(MethodDefinition networkInitializeIfDisabledMd)
393+
private void CallNetworkInitialize(MethodDefinition networkIntializeMd)
400394
{
401-
ILProcessor processor = networkInitializeIfDisabledMd.Body.GetILProcessor();
395+
ILProcessor processor = networkIntializeMd.Body.GetILProcessor();
402396

403-
networkInitializeIfDisabledMd.Body.Instructions.Clear();
397+
networkIntializeMd.Body.Instructions.Clear();
404398
CallMethod(NETWORKINITIALIZE_EARLY_INTERNAL_NAME);
405399
CallMethod(NETWORKINITIALIZE_LATE_INTERNAL_NAME);
406400
processor.Emit(OpCodes.Ret);
407401

408402
void CallMethod(string name)
409403
{
410-
MethodReference initIfDisabledMr = networkInitializeIfDisabledMd.DeclaringType.GetMethodReference(base.Session, name);
404+
MethodReference initIfDisabledMr = networkIntializeMd.DeclaringType.GetMethodReference(base.Session, name);
411405
processor.Emit(OpCodes.Ldarg_0);
412406
processor.Emit(initIfDisabledMr.GetCallOpCode(base.Session), initIfDisabledMr);
413407
}
@@ -473,8 +467,7 @@ internal void CreateFirstNetworkInitializeCall(TypeDefinition typeDef, MethodDef
473467
{
474468
created = true;
475469

476-
thisAwakeMethodDef = new(NetworkBehaviourHelper.AWAKE_METHOD_NAME, MethodDefinitionExtensions.PUBLIC_VIRTUAL_ATTRIBUTES,
477-
typeDef.Module.TypeSystem.Void);
470+
thisAwakeMethodDef = new(NetworkBehaviourHelper.AWAKE_METHOD_NAME, MethodDefinitionExtensions.PUBLIC_VIRTUAL_ATTRIBUTES, typeDef.Module.TypeSystem.Void);
478471
thisAwakeMethodDef.Body.InitLocals = true;
479472
typeDef.Methods.Add(thisAwakeMethodDef);
480473

@@ -500,14 +493,11 @@ internal void CreateFirstNetworkInitializeCall(TypeDefinition typeDef, MethodDef
500493
if (created && firstUserAwakeMethodDef != null)
501494
{
502495
MethodReference baseAwakeMethodRef = typeDef.Module.ImportReference(firstUserAwakeMethodDef);
503-
instructions.Add(processor.Create(OpCodes.Ldarg_0));//this.
496+
instructions.Add(processor.Create(OpCodes.Ldarg_0)); //this.
504497
instructions.Add(processor.Create(OpCodes.Call, baseAwakeMethodRef));
505498
}
506499

507500
processor.InsertFirst(instructions);
508501
}
509-
510-
511-
512502
}
513503
}

Assets/FishNet/CodeGenerating/Processing/Prediction/PredictionProcessor.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ public override bool ImportReferences()
122122
base.ImportReference(typeof(BasicQueue<>));
123123
ReplicateULDelegate_TypeRef = base.ImportReference(typeof(ReplicateUserLogicDelegate<>));
124124
ReconcileULDelegate_TypeRef = base.ImportReference(typeof(ReconcileUserLogicDelegate<>));
125-
125+
126126
TypeDefinition replicateDataTd = base.ImportReference(typeof(ReplicateDataContainer<>)).CachedResolve(base.Session);
127127
ReplicateData_Ctor_MethodRef = base.ImportReference(replicateDataTd.GetConstructor(parameterCount: 2));
128-
128+
129129
//Get/Set tick.
130130
locType = typeof(IReplicateData);
131131
foreach (SR.MethodInfo mi in locType.GetMethods())
@@ -562,7 +562,6 @@ private void CreateFields(TypeDefinition typeDef, MethodDefinition replicateMd,
562562
{
563563
GeneralHelper gh = base.GetClass<GeneralHelper>();
564564
TypeReference replicateDataTr = replicateMd.Parameters[0].ParameterType;
565-
TypeReference replicateDataArrTr = replicateDataTr.MakeArrayType();
566565
TypeReference reconcileDataTr = reconcileMd.Parameters[0].ParameterType;
567566

568567
GenericInstanceType git;
@@ -597,7 +596,8 @@ private void CreateFields(TypeDefinition typeDef, MethodDefinition replicateMd,
597596
typeDef.Fields.Add(lastReconcileDataFd);
598597

599598
//Used for delta replicates.
600-
FieldDefinition lastReadReplicateFd = new($"_lastReadReplicate___{replicateMd.Name}", FieldAttributes.Private, replicateDataTr);
599+
git = gh.GetGenericType(typeof(ReplicateDataContainer<>), replicateDataTr);
600+
FieldDefinition lastReadReplicateFd = new($"_lastReadReplicate___{replicateMd.Name}", FieldAttributes.Private, git);
601601
typeDef.Fields.Add(lastReadReplicateFd);
602602

603603
predictionFields = new()
@@ -746,7 +746,7 @@ bool CreateReplicate()
746746
//new ReplicateData<T>(data, channel)
747747
processor.Emit(OpCodes.Ldarg, replicateDataPd);
748748
processor.Emit(OpCodes.Ldarg, channelPd);
749-
GenericInstanceType git = GetGenericReplicateData(replicateDataTr);
749+
GenericInstanceType git = GetGenericReplicateDataContainer(replicateDataTr);
750750
MethodReference ctorMr = ReplicateData_Ctor_MethodRef.MakeHostInstanceGeneric(base.Session, git);
751751
processor.Emit(OpCodes.Newobj, ctorMr);
752752

@@ -1062,15 +1062,15 @@ private bool CreateReconcileReader(TypeDefinition typeDef, MethodDefinition reco
10621062
MethodReference methodGim = nbh.Reconcile_Reader_MethodRef.GetMethodReference(base.Session, dataTr);
10631063

10641064
processor.Emit(OpCodes.Ldarg_0);
1065-
1065+
10661066
/* nb.Reconcile_Reader(readerPd, ref lastReadReconcile); */
10671067
processor.Emit(OpCodes.Ldarg, readerPd);
10681068
//Data to assign read value to.
10691069
processor.Emit(OpCodes.Ldarg_0);
10701070
processor.Emit(OpCodes.Ldflda, predictionFields.LastReadReconcile);
10711071

10721072
processor.Emit(OpCodes.Call, methodGim);
1073-
1073+
10741074
//Add end of method.
10751075
processor.Emit(OpCodes.Ret);
10761076

@@ -1081,11 +1081,10 @@ private bool CreateReconcileReader(TypeDefinition typeDef, MethodDefinition reco
10811081
/// <summary>
10821082
/// Outputs generic RingBuffer for dataTr.
10831083
/// </summary>
1084-
public GenericInstanceType GetGenericReplicateData(TypeReference dataTr)
1084+
public GenericInstanceType GetGenericReplicateDataContainer(TypeReference dataTr)
10851085
{
1086-
TypeReference containerTr = base.ImportReference(typeof(ReplicateDataContainer<>));
1087-
return containerTr.MakeGenericInstanceType(dataTr);
1088-
1086+
TypeReference typeTr = base.ImportReference(typeof(ReplicateDataContainer<>));
1087+
return typeTr.MakeGenericInstanceType(new TypeReference[] { dataTr });
10891088
}
10901089
#endregion
10911090
}

Assets/FishNet/Demos/Benchmarks/NetworkTransform/Scenes/NetworkTransform Benchmark.unity

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ GameObject:
11941194
- component: {fileID: 7443408886575219566}
11951195
- component: {fileID: 7443408886575219567}
11961196
- component: {fileID: 7443408886575219568}
1197+
- component: {fileID: 7443408886575219569}
11971198
m_Layer: 0
11981199
m_Name: NetworkManager
11991200
m_TagString: Untagged
@@ -1291,3 +1292,22 @@ MonoBehaviour:
12911292
type: 3}
12921293
_addToDefaultScene: 1
12931294
Spawns: []
1295+
--- !u!114 &7443408886575219569
1296+
MonoBehaviour:
1297+
m_ObjectHideFlags: 0
1298+
m_CorrespondingSourceObject: {fileID: 0}
1299+
m_PrefabInstance: {fileID: 0}
1300+
m_PrefabAsset: {fileID: 0}
1301+
m_GameObject: {fileID: 7443408886575219563}
1302+
m_Enabled: 1
1303+
m_EditorHideFlags: 0
1304+
m_Script: {fileID: 11500000, guid: 6d0962ead4b02a34aae248fccce671ce, type: 3}
1305+
m_Name:
1306+
m_EditorClassIdentifier:
1307+
WriteSceneObjectDetails: 0
1308+
ValidateRpcLengths: 1
1309+
DisableObserversRpcLinks: 0
1310+
DisableTargetRpcLinks: 0
1311+
DisableServerRpcLinks: 0
1312+
DisableReplicateRpcLinks: 0
1313+
DisableReconcileRpcLinks: 0

Assets/FishNet/Demos/Prediction/CharacterController/CharacterController Prediction Demo.unity

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,17 @@ MonoBehaviour:
279279
_controllerMovementSettings:
280280
EnableTeleport: 0
281281
TeleportThreshold: 0
282-
AdaptiveInterpolationValue: 1
282+
AdaptiveInterpolationValue: 4
283283
InterpolationValue: 2
284284
SmoothedProperties: 4294967295
285+
SnapNonSmoothedProperties: 0
285286
_spectatorMovementSettings:
286287
EnableTeleport: 0
287288
TeleportThreshold: 0
288-
AdaptiveInterpolationValue: 1
289+
AdaptiveInterpolationValue: 4
289290
InterpolationValue: 2
290291
SmoothedProperties: 4294967295
292+
SnapNonSmoothedProperties: 0
291293
--- !u!1 &555580081
292294
GameObject:
293295
m_ObjectHideFlags: 0

Assets/FishNet/Demos/Prediction/CharacterController/Prefabs/CharacterControllerPrediction.prefab

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ MonoBehaviour:
186186
_addedNetworkObject: {fileID: 8013474958425823559}
187187
_networkObjectCache: {fileID: 8013474958425823559}
188188
_maximumSimultaneousHits: 16
189-
_historyDuration: 0.5
190189
_additionalSize: 0.1
191190
_layers:
192191
serializedVersion: 2
@@ -363,12 +362,14 @@ MonoBehaviour:
363362
_controllerMovementSettings:
364363
EnableTeleport: 0
365364
TeleportThreshold: 0
366-
AdaptiveInterpolationValue: 1
365+
AdaptiveInterpolationValue: 4
367366
InterpolationValue: 2
368367
SmoothedProperties: 4294967295
368+
SnapNonSmoothedProperties: 0
369369
_spectatorMovementSettings:
370370
EnableTeleport: 0
371371
TeleportThreshold: 0
372-
AdaptiveInterpolationValue: 1
372+
AdaptiveInterpolationValue: 4
373373
InterpolationValue: 2
374374
SmoothedProperties: 4294967295
375+
SnapNonSmoothedProperties: 0

Assets/FishNet/Demos/Prediction/CharacterController/Scripts/CharacterControllerPrediction.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,8 @@ private void PerformReplicate(ReplicateData rd, ReplicateState state = Replicate
302302
* wrong. If you do however predict wrong often smoothing will cover up the mistake. */
303303
else if (state.IsFuture())
304304
{
305-
/* Predict up to whatever interpolation is on the PredictionManager. This is the safest way to protect against
306-
* graphical jitter by not predicting beyond global interpolation. */
307-
if (rd.GetTick() - _lastTickedReplicateData.GetTick() >= base.PredictionManager.StateInterpolation)
305+
/* Predict up to 1 tick more. */
306+
if (rd.GetTick() - _lastTickedReplicateData.GetTick() > 1)
308307
{
309308
useDefaultForces = true;
310309
}

Assets/FishNet/Plugins.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/FishNet/Plugins/Edgegap.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Assets/FishNet/Plugins/Edgegap/CHANGELOG.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

Assets/FishNet/Plugins/Edgegap/CHANGELOG.md.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)