public static ETR_File Load(byte[] bytes) { ETR_File etrFile = new ETR_File(); etrFile.Bytes = bytes; etrFile.ETR_Entries = new List <ETR_MainEntry>(); etrFile.ETR_TextureEntries = new List <ETR_TextureEntry>(); int section1Count = BitConverter.ToInt16(bytes, 12); int section2Count = BitConverter.ToInt16(bytes, 14); int section1Offset = BitConverter.ToInt32(bytes, 16); int section2Offset = BitConverter.ToInt32(bytes, 20); for (int i = 0; i < section1Count; i++) { ETR_MainEntry newEntry = new ETR_MainEntry(); newEntry.I_108 = BitConverter.ToUInt16(bytes, section1Offset + 108); newEntry.Color1_R = BitConverter.ToSingle(bytes, section1Offset + 120); newEntry.Color1_G = BitConverter.ToSingle(bytes, section1Offset + 124); newEntry.Color1_B = BitConverter.ToSingle(bytes, section1Offset + 128); newEntry.Color1_A = BitConverter.ToSingle(bytes, section1Offset + 132); newEntry.Color2_R = BitConverter.ToSingle(bytes, section1Offset + 136); newEntry.Color2_G = BitConverter.ToSingle(bytes, section1Offset + 140); newEntry.Color2_B = BitConverter.ToSingle(bytes, section1Offset + 144); newEntry.Color2_A = BitConverter.ToSingle(bytes, section1Offset + 148); //Parse main entry etrFile.ETR_Entries.Add(newEntry); section1Offset += 176; } for (int i = 0; i < section2Count; i++) { etrFile.ETR_TextureEntries.Add(new ETR_TextureEntry() { I_01 = bytes[section2Offset + 1] }); section2Offset += 28; } return(etrFile); }
public static ETR_File Load(byte[] bytes) { ETR_File etrFile = new ETR_File(); etrFile.Bytes = bytes; etrFile.ETR_Entries = new List <ETR_MainEntry>(); etrFile.ETR_TextureEntries = new List <ETR_TextureEntry>(); int section1Count = BitConverter.ToInt16(bytes, 12); int section2Count = BitConverter.ToInt16(bytes, 14); int section1Offset = BitConverter.ToInt32(bytes, 16); int section2Offset = BitConverter.ToInt32(bytes, 20); for (int i = 0; i < section1Count; i++) { ETR_MainEntry newEntry = new ETR_MainEntry(); newEntry.I_108 = BitConverter.ToUInt16(bytes, section1Offset + 108); newEntry.Color1_R = BitConverter.ToSingle(bytes, section1Offset + 120); newEntry.Color1_G = BitConverter.ToSingle(bytes, section1Offset + 124); newEntry.Color1_B = BitConverter.ToSingle(bytes, section1Offset + 128); newEntry.Color1_A = BitConverter.ToSingle(bytes, section1Offset + 132); newEntry.Color2_R = BitConverter.ToSingle(bytes, section1Offset + 136); newEntry.Color2_G = BitConverter.ToSingle(bytes, section1Offset + 140); newEntry.Color2_B = BitConverter.ToSingle(bytes, section1Offset + 144); newEntry.Color2_A = BitConverter.ToSingle(bytes, section1Offset + 148); //Unleashed PR: //+16 is to skip the 4 floats for EndPoint that come BEFORE Extrude Points //XenoXMLConverter output has it come after int extrudePointOffset = BitConverter.ToInt32(bytes, section1Offset + 116) + section1Offset + 16; int extrudePointCount = BitConverter.ToInt32(bytes, section1Offset + 156); //actual number of Extrude Points = number of Extrude Points in binary file + 1 extrudePointCount += extrudePointCount >= 1 ? 1 : 0; for (int j = 0; j < extrudePointCount; j++) { float X = BitConverter.ToSingle(bytes, extrudePointOffset); float Y = BitConverter.ToSingle(bytes, extrudePointOffset + 4); newEntry.ExtrudePoints.Add(new ETR_Point(X, Y)); extrudePointOffset += 8; } //Parse main entry etrFile.ETR_Entries.Add(newEntry); section1Offset += 176; } for (int i = 0; i < section2Count; i++) { etrFile.ETR_TextureEntries.Add(new ETR_TextureEntry() { I_01 = bytes[section2Offset + 1] }); section2Offset += 28; } return(etrFile); }