forked from zombieb/undead-universal-patch-il2cpp
backend refactor yay!!! 1.4.0
This commit is contained in:
58
Patches/GameManager/FreeSpawns.cs
Normal file
58
Patches/GameManager/FreeSpawns.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class FreeSpawnsPatch_Array
|
||||
{
|
||||
public static List<string> config = GameFreeSpawns.config.Get();
|
||||
|
||||
public static string TargetTypeName = "GamePlayerSpawnPoint";
|
||||
public static string TargetMethodName = "Awake";
|
||||
public static string Description = "FreeSpawns event patch";
|
||||
public static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GameManagerConfig.AnyGameFreeSpawn.Value) return false;
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
public static void Postfix(ref GamePlayerSpawnPoint __instance)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting FreeSpawns patch");
|
||||
GameManager man = NetworkedSingletonMonoBehaviour<GameManager>.instance;
|
||||
|
||||
if (man.CurrentGameConfiguration == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration was null");
|
||||
return;
|
||||
}
|
||||
if (man.CurrentGameConfiguration.configurationData == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("CurrentGameConfiguration.configurationData was null");
|
||||
return;
|
||||
}
|
||||
if (!config.Contains(man.CurrentGameConfiguration.configurationData.Name))
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Game '{man.CurrentGameConfiguration.configurationData.Name}' is not specified by GameFreeSpawns");
|
||||
return;
|
||||
}
|
||||
|
||||
__instance.GameTeamPlayerIndex = GameTeamPlayerIndex.ANY_INDEX;
|
||||
}
|
||||
}
|
||||
58
Patches/GameManager/TeamConfigurator.cs
Normal file
58
Patches/GameManager/TeamConfigurator.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using RecRoom.Core.GameManagement;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager;
|
||||
|
||||
[HarmonyPatch]
|
||||
public class TeamConfiguratorPatch
|
||||
{
|
||||
static List<GameConfiguration> gameConfig = TeamConfigurator.config.Get();
|
||||
|
||||
static string TargetTypeName = "GameConfigurationTool";
|
||||
static string TargetMethodName = "SetGameConfiguration";
|
||||
static string Description = "TeamConfigurator event patch";
|
||||
|
||||
static Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
static MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
|
||||
|
||||
public static bool Prepare()
|
||||
{
|
||||
if (!GameManagerConfig.StaticGameTeamConfig.Value) return false;
|
||||
if (targetMethod == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MethodBase TargetMethod() => targetMethod;
|
||||
|
||||
public static void Prefix(ref GameConfigurationAsset config, ref bool showNotification)
|
||||
{
|
||||
var conf = config;
|
||||
showNotification = GenericConfig.PatchDebug.Value;
|
||||
|
||||
var teamConf = gameConfig.Find(match => match.GameName == conf.Name);
|
||||
if (teamConf == null)
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"'{config.Name}' does not have explicit team configurations");
|
||||
return;
|
||||
}
|
||||
|
||||
var arr = new Il2CppStructArray<TeamConfiguration>(teamConf.TeamConfigurations.Count);
|
||||
for (int i = 0; i < arr.Length; i++) arr[i] = new TeamConfiguration { MaxTeamSize = teamConf.TeamConfigurations[i].Size };
|
||||
config.TeamConfigurations = arr;
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New team configuration length for '{config.Name}': {arr.Length}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user