Important [OLD] Setup dev environment for C# plugins

Viproz

Moderator
Moderator
Aug 12, 2014
39
9
8
France
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

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

Image hosted by http://oximg.com/

Now let's go in the option menu (blue circle is right click)

Image hosted by http://oximg.com/

Change the configuration as followed

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

Image hosted by http://oximg.com/

And now let's go into Release mode

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 :

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 !
 
Last edited:

Snake

Moderator
Moderator
Jul 13, 2014
288
172
28
I'm starting to translate all my plugins from JavaScript to C#. If you need any help tell me. Keep it up !
 

Viproz

Moderator
Moderator
Aug 12, 2014
39
9
8
France
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 :)
 

Snake

Moderator
Moderator
Jul 13, 2014
288
172
28
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 !
 

Viproz

Moderator
Moderator
Aug 12, 2014
39
9
8
France
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 ;)
 

PreFiX

New Member
Trusted Member
Member
Aug 8, 2014
14
1
3
what is point of c# if we have magma ones? they are open source.
 

Viproz

Moderator
Moderator
Aug 12, 2014
39
9
8
France
what is point of c# if we have magma ones? they are open source.
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
 

PreFiX

New Member
Trusted Member
Member
Aug 8, 2014
14
1
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
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 :)
 

mikec

Master Of All That I Survey
Administrator
Jul 12, 2014
296
150
28
Los Angeles, California, USA
Fougerite isn't Magma.
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 :)
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.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,435
113
At your house.
github.com
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 :)
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
 

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
84
18
California
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:
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?
 
Last edited:

Snake

Moderator
Moderator
Jul 13, 2014
288
172
28
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:
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?
Add Fougerite.dll as a reference and use it in the class.
C#:
using Fougerite;

The class of the plugin must extend Fougerite.Module :
C#:
public class GroupModule : Fougerite.Module
First add the plugin information and etc... :
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 :
C#:
public override void Initialize()
{
Hooks.OnCommand += HandleCommand;
}

public override void DeInitialize()
{
Hooks.OnCommand -= HandleCommand;
}
Then add your code to the HandleCommand :
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
 
Last edited:
  • Useful
Reactions: CorrosionX

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
84
18
California
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:
NoWasteland=NoWasteland
because my folder and dll are the same name.
 
  • Agree
Reactions: Snake

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,435
113
At your house.
github.com
  • Like
Reactions: CorrosionX

CorrosionX

Plugin Developer
Plugin Developer
Sep 3, 2014
212
84
18
California
/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:
Server.Broadcast ("This is a test of the emergency broadcast system");
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.
 

balu92

Moderator
Moderator
Jul 11, 2014
338
75
28
33
/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:
Server.Broadcast ("This is a test of the emergency broadcast system");
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.
Server.GetServer().Broadcast(msg);