Skip to content

Commit

Permalink
DefaultUnits v1.0.0 - Mono support
Browse files Browse the repository at this point in the history
- CI integration
- Mono support (dedicated server)
  • Loading branch information
data-bomb authored Dec 31, 2023
1 parent d41e3dc commit f2dfdaa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 41 deletions.
31 changes: 22 additions & 9 deletions Si_DefaultUnits/Si_DefaultUnits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using HarmonyLib;
#if NET6_0
using Il2Cpp;
#else
using System.Reflection;
#endif

using HarmonyLib;
using MelonLoader;
using Si_DefaultUnits;
using AdminExtension;
using UnityEngine;
using Il2CppSystem.IO;
using System;
using SilicaAdminMod;

[assembly: MelonInfo(typeof(DefaultUnits), "[Si] Default Spawn Units", "0.9.5", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonInfo(typeof(DefaultUnits), "Default Spawn Units", "1.0.0", "databomb", "https://github.com/data-bomb/Silica")]
[assembly: MelonGame("Bohemia Interactive", "Silica")]
[assembly: MelonOptionalDependencies("Admin Mod")]

namespace Si_DefaultUnits
{
Expand Down Expand Up @@ -76,10 +82,10 @@ public override void OnInitializeMelon()
}

// patch as close to where it's used
[HarmonyPatch(typeof(Il2Cpp.MP_Strategy), nameof(Il2Cpp.MP_Strategy.GetUnitPrefabForPlayer))]
[HarmonyPatch(typeof(MP_Strategy), nameof(MP_Strategy.GetUnitPrefabForPlayer))]
private static class ApplyPatch_MP_Strategy_GetUnitPrefabForPlayer
{
public static void Prefix(Il2Cpp.MP_Strategy __instance, UnityEngine.GameObject __result, Il2Cpp.Player __0)
public static void Prefix(MP_Strategy __instance, UnityEngine.GameObject __result, Player __0)
{
try
{
Expand All @@ -88,7 +94,7 @@ public static void Prefix(Il2Cpp.MP_Strategy __instance, UnityEngine.GameObject
return;
}

Team playerTeam = __0.m_Team;
Team playerTeam = __0.Team;

// was there a change in tech tier or is it the first spawn of the round for this team?
if (!TechTierUpdated(playerTeam) && !teamFirstSpawn[playerTeam.Index])
Expand Down Expand Up @@ -137,10 +143,10 @@ public static void Prefix(Il2Cpp.MP_Strategy __instance, UnityEngine.GameObject

// reset tech tiers back to 0
// note: players join and spawn *before* OnGameStarted fires, so it's important to reset back to 0 as soon as the game ends
[HarmonyPatch(typeof(Il2Cpp.MusicJukeboxHandler), nameof(Il2Cpp.MusicJukeboxHandler.OnGameStarted))]
[HarmonyPatch(typeof(MusicJukeboxHandler), nameof(MusicJukeboxHandler.OnGameStarted))]
private static class ApplyPatch_MusicJukeboxHandler_OnGameStarted
{
public static void Postfix(Il2Cpp.MusicJukeboxHandler __instance, Il2Cpp.GameMode __0)
public static void Postfix(MusicJukeboxHandler __instance, GameMode __0)
{
try
{
Expand All @@ -156,7 +162,14 @@ public static void Postfix(Il2Cpp.MusicJukeboxHandler __instance, Il2Cpp.GameMod
if (Team.Teams[i].CurrentTechnologyTier != 0)
{
MelonLogger.Warning("Manually resetting tech tier level to 0 for team: " + Team.Teams[i].TeamName);

#if NET6_0
Team.Teams[i].CurrentTechnologyTier = 0;
#else
Type teamType = typeof(Team);
PropertyInfo currentTechTierProperty = teamType.GetProperty("CurrentTechnologyTier");
currentTechTierProperty.SetValue(Team.Teams[i], 0);
#endif
}
}

Expand Down
35 changes: 3 additions & 32 deletions Si_DefaultUnits/Si_DefaultUnits.csproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TargetFrameworks>net6.0;netstandard2.1</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<Reference Include="0Harmony">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Il2CppInterop.Runtime">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\Il2CppInterop.Runtime.dll</HintPath>
</Reference>
<Reference Include="Il2Cppmscorlib">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\Il2Cppmscorlib.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="Si_AdminExtension">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\net6\Si_AdminExtension.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Silica\MelonLoader\Il2CppAssemblies\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<PackageReference Include="Silica-MelonLoader-AdminMod" Version="2.0.0" />
<PackageReference Include="Silica-MelonLoader-Dependencies" Version="0.8.19" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions Si_DefaultUnits/Si_DefaultUnits.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33723.286
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Si_DefaultUnits", "Si_DefaultUnits.csproj", "{30CCA1CE-4745-4664-993F-FC072FF2429E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{30CCA1CE-4745-4664-993F-FC072FF2429E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{30CCA1CE-4745-4664-993F-FC072FF2429E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{30CCA1CE-4745-4664-993F-FC072FF2429E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{30CCA1CE-4745-4664-993F-FC072FF2429E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4E9A46B4-E6A1-451A-9077-9719A67BF79C}
EndGlobalSection
EndGlobal

0 comments on commit f2dfdaa

Please sign in to comment.