Skip to content

Commit

Permalink
Updated for BepInEx 6.0.0be
Browse files Browse the repository at this point in the history
  • Loading branch information
derekShaheen committed Mar 10, 2024
1 parent a76743c commit a56fba5
Show file tree
Hide file tree
Showing 18 changed files with 478 additions and 410 deletions.
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4124fadb-8531-4922-be3f-526020e5406a")]
[assembly: Guid("70cf1763-3ba1-477c-a53f-f74447764d9c")]

// Version information for an assembly consists of the following four values:
//
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.2.3")]
[assembly: AssemblyFileVersion("2.0.2.3")]
37 changes: 34 additions & 3 deletions SkToolbox/Controllers/CommandHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using BepInEx.Unity.Mono;
using BepInEx;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -219,13 +221,14 @@ public void Help(string command = null, bool displayDescriptions = true)
.ToList();

StringBuilder sb = new StringBuilder();

sb.AppendLine("Command Syntax: command <requiredArg> [optionalArg=default]");
sb.AppendLine("<requiredArg>: A required argument. Must be provided for the command to work.");
sb.AppendLine("[optionalArg=default]: An optional argument with a default value. If not provided, it defaults to the value after '='.");
foreach (CommandMeta meta in cmds)
{
string fullCommand = meta.data.Keyword;
string hint = meta.arguments.Count > 0 ? $" {meta.hint.WithColor(Color.cyan)}" : "";

//sb.Append(meta.isStandard ? "[Standard] " : "")
sb.Append(meta.isStandard ? fullCommand.WithColor(Color.blue + Color.yellow / 2f) : fullCommand.WithColor(Color.yellow))
.Append(hint);

Expand Down Expand Up @@ -278,6 +281,7 @@ public System.Collections.IEnumerator Register()
{
var typesWithCommands = assembly.GetTypes()
.Where(type => type.GetMethods().Any(method => method.GetCustomAttribute<Command>() != null));
bool assemblyHasCommands = false;
foreach (var type in typesWithCommands)
{
foreach (var method in type.GetMethods().Where(m => m.GetCustomAttribute<Command>() != null))
Expand All @@ -293,6 +297,7 @@ public System.Collections.IEnumerator Register()
commandMeta.isStandard = true;
}
query.Add(commandMeta);
assemblyHasCommands = true;
}
catch (Exception ex)
{
Expand All @@ -301,6 +306,32 @@ public System.Collections.IEnumerator Register()
}
}
}

if (assemblyHasCommands && assembly != this.GetType().Assembly)
{
var pluginTypes = assembly.GetTypes()
.Where(type => typeof(BaseUnityPlugin).IsAssignableFrom(type) && type.GetCustomAttribute<BepInPlugin>() != null);

foreach (var pluginType in pluginTypes)
{
// Extract the MODNAME and VERSION information using case-insensitive search.
var modNameField = pluginType.GetFields(BindingFlags.Public | BindingFlags.Static)
.FirstOrDefault(field => string.Equals(field.Name, "MODNAME", StringComparison.OrdinalIgnoreCase));
var versionField = pluginType.GetFields(BindingFlags.Public | BindingFlags.Static)
.FirstOrDefault(field => string.Equals(field.Name, "VERSION", StringComparison.OrdinalIgnoreCase));

if (modNameField != null && versionField != null)
{
var modName = (string)modNameField.GetValue(null);
var version = (string)versionField.GetValue(null);

Loaders.SkBepInExLoader.Loader.pluginInfo.Add(modName, version);

Logger.Debug($"Found module: {modName}, Version: {version}");
}
}
assemblyHasCommands = false;
}
}
catch (Exception ex) when (!(ex is IndexOutOfRangeException))
{
Expand Down
Loading

0 comments on commit a56fba5

Please sign in to comment.