Search Unity

Darknet

Discussion in 'Multiplayer' started by alanis, Oct 8, 2009.

  1. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    While browsing for alternatives for a small scale mmo server to work with unity3d, I came across Darknet
    http://darkbasicpro.thegamecreators.com/?f=darknet

    regarding their product specs it states:


    "It uses both UDP and TCP protocol making it suitable for virtually any type of online game ranging from fast paced first person shooters to large scale massively multiplayer online games. It is very easy to use and well documented with several code examples. DarkNet is compatible with Dark Basic Professional, C++ and .NET compatible languages (e.g. C#, VB.NET)."




    Does this mean it can work with Unity3d right out of the box, without too many mod hassles or tweaks?

    I searched on unity forums but could not find any posts of threads regarding Darknet


    Has anyone used it before?

    comments pros and cons are welcome.



    If it can work with unity3d that will be a great alternative for $32.99 I must say.

    thank you.
     
  2. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I will let you know later tonight.
    edit:
    this will have to wait until tomorrow, I've purchased the library but since they take from 24 hours to 72 hours to confirm and release the product for download, this could be sometime tomorrow or monday before I can test.
     
  3. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Thank you zumwalt,
    keep us updated
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    would be the first TGC product that does not only sound nice but also work as advertised.
    But looking forward to get your opinion on it zumwalt and potential comparisions to photon and especially lidgren
     
  5. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    DarkNET is actually MikeNet, found that out after purchasing and downloading it. He has built it with VS 2008 so none of the projects compile or work with < VS 2008 extensions. Another down side is that the assembly file that he gives (MikeNet.dll) was last updated on Janyuary 10'th of this year, so no new updates in the past 9 months, not that this is bad, it just means it has no active current development on the release build.

    I created a project first in VS 2005 C#, added the library which went ok, no errors on adding it, the methods are understood, however, when attempting to actually use it, I get assembly errors, like something is missing. Well the missing item has to be a library only found from VS 2008 so I am installing that now to see what I find out.

    This is going to go 1 of 2 ways, either he is using libraries which are not going to be supported by Mono at this time, or I will identify which additional libraries that have to be added to the project folder for this thing to actually work. I am disappointed that the creator who is an independent developer, geared his library for only VS 2008 and used Framework 3.5 dependent calls which I think is the case.

    If this is true, and I will know sometime later today after VS 2008 finishes its install in my Parallels desktop, then the answer is almost a definite no about it working with Unity, at least not on the Mac, although it possibly will work on the PC since I think you can use native framework with Unity on the PC.
     
  6. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Well, first I can say that the thing works with VS 2008 C# and I created a simple client and simple server to test CPU load with them both in IDLE state. The image below represents a total of 4 threads running, the server has 2 threads, on thread is the server the other thread is the message handler (I separated the two out), the client is done the same way, the client itself is one thread the message handler is a different thread.

    Getting ready to see if I can get what I have done to now work in Unity without me creating any sort of bridge library. (basically this is the point where we go either hmm / doh / yay)
     

    Attached Files:

  7. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    And the answer, is...

    DOH

    All MikeNET is good for in Unity at the moment is MDK.
    (for those who never played the game or watched Demolition Man with Stalone..) Murder / Death / Kill

    The library is using some features beyond just framework 2.0, so not only getting null reference exceptions in Unity, but it is bad enough for the bug reporter to open and then Unity locks up, have to force quit Unity and then let Unity rebuild its manifest for the project.

    Seems like a good windows engine for entry level networking at the moment though, just way to many limitations. I sent the developer an email asking him if he has a version that works with VS 2005, if so then hopefully that version uses a lower framework.

    Sorry

    Moving on to Photon now to play with it some and see what it can do!
     
  8. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Thank you for taking the time and review DarNet for us,

    I guess it was just too good to be truth, it sounded really nice features and price wise on advertisement but unfortunately not what we expected, after reading your review, well at least it wont work with unity3d,
    I guess it may be good and as described specially cratfed for its native product category which is DBpro.

    I just hope the developer of DarkNet will look into this and he can come up with something or a new version that can be compatible or will work with unity.

    I guess they should of have a demo or trial for Darket, so user can try it beforre purchase to test if it is right for their needs or compatible.

    Thanks again.
     
  9. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    My pleasure, if you run across any other .Net type networking you want me to look into, please let me know.

    Best regards.
     
  10. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    So for C# / .NET only it is and will remain lidgren then I guess, aside of photon naturally
     
  11. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    So far, I got a hold of the latest build of that library, going to work with it some, interesting that it is a free library set for what it appears to do. More on that and Photon later. Still setting up my Photon project.
     
  12. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    How is lidgren?

    is it any good, features? easy to use, etc...

    will it work with unity right out of the box?

    documentation?


    I was searching here on the forums but could not find any info about it or reviews.




    thanks
     
  13. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    lidgren is dead simple to use.
    if you require any realistic documentation for it, then you basically will just need to do a basic network programming refresh before, as it is as simple as networking can get.
    Kind of Enet meets C# to put it simple. a handfull of methods and you putting data in and out and the rest is your job. it only gives you the network layer nothing more
     
  14. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Latest version of lidgren is july 7 of this year, it has samples that come with it and documentation, on top of that, it is free and comes with visual studio projects.

    Find it here:
    http://code.google.com/p/lidgren-library-network/

    Image of zip contents of lidgren:
     

    Attached Files:

  15. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    thank you,

    nice,
    it looks good, I will definately take a look at it.

    have you guys tested it out yet?

    how does it compare to photon.

    I am more inclined to building an mmorpg, well, we might take out the first "m" let put it more appealing and credible for an indie morpg.

    So basically here what matters is a good reliable and expandible networking system client - server, something that in the future will meet the demanding of concurrent connections.

    You know, Its is quite impressive how those open source mmo server like arcemu work great, I have seen up to 5000 concurrent online players connections in 1 single hardware server, not bad, I gues the developers have been polishing the code all this time.


    Its time for unity to become more unite and start a mmo community project, a lot of other game engines outhere do it now adays,
    take for instance leadwerks, they got now their own community mmorpg project going on right now, they pretty much got a base on that and they are using raknet.

    might want to check them out,
    so far they started the project a couple of months ago and now they pretty much got a working client and server using raknet and adding extra game logic basic rpg features stuff to it.
    all c++ coding source code available client and server.
    http://forum.leadwerks.com/viewtopic.php?f=1&t=3807&hilit=mmorpg
    its called LE Community MMO (LEC MMO)

    Torque: they have or had their own mmorpg , tmmokit
    whhich was avaiable to all users, even non license users. but I guess that just changed, ever since t3d rc came out, th emmokit website mmoworkshop.com got shut down, and its been almost 2 to 3 weeks that the kit is not available and so the website, the site is up now but under construction, they posted a note saying that the websit eis migrating to another server, but so far almost 3 weeks and no migration or content on it.

    I dont think is the migration thing what shut down mmoworkshop.
    migrating a site can be done in matter of hours and not weeks, just redirect dns to point to new host, backup your site and restore site, as simple as that.
    I mean I have completely restored a full production hosting server with over 700 hosting account from scratch in no more then 3 to 4 hours, hardened the server configured and all accounts migrated.

    I think is because their new t3d license deal,
    ohh well, is their loss and our gain.


    Some thing like community project needs to be started here at unity, I mean it doesnt have to be a complete fully featured mmorpg demo, but something very basic that will jump start someone interested on unity to ease up the pain of putting together a networked game.


    ohh well, let me hear your comments on photon vs lidgren



    regards
     
  16. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    lidgren has no server backend. its a network layer only, so comparing it to photon is actually impossible.

    One is one and the other is the other :)
     
  17. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    yes, I just noticed that. :-(

    Ohh well, still looking for more alternatives server backend.

    thanks guys
     
  18. Deleted User

    Deleted User

    Guest

    Have you looked at SmartFoxServer - http://smartfoxserver.com/ ?

    I haven't tried it, but it's the only product I've seen besides Proton/Neutron that advertises a Unity client lib, and I've seen some mention of it on the forums here.
     
  19. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Ahh yes,

    I have looked at it and it is nice, Thomas has done a great job on the api, although I was looking for both UDP, TCP capable one.

    But I may look at it again and see if it will do the job for what i need it for.
     
  20. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    TCP + UDP + Unity likely means Photon only unless you develop it yourself I fear
     
  21. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Yes, you are right dreamora,
    So far Photon is the way to go, for this project.

    raknet will be the other option, but raknet is only a library and there is no server yet, if I am not mistaken.

    so the server will need to be built using raknet and an api to work with unity.


    Allthough I have read a littel bit about darkstar and there is a current c# api for darkstar and it may work with unity aswell, although I havent put that many attention to it, will look it over.
     
  22. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Raknet library conversion is taking me longer than expected, 2 reasons for that, first is that I am not comfortable with managed C++, it is a different animal than normal unmanaged C++ on top of that, you can only compile managed C++ in windows as it exposes framekwork integration. I am running into some unexpected snags in the engine so I am having to rethink certain aspects of the library set.

    I am still working through Photon right now, but I can say that it seems very viable for an MMO in the long run. However I haven't figured out yet how to get a few things going with it that I want, which is ok, it will take a few weeks to get fully comfortable with it.

    If you want plug and play with less work, use Photon or SmartFox, if you know C++, you will want to use Raknet. For the price and abilities, all 3 are very good.
     
  23. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Well, raknet was my first choice, but getting it to work with unity will be kinda tough, since no plug and play deal atm.

    smartfox looks good, although it ony uses tcp, and no UPD as i need, but is well documented on their website.

    in the other hand photon, looks like is going to do the job, but practly there is no documentation for it, nor community forums where you can express your hair pulling frustration to the public, lol
    I guess photon was intended for the experienced networking guys. and not form me wannabe one.

    well, I think there is not much I can do at the moment but to keep on trying and get my feet more deeper into the water on networking coding and dabilities. so far its been a year that I am getting my feet wet into the networking game developement and still feel that I am a noob, so I guess by the time I get more proficient on to it, Ill bet you new technology will come onto place and will have to learn again to keep up to the standards, lol

    I will keep my eyes open for new stuff, I usually do very deep research on the topic and hopefully will find other alternatives.
     
  24. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    Hi, I am the developer of DarkNet.

    The last update to DarkNet was September 18th 2009. DarkNet has evolved significantly since its first release and is still in development. The networking module has been optimized to the extent that I now believe it to be perfect. Currently in the works is a NAT punch-through demo and a 64 bit version of the plugin. So, contrary to what was stated earlier in this thread, DarkNet is still in active development.

    DarkNet is written in C++ (unmanaged) and was originally designed for C++. It has additional code to make it compatible with CLR and DarkBASIC Pro.

    The CLR version is the one that you are having trouble with. I'm not sure why it doesn't work with VS 2005 but I do know why it isn't working with Mono.
    DarkNet is compiled using a mixture of native and managed C++ which Mono does not support, mono needs pure managed C++ as stated here: http://www.mono-project.com/CPlusPlus

    DarkNet is compiled using visual studio 2008 with the project setting CLR set to: 'Common Language Runtime Support (/clr)'. If anyone knows steps to facilitate VS 2005 compatibility please explain them to me and I will release an update if successful.

    One other limitation applicable to Unity is that the executables will only work on windows because windows libraries are used, most importantly winsock for networking. I am probably going to look at moving to a more portable networking API in the future, but this is unlikely to happen any time soon.

    Good luck with your project, hopefully my post will have cleared up some of your queries. Please feel free to ask further questions and I will respond ASAP.
     
  25. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I am in the process of converting RakNet to Managed C++, I am also using the /clr option within the build. I switched all classes in the unmanaged C++ code to Public Class 'Name' so that they are visible in a managed environment. I am by no means proficient at converting unmanaged C++ to managed C++ so I would be of no use to help you figure out what is left to move anything unmanaged in your library to managed.

    As far as Visual Studio 2005 build, I will email you the error so we keep that offline, however, I doubt it will be of any use since the error is very generic, basically it is complaining that an assembly is missing, but it doesn't mention which one or why.

    The same identical code works in Visual Studio 2008 build of a C# test application. Honestly it would probably be quicker for you to get ahold of Visual Studio 2005 C# and test the build there so you can debug / trace the real missing assembly. Unity is 2 fold, I have written a program that uses a SWIG converted unmanaged library into a managed library and that library will only work with Windows and will not work with the Mac, I suspect the same will be the case here, if you can get your library to compile and work with VS 2005 C# then I suspect that it will work at least on Windows.

    I will send you another email tonight with an attached VS C# 2005 project for further troubleshooting. It would be great if this can be tested and working with Unity at the very least on Windows even if it won't support the Mac.

    FYI: January of 2009 is the only build that TheGameCreators has and is selling with no updates.
     
  26. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99

    Hi there MichaelPryor,
    thanks for taking the time to post your comments regarding Darkent I am glad you as the developer of the application is here to respond to our questions,

    As you can see we are looking for alternatives for networking games with unity3d,

    As I was on my research I came across your application and wanted to see if it works with unity.

    Darknet will be a great affordable solution for unity networking games, specially if the features described on the product will work for unity.

    I wonder if you may consider doing a unity version for darknet, at least for the windoew platform, since you stated is not compatible with mac, but it will be great if we can use it on the unity for windows.

    As you can see so far there a few options available for making a networked game in unity like:.

    1- build your own server - most of the case even the most experienced programmer wont do it, is like reinventing the wheel and so much time consumming.

    2-smartfoxserver - this is a great option which there is already an api for unity, but only TCP available. great documentation

    3- photon server, TCP, UDP which looks like a great server side mostly for advanced experience programmers. little to non documentation so it even hard for us low programming skilled game artist designers.

    3- raknet - raknet is a great alternatice, but no unity api exist so experienced programmming needed to make it work.


    I would really like to see Darknet to be an alternative for unity windows platform.
    since it is a great price and great features, great documentation and it looks easy to use for individuals low budget multyplayers game devs wannabe.

    to have an api , plugin or make it fully compatible to darknet version for unity if possible, something like to work with unity right out of the box wil be great since there is great market here on unity to expand your business.

    Since there is no demo available for darknet yet, is hard to see what we will get or can do.

    Question:
    Does darknet come with a ready made server side? or it will need to be built from scratch?

    Looking forward to hear your comments or feedback.

    thanks again for your time.
     
  27. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    Yes definitely, if it is possible I will create a unity3D compatible version.

    I will do some investigating over the next few days and get back to you guys. Zumwalt seems to be doing a similar thing with RakNet as was done with DarkNet to create the CLR version, so I will post details on exactly what I did so we can see what is going wrong.

    In the mean time you can get alot of information about DarkNet on its website (including demos and documentation): www.darknetworking.net.
     
  28. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Hi Michael, thanks for your prompt reply.

    I am glad to hear that you will be working on a darknet version for unity. this will be great option.

    Now, as my prevous question :

    does darknet have a ready made server side? or is it just the libray?

    if so, how hard will it be to do a server.


    thanks again
     
  29. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    (I'll help answer these questions) DarkNet is a library set (DLL), you include this library in your references and simply "Use" the methods. They are all public static, there isn't even a namespace, they are simply classes. There are 3 main classes, everything else is under those classes, you just have to use them in the right order for them to "work". You create your own server, you create your own client to connect to the server.

    It is very easy to work with, didn't take me very long to build that client and server for the initial test in VS 2008. The list of methods in each class are documented so you know what the inputs and outputs are and there are plenty of examples written for it to learn from. If you were making a game in Visual Studio either in C++ or C# / VB.Net this set is easy to get up and running and it has practically no CPU overhead.
     
  30. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Thank you zumwalt,

    Nice to hear that.

    looking forward to see if Michael can get Darknet version for unity soon.

    thanks again
     
  31. hogus

    hogus

    Joined:
    Jul 9, 2009
    Posts:
    145
    Is there a thread or wiki page somewhere that details all things that are fundamentally wrong with Unity's network implementation?

    For myself, I've managed to get the networking up and running, a master server compiled and everything connecting and running. But I haven't really used it out there in the wild that much.

    Now I'm fooling around with Lidgren, mainly just because it's fun to play with multiple libraries... and I'd like to know what it is that we are trying to fix here so I can maybe try heading in some meaningful direction.

    Also, does anyone know if Lidgren would work with a mono implementation. I'm a M$ guy myself, so I have no real way to test this for myself.
     
  32. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    There is nothing wrong with Unity's networking.
    But its targeted at small scale temporal game environments, it will not work as an MMO networking or larger scale server networking.
    There are threads on the topic, especially the mmo thread with 4+ pages that contain valuable information on that topic
     
  33. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    Hi again,

    I have looked into Unity3D and now understand it a little better (hopefully).

    Is the visual studio 2005 issue not directly related to Unity3D? My understanding is that Unity3D uses Mono to run its scripts and is thus unrelated to VS.
    Am I right in thinking compatibility with Mono is the problem?

    For Unity3D Indie users, I am looking at ways to make DarkNet compatible but I don't think it is going to be straightforward. I should have some news for you within a week or two.

    For Unity3D Pro users, this page: http://unity3d.com/support/documentation/Manual/Plugins.html explains how you can call methods of a C++ DLL. You can get the C++ version of DarkNet, compiled as a DLL rather than library (.lib) from here: www.darknetworking.net/MikeNetUnity.dll which you should hopefully have some success with. Also attached is a header file which you can use to see the available functions. I suggest trying these two functions which are nice and simple:
    Code (csharp):
    1. bool mnGetErrorFlag();
    2. void mnSetErrorFlag();
    I expect that this DLL will not yet be fully functional, particularly in the area of string returning, but I just want to see if I am going in the right direction.

    Let me know how you get on as I don't own the pro version so cannot test. I will probably purchase it in the future so that I am able to run propper tests.
     

    Attached Files:

  34. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I have grabbed the DLL and going to give this a test in Pro shorlty.

    EDIT: the vs 2005 issue is independent of Unity all together, DarkNet simply doesn't work with VS 2005 C#.

    I have ran across this issue before, I have the DLL in the assets / plugins folder and get this error, so I move it up one level and get the same error. Unity is designed in such a way that you can't have the DLL in the same folder as the Unity.exe file, meaning that when you are in the "Editor" you can't expect the DLL to be in the same folder as the editor binary.

    This will eventually blow up unity, but I know what to do, I will compile my test program, deploy it to windows and move the DLL to the same folder as the binary and test.

    Edit:
    (sigh)
    Ok, it is as I suspected, your DLL is looking to be in the same folder as the game binary, this will definately NOT work, this is a flaw with Unity, I have had a ticket open on this particular issue for ages now. Case Reference (Case 167943) which dates back to March 20th of this year. (ticket is in closed status by the way, it is not likely they will change or fix this particular issue since it is uncommon)

    Once I move the DLL to the same folder as the compiled program binary (exe), I then get the following error on my logs:
    Going to look at the header and see where that method is really hiding.

    Another [Edit]
    You only have 1 public static export exposed, I just did an ordinal check using "dumpbin" command:
    dumpbin mikenetunity.dll /EXPORT

    This would give me a list of all public methods and their ordinals to use for the dllimport in Unity, this came back with only 1 hit. Ordinal position #4, which is your Init_locks method.

    This is my code btw (in Unity)
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Runtime.InteropServices;
    5.  
    6. public class DarkNetUse : MonoBehaviour {
    7.  
    8.     [DllImport("MikeNetUnity.dll")]
    9.     static extern bool mnGetErrorFlag();
    10.     [DllImport("MikeNetUnity.dll")]
    11.     static extern void mnSetErrorFlag();
    12.    
    13.     // Use this for initialization
    14.     void Start () {
    15.        
    16.     Debug.Log(mnGetErrorFlag());
    17.     }
    18.    
    19.     // Update is called once per frame
    20.     void Update () {
    21.    
    22.     }
    23. }
    24.  
    Also, placing the MikeNet.dll into the assets folder, then calling Debug.Log(mn.GetErrorFlag()); shuts down Unity on Windows build. To be more specific:

    I will see about writing a C# DLL in 2008 that creates its own thread to start that DLL in on its own, and passes the value back to me so I can pass it back to Unity and see what happens.

    Edit: epic failure on my part, even though I can get it to work in VS 2008, I can't get it to "not" crash Unity. Still can't get it to work on 2005, you are not using LINQ are you?
     
  35. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    Sorry about that, I made a criminal mistake!

    This second attempt should work. All commands other than string returning commands you should be able to use:
    www.darknetworking.net/MikeNetUnity2.dll

    I have tested this in C# (VS 2008) using the same method that Unity Pro is using. This example code works:
    Code (csharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Runtime.InteropServices;
    6.  
    7. public class MyClass
    8. {
    9.     public static void Main()
    10.     {
    11.         Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
    12.         ClearPacket();
    13.     }
    14.  
    15.     public static void ClearPacket()
    16.     {
    17.         mnClearPacket(2525);
    18.     }
    19.  
    20.     [DllImport("MikeNetU.dll")]
    21.     private static extern int mnClearPacket(Int64 Packet);
    22. }
     
  36. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    (Edit I am an idiot, I forgot to include Using System, appended but still got the same error in your DLL, without using System, I don't have full datat types available)

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System;
    4. using System.Collections;
    5. using System.Runtime.InteropServices;
    6.  
    7. public class DarkNetUse : MonoBehaviour {
    8.     const string iPath = @"C:\Users\zumwalt\Documents\GameSavingAndLoadingXML\Assets\Plugins\MikeNetUnity2.dll";
    9.    
    10.     [DllImport(iPath)]
    11.     static extern   bool mnGetErrorFlag();
    12.     [DllImport(iPath)]
    13.     static extern void mnSetErrorFlag();
    14.    
    15.     [DllImport(iPath)]
    16.     static extern int mnClearPacket(Int64 Packet);
    17.    
    18.     // Use this for initialization
    19.     void Start () {
    20.         Debug.Log("Error Flag Condition:" + mnGetErrorFlag().ToString());
    21.         mnClearPacket(2525);
    22.     }
    23.    
    24.     // Update is called once per frame
    25.     void Update () {
    26.    
    27.     }
    28. }
    29.  
    Any way that your DLL can be made not to look for the binary in the same folder as the DLL? As I stated earlier, Unity does not support this because in the Editor mode that would mean that the binary is the Unity.exe on Windows and when a game is built and deployed, the user DLL's are in a plugins folder which means the DLL will be one level below the binary in a deployed build.
     

    Attached Files:

  37. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    The DLL doesn't look for the binary, the binary looks for the DLL.

    You can either:
    - Have two copies of the DLL, one in the unity plugin folder and one in the working directory of the exe.
    - Set a full destination address for DllImport. It looks like you've done this so it should work; it does in VS.

    Would something like this not work?
    Code (csharp):
    1.     [DllImport("Plugins/MikeNetUnity.dll")]
    2.     private static extern int mnSetCursor(long Packet, uint Position);

    I saw a DarkNet error message at the end of your last post. This is a sign of success as that error should be displayed since mnClearPacket is trying to clear a packet that doesn't exist. Did you get that using Unity3D? And just to clarify, are you still getting that access violation error?
     
  38. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Edit:
    const string iPath = @"Plugins\MikeNetUnity2.dll";
    That doesn't work, still get dllnotfound, I have to use the full path while debugging. Ine the final build I can simply move the DLL to the application root to beside the exe. FYI if you place any DLL in the same folder with the Unity.exe, the editor thinks you are moving files around while editing the project and eventually dies with errors about files being moved, I have that in that ticket I mentioned earlier.

    I have just attached my working CS file for the Client end, I can attach the C# file for the 2008 server piece also if need be. This CS file would go in the assets folder and be attached to an empty game object.

    Yes, I got that using Unity3d Pro, I am no longer getting the access violation error anymore which is greate.
    End Edit:

    A few missing references though, but you are getting much closer with this build, here is a test project screen shot that I did, this shows 1 of the missing references, specifically for:

    Code (csharp):
    1.  
    2. [DllImport(iPath)]
    3.   static extern string mnGetLocalIPTCP(int Instance);
    4.  
     

    Attached Files:

  39. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    This is very good news, results of the test are as expected, the commands that return strings will not work yet. I know exactly what to do about those commands and am currently working on it. I should have a fully working version for you some time soon :)

    I don't think theres anything I can do about the dllnotfound issue. I think that is purely a Unity3D bug or limitation that they need to sort out.

    Thanks for testing.
     
  40. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Yea, I have spent plenty of time trying to figure out a fix to that issue, unfortunately there really is none. In reality with Pro, we are supposed to create a Plugins folder (which I have done) place the DLL in that folder (again, which I did) and when we use the [DllImport("dllname.dll")] it should simply find it and use it, but that is hardly the case all of the time. The only work around is to hard code the path during development and on deploy, move the DLL out of the plugins folder and put it in the root of the game folder with the game exe. That will be the case with your library also.

    Looking forward to your next build!
    I will spend time this weekend making a Unity CS file that has all of the DllImports for all of your public methods, going to take some time to create since I can't export out the manifest with all of the methods and their inputs / outputs. Lucky for me I type fast. (210 + wpm, in code, faster if normal typing)
     
  41. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    I was going to do that before releasing this version of the plugin. If you make significant progress on it then please post it here or email it to me; it would help a great deal!

    By the way, I have had to do this sort of thing before and the best way I have found is to simply copy and paste the functions of the header file and make adjustments to it within C#; this reduces the number of mistakes. Note that functions that return string should return IntPtr (not char*) and functions that take string as a parameter should take String (not char*). There are data types differences for the other types but most are fairly obvious.
     
  42. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I will have much more time to work on this tonight, I remoted into my home machine to do the testing during my breaks. Strings can be set to be marshed as follows:

    Code (csharp):
    1.  
    2. [DllImport(DLLFILE)]
    3. public static extern void TheMethod([MarshalAs(UnmanagedType.LPStr)] string theValue);
    4.  
    This works for all strings.
     
  43. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    This file is something like 90% done for you.
    You need to add in your structures from your header file and adjust anything that isn't correct. This is a first time run through on converting the header, I haven't tested this yet. Just trying to help as quickly as I can. This is the file that would be attached to an Empty Game Object to use your library. If it is useful to help you along great.

    Edit: just updated the cs file,testing it with Unity right now, had to make some minor fixes.

    Edit:
    Initial test, good results, same entry point error until you update the dll for those strings.
     

    Attached Files:

  44. MichaelPryor

    MichaelPryor

    Joined:
    Oct 13, 2009
    Posts:
    14
    Thanks for that, saved me alot of time :).

    The unity version of DarkNet is now complete and you should be able to use all commands as normal.

    You can't use the DarkNet classes but this isn't a major issue. Equivalent functions already exist for the clPacket class because DarkBASIC Pro is not object orientated. There is no equivalent exception class, but this only means that you cannot use the exception error mode; there are two other error modes available.

    I will apply finishing touches and then send this off to TGC. For now you can download and test the DLL by downloading it from here:
    www.darknetworking.net/MikeNetUnity3.dll

    You should include 'DarkNet.cs' in your projects so that you can access all DarkNet functions:
    www.darknetworking.net/DarkNet.cs

    Here is some demo code, which outlines how to use mnGetStringC which is an unusual command because it expects you to clean up the memory of the string it returns. All other string returning commands are used normally and do not require this extra work:
    Code (csharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Runtime.InteropServices;
    6.  
    7.  
    8. public class MyClass
    9. {
    10.     public static void Main()
    11.     {
    12.         long Packet = DarkNet.mnCreatePacket();
    13.         DarkNet.mnAddStringC(Packet, "Hello world", 0, true);
    14.  
    15.         while (0 == 0)
    16.         {
    17.             DarkNet.mnSetCursor(Packet, 0);
    18.  
    19.             // When using mnGetStringC in C++ delete[] would be used
    20.             // In C sharp we can't do this so we must do the following:
    21.             // - Get a pointer to the string
    22.             // - Use this to create a C sharp string
    23.             // - Deallocate the DarkNet string
    24.             // If you do not deallocate the DarkNet string a memory leak will occur
    25.             IntPtr ptr = DarkNet.mnGetStringC(Packet, 0, true);
    26.             string str = Marshal.PtrToStringAnsi(ptr);
    27.             DarkNet.mnFreeString(ptr);
    28.  
    29.             Console.WriteLine(str);
    30.         }
    31.  
    32.         Console.ReadKey();
    33.     }
    34. }
     
  45. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    Awesome job, grabbing this now and testing!
     
  46. liverolA

    liverolA

    Joined:
    Feb 10, 2009
    Posts:
    347
    nice work!!!
     
  47. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Sounds great and it looks like a pretty capable solution :)

    Looking forward to hear more about it as I would be happy to remain in the .NET world (nothing against C, but all is better than its ugly sibling, C hack hack ;) )


    That I also have DBP is just a nice additional candy although I'm unsure if it ever again will be used ^^
     
  48. alanis

    alanis

    Joined:
    Mar 4, 2009
    Posts:
    99
    Wow,

    this is great news, I am glad this is heading the right way and a great alternative for unity.

    keep up the good work and keep us posted on pros and bugs if any.


    thanks
     
  49. zumwalt

    zumwalt

    Joined:
    Apr 18, 2007
    Posts:
    2,287
    I made a grave error on the values for the string return (rather dumb noob mistake really), here is the corrected DarkNet.CS file you will need, this one correctly handles the returns of strings from all the string methods :)

    Sorry about that, uber noob of me overlooking this.
     

    Attached Files:

  50. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Decided to buy it. Its a great price for what it seems to offer :)


    One question: From what I've seen it works through plugins because the regular .net one uses features above Mono 1.2.5 capabilities, or above anything but VC# 2008
    Is there a chance that this is going to be adressed in some way to make it usable within .NET 2.0?
    I ask because the dll approach makes it windows standalone only with the Unity Pro requirement, where as .net 2.0 would make it windows + osx + web
    Especially the cut on the webend is a "deeper one" in its usability.

    I would assume that although Unity has networking, DarkNet could become a strong second option if it would really support Unity, but I naturally don't know how many features are beeing used that make it impossible at the time.