private void CreateLocalLists() { foreach (Robot robot in BaseFile.ReplacedRobots) { ReplacedRobots.Add(robot); } foreach (JointPos joint in BaseFile.ReplacedJoints) { ReplacedJoints.Add(joint); } foreach (Polymodel model in BaseFile.ReplacedModels) { ReplacedModels.Add(model); } foreach (ReplacedBitmapElement bm in BaseFile.ReplacedObjBitmaps) { ReplacedObjBitmaps.Add(bm); } foreach (ReplacedBitmapElement bm in BaseFile.ReplacedObjBitmapPtrs) { ReplacedObjBitmapPtrs.Add(bm); } }
/// <summary> /// Generates all model's needed ObjBitmaps and ObjBitmapPointers /// </summary> private void LoadModelTextures() { Dictionary <string, int> textureMapping = new Dictionary <string, int>(); PIGImage img; EClip clip; ReplacedBitmapElement bm; //Add base file ObjBitmaps to this mess for (int i = 0; i < BaseHAM.BaseFile.ObjBitmaps.Count; i++) { img = BaseHAM.piggyFile.GetImage(BaseHAM.BaseFile.ObjBitmaps[i]); if (!img.IsAnimated && !textureMapping.ContainsKey(img.Name)) { textureMapping.Add(img.Name.ToLower(), i); } } //Add EClip names for (int i = 0; i < BaseHAM.EClips.Count; i++) { clip = BaseHAM.EClips[i]; if (clip.ChangingObjectTexture != -1) { textureMapping.Add(clip.Name.ToLower(), clip.ChangingObjectTexture); } } //If augment file, add augment obj bitmaps if (AugmentFile != null) { for (int i = 0; i < AugmentFile.ObjBitmaps.Count; i++) { img = BaseHAM.piggyFile.GetImage(AugmentFile.ObjBitmaps[i]); if (!textureMapping.ContainsKey(img.Name.ToLower())) { textureMapping.Add(img.Name.ToLower(), i + VHAMFile.NumDescent2ObjBitmaps); } } } //Nuke the old replaced ObjBitmaps and ObjBitmapPointers because they aren't needed anymore ReplacedObjBitmaps.Clear(); ReplacedObjBitmapPtrs.Clear(); //Generate the new elements Polymodel model; int replacedNum; List <int> newTextures = new List <int>(); string texName; for (int i = 0; i < ReplacedModels.Count; i++) { model = ReplacedModels[i]; replacedNum = model.BaseTexture; //Find the unique textures in this model for (int j = 0; j < model.TextureList.Count; j++) { texName = model.TextureList[j].ToLower(); if (!textureMapping.ContainsKey(texName)) { newTextures.Add(BaseHAM.piggyFile.GetBitmapIDFromName(texName)); } } //Generate the new ObjBitmaps foreach (int newID in newTextures) { ReplacedBitmapElement elem; elem.Data = (ushort)newID; elem.ReplacementID = replacedNum; ReplacedObjBitmaps.Add(elem); replacedNum++; } newTextures.Clear(); } //Finally augment things with our own images for (int i = 0; i < ReplacedObjBitmaps.Count; i++) { bm = ReplacedObjBitmaps[i]; img = BaseHAM.piggyFile.GetImage(bm.Data); if (!textureMapping.ContainsKey(img.Name.ToLower())) { textureMapping.Add(img.Name.ToLower(), bm.ReplacementID); } } //Final stage: generate new ObjBitmapPointers for (int i = 0; i < ReplacedModels.Count; i++) { model = ReplacedModels[i]; replacedNum = model.FirstTexture; foreach (string texture in model.TextureList) { string ltexture = texture.ToLower(); ReplacedBitmapElement elem; if (textureMapping.ContainsKey(ltexture)) { elem.Data = (ushort)textureMapping[ltexture]; } else { elem.Data = 0; } elem.ReplacementID = replacedNum; ReplacedObjBitmapPtrs.Add(elem); replacedNum++; } } }
/// <summary> /// Loads an HXM file from a given stream. /// </summary> /// <param name="stream">The stream to load the HXM data from.</param> public void Read(Stream stream) { BinaryReader br; br = new BinaryReader(stream); HAMDataReader data = new HAMDataReader(); int sig = br.ReadInt32(); int ver = br.ReadInt32(); if (sig != 559435080) { br.Dispose(); throw new InvalidDataException("HXMFile::Read: HXM file has bad header."); } if (ver != 1) { br.Dispose(); throw new InvalidDataException(string.Format("HXMFile::Read: HXM file has bad version. Got {0}, but expected 1", ver)); } int replacedRobotCount = br.ReadInt32(); for (int x = 0; x < replacedRobotCount; x++) { int replacementID = br.ReadInt32(); Robot robot = data.ReadRobot(br); robot.replacementID = replacementID; ReplacedRobots.Add(robot); } int replacedJointCount = br.ReadInt32(); for (int x = 0; x < replacedJointCount; x++) { int replacementID = br.ReadInt32(); JointPos joint = new JointPos(); joint.JointNum = br.ReadInt16(); joint.Angles.P = br.ReadInt16(); joint.Angles.B = br.ReadInt16(); joint.Angles.H = br.ReadInt16(); joint.ReplacementID = replacementID; ReplacedJoints.Add(joint); } int modelsToReplace = br.ReadInt32(); for (int x = 0; x < modelsToReplace; x++) { int replacementID = br.ReadInt32(); Polymodel model = data.ReadPolymodelInfo(br); model.ReplacementID = replacementID; model.InterpreterData = br.ReadBytes(model.ModelIDTASize); ReplacedModels.Add(model); model.DyingModelnum = br.ReadInt32(); model.DeadModelnum = br.ReadInt32(); } int objBitmapsToReplace = br.ReadInt32(); for (int x = 0; x < objBitmapsToReplace; x++) { ReplacedBitmapElement objBitmap = new ReplacedBitmapElement(); objBitmap.ReplacementID = br.ReadInt32(); objBitmap.Data = br.ReadUInt16(); ReplacedObjBitmaps.Add(objBitmap); //Console.WriteLine("Loading replacement obj bitmap, replacing slot {0} with {1} ({2})", objBitmap.replacementID, objBitmap.data, baseFile.piggyFile.images[objBitmap.data].name); } int objBitmapPtrsToReplace = br.ReadInt32(); for (int x = 0; x < objBitmapPtrsToReplace; x++) { ReplacedBitmapElement objBitmap = new ReplacedBitmapElement(); objBitmap.ReplacementID = br.ReadInt32(); objBitmap.Data = br.ReadUInt16(); ReplacedObjBitmapPtrs.Add(objBitmap); } }