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/>.
22
21
*/
23
22
24
- using HarmonyLib ;
23
+ #if NET6_0
25
24
using Il2Cpp ;
25
+ # endif
26
+
27
+ using HarmonyLib ;
26
28
using MelonLoader ;
27
29
using Si_Mapcycle ;
28
- using UnityEngine ;
29
30
using System . Timers ;
30
31
using MelonLoader . Utils ;
32
+ using System ;
33
+ using System . IO ;
34
+ using System . Collections . Generic ;
31
35
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 " ) ]
33
37
[ assembly: MelonGame ( "Bohemia Interactive" , "Silica" ) ]
38
+ [ assembly: MelonOptionalDependencies ( "Admin Mod" ) ]
34
39
35
40
namespace Si_Mapcycle
36
41
{
37
42
public class MapCycleMod : MelonMod
38
43
{
39
- static String mapName = "" ;
40
44
static GameMode gameModeInstance ;
41
45
static bool bEndRound ;
42
46
static bool bTimerExpired ;
@@ -82,51 +86,19 @@ public override void OnInitializeMelon()
82
86
}
83
87
}
84
88
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 )
122
90
{
123
91
MapCycleMod . bTimerExpired = true ;
124
92
}
125
93
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
127
99
private static class ApplyPatch_MusicJukeboxHandlerUpdate
128
100
{
129
- private static void Postfix ( Il2Cpp . MusicJukeboxHandler __instance )
101
+ private static void Postfix ( MusicJukeboxHandler __instance )
130
102
{
131
103
// check if timer expired
132
104
if ( MapCycleMod . bEndRound == true && MapCycleMod . bTimerExpired == true )
@@ -137,18 +109,18 @@ private static void Postfix(Il2Cpp.MusicJukeboxHandler __instance)
137
109
138
110
String sNextMap = sMapCycle [ iMapLoadCount % sMapCycle . Length ] ;
139
111
140
- String sCurrentMap = Il2Cpp . NetworkGameServer . GetServerMapName ( ) ;
112
+ String sCurrentMap = NetworkGameServer . GetServerMap ( ) ;
141
113
MelonLogger . Msg ( "Changing map to " + sNextMap + "..." ) ;
142
114
143
- Il2Cpp . NetworkGameServer . LoadLevel ( sNextMap , MapCycleMod . gameModeInstance . GameModeInfo ) ;
115
+ NetworkGameServer . LoadLevel ( sNextMap , MapCycleMod . gameModeInstance . GameModeInfo ) ;
144
116
}
145
117
}
146
118
}
147
119
148
- [ HarmonyPatch ( typeof ( Il2Cpp . MusicJukeboxHandler ) , nameof ( Il2Cpp . MusicJukeboxHandler . OnGameEnded ) ) ]
120
+ [ HarmonyPatch ( typeof ( MusicJukeboxHandler ) , nameof ( MusicJukeboxHandler . OnGameEnded ) ) ]
149
121
private static class ApplyPatch_OnGameEnded
150
122
{
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 )
152
124
{
153
125
MapCycleMod . gameModeInstance = __0 ;
154
126
MapCycleMod . bEndRound = true ;
@@ -162,4 +134,4 @@ public static void Postfix(Il2Cpp.MusicJukeboxHandler __instance, Il2Cpp.GameMod
162
134
}
163
135
}
164
136
}
165
- }
137
+ }
0 commit comments