Exemplo n.º 1
0
        private void LoadStory(Stream s)
        {
            var reader = new StoryReader();

            _story = reader.Read(s);

            databaseSelectorCb.Items.Clear();
            foreach (KeyValuePair <uint, Database> database in _story.Databases)
            {
                var  name  = "(Unnamed)";
                Node owner = database.Value.OwnerNode;
                if (owner != null)
                {
                    name = owner.Name.Length > 0 ? $"{owner.Name}({owner.NumParams})" : $"<{owner.TypeName()}>";
                }

                name += $" #{database.Key} ({database.Value.Facts.Count} rows)";

                databaseSelectorCb.Items.Add(name);

                if (databaseSelectorCb.Items.Count > 0)
                {
                    databaseSelectorCb.SelectedIndex = 0;
                }
            }
        }
Exemplo n.º 2
0
        private static Story LoadStory(String path)
        {
            string extension = Path.GetExtension(path).ToLower();

            Stream storyStream;

            switch (extension)
            {
            case ".lsv":
                storyStream = LoadStoryStreamFromSave(path);
                break;

            case ".osi":
                storyStream = LoadStoryStreamFromFile(path);
                break;

            default:
                throw new Exception($"Unsupported story/save extension: {extension}");
            }

            using (storyStream)
            {
                var reader = new StoryReader();
                return(reader.Read(storyStream));
            }
        }
Exemplo n.º 3
0
        private void loadStoryBtn_Click(object sender, EventArgs e)
        {
            using (var file = new FileStream(storyFilePath.Text, FileMode.Open, FileAccess.Read))
            {
                var reader = new StoryReader();
                Story = reader.Read(file);

                databaseSelectorCb.Items.Clear();
                foreach (var database in Story.Databases)
                {
                    var name  = "(Unnamed)";
                    var owner = database.Value.OwnerNode;
                    if (owner != null && owner.Name.Length > 0)
                    {
                        name = String.Format("{0}/{1}", owner.Name, owner.NameIndex);
                    }
                    else if (owner != null)
                    {
                        name = String.Format("<{0}>", owner.TypeName());
                    }

                    name += String.Format(" #{0} ({1} rows)", database.Key, database.Value.Facts.Count);

                    databaseSelectorCb.Items.Add(name);
                }
            }
        }
Exemplo n.º 4
0
        static void DebugDump(string storyPath, string debugPath)
        {
            Story story;

            using (var file = new FileStream(storyPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var reader = new StoryReader();
                story = reader.Read(file);
            }

            using (var debugFile = new FileStream(debugPath, FileMode.Create, FileAccess.Write))
            {
                using (var writer = new StreamWriter(debugFile))
                {
                    story.DebugDump(writer);
                }
            }
        }
Exemplo n.º 5
0
        private void RunTasks()
        {
            if (ExtractAll)
            {
                DoExtractPackage();
            }

            if (ConvertToLsx)
            {
                DoLsxConversion();
            }

            FileManager.TryToCreateDirectory(Path.Combine(DataDumpPath, "Dummy"));

            ReportProgress(50, "Loading meta.lsf ...");
            SaveMeta = LoadPackagedResource("meta.lsf");

            ReportProgress(52, "Loading globals.lsf ...");
            SaveGlobals = LoadPackagedResource("globals.lsf");

            ReportProgress(60, "Dumping mod list ...");
            if (DumpModList)
            {
                var modListPath = Path.Combine(DataDumpPath, "ModList.txt");
                DumpMods(modListPath);
            }

            ReportProgress(62, "Dumping variables ...");
            if (DumpGlobalVars)
            {
                var varsPath = Path.Combine(DataDumpPath, "GlobalVars.txt");
                DumpVariables(varsPath, true, false, false);
            }

            if (DumpCharacterVars)
            {
                var varsPath = Path.Combine(DataDumpPath, "CharacterVars.txt");
                DumpVariables(varsPath, false, true, false);
            }

            if (DumpItemVars)
            {
                var varsPath = Path.Combine(DataDumpPath, "ItemVars.txt");
                DumpVariables(varsPath, false, false, true);
            }

            ReportProgress(70, "Loading story ...");
            LSLib.LS.Node storyNode   = SaveGlobals.Regions["Story"].Children["Story"][0];
            var           storyStream = new MemoryStream(storyNode.Attributes["Story"].Value as byte[]);
            var           reader      = new StoryReader();

            SaveStory = reader.Read(storyStream);

            if (DumpStoryGoals)
            {
                DumpGoals();
            }

            if (DumpStoryDatabases)
            {
                ReportProgress(90, "Dumping databases ...");
                var dbDumpPath = Path.Combine(DataDumpPath, "Databases.txt");
                using (var dbDumpStream = new FileStream(dbDumpPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    var dbDumper = new DatabaseDumper(dbDumpStream);
                    dbDumper.DumpUnnamedDbs = IncludeUnnamedDatabases;
                    dbDumper.DumpAll(SaveStory);
                }
            }

            ReportProgress(100, "");
        }