Skip to content

Instantly share code, notes, and snippets.

@ByronMayne
Created November 28, 2017 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ByronMayne/b8f2cebe2ca2b89416da3d76c2486dbf to your computer and use it in GitHub Desktop.
Save ByronMayne/b8f2cebe2ca2b89416da3d76c2486dbf to your computer and use it in GitHub Desktop.
This is an example weaver componet
using System;
using Mono.Cecil;
using UnityEngine;
using Mono.Cecil.Cil;
namespace Weaver
{
// Inherit WeaverComponent to get callbacks and to show up as a componet in our ScriptableObject settings.
public class ServerCommandComponent : WeaverComponent
{
// Used for logging the name really does not matter.
public override string addinName
{
get
{
return "Server Command";
}
}
// Defines which type of callbacks you want. Used as an optimization
public override DefinitionType effectedDefintions
{
get
{
return DefinitionType.Method;
}
}
// Invoked for every method in each assembly that is listed in WeavedAssemblies in settings.
public override void VisitMethod(MethodDefinition methodDefinition)
{
CustomAttribute serverCommandAttribute = methodDefinition.GetCustomAttribute<ServerCommandAttribute>();
if (serverCommandAttribute == null)
{
// Our method does not have the attribute so we skip it.
return;
}
// Do the IL Injection.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment