public void HookBase(HookPoint hookPoint, HookOrder order, NLua.LuaFunction callback) { var targetType = hookPoint.DelegateType.GetGenericArguments()[0]; var call = this.GetType().GetMethod("InternalCall");//.MakeGenericMethod(targetType); var act = typeof(HookAction <>).MakeGenericType(targetType); var inst = Activator.CreateInstance(act, call); //if (initialized) //hookPoint.HookBase(this, new HookAction<Object>((ref HookContext ctx, ref Object args) => //{ // callback.Call(ctx, args); //})); //else //{ // lock (desiredHooks) // desiredHooks.Add(new HookEntry // { // hookPoint = hookPoint, // callback = new HookAction<Object>((ref HookContext ctx, ref Object args) => // { // callback.Call(ctx, args); // }), // order = order // }); //} }
//public static readonly HookPoint<HookArgs.PatchServer> PatchServer; static HookPoints() { ConsoleMessageReceived = new HookPoint <HookArgs.ConsoleMessageReceived>("console-message-received"); //UnkownReceivedPacket = new HookPoint<HookArgs.UnkownReceivedPacket>("unkown-receive-packet"); //UnkownSendPacket = new HookPoint<HookArgs.UnkownSendPacket>("unkown-send-packet"); //PlayerTeleport = new HookPoint<HookArgs.PlayerTeleport>("player-teleport"); ServerStateChange = new HookPoint <HookArgs.ServerStateChange>("server-state-change"); NewConnection = new HookPoint <HookArgs.NewConnection>("new-connection"); PluginLoadRequest = new HookPoint <HookArgs.PluginLoadRequest>("plugin-load-request"); ConnectionRequestReceived = new HookPoint <HookArgs.ConnectionRequestReceived>("connection-request-received"); DisconnectReceived = new HookPoint <HookArgs.DisconnectReceived>("disconnect-received"); ServerPassReceived = new HookPoint <HookArgs.ServerPassReceived>("server-pass-received"); PlayerPassReceived = new HookPoint <HookArgs.PlayerPassReceived>("player-pass-received"); PlayerDataReceived = new HookPoint <HookArgs.PlayerDataReceived>("player-data-received"); StateUpdateReceived = new HookPoint <HookArgs.StateUpdateReceived>("state-update-received"); InventoryItemReceived = new HookPoint <HookArgs.InventoryItemReceived>("inventory-item-received"); ObituaryReceived = new HookPoint <HookArgs.ObituaryReceived>("obituary-received"); PlayerWorldAlteration = new HookPoint <HookArgs.PlayerWorldAlteration>("player-world-alteration"); //DoorStateChanged = new HookPoint<HookArgs.DoorStateChanged>("door-state-changed"); LiquidFlowReceived = new HookPoint <HookArgs.LiquidFlowReceived>("liquid-flow-received"); ProjectileReceived = new HookPoint <HookArgs.ProjectileReceived>("projectile-received"); KillProjectileReceived = new HookPoint <HookArgs.KillProjectileReceived>("kill-projectile-received"); TileSquareReceived = new HookPoint <HookArgs.TileSquareReceived>("tile-square-received"); ChestBreakReceived = new HookPoint <HookArgs.ChestBreakReceived>("chest-break-received"); ChestOpenReceived = new HookPoint <HookArgs.ChestOpenReceived>("chest-open-received"); PvpSettingReceived = new HookPoint <HookArgs.PvpSettingReceived>("pvp-setting-received"); PartySettingReceived = new HookPoint <HookArgs.PartySettingReceived>("party-setting-received"); PlayerEnteringGame = new HookPoint <HookArgs.PlayerEnteringGame>("player-entering-game"); PlayerEnteredGame = new HookPoint <HookArgs.PlayerEnteredGame>("player-entered-game"); PlayerLeftGame = new HookPoint <HookArgs.PlayerLeftGame>("player-left-game"); PlayerAuthenticationChanging = new HookPoint <HookArgs.PlayerAuthenticationChanging>("player-auth-changing"); PlayerAuthenticationChanged = new HookPoint <HookArgs.PlayerAuthenticationChanged>("player-auth-change"); //Explosion = new HookPoint<HookArgs.Explosion>("explosion"); SignTextSet = new HookPoint <HookArgs.SignTextSet>("sign-text-set"); SignTextGet = new HookPoint <HookArgs.SignTextGet>("sign-text-get"); PluginsLoaded = new HookPoint <HookArgs.PluginsLoaded>("plugins-loaded"); //WorldLoaded = new HookPoint<HookArgs.WorldLoaded>("world-loaded"); //PlayerHurt = new HookPoint<HookArgs.PlayerHurt>("player-hurt"); //NpcHurt = new HookPoint<HookArgs.NpcHurt>("npc-hurt"); //NpcCreation = new HookPoint<HookArgs.NpcCreation>("npc-creation"); PlayerTriggeredEvent = new HookPoint <HookArgs.PlayerTriggeredEvent>("player-triggered-event"); PlayerChat = new HookPoint <HookArgs.PlayerChat>("player-chat"); Command = new HookPoint <HookArgs.Command>("command"); //WorldGeneration = new HookPoint<HookArgs.WorldGeneration>("world-generation"); WorldRequestMessage = new HookPoint <HookArgs.WorldRequestMessage>("world-request-message"); StartDefaultServer = new HookPoint <HookArgs.StartDefaultServer>("start-default-server"); //StatusTextChanged = new HookPoint<HookArgs.StatusTextChanged>("status-text-changed"); SendNetData = new HookPoint <HookArgs.SendNetData>("netmessage-senddata"); //UpdateServer = new HookPoint<HookArgs.UpdateServer>("update-server"); ProgramStart = new HookPoint <HookArgs.ProgramStart>("program-start"); StartCommandProcessing = new HookPoint <HookArgs.StartCommandProcessing>("start-command-processing"); ConfigurationLine = new HookPoint <HookArgs.ConfigurationLine>("config-line"); AddBan = new HookPoint <HookArgs.AddBan>("add-ban"); NPCSpawn = new HookPoint <HookArgs.NPCSpawn>("npc-spawn"); InvasionNPCSpawn = new HookPoint <HookArgs.InvasionNPCSpawn>("invasion-npc-spawn"); PlayerPreGreeting = new HookPoint <HookArgs.PlayerPreGreeting>("player-pre-greeting"); }
public void HookBase(HookPoint hookPoint, HookOrder order, Delegate callback) { if (initialized) { hookPoint.HookBase(this, callback); } else { lock (desiredHooks) desiredHooks.Add(new HookEntry { hookPoint = hookPoint, callback = callback, order = order }); } }
internal bool Dispose(object state = null) { if (Interlocked.CompareExchange(ref disposed, 1, 0) == 1) { return(true); } var result = Disable(); try { Disposed(state); } catch (Exception e) { Tools.WriteLine("Exception in disposal handler of plugin " + Name); Tools.WriteLine(e); result = false; } commands.Clear(); var hooks = new HookPoint[this.hooks.Count]; this.hooks.CopyTo(hooks, 0, hooks.Length); foreach (var hook in hooks) { hook.Unhook(this); } if (this.hooks.Count > 0) { Tools.WriteLine("Warning: failed to clean up {0} hooks of plugin {1}.", this.hooks.Count, Name); this.hooks.Clear(); } return(result); }
//public void HookBase(HookPoint hookPoint, HookOrder order, NLua.LuaFunction callback) //{ // if (initialized) // hookPoint.HookBase(this, new HookAction<Object>((ref HookContext ctx, ref Object args) => // { // callback.Call(ctx, args); // })); // else // { // lock (desiredHooks) // desiredHooks.Add(new HookEntry // { // hookPoint = hookPoint, // callback = new HookAction<Object>((ref HookContext ctx, ref Object args) => // { // callback.Call(ctx, args); // }), // order = order // }); // } //} public void Unhook(HookPoint hookPoint) { if (initialized) { hookPoint.Unhook(this); } else { lock (desiredHooks) { int i = 0; foreach (var h in desiredHooks) { if (h.hookPoint == hookPoint) { desiredHooks.RemoveAt(i); break; } i++; } } } }
//public static readonly HookPoint<HookArgs.PatchServer> PatchServer; static HookPoints() { ConsoleMessageReceived = new HookPoint<HookArgs.ConsoleMessageReceived>("console-message-received"); // UnknownReceivedPacket = new HookPoint<HookArgs.UnknownReceivedPacket>("unknown-receive-packet"); // UnknownSendPacket = new HookPoint<HookArgs.UnknownSendPacket>("unknown-send-packet"); //PlayerTeleport = new HookPoint<HookArgs.PlayerTeleport>("player-teleport"); ServerStateChange = new HookPoint<HookArgs.ServerStateChange>("server-state-change"); NewConnection = new HookPoint<HookArgs.NewConnection>("new-connection"); PluginLoadRequest = new HookPoint<HookArgs.PluginLoadRequest>("plugin-load-request"); ConnectionRequestReceived = new HookPoint<HookArgs.ConnectionRequestReceived>("connection-request-received"); DisconnectReceived = new HookPoint<HookArgs.DisconnectReceived>("disconnect-received"); ServerPassReceived = new HookPoint<HookArgs.ServerPassReceived>("server-pass-received"); PlayerPassReceived = new HookPoint<HookArgs.PlayerPassReceived>("player-pass-received"); PlayerDataReceived = new HookPoint<HookArgs.PlayerDataReceived>("player-data-received"); StateUpdateReceived = new HookPoint<HookArgs.StateUpdateReceived>("state-update-received"); InventoryItemReceived = new HookPoint<HookArgs.InventoryItemReceived>("inventory-item-received"); ObituaryReceived = new HookPoint<HookArgs.ObituaryReceived>("obituary-received"); PlayerWorldAlteration = new HookPoint<HookArgs.PlayerWorldAlteration>("player-world-alteration"); //DoorStateChanged = new HookPoint<HookArgs.DoorStateChanged>("door-state-changed"); LiquidFlowReceived = new HookPoint<HookArgs.LiquidFlowReceived>("liquid-flow-received"); ProjectileReceived = new HookPoint<HookArgs.ProjectileReceived>("projectile-received"); KillProjectileReceived = new HookPoint<HookArgs.KillProjectileReceived>("kill-projectile-received"); TileSquareReceived = new HookPoint<HookArgs.TileSquareReceived>("tile-square-received"); ChestBreakReceived = new HookPoint<HookArgs.ChestBreakReceived>("chest-break-received"); ChestOpenReceived = new HookPoint<HookArgs.ChestOpenReceived>("chest-open-received"); PvpSettingReceived = new HookPoint<HookArgs.PvpSettingReceived>("pvp-setting-received"); PartySettingReceived = new HookPoint<HookArgs.PartySettingReceived>("party-setting-received"); PlayerEnteringGame = new HookPoint<HookArgs.PlayerEnteringGame>("player-entering-game"); PlayerEnteredGame = new HookPoint<HookArgs.PlayerEnteredGame>("player-entered-game"); PlayerLeftGame = new HookPoint<HookArgs.PlayerLeftGame>("player-left-game"); PlayerAuthenticationChanging = new HookPoint<HookArgs.PlayerAuthenticationChanging>("player-auth-changing"); PlayerAuthenticationChanged = new HookPoint<HookArgs.PlayerAuthenticationChanged>("player-auth-change"); //Explosion = new HookPoint<HookArgs.Explosion>("explosion"); SignTextSet = new HookPoint<HookArgs.SignTextSet>("sign-text-set"); SignTextGet = new HookPoint<HookArgs.SignTextGet>("sign-text-get"); PluginsLoaded = new HookPoint<HookArgs.PluginsLoaded>("plugins-loaded"); //WorldLoaded = new HookPoint<HookArgs.WorldLoaded>("world-loaded"); //PlayerHurt = new HookPoint<HookArgs.PlayerHurt>("player-hurt"); //NpcHurt = new HookPoint<HookArgs.NpcHurt>("npc-hurt"); //NpcCreation = new HookPoint<HookArgs.NpcCreation>("npc-creation"); PlayerTriggeredEvent = new HookPoint<HookArgs.PlayerTriggeredEvent>("player-triggered-event"); PlayerChat = new HookPoint<HookArgs.PlayerChat>("player-chat"); Command = new HookPoint<HookArgs.Command>("command"); //WorldGeneration = new HookPoint<HookArgs.WorldGeneration>("world-generation"); WorldRequestMessage = new HookPoint<HookArgs.WorldRequestMessage>("world-request-message"); StartDefaultServer = new HookPoint<HookArgs.StartDefaultServer>("start-default-server"); //StatusTextChanged = new HookPoint<HookArgs.StatusTextChanged>("status-text-changed"); SendNetMessage = new HookPoint<HookArgs.SendNetMessage>("send-net-message"); ReceiveNetMessage = new HookPoint<HookArgs.ReceiveNetMessage>("receive-net-message"); //UpdateServer = new HookPoint<HookArgs.UpdateServer>("update-server"); ProgramStart = new HookPoint<HookArgs.ProgramStart>("program-start"); StartCommandProcessing = new HookPoint<HookArgs.StartCommandProcessing>("start-command-processing"); ConfigurationLine = new HookPoint<HookArgs.ConfigurationLine>("config-line"); AddBan = new HookPoint<HookArgs.AddBan>("add-ban"); NPCSpawn = new HookPoint<HookArgs.NPCSpawn>("npc-spawn"); InvasionNPCSpawn = new HookPoint<HookArgs.InvasionNPCSpawn>("invasion-npc-spawn"); PlayerPreGreeting = new HookPoint<HookArgs.PlayerPreGreeting>("player-pre-greeting"); NPCKilled = new HookPoint<HookArgs.NPCKilled>("npc-killed"); InvasionWarning = new HookPoint<HookArgs.InvasionWarning>("invasion-warning"); }
public void Hook <T>(HookPoint <T> hookPoint, HookOrder order, HookAction <T> callback) { HookBase(hookPoint, order, callback); }
public void Hook <T>(HookPoint <T> hookPoint, HookAction <T> callback) { Hook <T>(hookPoint, HookOrder.NORMAL, callback); }