Skip to content

Commit 9572e68

Browse files
author
FirstGearGames
committed
4.6.4
- Fixed NetworkBehaviour template paths not working properly for package manager releases (#858, #859). - Improved debug output on Validate Rpc Lengths. - Fixed MethodAccessException from codegen failing to change ReplicateDataContainer from Internal to Public. - Fixed yet another incorrect using being automatically added by Jetbrains rider.
1 parent 0dd00a4 commit 9572e68

File tree

12 files changed

+88
-44
lines changed

12 files changed

+88
-44
lines changed

Assets/FishNet/CodeGenerating/ILCore/FishNetILPP.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public override bool WillProcess(ICompiledAssembly compiledAssembly)
4848
bool referencesFishNet = FishNetILPP.IsFishNetAssembly(compiledAssembly) || compiledAssembly.References.Any(filePath => Path.GetFileNameWithoutExtension(filePath) == RUNTIME_ASSEMBLY_NAME);
4949
return referencesFishNet;
5050
}
51+
5152
public override ILPostProcessor GetInstance() => this;
53+
5254
public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
5355
{
5456
AssemblyDefinition assemblyDef = ILCoreHelper.GetAssemblyDefinition(compiledAssembly);
@@ -64,7 +66,7 @@ public override ILPostProcessResult Process(ICompiledAssembly compiledAssembly)
6466
return null;
6567

6668

67-
69+
6870
bool modified = false;
6971

7072
bool fnAssembly = IsFishNetAssembly(compiledAssembly);
@@ -153,7 +155,6 @@ private void TryLogV3ToV4Helpers(CodegenSession session)
153155
#endif
154156
}
155157

156-
157158
/// <summary>
158159
/// Makees methods public scope which use CodegenMakePublic attribute.
159160
/// </summary>
@@ -163,6 +164,14 @@ private bool ModifyMakePublicMethods(CodegenSession session)
163164
string makePublicTypeFullName = typeof(MakePublicAttribute).FullName;
164165
foreach (TypeDefinition td in session.Module.Types)
165166
{
167+
foreach (CustomAttribute tdCustomAttribute in td.CustomAttributes)
168+
{
169+
if (tdCustomAttribute.AttributeType.FullName == makePublicTypeFullName)
170+
{
171+
td.Attributes &= ~TypeAttributes.NotPublic;
172+
td.Attributes |= TypeAttributes.Public;
173+
}
174+
}
166175
foreach (MethodDefinition md in td.Methods)
167176
{
168177
foreach (CustomAttribute ca in md.CustomAttributes)
@@ -179,6 +188,7 @@ private bool ModifyMakePublicMethods(CodegenSession session)
179188
//There is always at least one modified.
180189
return true;
181190
}
191+
182192
/// <summary>
183193
/// Creates delegates for user declared serializers.
184194
/// </summary>
@@ -236,7 +246,7 @@ internal bool CreateDeclaredComparerDelegates(CodegenSession session)
236246

237247
return modified;
238248
}
239-
249+
240250
/// <summary>
241251
/// Creates serializers for types that use IncludeSerialization attribute.
242252
/// </summary>
@@ -274,7 +284,6 @@ bool CanSerialize()
274284
return modified;
275285
}
276286

277-
278287
/// <summary>
279288
/// Creaters serializers and calls for IBroadcast.
280289
/// </summary>
@@ -312,7 +321,6 @@ private bool CreateIBroadcast(CodegenSession session)
312321
climbTd = climbTd.GetNextBaseTypeDefinition(session);
313322
//this + name check 40ms
314323
} while (climbTd != null);
315-
316324
}
317325

318326

@@ -364,9 +372,7 @@ private bool CreateQOLAttributes(CodegenSession session)
364372
private bool CreateNetworkBehaviours(CodegenSession session)
365373
{
366374
//Get all network behaviours to process.
367-
List<TypeDefinition> networkBehaviourTypeDefs = session.Module.Types
368-
.Where(td => td.IsSubclassOf(session, session.GetClass<NetworkBehaviourHelper>().FullName))
369-
.ToList();
375+
List<TypeDefinition> networkBehaviourTypeDefs = session.Module.Types.Where(td => td.IsSubclassOf(session, session.GetClass<NetworkBehaviourHelper>().FullName)).ToList();
370376

371377
/* Remove types which are inherited. This gets the child most networkbehaviours.
372378
* Since processing iterates upward from each child there is no reason
@@ -436,6 +442,5 @@ private bool CreateSerializerInitializeDelegates(CodegenSession session)
436442
internal static bool IsFishNetAssembly(ICompiledAssembly assembly) => (assembly.Name == FishNetILPP.RUNTIME_ASSEMBLY_NAME);
437443
internal static bool IsFishNetAssembly(CodegenSession session) => (session.Module.Assembly.Name.Name == FishNetILPP.RUNTIME_ASSEMBLY_NAME);
438444
internal static bool IsFishNetAssembly(ModuleDefinition moduleDef) => (moduleDef.Assembly.Name.Name == FishNetILPP.RUNTIME_ASSEMBLY_NAME);
439-
440445
}
441446
}

Assets/FishNet/Runtime/Editor/NewNetworkBehaviour/CreateNewNetworkBehaviour.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
using System;
3+
using System.IO;
24
using UnityEditor;
35
using UnityEngine;
46
using File = System.IO.File;
@@ -9,12 +11,21 @@ namespace FishNet.Editing.NewNetworkBehaviourScript
911
internal sealed class CreateNewNetworkBehaviour : MonoBehaviour
1012
{
1113

12-
const string defaultTemplateName = "1-Scripting__MonoBehaviour Script-NewMonoBehaviourScript.cs.txt";
14+
private const string DEFAULT_TEMPLATE_NAME = "1-Scripting__MonoBehaviour Script-NewMonoBehaviourScript.cs.txt";
1315

1416
[MenuItem("Assets/Create/NetworkBehaviour Script", false, -220)]
1517
private static void CreateNewAsset()
1618
{
17-
string templatePath = Application.dataPath + "/FishNet/Assets/FishNet/Runtime/Editor/NewNetworkBehaviour/template.txt";
19+
string templatePath;
20+
if (Directory.Exists(Application.dataPath + "/FishNet"))
21+
{
22+
templatePath = Application.dataPath + "/FishNet/Assets/FishNet/Runtime/Editor/NewNetworkBehaviour/template.txt";
23+
}
24+
else
25+
{
26+
templatePath = "Packages/com.firstgeargames.fishnet/Runtime/Editor/NewNetworkBehaviour/template.txt";
27+
}
28+
1829
if (!File.Exists(templatePath))
1930
{
2031

@@ -30,7 +41,7 @@ private static void CreateNewAsset()
3041

3142
public static void CopyExistingTemplate(string templatePath)
3243
{
33-
File.Copy(EditorApplication.applicationContentsPath + "/Resources/ScriptTemplates/" + defaultTemplateName, templatePath);
44+
File.Copy(EditorApplication.applicationContentsPath + "/Resources/ScriptTemplates/" + DEFAULT_TEMPLATE_NAME, templatePath);
3445
string fileContent = File.ReadAllText(templatePath);
3546
fileContent = fileContent.ReplaceFirstOccurence("MonoBehaviour", "NetworkBehaviour");
3647
fileContent = fileContent.Replace("using UnityEngine;", "using UnityEngine;\nusing FishNet.Object;");
@@ -44,7 +55,7 @@ internal static class NetworkBehaviourStringExtension
4455
{
4556
public static string ReplaceFirstOccurence(this string str, string oldValue, string newValue)
4657
{
47-
int pos = str.IndexOf(oldValue);
58+
int pos = str.IndexOf(oldValue, StringComparison.Ordinal);
4859
if (pos < 0) return str;
4960
return str.Substring(0, pos) + newValue + str.Substring(pos + oldValue.Length);
5061

Assets/FishNet/Runtime/Managing/Client/ClientManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,9 @@ internal void ParseReader(PooledReader reader, Channel channel, bool print = fal
401401
* received. */
402402
if (reader.PeekPacketId() == PacketId.Split)
403403
{
404+
#if DEVELOPMENT
405+
NetworkManager.LastReadPacketId = PacketId.Split;
406+
#endif
404407
//Skip packetId.
405408
reader.ReadPacketId();
406409
int expectedMessages;
@@ -421,6 +424,7 @@ internal void ParseReader(PooledReader reader, Channel channel, bool print = fal
421424
{
422425
packetId = reader.ReadPacketId();
423426
#if DEVELOPMENT
427+
NetworkManager.LastReadPacketId = packetId;
424428
// if (!NetworkManager.IsServerStarted)
425429
// print = true;
426430
// if (print)

Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.RpcLinks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal void ParseRpcLink(PooledReader reader, ushort index, Channel channel)
7272
}
7373

7474
#if DEVELOPMENT
75-
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: true, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount);
75+
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: true, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount, channel);
7676
#endif
7777
}
7878

Assets/FishNet/Runtime/Managing/Client/Object/ClientObjects.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ internal void ParseReconcileRpc(PooledReader reader, Channel channel)
327327
SkipDataLength((ushort)PacketId.ObserversRpc, reader, dataLength);
328328

329329
#if DEVELOPMENT
330-
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount);
330+
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount, channel);
331331
#endif
332332
}
333333

@@ -354,7 +354,7 @@ internal void ParseObserversRpc(PooledReader reader, Channel channel)
354354
}
355355

356356
#if DEVELOPMENT
357-
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount);
357+
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount, channel);
358358
#endif
359359
}
360360

Assets/FishNet/Runtime/Managing/NetworkManager.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
using FishNet.Connection;
1+
#if UNITY_EDITOR || DEVELOPMENT_BUILD
2+
#define DEVELOPMENT
3+
#endif
4+
5+
#if UNITY_EDITOR
6+
using FishNet.Editing.PrefabCollectionGenerator;
7+
using UnityEditor;
8+
#endif
9+
10+
using FishNet.Connection;
211
using FishNet.Managing.Client;
312
using FishNet.Managing.Server;
413
using FishNet.Managing.Timing;
@@ -24,10 +33,7 @@
2433
using System.Runtime.CompilerServices;
2534
using GameKit.Dependencies.Utilities;
2635

27-
#if UNITY_EDITOR
28-
using FishNet.Editing.PrefabCollectionGenerator;
29-
using UnityEditor;
30-
#endif
36+
3137

3238
namespace FishNet.Managing
3339
{
@@ -161,6 +167,12 @@ public static IReadOnlyList<NetworkManager> Instances
161167
/// Starting index for RpcLinks.
162168
/// </summary>
163169
internal static ushort StartingRpcLinkIndex;
170+
#if DEVELOPMENT
171+
/// <summary>
172+
/// Last read packetId be it from server or client.
173+
/// </summary>
174+
internal PacketId LastReadPacketId;
175+
#endif
164176
#endregion
165177

166178
#region Serialized.
@@ -212,7 +224,7 @@ public static IReadOnlyList<NetworkManager> Instances
212224
/// <summary>
213225
/// Version of this release.
214226
/// </summary>
215-
public const string FISHNET_VERSION = "4.6.3";
227+
public const string FISHNET_VERSION = "4.6.4";
216228
/// <summary>
217229
/// Maximum framerate allowed.
218230
/// </summary>

Assets/FishNet/Runtime/Managing/Object/ManagedObjects.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ internal void ParseReplicateRpc(PooledReader reader, NetworkConnection conn, Cha
426426
SkipDataLength((ushort)PacketId.ServerRpc, reader, dataLength);
427427

428428
#if DEVELOPMENT
429-
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount);
429+
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount, channel);
430430
#endif
431431
}
432432

Assets/FishNet/Runtime/Managing/Server/Object/ServerObjects.Parsing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal void ParseServerRpc(PooledReader reader, NetworkConnection conn, Channe
3434
SkipDataLength((ushort)PacketId.ServerRpc, reader, dataLength);
3535

3636
#if DEVELOPMENT
37-
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount);
37+
NetworkBehaviour.TryPrintDebugForValidatedRpc(fromRpcLink: false, base.NetworkManager, reader, startReaderRemaining, rpcInformation, expectedReadAmount, channel);
3838
#endif
3939
}
4040
}

0 commit comments

Comments
 (0)