Vice City: Multiplayer

Server Development => Community Plugins => Topic started by: EK.IceFlake on Aug 27, 2018, 02:06 PM

Title: .NET Core plugin for VCMP
Post by: EK.IceFlake on Aug 27, 2018, 02:06 PM
Intro
I've been wanting .NET support in VCMP since over two years now (https://forum.vc-mp.org/?topic=2574.msg19253#msg19253). Now that I have the skills to actually attempt something like this myself... well, I decided why not take a go at it. So put simply this is a collection composed of

Repository
The main repository of this project can be found on GitLab. You can use this repository for

dotnet-vcmp repository (https://gitlab.com/fleka_e/dotnet-vcmp)

Additional support
You can get quick support about this plugin at Developers.cpp. However, if you want more complex or advanced support, you should create an issue on GitLab. This is so that I help not only you but any potential future users of this project as well.

Developers.cpp (https://forum.vc-mp.org/?topic=4856.msg35439)

Builds
Since I use Linux as my OS, it's not particularly easy for me to support Windows as well. All pre-built binaries you see here are tested on Linux 64 bit. The C# interoperability DLL will very likely work on Windows 64 bit as well. Do not try to use them on a 32 bit architecture - they will not work! I've made the source code platform-agnostic, so you can compile a 32 bit version yourself if you need to.

Note that you should add Fleka.DotnetVcmp.Interop as a Nuget dependency instead of using the DLL directly.


Compiling
The VCMP plugin uses the Meson build system. You need to have Meson installed in order to compile it. If you're on Windows, I recommend that you use Meson to generate a Visual Studio solution and compile it using Visual Studio.

Use dotnet build or dotnet publish to build a managed assembly.

Getting Meson (https://mesonbuild.com/Getting-meson.html)
Meson compilation guide (https://mesonbuild.com/Quick-guide.html#compiling-a-meson-project)

Setting up a hello world application

.NET core installation instructions (https://www.microsoft.com/net/learn/get-started-with-dotnet-tutorial#install)
Hello world test app class (https://gist.github.com/iFlake/4900642e17003a51994b19f4691fdbcc)
dotnet.json example configuration (https://gist.github.com/iFlake/4cbb65601d2787432fb450672b091c8d)

Windows
If you have an adequate Windows software development installation (with Visual Studio, Meson and .NET Core) and you don't need lots of help with this, you can contact me to volunteer to test and compile this plugin on Windows.

Side note
I don't recommend using this right now for developing scripts. It just exposes VCMP's raw API with no error checking at all, and you can easily run into segmentation faults, crashes or silent failures and you won't even be able to figure out why. You should really only be using this with a wrapper. I'll hopefully release an official wrapper soon, and you can also create unofficial wrappers if you like.
Title: Re: .NET Core plugin for VCMP
Post by: NicusorN5 on Aug 29, 2018, 09:02 AM
Is there any documentation  on the functions, or I have to look into the source code?
Title: Re: .NET Core plugin for VCMP
Post by: EK.IceFlake on Aug 29, 2018, 09:42 AM
Quote from: Athanatos on Aug 29, 2018, 09:02 AMIs there any documentation  on the functions, or I have to look into the source code?
Right now, the project contains no documentation since it just exposes VCMP's SDK to .NET without any modifications. So for the time being, all functions behave exactly as they do with the plugin SDK. The plugin SDK contains documentation on which errors can occur from a function, but that's all. So for the time being, you'll have to look into the source code; either in C# (this project) or C++ (VCMP's SDK). You should also take a look at how marshaling is handled in .NET.

Bear in mind that this is just for the interoperability layer. The wrapper (which is currently in development) is extensively documented and exposes its own set of functions which are designed to make scripting easier and safer.

Plugin functions (implemented in C#) (https://gitlab.com/fleka_e/dotnet-vcmp/blob/master/interop/VcmpApi/Classes/PluginFunctions.cs)
Plugin callbacks (implemented in C#) (https://gitlab.com/fleka_e/dotnet-vcmp/blob/master/interop/VcmpApi/Structures/PluginCallbacks.cs)
Plugin function signatures (implemented in C#) (https://gitlab.com/fleka_e/dotnet-vcmp/blob/master/interop/VcmpApi/Delegates/PluginFunctionDelegates.cs)
Plugin callback signatures (implemented in C#) (https://gitlab.com/fleka_e/dotnet-vcmp/blob/master/interop/VcmpApi/Delegates/PluginCallbackDelegates.cs)
VCMP SDK (implemented in C++) (https://gitlab.com/fleka_e/dotnet-vcmp/blob/master/loader/dependencies/plugin.h)
.NET marshaling (https://docs.microsoft.com/en-us/dotnet/framework/interop/interop-marshaling)
Title: Re: .NET Core plugin for VCMP
Post by: Sir. Cucuruchito on Aug 30, 2018, 08:49 PM
Quote from: Athanatos on Aug 29, 2018, 09:02 AMIs there any documentation  on the functions, or I have to look into the source code?

Like everything related to Vice City Multiplayer, the documentation is conspicuous by its absence.
Only looks Java plugin documentation or Squirrel implementation.