Important [OLD] Setup dev environment for C# plugins

Discussion in 'Tutorials & F.A.Q.' started by Viproz, Aug 20, 2014.

  1. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    Here is a tutorial on, for me, the best part of Fougerite, the C# plugins !

    We are going to learn how to setup the dev environment

    I - Requirement
    - The server files or at least the dlls
    - xamarin studio, get it from here : http://monodevelop.com/download so you don't have to install all of the xamarin products
    - Very little C# knowledge (you can learn on the go ;))

    II - Environment setup
    Here we are going to setup the environment to be able to simply make plugins and we are going to create our very first one !
    First of all, we are going to create folders :
    - In your preferred place for programming stuff create a folder called "FougeritePlugins"
    - In the newly created folder create a folder References

    Now copy the dll of the patched rust server in your References files (you can find them in your server file\rust_server_Data\Managed)

    Now you should have a FougeritePlugins folder with a References folder in it containing a lot of dlls, such as "Fougerite.dll" or "Assembly-CSharp.dll".

    Let's create the project, first launch Xamarin Studio
    In the step 4 you should enter your plugin name
    [​IMG]
    Image hosted by http://oximg.com/

    Next we will add the reference to the dlls, double ring means double clicks and you should repeat the steps 3 and 4 to add all the libs that you can see in the rectangle on the right
    [​IMG]
    Image hosted by http://oximg.com/

    Now let's go in the option menu (blue circle is right click)
    [​IMG]
    Image hosted by http://oximg.com/

    Change the configuration as followed
    [​IMG]
    Image hosted by http://oximg.com/

    Here is just a thing that I like to do, it will just put the generated dll in a sub folder so to release your plugin you'll just have to copy that folder
    [​IMG]
    Image hosted by http://oximg.com/

    And now let's go into Release mode
    [​IMG]
    Image hosted by http://oximg.com/

    Last thing, rename the default generated file MyClass to the name of your plugin (right click, rename)
    Now you should have something like this :
    [​IMG]
    Image hosted by http://oximg.com/

    All right we are done for this part, you have a fully setup dev environment, you just need to start coding, that will be in another tutorial !
     
    #1
    Last edited: Sep 9, 2014
    • Informative Informative x 3
  2. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    Reserved for expansion

    Tell me if so far I've done anything wrong !
     
    #2
  3. Snake
    Offline

    Snake Moderator Moderator

    Joined:
    Jul 13, 2014
    Messages:
    288
    Likes Received:
    44
    I'm starting to translate all my plugins from JavaScript to C#. If you need any help tell me. Keep it up !
     
    #3
  4. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    Okay some progress, I went to a really image heavy style, maybe a bit too much but I guess it's good so everyone can do it without knowing anything about the IDE

    Thanks Snake, I'll probably ask for help at some point about good hobbit or good ways to do things ;)

    I'll be out until Wednesday, if anyone want to help you're welcome to post here and I'll edit when I'll be back :)
     
    #4
  5. Snake
    Offline

    Snake Moderator Moderator

    Joined:
    Jul 13, 2014
    Messages:
    288
    Likes Received:
    44
    Nice to see it being updated. Btw, at the third image you writed "blue circle left click", isn't it right one ? :p Keep the good job !
     
    #5
  6. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    Yes indeed thanks, the right one isn't the left one it's the right one :p
     
    #6
  7. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    Okay so since I'm in an University now I don't have much time to continue this tutorial (I don't even have a computer that can run xmarin) so I'll keep it like that, could a mod change the title to something like "Setup dev environment for C# plugins" please ? :)

    Also if anyone want to continue it or use it, just pm me I'll give you all the things !
    Would be nice to have a tutorial on the interesting part, coding ;)
     
    #7
  8. mikec
    Offline

    mikec Master Of All That I Survey Administrator

    Joined:
    Jul 12, 2014
    Messages:
    296
    Likes Received:
    59
    It's perfectly OK to leave checked "Use MSBuild". I use Xamarin for Fougerite development, and I leave it checked.
     
    #8
  9. PreFiX
    Offline

    PreFiX New Member Member

    Joined:
    Aug 8, 2014
    Messages:
    13
    Likes Received:
    1
    what is point of c# if we have magma ones? they are open source.
     
    #9
  10. Viproz
    Offline

    Viproz Moderator Moderator

    Joined:
    Aug 12, 2014
    Messages:
    39
    Likes Received:
    3
    I personnaly find it easier, you have access to every function of the game without doing anything fancy and to program you even have autocompletition and such
     
    #10
  11. PreFiX
    Offline

    PreFiX New Member Member

    Joined:
    Aug 8, 2014
    Messages:
    13
    Likes Received:
    1
    But that's point of magma, that there should be added more and more functions and C# ones should extend magma plugins (More hooks and so on) like on sourcemod :)
     
    #11
  12. mikec
    Offline

    mikec Master Of All That I Survey Administrator

    Joined:
    Jul 12, 2014
    Messages:
    296
    Likes Received:
    59
    Fougerite isn't Magma.
    Look how well that worked out for Magma plugins. Making users wait on the keepers of the secret source to add features is not what Fougerite is about.
     
    #12
  13. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,850
    Likes Received:
    638
    No. As Mike said Fougerite's aim is to add more and more devrloping modules like Py or C#. Since C# is the main language its faster than any other.

    Sent from my Samsung Galaxy S4
     
    #13
  14. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    Any simple example c# plugins? Would like to learn C# while I'm learning javascript, maybe throw in python while we are at it?

    How about a simple conversion of:
    Code (Javascript):
    function On_Command(Player,cmd,args){
         if(cmd == "time"){
              Player.Message("Current Time is: " + World.Time);
         }
    }
    Also, is there any good tutorials to learning C# and Python?
     
    #14
    Last edited: Sep 24, 2014
  15. Snake
    Offline

    Snake Moderator Moderator

    Joined:
    Jul 13, 2014
    Messages:
    288
    Likes Received:
    44
    Add Fougerite.dll as a reference and use it in the class.
    Code (C#):
    using Fougerite;

    The class of the plugin must extend Fougerite.Module :
    Code (C#):
    public class GroupModule : Fougerite.Module


    First add the plugin information and etc... :
    Code (C#):

            public override string Name
            {
                get { return "Asd123"; }
            }
            public override string Author
            {
                get { return "Snake"; }
            }
            public override string Description
            {
                get { return "awesome"; }
            }
            public override Version Version
            {
                get { return new Version("1.0"); }
            }

    Then add the hooks on plugin initialize and remove them on plugin deinitalize :
    Code (C#):
    public override void Initialize()
    {
    Hooks.OnCommand += HandleCommand;
    }

    public override void DeInitialize()
    {
    Hooks.OnCommand -= HandleCommand;
    }

    Then add your code to the HandleCommand :
    Code (C#):
    void HandleCommand(Fougerite.Player pl, string cmd, string[] args){
         if (cmd == "time"){
              pl.Message("Current Time is : " + World.Time);
         }
    }

    And you're done !

    Also you can declarate using Player = Fougerite.Player so you don't need to write Fougerite. all the time.

    I guess I'll write a brief tutorial explaining all the basics if I have time. To check more examples you can take a look at AntiCheat and GlitchFix that come by default with fougerite :

    Link -> https://github.com/fougerite/Fougerite
     
    #15
    Last edited: Sep 24, 2014
    • Useful Useful x 1
  16. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    Wow, OK so thanks to your help and guide, I built my first "plugin" aka module, based on NoWasteland. Testing it now. Btw, how would we distribute these files? As the dll or cs file? Can both those + javascript be put into a zip to update the resource??

    Oh, btw, don't forget to mention you have to BUILD it when you are done.:D

    Once built, the dll needs to put into its own folder, and put into "/modules" folder, then you would edit Fougerite.cfg and add in a blank area, preferaby under other modules, the name of the dll, and the folder its located in.
    So mine would be
    Code (Text):
    NoWasteland=NoWasteland
    because my folder and dll are the same name.
     
    #16
    • Agree Agree x 1
  17. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,850
    Likes Received:
    638
    https://github.com/dretax/Python-Plugins/blob/master/BannedPeople/BannedPeople.py#L134
     
    #17
    • Like Like x 1
  18. CorrosionX
    Offline

    CorrosionX Plugin Developer Plugin Developer

    Joined:
    Sep 3, 2014
    Messages:
    212
    Likes Received:
    16
    /Users/stopspazzing/Projects/NoWasteland/NoWasteland/NoWasteland.cs(13,13): Error CS0120: An object reference is required to access non-static member `Fougerite.Server.Broadcast(string)' (CS0120) (NoWasteland)

    Code (Text):
    Server.Broadcast ("This is a test of the emergency broadcast system");
    Code (C#):
    public void Broadcast (string arg)
    {
        foreach (Player current in this.Players) {
            current.Message (arg);
        }
    }
     
    How would I send a Server.Broadcast?:confused:
    could just use the foreach, however, curious how to use broadcast.
     
    #18
  19. DreTaX
    Offline

    DreTaX Probably knows the answer... Administrator

    Joined:
    Jun 29, 2014
    Messages:
    3,850
    Likes Received:
    638
    Is ur void where ur sending the broadcast static?

    Sent from my Samsung Galaxy S4
     
    #19
  20. balu92
    Offline

    balu92 Moderator Moderator

    Joined:
    Jul 11, 2014
    Messages:
    338
    Likes Received:
    31
    Server.GetServer().Broadcast(msg);
     
    #20
    • Agree Agree x 1
    • Useful Useful x 1

Share This Page