示例#1
0
        public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize)
        {
            var retvalData = FunctionReference.Invoke(refIndex, argsSerialized);

            if (retvalData != null)
            {
                if (m_retvalBuffer == IntPtr.Zero)
                {
                    m_retvalBuffer     = Marshal.AllocHGlobal(32768);
                    m_retvalBufferSize = 32768;
                }

                if (m_retvalBufferSize < retvalData.Length)
                {
                    m_retvalBuffer = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length));
                }

                Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length);

                retvalSerialized = m_retvalBuffer;
                retvalSize       = retvalData.Length;
            }
            else
            {
                retvalSerialized = IntPtr.Zero;
                retvalSize       = 0;
            }
        }
示例#2
0
        public static byte[] CallRef(uint reference, byte[] argsSerialized)
        {
            try
            {
                return(FunctionReference.Invoke(reference, argsSerialized));
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception while calling native reference: {0}", e.ToString());

                return(new byte[] { 0xC0 });
            }
        }
示例#3
0
        public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize)
        {
            // not using using statements here as old Mono on Linux build doesn't know of these
#if IS_FXSERVER
            using (var syncContext = new SyncContextScope())
#endif
            {
                if (GameInterface.SnapshotStackBoundary(out var b))
                {
                    ScriptHost.SubmitBoundaryStart(b, b.Length);
                }

                try
                {
                    var retvalData = FunctionReference.Invoke(refIndex, argsSerialized);

                    if (retvalData != null)
                    {
                        if (m_retvalBuffer == IntPtr.Zero)
                        {
                            m_retvalBuffer     = Marshal.AllocHGlobal(32768);
                            m_retvalBufferSize = 32768;
                        }

                        if (m_retvalBufferSize < retvalData.Length)
                        {
                            m_retvalBuffer     = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length));
                            m_retvalBufferSize = retvalData.Length;
                        }

                        Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length);

                        retvalSerialized = m_retvalBuffer;
                        retvalSize       = retvalData.Length;
                    }
                    else
                    {
                        retvalSerialized = IntPtr.Zero;
                        retvalSize       = 0;
                    }
                }
                catch (Exception e)
                {
                    retvalSerialized = IntPtr.Zero;
                    retvalSize       = 0;

                    PrintError($"reference call", e.InnerException ?? e);
                }
            }
        }
示例#4
0
        public void CallRef(int refIndex, byte[] argsSerialized, out IntPtr retvalSerialized, out int retvalSize)
        {
            if (GameInterface.SnapshotStackBoundary(out var b))
            {
                ScriptHost.SubmitBoundaryStart(b, b.Length);
            }

            try
            {
                var retvalData = FunctionReference.Invoke(refIndex, argsSerialized);

                if (retvalData != null)
                {
                    if (m_retvalBuffer == IntPtr.Zero)
                    {
                        m_retvalBuffer     = Marshal.AllocHGlobal(32768);
                        m_retvalBufferSize = 32768;
                    }

                    if (m_retvalBufferSize < retvalData.Length)
                    {
                        m_retvalBuffer     = Marshal.ReAllocHGlobal(m_retvalBuffer, new IntPtr(retvalData.Length));
                        m_retvalBufferSize = retvalData.Length;
                    }

                    Marshal.Copy(retvalData, 0, m_retvalBuffer, retvalData.Length);

                    retvalSerialized = m_retvalBuffer;
                    retvalSize       = retvalData.Length;
                }
                else
                {
                    retvalSerialized = IntPtr.Zero;
                    retvalSize       = 0;
                }
            }
            catch (Exception e)
            {
                retvalSerialized = IntPtr.Zero;
                retvalSize       = 0;

                PrintError($"reference call", e.InnerException ?? e);
            }
        }