Solved Writing C# plugins?

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

  1. The post that you have quoted, I posted what I can only see using the JustDecompile.

    that is everything in the Assembly. DLL, or am I doing something wrong, because it shows no player function in it as you can see.

    Just did a rust and oxide update.

    here is what the Assembly-Csharp.DLL file contains.

    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)]


    Update:

    I checked some of the other dll files and all they have is this.


    [assembly: AssemblyCompany("")]
    [assembly: AssemblyConfiguration("")]
    [assembly: AssemblyCopyright("Copyright © 2014")]
    [assembly: AssemblyDescription("")]
    [assembly: AssemblyFileVersion("1.0.0.0")]
    [assembly: AssemblyProduct("Oxide.Game.Rust")]
    [assembly: AssemblyTitle("Oxide.Game.Rust")]
    [assembly: AssemblyTrademark("")]
    [assembly: AssemblyVersion("1.0.0.0")]
    [assembly: ComVisible(false)]
    [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
    [assembly: Guid("977c5198-6a97-47a4-951c-f28a07bb23ad")]
    [assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]

    I am a little confused, I must be doing something wrong.

    Thanks for the help thus far though.

    this is how I am understanding it.

    Take this block of code for example taken from notifier, cheers for the plugin BTW, I use it all the time.


    def tell(self, player, text, color='silver', f=True, profile=False):
    ''' Function to send a message to a player '''

    if self.prefix and f:

    rust.SendChatMessage(player, self.format('%s <%s>%s<end>' % (self.prefix, color, text)), None, PROFILE if not profile else profile)

    else:

    rust.SendChatMessage(player, self.format('<%s>%s<end>' % (color, text)), None, PROFILE if not profile else profile)

    I know that the first part of this example code is telling certain commands to turn on and off if you will and the other lines of code represent an if, an-an and.

    So in other words if lets say this person died then this command goes off, if not then this one does. I hope this is helping myself to understand and pointing me in the right direction.

    let me know please, thanks.
     
    Last edited by a moderator: Aug 2, 2015
  2. imma make a short youtube video about JustDecompile lol
     
  3. Also about decompiling... I'm using JetBrains and I found out that the search is somewhat limited. I've had much better success just decompiling the whole DLL into a new C# project and by loading it in Visual Studio. With all the built-in tools in there (add Resharper as a bonus) it's much easier to find and trace stuff. I don't know if JustDecompile is better, but the JetBrain search skips a lot of stuff because it only looks in stuff it previously decompiled when looking for anything other than function signatures, class member declarations and class names. For instance, if you are looking at examples of using a specific variable in the Rust code, JetBrains will only find the declaration of it instead of finding all the other functions/classes that reference it.
     
  4. Alright so on that note, I should get a different decompiler?

    Because clearly something is wrong with either the program or the DLL files.

    Also with Jetbrains, I take it that it is the developers, so what is the program from them that i should download? all I found was a free .net decompiler from Jetbrains.

    And the video would be awesome man thanks.
     
  5. I used the free version, works fine.
     
  6. Yeah I know it's free, but what is the software called?

    I found software called Dot Peak, is that the program from Jetbrains I need?

    Plus that Resharper program is a trial, any free variants?
     
  7. Yeah dotPeek is what I'm talking about, sorry should have mentioned that.

    Resharper is not free, I don't know if any similar tools that are free. I just mentioned it because it's from the same company, it's not going to help you find stuff in Assembly.csharp.dll any easier it's just in my opinion a must have tool for anyone who does more than poke around C#. It has a ton of small features that just makes everything smoother and easier. For instance if you move a block of code from one file to another, it will automatically add the "using" statements you're missing in the new file, if you move a constant from one class to another, it will change all references to it so they point to the new location, etc. It also has code formatting features, code completion and so many small features like that it's really nice.
     
  8. Thanks for the info for dotpeak. As for the Resharper software, Sounds interesting. I do understand what you mean by what it helps with. I guess it has its perks for beginners like me if it does in fact auto fill in using parameters once you use a class that is not recognized.

    Installed Dotpeak. hopefully I will see what I am told I should be seeing, instead of what I have posted.

    Whoa, when using dotpeak to open the dll.

    SO MUCH stuff is in it, and now I can see the functions.

    Thanks, this is what I needed, using JustDecompile showed nothing like Dotpeak does.

    Getting Resharper as well, test the trial out.

    Any tips for me?

    Update:

    This is the example code I am going to use.


    Code:
    // Reference: Oxide.Ext.Rust
    // Reference: Newtonsoft.Jsonusing System.Collections.Generic;
    using Newtonsoft.Json;namespace Oxide.Plugins
    {
      [Info("Sample Plugin", "bawNg", 0.1)]
      class SamplePlugin : RustPlugin
      {
      void Loaded()
      {
      var data = new Dictionary<string, string>() { { "Hello", "World" } };
      Puts("SamplePlugin made this: {0}", JsonConvert.SerializeObject(data));
      }  void OnPlayerInit(BasePlayer new_player)
      {
      foreach (var player in BasePlayer.activePlayerList)
      PrintToChat(player, "{0} has connected", new_player.displayName);
      }  [ConsoleCommand("sample")]
      void cmdConsoleSample(ConsoleSystem.Arg arg)
      {
      SendReply(arg, "SamplePlugin: You typed 'sample' in console");
      }  [ChatCommand("sample")]
      void cmdChatSample(BasePlayer player, string command, string[] args)
      {
      SendReply(player, "SamplePlugin: You typed /sample in chat");
      }
      }
    }

    Is it still usable or has it changed since then, if it has can someone give me a template I can use please.

    Another thing is, I have an idea for a mod, but instead of me having to completely write up a plugin that has already been done.

    Am I able to have my plugin hook into it, once the plugin has been activated, so I am able to add an "if" or an "and" to make sure my plugin takes effect while the other one has been activated. Instead of having separate plugins doing similiar things at certain times (Taking loading times in consideration).

    Another Update:

    Going through the Oxide API. I managed to see how by using VS2015 with Resharper it auto inserts using references. that is very helpful, so cheers for the information about it man.

    Only question I have is, Do I use the VS default layout or do I choose the Jetbrain setup?

    Right now it is set to VS setup.

    Update:

    Have another question.

    I have 2 blocks of code that I will post and I would like to know what block is the one that makes the private commands work as commands, like voteday and so on?


    Code:
            // Messages!
            string noPollOpen = "No poll is open at this time.";
            string alreadyVoted = "You have already voted once.";
            string voteProgress = "Vote progress: {0} / {1} ({2}%/{3}%)";
            string voteOpenTime = "Night time skip vote is now open for {0} minute(s).";
            string voteSuccessful = "Vote was successful, it will be daytime soon.";
            string voteFailed = "Vote failed, not enough players voted to skip night time.";
            string voteReOpenTime = "Vote will re-open in {0} minute(s).";
            string voteNow = "Type <color=#FF2211>/voteday</color> now to skip night time.";
            
    I JUST FOUND THE CODE BUTTON :D

    Second block below:


    Code:
                            noPollOpen = (string)messages["noPollOpen"];
                            alreadyVoted = (string)messages["alreadyVoted"];
                            voteProgress = (string)messages["voteProgress"];
                            voteOpenTime = (string)messages["voteOpenTime"];
                            voteSuccessful = (string)messages["voteSuccessful"];
                            voteFailed = (string)messages["voteFailed"];
                            voteReOpenTime = (string)messages["voteReOpenTime"];
                            voteNow = (string)messages["voteNow"];
    Any help would be greatly appreciated, thanks.
     
    Last edited by a moderator: Aug 7, 2015