Skip to content

Commit ed4f844

Browse files
author
Matthew Bate
committed
Current Map Playing Information
1 parent 0515aaf commit ed4f844

File tree

11 files changed

+308
-109
lines changed

11 files changed

+308
-109
lines changed

BHD-ServerManager/Classes/CoreObjects/CommonCore.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class CommonCore
1818
public static statInstance? instanceStats { get; set; }
1919
public static playerInstance? instancePlayers { get; set; }
2020
public static adminInstance? instanceAdmin { get; set; }
21+
public static mapInstance? instanceMaps { get; set; }
2122

2223
public static banInstance? instanceBans { get; set; }
2324
// Object: Ticker, Timer Constructor for periodic tasks
@@ -31,6 +32,7 @@ public static void InitializeCore()
3132
instanceStats = new statInstance();
3233
instancePlayers = new playerInstance();
3334
instanceAdmin = new adminInstance();
35+
instanceMaps = new mapInstance();
3436
instanceBans = DatabaseManager.LoadBanInstance();
3537

3638
// Initialize the Ticker

BHD-ServerManager/Classes/GameManagement/ServerMemory.cs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

BHD-ServerManager/Classes/GameManagement/StartServer.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ public static class StartServer
2323

2424

2525
// Internal Variables to Program
26-
private readonly static theInstance theInstance = CommonCore.theInstance!;
27-
private readonly static tabProfile tabProfile = Program.ServerManagerUI!.ProfileTab;
26+
private static theInstance theInstance => CommonCore.theInstance!;
27+
private static mapInstance mapInstance => CommonCore.instanceMaps!;
28+
private static tabProfile tabProfile => Program.ServerManagerUI!.ProfileTab;
2829

2930
// Function: createAutoRes
3031
public static bool createAutoRes()
3132
{
3233

3334
try
3435
{
35-
if (theInstance.MapPlaylists[theInstance.ActiveMapPlaylist] == null || theInstance.MapPlaylists[theInstance.ActiveMapPlaylist].Count == 0)
36+
if (mapInstance.Playlists[mapInstance.ActivePlaylist] == null || mapInstance.Playlists[mapInstance.ActivePlaylist].Count == 0)
3637
{
3738
AppDebug.Log("StartServer", "currentMapPlaylist is empty. Cannot create autores.bin.");
3839
return false;
@@ -91,7 +92,7 @@ public static bool createAutoRes()
9192
byte[] ServerNameBytes = Encoding.Default.GetBytes(theInstance.gameServerName);
9293
byte[] countryCodeBytes = Encoding.Default.GetBytes(theInstance.gameCountryCode);
9394
byte[] BindAddress = Encoding.Default.GetBytes(theInstance.profileBindIP!);
94-
byte[] firstMapFile = Encoding.Default.GetBytes(theInstance.MapPlaylists[theInstance.ActiveMapPlaylist][0].MapFile!);
95+
byte[] firstMapFile = Encoding.Default.GetBytes(mapInstance.Playlists[mapInstance.ActivePlaylist][0].MapFile!);
9596
byte[] maxSlotsBytes = BitConverter.GetBytes(theInstance.gameMaxSlots);
9697
byte[] dedicatedBytes = BitConverter.GetBytes(Convert.ToInt32(theInstance.gameDedicated));
9798
byte[] GameScoreBytes = BitConverter.GetBytes(theInstance.gameScoreKills);
@@ -102,7 +103,7 @@ public static bool createAutoRes()
102103
byte[] gamePlayOptionsBytes = BitConverter.GetBytes(gamePlayOptions);
103104
byte[] loopMapsBytes = BitConverter.GetBytes(loopMaps > 0 ? 1 : 0);
104105

105-
byte[] gameTypeBytes = BitConverter.GetBytes(theInstance.MapPlaylists[theInstance.ActiveMapPlaylist][0].MapType);
106+
byte[] gameTypeBytes = BitConverter.GetBytes(mapInstance.Playlists[mapInstance.ActivePlaylist][0].MapType);
106107
byte[] timeLimitBytes = BitConverter.GetBytes(theInstance.gameTimeLimit);
107108
byte[] respawnTimeBytes = BitConverter.GetBytes(theInstance.gameRespawnTime);
108109
byte[] allowCustomSkinsBytes = BitConverter.GetBytes(Convert.ToInt32(theInstance.gameCustomSkins));
@@ -120,7 +121,7 @@ public static bool createAutoRes()
120121
byte[] gamePortBytes = BitConverter.GetBytes(theInstance.profileBindPort);
121122
byte[] flagBallScoreBytes = BitConverter.GetBytes(theInstance.gameScoreFlags);
122123
byte[] zoneTimerBytes = BitConverter.GetBytes(theInstance.gameScoreZoneTime);
123-
byte[] customMapFlagBytes = BitConverter.GetBytes(Convert.ToInt32(theInstance.MapPlaylists[theInstance.ActiveMapPlaylist][0].ModType==9?1:0));
124+
byte[] customMapFlagBytes = BitConverter.GetBytes(Convert.ToInt32(mapInstance.Playlists[mapInstance.ActivePlaylist][0].ModType==9?1:0));
124125

125126
byte[] mapListPrehandle = BitConverter.GetBytes(10621344);
126127
byte[] finalAppSetup = Functions.ToByteArray("00 00 00 00 00 00 00 00 05 00 00 00 00".Replace(" ", ""));
@@ -313,7 +314,7 @@ public static bool createAutoRes()
313314

314315
byte[] endOfMap = Functions.ToByteArray("20 B5 B6 01 00 00 00 00 53 01 00 00 00 13 00 00 00 13 00 00 00 04 00 00 00".Replace(" ", ""));
315316

316-
foreach (var map in theInstance.MapPlaylists[theInstance.ActiveMapPlaylist])
317+
foreach (var map in mapInstance.Playlists[mapInstance.ActivePlaylist])
317318
{
318319

319320
byte[] mapFile = Encoding.GetEncoding("Windows-1252").GetBytes(map.MapFile);
@@ -334,7 +335,7 @@ public static bool createAutoRes()
334335
ms.Seek(ms.Position + 0x1C, SeekOrigin.Begin);
335336
}
336337

337-
for (int i = theInstance.MapPlaylists[theInstance.ActiveMapPlaylist].Count; i < 128; i++)
338+
for (int i = mapInstance.Playlists[mapInstance.ActivePlaylist].Count; i < 128; i++)
338339
{
339340
byte[] mapFile = Encoding.GetEncoding("Windows-1252").GetBytes("NA.bms");
340341
ms.Write(mapFile, 0, mapFile.Length);

BHD-ServerManager/Classes/InstanceManagers/adminInstanceManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace BHD_ServerManager.Classes.InstanceManagers;
1010
/// </summary>
1111
public static class adminInstanceManager
1212
{
13-
private static adminInstance adminInstance => adminInstance!;
13+
private static adminInstance adminInstance => CommonCore.instanceAdmin!;
1414
// Valid permissions that can be assigned to users
1515
private static readonly string[] ValidPermissions = new[]
1616
{

0 commit comments

Comments
 (0)