Skip to content

Commit

Permalink
Change HLightControl config when button pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelhauled committed May 20, 2021
1 parent 566e03b commit 07232b5
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/FreeHDefaults.Koikatu/FreeHDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using System.Linq;
using System.Xml.Serialization;
using BepInEx;
using BepInEx.Configuration;
using ChaCustom;
using FreeH;
using HarmonyLib;
using Illusion.Component;
using Manager;
using UniRx;
using UnityEngine;
using UnityEngine.Events;

namespace FreeHDefaults.Koikatu
{
Expand All @@ -27,7 +29,7 @@ public class FreeHDefaults : BaseUnityPlugin
private static readonly XmlSerializer xmlSerializer = new XmlSerializer(typeof(Savedata));
private static readonly int[] modeMagic = { 0, 1012, 1100, 3000, 4000 };

private void Start()
private void Awake()
{
Log.SetLogSource(Logger);
Harmony.CreateAndPatchAll(typeof(FreeHDefaults));
Expand All @@ -39,6 +41,22 @@ private void Start()
}
}

private void Start()
{
var lightControlType = Type.GetType("KK_HLightControl.KK_HLightControl, KK_HLightControl");
if(lightControlType != null)
{
var lightTraverse = Traverse.Create(lightControlType);
var toggleInfo = lightTraverse.Field("toggleInfo").GetValue<IList>();
var clickEventField = Traverse.Create(toggleInfo[0]).Field("clickEvent");
var btn = lightTraverse.Field("btn").GetValue<List<ConfigEntry<bool>>>().First();

var clickEvent = clickEventField.GetValue<UnityAction<bool>>();
clickEvent += x => { if(btn.Value != x) btn.Value = x; };
clickEventField.SetValue(clickEvent);
}
}

[HarmonyPostfix, HarmonyPatch(typeof(TitleScene), nameof(TitleScene.Start))]
private static void PrepareSavedata()
{
Expand Down

0 comments on commit 07232b5

Please sign in to comment.