@@ -17,12 +17,13 @@ namespace BHD_ServerManager.Classes.GameManagement
1717 public static class ServerMemory
1818 {
1919 // Global Variables
20- private readonly static theInstance thisInstance = CommonCore . theInstance ! ;
21- private readonly static playerInstance playerInstance = CommonCore . instancePlayers ! ;
20+ private static theInstance thisInstance => CommonCore . theInstance ! ;
21+ private static playerInstance playerInstance => CommonCore . instancePlayers ! ;
22+ private static mapInstance mapInstance => CommonCore . instanceMaps ! ;
2223
23- // START: Process Memory Variables
24- // Import of Dynamic Link Libraries
25- [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
24+ // START: Process Memory Variables
25+ // Import of Dynamic Link Libraries
26+ [ DllImport ( "kernel32.dll" , SetLastError = true ) ]
2627 public static extern nint OpenProcess ( int dwDesiredAccess , bool bInheritHandle , int dwProcessId ) ;
2728 [ DllImport ( "kernel32.dll" ) ]
2829 public static extern bool ReadProcessMemory ( int hProcess , int lpBaseAddress , byte [ ] lpBuffer , int dwSize , ref int lpNumberOfBytesRead ) ;
@@ -148,12 +149,12 @@ public static void UpdateMapListCount()
148149 ReadProcessMemory ( ( int ) processHandle , mapListLocationPtr , mapListLocationPtrBytes , mapListLocationPtrBytes . Length , ref mapListLocationBytesPtrRead ) ;
149150
150151 int mapListNumberOfMaps = BitConverter . ToInt32 ( mapListLocationPtrBytes , 0 ) + 0x4 ;
151- byte [ ] numberOfMaps = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
152+ byte [ ] numberOfMaps = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
152153 int numberofMapsWritten = 0 ;
153154 WriteProcessMemory ( ( int ) processHandle , mapListNumberOfMaps , numberOfMaps , numberOfMaps . Length , ref numberofMapsWritten ) ;
154155
155156 mapListNumberOfMaps += 0x4 ;
156- byte [ ] TotalnumberOfMaps = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
157+ byte [ ] TotalnumberOfMaps = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
157158 int TotalnumberofMapsWritten = 0 ;
158159 WriteProcessMemory ( ( int ) processHandle , mapListNumberOfMaps , TotalnumberOfMaps , TotalnumberOfMaps . Length , ref TotalnumberofMapsWritten ) ;
159160
@@ -822,7 +823,7 @@ public static void UpdateRedPassword()
822823 // Clears the current map cycle and fills it with empty maps
823824 public static void UpdateMapCycle1 ( )
824825 {
825- if ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count > 128 )
826+ if ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count > 128 )
826827 {
827828 throw new Exception ( "Someway, somehow, someone bypassed the maplist checks. You are NOT allowed to have more than 128 maps. #88" ) ;
828829 }
@@ -835,12 +836,12 @@ public static void UpdateMapCycle1()
835836 int mapCycleServerAddress = BitConverter . ToInt32 ( ServerMapCyclePtr , 0 ) ;
836837
837838 int mapCycleTotalAddress = mapCycleServerAddress + 0x4 ;
838- byte [ ] mapTotal = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
839+ byte [ ] mapTotal = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
839840 int mapTotalWritten = 0 ;
840841 WriteProcessMemory ( ( int ) processHandle , mapCycleTotalAddress , mapTotal , mapTotal . Length , ref mapTotalWritten ) ;
841842
842843 int mapCycleCurrentIndex = mapCycleServerAddress + 0xC ;
843- byte [ ] resetMapIndex = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
844+ byte [ ] resetMapIndex = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
844845 int resetMapIndexWritten = 0 ;
845846 WriteProcessMemory ( ( int ) processHandle , mapCycleCurrentIndex , resetMapIndex , resetMapIndex . Length , ref resetMapIndexWritten ) ;
846847
@@ -849,7 +850,7 @@ public static void UpdateMapCycle1()
849850 ReadProcessMemory ( ( int ) processHandle , mapCycleServerAddress , mapCycleListAddress , mapCycleListAddress . Length , ref mapCycleListAddressRead ) ;
850851 int mapCycleList = BitConverter . ToInt32 ( mapCycleListAddress , 0 ) ;
851852
852- foreach ( mapFileInfo entry in thisInstance . MapPlaylists [ 0 ] )
853+ foreach ( mapFileInfo entry in mapInstance . Playlists [ 0 ] )
853854 {
854855 int mapFileIndexLocation = mapCycleList ;
855856
@@ -869,7 +870,7 @@ public static void UpdateMapCycle1()
869870 // Actually updates the memory of the game server with the current map list
870871 public static void UpdateMapCycle2 ( )
871872 {
872- if ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count > 128 )
873+ if ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count > 128 )
873874 {
874875 throw new Exception ( "Someway, somehow, someone bypassed the maplist checks. You are NOT allowed to have more than 128 maps. #89" ) ;
875876 }
@@ -894,7 +895,7 @@ void WriteFixedString(string value, int length)
894895 }
895896
896897 // Write the first map
897- var firstMap = thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ 0 ] ;
898+ var firstMap = mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ 0 ] ;
898899 WriteFixedString ( firstMap . MapFile ! , 28 ) ;
899900 bw . Write ( new byte [ 256 ] ) ; // adjust this padding as needed
900901
@@ -911,9 +912,9 @@ void WriteFixedString(string value, int length)
911912 bw . Write ( new byte [ 24 ] ) ; // adjust this padding as needed
912913
913914 // Write additional maps
914- for ( int i = 1 ; i < thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ; i ++ )
915+ for ( int i = 1 ; i < mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ; i ++ )
915916 {
916- var map = thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ i ] ;
917+ var map = mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ i ] ;
917918 WriteFixedString ( map . MapFile ! , 28 ) ;
918919 bw . Write ( new byte [ 256 ] ) ; // adjust this padding as needed
919920
@@ -950,13 +951,13 @@ public static void UpdateSecondaryMapList()
950951 int mapCycleServerAddress = BitConverter . ToInt32 ( ServerMapCyclePtr , 0 ) ;
951952
952953 int mapCycleTotalAddress = mapCycleServerAddress + 0x4 ;
953- byte [ ] mapTotal = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
954+ byte [ ] mapTotal = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
954955 int mapTotalWritten = 0 ;
955956 WriteProcessMemory ( ( int ) processHandle , mapCycleTotalAddress , mapTotal , mapTotal . Length , ref mapTotalWritten ) ;
956957
957958
958959 int mapCycleCurrentIndex = mapCycleServerAddress + 0xC ;
959- byte [ ] resetMapIndex = BitConverter . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ) ;
960+ byte [ ] resetMapIndex = BitConverter . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ) ;
960961 int resetMapIndexWritten = 0 ;
961962 WriteProcessMemory ( ( int ) processHandle , mapCycleCurrentIndex , resetMapIndex , resetMapIndex . Length , ref resetMapIndexWritten ) ;
962963
@@ -967,17 +968,17 @@ public static void UpdateSecondaryMapList()
967968 int mapCycleList = BitConverter . ToInt32 ( mapCycleListAddress , 0 ) ;
968969
969970
970- for ( int i = 0 ; i < thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ; i ++ )
971+ for ( int i = 0 ; i < mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ; i ++ )
971972 {
972973 int mapFileIndexLocation = mapCycleList ;
973974 byte [ ] mapFileBytes = new byte [ 0x20 ] ; // 32 bytes
974- byte [ ] nameBytes = Encoding . ASCII . GetBytes ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ i ] . MapFile ! ) ;
975+ byte [ ] nameBytes = Encoding . ASCII . GetBytes ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ i ] . MapFile ! ) ;
975976 Array . Copy ( nameBytes , mapFileBytes , Math . Min ( nameBytes . Length , mapFileBytes . Length ) ) ;
976977 int mapFileBytesWritten = 0 ;
977978 WriteProcessMemory ( ( int ) processHandle , mapFileIndexLocation , mapFileBytes , mapFileBytes . Length , ref mapFileBytesWritten ) ;
978979 mapFileIndexLocation += 0x20 ;
979980
980- byte [ ] customMapFlag = BitConverter . GetBytes ( Convert . ToInt32 ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ i ] . ModType == 9 ? 1 : 0 ) ) ;
981+ byte [ ] customMapFlag = BitConverter . GetBytes ( Convert . ToInt32 ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ i ] . ModType == 9 ? 1 : 0 ) ) ;
981982 int customMapFlagWritten = 0 ;
982983 WriteProcessMemory ( ( int ) processHandle , mapFileIndexLocation , customMapFlag , customMapFlag . Length , ref customMapFlagWritten ) ;
983984 mapCycleList += 0x24 ;
@@ -1083,9 +1084,9 @@ public static void GetNextMapType()
10831084 int CurrentMapIndexBytesRead = 0 ;
10841085 ReadProcessMemory ( ( int ) processHandle , Ptr2 , CurrentMapIndexBytes , CurrentMapIndexBytes . Length , ref CurrentMapIndexBytesRead ) ;
10851086 int currentMapIndex = BitConverter . ToInt32 ( CurrentMapIndexBytes , 0 ) ;
1086- AppDebug . Log ( "ServerMemory" , "Number of Maps: " + thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count + " Pre-Check Current Map Index: " + currentMapIndex ) ;
1087+ AppDebug . Log ( "ServerMemory" , "Number of Maps: " + mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count + " Pre-Check Current Map Index: " + currentMapIndex ) ;
10871088
1088- if ( currentMapIndex + 1 >= thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count || thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ currentMapIndex + 1 ] == null )
1089+ if ( currentMapIndex + 1 >= mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count || mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ currentMapIndex + 1 ] == null )
10891090 {
10901091 currentMapIndex = 0 ;
10911092 }
@@ -1094,14 +1095,14 @@ public static void GetNextMapType()
10941095 currentMapIndex ++ ;
10951096 }
10961097
1097- AppDebug . Log ( "ServerMemory" , "Number of Maps: " + thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count + " Current Map Index: " + currentMapIndex ) ;
1098+ AppDebug . Log ( "ServerMemory" , "Number of Maps: " + mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count + " Current Map Index: " + currentMapIndex ) ;
10981099 int currentMapType = thisInstance . gameInfoGameType ;
1099- int nextMapType = thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ currentMapIndex ] . MapType ;
1100+ int nextMapType = mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ currentMapIndex ] . MapType ;
11001101
1101- AppDebug . Log ( "ServerMemory" , "Current Map Type: " + thisInstance . gameInfoMapName + " " + thisInstance . gameInfoGameType + " " + currentMapType ) ;
1102- AppDebug . Log ( "ServerMemory" , "Next Map Type: " + thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ currentMapIndex ] . MapName + " " + thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ currentMapIndex ] . MapType + " - " + nextMapType ) ;
1102+ AppDebug . Log ( "ServerMemory" , "Current Map Type: " + mapInstance . CurrentMapName + " " + thisInstance . gameInfoGameType + " " + currentMapType ) ;
1103+ AppDebug . Log ( "ServerMemory" , "Next Map Type: " + mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ currentMapIndex ] . MapName + " " + mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ currentMapIndex ] . MapType + " - " + nextMapType ) ;
11031104
1104- thisInstance . gameInfoNextMapGameType = nextMapType ;
1105+ mapInstance . NextMapGameType = nextMapType ;
11051106
11061107 }
11071108 public static void SetNextMapType ( )
@@ -1112,12 +1113,12 @@ public static void SetNextMapType()
11121113 {
11131114 // Change the MapType for the next map
11141115 var CurrentGameTypeAddr = baseAddr + 0x5F21A4 ;
1115- byte [ ] nextMaptypeBytes = BitConverter . GetBytes ( thisInstance . gameInfoNextMapGameType ) ;
1116+ byte [ ] nextMaptypeBytes = BitConverter . GetBytes ( mapInstance . NextMapGameType ) ;
11161117 int nextMaptypeBytesWrite = 0 ;
11171118 WriteProcessMemory ( ( int ) processHandle , CurrentGameTypeAddr , nextMaptypeBytes , nextMaptypeBytes . Length , ref nextMaptypeBytesWrite ) ;
11181119
11191120 // Deal with the Players
1120- theInstanceManager . changeTeamGameMode ( thisInstance . gameInfoGameType , thisInstance . gameInfoNextMapGameType ) ;
1121+ theInstanceManager . changeTeamGameMode ( thisInstance . gameInfoGameType , mapInstance . NextMapGameType ) ;
11211122 ServerMemory . UpdatePlayerTeam ( ) ; // Move players to their teams if applicable
11221123
11231124 }
@@ -1137,7 +1138,7 @@ public static void UpdateGameScores()
11371138 var startingPtr1 = 0 ;
11381139 var startingPtr2 = 0 ;
11391140
1140- switch ( thisInstance . gameInfoNextMapGameType )
1141+ switch ( mapInstance . NextMapGameType )
11411142 {
11421143 // KOTH/TKOTH
11431144 case 3 :
@@ -1217,9 +1218,9 @@ public static void UpdateNextMap(int NextMapIndex)
12171218
12181219 if ( NextMapIndex - 1 == - 1 )
12191220 {
1220- NextMapIndex = thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] . Count ;
1221+ NextMapIndex = mapInstance . Playlists [ mapInstance . ActivePlaylist ] . Count ;
12211222 }
1222- else if ( thisInstance . MapPlaylists [ thisInstance . ActiveMapPlaylist ] [ NextMapIndex - 1 ] != null )
1223+ else if ( mapInstance . Playlists [ mapInstance . ActivePlaylist ] [ NextMapIndex - 1 ] != null )
12231224 {
12241225 NextMapIndex -- ;
12251226 }
@@ -1557,7 +1558,7 @@ public static void ReadMemoryCurrentMissionName()
15571558 byte [ ] buffer = new byte [ 26 ] ;
15581559 ReadProcessMemory ( ( int ) processHandle , 0x0071569C , buffer , buffer . Length , ref bytesRead ) ;
15591560 string MissionName = Encoding . Default . GetString ( buffer ) ;
1560- thisInstance . gameInfoMapName = MissionName . Replace ( "\0 " , "" ) ;
1561+ mapInstance . CurrentMapName = MissionName . Replace ( "\0 " , "" ) ;
15611562
15621563
15631564 }
@@ -1589,7 +1590,7 @@ public static void ReadMemoryCurrentMapIndex()
15891590 byte [ ] mapIndexBytes = new byte [ 4 ] ;
15901591 int mapIndexRead = 0 ;
15911592 ReadProcessMemory ( ( int ) processHandle , MapCycleIndex , mapIndexBytes , mapIndexBytes . Length , ref mapIndexRead ) ;
1592- thisInstance . gameInfoCurrentMapIndex = BitConverter . ToInt32 ( mapIndexBytes , 0 ) ;
1593+ mapInstance . CurrentMapIndex = BitConverter . ToInt32 ( mapIndexBytes , 0 ) ;
15931594
15941595
15951596 }
0 commit comments