public void Read(OsiReader reader) { Index = reader.ReadUInt32(); Name = reader.ReadString(); SubGoalCombination = reader.ReadByte(); ParentGoals = new List <uint>(); var numItems = reader.ReadUInt32(); while (numItems-- > 0) { ParentGoals.Add(reader.ReadUInt32()); } SubGoals = new List <uint>(); numItems = reader.ReadUInt32(); while (numItems-- > 0) { SubGoals.Add(reader.ReadUInt32()); } Unknown = reader.ReadByte(); if (reader.MajorVersion > 1 || (reader.MajorVersion == 1 && reader.MinorVersion >= 1)) { InitCalls = reader.ReadList <Call>(); ExitCalls = reader.ReadList <Call>(); } else { InitCalls = new List <Call>(); ExitCalls = new List <Call>(); } }
public void Read(OsiReader reader) { Parameters = new ParameterList(); Parameters.Read(reader); FactsPosition = reader.BaseStream.Position; Facts = new FactCollection(this); reader.ReadList <Fact>(Facts); }
public void Read(OsiReader reader) { Index = reader.ReadUInt32(); Name = reader.ReadString(); SubGoalCombination = reader.ReadByte(); ParentGoals = reader.ReadRefList <GoalReference, Goal>(); SubGoals = reader.ReadRefList <GoalReference, Goal>(); Flags = reader.ReadByte(); if (reader.Ver >= OsiVersion.VerAddInitExitCalls) { InitCalls = reader.ReadList <Call>(); ExitCalls = reader.ReadList <Call>(); } else { InitCalls = new List <Call>(); ExitCalls = new List <Call>(); } }
public override void Read(OsiReader reader) { base.Read(reader); Calls = reader.ReadList <Call>(); Variables = new List <Variable>(); var variables = reader.ReadByte(); while (variables-- > 0) { var type = reader.ReadByte(); if (type != 1) { throw new InvalidDataException("Illegal value type in rule variable list"); } var variable = new Variable(); variable.Read(reader); if (variable.Adapted) { variable.VariableName = String.Format("_Var{0}", Variables.Count + 1); } Variables.Add(variable); } Line = reader.ReadUInt32(); if (reader.Ver >= OsiVersion.VerAddQuery) { IsQuery = reader.ReadBoolean(); } else { IsQuery = false; } }
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); } }
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); } }
public override void Read(OsiReader reader) { base.Read(reader); ReferencedBy = reader.ReadList <NodeEntryItem>(); }
public Story Read(Stream stream) { using (var reader = new OsiReader(stream)) { var story = new Story(); var header = new OsirisHeader(); header.Read(reader); reader.MinorVersion = header.MinorVersion; reader.MajorVersion = header.MajorVersion; story.MinorVersion = header.MinorVersion; story.MajorVersion = header.MajorVersion; if (reader.MajorVersion > 1 || (reader.MajorVersion == 1 && reader.MinorVersion > 7)) { var msg = String.Format( "Osiris version v{0}.{1} unsupported; this tool supports versions up to v1.7.", reader.MajorVersion, reader.MinorVersion ); throw new InvalidDataException(msg); } if (reader.MajorVersion > 1 || (reader.MajorVersion == 1 && reader.MinorVersion >= 4)) { reader.Scramble = 0xAD; } if (reader.MajorVersion > 1 || (reader.MajorVersion == 1 && reader.MinorVersion >= 5)) { story.Types = ReadTypes(reader); } else { story.Types = new Dictionary <uint, OsirisType>(); } story.Types[0] = new OsirisType(); story.Types[0].Index = 0; story.Types[0].Name = "UNKNOWN"; story.Types[1] = new OsirisType(); story.Types[1].Index = 1; story.Types[1].Name = "INTEGER"; story.Types[2] = new OsirisType(); story.Types[2].Index = 2; story.Types[2].Name = "FLOAT"; story.Types[3] = new OsirisType(); story.Types[3].Index = 3; story.Types[3].Name = "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.GlobalActions = reader.ReadList <Call>(); foreach (var node in story.Nodes) { if (node.Value.DatabaseRef.IsValid()) { var database = story.Databases[node.Value.DatabaseRef.DatabaseIndex]; if (database.OwnerNode != null) { throw new InvalidDataException("A database cannot be assigned to multiple database nodes!"); } database.OwnerNode = node.Value; } if (node.Value is RuleNode) { // Remove the __DEF__ postfix that is added to the end of Query nodes var rule = node.Value as RuleNode; if (rule.IsQuery) { var ruleRoot = rule.GetRoot(story); if (ruleRoot.Name != null && ruleRoot.Name.Length > 7 && ruleRoot.Name.Substring(ruleRoot.Name.Length - 7) == "__DEF__") { ruleRoot.Name = ruleRoot.Name.Substring(0, ruleRoot.Name.Length - 7); } } } if (node.Value is DataNode) { var data = node.Value as DataNode; foreach (var reference in data.ReferencedBy) { if (reference.NodeRef.IsValid()) { var ruleNode = story.Nodes[reference.NodeRef.NodeIndex]; if (reference.GoalId > 0 && ruleNode is RuleNode) { (ruleNode as RuleNode).DerivedGoalId = reference.GoalId; } } } } if (node.Value is TreeNode) { var tree = node.Value as TreeNode; if (tree.NextNode.NodeRef.IsValid()) { var nextNode = story.Nodes[tree.NextNode.NodeRef.NodeIndex]; if (nextNode is RuleNode) { (nextNode as RuleNode).DerivedGoalId = tree.NextNode.GoalId; } } } if (node.Value is RelNode) { var rel = node.Value as RelNode; if (rel.AdapterRef.IsValid()) { var adapter = story.Adapters[rel.AdapterRef.AdapterIndex]; if (adapter.OwnerNode != null) { throw new InvalidDataException("An adapter cannot be assigned to multiple join/rel nodes!"); } adapter.OwnerNode = node.Value; } } else if (node.Value is JoinNode) { var join = node.Value as JoinNode; if (join.Adapter1Ref.IsValid()) { var adapter = story.Adapters[join.Adapter1Ref.AdapterIndex]; if (adapter.OwnerNode != null) { throw new InvalidDataException("An adapter cannot be assigned to multiple join/rel nodes!"); } adapter.OwnerNode = node.Value; } if (join.Adapter2Ref.IsValid()) { var adapter = story.Adapters[join.Adapter2Ref.AdapterIndex]; if (adapter.OwnerNode != null) { throw new InvalidDataException("An adapter cannot be assigned to multiple join/rel nodes!"); } adapter.OwnerNode = node.Value; } } } return(story); } }