From 2b0c12bad4d7ca5cd4b4af7a33771e9c89d696a9 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:56:34 +0100 Subject: [PATCH 01/13] DebugUI (#6) --- .../Patches/Fixes/DebugUIHandlerPatch.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 ContentAPI/Patches/Fixes/DebugUIHandlerPatch.cs diff --git a/ContentAPI/Patches/Fixes/DebugUIHandlerPatch.cs b/ContentAPI/Patches/Fixes/DebugUIHandlerPatch.cs new file mode 100644 index 0000000..5d5197d --- /dev/null +++ b/ContentAPI/Patches/Fixes/DebugUIHandlerPatch.cs @@ -0,0 +1,26 @@ +namespace ContentAPI.Patches.Fixes +{ +#pragma warning disable SA1313 +#pragma warning disable SA1402 + using HarmonyLib; + using UnityEngine; + using Zorro.Core.CLI; + + /// + /// Patch for adding back the debug ui. + /// + [HarmonyPatch(typeof(DebugUIHandler), "Update")] + internal class DebugUIHandlerPatch + { + private static void Postfix(DebugUIHandler __instance) + { + if (Input.GetKeyDown(KeyCode.F1)) + { + if (__instance.IsOpen) + __instance.Hide(); + else + __instance.Show(); + } + } + } +} \ No newline at end of file From 4147a4e03a1869860db84003eb791eff370297ac Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sun, 8 Dec 2024 15:11:46 +0100 Subject: [PATCH 02/13] SendMessage --- ContentAPI/API/Features/Player.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ContentAPI/API/Features/Player.cs b/ContentAPI/API/Features/Player.cs index 9118440..145f3f3 100644 --- a/ContentAPI/API/Features/Player.cs +++ b/ContentAPI/API/Features/Player.cs @@ -203,6 +203,13 @@ public void SetFace(string text, bool safeCheck = true) playerRefs.visor.visorFaceText.text = safeCheck ? playerRefs.visor.SafetyCheckVisorText(text) : text; } + /// + /// Sends a message to the player. + /// + /// Message to send. It needs to be between 1-100 + /// Time until the text disappears. + public void SendMessage(string message, float time) => HelmetText.Instance.SetHelmetText(message, time); + /// /// Creates the player object. /// From 69a87b0d8828f4ff0d93fbe0b9c292406f82994f Mon Sep 17 00:00:00 2001 From: NotZer0Two Date: Sun, 8 Dec 2024 15:26:17 +0100 Subject: [PATCH 03/13] New Player Methods. --- ContentAPI/API/Features/Player.cs | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/ContentAPI/API/Features/Player.cs b/ContentAPI/API/Features/Player.cs index 145f3f3..029d78d 100644 --- a/ContentAPI/API/Features/Player.cs +++ b/ContentAPI/API/Features/Player.cs @@ -89,6 +89,60 @@ public Quaternion Rotation set => playerRefs.ragdoll.GetBodypart(BodypartType.Hip).rig.rotation = value; } + /// + /// Gets or sets player health. + /// + public float Health + { + get => playerData.health; + set => playerData.health = value; + } + + /// + /// Gets or sets the Oxygen of the player. + /// + public float Oxygen + { + get => playerData.remainingOxygen; + set => playerData.remainingOxygen = value; + } + + /// + /// Gets or sets the max Oxygen a player can have. + /// + public float MaxOxygen + { + get => playerData.maxOxygen; + set => playerData.maxOxygen = value; + } + + /// + /// Gets or sets a value indicating whether the player is using oxygen. + /// + public bool UsingOxygen + { + get => playerData.usingOxygen; + set => playerData.usingOxygen = value; + } + + /// + /// Gets or sets the current stamina. + /// + public float Stamina + { + get => playerData.currentStamina; + set => playerData.currentStamina = value; + } + + /// + /// Gets or sets the player mass. + /// + public float Mass + { + get => playerData.totalMass; + set => playerData.totalMass = value; + } + /// /// Gets Photon Class responsible for Networking Aspects. /// @@ -163,6 +217,16 @@ public static Player Get(PlayerAPI player) => (byte)danceType, }); + /// + /// Kills the player. + /// + public void Kill() => Base.RPCA_PlayerDie(); + + /// + /// Revives the player. + /// + public void Revive() => Base.RPCA_PlayerRevive(); + /// /// Makes the player ragdoll. /// From 097236b9b367c6631991e2fe77191e0205208917 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Mon, 9 Dec 2024 06:21:10 +0100 Subject: [PATCH 04/13] Modal + TickRate (#8) --- ContentAPI/API/Features/Lobby.cs | 28 +++++++++++++++ ContentAPI/API/Features/Modal.cs | 56 +++++++++++++++++++++++++++++ ContentAPI/Example/ModalShowcase.cs | 48 +++++++++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 ContentAPI/API/Features/Modal.cs create mode 100644 ContentAPI/Example/ModalShowcase.cs diff --git a/ContentAPI/API/Features/Lobby.cs b/ContentAPI/API/Features/Lobby.cs index 88d9ba9..b361713 100644 --- a/ContentAPI/API/Features/Lobby.cs +++ b/ContentAPI/API/Features/Lobby.cs @@ -246,6 +246,34 @@ public static IslandUnlock[] AllIslandUnlock /// The amount to add. public static void AddMetaCoins(int amount) => MetaProgressionHandler.SetMetaCoins(amount); + /// + /// Sets the ticks for the lobby. + /// + /// How fast everything goes. + public static void SetTickRate(float tick) + { + float ticks = 0.01666f / tick; + + UnityEngine.Time.timeScale = tick; + if (tick < 0.5f) + { + UnityEngine.Time.fixedDeltaTime *= 2f; + } + else + { + UnityEngine.Time.fixedDeltaTime = Mathf.Max(ticks, 0.0001f); + } + } + + /// + /// Resets the ticks. + /// + public static void ResetTickRate() + { + UnityEngine.Time.timeScale = 1; + UnityEngine.Time.fixedDeltaTime = 0.01666f; + } + /// /// Remove MetaCoins. /// diff --git a/ContentAPI/API/Features/Modal.cs b/ContentAPI/API/Features/Modal.cs new file mode 100644 index 0000000..3dfaf1b --- /dev/null +++ b/ContentAPI/API/Features/Modal.cs @@ -0,0 +1,56 @@ +namespace ContentAPI.API.Features +{ + using System.Collections.Generic; + + /// + /// Modal wrapper base class. + /// + public abstract class Modal + { + /// + /// Gets or sets the name of the item. + /// + public abstract string Title { get; set; } + + /// + /// Gets or sets the name of the item. + /// + public abstract string Body { get; set; } + + /// + /// Gets or sets a list of options. + /// + public abstract List Options { get; set; } + + /// + /// Shows the modal. + /// + public void Show() + { + if (Options.Count == 0) + { + ContentPlugin.Log.LogInfo("No options present going in safe mode."); + global::Modal.ShowError(Title, Body); + return; + } + + global::Modal.Show(title: Title, body: Body, options: Options.ToArray(), () => OnClosed()); + } + + /// + /// Called when the Modal is closed. + /// + /// This gets called everytime when a player clicks a button. + protected virtual void OnClosed() + { + } + + /// + /// Called when a button is pressed. + /// + /// The number of the button inside the list. + protected virtual void HandleButtonClick(int buttonNumber) + { + } + } +} \ No newline at end of file diff --git a/ContentAPI/Example/ModalShowcase.cs b/ContentAPI/Example/ModalShowcase.cs new file mode 100644 index 0000000..c3e93ca --- /dev/null +++ b/ContentAPI/Example/ModalShowcase.cs @@ -0,0 +1,48 @@ +namespace ContentAPI.Example +{ + using System.Collections.Generic; + + /// + /// Showcase how a modal works. + /// + public class ModalShowcase : API.Features.Modal + { + /// + /// Initializes a new instance of the class. + /// + public ModalShowcase() + { + Options.Add(new("No Cookie", () => HandleButtonClick(1))); + Options.Add(new("Cookie!!", () => HandleButtonClick(2))); + } + + /// + public override string Title { get; set; } = "Do you want a cookie?"; + + /// + public override string Body { get; set; } = "Click 'Cookie!!' for a special cookie."; + + /// + public override List Options { get; set; } = new(); + + /// + protected override void OnClosed() + { + ContentPlugin.Log.LogInfo("Cookie closed."); + base.OnClosed(); + } + + /// + protected override void HandleButtonClick(int buttonNumber) + { + if (buttonNumber == 1) + ContentPlugin.Log.LogInfo("No cookie :("); + else if (buttonNumber == 2) + ContentPlugin.Log.LogInfo("Cookie :)"); + else if (buttonNumber == 3) + ContentPlugin.Log.LogInfo("Wut bugged cookie??????"); + + base.HandleButtonClick(buttonNumber); + } + } +} \ No newline at end of file From 9f89e81286332e080ba5cccc159842d1ea6476f7 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:39:35 +0100 Subject: [PATCH 05/13] Custom Keybinds (#9) --- ContentAPI/API/Components/CustomKeybind.cs | 17 +++++++++++ ContentAPI/API/Features/Input.cs | 35 ++++++++++++++++++++++ ContentAPI/ContentPlugin.cs | 5 ++++ ContentAPI/Example/InputShowcase.cs | 20 +++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 ContentAPI/API/Components/CustomKeybind.cs create mode 100644 ContentAPI/API/Features/Input.cs create mode 100644 ContentAPI/Example/InputShowcase.cs diff --git a/ContentAPI/API/Components/CustomKeybind.cs b/ContentAPI/API/Components/CustomKeybind.cs new file mode 100644 index 0000000..1c6179e --- /dev/null +++ b/ContentAPI/API/Components/CustomKeybind.cs @@ -0,0 +1,17 @@ +namespace ContentAPI.API.Monobehavior +{ + using System.Linq; + using UnityEngine; + + /// + /// CustomKeybind controller. + /// + public class CustomKeybind : MonoBehaviour + { + private void Update() + { + foreach (Features.Input input in Features.Input.Registered.Where(input => Input.GetKeyDown(input.Key))) + input.ProcessInput(); + } + } +} \ No newline at end of file diff --git a/ContentAPI/API/Features/Input.cs b/ContentAPI/API/Features/Input.cs new file mode 100644 index 0000000..cf6d806 --- /dev/null +++ b/ContentAPI/API/Features/Input.cs @@ -0,0 +1,35 @@ +namespace ContentAPI.API.Features +{ + using System.Collections.Generic; + using UnityEngine; + + /// + /// Input base class. + /// + public abstract class Input + { + /// + /// Gets the list of current Item Managers. + /// + public static HashSet Registered { get; } = new(); + + /// + /// Gets or sets the button to press. + /// + public abstract KeyCode Key { get; set; } + + /// + /// Process the inputs. + /// + public abstract void ProcessInput(); + + /// + /// Registers the input. + /// + public void Register() + { + if (!Registered.Contains(this)) + Registered.Add(this); + } + } +} \ No newline at end of file diff --git a/ContentAPI/ContentPlugin.cs b/ContentAPI/ContentPlugin.cs index 824e1df..a18b23e 100644 --- a/ContentAPI/ContentPlugin.cs +++ b/ContentAPI/ContentPlugin.cs @@ -2,7 +2,10 @@ { using BepInEx; using BepInEx.Logging; + using ContentAPI.API.Monobehavior; using HarmonyLib; + using UnityEngine; + using UnityEngine.SceneManagement; /// /// Base class handling loading the plugin. @@ -41,6 +44,8 @@ private void Awake() Harmony = new(ContentGuid); Harmony.PatchAll(); + SceneManager.sceneLoaded += (arg0, mode) => new GameObject("ContentAPI_CustomKeybindings").AddComponent(); + Logger.LogInfo($"Plugin {ContentGuid}@{ContentVersion} is loaded!"); } } diff --git a/ContentAPI/Example/InputShowcase.cs b/ContentAPI/Example/InputShowcase.cs new file mode 100644 index 0000000..4e4c9e2 --- /dev/null +++ b/ContentAPI/Example/InputShowcase.cs @@ -0,0 +1,20 @@ +namespace ContentAPI.Example +{ + using UnityEngine; + using Input = ContentAPI.API.Features.Input; + + /// + /// KeyBind Showcase. + /// + public class InputShowcase : Input + { + /// + public override KeyCode Key { get; set; } = KeyCode.Backspace; + + /// + public override void ProcessInput() + { + ContentPlugin.Log.LogInfo("YOOO! The player clicked Backspace."); + } + } +} \ No newline at end of file From 7698bd556aec781d0866dc5fd70b212d568537e4 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:42:27 +0100 Subject: [PATCH 06/13] Funky bundle (#4) Co-authored-by: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> --- .../API/Extensions/AssetBundleExtensions.cs | 17 +++++++++++++++++ ContentAPI/ContentAPI.csproj | 4 +++- ContentAPI/ContentPlugin.cs | 2 +- 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 ContentAPI/API/Extensions/AssetBundleExtensions.cs diff --git a/ContentAPI/API/Extensions/AssetBundleExtensions.cs b/ContentAPI/API/Extensions/AssetBundleExtensions.cs new file mode 100644 index 0000000..ab896fe --- /dev/null +++ b/ContentAPI/API/Extensions/AssetBundleExtensions.cs @@ -0,0 +1,17 @@ +namespace ContentAPI.API.Extensions +{ + using UnityEngine; + + /// + /// Extensions related to asset bundles. + /// + public static class AssetBundleExtensions + { + /// + /// Gets an asset bundle from a path. + /// + /// The path to get the bundle from. + /// The asset bundle found. + public static AssetBundle GetAssetBundle(this string path) => AssetBundle.LoadFromFile(path); + } +} \ No newline at end of file diff --git a/ContentAPI/ContentAPI.csproj b/ContentAPI/ContentAPI.csproj index 4aa1129..36e21e6 100644 --- a/ContentAPI/ContentAPI.csproj +++ b/ContentAPI/ContentAPI.csproj @@ -37,14 +37,16 @@ + - + + diff --git a/ContentAPI/ContentPlugin.cs b/ContentAPI/ContentPlugin.cs index a18b23e..687028d 100644 --- a/ContentAPI/ContentPlugin.cs +++ b/ContentAPI/ContentPlugin.cs @@ -15,7 +15,7 @@ public class ContentPlugin : BaseUnityPlugin { /// - /// Plugin Name. + /// The guid of the ContentAPI. /// public const string ContentGuid = "Circus.ContentAPI"; private const string ContentName = "ContentAPI"; From 177dad4ad4f6b1fb29a691e6d890399a0840bb25 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Mon, 9 Dec 2024 17:48:13 +0100 Subject: [PATCH 07/13] bump --- ContentAPI/ContentAPI.csproj | 2 +- ContentAPI/ContentPlugin.cs | 6 ++---- ContentAPI/ThunderAssets/manifest.json | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ContentAPI/ContentAPI.csproj b/ContentAPI/ContentAPI.csproj index 36e21e6..638d9da 100644 --- a/ContentAPI/ContentAPI.csproj +++ b/ContentAPI/ContentAPI.csproj @@ -22,7 +22,7 @@ README.md GNU LICENSE - 0.0.1 + 0.0.3 diff --git a/ContentAPI/ContentPlugin.cs b/ContentAPI/ContentPlugin.cs index 99f4ca3..dc94954 100644 --- a/ContentAPI/ContentPlugin.cs +++ b/ContentAPI/ContentPlugin.cs @@ -1,10 +1,8 @@ namespace ContentAPI { using BepInEx; - using BepInEx.Logging;dev + using BepInEx.Logging; using ContentAPI.API.Monobehavior; - using ContentAPI.Events.EventArgs.Monsters; - using ContentAPI.Events.Handlers; using HarmonyLib; using UnityEngine; using UnityEngine.SceneManagement; @@ -21,7 +19,7 @@ public class ContentPlugin : BaseUnityPlugin /// public const string ContentGuid = "Circus.ContentAPI"; private const string ContentName = "ContentAPI"; - private const string ContentVersion = "0.0.1"; + private const string ContentVersion = "0.0.3"; private const bool ContentVanillaCompatible = true; /// diff --git a/ContentAPI/ThunderAssets/manifest.json b/ContentAPI/ThunderAssets/manifest.json index bd9495b..50fb07d 100644 --- a/ContentAPI/ThunderAssets/manifest.json +++ b/ContentAPI/ThunderAssets/manifest.json @@ -1,6 +1,6 @@ { "name": "ContentAPI", - "version_number": "0.0.1", + "version_number": "0.0.3", "website_url": "https://github.com/CircusStudios/ContentAPI/", "description": "A library of tools to help developers.", "dependencies": [ From 71323a7f30571f7f3d5b64451886567006111115 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:19:08 +0100 Subject: [PATCH 08/13] Pickup => Item (#12) --- ContentAPI/API/Features/Pickup.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ContentAPI/API/Features/Pickup.cs b/ContentAPI/API/Features/Pickup.cs index da12671..2a8bb08 100644 --- a/ContentAPI/API/Features/Pickup.cs +++ b/ContentAPI/API/Features/Pickup.cs @@ -38,6 +38,11 @@ public Pickup(PickupAPI item) /// public PickupAPI Base { get; private set; } + /// + /// Gets the item from the pickup. + /// + public Item Item => Item.Get(Base.itemInstance.item); + /// public Vector3 Position { From c3ee382981de31f9d41e68b46b0fbb0e93d70657 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:11:16 +0100 Subject: [PATCH 09/13] SteamWorkshop Config (#14) Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com> --- ...CustomKeybind.cs => CustomInputHandler.cs} | 12 +++-- ContentAPI/API/Features/Input.cs | 5 +++ ContentAPI/API/Features/Modal.cs | 3 +- ContentAPI/ContentAPI.csproj | 11 ++++- ContentAPI/ContentBepinLoad.cs | 22 +++++++++ ContentAPI/ContentPlugin.cs | 45 +++++++++---------- ContentAPI/Example/InputShowcase.cs | 5 ++- ContentAPI/Example/ModalShowcase.cs | 9 ++-- ContentAPI/Patches/Generic/PlayerWrapPatch.cs | 4 ++ ContentAPI/ThunderAssets/manifest.json | 2 +- 10 files changed, 82 insertions(+), 36 deletions(-) rename ContentAPI/API/Components/{CustomKeybind.cs => CustomInputHandler.cs} (56%) create mode 100644 ContentAPI/ContentBepinLoad.cs diff --git a/ContentAPI/API/Components/CustomKeybind.cs b/ContentAPI/API/Components/CustomInputHandler.cs similarity index 56% rename from ContentAPI/API/Components/CustomKeybind.cs rename to ContentAPI/API/Components/CustomInputHandler.cs index 1c6179e..636f414 100644 --- a/ContentAPI/API/Components/CustomKeybind.cs +++ b/ContentAPI/API/Components/CustomInputHandler.cs @@ -1,17 +1,21 @@ -namespace ContentAPI.API.Monobehavior +namespace ContentAPI.API.Components { - using System.Linq; using UnityEngine; /// /// CustomKeybind controller. /// - public class CustomKeybind : MonoBehaviour + public class CustomInputHandler : MonoBehaviour { private void Update() { - foreach (Features.Input input in Features.Input.Registered.Where(input => Input.GetKeyDown(input.Key))) + foreach (Features.Input input in Features.Input.Registered) + { + if (!Input.GetKeyDown(input.Key)) + continue; + input.ProcessInput(); + } } } } \ No newline at end of file diff --git a/ContentAPI/API/Features/Input.cs b/ContentAPI/API/Features/Input.cs index cf6d806..28ffc27 100644 --- a/ContentAPI/API/Features/Input.cs +++ b/ContentAPI/API/Features/Input.cs @@ -31,5 +31,10 @@ public void Register() if (!Registered.Contains(this)) Registered.Add(this); } + + /// + /// Unregisters the input. + /// + public void UnRegister() => Registered.Remove(this); } } \ No newline at end of file diff --git a/ContentAPI/API/Features/Modal.cs b/ContentAPI/API/Features/Modal.cs index 3dfaf1b..6e12afa 100644 --- a/ContentAPI/API/Features/Modal.cs +++ b/ContentAPI/API/Features/Modal.cs @@ -1,6 +1,7 @@ namespace ContentAPI.API.Features { using System.Collections.Generic; + using UnityEngine; /// /// Modal wrapper base class. @@ -29,7 +30,7 @@ public void Show() { if (Options.Count == 0) { - ContentPlugin.Log.LogInfo("No options present going in safe mode."); + Debug.Log("No options present going in safe mode."); global::Modal.ShowError(Title, Body); return; } diff --git a/ContentAPI/ContentAPI.csproj b/ContentAPI/ContentAPI.csproj index 638d9da..f9137d0 100644 --- a/ContentAPI/ContentAPI.csproj +++ b/ContentAPI/ContentAPI.csproj @@ -10,6 +10,7 @@ https://nuget.bepinex.dev/v3/index.json ContentAPI + C:\Program Files (x86)\Steam\steamapps\common\Content Warning @@ -22,7 +23,7 @@ README.md GNU LICENSE - 0.0.3 + 0.0.4 @@ -56,8 +57,16 @@ + + + + + + + + true recommended diff --git a/ContentAPI/ContentBepinLoad.cs b/ContentAPI/ContentBepinLoad.cs new file mode 100644 index 0000000..b0a1657 --- /dev/null +++ b/ContentAPI/ContentBepinLoad.cs @@ -0,0 +1,22 @@ +namespace ContentAPI +{ + using BepInEx; + using HarmonyLib; + using UnityEngine; + using static ContentPlugin; + + /// + /// Handles loading the API through BepInEx. + /// + [BepInPlugin(ContentGuid, ContentName, ContentVersion)] + public class ContentBepinLoad : BaseUnityPlugin + { + private void Awake() + { + gameObject.hideFlags = HideFlags.HideAndDontSave; + + _ = ContentPlugin.GameObject; + new Harmony(ContentGuid).PatchAll(); + } + } +} \ No newline at end of file diff --git a/ContentAPI/ContentPlugin.cs b/ContentAPI/ContentPlugin.cs index dc94954..b78d402 100644 --- a/ContentAPI/ContentPlugin.cs +++ b/ContentAPI/ContentPlugin.cs @@ -1,52 +1,51 @@ namespace ContentAPI { - using BepInEx; - using BepInEx.Logging; - using ContentAPI.API.Monobehavior; - using HarmonyLib; + using ContentAPI.API.Components; using UnityEngine; - using UnityEngine.SceneManagement; /// /// Base class handling loading the plugin. /// - [BepInPlugin(ContentGuid, ContentName, ContentVersion)] [ContentWarningPlugin(ContentGuid, ContentVersion, ContentVanillaCompatible)] - public class ContentPlugin : BaseUnityPlugin + public static class ContentPlugin { /// /// The guid of the ContentAPI. /// public const string ContentGuid = "Circus.ContentAPI"; - private const string ContentName = "ContentAPI"; - private const string ContentVersion = "0.0.3"; - private const bool ContentVanillaCompatible = true; /// - /// Gets the instance of the plugin. + /// Gets the name to be used. /// - public static ContentPlugin Instance { get; private set; } + public const string ContentName = "ContentAPI"; /// - /// Gets the plugin Logger. + /// Gets the version of the API. /// - internal static ManualLogSource Log { get; private set; } + public const string ContentVersion = "0.0.4"; /// - /// Gets the Harmony. + /// Gets whether its compatible with vanilla. /// - internal static Harmony Harmony { get; private set; } + public const bool ContentVanillaCompatible = true; - private void Awake() + static ContentPlugin() { - Instance = this; - Log = Logger; - Harmony = new(ContentGuid); - Harmony.PatchAll(); + CreateObjects(); + } - SceneManager.sceneLoaded += (arg0, mode) => new GameObject("ContentAPI_CustomKeybindings").AddComponent(); + /// + /// Gets the used by the API. + /// + public static GameObject GameObject { get; private set; } + + private static void CreateObjects() + { + GameObject = new("ContentAPI"); + GameObject.hideFlags = HideFlags.HideAndDontSave; + Object.DontDestroyOnLoad(GameObject); - Logger.LogInfo($"Plugin {ContentGuid}@{ContentVersion} is loaded!"); + GameObject.AddComponent(); } } } \ No newline at end of file diff --git a/ContentAPI/Example/InputShowcase.cs b/ContentAPI/Example/InputShowcase.cs index 4e4c9e2..e053864 100644 --- a/ContentAPI/Example/InputShowcase.cs +++ b/ContentAPI/Example/InputShowcase.cs @@ -9,12 +9,13 @@ namespace ContentAPI.Example public class InputShowcase : Input { /// - public override KeyCode Key { get; set; } = KeyCode.Backspace; + public override KeyCode Key { get; set; } = KeyCode.F2; /// public override void ProcessInput() { - ContentPlugin.Log.LogInfo("YOOO! The player clicked Backspace."); + Debug.Log("YOOO! The player clicked F2."); + API.Features.Player.LocalPlayer?.Ragdoll(5); } } } \ No newline at end of file diff --git a/ContentAPI/Example/ModalShowcase.cs b/ContentAPI/Example/ModalShowcase.cs index c3e93ca..fcc279d 100644 --- a/ContentAPI/Example/ModalShowcase.cs +++ b/ContentAPI/Example/ModalShowcase.cs @@ -1,6 +1,7 @@ namespace ContentAPI.Example { using System.Collections.Generic; + using UnityEngine; /// /// Showcase how a modal works. @@ -28,7 +29,7 @@ public ModalShowcase() /// protected override void OnClosed() { - ContentPlugin.Log.LogInfo("Cookie closed."); + Debug.Log("Cookie closed."); base.OnClosed(); } @@ -36,11 +37,11 @@ protected override void OnClosed() protected override void HandleButtonClick(int buttonNumber) { if (buttonNumber == 1) - ContentPlugin.Log.LogInfo("No cookie :("); + Debug.Log("No cookie :("); else if (buttonNumber == 2) - ContentPlugin.Log.LogInfo("Cookie :)"); + Debug.Log("Cookie :)"); else if (buttonNumber == 3) - ContentPlugin.Log.LogInfo("Wut bugged cookie??????"); + Debug.Log("Wut bugged cookie??????"); base.HandleButtonClick(buttonNumber); } diff --git a/ContentAPI/Patches/Generic/PlayerWrapPatch.cs b/ContentAPI/Patches/Generic/PlayerWrapPatch.cs index cfd5991..7906697 100644 --- a/ContentAPI/Patches/Generic/PlayerWrapPatch.cs +++ b/ContentAPI/Patches/Generic/PlayerWrapPatch.cs @@ -2,9 +2,13 @@ namespace ContentAPI.Patches.Generic { #pragma warning disable SA1313 #pragma warning disable SA1402 + using System.Collections.Generic; + using System.Reflection.Emit; using ContentAPI.API.Features; + using ContentAPI.API.Features.Pools; using ContentAPI.Events.Handlers; using HarmonyLib; + using static HarmonyLib.AccessTools; using PlayerAPI = global::Player; /// diff --git a/ContentAPI/ThunderAssets/manifest.json b/ContentAPI/ThunderAssets/manifest.json index 50fb07d..63e8254 100644 --- a/ContentAPI/ThunderAssets/manifest.json +++ b/ContentAPI/ThunderAssets/manifest.json @@ -1,6 +1,6 @@ { "name": "ContentAPI", - "version_number": "0.0.3", + "version_number": "0.0.4", "website_url": "https://github.com/CircusStudios/ContentAPI/", "description": "A library of tools to help developers.", "dependencies": [ From b7eb416c4bfe5bb68ce634bcec60260bb0abccb6 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Wed, 11 Dec 2024 23:15:57 +0100 Subject: [PATCH 10/13] fix debug.log --- ContentAPI/Example/InputShowcase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ContentAPI/Example/InputShowcase.cs b/ContentAPI/Example/InputShowcase.cs index 3d4d359..30fe54a 100644 --- a/ContentAPI/Example/InputShowcase.cs +++ b/ContentAPI/Example/InputShowcase.cs @@ -11,11 +11,10 @@ public class InputShowcase : Input /// public override KeyCode Key { get; set; } = KeyCode.Backspace; - /// public override void ProcessInput() { - ContentPlugin.Log.LogInfo("YOOO! The player clicked Backspace."); + Debug.Log("YOOO! The player clicked Backspace."); } } } \ No newline at end of file From 1c3e6aed350eaa960f345363d2ee058313864c03 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:25:25 +0100 Subject: [PATCH 11/13] Support for BepInEx and Vanilla Content (#17) --- ContentAPI/API/Features/Player.cs | 3 +- ContentAPI/ContentAPI.csproj | 37 +++++++++++++++++-- ContentAPI/ContentBepinLoad.cs | 6 ++- ContentAPI/Patches/Generic/PickupWrapPatch.cs | 9 ++++- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/ContentAPI/API/Features/Player.cs b/ContentAPI/API/Features/Player.cs index 029d78d..b749885 100644 --- a/ContentAPI/API/Features/Player.cs +++ b/ContentAPI/API/Features/Player.cs @@ -27,7 +27,8 @@ public class Player : IWrapper, IWorldSpace internal Player(PlayerAPI player) { Base = player; - Dictionary.Add(player.gameObject, this); + if (!Dictionary.ContainsKey(player.gameObject)) + Dictionary.Add(player.gameObject, this); } /// diff --git a/ContentAPI/ContentAPI.csproj b/ContentAPI/ContentAPI.csproj index f9137d0..dfc2dcc 100644 --- a/ContentAPI/ContentAPI.csproj +++ b/ContentAPI/ContentAPI.csproj @@ -58,13 +58,44 @@ - + + - - + + + + BEPINEX + $(AssemblyName).BepInEx + + + + + + + + + $(AssemblyName) + + + + + + + + + + + + diff --git a/ContentAPI/ContentBepinLoad.cs b/ContentAPI/ContentBepinLoad.cs index b0a1657..7c25bad 100644 --- a/ContentAPI/ContentBepinLoad.cs +++ b/ContentAPI/ContentBepinLoad.cs @@ -1,4 +1,5 @@ -namespace ContentAPI +#if BEPINEX +namespace ContentAPI { using BepInEx; using HarmonyLib; @@ -19,4 +20,5 @@ private void Awake() new Harmony(ContentGuid).PatchAll(); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/ContentAPI/Patches/Generic/PickupWrapPatch.cs b/ContentAPI/Patches/Generic/PickupWrapPatch.cs index ab9a79c..a6c60bc 100644 --- a/ContentAPI/Patches/Generic/PickupWrapPatch.cs +++ b/ContentAPI/Patches/Generic/PickupWrapPatch.cs @@ -27,9 +27,14 @@ private static void Postfix(PickupAPI __instance) [HarmonyPatch(typeof(PickupAPI), nameof(PickupAPI.OnDisable))] internal class PickupWrapPatch_Remove { - private static void Postfix(PickupAPI __instance) + private static void Prefix(PickupAPI __instance) { - Pickup.Items.Remove(Pickup.Get(__instance.m_itemID)); + Pickup pickup = Pickup.Get(__instance.m_itemID); + + if (pickup == null) + return; + + Pickup.Items.Remove(pickup); } } } \ No newline at end of file From eee8da2a714adeab7cce8e8ee149f457ac0b0834 Mon Sep 17 00:00:00 2001 From: Nameless <85962933+Misfiy@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:29:11 +0100 Subject: [PATCH 12/13] Bump --- ContentAPI/ContentAPI.csproj | 2 +- ContentAPI/ContentPlugin.cs | 2 +- ContentAPI/ThunderAssets/manifest.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ContentAPI/ContentAPI.csproj b/ContentAPI/ContentAPI.csproj index dfc2dcc..dbdbb13 100644 --- a/ContentAPI/ContentAPI.csproj +++ b/ContentAPI/ContentAPI.csproj @@ -23,7 +23,7 @@ README.md GNU LICENSE - 0.0.4 + 0.0.5 diff --git a/ContentAPI/ContentPlugin.cs b/ContentAPI/ContentPlugin.cs index b78d402..526b0e6 100644 --- a/ContentAPI/ContentPlugin.cs +++ b/ContentAPI/ContentPlugin.cs @@ -22,7 +22,7 @@ public static class ContentPlugin /// /// Gets the version of the API. /// - public const string ContentVersion = "0.0.4"; + public const string ContentVersion = "0.0.5"; /// /// Gets whether its compatible with vanilla. diff --git a/ContentAPI/ThunderAssets/manifest.json b/ContentAPI/ThunderAssets/manifest.json index 63e8254..9eb312b 100644 --- a/ContentAPI/ThunderAssets/manifest.json +++ b/ContentAPI/ThunderAssets/manifest.json @@ -1,6 +1,6 @@ { "name": "ContentAPI", - "version_number": "0.0.4", + "version_number": "0.0.5", "website_url": "https://github.com/CircusStudios/ContentAPI/", "description": "A library of tools to help developers.", "dependencies": [ From 7bc6d9e248f86cb69d787c3b60fa4d9080e86e04 Mon Sep 17 00:00:00 2001 From: notzerotwo_ <63092138+NotZer0Two@users.noreply.github.com> Date: Fri, 13 Dec 2024 15:43:54 +0100 Subject: [PATCH 13/13] Fixes (#19) Co-authored-by: Nameless <85962933+Misfiy@users.noreply.github.com> --- ContentAPI/API/Components/CustomKeybind.cs | 17 ----------------- ContentAPI/Example/InputShowcase.cs | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) delete mode 100644 ContentAPI/API/Components/CustomKeybind.cs diff --git a/ContentAPI/API/Components/CustomKeybind.cs b/ContentAPI/API/Components/CustomKeybind.cs deleted file mode 100644 index 1c6179e..0000000 --- a/ContentAPI/API/Components/CustomKeybind.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace ContentAPI.API.Monobehavior -{ - using System.Linq; - using UnityEngine; - - /// - /// CustomKeybind controller. - /// - public class CustomKeybind : MonoBehaviour - { - private void Update() - { - foreach (Features.Input input in Features.Input.Registered.Where(input => Input.GetKeyDown(input.Key))) - input.ProcessInput(); - } - } -} \ No newline at end of file diff --git a/ContentAPI/Example/InputShowcase.cs b/ContentAPI/Example/InputShowcase.cs index 30fe54a..8d7446c 100644 --- a/ContentAPI/Example/InputShowcase.cs +++ b/ContentAPI/Example/InputShowcase.cs @@ -14,7 +14,7 @@ public class InputShowcase : Input /// public override void ProcessInput() { - Debug.Log("YOOO! The player clicked Backspace."); + Debug.Log("The player Clicked Backspace Button."); } } } \ No newline at end of file