private void SaveRoomTable(List <SerializableDOMNode> entries, EndianBinaryWriter writer)
        {
            int base_offset = (int)writer.BaseStream.Position;

            foreach (var entry in entries)
            {
                writer.Write((int)0); // Placeholders for entry offsets
            }

            writer.Seek(base_offset, SeekOrigin.Begin);

            int first_entry_offset = (int)writer.BaseStream.Length;

            foreach (var entry in entries)
            {
                writer.Write((int)writer.BaseStream.Length);
                writer.Seek(0, SeekOrigin.End);

                entry.Save(writer);

                base_offset += 4;

                writer.Seek(base_offset, SeekOrigin.Begin);
            }

            writer.Seek(first_entry_offset, SeekOrigin.Begin);

            foreach (var entry in entries)
            {
                RoomTableEntryNode node = entry as RoomTableEntryNode;
                node.WriteLoadedRoomTable(writer);
            }

            writer.Seek(0, SeekOrigin.End);
        }
Пример #2
0
        public List <WDOMNode> GetMapEntities()
        {
            var loadedActors = new List <WDOMNode>();

            foreach (var chunk in m_chunkList)
            {
                m_reader.BaseStream.Position = chunk.ChunkOffset;
                MapActorDescriptor template = Globals.ActorDescriptors.Find(x => x.FourCC == chunk.FourCC);
                if (template == null)
                {
                    Console.WriteLine("Unsupported FourCC: {0}", chunk.FourCC);
                    continue;
                }

                switch (chunk.FourCC)
                {
                // Don't turn these into map actors, as they will be handled elsewhere.
                //case "RTBL":
                case FourCC.MECO:
                case FourCC.MEMA:
                    break;

                case FourCC.SCOB:
                case FourCC.SCO0:
                case FourCC.SCO1:
                case FourCC.SCO2:
                case FourCC.SCO3:
                case FourCC.SCO4:
                case FourCC.SCO5:
                case FourCC.SCO6:
                case FourCC.SCO7:
                case FourCC.SCO8:
                case FourCC.SCO9:
                case FourCC.SCOa:
                case FourCC.SCOb:
                case FourCC.TGSC:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        // We need to read the entity name so we can load the right derived class for it
                        string entity_name = Encoding.ASCII.GetString(m_reader.PeekReadBytes(8)).Trim('\0');

                        Type actorType             = WResourceManager.GetTypeByName(entity_name);
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);

                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        entity.Transform.LocalScale = new Vector3(m_reader.ReadByte() / 10f, m_reader.ReadByte() / 10f, m_reader.ReadByte() / 10f);
                        int padding = m_reader.ReadByte();

                        loadedActors.Add(entity);
                    }
                    break;

                case FourCC.ACTR:
                case FourCC.ACT0:
                case FourCC.ACT1:
                case FourCC.ACT2:
                case FourCC.ACT3:
                case FourCC.ACT4:
                case FourCC.ACT5:
                case FourCC.ACT6:
                case FourCC.ACT7:
                case FourCC.ACT8:
                case FourCC.ACT9:
                case FourCC.ACTa:
                case FourCC.ACTb:
                case FourCC.TGOB:
                case FourCC.TGDR:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        // We need to read the entity name so we can load the right derived class for it
                        string entity_name = Encoding.ASCII.GetString(m_reader.PeekReadBytes(8)).Trim('\0');

                        Type actorType             = WResourceManager.GetTypeByName(entity_name);
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);

                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        loadedActors.Add(entity);
                    }
                    break;

                case FourCC.RTBL:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        int entry_offset = m_reader.ReadInt32();

                        int next_offset = (int)m_reader.BaseStream.Position;
                        m_reader.BaseStream.Seek(entry_offset, SeekOrigin.Begin);

                        RoomTableEntryNode rtbl_entry = new RoomTableEntryNode(chunk.FourCC, m_world, m_reader);
                        loadedActors.Add(rtbl_entry);

                        m_reader.BaseStream.Seek(next_offset, SeekOrigin.Begin);
                    }

                    break;

                default:
                    for (int i = 0; i < chunk.ElementCount; i++)
                    {
                        Type actorType             = Type.GetType($"WindEditor.{template.ClassName}");
                        SerializableDOMNode entity = (SerializableDOMNode)Activator.CreateInstance(actorType, chunk.FourCC, m_world);
                        entity.Load(m_reader);
                        entity.Layer = chunk.Layer;

                        loadedActors.Add(entity);
                    }
                    break;
                }
            }

            // var dict = new Dictionary<string, List<WDOMNode>>();
            // foreach(var actor in loadedActors)
            // {
            //     if (!dict.ContainsKey(actor.FourCC))
            //         dict[actor.FourCC] = new List<WDOMNode>();
            //     dict[actor.FourCC].Add(actor);
            // }
            //
            // string[] nodes = new[] { "EnvR", "Pale", "Virt", "Colo" };
            // foreach(var node in nodes)
            // {
            //     if (dict.ContainsKey(node))
            //         Console.WriteLine("{0} Count: {1}", node, dict[node].Count);
            //
            // }

            AssignPaths(loadedActors);

            return(loadedActors);
        }