コード例 #1
0
        private void ScanSemiGlobals(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            lbfiles.Items.Clear();
            this.btimport.Enabled = false;

            if (cbsemi.SelectedIndex < 0)
            {
                return;
            }
            ArrayList loaded = new ArrayList();

            try
            {
                SimPe.Plugin.NamedGlob glob = (SimPe.Plugin.NamedGlob)cbsemi.Items[cbsemi.SelectedIndex];
                Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFileByGroup(glob.SemiGlobalGroup);

                lbfiles.Sorted = false;
                foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                {
                    if (item.FileDescriptor.Type == Data.MetaData.BHAV_FILE)
                    {
                        SimPe.Plugin.Bhav bhav = new SimPe.Plugin.Bhav(null);
                        bhav.ProcessData(item);
                        item.FileDescriptor.Filename = item.FileDescriptor.TypeName.shortname + ": " + bhav.FileName + " (" + item.FileDescriptor.ToString() + ")";
                    }
                    else if (item.FileDescriptor.Type == Data.MetaData.STRING_FILE)
                    {
                        SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                        str.ProcessData(item);
                        item.FileDescriptor.Filename = item.FileDescriptor.TypeName.shortname + ": " + str.FileName + " (" + item.FileDescriptor.ToString() + ")";
                    }
                    else if (item.FileDescriptor.Type == 0x42434F4E)                      //BCON
                    {
                        SimPe.Plugin.Bcon bcon = new SimPe.Plugin.Bcon();
                        bcon.ProcessData(item);
                        item.FileDescriptor.Filename = item.FileDescriptor.TypeName.shortname + ": " + bcon.FileName + " (" + item.FileDescriptor.ToString() + ")";
                    }
                    else
                    {
                        item.FileDescriptor.Filename = item.FileDescriptor.ToString();
                    }

                    if (!loaded.Contains(item.FileDescriptor))
                    {
                        lbfiles.Items.Add(item, ((item.FileDescriptor.Type == Data.MetaData.BHAV_FILE) || (item.FileDescriptor.Type == 0x42434F4E)));
                        loaded.Add(item.FileDescriptor);
                    }
                }
                lbfiles.Sorted        = true;
                this.btimport.Enabled = (lbfiles.Items.Count > 0);
            }
            catch (Exception) {}

            this.Cursor = Cursors.Default;
        }
コード例 #2
0
        private void ImportFiles(object sender, System.EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            //first find the highest Instance of a BHAV, BCON in the package
            Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.BHAV_FILE);
            uint maxbhavinst = 0x1000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                if ((pfd.Instance < 0x2000) && (pfd.Instance > maxbhavinst))
                {
                    maxbhavinst = pfd.Instance;
                }
            }
            Hashtable bhavalias = new Hashtable();

            maxbhavinst++;

            //her is the BCOn part
            pfds = package.FindFiles(0x42434F4E);
            uint maxbconinst = 0x1000;

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
            {
                if ((pfd.Instance < 0x2000) && (pfd.Instance > maxbconinst))
                {
                    maxbconinst = pfd.Instance;
                }
            }
            Hashtable bconalias = new Hashtable();

            maxbconinst++;


            ArrayList bhavs = new ArrayList();
            ArrayList ttabs = new ArrayList();

            package.BeginUpdate();
            try
            {
                for (int i = 0; i < lbfiles.Items.Count; i++)
                {
                    if (!lbfiles.GetItemChecked(i))
                    {
                        continue;
                    }
                    Interfaces.Scenegraph.IScenegraphFileIndexItem item = (Interfaces.Scenegraph.IScenegraphFileIndexItem)lbfiles.Items[i];
                    SimPe.Packages.PackedFileDescriptor            npfd = new SimPe.Packages.PackedFileDescriptor();
                    npfd.Type     = item.FileDescriptor.Type;
                    npfd.Group    = item.FileDescriptor.Group;
                    npfd.Instance = item.FileDescriptor.Instance;
                    npfd.SubType  = item.FileDescriptor.SubType;
                    npfd.UserData = item.Package.Read(item.FileDescriptor).UncompressedData;
                    package.Add(npfd);

                    if (npfd.Type == Data.MetaData.BHAV_FILE)
                    {
                        maxbhavinst++;
                        npfd.Group = 0xffffffff;
                        bhavalias[(ushort)npfd.Instance] = (ushort)maxbhavinst;
                        npfd.Instance = maxbhavinst;

                        SimPe.Plugin.Bhav bhav = new SimPe.Plugin.Bhav(prov.OpcodeProvider);
                        bhav.ProcessData(npfd, package);
                        if (cbname.Checked)
                        {
                            bhav.FileName = "[" + cbsemi.Text + "] " + bhav.FileName;
                        }
                        bhav.SynchronizeUserData();

                        bhavs.Add(bhav);
                    }
                    else if (npfd.Type == 0x42434F4E)                     //BCON
                    {
                        npfd.Instance = maxbconinst++;
                        npfd.Group    = 0xffffffff;
                        bconalias[(ushort)npfd.Instance] = (ushort)npfd.Instance;

                        SimPe.Plugin.Bcon bcon = new SimPe.Plugin.Bcon();
                        bcon.ProcessData(npfd, package);
                        if (cbname.Checked)
                        {
                            bcon.FileName = "[" + cbsemi.Text + "] " + bcon.FileName;
                        }
                        bcon.SynchronizeUserData();
                    }
                    else if (npfd.Type == 0x54544142)                      //TTAB
                    {
                        SimPe.Plugin.Ttab ttab = new SimPe.Plugin.Ttab(prov.OpcodeProvider);
                        ttab.ProcessData(npfd, package);

                        ttabs.Add(ttab);
                    }
                }

                if (cbfix.Checked)
                {
                    pfds = package.FindFiles(Data.MetaData.BHAV_FILE);
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                    {
                        SimPe.Plugin.Bhav bhav = new SimPe.Plugin.Bhav(prov.OpcodeProvider);
                        bhav.ProcessData(pfd, package);

                        bhavs.Add(bhav);
                    }

                    pfds = package.FindFiles(0x54544142);
                    foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds)
                    {
                        SimPe.Plugin.Ttab ttab = new SimPe.Plugin.Ttab(prov.OpcodeProvider);
                        ttab.ProcessData(pfd, package);

                        ttabs.Add(ttab);
                    }
                }

                //Relink all SemiGlobals in imported BHAV's
                foreach (SimPe.Plugin.Bhav bhav in bhavs)
                {
                    foreach (SimPe.PackedFiles.Wrapper.Instruction i in bhav)
                    {
                        if (bhavalias.Contains(i.OpCode))
                        {
                            i.OpCode = (ushort)bhavalias[i.OpCode];
                        }
                    }
                    bhav.SynchronizeUserData();
                }

                //Relink all TTAbs
                foreach (SimPe.Plugin.Ttab ttab in ttabs)
                {
                    foreach (SimPe.PackedFiles.Wrapper.TtabItem item in ttab)
                    {
                        if (bhavalias.Contains(item.Guardian))
                        {
                            item.Guardian = (ushort)bhavalias[item.Guardian];
                        }
                        if (bhavalias.Contains(item.Action))
                        {
                            item.Action = (ushort)bhavalias[item.Action];
                        }
                    }
                    ttab.SynchronizeUserData();
                }
            }
            finally
            {
                package.EndUpdate();
            }
            this.Cursor = Cursors.Default;
            Close();
        }