Exemplo n.º 1
0
 internal void ClearCalleeSaves()
 {
     EBX.ClearCalleeReg();
     ESI.ClearCalleeReg();
     EDI.ClearCalleeReg();
     EBP.ClearCalleeReg();
 }
Exemplo n.º 2
0
 internal void SetCalleeSaves(SpillContext *context)
 {
     EBX.SetCalleeReg(&context->ebx);
     EDI.SetCalleeReg(&context->edi);
     ESI.SetCalleeReg(&context->esi);
     EBP.SetCalleeReg(&context->ebp);
 }
Exemplo n.º 3
0
 void SetCalleeSaves(CalleeSaveRegistersX86 *calleeSaveRegisters)
 {
     EBX.SetCalleeReg(&calleeSaveRegisters->EBX);
     EDI.SetCalleeReg(&calleeSaveRegisters->EDI);
     ESI.SetCalleeReg(&calleeSaveRegisters->ESI);
     EBP.SetCalleeReg(&calleeSaveRegisters->EBP);
 }
Exemplo n.º 4
0
 public void LoadMesh(byte[] sha1res, byte[] sha1ebx, string path)
 {
     rtb2.Text = "";
     currPath  = path;
     tv3.Nodes.Clear();
     rawResBuffer = main.Host.getDataBySha1(sha1res);
     rawEbxBuffer = main.Host.getDataBySha1(sha1ebx);
     if (rawEbxBuffer == null || rawResBuffer == null)
     {
         return;
     }
     try
     {
         hb1.ByteProvider = new DynamicByteProvider(rawResBuffer);
         hb2.ByteProvider = new DynamicByteProvider(new byte[0]);
         mesh             = new MeshAsset(new MemoryStream(rawResBuffer));
         rtb2.Text        = mesh.ToString();
         toolStripComboBox1.Items.Clear();
         for (int i = 0; i < mesh.lods.Count; i++)
         {
             toolStripComboBox1.Items.Add("LOD " + i);
         }
         if (mesh.lods.Count > 0)
         {
             toolStripComboBox1.SelectedIndex = 0;
         }
         ebxObject = new EBX(new MemoryStream(rawEbxBuffer));
         tv3.Nodes.Add(ebxObject.ToNode());
     }
     catch (Exception ex)
     {
         rtb2.Text = "ERROR!!!:\n" + ex.Message + "\n\n" + rtb2.Text;
     }
 }
Exemplo n.º 5
0
 internal void ClearFrame(UIntPtr calleeSaveMask,
                          bool framePointerOmitted)
 {
     if (!framePointerOmitted)
     {
         VTable.Assert((calleeSaveMask & 0x10) == 0,
                       "EBP should not be callee saved");
         EBP.ClearFrameReg();
     }
     if ((calleeSaveMask & 0x1) != 0)
     {
         EBX.ClearFrameReg();
     }
     if ((calleeSaveMask & 0x8) != 0)
     {
         EBP.ClearFrameReg();
     }
     if ((calleeSaveMask & 0x4) != 0)
     {
         ESI.ClearFrameReg();
     }
     if ((calleeSaveMask & 0x2) != 0)
     {
         EDI.ClearFrameReg();
     }
 }
Exemplo n.º 6
0
 internal void ScanLiveRegs(UIntPtr mask,
                            NonNullReferenceVisitor referenceVisitor)
 {
     EDI.ScanLiveReg((mask >> 2) & 0x3, referenceVisitor);
     ESI.ScanLiveReg((mask >> 4) & 0x3, referenceVisitor);
     EBX.ScanLiveReg((mask >> 0) & 0x3, referenceVisitor);
     EBP.ScanLiveReg((mask >> 6) & 0x3, referenceVisitor);
 }
Exemplo n.º 7
0
        internal void PopFrame(UIntPtr *framePointer,
                               UIntPtr calleeSaveMask,
                               bool framePointerOmitted,
                               bool hasTransitionRecord)
        {
            UIntPtr *calleeSaveStart;

            if (framePointerOmitted)
            {
                calleeSaveStart = framePointer - 1;
            }
            else
            {
                VTable.Assert((calleeSaveMask & 0x100) == 0,
                              "EBP should not be callee saved");
                calleeSaveStart = framePointer;
                EBP.PopFrameReg(ref calleeSaveStart);
            }
            if (hasTransitionRecord)
            {
                calleeSaveStart -=
                    sizeof(CallStack.TransitionRecord) / sizeof(UIntPtr);
            }

            // Note: the order in which these appear is important!
            if ((calleeSaveMask & 0x1) != 0)
            {
                EBX.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x80) != 0)
            {
                EBP.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x4) != 0)
            {
                ESI.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x2) != 0)
            {
                EDI.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x8) != 0)
            {
                R12.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x10) != 0)
            {
                R13.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x20) != 0)
            {
                R14.PopFrameReg(ref calleeSaveStart);
            }
            if ((calleeSaveMask & 0x40) != 0)
            {
                R15.PopFrameReg(ref calleeSaveStart);
            }
        }
Exemplo n.º 8
0
        public MorphStaticExtended(MemoryStream resStream, MemoryStream ebxStream, string name) : base(resStream, name)
        {
            ebx = new EBX(ebxStream);
            var imports = EbxUtils.LoadEbxImport(ebx);

            if (imports.Count == 1)
            {
                PresetMesh = imports[0];
            }
        }
Exemplo n.º 9
0
 internal void ClearCalleeSaves()
 {
     EBX.ClearCalleeReg();
     ESI.ClearCalleeReg();
     EDI.ClearCalleeReg();
     EBP.ClearCalleeReg();
     R12.ClearCalleeReg();
     R13.ClearCalleeReg();
     R14.ClearCalleeReg();
     R15.ClearCalleeReg();
 }
Exemplo n.º 10
0
 void SetCalleeSaves(CalleeSaveRegistersX64 *calleeSaveRegisters)
 {
     EBX.SetCalleeReg(&calleeSaveRegisters->EBX);
     EDI.SetCalleeReg(&calleeSaveRegisters->EDI);
     ESI.SetCalleeReg(&calleeSaveRegisters->ESI);
     EBP.SetCalleeReg(&calleeSaveRegisters->EBP);
     R12.SetCalleeReg(&calleeSaveRegisters->R12);
     R13.SetCalleeReg(&calleeSaveRegisters->R13);
     R14.SetCalleeReg(&calleeSaveRegisters->R14);
     R15.SetCalleeReg(&calleeSaveRegisters->R15);
 }
Exemplo n.º 11
0
 internal void SetCalleeSaves(SpillContext *context)
 {
     EBX.SetCalleeReg(&context->bx);
     EDI.SetCalleeReg(&context->di);
     ESI.SetCalleeReg(&context->si);
     EBP.SetCalleeReg(&context->bp);
     R12.SetCalleeReg(&context->r12);
     R13.SetCalleeReg(&context->r13);
     R14.SetCalleeReg(&context->r14);
     R15.SetCalleeReg(&context->r15);
 }
Exemplo n.º 12
0
 public void LoadEBX(byte[] sha1, string path)
 {
     currPath = path;
     currSha1 = sha1;
     byte[] buff = main.Host.getDataBySha1(sha1);
     if (buff == null)
     {
         return;
     }
     if (guidCache != null)
     {
         ebxObj = new EBX(new MemoryStream(buff), guidCache);
     }
     else
     {
         ebxObj = new EBX(new MemoryStream(buff));
     }
     DisplayEBX();
 }
Exemplo n.º 13
0
        public static List <string> LoadEbxImport(EBX ebx)
        {
            var ImportValues = new List <string>();

            if (ebxGuid != null)
            {
                foreach (EBX.FBGuid guid in ebx.imports.Keys)
                {
                    string key = guid.ToString().Replace("-", "");
                    if (ebxGuid.ContainsKey(key))
                    {
                        ImportValues.Add(ebxGuid[key]);
                    }
                    else
                    {
                        ImportValues.Add("Not found!");
                    }
                }
            }
            return(ImportValues);
        }
Exemplo n.º 14
0
        private void toolStripButton5_Click(object sender, EventArgs e)
        {
            int n = toolStripComboBox1.SelectedIndex;

            string selectedSkeleton = null;

            if (toolStripComboBox2.Enabled && toolStripComboBox2.SelectedIndex > 1)
            {
                selectedSkeleton = (string)toolStripComboBox2.SelectedItem;
            }

            ExportMeshSaveDialog emsd = new ExportMeshSaveDialog(mesh.lods.Count, 100f, false,
                                                                 (mesh.header.type == MeshType.MeshType_Skinned), selectedSkeleton, n);

            if (emsd.ShowDialog() == DialogResult.OK)
            {
                // we try to load the skeleton only if none was already selected for preview
                // or if one was selected and it is different from the one selected in the option window
                if (!skeletons.ContainsKey(toolStripComboBox2.SelectedItem.ToString()) ||
                    (skeletons.ContainsKey(toolStripComboBox2.SelectedItem.ToString()) &&
                     skeletons[toolStripComboBox2.SelectedItem.ToString()] != emsd.Skeleton))
                {
                    string sha1 = emsd.Skeleton;
                    if (sha1 != null)
                    {
                        var sebx = new EBX(new MemoryStream(main.Host.getDataBySha1(Helpers.HexStringToByteArray(sha1))));
                        skeleton = new SkeletonAsset(sebx);
                    }
                }
                // scale
                float aScale = emsd.ExportScale;
                // get exporter by format
                var exporter = MeshExporter.GetExporterByExtension(emsd.Format, skeleton);
                if (exporter != null)
                {
                    if (emsd.AllLod)
                    {
                        FolderBrowserDialog fbd = new FolderBrowserDialog();
                        fbd.Description = "Select folder where to save the lods";

                        if (fbd.ShowDialog() == DialogResult.OK)
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            for (int i = 0; i < mesh.lods.Count; i++)
                            {
                                PrepareLodForExport(mesh, i);
                            }
                            exporter.ExportAllLods(mesh, fbd.SelectedPath, aScale);
                            MessageBox.Show("Done.");
                            Cursor.Current = Cursors.Default;
                        }
                    }
                    else
                    {
                        // lod
                        int sLod = emsd.Lod;

                        SaveFileDialog saveFileDiag = new SaveFileDialog();
                        saveFileDiag.Title    = "Save as...";
                        saveFileDiag.Filter   = "*" + emsd.Format + "|*" + emsd.Format;
                        saveFileDiag.FileName = mesh.lods[n].shortName;
                        if (saveFileDiag.ShowDialog() == DialogResult.OK)
                        {
                            Cursor.Current = Cursors.WaitCursor;
                            string targetFile = saveFileDiag.FileName;
                            PrepareLodForExport(mesh, sLod);
                            exporter.ExportLod(mesh, sLod, targetFile, aScale);
                            MessageBox.Show("Done.");
                            Cursor.Current = Cursors.Default;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Unknown extension " + emsd.Format);
                }
            }
        }
Exemplo n.º 15
0
        private void button1_Click(object sender, EventArgs e)
        {
            TreeNode t = tv3.SelectedNode;

            if (field == null || t == null)
            {
                return;
            }
            List <int> ind = new List <int>();

            ind.Add(t.Index);
            while (t.Parent.Parent != null)
            {
                t = t.Parent;
                ind.Insert(0, t.Index);
            }
            try
            {
                byte   typ = field.layout.GetFieldType();
                byte[] buff;
                switch (typ)
                {
                case 0xA:
                case 0xB:
                case 0xC:
                    byte b = Convert.ToByte(textBox1.Text, 16);
                    ebxObj.rawBuffer[field.offset] = b;
                    break;

                case 0xD:
                case 0xE:
                    ushort us = Convert.ToUInt16(textBox1.Text, 16);
                    buff = BitConverter.GetBytes(us);
                    for (int i = 0; i < 2; i++)
                    {
                        ebxObj.rawBuffer[field.offset + i] = buff[i];
                    }
                    break;

                case 3:
                case 0xF:
                case 0x10:
                    uint ui = Convert.ToUInt32(textBox1.Text, 16);
                    buff = BitConverter.GetBytes(ui);
                    for (int i = 0; i < 4; i++)
                    {
                        ebxObj.rawBuffer[field.offset + i] = buff[i];
                    }
                    break;

                case 0x13:
                    float f = Convert.ToSingle(textBox1.Text);
                    buff = BitConverter.GetBytes(f);
                    for (int i = 0; i < 4; i++)
                    {
                        ebxObj.rawBuffer[field.offset + i] = buff[i];
                    }
                    break;

                case 0x11:
                case 0x12:
                case 0x14:
                    ulong ul = Convert.ToUInt64(textBox1.Text, 16);
                    buff = BitConverter.GetBytes(ul);
                    for (int i = 0; i < 8; i++)
                    {
                        ebxObj.rawBuffer[field.offset + i] = buff[i];
                    }
                    break;
                }
                ebxObj = new EBX(new MemoryStream(ebxObj.rawBuffer));
                DisplayEBX();
                t = tv3.Nodes[0];
                foreach (int i in ind)
                {
                    t = t.Nodes[i];
                }
                tv3.SelectedNode = t;
                GC.Collect();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in input: " + ex.Message);
            }
        }
Exemplo n.º 16
0
        // export selected morph :
        // search for base mesh and applies selected morph deformation to it and to selected skeleton and exports the result.
        private void exportMorphToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (rawEbxBuffer != null && rawResBuffer != null)
            {
                string morphName = Path.GetFileName(currPath);
                var    morph     = new MorphStaticExtended(new MemoryStream(rawResBuffer), new MemoryStream(rawEbxBuffer), morphName);

                ExportMeshSaveDialog emd = new ExportMeshSaveDialog(morph.LodCount, 100f, true);
                if (emd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    // look for preset Mesh
                    DataInfo presetMeshRes = SearchItemRES(morph.PresetMesh);
                    if (presetMeshRes != null)
                    {
                        byte[]    meshData        = main.Host.getDataBySha1(presetMeshRes.sha1);
                        MeshAsset presetMeshAsset = new MeshAsset(new MemoryStream(meshData));

                        SkeletonAsset skeleton = null;
                        int           lod      = emd.Lod;
                        string        sha1     = emd.Skeleton;
                        if (sha1 != null)
                        {
                            var sebx = new EBX(new MemoryStream(main.Host.getDataBySha1(Helpers.HexStringToByteArray(sha1))));
                            skeleton = new SkeletonAsset(sebx);
                        }

                        float oScale          = emd.ExportScale;
                        bool  bakeMorphToMesh = emd.BakeMorph;

                        string        ext      = emd.Format;
                        IMeshExporter exporter = MeshExporter.GetExporterByExtension(ext, skeleton);
                        Cursor.Current = Cursors.Default;
                        if (emd.AllLod)
                        {
                            FolderBrowserDialog fbd = new FolderBrowserDialog();
                            fbd.Description = "Select folder where to save all LODS...";

                            if (fbd.ShowDialog() == DialogResult.OK)
                            {
                                Cursor.Current = Cursors.WaitCursor;
                                for (int i = 0; i < morph.LodCount; i++)
                                {
                                    ChunkInfo lodChunk = SearchChunk(Helpers.ByteArrayToHexString(presetMeshAsset.lods[i].chunkID));
                                    if (lodChunk != null)
                                    {
                                        byte[] rawChunkBuffer = main.Host.getDataBySha1(lodChunk.sha1);
                                        presetMeshAsset.lods[i].LoadVertexData(new MemoryStream(rawChunkBuffer));
                                    }
                                }
                                exporter.ExportAllLodsWithMorph(presetMeshAsset, morph, fbd.SelectedPath, oScale, bakeMorphToMesh);
                                MessageBox.Show("Done.");
                                Cursor.Current = Cursors.Default;
                            }
                        }
                        else
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Title    = "Save Morph as...";
                            sfd.Filter   = "*" + ext + "|*" + ext;
                            sfd.FileName = Path.GetFileName(currPath) + ext;

                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                Cursor.Current = Cursors.WaitCursor;
                                ChunkInfo lodChunk = SearchChunk(Helpers.ByteArrayToHexString(presetMeshAsset.lods[lod].chunkID));
                                if (lodChunk != null)
                                {
                                    byte[] rawChunkBuffer = main.Host.getDataBySha1(lodChunk.sha1);
                                    presetMeshAsset.lods[lod].LoadVertexData(new MemoryStream(rawChunkBuffer));
                                    exporter.ExportLodWithMorph(presetMeshAsset, lod, morph, sfd.FileName, oScale, bakeMorphToMesh);
                                    MessageBox.Show("Done.");
                                    Cursor.Current = Cursors.Default;
                                }
                                else
                                {
                                    MessageBox.Show("Error : chunk for this lod was not found");
                                }
                            }
                        }
                        Cursor.Current = Cursors.Default;
                    }
                    else
                    {
                        MessageBox.Show("Error : Res data corresponding to preset mesh " + morph.PresetMesh + " not found.");
                    }
                }
            }
        }