Пример #1
0
        private void PatchEvent <T>(Common.Events ev)
        {
            var type = typeof(T);

            if (InEventList(PatchedEvents, type, ev))
            {
                _logger.Log($"Event is already patched: {ev} of {type.Name}");
                return;
            }
            AddToEventList(PatchedEvents, type, ev);

            switch (ev)
            {
            case Common.Events.BeforeAwake:
                _harmonyHelper.AddPrefix <T>("Awake", typeof(Patches), nameof(Patches.BeforeAwake));
                break;

            case Common.Events.AfterAwake:
                _harmonyHelper.AddPostfix <T>("Awake", typeof(Patches), nameof(Patches.AfterAwake));
                break;

            case Common.Events.BeforeStart:
                _harmonyHelper.AddPrefix <T>("Start", typeof(Patches), nameof(Patches.BeforeStart));
                break;

            case Common.Events.AfterStart:
                _harmonyHelper.AddPostfix <T>("Start", typeof(Patches), nameof(Patches.AfterStart));
                break;

            case Common.Events.BeforeEnable:
                _harmonyHelper.AddPrefix <T>("OnEnable", typeof(Patches), nameof(Patches.BeforeEnable));
                break;

            case Common.Events.AfterEnable:
                _harmonyHelper.AddPostfix <T>("OnEnable", typeof(Patches), nameof(Patches.AfterEnable));
                break;

            case Common.Events.BeforeDisable:
                _harmonyHelper.AddPrefix <T>("OnDisable", typeof(Patches), nameof(Patches.BeforeDisable));
                break;

            case Common.Events.AfterDisable:
                _harmonyHelper.AddPostfix <T>("OnDisable", typeof(Patches), nameof(Patches.AfterDisable));
                break;

            default:
                _console.WriteLine("Error: unrecognized event: " + ev);
                throw new ArgumentOutOfRangeException(nameof(ev), ev, null);
            }
        }
Пример #2
0
        public ModInputHandler(IModLogger logger, IModConsole console, IHarmonyHelper patcher, IOwmlConfig owmlConfig, IModEvents events)
        {
            var textures = new ModInputTextures();

            textures.FillTextureLibrary();
            Textures = textures;

            _console = console;
            _logger  = logger;

            var listenerObject = new GameObject("GameBindingsChangeListener");
            var listener       = listenerObject.AddComponent <BindingChangeListener>();

            listener.Initialize(this, events);

            if (owmlConfig.BlockInput)
            {
                patcher.AddPostfix <SingleAxisCommand>("UpdateInputCommand", typeof(InputInterceptor), nameof(InputInterceptor.SingleAxisUpdatePost));
                patcher.AddPostfix <DoubleAxisCommand>("UpdateInputCommand", typeof(InputInterceptor), nameof(InputInterceptor.DoubleAxisUpdatePost));
            }
            Instance = this;
        }