88 * If not, see <https://www.gnu.org/licenses/>.
99 */
1010
11- using Achievements . Handlers ;
12- using HarmonyLib ;
13- using Interactables . Interobjects . DoorUtils ;
14- using InventorySystem . Items . ThrowableProjectiles ;
15- using PlayerRoles ;
16- using PlayerRoles . PlayableScps . Scp079 . Rewards ;
17- using PlayerRoles . PlayableScps . Scp939 . Mimicry ;
18- using System ;
1911using System . Collections . Generic ;
2012using System . Diagnostics ;
2113using System . Linq ;
2214using System . Reflection ;
2315using System . Reflection . Emit ;
16+ using Achievements . Handlers ;
17+ using HarmonyLib ;
18+ using Interactables . Interobjects . DoorUtils ;
2419using InventorySystem . Disarming ;
2520using InventorySystem . Items ;
21+ using InventorySystem . Items . ThrowableProjectiles ;
2622using InventorySystem . Searching ;
27- using LabApi . Features . Console ;
2823using MapGeneration . Distributors ;
24+ using PlayerRoles ;
25+ using PlayerRoles . PlayableScps . HumanTracker ;
2926using PlayerRoles . PlayableScps . Scp079 ;
27+ using PlayerRoles . PlayableScps . Scp079 . Rewards ;
28+ using PlayerRoles . PlayableScps . Scp939 . Mimicry ;
3029using PlayerStatsSystem ;
3130using UncomplicatedCustomRoles . API . Features ;
3231using UncomplicatedCustomRoles . Manager ;
@@ -37,12 +36,13 @@ namespace UncomplicatedCustomRoles.Patches
3736 [ HarmonyPatch ( typeof ( PlayerRoleManager ) , nameof ( PlayerRoleManager . CurrentRole ) , MethodType . Getter ) ]
3837 internal class PlayerRoleManagerPatch
3938 {
40- static bool Prefix ( PlayerRoleManager __instance , ref PlayerRoleBase __result )
39+ private static bool Prefix ( PlayerRoleManager __instance , ref PlayerRoleBase __result )
4140 {
4241 if ( __instance . Hub == null || __instance . Hub . netId == 0 )
4342 return true ;
4443
45- if ( __instance . Hub is not null && DisguiseTeam . RoleBaseList . TryGetValue ( __instance . Hub . PlayerId , out PlayerRoleBase role ) )
44+ if ( __instance . Hub is not null &&
45+ DisguiseTeam . RoleBaseList . TryGetValue ( __instance . Hub . PlayerId , out PlayerRoleBase role ) )
4646 {
4747 if ( role is null )
4848 LogManager . Error ( $ "Disguised role for player { __instance . Hub . PlayerId } is null!") ;
@@ -55,7 +55,7 @@ static bool Prefix(PlayerRoleManager __instance, ref PlayerRoleBase __result)
5555 return true ;
5656 }
5757 }
58-
58+
5959 [ HarmonyPatch ( typeof ( PlayerRolesUtils ) , nameof ( PlayerRolesUtils . GetRoleId ) ) ]
6060 internal class PlayerRolesUtilsPatch
6161 {
@@ -82,11 +82,11 @@ internal class PlayerRolesUtilsPatch
8282 $ "{ typeof ( Scp079Recontainer ) } ::{ nameof ( Scp079Recontainer . OnServerRoleChanged ) } "
8383 } ;
8484
85- static bool Prefix ( ReferenceHub hub , ref RoleTypeId __result )
85+ private static bool Prefix ( ReferenceHub hub , ref RoleTypeId __result )
8686 {
8787 if ( hub == null )
8888 return true ;
89-
89+
9090 if ( ! DisguiseTeam . List . TryGetValue ( hub . PlayerId , out Team team ) )
9191 return true ;
9292
@@ -118,21 +118,22 @@ static bool Prefix(ReferenceHub hub, ref RoleTypeId __result)
118118 [ HarmonyPatch ( typeof ( ExplosionGrenade ) , nameof ( ExplosionGrenade . ExplodeDestructible ) ) ]
119119 internal class GrenadeTranspiler
120120 {
121- static IEnumerable < CodeInstruction > Transpiler ( IEnumerable < CodeInstruction > instructions )
121+ private static IEnumerable < CodeInstruction > Transpiler ( IEnumerable < CodeInstruction > instructions )
122122 {
123123 List < CodeInstruction > newInstructions = new ( instructions ) ;
124124 int index = - 1 ;
125125
126126 for ( int i = 0 ; i < newInstructions . Count ; i ++ )
127- {
128- if ( newInstructions [ i ] . opcode == OpCodes . Call && newInstructions [ i ] . operand is MethodInfo method && method == Method ( typeof ( PlayerRolesUtils ) , nameof ( PlayerRolesUtils . GetRoleId ) , new Type [ ] { typeof ( ReferenceHub ) } ) )
127+ if ( newInstructions [ i ] . opcode == OpCodes . Call && newInstructions [ i ] . operand is MethodInfo method &&
128+ method == Method ( typeof ( PlayerRolesUtils ) , nameof ( PlayerRolesUtils . GetRoleId ) ,
129+ [ typeof ( ReferenceHub ) ] ) )
129130 {
130131 index = i ;
131132 break ;
132133 }
133- }
134134
135- newInstructions [ index + 1 ] . operand = Method ( typeof ( PlayerRolesUtils ) , nameof ( PlayerRolesUtils . GetTeam ) , new Type [ ] { typeof ( ReferenceHub ) } ) ;
135+ newInstructions [ index + 1 ] . operand = Method ( typeof ( PlayerRolesUtils ) , nameof ( PlayerRolesUtils . GetTeam ) ,
136+ [ typeof ( ReferenceHub ) ] ) ;
136137 newInstructions . RemoveAt ( index ) ;
137138
138139 return newInstructions ;
@@ -142,7 +143,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst
142143 [ HarmonyPatch ( typeof ( PickupSearchCompletor ) , nameof ( PickupSearchCompletor . ValidateAny ) ) ]
143144 public class PickupSearchCompletorPatch
144145 {
145- static bool Prefix ( PickupSearchCompletor __instance , ref bool __result )
146+ private static bool Prefix ( PickupSearchCompletor __instance , ref bool __result )
146147 {
147148 if ( ! DisguiseTeam . List . TryGetValue ( __instance . Hub . PlayerId , out Team team ) || team != Team . SCPs ||
148149 __instance . Hub . roleManager . CurrentRole . RoleTypeId . GetTeam ( ) == Team . SCPs ) return true ;
@@ -151,39 +152,49 @@ static bool Prefix(PickupSearchCompletor __instance, ref bool __result)
151152 return false ;
152153 }
153154 }
154-
155+
155156 [ HarmonyPatch ]
156157 public class DoorPermissionsPolicyPatch
157158 {
158- static MethodBase TargetMethod ( )
159+ private static MethodBase TargetMethod ( )
159160 {
160- return Method ( typeof ( DoorPermissionsPolicy ) , "CheckPermissions" , new [ ] { typeof ( ReferenceHub ) , typeof ( IDoorPermissionRequester ) , typeof ( PermissionUsed ) . MakeByRefType ( ) } ) ;
161+ return Method ( typeof ( DoorPermissionsPolicy ) , "CheckPermissions" ,
162+ [
163+ typeof ( ReferenceHub ) , typeof ( IDoorPermissionRequester ) , typeof ( PermissionUsed ) . MakeByRefType ( )
164+ ] ) ;
161165 }
162166
163- static bool Prefix ( DoorPermissionsPolicy __instance , ReferenceHub hub , IDoorPermissionRequester requester , out PermissionUsed callback , ref bool __result )
167+ private static bool Prefix ( DoorPermissionsPolicy __instance , ReferenceHub hub ,
168+ IDoorPermissionRequester requester ,
169+ out PermissionUsed callback , ref bool __result )
164170 {
165171 callback = null ;
166172 if ( __instance . RequiredPermissions == DoorPermissionFlags . None || hub . serverRoles . BypassMode )
167173 {
168174 __result = true ;
169175 return false ;
170176 }
177+
171178 if ( hub . roleManager . CurrentRole is IDoorPermissionProvider currentRole &&
172179 ( ! DisguiseTeam . List . TryGetValue ( hub . PlayerId , out Team team ) || team != Team . SCPs ) )
173180 {
174181 __result = __instance . CheckPermissions ( currentRole , requester , out callback ) ;
175182 return false ;
176183 }
184+
177185 ItemBase curInstance = hub . inventory . CurInstance ;
178- __result = curInstance != null && curInstance is IDoorPermissionProvider provider && __instance . CheckPermissions ( provider , requester , out callback ) ;
186+ __result = curInstance != null && curInstance is IDoorPermissionProvider provider &&
187+ __instance . CheckPermissions ( provider , requester , out callback ) ;
179188 return false ;
180189 }
181190 }
182-
183- [ HarmonyPatch ( typeof ( DoorPermissionsPolicyExtensions ) , nameof ( DoorPermissionsPolicyExtensions . GetCombinedPermissions ) ) ]
191+
192+ [ HarmonyPatch ( typeof ( DoorPermissionsPolicyExtensions ) ,
193+ nameof ( DoorPermissionsPolicyExtensions . GetCombinedPermissions ) ) ]
184194 public class DoorPermissionsPolicyExtensionsPatch
185195 {
186- static bool Prefix ( ReferenceHub hub , IDoorPermissionRequester requester , ref DoorPermissionFlags __result )
196+ private static bool Prefix ( ReferenceHub hub , IDoorPermissionRequester requester ,
197+ ref DoorPermissionFlags __result )
187198 {
188199 if ( hub == null )
189200 {
@@ -212,17 +223,51 @@ static bool Prefix(ReferenceHub hub, IDoorPermissionRequester requester, ref Doo
212223 }
213224 }
214225
226+ [ HarmonyPatch ( typeof ( LastHumanTracker ) , nameof ( LastHumanTracker . TryGetLastTarget ) ) ]
227+ public class LastHumanTrackerPatch
228+ {
229+ private static bool Prefix ( ref ReferenceHub lastTarget , ref bool __result )
230+ {
231+ lastTarget = null ;
232+ int humanCount = 0 ;
233+ int scpCount = 0 ;
234+
235+ foreach ( ReferenceHub hub in ReferenceHub . AllHubs )
236+ {
237+ Team effectiveTeam = hub . GetRoleId ( ) . GetTeam ( ) ;
238+ if ( DisguiseTeam . List . TryGetValue ( hub . PlayerId , out Team fakeTeam ) )
239+ effectiveTeam = fakeTeam ;
240+
241+ if ( effectiveTeam == Team . SCPs )
242+ {
243+ ++ scpCount ;
244+ }
245+ else if ( hub . IsAlive ( ) && effectiveTeam != Team . Dead && effectiveTeam != Team . Dead )
246+ {
247+ ++ humanCount ;
248+ lastTarget = hub ;
249+ }
250+ }
251+
252+ __result = humanCount == 1 && scpCount > 0 ;
253+ return false ;
254+ }
255+ }
256+
215257 [ HarmonyPatch ( typeof ( Scp079Recontainer ) , nameof ( Scp079Recontainer . OnServerRoleChanged ) ) ]
216258 public class Scp079RecontainerPatch
217259 {
218- static bool Prefix ( Scp079Recontainer __instance , ReferenceHub hub , RoleTypeId newRole , RoleChangeReason reason )
260+ private static bool Prefix ( Scp079Recontainer __instance , ReferenceHub hub , RoleTypeId newRole ,
261+ RoleChangeReason reason )
219262 {
220263 Team team = hub . GetRoleId ( ) . GetTeam ( ) ;
221264 if ( DisguiseTeam . List . TryGetValue ( hub . PlayerId , out Team t ) )
222265 team = t ;
223- Logger . Debug ( $ "Player { hub . PlayerId } changed role to { newRole } for reason { reason } . Checking if recontainment is needed...") ;
224- Logger . Debug ( $ "Player's current role: { hub . GetRoleId ( ) } , team: { team } ") ;
225- if ( newRole != RoleTypeId . Spectator || ! IsScpButNot079 ( hub . GetRoleId ( ) , team ) || Scp079Role . ActiveInstances . Count == 0 ||
266+ LogManager . Debug (
267+ $ "Player { hub . PlayerId } changed role to { newRole } for reason { reason } . Checking if recontainment is needed...") ;
268+ LogManager . Debug ( $ "Player's current role: { hub . GetRoleId ( ) } , team: { team } ") ;
269+ if ( newRole != RoleTypeId . Spectator || ! IsScpButNot079 ( hub . GetRoleId ( ) , team ) ||
270+ Scp079Role . ActiveInstances . Count == 0 ||
226271 ReferenceHub . AllHubs . Any ( x =>
227272 {
228273 if ( x == hub )
@@ -244,7 +289,7 @@ static bool Prefix(Scp079Recontainer __instance, ReferenceHub hub, RoleTypeId ne
244289
245290 private static bool IsScpButNot079 ( RoleTypeId roleTypeId , Team team )
246291 {
247- Logger . Debug ( $ "Checking if role { roleTypeId } is an SCP but not 079 for team { team } ") ;
292+ LogManager . Debug ( $ "Checking if role { roleTypeId } is an SCP but not 079 for team { team } ") ;
248293 return team == Team . SCPs && roleTypeId != RoleTypeId . Scp079 ;
249294 }
250295 }
0 commit comments