@@ -16,6 +16,7 @@ namespace Reactor.Networking.Attributes;
16
16
public sealed class InnerNetObjectAttribute : Attribute
17
17
{
18
18
private static readonly HashSet < Assembly > _registeredAssemblies = new ( ) ;
19
+ private static readonly HashSet < MethodInfo > _registeredMethods = new ( ) ;
19
20
20
21
/// <summary>
21
22
/// Registers all <see cref="InnerNetObject"/>s annotated with <see cref="InnerNetObjectAttribute"/> in the specified <paramref name="assembly"/>.
@@ -49,20 +50,7 @@ public static void Register(Assembly assembly)
49
50
50
51
if ( prefabMethod != null )
51
52
{
52
- var prefab = prefabMethod . Invoke ( null , null ) ;
53
-
54
- if ( prefab == null )
55
- {
56
- Warning ( $ "Failed to register InnerNetObject, prefab return null.") ;
57
- }
58
- else if ( prefab is InnerNetObject netObj )
59
- {
60
- AddInnerNetObject ( netObj ) ;
61
- }
62
- else if ( prefab is GameObject gameObj )
63
- {
64
- AddInnerNetObject ( gameObj ) ;
65
- }
53
+ _registeredMethods . Add ( prefabMethod ) ;
66
54
}
67
55
else
68
56
{
@@ -77,6 +65,35 @@ public static void Register(Assembly assembly)
77
65
}
78
66
}
79
67
68
+ internal static void LoadRegistered ( )
69
+ {
70
+ if ( _registeredMethods . Count > 0 ) // Increase array length by one because of beginning if check in InnerNetClient.CoHandleSpawn()
71
+ {
72
+ var innerNetClient = AmongUsClient . Instance ;
73
+ var list2 = innerNetClient . SpawnableObjects . ToList ( ) ;
74
+ list2 . Add ( new ( ) ) ;
75
+ innerNetClient . SpawnableObjects = list2 . ToArray ( ) ;
76
+ }
77
+
78
+ foreach ( var prefabMethod in _registeredMethods )
79
+ {
80
+ var prefab = prefabMethod . Invoke ( null , null ) ;
81
+
82
+ if ( prefab == null )
83
+ {
84
+ Warning ( $ "Failed to register InnerNetObject, prefab return null.") ;
85
+ }
86
+ else if ( prefab is InnerNetObject netObj )
87
+ {
88
+ AddInnerNetObject ( netObj ) ;
89
+ }
90
+ else if ( prefab is GameObject gameObj )
91
+ {
92
+ AddInnerNetObject ( gameObj ) ;
93
+ }
94
+ }
95
+ }
96
+
80
97
private static void AddInnerNetObject ( InnerNetObject prefab )
81
98
{
82
99
var innerNetClient = AmongUsClient . Instance ;
@@ -110,12 +127,6 @@ private static void AddInnerNetObject(GameObject prefab)
110
127
111
128
internal static void Initialize ( )
112
129
{
113
- // Increase array length by one because of beginning if check in InnerNetClient.CoHandleSpawn()
114
- var innerNetClient = AmongUsClient . Instance ;
115
- var list2 = innerNetClient . SpawnableObjects . ToList ( ) ;
116
- list2 . Add ( new ( ) ) ;
117
- innerNetClient . SpawnableObjects = list2 . ToArray ( ) ;
118
-
119
130
IL2CPPChainloader . Instance . PluginLoad += ( _ , assembly , _ ) => Register ( assembly ) ;
120
131
}
121
132
}
0 commit comments