Example #1
0
        public unsafe Instance(ObjectRef objectRef, params string[] dataRefs)
        {
            if (dataRefs == null)
            {
                throw new ArgumentNullException(nameof(dataRefs));
            }

            _dataRefCount = dataRefs.Length;

            var refs = stackalloc byte *[dataRefs.Length + 1];

            for (int i = 0; i < dataRefs.Length; i++)
            {
                refs[i] = (byte *)Marshal.StringToCoTaskMemUTF8(dataRefs[i]);
            }

            refs[dataRefs.Length] = null;

            _instanceRef = InstanceAPI.CreateInstance(objectRef, refs);

            for (int i = dataRefs.Length - 1; i >= 0; i--)
            {
                Marshal.FreeCoTaskMem((IntPtr)refs[i]);
            }
        }
            static void OnObjectLoaded(ObjectRef objectRef, void *inrefcon)
            {
                var handle = GCHandle.FromIntPtr(new IntPtr(inrefcon));
                var tcs    = (TaskCompletionSource <SceneryObject>)handle.Target;

                tcs.TrySetResult(objectRef != default ? new SceneryObject(objectRef) : null);
                handle.Free();
            }