[C#] Rpg.NET Export Tool

Started by ForeverZer0, May 18, 2014, 10:17:54 pm

Previous topic - Next topic

ForeverZer0

May 18, 2014, 10:17:54 pm Last Edit: March 11, 2015, 12:01:11 am by ForeverZer0
Rpg.NET Export Tool
Authors: ForeverZer0
Version: 1.0
Type: .NET Post-Built Tool



Introduction

This application is designed to allow you to create Microsoft .NET assemblies that can interop with RGSS using Ruby's Win32API. Assemblies built that target the .NET Framework are managed code, and are unable to be invoked using Ruby. This application performs a post-build process on your existing .NET projects that allows them to be invoked with Win32API, just like that of an unmanaged C/C++ library. Since many on this forum are C# (and other .NET Framework languages) programmers, this should hopefully open up many new possibilities for us that have since moved on from RGSS due to it's simplicity, but still have an active interest in it.



Features


  • Extremely simple to create managed .NET assemblies that can interop with Ruby

  • Easily modify and use existing projects

  • Only need to add a single method attribute to functions that you want to export





Download

.NET Framework v.4.0
Rpg.NET Export.zip (116 KB)

Requires Microsoft .NET Framework 4.0

.NET Framework v.2.0
Rpg.NET Export.zip (116 KB)

This version of the framework is already pre-installed on Windows XP SP3 and above.

Contains everything needed to built projects with exported functions.

  • RpgExport.exe
    Main tool that performs the compilation

  • RpgExport.exe.config
    Configuration file for the RpgExport tool. Can be modified manually, but not required

  • RpgExportAttribute.dll
    Library that needs to be referenced by your project, and contains the method attribute. The dependency will be removed during the post-build process, so this file will NOT need to be deployed with your project



Source Code
Source Forge



Instructions

Step 1
Download the above file, and unzip to anywhere on your computer.

Step 2
Create a new project, targeting whichever framework you prefer. Remember that pretty much every Window's computer out there will have .NET Framework installed already on it, but higher versions such as 3.5 and 4.0 may not be, and could possibly require the end-user to install before your assembly will work on it.

After creating your project, make a reference to RpgExportAttribute.dll.

Spoiler: ShowHide


Step 3
Now create your code as you please. The only important factor to implement is that the methods must be marked as "static", and they need decorated with the "RpgExport" attribute that is imported from the RpgExportAttribute.dll. The only required argument with the attribute is the name that it will be as exported as, which can be different than the actual method name. Following is a rather simple example:

Spoiler: ShowHide


The name assigned within the "RpgExport" attribute is the name that will be invoked with Ruby's Win32API class.

Step 4
Now build your project, and open up the RpgExport.exe tool.
Either drag-drop the created assembly onto the form, type in the full path to the file, or use the dialog to set the assembly as the input assembly.

Spoiler: ShowHide


Here is a quick explanation of the parameters that can be set in the application:

  • IL Assembler Location
    This is the location of "ilasm.exe", selected from list of versions found on the system. I personally have not found any difference in which version is used, and have always just used the highest version available.

  • IL Disassembler Location
    This is the location of "ildasm.exe", selected from list of versions found on the system. Again, I have not found any difference in which is used.

  • Input Assembly
    The input assembly that will be recompiled

  • Output Assembly
    This is the output path of the assembly. If blank, the input assembly will simply be overwritten.

  • Architecture
    This is the target CPU architecture the assembly will target. Typically "Any CPU" will work just fine.

  • Optimize
    This is the same as checking "Optimize" in the within the Build Properties of the project, and is the default of any "Release" build. There really isn't any reason this should not be used.



Step 5
After making any changes you need, click "Export" and the project will be rebuilt. Copy this output assembly to your RPG Maker project's game folder, and you are ready for a test.

Spoiler: ShowHide


Step 6
Within RPG Maker, create the necessary Win32API object, and invoke your new method!

Spoiler: ShowHide


Spoiler: ShowHide




Tips and Tricks

I will add  more to this section later, and explain more on the few things that follow just to get you started.

Invoke Ruby Code From .NET Assembly

Include "System.Runtime.InteropServices" in a class, and use P/Invoke to exectute Ruby code. The only little hiccup I have run in to so far is that ensure any class that implements importing unmanaged DLLs is marked as "internal", and not the within a class you are exporting functions from. To see what I mean, look at the following two pictures.

Spoiler: ShowHide


Spoiler: ShowHide


Win32API.new('RpgNet.dll', 'SayHello', 'p', '').call('ForeverZer0')


Encrypting/Compressing Scripts

Yup, this is actually quite simple, a very good encryption, but does require the use of one other post-built tool. I will explain more tomorrow within the next day or so.



Notes

Feel free to report any bugs, issues, or comments, I will try to answer anything that I can.
Please give credit if using in your project!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

PhoenixFire

Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

This is definitely cool. Can't wait to see some other stuff with this. :3

ForeverZer0

Thank you all.
I added the download link for version that target Framework 2.0.
I wasn't thinking that when I created using 4.0, one could not make references to the DLL without also targetting 4.0.  Using 2.0 should allow you to use any version you like.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Loveless

Sorry for the necro but I just wanted to say/ask a few things:
-This is beautiful. Much thanks.
-Is the source for this available anywhere? I assume the project itself is abandoned by now.
  -If yes, where and is there a list of bugs or something (maybe some features that were planned but never implemented) that I can use to continue development on my own.

After making use of this I've grown to love the idea too much to give up on it so if there's no source available anywhere I'll probably end up starting from scratch and working to implement the idea myself. At the very least I'd like to let my appreciation of this initiative be known.
   

ForeverZer0

I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Loveless


ForeverZer0

Oops, I might have it set to private, I will check it out when I get home later, or tomorrow.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Loveless

No problem. I've got time and more than enough to work with at this point.

PhoenixFire

I would be interested to see just what this can do.. C# does after all, have networking capabilities; it would be very cool to see someone take advantage of this possibility, and create an even better networking system for RM games. i guess my only thought on it though, is just feasible that would be..
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

KK20

If you wanted to expand upon the server, you'd have to know C# and compile it yourself.
Meanwhile, RMX-OS is Ruby (can you script in RPG Maker? Then you are good to go) and doesn't even need compiling. Extensions are easy because of that.

As for me, I'm just making my server in C/C++ as I really doubt anyone would need to modify the server code for AWE.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Loveless

March 09, 2015, 08:18:26 pm #12 Last Edit: March 09, 2015, 08:19:37 pm by Loveless
Quote from: KK20 on March 09, 2015, 07:29:04 pm
If you wanted to expand upon the server, you'd have to know C# and compile it yourself.
Meanwhile, RMX-OS is Ruby (can you script in RPG Maker? Then you are good to go) and doesn't even need compiling. Extensions are easy because of that.

As for me, I'm just making my server in C/C++ as I really doubt anyone would need to modify the server code for AWE.

I don't know much about servers in most regards but my plans would have, generally, been more for personal use. I realize the implications of this type of system but I can't think of a way to distribute it the way normal scripts are shared. Sure we could make a new and infinitely better server but what's the point if the people you made it for wouldn't even be able to use it. Not that it's really a problem seeing as I'm pretty sure this was only ever meant for the more experienced anyways.

ForeverZer0

Fixed the permission on the Source Forge page, and added the link to the main post.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.