public void LoadPlugin(string name) { Logger.LogDebug("[MoonSharp] Loading plugin " + name + "."); if (plugins.ContainsKey(name)) { Logger.LogError("[MoonSharp] " + name + " plugin is already loaded."); throw new InvalidOperationException("[MoonSharp] " + name + " plugin is already loaded."); } try { string code = GetPluginScriptText(name); DirectoryInfo path = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name)); LuaPlugin plugin = new LuaPlugin(name, code, path); InstallHooks(plugin); plugins.Add(name, plugin); if (plugin.Globals.Contains("On_PluginInit")) { plugin.Invoke("On_PluginInit", new object[0]); } Logger.Log("[MoonSharp] " + name + " plugin was loaded successfuly."); } catch (Exception ex) { string arg = name + " plugin could not be loaded."; Server.GetServer().BroadcastFrom(Name, arg); Logger.LogError(arg); Logger.LogException(ex); } }
private void InstallHooks(LuaPlugin plugin) { foreach (string method in plugin.Globals) { if (!method.StartsWith("On_") && !method.EndsWith("Callback")) { continue; } Logger.LogDebug("Found function: " + method); switch (method) { case "On_ServerInit": Hooks.OnServerInit += new Hooks.ServerInitDelegate(plugin.OnServerInit); break; case "On_ServerShutdown": Hooks.OnServerShutdown += new Hooks.ServerShutdownDelegate(plugin.OnServerShutdown); break; case "On_ItemsLoaded": Hooks.OnItemsLoaded += new Hooks.ItemsDatablocksLoaded(plugin.OnItemsLoaded); break; case "On_TablesLoaded": Hooks.OnTablesLoaded += new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); break; case "On_Chat": Hooks.OnChat += new Hooks.ChatHandlerDelegate(plugin.OnChat); break; case "On_Console": OnConsoleReceived += new ConsoleHandlerDelegate(plugin.OnConsole); break; case "On_Command": Hooks.OnCommand += new Hooks.CommandHandlerDelegate(plugin.OnCommand); break; case "On_PlayerConnected": Hooks.OnPlayerConnected += new Hooks.ConnectionHandlerDelegate(plugin.OnPlayerConnected); break; case "On_PlayerDisconnected": Hooks.OnPlayerDisconnected += new Hooks.DisconnectionHandlerDelegate(plugin.OnPlayerDisconnected); break; case "On_PlayerKilled": Hooks.OnPlayerKilled += new Hooks.KillHandlerDelegate(plugin.OnPlayerKilled); break; case "On_PlayerHurt": Hooks.OnPlayerHurt += new Hooks.HurtHandlerDelegate(plugin.OnPlayerHurt); break; case "On_PlayerSpawn": Hooks.OnPlayerSpawning += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawn); break; case "On_PlayerSpawned": Hooks.OnPlayerSpawned += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawned); break; case "On_PlayerGathering": Hooks.OnPlayerGathering += new Hooks.PlayerGatheringHandlerDelegate(plugin.OnPlayerGathering); break; case "On_EntityHurt": Hooks.OnEntityHurt += new Hooks.EntityHurtDelegate(plugin.OnEntityHurt); break; case "On_EntityDecay": Hooks.OnEntityDecay += new Hooks.EntityDecayDelegate(plugin.OnEntityDecay); break; case "On_EntityDestroyed": Hooks.OnEntityDestroyed += new Hooks.EntityDestroyedDelegate(plugin.OnEntityDestroyed); break; case "On_EntityDeployed": Hooks.OnEntityDeployedWithPlacer += new Hooks.EntityDeployedWithPlacerDelegate(plugin.OnEntityDeployed); break; case "On_NPCHurt": Hooks.OnNPCHurt += new Hooks.HurtHandlerDelegate(plugin.OnNPCHurt); break; case "On_NPCKilled": Hooks.OnNPCKilled += new Hooks.KillHandlerDelegate(plugin.OnNPCKilled); break; case "On_BlueprintUse": Hooks.OnBlueprintUse += new Hooks.BlueprintUseHandlerDelegate(plugin.OnBlueprintUse); break; case "On_DoorUse": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin.OnDoorUse); break; case "On_AllPluginsLoaded": LuaModule.OnAllLoaded += new LuaModule.AllLoadedDelegate(plugin.OnAllPluginsLoaded); break; case "On_PlayerTeleport": Hooks.OnPlayerTeleport += new Hooks.TeleportDelegate(plugin.OnPlayerTeleport); break; case "On_PluginInit": plugin.Invoke("On_PluginInit", new object[0]); break; case "On_Crafting": Hooks.OnCrafting += new Hooks.CraftingDelegate(plugin.OnCrafting); break; case "On_ResourceSpawn": Hooks.OnResourceSpawned += new Hooks.ResourceSpawnDelegate(plugin.OnResourceSpawned); break; case "On_ItemAdded": Hooks.OnItemAdded += new Hooks.ItemAddedDelegate(plugin.OnItemAdded); break; case "On_ItemRemoved": Hooks.OnItemRemoved += new Hooks.ItemRemovedDelegate(plugin.OnItemRemoved); break; case "On_Airdrop": Hooks.OnAirdropCalled += new Hooks.AirdropDelegate(plugin.OnAirdrop); break; //case "On_AirdropCrateDropped": Hooks.OnAirdropCrateDropped += new Hooks.AirdropCrateDroppedDelegate(plugin.OnAirdropCrateDropped); break; case "On_SteamDeny": Hooks.OnSteamDeny += new Hooks.SteamDenyDelegate(plugin.OnSteamDeny); break; case "On_PlayerApproval": Hooks.OnPlayerApproval += new Hooks.PlayerApprovalDelegate(plugin.OnPlayerApproval); break; case "On_Research": Hooks.OnResearch += new Hooks.ResearchDelegate(plugin.OnResearch); break; case "On_ServerSaved": Hooks.OnServerSaved += new Hooks.ServerSavedDelegate(plugin.OnServerSaved); break; case "On_VoiceChat": Hooks.OnShowTalker += new Hooks.ShowTalkerDelegate(plugin.OnShowTalker); break; case "On_ItemPickup": Hooks.OnItemPickup += new Hooks.ItemPickupDelegate(plugin.OnItemPickup); break; case "On_FallDamage": Hooks.OnFallDamage += new Hooks.FallDamageDelegate(plugin.OnFallDamage); break; case "On_LootUse": Hooks.OnLootUse += new Hooks.LootEnterDelegate(plugin.OnLootUse); break; case "On_PlayerBan": Hooks.OnPlayerBan += new Hooks.BanEventDelegate(plugin.OnBanEvent); break; case "On_RepairBench": Hooks.OnRepairBench += new Hooks.RepairBenchEventDelegate(plugin.OnRepairBench); break; case "On_ItemMove": Hooks.OnItemMove += new Hooks.ItemMoveEventDelegate(plugin.OnItemMove); break; case "On_GenericSpawnLoad": Hooks.OnGenericSpawnerLoad += new Hooks.GenericSpawnerLoadDelegate(plugin.OnGenericSpawnLoad); break; case "On_ServerLoaded": Hooks.OnServerLoaded += new Hooks.ServerLoadedDelegate(plugin.OnServerLoaded); break; case "On_SupplySignalExploded": Hooks.OnSupplySignalExpode += new Hooks.SupplySignalDelegate(plugin.OnSupplySignalExploded); break; } } }
//private static List<String> asd = new List<string> {("CanOpenDoor", )}; private void InstallHooks(LuaPlugin plugin) { foreach (string method in plugin.Globals) { if (!method.StartsWith("On_") && !method.EndsWith("Callback")) { continue; } Logger.LogDebug("Found function: " + method); switch (method) { case "On_ServerInit": Hooks.OnServerInit += new Hooks.ServerInitDelegate(plugin.OnServerInit); break; case "On_ServerShutdown": Hooks.OnServerShutdown += new Hooks.ServerShutdownDelegate(plugin.OnServerShutdown); break; case "On_ItemsLoaded": Hooks.OnItemsLoaded += new Hooks.ItemsDatablocksLoaded(plugin.OnItemsLoaded); break; case "On_TablesLoaded": Hooks.OnTablesLoaded += new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); break; case "On_Chat": Hooks.OnChat += new Hooks.ChatHandlerDelegate(plugin.OnChat); break; case "On_Console": OnConsoleReceived += new ConsoleHandlerDelegate(plugin.OnConsole); break; case "On_Command": Hooks.OnCommand += new Hooks.CommandHandlerDelegate(plugin.OnCommand); break; case "On_PlayerConnected": Hooks.OnPlayerConnected += new Hooks.ConnectionHandlerDelegate(plugin.OnPlayerConnected); break; case "On_PlayerDisconnected": Hooks.OnPlayerDisconnected += new Hooks.DisconnectionHandlerDelegate(plugin.OnPlayerDisconnected); break; case "On_PlayerKilled": Hooks.OnPlayerKilled += new Hooks.KillHandlerDelegate(plugin.OnPlayerKilled); break; case "On_PlayerHurt": Hooks.OnPlayerHurt += new Hooks.HurtHandlerDelegate(plugin.OnPlayerHurt); break; case "On_PlayerSpawn": Hooks.OnPlayerSpawning += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawn); break; case "On_PlayerSpawned": Hooks.OnPlayerSpawned += new Hooks.PlayerSpawnHandlerDelegate(plugin.OnPlayerSpawned); break; case "On_PlayerGathering": Hooks.OnPlayerGathering += new Hooks.PlayerGatheringHandlerDelegate(plugin.OnPlayerGathering); break; case "On_EntityHurt": Hooks.OnEntityHurt += new Hooks.EntityHurtDelegate(plugin.OnEntityHurt); break; case "On_EntityDecay": Hooks.OnEntityDecay += new Hooks.EntityDecayDelegate(plugin.OnEntityDecay); break; case "On_EntityDestroyed": Hooks.OnEntityDestroyed += new Hooks.EntityDestroyedDelegate(plugin.OnEntityDestroyed); break; case "On_EntityDeployed": Hooks.OnEntityDeployed += new Hooks.EntityDeployedDelegate(plugin.OnEntityDeployed); break; case "On_NPCHurt": Hooks.OnNPCHurt += new Hooks.HurtHandlerDelegate(plugin.OnNPCHurt); break; case "On_NPCKilled": Hooks.OnNPCKilled += new Hooks.KillHandlerDelegate(plugin.OnNPCKilled); break; case "On_BlueprintUse": Hooks.OnBlueprintUse += new Hooks.BlueprintUseHandlerDelegate(plugin.OnBlueprintUse); break; case "On_DoorUse": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin.OnDoorUse); break; case "On_AllPluginsLoaded": LuaModule.OnAllLoaded += new LuaModule.AllLoadedDelegate(plugin.OnAllPluginsLoaded); break; case "On_PlayerTeleport": Hooks.OnPlayerTeleport += new Hooks.TeleportDelegate(plugin.OnPlayerTeleport); break; case "On_PluginInit": plugin.Invoke("On_PluginInit", new object[0]); break; case "On_Crafting": Hooks.OnCrafting += new Hooks.CraftingDelegate(plugin.OnCrafting); break; case "On_ResourceSpawn": Hooks.OnResourceSpawned += new Hooks.ResourceSpawnDelegate(plugin.OnResourceSpawned); break; case "On_ItemAdded": Hooks.OnItemAdded += new Hooks.ItemAddedDelegate(plugin.OnItemAdded); break; case "On_ItemRemoved": Hooks.OnItemRemoved += new Hooks.ItemRemovedDelegate(plugin.OnItemRemoved); break; case "On_Airdrop": Hooks.OnAirdropCalled += new Hooks.AirdropDelegate(plugin.OnAirdrop); break; case "On_SteamDeny": Hooks.OnSteamDeny += new Hooks.SteamDenyDelegate(plugin.OnSteamDeny); break; case "On_PlayerApproval": Hooks.OnPlayerApproval += new Hooks.PlayerApprovalDelegate(plugin.OnPlayerApproval); break; case "On_Research": Hooks.OnResearch += new Hooks.ResearchDelegate(plugin.OnResearch); break; //TODO: Oxide Hook Names /*case "Init": plugin.Invoke("Init", new object[0]); break; * //case "ModifyDamage": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin); break; * case "OnBlueprintUse": Hooks.OnBlueprintUse += new Hooks.BlueprintUseHandlerDelegate(plugin.OnBlueprintUseOxide); break; * case "OnDatablocksLoaded": Hooks.OnTablesLoaded += new Hooks.LootTablesLoaded(plugin.OnTablesLoaded); break; * //case "OnDoorToggle": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin); break; * //case "OnHurt": Hooks.Hu += new Hooks.DoorOpenHandlerDelegate(plugin); break; * case "OnItemAdded": Hooks.OnItemAdded += new Hooks.ItemAddedDelegate(plugin); break; * case "OnItemRemoved": Hooks.OnItemRemoved += new Hooks.ItemRemovedDelegate(plugin); break; * //case "OnKilled": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin); break; * case "OnPlaceStructure": Hooks.OnEntityDeployed += new Hooks.EntityDeployedDelegate(plugin); break; * //case "OnResearchItem": Hooks.OnDoorUse += new Hooks.DoorOpenHandlerDelegate(plugin); break; * case "OnResourceNodeLoaded": Hooks.OnResourceSpawned += new Hooks.ResourceSpawnDelegate(plugin); break; * case "OnRunCommand": Hooks.OnConsoleReceived += new Hooks.ConsoleHandlerDelegate(plugin); break; * case "OnServerInitialized": Hooks.OnServerInit += new Hooks.ServerInitDelegate(plugin); break; * case "OnSpawnPlayer": Hooks.OnPlayerSpawned += new Hooks.PlayerSpawnHandlerDelegate(plugin); break; * case "OnStartCrafting": Hooks.OnCrafting += new Hooks.CraftingDelegate(plugin); break; * case "OnStructureDecay": Hooks.OnEntityDecay += new Hooks.EntityDecayDelegate(plugin); break; * case "OnUserApprove": Hooks.OnPlayerApproval += new Hooks.PlayerApprovalDelegate(plugin); break; * case "OnUserChat": Hooks.OnChat += new Hooks.ChatHandlerDelegate(plugin); break; * case "OnUserConnect": Hooks.OnPlayerConnected += new Hooks.ConnectionHandlerDelegate(plugin); break; * case "OnUserDisconnect": Hooks.OnPlayerDisconnected += new Hooks.DisconnectionHandlerDelegate(plugin); break; * case "PostInit": LuaModule.OnAllLoaded += new LuaModule.AllLoadedDelegate(plugin.OnAllPluginsLoaded); break;*/ } } }