Exemple #1
0
        public unsafe void *feedRawSliceIntoDll(IntPoint[][] rawslice)
        {
            int            numpaths = (int)rawslice.Length;
            InputSliceInfo info     = dll.createInputSlice(numpaths);

            try {
                int *numpointss = info.numpointsArray;
                for (int i = 0; i < numpaths; i++)
                {
                    *(numpointss++) = (int)rawslice[i].Length;
                }
                long **paths = dll.getPathsArray(info.slice);
                numpointss = info.numpointsArray;
                for (int i = 0; i < numpaths; ++i)
                {
                    int numpoints = *(numpointss++);
                    //System.Windows.Forms.Application.DoEvents();
                    long *     path = *(paths++);
                    IntPoint[] pth  = rawslice[i];
                    for (int j = 0; j < numpoints; j++)
                    {
                        *(path++) = (long)(pth[j].x * dll.factor_slicer_to_internal);
                        *(path++) = (long)(pth[j].y * dll.factor_slicer_to_internal);
                    }
                }
            } catch {
                dll.freeInputSlice(info.slice);
                throw;
            }
            return(info.slice);
        }
Exemple #2
0
        private static void RedirectCall(MethodInfo from, MethodInfo to)
        {
            IntPtr methodPtr1 = from.MethodHandle.Value;
            IntPtr methodPtr2 = to.MethodHandle.Value;

            from.MethodHandle.GetFunctionPointer();
            to.MethodHandle.GetFunctionPointer();

            IntPtr domain = mono_domain_get();

            unsafe
            {
                byte * jitCodeHash      = ((byte *)domain.ToPointer() + 0xE8);
                long **jitCodeHashTable = *(long ***)(jitCodeHash + 0x20);
                uint   tableSize        = *(uint *)(jitCodeHash + 0x18);

                void *jitInfoFrom = null, jitInfoTo = null;

                long mptr1  = methodPtr1.ToInt64();
                uint index1 = ((uint)mptr1) >> 3;
                for (long *value = jitCodeHashTable[index1 % tableSize];
                     value != null;
                     value = *(long **)(value + 1))
                {
                    if (mptr1 == *value)
                    {
                        jitInfoFrom = value;
                        break;
                    }
                }

                long mptr2  = methodPtr2.ToInt64();
                uint index2 = ((uint)mptr2) >> 3;
                for (long *value = jitCodeHashTable[index2 % tableSize];
                     value != null;
                     value = *(long **)(value + 1))
                {
                    if (mptr2 == *value)
                    {
                        jitInfoTo = value;
                        break;
                    }
                }
                if (jitInfoFrom == null || jitInfoTo == null)
                {
                    Debug.Log("Could not find methods");
                    return;
                }


                ulong *fromPtr, toPtr;
                fromPtr        = (ulong *)jitInfoFrom;
                toPtr          = (ulong *)jitInfoTo;
                *(fromPtr + 2) = *(toPtr + 2);
                *(fromPtr + 3) = *(toPtr + 3);
            }
        }
Exemple #3
0
        public unsafe static long[][] ToLongArray(long **array_ptr, long *count_ptr, long length)
        {
            var array_count = ToLongArray(count_ptr, length);
            var array       = new long[array_count.Length][];

            for (int i = 0; i < array_count.Length; i++)
            {
                array[i] = ToLongArray(array_ptr[i], array_count[i]);
            }
            Free(new IntPtr(array_ptr));
            return(array);
        }
Exemple #4
0
        public override void EnsureInitialized()
        {
            base.EnsureInitialized();

            OriginalVmtAddress = (IntPtr)((long **)InstanceAddress)[0];

            Length = CountFuncs(OriginalVmtAddress) * sizeof(long);

            int    copySize = Length + sizeof(long);
            long **newVmt   = (long **)Marshal.AllocHGlobal(copySize);

            Buffer.MemoryCopy((void *)OriginalVmtAddress, newVmt, copySize, copySize);

            VmtAddress = (IntPtr)newVmt;
            SetVmt(VmtAddress);
        }
Exemple #5
0
        //helper method to read an output slice
        private unsafe void readOutputSlice(void *result, bool mode2D, double z, int sliceIdx, MultiSlicerInterface.MultiCfg.PathType pathtype, Color[] colorList, Transaction tr, BlockTableRecord btr)
        {
            Color col;

            SI.OutputSliceInfo info = dll.getOutputSliceInfo(result, sliceIdx, (int)pathtype);
            int numpaths            = info.numpaths;

            if (numpaths == 0)
            {
                return;
            }
            int *  numpointss    = info.numpointsArray;
            long **paths         = info.pathsArray;
            double scalingFactor = dll.factor_internal_to_input;

            if (!mode2D)
            {
                z   = info.z * dll.factor_internal_to_input;
                col = colorList[info.ntool];
            }
            else
            {
                col = colorList[sliceIdx];
            }
            for (int i = 0; i < numpaths; i++)
            {
                int      numpoints = *(numpointss++);
                long *   path      = *(paths++);
                Polyline p         = new Polyline();
                if (numpoints > 0)
                {
                    for (int j = 0; j < numpoints; j++)
                    {
                        p.AddVertexAt(j, new Point2d((*(path++)) * scalingFactor, (*(path++)) * scalingFactor), 0, 0, 0);
                    }
                    p.Color     = col;
                    p.Elevation = z;
                    addPolyline(tr, btr, p);
                }
            }
        }
Exemple #6
0
        public unsafe void loadAddSlices(string configname, string file, bool onlyToolpaths, bool useJustNtool, int justNtool)
        {
            doActionForFile(configname, file, (string pathsfile) => {
                modifyAutoCADDocument((Transaction tr, BlockTableRecord btr) => {
                    using (SI.MultiSlicerLoader loader = new SI.MultiSlicerLoader(dll, pathsfile)) {
                        int numRecords       = loader.pathsFileNumRecords();
                        long **paths         = null;
                        double **pathsd      = null;
                        bool isDouble        = false;
                        SI.LoadPathInfo info = new SI.LoadPathInfo();
                        while (loader.readNextPathFromFile(ref isDouble, ref info))
                        {
                            if (onlyToolpaths && !(
                                    (info.type == (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_PERIMETER) ||
                                    (info.type == (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_SURFACE) ||
                                    (info.type == (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_INFILLING)))
                            {
                                continue;
                            }
                            if (isDouble)
                            {
                                pathsd = (double **)info.pathsArray;
                            }
                            else
                            {
                                paths = (long **)info.pathsArray;
                            }
                            long *path           = null;
                            double *pathd        = null;
                            double scalingFactor = info.scaling;
                            int ntool            = info.ntool;
                            if (useJustNtool && ntool != justNtool)
                            {
                                continue;
                            }
                            Color col;
                            switch (info.type)
                            {
                            case (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_RAW_CONTOUR: col = globalContourColor; break;

                            case (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_PROCESSED_CONTOUR: col = contourColors[ntool]; break;

                            case (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_PERIMETER: col = perimeterColors[ntool]; break;

                            case (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_SURFACE: col = surfaceColors[ntool]; break;

                            case (int)MultiSlicerInterface.MultiCfg.LoadPathType.PATHTYPE_TOOLPATH_INFILLING: col = infillingColors[ntool]; break;

                            default: col = otherColor; break;     //this should never happen
                            }
                            for (int i = 0; i < info.numpaths; i++)
                            {
                                int numpoints = *(info.numpointsArray++);
                                Polyline p    = new Polyline();
                                if (numpoints > 0)
                                {
                                    if (isDouble)
                                    {
                                        pathd = *(pathsd++);
                                        for (int j = 0; j < numpoints; j++)
                                        {
                                            p.AddVertexAt(j, new Point2d((*(pathd++)), (*(pathd++))), 0, 0, 0);
                                        }
                                    }
                                    else
                                    {
                                        path = *(paths++);
                                        for (int j = 0; j < numpoints; j++)
                                        {
                                            p.AddVertexAt(j, new Point2d((*(path++)) * scalingFactor, (*(path++)) * scalingFactor), 0, 0, 0);
                                        }
                                    }
                                }
                                p.Color     = col;
                                p.Elevation = info.z;
                                addPolyline(tr, btr, p);
                            }
                        }
                    }
                });
            });
        }
Exemple #7
0
 public int GetFrameRateList([NativeTypeName("IPin *")] IPin *pPin, [NativeTypeName("long")] int iIndex, SIZE Dimensions, [NativeTypeName("long *")] int *ListSize, [NativeTypeName("LONGLONG **")] long **FrameRates)
 {
     return(((delegate * unmanaged <IAMVideoControl *, IPin *, int, SIZE, int *, long **, int>)(lpVtbl[8]))((IAMVideoControl *)Unsafe.AsPointer(ref this), pPin, iIndex, Dimensions, ListSize, FrameRates));
 }
Exemple #8
0
        /// <summary>
        /// Redirects all calls from method 'from' to method 'to'. This version works
        /// only if the 'from' method has already been compiled (use GetFunctionPointer to force
        /// this) but no function calling 'from' have already been compiled. In fact, this
        /// function forces compilation for 'to' and 'from'. 'to' and 'from' are assumed
        /// to be normal methods.
        /// After compilation, this method looks up the MonoJitInfo structs for both methods
        /// from domain->jit_info_hash and patches sets the pointer to native code to the code
        /// obtained from compiling 'to'.
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        private static void RedirectCall(MethodInfo from, MethodInfo to)
        {
            /* We assume that we are only dealing with 'normal' functions (in Mono lingua).
             * This excludes in particular:
             *  - generic functions
             *  - PInvokes
             *  - methods built at runtime
             */
            IntPtr methodPtr1 = from.MethodHandle.Value;
            IntPtr methodPtr2 = to.MethodHandle.Value;

            // ensure that both methods are compiled
            from.MethodHandle.GetFunctionPointer();
            to.MethodHandle.GetFunctionPointer();

            // get domain->jit_code_hash
            IntPtr domain = mono_domain_get();

            unsafe
            {
                byte * jitCodeHash      = ((byte *)domain.ToPointer() + 0xE8);
                long **jitCodeHashTable = *(long ***)(jitCodeHash + 0x20);
                uint   tableSize        = *(uint *)(jitCodeHash + 0x18);

                void *jitInfoFrom = null, jitInfoTo = null;

                // imitate the behavior of mono_internal_hash_table_lookup to get both MonoJitInfo ptrs
                long mptr1  = methodPtr1.ToInt64();
                uint index1 = ((uint)mptr1) >> 3;
                for (long *value = jitCodeHashTable[index1 % tableSize];
                     value != null;
                     value = *(long **)(value + 1))
                {
                    if (mptr1 == *value)
                    {
                        jitInfoFrom = value;
                        break;
                    }
                }

                long mptr2  = methodPtr2.ToInt64();
                uint index2 = ((uint)mptr2) >> 3;
                for (long *value = jitCodeHashTable[index2 % tableSize];
                     value != null;
                     value = *(long **)(value + 1))
                {
                    if (mptr2 == *value)
                    {
                        jitInfoTo = value;
                        break;
                    }
                }
                if (jitInfoFrom == null || jitInfoTo == null)
                {
                    DebugLog.Log("Could not find methods");
                    return;
                }


                // copy over code_start, used_regs, code_size and ignore the rest for now.
                // code_start beings at +0x10, code_size goes til +0x20
                ulong *fromPtr, toPtr;
                fromPtr        = (ulong *)jitInfoFrom;
                toPtr          = (ulong *)jitInfoTo;
                *(fromPtr + 2) = *(toPtr + 2);
                *(fromPtr + 3) = *(toPtr + 3);
            }
        }
Exemple #9
0
        public static unsafe IntPtr GetGlobalAddress(int index)
        {
            long **addr = (long **)GlobalAddress.ToPointer();

            return(new IntPtr(&addr[index >> 18][index & 0x3FFFF]));
        }