Skip to content

Commit 456d359

Browse files
authored
Mapcycle v1.1.0 - Mono support
- Adds mono support (dedicated servers) - CI integration
1 parent 9ac54ef commit 456d359

File tree

3 files changed

+69
-98
lines changed

3 files changed

+69
-98
lines changed

Si_Mapcycle/Si_Mapcycle.cs

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
/*
2-
Silica Mapcycle Mod
3-
Copyright (C) 2023 by databomb
4-
5-
* Description *
6-
For Silica listen servers, automatically generates a mapcycle.txt file
7-
and switches to the next map in the cycle at the end of each round.
8-
9-
* License *
10-
This program is free software: you can redistribute it and/or modify
11-
it under the terms of the GNU General Public License as published by
12-
the Free Software Foundation, either version 3 of the License, or
13-
(at your option) any later version.
14-
15-
This program is distributed in the hope that it will be useful,
16-
but WITHOUT ANY WARRANTY; without even the implied warranty of
17-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18-
GNU General Public License for more details.
19-
20-
You should have received a copy of the GNU General Public License
21-
along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
/*
2+
Silica Map Cycle
3+
Copyright (C) 2023 by databomb
4+
5+
* Description *
6+
Provides map management and cycles to a server.
7+
8+
* License *
9+
This program is free software: you can redistribute it and/or modify
10+
it under the terms of the GNU General Public License as published by
11+
the Free Software Foundation, either version 3 of the License, or
12+
(at your option) any later version.
13+
14+
This program is distributed in the hope that it will be useful,
15+
but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
GNU General Public License for more details.
18+
19+
You should have received a copy of the GNU General Public License
20+
along with this program. If not, see <http://www.gnu.org/licenses/>.
2221
*/
2322

24-
using HarmonyLib;
23+
#if NET6_0
2524
using Il2Cpp;
25+
# endif
26+
27+
using HarmonyLib;
2628
using MelonLoader;
2729
using Si_Mapcycle;
28-
using UnityEngine;
2930
using System.Timers;
3031
using MelonLoader.Utils;
32+
using System;
33+
using System.IO;
34+
using System.Collections.Generic;
3135

32-
[assembly: MelonInfo(typeof(MapCycleMod), "[Si] Mapcycle", "1.0.2", "databomb", "https://github.com/data-bomb/Silica_ListenServer")]
36+
[assembly: MelonInfo(typeof(MapCycleMod), "Mapcycle", "1.1.0", "databomb", "https://github.com/data-bomb/Silica")]
3337
[assembly: MelonGame("Bohemia Interactive", "Silica")]
38+
[assembly: MelonOptionalDependencies("Admin Mod")]
3439

3540
namespace Si_Mapcycle
3641
{
3742
public class MapCycleMod : MelonMod
3843
{
39-
static String mapName = "";
4044
static GameMode gameModeInstance;
4145
static bool bEndRound;
4246
static bool bTimerExpired;
@@ -82,51 +86,19 @@ public override void OnInitializeMelon()
8286
}
8387
}
8488

85-
public override void OnSceneWasLoaded(int buildIndex, string sceneName)
86-
{
87-
mapName = sceneName;
88-
}
89-
public const string defaultColor = "<color=#DDE98C>";
90-
public const string chatPrefix = "<b>" + defaultColor + "[<color=#DFA725>SAM" + defaultColor + "]</b> ";
91-
92-
//TODO change to use the admin helper methods instead
93-
[HarmonyPatch(typeof(Il2CppSilica.UI.Chat), nameof(Il2CppSilica.UI.Chat.MessageReceived))]
94-
private static class ApplyChatReceiveCurrentMatchInfo
95-
{
96-
public static void Postfix(Il2CppSilica.UI.Chat __instance, Il2Cpp.Player __0, string __1, bool __2)
97-
{
98-
try
99-
{
100-
if (__instance.ToString().Contains("alien") && __2 == false)
101-
{
102-
103-
bool isCurrMapCommand = String.Equals(__1, "!currentmap", StringComparison.OrdinalIgnoreCase);
104-
if (isCurrMapCommand)
105-
{
106-
Il2Cpp.Player serverPlayer = Il2Cpp.NetworkGameServer.GetServerPlayer();
107-
serverPlayer.SendChatMessage(chatPrefix + defaultColor + " Current map is " + String.Concat(mapName), false);
108-
109-
}
110-
}
111-
}
112-
catch (Exception exception)
113-
{
114-
string error = exception.Message;
115-
error += "\n" + exception.TargetSite;
116-
error += "\n" + exception.StackTrace;
117-
MelonLogger.Error(error);
118-
}
119-
}
120-
}
121-
private static void HandleTimerChangeLevel(object source, ElapsedEventArgs e)
89+
private static void HandleTimerChangeLevel(object source, ElapsedEventArgs e)
12290
{
12391
MapCycleMod.bTimerExpired = true;
12492
}
12593

126-
[HarmonyPatch(typeof(Il2Cpp.MusicJukeboxHandler), nameof(Il2Cpp.MusicJukeboxHandler.Update))]
94+
#if NET6_0
95+
[HarmonyPatch(typeof(MusicJukeboxHandler), nameof(MusicJukeboxHandler.Update))]
96+
#else
97+
[HarmonyPatch(typeof(MusicJukeboxHandler), "Update")]
98+
#endif
12799
private static class ApplyPatch_MusicJukeboxHandlerUpdate
128100
{
129-
private static void Postfix(Il2Cpp.MusicJukeboxHandler __instance)
101+
private static void Postfix(MusicJukeboxHandler __instance)
130102
{
131103
// check if timer expired
132104
if (MapCycleMod.bEndRound == true && MapCycleMod.bTimerExpired == true)
@@ -137,18 +109,18 @@ private static void Postfix(Il2Cpp.MusicJukeboxHandler __instance)
137109

138110
String sNextMap = sMapCycle[iMapLoadCount % sMapCycle.Length];
139111

140-
String sCurrentMap = Il2Cpp.NetworkGameServer.GetServerMapName();
112+
String sCurrentMap = NetworkGameServer.GetServerMap();
141113
MelonLogger.Msg("Changing map to " + sNextMap + "...");
142114

143-
Il2Cpp.NetworkGameServer.LoadLevel(sNextMap, MapCycleMod.gameModeInstance.GameModeInfo);
115+
NetworkGameServer.LoadLevel(sNextMap, MapCycleMod.gameModeInstance.GameModeInfo);
144116
}
145117
}
146118
}
147119

148-
[HarmonyPatch(typeof(Il2Cpp.MusicJukeboxHandler), nameof(Il2Cpp.MusicJukeboxHandler.OnGameEnded))]
120+
[HarmonyPatch(typeof(MusicJukeboxHandler), nameof(MusicJukeboxHandler.OnGameEnded))]
149121
private static class ApplyPatch_OnGameEnded
150122
{
151-
public static void Postfix(Il2Cpp.MusicJukeboxHandler __instance, Il2Cpp.GameMode __0, Il2Cpp.Team __1)
123+
public static void Postfix(MusicJukeboxHandler __instance, GameMode __0, Team __1)
152124
{
153125
MapCycleMod.gameModeInstance = __0;
154126
MapCycleMod.bEndRound = true;
@@ -162,4 +134,4 @@ public static void Postfix(Il2Cpp.MusicJukeboxHandler __instance, Il2Cpp.GameMod
162134
}
163135
}
164136
}
165-
}
137+
}

Si_Mapcycle/Si_Mapcycle.csproj

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
4+
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
65
<Nullable>enable</Nullable>
76
</PropertyGroup>
87

98
<ItemGroup>
10-
<Reference Include="0Harmony">
11-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\0Harmony.dll</HintPath>
12-
</Reference>
13-
<Reference Include="Assembly-CSharp">
14-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll</HintPath>
15-
</Reference>
16-
<Reference Include="Il2CppInterop.Runtime">
17-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\Il2CppInterop.Runtime.dll</HintPath>
18-
</Reference>
19-
<Reference Include="Il2Cppmscorlib">
20-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\Il2Cppmscorlib.dll</HintPath>
21-
</Reference>
22-
<Reference Include="MelonLoader">
23-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\MelonLoader.dll</HintPath>
24-
</Reference>
25-
<Reference Include="UnityEngine">
26-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.dll</HintPath>
27-
</Reference>
28-
<Reference Include="UnityEngine.CoreModule">
29-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.CoreModule.dll</HintPath>
30-
</Reference>
31-
<Reference Include="UnityEngine.InputLegacyModule">
32-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.InputLegacyModule.dll</HintPath>
33-
</Reference>
34-
<Reference Include="UnityEngine.PhysicsModule">
35-
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.PhysicsModule.dll</HintPath>
36-
</Reference>
9+
<PackageReference Include="Silica-MelonLoader-AdminMod" Version="2.0.0" />
10+
<PackageReference Include="Silica-MelonLoader-Dependencies" Version="0.8.19" />
3711
</ItemGroup>
3812

3913
</Project>

Si_Mapcycle/Si_Mapcycle.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33723.286
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Si_Mapcycle", "Si_Mapcycle.csproj", "{078E6BF5-E9A2-432E-BFA3-D7B979203089}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{078E6BF5-E9A2-432E-BFA3-D7B979203089}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{078E6BF5-E9A2-432E-BFA3-D7B979203089}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{078E6BF5-E9A2-432E-BFA3-D7B979203089}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{078E6BF5-E9A2-432E-BFA3-D7B979203089}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {1248F685-F5BD-4E21-B2DC-36FFDCD26B9A}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)