McOffsky
McOffsky

Reputation: 205

Unity3d ingame plugin fails to load system32 dll

I'am developing plugin for Kerbal Space Program (Windows 8.1) so I can use zeroconf networking (bonjour) from game. I'am using Mono.Zeroconf wrapper, Bonjour is installed and working. Simple console app works fine, service is visible on network.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Mono.Zeroconf;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            RegisterService service = new RegisterService();
            service.Name = "test server";
            service.RegType = "_daap._tcp";
            service.ReplyDomain = "local.";
            service.Port = 6060;

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord();
            txt_record.Add("Password", "false");
            service.TxtRecord = txt_record;

            service.Register();
            Console.WriteLine("Service registered!");
            Console.ReadLine();
        }
    }
}

But when I copy code and dlls to Unity3d plugin it fails to load Bonjour provider.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using KSP;
using UnityEngine;
using Mono.Zeroconf;

namespace KSP_dnssdServer
{
    [KSPAddon(KSPAddon.Startup.EveryScene, true)]
    class dnssdServer: MonoBehaviour
    {
        private float lastUpdate = 0.0f;
        private float lastFixedUpdate = 0.0f;
        private float logInterval = 5.0f;

        public RegisterService service;


        public dnssdServer()
        {

            if (instance == null) {
                instance = this;
                Debug.Log("dnssdServer Started");  
            } else {
                Debug.Log("dnssdServer already running, marking this instance as stale");
            }

            service = new RegisterService();
            service.Name = "TestService";
            service.RegType = "_ksp_dnssd._tcp";
            service.ReplyDomain = "local.";
            service.Port = 24321;

            // TxtRecords are optional
            TxtRecord txt_record = new TxtRecord();
            txt_record.Add("Password", "false");
            service.TxtRecord = txt_record;

            service.Register();

            Debug.Log("Service registered!");

            GameObject.DontDestroyOnLoad(this);
        }

        /*
         * Called after the scene is loaded.
         */
        void Awake()
        {
        }

        /*
         * Called next.
         */
        void Start()
        {
        }

        /*
         * Called every frame
         */
        void Update()
        {
        }

        /*
         * Called at a fixed time interval determined by the physics time step.
         */
        void FixedUpdate()
        {
            if ((Time.time - lastFixedUpdate) > logInterval)
            {
                lastFixedUpdate = Time.time;
                Debug.Log(instance.GetInstanceID().ToString("X"));
            }
        }

        void OnDestroy()
        {
            service.Dispose();
        }


    }
}

I'm assuming there is a problem with loading system32 dll's from plugin level. Any idea how to solve this?

Upvotes: 0

Views: 276

Answers (1)

McOffsky
McOffsky

Reputation: 205

And the anwser is... Mono.Zeroconf dlls should not be placed in subfolder, like I had them in my project. Mono.Zeroconf files on windows in this case need to be next to your plugin dll.

Upvotes: 1

Related Questions