Пример #1
0
 public void Visit(OsirisType type)
 {
     writer.WriteStartObject();
     writer.WritePropertyName("name");
     writer.WriteValue(type.Name);
     writer.WriteEndObject();
 }
Пример #2
0
        public static OsirisType MakeBuiltin(byte index, string name)
        {
            var type = new OsirisType();

            type.Index     = index;
            type.Alias     = 0;
            type.Name      = name;
            type.IsBuiltin = true;
            return(type);
        }
Пример #3
0
        private Dictionary <uint, OsirisType> ReadTypes(OsiReader reader)
        {
            var types = new Dictionary <uint, OsirisType>();
            var count = reader.ReadUInt32();

            while (count-- > 0)
            {
                var type = new OsirisType();
                type.Read(reader);
                types.Add(type.Index, type);
            }

            return(types);
        }
Пример #4
0
        public Story Read(Stream stream)
        {
            var story = new Story();

            using (var reader = new OsiReader(stream, story))
            {
                var header = new SaveFileHeader();
                header.Read(reader);
                reader.MinorVersion = header.MinorVersion;
                reader.MajorVersion = header.MajorVersion;
                story.MinorVersion  = header.MinorVersion;
                story.MajorVersion  = header.MajorVersion;

                if (reader.Ver > OsiVersion.VerLastSupported)
                {
                    var msg = String.Format(
                        "Osiris version v{0}.{1} unsupported; this tool supports loading up to version 1.12.",
                        reader.MajorVersion, reader.MinorVersion
                        );
                    throw new InvalidDataException(msg);
                }

                if (reader.Ver >= OsiVersion.VerScramble)
                {
                    reader.Scramble = 0xAD;
                }

                if (reader.Ver >= OsiVersion.VerAddTypeMap)
                {
                    story.Types = ReadTypes(reader);
                    foreach (var type in story.Types)
                    {
                        if (type.Value.Alias != 0)
                        {
                            reader.TypeAliases.Add(type.Key, type.Value.Alias);
                        }
                    }
                }
                else
                {
                    story.Types = new Dictionary <uint, OsirisType>();
                }

                if (reader.Ver >= OsiVersion.VerExternalStringTable && reader.Ver < OsiVersion.VerRemoveExternalStringTable)
                {
                    story.ExternalStringTable = ReadStrings(reader);
                }
                else
                {
                    story.ExternalStringTable = new List <string>();
                }

                story.Types[0] = OsirisType.MakeBuiltin(0, "UNKNOWN");
                story.Types[1] = OsirisType.MakeBuiltin(1, "INTEGER");

                if (reader.Ver >= OsiVersion.VerEnhancedTypes)
                {
                    story.Types[2] = OsirisType.MakeBuiltin(2, "INTEGER64");
                    story.Types[3] = OsirisType.MakeBuiltin(3, "REAL");
                    story.Types[4] = OsirisType.MakeBuiltin(4, "STRING");
                    story.Types[5] = OsirisType.MakeBuiltin(5, "GUIDSTRING");
                }
                else
                {
                    story.Types[2] = OsirisType.MakeBuiltin(2, "FLOAT");
                    story.Types[3] = OsirisType.MakeBuiltin(3, "STRING");
                }

                story.DivObjects    = reader.ReadList <OsirisDivObject>();
                story.Functions     = reader.ReadList <Function>();
                story.Nodes         = ReadNodes(reader);
                story.Adapters      = ReadAdapters(reader);
                story.Databases     = ReadDatabases(reader);
                story.Goals         = ReadGoals(reader, story);
                story.GlobalActions = reader.ReadList <Call>();

                foreach (var node in story.Nodes)
                {
                    node.Value.PostLoad(story);
                }

                return(story);
            }
        }
Пример #5
0
        public Story Read(Stream stream)
        {
            var story = new Story();

            using (var reader = new OsiReader(stream, story))
            {
                var header = new SaveFileHeader();
                header.Read(reader);
                reader.MinorVersion = header.MinorVersion;
                reader.MajorVersion = header.MajorVersion;
                story.MinorVersion  = header.MinorVersion;
                story.MajorVersion  = header.MajorVersion;

                if (reader.Ver > OsiVersion.VerLastSupported)
                {
                    var msg = String.Format(
                        "Osiris version v{0}.{1} unsupported; this tool supports loading up to version 1.12.",
                        reader.MajorVersion, reader.MinorVersion
                        );
                    throw new InvalidDataException(msg);
                }

                if (reader.Ver >= OsiVersion.VerScramble)
                {
                    reader.Scramble = 0xAD;
                }

                story.Types = ReadTypes(reader, story);

                if (reader.Ver >= OsiVersion.VerExternalStringTable && reader.Ver < OsiVersion.VerRemoveExternalStringTable)
                {
                    story.ExternalStringTable = ReadStrings(reader);
                }
                else
                {
                    story.ExternalStringTable = new List <string>();
                }

                story.Types[0] = OsirisType.MakeBuiltin(0, "UNKNOWN");
                story.Types[1] = OsirisType.MakeBuiltin(1, "INTEGER");

                if (reader.Ver >= OsiVersion.VerEnhancedTypes)
                {
                    story.Types[2] = OsirisType.MakeBuiltin(2, "INTEGER64");
                    story.Types[3] = OsirisType.MakeBuiltin(3, "REAL");
                    story.Types[4] = OsirisType.MakeBuiltin(4, "STRING");
                    // BG3 defines GUIDSTRING in the .osi file
                    if (!story.Types.ContainsKey(5))
                    {
                        story.Types[5] = OsirisType.MakeBuiltin(5, "GUIDSTRING");
                    }
                }
                else
                {
                    story.Types[2] = OsirisType.MakeBuiltin(2, "FLOAT");
                    story.Types[3] = OsirisType.MakeBuiltin(3, "STRING");

                    // Populate custom type IDs for versions that had no type alias map
                    if (reader.Ver < OsiVersion.VerAddTypeMap)
                    {
                        for (byte typeId = 4; typeId <= 17; typeId++)
                        {
                            story.Types[typeId]       = OsirisType.MakeBuiltin(typeId, $"TYPE{typeId}");
                            story.Types[typeId].Alias = 3;
                            reader.TypeAliases.Add(typeId, 3);
                        }
                    }
                }

                story.DivObjects    = reader.ReadList <OsirisDivObject>();
                story.Functions     = reader.ReadList <Function>();
                story.Nodes         = ReadNodes(reader);
                story.Adapters      = ReadAdapters(reader);
                story.Databases     = ReadDatabases(reader);
                story.Goals         = ReadGoals(reader, story);
                story.GlobalActions = reader.ReadList <Call>();

                story.FunctionSignatureMap = new Dictionary <string, Function>();
                foreach (var func in story.Functions)
                {
                    story.FunctionSignatureMap.Add(func.Name.Name + "/" + func.Name.Parameters.Types.Count.ToString(), func);
                }

                foreach (var node in story.Nodes)
                {
                    node.Value.PostLoad(story);
                }

                return(story);
            }
        }