Upload from upload_mods.ps1

This commit is contained in:
Nathaniel Cosford
2025-06-04 16:16:46 +09:30
commit 78abcd79dd
20 changed files with 1000 additions and 0 deletions

17
Harmony/Init.cs Normal file
View File

@@ -0,0 +1,17 @@
using System.Reflection;
public class CustomPlayerActionManagerInit : IModApi
{
private static bool inited = false;
public void InitMod(Mod _modInstance)
{
if(inited)
return;
inited = true;
Log.Out(" Loading Patch: " + GetType());
ModEvents.GameAwake.RegisterHandler(CustomPlayerActionManager.InitCustomControls);
var harmony = new HarmonyLib.Harmony(GetType().ToString());
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
}

141
Harmony/Patches.cs Normal file
View File

@@ -0,0 +1,141 @@
using HarmonyLib;
using System.Collections.Generic;
using System.Reflection.Emit;
[HarmonyPatch]
public class Patches
{
[HarmonyPatch(typeof(BindingInfo), MethodType.Constructor, new[] { typeof(XUiView), typeof(string), typeof(string) })]
[HarmonyPostfix]
private static void Postfix_ctor_BindingInfo(BindingInfo __instance, string _sourceText)
{
if (!string.IsNullOrEmpty(_sourceText) && _sourceText.StartsWith("{keybindingEntryCount"))
{
__instance.RefreshValue(true);
}
}
[HarmonyPatch(typeof(XUiC_OptionsController), nameof(XUiC_OptionsController.GetBindingValue))]
[HarmonyPostfix]
private static void Postfix_GetBindingValue_XUiC_OptionsController(ref string _value, string _bindingName, ref bool __result, XUiC_OptionsController __instance)
{
if (__result)
{
return;
}
if (!string.IsNullOrEmpty(_bindingName) && _bindingName.StartsWith("keybindingEntryCount"))
{
if (CustomPlayerActionManager.arr_row_counts_controller == null)
{
ReversePatches.InitControllerActionList(__instance);
}
int index = int.Parse(_bindingName.Substring(_bindingName.Length - 1));
_value = CustomPlayerActionManager.arr_row_counts_controller[index].ToString();
__result = true;
return;
}
}
[HarmonyPatch(typeof(XUiC_OptionsControls), nameof(XUiC_OptionsControls.createControlsEntries))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler_createControlsEntries_XUiC_OptionsControls(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for(int i = 0; i < codes.Count; ++i)
{
if (codes[i].opcode == OpCodes.Stloc_2)
{
codes.Insert(i, CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.CreateActionArray)));
break;
}
}
return codes;
}
[HarmonyPatch(typeof(XUiC_OptionsController), nameof(XUiC_OptionsController.createControlsEntries))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler_createControlsEntries_XUiC_OptionsController(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for(int i = 0; i < codes.Count; ++i)
{
if (codes[i].opcode == OpCodes.Stloc_0)
{
codes.InsertRange(i - 1, new[]
{
new CodeInstruction(OpCodes.Ldarg_0),
CodeInstruction.LoadField(typeof(XUiC_OptionsController), nameof(XUiC_OptionsController.actionTabGroups)),
CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.CreateControllerActions))
});
break;
}
}
return codes;
}
[HarmonyPatch(typeof(XUiC_OptionsController), nameof(XUiC_OptionsController.storeCurrentBindings))]
[HarmonyPostfix]
private static void Postfix_storeCurrentBindings_XUiC_OptionsController(XUiC_OptionsController __instance)
{
CustomPlayerActionManager.StoreCurrentCustomBindings(__instance.actionBindingsOnOpen);
}
[HarmonyPatch(typeof(XUiC_OptionsControls), nameof(XUiC_OptionsControls.storeCurrentBindings))]
[HarmonyPostfix]
private static void Postfix_storeCurrentBindings_XUiC_OptionsControls(XUiC_OptionsControls __instance)
{
CustomPlayerActionManager.StoreCurrentCustomBindings(__instance.actionBindingsOnOpen);
}
[HarmonyPatch(typeof(GameOptionsManager), nameof(GameOptionsManager.SaveControls))]
[HarmonyPostfix]
private static void Postfix_SaveControls_GameOptionsManager()
{
CustomPlayerActionManager.SaveCustomControls();
}
[HarmonyPatch(typeof(GameOptionsManager), nameof(GameOptionsManager.ResetGameOptions))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler_ResetGameOptions_GameOptionsManager(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
var mtd_save_controls = AccessTools.Method(typeof(GameOptionsManager), nameof(GameOptionsManager.SaveControls));
for (int i = 0; i < codes.Count; ++i)
{
if (codes[i].Calls(mtd_save_controls))
{
codes.Insert(i + 1, CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.ResetCustomControls)));
i++;
}
}
return codes;
}
[HarmonyPatch(typeof(ActionSetManager), nameof(ActionSetManager.LogActionSets))]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler_LogActionSets_ActionSetManager(IEnumerable<CodeInstruction> instructions)
{
var codes = new List<CodeInstruction>(instructions);
for(int i = codes.Count - 1; i >= 0; --i)
{
if (codes[i].opcode == OpCodes.Ldloc_1)
{
codes.Insert(i + 1, CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.CreateDebugInfo)));
break;
}
}
return codes;
}
}

138
Harmony/ReversePatches.cs Normal file
View File

@@ -0,0 +1,138 @@
using HarmonyLib;
using InControl;
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
internal static class ReversePatches
{
//[HarmonyPatch(typeof(XUiC_OptionsControls), nameof(XUiC_OptionsControls.createControlsEntries))]
//[HarmonyReversePatch(HarmonyReversePatchType.Snapshot)]
internal static void InitPlayerActionList(XUiC_OptionsControls __instance)
{
//IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
//{
// if (instructions == null)
// {
// yield break;
// }
// yield return CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.InitCustomControls));
// foreach (var code in instructions)
// {
// if (code.opcode != OpCodes.Stloc_1)
// {
// yield return code;
// }
// else
// {
// yield return new CodeInstruction(OpCodes.Pop);
// yield return new CodeInstruction(OpCodes.Ldloc_0);
// yield return CodeInstruction.Call(typeof(CustomPlayerActionManager), nameof(CustomPlayerActionManager.ResizeGrid));
// yield return new CodeInstruction(OpCodes.Ret);
// break;
// }
// }
//}
//_ = Transpiler(null);
SortedDictionary<PlayerActionData.ActionTab, SortedDictionary<PlayerActionData.ActionGroup, List<PlayerAction>>> sortedDictionary = new SortedDictionary<PlayerActionData.ActionTab, SortedDictionary<PlayerActionData.ActionGroup, List<PlayerAction>>>();
PlayerActionsBase[] array = CustomPlayerActionManager.CreateActionArray(new PlayerActionsBase[5]
{
__instance.xui.playerUI.playerInput,
__instance.xui.playerUI.playerInput.VehicleActions,
__instance.xui.playerUI.playerInput.PermanentActions,
__instance.xui.playerUI.playerInput.GUIActions,
PlayerActionsGlobal.Instance
});
for (int i = 0; i < array.Length; i++)
{
foreach (PlayerAction action in array[i].Actions)
{
if (!(action.UserData is PlayerActionData.ActionUserData actionUserData))
{
continue;
}
switch (actionUserData.appliesToInputType)
{
default:
throw new ArgumentOutOfRangeException();
case PlayerActionData.EAppliesToInputType.KbdMouseOnly:
case PlayerActionData.EAppliesToInputType.Both:
if (!actionUserData.doNotDisplay)
{
SortedDictionary<PlayerActionData.ActionGroup, List<PlayerAction>> sortedDictionary2;
if (sortedDictionary.ContainsKey(actionUserData.actionGroup.actionTab))
{
sortedDictionary2 = sortedDictionary[actionUserData.actionGroup.actionTab];
}
else
{
sortedDictionary2 = new SortedDictionary<PlayerActionData.ActionGroup, List<PlayerAction>>();
sortedDictionary.Add(actionUserData.actionGroup.actionTab, sortedDictionary2);
}
List<PlayerAction> list;
if (sortedDictionary2.ContainsKey(actionUserData.actionGroup))
{
list = sortedDictionary2[actionUserData.actionGroup];
}
else
{
list = new List<PlayerAction>();
sortedDictionary2.Add(actionUserData.actionGroup, list);
}
list.Add(action);
}
break;
case PlayerActionData.EAppliesToInputType.None:
case PlayerActionData.EAppliesToInputType.ControllerOnly:
break;
}
}
}
CustomPlayerActionManager.ResizeGrid(sortedDictionary);
}
internal static void InitControllerActionList(XUiC_OptionsController __instance)
{
PlayerActionsBase[] array = new PlayerActionsBase[]
{
__instance.xui.playerUI.playerInput,
__instance.xui.playerUI.playerInput.VehicleActions
};
Dictionary<string, List<PlayerAction>> dictionary = new Dictionary<string, List<PlayerAction>>();
dictionary.Add("inpTabPlayerOnFoot", new List<PlayerAction>());
PlayerActionsBase[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
foreach (PlayerAction playerAction in array2[i].ControllerRebindableActions)
{
PlayerActionData.ActionUserData actionUserData = playerAction.UserData as PlayerActionData.ActionUserData;
if (actionUserData != null)
{
if (actionUserData.actionGroup.actionTab.tabNameKey == "inpTabPlayerControl" || actionUserData.actionGroup.actionTab.tabNameKey == "inpTabToolbelt")
{
dictionary["inpTabPlayerOnFoot"].Add(playerAction);
}
else if (dictionary.ContainsKey(actionUserData.actionGroup.actionTab.tabNameKey))
{
dictionary[actionUserData.actionGroup.actionTab.tabNameKey].Add(playerAction);
}
else
{
dictionary.Add(actionUserData.actionGroup.actionTab.tabNameKey, new List<PlayerAction>());
dictionary[actionUserData.actionGroup.actionTab.tabNameKey].Add(playerAction);
}
}
}
}
dictionary["inpTabPlayerOnFoot"].Add(__instance.xui.playerUI.playerInput.PermanentActions.PushToTalk);
CustomPlayerActionManager.CreateControllerActions(dictionary);
CustomPlayerActionManager.ResizeControllerGrid(dictionary);
}
}