Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Harmony mod into Tweaks #26

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/! Old Projects/
/! Automation/node_modules
/[Ll]ibrary/
.vs
.vs
.idea
Binary file modified Tweaks/Assets/CustomAssemblies/TweaksAssembly.dll
Binary file not shown.
7 changes: 0 additions & 7 deletions Tweaks/Assets/CustomAssemblies/TweaksAssembly.dll.mdb.meta

This file was deleted.

Binary file modified Tweaks/Assets/CustomAssemblies/TweaksAssembly.pdb
Binary file not shown.
Binary file added Tweaks/Assets/HarmonyLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions Tweaks/Assets/HarmonyLogo.png.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Tweaks/Assets/Tweaks.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,7 @@ GameObject:
- component: {fileID: 114820551977261236}
- component: {fileID: 114476729585178434}
- component: {fileID: 114185708029586830}
- component: {fileID: 114896487176763920}
m_Layer: 0
m_Name: Tweaks
m_TagString: Untagged
Expand Down Expand Up @@ -4752,6 +4753,7 @@ MonoBehaviour:
SolvesPrefab: {fileID: 114413820837038322}
NeediesPrefab: {fileID: 114149257704933498}
ConfidencePrefab: {fileID: 114481655518132758}
currentBomb: {fileID: 0}
--- !u!114 &114005097899498534
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down Expand Up @@ -6716,6 +6718,18 @@ MonoBehaviour:
m_EditorClassIdentifier:
ShaderNames:
- GUI/KT 3D Text
--- !u!114 &114896487176763920
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1753844279872294}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -234249795, guid: f9655ca10095c2c45b4f86c01198f02e, type: 3}
m_Name:
m_EditorClassIdentifier:
HarmonyTexture: {fileID: 2800000, guid: 409387a4068e84f94acfb31f0058db57, type: 3}
--- !u!114 &114902843554147134
MonoBehaviour:
m_ObjectHideFlags: 1
Expand Down
168 changes: 168 additions & 0 deletions Tweaks/TweaksAssembly/HarmonyModPatches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
using System.Collections.Generic;
using System.Reflection.Emit;
using System.IO;
using System.Linq;
using Assets.Scripts.Mods;
using Assets.Scripts.Services;
using Assets.Scripts.Settings;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

namespace TweaksAssembly.Patching
{
internal static class HarmonyPatchInfo
{
public static string ModInfoFile = "modInfo.json";
public static Texture HarmonyTexture;

public static bool ToggleModInfo()
{
if (ModInfoFile == "modInfo.json")
{
ModInfoFile = "modInfo_Harmony.json";
return false;
}
ModInfoFile = "modInfo.json";
return true;
}
}

[HarmonyPatch(typeof(ModManager), "GetModInfoFromPath")]
[HarmonyPriority(Priority.First)]
internal static class ModInfoPatch
{
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
foreach (var instruction in instructions)
{
if (instruction.opcode == OpCodes.Ldstr && (string) instruction.operand == "modInfo.json")
yield return new CodeInstruction(OpCodes.Ldsfld,
typeof(HarmonyPatchInfo).GetField("ModInfoFile", AccessTools.all));
else yield return instruction;
}
}
}

[HarmonyPatch(typeof(ManageModsScreen), "OnEnable")]
[HarmonyPriority(Priority.First)]
internal static class WorkshopPatch
{
public static bool Prefix(ManageModsScreen __instance, ref List<ModInfo> ___installedMods, ref List<ModInfo> ___fullListOfMods, ref List<ModInfo> ___allSubscribedMods)
{
ModManager.Instance.ReloadModMetaData();
___installedMods = ModManager.Instance.InstalledModInfos.Values
.Where(info => File.Exists(Path.Combine(info.FilePath, HarmonyPatchInfo.ModInfoFile))).ToList();
___allSubscribedMods = AbstractServices.Instance.GetSubscribedMods();
___fullListOfMods = HarmonyPatchInfo.ModInfoFile == "modInfo.json"
? ___installedMods.Union(___allSubscribedMods).ToList()
: ___installedMods;
___fullListOfMods.Sort((ModInfo a, ModInfo b) => a.Title.CompareTo(b.Title));
Traverse.Create(__instance).Method("ShowMods").GetValue();
return false;
}
}

[HarmonyPatch(typeof(ModManagerManualInstructionScreen), "HandleContinue")]
[HarmonyPriority(Priority.First)]
internal static class ContinueButtonPatch
{
public static bool Prefix(ModManagerManualInstructionScreen __instance, out bool __result)
{
bool cont = HarmonyPatchInfo.ToggleModInfo();
ManualButtonPatch.AutoCloseManager = false;
__result = false;
if (cont)
return true;
__instance.ReleaseSelection();
SceneManager.Instance.EnterModManagerState();
return false;
}
}

[HarmonyPatch(typeof(ModManagerManualInstructionScreen), "HandleOpenManualFolder")]
[HarmonyPriority(Priority.First)]
internal static class ManualButtonPatch
{
public static bool AutoCloseManager;

public static bool Prefix(ModManagerManualInstructionScreen __instance, out bool __result)
{
bool value = ContinueButtonPatch.Prefix(__instance, out __result);
if(value)
return true;
AutoCloseManager = true;
return false;
}
}

[HarmonyPatch(typeof(ModManagerState), "ShouldShowManualInstructions")]
[HarmonyPriority(Priority.First)]
internal static class InstructionPatch
{
public static bool Prefix(out bool __result)
{
__result = true;
return false;
}
}

[HarmonyPatch(typeof(ModManagerHoldable), "GoToModManagerState")]
[HarmonyPriority(Priority.First)]
internal static class ModManagerPatch
{
public static void Prefix()
{
ChangeButtonText.AllowAutoContinue = false;
}
}

[HarmonyPatch(typeof(MenuScreen), "EnterScreenComplete")]
[HarmonyPriority(Priority.First)]
internal static class ChangeButtonText
{
public static bool AllowAutoContinue = true;

public static void Postfix(MenuScreen __instance)
{
if (HarmonyPatchInfo.ModInfoFile == "modInfo.json")
{
if (__instance is ModManagerManualInstructionScreen screen)
{
screen.ContinueButton.GetComponentInChildren<TextMeshProUGUI>(true)
.text = "Manage Harmony mods";
screen.OpenManualFolderButton.GetComponentInChildren<TextMeshProUGUI>(true).text =
"Skip Harmony manager";
MonoBehaviour.Destroy(screen.GetComponentInChildren<RawImage>());
var texts = screen.GetComponentsInChildren<TextMeshProUGUI>(true);
texts[1].text =
"Click this button if you'd like to skip the Harmony mod manager and load the Harmony mods that according to the previous configuration!";
texts[5].text =
"Or click this button if you'd like to select which Harmony mods should be enabled or disabled!";
texts[5].transform.localPosition = new Vector3(texts[5].transform.localPosition.x + 190,
texts[5].transform.localPosition.y - 90, texts[5].transform.localPosition.z);
if (Tweaks.settings.AutoSkipFinalizeScreen || (AllowAutoContinue && PlayerSettingsManager.Instance.PlayerSettings.UseModsAlways))
screen.OpenManualFolderButton.OnInteract();
}
}
else if (ManualButtonPatch.AutoCloseManager && __instance is ModManagerManualInstructionScreen ManualScreen)
ManualScreen.ContinueButton.OnInteract();
else if (__instance is ModManagerMainMenuScreen MenuScreen)
{
MenuScreen.SteamWorkshopBrowserButton.gameObject.SetActive(false);
MenuScreen.GetComponentInChildren<TextMeshProUGUI>().text = "Harmony Mod Manager";
var image = MenuScreen.GetComponentInChildren<RawImage>();
image.texture = HarmonyPatchInfo.HarmonyTexture;
image.transform.localScale = new Vector3(image.transform.localScale.x + 1,
image.transform.localScale.y, image.transform.localScale.z);
MenuScreen.ManageModsButton.GetComponentInChildren<TextMeshProUGUI>(true).text =
"Manage Harmony mods";
if (ManualButtonPatch.AutoCloseManager)
MenuScreen.ReturnToGameButton.OnInteract();
}
else if(__instance is ManageModsScreen ManagerScreen)
ManagerScreen.GetComponentInChildren<TextMeshProUGUI>().text = "Manage installed Harmony mods";
}
}
}
10 changes: 8 additions & 2 deletions Tweaks/TweaksAssembly/Tweaks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -71,7 +71,11 @@ public void Awake()
modConfig = new ModConfig<TweakSettings>("TweakSettings", OnReadError);
UpdateSettings();
StartCoroutine(Modes.LoadDefaultSettings());


HarmonyPatchInfo.HarmonyTexture = GetComponent<TweaksStorage>().HarmonyTexture;
Patching.EnsurePatch("Harmony", typeof(ModInfoPatch), typeof(WorkshopPatch), typeof(ContinueButtonPatch),
typeof(ManualButtonPatch), typeof(InstructionPatch), typeof(ModManagerPatch), typeof(ChangeButtonText));

DemandBasedLoading.EverLoadedModules = !settings.DemandBasedModLoading;
DemandBasedSettingCache = settings.DemandBasedModLoading;

Expand Down Expand Up @@ -863,6 +867,7 @@ void LogChildren(Transform goTransform, int depth = 0)
},
new Dictionary<string, object> { { "Key", "FadeTime" }, { "Text", "Fade Time" }, { "Description", "The number seconds should it take to fade in and out of scenes." } },
new Dictionary<string, object> { { "Key", "InstantSkip" }, { "Text", "Instant Skip" }, { "Description", "Skips the gameplay loading screen as soon as possible." } },
new Dictionary<string, object> {{"Key", "AutoSkipFinalizeScreen"}, {"Text", "Auto-skip Finalize Screen"}, {"Description", "Automatically skips the Harmony Manager loading the enabled mods."}},
new Dictionary<string, object> { { "Key", "SkipGameplayDelay" }, { "Text", "Skip Gameplay Delay" }, { "Description", "Skips the delay at the beginning of a round when the lights are out." } },
new Dictionary<string, object> { { "Key", "BetterCasePicker" }, { "Text", "Better Case Picker" }, { "Description", "Chooses the smallest case that fits instead of a random one." } },
new Dictionary<string, object> { { "Key", "EnableModsOnlyKey" }, { "Text", "Enable Mods Only Key" }, { "Description", "Turns the Mods Only key to be on by default." } },
Expand Down Expand Up @@ -922,6 +927,7 @@ class TweakSettings
{
public float FadeTime = 1f;
public bool InstantSkip = true;
public bool AutoSkipFinalizeScreen = false;
public bool SkipGameplayDelay = false;
public bool BetterCasePicker = true;
public bool EnableModsOnlyKey = false;
Expand Down
6 changes: 6 additions & 0 deletions Tweaks/TweaksAssembly/TweaksStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using UnityEngine;

class TweaksStorage : MonoBehaviour
{
public Texture HarmonyTexture;
}