Beispiel #1
0
        public Dll(string path, ushort dll_id)
            : this(path)
        {
            Id = dll_id;
            Console.WriteLine("UOExt: Loading {0} ({1})", Path.GetFileNameWithoutExtension(path), path);
            if (Config.Is64Bit || Config.IsUnix)
            {
                if (!File.Exists(path + ".xml"))
                {
                    throw new FileNotFoundException("Can't find {0}", path + ".xml");
                }
                XmlTextReader xml = new XmlTextReader(path + ".xml");
                xml.WhitespaceHandling = WhitespaceHandling.None;
                string name = "";
                byte packets = 0;
                while (xml.Read())
                {
                    if (xml.NodeType == XmlNodeType.Element && xml.Name == "Library")
                    {
                        uint amount = UInt32.Parse(xml.GetAttribute("Plugins"));
                        Plugins = new Plugin[amount];
                        while (xml.Read())
                        {
                            if (xml.Name == "Plugin")
                            {
                                uint id = UInt32.Parse(xml.GetAttribute("Id"));
//                                uint amount = UInt32.Parse(xml.GetAttribute("Descriptors"));
                                while (xml.Read() && xml.Name == "Descriptor")
                                {
                                    uint descr = UInt32.Parse(xml.GetAttribute("Id"));
                                    string value = xml.GetAttribute("Value");
                                    switch (descr)
                                    {
                                        case PD_NAME:
                                            name = value;
                                            break;
                                        case PD_PACKETSAMOUNT:
                                            packets = Byte.Parse(value);
                                            break;

                                    }
                                }
                                Plugins[id] = new Plugin(dll_id, (byte)id, packets, name);
                                Console.WriteLine("UOExt:  {0}) Name: '{1}', Packets: {2}", id, name, packets);
                            }
                        }
                    }
                }

            }
            else
            {
                IntPtr hModule = LoadLibrary(path);
                IntPtr ptrDllInit = GetProcAddress(hModule, "DllInit");
                IntPtr ptrDllInitDone = GetProcAddress(hModule, "DllInitDone");

                DllInit plgDllInit = (DllInit)Marshal.GetDelegateForFunctionPointer(ptrDllInit, typeof(DllInit));
                DllInitDone plgDllInitDone = (DllInitDone)Marshal.GetDelegateForFunctionPointer(ptrDllInitDone, typeof(DllInitDone));

                IntPtr plgs = plgDllInit();
                int plgs_count = Marshal.ReadInt32(plgs);
                Plugins = new Plugin[plgs_count];
                for (int i = 0; i < plgs_count; i++)
                {
                    IntPtr currentPlgInfo = new IntPtr(Marshal.ReadInt32(plgs, i * 4 + 4));
                    uint descriptors_count = (uint)(Marshal.ReadInt32(currentPlgInfo, 4));

                    byte packets = 0;
                    string name = null;
                    for (int j = 0; j < descriptors_count; j++)
                    {
                        uint key = (uint)(Marshal.ReadInt32(currentPlgInfo, j * 4 + 4));
                        uint value = (uint)(Marshal.ReadInt32(currentPlgInfo, j * 4 + 8));

                        switch (key)
                        {
                            case PD_NAME:
                                name = Marshal.PtrToStringAnsi(new IntPtr(value));
                                break;
                            case PD_PACKETSAMOUNT:
                                packets = (byte)value;
                                break;
                        }
                    }
                    Plugins[i] = new Plugin(dll_id, (byte)i, packets, name);
                    Console.WriteLine("UOExt:  {0}) Name: '{1}', Packets: {2}", i, name, packets);
                }


                plgDllInitDone();

                FreeLibrary(hModule);
            }
        }
Beispiel #2
0
        private static Plugin[] ReadLoadingOrder()
        {
            if (!File.Exists(Config.PluginInitOrderFile)) return new Plugin[0];

            string[] info = File.ReadAllLines(Config.PluginInitOrderFile);
            int loaded = 0;
            Plugin[] order = new Plugin[info.Length];

            char[] splitter = new char[1];
            splitter[0] = ',';
            for (int i = 0; i < info.Length; i++)
            {
                string[] row = info[i].Split(splitter, 2);
                row[0] = row[0].Trim();
                row[1] = row[1].Trim();
                Dll c_dll = null;
                for (int j = 0; j < Dlls.Length; j++)
                {
                    if (Dlls[j].Name == row[0])
                    {
                        c_dll = Dlls[j];
                        break;
                    }
                }
                if (c_dll != null)
                {
                    int number;
                    bool is_number = int.TryParse(row[1], out number);
                    for (int j = 0; j < c_dll.Plugins.Length; j++)
                    {
                        if (((is_number) && (number == c_dll.Plugins[j].Id)) || ((!is_number) && (row[1] == c_dll.Plugins[j].Name)))
                        {
                            order[loaded++] = c_dll.Plugins[j];
                            break;
                        }
                    }
                }
            }
            if (loaded != order.Length)
            {
                Plugin[] tmp = new Plugin[loaded];
                Array.Copy(order, tmp, loaded);
                order = tmp;
            }
            return order;
        }