1+ using System . Runtime . InteropServices ;
12using CounterStrikeSharp . API ;
23using CounterStrikeSharp . API . Core ;
34using CounterStrikeSharp . API . Modules . Cvars ;
1011
1112namespace FiveStack ;
1213
14+ [ UnmanagedFunctionPointer ( CallingConvention . ThisCall ) ]
15+ delegate IntPtr GetAddonNameDelegate ( IntPtr self ) ;
16+
1317public class MatchManager
1418{
1519 private MatchData ? _matchData ;
@@ -28,6 +32,7 @@ public class MatchManager
2832 // public CoachSystem _coachSystem;
2933 public KnifeSystem knifeSystem ;
3034 public CaptainSystem captainSystem ;
35+ public INetworkServerService _networkServerService ;
3136
3237 public MatchManager (
3338 ILogger < MatchManager > logger ,
@@ -38,7 +43,8 @@ public MatchManager(
3843 KnifeSystem KnifeSystem ,
3944 ReadySystem ReadySystem ,
4045 CaptainSystem CaptainSystem ,
41- EnvironmentService environmentService
46+ EnvironmentService environmentService ,
47+ INetworkServerService networkServerService
4248 )
4349 {
4450 _logger = logger ;
@@ -50,6 +56,7 @@ EnvironmentService environmentService
5056 captainSystem = CaptainSystem ;
5157 _backUpManagement = backUpManagement ;
5258 _environmentService = environmentService ;
59+ _networkServerService = networkServerService ;
5360 }
5461
5562 public void Init ( MatchData match )
@@ -241,10 +248,22 @@ public void SetupMatch(MatchData match)
241248 return ;
242249 }
243250
244- _logger . LogInformation ( $ "Game State { _currentMap . status } on { _currentMap . map . label } { _currentMap . map . name } / { Server . MapName } ") ;
251+ _logger . LogInformation (
252+ $ "Game State { _currentMap . status } on ({ _currentMap . map . name } ) / { Server . MapName } "
253+ ) ;
245254
246- // attempt to reduce the number of bad map naming issues
247- if ( ! new [ ] { _currentMap . map . name , _currentMap . map . label . ToLower ( ) } . Contains ( Server . MapName . ToLower ( ) ) )
255+ if ( _currentMap . map . workshop_map_id is not null )
256+ {
257+ string currentWorkshopID = GetWorkshopID ( ) ;
258+ _logger . LogInformation ( $ "Checking Workshop Map { _currentMap . map . workshop_map_id } / { currentWorkshopID } ") ;
259+
260+ if ( _currentMap . map . workshop_map_id != currentWorkshopID )
261+ {
262+ ChangeMap ( _currentMap . map ) ;
263+ return ;
264+ }
265+ }
266+ else if ( ! Server . MapName . ToLower ( ) . Contains ( _currentMap . map . name . ToLower ( ) ) )
248267 {
249268 ChangeMap ( _currentMap . map ) ;
250269 return ;
@@ -270,6 +289,16 @@ public void SetupMatch(MatchData match)
270289 }
271290 }
272291
292+ private string GetWorkshopID ( )
293+ {
294+ IntPtr networkGameServer = _networkServerService . GetIGameServerHandle ( ) ;
295+ IntPtr vtablePtr = Marshal . ReadIntPtr ( networkGameServer ) ;
296+ IntPtr functionPtr = Marshal . ReadIntPtr ( vtablePtr + ( 25 * IntPtr . Size ) ) ;
297+ var getAddonName = Marshal . GetDelegateForFunctionPointer < GetAddonNameDelegate > ( functionPtr ) ;
298+ IntPtr result = getAddonName ( networkGameServer ) ;
299+ return Marshal . PtrToStringAnsi ( result ) ! . Split ( ',' ) [ 0 ] ;
300+ }
301+
273302 public void SetupTeamNames ( )
274303 {
275304 MatchMap ? _currentMap = GetCurrentMap ( ) ;
0 commit comments