Thread Status:
Not open for further replies.
  1. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Any methods/functions/etc would need to be found by peeking at existing plugins, or doing your own digging into the Rust DLLs. The only things that Oxide provides right now is hooks, which are standard between plugin languages. https://github.com/OxideMod/Oxide/blob/master/Oxide.Ext.Rust/hooks.txt
     
  2. Feramor

    Feramor Shack Builder Plugin Developer

    Calling Library functions with C# I used RustWeb Library to demonstrate.
    To get structure and function list of library
    Code (Text):
            List<string> GetFunctionList(string LibraryName)
            {
                List<string> FunctionList = new List<string>();
                Library CurrentLib = Interface.GetMod().GetLibrary<Library>(LibraryName);
                if (CurrentLib != null)
                {
                    foreach(string Current in CurrentLib.GetFunctionNames())
                    {
                        System.Reflection.MethodInfo CurrentMethod = CurrentLib.GetFunction(Current);
                        FunctionList.Add(CurrentMethod.ToString());
                    }
                }
                return FunctionList;
            }
    Example
    Code (Text):
                List<string> FunctionList = GetFunctionList("RustWeb");
                foreach (string Current in FunctionList)
                {
                    Puts(Current);
                }
    Code (Text):
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] System.String GetRootDir()
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] System.String GetIp()
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Int32 GetPort()
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] System.String GetConfigString(System.String, System.String)
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Boolean GetConfigBool(System.String, Boolean)
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Int32 GetConfigBool(System.String, Int32)
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Boolean AddFriend(System.String, System.String)
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Boolean DeleteFriend(System.String, System.String)
    [2/14/2015 7:53:52 PM] [Oxide] 7:53 PM [Info] Boolean HasFriend(System.String, System.String, Boolean)
    To run a Library Function
    Code (Text):
            object CallLibraryFunction(string LibraryName,string FunctionName,params object[]  parametersArray)
            {
                Library CurrentLib = Interface.GetMod().GetLibrary<Library>(LibraryName);
                if (CurrentLib != null)
                 {

                     Type CurrentType = CurrentLib.GetType();
                     object classInstance = Activator.CreateInstance(CurrentType, null);
                     System.Reflection.MethodInfo CurrentMethod = CurrentLib.GetFunction(FunctionName);
                     System.Reflection.ParameterInfo[] parameters = CurrentMethod.GetParameters();
                     if (parameters.Length == parametersArray.Length)
                     {
                         if (parameters.Length == 0)
                         {
                             return CurrentMethod.Invoke(classInstance, null);
                         }
                         else
                         {
                             return CurrentMethod.Invoke(classInstance, parametersArray);
                         }
                     }
                     else
                         return null;
                 }
                else
                {
                    return null;
                }
            }
    Example
    -With no paramater
    Calling GetRootDir from RustWeb
    string RootDir = (string) CallLibraryFunction("RustWeb","GetRootDir");
    -With paramater
    Code (Text):
            void GetShares(BasePlayer Player)
            {
                foreach (BasePlayer Current in BasePlayer.activePlayerList)
                {
                    bool ISharing = (bool)CallLibraryFunction("RustWeb", "HasFriend", new object[] { Player.userID.ToString(), Current.userID.ToString(), false });
                    bool HeSharing = (bool)CallLibraryFunction("RustWeb", "HasFriend", new object[] { Current.userID.ToString(), Player.userID.ToString(), false });
                    if (ISharing)
                    {
                        Puts("Test1");
                        Current.SendConsoleCommand("chat.add", Player.userID, string.Format("Code Test : Currently you are sharing location with {0}.", Current.displayName.ToString()), 1.0);
                    }
                    if (HeSharing)
                    {
                        Puts("Test2");
                        Current.SendConsoleCommand("chat.add", Player.userID, string.Format("Code Test : Currently {0} are sharing location with you.", Current.displayName.ToString()), 1.0);
                    }
                }
            }
    Code (Text):
            object CallPluginFunction(string PluginName,string Function, params object[]  parametersArray)
            {
                object retrun_val = null;
                Core.Libraries.Plugins loadedPlugins = Interface.GetMod().GetLibrary<Core.Libraries.Plugins>("Plugins");
                Plugin CurrentPlugin = loadedPlugins.Find(PluginName);
                if (CurrentPlugin != null)
                {
                    try
                    {
                        retrun_val = CurrentPlugin.CallHook(Function, parametersArray);
                    }
                    catch { }
                }
                return retrun_val;
            }
    I used RustDB plugin to call sendToAdmins function from C#
    CallPluginFunction("RustDB","sendToAdmins",new object[] {"Call Faction Test"});
     
    Last edited: Feb 14, 2015
  3. dcode

    dcode Airdrop Stalker Server Owner Plugin Developer

    I have a feature request for this :) The BetterLoot plugin I wrote is becoming bigger while I am trying to implement LootDefinitions for different kinds of item containers, and I'd be really happy if I could either a) split things up into multiple source files (like BetterLott.cs, BetterLoot.Core.cs, ...) or b) being able to simply drop the compiled DLL file into plugins/. Any chance to make this possible? :)
     
  4. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    You should already be able to split and utilize other plugins any way you'd like. There shouldn't be a need for compiled DLLs. I also don't see compiled DLLs ever being supported as plugins either. @bawNg
     
  5. dcode

    dcode Airdrop Stalker Server Owner Plugin Developer

    Cool :) How would I ideally do this, if I have two or more .cs files for a single plugin?
     
  6. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    Each file would be its own plugin, you'd just need to check for the additional plugins from the main or however you want to set it up, and then call the hooks you need from those plugins.
     
  7. bawNg

    bawNg Wood Hoarder Oxide Developer

    You can use the PluginReference attribute in C# plugins to automatically maintain a reference to another plugin. The reference will be a valid reference when it is loaded and null the other plugin has been unloaded. Here is an example of usage:
    Code (C#):
    // Reference: Oxide.Ext.Rust
    using Oxide.Core.Plugins;

    namespace Oxide.Plugins
    {
        [Info("Something that uses rustio", "bawNg", 0.1)]
        class MyPlugin : RustPlugin
        {
            // Create and automatically maintain a reference to a plugin
            [PluginReference] Plugin rustio;

            [ChatCommand("addfriend")]
            void AddFriendCommand(BasePlayer player, string command, string[] args)
            {
                // Plugins can be used as a boolean expression instead of explicitly checking for null
                if (rustio)
                    rustio.Call("AddFriend", player.userID, args[0]);
                else
                    SendReply(player, "Error: RustIO is not loaded!");
            }

            // You can also use C# 6 syntax if you don't care if the plugin is not loaded
            void MaybeAddFriend(BasePlayer player, string steam_id)
            {
                // Add a friend if rustio is loaded, or do nothing
                rustio?.Call("AddFriend", player.userID, steam_id);
            }
        }
    }
     
     
    Tirenta and Wulf like this.
  8. Tirenta

    Tirenta Naked Wanderer

    i try call like this

    Code (C#):
    private void Loaded()
            {
                var temp =
                    ( from plugin in plugins.GetAll() where plugin.Title == "MessageControl" select plugin ).FirstOrDefault(
                        );

                if( temp != null )
                {
                    temp.Call( "Foo" );
                    Puts( "called" );
                }
                else Puts( "null" );
            }
    MessageControl class:
    Code (C#):

    [Info ( "MessageControl" , "Tirenta" , "1.0.0" )] internal partial class MessageControl : RustPlugin
        {
            public void Foo()
            {
                Puts( "Foooooo" );
            }
        }
     
    And console log:
    calledFunc.PNG

    What's wrong? :)
     
    Last edited: Mar 14, 2015
  9. Nogrod

    Nogrod Shotgun Ace Oxide Developer

    remove the public from Foo...just "void Foo()" or private and it should work

    Also: you can use plugins.Find("MessageControl") instead of Linq
     
    Tirenta likes this.
  10. Tirenta

    Tirenta Naked Wanderer

    oh, thank u :) its work
    kk, its just test)
     
  11. Mughisi

    Mughisi Grenade Master Community Mod Oxide Developer

    As pointed out by @bawNg just before your post you can actually use the PluginReference API when writing plugins in C# (http://oxidemod.org/threads/csharp-c-plugins-now-supported.6586/page-2#post-72569)
    So taking your post as example you could simply do this:
    Code (Text):
    // Reference: Oxide.Ext.Rust
    using Oxide.Core.Plugins;

    namespace Oxide.Plugins
    {
        [Info ("Plugin" , "Tirenta" , "1.0.0")]
        class MyPlugin : RustPlugin
        {
            // Create and automatically maintain a reference to a plugin
            [PluginReference] Plugin MessageControl;

            void Loaded()
           {
               if (MessageControl)
               {
                    MessageControl.Call("Foo");
                    Puts("called");
               }
               else Puts("null");
               
               // You can also use C# 6 syntax if you don't care if the plugin is not loaded
               MessageControl?.Call("Foo");
           }
        }
    }
     
    I didn't use an editor for that example and just typed it here in the code box so if there would be any typos please excuse me, you just need to make sure that the PluginReference is the name of the plugin you are referencing to.
     
    Last edited: Mar 14, 2015
    Tirenta likes this.
  12. Tirenta

    Tirenta Naked Wanderer

    Hey all, i want to get global hook on chat, when it's no command.
    In docs:
    OnPlayerChat(chat.say arg)

    but chat have'nt field say:

    Снимок.PNG

    so what can i do? :) i need to remake display nick and message and etc., but without this hook i can't get colored nick
     
  13. dcode

    dcode Airdrop Stalker Server Owner Plugin Developer

    The argument is ConsoleSystem.Arg. You may also use chat.Arg, but you'll need to add a using Rust; to your using directives.
     
    Tirenta likes this.
  14. Tirenta

    Tirenta Naked Wanderer

    thank, it's work, but message is duplicated, i can block original? :)
     
  15. dcode

    dcode Airdrop Stalker Server Owner Plugin Developer

    Returning anything else than null from the hook method will override the default behaviour. But beware that this will also cancel propagation of the message to other plugins using the same hook.

    Code (Text):
    [HookMethod("OnPlayerChat")]
    object OnPlayerChat(ConsoleSystem.Arg arg) {
        if (...) {
            return false;
        }
        return null;
    }
     
    Tirenta likes this.
  16. BigWorld

    BigWorld Naked Wanderer

    .cs plugins are not working.
    oxide.load Kits to answer:
    [Debug] Plugin is already being loaded: Kits

    Rust server running on a wine64 (linux). Looking for what is special libraries?

    Thank you
     
  17. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    The compiler is Mono x86, so your version of Wine and OS would need to be capable of using x86 DLLs, in this case the msvcr120.dll included. If you see that message, there's likely an underlying issue which you could check for in the compiler logs.
     
  18. BigWorld

    BigWorld Naked Wanderer

    I'm sorry, I do not quite understand. what I need to do and how the logs to see?
     
  19. Wulf

    Wulf Community Admin Community Admin Oxide Developer

    I'm not really sure, I haven't tested it on Wine at all. The msvcr120.dll in the root is what the compiler uses, so it's likely an issue with Wine and it, generally an OS arch incompatibility.
     
  20. BigWorld

    BigWorld Naked Wanderer

    true, the problem is only in the wine. but I can run the server the only way and all works well. possible guilt lacks any libraries.
    --- Double Post Merged, Jun 6, 2015, Original Post Date: Jun 4, 2015 ---
    Thank you for the update. The new version now runs on wine. But cs plugins still are not compiled.
     
Thread Status:
Not open for further replies.