-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
97 lines (83 loc) · 3.01 KB
/
Plugin.cs
File metadata and controls
97 lines (83 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using PotionCraft.Assemblies.AchievementsSystem;
using PotionCraft.ManagersSystem.Application;
using PotionCraft.ManagersSystem.Debug;
using PotionCraft.SceneLoader;
using PotionCraft.Settings;
namespace EnableDev;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource Log;
private const string HarmonyID = "com.github.qe201020335.PotionCraftEnableDev";
private readonly Harmony _harmony = new Harmony(HarmonyID);
private static ConfigEntry<bool> EnableDevModeOnStart;
private static ConfigEntry<bool> EnableCheatCodes;
internal static ConfigEntry<bool> EnableAchievementsOnDevMode { get; private set; }
private void Awake()
{
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
Log = Logger;
EnableDevModeOnStart = Config.Bind("General", "EnableDevModeOnStart", true,
"Whether the game will start with developer mode enabled as default");
EnableCheatCodes = Config.Bind("General", "EnableCheatCodes", true,
"Enable cheat codes?");
EnableAchievementsOnDevMode = Config.Bind("General", "EnableAchievementsOnDevMode", true,
"Enable achievements when developer mode is active?");
_harmony.PatchAll();
}
internal static void ModifyBuildConfig()
{
Log.LogInfo("Modifying game build settings!");
if (EnableDevModeOnStart.Value)
{
Log.LogDebug("Enable dev mode on start");
Settings<ApplicationManagerSettings>.Asset.developerModeOnStartInBuild = true;
}
if (EnableCheatCodes.Value)
{
Log.LogDebug("Enable cheat codes");
Settings<DebugManagerSettings>.Asset.cheatCodesDebug = true;
}
}
}
[HarmonyPatch(typeof(LoadingQueue), "Add")]
public static class LoadingQueuePatch
{
[HarmonyPrefix]
public static void Patch(string name, Action action)
{
// Plugin.Log.LogDebug($"{name}");
if (name == "InitializeDeveloperMode")
{
Plugin.ModifyBuildConfig();
}
}
}
[HarmonyPatch]
public static class AchievementsManagerPatch
{
[HarmonyTargetMethods]
public static IEnumerable<MethodBase> Methods()
{
return typeof(AchievementsManager)
.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
.Where(m => m.Name == nameof(AchievementsManager.UnlockAchievement))
.Append(AccessTools.Method(typeof(AchievementsManager), nameof(AchievementsManager.RetrounlockAchievement)));
}
[HarmonyPrefix]
public static void Patch(ref bool isDeveloperMode)
{
if (Plugin.EnableAchievementsOnDevMode.Value)
{
isDeveloperMode = false;
}
}
}