Ejemplo n.º 1
0
        public static bool ResizeRecord(DirRec rec, int len)
        {
            // first check if there is enough space
            int lba = rec.LbaData;
            int num = (rec.LenData + 2047) / 2048;

            for (int i = num; i < len; i++)
            {
                if (RamDisk.map[lba + i] != 0)
                {
                    return(Logger.Fail("Cannot resize " + rec.GetFileName() + " not enough space"));
                }
            }
            // claim new sectors
            for (int i = num; i < len; i++)
            {
                RamDisk.map[lba + i] = 0x6F;
            }
            // free old sectors
            for (int i = len; i < num; i++)
            {
                RamDisk.map[lba + i] = 0x00;
            }
            rec.LenData = len;
            return(true);
        }
Ejemplo n.º 2
0
        public override string GetExportName()
        {
            DirRec rec  = GetRec();
            string name = rec.GetFileName();

            string[] parts = name.Split(new char[] { '.' });
            return(parts[0] + "-IMAGE-" + id.ToString("D2"));
        }
Ejemplo n.º 3
0
 public Room(string url, int pos, DirRec rec,
             Zone zone, int zoneid, int roomid) :
     base(url, pos, rec)
 {
     mpd       = Model.mpds[rec.GetUrl()];
     this.zone = zone;
     ZoneId    = zoneid;
     RoomId    = roomid;
     Name      = rec.GetFileName();
 }
Ejemplo n.º 4
0
        public Zone(string url, int pos, DirRec rec) :
            base(url, pos, rec)
        {
            znd = Model.znds[rec.GetUrl()];

            string file = rec.GetFileName();
            string text = file.Substring(4, file.IndexOf('.') - 4);

            zoneid = int.Parse(text);
        }
Ejemplo n.º 5
0
 public void OpenDisk()
 {
     treeview.Nodes.Clear();
     combobox.Items.Clear();
     combobox.Text = "";
     foreach (Zone zone in Model.zones.Values)
     {
         string key = zone.GetUrl();
         DirRec rec = zone.GetRec();
         string txt = rec.GetFileName();
         zones.Add(txt, key);
         combobox.Items.Add(txt);
     }
     sub_property.Notify(null);
 }
Ejemplo n.º 6
0
        public bool Visit(string url, DirRec dir)
        {
            string   name = dir.GetFileName();
            TreeNode leaf = node.Nodes.Add(url, name);

            if (dir.FileFlags_Directory)
            {
                leaf.ImageIndex         = SysIcons.GetDirIconIndex(false);
                leaf.SelectedImageIndex = SysIcons.GetDirIconIndex(true);
                Iso9660.EnumDir(url, dir, new EnumDiskView(leaf));
            }
            else
            {
                int icon = SysIcons.GetFileIconIndex(name);
                leaf.ImageIndex = leaf.SelectedImageIndex = icon;
            }
            return(true);
        }
Ejemplo n.º 7
0
        public bool AddRoom(TreeNode root, int id, int pos)
        {
            int lba = RamDisk.GetS32(pos + 8 * id);

            try {
                string url = GetUrl() + "/Room/" + id;
                DirRec mpd = Iso9660.GetByLba(lba);
                Room   obj = new Room(mpd.GetUrl(), 0, mpd, this, zoneid, id);
                rooms.Add(obj);
                Model.Add(url, obj);
                Publisher.Register(obj);

                TreeNode node = root.Nodes.Add(url, mpd.GetFileName(), 1, 1);
                obj.AddRoom(node, url, id, pos);
                return(true);
            } catch {
                return(false);
            }
        }
Ejemplo n.º 8
0
        public static bool MoveRecord(DirRec rec, int lba)
        {
            // first check if there is enough space
            int old = rec.LbaData;
            int len = (rec.LenData + 2047) / 2048;

            for (int i = 0; i < len; i++)
            {
                // self intersection is not a problem
                if ((lba + i >= old) && (lba + i < old + len))
                {
                    continue;
                }
                // check for collisions
                if (RamDisk.map[lba + i] != 0)
                {
                    return(Logger.Fail("Cannot move " + rec.GetFileName() + " not enough space"));
                }
            }
            // swap the sectors
            for (int i = 0; i < len; i++)
            {
                int src = old + i;
                int des = lba + i;
                if (!RamDisk.Swap(src, des))
                {
                    return(false);
                }
            }
            rec.LbaData = lba;
            for (int i = 0; i < len; i++)
            {
                RamDisk.map[lba + i] = 0x78;
                RamDisk.map[old + i] = 0x00;
            }
            return(true);
        }
Ejemplo n.º 9
0
        public bool Visit(string url, DirRec dir)
        {
            string name = dir.GetFileName();
            string ext  = dir.GetFileExt();

            if (extensions.Contains(ext))
            {
                //Iso9660.ReadFile(dir);
                int lba = dir.LbaData;
                int len = dir.LenData;
                int pos = lba * 2048;
                switch (ext)
                {
                case ".BIN": Model.bins.Add(url, new BIN(url, pos)); break;

                case ".DAT": Model.dats.Add(url, new DAT(url, pos)); break;

                case ".PRG": Model.prgs.Add(url, new PRG(url, pos)); break;

                case ".SYD": Model.syds.Add(url, new SYD(url, pos)); break;

                case ".ARM": Model.arms.Add(url, new ARM(url, pos)); break;

                case ".ZND": Model.znds.Add(url, new ZND(url, pos)); break;

                case ".MPD": Model.mpds.Add(url, new MPD(url, pos)); break;

                case ".ZUD": Model.zuds.Add(url, new ZUD(url, pos)); break;

                case ".SHP": Model.shps.Add(url, new SHP(url, pos)); break;

                case ".WEP": Model.weps.Add(url, new WEP(url, pos)); break;

                case ".SEQ": Model.seqs.Add(url, new SEQ(url, pos)); break;
                }

                switch (ext)
                {
                case ".BIN":
                case ".DAT":
                case ".PRG":
                case ".SYD":
                case ".ARM":
                case ".ZND":
                case ".MPD":
                case ".ZUD":
                case ".SEQ":
                case ".SHP":
                case ".WEP":
                    Model.SetPos(name, pos);
                    Model.SetLen(name, len);
                    Model.SetRec(name, dir);
                    if (name == "ITEMNAME.BIN")
                    {
                        Model.SetPos("ITEMNAME.BIN", dir.LbaData * 2048);
                        Model.SetLen("ITEMNAME.BIN", dir.LenData);
                        Model.SetRec("ITEMNAME.BIN", dir);
                    }
                    if (name == "ITEMHELP.BIN")
                    {
                        Model.SetPos("ITEMHELP.BIN", dir.LbaData * 2048);
                        Model.SetLen("ITEMHELP.BIN", dir.LenData);
                        Model.SetRec("ITEMHELP.BIN", dir);
                    }
                    if (name == "00.SHP")
                    {
                        Model.lba_00_shp = lba;
                    }
                    if (name == "01.WEP")
                    {
                        Model.lba_01_wep = lba;
                    }
                    break;
                }

                if (ext == ".ZND")
                {
                    string[] parts = url.Split(new char[] { ':' });
                    if (parts.Length > 1)
                    {
                        string key  = "APP:" + parts[1];
                        Zone   zone = new Zone(key, 0, dir);
                        Model.zones.Add(key, zone);
                        Model.Add(key, zone);
                        Publisher.Register(zone);
                    }
                }
            }
            else if (name.Contains("SLUS"))
            {
                int pos = dir.LbaData * 2048;
                int len = dir.LenData;
                Model.SetPos("SLUS", pos);
                Model.SetLen("SLUS", len);
                Model.SetRec("SLUS", dir);
                PRG prg = new PRG(url, pos);
                Model.prgs.Add(url, prg);
                Publisher.Register(prg);
            }
            else if (dir.FileFlags_Directory)
            {
                return(Iso9660.EnumDir(url, dir, this));
            }
            return(true);
        }
Ejemplo n.º 10
0
        public bool AddActor(TreeNode root, int id, int pos, int lba)
        {
            try {
                // ************************************************************
                // Add the actor
                string url      = GetUrl() + "/Actors/Actor_" + id;
                string znd_file = GetRec().GetFileName();
                DirRec zud      = Iso9660.GetByLba(lba);
                Actor  obj      = new Actor(url, pos, GetRec(), this, zoneid, id, zud);
                actors.Add(obj);
                Model.Add(url, obj);
                Publisher.Register(obj);
                TreeNode node = root.Nodes.Add(url, obj.Name, 2, 2);

                // ************************************************************
                // Add the ZUD file
                TreeNode tv_model = node.Nodes.Add(url + "/Model", zud.GetFileName(), 28, 28);
                tv_model.Nodes.Add(url + "/Model/SHP", "SHP", 28, 28);
                tv_model.Nodes.Add(url + "/Model/WEP", "WEP", 28, 28);
                tv_model.Nodes.Add(url + "/Model/SEQ", "SEQ Common", 29, 29);
                tv_model.Nodes.Add(url + "/Model/SEQ", "SEQ Battle", 29, 29);

                // ************************************************************
                // Add bodyparts
                for (int j = 0; j < 6; j++)
                {
                    string[] part_name = new string[] {
                        "L.ARM", "R.ARM", "HEAD", "BODY", "LEGS", "OTHER",
                    };

                    int           ptr_part = pos + 0x238 + j * 0x5C;
                    string        k1       = url + "/BodyParts/" + part_name[j];
                    ActorBodyPart part     = new ActorBodyPart(k1, ptr_part, GetRec());
                    bodyparts.Add(part);
                    Model.Add(k1, part);
                    Publisher.Register(part);
                }
                TreeNode tv_body = node.Nodes.Add(url + "/BodyParts", "BodyParts", 5, 5);
                tv_body.Nodes.Add(url + "/BodyParts/L.ARM", "L.ARM", 8, 8);
                tv_body.Nodes.Add(url + "/BodyParts/R.ARM", "R.ARM", 8, 8);
                tv_body.Nodes.Add(url + "/BodyParts/HEAD", "HEAD", 6, 6);
                tv_body.Nodes.Add(url + "/BodyParts/BODY", "BODY", 7, 7);
                tv_body.Nodes.Add(url + "/BodyParts/LEGS", "LEGS", 9, 9);
                tv_body.Nodes.Add(url + "/BodyParts/OTHER", "OTHER", 5, 5);

                // ************************************************************
                // Add armours
                for (int j = 0; j < 6; j++)
                {
                    string[] part_name = new string[] {
                        "L.ARM", "R.ARM", "HEAD", "BODY", "LEGS", "OTHER",
                    };

                    int         ptr_part = pos + 0x238 + j * 0x5C + 0x20;
                    string      k2       = url + "/Equip/" + part_name[j];
                    ActorArmour armour   = new ActorArmour(k2, ptr_part, GetRec());
                    armours.Add(armour);
                    Model.Add(k2, armour);
                    Publisher.Register(armour);
                }
                TreeNode tv_equip = node.Nodes.Add(url + "/Equip", "Equipment", 39, 39);
                tv_equip.Nodes.Add(url + "/Equip/L.ARM", "L.ARM", 8, 8);
                tv_equip.Nodes.Add(url + "/Equip/R.ARM", "R.ARM", 8, 8);
                tv_equip.Nodes.Add(url + "/Equip/HEAD", "HEAD", 6, 6);
                tv_equip.Nodes.Add(url + "/Equip/BODY", "BODY", 7, 7);
                tv_equip.Nodes.Add(url + "/Equip/LEGS", "LEGS", 9, 9);
                tv_equip.Nodes.Add(url + "/Equip/OTHER", "OTHER", 5, 5);

                // ************************************************************
                // Add weapon
                ActorWeapon weapon = new ActorWeapon(url + "/Weapon", pos + 0x34, GetRec());
                weapons.Add(weapon);
                Model.Add(url + "/Weapon", weapon);
                Publisher.Register(weapon);

                ActorBlade blade = new ActorBlade(url + "/Weapon/Blade", pos + 0x34, GetRec());
                blades.Add(blade);
                Model.Add(url + "/Weapon/Blade", blade);
                Publisher.Register(blade);

                ActorGrip grip = new ActorGrip(url + "/Weapon/Grip", pos + 0x64, GetRec());
                grips.Add(grip);
                Model.Add(url + "/Weapon/Grip", grip);
                Publisher.Register(grip);
                for (int j = 0; j < 3; j++)
                {
                    int      ptr_gem = pos + 0x94 + j * 0x30;
                    string   key     = url + "/Weapon/Gem" + (j + 1);
                    ActorGem gem     = new ActorGem(key, ptr_gem, GetRec());
                    weapon_gems.Add(gem);
                    Model.Add(key, gem);
                    Publisher.Register(gem);
                }

                TreeNode tv_weapon = node.Nodes.Add(url + "/Weapon", "Weapon", 12, 12);
                tv_weapon.Nodes.Add(url + "/Weapon/Blade", "Blade", 13, 13);
                tv_weapon.Nodes.Add(url + "/Weapon/Grip", "Grip", 14, 14);
                tv_weapon.Nodes.Add(url + "/Weapon/Gem1", "Gem1", 24, 24);
                tv_weapon.Nodes.Add(url + "/Weapon/Gem2", "Gem2", 25, 25);
                tv_weapon.Nodes.Add(url + "/Weapon/Gem3", "Gem3", 26, 26);

                // ************************************************************
                // Add shield
                ActorShield shield = new ActorShield(url + "/Shield", pos + 0x140, GetRec());
                shields.Add(shield);
                Model.Add(url + "/Shield", shield);
                Publisher.Register(shield);
                for (int j = 0; j < 3; j++)
                {
                    int      ptr_gem = pos + 0x170 + j * 0x30;
                    string   key     = url + "/Shield/Gem" + (j + 1);
                    ActorGem gem     = new ActorGem(key, ptr_gem, GetRec());
                    shield_gems.Add(gem);
                    Model.Add(key, gem);
                    Publisher.Register(gem);
                }

                TreeNode tv_shield = node.Nodes.Add(url + "/Shield", "Shield", 11, 11);
                tv_shield.Nodes.Add(url + "/Shield/Gem1", "Gem1", 24, 24);
                tv_shield.Nodes.Add(url + "/Shield/Gem2", "Gem2", 25, 25);
                tv_shield.Nodes.Add(url + "/Shield/Gem3", "Gem3", 26, 26);

                // ************************************************************
                // Add accessory
                TreeNode       tv_accessory = node.Nodes.Add(url + "/Accessory", "Accessory", 10, 10);
                ActorAccessory accessory    = new ActorAccessory(url + "/Accessory", pos + 0x204, GetRec());
                accessories.Add(accessory);
                Model.Add(url + "/Accessory", accessory);
                Publisher.Register(accessory);
                return(true);
            } catch {
                return(false);
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        public static bool EnumDir(string url, DirRec dir, IEnumDir iterator)
        {
            int pos = dir.LbaData * 2048;
            int end = pos + dir.LenData;

            pos += RamDisk.GetU8(pos); // skip current directory
            pos += RamDisk.GetU8(pos); // skip parent directory
            while (pos < end)
            {
                byte len = RamDisk.GetU8(pos);
                if (len == 0)
                {
                    pos = ((pos / 2048) + 1) * 2048;
                }
                else
                {
                    string key = url + "/" + GetRecordFileName(pos);
                    DirRec rec = null;
                    if (Records.ContainsKey(key))
                    {
                        rec = Records[key];
                    }
                    else
                    {
                        rec = new DirRec(key, pos);
                        Model.SetPos(key, pos);
                        Model.SetLen(key, rec.LenData);
                        Model.SetRec(key, rec);
                        string name = rec.GetFileName();
                        int    lba  = rec.LbaData;
                        int    num  = (rec.LenData + 2047) / 2048;
                        if (rec.FileFlags_Directory)
                        {
                            for (int i = 0; i < num; i++)
                            {
                                RamDisk.Read(lba + i);
                            }
                        }
                        else
                        {
                            for (int i = 0; i < num; i++)
                            {
                                if (RamDisk.map[lba + i] == 0)
                                {
                                    RamDisk.map[lba + i] = 0x6F;
                                }
                            }
                        }
                        try {
                            Records.Add(key, rec);
                            Path2Pos.Add(key, rec.GetPos());
                            Lba2Path.Add(lba, key);
                            Publisher.Register(key, rec);
                        } catch (Exception e) {
                            Logger.Warn("Cannot register " + name + " " + e.Message);
                        }
                    }
                    if (rec.FileFlags_Directory)
                    {
                        int lba = rec.LbaData;
                        int num = (rec.LenData + 2047) / 2048;
                        for (int i = 0; i < num; i++)
                        {
                            RamDisk.Read(lba + i);
                        }

                        if (iterator != null)
                        {
                            iterator.Visit(key, rec);
                        }
                    }
                    pos += len;
                }
            }

            pos  = dir.LbaData * 2048;
            pos += RamDisk.GetU8(pos); // skip current directory
            pos += RamDisk.GetU8(pos); // skip parent directory
            while (pos < end)
            {
                byte len = RamDisk.GetU8(pos);
                if (len == 0)
                {
                    pos = ((pos / 2048) + 1) * 2048;
                }
                else
                {
                    string key = url + "/" + GetRecordFileName(pos);
                    DirRec rec = Records[key];
                    if (!rec.FileFlags_Directory)
                    {
                        if (iterator != null)
                        {
                            iterator.Visit(key, rec);
                        }
                    }
                    pos += len;
                }
            }
            return(true);
        }