Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
652 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SFSML.Attributes | ||
{ | ||
public class MyModEntryPoint : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SFSML.Exceptions | ||
{ | ||
class MyCoreException : Exception | ||
{ | ||
public MyCaller caller; | ||
public readonly string file; | ||
public readonly string msg; | ||
public MyCoreException(string message, string myFile) : base("Whoops something went wrong!") | ||
{ | ||
this.file = myFile; | ||
this.msg = message; | ||
} | ||
|
||
public class MyCaller | ||
{ | ||
public readonly string function; | ||
public readonly string file; | ||
public MyCaller(string functionName, string fileName) | ||
{ | ||
this.function = functionName; | ||
this.file = fileName; | ||
} | ||
public string construct() | ||
{ | ||
return function + "()" + " [" + file + "]"; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* User: JordivdMolen | ||
* Date: 2/15/2018 | ||
* Time: 10:35 AM | ||
* | ||
* Using this file for commercial purposes can result | ||
* in violating the license! | ||
*/ | ||
using System; | ||
using SFSML.HookSystem; | ||
|
||
namespace SFSML.HookSystem.HookExceptions | ||
{ | ||
/// <summary> | ||
/// Description of NotHookedException. | ||
/// </summary> | ||
public class NotHookedException : Exception | ||
{ | ||
public MyInitialHook target; | ||
public NotHookedException(MyInitialHook tgt) : base("This hook is not registered in a MyBaseHookable") | ||
{ | ||
this.target = tgt; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
| ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SFSML.HookSystem.MainHooks | ||
{ | ||
class MyGameLoadedHook : MyBaseHook<MyGameLoadedHook> | ||
{ | ||
public ModLoader core; | ||
public MyGameLoadedHook(ModLoader coreLoader, String test) | ||
{ | ||
this.core = coreLoader; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* User: JordivdMolen | ||
* Date: 2/14/2018 | ||
* Time: 9:26 PM | ||
* | ||
* Using this file for commercial purposes can result | ||
* in violating the license! | ||
*/ | ||
using System; | ||
using System.Collections.Generic; | ||
using SFSML.HookSystem.HookExceptions; | ||
using System.Reflection; | ||
|
||
namespace SFSML.HookSystem | ||
{ | ||
/// <summary> | ||
/// Event-like system, baseclass. | ||
/// </summary> | ||
public abstract class MyBaseHook<T> : MyInitialHook | ||
{ | ||
private MyBaseHookable infested = null; | ||
protected Func<T, T> onInvoke = null; | ||
public MyBaseHook() | ||
{ | ||
this.baseType = typeof(T); | ||
} | ||
|
||
/// <summary> | ||
/// setOnInvoke AKA Register hook as hookListener | ||
/// </summary> | ||
/// <param name="hook">This function will be ran when the hook is casted</param> | ||
/// <param name="root">This object should be the object you are registering the hook on.</param> | ||
public void setOnInvoke(Func<T, T> hook, MyBaseHookable root) | ||
{ | ||
if (this.onInvoke == null) | ||
{ | ||
this.onInvoke = hook; | ||
root.registerListener<T>(this); | ||
} | ||
else | ||
{ | ||
throw new Exception("OnInvoke is already set @ setOnInvoke"); | ||
} | ||
} | ||
|
||
public T invoke(T e) | ||
{ | ||
if (!(e is MyBaseHook<T>)) | ||
{ | ||
throw new Exception("event has to be an instace of MyBaseHook<T> @ Invoke"); | ||
} | ||
if (!this.isListener()) | ||
{ | ||
throw new Exception("This hook is not a listener! @ Invoke"); | ||
} | ||
MyBaseHook<T> hookT = ((object) e) as MyBaseHook<T>; | ||
T invokeResult = this.onInvoke(e); | ||
return invokeResult; | ||
} | ||
|
||
|
||
public Dictionary<String,FieldInfo> getEventArgumets() | ||
{ | ||
Dictionary<String, FieldInfo> args = new Dictionary<String, FieldInfo>(); | ||
foreach (FieldInfo fi in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance)) | ||
{ | ||
if (fi.DeclaringType == typeof(T)) | ||
{ | ||
args[fi.Name] = fi; | ||
} | ||
} | ||
return args; | ||
} | ||
|
||
public bool isListener() | ||
{ | ||
return this.onInvoke != null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Created by SharpDevelop. | ||
* User: JordivdMolen | ||
* Date: 2/14/2018 | ||
* Time: 9:39 PM | ||
* | ||
* Using this file for commercial purposes can result | ||
* in violating the license! | ||
*/ | ||
using SFSML.Exceptions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
|
||
namespace SFSML.HookSystem | ||
{ | ||
/// <summary> | ||
/// Description of MyBaseHookable. | ||
/// </summary> | ||
public class MyBaseHookable | ||
{ | ||
private List<MyInitialHook> hooks = new List<MyInitialHook>(); | ||
public MyBaseHookable() | ||
{ | ||
} | ||
|
||
public void registerListener<T>(MyBaseHook<T> e) | ||
{ | ||
if (!e.isListener()) | ||
{ | ||
throw new MyCoreException("This hook is not a listener! @ RegisterListener","registerListener<?>()"); | ||
} | ||
this.hooks.Add(e); | ||
} | ||
public void removeListener(MyInitialHook e) | ||
{ | ||
this.hooks.Remove(e); | ||
} | ||
public T castHook<T>(T e) | ||
{ | ||
T usedCaller = (T) ((MyInitialHook)(object)e).Clone(); | ||
MyBaseHook<T> convertedBase = (Object) e as MyBaseHook<T>; | ||
Dictionary<String, FieldInfo> initialFields = convertedBase.getEventArgumets(); | ||
foreach (MyInitialHook initHook in this.hooks) | ||
{ | ||
T ih = (T) (object) initHook; | ||
MyBaseHook<T> convertedHook = (MyBaseHook<T>) initHook; | ||
T afterInvoke = convertedHook.invoke(usedCaller); | ||
convertedHook = (object) afterInvoke as MyBaseHook<T>; | ||
Dictionary<String, FieldInfo> initHookFields = convertedHook.getEventArgumets(); | ||
if (convertedHook.isCanceled()) | ||
{ | ||
convertedBase.forceCanceled(true); | ||
} | ||
foreach (String fieldName in initialFields.Keys) | ||
{ | ||
FieldInfo orginField = initialFields[fieldName]; | ||
FieldInfo newField = initHookFields[fieldName]; | ||
object orginValue = orginField.GetValue(e); | ||
object newValue = newField.GetValue(afterInvoke); | ||
if (orginValue != newValue) | ||
{ | ||
orginField.SetValue(e, newValue); | ||
} | ||
} | ||
} | ||
return (T) (object) convertedBase; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using SFSML.HookSystem; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace SFSML.HookSystem | ||
{ | ||
public class MyInitialHook : ICloneable | ||
{ | ||
private MyBaseHookable infested = null; | ||
protected Type baseType; | ||
protected bool cancel = false; | ||
public MyInitialHook() | ||
{ | ||
} | ||
|
||
public Type getInitialType() | ||
{ | ||
return this.baseType; | ||
} | ||
|
||
public bool isCanceled() | ||
{ | ||
return this.cancel; | ||
} | ||
|
||
public void forceCanceled(bool state) | ||
{ | ||
this.cancel = state; | ||
} | ||
|
||
public object Clone() | ||
{ | ||
return this.MemberwiseClone(); | ||
} | ||
} | ||
} |
Oops, something went wrong.