@@ -101,6 +101,7 @@ public WeaponOnBack()
101101
102102 Tick += UpdateWeaponsOnBackAsync ;
103103 Tick += LoadWeaponAsset ;
104+ Tick += ReAttachWeapons ;
104105
105106 API . RegisterCommand ( "wob" , new Action < int , List < object > , string > ( ( source , args , raw ) =>
106107 {
@@ -239,6 +240,11 @@ public static void SetWeapon(Weapon weapon)
239240 DisplayGroupsWeapon [ equipGroup ] = weapon ;
240241 }
241242
243+ public static void SetWeapon ( WeaponDisplayGroup displayGroup , Weapon weapon )
244+ {
245+ DisplayGroupsWeapon [ displayGroup ] = weapon ;
246+ }
247+
242248 public static Weapon GetWeapon ( WeaponDisplayGroup displayGroup )
243249 {
244250 DisplayGroupsWeapon . TryGetValue ( displayGroup , out var weapon ) ;
@@ -267,6 +273,32 @@ public static void DeleteAllWeaponObjects()
267273 }
268274 }
269275
276+ static async Task ReAttachWeapons ( )
277+ {
278+ WeaponDisplay . GetAllDisplayedWeaponObjects ( )
279+ . Where ( d => ! ( d . Value is null ) && d . Value . Exists ( ) )
280+ . ToList ( )
281+ . ForEach ( d =>
282+ {
283+ var weaponDisplayGroup = d . Key ;
284+ var weaponObject = d . Value ;
285+ var weapon = WeaponDisplay . GetWeapon ( weaponDisplayGroup ) ;
286+
287+ // Try sync
288+ API . NetworkRegisterEntityAsNetworked ( API . ObjToNet ( weaponObject . Handle ) ) ;
289+ weaponObject . IsPersistent = true ;
290+ var netId = API . NetworkGetNetworkIdFromEntity ( weaponObject . Handle ) ;
291+ API . SetNetworkIdCanMigrate ( netId , true ) ;
292+ API . SetNetworkIdExistsOnAllMachines ( netId , true ) ;
293+ API . NetworkRequestControlOfEntity ( weaponObject . Handle ) ;
294+
295+ AttachWeapon ( weapon , weaponObject ) ;
296+ Debug . WriteLine ( $ "[{ ResourceName } ]ReAttachWeapon: weapon: { weapon . Hash } , model: { weaponObject . Model . Hash } , handle: { weaponObject . Handle } ") ;
297+ } ) ;
298+
299+ await Delay ( 1000 * 10 ) ;
300+ }
301+
270302 static async Task UpdateWeaponsOnBackAsync ( )
271303 {
272304 await Delay ( 100 ) ;
@@ -306,6 +338,7 @@ static async Task UpdateWeaponsOnBackAsync()
306338
307339 AttachWeapon ( weaponNeedToCreate , weaponObject ) ;
308340
341+ WeaponDisplay . SetWeapon ( WeaponDisplay . GetWeaponDisplayGroup ( weaponNeedToCreate ) , weaponNeedToCreate ) ;
309342 WeaponDisplay . SetWeaponObject ( WeaponDisplay . GetWeaponDisplayGroup ( weaponNeedToCreate ) , weaponObject ) ;
310343
311344 _latestWeaponObjectOnBack = weaponObject ;
0 commit comments