Skip to content

Commit

Permalink
Apply new code style formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
catapillie committed Dec 20, 2022
1 parent 34f849b commit 091f724
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 105 deletions.
103 changes: 51 additions & 52 deletions Code/Behavior/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,73 @@
using MonoMod.Utils;
using System.Reflection;

namespace Celeste.Mod.ShatteringStrawberries
namespace Celeste.Mod.ShatteringStrawberries;

public static class Hooks
{
public static class Hooks
{
#region Used methods & types
#region Used methods & types

private static readonly MethodInfo m_Strawberry_CollectRountine
= typeof(Strawberry).GetMethod("CollectRoutine", BindingFlags.Instance | BindingFlags.NonPublic)
.GetStateMachineTarget();
private static readonly MethodInfo m_Strawberry_CollectRountine
= typeof(Strawberry).GetMethod("CollectRoutine", BindingFlags.Instance | BindingFlags.NonPublic)
.GetStateMachineTarget();

private static readonly MethodInfo m_Entity_RemoveSelf
= typeof(Entity).GetMethod(nameof(Entity.RemoveSelf), BindingFlags.Instance | BindingFlags.Public);
private static readonly MethodInfo m_Entity_RemoveSelf
= typeof(Entity).GetMethod(nameof(Entity.RemoveSelf), BindingFlags.Instance | BindingFlags.Public);

private static readonly MethodInfo m_PlayerDeadBody_DeathRountine
= typeof(PlayerDeadBody).GetMethod("DeathRoutine", BindingFlags.Instance | BindingFlags.NonPublic)
.GetStateMachineTarget();
private static readonly MethodInfo m_PlayerDeadBody_DeathRountine
= typeof(PlayerDeadBody).GetMethod("DeathRoutine", BindingFlags.Instance | BindingFlags.NonPublic)
.GetStateMachineTarget();

private static readonly FieldInfo f_PlayerDeadBody_DeathRoutine
= typeof(PlayerDeadBody).GetNestedType("<DeathRoutine>d__15", BindingFlags.NonPublic)
.GetField("<>2__current", BindingFlags.Instance | BindingFlags.NonPublic);

private static readonly FieldInfo f_PlayerDeadBody_DeathRoutine
= typeof(PlayerDeadBody).GetNestedType("<DeathRoutine>d__15", BindingFlags.NonPublic)
.GetField("<>2__current", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly FieldInfo f_PlayerDeadBody_player
= typeof(PlayerDeadBody).GetField("player", BindingFlags.Instance | BindingFlags.NonPublic);

private static readonly FieldInfo f_PlayerDeadBody_player
= typeof(PlayerDeadBody).GetField("player", BindingFlags.Instance | BindingFlags.NonPublic);
#endregion

#endregion
private static ILHook IL_Strawberry_CollectRountine;
private static ILHook IL_PlayerDeadBody_DeathRountine;

private static ILHook IL_Strawberry_CollectRountine;
private static ILHook IL_PlayerDeadBody_DeathRountine;
internal static void Hook()
{
IL_Strawberry_CollectRountine = new ILHook(m_Strawberry_CollectRountine, Mod_Strawberry_CollectRountine);
IL_PlayerDeadBody_DeathRountine = new ILHook(m_PlayerDeadBody_DeathRountine, Mod_PlayerDeadBody_DeathRountine);
}

internal static void Hook()
{
IL_Strawberry_CollectRountine = new ILHook(m_Strawberry_CollectRountine, Mod_Strawberry_CollectRountine);
IL_PlayerDeadBody_DeathRountine = new ILHook(m_PlayerDeadBody_DeathRountine, Mod_PlayerDeadBody_DeathRountine);
}
internal static void Unhook()
{
IL_Strawberry_CollectRountine.Dispose();
IL_PlayerDeadBody_DeathRountine.Dispose();
}

internal static void Unhook()
{
IL_Strawberry_CollectRountine.Dispose();
IL_PlayerDeadBody_DeathRountine.Dispose();
}
private static void Mod_Strawberry_CollectRountine(ILContext il)
{
ILCursor cursor = new(il);

private static void Mod_Strawberry_CollectRountine(ILContext il)
{
ILCursor cursor = new(il);
cursor.GotoNext(MoveType.After, instr => instr.MatchCallvirt(m_Entity_RemoveSelf));
cursor.Emit(OpCodes.Ldloc_1);
cursor.EmitDelegate(Strawberries.OnShatter);
}

cursor.GotoNext(MoveType.After, instr => instr.MatchCallvirt(m_Entity_RemoveSelf));
cursor.Emit(OpCodes.Ldloc_1);
cursor.EmitDelegate(Strawberries.OnShatter);
}
private static void Mod_PlayerDeadBody_DeathRountine(ILContext il)
{
ILCursor cursor = new(il);
cursor.GotoNext(MoveType.After, instr => instr.MatchStfld<DeathEffect>(nameof(DeathEffect.OnUpdate)));

private static void Mod_PlayerDeadBody_DeathRountine(ILContext il)
{
ILCursor cursor = new(il);
cursor.GotoNext(MoveType.After, instr => instr.MatchStfld<DeathEffect>(nameof(DeathEffect.OnUpdate)));
Instruction skip = cursor.Clone()
.GotoNext(MoveType.After, instr => instr.MatchStfld(f_PlayerDeadBody_DeathRoutine))
.Next;

Instruction skip = cursor.Clone()
.GotoNext(MoveType.After, instr => instr.MatchStfld(f_PlayerDeadBody_DeathRoutine))
.Next;
Instruction next = cursor.Next;

Instruction next = cursor.Next;
cursor.EmitDelegate(() => ShatteringStrawberriesModule.Settings.PlayerExplosion);
cursor.Emit(OpCodes.Brfalse_S, next);

cursor.EmitDelegate(() => ShatteringStrawberriesModule.Settings.PlayerExplosion);
cursor.Emit(OpCodes.Brfalse_S, next);
cursor.Emit(OpCodes.Ldloc_1);
cursor.EmitDelegate(Players.OnShatter);

cursor.Emit(OpCodes.Ldloc_1);
cursor.EmitDelegate(Players.OnShatter);

cursor.Emit(OpCodes.Br_S, skip);
}
cursor.Emit(OpCodes.Br_S, skip);
}
}
45 changes: 25 additions & 20 deletions Code/ShatteringStrawberriesModule.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
using Celeste.Mod.ShatteringStrawberries.Components;
using System;

namespace Celeste.Mod.ShatteringStrawberries {
public class ShatteringStrawberriesModule : EverestModule {
public static ShatteringStrawberriesModule Instance { get; private set; }
namespace Celeste.Mod.ShatteringStrawberries;

public override Type SettingsType => typeof(ShatteringStrawberriesModuleSettings);
public static ShatteringStrawberriesModuleSettings Settings => (ShatteringStrawberriesModuleSettings) Instance._Settings;
public class ShatteringStrawberriesModule : EverestModule
{
public static ShatteringStrawberriesModule Instance { get; private set; }

public ShatteringStrawberriesModule() {
Instance = this;
}
public override Type SettingsType => typeof(ShatteringStrawberriesModuleSettings);
public static ShatteringStrawberriesModuleSettings Settings => (ShatteringStrawberriesModuleSettings)Instance._Settings;

public override void Load() {
Hooks.Hook();
}
public ShatteringStrawberriesModule()
{
Instance = this;
}

public override void Load()
{
Hooks.Hook();
}

public override void LoadContent(bool firstLoad) {
base.LoadContent(firstLoad);
public override void LoadContent(bool firstLoad)
{
base.LoadContent(firstLoad);

Strawberries.InitializeContent();
Players.InitializeContent();
DebrisLiquid.InitializeContent();
}
Strawberries.InitializeContent();
Players.InitializeContent();
DebrisLiquid.InitializeContent();
}

public override void Unload() {
Hooks.Unhook();
}
public override void Unload()
{
Hooks.Unhook();
}
}
71 changes: 38 additions & 33 deletions Code/UI/TextMenuHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,43 @@
using System;
using System.Collections.Generic;

namespace Celeste.Mod.ShatteringStrawberries.UI {
public static class TextMenuHelper {
public static TextMenu.Item AddWarning(this TextMenu.Item option, TextMenu containingMenu, string description, bool icon) {
TextMenuExt.EaseInSubHeaderExt descriptionText = new(description, false, containingMenu, icon ? "areas/new-yellow" : null) {
TextColor = Color.Firebrick,
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
if (items.Contains(option))
TextMenuExt.Insert(containingMenu, items.IndexOf(option) + 1, descriptionText);

option.OnEnter = (Action)Delegate.Combine(option.OnEnter, () => { descriptionText.FadeVisible = true; });
option.OnLeave = (Action)Delegate.Combine(option.OnLeave, () => { descriptionText.FadeVisible = false; });

return option;
}

public static TextMenuExt.EaseInSubHeaderExt AddThenGetDescription(this TextMenu.Item option, TextMenu containingMenu, string description) {
TextMenuExt.EaseInSubHeaderExt descriptionText = new(description, false, containingMenu) {
TextColor = Color.DimGray,
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
if (items.Contains(option))
TextMenuExt.Insert(containingMenu, items.IndexOf(option) + 1, descriptionText);

option.OnEnter = (Action)Delegate.Combine(option.OnEnter, () => { descriptionText.FadeVisible = true; });
option.OnLeave = (Action)Delegate.Combine(option.OnLeave, () => { descriptionText.FadeVisible = false; });

return descriptionText;
}
namespace Celeste.Mod.ShatteringStrawberries.UI;

public static class TextMenuHelper
{
public static TextMenu.Item AddWarning(this TextMenu.Item option, TextMenu containingMenu, string description, bool icon)
{
TextMenuExt.EaseInSubHeaderExt descriptionText = new(description, false, containingMenu, icon ? "areas/new-yellow" : null)
{
TextColor = Color.Firebrick,
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
if (items.Contains(option))
TextMenuExt.Insert(containingMenu, items.IndexOf(option) + 1, descriptionText);

option.OnEnter = (Action)Delegate.Combine(option.OnEnter, () => { descriptionText.FadeVisible = true; });
option.OnLeave = (Action)Delegate.Combine(option.OnLeave, () => { descriptionText.FadeVisible = false; });

return option;
}

public static TextMenuExt.EaseInSubHeaderExt AddThenGetDescription(this TextMenu.Item option, TextMenu containingMenu, string description)
{
TextMenuExt.EaseInSubHeaderExt descriptionText = new(description, false, containingMenu)
{
TextColor = Color.DimGray,
HeightExtra = 0f
};

List<TextMenu.Item> items = containingMenu.GetItems();
if (items.Contains(option))
TextMenuExt.Insert(containingMenu, items.IndexOf(option) + 1, descriptionText);

option.OnEnter = (Action)Delegate.Combine(option.OnEnter, () => { descriptionText.FadeVisible = true; });
option.OnLeave = (Action)Delegate.Combine(option.OnLeave, () => { descriptionText.FadeVisible = false; });

return descriptionText;
}
}

0 comments on commit 091f724

Please sign in to comment.