Skip to content

Commit

Permalink
Code cleansing, might've fixed a long standing error.
Browse files Browse the repository at this point in the history
  • Loading branch information
krypto5863 committed Jan 23, 2023
1 parent 753905f commit d12344d
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 295 deletions.
21 changes: 15 additions & 6 deletions MenuDatabaseReplacer/CacheFile.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace ShortMenuVanillaDatabase
{
public class CacheFile
{
public Dictionary<string, DateTime> CachedLoadedAndDatedArcs { get; set; }
public List<CacheFile.MenuStub> MenusList { get; set; }
public List<MenuStub> MenusList { get; set; }

public CacheFile()
{
Expand All @@ -18,6 +18,15 @@ public CacheFile()

public class MenuStub
{
public MenuStub()
{
}

public MenuStub(string fileName)
{
FileName = fileName;
}

public string FileName { get; set; }
public string PathInMenu { get; set; }
public ulong Hash { get; set; }
Expand All @@ -30,12 +39,12 @@ public class MenuStub
public MPN Category { get; set; }

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

public string ColorSetMenu { get; set; }

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

public bool DelMenu { get; set; }
public bool ManMenu { get; set; }
Expand Down
48 changes: 24 additions & 24 deletions MenuDatabaseReplacer/JustLogging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,164 +8,164 @@ internal class JustLogging
[HarmonyPostfix]
private static void IsFinished(ref bool __result)
{
Main.logger.LogDebug($"A call to check if job was finished was made, returned {__result}");
Main.PLogger.LogDebug($"A call to check if job was finished was made, returned {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetDataSize")]
[HarmonyPostfix]
private static void GiveDataSize(ref int __result)
{
Main.logger.LogDebug($"returning size of {__result}");
Main.PLogger.LogDebug($"returning size of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "IsHeaderCheck")]
[HarmonyPostfix]
private static void header(ref bool __result)
{
Main.logger.LogDebug($"returning headercheck of {__result}");
Main.PLogger.LogDebug($"returning headercheck of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetVersion")]
[HarmonyPostfix]
private static void getver(ref int __result)
{
Main.logger.LogDebug($"returning version of {__result}");
Main.PLogger.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}");
Main.PLogger.LogDebug($"returning hash of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetMenuFileName")]
[HarmonyPostfix]
private static void menufilename(ref string __result)
{
Main.logger.LogDebug($"returning menufilename of {__result}");
Main.PLogger.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}");
Main.PLogger.LogDebug($"returning parentmenufile of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetSrcFileName")]
[HarmonyPostfix]
private static void getsrcfilename(ref string __result)
{
Main.logger.LogDebug($"returning srcfilename of {__result}");
Main.PLogger.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}");
Main.PLogger.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}");
Main.PLogger.LogDebug($"returning category of {__result}");
}

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

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

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

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

[HarmonyPatch(typeof(MenuDataBase), "GetCategoryMpn")]
[HarmonyPostfix]
private static void categorympn(ref int __result)
{
Main.logger.LogDebug($"returning category mpn of {__result}");
Main.PLogger.LogDebug($"returning category mpn of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetColorSetMpn")]
[HarmonyPostfix]
private static void colorsetmpn(ref int __result)
{
Main.logger.LogDebug($"returning colorsetmpn of {__result}");
Main.PLogger.LogDebug($"returning colorsetmpn of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetMenuNameInColorSet")]
[HarmonyPostfix]
private static void getmenucolor(ref string __result)
{
Main.logger.LogDebug($"returning menu color of {__result}");
Main.PLogger.LogDebug($"returning menu color of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetMultiColorId")]
[HarmonyPostfix]
private static void multicolorid(ref int __result)
{
Main.logger.LogDebug($"returning multicolorid of {__result}");
Main.PLogger.LogDebug($"returning multicolorid of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetIconS")]
[HarmonyPostfix]
private static void geticonstring(ref string __result)
{
Main.logger.LogDebug($"returning icon of {__result}");
Main.PLogger.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}");
Main.PLogger.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}");
Main.PLogger.LogDebug($"returning delmenu of {__result}");
}

[HarmonyPatch(typeof(MenuDataBase), "GetPriority")]
[HarmonyPostfix]
private static void priority(ref float __result)
{
Main.logger.LogDebug($"returning priority of {__result}");
Main.PLogger.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}");
Main.PLogger.LogDebug($"returning is man menu of {__result}");
}

//Not Implemented...
Expand All @@ -175,7 +175,7 @@ private static void iscoll(ref bool __result, MenuDataBase __instance)
{
if (__result == true)
{
Main.logger.LogDebug($"returning is collabo of {__result} for {__instance.GetMenuFileName()}");
Main.PLogger.LogDebug($"returning is collabo of {__result} for {__instance.GetMenuFileName()}");
}
}
}
Expand Down
48 changes: 26 additions & 22 deletions MenuDatabaseReplacer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,34 @@
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security;
using System.Security.Permissions;

//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.
//These two lines tell your plugin to not give a flying fuck about accessing private variables/classes whatever. It requires a publicized stub of the library with those private objects though.
[module: UnverifiableCode]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]

namespace ShortMenuVanillaDatabase
{
//This is the metadata set for your plugin.
[BepInPlugin("ShortMenuVanillaDatabase", "ShortMenuVanillaDatabase", "1.2")]
[SuppressMessage("ReSharper", "InconsistentNaming")]
[SuppressMessage("ReSharper", "RedundantAssignment")]
public class Main : BaseUnityPlugin
{
public static Main @this;
public static Main This;

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

//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>();
private static readonly Dictionary<MenuDataBase, int> IndexToRead = new Dictionary<MenuDataBase, int>();

//Config entry variable. You set your configs to this.
//internal static ConfigEntry<bool> ExampleConfig;
Expand All @@ -36,40 +39,41 @@ public class Main : BaseUnityPlugin

private void Awake()
{
//Useful for engaging coroutines or accessing variables non-static variables. Completely optional though.
@this = this;
//Useful for engaging co-routines or accessing variables non-static variables. Completely optional though.
This = this;

//pushes the logger to a public static var so you can use the bepinex logger from other classes.
logger = Logger;
//pushes the PLogger to a public static var so you can use the bepInEx PLogger from other classes.
PLogger = Logger;

//Binds the configuration. In other words it sets your ConfigEntry var to your config setup.
//ExampleConfig = Config.Bind("Section", "Name", false, "Description");

//Installs the patches in the Main class.

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

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

if (!HasDependencies)
if (!hasDependencies)
{
Main.logger.LogFatal("SMVD is missing some dependencies! SMVD will not operate correctly and neither will your game!");
PLogger.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));
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.
[HarmonyPatch(typeof(MenuDataBase), MethodType.Constructor, new Type[] { typeof(IntPtr), typeof(EnumData), typeof(EnumData) })]
[HarmonyPatch(typeof(MenuDataBase), MethodType.Constructor, typeof(IntPtr), typeof(EnumData), typeof(EnumData))]
[HarmonyPrefix]
private static void BuildingDatabase()
{
logger.LogDebug("Created the database...");
PLogger.LogDebug("Created the database...");

Database = new MenuDatabaseReplacement();
}
Expand All @@ -91,17 +95,17 @@ private static bool IsFinished(ref bool __result)
[HarmonyPrefix]
private static bool StartLoad()
{
logger.LogInfo("Starting Vanilla Menu Files Analysis...");
PLogger.LogInfo("Starting Vanilla Menu Files Analysis...");

@this.StartCoroutine(Database.StartLoading());
This.StartCoroutine(Database.StartLoading());
#if !OnlyCompare
return false;
#else
return true;
#endif
}

[HarmonyPatch(typeof(MenuDataBase), "Dispose", new Type[] { typeof(bool) })]
[HarmonyPatch(typeof(MenuDataBase), "Dispose", typeof(bool))]
[HarmonyPrefix]
private static bool DisposeVar(MenuDataBase __instance)
{
Expand Down Expand Up @@ -328,7 +332,7 @@ private static bool GetCategoryMpn(ref int __result, ref MenuDataBase __instance
private static bool GetColorSetMpn(ref int __result, ref MenuDataBase __instance)
{
#if !OnlyCompare
__result = (int)Database.MenusList[IndexToRead[__instance]].ColorSetMPN;
__result = (int)Database.MenusList[IndexToRead[__instance]].ColorSetMpn;

return false;
#else
Expand All @@ -354,7 +358,7 @@ private static bool GetMenuNameInColorSet(ref string __result, ref MenuDataBase
private static bool GetMultiColorId(ref int __result, ref MenuDataBase __instance)
{
#if !OnlyCompare
__result = (int)Database.MenusList[IndexToRead[__instance]].MultiColorID;
__result = (int)Database.MenusList[IndexToRead[__instance]].MultiColorId;

return false;
#else
Expand Down
Loading

0 comments on commit d12344d

Please sign in to comment.