Skip to content

Commit

Permalink
Added restore of class roster icons in story mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed Feb 12, 2021
1 parent 75c3884 commit 5607302
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 2 deletions.
112 changes: 112 additions & 0 deletions src/KK_Fix_RestoreMissingFunctions/CalendarIcon/CalendarIconHooks.cs
@@ -0,0 +1,112 @@
using System;
using ActionGame;
using ActionGame.Chara;
using HarmonyLib;
using Illusion.Component;
using KKAPI.Utilities;
using Manager;
using UniRx;
using UniRx.Triggers;
using UnityEngine;

namespace IllusionFixes
{
public partial class RestoreMissingFunctions
{
private static class CalendarIconHooks
{
[HarmonyPostfix]
[HarmonyPatch(typeof(ActionMap), "Reserve")]
private static void OnMapChangedHook(ActionMap __instance)
{
if (__instance.mapRoot == null || __instance.isMapLoading) return;

// All 4 classroom ids
if (__instance.no == 5 || __instance.no == 8 || __instance.no == 9 || __instance.no == 11)
{
try
{
SpawnCrestActionPoint();
}
catch (Exception e)
{
Logger.LogError(e);
}
}
}

private static void SpawnCrestActionPoint()
{
Logger.LogDebug("Spawning crest action point");

if (_iconOff == null)
{
_iconOff = (ResourceUtils.GetEmbeddedResource(@"action_icon_calendar_off.png").LoadTexture()
?? throw new Exception("asset not found - action_icon_calendar_off")).ToSprite();
DontDestroyOnLoad(_iconOff);
}

if (_iconOn == null)
{
_iconOn = (ResourceUtils.GetEmbeddedResource(@"action_icon_calendar_on.png").LoadTexture()
?? throw new Exception("asset not found - action_icon_calendar_on")).ToSprite();
DontDestroyOnLoad(_iconOn);
}

var inst = CommonLib.LoadAsset<GameObject>("map/playeractionpoint/00.unity3d", "PlayerActionPoint_05", true);
var parent = GameObject.Find("Map/ActionPoints");
inst.transform.SetParent(parent.transform, true);

var pap = inst.GetComponentInChildren<PlayerActionPoint>();
var iconRootObject = pap.gameObject;
var iconRootTransform = pap.transform;
DestroyImmediate(pap, false);

// position above the small table
iconRootTransform.position = new Vector3(2.43f, 0.45f, 4.55f);

if (iconRootObject.GetComponent<ObservableUpdateTrigger>())
Console.WriteLine("was spawned -=--------------");

var evt = iconRootObject.AddComponent<TriggerEnterExitEvent>();
var animator = iconRootObject.GetComponentInChildren<Animator>();
var rendererIcon = iconRootObject.GetComponentInChildren<SpriteRenderer>();
rendererIcon.sprite = _iconOff;
var playerInRange = false;
evt.onTriggerEnter += c =>
{
if (!c.CompareTag("Player")) return;
playerInRange = true;
animator.Play("icon_action");
rendererIcon.sprite = _iconOn;
c.GetComponent<Player>().actionPointList.Add(evt);
};
evt.onTriggerExit += c =>
{
if (!c.CompareTag("Player")) return;
playerInRange = false;
animator.Play("icon_stop");
rendererIcon.sprite = _iconOff;
c.GetComponent<Player>().actionPointList.Remove(evt);
};

var player = Singleton<Game>.Instance.actScene.Player;
evt.UpdateAsObservable()
.Where(_ => playerInRange && ActionInput.isAction && !player.isActionNow && !Singleton<Scene>.Instance.IsNowLoadingFade)
.Subscribe(_ =>
{
Singleton<Scene>.Instance.LoadReserve(new Scene.Data
{
assetBundleName = "action/menu/classschedulemenu.unity3d",
levelName = "ClassScheduleMenu",
isAdd = true,
isAsync = true
}, false);
})
.AddTo(evt);
}

private static Sprite _iconOff, _iconOn;
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -63,12 +63,18 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CalendarIcon\CalendarIconHooks.cs" />
<Compile Include="RestoreMissingFunctions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="CalendarIcon\action_icon_calendar_off.png" />
<EmbeddedResource Include="CalendarIcon\action_icon_calendar_on.png" />
</ItemGroup>
<Import Project="..\Common\Common.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=calendaricon/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
11 changes: 9 additions & 2 deletions src/KK_Fix_RestoreMissingFunctions/RestoreMissingFunctions.cs
Expand Up @@ -5,6 +5,7 @@
using System.Reflection;
using System.Reflection.Emit;
using BepInEx;
using BepInEx.Logging;
using Common;
using Config;
using HarmonyLib;
Expand All @@ -21,13 +22,17 @@ namespace IllusionFixes
[BepInProcess(Constants.GameProcessNameSteam)]
[BepInDependency(KoikatuAPI.GUID, "1.7")]
[BepInPlugin(GUID, PluginName, Constants.PluginsVersion)]
public class RestoreMissingFunctions : BaseUnityPlugin
public partial class RestoreMissingFunctions : BaseUnityPlugin
{
public const string GUID = "KK_Fix_RestoreMissingFunctions";
public const string PluginName = "Restore missing functions";

private static new ManualLogSource Logger;

private void Awake()
{
Logger = base.Logger;

// Add missing head type selection if the game supports it (ui for it was added in darkness for some reason)
var missingDarkness = typeof(ChaInfo).GetProperty("exType", BindingFlags.Public | BindingFlags.Instance) == null;
if (missingDarkness)
Expand All @@ -39,10 +44,12 @@ private void Awake()
MakerAPI.RegisterCustomSubCategories += MakerAPI_RegisterCustomSubCategories;
}

var h = new Harmony(GUID);
h.PatchAll(typeof(CalendarIconHooks));

// Fixes only needed for party
if (Paths.ProcessName == Constants.GameProcessNameSteam)
{
var h = new Harmony(GUID);
h.Patch(AccessTools.Method(typeof(ConfigScene), "Start"),
postfix: new HarmonyMethod(typeof(RestoreMissingFunctions), nameof(ConfigAddFix)));
h.Patch(AccessTools.Method("Localize.Translate.Manager:SetLanguage", new[] { typeof(int) }),
Expand Down

0 comments on commit 5607302

Please sign in to comment.