Renegade Public Forums
C&C: Renegade -- Dead since 2012!™
Home » Renegade Discussions » Mod Release Forum » RenSharp v1.0
RenSharp v1.0 [message #493093] Sat, 08 June 2019 12:38 Go to next message
Neijwiert  is currently offline Neijwiert  
Messages: 130
Registered: October 2009
Recruit
From: *direct-adsl.nl
Are you struggling with your everday development in C++?
Do you suck with memory management or just the general hassle to get third party libraries for your custom Dragonade plugin?

Well, no more!

Introducing RenSharp v1.0 for Dragonade v1.98

This framework I created lets you make plugins for your FDS in .NET 4.7.2. You're probably wondering: will this need a heavily modified scripts.dll? I hear you and that's why I made sure it is bootstrapped by a regular Dragonade plugin.

"Are there any other limitations?", is probably your next question. Very few, here they are:

- You can only create custom classes (i.e. specialization of classes) for the classes I made support for. However the reach of this support is the same as you'd use in any normal Dragonade plugin (event classes, console functions, player observer, object observer, etc).

- I only made support for the template classes that are used throughout scripts.dll. Any customizations on this are not supported.

- Even though I added in some more safety nets to check for nulls etc. You can still fuck this up and make it crash horribly. Although the checks in place will also throw a managed exception and if not catched and handled will gracefully shutdown the FDS.

- Some design choices removed some support. For example there is no 'const' concept. But these choices shouldn't really limit your imagination.

- That's about it of what I can come up with on top of my head right now.


With any plugin interface there are a few 'gotchas' and for RenSharp those are:

- Inheritance is pretty much the same as you would in Dragonade. Except static initialization (using macros to register stuff) will not work in C#. Further explanation how this is handled is discussed in the example plugin.

- All managed classes are basically handles to their C++ variants. You can bind the C++ pointer using the appropiate constructor which takes an IntPtr as an argument. These handle classes are not inheriting from IDisposable and assume they are not in charge of cleaning up that handle. If one of these handle classes is wrapped around an IUmanagedContainer<T> class that means that you MUST dispose them when you're done with them. As these containers indicate that you are indeed in charge of cleanup.

- If you pass ownership of an unmanaged pointer to the C++ side (which does the memory management) you should make sure to release the pointer on the managed side. To make sure the garbage collector never disposes it. Likewise, when you keep ownership on the managed side, you should keep a reference to the object for as long as you want to keep it alive.

- Don't call any methods or use properties of which you don't really know what they do. You can screw it up. Otherwise, if you consider yourself well versed in this stuff, go right ahead.

- Any more gotchas or usage are pretty much discussed in the example plugin.


How to get started?
The only config this adds to da.ini is 'RenSharpPlugins'. You name managed plugin .dlls the same way as you would under 'Plugins'. To start RenSharp you also need to add 'da_RenSharp.dll' under 'Plugins'. Preferably on position 1. But that is up to you. Then follow one of the instructions below:

The quickest way to get started is to just use any Visual Studio version that can handle .NET 4.7.2. (for VS2019 you can just use the Visual Studio Installer to install .NET 4.7.2.). Create a new .NET 4.7.2. C# class library and search for the NuGet package 'Neijwiert.RenSharp' (right-mouse click on your project and click Manage NuGet Packages...) and click Install. All Renegade stuff is placed under the RenSharp namespace. When the NuGet package is installed it shows a readme.txt on how to properly set your target platform. You then have to place YourPlugin.dll, da_RenSharp.dll, ManagedRenSharp.dll and ManagedScripts.dll in your FDS folder. You can find these .dlls in 'YourPlugin\packages\Neijwiert.RenSharp.1.0.0\content' and 'YourPlugin\packages\Neijwiert.RenSharp.1.0.0\lib'.

The slow way is to compile it yourself. You can download the ZIP file with the source, or from GitHub. Compilation requires you to have C++/CLI build tools installed (use Visual Studio Installer) and .NET 4.7.2. (also use Visual Studio Installer). You can use a newer Visual Studio version as long as you have Visual Studio 2012 installed on your computer, with latest updates (whenever it prompts you to update the projects when you open the solution, you need to hit cancel). For the C++ stuff you need the same requirements as you would when you build Dragonade. Then you can just add a .NET 4.7.2. class library project and add a reference to 'ManagedScripts'. Make sure you configurate the class library to build as x86. Then you're ready to build and use everything.


I pretty much made all this without drawing out a plan. I made some design mistakes and I also couldn't test everything due to the size of it. If you find anything broken/not working or stupidly designed message met and I see if I can get it fixed. This also applies for new feature requests. The best way to approach me would be via GitHub probably or a PM here. This cost me a lot of time and effort to make and I hope you guys are going to enjoy it and hopefully open up modding to some more less experienced coders. Everything is licensed under the Apache 2.0 license, which means you can do everything, but you must mention my name and include a copy of the license. I'm wide open to responses to this negative and positive, feel free to reply to this post.

GitHub: https://github.com/Neijwiert/RenSharp
NuGet: https://www.nuget.org/packages/Neijwiert.RenSharp/1.0.0

Re: RenSharp v1.0 [message #493094] Mon, 10 June 2019 08:13 Go to previous messageGo to next message
MasterCan  is currently offline MasterCan  
Messages: 13
Registered: August 2017
Recruit
From: 94.121.136*
I was working on a similar thing with C# and same name! LOL
But I was not able to continue for other things, and life.
It is working thoe, but not ready for releasing to public.

Thanks anyway Smile
Re: RenSharp v1.0 [message #493095] Mon, 10 June 2019 08:16 Go to previous messageGo to next message
MasterCan  is currently offline MasterCan  
Messages: 13
Registered: August 2017
Recruit
From: 94.121.136*
Left screenshot in attachemnts. This one was working like BRenBot.

Re: RenSharp v1.0 [message #493096] Mon, 10 June 2019 08:49 Go to previous messageGo to next message
Neijwiert  is currently offline Neijwiert  
Messages: 130
Registered: October 2009
Recruit
From: 143.179.48*
Well that is interesting. I'm curious as to what you have so far. It was a hella of a lot of work so youve saved yourself some trouble.
Re: RenSharp v1.0 [message #493097] Tue, 11 June 2019 02:38 Go to previous messageGo to next message
MasterCan  is currently offline MasterCan  
Messages: 13
Registered: August 2017
Recruit
From: 94.121.136*
I believe so lol
Re: RenSharp v1.0 [message #493098] Tue, 11 June 2019 02:39 Go to previous messageGo to next message
MasterCan  is currently offline MasterCan  
Messages: 13
Registered: August 2017
Recruit
From: 94.121.136*
I can show you what I did so far if you have Discord Smile
Add me "The Unstoppable (TR)#1000"
Re: RenSharp v1.0 [message #493101] Sat, 15 June 2019 02:28 Go to previous message
Neijwiert  is currently offline Neijwiert  
Messages: 130
Registered: October 2009
Recruit
From: 143.179.48*
I think I'll be making some tutorial videos on how to use, because I think some people have problems understanding how it works. I admit the example plugin isn't very helpful.
Previous Topic: Dragonade 1.98 for Scripts 4.6 Update 7
Next Topic:2 New Plugins by Me: Building Fund and Building Warnings.
Goto Forum:
  


Current Time: Sat Jun 15 13:42:36 MST 2019
.:: Contact :: Home ::.

Powered by: FUDforum 2.7.7RC2.
Copyright ©2001-2007 FUD Forum Bulletin Board Software