SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 28/12/2015, 12:58 PM   #1
Seregamil1
Big Clucker
 
Join Date: Nov 2012
Location: Russia, Altay
Posts: 132
Reputation: 45
Lightbulb .NET Plugin - Write plugins in .NET

So. This is a experimental project that allows you to write plugins at C#.


The functions on the server side:
callDotnetMethod - it calls the C# method
Code:
Parameter's:
methodName - name of the method split[] - key for parameters
i - int32 f - float s - string c - char
{Float,_}:... - arguments
Return's:
int32, boolean, float
Quote:
Due to the fact that AMX can not return a text value, it was necessary to create an alternative function based on the previous
callDotnetMethodStr - An alternative to the previous function, but it records the text in variable
Code:
Parameter's:
methodName - name of the method split[] - key for parameters
i - int32 f - float s - string c - char
str[] - array for string length - array length {Float,_}:... - arguments
Always returns 1!
The functions on the plugin side:

cpp.callRemoteCallback - It calls a function by name and passes parameters.
Code:
Parameter's:
string callback - callback name params object[] args - arguments
cpp.logwrite - write message to console
An example of using these functions

Pawn:
PHP Code:
#include <a_samp>

native callDotnetMethod(methodName[], split[], {Float,_}:...);
native callDotnetMethodStr(methodName[], str[], lensplit[], {Float,_}:...);

main(){

}

public 
OnGameModeInit() {
    
callDotnetMethod("onDotnetLoaded""cf"'v'1.0);

    new 
temp_int callDotnetMethod("kernel.testINT""ii"1024);
    
printf("testINT returned: %i"temp_int);
    
    new 
temp_bool callDotnetMethod("kernel.testBOOL""isi"1"boolean=)"0);
    
printf("testBOOL returned: %i"temp_bool);
    
    new 
temp_float callDotnetMethod("kernel.testFLOAT""ifcf"101.432'c'242);
    
printf("testFLOAT returned: %f"temp_float);
    
    new 
temp_str16 ] ;
    
callDotnetMethodStr("kernel.testSTRING"temp_strsizeof temp_str"sss""by""Seregamil""dotNET v1.0");
    
printf("testSTRING returned: %s"temp_str);
    return 
true ;
}

forward onDotnetWasLoaded(str[]);
public 
onDotnetWasLoaded(str[]){
    print(
str);

C#:
PHP Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace 
c_sharp
{
    public class 
kernel
    
{
        public static 
object onDotnetLoaded(params object[] args)
        {
            
cpp.logwrite("dotnet-> onDotnetLoaded was called. ARGS:");
            foreach (
object arg in args)
            {
                
cpp.logwrite(arg.ToString());
            }

            
cpp.callRemoteCallback("onDotnetWasLoaded""Hello! =)");
            return 
true;
        }

        public static 
object testINT(params object[] args)
        {
            
cpp.logwrite("dotnet-> testINT was called");
            
int a Convert.ToInt32(args[0]);
            
int b Convert.ToInt32(args[1]);
            return 
;
        }

        public static 
object testBOOL(params object[] args)
        {
            
cpp.logwrite("dotnet-> testBOOL was called.");
            return 
false;
        }

        public static 
object testSTRING(params object[] args)
        {
            
cpp.logwrite("dotnet-> testSTRING was called." );

            foreach (
object arg in args)
            {
                
cpp.logwrite(string.Format("{0}: {1}",arg.GetType(), arg.ToString()));
            }

            return 
"blackJack prod.";
        }

        public static 
object testFLOAT(params object[] args)
        {
            
cpp.logwrite("dotnet-> testFLOAT was called. ARGS:");
            
float result 13.228f;
            return 
result;
        }
    }

Result:


The solution contains 2 project. First at C #, the second at C ++. It's a COM assembly.
When compiling formed a * .dll file in the right directory. In my case it S:\gta-o\plugins\.
I'm using VS 2012 Express.

ATTENTION. COMPILATION OF PROJECT MADE IN ADMINISTATOR MODE

I have not tested the project in a Linux environment.

Link to project with examples: https://github.com/Seregamil/.NET-plugin

Last edited by Seregamil1; 30/12/2015 at 06:27 AM.
Seregamil1 is offline   Reply With Quote
Old 29/12/2015, 06:19 PM   #2
NewbProgrammer
Guest
 
Posts: n/a
Default Re: .NET Plugin

This is nice. Can write an entire gamemode with this.
  Reply With Quote
Old 29/12/2015, 10:38 PM   #3
Carper
Little Clucker
 
Carper's Avatar
 
Join Date: Oct 2013
Posts: 32
Reputation: 5
Default Re: .NET Plugin

Very nice!
Carper is offline   Reply With Quote
Old 29/12/2015, 10:44 PM   #4
mk124
Huge Clucker
 
mk124's Avatar
 
Join Date: Jul 2007
Location: Nanning, China
Posts: 319
Reputation: 59
Default Re: .NET Plugin

Nice work, but this has already been done in a better and bigger way by a user called ikkentim.
I think it would be nice if you work with him together on one project. You can take a look at his project here: http://forum.sa-mp.com/showthread.php?t=511686
__________________
mk124 is offline   Reply With Quote
Old 30/12/2015, 02:56 AM   #5
Seregamil1
Big Clucker
 
Join Date: Nov 2012
Location: Russia, Altay
Posts: 132
Reputation: 45
Default Re: .NET Plugin

Quote:
Originally Posted by mk124 View Post
Nice work, but this has already been done in a better and bigger way by a user called ikkentim.
I think it would be nice if you work with him together on one project. You can take a look at his project here: http://forum.sa-mp.com/showthread.php?t=511686

His project allows you to write gamemode on C#
My project allows you to write plugin on C#
Seregamil1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Centos7 - Streamer plugin and crashdetect plugin Su37Erich Server Support 3 12/08/2016 12:18 AM
[MySQL] From StickenKid's plugin to BlueG's plugin jessejanssen Scripting Help 2 15/06/2014 01:20 AM
mysql plugin. loading plugin failed ikkentim Help Archive 2 10/02/2011 02:32 PM


All times are GMT. The time now is 11:44 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.