diff --git a/Bundles/swconsoleui.bundle b/Bundles/swconsoleui.bundle deleted file mode 100644 index 951a47f5..00000000 Binary files a/Bundles/swconsoleui.bundle and /dev/null differ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..99d4bf1d --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,47 @@ +# Contributing to Space Warp + +Thank you for your interest in contributing to Space Warp! This document outlines the guidelines for contributing to this project. + +## Getting Started + +To get started, you will need to have [Git](https://git-scm.com/) and a legit copy of [Kerbal Space Program 2](https://www.kerbalspaceprogram.com/games-kerbal-space-program-2) installed on your machine. You will also need to have a GitHub account. + +## Contributing to Issues + +We welcome contributions from the community to help us improve Space Warp. You can contribute by submitting bug reports, feature requests, or code changes. + +### Issue Tracker + +All contributions to Space Warp are tracked on the [GitHub issue tracker](https://github.com/SpaceWarpDev/SpaceWarp/issues). Before you start working on a feature or issue, please check the issue tracker to make sure that it has not already been reported. + +### Reporting Bugs + +If you encounter a bug while using Space Warp, please report it on the issue tracker. When submitting a bug report, please include as much information as possible, including the steps to reproduce the bug and any error messages that you received. + +### Feature Requests + +If you have an idea for a new feature or improvement to Space Warp, please submit it on the issue tracker. We encourage you to discuss your idea with the community before submitting a feature request. + +### Contributing Code + +If you would like to contribute code to Space Warp, please follow these guidelines: + +1. Create a fork of the Space Warp repository. +2. Clone your fork onto your local machine. +3. Create a new branch for your changes. +4. Make your changes on the new branch. +5. Test your changes to make sure they work as expected. +6. Commit your changes and push them to your fork. +7. Create a pull request on the main Space Warp repository. + +### Good First Issues + +We mark some issues as "good first issue" to help new contributors get started with the project. These issues are usually relatively simple and don't require a lot of experience with the project. + +## Code of Conduct + +We expect all contributors to follow our [Code of Conduct](CODE_OF_CONDUCT.md). Please review this document before contributing to Space Warp. + +## License + +Space Warp is licensed under the [MIT License](LICENSE). By contributing to this project, you agree to license your contributions under the same license. diff --git a/Doorstop/.doorstop_version b/Doorstop/.doorstop_version deleted file mode 100644 index 0c89fc92..00000000 --- a/Doorstop/.doorstop_version +++ /dev/null @@ -1 +0,0 @@ -4.0.0 \ No newline at end of file diff --git a/Doorstop/doorstop_config.ini b/Doorstop/doorstop_config.ini deleted file mode 100644 index 2bd6babd..00000000 --- a/Doorstop/doorstop_config.ini +++ /dev/null @@ -1,45 +0,0 @@ -# General options for Unity Doorstop -[General] - -# Enable Doorstop? -enabled=true - -# Path to the assembly to load and execute -# NOTE: The entrypoint must be of format `static void Doorstop.Entrypoint.Start()` -target_assembly=SpaceWarp/Core/SpaceWarp.dll - -# If true, Unity's output log is redirected to \output_log.txt -redirect_output_log=false - -# If enabled, DOORSTOP_DISABLE env var value is ignored -# USE THIS ONLY WHEN ASKED TO OR YOU KNOW WHAT THIS MEANS -ignore_disable_switch=false - - -# Options specific to running under Unity Mono runtime -[UnityMono] - -# Overrides default Mono DLL search path -# Sometimes it is needed to instruct Mono to seek its assemblies from a different path -# (e.g. mscorlib is stripped in original game) -# This option causes Mono to seek mscorlib and core libraries from a different folder before Managed -# Original Managed folder is added as a secondary folder in the search path -dll_search_path_override= - -# If true, Mono debugger server will be enabled -debug_enabled=false - -# When debug_enabled is true, specifies the address to use for the debugger server -debug_address=127.0.0.1:10000 - -# If true and debug_enabled is true, Mono debugger server will suspend the game execution until a debugger is attached -debug_suspend=false - -# Options sepcific to running under Il2Cpp runtime -[Il2Cpp] - -# Path to coreclr.dll that contains the CoreCLR runtime -coreclr_path= - -# Path to the directory containing the managed core libraries for CoreCLR (mscorlib, System, etc.) -corlib_dir= diff --git a/Doorstop/winhttp.dll b/Doorstop/winhttp.dll deleted file mode 100644 index e9816fd7..00000000 Binary files a/Doorstop/winhttp.dll and /dev/null differ diff --git a/ExampleMod/ExampleMod.cs b/ExampleMod/ExampleMod.cs index ca0e90c3..ef19e495 100644 --- a/ExampleMod/ExampleMod.cs +++ b/ExampleMod/ExampleMod.cs @@ -1,20 +1,23 @@ -using SpaceWarp.API.Mods; -using SpaceWarp.API.AssetBundles; -using SpaceWarp.API; +using BepInEx; +using BepInEx.Logging; +using SpaceWarp.API.Mods; +using SpaceWarp.API.Assets; using KSP.UI.Binding; using KSP.Sim.impl; +using SpaceWarp; +using SpaceWarp.API.UI; +using SpaceWarp.API.UI.Appbar; using UnityEngine; namespace ExampleMod; -[MainMod] -public class ExampleMod : Mod +[BepInPlugin("com.SpaceWarpAuthorName.ExampleMod", "ExampleMod", "3.0.0")] +[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)] +public class ExampleMod : BaseSpaceWarpPlugin { - public GUISkin _spaceWarpUISkin; private bool drawUI; private Rect windowRect; - private bool loaded; private static ExampleMod Instance { get; set; } @@ -25,30 +28,22 @@ public class ExampleMod : Mod public override void OnInitialized() { base.OnInitialized(); - - if (loaded) - { - Destroy(this); - } - - loaded = true; Instance = this; // Example of using the logger, Were going to log a message to the console, ALT + C to open the console. - Logger.Info("Hello World, Im a spacewarp Mod."); + Logger.LogInfo("Hello World, Im a spacewarp Mod."); - // Example of using the asset loader, were going to load the SpaceWarp GUI skin. - // [FORMAT]: space_warp/[assetbundle_name]/[folder_in_assetbundle]/[file.type] - ResourceManager.TryGetAsset( - "space_warp/swconsoleui/swconsoleUI/spacewarpConsole.guiskin", - out _spaceWarpUISkin - ); - // Register the mod's button on the SpaceWarp application bar. - SpaceWarpManager.RegisterAppButton( + // Register the mod's button in KSP 2s app.bar + // This requires an `icon.png` file to exist under [plugin_folder]/assets/images + Appbar.RegisterAppButton( "Example Mod", "BTN-ExampleMod", - SpaceWarpManager.LoadIcon(), + // Example of using the asset loader, were going to load the apps icon + // Path format [mod_id]/images/filename + // for bundles its [mod_id]/[bundle_name]/[path to file in bundle with out assets/bundle]/filename.extension + // There is also a try get asset function, that returns a bool on whether or not it could grab the asset + AssetManager.GetAsset($"{SpaceWarpMetadata.ModID}/images/icon.png"), ToggleButton ); } @@ -72,7 +67,7 @@ private void ToggleButton(bool toggle) public void OnGUI() { // Set the GUI skin to the SpaceWarp GUI skin. - GUI.skin = _spaceWarpUISkin; + GUI.skin = Skins.ConsoleSkin; if (drawUI) { @@ -96,6 +91,9 @@ private static void FillWindow(int windowID) GUILayout.Label("Example Mod - Built with Space-Warp"); GUI.DragWindow(new Rect(0, 0, 10000, 500)); } + + private float lastUpdateTime = 0.0f; + private float updateInterval = 1.0f; /// /// Runs every frame and performs various tasks based on the game state. @@ -103,23 +101,40 @@ private static void FillWindow(int windowID) private void LateUpdate() { // Now lets play with some Game objects - if (Instance.Game.GlobalGameState.GetState() == KSP.Game.GameState.MainMenu) + // Check if the specified interval has elapsed + if (Time.time - lastUpdateTime >= updateInterval) { - KSP.Audio.KSPAudioEventManager.SetMasterVolume(Mathf.Sin(Time.time) * 100); + // Update the last update time to the current time + lastUpdateTime = Time.time; + + // Now lets play with some Game objects + if (Game.GlobalGameState.GetState() == KSP.Game.GameState.MainMenu) + { + Logger.Log(LogLevel.None, "This is log level none"); + Logger.Log(LogLevel.Debug, "This is log level debug"); + Logger.Log(LogLevel.Info, "This is log level info"); + Logger.Log(LogLevel.Warning, "This is log level warning"); + Logger.Log(LogLevel.Error, "This is log level error"); + Logger.Log(LogLevel.Fatal, "This is log level fatal"); + Logger.Log(LogLevel.Message, "This is log level message"); + Logger.Log(LogLevel.All, "This is log level all"); + + KSP.Audio.KSPAudioEventManager.SetMasterVolume(Mathf.Sin(Time.time) * 100); + } } - else if (Instance.Game.GlobalGameState.GetState() == KSP.Game.GameState.FlightView) + else if (Game.GlobalGameState.GetState() == KSP.Game.GameState.FlightView) { // Getting the active vessel, staging it over and over and printing out all the parts. - VesselComponent _activeVessel = Instance.Game.ViewController.GetActiveSimVessel(); + VesselComponent _activeVessel = Game.ViewController.GetActiveSimVessel(); if (_activeVessel != null) { _activeVessel.ActivateNextStage(); - Logger.Warn("Stagin Active Vessel: " + _activeVessel.Name); + Logger.LogWarning("Stagin Active Vessel: " + _activeVessel.Name); VesselBehavior behavior = Game.ViewController.GetBehaviorIfLoaded(_activeVessel); foreach (PartBehavior pb in behavior.parts) { - Logger.Warn(pb.name); + Logger.LogWarning(pb.name); } } } diff --git a/ExampleMod/ExampleMod.csproj b/ExampleMod/ExampleMod.csproj index 56930641..4747af9a 100644 --- a/ExampleMod/ExampleMod.csproj +++ b/ExampleMod/ExampleMod.csproj @@ -1,19 +1,24 @@  - - netstandard2.0 + net472 11 true false + false - - ..\external_dlls\Assembly-CSharp.dll true + false + + + + + + - \ No newline at end of file + diff --git a/ExampleMod/modInfo.json b/ExampleMod/swinfo.json similarity index 92% rename from ExampleMod/modInfo.json rename to ExampleMod/swinfo.json index 3c1920f7..cf57cdbd 100644 --- a/ExampleMod/modInfo.json +++ b/ExampleMod/swinfo.json @@ -4,10 +4,10 @@ "author": "Space-Warp Team", "description": "A Example Mod for Space-Warp", "source": "https://github.com/SpaceWarpDev/SpaceWarp/tree/main/ExampleMod", - "version": "v0.3.0", + "version": "0.4.0", "dependencies": [], "ksp2_version": { "min": "0", "max": "1" } -} \ No newline at end of file +} diff --git a/ModTemplateGenerator.py b/ModTemplateGenerator.py deleted file mode 100644 index c37681b1..00000000 --- a/ModTemplateGenerator.py +++ /dev/null @@ -1,299 +0,0 @@ -# -------------------------------------- # -# KSP2 Space Warp Mod Template Generator # -# -------------------------------------- # -import shutil, json -from xml.dom import minidom - -# Generates a structure like the following -# mod_project -# mod_id -# modinfo.json -# README.md -# assets/ -# parts/ -# models/ -# resources/ -# bin/ -# config/ -# ModId -# Mod.cs -# Config.cs -# mod_project.csproj -# external_dlls/ -# .gitignore -# .gitignore -# -# -# .gitignore -# *.rsuser -# *.suo -# *.user -# *.userosscache -# *.sln.docstates -# *.userprefs -# mono_crash.* -# [Dd]ebug/ -# [Dd]ebugPublic/ -# [Rr]elease/ -# [Rr]eleases/ -# x64/ -# x86/ -# [Aa][Rr][Mm]/ -# [Aa][Rr][Mm]64/ -# bld/ -# [Bb]in/ -# [Oo]bj/ -# [Ll]og/ -# [Ll]ogs/ -# -# external_dlls/.gitignore -# * -# !.gitignore - -import os -from os.path import expanduser - - -def find_ksp2_install_path(): - # Checks if Operating System is NOT Windows - if os.path != "nt": - steam_install_folder = "" - return steam_install_folder - else: - # Look for the game in Steam library folders - steam_path = os.path.join(os.getenv("ProgramFiles(x86)"), "Steam") - steam_library_folders_file = os.path.join( - steam_path, "steamapps", "libraryfolders.vdf" - ) - steam_install_folder = os.path.join( - steam_path, "steamapps", "common", "Kerbal Space Program 2" - ) - - if os.path.exists(steam_library_folders_file): - with open(steam_library_folders_file) as f: - for line in f: - if "BaseInstallFolder" in line: - steam_library_path = line.strip().split('"')[3] - if os.path.exists( - os.path.join( - steam_library_path, - "steamapps", - "appmanifest_1406800.acf", - ) - ): - steam_install_folder = os.path.join( - steam_library_path, - "steamapps", - "common", - "Kerbal Space Program 2", - ) - break - - # Look for the game in default installation path - if not os.path.exists(steam_install_folder): - default_install_folder = os.path.join( - os.getenv("ProgramFiles"), "Private Division", "Kerbal Space Program 2" - ) - if os.path.exists(default_install_folder): - steam_install_folder = default_install_folder - - return steam_install_folder - - -print("Space Warp Mod Setup Wizard") - -# while True: -# project_name = input("What would you like to name the project: ") -# if not project_name: -# print("Project name cannot be empty, please try again.") -# else: -# break - -while True: - mod_id = input("What is the ID of the mod (This should be in snake_case): ") - if not mod_id: - print("Mod ID cannot be empty, please try again.") - else: - break - -while True: - mod_author = input("Who is the author of the mod: ") - if not mod_author: - print("Mod author cannot be empty, please try again.") - else: - break - -while True: - mod_name = input("What is the name of the mod: ") - if not mod_name: - print("Mod name cannot be empty, please try again.") - else: - break - -mod_description = input("What is a short description of the mod: ") -mod_source = input("What is the source link of the mod: ") -mod_version = input("What is the starting version of the mod: ") -mod_ksp_min_version = input( - "What is the minimum version of KSP2 this mod will accept: " -) -mod_ksp_max_version = input( - "What is the maximum version of KSP2 this mod will accept: " -) - -steam_install_folder = find_ksp2_install_path() - -if os.path.exists(steam_install_folder): - print(f"Kerbal Space Program 2 is installed at {steam_install_folder}") -else: - steam_install_folder = input( - "Could not find the installation path for Kerbal Space Program 2.\nPlease enter the path to the KSP2 installation folder manually: " - ) - -managed_path = os.path.join(steam_install_folder, "KSP2_x64_Data", "Managed") -space_warp_path = os.path.join(steam_install_folder, "SpaceWarp", "core") - -mod_id_title = mod_id.replace("_", " ").title().replace(" ", "") - - -os.mkdir(mod_id) -os.mkdir(f"{mod_id}/{mod_id}") -os.mkdir(f"{mod_id}/{mod_id}/assets") -os.mkdir(f"{mod_id}/{mod_id}/assets/parts") -os.mkdir(f"{mod_id}/{mod_id}/assets/models") -os.mkdir(f"{mod_id}/{mod_id}/assets/resources") -os.mkdir(f"{mod_id}/{mod_id}/bin") -os.mkdir(f"{mod_id}/{mod_id}/config") -os.mkdir(f"{mod_id}/{mod_id_title}Project") -os.mkdir(f"{mod_id}/{mod_id_title}Project/{mod_id_title}") -os.mkdir(f"{mod_id}/external_dlls") - -external_dlls = f"{mod_id}/external_dlls" -release_folder = f"{mod_id}/{mod_id}" - - -for filename in os.listdir(space_warp_path): - if filename.endswith(".dll"): - shutil.copy2(os.path.join(space_warp_path, filename), external_dlls) - -for filename in os.listdir(managed_path): - if filename.endswith(".dll"): - shutil.copy2(os.path.join(managed_path, filename), external_dlls) - -with open(f"{external_dlls}/.gitignore", "w") as external_gitignore: - external_gitignore.write("*\n!.gitignore") - -with open(f"{mod_id}/.gitignore", "w") as main_gitignore: - main_gitignore.write( - '\n'.join([ - "*.rsuser", - "*.suo", - "*.user", - "*.userosscache", - "*.sln.docstates", - "*.userprefs", - "mono_crash.*", - "[Dd]ebug/", - "[Dd]ebugPublic/", - "[Rr]elease/", - "[Rr]eleases/", - "x64/", - "x86/", - "[Aa][Rr][Mm]/", - "[Aa][Rr][Mm]64/", - "bld/", - "[Bb]in/", - "[Oo]bj/", - "[Ll]og/", - "[Ll]ogs/", - ]) - ) - -with open(f"{release_folder}/modinfo.json", "w") as modinfo: - modinfo.write( - json.dumps( - { - "mod_id": mod_id, - "author": mod_author, - "name": mod_name, - "description": mod_description, - "source": mod_source, - "version": mod_version, - "dependencies": [], - "ksp2_version": { - "min": mod_ksp_min_version, - "max": mod_ksp_max_version, - }, - }, - indent=4, - ) - ) -with open(f"README.json", "w") as readme: - readme.write("# Usage") - readme.write( - "Any code compiled in the csproj's dll should be moved to the /bin folder of the mod" - ) - -with open(f"{release_folder}/README.json", "w") as readme: - readme.write("# Default Readme") - -code_folder = f"{mod_id}/{mod_id_title}Project/{mod_id_title}" - -with open(f"{code_folder}/{mod_id_title}Mod.cs", "w") as default_code: - default_code.write( - "using SpaceWarp.API.Mods;\n\nnamespace " - + mod_id_title - + "\n{\n [MainMod]\n public class " - + mod_id_title - + 'Mod : Mod\n {\n public override void OnInitialized()\n {\n Logger.Info("Mod is initialized");\n }\n }\n}' - ) - -with open(f"{code_folder}/{mod_id_title}Config.cs", "w") as default_config: - default_config.write( - "using SpaceWarp.API.Configuration;\nusing Newtonsoft.Json;\n\nnamespace " - + mod_id_title - + "\n{\n [JsonObject(MemberSerialization.OptOut)]\n [ModConfig]\n public class " - + mod_id_title - + 'Config\n {\n [ConfigField("pi")] [ConfigDefaultValue(3.14159)] public double pi;\n }\n}' - ) - - -def quickCreateProperty(root, name, text): - a = root.createElement(name) - b = root.createTextNode(text) - a.appendChild(b) - return a - - -with open(f"{mod_id}/{mod_id_title}Project/{mod_id_title}.csproj", "w") as csproj: - root = minidom.Document() - xml = root.createElement("Project") - xml.setAttribute("Sdk", "Microsoft.NET.Sdk") - root.appendChild(xml) - propertyGroup = root.createElement("PropertyGroup") - xml.appendChild(propertyGroup) - propertyGroup.appendChild( - quickCreateProperty(root, "TargetFramework", "netstandard2.0") - ) - propertyGroup.appendChild(quickCreateProperty(root, "AllowUnsafeBlocks", "true")) - propertyGroup.appendChild(quickCreateProperty(root, "LangVersion", "11")) - propertyGroup.appendChild(quickCreateProperty(root, "ImplicitUsings", "true")) - - itemGroup = root.createElement("ItemGroup") - xml.appendChild(itemGroup) - - refs = [ - "..\\external_dlls\\SpaceWarp.dll", - "..\\external_dlls\\UnityEngine.dll", - "..\\external_dlls\\UnityEngine.CoreModule.dll", - "..\\external_dlls\\Assembly-CSharp.dll", - "..\\external_dlls\\NewtonSoft.Json.dll", - "..\\external_dlls\\NewtonSoft.Json.dll", - ] - - for ref in refs: - element = root.createElement("Reference") - element.setAttribute("Include", ref) - itemGroup.appendChild(element) - - xml_str = root.toprettyxml(indent=" ") - csproj.write(xml_str) diff --git a/NuGet.config b/NuGet.config index 882d99d7..fffd9183 100644 --- a/NuGet.config +++ b/NuGet.config @@ -1,8 +1,6 @@ - - - \ No newline at end of file + diff --git a/README.md b/README.md index 83a902b7..1153034d 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,7 @@ To compile this project, you will need to follow these steps: 1. Install NuGet 2. Run `nuget restore` inside the top directory to install the packages. 3. Copy everything in the `Kerbal Space Program 2\KSP2_x64_Data\Managed` folder into the `external_dlls/` folder. -4. Run one of the build scripts (see below for more info) and copy the contents from the correct build output directory into the KSP2 root directory. -5. Launch KSP2 and wait until the title screen appears. You should see a mods folder under the `SpaceWarp` folder. -6. Drag any mods that follow the structure below into that mods folder. +4. Run one of the build scripts (see below for more info) and copy the contents from the correct build output directory into the KSP2 root director Mods are currently implemented as monobehaviours with two fields: a `Logger` for logging and a `Manager` that points to Spacewarp. A mod template generator exists as a Python script. @@ -34,23 +32,21 @@ Mods are currently implemented as monobehaviours with two fields: a `Logger` for The mod structure is still a work in progress. However, the current structure is as follows: -* [KSP_ROOT]/SpaceWarp/Mods +* [KSP_ROOT]/BepInEx/Plugins * example_mod - * modinfo.json + * swinfo.json * README.md * assets/ * bundles/ + * \*.bundle + * images/ * \* - * assembly/ - * parts/ - * *.json - * models/ - * *.json - * resources/ - * *.json - * bin/ - * config/ - * .ignore (optional, if this file is present, the mod will be skipped!) + * localization/ + * \*.csv + * addressables/ + * catalog.json + * \* + * \*.dll ## Build Scripts @@ -62,9 +58,5 @@ The build scripts are: The available arguments are: - `-r` or `--release` to build in release mode -- `-t [target]` or `--target [target]` to build for a specific target (accepted values: `bepinex` or `doorstop`) -- `-a` or `--all` to build for both BepInEx and Doorstop -When building for BepInEx, the build output will be in `build/BepInEx`, and the compressed version will be `build/SpaceWarp-BepInEx-[Debug|Release]-[commit].zip`. - -When building for Unity Doorstop (standalone), the build output will be in `build/Doorstop`, and the compressed version will be `build/SpaceWarp-Doorstop-[Debug|Release]-[commit].zip`. +When building, the build output will be in `build/SpaceWarp`, and the compressed version will be `build/SpaceWarp-[Debug|Release]-[commit].zip`. diff --git a/SpaceWarp/API/AssetBundles/ResourceManager.cs b/SpaceWarp/API/Assets/AssetManager.cs similarity index 57% rename from SpaceWarp/API/AssetBundles/ResourceManager.cs rename to SpaceWarp/API/Assets/AssetManager.cs index 7f7251a6..820aafa3 100644 --- a/SpaceWarp/API/AssetBundles/ResourceManager.cs +++ b/SpaceWarp/API/Assets/AssetManager.cs @@ -1,47 +1,42 @@ -using System.Collections.Generic; -using System.Linq; -using SpaceWarp.API.Logging; +using System; +using System.Collections.Generic; +using BepInEx.Logging; using UnityEngine; -namespace SpaceWarp.API.AssetBundles; +namespace SpaceWarp.API.Assets; -public static class ResourceManager +public static class AssetManager { - static readonly Dictionary AllAssets = new Dictionary(); + private static readonly Dictionary AllAssets = new(); internal static void RegisterAssetBundle(string modId, string assetBundleName, AssetBundle assetBundle) { assetBundleName = assetBundleName.Replace(".bundle", ""); - ModLogger logger = new ModLogger($"{modId}/{assetBundleName}"); + ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource($"{modId}/{assetBundleName}"); // TODO: use async loading instead? // Object[] bundleObjects = assetBundle.LoadAllAssets(); string[] names = assetBundle.GetAllAssetNames(); - for (int i = 0; i < names.Length; i++) + foreach (var name in names) { - List assetNamePath = names[i].Split('/').ToList(); - if (assetNamePath[0].ToLower() == "assets") + var assetName = name; + + if (assetName.ToLower().StartsWith("assets/")) { - assetNamePath.RemoveAt(0); + assetName = assetName["assets/".Length..]; } - string assetName = ""; - for (int j = 0; j < assetNamePath.Count; j++) + if (assetName.ToLower().StartsWith(assetBundleName + "/")) { - assetName += assetNamePath[j]; - if (j != assetNamePath.Count - 1) - { - assetName += "/"; - } + assetName = assetName[(assetBundleName.Length + 1)..]; } - string path = modId + "/" + assetBundleName + "/" + assetName; path = path.ToLower(); - Object bundleObject = assetBundle.LoadAsset(names[i]); - - logger.Info($"registering path \"{path}\""); + + UnityObject bundleObject = assetBundle.LoadAsset(name); + logger.LogInfo($"registering path \"{path}\""); AllAssets.Add(path, bundleObject); } @@ -65,6 +60,15 @@ internal static void RegisterAssetBundle(string modId, string assetBundleName, A // } } + internal static void RegisterSingleAsset(string modId, string internalAssetPath, T asset) where T : UnityObject + { + var path = $"{modId}/{internalAssetPath}"; + path = path.ToLower(); + ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource($"{path}"); + logger.LogInfo($"registering path \"{path}\""); + AllAssets.Add(path,asset); + } + /// /// Gets an asset from the specified asset path /// @@ -77,17 +81,17 @@ public static T GetAsset(string path) where T: UnityEngine.Object string[] subPaths = path.Split('/', '\\'); if (subPaths.Length < 3) { - throw new System.ArgumentException("Invalid path, asset paths must follow to following structure: {mod_id}/{asset_bundle}/{asset_path}"); + throw new ArgumentException("Invalid path, asset paths must follow to following structure: {mod_id}/{asset_bundle}/{asset_path}"); } - if (!AllAssets.TryGetValue(path, out Object value)) + if (!AllAssets.TryGetValue(path, out UnityObject value)) { - throw new System.Exception($"Unable to find asset at path \"{path}\""); + throw new IndexOutOfRangeException($"Unable to find asset at path \"{path}\""); } - if (!(value is T tValue)) + if (value is not T tValue) { - throw new System.Exception($"The asset at path {path} isn't of type {typeof(T).Name} but of type {value.GetType().Name}"); + throw new InvalidCastException($"The asset at path {path} isn't of type {typeof(T).Name} but of type {value.GetType().Name}"); } return tValue; @@ -100,20 +104,21 @@ public static T GetAsset(string path) where T: UnityEngine.Object /// an asset path, format: {mod_id}/{asset_bundle}/{asset_name} /// the asset output /// Whether or not the asset exists and is loaded - public static bool TryGetAsset(string path, out T asset) where T : Object + public static bool TryGetAsset(string path, out T asset) where T : UnityObject { path = path.ToLower(); asset = null; string[] subPaths = path.Split('/', '\\'); + if (subPaths.Length < 3) { return false; } - if (!AllAssets.TryGetValue(path, out Object value)) + if (!AllAssets.TryGetValue(path, out UnityObject value)) { return false; } - if (!(value is T tValue)) + if (value is not T tValue) { return false; } diff --git a/SpaceWarp/API/Configuration/ConfigDefaultValueAttribute.cs b/SpaceWarp/API/Configuration/ConfigDefaultValueAttribute.cs deleted file mode 100644 index caa370f3..00000000 --- a/SpaceWarp/API/Configuration/ConfigDefaultValueAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace SpaceWarp.API.Configuration; - -public class ConfigDefaultValueAttribute : Attribute -{ - public readonly object DefaultValue; - - public ConfigDefaultValueAttribute(object defaultValue) - { - DefaultValue = defaultValue; - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Configuration/ConfigFieldAttribute.cs b/SpaceWarp/API/Configuration/ConfigFieldAttribute.cs deleted file mode 100644 index 990e482c..00000000 --- a/SpaceWarp/API/Configuration/ConfigFieldAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace SpaceWarp.API.Configuration; - -public class ConfigFieldAttribute : Attribute -{ - public readonly string Name; - - public ConfigFieldAttribute(string name) - { - Name = name; - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Configuration/ConfigSectionAttribute.cs b/SpaceWarp/API/Configuration/ConfigSectionAttribute.cs deleted file mode 100644 index 6bd882f9..00000000 --- a/SpaceWarp/API/Configuration/ConfigSectionAttribute.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace SpaceWarp.API.Configuration; - -public class ConfigSectionAttribute : Attribute -{ - public readonly string Path; - - public ConfigSectionAttribute(string path) - { - Path = path; - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Configuration/ConfigurationManager.cs b/SpaceWarp/API/Configuration/ConfigurationManager.cs deleted file mode 100644 index 7bf73574..00000000 --- a/SpaceWarp/API/Configuration/ConfigurationManager.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using SpaceWarp.API.Managers; -using Newtonsoft.Json; - -namespace SpaceWarp.API.Configuration; - -public class ConfigurationManager : Manager -{ - private readonly Dictionary _modConfigurations = new Dictionary(); - - public void Add(string id, (Type configType, object configObject, string path) configuration) - { - if (_modConfigurations.ContainsKey(id)) - { - return; - } - - _modConfigurations[id] = configuration; - } - - public bool TryGet(string id, out (Type configType, object configObject, string path) config) - { - return _modConfigurations.TryGetValue(id, out config); - } - - public void UpdateConfiguration(string id) - { - if (!_modConfigurations.TryGetValue(id, out (Type, object, string) config)) - { - return; - } - - // Saves the new configuration - File.WriteAllText(config.Item3,JsonConvert.SerializeObject(config.Item2)); - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Configuration/ModConfigAttribute.cs b/SpaceWarp/API/Configuration/ModConfigAttribute.cs deleted file mode 100644 index ffd1e156..00000000 --- a/SpaceWarp/API/Configuration/ModConfigAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System; - -namespace SpaceWarp.API.Configuration; - -public class ModConfigAttribute : Attribute -{ - -} \ No newline at end of file diff --git a/SpaceWarp/API/Game/Messages/StateChanges.cs b/SpaceWarp/API/Game/Messages/StateChanges.cs new file mode 100644 index 00000000..d4043542 --- /dev/null +++ b/SpaceWarp/API/Game/Messages/StateChanges.cs @@ -0,0 +1,220 @@ +using System; +using KSP.Game; +using KSP.Messages; + +namespace SpaceWarp.API.Game.Messages; + +/// +/// A class that contains a list of events that are published either when a state is entered or left +/// +public static class StateChanges +{ + #region Entering States + public static event Action InvalidStateEntered; + public static event System.Action WarmUpLoadingStateEntered; + public static event System.Action MainMenuStateEntered; + public static event System.Action KerbalSpaceCenterStateEntered; + public static event System.Action VehicleAssemblyBuilderEntered; + public static event System.Action BaseAssemblyEditorEntered; + public static event System.Action FlightViewEntered; + public static event System.Action ColonyViewEntered; + public static event System.Action Map3DViewEntered; + public static event System.Action PhotoModeEntered; + public static event System.Action MetricsModeEntered; + public static event System.Action PlanetViewerEntered; + public static event System.Action LoadingEntered; + public static event System.Action TrainingCenterEntered; + public static event System.Action MissionControlEntered; + public static event System.Action TrackingStationEntered; + public static event System.Action ResearchAndDevelopmentEntered; + public static event System.Action LaunchpadEntered; + public static event System.Action RunwayEntered; + public static event System.Action FlagEntered; + + #endregion + + #region Leaving States + + public static event System.Action InvalidStateLeft; + public static event System.Action WarmUpLoadingStateLeft; + public static event System.Action MainMenuStateLeft; + public static event System.Action KerbalSpaceCenterStateLeft; + public static event System.Action VehicleAssemblyBuilderLeft; + public static event System.Action BaseAssemblyEditorLeft; + public static event System.Action FlightViewLeft; + public static event System.Action ColonyViewLeft; + public static event System.Action PhotoModeLeft; + public static event System.Action Map3DViewLeft; + public static event System.Action MetricsModeLeft; + public static event System.Action PlanetViewerLeft; + public static event System.Action LoadingLeft; + public static event System.Action TrainingCenterLeft; + public static event System.Action MissionControlLeft; + public static event System.Action TrackingStationLeft; + public static event System.Action ResearchAndDevelopmentLeft; + public static event System.Action LaunchpadLeft; + public static event System.Action RunwayLeft; + public static event System.Action FlagLeft; + + #endregion + + #region State changing + + /// + /// Action(Message,PreviousState,CurrentState> + /// + public static event System.Action GameStateChanged; + + #endregion + + #region State Handling + + internal static void OnGameStateEntered(MessageCenterMessage message) + { + GameStateEnteredMessage msg = message as GameStateEnteredMessage; + switch (msg!.StateBeingEntered) + { + case GameState.Invalid: + InvalidStateEntered?.Invoke(msg); + break; + case GameState.WarmUpLoading: + WarmUpLoadingStateEntered?.Invoke(msg); + break; + case GameState.MainMenu: + MainMenuStateEntered?.Invoke(msg); + break; + case GameState.KerbalSpaceCenter: + KerbalSpaceCenterStateEntered?.Invoke(msg); + break; + case GameState.VehicleAssemblyBuilder: + VehicleAssemblyBuilderEntered?.Invoke(msg); + break; + case GameState.BaseAssemblyEditor: + BaseAssemblyEditorEntered?.Invoke(msg); + break; + case GameState.FlightView: + FlightViewEntered?.Invoke(msg); + break; + case GameState.ColonyView: + ColonyViewEntered?.Invoke(msg); + break; + case GameState.Map3DView: + Map3DViewEntered?.Invoke(msg); + break; + case GameState.PhotoMode: + PhotoModeEntered?.Invoke(msg); + break; + case GameState.MetricsMode: + MetricsModeEntered?.Invoke(msg); + break; + case GameState.PlanetViewer: + PlanetViewerEntered?.Invoke(msg); + break; + case GameState.Loading: + LoadingEntered?.Invoke(msg); + break; + case GameState.TrainingCenter: + TrainingCenterEntered?.Invoke(msg); + break; + case GameState.MissionControl: + MissionControlEntered?.Invoke(msg); + break; + case GameState.TrackingStation: + TrackingStationEntered?.Invoke(msg); + break; + case GameState.ResearchAndDevelopment: + ResearchAndDevelopmentEntered?.Invoke(msg); + break; + case GameState.Launchpad: + LaunchpadEntered?.Invoke(msg); + break; + case GameState.Runway: + RunwayEntered?.Invoke(msg); + break; + case GameState.Flag: + FlagEntered?.Invoke(msg); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + + internal static void OnGameStateLeft(MessageCenterMessage message) + { + GameStateLeftMessage msg = message as GameStateLeftMessage; + switch (msg!.StateBeingLeft) + { + case GameState.Invalid: + InvalidStateLeft?.Invoke(msg); + break; + case GameState.WarmUpLoading: + WarmUpLoadingStateLeft?.Invoke(msg); + break; + case GameState.MainMenu: + MainMenuStateLeft?.Invoke(msg); + break; + case GameState.KerbalSpaceCenter: + KerbalSpaceCenterStateLeft?.Invoke(msg); + break; + case GameState.VehicleAssemblyBuilder: + VehicleAssemblyBuilderLeft?.Invoke(msg); + break; + case GameState.BaseAssemblyEditor: + BaseAssemblyEditorLeft?.Invoke(msg); + break; + case GameState.FlightView: + FlightViewLeft?.Invoke(msg); + break; + case GameState.ColonyView: + ColonyViewLeft?.Invoke(msg); + break; + case GameState.Map3DView: + Map3DViewLeft?.Invoke(msg); + break; + case GameState.PhotoMode: + PhotoModeLeft?.Invoke(msg); + break; + case GameState.MetricsMode: + MetricsModeLeft?.Invoke(msg); + break; + case GameState.PlanetViewer: + PlanetViewerLeft?.Invoke(msg); + break; + case GameState.Loading: + LoadingLeft?.Invoke(msg); + break; + case GameState.TrainingCenter: + TrainingCenterLeft?.Invoke(msg); + break; + case GameState.MissionControl: + MissionControlLeft?.Invoke(msg); + break; + case GameState.TrackingStation: + TrackingStationLeft?.Invoke(msg); + break; + case GameState.ResearchAndDevelopment: + ResearchAndDevelopmentLeft?.Invoke(msg); + break; + case GameState.Launchpad: + LaunchpadLeft?.Invoke(msg); + break; + case GameState.Runway: + RunwayLeft?.Invoke(msg); + break; + case GameState.Flag: + FlagLeft?.Invoke(msg); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + internal static void OnGameStateChanged(MessageCenterMessage message) + { + var msg = message as GameStateChangedMessage; + GameStateChanged?.Invoke(msg!,msg!.PreviousState,msg!.CurrentState); + } + + #endregion +} \ No newline at end of file diff --git a/SpaceWarp/API/Logging/BaseModLogger.cs b/SpaceWarp/API/Logging/BaseModLogger.cs deleted file mode 100644 index 91570e65..00000000 --- a/SpaceWarp/API/Logging/BaseModLogger.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace SpaceWarp.API.Logging; - -/// -/// Used to print logs on each mod. -/// -public abstract class BaseModLogger -{ - protected abstract void Log(LogLevel level, string message); - - public void Trace(string message) => Log(LogLevel.Trace, message); - public void Debug(string message) => Log(LogLevel.Debug, message); - public void Info(string message) => Log(LogLevel.Info, message); - public void Warn(string message) => Log(LogLevel.Warn, message); - public void Error(string message) => Log(LogLevel.Error, message); - public void Critical(string message) => Log(LogLevel.Critical, message); -} \ No newline at end of file diff --git a/SpaceWarp/API/Logging/LogLevel.cs b/SpaceWarp/API/Logging/LogLevel.cs deleted file mode 100644 index ee8a7702..00000000 --- a/SpaceWarp/API/Logging/LogLevel.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace SpaceWarp.API.Logging; - -/// -/// Log levels for the BaseModLogger class. -/// -public enum LogLevel -{ - Trace = 0, - Debug = 1, - Info = 2, - Warn = 3, - Error = 4, - Critical = 5 -} \ No newline at end of file diff --git a/SpaceWarp/API/Logging/ModLogger.cs b/SpaceWarp/API/Logging/ModLogger.cs deleted file mode 100644 index 07b8dff0..00000000 --- a/SpaceWarp/API/Logging/ModLogger.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Text; - -namespace SpaceWarp.API.Logging; - -/// -/// Unique logger for each mod, each mod has its own logger to accomodate different behaviours. -/// -public class ModLogger : BaseModLogger -{ - private readonly string _moduleName; - - /// - /// Creates a ModLogger for a module - /// - /// - public ModLogger(string moduleName) - { - _moduleName = moduleName; - } - - private string BuildLogMessage(LogLevel level, string message) - { - StringBuilder sb = new StringBuilder(); - - sb.Append($"[{DateTime.Now:HH:mm:ss.fff}] "); - sb.Append($"[{_moduleName}] "); - sb.Append($"[{level}] "); - sb.Append(message); - - return sb.ToString(); - } - - protected override void Log(LogLevel level, string message) - { - if ((int)level >= SpaceWarpGlobalConfiguration.Instance.LogLevel) - { - string logMessage = BuildLogMessage(level, message); - UnityEngine.Debug.Log(logMessage); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Managers/Manager.cs b/SpaceWarp/API/Managers/Manager.cs deleted file mode 100644 index 86f8a74d..00000000 --- a/SpaceWarp/API/Managers/Manager.cs +++ /dev/null @@ -1,19 +0,0 @@ -using KSP.Game; - -namespace SpaceWarp.API.Managers; - -/// -/// Class to register itself on the ManagerLocator class for ease and performant access. -/// -public class Manager : KerbalMonoBehaviour -{ - protected virtual void Start() - { - ManagerLocator.Add(this); - } - - private void OnDestroy() - { - ManagerLocator.Remove(this); - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Managers/ManagerLocator.cs b/SpaceWarp/API/Managers/ManagerLocator.cs deleted file mode 100644 index 1e1f71aa..00000000 --- a/SpaceWarp/API/Managers/ManagerLocator.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace SpaceWarp.API.Managers; - -public static class ManagerLocator -{ - private static readonly Dictionary Managers = new Dictionary(); - - /// - /// Adds a manager object to the Managers dictionary. This should only run on Start(). - /// - /// The Mod component - public static void Add(MonoBehaviour manager) - { - if (Managers.TryGetValue(manager.GetType(), out object _)) - { - return; - } - - Managers.Add(manager.GetType(), manager); - } - - /// - /// Tries to get a manager from the Managers dictionary. - /// - /// The mod object found. - /// The type of Mod you want to find. - /// - public static bool TryGet(out T foundMod) where T : MonoBehaviour - { - bool hasMod = Managers.TryGetValue(typeof(T), out object mod); - - foundMod = mod as T; - return hasMod; - } - - /// - /// Removes a manager from the dictionary - /// - /// - public static void Remove(Manager manager) - { - Managers.Remove(manager.GetType()); - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Mods/BaseSpaceWarpPlugin.cs b/SpaceWarp/API/Mods/BaseSpaceWarpPlugin.cs new file mode 100644 index 00000000..da5d42b2 --- /dev/null +++ b/SpaceWarp/API/Mods/BaseSpaceWarpPlugin.cs @@ -0,0 +1,49 @@ +using BepInEx; +using BepInEx.Logging; +using KSP.Game; +using KSP.Messages; +using KSP.VFX; +using SpaceWarp.API.Mods.JSON; + +namespace SpaceWarp.API.Mods; + +/// +/// Represents a KSP2 Mod, you should inherit from this and do your manager processing. +/// +public abstract class BaseSpaceWarpPlugin : BaseUnityPlugin +{ + #region KspBehaviour things + protected static GameInstance Game => GameManager.Instance == null ? null : GameManager.Instance.Game; + + protected MessageCenter Messages => Game.Messages; + + // ReSharper disable Unity.NoNullPropagation + // fine because its null checked by Game properly + protected ContextualFxSystem CFXSystem => Game?.GraphicsManager?.ContextualFxSystem; + + protected bool IsGameShuttingDown => Game == null; + #endregion + + public ModInfo SpaceWarpMetadata { get; internal set; } + internal ManualLogSource ModLogger => base.Logger; + public string PluginFolderPath { get; internal set; } + + /// + /// 1st stage initialization + /// This is called before any of the game is actually loaded, it is called as early as possible in the games bootstrap process. + /// + public virtual void OnPreInitialized() { } + + /// + /// 2nd stage initialization + /// This is called after the game is loaded, and after your mods assets are loaded. + /// + public virtual void OnInitialized() { } + + /// + /// 3rd stage initialization + /// This is called after all mods have done first stage initialization + /// + public virtual void OnPostInitialized() { } + +} diff --git a/SpaceWarp/API/Mods/GlobalModDefines.cs b/SpaceWarp/API/Mods/GlobalModDefines.cs index 0bbf52b1..d93043e8 100644 --- a/SpaceWarp/API/Mods/GlobalModDefines.cs +++ b/SpaceWarp/API/Mods/GlobalModDefines.cs @@ -4,7 +4,6 @@ namespace SpaceWarp.API.Mods; public static class GlobalModDefines { - public const string BINARIES_FOLDER = "bin"; - - public static readonly string ASSET_BUNDLES_FOLDER = Path.Combine("assets","bundles"); + public static readonly string AssetBundlesFolder = Path.Combine("assets", "bundles"); + public static readonly string ImageAssetsFolder = Path.Combine("assets", "images"); } \ No newline at end of file diff --git a/SpaceWarp/API/Mods/JSON/DependencyInfo.cs b/SpaceWarp/API/Mods/JSON/DependencyInfo.cs index dbdac248..dc3486e6 100644 --- a/SpaceWarp/API/Mods/JSON/DependencyInfo.cs +++ b/SpaceWarp/API/Mods/JSON/DependencyInfo.cs @@ -6,11 +6,11 @@ namespace SpaceWarp.API.Mods.JSON; /// Represents the json property info. Properties have to use the same name as in the JSON file, that's why they break convention. /// [JsonObject(MemberSerialization.OptIn)] -public class DependencyInfo +public sealed class DependencyInfo { [JsonProperty("id")] - public string id { get; set; } + public string ID { get; internal set; } [JsonProperty("version")] - public SupportedVersionsInfo version { get; set; } -} \ No newline at end of file + public SupportedVersionsInfo Version { get; internal set; } +} diff --git a/SpaceWarp/API/Mods/JSON/ModInfo.cs b/SpaceWarp/API/Mods/JSON/ModInfo.cs index abe8964d..e5130c48 100644 --- a/SpaceWarp/API/Mods/JSON/ModInfo.cs +++ b/SpaceWarp/API/Mods/JSON/ModInfo.cs @@ -7,29 +7,29 @@ namespace SpaceWarp.API.Mods.JSON; /// Representation of the mod info JSON file. /// [JsonObject(MemberSerialization.OptIn)] -public class ModInfo +public sealed class ModInfo { [JsonProperty("mod_id")] - public string mod_id { get; set; } + public string ModID { get; internal set; } [JsonProperty("name")] - public string name { get; set; } + public string Name { get; internal set; } [JsonProperty("author")] - public string author { get; set; } - + public string Author { get; internal set; } + [JsonProperty("description")] - public string description { get; set; } - + public string Description { get; internal set; } + [JsonProperty("source")] - public string source { get; set; } + public string Source { get; internal set; } [JsonProperty("version")] - public string version { get; set; } + public string Version { get; internal set; } [JsonProperty("dependencies")] - public List dependencies { get; set; } = new List(); + public List Dependencies { get; internal set; } [JsonProperty("ksp2_version")] - public SupportedVersionsInfo supported_ksp2_versions { get; set; } = new SupportedVersionsInfo(); -} \ No newline at end of file + public SupportedVersionsInfo SupportedKsp2Versions { get; internal set; } +} diff --git a/SpaceWarp/API/Mods/JSON/SupportedVersionsInfo.cs b/SpaceWarp/API/Mods/JSON/SupportedVersionsInfo.cs index a483a898..5ea1372e 100644 --- a/SpaceWarp/API/Mods/JSON/SupportedVersionsInfo.cs +++ b/SpaceWarp/API/Mods/JSON/SupportedVersionsInfo.cs @@ -6,11 +6,11 @@ namespace SpaceWarp.API.Mods.JSON; /// Representation of the supported version info of a mod from a JSON file. /// [JsonObject(MemberSerialization.OptIn)] -public class SupportedVersionsInfo +public sealed class SupportedVersionsInfo { [JsonProperty("min")] - public string min { get; set; } = "0.0.0"; + public string Min { get; internal set; } = "0.0.0"; [JsonProperty("max")] - public string max { get; set; } = "*"; -} \ No newline at end of file + public string Max { get; internal set; } = "*"; +} diff --git a/SpaceWarp/API/Mods/MainModAttribute.cs b/SpaceWarp/API/Mods/MainModAttribute.cs deleted file mode 100644 index e5838097..00000000 --- a/SpaceWarp/API/Mods/MainModAttribute.cs +++ /dev/null @@ -1,5 +0,0 @@ -using System; - -namespace SpaceWarp.API.Mods; - -public class MainModAttribute : Attribute { } \ No newline at end of file diff --git a/SpaceWarp/API/Mods/Mod.cs b/SpaceWarp/API/Mods/Mod.cs deleted file mode 100644 index 6528c730..00000000 --- a/SpaceWarp/API/Mods/Mod.cs +++ /dev/null @@ -1,41 +0,0 @@ -using KSP.Game; -using SpaceWarp.API.Logging; -using SpaceWarp.API.Mods.JSON; -using UnityEngine; - -namespace SpaceWarp.API.Mods; - -/// -/// Represents a KSP2 Mod, you should inherit from this and do your manager processing. -/// -public abstract class Mod : KerbalMonoBehaviour -{ - public BaseModLogger Logger; - public ModInfo Info; - - - - public virtual void Initialize() - { - } - - private void OnDestroy() - { - ModLocator.Remove(this); - } - - public virtual void OnInitialized() - { - // Empty - } - - public void Setup(Transform transformParent, ModInfo info) - { - transform.SetParent(transformParent); - - ModLogger newModLogger = new ModLogger(info.name); - Logger = newModLogger; - - Info = info; - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Mods/ModLocator.cs b/SpaceWarp/API/Mods/ModLocator.cs deleted file mode 100644 index e3116207..00000000 --- a/SpaceWarp/API/Mods/ModLocator.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace SpaceWarp.API.Mods; - -/// -/// Useful performance-optimized locator for Mod objects. Should be used instead of any other way. -/// -public static class ModLocator -{ - private static readonly Dictionary Mods = new Dictionary(); - - /// - /// Adds a mod object to the Mods dictionary. This should only run on Mod.Start(). - /// - /// The Mod component - public static void Add(Mod modObject) - { - if (Mods.TryGetValue(modObject.GetType(), out object _)) - { - return; - } - - Mods.Add(modObject.GetType(), modObject); - } - - /// - /// Tries to get a mod from the Mods dictionary. - /// - /// The mod object found. - /// The type of Mod you want to find. - /// - public static bool TryGet(out T foundMod) where T : Mod - { - bool hasMod = Mods.TryGetValue(typeof(T), out object mod); - - foundMod = mod as T; - return hasMod; - } - - /// - /// Removes a manager from the dictionary - /// - /// - public static void Remove(Mod modObject) - { - Mods.Remove(modObject.GetType()); - } -} \ No newline at end of file diff --git a/SpaceWarp/API/SpaceWarpGlobalConfiguration.cs b/SpaceWarp/API/SpaceWarpGlobalConfiguration.cs deleted file mode 100644 index ba0e8269..00000000 --- a/SpaceWarp/API/SpaceWarpGlobalConfiguration.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System; -using System.ComponentModel; -using System.IO; -using Newtonsoft.Json; -using UnityEngine; - -namespace SpaceWarp.API; - -[JsonObject(MemberSerialization.OptIn)] -public class SpaceWarpGlobalConfiguration -{ - public static SpaceWarpGlobalConfiguration Instance; - - private static string SPACEWARP_CONFIG_FULL_PATH = Path.Combine(SpaceWarpManager.MODS_FULL_PATH,SPACE_WARP_CONFIG_FILE_NAME); - private const string SPACE_WARP_CONFIG_FILE_NAME = "space_warp_config.json"; - - /// - /// Loading Global Configuration and puting it into Instance. - /// - public static void Init() - { - if (!File.Exists(SPACEWARP_CONFIG_FULL_PATH)) - { - Instance = new SpaceWarpGlobalConfiguration(); - Instance.ApplyDefaultValues(); - } - else - { - try - { - string json = File.ReadAllText(SPACEWARP_CONFIG_FULL_PATH); - Instance = JsonConvert.DeserializeObject(json); - } - catch (Exception exception) - { - //TODO: log this in a nicer way, for now I guess we can just construct a new logger - Debug.LogError($"Loading space warp config failed\nException: {exception}"); - - File.Delete(SPACEWARP_CONFIG_FULL_PATH); - Init(); - return; - } - } - - try - { - File.WriteAllLines(SPACEWARP_CONFIG_FULL_PATH, new[] { JsonConvert.SerializeObject(Instance) }); - } - catch (Exception exception) - { - //TODO: log this in a nicer way, for now I guess we can just construct a new logger - Debug.LogError($"Saving the spacewarp config failed\nException: {exception}"); - } - } - - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] - [DefaultValue((int)Logging.LogLevel.Info)] - public int LogLevel { get; set; } - - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] - [DefaultValue((bool)false)] - public bool HarmonyLoggin { get; set; } - - [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] - [DefaultValue((int)Logging.LogLevel.Info)] - public int HarmonyLogLevel { get; set; } - - public void ApplyDefaultValues() - { - LogLevel = (int)Logging.LogLevel.Info; - HarmonyLoggin = false; - HarmonyLogLevel = (int)Logging.LogLevel.Info; - } -} \ No newline at end of file diff --git a/SpaceWarp/API/SpaceWarpManager.cs b/SpaceWarp/API/SpaceWarpManager.cs deleted file mode 100644 index 48b75ff9..00000000 --- a/SpaceWarp/API/SpaceWarpManager.cs +++ /dev/null @@ -1,771 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; -using HarmonyLib; -using UnityEngine; -using Newtonsoft.Json; -using SpaceWarp.API.Configuration; -using SpaceWarp.API.Logging; -using SpaceWarp.API.AssetBundles; -using SpaceWarp.API.Managers; -using SpaceWarp.API.Mods; -using SpaceWarp.API.Mods.JSON; -using SpaceWarp.API.Toolbar; -using SpaceWarp.API.Versions; -using SpaceWarp.Compilation; -using SpaceWarp.Patching; -using SpaceWarp.UI; -using UnityEngine.AddressableAssets; -using UnityEngine.AddressableAssets.ResourceLocators; -using UnityEngine.AddressableAssets.ResourceProviders; -using UnityEngine.ResourceManagement.AsyncOperations; - -namespace SpaceWarp.API; - -/// -/// Handles all the SpaceWarp initialization and mod processing. -/// -public class SpaceWarpManager : Manager -{ - private BaseModLogger _modLogger; - - private const string MODS_FOLDER_NAME = "Mods"; - #if DOORSTOP_BUILD - public static string SPACE_WARP_PATH = Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).FullName + "/"; - #else - public static string SPACE_WARP_PATH = Path.Combine(Directory.GetParent(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)).Parent.Parent.FullName,"SpaceWarp"); - #endif - public static string MODS_FULL_PATH = Path.Combine(SPACE_WARP_PATH,MODS_FOLDER_NAME); - - public SpaceWarpGlobalConfiguration SpaceWarpConfiguration; - - private readonly List _allModScripts = new List(); - internal readonly List<(string, ModInfo)> _modLoadOrder = new List<(string, ModInfo)>(); - public readonly List<(string,ModInfo)> LoadedMods = new List<(string,ModInfo)>(); - private static readonly List<(string, ModInfo)> AllEnabledModInfo = new List<(string, ModInfo)>(); - - public readonly List<(string,ModInfo)> IgnoredMods = new List<(string,ModInfo)>(); - - public ModListUI ModListUI { get; private set; } - protected override void Start() - { - - Debug.Log($"Space Warp Path {SPACE_WARP_PATH}"); - Debug.Log($"Mods Path {MODS_FULL_PATH}"); - - base.Start(); - - Initialize(); - } - - /// - /// Initializes the SpaceWarp manager. - /// - private void Initialize() - { - ToolbarBackend.AppBarInFlightSubscriber.AddListener(LoadAllButtons); - InitializeConfigManager(); - - InitializeModLogger(); - - LoadingScreenPatcher.AddModLoadingScreens(); - } - - /// - ///Initializes the configuration manager - /// - public void InitializeConfigManager() - { - GameObject confManagerObject = new GameObject("Configuration Manager"); - Persist(confManagerObject); - - confManagerObject.AddComponent(); - confManagerObject.SetActive(true); - } - - /// - /// Initializes the SpaceWarp mod logger. - /// - private void InitializeModLogger() - { - _modLogger = new ModLogger("Space Warp"); - _modLogger.Info("Warping Spacetime"); - } - - /// - /// Read all the mods in the mods path - /// - internal void ReadMods() - { - _modLogger.Info("Reading mods"); - - string[] modDirectories; - try - { - modDirectories = Directory.GetDirectories(MODS_FULL_PATH); - } - catch(Exception exception) - { - _modLogger.Critical($"Unable to open mod path: {MODS_FULL_PATH}\nException:{exception}"); - return; - } - - if (modDirectories.Length == 0) - { - _modLogger.Warn("No mods were found! No panic though."); - } - - foreach (string modFolderuntrimmedU in modDirectories) - { - string modFolder = modFolderuntrimmedU.TrimEnd('/', '\\'); - - string modName = Path.GetFileName(modFolder); - if (!File.Exists(Path.Combine(modFolder,"modinfo.json"))) - { - _modLogger.Warn($"Found mod {modName} without modinfo.json"); - continue; - } - - if (File.Exists(Path.Combine(modFolder,".ignore"))) - { - _modLogger.Info($"Skipping mod {modName} due to .ignore file"); - ModInfo ignore_info = JsonConvert.DeserializeObject(File.ReadAllText(modFolder + "\\modinfo.json")); - string ignore_fileName = Path.GetFileName(modFolder); - IgnoredMods.Add((ignore_fileName,ignore_info)); - continue; - } - _modLogger.Info($"Found mod: {modName}, adding to enable mods"); - - ModInfo info = JsonConvert.DeserializeObject(File.ReadAllText(modFolder + "\\modinfo.json")); - string fileName = Path.GetFileName(modFolder); - AllEnabledModInfo.Add((fileName,info)); - } - - ResolveLoadOrder(); - } - - /// - /// Checks if all dependencies are resolved. - /// - /// - /// - private bool AreDependenciesResolved(ModInfo mod) - { - foreach (DependencyInfo dependency in mod.dependencies) - { - _modLogger.Info($"{mod.name} dependency - {dependency.id} {dependency.version.min}-{dependency.version.max}"); - - string dependencyID = dependency.id; - SupportedVersionsInfo dependencyVersion = dependency.version; - - bool found = false; - foreach ((string, ModInfo) loadedMod in _modLoadOrder) - { - if (loadedMod.Item2.mod_id != dependencyID) - { - continue; - } - - string depLoadedVersion = loadedMod.Item2.version; - - if (!VersionUtility.IsVersionAbove(depLoadedVersion, dependencyVersion.min)) - return false; - if (!VersionUtility.IsVersionBellow(depLoadedVersion, dependencyVersion.max)) - return false; - - found = true; - } - - if (!found) return false; - } - - return true; - } - - /// - /// Resolves mod order - /// - private void ResolveLoadOrder() - { - //TODO: Make this way more optimized! - _modLogger.Info("Resolving Load Order"); - bool changed = true; - while (changed) - { - changed = false; - List toRemove = new List(); - for (int i = 0; i < AllEnabledModInfo.Count; i++) - { - _modLogger.Info("Attempting to resolve dependencies for " + AllEnabledModInfo[i].Item1); - if (AreDependenciesResolved(AllEnabledModInfo[i].Item2)) - { - _modLoadOrder.Add(AllEnabledModInfo[i]); - toRemove.Add(i); - changed = true; - } - } - - for (int i = toRemove.Count - 1; i >= 0; i--) - { - AllEnabledModInfo.RemoveAt(toRemove[i]); - } - } - - if (AllEnabledModInfo.Count > 0) - { - foreach ((string modName, ModInfo info) in AllEnabledModInfo) - { - _modLogger.Warn($"Skipping loading of {modName} as not all dependencies could be met"); - } - } - LoadingScreenPatcher.AddAllModLoadingSteps(); - } - - internal void InitializeAssets() - { - _modLogger.Info("Initializing mod assets"); - - foreach ((string modName, ModInfo info) in _modLoadOrder) - { - LoadSingleModAssets(modName, info); - } - - } - - - internal void LoadSpaceWarpAssets() - { - string bundlesPath = Path.Combine(SPACE_WARP_PATH, GlobalModDefines.ASSET_BUNDLES_FOLDER); - - if (Directory.Exists(bundlesPath)) - { - foreach (string file in Directory.GetFiles(bundlesPath)) - { - _modLogger.Info($"Found space warp asset file {file}"); - string assetBundleName = Path.GetFileNameWithoutExtension(file); - if (Path.GetExtension(file) != ".bundle") continue; - - - AssetBundle assetBundle = AssetBundle.LoadFromFile(file); - - if (assetBundle == null) - { - _modLogger.Error($"Failed to load AssetBundle space_warp/{assetBundleName}"); - continue; - } - ResourceManager.RegisterAssetBundle("space_warp", assetBundleName, assetBundle); - _modLogger.Info($"Loaded AssetBundle space_warp/{assetBundleName}"); - } - } - } - - /// - /// Loads a single mods assets - /// - /// the name/id of the mod - /// the mod info structure that describes the mod - internal void LoadSingleModAssets(string modName, ModInfo info) - { - string modFolder = Path.Combine(MODS_FULL_PATH, modName); - - // Now we load all asset bundles under the asset/bundles folder of the mod - string bundlesPath = modFolder + GlobalModDefines.ASSET_BUNDLES_FOLDER; - if (Directory.Exists(bundlesPath)) - { - foreach (string file in Directory.GetFiles(bundlesPath)) - { - string assetBundleName = Path.GetFileNameWithoutExtension(file); - if (Path.GetExtension(file) != ".bundle") continue; - - - AssetBundle assetBundle = AssetBundle.LoadFromFile(file); - - if (assetBundle == null) - { - _modLogger.Error($"Failed to load AssetBundle {info.mod_id}/{assetBundleName}"); - continue; - } - ResourceManager.RegisterAssetBundle(info.mod_id, assetBundleName, assetBundle); - _modLogger.Info($"Loaded AssetBundle {info.mod_id}/{assetBundleName}"); - } - } - else - { - _modLogger.Info($"Did not load assets for {modName} as no assets folder existed!"); - } - - // TODO: load part specific json stuff - } - - /// - /// Runs the mod initialization procedures. - /// - internal void InitializeMods() - { - _modLogger.Info("Initializing mods"); - - - foreach ((string modName, ModInfo info) in _modLoadOrder) - { - InitializeSingleMod(modName, info); - } - } - - /// - /// Initializes a single mod - /// - /// the name/id of the mod - /// the mod info structure that describes the mod - internal void InitializeSingleMod(string modName, ModInfo info) - { - string modFolder = Path.Combine(MODS_FULL_PATH, modName); - - _modLogger.Info($"Found mod: {modName}, attempting to load mod"); - - // Now we load all assemblies under the code folder of the mod - string codePath = Path.Combine(modFolder, GlobalModDefines.BINARIES_FOLDER); - - if (Directory.Exists(codePath)) - { - if (!TryLoadMod(codePath, modName, info, out Type mainModType)) - { - // error logging is done inside TryLoadMod - return; - } - - InitializeModObject(modName, info, mainModType); - } - else - { - _modLogger.Error($"Directory not found: {codePath}"); - } - } - - /// - /// Tries to load a mod at a path - /// - /// The full path to this mod binaries. - /// The mod name - /// The Mod type found - /// If the mod was successfully found. - private bool TryLoadMod(string codePath, string modName, ModInfo modInfo, out Type mainModType) - { - string[] files; - try - { - files = Directory.GetFiles(codePath); - } - catch - { - _modLogger.Error($"Could not load mod: {modName}, unable to read directory"); - mainModType = null; - return false; - } - - List modAssemblies = new List(); - foreach (string file in files) - { - // we only want to load dll files, ignore everything else - if (!file.EndsWith(".dll")) - { - _modLogger.Warn($"Non-dll file found in \"{codePath}\" \"{file}\", Ignoring"); - continue; - } - - Assembly asm; - try - { - asm = Assembly.LoadFrom(file); - } - catch(Exception exeption) - { - _modLogger.Error($"Could not load mod: {modName}, Failed to load assembly {file}\nException: {exeption}"); - mainModType = null; - - return false; - } - - modAssemblies.Add(asm); - } - - - string modFolder = Path.Combine(MODS_FULL_PATH,modName); - string srcPath = Path.Combine(modFolder, "src"); - if (Directory.Exists(srcPath) && Directory.GetFiles(srcPath, "*",SearchOption.AllDirectories).Length > 0) - { - var result = ModCompiler.CompileMod(modInfo.mod_id, srcPath); - if (result != null) - { - modAssemblies.Add(result); - } - } - - mainModType = null; - foreach (Assembly asm in modAssemblies) - { - Type[] types; - try - { - types = asm.GetTypes(); - } - catch - { - _modLogger.Error($"Could not load mod: {modName}, Unable to get types out of assembly {asm.FullName}"); - - mainModType = null; - return false; - } - - - mainModType = types.FirstOrDefault(type => type.GetCustomAttribute() != null); - if (mainModType != null) break; - } - - if (mainModType == null) - { - _modLogger.Error($"Could not load mod: {modName}, no type with [MainMod] exists"); - return false; - } - - - // We want to load the configuration for the mod as well - Type configurationModType = null; - foreach (Assembly asm in modAssemblies) - { - configurationModType = asm.GetTypes() - .FirstOrDefault(type => type.GetCustomAttribute () != null); - if (configurationModType != null) break; - } - - if (configurationModType != null) - { - InitializeModConfig(configurationModType, modName); - } - - if (!typeof(Mod).IsAssignableFrom(mainModType)) - { - _modLogger.Error($"Could not load mod: {modName}, the found class ({mainModType.FullName}) with [MainMod] doesn't inherit from {nameof(Mod)}"); - - mainModType = null; - return false; - } - - // Harmony patch everything in the current mod! - Harmony harmony = new Harmony($"com.mod.{modInfo.author}.{modInfo.mod_id}"); - foreach (Assembly asm in modAssemblies) - { - harmony.PatchAll(asm); - } - - return true; - - } - - /// - /// Tries to find a specific mods config file, if none is found, one is created - /// - private void InitializeModConfig(Type config_type, string mod_id) - { - object modConfiguration = null; - var config_path = Path.Combine(MODS_FULL_PATH, mod_id, "config","config.json"); - if (!File.Exists(config_path)) - { - modConfiguration = Activator.CreateInstance(config_type); - foreach (var fieldInfo in config_type.GetFields(BindingFlags.Instance | BindingFlags.Public)) - { - var def = fieldInfo.GetCustomAttribute(); - if (def != null) - { - fieldInfo.SetValue(modConfiguration, def.DefaultValue); - } - } - } - else - { - try - { - string json = File.ReadAllText(config_path); - modConfiguration = JsonConvert.DeserializeObject(json,config_type); - - } - catch (Exception exception) - { - _modLogger.Error($"Loading mod config failed\nException: {exception}"); - - File.Delete(config_path); - InitializeModConfig(config_type, mod_id); - return; - } - } - - try - { - File.WriteAllLines(config_path, new[] { JsonConvert.SerializeObject(modConfiguration) }); - } - catch (Exception exception) - { - _modLogger.Error($"Saving mod config failed\nException: {exception}"); - } - - if (ManagerLocator.TryGet(out ConfigurationManager configurationManager)) - { - configurationManager.Add(mod_id,(config_type,modConfiguration,config_path)); - } - } - - /// - /// Initializes a mod object. - /// - /// The mod name to initialize. - /// The mod type to initialize. - /// The new mod logger to spawn - private void InitializeModObject(string modName, ModInfo info, Type mainModType) - { - GameObject modObject = new GameObject($"Mod: {modName}"); - Mod modComponent = (Mod)modObject.AddComponent(mainModType); - - _allModScripts.Add(modComponent); - - modComponent.Setup(transform.parent, info); - modObject.SetActive(true); - - _modLogger.Info($"Loaded: {modName}"); - - // we probably dont want to completely stop loading mods if 1 mod throws an exception on Initialize - try - { - ModLocator.Add(modComponent); - Persist(modObject); - modComponent.Initialize(); - } - catch(Exception exception) - { - _modLogger.Critical($"Exception in {modName} Initialize(): {exception}"); - } - - LoadedMods.Add((modName, info)); - } - - /// - /// Calls the OnInitialized method on each initialized mod. - /// - internal void InvokePostInitializeModsAfterAllModsLoaded() - { - foreach (Mod mod in _allModScripts) - { - try - { - mod.OnInitialized(); - } - catch(Exception exception) - { - _modLogger.Critical($"Exception in {mod.name} AfterInitialization(): {exception}"); - } - } - InitModUI(); - } - /// - /// Initializes the UI for the mod list and configuration menu - /// - private void InitModUI() - { - GameObject modUIObject = new GameObject("Space Warp Mod UI"); - Persist(modUIObject); - - modUIObject.transform.SetParent(transform.parent); - ModListUI = modUIObject.AddComponent(); - - modUIObject.SetActive(true); - - GameObject consoleUIObject = new GameObject("Space Warp Console"); - Persist(consoleUIObject); - consoleUIObject.transform.SetParent(transform.parent); - SpaceWarpConsole con = consoleUIObject.AddComponent(); - consoleUIObject.SetActive(true); - } - - private static List<(string text, Sprite icon, string ID, Action action)> _buttonsToBeLoaded = - new List<(string text, Sprite icon, string ID, Action action)>(); - - public T RegisterGameToolbarMenu(string text, string title, string id, Sprite icon) where T : ToolbarMenu - { - GameObject toolBarUIObject = new GameObject($"Toolbar: {id}"); - Persist(toolBarUIObject); - ToolbarMenu menu = toolBarUIObject.AddComponent(); - menu.Title = title; - toolBarUIObject.transform.SetParent(transform.parent); - toolBarUIObject.SetActive(true); - _buttonsToBeLoaded.Add((text,icon,id,menu.ToggleGUI)); - return menu as T; - } - - public static void RegisterAppButton(string text, string id, Sprite icon, Action func) => - _buttonsToBeLoaded.Add((text ,icon, id, func)); - - /// - /// Allows an object to persist through KSP 2s destruction - /// - /// Object that should be persisted - public static void Persist(GameObject toPersist) - { - DontDestroyOnLoad(toPersist); - toPersist.tag = "Game Manager"; - } - - private static GUISkin _skin = null; - - public static GUISkin Skin - { - get - { - if (_skin == null) - ResourceManager.TryGetAsset("space_warp/swconsoleui/swconsoleUI/spacewarpConsole.guiskin", out - (_skin)); - return _skin; - } - } - - private void LoadAllButtons() - { - foreach (var button in _buttonsToBeLoaded) - { - ToolbarBackend.AddButton(button.text, button.icon, button.ID, button.action); - } - } - - /// - /// Loads a png called 'icon.png' as a sprite from the same folder as the calling dll. - /// In our case this should be SpaceWarp\Mods\[mod]\bin\icon.png - /// - /// The size of the png. The appbar expects 24x24. - public static Sprite LoadIcon(int size = 24) - { - string folderPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); - - return LoadIcon(Path.Combine(folderPath, "icon.png"), size); - } - - /// - /// Loads a png at the given path as a sprite. - /// - /// Path to the png. - /// The size of the png. The appbar expects 24x24. - public static Sprite LoadIcon(string path, int size = 24) - { - Texture2D tex = new Texture2D(size, size, TextureFormat.ARGB32, false); - tex.filterMode = FilterMode.Point; - - if (File.Exists(path)) - { - byte[] fileContent = File.ReadAllBytes(path); - ImageConversion.LoadImage(tex, fileContent); - } - - return Sprite.Create(tex, new Rect(0, 0, size, size), new Vector2(0.5f, 0.5f)); - } - - public void InitializeAddressablesFolder() - { - LoadSpaceWarpAddressables(); - } - - public IEnumerator LoadAddressable(string catalog) - { - _modLogger.Info($"Attempting to load {catalog}"); - AsyncOperationHandle operation = Addressables.LoadContentCatalogAsync(catalog, null); - yield return operation; - if (operation.Status == AsyncOperationStatus.Failed) - { - _modLogger.Error($"Failed to load addressables catalog {catalog}"); - } - else - { - _modLogger.Info($"Loaded addressables catalog {catalog}"); - var locator = operation.Result; - _modLogger.Info($"{catalog} ----- {locator.LocatorId}"); - Game.Assets.RegisterResourceLocator(locator); - } - } - - public void LoadSpaceWarpAddressables() - { - string addressablesPath = Path.Combine(SPACE_WARP_PATH,"addressables"); - string catalogPath = Path.Combine(addressablesPath,"catalog.json"); - if (File.Exists(catalogPath)) - { - StartCoroutine(LoadAddressable(catalogPath)); - } - } - - public void LoadSingleModAddressables(string modID, ModInfo info) - { - string modFolder = Path.Combine(MODS_FULL_PATH, modID); - string addressablesPath = Path.Combine(modFolder,"addressables"); - _modLogger.Info($"Loading addressables for {modID}"); - string catalogPath = Path.Combine(addressablesPath, "catalog.json"); - if (File.Exists(catalogPath)) - { - _modLogger.Info($"Found addressables for {modID}"); - StartCoroutine(LoadAddressable(catalogPath)); - } - else - { - _modLogger.Info($"Did not find addressables for {modID}"); - } - } - - private void LoadLocalizationFromFolder(string folder) - { - _modLogger.Info($"Attempting to load localizations from {folder}"); - I2.Loc.LanguageSourceData languageSourceData = null; - if (!Directory.Exists(folder)) - { - _modLogger.Info($"{folder} does not exist, not loading localizations."); - return; - } - DirectoryInfo info = new DirectoryInfo(folder); - foreach (var csvFile in info.GetFiles("*.csv")) - { - languageSourceData ??= new I2.Loc.LanguageSourceData(); - var csvData = File.ReadAllText(csvFile.FullName); - languageSourceData.Import_CSV("", csvData, I2.Loc.eSpreadsheetUpdateMode.AddNewTerms); - } - - foreach (var i2csvFile in info.GetFiles("*.i2csv")) - { - languageSourceData ??= new I2.Loc.LanguageSourceData(); - var i2csvData = File.ReadAllText(i2csvFile.FullName); - languageSourceData.Import_I2CSV("", i2csvData, I2.Loc.eSpreadsheetUpdateMode.AddNewTerms); - } - - if (languageSourceData != null) - { - _modLogger.Info($"Loaded localizations from {folder}"); - I2.Loc.LocalizationManager.AddSource(languageSourceData); - } - else - { - _modLogger.Info($"No localizations found in {folder}"); - } - } - public void LoadSpaceWarpLocalizations() - { - if (I2.Loc.LocalizationManager.Sources.Count == 0) - { - I2.Loc.LocalizationManager.UpdateSources(); - } - - string localizationsPath = Path.Combine(SPACE_WARP_PATH, "localizations"); - LoadLocalizationFromFolder(localizationsPath); - } - - public void LoadSingleModLocalization(string modID, ModInfo info) - { - string modFolder = Path.Combine(MODS_FULL_PATH, modID); - string localizationsPath = Path.Combine(modFolder, "localizations"); - LoadLocalizationFromFolder(localizationsPath); - } -} \ No newline at end of file diff --git a/SpaceWarp/API/Toolbar/ToolbarBackend.cs b/SpaceWarp/API/Toolbar/ToolbarBackend.cs deleted file mode 100644 index b1636a93..00000000 --- a/SpaceWarp/API/Toolbar/ToolbarBackend.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Attribution Notice To Lawrence/HatBat of https://github.com/Halbann/LazyOrbit -// This file is licensed under https://creativecommons.org/licenses/by-sa/4.0/ - -using System; -using System.Collections; -using HarmonyLib; -using I2.Loc; -using KSP.Api; -using KSP.Api.CoreTypes; -using KSP.Sim.impl; -using KSP.UI.Binding; -using KSP.UI.Flight; -using SpaceWarp.API.Logging; -using TMPro; -using UnityEngine; -using UnityEngine.Events; -using UnityEngine.UI; -using Object = UnityEngine.Object; - -namespace SpaceWarp.API.Toolbar; - -public static class ToolbarBackend -{ - private static BaseModLogger _logger = new ModLogger("ToolbarBackend"); - public static GameObject AddButton(string buttonText, Sprite buttonIcon, string buttonId, Action function) - { - // Find the resource manager button and "others" group. - - // Say the magic words... - GameObject list = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Popup Canvas/Container/ButtonBar/BTN-App-Tray/appbar-others-group"); - GameObject resourceManger = list?.GetChild("BTN-Resource-Manager"); - - if (list == null || resourceManger == null) - { - _logger.Info("Couldn't find appbar."); - return null; - } - - // Clone the resource manager button. - GameObject appButton = Object.Instantiate(resourceManger, list.transform); - appButton.name = buttonId; - - // Change the text. - TextMeshProUGUI text = appButton.GetChild("Content").GetChild("TXT-title").GetComponent(); - text.text = buttonText; - - Localize localizer = text.gameObject.GetComponent(); - if (localizer) - Object.Destroy(localizer); - - // Change the icon. - GameObject icon = appButton.GetChild("Content").GetChild("GRP-icon"); - Image image = icon.GetChild("ICO-asset").GetComponent(); - image.sprite = buttonIcon; - - // Add our function call to the toggle. - ToggleExtended utoggle = appButton.GetComponent(); - utoggle.onValueChanged.AddListener(state => function(state)); - - // Set the initial state of the button. - UIValue_WriteBool_Toggle toggle = appButton.GetComponent(); - toggle.BindValue(new Property(false)); - - // Bind the action to close the tray after pressing the button. - IAction action = resourceManger.GetComponent().Action; - appButton.GetComponent().BindAction(action); - - _logger.Info($"Added appbar button: {buttonId}"); - - return appButton; - } - - public static UnityEvent AppBarInFlightSubscriber = new UnityEvent(); - - internal static void SubscriberSchedulePing() - { - GameObject gameObject = new GameObject(); - gameObject.AddComponent(); - gameObject.SetActive(true); - } -} - -class ToolbarBackendObject : KerbalBehavior -{ - public new void Start() - { - - StartCoroutine(awaiter()); - } - - private IEnumerator awaiter() - { - yield return new WaitForSeconds(1); - ToolbarBackend.AppBarInFlightSubscriber.Invoke(); - Destroy(this); - } -} - -//TODO: Much better way of doing this -[HarmonyPatch(typeof(UIFlightHud))] -[HarmonyPatch("Start")] -class ToolbarBackendAppBarPatcher -{ - public static void Postfix(UIFlightHud __instance) => ToolbarBackend.SubscriberSchedulePing(); -} \ No newline at end of file diff --git a/SpaceWarp/API/UI/Appbar/Appbar.cs b/SpaceWarp/API/UI/Appbar/Appbar.cs new file mode 100644 index 00000000..2176d507 --- /dev/null +++ b/SpaceWarp/API/UI/Appbar/Appbar.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using BepInEx.Bootstrap; +using UnityEngine; +using SpaceWarp.Backend.UI.Appbar; + + +namespace SpaceWarp.API.UI.Appbar; + +public static class Appbar +{ + private static readonly List<(string text, Sprite icon, string ID, Action action)> ButtonsToBeLoaded = new(); + private static readonly List<(string text, Sprite icon, string ID, Action action)> OABButtonsToBeLoaded = new(); + + /// + /// Register a appbar menu for the game + /// + /// The text in the appbar menu + /// The title of the menu + /// A unique id for the appbar menu eg: "BTN-Example" + /// A Sprite for the icon in the appbar + /// The type of the appbar menu, must extend AppbarMenu + /// An instance of T which has been added to a GameObject + public static T RegisterGameAppbarMenu(string text, string title, string id, Sprite icon) where T : AppbarMenu + { + GameObject toolBarUIObject = new GameObject($"Toolbar: {id}"); + toolBarUIObject.Persist(); + AppbarMenu menu = toolBarUIObject.AddComponent(); + menu.Title = title; + menu.ID = id; + toolBarUIObject.transform.SetParent(Chainloader.ManagerObject.transform); + toolBarUIObject.SetActive(true); + ButtonsToBeLoaded.Add((text, icon, id, menu.ToggleGUI)); + return menu as T; + } + + /// + /// Register a appbar menu for the game + /// + /// The text in the appbar menu + /// The title of the menu + /// A unique id for the appbar menu eg: "BTN-Example" + /// A Texture2D for the icon in the appbar + /// The type of the appbar menu, must extend AppbarMenu + /// An instance of T which has been added to a GameObject + public static T RegisterGameAppbarMenu(string text, string title, string id, Texture2D icon) where T : AppbarMenu + { + return RegisterGameAppbarMenu(text, title, id, GetAppBarIconFromTexture(icon)); + } + + /// + /// Register a button on the games AppBar + /// + /// The text in the appbar menu + /// A unique id for the appbar menu eg: "BTN-Example" + /// A Sprite for the icon in the appbar + /// The function to be called when this button is clicked + public static void RegisterAppButton(string text, string id, Sprite icon, Action func) + { + ButtonsToBeLoaded.Add((text, icon, id, func)); + } + + /// + /// Register a button on the games AppBar + /// + /// The text in the appbar menu + /// A unique id for the appbar menu eg: "BTN-Example" + /// A Texture2D for the icon in the appbar + /// The function to be called when this button is clicked + public static void RegisterAppButton(string text, string id, Texture2D icon, Action func) + { + RegisterAppButton(text, id, GetAppBarIconFromTexture(icon), func); + } + + /// + /// Register a button on the OAB AppBar + /// + /// The text in the appbar menu + /// A unique id for the appbar menu eg: "BTN-ExampleOAB" + /// A Sprite for the icon in the appbar + /// The function to be called when this button is clicked + public static void RegisterOABAppButton(string text, string id, Sprite icon, Action func) + { + OABButtonsToBeLoaded.Add((text, icon, id, func)); + } + + /// + /// Register a button on the OAB AppBar + /// + /// The text in the appbar menu + /// A unique id for the appbar menu eg: "BTN-ExampleOAB" + /// A Texture2D for the icon in the appbar + /// The function to be called when this button is clicked + public static void RegisterOABAppButton(string text, string id, Texture2D icon, Action func) + { + RegisterOABAppButton(text, id, GetAppBarIconFromTexture(icon), func); + } + + + /// + /// Convert a Texture2D to a Sprite + /// + /// The Texture2D + /// The width of the sprite, 0 for inferring + /// The height of the sprite, 0 for inferring + /// The Texture2D converted to a Sprite + public static Sprite GetAppBarIconFromTexture(Texture2D texture, int width=0, int height=0) + { + if (width == 0) width = texture.width; + if (height == 0) height = texture.height; + + return Sprite.Create(texture, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f)); + } + + internal static void LoadAllButtons() + { + foreach (var button in ButtonsToBeLoaded) + { + AppbarBackend.AddButton(button.text, button.icon, button.ID, button.action); + } + } + + internal static void LoadOABButtons() + { + foreach (var button in OABButtonsToBeLoaded) + { + AppbarBackend.AddOABButton(button.text, button.icon, button.ID, button.action); + } + } +} diff --git a/SpaceWarp/API/Toolbar/ToolbarMenu.cs b/SpaceWarp/API/UI/Appbar/AppbarMenu.cs similarity index 64% rename from SpaceWarp/API/Toolbar/ToolbarMenu.cs rename to SpaceWarp/API/UI/Appbar/AppbarMenu.cs index d880dd84..aee7780e 100644 --- a/SpaceWarp/API/Toolbar/ToolbarMenu.cs +++ b/SpaceWarp/API/UI/Appbar/AppbarMenu.cs @@ -1,17 +1,17 @@ -using System.IO; -using System.Reflection; using KSP.Game; using KSP.Sim.impl; -using SpaceWarp.API.AssetBundles; +using KSP.UI.Binding; using UnityEngine; -namespace SpaceWarp.API.Toolbar; +namespace SpaceWarp.API.UI.Appbar; -public abstract class ToolbarMenu : KerbalBehavior +public abstract class AppbarMenu : KerbalBehavior { - private GUISkin _spaceWarpConsoleSkin = null; - private bool _drawing = false; - + private GUISkin _spaceWarpConsoleSkin; + private bool _drawing; + internal string ID; + private GUIStyle _closeButtonStyle; + public abstract float Width { get; @@ -38,7 +38,7 @@ public virtual GUISkin Skin { if (_spaceWarpConsoleSkin == null) { - ResourceManager.TryGetAsset($"space_warp/swconsoleui/swconsoleUI/spacewarpConsole.guiskin", out _spaceWarpConsoleSkin); + _spaceWarpConsoleSkin = Skins.ConsoleSkin; } return _spaceWarpConsoleSkin; @@ -57,8 +57,12 @@ public void OnGUI() { if (!_drawing || GameManager.Instance.Game.GlobalGameState.GetState() != GameState.FlightView) return; + GUI.skin = Skin; - + _closeButtonStyle ??= new GUIStyle(GUI.skin.button) + { + fontSize = 8 + }; int controlID = GUIUtility.GetControlID(FocusType.Passive); GUILayoutOption width = GUILayout.Width(Width); @@ -79,9 +83,21 @@ public void ToggleGUI() private void DoDrawing(int windowID) { + Rect closeButtonRect = new Rect(Width - 23, 6, 16, 16); + if (GUI.Button(new Rect(_windowRect.width - 18, 2, 16, 16), "x", _closeButtonStyle)) + { + CloseWindow(); + GUIUtility.ExitGUI(); + } DrawWindow(windowID); GUI.DragWindow(new Rect(0, 0, 10000, 10000)); } public abstract void DrawWindow(int windowID); + + public void CloseWindow() + { + ToggleGUI(false); + GameObject.Find(ID)?.GetComponent()?.SetValue(false); + } } \ No newline at end of file diff --git a/SpaceWarp/API/UI/MainMenu.cs b/SpaceWarp/API/UI/MainMenu.cs new file mode 100644 index 00000000..15db6f56 --- /dev/null +++ b/SpaceWarp/API/UI/MainMenu.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace SpaceWarp.API.UI; + +public static class MainMenu +{ + internal static readonly List<(string name, Action onClicked)> MenuButtonsToBeAdded = new (); + + + /// + /// Registers a button to be added to the main menu. + /// + /// The name of the button on the menu. + /// The action that is invoked when the button is pressed + public static void RegisterMenuButton(string name, Action onClicked) + { + MenuButtonsToBeAdded.Add((name,onClicked)); + } +} \ No newline at end of file diff --git a/SpaceWarp/API/UI/Skins.cs b/SpaceWarp/API/UI/Skins.cs new file mode 100644 index 00000000..59da0818 --- /dev/null +++ b/SpaceWarp/API/UI/Skins.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace SpaceWarp.API.UI; + +// This exposes the SpaceWarp internal skins +public static class Skins +{ + public static GUISkin ConsoleSkin => SpaceWarpManager.Skin; +} \ No newline at end of file diff --git a/SpaceWarp/API/Versions/VersionUtility.cs b/SpaceWarp/API/Versions/VersionUtility.cs index defaff80..93e91aa4 100644 --- a/SpaceWarp/API/Versions/VersionUtility.cs +++ b/SpaceWarp/API/Versions/VersionUtility.cs @@ -2,6 +2,12 @@ public static class VersionUtility { + /// + /// Checks if one semantic version is above another + /// + /// The version to check against + /// The version that is being checked + /// toCheck >= version public static bool IsVersionAbove(string version, string toCheck) { if (version == "") @@ -11,24 +17,17 @@ public static bool IsVersionAbove(string version, string toCheck) string[] semanticVersion = toCheck.Split('.'); string[] requiredVersion = version.Split('.'); - - for (int i = 0; i < requiredVersion.Length; i++) - { - if (requiredVersion[i] == "*") - { - continue; - } - - if (int.Parse(semanticVersion[i]) < int.Parse(requiredVersion[i])) - { - return false; - } - } - return true; + return !requiredVersion.Where((t, i) => t != "*" && int.Parse(semanticVersion[i]) < int.Parse(t)).Any(); } - public static bool IsVersionBellow(string version, string toCheck) + /// + /// Checks if one semantic version is below another + /// + /// The version to check against + /// The version that is being checked + /// toCheck is less than or equal to version + public static bool IsVersionBelow(string version, string toCheck) { if (version == "") { @@ -37,20 +36,7 @@ public static bool IsVersionBellow(string version, string toCheck) string[] semanticVersion = toCheck.Split('.'); string[] requiredVersion = version.Split('.'); - - for (int i = 0; i < requiredVersion.Length; i++) - { - if (requiredVersion[i] == "*") - { - continue; - } - - if (int.Parse(semanticVersion[i]) > int.Parse(requiredVersion[i])) - { - return false; - } - } - return true; + return !requiredVersion.Where((t, i) => t != "*" && int.Parse(semanticVersion[i]) > int.Parse(t)).Any(); } } \ No newline at end of file diff --git a/SpaceWarp/AssetHelpers.cs b/SpaceWarp/AssetHelpers.cs new file mode 100644 index 00000000..779ba479 --- /dev/null +++ b/SpaceWarp/AssetHelpers.cs @@ -0,0 +1,63 @@ +using System.IO; +using KSP.Game; +using UnityEngine.AddressableAssets; +using UnityEngine.AddressableAssets.ResourceLocators; +using UnityEngine.ResourceManagement.AsyncOperations; + +namespace SpaceWarp; + +internal static class AssetHelpers +{ + public static void LoadAddressable(string catalog) + { + SpaceWarpManager.Logger.LogInfo($"Attempting to load {catalog}"); + AsyncOperationHandle operation = Addressables.LoadContentCatalogAsync(catalog); + operation.WaitForCompletion(); + if (operation.Status == AsyncOperationStatus.Failed) + { + SpaceWarpManager.Logger.LogError($"Failed to load addressables catalog {catalog}"); + } + else + { + SpaceWarpManager.Logger.LogInfo($"Loaded addressables catalog {catalog}"); + var locator = operation.Result; + SpaceWarpManager.Logger.LogInfo($"{catalog} ----- {locator.LocatorId}"); + GameManager.Instance.Game.Assets.RegisterResourceLocator(locator); + } + } + + internal static void LoadLocalizationFromFolder(string folder) + { + SpaceWarpManager.Logger.LogInfo($"Attempting to load localizations from {folder}"); + I2.Loc.LanguageSourceData languageSourceData = null; + if (!Directory.Exists(folder)) + { + SpaceWarpManager.Logger.LogInfo($"{folder} does not exist, not loading localizations."); + return; + } + DirectoryInfo info = new DirectoryInfo(folder); + foreach (var csvFile in info.GetFiles("*.csv")) + { + languageSourceData ??= new I2.Loc.LanguageSourceData(); + var csvData = File.ReadAllText(csvFile.FullName); + languageSourceData.Import_CSV("", csvData, I2.Loc.eSpreadsheetUpdateMode.AddNewTerms); + } + + foreach (var i2csvFile in info.GetFiles("*.i2csv")) + { + languageSourceData ??= new I2.Loc.LanguageSourceData(); + var i2csvData = File.ReadAllText(i2csvFile.FullName); + languageSourceData.Import_I2CSV("", i2csvData, I2.Loc.eSpreadsheetUpdateMode.AddNewTerms); + } + + if (languageSourceData != null) + { + SpaceWarpManager.Logger.LogInfo($"Loaded localizations from {folder}"); + I2.Loc.LocalizationManager.AddSource(languageSourceData); + } + else + { + SpaceWarpManager.Logger.LogInfo($"No localizations found in {folder}"); + } + } +} diff --git a/SpaceWarp/Backend/UI/Appbar/AppbarBackend.cs b/SpaceWarp/Backend/UI/Appbar/AppbarBackend.cs new file mode 100644 index 00000000..a9e60215 --- /dev/null +++ b/SpaceWarp/Backend/UI/Appbar/AppbarBackend.cs @@ -0,0 +1,329 @@ +// Attribution Notice To Lawrence/HatBat of https://github.com/Halbann/LazyOrbit +// This file is licensed under https://creativecommons.org/licenses/by-sa/4.0/ + +using System; +using System.Collections; +using System.Reflection; +using BepInEx.Logging; +using HarmonyLib; +using I2.Loc; +using KSP; +using KSP.Api; +using KSP.Api.CoreTypes; +using KSP.Game; +using KSP.OAB; +using KSP.Sim.impl; +using KSP.UI.Binding; +using KSP.UI.Flight; +using SpaceWarp.API.Assets; +using TMPro; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.UI; +using static SpaceWarp.Backend.UI.Appbar.AppbarBackend; +using Object = UnityEngine.Object; + +namespace SpaceWarp.Backend.UI.Appbar; + +internal static class AppbarBackend +{ + + private static readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("ToolbarBackend"); + + #region Flight App Bar + + private static UIValue_WriteBool_Toggle trayState; + + public static GameObject AddButton(string buttonText, Sprite buttonIcon, string buttonId, Action function) + { + // Find the resource manager button and "others" group. + + // Say the magic words... + GameObject list = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Popup Canvas/Container/ButtonBar/BTN-App-Tray/appbar-others-group"); + GameObject resourceManger = list?.GetChild("BTN-Resource-Manager"); + + if (list == null || resourceManger == null) + { + _logger.LogInfo("Couldn't find appbar."); + return null; + } + + trayState = list.transform.parent.gameObject.GetComponent(); + + // Clone the resource manager button. + GameObject appButton = Object.Instantiate(resourceManger, list.transform); + appButton.name = buttonId; + + // Change the text. + TextMeshProUGUI text = appButton.GetChild("Content").GetChild("TXT-title").GetComponent(); + text.text = buttonText; + + Localize localizer = text.gameObject.GetComponent(); + if (localizer) + { + Object.Destroy(localizer); + } + + // Change the icon. + GameObject icon = appButton.GetChild("Content").GetChild("GRP-icon"); + Image image = icon.GetChild("ICO-asset").GetComponent(); + image.sprite = buttonIcon; + + // Add our function call to the toggle. + ToggleExtended utoggle = appButton.GetComponent(); + utoggle.onValueChanged.AddListener(state => function(state)); + utoggle.onValueChanged.AddListener(state => SetTrayState(false)); + + // Set the initial state of the button. + UIValue_WriteBool_Toggle toggle = appButton.GetComponent(); + toggle.BindValue(new Property(false)); + + _logger.LogInfo($"Added appbar button: {buttonId}"); + + return appButton; + } + + public static void SetTrayState(bool state) + { + if (trayState == null) + return; + + trayState.SetValue(state); + } + + #endregion + + #region OAB App Bar + + private static GameObject _oabTray; + private static GameObject OABTray + { + get + { + if (_oabTray == null) + return _oabTray = CreateOABTray(); + + return _oabTray; + } + set => _oabTray = value; + } + + private static Property _oabState; + + private static GameObject CreateOABTray() + { + _logger.LogInfo("Creating OAB app button tray..."); + + // Find the OAB app bar and the kerbal manager button. + + // Say the magic words... + GameObject oabAppBar = GameObject.Find("OAB(Clone)/HUDSpawner/HUD/widget_SideBar/widget_sidebarNav"); + GameObject kerbalManager = oabAppBar?.GetChild("button_kerbal-manager"); + + if (oabAppBar == null || kerbalManager == null) + { + _logger.LogError("Couldn't find OAB appbar."); + return null; + } + + // Clone the kerbal manager button. + GameObject oabTrayButton = Object.Instantiate(kerbalManager, oabAppBar.transform); + oabTrayButton.name = "OAB-AppTrayButton"; + + // Set the initial state of the button. + UIValue_WriteBool_Toggle toggle = oabTrayButton.GetComponent(); + Property state = new Property(false); + toggle.BindValue(state); + _oabState = state; + + // Set the button icon. + Image image = oabTrayButton.GetComponent(); + Texture2D tex = AssetManager.GetAsset("spacewarp/images/oabTrayButton.png"); + tex.filterMode = FilterMode.Point; + image.sprite = Sprite.Create(tex, new Rect(0, 0, 32, 32), new Vector2(0.5f, 0.5f)); + + // Delete the old tooltip. + var tooltip = oabTrayButton.GetComponent(); + Object.DestroyImmediate(tooltip); + + // Create a new tooltip holder, having it on a separate game object prevents + // the tooltip from showing up on children of the tray button. + GameObject tooltipObject = new GameObject("OAB-AppTrayTooltip"); + + tooltipObject.AddComponent().CopyFrom(oabTrayButton.GetComponent()); + tooltipObject.transform.SetParent(oabTrayButton.transform); + tooltipObject.transform.localPosition = Vector3.zero; + + // ObjectAssemblyBuilderTooltipDisplay seems to require an image to work. + Image tooltipImage = tooltipObject.AddComponent(); + tooltipImage.color = new Color(0, 0, 0, 0); + + // Create the tooltip itself. + tooltip = tooltipObject.AddComponent(); + tooltip.GetType().GetField("tooltipText", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(tooltip, "App Tray"); + + // Clone the tray from the flight UI. + GameObject trayButton = GameManager.Instance.Game.UI.GetPopupCanvas().gameObject.GetChild("BTN-App-Tray"); + GameObject oabTray = Object.Instantiate(trayButton.GetChild("appbar-others-group"), oabTrayButton.transform); + oabTray.name = "OAB-AppTray"; + + // Bind the tray state with our button. + oabTray.GetComponent().BindValue(state); + + // Change the background colour. + var oabAppBarBG = oabAppBar.GetChild("BG-AppBar").GetComponent(); + oabTray.GetComponent().color = oabAppBarBG.color; + + // Delete the existing buttons in the tray. + for (int i = 0; i < oabTray.transform.childCount; i++) + { + var child = oabTray.transform.GetChild(i); + + if (child.name.Contains("ELE-border")) + continue; + + Object.Destroy(child.gameObject); + } + + _logger.LogInfo("Created OAB app button tray."); + + return oabTray; + } + + public static GameObject AddOABButton(string buttonText, Sprite buttonIcon, string buttonId, Action function) + { + _logger.LogInfo($"Adding OAB app bar button: {buttonId}."); + + // Find the resource manager button. + GameObject list = GameObject.Find("GameManager/Default Game Instance(Clone)/UI Manager(Clone)/Popup Canvas/Container/ButtonBar/BTN-App-Tray/appbar-others-group"); + GameObject resourceManger = list?.GetChild("BTN-Resource-Manager"); + + if (resourceManger == null) + { + _logger.LogError("Couldn't find the appbar."); + return null; + } + + // Clone the resource manager button. + GameObject appButton = Object.Instantiate(resourceManger, OABTray.transform); + appButton.name = buttonId; + + // Change the text. + TextMeshProUGUI text = appButton.GetChild("Content").GetChild("TXT-title").GetComponent(); + text.text = buttonText; + + Localize localizer = text.gameObject.GetComponent(); + if (localizer) + Object.Destroy(localizer); + + // Change the icon. + GameObject icon = appButton.GetChild("Content").GetChild("GRP-icon"); + Image image = icon.GetChild("ICO-asset").GetComponent(); + image.sprite = buttonIcon; + + // Add our function call to the toggle. + ToggleExtended utoggle = appButton.GetComponent(); + utoggle.onValueChanged.AddListener(state => function(state)); + + // Set the initial state of the button. + UIValue_WriteBool_Toggle toggle = appButton.GetComponent(); + toggle.BindValue(new Property(false)); + + // Bind the action to close the tray after pressing the button. + Action action = () => SetOABTrayState(false); + appButton.GetComponent().BindAction(new DelegateAction(action)); + + _logger.LogInfo($"Added appbar button: {buttonId}"); + + return appButton; + } + + public static void SetOABTrayState(bool state) + { + if (_oabTray == null) + return; + + _oabState.SetValue(state); + } + + #endregion + + public static readonly UnityEvent AppBarOABSubscriber = new(); + public static readonly UnityEvent AppBarInFlightSubscriber = new(); + + internal static void SubscriberSchedulePing(AppbarEvent type) + { + _logger.LogInfo($"App bar creation event started: {type}"); + + GameObject gameObject = new GameObject(); + ToolbarBackendObject waiterObject = gameObject.AddComponent(); + + switch (type) + { + case AppbarEvent.Flight: + waiterObject.creationEvent = AppBarInFlightSubscriber; + break; + case AppbarEvent.OAB: + waiterObject.creationEvent = AppBarOABSubscriber; + break; + default: + break; + } + + waiterObject.type = type; + gameObject.SetActive(true); + } + + internal enum AppbarEvent + { + Flight, + OAB + } +} + +internal class ToolbarBackendObject : KerbalBehavior +{ + internal UnityEvent creationEvent; + internal AppbarEvent type; + + public new void Start() + { + StartCoroutine(awaiter()); + } + + private IEnumerator awaiter() + { + switch (type) + { + case AppbarEvent.Flight: + yield return new WaitForSeconds(1); + break; + case AppbarEvent.OAB: + yield return new WaitForFixedUpdate(); + break; + default: + yield return new WaitForSeconds(1); + break; + } + + creationEvent.Invoke(); + Destroy(this); + } +} + +//TODO: Much better way of doing this +[HarmonyPatch(typeof(UIFlightHud))] +[HarmonyPatch("Start")] +internal class ToolbarBackendAppBarPatcher +{ + public static void Postfix(UIFlightHud __instance) => + AppbarBackend.SubscriberSchedulePing(AppbarBackend.AppbarEvent.Flight); +} + +[HarmonyPatch(typeof(OABSideBar))] +[HarmonyPatch("Start")] +internal class ToolbarBackendOABSideBarPatcher +{ + public static void Postfix(OABSideBar __instance) => + AppbarBackend.SubscriberSchedulePing(AppbarBackend.AppbarEvent.OAB); +} diff --git a/SpaceWarp/BepInExEntrypoint.cs b/SpaceWarp/BepInExEntrypoint.cs deleted file mode 100644 index c5c8301f..00000000 --- a/SpaceWarp/BepInExEntrypoint.cs +++ /dev/null @@ -1,15 +0,0 @@ -#if !DOORSTOP_BUILD -using BepInEx; - -namespace SpaceWarp -{ - [BepInPlugin("com.github.x606.spacewarp", "SpaceWarp", MyPluginInfo.PLUGIN_VERSION)] - public class BepInExEntrypoint : BaseUnityPlugin - { - public void Awake() - { - SpaceWarpEntrypoint.Start(); - } - } -} -#endif diff --git a/SpaceWarp/Compilation/ModCompiler.cs b/SpaceWarp/Compilation/ModCompiler.cs deleted file mode 100644 index 6adeb741..00000000 --- a/SpaceWarp/Compilation/ModCompiler.cs +++ /dev/null @@ -1,132 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using SpaceWarp.API; -using SpaceWarp.API.Logging; -using UniLinq; - -namespace SpaceWarp.Compilation; - -public static class ModCompiler -{ - public static readonly string CACHE_LOCATION = Path.Combine(SpaceWarpManager.SPACE_WARP_PATH,"mod_cache"); - - private static BaseModLogger _logger = new ModLogger("Roslyn Compilation"); - public static Assembly CompileMod(string modID, string modSrcPath) - { - try - { - if (!Directory.Exists(modSrcPath)) - { - return null; - } - _logger.Info($"starting compilation of {modID}"); - - if (!CreateNewCompilation(modID, modSrcPath)) - { - _logger.Info($"found cached version of {modID}"); - return GetCachedCompilation(modID); - } - - _logger.Info($"no cached version for {modID}, generating assembly"); - - // Now work on adding dependencies to the tree - return CompileNewAssemblyAndCache(modID, modSrcPath); - } - catch (Exception e) - { - _logger.Error($"error compiling scripts for {modID}\n{e}"); - return null; - } - } - - private static string[] AllSourceFiles(string modSrcPath) - { - DirectoryInfo directoryInfo = new DirectoryInfo(modSrcPath); - string[] sourceFiles = directoryInfo.EnumerateFiles("*.cs", SearchOption.AllDirectories) - .Select(fileInfo => fileInfo.FullName) - .ToArray(); - return sourceFiles; - } - - private static bool CreateNewCompilation(string modID, string modSrcPath) - { - string[] allSourceFiles = AllSourceFiles(modSrcPath); - DateTime latestWriteTime = DateTime.FromBinary(0); - foreach (var sourceFile in allSourceFiles) - { - if (File.GetLastWriteTime(sourceFile) > latestWriteTime) - { - latestWriteTime = File.GetLastWriteTime(sourceFile); - } - } - - if (!Directory.Exists(CACHE_LOCATION)) - { - Directory.CreateDirectory(CACHE_LOCATION); - return true; - } - - if (!File.Exists(Path.Combine(CACHE_LOCATION,modID + ".dll"))) - { - return true; - } - - if (File.GetLastWriteTime(Path.Combine(CACHE_LOCATION,modID + ".dll")) < latestWriteTime) - { - return true; - } - - return false; - } - - private static Assembly GetCachedCompilation(string modID) - { - return Assembly.LoadFrom(Path.Combine(CACHE_LOCATION,modID + ".dll")); - } - - private static Assembly CompileNewAssemblyAndCache(string modID, string modSrcPath) - { - string[] allSourceFiles = AllSourceFiles(modSrcPath); - List trees = Enumerable.ToList( - Enumerable.Select( - Enumerable.Select(allSourceFiles, File.ReadAllText), - code => CSharpSyntaxTree.ParseText(code) - ) - ); - - List references = Enumerable.ToList( - Enumerable.Cast( - from asm in AppDomain.CurrentDomain.GetAssemblies() - where !asm.IsDynamic - select MetadataReference.CreateFromFile(asm.Location) - ) - ); - - var compilation = CSharpCompilation.Create(modID + ".dll", trees, references, - new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)); - - var result = compilation.Emit(Path.Combine(CACHE_LOCATION,modID + ".dll")); - foreach (Diagnostic diagnostic in result.Diagnostics) - { - if (diagnostic.WarningLevel == 0) - { - _logger.Error(diagnostic.ToString()); - } - else - { - _logger.Info(diagnostic.ToString()); - } - } - - _logger.Info(result.ToString()); - if (!result.Success) - { - File.Delete(Path.Combine(CACHE_LOCATION,modID + ".dll")); - } - return !result.Success ? null : Assembly.LoadFile(Path.Combine(CACHE_LOCATION,modID + ".dll")); - } -} \ No newline at end of file diff --git a/SpaceWarp/Entrypoint.cs b/SpaceWarp/Entrypoint.cs deleted file mode 100644 index 15fed0cd..00000000 --- a/SpaceWarp/Entrypoint.cs +++ /dev/null @@ -1,62 +0,0 @@ -using HarmonyLib; -using KSP.Logging; -using SpaceWarp.API; -using SpaceWarp.UI; -using System.Reflection; -using UnityEngine.SceneManagement; -using HarmonyLogger = HarmonyLib.Tools.Logger; - -#if DOORSTOP_BUILD -namespace Doorstop -{ - public class Entrypoint -#else -namespace SpaceWarp { - public class SpaceWarpEntrypoint -#endif -{ - private static bool _patched; - - private const string HARMONY_PACKAGE_URL = "com.github.x606.spacewarp"; - - /// - /// EntryPoint for Spacewarp, called from Doorstop - /// - public static void Start() - { - SpaceWarpGlobalConfiguration.Init(); - - SceneManager.sceneLoaded += OnSceneLoaded; - - KspLogManager.AddLogCallback(SpaceWarpConsoleLogListener.LogCallback); - if (SpaceWarpGlobalConfiguration.Instance.HarmonyLoggin) - { - HarmonyLogger.ChannelFilter = HarmonyLogger.LogChannel.All; - HarmonyLogger.MessageReceived += SpaceWarpConsoleLogListener.HarmonyLogCallback; - } - } - - /// - /// Add OnGameStarted as postfix to StartGame - /// - static void OnSceneLoaded(Scene unused1, LoadSceneMode unused2) - { - if (!_patched) - { - InitializePatches(); - _patched = true; - } - } - - /// - /// Initializes Harmony - /// - - static void InitializePatches() - { - Harmony harmony = new Harmony(HARMONY_PACKAGE_URL); - - harmony.PatchAll(Assembly.GetExecutingAssembly()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/InternalExtensions.cs b/SpaceWarp/InternalExtensions.cs new file mode 100644 index 00000000..e7f14502 --- /dev/null +++ b/SpaceWarp/InternalExtensions.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace SpaceWarp; + +internal static class InternalExtensions +{ + public static void Persist(this UnityObject obj) + { + UnityObject.DontDestroyOnLoad(obj); + obj.hideFlags |= HideFlags.HideAndDontSave; + } +} diff --git a/SpaceWarp/Patching/BootstrapPatch.cs b/SpaceWarp/Patching/BootstrapPatch.cs new file mode 100644 index 00000000..71dc62f5 --- /dev/null +++ b/SpaceWarp/Patching/BootstrapPatch.cs @@ -0,0 +1,64 @@ +using HarmonyLib; +using KSP.Game; +using MonoMod.Cil; +using SpaceWarp.Patching.LoadingActions; + +namespace SpaceWarp.Patching; + +[HarmonyPatch] +internal static class BootstrapPatch +{ + [HarmonyPrefix] + [HarmonyPatch(typeof(GameManager), nameof(GameManager.Awake))] + private static void GetSpaceWarpMods() + { + SpaceWarpManager.GetSpaceWarpPlugins(); + } + + [HarmonyILManipulator] + [HarmonyPatch(typeof(GameManager), nameof(GameManager.StartBootstrap))] + private static void PatchInitializationsIL(ILContext ilContext, ILLabel endLabel) + { + ILCursor ilCursor = new(ilContext); + + var flowProp = AccessTools.DeclaredProperty(typeof(GameManager), nameof(GameManager.LoadingFlow)); + + ilCursor.GotoNext( + MoveType.After, + instruction => instruction.MatchCallOrCallvirt(flowProp.SetMethod) + ); + + ilCursor.EmitDelegate(static () => + { + foreach (var plugin in SpaceWarpManager.SpaceWarpPlugins) + { + GameManager.Instance.LoadingFlow.AddAction(new PreInitializeModAction(plugin)); + } + }); + + ilCursor.GotoLabel(endLabel, MoveType.Before); + ilCursor.Index -= 1; + ilCursor.EmitDelegate(static () => + { + var flow = GameManager.Instance.LoadingFlow; + + foreach (var plugin in SpaceWarpManager.SpaceWarpPlugins) + { + flow.AddAction(new LoadLocalizationAction(plugin)); + flow.AddAction(new LoadAddressablesAction(plugin)); + flow.AddAction(new LoadAssetAction(plugin)); + } + + foreach (var plugin in SpaceWarpManager.SpaceWarpPlugins) + { + flow.AddAction(new InitializeModAction(plugin)); + } + + foreach (var plugin in SpaceWarpManager.SpaceWarpPlugins) + { + flow.AddAction(new PostInitializeModAction(plugin)); + } + + }); + } +} diff --git a/SpaceWarp/Patching/ConfigurationPatch.cs b/SpaceWarp/Patching/ConfigurationPatch.cs new file mode 100644 index 00000000..e9dfcc46 --- /dev/null +++ b/SpaceWarp/Patching/ConfigurationPatch.cs @@ -0,0 +1,19 @@ +using BepInEx; +using BepInEx.Bootstrap; +using ConfigurationManager.Utilities; +using HarmonyLib; + +namespace SpaceWarp.Patching; + +[HarmonyPatch(typeof(Utils))] +[HarmonyPatch(nameof(Utils.FindPlugins))] +public class ConfigurationPatch +{ + static void Postfix(ref BaseUnityPlugin[] __result) + { + //Disable because I know what I am doing. +#pragma warning disable CS0618 + __result = Chainloader.Plugins.ToArray(); +#pragma warning restore CS0618 + } +} \ No newline at end of file diff --git a/SpaceWarp/Patching/FixGetTypes.cs b/SpaceWarp/Patching/FixGetTypes.cs new file mode 100644 index 00000000..d6234655 --- /dev/null +++ b/SpaceWarp/Patching/FixGetTypes.cs @@ -0,0 +1,30 @@ +using System; +using System.Reflection; +using HarmonyLib; + +namespace SpaceWarp.Patching; + +[HarmonyPatch] +internal static class FixGetTypes +{ + [HarmonyFinalizer] + [HarmonyPatch(typeof(Assembly), nameof(Assembly.GetTypes), new Type[0])] + [HarmonyPatch(typeof(Assembly), nameof(Assembly.GetExportedTypes))] + private static Exception GetTypesFix(Exception __exception, Assembly __instance, ref Type[] __result) + { + if (__exception is ReflectionTypeLoadException reflectionTypeLoadException) + { + SpaceWarpManager.Logger.LogWarning($"Types failed to load from assembly {__instance.FullName} due to the reasons below, continuing anyway."); + SpaceWarpManager.Logger.LogWarning($"Exception: {__exception}"); + + foreach (var exception in reflectionTypeLoadException.LoaderExceptions) + { + SpaceWarpManager.Logger.LogWarning(exception.ToString()); + } + __result = reflectionTypeLoadException.Types.Where(type => type != null).ToArray(); + return null; + } + + return __exception; + } +} diff --git a/SpaceWarp/Patching/LoadingActions/AfterModsLoadedAction.cs b/SpaceWarp/Patching/LoadingActions/AfterModsLoadedAction.cs deleted file mode 100644 index 41a54d2d..00000000 --- a/SpaceWarp/Patching/LoadingActions/AfterModsLoadedAction.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class AfterModsLoadedAction : FlowAction -{ - public AfterModsLoadedAction(string name) : base(name) - { - // - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.InvokePostInitializeModsAfterAllModsLoaded(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/InitializeModAction.cs b/SpaceWarp/Patching/LoadingActions/InitializeModAction.cs new file mode 100644 index 00000000..ca2949b4 --- /dev/null +++ b/SpaceWarp/Patching/LoadingActions/InitializeModAction.cs @@ -0,0 +1,29 @@ +using System; +using KSP.Game.Flow; +using SpaceWarp.API.Mods; + +namespace SpaceWarp.Patching.LoadingActions; + +internal sealed class InitializeModAction : FlowAction +{ + private readonly BaseSpaceWarpPlugin Plugin; + + public InitializeModAction(BaseSpaceWarpPlugin plugin) : base($"Initialization for plugin {plugin.Info.Metadata.Name}") + { + Plugin = plugin; + } + + public override void DoAction(Action resolve, Action reject) + { + try + { + Plugin.OnInitialized(); + resolve(); + } + catch (Exception e) + { + Plugin.ModLogger.LogError(e.ToString()); + reject(null); + } + } +} diff --git a/SpaceWarp/Patching/LoadingActions/LoadAddressablesAction.cs b/SpaceWarp/Patching/LoadingActions/LoadAddressablesAction.cs index e3594a75..1ed2f78f 100644 --- a/SpaceWarp/Patching/LoadingActions/LoadAddressablesAction.cs +++ b/SpaceWarp/Patching/LoadingActions/LoadAddressablesAction.cs @@ -1,34 +1,43 @@ using System; +using System.IO; +using BepInEx.Logging; using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; -using SpaceWarp.API.Mods.JSON; +using SpaceWarp.API.Mods; namespace SpaceWarp.Patching.LoadingActions; -public class LoadAddressablesAction : FlowAction +internal sealed class LoadAddressablesAction : FlowAction { - private string _modID; - private ModInfo _info; + private readonly BaseSpaceWarpPlugin Plugin; + private static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("Addressables Loader"); - public LoadAddressablesAction(string name, string modID, ModInfo info) : base(name) + public LoadAddressablesAction(BaseSpaceWarpPlugin plugin) : base($"Loading addressables for {plugin.SpaceWarpMetadata.Name}") { - _modID = modID; - _info = info; + Plugin = plugin; } public override void DoAction(Action resolve, Action reject) { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - try { - spaceWarpManager.LoadSingleModAddressables(_modID,_info); + string addressablesPath = Path.Combine(Plugin.PluginFolderPath, "addressables"); + Logger.LogInfo($"Loading addressables for {Plugin.SpaceWarpMetadata.Name}"); + string catalogPath = Path.Combine(addressablesPath, "catalog.json"); + if (File.Exists(catalogPath)) + { + Logger.LogInfo($"Found addressables for {Plugin.SpaceWarpMetadata.Name}"); + AssetHelpers.LoadAddressable(catalogPath); + } + else + { + Logger.LogInfo($"Did not find addressables for {Plugin.SpaceWarpMetadata.Name}"); + } resolve(); } catch (Exception e) { - reject(e.ToString()); + Plugin.ModLogger.LogError(e.ToString()); + reject(null); } } } \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadAssetAction.cs b/SpaceWarp/Patching/LoadingActions/LoadAssetAction.cs index 299bc1d0..464cc6e4 100644 --- a/SpaceWarp/Patching/LoadingActions/LoadAssetAction.cs +++ b/SpaceWarp/Patching/LoadingActions/LoadAssetAction.cs @@ -1,33 +1,99 @@ using System; +using System.IO; +using BepInEx.Logging; using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; -using SpaceWarp.API.Mods.JSON; +using SpaceWarp.API.Assets; +using SpaceWarp.API.Mods; +using UnityEngine; namespace SpaceWarp.Patching.LoadingActions; -public class LoadAssetAction : FlowAction +internal sealed class LoadAssetAction : FlowAction { - private readonly string _modID; - private readonly ModInfo _info; - public LoadAssetAction(string name, string modID, ModInfo info) : base(name) + private readonly BaseSpaceWarpPlugin Plugin; + private static readonly ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("Asset Loader"); + + public LoadAssetAction(BaseSpaceWarpPlugin plugin) : base($"Loading {plugin.SpaceWarpMetadata.Name} assets") { - _modID = modID; - _info = info; + Plugin = plugin; } public override void DoAction(Action resolve, Action reject) { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - try { - spaceWarpManager.LoadSingleModAssets(_modID,_info); + string bundlesPath = Path.Combine(Plugin.PluginFolderPath, GlobalModDefines.AssetBundlesFolder); + if (Directory.Exists(bundlesPath)) + { + foreach (string file in Directory.GetFiles(bundlesPath)) + { + string assetBundleName = Path.GetFileNameWithoutExtension(file); + if (Path.GetExtension(file) != ".bundle") continue; + + + AssetBundle assetBundle = AssetBundle.LoadFromFile(file); + + if (assetBundle == null) + { + Logger.LogError($"Failed to load AssetBundle {Plugin.SpaceWarpMetadata.ModID}/{assetBundleName}"); + continue; + } + AssetManager.RegisterAssetBundle(Plugin.SpaceWarpMetadata.ModID, assetBundleName, assetBundle); + Logger.LogInfo($"Loaded AssetBundle {Plugin.SpaceWarpMetadata.ModID}/{assetBundleName}"); + } + } + else + { + Logger.LogInfo($"Did not load asset bundles for {Plugin.SpaceWarpMetadata.Name} as no asset bundles folder existed!"); + } + + string imagesPath = Path.Combine(Plugin.PluginFolderPath, GlobalModDefines.ImageAssetsFolder); + if (Directory.Exists(imagesPath)) + { + var directoryInfo = new DirectoryInfo(imagesPath); + foreach (string file in directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories).Select(fileInfo => fileInfo.FullName)) + { + var assetPathList = PathHelpers.GetRelativePath(imagesPath, file).Split(Path.DirectorySeparatorChar); + //We have to make sure it uses '/' as the path separator and toLower() the names + var assetPath = ""; + for (int i = 0; i < assetPathList.Length; i++) + { + assetPath += assetPathList[i].ToLower(); + if (i != assetPathList.Length - 1) + { + assetPath += "/"; + } + } + + assetPath = $"images/{assetPath}"; + + Texture2D tex = new Texture2D(2, 2, TextureFormat.ARGB32, false) + { + filterMode = FilterMode.Point + }; + try + { + var fileData = File.ReadAllBytes(file); + tex.LoadImage(fileData); // Will automatically resize + AssetManager.RegisterSingleAsset(Plugin.SpaceWarpMetadata.ModID,assetPath,tex); + } + catch (Exception e) + { + Plugin.ModLogger.LogError(e.ToString()); + } + } + } + else + { + Logger.LogInfo($"Did not load images bundles for {Plugin.SpaceWarpMetadata.Name} as no images folder existed! (should be at {imagesPath}"); + } + resolve(); } catch (Exception e) { - reject(e.ToString()); + Plugin.ModLogger.LogError(e.ToString()); + reject(null); } } } \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadAssetsAction.cs b/SpaceWarp/Patching/LoadingActions/LoadAssetsAction.cs deleted file mode 100644 index 588bc932..00000000 --- a/SpaceWarp/Patching/LoadingActions/LoadAssetsAction.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class LoadAssetsAction : FlowAction -{ - public LoadAssetsAction(string name) : base(name) - { - // - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.InitializeAssets(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadLocalizationAction.cs b/SpaceWarp/Patching/LoadingActions/LoadLocalizationAction.cs index 0b6131bb..e59f27f8 100644 --- a/SpaceWarp/Patching/LoadingActions/LoadLocalizationAction.cs +++ b/SpaceWarp/Patching/LoadingActions/LoadLocalizationAction.cs @@ -1,34 +1,31 @@ using System; +using System.IO; using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; -using SpaceWarp.API.Mods.JSON; +using SpaceWarp.API.Mods; namespace SpaceWarp.Patching.LoadingActions; -public class LoadLocalizationAction : FlowAction +internal sealed class LoadLocalizationAction : FlowAction { - private string _modID; - private ModInfo _info; + private readonly BaseSpaceWarpPlugin Plugin; - public LoadLocalizationAction(string name, string modID, ModInfo info) : base(name) + public LoadLocalizationAction(BaseSpaceWarpPlugin plugin) : base($"Loading localizations for plugin {plugin.SpaceWarpMetadata.Name}") { - _modID = modID; - _info = info; + Plugin = plugin; } public override void DoAction(Action resolve, Action reject) { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - try { - spaceWarpManager.LoadSingleModLocalization(_modID,_info); + string localizationsPath = Path.Combine(Plugin.PluginFolderPath, "localizations"); + AssetHelpers.LoadLocalizationFromFolder(localizationsPath); resolve(); } catch (Exception e) { - reject(e.ToString()); + Plugin.ModLogger.LogError(e.ToString()); + reject(null); } } } \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadModAction.cs b/SpaceWarp/Patching/LoadingActions/LoadModAction.cs deleted file mode 100644 index 500608c7..00000000 --- a/SpaceWarp/Patching/LoadingActions/LoadModAction.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; -using SpaceWarp.API.Mods.JSON; - -namespace SpaceWarp.Patching.LoadingActions; - -public class LoadModAction : FlowAction -{ - private readonly string _modID; - private readonly ModInfo _info; - - public LoadModAction(string name, string modID, ModInfo info) : base(name) - { - _modID = modID; - _info = info; - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.InitializeSingleMod(_modID,_info); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadModsAction.cs b/SpaceWarp/Patching/LoadingActions/LoadModsAction.cs deleted file mode 100644 index 9c23442e..00000000 --- a/SpaceWarp/Patching/LoadingActions/LoadModsAction.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class LoadModsAction : FlowAction -{ - public LoadModsAction(string name) : base(name) - { - // - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.InitializeMods(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpAddressablesAction.cs b/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpAddressablesAction.cs deleted file mode 100644 index c857ce8d..00000000 --- a/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpAddressablesAction.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class LoadSpaceWarpAddressablesAction : FlowAction -{ - public LoadSpaceWarpAddressablesAction(string name) : base(name) - { - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.InitializeAddressablesFolder(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpLocalizationsAction.cs b/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpLocalizationsAction.cs deleted file mode 100644 index 8f347067..00000000 --- a/SpaceWarp/Patching/LoadingActions/LoadSpaceWarpLocalizationsAction.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class LoadSpaceWarpLocalizationsAction : FlowAction -{ - public LoadSpaceWarpLocalizationsAction(string name) : base(name) - { - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.LoadSpaceWarpLocalizations(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/PostInitializeModAction.cs b/SpaceWarp/Patching/LoadingActions/PostInitializeModAction.cs new file mode 100644 index 00000000..106bbb86 --- /dev/null +++ b/SpaceWarp/Patching/LoadingActions/PostInitializeModAction.cs @@ -0,0 +1,29 @@ +using System; +using KSP.Game.Flow; +using SpaceWarp.API.Mods; + +namespace SpaceWarp.Patching.LoadingActions; + +internal sealed class PostInitializeModAction : FlowAction +{ + private readonly BaseSpaceWarpPlugin Plugin; + + public PostInitializeModAction(BaseSpaceWarpPlugin plugin) : base($"Post-initialization for plugin {plugin.Info.Metadata.Name}") + { + Plugin = plugin; + } + + public override void DoAction(Action resolve, Action reject) + { + try + { + Plugin.OnPostInitialized(); + resolve(); + } + catch (Exception e) + { + Plugin.ModLogger.LogError(e.ToString()); + reject(null); + } + } +} diff --git a/SpaceWarp/Patching/LoadingActions/PreInitializeModAction.cs b/SpaceWarp/Patching/LoadingActions/PreInitializeModAction.cs new file mode 100644 index 00000000..f6168f03 --- /dev/null +++ b/SpaceWarp/Patching/LoadingActions/PreInitializeModAction.cs @@ -0,0 +1,29 @@ +using System; +using KSP.Game.Flow; +using SpaceWarp.API.Mods; + +namespace SpaceWarp.Patching.LoadingActions; + +internal sealed class PreInitializeModAction : FlowAction +{ + private readonly BaseSpaceWarpPlugin Plugin; + + public PreInitializeModAction(BaseSpaceWarpPlugin plugin) : base($"Pre-initialization for plugin {plugin.Info.Metadata.Name}") + { + Plugin = plugin; + } + + public override void DoAction(Action resolve, Action reject) + { + try + { + Plugin.OnPreInitialized(); + resolve(); + } + catch (Exception e) + { + Plugin.ModLogger.LogError(e.ToString()); + reject(null); + } + } +} diff --git a/SpaceWarp/Patching/LoadingActions/ReadingModsAction.cs b/SpaceWarp/Patching/LoadingActions/ReadingModsAction.cs deleted file mode 100644 index ea3698c1..00000000 --- a/SpaceWarp/Patching/LoadingActions/ReadingModsAction.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class ReadingModsAction : FlowAction -{ - public ReadingModsAction(string name) : base(name) - { - // - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.ReadMods(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingActions/SpaceWarpAssetInitializationAction.cs b/SpaceWarp/Patching/LoadingActions/SpaceWarpAssetInitializationAction.cs deleted file mode 100644 index e531f366..00000000 --- a/SpaceWarp/Patching/LoadingActions/SpaceWarpAssetInitializationAction.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using KSP.Game.Flow; -using SpaceWarp.API; -using SpaceWarp.API.Managers; - -namespace SpaceWarp.Patching.LoadingActions; - -public class SpaceWarpAssetInitializationAction : FlowAction -{ - public SpaceWarpAssetInitializationAction(string name) : base(name) - { - } - - public override void DoAction(Action resolve, Action reject) - { - ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager); - - try - { - spaceWarpManager.LoadSpaceWarpAssets(); - resolve(); - } - catch (Exception e) - { - reject(e.ToString()); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/LoadingScreenPatcher.cs b/SpaceWarp/Patching/LoadingScreenPatcher.cs deleted file mode 100644 index ad7ff4e4..00000000 --- a/SpaceWarp/Patching/LoadingScreenPatcher.cs +++ /dev/null @@ -1,42 +0,0 @@ -using KSP.Game; -using SpaceWarp.API; -using SpaceWarp.API.Managers; -using SpaceWarp.Patching.LoadingActions; - - -namespace SpaceWarp.Patching; - -/// -/// Patches the loading screen to add the mod loading -/// -public class LoadingScreenPatcher -{ - public static void AddModLoadingScreens() - { - GameManager gameManager = GameManager.Instance; - gameManager.LoadingFlow.AddAction(new ReadingModsAction("Resolving Space Warp Mod Load Order")); - gameManager.LoadingFlow.AddAction( - new LoadSpaceWarpAddressablesAction("Initializing Space Warp Provided Addressables")); - gameManager.LoadingFlow.AddAction( - new SpaceWarpAssetInitializationAction("Initializing Space Warp Provided Assets")); - gameManager.LoadingFlow.AddAction( - new LoadSpaceWarpLocalizationsAction("Initializing Space Warp Localizations")); - } - - public static void AddAllModLoadingSteps() - { - GameManager gameManager = GameManager.Instance; - if (!ManagerLocator.TryGet(out SpaceWarpManager spaceWarpManager)) return; //TODO: Log a message here - foreach (var mod in spaceWarpManager._modLoadOrder) - { - gameManager.LoadingFlow.AddAction(new LoadAddressablesAction($"Loading addressables for {mod.Item1}", - mod.Item1, mod.Item2)); - gameManager.LoadingFlow.AddAction(new LoadAssetAction($"Loading assets for {mod.Item1}", mod.Item1, - mod.Item2)); - gameManager.LoadingFlow.AddAction(new LoadLocalizationAction($"Loading localizations for {mod.Item1}", mod.Item1, mod.Item2)); - gameManager.LoadingFlow.AddAction(new LoadModAction($"Initializing {mod.Item1}", mod.Item1, mod.Item2)); - } - - gameManager.LoadingFlow.AddAction(new AfterModsLoadedAction("Space Warp Mod Post-Initialization")); - } -} \ No newline at end of file diff --git a/SpaceWarp/Patching/MainMenuPatcher.cs b/SpaceWarp/Patching/MainMenuPatcher.cs index dd435a69..c5df6255 100644 --- a/SpaceWarp/Patching/MainMenuPatcher.cs +++ b/SpaceWarp/Patching/MainMenuPatcher.cs @@ -1,7 +1,6 @@ using HarmonyLib; using KSP.Api.CoreTypes; -using SpaceWarp.API; -using SpaceWarp.API.Managers; +using SpaceWarp.API.UI; using TMPro; using UnityEngine; @@ -9,41 +8,31 @@ namespace SpaceWarp.Patching; [HarmonyPatch(typeof(KSP.Game.StartupFlow.LandingHUD))] [HarmonyPatch("Start")] -class MainMenuPatcher +internal class MainMenuPatcher { public static void Postfix(KSP.Game.StartupFlow.LandingHUD __instance) { - Transform menuItemsGroupTransform = __instance.transform.FindChildEx("MenuItemsGroup"); - Transform singleplayerButtonTransform = menuItemsGroupTransform.FindChildEx("Singleplayer"); - GameObject modsButton = Object.Instantiate(singleplayerButtonTransform.gameObject, menuItemsGroupTransform, false); - modsButton.name = "Mods"; - - // Move the button to be above the Exit button. - modsButton.transform.SetSiblingIndex(modsButton.transform.GetSiblingIndex() - 1); - - // Rebind the button's action to open the mod manager dialog. - UIAction_Void_Button uiAction = modsButton.GetComponent(); - DelegateAction action = new DelegateAction(); - action.BindDelegate(ModsOnClick); - uiAction.BindAction(action); - - // Set the label to "Mods". - TextMeshProUGUI tmp = modsButton.GetComponentInChildren(); + foreach (var menuButtonToBeAdded in MainMenu.MenuButtonsToBeAdded) + { + GameObject newButton = Object.Instantiate(singleplayerButtonTransform.gameObject, menuItemsGroupTransform, false); + newButton.name = menuButtonToBeAdded.name; - tmp.SetText("Mods"); + // Move the button to be above the Exit button. + newButton.transform.SetSiblingIndex(newButton.transform.GetSiblingIndex() - 1); - } + // Rebind the button's action to call the action + UIAction_Void_Button uiAction = newButton.GetComponent(); + DelegateAction action = new(); + action.BindDelegate(() => menuButtonToBeAdded.onClicked.Invoke()); + uiAction.BindAction(action); - static void ModsOnClick() - { - bool found = ManagerLocator.TryGet(out SpaceWarpManager manager); + // Set the label to "Mods". + TextMeshProUGUI tmp = newButton.GetComponentInChildren(); - if (found) - { - manager.ModListUI.ToggleVisible(); + tmp.SetText(menuButtonToBeAdded.name); } } -} \ No newline at end of file +} diff --git a/SpaceWarp/Patching/StartGamePatch.cs b/SpaceWarp/Patching/StartGamePatch.cs deleted file mode 100644 index 346526a6..00000000 --- a/SpaceWarp/Patching/StartGamePatch.cs +++ /dev/null @@ -1,14 +0,0 @@ -using HarmonyLib; - - -namespace SpaceWarp.Patching; - -[HarmonyPatch(typeof(KSP.Game.GameManager))] -[HarmonyPatch("StartGame")] -public class StartGamePatch -{ - public static void Prefix() - { - StartupManager.OnGameStarted(); - } -} \ No newline at end of file diff --git a/SpaceWarp/PathHelpers.cs b/SpaceWarp/PathHelpers.cs new file mode 100644 index 00000000..b2483b60 --- /dev/null +++ b/SpaceWarp/PathHelpers.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; + +namespace SpaceWarp; + +internal static class PathHelpers +{ + /// + /// Creates a relative path from one file or folder to another. + /// + /// Contains the directory that defines the start of the relative path. + /// Contains the path that defines the endpoint of the relative path. + /// The relative path from the start directory to the end path. + /// or is null. + /// + /// + internal static string GetRelativePath(string fromPath, string toPath) + { + if (string.IsNullOrEmpty(fromPath)) + { + throw new ArgumentNullException(nameof(fromPath)); + } + + if (string.IsNullOrEmpty(toPath)) + { + throw new ArgumentNullException(nameof(toPath)); + } + + Uri fromUri = new Uri(AppendDirectorySeparatorChar(fromPath)); + Uri toUri = new Uri(AppendDirectorySeparatorChar(toPath)); + + if (fromUri.Scheme != toUri.Scheme) + { + return toPath; + } + + Uri relativeUri = fromUri.MakeRelativeUri(toUri); + string relativePath = Uri.UnescapeDataString(relativeUri.ToString()); + + if (string.Equals(toUri.Scheme, Uri.UriSchemeFile, StringComparison.OrdinalIgnoreCase)) + { + relativePath = relativePath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); + } + + return relativePath; + } + + private static string AppendDirectorySeparatorChar(string path) + { + // Append a slash only if the path is a directory and does not have a slash. + if (!Path.HasExtension(path) && !path.EndsWith(Path.DirectorySeparatorChar.ToString())) + { + return path + Path.DirectorySeparatorChar; + } + + return path; + } +} \ No newline at end of file diff --git a/SpaceWarp/SpaceWarp.csproj b/SpaceWarp/SpaceWarp.csproj index 88314d58..b4bb46a3 100644 --- a/SpaceWarp/SpaceWarp.csproj +++ b/SpaceWarp/SpaceWarp.csproj @@ -1,41 +1,69 @@  - 0.3.0 - latest + 0.4.0 + net472 + 11 true false - true - net472;netstandard2.0 + false + + CS0436 ..\external_dlls\Assembly-CSharp.dll true + false ..\external_dlls\Unity.TextMeshPro.dll + false ..\external_dlls\UnityEngine.UI.dll + false ..\external_dlls\Unity.Addressables.dll + false ..\external_dlls\Unity.ResourceManager.dll + false - - ..\external_dlls\UnityEngine.ImageConversionModule.dll + + ..\external_dlls\KSPLogging.dll + false + + ..\ThirdParty\ConfigurationManager\ConfigurationManager.dll + true + + + + + + + + + + + + - - - - - - - + + + + System.Index; + System.Range; + System.Diagnostics.CodeAnalysis.NotNullWhenAttribute; + System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute; + + diff --git a/SpaceWarp/SpaceWarpManager.cs b/SpaceWarp/SpaceWarpManager.cs new file mode 100644 index 00000000..532ffed2 --- /dev/null +++ b/SpaceWarp/SpaceWarpManager.cs @@ -0,0 +1,83 @@ +using System; +using System.IO; +using System.Collections.Generic; +using BepInEx; +using BepInEx.Bootstrap; +using BepInEx.Logging; +using Newtonsoft.Json; +using UnityEngine; +using SpaceWarp.API.Assets; +using SpaceWarp.API.Mods; +using SpaceWarp.API.Mods.JSON; +using SpaceWarp.API.UI.Appbar; +using SpaceWarp.Backend.UI.Appbar; +using SpaceWarp.UI; + +namespace SpaceWarp; + +/// +/// Handles all the SpaceWarp initialization and mod processing. +/// +internal static class SpaceWarpManager +{ + internal static ManualLogSource Logger; + internal static string SpaceWarpFolder; + internal static IReadOnlyList SpaceWarpPlugins; + internal static ConfigurationManager.ConfigurationManager ConfigurationManager; + internal static void GetSpaceWarpPlugins() + { + + // obsolete warning for Chainloader.Plugins, is fine since we need ordered list + // to break this we would likely need to upgrade to BIE 6, which isn't happening + #pragma warning disable CS0618 + var spaceWarpPlugins = Chainloader.Plugins.OfType().ToList(); + SpaceWarpPlugins = spaceWarpPlugins; + + #pragma warning restore CS0618 + foreach (var plugin in SpaceWarpPlugins.ToArray()) + { + var folderPath = Path.GetDirectoryName(plugin.Info.Location); + plugin.PluginFolderPath = folderPath; + if (Path.GetFileName(folderPath) == "plugins") + { + Logger.LogError($"Found Space Warp mod {plugin.Info.Metadata.Name} in the BepInEx/plugins directory. This mod will not be initialized."); + spaceWarpPlugins.Remove(plugin); + continue; + } + var modInfoPath = Path.Combine(folderPath!, "swinfo.json"); + if (!File.Exists(modInfoPath)) + { + Logger.LogError($"Found Space Warp plugin {plugin.Info.Metadata.Name} without a swinfo.json next to it. This mod will not be initialized."); + spaceWarpPlugins.Remove(plugin); + continue; + } + plugin.SpaceWarpMetadata = JsonConvert.DeserializeObject(File.ReadAllText(modInfoPath)); + } + } + + public static void Initialize(SpaceWarpPlugin spaceWarpPlugin) + { + Logger = spaceWarpPlugin.Logger; + + SpaceWarpFolder = Path.GetDirectoryName(spaceWarpPlugin.Info.Location); + + AppbarBackend.AppBarInFlightSubscriber.AddListener(Appbar.LoadAllButtons); + AppbarBackend.AppBarOABSubscriber.AddListener(Appbar.LoadOABButtons); + } + + public static ModListUI ModListUI { get; internal set; } + + private static GUISkin _skin; + + public static GUISkin Skin + { + get + { + if (!_skin) + { + AssetManager.TryGetAsset("spacewarp/swconsoleui/spacewarpconsole.guiskin", out _skin); + } + return _skin; + } + } +} \ No newline at end of file diff --git a/SpaceWarp/SpaceWarpPlugin.cs b/SpaceWarp/SpaceWarpPlugin.cs new file mode 100644 index 00000000..874b48d5 --- /dev/null +++ b/SpaceWarp/SpaceWarpPlugin.cs @@ -0,0 +1,98 @@ +global using UnityObject = UnityEngine.Object; +global using System.Linq; +using BepInEx; +using BepInEx.Bootstrap; +using BepInEx.Configuration; +using BepInEx.Logging; +using HarmonyLib; +using KSP.Messages; +using SpaceWarp.API.Game.Messages; +using SpaceWarp.API.Mods; +using SpaceWarp.UI; +using UnityEngine; + +namespace SpaceWarp; + +[BepInDependency(ConfigurationManager.ConfigurationManager.GUID,ConfigurationManager.ConfigurationManager.Version)] +[BepInPlugin(ModGuid, ModName, ModVer)] +public sealed class SpaceWarpPlugin : BaseSpaceWarpPlugin +{ + public const string ModGuid = "com.github.x606.spacewarp"; + public const string ModName = "Space Warp"; + public const string ModVer = MyPluginInfo.PLUGIN_VERSION; + + internal ConfigEntry configErrorColor; + internal ConfigEntry configWarningColor; + internal ConfigEntry configMessageColor; + internal ConfigEntry configInfoColor; + internal ConfigEntry configDebugColor; + internal ConfigEntry configAllColor; + internal ConfigEntry configShowConsoleButton; + internal ConfigEntry configShowTimeStamps; + internal ConfigEntry configTimeStampFormat; + internal ConfigEntry configDebugMessageLimit; + + internal new ManualLogSource Logger => base.Logger; + + public void Awake() + { + configErrorColor = Config.Bind("Debug Console", "Color Error", Color.red, + "The color for log messages that have the level: Error/Fatal (bolded)"); + configWarningColor = Config.Bind("Debug Console", "Color Warning", Color.yellow, + "The color for log messages that have the level: Warning"); + configMessageColor = Config.Bind("Debug Console", "Color Message", Color.white, + "The color for log messages that have the level: Message"); + configInfoColor = Config.Bind("Debug Console", "Color Info", Color.cyan, + "The color for log messages that have the level: Info"); + configDebugColor = Config.Bind("Debug Console", "Color Debug", Color.green, + "The color for log messages that have the level: Debug"); + configAllColor = Config.Bind("Debug Console", "Color All", Color.magenta, + "The color for log messages that have the level: All"); + configShowConsoleButton = Config.Bind("Debug Console", "Show Console Button", false, + "Show console button in app.bar, requires restart"); + configShowTimeStamps = Config.Bind("Debug Console", "Show Timestamps", true, + "Show time stamps in debug console"); + configTimeStampFormat = Config.Bind("Debug Console", "Timestamp Format", "HH:mm:ss.fff", + "The format for the timestamps in the debug console."); + configDebugMessageLimit = Config.Bind("Debug Console", "Message Limit", 1000, + "The maximum number of messages to keep in the debug console."); + + BepInEx.Logging.Logger.Listeners.Add(new SpaceWarpConsoleLogListener(this)); + + Harmony.CreateAndPatchAll(typeof(SpaceWarpPlugin).Assembly, ModGuid); + + SpaceWarpManager.Initialize(this); + } + + + public override void OnInitialized() + { + base.OnInitialized(); + + Game.Messages.Subscribe(typeof(GameStateEnteredMessage), StateChanges.OnGameStateEntered,false,true); + Game.Messages.Subscribe(typeof(GameStateLeftMessage), StateChanges.OnGameStateLeft,false,true); + Game.Messages.Subscribe(typeof(GameStateChangedMessage), StateChanges.OnGameStateChanged,false,true); + + InitializeUI(); + } + + private void InitializeUI() + { + SpaceWarpManager.ConfigurationManager = (ConfigurationManager.ConfigurationManager)Chainloader.PluginInfos[global::ConfigurationManager.ConfigurationManager.GUID].Instance; + GameObject modUIObject = new("Space Warp Mod UI"); + modUIObject.Persist(); + + modUIObject.transform.SetParent(transform); + SpaceWarpManager.ModListUI = modUIObject.AddComponent(); + + modUIObject.SetActive(true); + + GameObject consoleUIObject = new("Space Warp Console"); + consoleUIObject.Persist(); + consoleUIObject.transform.SetParent(Chainloader.ManagerObject.transform); + consoleUIObject.AddComponent(); + consoleUIObject.SetActive(true); + + API.UI.MainMenu.RegisterMenuButton("mods", SpaceWarpManager.ModListUI.ToggleVisible); + } +} \ No newline at end of file diff --git a/SpaceWarp/StartupManager.cs b/SpaceWarp/StartupManager.cs deleted file mode 100644 index d9bf68f4..00000000 --- a/SpaceWarp/StartupManager.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using UnityEngine; -using System.IO; -using SpaceWarp.API; - -namespace SpaceWarp; - -/// -/// Starts the SpaceWarm mod manager -/// -public static class StartupManager -{ - public static SpaceWarpManager SpaceWarpObject; - public static bool _hasInitialized = false; - - /// - /// This will be called once the KSP2 game is loaded. - /// - /// - public static void OnGameStarted() - { - // since OnGameStarted could be called multiple times, we want to make sure we only do anything on first call. - if (_hasInitialized) - { - return; - } - - CreateModDirectoryIfNotExists(); - CreateSpaceWarpManager(); - - Console.WriteLine("[Space Warp] Space Warp mod manager loaded!"); - _hasInitialized = true; - } - - /// - /// Creates the space warp manager object. - /// - private static void CreateSpaceWarpManager() - { - GameObject spaceWarp = new GameObject("Space Warp"); - SpaceWarpManager.Persist(spaceWarp); - SpaceWarpObject = spaceWarp.AddComponent(); - spaceWarp.SetActive(true); - // SpaceWarpObject.Initialize(); - } - - /// - /// Creates the mod folder if it doesn't exist. - /// - private static void CreateModDirectoryIfNotExists() - { - Directory.CreateDirectory(SpaceWarpManager.MODS_FULL_PATH); - } -} \ No newline at end of file diff --git a/SpaceWarp/UI/ModConfigurationSection.cs b/SpaceWarp/UI/ModConfigurationSection.cs deleted file mode 100644 index eff00147..00000000 --- a/SpaceWarp/UI/ModConfigurationSection.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -namespace SpaceWarp.UI; - -public class ModConfigurationSection -{ - public bool Open = false; - - public readonly List<(string name, FieldInfo info, object confAttribute, string currentStringValue)> Properties = new List<(string name, FieldInfo info, object confAttribute, string currentStringValue)>(); - public readonly List<(string path, ModConfigurationSection section)> SubSections = new List<(string path, ModConfigurationSection section)>(); - - private ModConfigurationSection TouchSubSection(string subsection) - { - (string path, ModConfigurationSection section) sub1 = SubSections.FirstOrDefault(sub => sub.path == subsection); - - if (sub1 != default) - { - return sub1.section; - } - - ModConfigurationSection sub2 = new ModConfigurationSection(); - SubSections.Add((subsection, sub2)); - return sub2; - - } - public void Insert(string[] path, (string name, FieldInfo info, object confAttribute, string currentStringValue) property) - { - StringBuilder sb = new StringBuilder(); - foreach (string t in path) - { - sb.Append(t + "/"); - } - if (path.Length > 0) - { - List subPath = new List(); - for (int i = 1; i < path.Length; i++) - { - subPath.Add(path[i]); - } - - ModConfigurationSection receivedSub = TouchSubSection(path[0]); - - receivedSub.Insert(subPath.ToArray(),property); - } - else - { - Properties.Add(property); - } - } -} \ No newline at end of file diff --git a/SpaceWarp/UI/ModConfigurationUI.cs b/SpaceWarp/UI/ModConfigurationUI.cs deleted file mode 100644 index e77de934..00000000 --- a/SpaceWarp/UI/ModConfigurationUI.cs +++ /dev/null @@ -1,216 +0,0 @@ -using System; -using System.ComponentModel; -using System.Reflection; -using KSP.Game; -using SpaceWarp.API; -using SpaceWarp.API.Configuration; -using SpaceWarp.API.Managers; -using UnityEngine; -using UnityEngine.Serialization; - -namespace SpaceWarp.UI; - -public class ModConfigurationUI : KerbalMonoBehaviour -{ - public Type ConfigurationType; - public object ConfigurationObject; - - [FormerlySerializedAs("ModID")] public string modID; - - private int _windowWidth = 350; - private int _windowHeight = 700; - private Rect _windowRect; - - private static GUIStyle _boxStyle; - - private ModConfigurationSection _rootSection; - private GUIStyle _spaceWarpUISkinToggled; - private bool hasGUIStyles = false; - - private void Awake() - { - _windowWidth = (int)(Screen.width * 0.5f); - _windowHeight = (int)(Screen.height * 0.5f); - } - - public void Start() - { - _rootSection = new ModConfigurationSection(); - foreach (FieldInfo field in ConfigurationType.GetFields(BindingFlags.Instance | BindingFlags.Public)) - { - object attribute; - string attributeName; - string section = ""; - - ConfigSectionAttribute sectionAttribute = field.GetCustomAttribute(); - - if (sectionAttribute != null) - { - section = sectionAttribute.Path; - } - - ConfigFieldAttribute fieldAttribute = field.GetCustomAttribute(); - - if (fieldAttribute == null) - { - // attribute = fieldAttribute; - // attributeName = fieldAttribute.Name; - // _rootSection.Insert(section.Split(new []{'/'},StringSplitOptions.RemoveEmptyEntries), (attributeName, field, attribute, field.GetValue(ConfigurationObject).ToString())); - continue; - } - attribute = fieldAttribute; - attributeName = fieldAttribute.Name; - - var value = field.GetValue(ConfigurationObject); - _rootSection.Insert(section.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries), - (attributeName, field, attribute, value != null ? value.ToString() : "")); - } - - _windowRect = new Rect((Screen.width * 0.15f), (Screen.height * 0.15f), 0, 0); - } - - private void GetGUIStyles() - { - _spaceWarpUISkinToggled = new GUIStyle(SpaceWarpManager.Skin.button); - var oldNormal = _spaceWarpUISkinToggled.normal; - var oldHover = _spaceWarpUISkinToggled.hover; - var oldActive = _spaceWarpUISkinToggled.active; - var oldFocused = _spaceWarpUISkinToggled.focused; - _spaceWarpUISkinToggled.normal = _spaceWarpUISkinToggled.onNormal; - _spaceWarpUISkinToggled.hover = _spaceWarpUISkinToggled.onHover; - _spaceWarpUISkinToggled.active = _spaceWarpUISkinToggled.onActive; - _spaceWarpUISkinToggled.focused = _spaceWarpUISkinToggled.onFocused; - _spaceWarpUISkinToggled.onNormal = oldNormal; - _spaceWarpUISkinToggled.onHover = oldHover; - _spaceWarpUISkinToggled.onActive = oldActive; - _spaceWarpUISkinToggled.onFocused = oldFocused; - hasGUIStyles = true; - } - public void OnGUI() - { - GUI.skin = SpaceWarpManager.Skin; - if (!hasGUIStyles) - { - - } - int controlID = GUIUtility.GetControlID(FocusType.Passive); - string header = $"{modID} configuration"; - - GUILayoutOption width = GUILayout.Width((float)(_windowWidth * 0.5)); - GUILayoutOption height = GUILayout.Height((float)(_windowHeight * 0.5)); - - _windowRect = GUILayout.Window(controlID, _windowRect, FillWindow, header, width, height); - } - - private string EditorInputField(string fieldName, FieldInfo info, string current) - { - var result = ""; - GUILayout.BeginHorizontal(); - - if (info.FieldType != typeof(bool)) - { - GUILayout.Label(fieldName); - - string rawInputValue = GUILayout.TextField(current); - result = rawInputValue; - try - { - object convertedInputValue = TypeDescriptor.GetConverter(info.FieldType) - .ConvertFromInvariantString(rawInputValue); - info.SetValue(ConfigurationObject, convertedInputValue); - } - catch - { - // ignored - } - } - else - { - bool toggleValue = GUILayout.Toggle((bool)info.GetValue(ConfigurationObject), fieldName); - result = toggleValue.ToString(); - info.SetValue(ConfigurationObject, toggleValue); - } - - GUILayout.EndHorizontal(); - return result; - } - - private string EditorForField((string name, FieldInfo info, object confAttribute, string currentStringValue) field) - { - if (field.confAttribute is ConfigFieldAttribute) - { - return EditorInputField(field.name, field.info, field.currentStringValue); - } - else - { - return ""; - } - } - - private void SectionPropertyViewer(string sectionName, ModConfigurationSection section, string parent) - { - - - if (GUILayout.Button((section.Open ? "V " : "> ") + (parent == "" ? sectionName : parent + "/" + sectionName))) - { - section.Open = !section.Open; - } - - if (!section.Open) - { - return; - } - - - for (int i = 0; i < section.Properties.Count; i++) - { - var prop = section.Properties[i]; - var str = EditorForField(prop); - prop.currentStringValue = str; - section.Properties[i] = prop; - } - - foreach ((string path, ModConfigurationSection section) sub in section.SubSections) - { - SectionPropertyViewer(sub.path, sub.section, parent == "" ? sectionName : parent + "/" + sectionName); - } - } - - public ModConfigurationUI(Rect windowRect) - { - _windowRect = windowRect; - } - - private void FillWindow(int windowID) - { - _boxStyle = GUI.skin.GetStyle("Box"); - GUILayout.BeginVertical(); - - // These are the root properties - for (int i = 0; i < _rootSection.Properties.Count; i++) - { - var prop = _rootSection.Properties[i]; - var str = EditorForField(prop); - prop.currentStringValue = str; - _rootSection.Properties[i] = prop; - } - - foreach ((string path, ModConfigurationSection section) section in _rootSection.SubSections) - { - SectionPropertyViewer(section.path, section.section, ""); - } - - if (GUILayout.Button("Save and close")) - { - //Run saving code from the configuration manager - if (ManagerLocator.TryGet(out ConfigurationManager configurationManager)) - { - configurationManager.UpdateConfiguration(modID); - } - Destroy(this); - } - - GUILayout.EndVertical(); - GUI.DragWindow(new Rect(0, 0, 10000, 500)); - } -} \ No newline at end of file diff --git a/SpaceWarp/UI/ModListUI.cs b/SpaceWarp/UI/ModListUI.cs index c0d876ee..d2115d69 100644 --- a/SpaceWarp/UI/ModListUI.cs +++ b/SpaceWarp/UI/ModListUI.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using KSP.Game; -using SpaceWarp.API; -using SpaceWarp.API.AssetBundles; -using SpaceWarp.API.Configuration; -using SpaceWarp.API.Managers; +using KSP.Game; using SpaceWarp.API.Mods.JSON; using UnityEngine; @@ -14,21 +7,20 @@ namespace SpaceWarp.UI; public class ModListUI : KerbalMonoBehaviour { private static bool _loaded; + private bool _drawUI; private Rect _windowRect; + private ModInfo _selectedMetaData; private int _windowWidth = 350; private int _windowHeight = 700; private static GUIStyle _boxStyle; private static Vector2 _scrollPositionMods; - private string _selectedMod; - private ModInfo _selectedModInfo; - private GUISkin _spaceWarpUISkin; - - private List<(string, bool)> _toggles = new List<(string, bool)>(); - private List<(string, bool)> _initialToggles = new List<(string, bool)>(); - private readonly Dictionary _wasToggledDict = new Dictionary(); + private static Vector2 _scrollPositionInfo; + private static GUIStyle _closeButtonStyle; + + private const string ModListHeader = "ModListHeader"; public void Start() { @@ -46,242 +38,113 @@ private void Awake() _windowHeight = (int)(Screen.height * 0.85f); _windowRect = new Rect(Screen.width * 0.15f, Screen.height * 0.15f, 0, 0); - ResourceManager.TryGetAsset($"space_warp/swconsoleui/swconsoleUI/spacewarpConsole.guiskin", out _spaceWarpUISkin); } private void OnGUI() { - GUI.skin = _spaceWarpUISkin; + GUI.skin = SpaceWarpManager.Skin; if (!_drawUI) { return; } + _closeButtonStyle ??= new GUIStyle(GUI.skin.button) + { + fontSize = 8 + }; + int controlID = GUIUtility.GetControlID(FocusType.Passive); - const string header = "spacewarp.modlist"; GUILayoutOption width = GUILayout.Width((float)(_windowWidth * 0.8)); GUILayoutOption height = GUILayout.Height((float)(_windowHeight * 0.8)); - GUI.skin = _spaceWarpUISkin; + GUI.skin = SpaceWarpManager.Skin; - _windowRect = GUILayout.Window(controlID, _windowRect, FillWindow, header, width, height); + _windowRect = GUILayout.Window(controlID, _windowRect, FillWindow, ModListHeader, width, height); } - + private void Update() { if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.M)) { ToggleVisible(); } + + if (Input.GetKey(KeyCode.Escape) && _drawUI) + { + CloseWindow(); + GUIUtility.ExitGUI(); + } + } private void FillWindow(int windowID) { - if (_initialToggles.Count == 0) - { - _initialToggles = new List<(string, bool)>(_toggles); - } - _boxStyle = GUI.skin.GetStyle("Box"); - GUILayout.BeginHorizontal(); - GUILayout.BeginVertical(); - - _scrollPositionMods = GUILayout.BeginScrollView(_scrollPositionMods, false, true, - GUILayout.Height((float)(_windowHeight * 0.8)), GUILayout.Width(300)); - - GUILayout.BeginHorizontal(); - if (GUILayout.Button("Disable All")) - { - for (int i = 0; i < _toggles.Count; i++) - { - _toggles[i] = (_toggles[i].Item1, false); - } - } - - if (GUILayout.Button("Enable All")) + if (GUI.Button(new Rect(_windowRect.width - 18, 2, 16, 16), "x", _closeButtonStyle)) { - for (int i = 0; i < _toggles.Count; i++) - { - _toggles[i] = (_toggles[i].Item1, true); - } + _drawUI = false; + GUIUtility.ExitGUI(); } - GUILayout.EndHorizontal(); - + GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); - if (ManagerLocator.TryGet(out SpaceWarpManager managerRemove)) - { - if (GUILayout.Button("Revert Changes")) - { - // Replace _toggles list with backup copy - _toggles = new List<(string, bool)>(_initialToggles); + GUILayout.BeginVertical(); - // Delete all ignore files - foreach ((string modID, ModInfo modInfo) in managerRemove.LoadedMods) - { - if (File.Exists($"SpaceWarp/Mods/{modID}/.ignore")) - { - File.Delete($"SpaceWarp/Mods/{modID}/.ignore"); - } - } - } - } + _scrollPositionMods = GUILayout.BeginScrollView( + _scrollPositionMods, + false, + false, + GUILayout.Height((float)(_windowHeight * 0.8)), + GUILayout.Width(300) + ); - GUILayout.EndHorizontal(); - - int numChanges = 0; - for (int i = 0; i < _toggles.Count; i++) + foreach (var mod in SpaceWarpManager.SpaceWarpPlugins) { - if (_toggles[i].Item2 != _initialToggles[i].Item2) + if (GUILayout.Button(mod.SpaceWarpMetadata.Name)) { - numChanges++; + _selectedMetaData = mod.SpaceWarpMetadata; } } - - if (numChanges > 0) - { - GUILayout.Label($"{numChanges} changes detected, please restart"); - } - - if (ManagerLocator.TryGet(out SpaceWarpManager manager)) - { - foreach ((string modID, ModInfo modInfo) in manager.LoadedMods) - { - int toggleIndex = _toggles.FindIndex(t => t.Item1 == modID); - if (toggleIndex == -1) // Toggle not found, add a new one - { - _toggles.Add((modID, true)); - toggleIndex = _toggles.Count - 1; - } - - bool isToggled = _toggles[toggleIndex].Item2; // current state of the toggle - bool wasToggled = _wasToggledDict.ContainsKey(modID) && _wasToggledDict[modID]; // previous state of the toggle (defaults to false if not found) - - GUILayout.BeginHorizontal(); - _toggles[toggleIndex] = (modID, GUILayout.Toggle(isToggled, "")); - if (GUILayout.Button(modID)) - { - _selectedMod = modID; - _selectedModInfo = modInfo; - } - GUILayout.EndHorizontal(); - - // Edge detection - if (!isToggled && wasToggled) // falling edge - { - File.Create($"SpaceWarp/Mods/{modID}/.ignore").Close(); - } - else if (isToggled && !wasToggled) // rising edge - { - File.Delete($"SpaceWarp/Mods/{modID}/.ignore"); - } - - _wasToggledDict[modID] = isToggled; // update the previous state of the toggle - } - - - foreach ((string modID, ModInfo modInfo) in manager.IgnoredMods) - { - int toggleIndex = _toggles.FindIndex((t) => t.Item1 == modID); - if (toggleIndex == -1) // Toggle not found, add a new one - { - _toggles.Add((modID, false)); - toggleIndex = _toggles.Count - 1; - } - - bool isToggled = _toggles[toggleIndex].Item2; // current state of the toggle - bool wasToggled = !_wasToggledDict.ContainsKey(modID) || _wasToggledDict[modID]; - - GUILayout.BeginHorizontal(); - - // Add a space to vertically center the toggle button - GUILayoutOption[] alignMiddleOption = { GUILayout.Height(30)}; - - _toggles[toggleIndex] = (modID, GUILayout.Toggle(isToggled, "", alignMiddleOption)); - if (GUILayout.Button(modID)) - { - _selectedMod = modID; - _selectedModInfo = modInfo; - } - - GUILayout.EndHorizontal(); - // Edge detection - if (isToggled && !wasToggled) // falling edge - { - File.Delete($"SpaceWarp/Mods/{modID}/.ignore"); - } - else if (!isToggled && wasToggled) // rising edge - { - File.Create($"SpaceWarp/Mods/{modID}/.ignore").Close(); - } - - _wasToggledDict[modID] = isToggled; // update the previous state of the toggle - } - } - GUILayout.EndScrollView(); GUILayout.EndVertical(); - GUILayout.BeginVertical(); - - if (_selectedModInfo != null) - { - CreateModConfigurationUI(); + if (_selectedMetaData != null) + { + GUILayout.BeginVertical(); + _scrollPositionInfo = GUILayout.BeginScrollView(_scrollPositionInfo, false, false); + GUILayout.Label($"{_selectedMetaData.Name} (id: {_selectedMetaData.ModID})"); + GUILayout.Label($"Author: {_selectedMetaData.Author}"); + GUILayout.Label($"Version: {_selectedMetaData.Version}"); + GUILayout.Label($"Source: {_selectedMetaData.Source}"); + GUILayout.Label($"Description: {_selectedMetaData.Description}"); + GUILayout.Label($"KSP2 Version: {_selectedMetaData.SupportedKsp2Versions.Min} - {_selectedMetaData.SupportedKsp2Versions.Max}"); + GUILayout.Label($"Dependencies"); + + foreach (DependencyInfo dependency in _selectedMetaData.Dependencies) + { + GUILayout.Label($"{dependency.ID}: {dependency.Version.Min} - {dependency.Version.Max}"); + } + GUILayout.EndScrollView(); + GUILayout.EndVertical(); } - else + + GUILayout.EndHorizontal(); + if (GUILayout.Button("Open Configuration Manager")) { - GUILayout.Label("No mod selected"); + SpaceWarpManager.ConfigurationManager.DisplayingWindow = + !SpaceWarpManager.ConfigurationManager.DisplayingWindow; + _drawUI = false; } - GUILayout.EndVertical(); - GUILayout.EndHorizontal(); - GUI.DragWindow(); } - private void CreateModConfigurationUI() - { - GUILayout.Label(_selectedModInfo.name); - GUILayout.Label($"Author: {_selectedModInfo.author}"); - GUILayout.Label($"Version: {_selectedModInfo.version}"); - GUILayout.Label($"Source: {_selectedModInfo.source}"); - GUILayout.Label($"Description: {_selectedModInfo.description}"); - GUILayout.Label($"KSP2 Version: {_selectedModInfo.supported_ksp2_versions.min} - {_selectedModInfo.supported_ksp2_versions.max}"); - GUILayout.Label($"Dependencies"); - - foreach (DependencyInfo dependency in _selectedModInfo.dependencies) - { - GUILayout.Label($"{dependency.id}: {dependency.version.min} - {dependency.version.max}"); - } - - if (!ManagerLocator.TryGet(out ConfigurationManager configManager)) - { - return; - } - - if (!configManager.TryGet(_selectedModInfo.mod_id, out (Type configType, object configObject, string path) config)) - { - return; - } - - if (!GUILayout.Button("Configure")) - { - return; - } - - GameObject go = new GameObject(_selectedModInfo.mod_id); - go.transform.SetParent(transform); - - ModConfigurationUI configUI = go.AddComponent(); - - configUI.ConfigurationType = config.configType; - configUI.ConfigurationObject = config.configObject; - configUI.modID = _selectedMod; - - - go.SetActive(true); - } - public void ToggleVisible() { _drawUI = !_drawUI; } + + public void CloseWindow() + { + ToggleVisible(); + } + } \ No newline at end of file diff --git a/SpaceWarp/UI/SpaceWarpConsole.cs b/SpaceWarp/UI/SpaceWarpConsole.cs index 2b00a83a..8e5c4bfc 100644 --- a/SpaceWarp/UI/SpaceWarpConsole.cs +++ b/SpaceWarp/UI/SpaceWarpConsole.cs @@ -1,108 +1,135 @@ -using System.Collections.Generic; -using KSP.Sim.impl; +using BepInEx.Bootstrap; +using BepInEx.Logging; +using KSP.Game; +using KSP.UI.Binding; +using SpaceWarp.API.Assets; +using SpaceWarp.API.UI.Appbar; using UnityEngine; -using SpaceWarp.API; namespace SpaceWarp.UI; -public class SpaceWarpConsole : KerbalBehavior +public sealed class SpaceWarpConsole : KerbalMonoBehaviour { - private static bool _loaded; - private bool _drawUI; private Rect _windowRect; - bool _autoScroll = true; + private string _search = ""; + private bool _autoScroll = true; + + private const ControlTypes ConsoleLocks = ControlTypes.All; + private const string ConsoleLockID = "spacewarp.console"; private int _windowWidth = 350; private int _windowHeight = 700; - private static GUIStyle _boxStyle; private static Vector2 _scrollPosition; private static Vector2 _scrollView; - private readonly Queue _debugMessages = new(); + private GUIStyle _closeButtonStyle; + private SpaceWarpPlugin _spaceWarpPluginInstance; - public new void Start() - { - if (_loaded) - { - Destroy(this); - } - - _loaded = true; - } - private new void Awake() + private void Awake() { - _windowWidth = (int)(Screen.width * 0.5f); _windowHeight = (int)(Screen.height * 0.5f); - - _windowRect = new Rect((Screen.width * 0.15f), (Screen.height * 0.15f), 0, 0); + _windowRect = new Rect(Screen.width * 0.15f, Screen.height * 0.15f, 0, 0); _scrollPosition = Vector2.zero; - + _spaceWarpPluginInstance = (Chainloader.PluginInfos[SpaceWarpPlugin.ModGuid].Instance as SpaceWarpPlugin)!; + + if (_spaceWarpPluginInstance.configShowConsoleButton.Value) + Appbar.RegisterAppButton( + "Console", + "BTN-SWConsole", + // Example of using the asset loader, were going to load the apps icon + // Path format [mod_id]/images/filename + // for bundles its [mod_id]/[bundle_name]/[path to file in bundle with out assets/bundle]/filename.extension + // There is also a try get asset function, that returns a bool on whether or not it could grab the asset + AssetManager.GetAsset("spacewarp/images/console.png"), + ToggleVisible + ); } private void OnGUI() { GUI.skin = SpaceWarpManager.Skin; + if (!_drawUI) { return; } + _closeButtonStyle ??= new GUIStyle(GUI.skin.button) + { + fontSize = 8 + }; + int controlID = GUIUtility.GetControlID(FocusType.Passive); - string header = $"spacewarp.console"; GUILayoutOption width = GUILayout.Width((float)(_windowWidth * 0.8)); GUILayoutOption height = GUILayout.Height((float)(_windowHeight * 0.8)); - - _windowRect = GUILayout.Window(controlID, _windowRect, DrawConsole, header, width, height); + + _windowRect = GUILayout.Window(controlID, _windowRect, DrawConsole, ConsoleLockID, width, height); } - + private void Update() { if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.C)) { - _drawUI = !_drawUI; + ToggleVisible(!_drawUI); + } + + if (Input.GetKey(KeyCode.Escape) && _drawUI) + { + CloseWindow(); + GUIUtility.ExitGUI(); } } private void DrawConsole(int windowID) { - _boxStyle = GUI.skin.GetStyle("Box"); + if (GUI.Button(new Rect(_windowRect.width - 18, 2, 16, 16), "x", _closeButtonStyle)) + { + CloseWindow(); + GUIUtility.ExitGUI(); + } + GUILayout.BeginVertical(); + _search = GUILayout.TextField(_search); _scrollView = GUILayout.BeginScrollView(_scrollPosition, false, true); - + foreach (string message in SpaceWarpConsoleLogListener.DebugMessages) { - string new_message = "" + message + "\n"; - GUILayout.Label( new_message); - if(_autoScroll) - { - _scrollView.Set(_scrollView.x, Mathf.Infinity ); - _scrollPosition = _scrollView; - } - else - { - _scrollPosition = _scrollView; - } + if (!message.ToLower().Contains(_search.ToLower())) continue; + + // Parse the log level from the message string + LogLevel logType = GetLogLevelFromMessage(message); + + // Apply a different color style based on the log level + GUIStyle style = GetLogStyle(logType); + + if (logType == LogLevel.Fatal) style.fontStyle = FontStyle.Bold; + + GUILayout.Label(message, style); } - - GUILayout.EndScrollView(); - GUILayout.BeginHorizontal(); - if (GUILayout.Button("Close")) + if (_autoScroll) { - _drawUI = false; - GUIUtility.ExitGUI(); + _scrollView.Set(_scrollView.x, Mathf.Infinity); + _scrollPosition = _scrollView; + } + else + { + _scrollPosition = _scrollView; } + GUILayout.EndScrollView(); + GUILayout.BeginHorizontal(); + if (GUILayout.Button("Clear")) { SpaceWarpConsoleLogListener.DebugMessages.Clear(); } - if (GUILayout.Button( _autoScroll ? "Auto Scroll: On" : "Auto Scroll: Off" )) + if (GUILayout.Button(_autoScroll ? "Auto Scroll: On" : "Auto Scroll: Off")) { //Todo: Add proper close button to top corner and add input lock button back. // GameManager.Instance.Game.ViewController.inputLockManager.ClearControlLocks(); @@ -113,4 +140,53 @@ private void DrawConsole(int windowID) GUILayout.EndVertical(); GUI.DragWindow(new Rect(0, 0, 10000, 500)); } + + private LogLevel GetLogLevelFromMessage(string message) + { + var logParts = message.ToLower().Replace(" ", "").Split(']'); + var logLevelIndex = _spaceWarpPluginInstance.configShowTimeStamps.Value ? 1 : 0; + + return logParts[logLevelIndex] switch + { + { } logMessage when logMessage.StartsWith("[fatal") => LogLevel.Fatal, + { } logMessage when logMessage.StartsWith("[error") => LogLevel.Error, + { } logMessage when logMessage.StartsWith("[warn") => LogLevel.Warning, + { } logMessage when logMessage.StartsWith("[message") => LogLevel.Message, + { } logMessage when logMessage.StartsWith("[info") => LogLevel.Info, + { } logMessage when logMessage.StartsWith("[debug") => LogLevel.Debug, + { } logMessage when logMessage.StartsWith("[all") => LogLevel.All, + _ => LogLevel.None + }; + } + + private GUIStyle GetLogStyle(LogLevel logLevel) + { + GUIStyle style = new GUIStyle(GUI.skin.label); + + style.normal.textColor = logLevel switch + { + LogLevel.Fatal => _spaceWarpPluginInstance.configErrorColor.Value, + LogLevel.Error => _spaceWarpPluginInstance.configErrorColor.Value, + LogLevel.Warning => _spaceWarpPluginInstance.configWarningColor.Value, + LogLevel.Message => _spaceWarpPluginInstance.configMessageColor.Value, + LogLevel.Info => _spaceWarpPluginInstance.configInfoColor.Value, + LogLevel.Debug => _spaceWarpPluginInstance.configDebugColor.Value, + LogLevel.All => _spaceWarpPluginInstance.configAllColor.Value, + _ => style.normal.textColor + }; + + return style; + } + + public void ToggleVisible(bool shouldDraw) + { + _drawUI = shouldDraw; + Game.ViewController.inputLockManager.SetControlLock(_drawUI ? ConsoleLocks : ControlTypes.None, ConsoleLockID); + } + + public void CloseWindow() + { + ToggleVisible(false); + GameObject.Find("BTN-SWConsole")?.GetComponent()?.SetValue(false); + } } \ No newline at end of file diff --git a/SpaceWarp/UI/SpaceWarpConsoleLogListener.cs b/SpaceWarp/UI/SpaceWarpConsoleLogListener.cs index 5c183881..44cbfbb3 100644 --- a/SpaceWarp/UI/SpaceWarpConsoleLogListener.cs +++ b/SpaceWarp/UI/SpaceWarpConsoleLogListener.cs @@ -1,67 +1,51 @@ -using SpaceWarp.API; using System; using System.Collections.Generic; -using UnityEngine; -using HarmonyLogger = HarmonyLib.Tools.Logger; +using BepInEx.Logging; + namespace SpaceWarp.UI; -public class SpaceWarpConsoleLogListener +public sealed class SpaceWarpConsoleLogListener : ILogListener { - internal static readonly List DebugMessages = new List(); - internal static SpaceWarpGlobalConfiguration config = SpaceWarpGlobalConfiguration.Instance; + private readonly SpaceWarpPlugin _spaceWarpPluginInstance; + + internal static readonly List DebugMessages = new(); - public static void LogCallback(string condition, string stackTrace, LogType type) + public SpaceWarpConsoleLogListener(SpaceWarpPlugin spaceWarpPluginInstance) { - switch (type) - { - case LogType.Error: - if (config.LogLevel >= (int)LogType.Error) - DebugMessages.Add($"[ERR] {condition}"); - break; - case LogType.Assert: - if (config.LogLevel >= (int)LogType.Assert) - DebugMessages.Add($"[AST] {condition}"); - break; - case LogType.Warning: - if (config.LogLevel >= (int)LogType.Warning) - DebugMessages.Add($"[WRN] {condition}"); - break; - case LogType.Log: - if (config.LogLevel >= (int)LogType.Log) - DebugMessages.Add($"[LOG] {condition}"); - break; - case LogType.Exception: - if (config.LogLevel >= (int)LogType.Exception) - DebugMessages.Add($"[EXC] {condition}"); - break; - default: - throw new ArgumentOutOfRangeException(nameof(type), type, null); - } + _spaceWarpPluginInstance = spaceWarpPluginInstance; } - public static void HarmonyLogCallback(object sender, HarmonyLogger.LogEventArgs e) + public void LogEvent(object sender, LogEventArgs eventArgs) { - switch (e.LogChannel) + DebugMessages.Add(BuildMessage(TimestampMessage(), eventArgs.Level, eventArgs.Data, eventArgs.Source)); + LogMessageJanitor(); + } + + private void LogMessageJanitor() + { + var configDebugMessageLimit = _spaceWarpPluginInstance.configDebugMessageLimit.Value; + if (DebugMessages.Count > configDebugMessageLimit) { - case HarmonyLogger.LogChannel.Info: - if (config.HarmonyLogLevel >= (int)LogType.Log) - DebugMessages.Add($"[HINF] {e.Message}"); - break; - case HarmonyLogger.LogChannel.Warn: - if (config.HarmonyLogLevel >= (int)LogType.Warning) - DebugMessages.Add($"[HWRN] {e.Message}"); - break; - case HarmonyLogger.LogChannel.Error: - if (config.HarmonyLogLevel >= (int)LogType.Error) - DebugMessages.Add($"[HERR] {e.Message}"); - break; - case HarmonyLogger.LogChannel.IL: - if (config.HarmonyLogLevel >= (int)LogType.Exception) - DebugMessages.Add($"[HIL] {e.Message}"); - break; - default: - DebugMessages.Add($"[HARM] {e.Message}"); - break; + DebugMessages.RemoveRange(0, DebugMessages.Count - configDebugMessageLimit); } } + + private string TimestampMessage() + { + return _spaceWarpPluginInstance.configShowTimeStamps.Value + ? "[" + DateTime.Now.ToString(_spaceWarpPluginInstance.configTimeStampFormat.Value) + "] " + : ""; + } + + private static string BuildMessage(string timestamp, LogLevel level, object data, ILogSource source) + { + return level == LogLevel.None + ? $"{timestamp}[{source.SourceName}] {data}" + : $"{timestamp}[{level} : {source.SourceName}] {data}"; + } + + public void Dispose() + { + DebugMessages.Clear(); + } } \ No newline at end of file diff --git a/Bundles/README.md b/SpaceWarpBuildTemplate/assets/bundles/README.md similarity index 100% rename from Bundles/README.md rename to SpaceWarpBuildTemplate/assets/bundles/README.md diff --git a/SpaceWarpBuildTemplate/assets/bundles/swconsoleui.bundle b/SpaceWarpBuildTemplate/assets/bundles/swconsoleui.bundle new file mode 100644 index 00000000..a4417c36 Binary files /dev/null and b/SpaceWarpBuildTemplate/assets/bundles/swconsoleui.bundle differ diff --git a/SpaceWarpBuildTemplate/assets/images/console.png b/SpaceWarpBuildTemplate/assets/images/console.png new file mode 100644 index 00000000..c708e45d Binary files /dev/null and b/SpaceWarpBuildTemplate/assets/images/console.png differ diff --git a/SpaceWarpBuildTemplate/assets/images/oabTrayButton.png b/SpaceWarpBuildTemplate/assets/images/oabTrayButton.png new file mode 100644 index 00000000..ca651e77 Binary files /dev/null and b/SpaceWarpBuildTemplate/assets/images/oabTrayButton.png differ diff --git a/SpaceWarpBuildTemplate/swinfo.json b/SpaceWarpBuildTemplate/swinfo.json new file mode 100644 index 00000000..0744b84f --- /dev/null +++ b/SpaceWarpBuildTemplate/swinfo.json @@ -0,0 +1,13 @@ +{ + "mod_id": "SpaceWarp", + "name": "Space Warp", + "author": "Space-Warp Team", + "description": "Space-Warp is an API for KSP2 mod developers.", + "source": "https://github.com/SpaceWarpDev/SpaceWarp", + "version": "0.4.0", + "dependencies": [], + "ksp2_version": { + "min": "0", + "max": "*" + } +} diff --git a/TemplateGenV2.py b/TemplateGenV2.py deleted file mode 100644 index 606dad6c..00000000 --- a/TemplateGenV2.py +++ /dev/null @@ -1,703 +0,0 @@ -# A better template generator -# Includes support for generating .csproj for roslyn and/or compiled mods -# Then also generates example code for those mods -import shutil, json -import os -from xml.dom import minidom - -template_mod = """ -// Import the Space Warp mod API -using SpaceWarp.API.Mods; - -namespace %NAMESPACE%; - -// Define our mod class with the [MainMod] attribute -[MainMod] -public class %MODNAME%Mod : Mod { - // This is our second stage initialization function, all assets and dependencies should be loaded by now. - public override void OnInitialized() { - // The mod class contains an Info and Logger class - Logger.Info($"{Info.name} OnInitialized()"); - } -} -""" - -template_configuration = """ -using SpaceWarp.API.Configuration; -using Newtonsoft.Json; -namespace %NAMESPACE%; - -// Define our config class with the [ModConfig] attribute -[ModConfig] -[JsonObject(MemberSerialization.OptOut)] -public class %MODNAME%Config { - [ConfigField("funny number")] - [ConfigDefaultValue(69)] - public int funny_number; -} -""" - -template_gitignore = """ -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. -## -## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore - -# User-specific files -*.rsuser -*.suo -*.user -*.userosscache -*.sln.docstates - -# User-specific files (MonoDevelop/Xamarin Studio) -*.userprefs - -# Mono auto generated files -mono_crash.* - -# Build results -[Dd]ebug/ -[Dd]ebugPublic/ -[Rr]elease/ -[Rr]eleases/ -x64/ -x86/ -[Aa][Rr][Mm]/ -[Aa][Rr][Mm]64/ -bld/ -[Bb]in/ -[Oo]bj/ -[Ll]og/ -[Ll]ogs/ - -# Visual Studio 2015/2017 cache/options directory -.vs/ -.idea/ -# Uncomment if you have tasks that create the project's static files in wwwroot -#wwwroot/ - -# Visual Studio 2017 auto generated files -Generated\ Files/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -# NUnit -*.VisualState.xml -TestResult.xml -nunit-*.xml - -# Build Results of an ATL Project -[Dd]ebugPS/ -[Rr]eleasePS/ -dlldata.c - -# Benchmark Results -BenchmarkDotNet.Artifacts/ - -# .NET Core -project.lock.json -project.fragment.lock.json -artifacts/ - -# StyleCop -StyleCopReport.xml - -# Files built by Visual Studio -*_i.c -*_p.c -*_h.h -*.ilk -*.meta -*.obj -*.iobj -*.pch -*.pdb -*.ipdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*_wpftmp.csproj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.svclog -*.scc - -# Chutzpah Test files -_Chutzpah* - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opendb -*.opensdf -*.sdf -*.cachefile -*.VC.db -*.VC.VC.opendb - -# Visual Studio profiler -*.psess -*.vsp -*.vspx -*.sap - -# Visual Studio Trace Files -*.e2e - -# TFS 2012 Local Workspace -$tf/ - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper -*.DotSettings.user - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# AxoCover is a Code Coverage Tool -.axoCover/* -!.axoCover/settings.json - -# Visual Studio code coverage results -*.coverage -*.coveragexml - -# NCrunch -_NCrunch_* -.*crunch*.local.xml -nCrunchTemp_* - -# MightyMoose -*.mm.* -AutoTest.Net/ - -# Web workbench (sass) -.sass-cache/ - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.[Pp]ublish.xml -*.azurePubxml -# Note: Comment the next line if you want to checkin your web deploy settings, -# but database connection strings (with potential passwords) will be unencrypted -*.pubxml -*.publishproj - -# Microsoft Azure Web App publish settings. Comment the next line if you want to -# checkin your Azure Web App publish settings, but sensitive information contained -# in these scripts will be unencrypted -PublishScripts/ - -# NuGet Packages -*.nupkg -# NuGet Symbol Packages -*.snupkg -# The packages folder can be ignored because of Package Restore -**/[Pp]ackages/* -# except build/, which is used as an MSBuild target. -!**/[Pp]ackages/build/ -# Uncomment if necessary however generally it will be regenerated when needed -#!**/[Pp]ackages/repositories.config -# NuGet v3's project.json files produces more ignorable files -*.nuget.props -*.nuget.targets - -# Microsoft Azure Build Output -csx/ -*.build.csdef - -# Microsoft Azure Emulator -ecf/ -rcf/ - -# Windows Store app package directories and files -AppPackages/ -BundleArtifacts/ -Package.StoreAssociation.xml -_pkginfo.txt -*.appx -*.appxbundle -*.appxupload - -# Visual Studio cache files -# files ending in .cache can be ignored -*.[Cc]ache -# but keep track of directories ending in .cache -!?*.[Cc]ache/ - -# Others -ClientBin/ -~$* -*~ -*.dbmdl -*.dbproj.schemaview -*.jfm -*.pfx -*.publishsettings -orleans.codegen.cs - -# Including strong name files can present a security risk -# (https://github.com/github/gitignore/pull/2483#issue-259490424) -#*.snk - -# Since there are multiple workflows, uncomment next line to ignore bower_components -# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) -#bower_components/ - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file -# to a newer Visual Studio version. Backup files are not needed, -# because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm -ServiceFabricBackup/ -*.rptproj.bak - -# SQL Server files -*.mdf -*.ldf -*.ndf - -# Business Intelligence projects -*.rdl.data -*.bim.layout -*.bim_*.settings -*.rptproj.rsuser -*- [Bb]ackup.rdl -*- [Bb]ackup ([0-9]).rdl -*- [Bb]ackup ([0-9][0-9]).rdl - -# Microsoft Fakes -FakesAssemblies/ - -# GhostDoc plugin setting file -*.GhostDoc.xml - -# Node.js Tools for Visual Studio -.ntvs_analysis.dat -node_modules/ - -# Visual Studio 6 build log -*.plg - -# Visual Studio 6 workspace options file -*.opt - -# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) -*.vbw - -# Visual Studio LightSwitch build output -**/*.HTMLClient/GeneratedArtifacts -**/*.DesktopClient/GeneratedArtifacts -**/*.DesktopClient/ModelManifest.xml -**/*.Server/GeneratedArtifacts -**/*.Server/ModelManifest.xml -_Pvt_Extensions - -# Paket dependency manager -.paket/paket.exe -paket-files/ - -# FAKE - F# Make -.fake/ - -# CodeRush personal settings -.cr/personal - -# Python Tools for Visual Studio (PTVS) -__pycache__/ -*.pyc - -# Cake - Uncomment if you are using it -# tools/** -# !tools/packages.config - -# Tabs Studio -*.tss - -# Telerik's JustMock configuration file -*.jmconfig - -# BizTalk build output -*.btp.cs -*.btm.cs -*.odx.cs -*.xsd.cs - -# OpenCover UI analysis results -OpenCover/ - -# Azure Stream Analytics local run output -ASALocalRun/ - -# MSBuild Binary and Structured Log -*.binlog - -# NVidia Nsight GPU debugger configuration file -*.nvuser - -# MFractors (Xamarin productivity tool) working folder -.mfractor/ - -# Local History for Visual Studio -.localhistory/ - -# BeatPulse healthcheck temp database -healthchecksdb - -# Backup folder for Package Reference Convert tool in Visual Studio 2017 -MigrationBackup/ - -# Ionide (cross platform F# VS Code tools) working folder -.ionide/ - -# Build script folder -build/ - -# Idea folder -.idea -""" - -template_external_gitignore = """ -* -!.gitignore -""" - -def find_ksp2_install_path(): - # Checks if Operating System is NOT Windows - if os.path != "nt": - steam_install_folder = "" - return steam_install_folder - else: - # Look for the game in Steam library folders - steam_path = os.path.join(os.getenv("ProgramFiles(x86)"), "Steam") - steam_library_folders_file = os.path.join( - steam_path, "steamapps", "libraryfolders.vdf" - ) - steam_install_folder = os.path.join( - steam_path, "steamapps", "common", "Kerbal Space Program 2" - ) - - if os.path.exists(steam_library_folders_file): - with open(steam_library_folders_file) as f: - for line in f: - if "BaseInstallFolder" in line: - steam_library_path = line.strip().split('"')[3] - if os.path.exists( - os.path.join( - steam_library_path, - "steamapps", - "appmanifest_1406800.acf", - ) - ): - steam_install_folder = os.path.join( - steam_library_path, - "steamapps", - "common", - "Kerbal Space Program 2", - ) - break - - # Look for the game in default installation path - if not os.path.exists(steam_install_folder): - default_install_folder = os.path.join( - os.getenv("ProgramFiles"), "Private Division", "Kerbal Space Program 2" - ) - if os.path.exists(default_install_folder): - steam_install_folder = default_install_folder - -mode = 0 # 0 = roslyn, 1 = compiled, 2 = both (roslyn template), 3 = both (compiled template) - -mod_id = "" -mod_name = "" -mod_author = "" - -print("Space Warp Mod Setup Wizard") -while True: - compilation_mode = input("Is this mod going to be (R)oslyn, (C)ompiled, or (B)oth: ") - if not compilation_mode: - print("Please input a mode") - else: - if compilation_mode.lower().startswith("r"): - mode = 0 - break - elif compilation_mode.lower().startswith("c"): - mode = 1 - break - elif compilation_mode.lower().startswith("b"): - while True: - template_mode = input("Do you want the template to be (R)oslyn or (C)ompiled: ") - if not template_mode: - print("Please input a template mode") - else: - if template_mode.lower().startswith("r"): - mode = 2 - break - elif template_mode.lower().startswith("c"): - mode = 3 - break - else: - print("Please input one of the available options") - break - print("Please input one of the available options") - - -while True: - mod_id = input("What is the ID of the mod (This should be in snake_case): ") - if not mod_id: - print("Mod ID cannot be empty, please try again.") - else: - break - - - -while True: - mod_author = input("Who is the author of the mod: ") - if not mod_author: - print("Mod author cannot be empty, please try again.") - else: - break - -while True: - mod_name = input("What is the name of the mod: ") - if not mod_name: - print("Mod name cannot be empty, please try again.") - else: - break - -mod_description = input("What is a short description of the mod: ") -mod_source = input("What is the source link of the mod: ") -mod_version = input("What is the starting version of the mod: ") -mod_ksp_min_version = input( - "What is the minimum version of KSP2 this mod will accept: " -) -mod_ksp_max_version = input( - "What is the maximum version of KSP2 this mod will accept: " -) - -steam_install_folder = find_ksp2_install_path() - -if os.path.exists(steam_install_folder): - print(f"Kerbal Space Program 2 is installed at {steam_install_folder}") -else: - steam_install_folder = input( - "Could not find the installation path for Kerbal Space Program 2.\nPlease enter the path to the KSP2 installation folder manually: " - ) - -managed_path = os.path.join(steam_install_folder, "KSP2_x64_Data", "Managed") -space_warp_path = "" -bepinex_path = "" -use_bepinex = False -if os.path.exists(os.path.join(steam_install_folder, "SpaceWarp", "core")): - space_warp_path = os.path.join(steam_install_folder, "SpaceWarp", "core") -elif os.path.exists(os.path.join(steam_install_folder,"BepInEx","SpaceWarp")): - space_warp_path = os.path.join(steam_install_folder, "BepInEx","SpaceWarp") - use_bepinex = True - bepinex_path = os.path.join(steam_install_folder,"BepInEx","core") -else: - print("Could not find a space warp installation, are you sure space warp is installed?") - -def touch(name): - open(name,"w").close() - -mod_id_title = mod_id.replace("_", " ").title().replace(" ", "") - -os.mkdir(mod_id) -os.mkdir(f"{mod_id}/external_dlls") -os.mkdir(f"{mod_id}/{mod_id}") -os.mkdir(f"{mod_id}/{mod_id}/assets") -os.mkdir(f"{mod_id}/{mod_id}/assets/bundles") -touch(f"{mod_id}/{mod_id}/assets/bundles/BUNDLES_HERE") -os.mkdir(f"{mod_id}/{mod_id}/bin") -touch(f"{mod_id}/{mod_id}/bin/BINARIES_HERE") -os.mkdir(f"{mod_id}/{mod_id}/config") -touch(f"{mod_id}/{mod_id}/config/CONFIGURATION_HERE") -os.mkdir(f"{mod_id}/{mod_id}/localization") -touch(f"{mod_id}/{mod_id}/localization/LOCALIZATION_HERE") -os.mkdir(f"{mod_id}/{mod_id}/addressables") -touch(f"{mod_id}/{mod_id}/localization/ADDRESSABLES_HERE") -if mode == 0 or mode >= 2: - os.mkdir(f"{mod_id}/{mod_id}/src") - os.mkdir(f"{mod_id}/{mod_id}/src/{mod_id_title}") -if mode == 1 or mode >= 2: - os.mkdir(f"{mod_id}/{mod_id_title}Project") - os.mkdir(f"{mod_id}/{mod_id_title}Project/{mod_id_title}") - - -external_dlls = f"{mod_id}/external_dlls" -release_folder = f"{mod_id}/{mod_id}" - -dll_list = [] - - -for filename in os.listdir(space_warp_path): - if (filename.endswith(".dll")): - shutil.copy2(os.path.join(space_warp_path, filename), external_dlls) - dll_list.append(filename) - -if use_bepinex: - for filename in os.listdir(bepinex_path): - if filename.endswith(".dll") and filename.lower().find("bepinex") == -1: - shutil.copy2(os.path.join(bepinex_path, filename), external_dlls) - dll_list.append(filename) - -for filename in os.listdir(managed_path): - if filename.endswith(".dll"): - shutil.copy2(os.path.join(managed_path, filename), external_dlls) - dll_list.append(filename) - -with open(f"{external_dlls}/.gitignore", "w") as external_gitignore: - external_gitignore.write(template_external_gitignore) - -with open(f"{mod_id}/.gitignore","w") as main_gitignore: - main_gitignore.write(template_gitignore) - -with open(f"{release_folder}/modinfo.json", "w") as modinfo: - modinfo.write( - json.dumps( - { - "mod_id": mod_id, - "author": mod_author, - "name": mod_name, - "description": mod_description, - "source": mod_source, - "version": mod_version, - "dependencies": [], - "ksp2_version": { - "min": mod_ksp_min_version, - "max": mod_ksp_max_version, - }, - }, - indent=4, - ) - ) - -with open(f"{mod_id}/README.md", "w") as readme: - readme.write("# Usage") - readme.write("Copy all space warp dlls and ksp dlls into external dlls") - readme.write( - "# Template Mod" - ) - - -with open(f"{release_folder}/README.json", "w") as readme: - readme.write("# Default Readme") -code_folder = "" -if mode == 1 or mode == 3: - code_folder = f"{mod_id}/{mod_id_title}Project/{mod_id_title}" -else: - code_folder = f"{mod_id}/{mod_id}/src" - -with open(f"{code_folder}/{mod_id_title}Mod.cs", "w") as default_code: - default_code.write( - template_mod.replace("%NAMESPACE%",mod_id_title).replace("%MODNAME%",mod_id_title) - ) - -with open(f"{code_folder}/{mod_id_title}Config.cs", "w") as default_code: - default_code.write( - template_configuration.replace("%NAMESPACE%",mod_id_title).replace("%MODNAME%",mod_id_title) - ) - -if mode == 0 or mode >= 2: - - with open(f"{mod_id}/{mod_id}/.gitignore","w") as main_gitignore: - main_gitignore.write(template_gitignore) - -if mode == 1 or mode >= 2: - with open(f"{mod_id}/{mod_id_title}Project/.gitignore","w") as main_gitignore: - main_gitignore.write(template_gitignore) - - - -def quick_create_property(root, name, text): - a = root.createElement(name) - b = root.createTextNode(text) - a.appendChild(b) - return a - - -def gen_csproj(csproj_name, dll_list, is_compiled=False): - root = minidom.Document() - xml = root.createElement("Project") - xml.setAttribute("Sdk", "Microsoft.NET.Sdk") - root.appendChild(xml) - propertyGroup = root.createElement("PropertyGroup") - xml.appendChild(propertyGroup) - propertyGroup.appendChild( - quick_create_property(root, "TargetFramework", "net472") - ) - propertyGroup.appendChild(quick_create_property(root, "AllowUnsafeBlocks", "true")) - propertyGroup.appendChild(quick_create_property(root, "LangVersion", "latest")) - propertyGroup.appendChild(quick_create_property(root, "ImplicitUsings", "true")) - - itemGroup = root.createElement("ItemGroup") - xml.appendChild(itemGroup) - - refs = [ - os.path.join("..","external_dlls",f"{dll}") for dll in dll_list - ] - - for ref in refs: - element = root.createElement("Reference") - element.setAttribute("Include", ref) - itemGroup.appendChild(element) - - if is_compiled: - after_build_group = root.createElement("PropertyGroup") - xml.appendChild(after_build_group) - after_build_group.appendChild( - quick_create_property(root,"PostBuildEvent",""" -"$(ProjectDir)pdb2mdb\\pdb2mdb.exe" "$(TargetPath)" -copy /Y "$(TargetDir)$(ProjectName).dll" "../%MOD_ID%/bin/$(ProjectName).dll" -copy /Y "$(TargetDir)$(ProjectName).pdb" "../%MOD_ID%/bin/$(ProjectName).pdb" -copy /Y "$(TargetDir)$(ProjectName).dll.mdb" "../%MOD_ID%/bin/$(ProjectName).dll.mdb" -""".replace("%MOD_ID%",mod_id)) - ) - - xml_str = root.toprettyxml(indent=" ") - with open(csproj_name + ".csproj", "w") as csproj: - csproj.write(xml_str) - -if mode == 0 or mode >= 2: - gen_csproj(f"{mod_id}/{mod_id}/{mod_id_title}",dll_list,False) -if mode == 1 or mode >= 2: - gen_csproj(f"{mod_id}/{mod_id_title}Project/{mod_id_title}",dll_list,True) \ No newline at end of file diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/config/BepInEx.cfg b/ThirdParty/BepInEx 5.4.21/BepInEx/config/BepInEx.cfg new file mode 100644 index 00000000..186eff3c --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/config/BepInEx.cfg @@ -0,0 +1,151 @@ +[Caching] + +## Enable/disable assembly metadata cache +## Enabling this will speed up discovery of plugins and patchers by caching the metadata of all types BepInEx discovers. +# Setting type: Boolean +# Default value: true +EnableAssemblyCache = true + +[Chainloader] + +## If enabled, hides BepInEx Manager GameObject from Unity. +## This can fix loading issues in some games that attempt to prevent BepInEx from being loaded. +## Use this only if you know what this option means, as it can affect functionality of some older plugins. +## +# Setting type: Boolean +# Default value: false +HideManagerGameObject = true + +[Harmony.Logger] + +## Specifies which Harmony log channels to listen to. +## NOTE: IL channel dumps the whole patch methods, use only when needed! +# Setting type: LogChannel +# Default value: Warn, Error +# Acceptable values: None, Info, IL, Warn, Error, Debug, All +# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning) +LogChannels = Info, Warn, Error, Debug + +[Logging] + +## Enables showing unity log messages in the BepInEx logging system. +# Setting type: Boolean +# Default value: true +UnityLogListening = true + +## If enabled, writes Standard Output messages to Unity log +## NOTE: By default, Unity does so automatically. Only use this option if no console messages are visible in Unity log +## +# Setting type: Boolean +# Default value: false +LogConsoleToUnityLog = false + +[Logging.Console] + +## Enables showing a console for log output. +# Setting type: Boolean +# Default value: false +Enabled = false + +## If enabled, will prevent closing the console (either by deleting the close button or in other platform-specific way). +# Setting type: Boolean +# Default value: false +PreventClose = false + +## If true, console is set to the Shift-JIS encoding, otherwise UTF-8 encoding. +# Setting type: Boolean +# Default value: false +ShiftJisEncoding = false + +## Hints console manager on what handle to assign as StandardOut. Possible values: +## Auto - lets BepInEx decide how to redirect console output +## ConsoleOut - prefer redirecting to console output; if possible, closes original standard output +## StandardOut - prefer redirecting to standard output; if possible, closes console out +## +# Setting type: ConsoleOutRedirectType +# Default value: Auto +# Acceptable values: Auto, ConsoleOut, StandardOut +StandardOutType = Auto + +## Which log levels to show in the console output. +# Setting type: LogLevel +# Default value: Fatal, Error, Warning, Message, Info +# Acceptable values: None, Fatal, Error, Warning, Message, Info, Debug, All +# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning) +LogLevels = Fatal, Error, Warning, Message, Info + +[Logging.Disk] + +## Include unity log messages in log file output. +# Setting type: Boolean +# Default value: false +WriteUnityLog = false + +## Appends to the log file instead of overwriting, on game startup. +# Setting type: Boolean +# Default value: false +AppendLog = false + +## Enables writing log messages to disk. +# Setting type: Boolean +# Default value: true +Enabled = true + +## Which log leves are saved to the disk log output. +# Setting type: LogLevel +# Default value: Fatal, Error, Warning, Message, Info +# Acceptable values: None, Fatal, Error, Warning, Message, Info, Debug, All +# Multiple values can be set at the same time by separating them with , (e.g. Debug, Warning) +LogLevels = Fatal, Error, Warning, Message, Info + +[Preloader] + +## Enables or disables runtime patches. +## This should always be true, unless you cannot start the game due to a Harmony related issue (such as running .NET Standard runtime) or you know what you're doing. +# Setting type: Boolean +# Default value: true +ApplyRuntimePatches = true + +## Specifies which MonoMod backend to use for Harmony patches. Auto uses the best available backend. +## This setting should only be used for development purposes (e.g. debugging in dnSpy). Other code might override this setting. +# Setting type: MonoModBackend +# Default value: auto +# Acceptable values: auto, dynamicmethod, methodbuilder, cecil +HarmonyBackend = auto + +## If enabled, BepInEx will save patched assemblies into BepInEx/DumpedAssemblies. +## This can be used by developers to inspect and debug preloader patchers. +# Setting type: Boolean +# Default value: false +DumpAssemblies = false + +## If enabled, BepInEx will load patched assemblies from BepInEx/DumpedAssemblies instead of memory. +## This can be used to be able to load patched assemblies into debuggers like dnSpy. +## If set to true, will override DumpAssemblies. +# Setting type: Boolean +# Default value: false +LoadDumpedAssemblies = false + +## If enabled, BepInEx will call Debugger.Break() once before loading patched assemblies. +## This can be used with debuggers like dnSpy to install breakpoints into patched assemblies before they are loaded. +# Setting type: Boolean +# Default value: false +BreakBeforeLoadAssemblies = false + +[Preloader.Entrypoint] + +## The local filename of the assembly to target. +# Setting type: String +# Default value: UnityEngine.CoreModule.dll +Assembly = UnityEngine.CoreModule.dll + +## The name of the type in the entrypoint assembly to search for the entrypoint method. +# Setting type: String +# Default value: Application +Type = Application + +## The name of the method in the specified entrypoint assembly and type to hook and load Chainloader from. +# Setting type: String +# Default value: .cctor +Method = .cctor + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.dll new file mode 100644 index 00000000..99daef72 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.xml new file mode 100644 index 00000000..70ec4135 --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony.xml @@ -0,0 +1,4288 @@ + + + + 0Harmony + + + + A factory to create delegate types + + + + Instance for the delegate type factory + + + Exists for API compatibility with Harmony + + + + + Creates a delegate type for a method + + Type of the return value + Types of the arguments + The new delegate type for the given type info + + + + Creates a delegate type for a method + + Type of the return value + Types of the arguments + Calling convention. If specified, adds to the delegate type + The new delegate type for the given type info + + + Creates a delegate type for a method + The method + The new delegate type + + + Creates a delegate type for a method + The method + Calling convention. If specified, adds to the delegate type. + The new delegate type + + + A getter delegate type + Type that getter gets field/property value from + Type of the value that getter gets + The instance get getter uses + An delegate + + + + A setter delegate type + Type that setter sets field/property value for + Type of the value that setter sets + The instance the setter uses + The value the setter uses + An delegate + + + + A constructor delegate type + Type that constructor creates + An delegate + + + + A helper class for fast access to getters and setters + + + Creates an instantiation delegate + Type that constructor creates + The new instantiation delegate + + + + Creates an getter delegate for a property + Type that getter reads property from + Type of the property that gets accessed + The property + The new getter delegate + + + + Creates an getter delegate for a field + Type that getter reads field from + Type of the field that gets accessed + The field + The new getter delegate + + + + Creates an getter delegate for a field (with a list of possible field names) + Type that getter reads field/property from + Type of the field/property that gets accessed + A list of possible field names + The new getter delegate + + + + Creates an setter delegate + Type that setter assigns property value to + Type of the property that gets assigned + The property + The new setter delegate + + + + Creates an setter delegate for a field + Type that setter assigns field value to + Type of the field that gets assigned + The field + The new getter delegate + + + + A delegate to invoke a method + The instance + The method parameters + The method result + + + A helper class to invoke method with delegates + + + Creates a fast invocation handler from a method + The method to invoke + Controls if boxed value object is accessed/updated directly + The + + + The directBoxValueAccess option controls how value types passed by reference (e.g. ref int, out my_struct) are handled in the arguments array + passed to the fast invocation handler. + Since the arguments array is an object array, any value types contained within it are actually references to a boxed value object. + Like any other object, there can be other references to such boxed value objects, other than the reference within the arguments array. + For example, + + var val = 5; + var box = (object)val; + var arr = new object[] { box }; + handler(arr); // for a method with parameter signature: ref/out/in int + + + + + If directBoxValueAccess is true, the boxed value object is accessed (and potentially updated) directly when the handler is called, + such that all references to the boxed object reflect the potentially updated value. + In the above example, if the method associated with the handler updates the passed (boxed) value to 10, both box and arr[0] + now reflect the value 10. Note that the original val is not updated, since boxing always copies the value into the new boxed value object. + + + If directBoxValueAccess is false (default), the boxed value object in the arguments array is replaced with a "reboxed" value object, + such that potential updates to the value are reflected only in the arguments array. + In the above example, if the method associated with the handler updates the passed (boxed) value to 10, only arr[0] now reflects the value 10. + + + + + Patch function helpers + + + Sorts patch methods by their priority rules + The original method + Patches to sort + Use debug mode + The sorted patch methods + + + + Sorts patch methods by their priority rules + The original method + Patches to sort + Use debug mode + The sorted patch methods + + + + Creates new replacement method with the latest patches and detours the original method + The original method + Information describing the patches + The newly created replacement method + + + + + High-level IL code manipulator for MonoMod that allows to manipulate a method as a stream of CodeInstructions. + + + + + Initialize IL transpiler + + Body of the method to transpile + Whether to always log everything for this instance + + + + Adds a transpiler method that edits the IL of the given method + + Transpiler method + Currently not implemented + + + + Processes and writes IL to the provided method body. + Note that this cleans the existing method body (removes insturctions and exception handlers). + + Method body to write to. + Original method that transpiler can optionally call into + + One of IL opcodes contains a CallSide (e.g. calli), which is currently not + fully supported. + + One of IL opcodes with an operand contains a null operand. + + + + Normalizes instructions into a consistent format for passing to transpilers. + Converts short branches to long, ensures that certain fields are properly initialized. + + Enumerable of instructions + Enumerable of normalized instructions + + + + Basic safe DLL emitter for dynamically generated s. + + Based on https://github.com/MonoMod/MonoMod.Common/blob/master/Utils/DMDGenerators/DMDCecilGenerator.cs + + + + Helper wrapper around ILProcessor to allow emitting code at certain positions + + + + + Write method body to a ILDasm -like representation + + Method body to write + String representation of the method body (locals and instruction) + Unexpected exception block type + + + + Patching methods potentially messes up the stack. + Especially calls to GetExecutingAssembly won't turn in correct methods + + + + Creates a patch sorter + Array of patches that will be sorted + Use debugging + + + Sorts internal PatchSortingWrapper collection and caches the results. + After first run the result is provided from the cache. + The original method + The sorted patch methods + + + Sorts internal PatchSortingWrapper collection and caches the results. + After first run the result is provided from the cache. + The original method + The sorted patch methods as instance + + + Checks if the sorter was created with the same patch list and as a result can be reused to + get the sorted order of the patches. + List of patches to check against + true if equal + + + Removes one unresolved dependency from the least important patch. + + + Outputs all unblocked patches from the waiting list to results list + + + Adds patch to both results list and handled patches set + Patch to add + + + Wrapper used over the Patch object to allow faster dependency access and + dependency removal in case of cyclic dependencies + + + Create patch wrapper object used for sorting + Patch to wrap + + + Determines how patches sort + The other patch + integer to define sort order (-1, 0, 1) + + + Determines whether patches are equal + The other patch + true if equal + + + Hash function + A hash code + + + Bidirectionally registers Patches as after dependencies + List of dependencies to register + + + Bidirectionally registers Patches as before dependencies + List of dependencies to register + + + Bidirectionally removes Patch from after dependencies + Patch to remove + + + Bidirectionally removes Patch from before dependencies + Patch to remove + + + Specifies the type of method + + + + This is a normal method + + + This is a getter + + + This is a setter + + + This is a constructor + + + This is a static constructor + + + This is an enumerator (, or UniTask coroutine) + This path will target the method that contains the actual enumerator code + + + Specifies the type of argument + + + + This is a normal argument + + + This is a reference argument (ref) + + + This is an out argument (out) + + + This is a pointer argument (&) + + + Specifies the type of patch + + + + Any patch + + + A prefix patch + + + A postfix patch + + + A transpiler + + + A finalizer + + + A reverse patch + + + A MonoMod + + + Specifies the type of reverse patch + + + + Use the unmodified original method (directly from IL) + + + Use the original as it is right now including previous patches but excluding future ones + + + Specifies the type of method call dispatching mechanics + + + + Call the method using dynamic dispatching if method is virtual (including overriden) + + + This is the built-in form of late binding (a.k.a. dynamic binding) and is the default dispatching mechanic in C#. + This directly corresponds with the instruction. + + + For virtual (including overriden) methods, the instance type's most-derived/overriden implementation of the method is called. + For non-virtual (including static) methods, same behavior as : the exact specified method implementation is called. + + + Note: This is not a fully dynamic dispatch, since non-virtual (including static) methods are still called non-virtually. + A fully dynamic dispatch in C# involves using + the dynamic type + (actually a fully dynamic binding, since even the name and overload resolution happens at runtime), which does not support. + + + + + Call the method using static dispatching, regardless of whether method is virtual (including overriden) or non-virtual (including static) + + + a.k.a. non-virtual dispatching, early binding, or static binding. + This directly corresponds with the instruction. + + + For both virtual (including overriden) and non-virtual (including static) methods, the exact specified method implementation is called, without virtual/override mechanics. + + + + + The base class for all Harmony annotations (not meant to be used directly) + + + + The common information for all attributes + + + Annotation to define targets of your Harmony patch methods + + + + An empty annotation can be used together with TargetMethod(s) + + + + An annotation that specifies a class to patch + The declaring class/type + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The argument types of the method or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + An array of argument types to target overloads + Array of + + + + An annotation that specifies a method, property or constructor to patch + Assembly-qualified name of the declaring class/type + The name of the method, property or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + Assembly-qualified name of the declaring class/type + The name of the method, property or constructor to patch + The + An array of argument types to target overloads + Array of + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + An array of argument types to target overloads + Array of + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + The + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + An array of argument types to target overloads + An array of + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + The + + + + An annotation that specifies a method, property or constructor to patch + The + + + + An annotation that specifies a method, property or constructor to patch + The + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The + An array of argument types to target overloads + An array of + + + + An annotation that specifies a method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + An array of argument types to target overloads + An array of + + + + Annotation to define the original method for delegate injection + + + + An annotation that specifies a class to patch + The declaring class/type + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The argument types of the method or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + An array of argument types to target overloads + Array of + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The + An array of argument types to target overloads + Array of + + + + An annotation that specifies a method, property or constructor to patch + The declaring class/type + The name of the method, property or constructor to patch + The + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + An array of argument types to target overloads + An array of + + + + An annotation that specifies a method, property or constructor to patch + The name of the method, property or constructor to patch + The + + + + An annotation that specifies call dispatching mechanics for the delegate + The + + + + An annotation that specifies a method, property or constructor to patch + The + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + The + An array of argument types to target overloads + An array of + + + + An annotation that specifies a method, property or constructor to patch + An array of argument types to target overloads + + + + An annotation that specifies a method, property or constructor to patch + An array of argument types to target overloads + An array of + + + + Annotation to define your standin methods for reverse patching + + + + An annotation that specifies the type of reverse patching + The of the reverse patch + + + + A Harmony annotation to define that all methods in a class are to be patched + + + + A Harmony annotation used to change order in which Harmony patches are applied + + + + A Harmony annotation to define patch priority + The priority + + + + A Harmony annotation to define that a patch comes before another patch + + + + A Harmony annotation to define that a patch comes before another patch + The array of harmony IDs of the other patches + + + + A Harmony annotation to define that a patch comes after another patch + + + A Harmony annotation to define that a patch comes after another patch + The array of harmony IDs of the other patches + + + + A Harmony annotation to output a debug log for a patch + + + A Harmony annotation to debug a patch (output uses to log to your Desktop) + + + + A Harmony annotation to emit IL of the patch to a DLL + + + + A Harmony annotation to emit IL of the patch to the current working directory + + + + A Harmony annotation to emit IL of the patch to the given path + Directory to which emit the patch + + + + A Harmony attribute to automatically wrap the patch into try/catch. Exceptions are logged to Harmony log and eaten. + + + + If specified on a prefix, postfix or a finalizer, the method will be automatically wrapped into try/catch. + + + + Specifies the Prepare function in a patch class + + + + Specifies the Cleanup function in a patch class + + + + Specifies the TargetMethod function in a patch class + + + + Specifies the TargetMethods function in a patch class + + + + Specifies the Prefix function in a patch class + + + + Specifies the Postfix function in a patch class + + + + Specifies the Transpiler function in a patch class + + + + Specifies the ILManipulator function in a patch class> + + + + Specifies the Finalizer function in a patch class + + + + A Harmony annotation to declare injected arguments + + + + The name of the original argument + + + + The index of the original argument + + + + The new name of the original argument + + + + An annotation to declare injected arguments by name + + + + An annotation to declare injected arguments by index + Zero-based index + + + + An annotation to declare injected arguments by renaming them + Name of the original argument + New name + + + + An annotation to declare injected arguments by index and renaming them + Zero-based index + New name + + + + An abstract wrapper around OpCode and their operands. Used by transpilers + + + + The opcode + + + + The operand + + + + All labels defined on this instruction + + + + All exception block boundaries defined on this instruction + + + + Creates a new CodeInstruction with a given opcode and optional operand + The opcode + The operand + + + + Create a full copy (including labels and exception blocks) of a CodeInstruction + The to copy + + + + Clones a CodeInstruction and resets its labels and exception blocks + A lightweight copy of this code instruction + + + + Clones a CodeInstruction, resets labels and exception blocks and sets its opcode + The opcode + A copy of this CodeInstruction with a new opcode + + + + Clones a CodeInstruction, resets labels and exception blocks and sets its operand + The operand + A copy of this CodeInstruction with a new operand + + + + Creates a CodeInstruction calling a method (CALL) + The class/type where the method is declared + The name of the method (case sensitive) + Optional parameters to target a specific overload of the method + Optional list of types that define the generic version of the method + A code instruction that calls the method matching the arguments + + + + Creates a CodeInstruction calling a method (CALL) + The target method in the form TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType like Some.Namespace.Type. + Optional parameters to target a specific overload of the method + Optional list of types that define the generic version of the method + A code instruction that calls the method matching the arguments + + + + Creates a CodeInstruction calling a method (CALL) + The lambda expression using the method + + + + + Creates a CodeInstruction calling a method (CALL) + The lambda expression using the method + + + + + Creates a CodeInstruction calling a method (CALL) + The lambda expression using the method + + + + + Creates a CodeInstruction calling a method (CALL) + The lambda expression using the method + + + + + Returns an instruction to call the specified closure + The delegate type to emit + The closure that defines the method to call + A that calls the closure as a method + + + + Creates a CodeInstruction loading a field (LD[S]FLD[A]) + The class/type where the field is defined + The name of the field (case sensitive) + Use address of field + + + + Creates a CodeInstruction storing to a field (ST[S]FLD) + The class/type where the field is defined + The name of the field (case sensitive) + + + + Returns a string representation of the code instruction + A string representation of the code instruction + + + + Exception block types + + + + The beginning of an exception block + + + + The beginning of a catch block + + + + The beginning of an except filter block + + + + The beginning of a fault block + + + + The beginning of a finally block + + + + The end of an exception block + + + + An exception block + + + + Block type + + + + Catch type + + + + Creates an exception block + The + The catch type + + + + + An exception thrown when a patch argument in a Harmony patch is invalid. + + + + + Original method to be patched. + + + + + Patch that was attempted to be applied. + + + + + + + + Constructs a new exception instance. + + Message of the exception. + Original method to be patched. + Patch that was attempted to be applied. + + + + An exception thrown when a reflection member is not found. + + + + + + + The Harmony instance is the main entry to Harmony. After creating one with an unique identifier, it is used to patch and query the current application domain + + + + Set to true before instantiating Harmony to debug Harmony or use an environment variable to set HARMONY_DEBUG to '1' like this: cmd /C "set HARMONY_DEBUG=1 && game.exe" + This is for full debugging. To debug only specific patches, use the attribute + + + + Creates a new Harmony instance + A unique identifier (you choose your own) + A Harmony instance + + + + The unique identifier + + + + Searches the current assembly for Harmony annotations and uses them to create patches + This method can fail to use the correct assembly when being inlined. It calls StackTrace.GetFrame(1) which can point to the wrong method/assembly. If you are unsure or run into problems, use PatchAll(Assembly.GetExecutingAssembly()) instead. + + + + Creates a empty patch processor for an original method + The original method/constructor + A new instance + + + + Creates a patch class processor from an annotated class + The class/type + A new instance + + + + Creates a patch class processor from an annotated class + The class/type + If true, the type doesn't need to have any attributes present for processing + A new instance + + + + Creates a reverse patcher for one of your stub methods + The original method/constructor + The stand-in stub method as + A new instance + + + + Searches an assembly for Harmony annotations and uses them to create patches + The assembly + + + + Searches the given type for Harmony annotation and uses them to create patches + The type to search + + + + Creates patches by manually specifying the methods + The original method/constructor + An optional prefix method wrapped in a object + An optional postfix method wrapped in a object + An optional transpiler method wrapped in a object + An optional finalizer method wrapped in a object + An optional ilmanipulator method wrapped in a + The replacement method that was created to patch the original method + + + + Creates patches by manually specifying the methods + The original method/constructor + An optional prefix method wrapped in a object + An optional postfix method wrapped in a object + An optional transpiler method wrapped in a object + An optional finalizer method wrapped in a object + The replacement method that was created to patch the original method + + + + Patches a foreign method onto a stub method of yours and optionally applies transpilers during the process + The original method/constructor you want to duplicate + Your stub method as that will become the original. Needs to have the correct signature (either original or whatever your transpilers generates) + An optional transpiler as method that will be applied during the process + An optional ilmanipulator as method that will be applied during the process + The replacement method that was created to patch the stub method + + + + Patches a foreign method onto a stub method of yours and optionally applies transpilers during the process + The original method/constructor you want to duplicate + Your stub method as that will become the original. Needs to have the correct signature (either original or whatever your transpilers generates) + An optional transpiler as method that will be applied during the process + The replacement method that was created to patch the stub method + + + + Unpatches all methods that were patched by the specified . Unpatching is done by repatching methods without patches of this instance. + The Harmony ID to restrict unpatching to a specific Harmony instance. + Gets thrown when a null or empty HarmonyID gets passed in. + + + + Unpatches all methods that were patched by this Harmony instance's ID. Unpatching is done by repatching methods without patches of this instance. + + + + Globally unpatches ALL methods by patching them with zero patches. Complete unpatching is not supported. + + + + Unpatches methods by patching them with zero patches. Fully unpatching is not supported. Be careful, unpatching is global + The Harmony ID to restrict unpatching to a specific Harmony instance. Whether this parameter is actually optional is determined by the global flag + When is set to true, the execution of this method will be skipped when no is specified. + + + + Unpatches a method by patching it with zero patches. Fully unpatching is not supported. Be careful, unpatching is global + The original method/constructor + The + The optional Harmony ID to restrict unpatching to a specific Harmony instance + + + + Unpatches a method by patching it with zero patches. Fully unpatching is not supported. Be careful, unpatching is global + The original method/constructor + The patch method as method to remove + + + + Test for patches from a specific Harmony ID + The Harmony ID + True if patches for this ID exist + + + + Gets patch information for a given original method + The original method/constructor + The patch information as + + + + Gets the methods this instance has patched + An enumeration of original methods/constructors + + + + Gets all patched original methods in the appdomain + An enumeration of patched original methods/constructors + + + + Gets the original method from a given replacement method + A replacement method, for example from a stacktrace + The original method/constructor or null if not found + + + + Tries to get the method from a stackframe including dynamic replacement methods + The + For normal frames, frame.GetMethod() is returned. For frames containing patched methods, the replacement method is returned or null if no method can be found + + + + Gets Harmony version for all active Harmony instances + [out] The current Harmony version + A dictionary containing assembly versions keyed by Harmony IDs + + + + Creates a new Harmony instance and applies all patches specified in the type + The type to scan for patches. + The ID for the Harmony instance to create, which will be used. + + + + Applies all patches specified in the assembly + The assembly to scan. + The ID for the Harmony instance to create, which will be used. + + + + Under Mono, HarmonyException wraps IL compile errors with detailed information about the failure + + + + Default serialization constructor (not implemented) + The info + The context + + + + Get a list of IL instructions in pairs of offset+code + A list of key/value pairs which represent an offset and the code at that offset + + + + Get a list of IL instructions without offsets + A list of + + + + Get the error offset of the errornous IL instruction + The offset + + + + Get the index of the errornous IL instruction + The index into the list of instructions or -1 if not found + + + + Class that holds all Global Harmony settings + + + + Set to true to disallow executing the legacy instance method without specifying a harmonyId. + If set to true and the legacy instance method is called without passing a harmonyId, then execution of said method will be skipped. + + + A wrapper around a method to use it as a patch (for example a Prefix) + + + + The original method + + + + Class/type declaring this patch + + + + Patch method name + + + + Optional patch + + + + Array of argument types of the patch method + + + + of the patch + + + + Install this patch before patches with these Harmony IDs + + + + Install this patch after patches with these Harmony IDs + + + + Reverse patch type, see + + + + Create debug output for this patch + + + + If not null, the IL of the patch is output to this path + + + + Whether to use (true) or (false) mechanics + for -attributed delegate + + + + Whether to wrap the patch itself into a try/catch. + + + + Default constructor + + + + Creates a patch from a given method + The original method + + + + Creates a patch from a given method + The original method + The patch + A list of harmony IDs that should come after this patch + A list of harmony IDs that should come before this patch + Set to true to generate debug output + + + + Creates a patch from a given method + The patch class/type + The patch method name + The optional argument types of the patch method (for overloaded methods) + + + + Gets the names of all internal patch info fields + A list of field names + + + + Merges annotations + The list of to merge + The merged + + + + Returns a string that represents the annotation + A string representation + + + + Annotation extensions + + + + Copies annotation information + The source + The destination + + + + Clones an annotation + The to clone + A copied + + + + Merges annotations + The master + The detail + A new, merged + + + + Gets all annotations on a class/type + The class/type + A list of all + + + + Gets merged annotations on a class/type + The class/type + The merged + + + + Gets all annotations on a method + The method/constructor + A list of + + + + Gets merged annotations on a method + The method/constructor + The merged + + + + + A mutable representation of an inline signature, similar to Mono.Cecil's CallSite. + Used by the calli instruction, can be used by transpilers + + + + + See + + + + See + + + + See + + + + The list of all parameter types or function pointer signatures received by the call site + + + + The return type or function pointer signature returned by the call site + + + + Returns a string representation of the inline signature + A string representation of the inline signature + + + + + A mutable representation of a parameter type with an attached type modifier, + similar to Mono.Cecil's OptionalModifierType / RequiredModifierType and C#'s modopt / modreq + + + + + Whether this is a modopt (optional modifier type) or a modreq (required modifier type) + + + + The modifier type attached to the parameter type + + + + The modified parameter type + + + + Returns a string representation of the modifier type + A string representation of the modifier type + + + + Patch serialization + + + + Control the binding of a serialized object to a type + Specifies the assembly name of the serialized object + Specifies the type name of the serialized object + The type of the object the formatter creates a new instance of + + + + Serializes a patch info + The + The serialized data + + + + Deserialize a patch info + The serialized data + A + + + + Compare function to sort patch priorities + The patch + Zero-based index + The priority + A standard sort integer (-1, 0, 1) + + + + Serializable patch information + + + + Prefixes as an array of + + + + Postfixes as an array of + + + + Transpilers as an array of + + + + Finalizers as an array of + + + + ILManipulators as an array of + + + + Returns if any of the patches wants debugging turned on + + + + Returns a list of paths that the IL should be dumped to + + + + Adds prefixes + An owner (Harmony ID) + The patch methods + + + + Adds a prefix + + + Removes prefixes + The owner of the prefixes, or * for all + + + + Adds postfixes + An owner (Harmony ID) + The patch methods + + + + Adds a postfix + + + Removes postfixes + The owner of the postfixes, or * for all + + + + Adds transpilers + An owner (Harmony ID) + The patch methods + + + + Adds a transpiler + + + Removes transpilers + The owner of the transpilers, or * for all + + + + Adds finalizers + An owner (Harmony ID) + The patch methods + + + + Adds a finalizer + + + Removes finalizers + The owner of the finalizers, or * for all + + + + Adds ilmanipulators + An owner (Harmony ID) + The patch methods + + + + Removes ilmanipulators + The owner of the ilmanipulators, or * for all + + + + Removes a patch using its method + The method of the patch to remove + + + + Gets a concatenated list of patches + The Harmony instance ID adding the new patches + The patches to add + The current patches + + + + Gets a list of patches with any from the given owner removed + The owner of the methods, or * for all + The current patches + + + + A serializable patch + + + + Zero-based index + + + + The owner (Harmony ID) + + + + The priority, see + + + + Keep this patch before the patches indicated in the list of Harmony IDs + + + + Keep this patch after the patches indicated in the list of Harmony IDs + + + + A flag that will log the replacement method via every time this patch is used to build the replacement, even in the future + + + + If not null, IL DLL is output to this directory + + + + Whether to wrap the patch into a general try/catch that logs the error + + + + The method of the static patch method + + + + Creates a patch + The method of the patch + Zero-based index + An owner (Harmony ID) + The priority, see + A list of Harmony IDs for patches that should run after this patch + A list of Harmony IDs for patches that should run before this patch + A flag that will log the replacement method via every time this patch is used to build the replacement, even in the future + + + + Creates a patch + The method of the patch + Zero-based index + An owner (Harmony ID) + The priority, see + A list of Harmony IDs for patches that should run after this patch + A list of Harmony IDs for patches that should run before this patch + A flag that will log the replacement method via every time this patch is used to build the replacement, even in the future + Whether to wrap the patch into a general try/catch that logs the error + + + + Creates a patch + The method of the patch + Zero-based index + An owner (Harmony ID) + The priority, see + A list of Harmony IDs for patches that should run after this patch + A list of Harmony IDs for patches that should run before this patch + A flag that will log the replacement method via every time this patch is used to build the replacement, even in the future + Whether to wrap the patch into a general try/catch that logs the error + If not null, the patch IL DLL is saved to this directory + + + + Creates a patch + The method of the patch + Zero-based index + An owner (Harmony ID) + + + Get the patch method or a DynamicMethod if original patch method is a patch factory + The original method/constructor + The method of the patch + + + + Determines whether patches are equal + The other patch + true if equal + + + + Determines how patches sort + The other patch + integer to define sort order (-1, 0, 1) + + + + Hash function + A hash code + + + + A PatchClassProcessor used to turn on a class/type into patches + + + + Creates a patch class processor by pointing out a class. Similar to PatchAll() but without searching through all classes. + The Harmony instance + The class to process (need to have at least a [HarmonyPatch] attribute if allowUnannotatedType is set to false) + + + + Creates a patch class processor by pointing out a class. Similar to PatchAll() but without searching through all classes. + The Harmony instance + The class to process (need to have at least a [HarmonyPatch] attribute if allowUnannotatedType is set to false) + If true, the type doesn't need to have any attributes present for processing + + + + Applies the patches + A list of all created replacement methods or null if patch class is not annotated + + + + A group of patches + + + + A collection of prefix + + + + A collection of postfix + + + + A collection of transpiler + + + + A collection of finalizer + + + + A collection of ILManipulator + + + + Gets all owners (Harmony IDs) or all known patches + The patch owners + + + + Creates a group of patches + An array of prefixes as + An array of postfixes as + An array of transpileres as + An array of finalizeres as + An array of ilmanipulators as + + + + Creates a group of patches + An array of prefixes as + An array of postfixes as + An array of transpileres as + An array of finalizeres as + + + + + IL manipulator to create Harmony-style patches. + + + + + Initializes a new instance of the class. + + Patches to apply to the body. + + + + Manipulates a by applying Harmony patches to it. + + + Reference to the method that should be considered as original. Used to reference parameter and + return types. + + Collection of Harmony patches to apply. + Method body to manipulate as instance. Should contain instructions to patch. + + In most cases you will want to use to create or obtain global + patch info for the method that contains aggregated info of all Harmony instances. + + + + + Manipulates IL into a replacement method with Harmony patches applied to it. + + Original method that contains and other metadata. + IL to rewrite. + + + + Convert the IL code into a Harmony patch. + + IL body of the method to rewrite into a Harmony patch. + Original method to use for context. + + + + Method patcher for normal managed methods that have IL body attached to them. + Uses in order to apply hooks in a way compatible with MonoMod's own + hooking system. + + + + + + + + + + + + + + + + + + A handler for that checks if a method is a normal Managed method. + + Not used + Patch resolver arguments + + + + + A general method patcher for implementing custom Harmony patcher backends. + + + + + + Constructs a method patcher + + Original method to patch + + + + + Original method to patch. + + + + + + Prepares method body for the unpatched that simply calls + function. + + + A that contains a call to + the original method to pass to the IL manipulator. + If null, Harmony patches must be manually applied to the original via . + + + + + + Detours to the provided replacement function. If called multiple times, + is re-detoured to the new method. + + + Result of + if returned non-null. + Otherwise, this will be null, in which case you must manually generate Harmony-patched method + with . + + of the hook, if it's different from `replacement`. + + + + + Creates a copy of the original method. If not possible, creates a method that calls into the original method. + + Copy of the original method that is transpileable. If not possible, returns null. + + This method creates a pure copy of the original method that is usable with transpilers. Currently, this + method is used to generate reverse patchers. + If a purse IL copy is not possible, a best approximation should be generated + (e.g. a wrapper that calls original method). + If no best approximation is possible, this method should return null, in which case generating reverse + patchers for the method will fail. + + + + + + A method patcher that uses to patch internal calls, + methods marked with and any other managed method that CLR managed-to-native + trampolines for and which has no IL body defined. + + + + + Constructs a new instance of method patcher. + + + + + + + + + + + + + + + A handler for that checks if a method doesn't have a body + (e.g. it's icall or marked with ) and thus can be patched with + . + + Not used + Patch resolver arguments + + + + + A global manager for handling Harmony patch state. Contains information about all patched methods and all + actual instances that handle patching implementation. + + + + + + Method patcher resolve event. + + + When a method is to be patched, this resolver event is called once on the method to determine which + backend to use in order to patch the method. + To make Harmony use the specified backend, set to an + instance of the method patcher backend to use. + + + + + + Creates or gets an existing instance of that handles patching the method. + + Method to patch. + Instance of that handles patching the method. + No suitable patcher found for the method. + + + + + Gets patch info for the given target method. + + Method to get patch info for. + Current patch info of the method. + + + + + Gets or creates patch info for the given method. + + Method to get info from. + An existing or new patch info for the method containing information about the applied patches. + + + + + Gets all methods that have been patched. + + List of methods that have been patched. + + + + + Removes all method resolvers. Use with care, this removes the default ones too! + + + + + Patcher resolve event arguments. + + + + + + Original method that is to be patched. + + + + + + Method patcher to use to patch . + Set this value to specify which one to use. + + + + + A PatchProcessor handles patches on a method/constructor + + + + Creates an empty patch processor + The Harmony instance + The original method/constructor + + + + Adds a prefix + The prefix as a + A for chaining calls + + + + Adds a prefix + The prefix method + A for chaining calls + + + + Adds a postfix + The postfix as a + A for chaining calls + + + + Adds a postfix + The postfix method + A for chaining calls + + + + Adds a transpiler + The transpiler as a + A for chaining calls + + + + Adds a transpiler + The transpiler method + A for chaining calls + + + + Adds a finalizer + The finalizer as a + A for chaining calls + + + + Adds a finalizer + The finalizer method + A for chaining calls + + + + Adds an ilmanipulator + The ilmanipulator as a + A for chaining calls + + + + Adds an ilmanipulator + The ilmanipulator method + A for chaining calls + + + + Gets all patched original methods in the appdomain + An enumeration of patched method/constructor + + + + Applies all registered patches + The generated replacement method + + + + Unpatches patches of a given type and/or Harmony ID + The patch type + Harmony ID or * for any + A for chaining calls + + + + Unpatches a specific patch + The method of the patch + A for chaining calls + + + + Gets patch information on an original + The original method/constructor + The patch information as + + + + Sort patch methods by their priority rules + The original method + Patches to sort + The sorted patch methods + + + + Gets Harmony version for all active Harmony instances + [out] The current Harmony version + A dictionary containing assembly version keyed by Harmony ID + + + + Creates a new empty generator to use when reading method bodies + A new + + + + Creates a new generator matching the method/constructor to use when reading method bodies + The original method/constructor to copy method information from + A new + + + + Returns the methods unmodified list of code instructions + The original method/constructor + Optionally an existing generator that will be used to create all local variables and labels contained in the result (if not specified, an internal generator is used) + A list containing all the original + + + + Returns the methods unmodified list of code instructions + The original method/constructor + A new generator that now contains all local variables and labels contained in the result + A list containing all the original + + + + Returns the methods current list of code instructions after all existing transpilers have been applied + The original method/constructor + Apply only the first count of transpilers + Optionally an existing generator that will be used to create all local variables and labels contained in the result (if not specified, an internal generator is used) + A list of + + + + Returns the methods current list of code instructions after all existing transpilers have been applied + The original method/constructor + A new generator that now contains all local variables and labels contained in the result + Apply only the first count of transpilers + A list of + + + + A low level way to read the body of a method. Used for quick searching in methods + The original method + All instructions as opcode/operand pairs + + + + A low level way to read the body of a method. Used for quick searching in methods + The original method + An existing generator that will be used to create all local variables and labels contained in the result + All instructions as opcode/operand pairs + + + + A patch priority + + + + Patch last + + + + Patch with very low priority + + + + Patch with low priority + + + + Patch with lower than normal priority + + + + Patch with normal priority + + + + Patch with higher than normal priority + + + + Patch with high priority + + + + Patch with very high priority + + + + Patch first + + + + A reverse patcher + + + + Creates a reverse patcher + The Harmony instance + The original method/constructor + Your stand-in stub method as + + + + Applies the patch + The type of patch, see + The generated replacement method + + + + A collection of commonly used transpilers + + + + Returns an instruction to call the specified delegate + The delegate type to emit + The delegate to emit + The instruction to call the specified action + + + + A transpiler that replaces all occurrences of a given method with another one using the same signature + The enumeration of to act on + Method or constructor to search for + Method or constructor to replace with + Modified enumeration of + + + + A transpiler that alters instructions that match a predicate by calling an action + The enumeration of to act on + A predicate selecting the instructions to change + An action to apply to matching instructions + Modified enumeration of + + + + A transpiler that logs a text at the beginning of the method + The instructions to act on + The log text + Modified enumeration of + + + + A transpiler that replaces the entire body of the method with another one + The replacement method. It's up to the caller of this transpiler to make sure that the signatures match. + of the patch. This is passed via transpiler. + A collection of that contains instructions of replacement method. + The replacement method is not a managed method that contains any IL. + This transpiler has a side effect of clearing up all previous locals and previous transpilers. + Use to run this transpiler as early as possible. + + + A helper class for reflection related functions + + + + Shortcut for to simplify the use of reflections and make it work for any access level + + + + Shortcut for to simplify the use of reflections and make it work for any access level but only within the current type + + + + Enumerates all assemblies in the current app domain, excluding visual studio assemblies + An enumeration of + + + Gets a type by name. Prefers a full name with namespace but falls back to the first type matching the name otherwise + The name + A type or null if not found + + + + Gets all successfully loaded types from a given assembly + The assembly + An array of types + + This calls and returns , while catching any thrown . + If such an exception is thrown, returns the successfully loaded types (, + filtered for non-null values). + + + + + Enumerates all successfully loaded types in the current app domain, excluding visual studio assemblies + An enumeration of all in all assemblies, excluding visual studio assemblies + + + Applies a function going up the type hierarchy and stops at the first non-null result + Result type of func() + The class/type to start with + The evaluation function returning T + The first non-null result, or null if no match + + The type hierarchy of a class or value type (including struct) does NOT include implemented interfaces, + and the type hierarchy of an interface is only itself (regardless of whether that interface implements other interfaces). + The top-most type in the type hierarchy of all non-interface types (including value types) is . + + + + + Applies a function going into inner types and stops at the first non-null result + Generic type parameter + The class/type to start with + The evaluation function returning T + The first non-null result, or null if no match + + + + Gets the reflection information for a directly declared field + The class/type where the field is defined + The name of the field + A field or null when type/name is null or when the field cannot be found + + + + Gets the reflection information for a field by searching the type and all its super types + The class/type where the field is defined + The name of the field (case sensitive) + A field or null when type/name is null or when the field cannot be found + + + + Gets the reflection information for a field + The class/type where the field is declared + The zero-based index of the field inside the class definition + A field or null when type is null or when the field cannot be found + + + + Gets the reflection information for a directly declared property + The class/type where the property is declared + The name of the property (case sensitive) + A property or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for the getter method of a directly declared property + The class/type where the property is declared + The name of the property (case sensitive) + A method or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for the setter method of a directly declared property + The class/type where the property is declared + The name of the property (case sensitive) + A method or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for a property by searching the type and all its super types + The class/type + The name + A property or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for the getter method of a property by searching the type and all its super types + The class/type + The name + A method or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for the setter method of a property by searching the type and all its super types + The class/type + The name + A method or null when type/name is null or when the property cannot be found + + + + Gets the reflection information for a directly declared method + The class/type where the method is declared + The name of the method (case sensitive) + Optional parameters to target a specific overload of the method + Optional list of types that define the generic version of the method + A method or null when type/name is null or when the method cannot be found + + + + Gets the reflection information for a method by searching the type and all its super types + The class/type where the method is declared + The name of the method (case sensitive) + Optional parameters to target a specific overload of the method + Optional list of types that define the generic version of the method + A method or null when type/name is null or when the method cannot be found + + + + Gets the reflection information for a method by searching the type and all its super types + The target method in the form TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType like Some.Namespace.Type. + Optional parameters to target a specific overload of the method + Optional list of types that define the generic version of the method + A method or null when type/name is null or when the method cannot be found + + + + Gets method of an enumerator method. + Enumerator method from which to get its + of the enumerator or null if no valid enumerator is detected + + + Gets the names of all method that are declared in a type + The declaring class/type + A list of method names + + + + Gets the names of all method that are declared in the type of the instance + An instance of the type to search in + A list of method names + + + + Gets the names of all fields that are declared in a type + The declaring class/type + A list of field names + + + + Gets the names of all fields that are declared in the type of the instance + An instance of the type to search in + A list of field names + + + + Gets the names of all properties that are declared in a type + The declaring class/type + A list of property names + + + + Gets the names of all properties that are declared in the type of the instance + An instance of the type to search in + A list of property names + + + + Gets the type of any class member of + A member + The class/type of this member + + + + Test if a class member is actually an concrete implementation + A member + True if the member is a declared + + + + Gets the real implementation of a class member + A member + The member itself if its declared. Otherwise the member that is actually implemented in some base type + + + + Gets the reflection information for a directly declared constructor + The class/type where the constructor is declared + Optional parameters to target a specific overload of the constructor + Optional parameters to only consider static constructors + A constructor info or null when type is null or when the constructor cannot be found + + + + Gets the reflection information for a constructor by searching the type and all its super types + The class/type where the constructor is declared + Optional parameters to target a specific overload of the method + Optional parameters to only consider static constructors + A constructor info or null when type is null or when the method cannot be found + + + + Gets reflection information for all declared constructors + The class/type where the constructors are declared + Optional parameters to only consider static constructors + A list of constructor infos + + + + Gets reflection information for all declared methods + The class/type where the methods are declared + A list of methods + + + + Gets reflection information for all declared properties + The class/type where the properties are declared + A list of properties + + + + Gets reflection information for all declared fields + The class/type where the fields are declared + A list of fields + + + + Gets the return type of a method or constructor + The method/constructor + The return type + + + + Given a type, returns the first inner type matching a recursive search by name + The class/type to start searching at + The name of the inner type (case sensitive) + The inner type or null if type/name is null or if a type with that name cannot be found + + + + Given a type, returns the first inner type matching a recursive search with a predicate + The class/type to start searching at + The predicate to search with + The inner type or null if type/predicate is null or if a type with that name cannot be found + + + + Given a type, returns the first method matching a predicate + The class/type to start searching at + The predicate to search with + The method or null if type/predicate is null or if a type with that name cannot be found + + + + Given a type, returns the first constructor matching a predicate + The class/type to start searching at + The predicate to search with + The constructor info or null if type/predicate is null or if a type with that name cannot be found + + + + Given a type, returns the first property matching a predicate + The class/type to start searching at + The predicate to search with + The property or null if type/predicate is null or if a type with that name cannot be found + + + + Returns an array containing the type of each object in the given array + An array of objects + An array of types or an empty array if parameters is null (if an object is null, the type for it will be object) + + + + Creates an array of input parameters for a given method and a given set of potential inputs + The method/constructor you are planing to call + The possible input parameters in any order + An object array matching the method signature + + + + A readable/assignable reference delegate to an instance field of a class or static field (NOT an instance field of a struct) + + An arbitrary type if the field is static; otherwise the class that defines the field, or a parent class (including ), + implemented interface, or derived class of this type + + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The runtime instance to access the field (ignored and can be omitted for static fields) + A readable/assignable reference to the field + Null instance passed to a non-static field ref delegate + + Instance of invalid type passed to a non-static field ref delegate + (this can happen if is a parent class or interface of the field's declaring type) + + + + This delegate cannot be used for instance fields of structs, since a struct instance passed to the delegate would be passed by + value and thus would be a copy that only exists within the delegate's invocation. This is fine for a readonly reference, + but makes assignment futile. Use instead. + + + Note that is not required to be the field's declaring type. It can be a parent class (including ), + implemented interface, or a derived class of the field's declaring type ("instanceOfT is FieldDeclaringType" must be possible). + Specifically, must be assignable from OR to the field's declaring type. + Technically, this allows Nullable, although Nullable is only relevant for structs, and since only static fields of structs + are allowed for this delegate, and the instance passed to such a delegate is ignored, this hardly matters. + + + Similarly, is not required to be the field's field type, unless that type is a non-enum value type. + It can be a parent class (including object) or implemented interface of the field's field type. It cannot be a derived class. + This variance is not allowed for value types, since that would require boxing/unboxing, which is not allowed for ref values. + Special case for enum types: can also be the underlying integral type of the enum type. + Specifically, for reference types, must be assignable from + the field's field type; for non-enum value types, must be exactly the field's field type; for enum types, + must be either the field's field type or the underyling integral type of that field type. + + + This delegate supports static fields, even those defined in structs, for legacy reasons. + For such static fields, is effectively ignored. + Consider using (and StaticFieldRefAccess methods that return it) instead for static fields. + + + + + + Creates a field reference delegate for an instance field of a class + The class that defines the instance field, or derived class of this type + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The name of the field + A readable/assignable delegate + + + For backwards compatibility, there is no class constraint on . + Instead, the non-value-type check is done at runtime within the method. + + + + + + Creates an instance field reference for a specific instance of a class + The class that defines the instance field, or derived class of this type + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The instance + The name of the field + A readable/assignable reference to the field + + + This method is meant for one-off access to a field's value for a single instance. + If you need to access a field's value for potentially multiple instances, use instead. + FieldRefAccess<T, F>(instance, fieldName) is functionally equivalent to FieldRefAccess<T, F>(fieldName)(instance). + + + For backwards compatibility, there is no class constraint on . + Instead, the non-value-type check is done at runtime within the method. + + + + + + Creates a field reference delegate for an instance field of a class or static field (NOT an instance field of a struct) + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + + The type that defines the field, or derived class of this type; must not be a struct type unless the field is static + + The name of the field + + A readable/assignable delegate with T=object + (for static fields, the instance delegate parameter is ignored) + + + + This method is meant for cases where the given type is only known at runtime and thus can't be used as a type parameter T + in e.g. . + + + This method supports static fields, even those defined in structs, for legacy reasons. + Consider using (and other overloads) instead for static fields. + + + + + + Creates a field reference delegate for an instance field of a class or static field (NOT an instance field of a struct) + + An arbitrary type if the field is static; otherwise the class that defines the field, or a parent class (including ), + implemented interface, or derived class of this type ("instanceOfT is FieldDeclaringType" must be possible) + + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The field + A readable/assignable delegate + + + This method is meant for cases where the field has already been obtained, avoiding the field searching cost in + e.g. . + + + This method supports static fields, even those defined in structs, for legacy reasons. + For such static fields, is effectively ignored. + Consider using (and other overloads) instead for static fields. + + + For backwards compatibility, there is no class constraint on . + Instead, the non-value-type check is done at runtime within the method. + + + + + + Creates a field reference for an instance field of a class + + The type that defines the field; or a parent class (including ), implemented interface, or derived class of this type + ("instanceOfT is FieldDeclaringType" must be possible) + + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The instance + The field + A readable/assignable reference to the field + + + This method is meant for one-off access to a field's value for a single instance and where the field has already been obtained. + If you need to access a field's value for potentially multiple instances, use instead. + FieldRefAccess<T, F>(instance, fieldInfo) is functionally equivalent to FieldRefAccess<T, F>(fieldInfo)(instance). + + + For backwards compatibility, there is no class constraint on . + Instead, the non-value-type check is done at runtime within the method. + + + + + + A readable/assignable reference delegate to an instance field of a struct + The struct that defines the instance field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + A reference to the runtime instance to access the field + A readable/assignable reference to the field + + + + Creates a field reference delegate for an instance field of a struct + The struct that defines the instance field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The name of the field + A readable/assignable delegate + + + + Creates an instance field reference for a specific instance of a struct + The struct that defines the instance field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The instance + The name of the field + A readable/assignable reference to the field + + + This method is meant for one-off access to a field's value for a single instance. + If you need to access a field's value for potentially multiple instances, use instead. + StructFieldRefAccess<T, F>(ref instance, fieldName) is functionally equivalent to StructFieldRefAccess<T, F>(fieldName)(ref instance). + + + + + + Creates a field reference delegate for an instance field of a struct + The struct that defines the instance field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The field + A readable/assignable delegate + + + This method is meant for cases where the field has already been obtained, avoiding the field searching cost in + e.g. . + + + + + + Creates a field reference for an instance field of a struct + The struct that defines the instance field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The instance + The field + A readable/assignable reference to the field + + + This method is meant for one-off access to a field's value for a single instance and where the field has already been obtained. + If you need to access a field's value for potentially multiple instances, use instead. + StructFieldRefAccess<T, F>(ref instance, fieldInfo) is functionally equivalent to StructFieldRefAccess<T, F>(fieldInfo)(ref instance). + + + + + + A readable/assignable reference delegate to a static field + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + A readable/assignable reference to the field + + + + Creates a static field reference + The type (can be class or struct) the field is defined in + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The name of the field + A readable/assignable reference to the field + + + + Creates a static field reference + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The type (can be class or struct) the field is defined in + The name of the field + A readable/assignable reference to the field + + + + Creates a static field reference + An arbitrary type (by convention, the type the field is defined in) + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The field + A readable/assignable reference to the field + + The type parameter is only used in exception messaging and to distinguish between this method overload + and the overload (which returns a rather than a reference). + + + + + Creates a static field reference delegate + + The type of the field; or if the field's type is a reference type (a class or interface, NOT a struct or other value type), + a type that is assignable from that type; or if the field's type is an enum type, + either that type or the underlying integral type of that enum type + + The field + A readable/assignable delegate + + + + Creates a delegate to a given method + The delegate Type + The method to create a delegate from. + + Only applies for instance methods. If null (default), returned delegate is an open (a.k.a. unbound) instance delegate + where an instance is supplied as the first argument to the delegate invocation; else, delegate is a closed (a.k.a. bound) + instance delegate where the delegate invocation always applies to the given . + + + Only applies for instance methods. If true (default) and is virtual, invocation of the delegate + calls the instance method virtually (the instance type's most-derived/overriden implementation of the method is called); + else, invocation of the delegate calls the exact specified (this is useful for calling base class methods) + Note: if false and is an interface method, an ArgumentException is thrown. + + A delegate of given to given + + + Delegate invocation is more performant and more convenient to use than + at a one-time setup cost. + + + Works for both type of static and instance methods, both open and closed (a.k.a. unbound and bound) instance methods, + and both class and struct methods. + + + + + + Creates a delegate for a given delegate definition, attributed with [] + The delegate Type, attributed with [] + + Only applies for instance methods. If null (default), returned delegate is an open (a.k.a. unbound) instance delegate + where an instance is supplied as the first argument to the delegate invocation; else, delegate is a closed (a.k.a. bound) + instance delegate where the delegate invocation always applies to the given . + + A delegate of given to the method specified via [] + attributes on + + This calls with the method and virtualCall arguments + determined from the [] attributes on , + and the given (for closed instance delegates). + + + + + Returns who called the current method + The calling method/constructor (excluding the caller) + + + + Rethrows an exception while preserving its stack trace (throw statement typically clobbers existing stack traces) + The exception to rethrow + + + + True if the current runtime is based on Mono, false otherwise (.NET) + + + + True if the current runtime is .NET Framework, false otherwise (.NET Core or Mono, although latter isn't guaranteed) + + + + True if the current runtime is .NET Core, false otherwise (Mono or .NET Framework) + + + + Throws a missing member runtime exception + The type that is involved + A list of names + + + + Gets default value for a specific type + The class/type + The default value + + + + Creates an (possibly uninitialized) instance of a given type + The class/type + The new instance + + + + Creates an (possibly uninitialized) instance of a given type + The class/type + The new instance + + + + + A cache for the or similar Add methods for different types. + + + + Makes a deep copy of any object + The type of the instance that should be created; for legacy reasons, this must be a class or interface + The original object + A copy of the original object but of type T + + + + Makes a deep copy of any object + The type of the instance that should be created + The original object + [out] The copy of the original object + Optional value transformation function (taking a field name and src/dst instances) + The optional path root to start with + + + + Makes a deep copy of any object + The original object + The type of the instance that should be created + Optional value transformation function (taking a field name and src/dst instances) + The optional path root to start with + The copy of the original object + + + + Tests if a type is a struct + The type + True if the type is a struct + + + + Tests if a type is a class + The type + True if the type is a class + + + + Tests if a type is a value type + The type + True if the type is a value type + + + + Tests if a type is an integer type + The type + True if the type represents some integer + + + + Tests if a type is a floating point type + The type + True if the type represents some floating point + + + + Tests if a type is a numerical type + The type + True if the type represents some number + + + + Tests if a type is void + The type + True if the type is void + + + + Test whether an instance is of a nullable type + Type of instance + An instance to test + True if instance is of nullable type, false if not + + + + Tests whether a type or member is static, as defined in C# + The type or member + True if the type or member is static + + + + Tests whether a type is static, as defined in C# + The type + True if the type is static + + + + Tests whether a property is static, as defined in C# + The property + True if the property is static + + + + Tests whether an event is static, as defined in C# + The event + True if the event is static + + + + Calculates a combined hash code for an enumeration of objects + The objects + The hash code + + + + A CodeInstruction match + + + The name of the match + + + The matched opcodes + + + The matched operands + + + The matched labels + + + The matched blocks + + + The jumps from the match + + + The jumps to the match + + + The match predicate + + + Creates a code match + The optional opcode + The optional operand + The optional name + + + + Creates a code match + The CodeInstruction + An optional name + + + + Creates a code match + The predicate + An optional name + + + + Returns a string that represents the match + A string representation + + + + Creates a new code match for an opcode + Opcode to match + + + + Creates a new code match for a code instruction + Code instruction + + + + A CodeInstruction matcher + + + The current position + The index or -1 if out of bounds + + + + Gets the number of code instructions in this matcher + The count + + + + Checks whether the position of this CodeMatcher is within bounds + True if this CodeMatcher is valid + + + + Checks whether the position of this CodeMatcher is outside its bounds + True if this CodeMatcher is invalid + + + + Gets the remaining code instructions + The remaining count + + + + Gets the opcode at the current position + The opcode + + + + Gets the operand at the current position + The operand + + + + Gets the labels at the current position + The labels + + + + Gets the exception blocks at the current position + The blocks + + + + Creates an empty code matcher + + + Creates a code matcher from an enumeration of instructions + The instructions (transpiler argument) + An optional IL generator + + + + Makes a clone of this instruction matcher + A copy of this matcher + + + + Gets instructions at the current position + The instruction + + + + Gets instructions at the current position with offset + The offset + The instruction + + + + Gets all instructions + A list of instructions + + + + Gets all instructions as an enumeration + A list of instructions + + + + Gets some instructions counting from current position + Number of instructions + A list of instructions + + + + Gets all instructions within a range + The start index + The end index + A list of instructions + + + + Gets all instructions within a range (relative to current position) + The start offset + The end offset + A list of instructions + + + + Gets a list of all distinct labels + The instructions (transpiler argument) + A list of Labels + + + + Reports a failure + The method involved + The logger + True if current position is invalid and error was logged + + + + Throw an InvalidOperationException if current state is invalid (position out of bounds / last match failed) + Explanation of where/why the exception was thrown that will be added to the exception message + The same code matcher + + + + Throw an InvalidOperationException if current state is invalid (position out of bounds / last match failed), + or if the matches do not match at current position + Explanation of where/why the exception was thrown that will be added to the exception message + Some code matches + The same code matcher + + + + Throw an InvalidOperationException if current state is invalid (position out of bounds / last match failed), + or if the matches do not match at any point between current position and the end + Explanation of where/why the exception was thrown that will be added to the exception message + Some code matches + The same code matcher + + + + Throw an InvalidOperationException if current state is invalid (position out of bounds / last match failed), + or if the matches do not match at any point between current position and the start + Explanation of where/why the exception was thrown that will be added to the exception message + Some code matches + The same code matcher + + + + Throw an InvalidOperationException if current state is invalid (position out of bounds / last match failed), + or if the check function returns false + Explanation of where/why the exception was thrown that will be added to the exception message + Function that checks validity of current state. If it returns false, an exception is thrown + The same code matcher + + + + Sets an instruction at current position + The instruction to set + The same code matcher + + + + Sets instruction at current position and advances + The instruction + The same code matcher + + + + Sets opcode and operand at current position + The opcode + The operand + The same code matcher + + + + Sets opcode and operand at current position and advances + The opcode + The operand + The same code matcher + + + + Sets opcode at current position and advances + The opcode + The same code matcher + + + + Sets operand at current position and advances + The operand + The same code matcher + + + + Creates a label at current position + [out] The label + The same code matcher + + + + Creates a label at a position + The position + [out] The new label + The same code matcher + + + + Adds an enumeration of labels to current position + The labels + The same code matcher + + + + Adds an enumeration of labels at a position + The position + The labels + The same code matcher + + + + Sets jump to + Branch instruction + Destination for the jump + [out] The created label + The same code matcher + + + + Inserts some instructions + The instructions + The same code matcher + + + + Inserts an enumeration of instructions + The instructions + The same code matcher + + + + Inserts a branch + The branch opcode + Branch destination + The same code matcher + + + + Inserts some instructions and advances the position + The instructions + The same code matcher + + + + Inserts an enumeration of instructions and advances the position + The instructions + The same code matcher + + + + Inserts a branch and advances the position + The branch opcode + Branch destination + The same code matcher + + + + Removes current instruction + The same code matcher + + + + Removes some instruction from current position by count + Number of instructions + The same code matcher + + + + Removes the instructions in a range + The start + The end + The same code matcher + + + + Removes the instructions in a offset range + The start offset + The end offset + The same code matcher + + + + Advances the current position + The offset + The same code matcher + + + + Moves the current position to the start + The same code matcher + + + + Moves the current position to the end + The same code matcher + + + + Searches forward with a predicate and advances position + The predicate + The same code matcher + + + + Searches backwards with a predicate and reverses position + The predicate + The same code matcher + + + + Matches forward and advances position + True to set position to end of match, false to set it to the beginning of the match + Some code matches + The same code matcher + + + + Matches backwards and reverses position + True to set position to end of match, false to set it to the beginning of the match + Some code matches + The same code matcher + + + + Matches forward and advances position to beginning of matching sequence + Some code matches + The same code matcher + + + + Matches forward and advances position to ending of matching sequence + Some code matches + The same code matcher + + + + Matches backwards and reverses position to beginning of matching sequence + Some code matches + The same code matcher + + + + Matches backwards and reverses position to ending of matching sequence + Some code matches + The same code matcher + + + + Repeats a match action until boundaries are met + The match action + An optional action that is executed when no match is found + The same code matcher + + + + Gets a match by its name + The match name + An instruction + + + + General extensions for common cases + + + + Joins an enumeration with a value converter and a delimiter to a string + The inner type of the enumeration + The enumeration + An optional value converter (from T to string) + An optional delimiter + The values joined into a string + + + + Converts an array of types (for example methods arguments) into a human readable form + The array of types + A human readable description including brackets + + + + A full description of a type + The type + A human readable description + + + + A a full description of a method or a constructor without assembly details but with generics + The method/constructor + A human readable description + + + + A helper converting parameter infos to types + The array of parameter infos + An array of types + + + + A helper to access a value via key from a dictionary + The key type + The value type + The dictionary + The key + The value for the key or the default value (of T) if that key does not exist + + + + A helper to access a value via key from a dictionary with extra casting + The value type + The dictionary + The key + The value for the key or the default value (of T) if that key does not exist or cannot be cast to T + + + + Escapes Unicode and ASCII non printable characters + The string to convert + The string to convert + A string literal surrounded by + + + + Extensions for + + + + Shortcut for testing whether the operand is equal to a non-null value + The + The value + True if the operand has the same type and is equal to the value + + + + Shortcut for testing whether the operand is equal to a non-null value + The + The value + True if the operand is equal to the value + This is an optimized version of for + + + + Shortcut for code.opcode == opcode && code.OperandIs(operand) + The + The + The operand value + True if the opcode is equal to the given opcode and the operand has the same type and is equal to the given operand + + + + Shortcut for code.opcode == opcode && code.OperandIs(operand) + The + The + The operand value + True if the opcode is equal to the given opcode and the operand is equal to the given operand + This is an optimized version of for + + + + Tests for any form of Ldarg* + The + The (optional) index + True if it matches one of the variations + + + + Tests for Ldarga/Ldarga_S + The + The (optional) index + True if it matches one of the variations + + + + Tests for Starg/Starg_S + The + The (optional) index + True if it matches one of the variations + + + + Tests for any form of Ldloc* + The + The optional local variable + True if it matches one of the variations + + + + Tests for any form of Stloc* + The + The optional local variable + True if it matches one of the variations + + + + Tests if the code instruction branches + The + The label if the instruction is a branch operation or if not + True if the instruction branches + + + + Tests if the code instruction calls the method/constructor + The + The method + True if the instruction calls the method or constructor + + + + Tests if the code instruction loads a constant + The + True if the instruction loads a constant + + + + Tests if the code instruction loads an integer constant + The + The integer constant + True if the instruction loads the constant + + + + Tests if the code instruction loads a floating point constant + The + The floating point constant + True if the instruction loads the constant + + + + Tests if the code instruction loads an enum constant + The + The enum + True if the instruction loads the constant + + + + Tests if the code instruction loads a field + The + The field + Set to true if the address of the field is loaded + True if the instruction loads the field + + + + Tests if the code instruction stores a field + The + The field + True if the instruction stores this field + + + + Adds labels to the code instruction and return it + The + One or several to add + The same code instruction + + + Adds labels to the code instruction and return it + The + An enumeration of + The same code instruction + + + Extracts all labels from the code instruction and returns them + The + A list of + + + Moves all labels from the code instruction to a different one + The to move the labels from + The to move the labels to + The code instruction labels were moved from (now empty) + + + Moves all labels from a different code instruction to the current one + The to move the labels from + The to move the labels to + The code instruction that received the labels + + + Adds ExceptionBlocks to the code instruction and return it + The + One or several to add + The same code instruction + + + Adds ExceptionBlocks to the code instruction and return it + The + An enumeration of + The same code instruction + + + Extracts all ExceptionBlocks from the code instruction and returns them + The + A list of + + + Moves all ExceptionBlocks from the code instruction to a different one + The to move the ExceptionBlocks from + The to move the ExceptionBlocks to + The code instruction blocks were moved from (now empty) + + + Moves all ExceptionBlocks from a different code instruction to the current one + The to move the ExceptionBlocks from + The to move the ExceptionBlocks to + The code instruction that received the blocks + + + General extensions for collections + + + + A simple way to execute code for every element in a collection + The inner type of the collection + The collection + The action to execute + + + + A simple way to execute code for elements in a collection matching a condition + The inner type of the collection + The collection + The predicate + The action to execute + + + + A helper to add an item to a collection + The inner type of the collection + The collection + The item to add + The collection containing the item + + + + A helper to add an item to an array + The inner type of the collection + The array + The item to add + The array containing the item + + + + A helper to add items to an array + The inner type of the collection + The array + The items to add + The array containing the items + + + + General extensions for collections + + + + Tests a class member if it has an IL method body (external methods for example don't have a body) + The member to test + Returns true if the member has an IL body or false if not + + + A file log for debugging + + + + Full pathname of the log file, defaults to a file called harmony.log.txt on your Desktop + + + + The indent character. The default is tab + + + + The current indent level + + + + Changes the indentation level + The value to add to the indentation level + + + + Log a string in a buffered way. Use this method only if you are sure that FlushBuffer will be called + or else logging information is incomplete in case of a crash + The string to log + + + + Logs a list of string in a buffered way. Use this method only if you are sure that FlushBuffer will be called + or else logging information is incomplete in case of a crash + A list of strings to log (they will not be re-indented) + + + + Returns the log buffer and optionally empties it + True to empty the buffer + The buffer. + + + + Replaces the buffer with new lines + The lines to store + + + + Flushes the log buffer to disk (use in combination with LogBuffered) + + + + Log a string directly to disk. Slower method that prevents missing information in case of a crash + The string to log. + + + + Log a string directly to disk if Harmony.DEBUG is true. Slower method that prevents missing information in case of a crash + The string to log. + + + + Resets and deletes the log + + + + Logs some bytes as hex values + The pointer to some memory + The length of bytes to log + + + + + Default Harmony logger that writes to a file + + + + + Whether or not to enable writing the log. + + + + + Text writer to write the logs to. If not set, defaults to a file log. + + + + + File path of the log. + + + + + Main logger class that exposes log events. + + + + + A single log event that represents a single log message. + + + + + Log channel of the message. + + + + + The log message. + + + + + Log channel for the messages. + + + + + No channels (or an empty channel). + + + + + Basic information. + + + + + Full IL dumps of the generated dynamic methods. + + + + + Channel for warnings. + + + + + Channel for errors. + + + + + Additional debug information that is related to patching + + + + + All channels. + + + + + Filter for which channels should be listened to. + If the channel is in the filter, all log messages from that channel get propagated into event. + + + + + Event fired on any incoming message that passes the channel filter. + + + + + Pretty print a full type name. + + The . + The pretty printed full type name. + + + + A helper class to retrieve reflection info for non-private methods + + + + Given a lambda expression that calls a method, returns the method info + The lambda expression using the method + The method in the lambda expression + + + + Given a lambda expression that calls a method, returns the method info + The generic type + The lambda expression using the method + The method in the lambda expression + + + + Given a lambda expression that calls a method, returns the method info + The generic type + The generic result type + The lambda expression using the method + The method in the lambda expression + + + + Given a lambda expression that calls a method, returns the method info + The lambda expression using the method + The method in the lambda expression + + + + A reflection helper to read and write private elements + The result type defined by GetValue() + + + + Creates a traverse instance from an existing instance + The existing instance + + + + Gets/Sets the current value + The value to read or write + + + + A reflection helper to read and write private elements + + + + Creates a new traverse instance from a class/type + The class/type + A instance + + + + Creates a new traverse instance from a class T + The class + A instance + + + + Creates a new traverse instance from an instance + The object + A instance + + + + Creates a new traverse instance from a named type + The type name, for format see + A instance + + + + Creates a new and empty traverse instance + + + + Creates a new traverse instance from a class/type + The class/type + + + + Creates a new traverse instance from an instance + The object + + + + Gets the current value + The value + + + + Gets the current value + The type of the value + The value + + + + Invokes the current method with arguments and returns the result + The method arguments + The value returned by the method + + + + Invokes the current method with arguments and returns the result + The type of the value + The method arguments + The value returned by the method + + + + Sets a value of the current field or property + The value + The same traverse instance + + + + Gets the type of the current field or property + The type + + + + Moves the current traverse instance to a inner type + The type name + A traverse instance + + + + Moves the current traverse instance to a field + The type name + A traverse instance + + + + Moves the current traverse instance to a field + The type of the field + The type name + A traverse instance + + + + Gets all fields of the current type + A list of field names + + + + Moves the current traverse instance to a property + The type name + Optional property index + A traverse instance + + + + Moves the current traverse instance to a field + The type of the property + The type name + Optional property index + A traverse instance + + + + Gets all properties of the current type + A list of property names + + + + Moves the current traverse instance to a method + The name of the method + The arguments defining the argument types of the method overload + A traverse instance + + + + Moves the current traverse instance to a method + The name of the method + The argument types of the method + The arguments for the method + A traverse instance + + + + Gets all methods of the current type + A list of method names + + + + Checks if the current traverse instance is for a field + True if its a field + + + + Checks if the current traverse instance is for a property + True if its a property + + + + Checks if the current traverse instance is for a method + True if its a method + + + + Checks if the current traverse instance is for a type + True if its a type + + + + Iterates over all fields of the current type and executes a traverse action + Original object + The action receiving a instance for each field + + + + Iterates over all fields of the current type and executes a traverse action + Original object + Target object + The action receiving a pair of instances for each field pair + + + + Iterates over all fields of the current type and executes a traverse action + Original object + Target object + The action receiving a dot path representing the field pair and the instances + + + + Iterates over all properties of the current type and executes a traverse action + Original object + The action receiving a instance for each property + + + + Iterates over all properties of the current type and executes a traverse action + Original object + Target object + The action receiving a pair of instances for each property pair + + + + Iterates over all properties of the current type and executes a traverse action + Original object + Target object + The action receiving a dot path representing the property pair and the instances + + + + A default field action that copies fields to fields + + + + Returns a string that represents the current traverse + A string representation + + + + + Indicates that the marked symbol is used implicitly (e.g. via reflection, in external library), + so this symbol will not be reported as unused (as well as by other usage inspections). + + + + + Can be applied to attributes, type parameters, and parameters of a type assignable from . + When applied to an attribute, the decorated attribute behaves the same as . + When applied to a type parameter or to a parameter of type , indicates that the corresponding type + is used implicitly. + + + + + Specify the details of implicitly used symbol when it is marked + with or . + + + + Only entity marked with attribute considered used. + + + Indicates implicit assignment to a member. + + + + Indicates implicit instantiation of a type with fixed constructor signature. + That means any unused constructor parameters won't be reported as such. + + + + Indicates implicit instantiation of a type. + + + + Specify what is considered to be used implicitly when marked + with or . + + + + Members of entity marked with attribute are considered used. + + + Inherited entities are considered used. + + + Entity marked with attribute and all its members considered used. + + + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony20.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony20.dll new file mode 100644 index 00000000..67779b38 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/0Harmony20.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.dll new file mode 100644 index 00000000..03565da7 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.xml new file mode 100644 index 00000000..86b7dc6e --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Harmony.xml @@ -0,0 +1,86 @@ + + + + BepInEx.Harmony + + + + + Specifies the indices of parameters that are ByRef. + + + + + The indices of parameters that are ByRef. + + + + The indices of parameters that are ByRef. + + + + An extension class for Harmony based operations. + + + + + Applies all patches specified in the type. + + The HarmonyInstance to use. + The type to scan. + + + + A wrapper for Harmony based operations. + + + + + Applies all patches specified in the type. + + The type to scan. + The HarmonyInstance to use. + + + + Applies all patches specified in the type. + + The type to scan. + The ID for the Harmony instance to create, which will be used. + + + + Applies all patches specified in the assembly. + + The assembly to scan. + The HarmonyInstance to use. + + + + Applies all patches specified in the assembly. + + The assembly to scan. + The ID for the Harmony instance to create, which will be used. + + + + Applies all patches specified in the calling assembly. + + The Harmony instance to use. + + + + Applies all patches specified in the calling assembly. + + The ID for the Harmony instance to create, which will be used. + + + + Returns an instruction to call the specified delegate. + + The delegate type to emit. + The delegate to emit. + The instruction to + + + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.dll new file mode 100644 index 00000000..acdcdd05 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.xml new file mode 100644 index 00000000..fe5607df --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.Preloader.xml @@ -0,0 +1,169 @@ + + + + BepInEx.Preloader + + + + + Doorstop environment variables, passed into the BepInEx preloader. + https://github.com/NeighTools/UnityDoorstop/wiki#environment-variables + + + + + Path to the assembly that was invoked via Doorstop. Contains the same value as in "targetAssembly" configuration option in the config file. + + + + + Full path to the game's "Managed" folder that contains all the game's managed assemblies + + + + + Full path to the game executable currently running. + + + + + Array of paths where Mono searches DLLs from before assembly resolvers are invoked. + + + + + Delegate used in patching assemblies. + + The assembly that is being patched. + + + + Worker class which is used for loading and patching entire folders of assemblies, or alternatively patching and + loading assemblies one at a time. + + + + + List of all patcher plugins to be applied + + + + + Adds a single assembly patcher to the pool of applicable patches. + + Patcher to apply. + + + + Adds all patchers from all managed assemblies specified in a directory. + + Directory to search patcher DLLs from. + + + + Releases all patchers to let them be collected by GC. + + + + + Applies patchers to all assemblies in the given directory and loads patched assemblies into memory. + + Directories to load CLR assemblies from in their search order. + + + + Loads an individual assembly definition into the CLR. + + The assembly to load. + File name of the assembly being loaded. + + + + A single assembly patcher. + + + + + Target assemblies to patch. + + + + + Initializer method that is run before any patching occurs. + + + + + Finalizer method that is run after all patching is done. + + + + + The main patcher method that is called on every DLL defined in . + + + + + Type name of the patcher. + + + + + + + + + + + The main entrypoint of BepInEx, called from Doorstop. + + + + + Recreation of MonoMod's PlatformHelper.DeterminePlatform method, but with libc calls instead of creating processes. + + + + + This exists because the Mono implementation of is/was broken, and would call Write directly instead of calling TraceEvent. + + + + + The main entrypoint of BepInEx, and initializes all patchers and the chainloader. + + + + + The log writer that is specific to the preloader. + + + + + Inserts BepInEx's own chainloader entrypoint into UnityEngine. + + The assembly that will be attempted to be patched. + + + + Allocates a console window for use by BepInEx safely. + + + + + Log listener that listens to logs during preloading time and buffers messages for output in Unity logs later. + + + + + + + + + + + + + + + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.dll new file mode 100644 index 00000000..2fb6c0d0 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.xml new file mode 100644 index 00000000..03a03f4b --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/BepInEx.xml @@ -0,0 +1,1729 @@ + + + + BepInEx + + + + + Abstraction layer over Unity's input systems for use in universal plugins that need to use hotkeys. + It can use either Input or Unity.InputSystem, depending on what's available. Input is preferred. + WARNING: Use only inside of Unity's main thread! + + + + + Best currently supported input system. + + + + + True if the Input class is not disabled. + + + + + Generic input system interface. Just barely good enough for hotkeys. + + + + + + + + + + + + + + + + + + + + All KeyCodes supported by the current input system. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Base type of all classes representing and enforcing acceptable values of config settings. + + + + Type of values that this class can Clamp. + + + + Change the value to be acceptable, if it's not already. + + + + + Check if the value is an acceptable value. + + + + + Type of the supported values. + + + + + Get the string for use in config files. + + + + + Specify the list of acceptable values for a setting. + + + + + List of values that a setting can take. + + + + + Specify the list of acceptable values for a setting. + If the setting does not equal any of the values, it will be set to the first one. + + + + + + + + + + + + + + Specify the range of acceptable values for a setting. + + + + Lowest acceptable value + Highest acceptable value + + + + Lowest acceptable value + + + + + Highest acceptable value + + + + + + + + + + + + + + Provides access to a single setting inside of a . + + Type of the setting. + + + + Fired when the setting is changed. Does not detect changes made outside from this object. + + + + + Value of this setting. + + + + + + + + Container for a single setting of a . + Each config entry is linked to one config file. + + + + + Types of defaultValue and definition.AcceptableValues have to be the same as settingType. + + + + + Config file this entry is a part of. + + + + + Category and name of this setting. Used as a unique key for identification within a . + + + + + Description / metadata of this setting. + + + + + Type of the that this setting holds. + + + + + Default value of this setting (set only if the setting was not changed before). + + + + + Get or set the value of the setting. + + + + + Get the serialized representation of the value. + + + + + Set the value by using its serialized form. + + + + + If necessary, clamp the value to acceptable value range. T has to be equal to settingType. + + + + + Trigger setting changed event. + + + + + Write a description of this setting using all available metadata. + + + + + Section and key of a setting. Used as a unique key for identification within a . + The same definition can be used in multiple config files, it will point to different settings then. + + + + + + Group of the setting. All settings within a config file are grouped by this. + + + + + Name of the setting. + + + + + Create a new definition. Definitions with same section and key are equal. + + Group of the setting, case sensitive. + Name of the setting, case sensitive. + + + + + + + Check if the definitions are the same. + + + + + + Check if the definitions are the same. + + + + + + + + Check if the definitions are the same. + + + + + Check if the definitions are the same. + + + + + + + + Metadata of a . + + + + + Create a new description. + + Text describing the function of the setting and any notes or warnings. + Range of values that this setting can take. The setting's value will be automatically clamped. + Objects that can be used by user-made classes to add functionality. + + + + Text describing the function of the setting and any notes or warnings. + + + + + Range of acceptable values for a setting. + + + + + Objects that can be used by user-made classes to add functionality. + + + + + An empty description. + + + + + A helper class to handle persistent data. All public methods are thread-safe. + + + + + All config entries inside + + + + + Create a list with all config entries inside of this config file. + + + + + Create an array with all config entries inside of this config file. Should be only used for metadata purposes. + If you want to access and modify an existing setting then use + instead with no description. + + + + + Full path to the config file. The file might not exist until a setting is added and changed, or is called. + + + + + If enabled, writes the config to disk every time a value is set. + If disabled, you have to manually use or the changes will be lost! + + + + + + + + Create a new config file at the specified config path. + + Full path to a file that contains settings. The file will be created as needed. + If the config file/directory doesn't exist, create it immediately. + Information about the plugin that owns this setting file. + + + + Reloads the config from disk. Unsaved changes are lost. + + + + + Writes the config to disk. + + + + + Access one of the existing settings. If the setting has not been added yet, null is returned. + If the setting exists but has a different type than T, an exception is thrown. + New settings should be added with . + + Type of the value contained in this setting. + Section and Key of the setting. + + + + Access one of the existing settings. If the setting has not been added yet, null is returned. + If the setting exists but has a different type than T, an exception is thrown. + New settings should be added with . + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + + + + Access one of the existing settings. If the setting has not been added yet, false is returned. Otherwise, true. + If the setting exists but has a different type than T, an exception is thrown. + New settings should be added with . + + Type of the value contained in this setting. + Section and Key of the setting. + The ConfigEntry value to return. + + + + Access one of the existing settings. If the setting has not been added yet, null is returned. + If the setting exists but has a different type than T, an exception is thrown. + New settings should be added with . + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + The ConfigEntry value to return. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each definition can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section and Key of the setting. + Value of the setting if the setting was not created yet. + Description of the setting shown to the user and other metadata. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each section and key pair can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + Value of the setting if the setting was not created yet. + Description of the setting shown to the user and other metadata. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each section and key pair can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + Value of the setting if the setting was not created yet. + Simple description of the setting shown to the user. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each definition can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section and Key of the setting. + Value of the setting if the setting was not created yet. + Description of the setting shown to the user and other metadata. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each section and key pair can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + Value of the setting if the setting was not created yet. + Description of the setting shown to the user and other metadata. + + + + Create a new setting. The setting is saved to drive and loaded automatically. + Each section and key pair can be used to add only one setting, trying to add a second setting will throw an exception. + + Type of the value contained in this setting. + Section/category/group of the setting. Settings are grouped by this. + Name of the setting. + Value of the setting if the setting was not created yet. + Simple description of the setting shown to the user. + + + + Access a setting. Use Bind instead. + + + + + Access a setting. Use Bind instead. + + + + + An event that is fired every time the config is reloaded. + + + + + Fired when one of the settings is changed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Returns the ConfigDefinitions that the ConfigFile contains. + Creates a new array when the property is accessed. Thread-safe. + + + + + Returns the ConfigEntryBase values that the ConfigFile contains. + Creates a new array when the property is accessed. Thread-safe. + + + + + Provides access to a single setting inside of a . + + Type of the setting. + + + + Entry of this setting in the . + + + + + Unique definition of this setting. + + + + + Config file this setting is inside of. + + + + + Fired when the setting is changed. Does not detect changes made outside from this object. + + + + + Value of this setting. + + + + + A keyboard shortcut that can be used in Update method to check if user presses a key combo. The shortcut is only + triggered when the user presses the exact combination. For example, F + LeftCtrl will trigger only if user + presses and holds only LeftCtrl, and then presses F. If any other keys are pressed, the shortcut will not trigger. + + Can be used as a value of a setting in + to allow user to change this shortcut and have the changes saved. + + How to use: Use in this class instead of in the Update loop. + + + + + Shortcut that never triggers. + + + + + All KeyCode values that can be used in a keyboard shortcut. + + + + + Create a new keyboard shortcut. + + Main key to press + Keys that should be held down before main key is registered + + + + Main key of the key combination. It has to be pressed / let go last for the combination to be triggered. + If the combination is empty, is returned. + + + + + Modifiers of the key combination, if any. + + + + + Attempt to deserialize key combination from the string. + + + + + Serialize the key combination into a user readable string. + + + + + Check if the main key was just pressed (Input.GetKeyDown), and specified modifier keys are all pressed + + + + + Check if the main key is currently held down (Input.GetKey), and specified modifier keys are all pressed + + + + + Check if the main key was just lifted (Input.GetKeyUp), and specified modifier keys are all pressed. + + + + + + + + + + + + + + Arguments for events concerning a change of a setting. + + + + + + + + + Setting that was changed + + + + + Serializer/deserializer used by the config system. + + + + + Convert object of a given type to a string using available converters. + + + + + Convert string to an object of a given type using available converters. + + + + + Convert string to an object of a given type using available converters. + + + + + Get a converter for a given type if there is any. + + + + + Add a new type converter for a given type. + If a different converter is already added, this call is ignored and false is returned. + + + + + Check if a given type can be converted to and from string. + + + + + Give a list of types with registered converters. + + + + + For types that are in assemblies that can't get loaded before preloader runs (or it won't work on these assemblies) + + + + + A serializer/deserializer combo for some type(s). Used by the config system. + + + + + Used to serialize the type into a (hopefully) human-readable string. + Object is the instance to serialize, Type is the object's type. + + + + + Used to deserialize the type from a string. + String is the data to deserialize, Type is the object's type, should return instance to an object of Type. + + + + + True if an external console has been started, false otherwise. + + + + + The stream that writes to the standard out stream of the process. Should never be null. + + + + + The stream that writes to an external console. Null if no such console exists + + + + + Data class that represents information about a loadable BepInEx plugin. + Contains all metadata and additional info required for plugin loading by . + + + + + General metadata about a plugin. + + + + + Collection of attributes that describe what processes the plugin can run on. + + + + + Collection of attributes that describe what plugins this plugin depends on. + + + + + Collection of attributes that describe what plugins this plugin + is incompatible with. + + + + + File path to the plugin DLL + + + + + Instance of the plugin that represents this info. NULL if no plugin is instantiated from info (yet) + + + + + + + + This attribute denotes that a class is a plugin, and specifies the required metadata. + + + + + The unique identifier of the plugin. Should not change between plugin versions. + + + + + The user friendly name of the plugin. Is able to be changed between versions. + + + + + The specfic version of the plugin. + + + + The unique identifier of the plugin. Should not change between plugin versions. + The user friendly name of the plugin. Is able to be changed between versions. + The specfic version of the plugin. + + + + This attribute specifies any dependencies that this plugin has on other plugins. + + + + + Flags that are applied to a dependency + + + + + The plugin has a hard dependency on the referenced plugin, and will not run without it. + + + + + This plugin has a soft dependency on the referenced plugin, and is able to run without it. + + + + + The GUID of the referenced plugin. + + + + + The flags associated with this dependency definition. + + + + + The minimum version of the referenced plugin. + + + + + Marks this as depenant on another plugin. The other plugin will be loaded before this one. + If the other plugin doesn't exist, what happens depends on the parameter. + + The GUID of the referenced plugin. + The flags associated with this dependency definition. + + + + Marks this as depenant on another plugin. The other plugin will be loaded before this one. + If the other plugin doesn't exist or is of a version below , this plugin will not load and an error will be logged instead. + + The GUID of the referenced plugin. + The minimum version of the referenced plugin. + When version is supplied the dependency is always treated as HardDependency + + + + This attribute specifies other plugins that are incompatible with this plugin. + + + + + The GUID of the referenced plugin. + + + + + Marks this as incompatible with another plugin. + If the other plugin exists, this plugin will not be loaded and a warning will be shown. + + The GUID of the referenced plugin. + + + + This attribute specifies which processes this plugin should be run for. Not specifying this attribute will load the plugin under every process. + + + + + The name of the process that this plugin will run under. + + + + The name of the process that this plugin will run under. + + + + Helper class to use for retrieving metadata about a plugin, defined as attributes. + + + + + Retrieves the BepInPlugin metadata from a plugin type. + + The plugin type. + The BepInPlugin metadata of the plugin type. + + + + Retrieves the BepInPlugin metadata from a plugin instance. + + The plugin instance. + The BepInPlugin metadata of the plugin instance. + + + + Gets the specified attributes of a type, if they exist. + + The attribute type to retrieve. + The plugin type. + The attributes of the type, if existing. + + + + Gets the specified attributes of an instance, if they exist. + + The attribute type to retrieve. + The plugin instance. + The attributes of the instance, if existing. + + + + Retrieves the dependencies of the specified plugin type. + + The plugin type. + A list of all plugin types that the specified plugin type depends upon. + + + + This class is appended to AssemblyInfo.cs when BepInEx is built via a CI pipeline. + It is mainly intended to signify that the current build is not a release build and is special, like for instance a bleeding edge build. + + + + + The manager and loader for all plugins, and the entry point for BepInEx plugin system. + + + + + The loaded and initialized list of plugins. + + + + + List of all loaded via the chainloader. + + + + + Collection of error chainloader messages that occured during plugin loading. + Contains information about what certain plugins were not loaded. + + + + + The GameObject that all plugins are attached to as components. + + + + + Initializes BepInEx to be able to start the chainloader. + + + + + Analyzes the given type definition and attempts to convert it to a valid + + Type definition to analyze. + If the type represent a valid plugin, returns a instance. Otherwise, return null. + + + + The entrypoint for the BepInEx plugin system. + + + + + A cacheable metadata item. Can be used with and to cache plugin metadata. + + + + + Serialize the object into a binary format. + + + + + + Loads the object from binary format. + + + + + + A cached assembly. + + + + + + List of cached items inside the assembly. + + + + + Timestamp of the assembly. Used to check the age of the cache. + + + + + Provides methods for loading specified types from an assembly. + + + + + Default assembly resolved used by the + + + + + Default reader parameters used by + + + + + Event fired when fails to resolve a type during type loading. + + + + + Looks up assemblies in the given directory and locates all types that can be loaded and collects their metadata. + + The specific base type to search for. + The directory to search for assemblies. + A function to check if a type should be selected and to build the type metadata. + A filter function to quickly determine if the assembly can be loaded. + The name of the cache to get cached types from. + A dictionary of all assemblies in the directory and the list of type metadatas of types that match the selector. + + + + Loads an index of type metadatas from a cache. + + Name of the cache + Cacheable item + Cached type metadatas indexed by the path of the assembly that defines the type. If no cache is defined, return null. + + + + Saves indexed type metadata into a cache. + + Name of the cache + List of plugin metadatas indexed by the path to the assembly that contains the types + Cacheable item + + + + Converts TypeLoadException to a readable string. + + TypeLoadException + Readable representation of the exception + + + + The base plugin type that is used by the BepInEx plugin loader. + + + + + Information about this plugin as it was loaded. + + + + + Logger instance tied to this plugin. + + + + + Default config file tied to this plugin. The config file will not be created until + any settings are added and changed, or is called. + + + + + Create a new instance of a plugin and all of its tied in objects. + + BepInPlugin attribute is missing. + + + + Logs entries using Unity specific outputs. + + + + + Log levels to display. + + + + + Writer for the disk log. + + + + + Timer for flushing the logs to a file. + + + + + Whether to write Unity log messages to disk log. + + + + + Creates a new disk log listener. + + Path to the log. + Log levels to display. + Whether to append logs to an already existing log file. + Whether to include Unity log into the disk log. + + + + + + + + + + Disposes of Disk logger + + + + + Log event arguments. Contains info about the log message. + + + + + Logged data. + + + + + Log levels for the data. + + + + + Log source that emitted the log event. + + + + + Creates the log event args- + + Logged data. + Log level of the data. + Log source that emits these args. + + + + + + + Like but appends newline at the end. + + Same output as but with new line. + + + + A static Logger instance. + + + + + Collection of all log listeners that receive log events. + + + + + Collection of all log source that output log events. + + + + + Logs an entry to the current logger instance. + + The level of the entry. + The textual value of the entry. + + + + Creates a new log source with a name and attaches it to log sources. + + Name of the log source to create. + An instance of that allows to write logs. + + + + The level, or severity of a log entry. + + + + + No level selected. + + + + + A fatal error has occurred, which cannot be recovered from. + + + + + An error has occured, but can be recovered from. + + + + + A warning has been produced, but does not necessarily mean that something wrong has happened. + + + + + An important message that should be displayed to the user. + + + + + A message of low importance. + + + + + A message that would likely only interest a developer. + + + + + All log levels. + + + + + Helper methods for log level handling. + + + + + Gets the highest log level when there could potentially be multiple levels provided. + + The log level(s). + The highest log level supplied. + + + + Returns a translation of a log level to it's associated console colour. + + The log level(s). + A console color associated with the highest log level supplied. + + + + A generic log listener that receives log events and can route them to some output (e.g. file, console, socket). + + + + + Handle an incoming log event. + + Log source that sent the event. Don't use; instead use + Information about the log message. + + + + Log source that can output log messages. + + + + + Name of the log source. + + + + + Event that sends the log message. Call to send a log message. + + + + + A generic, multi-purpose log source. Exposes simple API to manually emit logs. + + + + + + + + + + + Creates a manual log source. + + Name of the log source. + + + + Logs a message with the specified log level. + + Log levels to attach to the message. Multiple can be used with bitwise ORing. + Data to log. + + + + Logs a message with level. + + Data to log. + + + + Logs a message with level. + + Data to log. + + + + Logs a message with level. + + Data to log. + + + + Logs a message with level. + + Data to log. + + + + Logs a message with level. + + Data to log. + + + + Logs a message with level. + + Data to log. + + + + + + + A source that routes all logs from API to BepInEx logger. + + + + + + Whether Trace logs are rerouted. + + + + + Creates a new trace log source. + + New log source (or already existing one). + + + + Internal log source. + + + + + Creates a new trace log source. + + + + + Writes a message to the underlying instance. + + The message to write. + + + + Writes a message and a newline to the underlying instance. + + The message to write. + + + + + + + + + + Logs entries using Unity specific outputs. + + + + + + + + + + + Logs entries using Unity specific outputs. + + + + + + + + + + + Logs entries using Unity specific outputs. + + + + + + + + + + + Creates a new Unity log source. + + + + + + + + Paths used by BepInEx + + + + + List of directories from where Mono will search assemblies before assembly resolving is invoked. + + + + + The directory that the core BepInEx DLLs reside in. + + + + + The path to the core BepInEx DLL. + + + + + The path to the main BepInEx folder. + + + + + The path of the currently executing program BepInEx is encapsulated in. + + + + + The directory that the currently executing process resides in. + On OSX however, this is the parent directory of the game.app folder. + + + + + The path to the Managed folder of the currently running Unity game. + + + + + The path to the config directory. + + + + + The path to the global BepInEx configuration file. + + + + + The path to temporary cache files. + + + + + The path to the patcher plugin folder which resides in the BepInEx folder. + + + + + The path to the plugin folder which resides in the BepInEx folder. + + This is ONLY guaranteed to be set correctly when Chainloader has been initialized. + + + + + + The name of the currently executing process. + + + + + Provides methods for running code on other threads and synchronizing with the main thread. + + + + + Current instance of the helper. + + + + + Gives methods for invoking delegates on the main unity thread, both synchronously and asynchronously. + Can be used in many built-in framework types, for example + and to make their events fire on the main unity thread. + + + + + Queue the delegate to be invoked on the main unity thread. Use to synchronize your threads. + + + + + Queue the delegate to be invoked on a background thread. Use this to run slow tasks without affecting the game. + NOTE: Most of Unity API can not be accessed while running on another thread! + + + Task to be executed on another thread. Can optionally return an Action that will be executed on the main thread. + You can use this action to return results of your work safely. Return null if this is not needed. + + + + + False if current code is executing on the main unity thread, otherwise True. + Warning: Will return true before the first frame finishes (i.e. inside plugin Awake and Start methods). + + + + + + Convenience extensions for utilizing multiple threads and using the . + + + + + + + + Apply a function to a collection of data by spreading the work on multiple threads. + Outputs of the functions are returned to the current thread and yielded one by one. + + Type of the input values. + Type of the output values. + Input values for the work function. + Function to apply to the data on multiple threads at once. + Number of worker threads. By default SystemInfo.processorCount is used. + An exception was thrown inside one of the threads, and the operation was aborted. + Need at least 1 workerCount. + + + + Generic helper properties and methods. + + + + + Whether current Common Language Runtime supports dynamic method generation using namespace. + + + + + An encoding for UTF-8 which does not emit a byte order mark (BOM). + + + + + Try to perform an action. + + Action to perform. + Possible exception that gets returned. + True, if action succeeded, false if an exception occured. + + + + Combines multiple paths together, as the specific method is not available in .NET 3.5. + + The multiple paths to combine together. + A combined path. + + + + Returns the parent directory of a path, optionally specifying the amount of levels. + + The path to get the parent directory of. + The amount of levels to traverse. Defaults to 1 + The parent directory. + + + + Tries to parse a bool, with a default value if unable to parse. + + The string to parse + The value to return if parsing is unsuccessful. + Boolean value of input if able to be parsed, otherwise default value. + + + + Converts a file path into a UnityEngine.WWW format. + + The file path to convert. + A converted file path. + + + + Indicates whether a specified string is null, empty, or consists only of white-space characters. + + The string to test. + True if the value parameter is null or empty, or if value consists exclusively of white-space characters. + + + + Sorts a given dependency graph using a direct toposort, reporting possible cyclic dependencies. + + Nodes to sort + Function that maps a node to a collection of its dependencies. + Type of the node in a dependency graph. + Collection of nodes sorted in the order of least dependencies to the most. + Thrown when a cyclic dependency occurs. + + + + Checks whether a given cecil type definition is a subtype of a provided type. + + Cecil type definition + Type to check against + Whether the given cecil type is a subtype of the type. + + + + Try to resolve and load the given assembly DLL. + + Name of the assembly, of the type . + Directory to search the assembly from. + The loaded assembly. + True, if the assembly was found and loaded. Otherwise, false. + + + + Try to resolve and load the given assembly DLL. + + Name of the assembly, of the type . + Directory to search the assembly from. + Reader parameters that contain possible custom assembly resolver. + The loaded assembly. + True, if the assembly was found and loaded. Otherwise, false. + + + + Tries to create a file with the given name + + Path of the file to create + File open mode + Resulting filestream + File access options + File share options + + + + + Try to parse given string as an assembly name + + Fully qualified assembly name + Resulting instance + true, if parsing was successful, otherwise false + + On some versions of mono, using fails because it runs on unmanaged side + which has problems with encoding. + Using solves this by doing parsing on managed side instead. + + + + + Gets unique files in all given directories. If the file with the same name exists in multiple directories, + only the first occurrence is returned. + + Directories to search from. + File pattern to search. + Collection of all files in the directories. + + + + Console class with safe handlers for Unity 4.x, which does not have a proper Console implementation + + + + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/HarmonyXInterop.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/HarmonyXInterop.dll new file mode 100644 index 00000000..ca690b19 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/HarmonyXInterop.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Mdb.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Mdb.dll new file mode 100644 index 00000000..bddf5cbd Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Mdb.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Pdb.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Pdb.dll new file mode 100644 index 00000000..9227f6db Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Pdb.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Rocks.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Rocks.dll new file mode 100644 index 00000000..a77ac871 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.Rocks.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.dll new file mode 100644 index 00000000..18735f93 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/Mono.Cecil.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.dll new file mode 100644 index 00000000..5709bbbd Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.xml new file mode 100644 index 00000000..45e9d3b6 --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.RuntimeDetour.xml @@ -0,0 +1,178 @@ + + + + MonoMod.RuntimeDetour + + + + + A fully managed detour. + Multiple Detours for a method to detour from can exist at any given time. Detours can be layered. + If you're writing your own detour manager or need to detour native functions, it's better to create instances of NativeDetour instead. + + + + + Mark the detour as applied in the detour chain. This can be done automatically when creating an instance. + + + + + Undo the detour without freeing it, allowing you to reapply it later. + + + + + Free the detour, while also permanently undoing it. This makes any further operations on this detour invalid. + + + + + Undo and free this temporary detour. + + + + + Generate a new DynamicMethod with which you can invoke the previous state. + + + + + Generate a new DynamicMethod with which you can invoke the previous state. + + + + + Generate a new DynamicMethod with which you can invoke the previous state. + + + + + A "raw" native detour, acting as a wrapper around NativeDetourData with a few helpers. + Only one NativeDetour for a method to detour from can exist at any given time. NativeDetours cannot be layered. + If you don't need the trampoline generator or any of the management helpers, use DetourManager.Native directly. + Unless you're writing your own detour manager or need to detour native functions, it's better to create instances of Detour instead. + + + + + Apply the native detour. This can be done automatically when creating an instance. + + + + + Undo the native detour without freeing the detour native data, allowing you to reapply it later. + + + + + Changes the source of this native detour to a new source address. This does not repair the old source location. + This also assumes that is simply a new address for the same method as this was constructed with. + + The new source location. + + + + Changed the target of this native detour to a new target. + + The new target address. + + + + Free the detour's data without undoing it. This makes any further operations on this detour invalid. + + + + + Undo and free this temporary detour. + + + + + Generate a new DynamicMethod with which you can invoke the previous state. + If the NativeDetour holds a reference to a managed method, a copy of the original method is returned. + If the NativeDetour holds a reference to a native function, an "undo-call-redo" trampoline with a matching signature is returned. + + + + + Generate a new delegate with which you can invoke the previous state. + If the NativeDetour holds a reference to a managed method, a copy of the original method is returned. + If the NativeDetour holds a reference to a native function, an "undo-call-redo" trampoline with a matching signature is returned. + + + + + Write the given value at the address to + offs, afterwards advancing offs by sizeof(byte). + + + + + Write the given value at the address to + offs, afterwards advancing offs by sizeof(ushort). + + + + + Write the given value at the address to + offs, afterwards advancing offs by sizeof(ushort). + + + + + Write the given value at the address to + offs, afterwards advancing offs by sizeof(ulong). + + + + + Generate a DynamicMethod to easily call the given native function from another DynamicMethod. + + The pointer to the native function to call. + A MethodBase with the target function's signature. + The detoured DynamicMethod. + + + + Fill the DynamicMethodDefinition with a throw. + + + + + Emit a call to DetourManager.Native.Copy using the given parameters. + + + + + Emit a call to DetourManager.Native.Apply using a copy of the given data. + + + + + The data forming a "raw" native detour, created and consumed by DetourManager.Native. + + + + + The method to detour from. Set when the structure is created by the IDetourNativePlatform. + + + + + The target method to be called instead. Set when the structure is created by the IDetourNativePlatform. + + + + + The type of the detour. Determined when the structure is created by the IDetourNativePlatform. + + + + + The size of the detour. Calculated when the structure is created by the IDetourNativePlatform. + + + + + DetourManager.Native-specific data. + + + + diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.dll b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.dll new file mode 100644 index 00000000..1d9fb357 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.dll differ diff --git a/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.xml b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.xml new file mode 100644 index 00000000..96ba37f4 --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/BepInEx/core/MonoMod.Utils.xml @@ -0,0 +1,1470 @@ + + + + MonoMod.Utils + + + + + An IL manipulation "context" with various helpers and direct access to the MethodBody. + + + + + The manipulator callback, accepted by the Invoke method. + + + + + + The manipulated method. + + + + + The manipulated method's IL processor. + + + + + The manipulated method body. + + + + + The manipulated method's module. + + + + + The manipulated method instructions. + + + + + A readonly list of all defined labels. + + + + + Has the context been made read-only? No further method access is possible, but the context has not yet been disposed. + + + + + Events which run when the context will be disposed. + + + + + The current reference bag. Used for methods such as EmitReference and EmitDelegate. + + + + + Invoke a given manipulator callback. + + The manipulator to run in this context. + + + + Mark this ILContext as read-only and prevent this context from further accessing the originally passed method. + + + If the method is altered prior to calling MakeReadOnly or afterwards by accessing the method directly, the results are undefined. + + + + + See + + + + + See + + + + + See + + + + + Define a new label to be marked with a cursor. + + A label without a target instruction. + + + + Define a new label pointing at a given instruction. + + The instruction the label will point at. + A label pointing at the given instruction. + + + + Determine the index of a given instruction. + + The instruction to get the index of. + The instruction index, or the end of the method body if it hasn't been found. + + + + Obtain all labels pointing at the given instruction. + + The instruction to get all labels for. + All labels targeting the given instruction. + + + + Bind an arbitary object to an ILContext for static retrieval. + + The type of the object. The combination of typeparam and id provides the unique static reference. + The object to store. + The id to use in combination with the typeparam for object retrieval. + + + + Dispose this context, making it read-only and invoking all OnDispose event listeners. + + + + + Obtain a string representation of this context (method ID and body). + + A string representation of this context. + + + + Specifies where a ILCursor should be positioned in relation to the target of a search function + + + + + Move the cursor before the first instruction in the match + + + + + Equivalent to Before with `cursor.MoveAfterLabels()` causing emitted instructions to become the target of incoming labels + + + + + Move the cursor after the last instruction in the match + + + + + Indicates whether the position of a ILCursor is the result of a search function and + if the next search should ignore the instruction preceeding or following this cursor. + + SearchTarget.Next is the result of searching with MoveType.Before, and SearchTarget.Prev from MoveType.After + + + + + A foward searching function cannot match the Next instruction and must move the cursor forward + + + + + A reverse searching function cannot match the Next instruction and must move the cursor backward + + + + + A cursor used to manipulate a method body in an ILContext. + + + + + The context to which this cursor belongs to. + + + + + The instruction immediately following the cursor position or null if the cursor is at the end of the instruction list. + + + + + The instruction immediately preceding the cursor position or null if the cursor is at the start of the instruction list. + + + + + The instruction immediately preceding the cursor position or null if the cursor is at the start of the instruction list. + + + + + The index of the instruction immediately following the cursor position. Range: 0 to Instrs.Count + Setter accepts negative indexing by adding Instrs.Count to the operand + + + + + Indicates whether the position of a MMILCursor is the result of a search function and + if the next search should ignore the instruction preceeding or following this cursor. + + See + + + + + Enumerates all labels which point to the current instruction (label.Target == Next) + + + + + See + + + + + See + + + + + See + + + + + See + + + + + See + + + + + Create a clone of this cursor. + + The cloned cursor. + + + + Is this cursor before the given instruction? + + The instruction to check. + True if this cursor is before the given instruction, false otherwise. + + + + Is this cursor after the given instruction? + + The instruction to check. + True if this cursor is after the given instruction, false otherwise. + + + + Obtain a string representation of this cursor (method ID, index, search target, surrounding instructions). + + A string representation of this cursor. + + + + Move the cursor to a target instruction. All other movements go through this. + + The target instruction + Where to move in relation to the target instruction and incoming labels (branches) + Whether to set the `SearchTarget` and skip the target instruction with the next search function + this + + + + Move the cursor after incoming labels (branches). If an instruction is emitted, all labels which currently point to Next, will point to the newly emitted instruction. + + this + + + + Move the cursor before incoming labels (branches). This is the default behaviour. Emitted instructions will not cause labels to change targets. + + this + + + + Move the cursor to a target index. Supports negative indexing. See + + this + + + + Overload for Goto(label.Target). defaults to MoveType.AfterLabel + + this + + + + Search forward and moves the cursor to the next sequence of instructions matching the corresponding predicates. See also + + this + If no match is found + + + + Search forward and moves the cursor to the next sequence of instructions matching the corresponding predicates. + + True if a match was found + + + + Search backward and moves the cursor to the next sequence of instructions matching the corresponding predicates. See also + + this + If no match is found + + + + Search backward and moves the cursor to the next sequence of instructions matching the corresponding predicates. + + True if a match was found + + + + Find the next occurences of a series of instructions matching the given set of predicates with gaps permitted. + + An array of cursors corresponding to each found instruction (MoveType.Before) + If no match is found + + + + Find the next occurences of a series of instructions matching the given set of predicates with gaps permitted. + + An array of cursors corresponding to each found instruction (MoveType.Before) + True if a match was found + + + + Search backwards for occurences of a series of instructions matching the given set of predicates with gaps permitted. + + An array of cursors corresponding to each found instruction (MoveType.Before) + If no match is found + + + + Search backwards for occurences of a series of instructions matching the given set of predicates with gaps permitted. + + An array of cursors corresponding to each found instruction (MoveType.Before) + True if a match was found + + + + Set the target of a label to the current position (label.Target = Next) and moves after it. + + The label to mark + + + + Create a new label targetting the current position (label.Target = Next) and moves after it. + + The newly created label + + + + Create a new label for use with + + A new label with no target + + + + Remove the Next instruction + + + + + Remove several instructions + + + + + Move the cursor and all labels the cursor is positioned after to a target instruction + + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position. + + The instruction opcode. + The instruction operand. + this + + + + Emit a new instruction at this cursor's current position, accessing a given member. + + The type in which the member is defined. + The instruction opcode. + The accessed member name. + this + + + + Bind an arbitary object to an ILContext for static retrieval. See + + + + + Emit the IL to retrieve a stored reference of type with the given and place it on the stack. + + + + + Store an object in the reference store, and emit the IL to retrieve it and place it on the stack. + + + + + Emit the IL to invoke a delegate as if it were a method. Stack behaviour matches OpCodes.Call + + + + + A label to be used in ILContexts. + + + + + The target instruction this label points at. + + + + + All instructions using this label. + + + + + An IL inline reference bag used for ILContexts. + + + + + Get the object for the given ID. + + The object type. + The object ID. + The stored object. + + + + Get a MethodInfo for the getter. + + The object type. + The getter method. + + + + Store a new object. + + The object type. + The object to be stored. + An ID to be used for all further operations. + + + + Remove the object with the given ID from the bag, essentially clearing the ID's slot. + + The object type. + The object ID. + + + + Get a MethodInfo invoking a delegate of the given type, with the delegate at the top of the stack. Used by . + + The delegate type. + A MethodInfo invoking a delegate of the given type. + + + + The default IL reference bag. Throws NotSupportedException for every operation. + + + + + An IL reference bag implementation to be used for runtime-generated methods. + + + + + Collection of extensions used by MonoMod and other projects. + + + + + Create a hexadecimal string for the given bytes. + + The input bytes. + The output hexadecimal string. + + + + Invokes all delegates in the invocation list, passing on the result to the next. + + Type of the result. + The multicast delegate. + The initial value and first parameter. + Any other arguments that may be passed. + The result of all delegates. + + + + Invokes all delegates in the invocation list, as long as the previously invoked delegate returns true. + + + + + Invokes all delegates in the invocation list, as long as the previously invoked delegate returns false. + + + + + Invokes all delegates in the invocation list, as long as the previously invoked delegate returns null. + + + + + Split PascalCase words to become Pascal Case instead. + + PascalCaseString + Pascal Case String + + + + Read the string from the BinaryReader BinaryWriter in a C-friendly format. + + The input which the method reads from. + The output string. + + + + Write the string to the BinaryWriter in a C-friendly format. + + The output which the method writes to. + The input string. + + + + Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates). + + The input delegate. + The output delegate. + + + + Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates). + + The input delegate. + The wanted output delegate type. + The output delegate. + + + + Print the exception to the console, including extended loading / reflection data useful for mods. + + + + + Get the method of interest for a given state machine method. + + The method creating the state machine. + The "main" method in the state machine. + + + + Gets the actual generic method definition of a method, as defined on the fully open type. + + The potentially instantiated method to find the definition of. + The original method definition, with no generic arguments filled in. + + + + Safely resolve a reference, silently discarding any exceptions. + + The reference to resolve. + The resolved definition or null. + + + + Safely resolve a reference, silently discarding any exceptions. + + The reference to resolve. + The resolved definition or null. + + + + Safely resolve a reference, silently discarding any exceptions. + + The reference to resolve. + The resolved definition or null. + + + + Safely resolve a reference, silently discarding any exceptions. + + The reference to resolve. + The resolved definition or null. + + + + Get a certain custom attribute from an attribute provider. + + The attribute provider. + The custom attribute name. + The first matching custom attribute, or null if no matching attribute has been found. + + + + Determine if an attribute provider has got a specific custom attribute. + + The attribute provider. + The custom attribute name. + true if the attribute provider contains the given custom attribute, false otherwise. + + + + Get the integer value pushed onto the stack with this instruction. + + The instruction to get the pushed integer value for. + The pushed integer value. + + + + Get the integer value pushed onto the stack with this instruction. + + The instruction to get the pushed integer value for. + The pushed integer value or null. + + + + Determine if the method call is a base method call. + + The caller method body. + The called method. + True if the called method is a base method of the caller method, false otherwise. + + + + Determine if the given method can be preferably called using callvirt. + + The called method. + True if the called method can be called using callvirt, false otherwise. + + + + Determine if the given type is a struct (also known as "value type") or struct-alike (f.e. primitive). + + The type to check. + True if the type is a struct, primitive or similar, false otherwise. + + + + Get the long form opcode for any short form opcode. + + The short form opcode. + The long form opcode. + + + + Get the short form opcode for any long form opcode. + + The long form opcode. + The short form opcode. + + + + Calculate updated instruction offsets. Required for certain manual fixes. + + The method to recalculate the IL instruction offsets for. + + + + Fix (and optimize) any instructions which should use the long / short form opcodes instead. + + The method to apply the fixes to. + + + + Check if the signatures of a given System.Reflection and Mono.Cecil member reference match. + + The System.Reflection member reference. + The Mono.Cecil member reference. + True if both references share the same signature, false otherwise. + + + + Check if the signatures of a given System.Reflection and Mono.Cecil member reference match. + + The Mono.Cecil member reference. + The System.Reflection member reference. + True if both references share the same signature, false otherwise. + + + + See + + + + + See + + + + + See + + + + + See + + + + + See + + + + + Determine if two types are compatible with each other (f.e. object with string, or enums with their underlying integer type). + + The first type. + The second type. + True if both types are compatible with each other, false otherwise. + + + + Creates a delegate of the specified type from this method. + + The method to create the delegate from. + The type of the delegate to create. + The delegate for this method. + + + + Creates a delegate of the specified type with the specified target from this method. + + The method to create the delegate from. + The type of the delegate to create. + The object targeted by the delegate. + The delegate for this method. + + + + Creates a delegate of the specified type from this method. + + The method to create the delegate from. + The type of the delegate to create. + The delegate for this method. + + + + Creates a delegate of the specified type with the specified target from this method. + + The method to create the delegate from. + The type of the delegate to create. + The object targeted by the delegate. + The delegate for this method. + + + + Find a method for a given ID. + + The type to search in. + The method ID. + Whether to perform a simple search pass as well or not. + The first matching method or null. + + + + Find a method for a given ID recursively (including the passed type's base types). + + The type to search in. + The method ID. + Whether to perform a simple search pass as well or not. + The first matching method or null. + + + + Find a method for a given ID. + + The type to search in. + The method ID. + Whether to perform a simple search pass as well or not. + The first matching method or null. + + + + Find a method for a given ID recursively (including the passed type's base types). + + The type to search in. + The method ID. + Whether to perform a simple search pass as well or not. + The first matching method or null. + + + + Find a property for a given name. + + The type to search in. + The property name. + The first matching property or null. + + + + Find a property for a given name recursively (including the passed type's base types). + + The type to search in. + The property name. + The first matching property or null. + + + + Find a field for a given name. + + The type to search in. + The field name. + The first matching field or null. + + + + Find a field for a given name recursively (including the passed type's base types). + + The type to search in. + The field name. + The first matching field or null. + + + + Find an event for a given name. + + The type to search in. + The event name. + The first matching event or null. + + + + Find an event for a given name recursively (including the passed type's base types). + + The type to search in. + The event name. + The first matching event or null. + + + + Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. + + The method to get the ID for. + The name to use instead of the reference's own name. + The ID to use instead of the reference's declaring type ID. + Whether the type ID should be included or not. System.Reflection avoids it by default. + Whether the ID should be "simple" (name only). + The ID. + + + + Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. + + The call site to get the ID for. + The ID. + + + + Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. + + The method to get the ID for. + The name to use instead of the reference's own name. + The ID to use instead of the reference's declaring type ID. + Whether the type ID should be included or not. System.Reflection avoids it by default. + Whether the method is regarded as a proxy method or not. Setting this paramater to true will skip the first parameter. + Whether the ID should be "simple" (name only). + The ID. + + + + Get the "patch name" - the name of the target to patch - for the given member. + + The member to get the patch name for. + The patch name. + + + + Get the "patch name" - the name of the target to patch - for the given member. + + The member to get the patch name for. + The patch name. + + + + Clone the given method definition. + + The original method. + The method definition to apply the cloning process onto, or null to create a new method. + A clone of the original method. + + + + Clone the given method body. + + The original method body. + The method which will own the newly cloned method body. + A clone of the original method body. + + + + Force-update a generic parameter's position and type. + + The generic parameter to update. + The new position. + The new type. + The updated generic parameter. + + + + Resolve a given generic parameter in another context. + + The new context. + The original generic parameter. + A generic parameter provided by the given context which matches the original generic parameter. + + + + Relink the given member reference (metadata token provider). + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Relink the given type reference. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Relink the given method reference. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Relink the given callsite. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Relink the given field reference. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Relink the given parameter definition. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Clone the given parameter definition. + + The original parameter definition. + A clone of the original parameter definition. + + + + Relink the given custom attribute. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Clone the given custom attribute. + + The original custom attribute. + A clone of the original custom attribute. + + + + Relink the given generic parameter reference. + + The reference to relink. + The relinker to use during the relinking process. + The generic context provided to relink generic references. + A relinked reference. + + + + Clone the given generic parameter. + + The original generic parameter. + A clone of the original generic parameter. + + + + Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#. + Note that sizeof(t) != Marshal.SizeOf(t), f.e. when t is char. + + The type to get the size from. + The managed type size. + + + + Get a type which matches what the method should receive via ldarg.0 + + The method to obtain the "this" parameter type from. + The "this" parameter type. + + + + Get a native function pointer for a given method. This matches an IL-level ldftn. + + + The result of ldftn doesn't always match that of MethodHandle.GetFunctionPointer(). + For example, ldftn doesn't JIT-compile the method on mono, which thus keeps the class constructor untouched. + And on .NET, struct overrides (f.e. ToString) have got multiple entry points pointing towards the same code. + + The method to get a native function pointer for. + The native function pointer. + + + + A variant of ILGenerator which uses Mono.Cecil under the hood. + + + + + The underlying Mono.Cecil.Cil.ILProcessor. + + + + + Abstract version of System.Reflection.Emit.ILGenerator. See for proper documentation. + + + + + Get a "real" ILGenerator for this ILGeneratorShim. + + A "real" ILGenerator. + + + + Get the proxy type for a given ILGeneratorShim type. The proxy type implements ILGenerator. + + The ILGeneratorShim type. + The "real" ILGenerator type. + + + + Get the proxy type for a given ILGeneratorShim type. The proxy type implements ILGenerator. + + The ILGeneratorShim type. + The "real" ILGenerator type. + + + + Get the non-generic proxy type implementing ILGenerator. + + The "real" ILGenerator type, non-generic. + + + + A DynamicMethodDefinition "generator", responsible for generating a runtime MethodInfo from a DMD MethodDefinition. + + + + + + A DMDGenerator implementation using Mono.Cecil to build an in-memory assembly. + + + + + Fill the DynamicMethod with a stub. + + + + + Fill the DynamicMethod with a stub. + + + + + Emit a reference to an arbitrary object. Note that the references "leak." + + + + + Emit a reference to an arbitrary object. Note that the references "leak." + + + + + Emit a reference to an arbitrary object. Note that the references "leak." + + + + + Emit a reference to an arbitrary object. Note that the references "leak." + + + + + Allows you to remap library paths / names and specify loading flags. Useful for cross-platform compatibility. Applies only to DynDll. + + + + + Open a given library and get its handle. + + The library name. + Whether to skip using the mapping or not. + Any optional platform-specific flags. + The library handle. + + + + Try to open a given library and get its handle. + + The library name. + The library handle, or null if it failed loading. + Whether to skip using the mapping or not. + Any optional platform-specific flags. + True if the handle was obtained, false otherwise. + + + + Release a library handle obtained via OpenLibrary. Don't release the result of OpenLibrary(null)! + + The library handle. + + + + Get a function pointer for a function in the given library. + + The library handle. + The function name. + The function pointer. + + + + Get a function pointer for a function in the given library. + + The library handle. + The function name. + The function pointer, or null if it wasn't found. + True if the function pointer was obtained, false otherwise. + + + + Extension method wrapping Marshal.GetDelegateForFunctionPointer + + + + + Fill all static delegate fields with the DynDllImport attribute. + Call this early on in the static constructor. + + The type containing the DynDllImport delegate fields. + Any optional mappings similar to the static mappings. + + + + Fill all instance delegate fields with the DynDllImport attribute. + Call this early on in the constructor. + + An instance of a type containing the DynDllImport delegate fields. + Any optional mappings similar to the static mappings. + + + + Similar to DllImport, but requires you to run typeof(DeclaringType).ResolveDynDllImports(); + + + + + The library or library alias to use. + + + + + A list of possible entrypoints that the function can be resolved to. Implicitly includes the field name and delegate name. + + + + The library or library alias to use. + A list of possible entrypoints that the function can be resolved to. Implicitly includes the field name and delegate name. + + + + A mapping entry, to be used by . + + + + + The name as which the library will be resolved as. Useful to remap libraries or to provide full paths. + + + + + Platform-dependent loading flags. + + + + The name as which the library will be resolved as. Useful to remap libraries or to provide full paths. + Platform-dependent loading flags. + + + + The relinker callback delegate type. + + The reference (metadata token provider) to relink. + The generic context provided to relink generic references. + A relinked reference. + + + + Generic platform enum. + + + + + Bit applied to all OSes (Unknown, Windows, MacOS, ...). + + + + + On demand 64-bit platform bit. + + + + + Applied to all NT and NT-oid platforms (Windows). + + + + + Applied to all Unix and Unix-oid platforms (macOS, Linux, ...). + + + + + On demand ARM platform bit. + + + + + On demand Wine bit. DON'T RELY ON THIS. + + + + + Unknown OS. + + + + + Windows, using the NT kernel. + + + + + macOS, using the Darwin kernel. + + + + + Linux. + + + + + Android, using the Linux kernel. + + + + + iOS, sharing components with macOS. + + + + diff --git a/ThirdParty/BepInEx 5.4.21/LICENSE b/ThirdParty/BepInEx 5.4.21/LICENSE new file mode 100644 index 00000000..6e409d03 --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/LICENSE @@ -0,0 +1,233 @@ +Skip to content +Search or jump to… +Pull requests +Issues +Codespaces +Marketplace +Explore + +@cheese3660 +BepInEx +/ +BepInEx.ConfigurationManager +Public +Fork your own copy of BepInEx/BepInEx.ConfigurationManager +Code +Issues +7 +Pull requests +1 +Actions +Projects +Security +Insights +Beta Try the new code view +BepInEx.ConfigurationManager/LICENSE +BepInEx/BepInEx.ConfigurationManager is licensed under the + +GNU Lesser General Public License v3.0 +Permissions of this copyleft license are conditioned on making available complete source code of licensed works and modifications under the same license or the GNU GPLv3. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work. + +Permissions + Commercial use + Modification + Distribution + Patent use + Private use +Limitations + Liability + Warranty +Conditions + License and copyright notice + Disclose source + State changes + Same license (library) +This is not legal advice. Learn more about repository licenses. +@ghorsington +ghorsington Changle GPL to LGPL +Latest commit 209602a on Jul 28, 2020 + History + 2 contributors +@ghorsington@ManlyMarco +165 lines (128 sloc) 7.47 KB + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. +Footer +© 2023 GitHub, Inc. +Footer navigation +Terms +Privacy +Security +Status +Docs +Contact GitHub +Pricing +API +Training +Blog +About +BepInEx.ConfigurationManager/LICENSE at master · BepInEx/BepInEx.ConfigurationManager \ No newline at end of file diff --git a/ThirdParty/BepInEx 5.4.21/README b/ThirdParty/BepInEx 5.4.21/README new file mode 100644 index 00000000..c5059afb --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/README @@ -0,0 +1,2 @@ +This contains binaries for BepInEx, which is under the LGPL V3 license, copy of which is provided here. +The source for these binaries can be found at https://github.com/BepInEx/BepInEx \ No newline at end of file diff --git a/ThirdParty/BepInEx 5.4.21/changelog.txt b/ThirdParty/BepInEx 5.4.21/changelog.txt new file mode 100644 index 00000000..36308c6d --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/changelog.txt @@ -0,0 +1,7 @@ +4 commits since v5.4.20 + +Changelog (excluding merges): +* (0d06996) [ghorsington] UnityInput: revert to null input in case of total failure +* (ea709e2) [ghorsington] Bump version +* (806d6d2) [ghorsington] UnityInput: remove hard dependency on Unity.InputManager (fixes #446) +* (a79d657) [ghorsington] UnityInput: Reformat, fix LegacyInputSystemAvailable not being static \ No newline at end of file diff --git a/ThirdParty/BepInEx 5.4.21/doorstop_config.ini b/ThirdParty/BepInEx 5.4.21/doorstop_config.ini new file mode 100644 index 00000000..a68f30f1 --- /dev/null +++ b/ThirdParty/BepInEx 5.4.21/doorstop_config.ini @@ -0,0 +1,16 @@ +[UnityDoorstop] +# Specifies whether assembly executing is enabled +enabled=true +# Specifies the path (absolute, or relative to the game's exe) to the DLL/EXE that should be executed by Doorstop +targetAssembly=BepInEx\core\BepInEx.Preloader.dll +# Specifies whether Unity's output log should be redirected to \output_log.txt +redirectOutputLog=false +# If enabled, DOORSTOP_DISABLE env var value is ignored +# USE THIS ONLY WHEN ASKED TO OR YOU KNOW WHAT THIS MEANS +ignoreDisableSwitch=false +# Overrides default Mono DLL search path +# Sometimes it is needed to instruct Mono to seek its assemblies from a different path +# (e.g. mscorlib is stripped in original game) +# This option causes Mono to seek mscorlib and core libraries from a different folder before Managed +# Original Managed folder is added as a secondary folder in the search path +dllSearchPathOverride= \ No newline at end of file diff --git a/ThirdParty/BepInEx 5.4.21/winhttp.dll b/ThirdParty/BepInEx 5.4.21/winhttp.dll new file mode 100644 index 00000000..bdf9c790 Binary files /dev/null and b/ThirdParty/BepInEx 5.4.21/winhttp.dll differ diff --git a/ThirdParty/ConfigurationManager/ConfigurationManager.dll b/ThirdParty/ConfigurationManager/ConfigurationManager.dll new file mode 100644 index 00000000..ef1e7073 Binary files /dev/null and b/ThirdParty/ConfigurationManager/ConfigurationManager.dll differ diff --git a/ThirdParty/ConfigurationManager/ConfigurationManager.xml b/ThirdParty/ConfigurationManager/ConfigurationManager.xml new file mode 100644 index 00000000..fb742bb1 --- /dev/null +++ b/ThirdParty/ConfigurationManager/ConfigurationManager.xml @@ -0,0 +1,197 @@ + + + + ConfigurationManager + + + + + Get entries for all core BepInEx settings + + + + + Get entries for all settings of a plugin + + + + + An easy way to let user configure how a plugin behaves without the need to make your own GUI. The user can change any of the settings you expose, even keyboard shortcuts. + https://github.com/ManlyMarco/BepInEx.ConfigurationManager + + + + + GUID of this plugin + + + + + Version constant + + + + + Event fired every time the manager window is shown or hidden. + + + + + Disable the hotkey check used by config manager. If enabled you have to set to show the manager. + + + + + + + + Is the config manager main window displayed on screen + + + + + Register a custom setting drawer for a given type. The action is ran in OnGui in a single setting slot. + Do not use any Begin / End layout methods, and avoid raising height from standard. + + + + + Rebuild the setting list. Use to update the config manager window if config settings were removed or added while it was open. + + + + + String currently entered into the search box + + + + + Class representing all data about a setting collected by ConfigurationManager. + + + + + List of values this setting can take + + + + + Range of the values this setting can take + + + + + Should the setting be shown as a percentage (only applies to value range settings) + + + + + Custom setting draw action + + + + + Show this setting in the settings screen at all? If false, don't show. + + + + + Category the setting is under. Null to be directly under the plugin. + + + + + If set, a "Default" button will be shown next to the setting to allow resetting to default. + + + + + Force the "Reset" button to not be displayed, even if a valid DefaultValue is available. + + + + + Force the setting name to not be displayed. Should only be used with a to get more space. + Can be used together with to gain even more space. + + + + + Optional description shown when hovering over the setting + + + + + Name of the setting + + + + + Plugin this setting belongs to + + + + + Only allow showing of the value. False whenever possible by default. + + + + + Type of the variable + + + + + Instance of the plugin that owns this setting + + + + + Is this setting advanced + + + + + Order of the setting on the settings list relative to other settings in a category. 0 by default, lower is higher on the list. + + + + + Get the value of this setting + + + + + Set the value of this setting + + + + + Implementation of + + + + + Custom converter from setting type to string for the textbox + + + + + Custom converter from string to setting type for the textbox + + + + + Arguments representing a change in value + + + + + + + + Newly assigned value + + + + diff --git a/ThirdParty/ConfigurationManager/LICENSE b/ThirdParty/ConfigurationManager/LICENSE new file mode 100644 index 00000000..6e409d03 --- /dev/null +++ b/ThirdParty/ConfigurationManager/LICENSE @@ -0,0 +1,233 @@ +Skip to content +Search or jump to… +Pull requests +Issues +Codespaces +Marketplace +Explore + +@cheese3660 +BepInEx +/ +BepInEx.ConfigurationManager +Public +Fork your own copy of BepInEx/BepInEx.ConfigurationManager +Code +Issues +7 +Pull requests +1 +Actions +Projects +Security +Insights +Beta Try the new code view +BepInEx.ConfigurationManager/LICENSE +BepInEx/BepInEx.ConfigurationManager is licensed under the + +GNU Lesser General Public License v3.0 +Permissions of this copyleft license are conditioned on making available complete source code of licensed works and modifications under the same license or the GNU GPLv3. Copyright and license notices must be preserved. Contributors provide an express grant of patent rights. However, a larger work using the licensed work through interfaces provided by the licensed work may be distributed under different terms and without source code for the larger work. + +Permissions + Commercial use + Modification + Distribution + Patent use + Private use +Limitations + Liability + Warranty +Conditions + License and copyright notice + Disclose source + State changes + Same license (library) +This is not legal advice. Learn more about repository licenses. +@ghorsington +ghorsington Changle GPL to LGPL +Latest commit 209602a on Jul 28, 2020 + History + 2 contributors +@ghorsington@ManlyMarco +165 lines (128 sloc) 7.47 KB + + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. +Footer +© 2023 GitHub, Inc. +Footer navigation +Terms +Privacy +Security +Status +Docs +Contact GitHub +Pricing +API +Training +Blog +About +BepInEx.ConfigurationManager/LICENSE at master · BepInEx/BepInEx.ConfigurationManager \ No newline at end of file diff --git a/ThirdParty/ConfigurationManager/README b/ThirdParty/ConfigurationManager/README new file mode 100644 index 00000000..019b6aef --- /dev/null +++ b/ThirdParty/ConfigurationManager/README @@ -0,0 +1,2 @@ +This contains binaries for BepInEx.ConfigurationManager, which is under the LGPL V3 license, copy of which is provided here. +The source for these binaries can be found at https://github.com/BepInEx/BepInEx.ConfigurationManager \ No newline at end of file diff --git a/builder.py b/builder.py index 366b5e74..6804f853 100644 --- a/builder.py +++ b/builder.py @@ -4,16 +4,15 @@ import subprocess import zipfile -DOORSTOP_DIR = os.path.abspath("Doorstop") -BUILD_DIR = os.path.abspath("build") -BUNDLES_DIR = os.path.abspath("Bundles") + +TEMPLATE_DIR = os.path.abspath("SpaceWarpBuildTemplate") SPACEWARP_DIR = os.path.abspath("SpaceWarp") +BUILD_DIR = os.path.abspath("build") +THIRD_PARTY = os.path.abspath("ThirdParty") -parser = argparse.ArgumentParser() +parser = argparse.ArgumentParser() parser.add_argument("-r", "--release", help="Build a release version", action="store_true") -parser.add_argument("-t", "--target", help="Build target", choices=["bepinex", "doorstop"], default="doorstop") -parser.add_argument("-a", "--all", help="Build all targets", action="store_true") def clean(): if os.path.exists(BUILD_DIR): @@ -25,30 +24,26 @@ def clean(): if os.path.exists(os.path.join(SPACEWARP_DIR, "obj")): shutil.rmtree(os.path.join(SPACEWARP_DIR, "obj")) -def build(release = False, doorstop = False): - build_type = "Doorstop" if doorstop else "BepInEx" - dotnet_args = ["dotnet", "build", os.path.join(SPACEWARP_DIR, "SpaceWarp.csproj"), "-c", "Release" if release else "Debug"] +def build(release = False): + dotnet_args = ["dotnet", "build", os.path.join(SPACEWARP_DIR,"SpaceWarp.csproj"), "-c", "Release" if release else "Debug"] build_output_dir = os.path.join(SPACEWARP_DIR, "bin", "Release" if release else "Debug") - output_dir = os.path.join(BUILD_DIR, build_type, "BepInEx", "plugins", "SpaceWarp") - - if doorstop: - dotnet_args.append("-p:DefineConstants=\"DOORSTOP_BUILD\"") - output_dir = os.path.join(BUILD_DIR, build_type, "SpaceWarp", "core") - + output_dir = os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "SpaceWarp") + # copy over the internals of the template print("=> Creating build directory...") - - os.makedirs(output_dir) - - if doorstop: - print("=> Copying doorstop DLLs...") - - for file in os.listdir(DOORSTOP_DIR): - shutil.copyfile(os.path.join(DOORSTOP_DIR, file), os.path.join(BUILD_DIR, build_type, file)) + os.makedirs(os.path.join(BUILD_DIR,"SpaceWarp"),True) + print("=> Copying BepInEx") + os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins"),True) + shutil.copytree(os.path.join(THIRD_PARTY,"BepInEx 5.4.21"),os.path.join(BUILD_DIR,"SpaceWarp"),dirs_exist_ok=True) + print("=> Copying BepInEx.ConfigurationManager") + os.makedirs(os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "ConfigurationManager"),True) + shutil.copytree(os.path.join(THIRD_PARTY,"ConfigurationManager"), os.path.join(BUILD_DIR, "SpaceWarp", "BepInEx", "plugins", "ConfigurationManager"),dirs_exist_ok=True) + + print("=> Copying output template") + shutil.copytree(TEMPLATE_DIR,output_dir) print(f"=> Executing: {' '.join(dotnet_args)}") output = subprocess.run(args=dotnet_args, capture_output=True) - print(" |=>| STDOUT") for line in str(output.stdout, "utf-8").splitlines(): @@ -60,52 +55,11 @@ def build(release = False, doorstop = False): print(f" {line}") print("=> Copying build outputs...") - def shutil_copy(file): shutil.copyfile(os.path.join(build_output_dir,file),os.path.join(output_dir,file)) - - to_transfer = [ - "0Harmony.dll", - "Mono.Cecil.dll", - "Mono.Cecil.Mdb.dll", - "Mono.Cecil.Pdb.dll", - "Mono.Cecil.Rocks.dll", - "MonoMod.RuntimeDetour.dll", - "MonoMod.Utils.dll", - "Microsoft.CodeAnalysis.dll", - "Microsoft.CodeAnalysis.CSharp.dll", - "System.Collections.Immutable.dll", - "System.Buffers.dll", - "System.Memory.dll", - "System.Reflection.Metadata.dll", - "System.Runtime.CompilerServices.Unsafe.dll", - "System.Text.Encoding.CodePages.dll", - "System.Threading.Tasks.Extensions.dll", - "System.Numerics.Vectors.dll", - ] - - if doorstop: - for file in to_transfer: - shutil_copy(file) - - if not release and os.path.exists(os.path.join(build_output_dir, "SpaceWarp.pdb")): - shutil.copyfile(os.path.join(build_output_dir, "SpaceWarp.pdb"), os.path.join(output_dir, "SpaceWarp.pdb")) - - shutil.copyfile(os.path.join(build_output_dir, "SpaceWarp.dll"), os.path.join(output_dir, "SpaceWarp.dll")) - - print("=> Finalizing build...") - - os.makedirs(os.path.join(BUILD_DIR, build_type, "SpaceWarp", "assets", "bundles")) - os.makedirs(os.path.join(BUILD_DIR, build_type, "SpaceWarp", "Mods")) - - with open(os.path.join(BUILD_DIR, build_type, "SpaceWarp", "Mods","mods_folder.txt"),"w") as mods_folder_txt: - mods_folder_txt.write("Mods go here") - - for bundle in os.listdir(BUNDLES_DIR): - if bundle.endswith(".bundle"): - shutil.copyfile(os.path.join(BUNDLES_DIR, bundle), os.path.join(BUILD_DIR, build_type, "SpaceWarp", "assets", "bundles", bundle)) - + shutil_copy("SpaceWarp.pdb") + shutil_copy("SpaceWarp.dll") def create_zip_name(prefix): git_output = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True) @@ -119,49 +73,25 @@ def mkzip(in_dir, out_zip): for root, dirs, files in os.walk(in_dir): for file in files: handle.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), in_dir)) - handle.close() -def compress(doorstop = False, release = False): - target_name = "Doorstop" if doorstop else "BepInEx" +def compress(release = False): release_target = "Release" if release else "Debug" - - mkzip(os.path.join(BUILD_DIR, target_name), create_zip_name(f"SpaceWarp-{target_name}-{release_target}")) - + mkzip(os.path.join(BUILD_DIR,"SpaceWarp"),create_zip_name(f"SpaceWarp-{release_target}")) + def main(): args = parser.parse_args() - - doorstop = args.target == "doorstop" - target_name = "Doorstop" if args.target == "doorstop" else "BepInEx" - total_steps = 5 if args.all else 3 - + total_steps = 3 print(f"====> [1/{total_steps}] Cleaning...") clean() + + print(f"====> [2/{total_steps}] Building...") - if args.all: - print(f"====> [2/{total_steps}] Building for BepInEx...") - - build(args.release, False) + build(args.release) - print(f"====> [3/{total_steps}] Building for Doorstop...") - - build(args.release, True) - - print(f"====> [4/{total_steps}] Compressing BepInEx build...") - - compress(False, args.release) - - print(f"====> [5/{total_steps}] Compressing Doorstop build...") - - compress(True, args.release) - else: - print(f"====> [2/{total_steps}] Building for {target_name}...") - - build(args.release, doorstop) - - print(f"====> [3/{total_steps}] Compressing {target_name} build...") - - compress(doorstop, args.release) + print(f"====> [3/{total_steps}] Compressing...") + + compress(args.release) -main() +main() \ No newline at end of file diff --git a/example_mod_info.json b/example_mod_info.json deleted file mode 100644 index aed175b1..00000000 --- a/example_mod_info.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "mod_id": "[SHOULD BE THE SAME AS FOLDER NAME]", - "name": "[DESCRIPTIVE NAME OF MOD]", - "author": "", - "description": "", - "source": "", - "version": "", - "dependencies": [ - { - "id": "example_mod", - "version": { - "min": "0.0.0", - "max": "9.9.9 (can be * for no max version)" - } - } - ], - "ksp2_version": { - "min": "...", - "max": "... (can be * for no max version)" - } -} \ No newline at end of file