private static MainFieldChara ReadMainChara(byte[] oneb) { MainFieldChara localMfc = new MainFieldChara(); using (MemoryStream ms = new MemoryStream(oneb)) using (BinaryReader br = new BinaryReader(ms)) { List <uint> timOffsets = new List <uint>(); uint timOffset; while ((timOffset = br.ReadUInt32()) != 0xffffffff) { timOffsets.Add(timOffset & 0x00FFFFFF); } uint modelPointer = br.ReadUInt32(); //read textures List <Texture2D> tex2Dreader = new List <Texture2D>(); for (int i = 0; i < timOffsets.Count; i++) { TIM2 tim = new TIM2(br, timOffsets[i]); tex2Dreader.Add(tim.GetTexture()); } localMfc.textures = tex2Dreader.ToArray(); //read models ms.Seek(modelPointer, SeekOrigin.Begin); Debug_MCH mch = new Debug_MCH(ms, br, Debug_MCH.mchMode.FieldMain); localMfc.mch = mch; } return(localMfc); }
private static MainFieldChara ReadMainChara(byte[] oneBytes) { var localMfc = new MainFieldChara(); using (var ms = new MemoryStream(oneBytes)) using (var br = new BinaryReader(ms)) { var timOffsets = new List <uint>(); uint timOffset; while ((timOffset = br.ReadUInt32()) != 0xffffffff) { timOffsets.Add(timOffset & 0x00FFFFFF); } var modelPointer = br.ReadUInt32(); //read textures var texture2DReader = timOffsets .Select(x => new TIM2(br, x)) .Select(x => x.GetTexture()).ToList() .AsReadOnly(); localMfc.Textures = texture2DReader.ToArray(); //read models ms.Seek(modelPointer, SeekOrigin.Begin); var mch = new Debug_MCH(ms, br, Debug_MCH.mchMode.FieldMain); localMfc.MCH = mch; } return(localMfc); }
/// <summary> /// Reads chara.one buffer -> chara one is a file packed with MCH files and TIM textures /// without pointers. File needs to be scanned /// </summary> /// <param name="buffer">Full chara.one file</param> public CharaOne(byte[] buffer) { this.buffer = buffer; List <Debug_MCH> mchs = new List <Debug_MCH>(); List <TextureHandler> texturesList = new List <TextureHandler>(); int i = 0; MemoryStream ms = null; using (BinaryReader br = new BinaryReader(ms = new MemoryStream(this.buffer))) { uint eof = br.ReadUInt32(); TIM2 tim; while (ms.CanRead) { if (ms.Position >= ms.Length) { break; } else if (BitConverter.ToUInt16(this.buffer, (int)ms.Position) == 0) { ms.Seek(2, SeekOrigin.Current); } else if (br.ReadUInt64() == 0x0000000800000010) { ms.Seek(-8, SeekOrigin.Current); tim = new TIM2(this.buffer, (uint)ms.Position); ms.Seek(tim.GetHeight * tim.GetWidth / 2 + 64, SeekOrigin.Current); //i.e. 64*20=1280/2=640 + 64= 704 + eof texturesList.Add(TextureHandler.Create($"chara_tim{(i++).ToString("D2")}", tim, 0, null)); } else //is geometry structure { ms.Seek(-8, SeekOrigin.Current); Debug_MCH mch = new Debug_MCH(ms, br); if (mch.bValid()) { mchs.Add(mch); } } } ms = null; } mchInstances = mchs.ToArray(); textures = texturesList.ToArray(); }