public void OpenAmaFile(string fileName) { statusBar.Text = ""; tbFileName.Text = fileName; amaFile = new AMA(); amaFile.Read(fileName); amaFile.SanityCheck(fileName); if (amaFile.WrongValues.Count > 0) { Console.WriteLine("Sanity check failed"); statusBar.Text = "Warning! File won't be saved properly!"; File.WriteAllText(fileName + "_check.txt", String.Join(" ", amaFile.StrangeList)); } listBoxGroup1.Items.Clear(); foreach (var obj in amaFile.Group1) { listBoxGroup1.Items.Add(obj.Name); } listBoxGroup2.Items.Clear(); foreach (var obj in amaFile.Group2) { listBoxGroup2.Items.Add(obj.Name); } if (amaFile.Group1.Count > 0) { tabControl.SelectedIndex = 0; listBoxGroup1.Select(); listBoxGroup1.SelectedIndex = 0; } else if (amaFile.Group2.Count > 0) { tabControl.SelectedIndex = 1; listBoxGroup2.Select(); listBoxGroup2.SelectedIndex = 0; } }
public override void Read(byte[] fileRaw) { Group1 = new List <Group1>(); Group2 = new List <Group2>(); base.Read(fileRaw); if (!AMA.IsAMA(fileRaw)) { return; } StrangeIsntIt(fileRaw, 0x4, 0); int g1Number = BitConverter.ToInt32(fileRaw, 0x8); int g2Number = BitConverter.ToInt32(fileRaw, 0xC); int g1ListPointer = BitConverter.ToInt32(fileRaw, 0x10); int g2ListPointer = BitConverter.ToInt32(fileRaw, 0x14); int g1NameListPointer = BitConverter.ToInt32(fileRaw, 0x18); int g2NameListPointer = BitConverter.ToInt32(fileRaw, 0x1C); var g1Dict = new Dictionary <int, Group1>(); var g2Dict = new Dictionary <int, Group2>(); for (int i = 0; i < g1Number; i++) { int ptr = BitConverter.ToInt32(fileRaw, g1ListPointer + 4 * i); g1Dict.Add(ptr, new Group1()); Group1.Add(g1Dict[ptr]); } for (int i = 0; i < g2Number; i++) { int ptr = BitConverter.ToInt32(fileRaw, g2ListPointer + 4 * i); g2Dict.Add(ptr, new Group2()); Group2.Add(g2Dict[ptr]); } foreach (int ptr in g2Dict.Keys) { g2Dict[ptr].Unknown12 = BitConverter.ToInt32(fileRaw, ptr); StrangeIsntIt(fileRaw, ptr + 0x04, Group2.IndexOf(g2Dict[ptr])); g2Dict[ptr].Unknown13 = BitConverter.ToInt32(fileRaw, ptr + 0x08); StrangeIsntIt(fileRaw, ptr + 0x0C, 0x00); g2Dict[ptr].PositionX = BitConverter.ToSingle(fileRaw, ptr + 0x10); g2Dict[ptr].PositionY = BitConverter.ToSingle(fileRaw, ptr + 0x14); g2Dict[ptr].SizeX = BitConverter.ToSingle(fileRaw, ptr + 0x18); g2Dict[ptr].SizeY = BitConverter.ToSingle(fileRaw, ptr + 0x1C); g2Dict[ptr].Unknown8 = BitConverter.ToInt32(fileRaw, ptr + 0x20); g2Dict[ptr].Unknown15 = BitConverter.ToInt32(fileRaw, ptr + 0x28); g2Dict[ptr].Unknown16 = BitConverter.ToInt32(fileRaw, ptr + 0x2C); g2Dict[ptr].Unknown18 = BitConverter.ToInt32(fileRaw, ptr + 0x30); g2Dict[ptr].Unknown19 = BitConverter.ToInt32(fileRaw, ptr + 0x34); for (int i = 0x38; i < 0x40; i = i + 4) { StrangeIsntIt(fileRaw, ptr + i, 0x00); } int ptr0 = BitConverter.ToInt32(fileRaw, ptr + 0x24); g2Dict[ptr].Unknown0 = BitConverter.ToInt32(fileRaw, ptr0); g2Dict[ptr].Unknown1 = BitConverter.ToInt32(fileRaw, ptr0 + 4); g2Dict[ptr].Unknown2 = BitConverter.ToInt32(fileRaw, ptr0 + 8); int ptr1 = BitConverter.ToInt32(fileRaw, ptr0 + 0xC); g2Dict[ptr].Unknown3 = BitConverter.ToInt32(fileRaw, ptr1); int ptr2 = BitConverter.ToInt32(fileRaw, ptr0 + 0x10); g2Dict[ptr].Unknown4 = BitConverter.ToInt32(fileRaw, ptr2); g2Dict[ptr].Unknown5 = BitConverter.ToInt32(fileRaw, ptr2 + 0x04); g2Dict[ptr].Unknown6 = BitConverter.ToInt32(fileRaw, ptr2 + 0x08); g2Dict[ptr].Unknown7 = BitConverter.ToSingle(fileRaw, ptr2 + 0x0C); g2Dict[ptr].Unknown8 = BitConverter.ToInt32(fileRaw, ptr + 0x54); g2Dict[ptr].Unknown9 = BitConverter.ToInt32(fileRaw, ptr + 0x58); g2Dict[ptr].Unknown10 = BitConverter.ToInt32(fileRaw, ptr + 0x5C); g2Dict[ptr].Unknown11 = BitConverter.ToInt32(fileRaw, ptr + 0x60); g2Dict[ptr].Unknown14 = BitConverter.ToInt32(fileRaw, ptr + 0x64); for (int i = 0x68; i < 0x68; i = i + 4) { StrangeIsntIt(fileRaw, ptr + i, 0x00); } g2Dict[ptr].Unknown20 = BitConverter.ToInt32(fileRaw, ptr + 0x68); g2Dict[ptr].Unknown21 = BitConverter.ToInt32(fileRaw, ptr + 0x6C); g2Dict[ptr].Unknown17 = BitConverter.ToInt32(fileRaw, ptr + 0x74); g2Dict[ptr].UVLeftEdge = BitConverter.ToSingle(fileRaw, ptr2 + 0x10); g2Dict[ptr].UVUpperEdge = BitConverter.ToSingle(fileRaw, ptr2 + 0x14); g2Dict[ptr].UVRightEdge = BitConverter.ToSingle(fileRaw, ptr2 + 0x18); g2Dict[ptr].UVBottomEdge = BitConverter.ToSingle(fileRaw, ptr2 + 0x1C); } foreach (int ptr in g1Dict.Keys) { StrangeIsntIt(fileRaw, ptr, 0x00); StrangeIsntIt(fileRaw, ptr + 4, Group1.IndexOf(g1Dict[ptr])); int ptrG1Child = BitConverter.ToInt32(fileRaw, ptr + 0x8); if (ptrG1Child != 0) { g1Dict[ptr].G1Child0 = g1Dict[ptrG1Child]; } ptrG1Child = BitConverter.ToInt32(fileRaw, ptr + 0xC); if (ptrG1Child != 0) { g1Dict[ptr].G1Child1 = g1Dict[ptrG1Child]; } int ptrParent = BitConverter.ToInt32(fileRaw, ptr + 0x10); if (ptrParent != 0) { g1Dict[ptr].Parent = g1Dict[ptrParent]; } int ptrG2Child = BitConverter.ToInt32(fileRaw, ptr + 0x14); if (ptrG2Child != 0) { g1Dict[ptr].G2Child0 = g2Dict[ptrG2Child]; } StrangeIsntIt(fileRaw, ptr + 0x18, 0x00); StrangeIsntIt(fileRaw, ptr + 0x1C, 0x00); } var sb = new StringBuilder(); for (int i = 0; i < g1Number; i++) { int ptr = BitConverter.ToInt32(fileRaw, g1NameListPointer + 4 * i); for (; fileRaw[ptr] != 0x00; ptr++) { sb.Append((char)fileRaw[ptr]); } Group1[i].Name = sb.ToString(); sb.Clear(); } for (int i = 0; i < g2Number; i++) { int ptr = BitConverter.ToInt32(fileRaw, g2NameListPointer + 4 * i); for (; fileRaw[ptr] != 0x00; ptr++) { sb.Append((char)fileRaw[ptr]); } Group2[i].Name = sb.ToString(); sb.Clear(); } }