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

Refactoring #24

Merged
merged 5 commits into from
Feb 3, 2024
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
7 changes: 2 additions & 5 deletions AI_CheatTools/AI_CheatTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<Private>False</Private>
</Reference>
<Reference Include="AI_ExtensibleSaveFormat, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ExtensibleSaveFormat.AIGirl.16.4.0\lib\net46\AI_ExtensibleSaveFormat.dll</HintPath>
<HintPath>..\packages\ExtensibleSaveFormat.AIGirl.18.2.0\lib\net46\AI_ExtensibleSaveFormat.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down Expand Up @@ -122,18 +122,15 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CheatToolsPlugin.cs" />
<Compile Include="CheatToolsWindow.cs" />
<Compile Include="CheatToolsWindowInit.AI.cs" />
<Compile Include="Hooks\BuildAnywhereHooks.cs" />
<Compile Include="Hooks\BuildOverlapHooks.cs" />
<Compile Include="Hooks\FishingHackHooks.cs" />
<Compile Include="Hooks\UnlockCraftingHooks.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="..\Shared_Noclip\Shared_Noclip.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
44 changes: 0 additions & 44 deletions AI_CheatTools/CheatToolsPlugin.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AIChara;
using AIProject;
using AIProject.Definitions;
using AIProject.SaveData;
using BepInEx.Configuration;
using Manager;
using RuntimeUnityEditor.Core.Inspector;
using RuntimeUnityEditor.Core.Inspector.Entries;
using RuntimeUnityEditor.Core.ObjectTree;
using RuntimeUnityEditor.Core.Utils;
using UnityEngine;
using UnityEngine.AI;
using Map = Manager.Map;
using Resources = Manager.Resources;

Expand All @@ -30,8 +33,34 @@ public static class CheatToolsWindowInit
private static KeyValuePair<object, string>[] _openInInspectorButtons;
private static bool _expandDesires, _expandSkills;

public static void Initialize()
internal static ConfigEntry<bool> BuildAnywhere;
internal static ConfigEntry<bool> BuildOverlap;

public static void Initialize(CheatToolsPlugin instance)
{
var config = instance.Config;

BuildAnywhere = config.Bind("Cheats", "Allow building anywhere", false);
BuildAnywhere.SettingChanged += (sender, args) => BuildAnywhereHooks.Enabled = BuildAnywhere.Value;
BuildAnywhereHooks.Enabled = BuildAnywhere.Value;

BuildOverlap = config.Bind("Cheats", "Allow building overlap", false);
BuildOverlap.SettingChanged += (sender, args) => BuildOverlapHooks.Enabled = BuildOverlap.Value;
BuildOverlapHooks.Enabled = BuildOverlap.Value;

NoclipFeature.InitializeNoclip(instance, () =>
{
if (!Map.IsInstance()) return null;
if (Map.Instance.Player == null) return null;
if (Map.Instance.Player.Controller == null) return null;
return Map.Instance.Player.Controller.GetComponent<NavMeshAgent>();
});

ToStringConverter.AddConverter<AgentActor>(heroine => !string.IsNullOrEmpty(heroine.CharaName) ? heroine.CharaName : heroine.name);
ToStringConverter.AddConverter<AgentData>(d => $"AgentData - {d.CharaFileName} | {d.NowCoordinateFileName}");
ToStringConverter.AddConverter<ChaFile>(d => $"ChaFile - {d.charaFileName ?? "Unknown"} ({d.parameter?.fullname ?? "Unknown"})");
ToStringConverter.AddConverter<ChaControl>(d => $"{d} - {d.chaFile?.parameter?.fullname ?? d.chaFile?.charaFileName ?? "Unknown"}");

CheatToolsWindow.OnShown += _ =>
{
_studioInstance = Studio.Studio.IsInstance() ? Studio.Studio.Instance : null;
Expand All @@ -51,7 +80,7 @@ public static void Initialize()
new KeyValuePair<object, string>(AnimalManager.IsInstance() ? AnimalManager.Instance : null, "Manager.AnimalManager.Instance"),
new KeyValuePair<object, string>(_map, "Manager.Map.Instance"),
new KeyValuePair<object, string>(Character.IsInstance() ? Character.Instance : null, "Manager.Character.Instance"),
new KeyValuePair<object, string>(Config.IsInstance() ? Config.Instance : null, "Manager.Config.Instance"),
new KeyValuePair<object, string>(Manager.Config.IsInstance() ? Manager.Config.Instance : null, "Manager.Config.Instance"),
new KeyValuePair<object, string>(_gameMgr, "Manager.Game.Instance"),
new KeyValuePair<object, string>(Manager.Housing.IsInstance() ? Manager.Housing.Instance : null, "Manager.Housing.Instance"),
new KeyValuePair<object, string>(_sceneInstance, "Manager.Scene.Instance"),
Expand Down Expand Up @@ -104,8 +133,8 @@ private static void DrawPlayerCheats(CheatToolsWindow cheatToolsWindow)
UnlockCraftingHooks.Enabled = GUILayout.Toggle(UnlockCraftingHooks.Enabled, "Enable free crafting");
NoclipFeature.NoclipMode = GUILayout.Toggle(NoclipFeature.NoclipMode, "Enable player noclip");

CheatToolsPlugin.BuildAnywhere.Value = GUILayout.Toggle(CheatToolsPlugin.BuildAnywhere.Value, "Allow building anywhere");
CheatToolsPlugin.BuildOverlap.Value = GUILayout.Toggle(CheatToolsPlugin.BuildOverlap.Value, "Allow building items to overlap");
BuildAnywhere.Value = GUILayout.Toggle(BuildAnywhere.Value, "Allow building anywhere");
BuildOverlap.Value = GUILayout.Toggle(BuildOverlap.Value, "Allow building items to overlap");

if (_resources != null)
{
Expand Down
10 changes: 6 additions & 4 deletions AI_CheatTools/Hooks/BuildAnywhereHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public static bool Enabled
if (value != Enabled)
{
if (value)
{
_hInstance = Harmony.CreateAndPatchAll(typeof(BuildAnywhereHooks));
}
else
{
_hInstance.UnpatchSelf();
Expand All @@ -30,15 +32,15 @@ public static bool Enabled
}
}

[HarmonyPatch(typeof(GuideManager), "GridArea", MethodType.Getter)]
[HarmonyPatch(typeof(GuideManager), nameof(GuideManager.GridArea), MethodType.Getter)]
[HarmonyPrefix]
public static bool GetGridArea(ref Vector3 __result)
{
__result = new Vector3(15000f, 15000f, 15000f);
return false;
}

[HarmonyPatch(typeof(VirtualCameraController), "Update")]
[HarmonyPatch(typeof(VirtualCameraController), nameof(VirtualCameraController.Update))]
[HarmonyPrefix]
public static bool GetUpdate(ref VirtualCameraController __instance)
{
Expand All @@ -47,7 +49,7 @@ public static bool GetUpdate(ref VirtualCameraController __instance)
return false;
}

[HarmonyPatch(typeof(GuideRotation), "Round")]
[HarmonyPatch(typeof(GuideRotation), nameof(GuideRotation.Round))]
[HarmonyPrefix]
public static bool CustomRot(ref float __result, float _value)
{
Expand All @@ -56,4 +58,4 @@ public static bool CustomRot(ref float __result, float _value)
return false;
}
}
}
}
12 changes: 7 additions & 5 deletions AI_CheatTools/Hooks/BuildOverlapHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static bool Enabled
if (value != Enabled)
{
if (value)
{
_hInstance = Harmony.CreateAndPatchAll(typeof(BuildOverlapHooks));
}
else
{
_hInstance.UnpatchSelf();
Expand All @@ -29,14 +31,14 @@ public static bool Enabled
}

[HarmonyPrefix]
[HarmonyPatch(typeof(CraftInfo), "IsOverlapNow", MethodType.Getter)]
[HarmonyPatch(typeof(OCItem), "IsOverlapNow", MethodType.Getter)]
[HarmonyPatch(typeof(OCFolder), "IsOverlapNow", MethodType.Getter)]
[HarmonyPatch(typeof(ObjectCtrl), "IsOverlapNow", MethodType.Getter)]
[HarmonyPatch(typeof(CraftInfo), nameof(CraftInfo.IsOverlapNow), MethodType.Getter)]
[HarmonyPatch(typeof(OCItem), nameof(OCItem.IsOverlapNow), MethodType.Getter)]
[HarmonyPatch(typeof(OCFolder), nameof(OCFolder.IsOverlapNow), MethodType.Getter)]
[HarmonyPatch(typeof(ObjectCtrl), nameof(ObjectCtrl.IsOverlapNow), MethodType.Getter)]
public static bool GetIsOverlapNow(ref bool __result)
{
__result = false;
return false;
}
}
}
}
8 changes: 5 additions & 3 deletions AI_CheatTools/Hooks/FishingHackHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static bool Enabled
if (value != Enabled)
{
if (value)
{
_hInstance = Harmony.CreateAndPatchAll(typeof(FishingHackHooks));
}
else
{
_hInstance.UnpatchSelf();
Expand All @@ -29,13 +31,13 @@ public static bool Enabled
}

[HarmonyPrefix]
[HarmonyPatch(typeof(FishingManager), "CheckArrowInCircle")]
[HarmonyPatch(typeof(FishingManager), nameof(FishingManager.CheckArrowInCircle))]
public static bool CheckPossible(FishingManager __instance, ref float ___fishHeartPoint)
{
___fishHeartPoint = 0f;
__instance.scene = FishingManager.FishingScene.Success;
AccessTools.Method(typeof(FishingManager), "SceneToSuccess").Invoke(__instance, null);
AccessTools.Method(typeof(FishingManager), nameof(FishingManager.SceneToSuccess)).Invoke(__instance, null);
return false;
}
}
}
}
13 changes: 7 additions & 6 deletions AI_CheatTools/Hooks/UnlockCraftingHooks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using AIProject;
using AIProject.UI;
using AIProject.UI.Viewer;
Expand Down Expand Up @@ -37,15 +38,15 @@ public static bool Enabled
}

[HarmonyPrefix]
[HarmonyPatch(typeof(CraftUI), "Possible")]
[HarmonyPatch(typeof(CraftUI), nameof(CraftUI.Possible))]
public static bool CheckPossible(ref RecipeDataInfo[] __result, RecipeDataInfo[] info)
{
__result = info;
return false;
}

[HarmonyPrefix]
[HarmonyPatch(typeof(CraftViewer), "Possible")]
[HarmonyPatch(typeof(CraftViewer), nameof(CraftViewer.Possible))]
public static bool CheckPossible(ref CraftItemNodeUI.Possible __result)
{
__result = new CraftItemNodeUI.Possible(false, true);
Expand All @@ -54,7 +55,7 @@ public static bool CheckPossible(ref CraftItemNodeUI.Possible __result)

// How many of required items are available
[HarmonyPrefix]
[HarmonyPatch(typeof(RecipeItemNodeUI), "ItemCount", MethodType.Getter)]
[HarmonyPatch(typeof(RecipeItemNodeUI), nameof(RecipeItemNodeUI.ItemCount), MethodType.Getter)]
public static bool GetCraftItemUIItemCount(ref int __result)
{
__result = 9999;
Expand All @@ -63,7 +64,7 @@ public static bool GetCraftItemUIItemCount(ref int __result)

private static void LoadInfoCtor(Manager.Housing.LoadInfo __instance)
{
__instance.requiredMaterials = new Manager.Housing.RequiredMaterial[0];
__instance.requiredMaterials = Array.Empty<Manager.Housing.RequiredMaterial>();
}
}
}
}
4 changes: 0 additions & 4 deletions AI_CheatTools/Properties/AssemblyInfo.cs

This file was deleted.

30 changes: 15 additions & 15 deletions AI_CheatTools/packages.config
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExtensibleSaveFormat.AIGirl" version="16.4.0" targetFramework="net46" developmentDependency="true" />
<package id="HarmonyX" version="2.6.0" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp-firstpass" version="2020.5.29.4" targetFramework="net46" />
<package id="ExtensibleSaveFormat.AIGirl" version="18.2.0" targetFramework="net46" developmentDependency="true" />
<package id="HarmonyX" version="2.6.0" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.Assembly-CSharp-firstpass" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.Sirenix.Serialization" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UniRx" version="2020.5.29.4" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.UnityEngine.AIModule" version="2018.2.21.4" targetFramework="net46" />
<package id="IllusionLibs.AIGirl.UniRx" version="2020.5.29.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UnityEngine.AIModule" version="2018.2.21.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UnityEngine.CoreModule" version="2018.2.21.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.AIGirl.UnityEngine.IMGUIModule" version="2018.2.21.4" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.BepInEx" version="5.4.20" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.Harmony" version="2.9.0" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.MonoMod" version="21.8.5.1" targetFramework="net46" />
<package id="IllusionModdingAPI.AIAPI" version="1.29.1" targetFramework="net46" developmentDependency="true" />
<package id="Mono.Cecil" version="0.11.4" targetFramework="net46" />
<package id="MonoMod.RuntimeDetour" version="21.11.1.1" targetFramework="net46" />
<package id="MonoMod.Utils" version="21.11.1.1" targetFramework="net46" />
<package id="RuntimeUnityEditor.Core" version="4.0.0.1" targetFramework="net46" developmentDependency="true" />
<package id="Unity.InputSystem" version="1.5.0" targetFramework="net46" />
<package id="IllusionLibs.BepInEx" version="5.4.20" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.Harmony" version="2.9.0" targetFramework="net46" developmentDependency="true" />
<package id="IllusionLibs.BepInEx.MonoMod" version="21.8.5.1" targetFramework="net46" developmentDependency="true" />
<package id="IllusionModdingAPI.AIAPI" version="1.29.1" targetFramework="net46" />
<package id="Mono.Cecil" version="0.11.4" targetFramework="net46" developmentDependency="true" />
<package id="MonoMod.RuntimeDetour" version="21.11.1.1" targetFramework="net46" developmentDependency="true" />
<package id="MonoMod.Utils" version="21.11.1.1" targetFramework="net46" developmentDependency="true" />
<package id="RuntimeUnityEditor.Core" version="4.0.0.1" targetFramework="net46" developmentDependency="true" />
<package id="Unity.InputSystem" version="1.5.0" targetFramework="net46" developmentDependency="true" />
</packages>
12 changes: 7 additions & 5 deletions HC_CheatTools/CheatToolsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

namespace CheatTools
{
[BepInPlugin(Metadata.GUID, "Cheat Tools", Version)]
[BepInPlugin(GUID, DisplayName, Version)]
[BepInDependency(RuntimeUnityEditorCore.GUID, RuntimeUnityEditorCore.Version)]
[BepInProcess("HoneyCome")]
[BepInProcess("HoneyCome")] // Studio is missing some important classes, so we can't run in it
public class CheatToolsPlugin : BasePlugin
{
public const string DisplayName = Metadata.DisplayName;
public const string GUID = Metadata.GUID;
public const string Version = Metadata.Version;

internal static new ManualLogSource Logger;
Expand All @@ -22,16 +24,16 @@ public CheatToolsPlugin()

public override void Load()
{
CheatToolsWindowInit.Initialize(this);

var runtimeUnityEditorCore = RuntimeUnityEditorCore.Instance;
if (runtimeUnityEditorCore == null)
{
Logger.Log(LogLevel.Error | LogLevel.Message, "Failed to get RuntimeUnityEditor! Make sure you don't have multiple versions of it installed!");
return;
}

CheatToolsWindowInit.InitializeCheats();

runtimeUnityEditorCore.AddFeature(new CheatToolsWindow(runtimeUnityEditorCore));
}
}
}
}
Loading