MaxtorCoder

ReadMD20

Jan 29th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.31 KB | None | 0 0
  1. public static void ReadMD20(BinaryReader br)
  2.         {
  3.             br.BaseStream.Position -= 8;
  4.             header = new M2Header();
  5.             header.magic = br.ReadUInt32();
  6.             header.version = br.ReadEnum<Versions>();
  7.             header.name = br.ReadM2Array();
  8.             header.flags = br.ReadUInt32();
  9.             header.GlobalLoops = br.ReadM2Array();
  10.             header.Animations = br.ReadM2Array();
  11.             header.AnimationsLookup = br.ReadM2Array();
  12.             header.Bones = br.ReadM2Array();
  13.             header.KeyBoneLookup = br.ReadM2Array();
  14.             header.Vertices = br.ReadM2Array();
  15.             header.SkinProfiles = br.ReadUInt32();
  16.             header.Colors = br.ReadM2Array();
  17.             header.Textures = br.ReadM2Array();
  18.             header.TextureWeights = br.ReadM2Array();
  19.             header.TextureTransform = br.ReadM2Array();
  20.             header.ReplacableTextureLookup = br.ReadM2Array();
  21.             header.Materials = br.ReadM2Array();
  22.             header.BoneLookupTable = br.ReadM2Array();
  23.             header.TextureLookupTable = br.ReadM2Array();
  24.             header.TexUnitLookupTable = br.ReadM2Array();
  25.             header.TransparancyLookupTable = br.ReadM2Array();
  26.             header.TexTransformLookupTable = br.ReadM2Array();
  27.             br.ReadBytes(56); // Skip CAaBox Boxes
  28.             header.CollisionTriangles = br.ReadM2Array();
  29.             header.CollisionVertices = br.ReadM2Array();
  30.             header.CollisionNormals = br.ReadM2Array();
  31.             header.Attachments = br.ReadM2Array();
  32.             header.AttachmentsLookupTable = br.ReadM2Array();
  33.             header.Events = br.ReadM2Array();
  34.             header.Lights = br.ReadM2Array();
  35.             header.Cameras = br.ReadM2Array();
  36.             header.CameraLookupTable = br.ReadM2Array();
  37.             header.RibbonEmmiters = br.ReadM2Array();
  38.             header.ParticleEmmiters = br.ReadM2Array();
  39.  
  40.             Console.WriteLine($"{header.magic} File Version: {header.version}\n");
  41.  
  42.             if (header.Textures.offset != 0)
  43.             {
  44.                 br.BaseStream.Position = header.Textures.offset;
  45.                 for (int i = 0; i < header.Textures.size; i++)
  46.                 {
  47.                     Texture _Texture = new Texture();
  48.                     long Pos = br.BaseStream.Position;
  49.  
  50.                     _Texture.Type = br.ReadEnum<TextureType>();
  51.                     _Texture.Flag = br.ReadEnum<TextureFlags>();
  52.                     _Texture.FilenameLength = br.ReadUInt32();
  53.                     _Texture.FilenameOffset = br.ReadUInt32();
  54.  
  55.                     br.BaseStream.Position = _Texture.FilenameOffset;
  56.                     _Texture.FileName = br.ReadChars((int)_Texture.FilenameLength);
  57.                     string FileName = new string(_Texture.FileName);
  58.  
  59.                     br.BaseStream.Position = Pos + 16;
  60.  
  61.                     Console.WriteLine($"Type: {_Texture.Type} Flag: {_Texture.Flag} " +
  62.                                       $"Length: {_Texture.FilenameLength} Offset: {_Texture.FilenameOffset}");
  63.                     Console.ForegroundColor = ConsoleColor.Cyan;
  64.                     Console.WriteLine($"FileName: {FileName}\n");
  65.                     Console.ForegroundColor = ConsoleColor.Gray;
  66.                     n++;
  67.                 }
  68.             }
  69.         }
Advertisement
Add Comment
Please, Sign In to add comment