Author Topic: FOnlineServer with Mono  (Read 17121 times)

Re: FOnlineServer with Mono
« Reply #45 on: July 06, 2013, 11:47:21 am »
Might I ask, does 2238 SDK support mono or not? Also, I do not understand the advantages by using mono.

Offline Bartosz

  • Rotator
  • There'd better be a killer reason...
Re: FOnlineServer with Mono
« Reply #46 on: July 07, 2013, 11:20:21 pm »
As of rev409, mono subdirectory has been removed from sdk/Server, and its development moved to: https://github.com/rotators/fomono

The repository contains only source files, the rest (modified engine executables + mono libs) are included in releases.

This is not only a part of moving our development endeavours in the open source wilderness, it should also make it easier for people wanting to use this modification - as it is now, the library source is the same as the files you need to alter for your particular application (Critter/Item/Map classes etc). Having those files separated as git repository can help with source management.

Might I ask, does 2238 SDK support mono or not? Also, I do not understand the advantages by using mono.

The mono integration hadn't been used with 2238, but you could easily set it up (using aforementioned repository). The only drawback would be that you will be using different server engine executable (you need to overwrite 2238' one with the one from fomono release) - if you're interested in details, ask.

As for advantages, well, just check the first post of this thread.
« Last Edit: July 07, 2013, 11:40:16 pm by Bartosz »

Offline wladimiiir

  • Rotator
  • Independent FOnline developer
Re: FOnlineServer with Mono
« Reply #47 on: July 09, 2013, 08:21:08 pm »
I have some questions about entry functions:

1. When I have entry function for initialization of critter in C#, am I supposed to use explicit conversion:
Code: [Select]
public static Critter InitCritter (IntPtr ptr, bool firstTime)
{
    Critter npc = (Critter) ptr;
    ...
or contructor
Code: [Select]
public static Critter InitCritter (IntPtr ptr, bool firstTime)
{
    Critter npc = new Critter(ptr);
    ...
Both seems to be working fine, but what is the difference here?

2. I would like to implement custom check_look function in C#, but I am not able to bind the function in scripts.cfg. Is it somehow possible or not really without some additional support in hardcoded part of Mono extension?

Thank you. :)

Offline Bartosz

  • Rotator
  • There'd better be a killer reason...
Re: FOnlineServer with Mono
« Reply #48 on: July 09, 2013, 08:42:11 pm »
1. Explicit conversion from IntPtr.Zero will return null reference, whereas new Critter(IntPtr.Zero) will create invalid wrapper pointing to IntPtr.Zero and possibly soon crashing the whole serv. But in init functions it's not possible for the pointer to be zero, so there is no difference here.

2. The scripts.cfg bindings are not working, because scripts.cfg won't allow you to define declaration, and take hardcoded one. And hardcoded ones are AS declarations, not mono ones, difference is:

Code: [Select]
// AS
viod funcname(int, int)
// mono
void Namespace.ClassName::Method(int,int)

so in mapper/dialog you may specify script as mono@SomeClass::Foo and have it working, but you can't do the same in scripts.cfg...

Of course you can do dirty:

Code: [Select]
// scripts.cfg
check_look some_module

// some_module
#pragma bindfunc "bool Helper(Critter&, Critter&) -> mono CheckLook::Check" // don't remember exact signature
bool check_look(Critter& cr1, Critter& cr2)
{
  return Helper(cr1,cr2);
}

// mono class
class CheckLook
{
  public bool static Check(IntPtr ptr1, IntPtr ptr2)
  {
    var cr1 = (Critter)ptr1;
    var cr2 = (Critter)ptr2;
    // ...
  }
}
« Last Edit: July 09, 2013, 08:47:27 pm by Bartosz »

Offline wladimiiir

  • Rotator
  • Independent FOnline developer
Re: FOnlineServer with Mono
« Reply #49 on: July 09, 2013, 08:53:44 pm »
1. Did you think about having implicit operator (instead of explicit) for Critter?
Code: [Select]
public static implicit operator Critter(IntPtr ptr)So in initialization function you could just write:
Code: [Select]
public static Critter InitCritter (IntPtr ptr, bool firstTime)
{
    Critter npc = ptr;
    ...

2. So if I understood it, without introducing some additional functions in FOnline.Main class, the only workaround how I could use it is to bind managed function
Code: [Select]
#pragma bindfunc "void Foo() -> mono Classname::MethodName"and call it in main.fos@check_look?
But I suppose this is stupid solution, right? :)

Offline Bartosz

  • Rotator
  • There'd better be a killer reason...
Re: FOnlineServer with Mono
« Reply #50 on: July 09, 2013, 10:18:12 pm »
1. I kinda don't like implicit conversions, would be damn useful if they would be used when engine calls mono method, but they don't (hence engine-callble methods take IntPtr as argument).

2. Yeah, kind of dirty, but should work.