Skip to content
This repository was archived by the owner on Apr 21, 2024. It is now read-only.

Commit cb42c2d

Browse files
author
BuildTools
committed
Made the CancellableEvent class an interface and added a few more events
1 parent 4e1f4be commit cb42c2d

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

Event.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using HarmonyLib;
2+
using Splotch.Event.GameEvents;
23
using Splotch.Loader;
34
using System;
45
using System.Collections.Generic;
@@ -127,9 +128,9 @@ public static void RunHandlers(Event e)
127128
/// <summary>
128129
/// An event that can be cancelled
129130
/// </summary>
130-
public abstract class CancellableEvent : Event
131+
public interface Cancellable
131132
{
132-
public bool Cancelled { get; set; } = false;
133+
bool Cancelled { get; set; }
133134
}
134135

135136
/// <summary>
@@ -144,8 +145,9 @@ namespace Splotch.Event.AbilityEvents
144145
/// <summary>
145146
/// A class that should be extended by any ability-related events
146147
/// </summary>
147-
public abstract class AbilityEvent : CancellableEvent
148+
public abstract class AbilityEvent : Event, Cancellable
148149
{
150+
public bool Cancelled { get; set; } = false;
149151

150152
/// <summary>
151153
/// Gets the ability related to the event
@@ -225,13 +227,24 @@ namespace Splotch.Event.PlayerEvents
225227
/// <summary>
226228
/// A class that should be extended by any player-related events
227229
/// </summary>
228-
public abstract class PlayerEvent : Event
230+
public abstract class PlayerEvent : GameEvent
229231
{
230232
/// <summary>
231233
/// Retrieves the player related to the event
232234
/// </summary>
233235
/// <returns></returns>
234236
public abstract Player GetPlayer();
237+
public override GameSessionHandler GetGameSessionHandler()
238+
{
239+
Player player = GetPlayer();
240+
FieldInfo selfRefField = typeof(GameSessionHandler).GetField("selfRef", BindingFlags.Static | BindingFlags.NonPublic);
241+
return selfRefField.GetValue(null) as GameSessionHandler;
242+
}
243+
244+
public SlimeController GetSlimeController()
245+
{
246+
return GetSlimeControllers()[GetPlayer().Id - 1];
247+
}
235248
}
236249

237250
public class PlayerDeathEvent : PlayerEvent
@@ -308,4 +321,20 @@ public static void Patch(ref PlayerBody __instance)
308321
RunHandlers(e);
309322
}
310323
}
324+
325+
}
326+
327+
namespace Splotch.Event.GameEvents
328+
{
329+
public abstract class GameEvent : Event, Cancellable
330+
{
331+
public bool Cancelled { get; set; } = false;
332+
333+
public abstract GameSessionHandler GetGameSessionHandler();
334+
public SlimeController[] GetSlimeControllers()
335+
{
336+
FieldInfo slimeControllersField = typeof(GameSessionHandler).GetField("slimeControllers", BindingFlags.Instance | BindingFlags.NonPublic);
337+
return slimeControllersField.GetValue(GetGameSessionHandler()) as SlimeController[];
338+
}
339+
}
311340
}

ModLoader.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public class ModInfo
125125
public string[] authors;
126126

127127
public SplotchMod splotchMod;
128+
public Assembly assembly;
128129
internal ModInfo(string dll, string className, string id, string name, string description, string version, string[] authors)
129130
{
130131
this.dll = dll;
@@ -146,8 +147,16 @@ internal bool LoadMod(string modFolder)
146147
try
147148
{
148149
string dllAbsolutePath = Path.Combine(modFolder, dll);
149-
Assembly assembly = Assembly.LoadFile(dllAbsolutePath);
150+
Logger.Debug($"Loading {dllAbsolutePath}");
151+
assembly = Assembly.LoadFile(dllAbsolutePath);
152+
Logger.Debug($"Loaded {assembly}");
150153
Type assemblyEntrypoint = assembly.GetType(className);
154+
if (assemblyEntrypoint == null)
155+
{
156+
Logger.Error($"{className} is not a valid class! Valid classes are: {string.Join<Type>(", ", assembly.GetTypes())}, if this is wrong, try changing the name of your assembly (your dll)");
157+
return false;
158+
}
159+
151160
if (assemblyEntrypoint.BaseType == typeof(SplotchMod))
152161
{
153162
splotchMod = (SplotchMod)Activator.CreateInstance(assemblyEntrypoint);

0 commit comments

Comments
 (0)