Skip to content

Commit

Permalink
Built versuion pre-1.0.0.a
Browse files Browse the repository at this point in the history
  • Loading branch information
JMteam09 committed Feb 21, 2018
1 parent e5523e0 commit 2e9e221
Show file tree
Hide file tree
Showing 13 changed files with 652 additions and 0 deletions.
Binary file added Builds/Managed/Assembly-CSharp.dll
Binary file not shown.
Binary file added Builds/preview-mod/TestMod1.dll
Binary file not shown.
11 changes: 11 additions & 0 deletions ModLoader/Attributes/MyModEntryPoint.cs
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SFSML.Attributes
{
public class MyModEntryPoint : Attribute
{
}
}
34 changes: 34 additions & 0 deletions ModLoader/Exceptions/MyCoreException.cs
@@ -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 + "]";
}
}
}
}
26 changes: 26 additions & 0 deletions ModLoader/HookSystem/HookExceptions/NotHookedException.cs
@@ -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;
}
}
}
17 changes: 17 additions & 0 deletions ModLoader/HookSystem/MainHooks/MyGameLoadedHook.cs
@@ -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;
}
}
}
81 changes: 81 additions & 0 deletions ModLoader/HookSystem/MyBaseHook.cs
@@ -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;
}
}
}
70 changes: 70 additions & 0 deletions ModLoader/HookSystem/MyBaseHookable.cs
@@ -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;
}
}
}
38 changes: 38 additions & 0 deletions ModLoader/HookSystem/MyInitialHook.cs
@@ -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();
}
}
}

0 comments on commit 2e9e221

Please sign in to comment.