Esempio n. 1
0
    public void LoadXfbinWindow()
    {
        // CLEAR OLD LIST IF THERE IS ONE
        for (int x = 0; x < GameObject.Find("Mesh List Content").transform.childCount; x++)
        {
            Destroy(GameObject.Find("Mesh List Content").transform.GetChild(0).gameObject);
        }
        indexOfMeshes    = new List <int>();
        fileBytes        = new List <byte>();
        SizeHeader       = 48;
        SelectedIndex    = 0;
        OverallMeshCount = 0;

        // NOW OPEN FILE
        VistaOpenFileDialog openFileDialog1 = new VistaOpenFileDialog
        {
            DefaultExt   = "xfbin",
            AddExtension = true
        };

        openFileDialog1.ShowDialog();

        string pathToXfbin = openFileDialog1.FileName;

        if (pathToXfbin != "" && File.Exists(pathToXfbin))
        {
            byte[] file = File.ReadAllBytes(pathToXfbin);

            for (int a = 0; a < file.Length; a++)
            {
                fileBytes.Add(file[a]);
            }

            foreach (Transform child_ in GameObject.Find("Mesh List Content").transform)
            {
                Destroy(child_.gameObject);
            }
            GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);
            indexOfMeshes.Clear();

            if (fileBytes[0] == 78 && fileBytes[1] == 85 && fileBytes[2] == 67 && fileBytes[3] == 67)
            {
                int MeshCount = 0;
                for (int x = 0; x < fileBytes.Count - 3; x++)
                {
                    if (fileBytes[x] == 78 && fileBytes[x + 1] == 68 && fileBytes[x + 2] == 80 && fileBytes[x + 3] == 51)
                    {
                        indexOfMeshes.Add(x);
                        List <char> meshName = new List <char>();
                        int         meshSize = 48 +
                                               (fileBytes[x + 17] * 0x10000 + fileBytes[x + 18] * 0x100 + fileBytes[x + 19]) +
                                               (fileBytes[x + 21] * 0x10000 + fileBytes[x + 22] * 0x100 + fileBytes[x + 23]) +
                                               (fileBytes[x + 25] * 0x10000 + fileBytes[x + 26] * 0x100 + fileBytes[x + 27]) +
                                               (fileBytes[x + 29] * 0x10000 + fileBytes[x + 30] * 0x100 + fileBytes[x + 31]);

                        for (int abc = 0; abc < 25; abc++)
                        {
                            meshName.Add((char)fileBytes[x + meshSize + abc]);
                        }

                        string MeshType = "";

                        int VertexLength_ =
                            (fileBytes[x + 0x18] * 0x1000000 + fileBytes[x + 0x19] * 0x10000 + fileBytes[x + 0x1A] * 0x100 + fileBytes[x + 0x1B])
                            /
                            (fileBytes[x + 0x6A] * 0x1000000 + fileBytes[x + 0x6B] * 0x10000 + fileBytes[x + 0x6C] * 0x100 + fileBytes[x + 0x6D]);

                        if (VertexLength_ != 0x20)
                        {
                            switch (fileBytes[x + 0x6E])
                            {
                            case 0x06:     // Storm teeth/eyes
                                           // NormalsHalfFloat
                                VertexLength_ = 0x1C;
                                break;

                            case 0x07:     // JoJo teeth
                                           // NormalsTanBiTanHalfFloat
                                VertexLength_ = 0x2C;
                                break;

                            case 0x11:     // Storm most meshes + JoJo eyes
                                           // NormalsFloat
                                VertexLength_ = 0x40;
                                break;

                            case 0x13:     // JoJo most meshes
                                           // NormalsTanBiTanFloat
                                VertexLength_ = 0x60;
                                break;

                            default:
                                VertexLength_ = 0x40;
                                break;
                            }
                        }

                        GameObject ListItem_ = Instantiate(ListItem);
                        GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta = GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta + new Vector2(0, 37.25f);
                        ListItem_Properties ListItemNew = ListItem_.GetComponent <ListItem_Properties>();
                        ListItemNew.MeshGroups =
                            fileBytes[x + 90] * 0x100 +
                            fileBytes[x + 91] * 1;
                        ListItemNew.MeshName             = new string(meshName.ToArray());
                        ListItemNew.VertexLength         = VertexLength_;
                        ListItemNew.MeshName_UI.text     = ListItemNew.MeshName + MeshType;
                        ListItemNew.VertexLength_UI.text = "Groups: " + ListItemNew.MeshGroups.ToString() + " | Length: " + ListItemNew.VertexLength.ToString();
                        ListItem_.transform.SetParent(GameObject.Find("Mesh List Content").transform);
                        ListItem_.transform.localScale = new Vector3(1, 1, 1);
                        ListItemNew.MeshID             = OverallMeshCount;
                        ListItem_.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => ListItemNew.SelectThisIndex());
                        ListItem_.name = "List Item " + MeshCount.ToString();
                        OverallMeshCount++;
                        MeshCount++;
                    }
                }

                // Read bones if it is 1cmn
                DialogResult CustomBones = MessageBox.Show("(Experimental) Do you want the tool to search for bone names inside the file and use the new bone editor? This is known to work in 1cmnbod1 but other models might have wrong IDs.", "", MessageBoxButtons.YesNo);
                if (CustomBones == DialogResult.Yes)
                {
                    try
                    {
                        Int32 StartID = 0x0;
                        Int32 EndID   = 0x0;

                        for (Int32 x = 0; x < fileBytes.Count; x++)
                        {
                            if (fileBytes[x] == 't' && fileBytes[x + 1] == 'r' && fileBytes[x + 2] == 'a' && fileBytes[x + 3] == 'l' && fileBytes[x + 4] == 'l')
                            {
                                StartID = x - 9;
                                x       = fileBytes.Count;
                            }
                        }

                        for (Int32 x = StartID + 1; x < fileBytes.Count; x++)
                        {
                            if (fileBytes[x] == 'c' && fileBytes[x + 1] == 'e' && fileBytes[x + 2] == 'l' && fileBytes[x + 3] == 's' && fileBytes[x + 4] == 'h' && fileBytes[x + 5] == 'a' && fileBytes[x + 6] == 'd' && fileBytes[x + 7] == 'e')
                            {
                                EndID = x;
                                x     = fileBytes.Count;
                            }
                        }

                        UnityEngine.Debug.Log(StartID);
                        UnityEngine.Debug.Log(EndID);

                        List <string> Lines        = new List <string>();
                        List <byte>   bytesInFile2 = new List <byte>();

                        for (int x = StartID; x < EndID; x++)
                        {
                            bytesInFile2.Add(fileBytes[x]);
                        }

                        for (int x = 0; x < bytesInFile2.Count; x++)
                        {
                            if (bytesInFile2[x] == 0x00)
                            {
                                bytesInFile2[x] = 0x0A;
                            }
                        }
                        string tx = Encoding.ASCII.GetString(bytesInFile2.ToArray());
                        Lines = tx.Split('\n').ToList();
                        bytesInFile2.Clear();
                        Lines.RemoveAt(1);
                        Lines.RemoveAt(Lines.Count - 1);

                        for (int x = 0; x < Lines.Count; x++)
                        {
                            Lines[x] = Lines[x].Remove(0, 4);
                        }

                        BoneList = Lines;
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("The tool wasn't able to parse the bone IDs. Changing to manual mode.");
                        BoneList = new List <string>();
                    }
                    //File.WriteAllLines("C:\\Users\\santi\\Desktop\\file.txt", Lines.ToArray());
                }
                else
                {
                    BoneList = new List <string>();
                }

                System.Windows.Forms.MessageBox.Show("Import finished. Found " + indexOfMeshes.Count.ToString() + " meshes in file.");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Not a valid .xfbin file.");
            }
        }
    }
Esempio n. 2
0
    public void LoadXfbinWindow()
    {
        System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
        openFileDialog1.DefaultExt   = "xfbin";
        openFileDialog1.AddExtension = true;
        openFileDialog1.ShowDialog();

        string pathToXfbin = openFileDialog1.FileName;

        if (pathToXfbin != "" && File.Exists(pathToXfbin))
        {
            fileBytes = File.ReadAllBytes(pathToXfbin);
            foreach (Transform child_ in GameObject.Find("Mesh List Content").transform)
            {
                Destroy(child_.gameObject);
            }
            GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta = new Vector2(0, 0);
            indexOfMeshes.Clear();

            if (fileBytes[0] == 78 && fileBytes[1] == 85 && fileBytes[2] == 67 && fileBytes[3] == 67)
            {
                int MeshCount = 0;
                for (int x = 0; x < fileBytes.Length - 3; x++)
                {
                    if (fileBytes[x] == 78 && fileBytes[x + 1] == 68 && fileBytes[x + 2] == 80 && fileBytes[x + 3] == 51)
                    {
                        indexOfMeshes.Add(x);
                        List <char> meshName = new List <char>();
                        int         meshSize = 48 + (fileBytes[x + 17] * 65536 + fileBytes[x + 18] * 256 + fileBytes[x + 19]) + (fileBytes[x + 21] * 65536 + fileBytes[x + 22] * 256 + fileBytes[x + 23]) + (fileBytes[x + 25] * 65536 + fileBytes[x + 26] * 256 + fileBytes[x + 27]) + (fileBytes[x + 29] * 65536 + fileBytes[x + 30] * 256 + fileBytes[x + 31]);

                        for (int abc = 0; abc < 25; abc++)
                        {
                            meshName.Add((char)fileBytes[x + meshSize + abc]);
                        }

                        int VertexLenght_;
                        if (fileBytes[x + 29] * 65536 + fileBytes[x + 30] * 256 + fileBytes[x + 31] == 0)
                        {
                            VertexLenght_ = 28;
                        }
                        else
                        {
                            VertexLenght_ = 64;
                        }
                        GameObject ListItem_ = Instantiate(ListItem);
                        GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta = GameObject.Find("Mesh List Content").GetComponent <RectTransform>().sizeDelta + new Vector2(0, 37.25f);
                        ListItem_Properties ListItemNew = ListItem_.GetComponent <ListItem_Properties>();
                        ListItemNew.MeshName             = new string(meshName.ToArray());
                        ListItemNew.VertexLenght         = VertexLenght_;
                        ListItemNew.MeshName_UI.text     = ListItemNew.MeshName;
                        ListItemNew.VertexLenght_UI.text = "Vertex Lenght: " + ListItemNew.VertexLenght.ToString();
                        ListItem_.transform.SetParent(GameObject.Find("Mesh List Content").transform);
                        ListItem_.transform.localScale = new Vector3(1, 1, 1);
                        ListItemNew.MeshID             = ListItem_.transform.GetSiblingIndex();
                        ListItem_.GetComponent <Button>().onClick.AddListener(() => ListItemNew.SelectThisIndex());
                        ListItem_.name = "List Item " + MeshCount.ToString();
                        MeshCount++;
                    }
                }
                System.Windows.Forms.MessageBox.Show("Import finished. Found " + indexOfMeshes.Count.ToString() + " meshes in file.");
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Not a valid .xfbin file.");
            }
        }
    }