private void LoadModel(TagIdent ident) { //var model = (ModelBlock) (Map.Deserialize(ident)); //var renderModel = model.RenderModel.Get<RenderModelBlock>(); //var scenarioObject = new ScenarioObject(model); //Scene.ObjectManager.Add(ident, scenarioObject); ////Scene.ProgramManager.LoadMaterials(renderModel.Materials.Select(x => x.Shader.Ident), Map); //Scene.CollisionManager.LoadScenarioObjectCollision(Scene.ObjectManager[ident]); //var @object = Scene.ObjectManager[ident]; //propertyGrid1.SelectedObject = renderModel.MarkerGroups; //glControl1.Controls.Clear(); //foreach (var markerGroup in renderModel.MarkerGroups) //{ // var name = markerGroup.Name.ToString(); // foreach (var marker in markerGroup.Markers) // { // glControl1.Controls.Add( // new FloatingLabel // { // Text = name, // BackColor = Color.Red, // ForeColor = Color.Black, // AutoSize = true, // Tag = marker // }); // } //} }
public void AssignShader(GlobalGeometryPartBlockNew part, CacheKey cacheKey, TagIdent shaderIdent) { var glocalKey = new TagGlobalKey(cacheKey, shaderIdent); // Does this work now? _shaderDictionary[part] = glocalKey; }
private void Allocate(TagIdent ident, int size) { //create virtual stream to write into var tagCacheStream = new VirtualStream(Index[Index.GlobalsIdent].VirtualAddress); var binaryWriter = new BinaryWriter(tagCacheStream); for (var i = 0; i < Index.Count; ++i) { var datum = Index[i]; // is this address affected by the shift? if (datum.Identifier == ident) { var alignment = Guerilla.Guerilla.AlignmentOf(Halo2.GetTypeOf(Index[ident].Class)); datum.VirtualAddress = binaryWriter.BaseStream.Align(alignment); binaryWriter.Write(new byte[size]); datum.Length = size; Index.Update(datum.Identifier, datum); } else { var data = Deserialize(datum.Identifier); var length = binaryWriter.BaseStream.Length; binaryWriter.Write(data); binaryWriter.Seek(0, SeekOrigin.End); length = (int)binaryWriter.BaseStream.Length - length; datum.Length = (int)length; Index.Update(datum.Identifier, datum); } } binaryWriter.WritePadding(512); }
public static T GetFromCache <T>(this TagIdent identifier, CacheKey cacheKey, bool skipCache = false) where T : GuerillaBlock { ActiveCache = Index[cacheKey]; var item = ActiveCache.Deserialize <T>(identifier); return(item); }
public ObjectListView( ) { SelectedObjectIdent = TagIdent.NullIdentifier; InitializeComponent( ); listView1.MouseDoubleClick += delegate { if (MouseDoubleClick != null) { MouseDoubleClick(this, SelectedObjectIdent); } }; listView1.SelectedIndexChanged += delegate { var index = listView1.SelectedIndices.Count > 0 ? listView1.SelectedIndices[0] : -1; if (index < 0) { SelectedObjectIdent = TagIdent.NullIdentifier; return; } var data = ( TagDatum )listView1.Items[index].Tag; SelectedObjectIdent = data.Identifier; if (OnSelectedObjectChanged != null) { OnSelectedObjectChanged(this, SelectedObjectIdent); } }; }
public string CalculateHash(TagIdent ident) { using (var sha1 = new SHA1CryptoServiceProvider()) { var hash = Convert.ToBase64String(sha1.ComputeHash(GetInternalTagMeta(ident))); return(hash); } }
public string CalculateTaghash(TagIdent ident) { using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider()) { var hash = Convert.ToBase64String(sha1.ComputeHash(this[ident].TagData)); //Console.WriteLine(hash); return(hash); } }
/// <summary> /// Returns the meta that is linked to the Tag /// </summary> /// <param name="ident"></param> /// <returns></returns> private byte[] GetInternalTagMeta(TagIdent ident) { using (this.Pin()) { Seek(ident); var tag = Index[ident]; var buffer = new byte[tag.Length]; Read(buffer, 0, tag.Length); return(buffer); } }
public static dynamic GetReferenceObject(TagIdent identifier, bool reload = false) { if (mapStream == null) { return(null); } if (reload) { mapStream.Remove(identifier); } return(mapStream[identifier].Deserialize( )); }
public long Seek(TagIdent tagident) { if (Index[tagident].Class == TagClass.Sbsp || Index[tagident].Class == TagClass.Ltmp) { var index = StructureMemoryBlockBindings[tagident]; ActiveAllocation(StructureCache.VirtualStructureCache0 + index); } var offset = Header.Version == HaloVersion.XBOX_RETAIL ? Index[tagident].VirtualAddress : Header.IndexInfo.IndexOffset + Index[tagident].VirtualAddress; return(Seek(offset, SeekOrigin.Begin)); }
public void Draw(TagIdent item) { if (objectInstances.ContainsKey(item)) { //IRenderable @object = objects[item] as IRenderable; //@object.Render( new[] { program, systemProgram } ); } else { var data = Halo2.GetReferenceObject(item); //objects[item] = new ScenarioObject( (ModelBlock)data ); } }
internal static bool ObjectChanged(TagIdent ident) { var newHash = mapStream.CalculateTaghash(ident); var currentHash = mapStream.GetTagHash(ident); if (currentHash == null) { return(false); } else { var equals = currentHash == newHash; return(!equals); } }
public IMap this[TagIdent tag_id] { get { if (current_tag.Identifier == tag_id) { return(this); } else { current_tag = Tags[tag_id.Index]; } return(this); } }
protected TagIndexBase(CacheStream cache) { var binaryReader = new BinaryReader(cache); classArrayAddress = binaryReader.ReadInt32(); classArrayCount = binaryReader.ReadInt32(); datumArrayAddress = binaryReader.ReadInt32(); ScenarioIdent = binaryReader.ReadTagIdent(); GlobalsIdent = binaryReader.ReadTagIdent(); _noodleValue = binaryReader.ReadInt32(); datumArrayCount = binaryReader.ReadInt32(); fourCC = binaryReader.ReadTagClass(); if (fourCC != new TagClass("tags")) { throw new InvalidDataException(); } }
private void LoadNetgameEquipment(List <ScenarioNetgameEquipmentBlock> list) { foreach (var item in list.Where(x => !TagIdent.IsNull(x.itemVehicleCollection.Ident) && (x.itemVehicleCollection.Class.ToString() == "vehc" || x.itemVehicleCollection.Class.ToString() == "itmc"))) { try { Add(item.itemVehicleCollection.Ident, new ScenarioObject(Halo2.GetReferenceObject <ModelBlock>( Halo2.GetReferenceObject <ObjectBlock>( item.itemVehicleCollection.Class.ToString() == "itmc" ? Halo2.GetReferenceObject <ItemCollectionBlock>(item.itemVehicleCollection).itemPermutations.First().item : Halo2.GetReferenceObject <VehicleCollectionBlock>(item.itemVehicleCollection).vehiclePermutations.First().vehicle).model)) { WorldMatrix = item.WorldMatrix } ); } catch (NullReferenceException) { } } }
public T Deserialize <T>(TagIdent ident) where T : GuerillaBlock { GuerillaBlock deserializedTag; if (_deserializedTagCache.TryGetValue(ident, out deserializedTag)) { return(( T )deserializedTag); } var type = Halo2.GetTypeOf(Index[ident].Class); if (type == null) { return(null); } Seek(ident); _deserializedTagCache[ident] = Deserialize(type); _tagHashDictionary[ident] = CalculateHash(ident); return(( T )_deserializedTagCache[ident]); }
private void RemoveModel(TagIdent ident) { //var @object = Scene.ObjectManager[ident]; //if (@object == null) return; //var collisionObject = // Scene.CollisionManager.World.CollisionObjectArray.FirstOrDefault(x => x == @object.CollisionObject); //if (collisionObject != null) //{ // Scene.CollisionManager.World.RemoveCollisionObject(@object.CollisionObject); //} //glControl1.Controls.Clear(); //foreach (var marker in @object.Markers) //{ // var markerCollisionObject = // Scene.CollisionManager.World.CollisionObjectArray.FirstOrDefault(x => x.UserObject == marker); // if (markerCollisionObject != null) // { // Scene.CollisionManager.World.RemoveCollisionObject(markerCollisionObject); // } //} //Scene.ObjectManager.Remove(ident); }
private void CopyStructureResources(Stream outputStream) { var scnrBlock = ( ScenarioBlock )Deserialize(Index.ScenarioIdent); foreach (var scenarioStructureBspReferenceBlock in scnrBlock.StructureBSPs) { var sbspReference = scenarioStructureBspReferenceBlock.StructureBSP; var ltmpReference = scenarioStructureBspReferenceBlock.StructureLightmap; var sbspBlock = ( ScenarioStructureBspBlock )Deserialize(sbspReference.Ident); foreach (var structureBspClusterBlock in sbspBlock.Clusters) { CopyResource(outputStream, structureBspClusterBlock); } foreach (var structureBspInstancedGeometryDefinitionBlock in sbspBlock.InstancedGeometriesDefinitions) { CopyResource(outputStream, structureBspInstancedGeometryDefinitionBlock.RenderInfo); } if (!TagIdent.IsNull(ltmpReference.Ident)) { var ltmpBlock = ( ScenarioStructureLightmapBlock )Deserialize(ltmpReference.Ident); foreach (var result in ltmpBlock.LightmapGroups.SelectMany(x => x.GeometryBuckets)) { CopyResource(outputStream, result); } } foreach (var result in sbspBlock.Decorators0.SelectMany(x => x.CacheBlocks)) { CopyResource(outputStream, result); } foreach (var globalWaterDefinitionsBlock in sbspBlock.WaterDefinitions) { CopyResource(outputStream, globalWaterDefinitionsBlock); } } }
public string GetTagHash(TagIdent ident) { return(this.hashTags.ContainsKey(ident) ? this.hashTags[ident] : null); }
public void Add(TagIdent item) { var data = Halo2.GetReferenceObject(item); objects[item] = new ScenarioObject((HierarchyModel)data); }
public void Remove(TagIdent ident) { deserializedTags.Remove(ident); }
public void Draw(TagIdent item) { if (objects.ContainsKey(item)) { IRenderable @object = objects[item] as IRenderable; @object.Render(new[] { program, systemProgram }); } else { var data = Halo2.GetReferenceObject(item); objects[item] = new ScenarioObject((HierarchyModel)data); } }
public void Add(TagIdent item) { var data = Halo2.GetReferenceObject(item); //objects[item] = new ScenarioObject( (ModelBlock)data ); }
public ScenarioObject this[TagIdent ident] { get { return this.objects.ContainsKey(ident) ? objects[ident] : null; } }
internal void Add(TagIdent ident, ScenarioObject @object) { objectInstances.Add(ident, @object); }
public void ClearCache(TagIdent ident) { _deserializedTagCache.Remove(ident); }
internal void Add(HierarchyModel model, TagIdent id) { objects[id] = new ScenarioObject(model); }
void IDefinition.FromArray(byte[] buffer) { BinaryReader bin = new BinaryReader(new MemoryStream(buffer)); bin.BaseStream.Seek(12, SeekOrigin.Begin); Shader = bin.ReadTagIdent(); }
public GuerillaBlock Deserialize(TagIdent ident) { return(Deserialize <GuerillaBlock>(ident)); }
public MapStream(string filename) : base(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, 1024) { this.MemoryBlocks = new VirtualMappedAddress[2]; //HEADER BinaryReader bin = new BinaryReader(this, Encoding.UTF8); this.Position = 0; if (bin.ReadTagClass() != (TagClass)"head") { throw new InvalidDataException("Not a halo-map file"); } this.Position = 42; BuildVersion = (Version)bin.ReadInt32(); this.Position = 16; int indexAddress = bin.ReadInt32(); int indexLength = bin.ReadInt32(); this.TagCacheLength = bin.ReadInt32(); if (BuildVersion == Version.PC_RETAIL) { this.Position += 12; } // Read maptype using (this.Pin()) { this.Position = 2048; this.Seek(320, SeekOrigin.Begin); this.Type = (MapType)bin.ReadInt32(); } this.Seek(332, SeekOrigin.Current); int stringTableLength = bin.ReadInt32(); this.Seek(4, SeekOrigin.Current); int stringTableAddress = bin.ReadInt32(); this.Seek(36, SeekOrigin.Current); MapName = bin.ReadFixedString(32); this.Seek(4, SeekOrigin.Current); Scenario = bin.ReadFixedString(256); this.Seek(4, SeekOrigin.Current); int pathsCount = bin.ReadInt32(); int pathsTableAddress = bin.ReadInt32(); int pathsTableLength = bin.ReadInt32(); this.Seek(pathsTableAddress, SeekOrigin.Begin); var Paths = Encoding.UTF8.GetString(bin.ReadBytes(pathsTableLength - 1)).Split(char.MinValue); Halo2.Paths.Assign(Paths); //STRINGS this.Seek(stringTableAddress, SeekOrigin.Begin); Strings = Encoding.UTF8.GetString(bin.ReadBytes(stringTableLength - 1)).Split(char.MinValue); Halo2.Strings.Assign(new List <string>(Strings)); // INDEX /* * Vista doesn't use memory addresses for the following address-values. (they are instead 0-based from the index-address) * * 0x00 Address to Classes array * 0x04 Classes array length * 0x08 Address to Tags array * 0x0C Scenario tag_id * 0x10 Match-Globals tag_id * 0x14 ~ * 0x18 Tags array length * 0xC0 'sgat' four_cc * * */ this.Seek(indexAddress, SeekOrigin.Begin); int tagClassTableVirtualAddress = bin.ReadInt32(); this.IndexVirtualAddress = tagClassTableVirtualAddress - 32; this.Seek(4, SeekOrigin.Current); int tagDatumTableVirtualAddress = bin.ReadInt32(); var ScenarioID = bin.ReadTagIdent(); var GlobalsID = bin.ReadTagIdent(); int tagDatumTableOffset = tagDatumTableVirtualAddress - tagClassTableVirtualAddress; this.Seek(4, SeekOrigin.Current); int tagDatumCount = bin.ReadInt32(); this.Seek(4 + tagDatumTableOffset, SeekOrigin.Current); Tags = new Tag[tagDatumCount]; for (int i = 0; i < tagDatumCount; i++) { Tags[i] = new Tag() { Type = bin.ReadTagClass(), Identifier = bin.ReadInt32(), VirtualAddress = bin.ReadInt32(), Length = bin.ReadInt32() }; //Borky vista fix - broken paths are broken //if (Tags[i].VirtualAddress == 0) continue; // var tag = Tags[i]; Tags[i].Path = Paths[Tags[i].Identifier.Index]; } // Calculate File-pointer magic SecondaryMagic = Tags[0].VirtualAddress - (indexAddress + indexLength); this.MemoryBlocks[1] = new VirtualMappedAddress() { Address = Tags[0].VirtualAddress, Length = TagCacheLength, Magic = SecondaryMagic, }; /* Intent: read the sbsp and lightmap address and lengths from the scenario tag * and store them in the Tags array. */ if (BuildVersion == Version.XBOX_RETAIL) { this.Seek(Tags[ScenarioID.Index].VirtualAddress - SecondaryMagic + 528, SeekOrigin.Begin); var count = bin.ReadInt32(); var address = bin.ReadInt32(); for (int i = 0; i < count; ++i) { this.Seek(address - SecondaryMagic + i * 68, SeekOrigin.Begin); var structureBlockOffset = bin.ReadInt32(); var structureBlockLength = bin.ReadInt32(); var structureBlockAddress = bin.ReadInt32(); if (i == 0) { this.PrimaryMagic = structureBlockAddress - structureBlockOffset; this.MemoryBlocks[0].Address = structureBlockAddress; this.MemoryBlocks[0].Magic = this.PrimaryMagic; this.MemoryBlocks[0].Length = structureBlockLength; } Seek(8, SeekOrigin.Current); var sbspIdentifier = bin.ReadTagIdent(); Seek(4, SeekOrigin.Current); var ltmpIdentifier = bin.ReadTagIdent(); Seek(structureBlockOffset, SeekOrigin.Begin); // is this the total block length or minus the 16? var blockLength = bin.ReadInt32(); var sbspVirtualAddress = bin.ReadInt32(); var ltmpVirtualAddress = bin.ReadInt32(); var sbsp = bin.ReadTagClass(); var hasLightmapData = !TagIdent.IsNull(ltmpIdentifier); var sbspLength = hasLightmapData ? ltmpVirtualAddress - sbspVirtualAddress : blockLength; var ltmpLength = blockLength - sbspLength; Tags[sbspIdentifier.Index].VirtualAddress = sbspVirtualAddress; Tags[sbspIdentifier.Index].Length = sbspLength; if (hasLightmapData) { Tags[ltmpIdentifier.Index].VirtualAddress = ltmpVirtualAddress; Tags[ltmpIdentifier.Index].Length = ltmpLength; } } ////UNICODE //this.Seek(Tags[GlobalsID.Index].VirtualAddress - SecondaryMagic + 400, SeekOrigin.Begin); //int unicodeCount = bin.ReadInt32(); //int unicodeTableLength = bin.ReadInt32(); //int unicodeIndexAddress = bin.ReadInt32(); //int unicodeTableAddress = bin.ReadInt32(); //Unicode = new UnicodeValueNamePair[unicodeCount]; //StringID[] strRefs = new StringID[unicodeCount]; //int[] strOffsets = new int[unicodeCount]; //this.Seek(unicodeIndexAddress, SeekOrigin.Begin); //for (int i = 0; i < unicodeCount; i++) //{ // strRefs[i] = (StringID)bin.ReadInt32(); // strOffsets[i] = bin.ReadInt32(); //} //for (int i = 0; i < unicodeCount; i++) //{ // this.Seek(unicodeTableAddress + strOffsets[i], SeekOrigin.Begin); // StringBuilder unicodeString = new StringBuilder(byte.MaxValue); // while (bin.PeekChar() != char.MinValue) // unicodeString.Append(bin.ReadChar()); // Unicode[i] = new UnicodeValueNamePair { Name = strRefs[i], Value = unicodeString.ToString() }; //} } this.deserializedTags = new Dictionary <TagIdent, dynamic>(this.Tags.Length); this.hashTags = new Dictionary <TagIdent, string>(this.Tags.Length); Halo2.ActiveMap(this); }
public CacheStream(string filename) : base(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8 * 1024) { //HEADER var binaryReader = new BinaryReader(this, Encoding.UTF8); Header = CacheHeader.DeserializeFrom(this); base.Seek(Header.PathsInfo.PathTableAddress, SeekOrigin.Begin); var paths = Encoding.UTF8.GetString(binaryReader.ReadBytes(Header.PathsInfo.PathTableLength - 1)).Split(Char.MinValue); //Halo2.Paths.Assign(paths); //STRINGS base.Seek(Header.StringsInfo.StringTableAddress, SeekOrigin.Begin); Strings = Encoding.UTF8.GetString(binaryReader.ReadBytes(Header.StringsInfo.StringTableLength - 1)).Split(Char.MinValue); Halo2.Strings.Assign(new List <string>(Strings)); // INDEX base.Seek(Header.IndexInfo.IndexOffset, SeekOrigin.Begin); Index = new TagIndex(this, paths); // Calculate File-pointer magic var secondaryMagic = Index[Index.GlobalsIdent].VirtualAddress - (Header.IndexInfo.IndexOffset + Header.IndexInfo.IndexLength); DefaultMemoryBlock = new VirtualMappedAddress { Address = Index[0].VirtualAddress, Length = Header.IndexInfo.MetaAllocationLength, Magic = secondaryMagic }; /* Intent: read the sbsp and lightmap address and lengths from the scenario tag * and store them in the Tags array. */ base.Seek(Index[Index.ScenarioIdent].VirtualAddress - secondaryMagic + 528, SeekOrigin.Begin); var count = binaryReader.ReadInt32(); var address = binaryReader.ReadInt32(); StructureMemoryBlockBindings = new Dictionary <TagIdent, int>(count * 2); StructureMemoryBlocks = new List <VirtualMappedAddress>(count); for (var i = 0; i < count; ++i) { base.Seek(address - secondaryMagic + i * 68, SeekOrigin.Begin); var structureBlockOffset = binaryReader.ReadInt32(); var structureBlockLength = binaryReader.ReadInt32(); var structureBlockAddress = binaryReader.ReadInt32(); base.Seek(8, SeekOrigin.Current); var sbspIdentifier = binaryReader.ReadTagIdent(); base.Seek(4, SeekOrigin.Current); var ltmpIdentifier = binaryReader.ReadTagIdent(); base.Seek(structureBlockOffset, SeekOrigin.Begin); var blockLength = binaryReader.ReadInt32(); var sbspVirtualAddress = binaryReader.ReadInt32(); var ltmpVirtualAddress = binaryReader.ReadInt32(); var sbsp = binaryReader.ReadTagClass(); var hasLightmapData = !TagIdent.IsNull(ltmpIdentifier); var sbspLength = hasLightmapData ? ltmpVirtualAddress - sbspVirtualAddress : blockLength; var ltmpLength = blockLength - sbspLength; var block = new VirtualMappedAddress { Address = structureBlockAddress, Length = structureBlockLength, Magic = structureBlockAddress - structureBlockOffset }; var sbspDatum = Index[sbspIdentifier]; sbspDatum.VirtualAddress = sbspVirtualAddress; sbspDatum.Length = sbspLength; Index.Update(sbspIdentifier, sbspDatum); StructureMemoryBlocks.Add(block); var index = StructureMemoryBlocks.Count - 1; StructureMemoryBlockBindings[sbspIdentifier] = index; if (hasLightmapData) { var ltmpDatum = Index[ltmpIdentifier]; ltmpDatum.VirtualAddress = ltmpVirtualAddress; ltmpDatum.Length = ltmpLength; Index.Update(ltmpIdentifier, ltmpDatum); StructureMemoryBlockBindings[ltmpIdentifier] = index; } ActiveAllocation(StructureCache.VirtualStructureCache0); } _deserializedTagCache = new Dictionary <TagIdent, GuerillaBlock>(Index.Count); _tagHashDictionary = new Dictionary <TagIdent, string>(Index.Count); Initialize(); }
void IField.SetFieldData(byte[] field_data, IStructure caller) { tag_class = (TagClass)BitConverter.ToInt32(field_data, 0); tag_identifier = BitConverter.ToInt32(field_data, 4); }
internal void Remove(TagIdent item) { this.objects.Remove(item); }
public T Deserialize <T>(TagIdent ident) where T : GuerillaBlock { return(( T )items[ident]); }
internal void Remove(TagIdent item) { this.objectInstances.Remove(item); }
public TagGlobalKey(CacheKey cacheKey, TagIdent tagKey) { CacheKey = cacheKey; TagKey = tagKey; }
public string GetTagHash(TagIdent ident) { return(_tagHashDictionary.ContainsKey(ident) ? _tagHashDictionary[ident] : null); }