Skip to content

Commit

Permalink
[KKS] Fix applying hooks multiple times; Improve logging
Browse files Browse the repository at this point in the history
in CustomTrespassingHsceneButtons
  • Loading branch information
ManlyMarco committed Jan 17, 2022
1 parent e63c51a commit fc901cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/KKSAPI/MainGame/CustomTrespassingHsceneButtons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace KKAPI.MainGame
{
/// <summary>
/// Used to add custom buttons to the H Scene "trespassing" menu (red button below position selections on the right, originally used when having H near another girl so you can start 3P).
/// Warning: Works both in main game and FreeH by default! If you don't want your button to appear in FreeH then check for <code>!hSprite.flags.isFreeH</code> in your spawnConditionCheck.
/// </summary>
public static class CustomTrespassingHsceneButtons
{
Expand Down Expand Up @@ -90,14 +91,13 @@ private static int SpawnButtons(HSprite hSprite, int existingButtons)
}
catch (Exception ex)
{
//todo use logger
Console.WriteLine($"Failed to spawn CustomTrespassingButton text={trespassingButton.ButtonText.Replace('\r', ' ').Replace('\n', ' ')}\n{ex}");
KoikatuAPI.Logger.LogWarning($"Failed to spawn CustomTrespassingButton text={trespassingButton.ButtonText.Replace('\r', ' ').Replace('\n', ' ')}\n{ex}");
}
}

if (spawnedButtons > 0)
{
Console.WriteLine($"Created {spawnedButtons} CustomTrespassingButtons ({existingButtons} existing)");
KoikatuAPI.Logger.LogInfo($"Created {spawnedButtons} CustomTrespassingButtons ({existingButtons} already existed)");
}

return spawnedButtons;
Expand All @@ -107,7 +107,7 @@ private static bool SpawnSingleButton(int id, HSprite hSprite, CustomTrespassing
{
if (buttonData.SpawnConditionCheck != null && !buttonData.SpawnConditionCheck(hSprite)) return false;

Console.WriteLine($"spawn id={id} name=" + buttonData.ButtonText);
//Console.WriteLine($"spawn id={id} name=" + buttonData.ButtonText);

var defaultBtn = hSprite.menuActionSub.GetObject(7);

Expand Down Expand Up @@ -163,10 +163,13 @@ private static bool SpawnSingleButton(int id, HSprite hSprite, CustomTrespassing
private static class Hooks
{
private static bool? _defaultBtnShown;
private static bool _applied = false;

public static void ApplyHooks()
{
if (_applied) return;
Harmony.CreateAndPatchAll(typeof(Hooks), typeof(Hooks).FullName);
_applied = true;
}

[HarmonyPostfix]
Expand Down Expand Up @@ -206,8 +209,7 @@ private static void InitPointMenuAndHelpPost(HSprite __instance, int _kind)
// Not initialized / no custom buttons
if (_defaultBtnShown == null) return;

Console.WriteLine(
$"_kind={_kind} _defaultBtnShown={(_defaultBtnShown != null ? _defaultBtnShown.Value.ToString() : "NULL")} active={__instance.autoDisableTrespassingHelp.gameObject.activeSelf}");
//Console.WriteLine($"_kind={_kind} _defaultBtnShown={(_defaultBtnShown != null ? _defaultBtnShown.Value.ToString() : "NULL")} active={__instance.autoDisableTrespassingHelp.gameObject.activeSelf}");

if (_kind == 3)
{
Expand Down

0 comments on commit fc901cd

Please sign in to comment.