public static Sector Read(EndianBinaryReader reader, Pointer offset, SuperObject so) { MapLoader l = MapLoader.Loader; Sector sect = new Sector(offset, so); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); Pointer off_lights_first = Pointer.Read(reader); if (l.mode != MapLoader.Mode.RaymanArenaGC) { Pointer off_lights_last = Pointer.Read(reader); } uint num_lights = reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); Pointer off_neighbor_first = Pointer.Read(reader); if (l.mode != MapLoader.Mode.RaymanArenaGC) { Pointer off_subsector_last = Pointer.Read(reader); } uint num_neighbors = reader.ReadUInt32(); reader.ReadUInt32(); if (l.mode != MapLoader.Mode.RaymanArenaGC) { reader.ReadUInt32(); } reader.ReadUInt32(); Pointer off_subsector_unk_first = Pointer.Read(reader); if (l.mode != MapLoader.Mode.RaymanArenaGC) { Pointer off_subsector_unk_last = Pointer.Read(reader); } uint num_subsectors_unk = reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); float minPoint_x = reader.ReadSingle(); float minPoint_z = reader.ReadSingle(); float minPoint_y = reader.ReadSingle(); float maxPoint_x = reader.ReadSingle(); float maxPoint_z = reader.ReadSingle(); float maxPoint_y = reader.ReadSingle(); sect.minBorder = new Vector3(minPoint_x, minPoint_y, minPoint_z); sect.maxBorder = new Vector3(maxPoint_x, maxPoint_y, maxPoint_z); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadByte(); if (l.mode == MapLoader.Mode.Rayman3GC) { sect.name = new string(reader.ReadChars(0x104)); l.print(sect.name); } if (num_lights > 0 && off_lights_first != null) { if (l.mode == MapLoader.Mode.RaymanArenaGC) { Pointer.Goto(ref reader, off_lights_first); for (int i = 0; i < num_lights; i++) { Pointer off_light = Pointer.Read(reader); if (off_light != null) { Pointer off_current = Pointer.Goto(ref reader, off_light); LightInfo r3l = LightInfo.Read(reader, off_light); if (r3l != null) { sect.sectorLights.Add(r3l); r3l.containingSectors.Add(sect); /*Light l = r3l.Light; * if (l != null) { * l.transform.parent = gao.transform; * }*/ } Pointer.Goto(ref reader, off_current); } } } else { Pointer off_lights_next = off_lights_first; for (int i = 0; i < num_lights; i++) { Pointer.Goto(ref reader, off_lights_next); //reader.ReadUInt32(); Pointer off_light = Pointer.Read(reader); off_lights_next = Pointer.Read(reader); if (l.mode == MapLoader.Mode.Rayman3GC) { Pointer off_lights_prev = Pointer.Read(reader); Pointer off_lights_header = Pointer.Read(reader); // points back to the pos in the header where off_lights first and last are defined } if (off_light != null) { Pointer.Goto(ref reader, off_light); LightInfo r3l = LightInfo.Read(reader, off_light); if (r3l != null) { sect.sectorLights.Add(r3l); r3l.containingSectors.Add(sect); /*Light l = r3l.Light; * if (l != null) { * l.transform.parent = gao.transform; * }*/ } } } } } if (num_neighbors > 0 && off_neighbor_first != null) { Pointer off_neighbor_next = off_neighbor_first; for (int i = 0; i < num_neighbors; i++) { Pointer.Goto(ref reader, off_neighbor_next); reader.ReadUInt16(); reader.ReadUInt16(); Pointer off_neighbor = Pointer.Read(reader); if (l.mode == MapLoader.Mode.RaymanArenaGC) { off_neighbor_next += 8; // We just read 8 bytes } else { off_neighbor_next = Pointer.Read(reader); } if (l.mode == MapLoader.Mode.Rayman3GC) { Pointer off_neighbor_prev = Pointer.Read(reader); Pointer off_sector_start = Pointer.Read(reader); } if (off_neighbor != null) { sect.neighborsPointers.Add(off_neighbor); } } } /*if(num_subsectors_unk > 0 && off_subsector_unk_first != null) { // only for father sector * R3Pointer off_subsector_next = off_subsector_unk_first; * for (int i = 0; i < num_subsectors_unk; i++) { * R3Pointer.Goto(ref reader, off_subsector_next); * R3Pointer off_subsector = R3Pointer.Read(reader); * off_subsector_next = R3Pointer.Read(reader); * R3Pointer off_subsector_prev = R3Pointer.Read(reader); * R3Pointer off_sector_start = R3Pointer.Read(reader); * if (off_subsector != null) { * sect.neighborsPointers.Add(off_subsector); * } * } * }*/ l.sectors.Add(sect); return(sect); }
public static Sector Read(Reader reader, Pointer offset, SuperObject so) { MapLoader l = MapLoader.Loader; Sector s = new Sector(offset, so); s.name = "Sector @ " + offset + ", SPO @ " + so.offset; //l.print(s.name); if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { if (Settings.s.game == Settings.Game.TTSE) { reader.ReadUInt32(); // always 1 or 0. whether the sector is active or not? } Pointer off_collideObj = Pointer.Read(reader); Pointer.DoAt(ref reader, off_collideObj, () => { //CollideMeshObject collider = CollideMeshObject.Read(reader, off_collideObj); // This has the exact same structure as a CollideMeshObject but with a sector superobject as material for the collieMeshElements }); LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); // "environments list" LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); // "surface list" } s.persos = LinkedList <Perso> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); s.staticLights = LinkedList <LightInfo> .Read(ref reader, Pointer.Current(reader), (off_element) => { LightInfo li = LightInfo.Read(reader, off_element); if (li != null) { li.containingSectors.Add(s); } return(li); }, flags : LinkedList.Flags.ElementPointerFirst | LinkedList.Flags.ReadAtPointer | ((Settings.s.hasLinkedListHeaderPointers) ? LinkedList.Flags.HasHeaderPointers : LinkedList.Flags.NoPreviousPointersForDouble), type : LinkedList.Type.Minimize ); s.dynamicLights = LinkedList <int> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Double); if (Settings.s.engineVersion <= Settings.EngineVersion.Montreal) { LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // "streams list", probably related to water } s.neighbors = LinkedList <NeighborSector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize); s.sectors_unk1 = LinkedList <NeighborSector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize); s.sectors_unk2 = LinkedList <Sector> .ReadHeader(reader, Pointer.Current(reader), type : LinkedList.Type.Minimize); LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // Placeholder LinkedList <int> .ReadHeader(reader, Pointer.Current(reader)); // Placeholder if (Settings.s.engineVersion > Settings.EngineVersion.Montreal) { s.sectorBorder = BoundingVolume.Read(reader, Pointer.Current(reader), BoundingVolume.Type.Box); reader.ReadUInt32(); if (Settings.s.game == Settings.Game.R2Revolution || Settings.s.game == Settings.Game.LargoWinch) { s.isSectorVirtual = reader.ReadByte(); reader.ReadByte(); s.sectorPriority = reader.ReadByte(); reader.ReadByte(); } else { s.isSectorVirtual = reader.ReadByte(); reader.ReadByte(); reader.ReadByte(); s.sectorPriority = reader.ReadByte(); if (Settings.s.engineVersion <= Settings.EngineVersion.R2) { s.off_skyMaterial = Pointer.Read(reader); s.skyMaterial = VisualMaterial.FromOffsetOrRead(s.off_skyMaterial, reader); } else { reader.ReadUInt32(); } reader.ReadByte(); if (Settings.s.hasNames) { s.name = reader.ReadString(0x104); l.print(s.name); } } } else { if (Settings.s.engineVersion == Settings.EngineVersion.Montreal) { reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); reader.ReadUInt32(); } if (Settings.s.game != Settings.Game.TTSE) { reader.ReadUInt32(); } Pointer off_name = Pointer.Read(reader); Pointer.DoAt(ref reader, off_name, () => { s.name = reader.ReadNullDelimitedString() + " @ " + offset; }); } /*if(num_subsectors_unk > 0 && off_subsector_unk_first != null) { // only for father sector * R3Pointer off_subsector_next = off_subsector_unk_first; * for (int i = 0; i < num_subsectors_unk; i++) { * R3Pointer.Goto(ref reader, off_subsector_next); * R3Pointer off_subsector = R3Pointer.Read(reader); * off_subsector_next = R3Pointer.Read(reader); * R3Pointer off_subsector_prev = R3Pointer.Read(reader); * R3Pointer off_sector_start = R3Pointer.Read(reader); * if (off_subsector != null) { * sect.neighborsPointers.Add(off_subsector); * } * } * }*/ l.sectors.Add(s); return(s); }
public static SetupModel ReadFromDat(uint fileId) { // Check the FileCache so we don't need to hit the FileSystem repeatedly if (DatManager.PortalDat.FileCache.ContainsKey(fileId)) { return((SetupModel)DatManager.PortalDat.FileCache[fileId]); } else { DatReader datReader = DatManager.PortalDat.GetReaderForFile(fileId); SetupModel m = new SetupModel(); m.ModelId = datReader.ReadUInt32(); m.Bitfield = datReader.ReadUInt32(); // Get all the GraphicsObjects in this SetupModel. These are all the 01-types. uint numParts = datReader.ReadUInt32(); for (int i = 0; i < numParts; i++) { m.Parts.Add(datReader.ReadUInt32()); } if ((m.Bitfield & 1) > 0) { for (int i = 0; i < numParts; i++) { m.ParentIndex.Add(datReader.ReadUInt32()); } } if ((m.Bitfield & 2) > 0) { for (int i = 0; i < numParts; i++) { m.DefaultScale.Add(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle())); } } int numHoldingLocations = datReader.ReadInt32(); if (numHoldingLocations > 0) { for (int i = 0; i < numHoldingLocations; i++) { int key = datReader.ReadInt32(); m.HoldingLocations.Add(key, LocationType.Read(datReader)); } } int numConnectionPoints = datReader.ReadInt32(); if (numConnectionPoints > 0) { for (int i = 0; i < numConnectionPoints; i++) { int key = datReader.ReadInt32(); m.ConnectionPoints.Add(key, LocationType.Read(datReader)); } } int placementsCount = datReader.ReadInt32(); for (int i = 0; i < placementsCount; i++) { int key = datReader.ReadInt32(); // there is a frame for each Part m.PlacementFrames.Add(key, PlacementType.Read(m.Parts.Count, datReader)); } int cylinderSphereCount = datReader.ReadInt32(); for (int i = 0; i < cylinderSphereCount; i++) { // Sphere is a Vector3 origin + float radius AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()); m.CylSpheres.Add(new CylSphere(origin, datReader.ReadSingle(), datReader.ReadSingle())); } int sphereCount = datReader.ReadInt32(); for (int i = 0; i < sphereCount; i++) { // Sphere is a Vector3 origin + float radius AceVector3 origin = new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()); m.Spheres.Add(new CSphere(origin, datReader.ReadSingle())); } m.Height = datReader.ReadSingle(); m.Radius = datReader.ReadSingle(); m.StepDownHeight = datReader.ReadSingle(); m.StepUpHeight = datReader.ReadSingle(); m.SortingSphere = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle()); m.SelectionSphere = new CSphere(new AceVector3(datReader.ReadSingle(), datReader.ReadSingle(), datReader.ReadSingle()), datReader.ReadSingle()); int numLights = datReader.ReadInt32(); if (numLights > 0) { for (int i = 0; i < numLights; i++) { int key = datReader.ReadInt32(); m.Lights.Add(key, LightInfo.Read(datReader)); } } m.DefaultAnimation = datReader.ReadUInt32(); m.DefaultScript = datReader.ReadUInt32(); m.DefaultMotionTable = datReader.ReadUInt32(); m.DefaultSoundTable = datReader.ReadUInt32(); m.DefaultScriptTable = datReader.ReadUInt32(); // Store this object in the FileCache DatManager.PortalDat.FileCache[fileId] = m; return(m); } }