66using MiraAPI . GameOptions ;
77using MiraAPI . Modifiers . Types ;
88using MiraAPI . Networking ;
9- using Reactor . Utilities ;
109using Reactor . Utilities . Extensions ;
1110using System ;
1211using System . Collections ;
12+ using BepInEx . Unity . IL2CPP . Utils . Collections ;
1313using TMPro ;
1414using UnityEngine ;
1515using Helpers = LaunchpadReloaded . Utilities . Helpers ;
@@ -32,89 +32,91 @@ public class HackedModifier : TimedModifier
3232 private HackNodeComponent ? _lastCloseNode ;
3333 private HackNodeComponent ? _closestNode ;
3434
35- public override void FixedUpdate ( )
36- {
37- base . FixedUpdate ( ) ;
35+ private Coroutine ? _hackEffectCoroutine ;
3836
39- IsImpostor = Player ! . Data . Role . IsImpostor ;
40-
41- var randomString = MiraAPI . Utilities . Helpers . RandomString ( Helpers . Random . Next ( 4 , 6 ) ,
42- "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#!?$(???#@)$@@@@0000" ) ;
43- Player ! . cosmetics . SetName ( randomString ) ;
44- Player . cosmetics . SetNameMask ( true ) ;
37+ public override void OnActivate ( )
38+ {
39+ GradientManager . SetGradientEnabled ( Player , false ) ;
40+ Player . cosmetics . SetColor ( 15 ) ;
4541
46- if ( Player . cosmetics . gameObject . activeSelf )
42+ if ( Player . cosmetics . CurrentPet != null )
4743 {
48- Player . cosmetics . gameObject . SetActive ( false ) ;
44+ Player . cosmetics . CurrentPet . gameObject . SetActive ( false ) ;
4945 }
5046
47+ Player . cosmetics . gameObject . SetActive ( false ) ;
48+
5149 if ( ! Player . AmOwner )
5250 {
5351 return ;
5452 }
5553
56- _closestNode = MiraAPI . Utilities . Helpers . FindClosestObjectOfType ( HackNodeComponent . AllNodes , PlayerControl . LocalPlayer . transform . position ) ;
54+ if ( Minigame . Instance != null )
55+ {
56+ Minigame . Instance . Close ( ) ;
57+ Minigame . Instance . Close ( ) ;
58+ }
5759
58- if ( _closestNode != null && _lastCloseNode != _closestNode )
60+ foreach ( var node in HackNodeComponent . AllNodes )
5961 {
60- foreach ( var node in HackNodeComponent . AllNodes )
61- {
62- node . SetArrowActive ( false ) ;
63- }
64- _closestNode . SetArrowActive ( true ) ;
62+ node . isActive = true ;
6563 }
6664
67- _lastCloseNode = _closestNode ;
65+ _hackedText = MiraAPI . Utilities . Helpers . CreateTextLabel ( "HackedText" , HudManager . Instance . transform , AspectPosition . EdgeAlignments . Top , new Vector3 ( 0 , 1 , 0 ) ) ;
6866
69- if ( _hackedText != null )
67+ if ( IsImpostor )
7068 {
71- _hackedText . text = $ "Find a node on the map to unhack! \n If you don't unhack in time, <b>YOU WILL DIE.</b> \n <size=70%> { Math . Round ( TimeRemaining , 0 ) } seconds remaining.</size>" ;
69+ return ;
7270 }
71+
72+ _hackEffectCoroutine = Player . StartCoroutine ( HackEffect ( ) . WrapToIl2Cpp ( ) ) ;
7373 }
7474
75- public override void OnActivate ( )
75+ public override void FixedUpdate ( )
7676 {
77- GradientManager . SetGradientEnabled ( Player ! , false ) ;
78- Player ! . cosmetics . SetColor ( 15 ) ;
77+ base . FixedUpdate ( ) ;
7978
80- if ( Player . cosmetics . CurrentPet != null )
79+ IsImpostor = Player . Data . Role . IsImpostor ;
80+
81+ var randomString = MiraAPI . Utilities . Helpers . RandomString ( Helpers . Random . Next ( 4 , 6 ) ,
82+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#!?$(???#@)$@@@@0000" ) ;
83+ Player . cosmetics . SetName ( randomString ) ;
84+ Player . cosmetics . SetNameMask ( true ) ;
85+
86+ if ( Player . cosmetics . gameObject . activeSelf )
8187 {
82- Player . cosmetics . CurrentPet . gameObject . SetActive ( false ) ;
88+ Player . cosmetics . gameObject . SetActive ( false ) ;
8389 }
8490
85- Player . cosmetics . gameObject . SetActive ( false ) ;
86-
8791 if ( ! Player . AmOwner )
8892 {
8993 return ;
9094 }
9195
92- if ( Minigame . Instance != null )
93- {
94- Minigame . Instance . Close ( ) ;
95- Minigame . Instance . Close ( ) ;
96- }
96+ _closestNode = MiraAPI . Utilities . Helpers . FindClosestObjectOfType ( HackNodeComponent . AllNodes , PlayerControl . LocalPlayer . transform . position ) ;
9797
98- foreach ( var node in HackNodeComponent . AllNodes )
98+ if ( _closestNode != null && _lastCloseNode != _closestNode )
9999 {
100- node . isActive = true ;
100+ foreach ( var node in HackNodeComponent . AllNodes )
101+ {
102+ node . SetArrowActive ( false ) ;
103+ }
104+ _closestNode . SetArrowActive ( true ) ;
101105 }
102106
103- _hackedText = MiraAPI . Utilities . Helpers . CreateTextLabel ( "HackedText" , HudManager . Instance . transform , AspectPosition . EdgeAlignments . Top , new Vector3 ( 0 , 1 , 0 ) ) ;
107+ _lastCloseNode = _closestNode ;
104108
105- if ( IsImpostor )
109+ if ( _hackedText != null )
106110 {
107- return ;
111+ _hackedText . text = $ "Find a node on the map to unhack! \n If you don't unhack in time, <b>YOU WILL DIE.</b> \n <size=70%> { Math . Round ( TimeRemaining , 0 ) } seconds remaining.</size>" ;
108112 }
109-
110- Coroutines . Start ( HackEffect ( ) ) ;
111113 }
112114
113115 public override void OnDeactivate ( )
114116 {
115117 DeActivating = true ;
116- GradientManager . SetGradientEnabled ( Player ! , true ) ;
117- Player ! . cosmetics . SetColor ( ( byte ) Player . Data . DefaultOutfit . ColorId ) ;
118+ GradientManager . SetGradientEnabled ( Player , true ) ;
119+ Player . cosmetics . SetColor ( ( byte ) Player . Data . DefaultOutfit . ColorId ) ;
118120
119121 if ( Player . cosmetics . CurrentPet != null )
120122 {
@@ -140,12 +142,12 @@ public override void OnDeactivate()
140142 _hackedText . gameObject . DestroyImmediate ( ) ;
141143 }
142144
143- if ( IsImpostor )
145+ if ( _hackEffectCoroutine == null )
144146 {
145147 return ;
146148 }
147149
148- Coroutines . Stop ( HackEffect ( ) ) ;
150+ Player . StopCoroutine ( _hackEffectCoroutine ) ;
149151 }
150152
151153 public override void OnDeath ( DeathReason reason )
0 commit comments