Skip to content

Commit

Permalink
Cleaned, made more robust, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krypto5863 committed Aug 3, 2022
1 parent 069c1dd commit d56eee4
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 52 deletions.
19 changes: 14 additions & 5 deletions MenuDatabaseReplacer/CacheFile.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShortMenuVanillaDatabase
{
Expand All @@ -10,11 +10,12 @@ public class CacheFile
public Dictionary<string, DateTime> CachedLoadedAndDatedArcs { get; set; }
public HashSet<CacheFile.MenuStub> MenusList { get; set; }

public CacheFile()
public CacheFile()
{
CachedLoadedAndDatedArcs = new Dictionary<string, DateTime>();
MenusList = new HashSet<MenuStub>();
}

public class MenuStub
{
public string FileName { get; set; }
Expand All @@ -24,15 +25,23 @@ public class MenuStub
public int Version { get; set; }
public string Icon { get; set; }
public string Description { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
public MPN Category { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
public MPN ColorSetMPN { get; set; }

public string ColorSetMenu { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
public MaidParts.PARTS_COLOR MultiColorID { get; set; }

public bool DelMenu { get; set; }
public bool ManMenu { get; set; }
public float Priority { get; set; }
public bool LegacyMenu { get; set; }
public string SourceArc { get; set; }
}
}
}
}
20 changes: 14 additions & 6 deletions MenuDatabaseReplacer/JustLogging.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShortMenuVanillaDatabase
{
class JustLogging
internal class JustLogging
{
[HarmonyPatch(typeof(MenuDataBase), "JobFinished")]
[HarmonyPostfix]
Expand Down Expand Up @@ -35,44 +31,51 @@ private static void getver(ref int __result)
{
Main.logger.LogDebug($"returning version of {__result}");
}

//Unimplemented...
[HarmonyPatch(typeof(MenuDataBase), "GetNativeHash")]
[HarmonyPostfix]
private static void givehash(ref ulong __result)
{
Main.logger.LogDebug($"returning hash of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetMenuFileName")]
[HarmonyPostfix]
private static void menufilename(ref string __result)
{
Main.logger.LogDebug($"returning menufilename of {__result}");
}

//Not Implemented...
[HarmonyPatch(typeof(MenuDataBase), "GetParentMenuFileName")]
[HarmonyPostfix]
private static void parentmenufile(ref string __result)
{
Main.logger.LogDebug($"returning parentmenufile of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetSrcFileName")]
[HarmonyPostfix]
private static void getsrcfilename(ref string __result)
{
Main.logger.LogDebug($"returning srcfilename of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetItemName")]
[HarmonyPostfix]
private static void getitemanme(ref string __result)
{
Main.logger.LogDebug($"returning returning item name of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetCategoryName")]
[HarmonyPostfix]
private static void categoryname(ref string __result)
{
Main.logger.LogDebug($"returning category of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetInfoText")]
[HarmonyPostfix]
private static void returninginfotext(ref string __result)
Expand Down Expand Up @@ -135,31 +138,36 @@ private static void geticonstring(ref string __result)
{
Main.logger.LogDebug($"returning icon of {__result}");
}

//Not Implemented...
[HarmonyPatch(typeof(MenuDataBase), "GetSaveItem")]
[HarmonyPostfix]
private static void getsaveitem(ref string __result)
{
Main.logger.LogDebug($"returning save item of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetBoDelOnly")]
[HarmonyPostfix]
private static void bodel(ref bool __result)
{
Main.logger.LogDebug($"returning delmenu of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetPriority")]
[HarmonyPostfix]
private static void priority(ref float __result)
{
Main.logger.LogDebug($"returning priority of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetIsMan")]
[HarmonyPostfix]
private static void getisman(ref bool __result)
{
Main.logger.LogDebug($"returning is man menu of {__result}");
}

//Not Implemented...
[HarmonyPatch(typeof(MenuDataBase), "GetIsCollabo")]
[HarmonyPostfix]
Expand All @@ -171,4 +179,4 @@ private static void iscoll(ref bool __result, MenuDataBase __instance)
}
}
}
}
}
38 changes: 31 additions & 7 deletions MenuDatabaseReplacer/Main.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;

//These two lines tell your plugin to not give a flying fuck about accessing private variables/classes whatever. It requires a publicized stubb of the library with those private objects though.
[module: UnverifiableCode]
Expand All @@ -17,21 +15,24 @@
namespace ShortMenuVanillaDatabase
{
//This is the metadata set for your plugin.
[BepInPlugin("ShortMenuVanillaDatabase", "ShortMenuVanillaDatabase", "1.1.3")]
[BepInPlugin("ShortMenuVanillaDatabase", "ShortMenuVanillaDatabase", "1.2")]
public class Main : BaseUnityPlugin
{
public static Main @this;

//Static var for the logger so you can log from other classes.
public static ManualLogSource logger;

//This is where the magic happens.
public static MenuDatabaseReplacement Database;

//I'd rather not use an index tbh but whatever, Kiss's implementation is literally retarded.
private static Dictionary<MenuDataBase, int> IndexToRead = new Dictionary<MenuDataBase, int>();

//Config entry variable. You set your configs to this.
//internal static ConfigEntry<bool> ExampleConfig;

static Harmony harmony;
private static Harmony harmony;

private void Awake()
{
Expand All @@ -46,14 +47,24 @@ private void Awake()

//Installs the patches in the Main class.

var Plugs = Directory.GetFiles(BepInEx.Paths.PluginPath, "*", SearchOption.AllDirectories)
.Select(t => Path.GetFileName(t).ToLower());

var HasDependencies = Plugs.Contains("system.threading.dll") && Plugs.Contains("cm3d2.toolkit.guest4168branch.dll");

if (!HasDependencies)
{
Main.logger.LogFatal("SMVD is missing some dependencies! SMVD will not operate correctly and neither will your game!");
}

#if !OnlyCompare
harmony = Harmony.CreateAndPatchAll(typeof(Main));
#else
//Harmony.CreateAndPatchAll(typeof(JustLogging));
#endif
}

//Basic harmony patch format. You specify the class to be patched and the method within that class to be patched. This patcher prefixes the method, meaning it runs before the patched method does. You can also postfix, run after the method patches and do lots of things like change parameters and results with harmony patching. Very powerful.
//Basic harmony patch format. You specify the class to be patched and the method within that class to be patched. This patcher prefixes the method, meaning it runs before the patched method does. You can also postfix, run after the method patches and do lots of things like change parameters and results with harmony patching. Very powerful.
[HarmonyPatch(typeof(MenuDataBase), MethodType.Constructor, new Type[] { typeof(IntPtr), typeof(EnumData), typeof(EnumData) })]
[HarmonyPrefix]
private static void BuildingDatabase()
Expand Down Expand Up @@ -89,6 +100,7 @@ private static bool StartLoad()
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "Dispose", new Type[] { typeof(bool) })]
[HarmonyPrefix]
private static bool DisposeVar(MenuDataBase __instance)
Expand Down Expand Up @@ -165,6 +177,7 @@ private static bool GetVersion(ref int __result, ref MenuDataBase __instance)
return true;
#endif
}

//Unimplemented... It's mostly only used within MenuDataBase for some functions. We don't need it.
[HarmonyPatch(typeof(MenuDataBase), "GetNativeHash")]
[HarmonyPrefix]
Expand All @@ -178,6 +191,7 @@ private static bool HashGet(ref ulong __result, ref MenuDataBase __instance)
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetMenuFileName")]
[HarmonyPrefix]
private static bool MenuName(ref string __result, ref MenuDataBase __instance)
Expand All @@ -190,6 +204,7 @@ private static bool MenuName(ref string __result, ref MenuDataBase __instance)
return true;
#endif
}

//Not Implemented... Never really called though. What's even the point?
[HarmonyPatch(typeof(MenuDataBase), "GetParentMenuFileName")]
[HarmonyPrefix]
Expand All @@ -203,6 +218,7 @@ private static bool ParentMenuName(ref string __result, ref MenuDataBase __insta
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetSrcFileName")]
[HarmonyPrefix]
private static bool GetSrcFileName(ref string __result, ref MenuDataBase __instance)
Expand All @@ -215,6 +231,7 @@ private static bool GetSrcFileName(ref string __result, ref MenuDataBase __insta
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetItemName")]
[HarmonyPrefix]
private static bool GetName(ref string __result, ref MenuDataBase __instance)
Expand All @@ -227,6 +244,7 @@ private static bool GetName(ref string __result, ref MenuDataBase __instance)
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetCategoryName")]
[HarmonyPrefix]
private static bool GetCategory(ref string __result, ref MenuDataBase __instance)
Expand All @@ -239,6 +257,7 @@ private static bool GetCategory(ref string __result, ref MenuDataBase __instance
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetInfoText")]
[HarmonyPrefix]
private static bool GetInfoText(ref string __result, ref MenuDataBase __instance)
Expand Down Expand Up @@ -355,6 +374,7 @@ private static bool GetIconS(ref string __result, ref MenuDataBase __instance)
return true;
#endif
}

//Not Implemented... Same deal, and I've yet to see it do anything. Will eventually implement.
[HarmonyPatch(typeof(MenuDataBase), "GetSaveItem")]
[HarmonyPrefix]
Expand All @@ -368,6 +388,7 @@ private static bool GetSaveItem(ref string __result)
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetBoDelOnly")]
[HarmonyPrefix]
private static bool GetBoDelOnly(ref bool __result, ref MenuDataBase __instance)
Expand All @@ -380,6 +401,7 @@ private static bool GetBoDelOnly(ref bool __result, ref MenuDataBase __instance)
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetPriority")]
[HarmonyPrefix]
private static bool GetPriority(ref float __result, ref MenuDataBase __instance)
Expand All @@ -392,6 +414,7 @@ private static bool GetPriority(ref float __result, ref MenuDataBase __instance)
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "GetIsMan")]
[HarmonyPrefix]
private static bool GetIsMan(ref bool __result, ref MenuDataBase __instance)
Expand All @@ -404,6 +427,7 @@ private static bool GetIsMan(ref bool __result, ref MenuDataBase __instance)
return true;
#endif
}

//Not Implemented... I don't even think this does anything but return false though...
[HarmonyPatch(typeof(MenuDataBase), "GetIsCollabo")]
[HarmonyPrefix]
Expand All @@ -418,4 +442,4 @@ private static bool GetIsCollabo(ref bool __result)
#endif
}
}
}
}
Loading

0 comments on commit d56eee4

Please sign in to comment.