Example #1
0
        public static string ExportDir(DirRec rec)
        {
            if (!Iso9660.ReadFile(rec))
            {
                return(null);
            }

            byte[] data = new byte[rec.LenRecord];
            if (!RamDisk.Get(rec.GetPos(), rec.LenRecord, data))
            {
                return(null);
            }

            string[] parts = rec.GetUrl().Split(new char[] { ':' });
            string   dir   = AppDomain.CurrentDomain.BaseDirectory + "tmp/";
            string   path  = (dir + parts[1]).Replace('/', '\\');

            try {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
                FileStream file = File.Create(path);
                file.Write(data, 0, rec.LenRecord);
                file.Close();
                return(path);
            } catch (Exception e) {
                Logger.Fail("Cannot create file " + path + " " + e.Message);
                return(null);
            }
        }
Example #2
0
        public bool Load()
        {
            items.Clear();
            Iso9660.ReadFile(Model.GetRec("ITEMNAME.BIN"));
            Iso9660.ReadFile(Model.GetRec("ITEMHELP.BIN"));
            DirRec rec = Model.GetRec("ITEMNAME.BIN");

            for (int i = 0; i < 512; i++)
            {
                string   key = "DB:Items/Item_" + i;
                MiscItem obj = new MiscItem(key, 0, i, rec);
                items.Add(obj);
                Model.Add(key, obj);
                Publisher.Register(obj);
            }
            return(true);
        }
Example #3
0
        public bool OpenZone(TreeView treeview)
        {
            DirRec rec = GetRec();

            Iso9660.ReadFile(rec);
            int pos = znd.GetPos();

            treeview.Nodes.Clear();
            TreeNode root     = new TreeNode(rec.GetFileName(), 0, 0);
            TreeNode tv_rooms = root.Nodes.Add("Zone/Rooms", "Rooms", 1, 1);
            TreeNode tv_actor = root.Nodes.Add("Zone/Actors", "Actors", 2, 2);
            TreeNode tv_image = root.Nodes.Add("Zone/Images", "Images", 3, 3);

            tv_rooms.ToolTipText = "List of rooms";
            tv_actor.ToolTipText = "List of actors";
            tv_image.ToolTipText = "Texture pack";
            treeview.Nodes.Add(root);
            root.ToolTipText = "Zone";

            string errors = "";
            string file   = GetRec().GetFileName();
            int    min    = 0x20;
            int    max    = GetRec().LenData;

            if (min > max)
            {
                errors += "file is smaller than ZND header\n";
            }

            int ptr_mpd = RamDisk.GetS32(pos + 0x00);
            int len_mpd = RamDisk.GetS32(pos + 0x04);
            int end_mpd = ptr_mpd + Math.Max(0, len_mpd);

            int ptr_zud = RamDisk.GetS32(pos + 0x08);
            int len_zud = RamDisk.GetS32(pos + 0x0C);
            int end_zud = ptr_zud + Math.Max(0, len_zud);

            int ptr_tim = RamDisk.GetS32(pos + 0x10);
            int len_tim = RamDisk.GetS32(pos + 0x14);
            int end_tim = ptr_tim + Math.Max(0, len_tim);

            if (len_mpd != 0)
            {
                if ((ptr_mpd < min) || (end_mpd > max))
                {
                    errors += "MPD section is out of bounds "
                              + ptr_mpd.ToString("X8") + "..."
                              + len_mpd.ToString("X8") + "\n";
                }
                min = end_mpd;
            }

            if (len_zud != 0)
            {
                if ((ptr_zud < min) || (end_zud > max))
                {
                    errors += "ZUD section is out of bounds "
                              + ptr_zud.ToString("X8") + "..."
                              + len_zud.ToString("X8") + "\n";
                }
                min = end_zud;
            }

            if (len_tim != 0)
            {
                if ((ptr_tim < min) || (end_tim > max))
                {
                    errors += "TIM section is out of bounds "
                              + ptr_tim.ToString("X8") + "..."
                              + len_tim.ToString("X8") + "\n";
                }
                min = end_tim;
            }

            if (end_mpd > ptr_zud)
            {
                errors += "MPD and ZUD sections overlap\n";
            }
            if (end_zud > ptr_tim)
            {
                errors += "ZUD and TIM sections overlap\n";
            }
            if (errors != "")
            {
                return(Logger.Warn(file + " is corrupt\n" + errors));
            }

            if (len_zud != 0)
            {
                int num_zud = RamDisk.GetS32(pos + ptr_zud);
                for (int i = 0; i < num_zud; i++)
                {
                    int ptr = ptr_zud + 4 + 8 * num_zud + 0x464 * i;
                    int lba = RamDisk.GetS32(pos + ptr_zud + 4 + 8 * i);
                    AddActor(tv_actor, i, ptr, lba);
                }
            }

            if (len_tim != 0)
            {
                int num_tim = RamDisk.GetS32(pos + ptr_tim + 0x10);
                int ptrx    = ptr_tim + 0x14;
                for (int i = 0; i < num_tim; i++)
                {
                    int len = RamDisk.GetS32(pos + ptrx);
                    try {
                        string  key = GetUrl() + "/Images/Image_" + i;
                        Texture obj = new Texture(key, ptrx + 4, len, i, GetRec());
                        images.Add(obj as Texture);
                        Model.Add(key, obj);
                        Publisher.Register(obj);
                    } catch {}
                    ptrx += len + 4;
                }

                foreach (Texture img in images)
                {
                    int    index = images.IndexOf(img);
                    string text  = "Image_" + index.ToString("D2");
                    int    icon  = (img.IsLookUpTable()) ? 4 : 3;
                    tv_image.Nodes.Add(img.GetUrl(), text, icon, icon);
                }
            }

            if (len_mpd != 0)
            {
                int num_mpd = len_mpd / 8;
                for (int i = 0; i < num_mpd; i++)
                {
                    AddRoom(tv_rooms, i, pos + ptr_mpd);
                }
            }

            root.Expand();
            tv_rooms.Expand();
            tv_actor.Expand();
            tv_image.Expand();
            root.EnsureVisible();
            return(true);
        }