private void ExportB1Button_Click(object sender, EventArgs e) { if (BoneNames.Any()) { File.WriteAllLines(modelName + "_bones.txt", BoneNames); MessageBox.Show($"File saved as \"" + modelName + "_bones.txt" + "\" in the program's directory.", $"Success"); } }
public static bool XfbinOpen(int xfbinNo, string xfbinPath) { byte[] fileBytes = File.ReadAllBytes(xfbinPath); List <NUD> meshList = new List <NUD>(); List <string> Lines = new List <string>(); int meshCount = 0; searchResults = SearchForByte("NDP3", fileBytes, 0, fileBytes.Length, 0); if (!searchResults.Any()) { MessageBox.Show($"Xfbin doesn't contain any meshes. Please select a valid xfbin.", $"Error"); return(false); } // Find the group names + arrange them if (SearchForByte("trall", fileBytes, 0, fileBytes.Length, 1).Any()) { int end = SearchForByte("trall", fileBytes, 0, fileBytes.Length, 1)[0]; string modelName = ""; int t = 0x20; int boneStart = 0; while (t <= 0x20 && t > 0) { modelName = Encoding.Default.GetString(fileBytes, end - t, 0x20); modelName = modelName.Remove(modelName.IndexOf("\0")); if (modelName.Contains("trall")) { for (int n = 0; n <= 0x20; n++) { if (fileBytes[end - t - n] == 0x00) { boneStart = end - t - n + 1; modelName = Encoding.Default.GetString(fileBytes, boneStart, 0x20); modelName = modelName.Remove(modelName.IndexOf("t0 trall")) + "bod1"; // xchr01bod1 n = 0x21; } } t = 0x21; } else { t -= 0x08; } } int groupStart = 0; int x = 0; bool isStorm = false; for (int n = 0; n >= 0; n++) { try { groupStart = SearchForByte(modelName, fileBytes, boneStart - x, 0, 1)[0]; } catch { isStorm = true; modelName = modelName.Remove(4, 2); // hack for nsuns models, ex: xchrbod1 groupStart = SearchForByte(modelName, fileBytes, boneStart - x, 0, 1)[0]; } x = boneStart - groupStart + 1; if (fileBytes[groupStart + modelName.Length] == 0) { n = -2; } } byte[] groupNames = new byte[boneStart - groupStart]; Array.Copy(fileBytes, groupStart, groupNames, 0, boneStart - groupStart); for (int o = 0; o < groupNames.Length; o++) { if (groupNames[o] == 0x00) { groupNames[o] = 0x0A; } } string tx = Encoding.ASCII.GetString(groupNames); Lines = tx.Split('\n').ToList(); Lines.RemoveAt(0); Lines.RemoveAt(Lines.Count - 1); foreach (string s in Lines.ToList()) { if (s.Contains(" ")) { Lines.Remove(s); } else { if (isStorm) { Lines[Lines.IndexOf(s)] = s.Remove(0, modelName.Length - 4); } else { Lines[Lines.IndexOf(s)] = s.Remove(0, modelName.Length + 1); } } } } // Read each mesh in the xfbin for (int i = 0; i < searchResults.Count; i++) { meshList.Add(LoadNud(fileBytes, searchResults[i], true)); meshCount++; } // Set each group name to its byte List <Group> groupBytes = new List <Group>(); foreach (NUD mesh in meshList) { for (int a = 0; a < mesh.GroupCount; a++) { if (!groupBytes.Any(g => g.EndByte == mesh.GroupBytes[a].EndByte)) { groupBytes.Add(mesh.GroupBytes[a]); } } } if (Lines.Any()) { try { foreach (Group g in groupBytes) { g.Name = Lines[groupBytes.IndexOf(g)]; } } catch { } } List <int> BoneIDs3 = BoneIDs; // Set the bone names obtained from the animation file if (BoneNames.Any()) { List <string> names = new List <string>(); for (int b = 0; b < BoneIDs.Last(); b++) { names.Add(BoneNames[b]); } BoneNames = names; } // Dynamically set the properties for each xfbin if (xfbinNo == 1) { xfbin1Open = true; xfbin1Path = xfbinPath; file1Bytes = fileBytes.ToList(); meshCount1 = meshCount; meshList1 = meshList; xfbin1Groups = groupBytes; } else if (xfbinNo == 2) { xfbin2Open = true; xfbin2Path = xfbinPath; file2Bytes = fileBytes.ToList(); meshCount2 = meshCount; meshList2 = meshList; xfbin2Groups = groupBytes; } return(true); }