Solved Writing C# plugins?

Discussion in 'Rust Development' started by sililia, Jun 27, 2015.

  1. Creating /commands is super easy:

    Code:
    [ChatCommand("test")]
    void cmdTest(BasePlayer player, string cmd, string[] args)
    {
        Puts("Test!");
    }
    Doing /test with a mod that has this loaded will output "Test!" in RCON.
     
  2. Ahh okay awesome, thanks for the help.

    Just to clarify, I use C# Console Application for new project and then add the references I need in order to get the variables that work with oxide and I guess I input them into "using"?

    Would I be needing any of the default references or can I remove them for this project and they will come back when I select new project
     
  3. It doesn't have to be a console app, could be a windows forms app, dll app, it's quite irrelevant as you'll never really run the resulting assembly. You're only using this project to make sure your code is compilable. When you send the .cs file to your server, Oxide will compile it and load it with it's own compiler/references.

    And yes, you add the libraries as references and then you can use "using" to load their namespaces. You don't need to use "using" you can also just use a fully qualified path to the library.

    For instance, you could do:
    var toto= new System.IO.File("xxxx");

    OR
    using "System.IO";
    var toto= new File("xxxx");

    So long as you don't have multiple namespaces loaded that have a definition for a class named "File" you'll be OK.

    You can still use fully qualified class paths if you have a "using" statement:
    using "System.IO";
    var toto= new System.IO.File("xxxx");
     
  4. Not 100% sure what you mean by that but I took it as you type out that command and where ("xxxx") goes thats where path location is yeah? or am I thinking too much computers lol

    Also the references I got was all the ones that was listed in the other thread made by you and also the UnityEngine.UI because I took that as User interface and if it is would love to know if we can modify any or even create our own UI in-game for certain plugins for example an admin UI menu instead of having to type all the commands, you press a GUI Button.

    UPDATE: I think I now know what you are talking about where XXXX is that is where i put the variable name in of what I want to use.

    With saving, do I save the file as a .cs or leave it as is?

    What file should I be looking at for player hooks? also like in the old rust do I have any hope in cracking the code for invisibility on command?

    For the record, more then happy to share the credit if

    also had a look at your plugins code and i don't understand how your using variables when you have no using in the script.

    Not to mention how you were able to know what variables to use to get that effect.

    This is what the default script looks like


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Test_Plugin
    {
    class Program
    {
    static void Main(string[] args)
    {
    }
    }
    }
     
  5. Ignore the xxxx it wasn't the point, the difference is how I'm getting to the "File" class. In the first example I am not using a "using" clause for System or System.IO so I went and wrote the full path to the class: new System.IO.File. In the second example I have a "using" clause on System.IO which allows me to just type "new File()".


    I haven't messed with UI, it's a new feature and from what I read it's still a bit limited.


    Save the plugin as .cs... also for some reason Oxide is picky on case, they want something starting with a capital letter and then not all caps.


    For hooks check the doc on here, they're all there and there aren't a ton so it's easy to make a quick read and see what each of them does. Depending on where you're going you're going to use different hooks or no hooks at all.


    Yeah I noticed that and I don't know why. I'm assuming it's because the class is declared in the Oxide.Plugins namespace.


    That's the hard part :) A mix of looking at existing mods, reading documentation, browsing decompiled classes and code, etc. That's where you (and I) spend most of our time when making plugins. Perseverance is king here.


    Yeah you can pretty much ignore that, it's the entry point of your EXE basically and since you're never even running the EXE there isn't much use to it when making plugins.
    [DOUBLEPOST=1435558835][/DOUBLEPOST]
    For the invisibility, I have no idea. In Legacy it was easy to do, all you had to do is give the user an admin suit right in his equipment slots and then on any damage remove the suit. Now, I don't know of any way.

    For the references what I do is I have 1 project with all my mods in it. I can cherry pick code here and there if I need to reuse. I create a new plugin by duplicating an existing one then stripping it of what I don't need.
     
  6. Thanks for all your help and clearing up the whole if I can get invisibility working, If you end up finding a way to do it please let me have a look at the code, I am not going to take it or anything I just want to see how it looks, all credit to the dev.

    Yeah I changed it to C#>Windows>Class Library instead of the console application and I know it does not matter, it just clears some code. even though i save it as .cs and with a capital letter at the start, thanks for that tip by the way.

    So what is the dos and don'ts of peoples scripts? like considering its there code, how can I even use it?

    Right now, I am trying to think of a plugin that we need that is not complex.

    Also how which bits of code goes where at the moment I have this
    Code:
    namespace Oxide.Plugins
    {
      [Info("Title of Plugin", "Your Name", 0.1, ResourceId = 714)]
      [Description("This is what the plugin does")]
      public class PluginName : RustPlugin
      {
      // This is where your plugin will do its magic...I know main code goes here but what line of code would I use first to start off the mod?
      }
    }
     
  7. Well you have some basic events like OnServerInitialized that run on start. From there you could do some stuff... or not.. depends what you're trying to do.

    You could also do like I did with NoDecay and go straight for a hook. In my case I didn't need more than that. In a next version I might add a multiplier instead of completely disabling decay. If I do that I'll want to make a config file from which I'll read the multiplier. You have events to manage config files as well. Look at the doc.. Look at existing mods.
     
  8. Thank you so much man, like really thanks for taking the time to explain things, so cheers for that

    Is there a couple of mods you could suggest when it comes to looking at some basic code, your one is a prime example, yet still a little complex but is very small to what it does, though you may see that as a small use, I do not lol

    I also had a look at AP -> CLICK and even that looks complex like I understand is mainly because of the messages and the security behind it but how would I break it down to simplify it?

    Managed to think of a plugin that I would like to learn how to make but I need to know how I go about telling an item once spawned in a chest or a furnace to delete the item and then once its taken over the command stops, I had a look over the command, found some commands to do with items but not sure where to type the item name so it knows what item if deposited it will get rid of or replace?

    Of course with all the help I have been given, there will be thanks and some notification on your end.

    Update: Looking at the API for Item Hooks at the moment found I think 3 that can be used

    1. OnItemCraft 2. OnItemAddedToContainer 3. OnItemRemovedFromContainer

    Am I on the right track?

    PS. to new people reading. Read the whole thread from start to finish, to get info on how to do things.
     
  9. Yes you are on the right track. Start by adding a puts or player msg in these and experiment to see when they are triggered, also look at the structures you receive in them (decompiling to see what they hold is a good idea here).

    As for what mods to look at jusy download anything that could possibly relate to what you are trying to achieve. I just have a folder to which I download all the mods and then I search for hooks I want to use in them to see what's possible
     
  10. Thanks for the help man really do appreciate it.

    Can you tell me what category to look at for the commands you are talking about so I can have a look at them. with the big list it's hard finding the commands.

    For others trying to also get into Plugin Development I recommend this Microsoft Video Guide on C# >LINK<

    Update: I realized that I believe I am missing some references but I am not sure what ones

    Went >HERE< and copied and pasted the text, and the red squiggly lines for errors showed up and when I click on it said it was not there, I am not sure what DLL file to use to fix it

    [ConsoleCommand("sample")] is one of the commands that it does not know.
     
  11. Make sure you have references to these:

    assembly-CSharp.dll
    Oxide.Core.dll
    Oxide.Ext.CSharp.dll
    Oxide.Game.Rust.dll
    UnityEngine.dll

    You might need others, I don't have them off the top of my head but I've use other DLL's from the Rust "managed" folder.

    The code example in your link also uses Newtonsoft's json lib, that's something you'll want to download if you want to use this lib. It's not something I use in my own plugins but it has it's uses.
     
  12. Wulf

    Wulf Community Admin

    You really don't need all of those references.
     
  13. Could someone link me to a thread or link for a list for each DLL file?

    that has like some info on what is in each DLL file, even just a couple of hooks.
     
  14. Wulf

    Wulf Community Admin

    A list of what?
     
  15. Some of these threads helped >HERE< just a simple list. Lets say what Oxide.Core contains for hooks to use, just have a little description of what is in each DLL file.

    Just so I have a rough idea on what DLL to look at, for the desired hook to use.
     
  16. Wulf

    Wulf Community Admin

    Oxide hooks are shown in our Docs: http://docs.oxidemod.org/rust/.

    Any Rust functions can be found in the decompiled Rust DLLs.
     
  17. Ahh right, well is there anywhere that has information of each dll so we sort of know where to look, for the function we need?
     
  18. Wulf

    Wulf Community Admin

    Get a .NET decompiler, and open RustDedicated_Data/Managed/Assembly-CSharp.dll. Pretty much everything is in there, you just need to browse. ;)
     
  19. Mate. THANK YOU VERY MUCH!

    Update: I am using JustDecompile and this is all that is in it


    using System.Reflection;
    using System.Runtime.CompilerServices;
    using System.Security.Permissions;

    [assembly: AssemblyVersion("0.0.0.0")]
    [assembly: PermissionSet(SecurityAction.RequestMinimum, XML="<PermissionSet class=\"System.Security.PermissionSet\"\r\nversion=\"1\">\r\n<IPermission class=\"System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\r\nversion=\"1\"\r\nFlags=\"SkipVerification\"/>\r\n</PermissionSet>\r\n")]
    [assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]

    Okay upon further research, the way it is looking to me is. The documentation that has the hooks is what you sort of copy and paste into visual and edit to what you want it to do.

    And of course the DLL has extra variables that are not listen in the documentation.

    Am I on the right track?

    Because I am noticing that the game or oxides code has pre built commands so instead of me building a program from scratch per say I am using the reference DLL files for the list of commands for rust oxide.

    If I am on the right track this has helped me HEAPS and will save me asking so many stupid question.

    The way I was seeing it is I needed to know off by heart all the variables for rust but now know it has it for me because of the references.

    I guess now I just need to know the starting blocks of code to use, to get a plugin off the ground.

    and also work out what DLL has what references to use.
     
    Last edited by a moderator: Aug 1, 2015
  20. just use the search function and search for possible names. For example if you search for data about the player, just use the search function using CTRL + F and search for "player", you will find "BasePlayer" and that is what you click on and then you can see it on the left side. And you can find stuff like: displayName : string | userID : Int64 and such