AGS Plugin API for C#

Started by smiley, Thu 22/07/2010 15:29:20

Previous topic - Next topic

Pumaman

Interesting!

Of course, you need to bear in mind that if you make a game that uses a C# plugin, then the player will need to have the .NET Framework installed in order to play your game.

Wonkyth

Not much of an issue for windows users.
"But with a ninja on your face, you live longer!"

tzachs

Quote from: Monsieur OUXX on Tue 03/08/2010 15:32:38
Calin, did that eventually work?

Works super for me (eventually)   :D
Expect a small demonstration plugin soon...

Yuri Patrick

Alright, back in the original post for this topic is the following:

"Register the script function in EngineStartup:
Code: ags

private AddNumbersDel del;
public void EngineStartup(IAGSEngine engine)
{
   del = new AddNumbersDel(AddNumbers);
   IntPtr address = Marshal.GetFunctionPointerForDelegate(del);
   engine.RegisterScriptFunction("AddNumbers", address);
}



Where in the world is IAGSEngine?! I have AGS Types but IAGSEngine is not in there. Is my AGS broken?

Calin Leafshade

i'm not sure what you mean...

in the code you posted 'engine' is an instance of the IAGSEngine class which is passed from the wrapper.

Yuri Patrick

Yes. I know that, but it is not accepting it. I have VS C# 2008 and am "using AGS.Types;" but when I try to compile with IAGSEngine anywhere in my code, it crashes and says I am missing a directive.

tzachs

Did you use the given template?
It's under Wrapper\Swig\IAGSEngine.cs

smiley

Small update:
The C++ glue code is included in the zip file.
PluginAPIWrapper.dll is compiled with MinGW, so you don't need the VC++ 2010 redist anymore.

goodohman


Hi there,

I'm trying to return a String from a function.

First I just tried to return a C# string - kaboom... it crashed
Then I thought wait.. return a CreateScriptString(mystring) - kaboom...
Then I thought wait... the IAGSEngine and agspluginPINVOKE might be wrong with the return type,
so I've changed them from "string" to "IntPtr" and still - kaboom...
I thought maybe "IntPtr" is not "real" enough as a const char*, so I've changed all to "void*" (in usafe context),
and guess what? yeah... - kaboom

so.. smiley or anybody else.. PLEAAAASSSEEEE does someone knows how to return a string from c# ?

Thanks!!!!!!!!!!!!!!

tzachs

You can take a look at the code I wrote for c# runner (the source code is in that thread), there are some functions there that return a string.

goodohman


Thanks Tzachs!

The C# Runner link appears to be dead, could you repost?
Alternatively, could you give me the short version answer?

Thanks!!

p.s.
any idea on how to access the new ags features from the plugin? (i.e. new audio stuff and attributes)

tzachs

Thanks for the heads up, I re-uploaded it to here.

As for the short version answer, I don't have something special to offer here, cause I don't remember doing anything different for strings that I didn't do for the other types, if was pretty straight forward.
You're probably missing something simple, so I would compare my code to yours and see what's different...

Also, regarding the new audio, my guess is that the API doesn't have that functionality, so no way to access it. However since the source code of the editor is available (and in c#), you can possibly modify it to access the audio somehow, though I'm not sure how much work it will take.

goodohman


tzachs, sorry for the long delay!

Your example is working alright, but the return type is actually derived from using the:

private static TOut CSRun<TIn, TOut>(TIn value, string className)

method (CSRunStringToString...)

Could you PLEASE verify a pure in-code string return type and let me know?

BIG THANKS!

tzachs

The CSRun is only a generic method to run delegates, it's an inner implementation and have no effect of the API, I could have easily replaced that call with a simple:
return "hello world";

This would have worked all the same (guaranteed, this was the first thing I tried when I started playing with smiley's api).

Yuri Patrick

Does anyone still have the C# wrapper? I tried all three of the links that I saw going to the file and they are all dead links. Please someone still have this. :)

Khris

Just send smiley a PM.
He was last active in July, he's still around it seems.

smiley


SMF spam blocked by CleanTalk