Code Monkey home page Code Monkey logo

bepinex.unityinput's Introduction

BepInEx.UnityInput

Adds Harmony hooks so that BepInEx plugins may intercept Unity's Global Input system.

Development for this largely stems from interest of extending functionality of Illusion games, such as Koikatsu, which extensively make use of UnityEngine.Input in places where by best practice it shouldn't.
In areas where you wish to use original game functionality through the simulation of button presses on the UI, you may need to occasionally fake an Input state.

Requirements

  • Install BepInEx 5.4 or later.

Using this in your own Plugins

Plugins that require BepInEx.UnityInput should specify the dependency like so

    [BepInPlugin(GUID, "MyPlugin", Version)]
    [BepInDependency("github.lunared.bepinex.unityinput", BepInDependency.DependencyFlags.HardDependency)]
    internal class MyPlugin : BaseUnityPlugin
    {
    }

Once your plugin is set up to depend on the UnityInput one, you can now reference the Global methods where you need to.

The functions are all exposed similar to Unity's own Input system. In this example, we can demonstrate how to click an Action button in Koikatsu's HSprite UI

using UnityEngine;
using KKAPI.MainGame;
using BepInEx.Unity; // this has InputSimulator in it, which we use to override input

namespace MyPlugin 
{
    internal class MyPluginController : GameCustomFunctionController 
    {

        protected override void OnStartH(HSceneProc proc, bool freeH)
        {
            StartCoroutine(PickAction(proc));
        }

        IEnumerator PickAction(HSceneProc proc)
        {
            while (true)
            {
                // get the list of visible actions from one of the interfaces
                var choices = proc.sprite.sonyu.categoryActionButton.lstButton.Where(
                    button => button.isActiveAndEnabled && button.interactable
                ).ToList();

                // leverage simulating clicking in the menu
                var index = Random.RandomRangeInt(0, choices.Count);
                var nextAction = choices[index];

                // many koikatsu actions check for left click mouse up 
                // within their onClick handler
                InputSimulator.MouseButtonUp(0);
                // perform our action
                nextAction?.onClick?.Invoke();
                // reset the input state after performing the action
                InputSimulator.UnsetMouseButton(0);
                yield return new WaitForSeconds(1f);
            }
        }
    }

bepinex.unityinput's People

Contributors

erodozer avatar sauceke avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.