How can I add some functions to Monogame files?

Hi there,

I’m trying to develop a monogame application for Virtual Reality using Oculus Rift and I need to add two really simple functions to Monogame in order to make my tutorial work (I can give you the link if some of you are interested)

So my question is simple : how can I edit/add some functions in Monogame files?

I never edited an open source framework before, and when I press F12 to see the definition, I can’t edit it.

Thanks in advance for your help,

Betamorfosis

Go to https://github.com/MonoGame/MonoGame/tree/develop (which you can find linked here http://www.monogame.net/downloads/)

And download the project.

Open the .sln file for your target platform

You can now build the project. You find the newly compiled .dlls in the default directory /bin/debug/win86 for example

In your main application, in the references, delete monogame.framework.dll and add the newly compiled monogame.dll

You can build it any way you like, all the changes can be used in your application

1 Like

Thanks for your quick answer.

I was indeed looking into the github files, and I found out the .cs files I was looking for.

But I didn’t found the .sln file for my platform (I’m using Monogame for windows).

As soon as I can find this file, I will be able to edit the files easily and generate a new dll file, I’m gonna keep looking you already helped me a lot.

the github site also has a short setup guide.

You need to run protobuild.exe to generate the .sln files

1 Like

Also see the doc page that nicely explains the easiest way to build from source: http://www.monogame.net/documentation/?page=Setting_Up_MonoGame_Source

1 Like

Howdie folks !!! On the topic of adding functions to the framework how does it work if one would like to release with these added functions ? Is this permitted or does it have to make its way into an official monogame release build ? Can one release a custom build of Monogame dll with your apps where you have added additional functions in the source ?

You do not need to make any adjustments at all!

The required .dlls are copied into the output directory of your application, the end-user does not need to have monogame installed on his machine.

If you use a modified monogame.dll that one will be copied to output. No problem.

ah great stuff!! thanks for the confirmation :slight_smile:

Hey guys thanks a lot for your help, after some testing I managed to get the .sln files, and it worked great ! (Had to install git, and run the commands given on Jjagg’s link, wouldn’t work otherwise don’t know why)

I did add 2 functions and tried to compile the code I was working on (Oculus with monogame example), and it did compile, but I’m having another issue : it says “System.AccessViolationException exception” on OcculusRift.SubmitRenderTargets(eye[0], eye[1]);

I know it’s a different problem, I just wanted to let you know you helped me going a step further :slight_smile:

If I can get it to work I can post the solution in here in case some people may encounter the same problem.

Maybe the render targets are disposed or not intialized correctly. AccessViolationException is thrown when unmanaged code reads or writes to protected memory.

I am debugging a lot, and it feels like a pretty weird bug : The render targets seems to have been initialized correctly (they have a width, height, IsDisposed at false, etc…), but the weird part is that when I’m in release mode, the program throw the exception in this line :

int result = rift.SubmitRenderTargets(renderTargetEye[0], renderTargetEye[1]);

but when I’m in debug mode, it throws the same exception inside the function :

public int SubmitRenderTargets(RenderTarget2D rtLeft, RenderTarget2D rtRight, int frame = 0)
{
IntPtr dxTexLeft = rtLeft.GetNativeDxResource();
IntPtr dxTexRight = rtRight.GetNativeDxResource();

(Throw exception here) =>        return NativeRift.SubmitRenderTargets(dxTexLeft, dxTexRight, frame);
    }

(And I checked, both IntPtr variables have a value)

SharpDX objects are COM based.
I don’t remember exactly what the calling convention for COM is, but in any case, have you tried to call IUnknown.AddReference() once on the render targets before you send them to SubmitRenderTargets()?