Exemplo n.º 1
0
        /* Faction.loadFromSave */
        private static Faction LoadFaction(ElementInfo root)
        {
            Faction result;
            string  factionName = root.Attributes.GetValueOrDefault("name", "UNKNOWN");
            int     neededValue = root.Attributes.GetInt("neededVal", 100);

            switch (root.Name)
            {
            case "HubFaction":
                result = new HubFaction(factionName, neededValue);
                break;

            case "EntropyFaction":
                result = new EntropyFaction(factionName, neededValue);
                break;

            case "CustomFaction":
                CustomFaction faction;
                result = faction = new CustomFaction(factionName, 100);
                foreach (var child in root.Children.Where(e => e.Name == "Action"))
                {
                    var action = new CustomFactionAction
                    {
                        ValueRequiredForTrigger = child.Attributes.GetInt("ValueRequired", 10),
                        FlagsRequiredForTrigger = child.Attributes.GetValueOrDefault("Flags", null)
                    };
                    foreach (var info in child.Children)
                    {
                        action.TriggerActions.Add(ActionsLoader.LoadAction(info));
                    }
                    faction.CustomActions.Add(action);
                }

                break;

            default:
                result = new Faction(factionName, neededValue);
                break;
            }

            result.playerValue          = root.Attributes.GetInt("playerVal", 0);
            result.idName               = root.Attributes.GetValueOrDefault("id", "");
            result.playerHasPassedValue = root.Attributes.GetBool("playerHasPassed");

            return(result);
        }
Exemplo n.º 2
0
        public static void LoadSaveFile(Stream stream, OS os)
        {
            var reader       = new StreamReader(stream);
            var saveFileText = reader.ReadToEnd();


            if (string.IsNullOrEmpty(saveFileText))
            {
                throw new FormatException("Blank account data detected! (This is a vanilla saving issue)");
            }

            var executor    = new EventExecutor(saveFileText, isPath: false);
            var subExecutor = new ParsedTreeExecutor();

            executor.AddExecutor("HacknetSave", (exec, info) =>
            {
                /* OS.loadTitleSaveData */
                MissionGenerator.generationCount = info.Attributes.GetInt("generatedMissionCount", 100);
                os.defaultUser.name  = os.username = info.Attributes.GetValue("Username");
                os.LanguageCreatedIn = info.Attributes.GetValueOrDefault("Language", "en-us");
                os.IsInDLCMode       = info.Attributes.GetBool("DLCMode") && Util.Extensions.CheckLabyrinths();
                os.DisableEmailIcon  = info.Attributes.GetBool("DisableMailIcon") && Util.Extensions.CheckLabyrinths();
            });

            /* OS.LoadExtraTitleSaveData / OS.ReadDLCSaveData */
            executor.AddExecutor("HacknetSave.DLC", (exec, info) =>
            {
                os.IsInDLCMode   = info.Attributes.GetBool("Active");
                var hasLoadedDLC = os.HasLoadedDLCContent = info.Attributes.GetBool("LoadedContent");

                if (hasLoadedDLC)
                {
                    "This save".ThrowNoLabyrinths();
                }
            });

            executor.AddExecutor("HacknetSave.DLC.Flags", (exec, info) =>
                                 os.PreDLCFaction = info.Attributes.GetValue("OriginalFaction"));

            executor.AddExecutor("HacknetSave.DLC.OriginalVisibleNodes", (exec, info) =>
                                 os.PreDLCVisibleNodesCache = info.Value, true);

            executor.AddExecutor("HacknetSave.DLC.ConditionalActions",
                                 (exec, info) => { os.ConditionalActions = ActionsLoader.LoadConditionalActions(info); }, true);

            executor.AddExecutor("HacknetSave.Flags", (exec, info) =>
            {
                /* ProgressionFlags.Load */
                var flags = os.Flags;

                flags.Flags.Clear();
                if (info.Value == null)
                {
                    return;
                }
                foreach (var flag in info.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var trueFlag = flag.Replace("[%%COMMAREPLACED%%]", ",");
                    // ReSharper disable StringLiteralTypo
                    if (trueFlag == "décrypté")
                    {
                        trueFlag = "decypher";
                    }
                    // ReSharper restore StringLiteralTypo
                    flags.AddFlag(trueFlag);
                }
            }, true);

            /* NetworkMap.load */

            executor.AddExecutor("HacknetSave.NetworkMap", (exec, info) =>
            {
                var sortAlgo = info.Attributes.GetValue("sort");
                if (!Enum.TryParse(sortAlgo, out os.netMap.SortingAlgorithm))
                {
                    /* TODO: Error reporting here */
                }

                subExecutor.Execute(info);

                foreach (var d in os.netMap.nodes.SelectMany(node => node.daemons))
                {
                    d.loadInit();
                }

                os.netMap.loadAssignGameNodes();
            }, true);

            executor.AddExecutor("HacknetSave.NetworkMap.visible", (exec, info) =>
            {
                var visibleNodes = info.Value;
                foreach (var node in visibleNodes.Split())
                {
                    os.netMap.visibleNodes.Add(Convert.ToInt32(node));
                }
            }, true);


            executor.AddExecutor("HacknetSave.NetworkMap.network.computer", (exec, info) =>
            {
                var computer = SaveLoader.LoadComputer(info, os);
                os.netMap.nodes.Add(computer);
            }, true);


            executor.AddExecutor("HacknetSave.mission",
                                 (exec, info) => { os.currentMission = SaveLoader.LoadMission(info); }, true);

            executor.AddExecutor("HacknetSave.AllFactions", (exec, info) =>
            {
                /* AllFactions.loadFromSave */
                var loadedFactions = new AllFactions();
                string curFac      = loadedFactions.currentFaction = info.Attributes.GetValue("current");
                foreach (var child in info.Children)
                {
                    Faction loaded = LoadFaction(child);
                    loadedFactions.factions.Add(loaded.idName, loaded);
                }

                os.allFactions = loadedFactions;
                if (curFac != "")
                {
                    os.currentFaction = loadedFactions.factions[curFac];
                }
            }, true);

            executor.AddExecutor("HacknetSave.other", (exec, info) =>
            {
                /* OS.loadOtherSaveData */
                MusicManager.playSongImmediatley(info.Attributes.GetValue("music"));
                os.homeNodeID        = info.Attributes.GetValueOrDefault("homeNode", "entropy00");
                os.homeAssetServerID = info.Attributes.GetValueOrDefault("homeAssetsNode", "entropy01");
            }, true);

            foreach (var exec in SaveDataLoaders)
            {
                executor.AddExecutor(exec.Key, exec.Value);
            }

            executor.OnOpenFile                   += OnOpenFile;
            executor.OnRead                       += OnRead;
            executor.OnReadElement                += OnReadElement;
            executor.OnReadEndElement             += OnReadEndElement;
            executor.OnReadDocument               += OnReadDocument;
            executor.OnReadComment                += OnReadComment;
            executor.OnReadText                   += OnReadText;
            executor.OnReadProcessingInstructions += OnReadProcessingInstructions;
            executor.OnCloseFile                  += OnCloseFile;

            executor.OnCloseFile += _ =>
            {
                OS.WillLoadSave     = false;
                os.FirstTimeStartup = false;
            };

            /* hook up child parser */
            subExecutor.delegateData = executor.delegateData;

            executor.Parse();
        }