internal static void CacheDisplayStringForThemeSwitch(object osObject)
        {
            var os = (OS)osObject;

            if (os.displayCache == null || lastFileData == null || (os.display.command != "cat" && os.display.command != "less"))
            {
                return;
            }

            if (isFlickering)
            {
                if (displayCache2 == null)
                {
                    displayCache2 = os.displayCache;

                    os.displayCache = Utils.SuperSmartTwimForWidth(LocalizedFileLoader.SafeFilterString(lastFileData), os.display.bounds.Width - 40, GuiData.tinyfont);
                }
                else
                {
                    var temp = displayCache2;
                    displayCache2   = os.displayCache;
                    os.displayCache = temp;
                }
            }
            else
            {
                os.displayCache = Utils.SuperSmartTwimForWidth(LocalizedFileLoader.SafeFilterString(lastFileData), os.display.bounds.Width - 40, GuiData.tinyfont);
            }

            isFlickering = false;
        }
예제 #2
0
        public static CustomFaction ParseFromFile(string filepath)
        {
            CustomFaction customFaction;

            using (FileStream fileStream = File.OpenRead(LocalizedFileLoader.GetLocalizedFilepath(filepath)))
                customFaction = Faction.loadFromSave(XmlReader.Create((Stream)fileStream)) as CustomFaction;
            return(customFaction);
        }
예제 #3
0
        public static Computer LoadComputer(string filename, bool preventAddingToNetmap = false, bool preventInitDaemons = false)
        {
            filename = LocalizedFileLoader.GetLocalizedFilepath(filename);

            os = OS.currentInstance;

            executor.SetText(filename, true);

            holder = new ComputerHolder();

            foreach (var custom in CustomExecutors)
            {
                var customInstance = (ComputerExecutor)Activator.CreateInstance(custom.ExecutorType);
                customInstance.Init(os, ref holder);
                executor.RegisterTempExecutor(custom.Element, customInstance.Execute, custom.Options);
            }

            foreach (var customDaemon in DaemonManager.CustomDaemons)
            {
                executor.RegisterTempExecutor("Computer." + customDaemon.Name, (exec, info) =>
                {
                    DaemonManager.TryLoadCustomDaemon(info, comp, os);
                });
            }

            if (!executor.TryParse(out var ex))
            {
                throw new FormatException($"{filename}: {ex.Message}", ex);
            }

            var ret = comp;

            comp = null;

            if (ret == null)
            {
                return(null);
            }

            if (!preventInitDaemons)
            {
                ret.initDaemons();
            }
            if (!preventAddingToNetmap)
            {
                os.netMap.nodes.Add(ret);
                eos?.links.Add(os.netMap.nodes.Count - 1);
            }

            os     = null;
            eos    = null;
            holder = null;

            return(ret);
        }
예제 #4
0
        public static bool onLoadRunnableActionsIntoOS(string filepath, object OSobj)
        {
            var truePath = LocalizedFileLoader.GetLocalizedFilepath(Utils.GetFileLoadPrefix() + filepath);
            var evt      = new Event.ActionsLoadIntoOSEvent(truePath, (OS)OSobj);
            var except   = evt.CallEvent();

            if (except.Count > 0)
            {
                throw new EventException("Failed to load conditional actions", except);
            }
            return(evt.IsCancelled);
        }
        public static ExtensionInfo LoadExtensionInfo(string folderpath)
        {
            var filepath = folderpath + "/ExtensionInfo.xml";

            if (!File.Exists(filepath))
            {
                throw new FileNotFoundException($"Could not find ExtensionInfo.xml in folder {folderpath}");
            }

            extInfo            = new ExtensionInfo();
            extInfo.FolderPath = folderpath;
            extInfo.Language   = "en-us";

            var    logopath  = folderpath + "/Logo.";
            string extension = null;

            if (File.Exists(logopath + "png"))
            {
                extension = "png";
            }
            else if (File.Exists(logopath + "jpg"))
            {
                extension = "jpg";
            }

            if (extension != null)
            {
                using (var input = File.OpenRead(logopath + extension))
                    extInfo.LogoImage = Texture2D.FromStream(Game1.getSingleton().GraphicsDevice, input);
            }

            executor.SetText(LocalizedFileLoader.GetLocalizedFilepath(filepath), true);

            foreach (var custom in CustomExecutors)
            {
                var instance = (ExtensionInfoExecutor)Activator.CreateInstance(custom.ExecutorType);
                instance.Init(ref extInfo);
                executor.RegisterTempExecutor(custom.Element, instance.Execute, custom.Options);
            }

            if (!executor.TryParse(out var ex))
            {
                throw new FormatException($"An exception occurred while trying to parse '{filepath}'", ex);
            }

            var ret = extInfo;

            extInfo = null;
            return(ret);
        }
        internal static void WrapOnceInCommandIL(ILContext il)
        {
            ILCursor c = new ILCursor(il);

            c.GotoNext(MoveType.Before,
                       x => x.MatchLdfld(AccessTools.Field(typeof(FileEntry), nameof(FileEntry.data))),
                       x => x.MatchStfld(AccessTools.Field(typeof(OS), nameof(OS.displayCache)))
                       );

            c.Index += 1;

            c.EmitDelegate <Func <string, string> >(fileData =>
            {
                lastFileData = fileData;
                return(Utils.SuperSmartTwimForWidth(LocalizedFileLoader.SafeFilterString(fileData), OS.currentInstance.display.bounds.Width - 40, GuiData.tinyfont));
            });
        }
예제 #7
0
        public static ActiveMission LoadContentMission(string filename)
        {
            if (ComputerLoader.MissionPreLoadComplete != null)
            {
                ComputerLoader.MissionPreLoadComplete();
            }

            mission = new ActiveMission(new List <MisisonGoal>(), null, default)
            {
                willSendEmail         = true,
                reloadGoalsSourceFile = filename
            };
            branches = new List <ActiveMission>();
            mission.email.attachments = new List <string>();

            hasMissionTag = false;

            executor.SetText(LocalizedFileLoader.GetLocalizedFilepath(filename), true);

            foreach (var custom in CustomExecutors)
            {
                var customInstance = (MissionExecutor)Activator.CreateInstance(custom.ExecutorType);
                customInstance.Init(OS.currentInstance, ref mission);
                executor.RegisterTempExecutor(custom.Element, customInstance.Execute, custom.Options);
            }

            if (!executor.TryParse(out var ex))
            {
                throw new FormatException($"{filename}: {ex.Message}", ex);
            }

            var ret = mission;

            mission  = null;
            branches = null;

            return(hasMissionTag ? ret : null);
        }
예제 #8
0
        public static Computer LoadComputer(string filename, OS os, bool preventAddingToNetmap = false, bool preventInitDaemons = false)
        {
            PreventNetmapAdd  = preventAddingToNetmap;
            PreventDaemonInit = preventInitDaemons;

            filename = LocalizedFileLoader.GetLocalizedFilepath(filename);
            Computer result = null;
            string   themeData;

            var executor    = new EventExecutor(filename, ignoreCase: true);
            var readContent = true;

            if (filename.Contains("ExampleComputer.xml") && !Util.Extensions.CheckLabyrinths())
            {
                executor.OnRead += exec =>
                {
                    var val = Regex.Replace(exec.Reader.Value.Trim().ToLower().Replace('_', ' '), @"s/\s{2,}/ /g", "");
                    if (readContent && val == "end labyrinths only content")
                    {
                        readContent = true;
                    }
                    else if (!readContent && val == "start labyrinths only content")
                    {
                        readContent = false;
                    }
                    return(readContent);
                };
            }

            executor.AddExecutor("Computer", (exec, info) =>
            {
                var compType = info.Attributes.GetValue("type");
                result       = new Computer(
                    info.Attributes.GetValue("name", true) ?? "UNKNOWN",
                    info.Attributes.GetValue("ip", true) ?? Utility.GenerateRandomIP(),
                    os.netMap.getRandomPosition(),
                    Convert.ToInt32(info.Attributes.GetValue("security")),
                    compType?.ToLower() == "empty" ? (byte)4 : Convert.ToByte(compType),
                    os)
                {
                    idName = info.Attributes.GetValue("id") ?? "UNKNOWN",
                    AllowsDefaultBootModule = info.Attributes.GetValue("allowsDefaultBootModule")?.ToLower() != "false",
                    icon = info.Attributes.GetValue("icon")
                };
                if (result.type != 4)
                {
                    return;
                }
                var folder = result.files.root.searchForFolder("home");
                folder?.files.Clear();
                folder?.folders.Clear();
            });

            executor.AddExecutor("Computer.File", (exec, info) =>
            {
                var encodedFileStr = info.Attributes.GetValueOrDefault("name", "Data", true).HacknetFilter();
                themeData          = info.Value;
                if (string.IsNullOrEmpty(themeData))
                {
                    themeData = Utility.GenerateBinString();
                }
                themeData          = themeData.HacknetFilter();
                var folderFromPath = result.getFolderFromPath(
                    info.Attributes.GetValueOrDefault("path", "home"), true);
                if (!info.Attributes.GetBool("EduSafe", true) &&
                    (Settings.EducationSafeBuild || !Settings.EducationSafeBuild) &&
                    info.Attributes.GetBool("EduSafeOnly"))
                {
                    return;
                }
                var file = folderFromPath.searchForFile(encodedFileStr);
                if (file == null)
                {
                    folderFromPath.files.Add(new FileEntry(themeData, encodedFileStr));
                }
                else
                {
                    file.data = encodedFileStr;
                }
            }, true);

            executor.AddExecutor("Computer.EncryptedFile", (exec, info) =>
            {
                var encodedFileStr = info.Attributes.GetValueOrDefault("name", "Data", true);
                var header         = info.Attributes.GetValueOrDefault("header", "ERROR");
                var ip             = info.Attributes.GetValueOrDefault("ip", "ERROR");
                var pass           = info.Attributes.GetValueOrDefault("pass", "");
                var extension      = info.Attributes.GetValue("extension");
                var doubleAttr     = info.Attributes.GetBool("double");
                themeData          = info.Value;
                if (string.IsNullOrEmpty(themeData))
                {
                    themeData = Utility.GenerateBinString();
                }
                themeData = themeData.HacknetFilter();
                if (doubleAttr)
                {
                    themeData = FileEncrypter.EncryptString(themeData, header, ip, pass, extension);
                }
                themeData = FileEncrypter.EncryptString(themeData, header, ip, pass,
                                                        (doubleAttr ? "_LAYER2.dec" : extension));
                var folderFromPath = result.getFolderFromPath(
                    info.Attributes.GetValue("path") ?? "home", true);
                var file = folderFromPath.searchForFile(encodedFileStr);
                if (file == null)
                {
                    folderFromPath.files.Add(new FileEntry(themeData, encodedFileStr));
                }
                else
                {
                    file.data = themeData;
                }
            }, true);


            executor.AddExecutor("Computer.MemoryDumpFile", (exec, info) =>
            {
                var memoryInfo = info.Children.FirstOrDefault(e => e.Name == "Memory");
                if (memoryInfo == null)
                {
                    /* TODO: error reporting */
                }
                var memoryContents = ReplacementsCommon.LoadMemoryContents(memoryInfo);
                var fileName       = info.Attributes.GetValueOrDefault("name", "Data");
                var folderFromPath = result.getFolderFromPath(info.Attributes.GetValueOrDefault("path", "home"), true);
                var file           = folderFromPath.searchForFile(fileName);
                if (file != null)
                {
                    file.data = memoryContents.GetEncodedFileString();
                }
                else
                {
                    folderFromPath.files.Add(new FileEntry(memoryContents.GetEncodedFileString(), fileName));
                }
            }, true);

            executor.AddExecutor("Computer.Memory", (exec, info) =>
            {
                result.Memory = ReplacementsCommon.LoadMemoryContents(info);
            }, true);

            executor.AddExecutor("Computer.CustomThemeFile", (exec, info) =>
            {
                var encodedFileStr = info.Attributes.GetValueOrDefault("name", "Data", true);
                themeData          = ThemeManager.getThemeDataStringForCustomTheme(info.Attributes.GetValue("themePath"));
                themeData          = string.IsNullOrEmpty(themeData)
                    ? "DEFINITION ERROR - Theme generated incorrectly. No Custom theme found at definition path"
                    : themeData.HacknetFilter();
                var folderFromPath = result.getFolderFromPath(
                    info.Attributes.GetValueOrDefault("path", "home"), true);
                var file = folderFromPath.searchForFile(encodedFileStr);
                if (file == null)
                {
                    folderFromPath.files.Add(new FileEntry(themeData, encodedFileStr));
                }
                else
                {
                    file.data = themeData;
                }
            });

            executor.AddExecutor("Computer.Ports", (exec, info) =>
                                 ComputerLoader.loadPortsIntoComputer(info.Value, result), true);

            executor.AddExecutor("Computer.PositionNear", (exec, info) =>
            {
                var target        = info.Attributes.GetValueOrDefault("target", "");
                var position      = info.Attributes.GetInt("position", 1);
                var total         = info.Attributes.GetInt("total", 3);
                var force         = info.Attributes.GetBool("force");
                var extraDistance = MathHelper.Clamp(info.Attributes.GetFloat("extraDistance"), -1, 1);
                ComputerLoader.postAllLoadedActions += () =>
                {
                    var c = Programs.getComputer(os, target);
                    if (c != null)
                    {
                        result.location = c.location
                                          + Corporation.getNearbyNodeOffset(
                            c.location,
                            position,
                            total,
                            os.netMap,
                            extraDistance,
                            force);
                    }
                };
            });

            executor.AddExecutor("Computer.Proxy", (exec, info) =>
            {
                var time = info.Attributes.GetFloat("time", 1);
                if (time <= 0f)
                {
                    result.hasProxy    = false;
                    result.proxyActive = false;
                }
            });

            executor.AddExecutor("Computer.PortsForCrack", (exec, info) =>
            {
                var val = info.Attributes.GetInt("val", -1);
                if (val != -1)
                {
                    result.portsNeededForCrack = val - 1;
                }
            });

            executor.AddExecutor("Computer.Firewall", (exec, info) =>
            {
                var level = info.Attributes.GetInt("level", 1);
                if (level <= 0)
                {
                    result.firewall = null;
                }
                else
                {
                    var solution = info.Attributes.GetValue("solution");
                    if (solution == null)
                    {
                        result.addFirewall(level);
                    }
                    else
                    {
                        result.addFirewall(
                            level, solution, info.Attributes.GetFloat("additionalTime"));
                    }
                }
            });

            executor.AddExecutor("Computer.Link", (exec, info) =>
            {
                var linkedComp =
                    Programs.getComputer(os, info.Attributes.GetValueOrDefault("target", ""));
                if (linkedComp != null)
                {
                    result.links.Add(os.netMap.nodes.IndexOf(linkedComp));
                }
            });

            executor.AddExecutor("Computer.Dlink", (exec, info) =>
            {
                /* captures for lambda */
                var offsetComp = result;
                var linkTo     = info.Attributes.GetValueOrDefault("target", "");
                ComputerLoader.postAllLoadedActions += () =>
                {
                    var linkedComp =
                        Programs.getComputer(os, linkTo);
                    if (linkedComp != null)
                    {
                        offsetComp.links.Add(os.netMap.nodes.IndexOf(linkedComp));
                    }
                };
            });

            executor.AddExecutor("Computer.Trace", (exec, info) =>
                                 result.traceTime = info.Attributes.GetFloat("time", 1));

            executor.AddExecutor("Computer.AdminPass", (exec, info) =>
                                 result.setAdminPassword(
                                     info.Attributes.GetValue("pass", true) ?? PortExploits.getRandomPassword()));

            executor.AddExecutor("Computer.Admin", (exec, info) =>
                                 result.admin = Utility.GetAdminFromString(
                                     info.Attributes.GetValueOrDefault("type", "basic"),
                                     info.Attributes.GetBool("resetPassword", true),
                                     info.Attributes.GetBool("isSuper")
                                     ));

            executor.AddExecutor("Computer.PortRemap", (exec, info) =>
            {
                if (!string.IsNullOrWhiteSpace(info.Value))
                {
                    result.PortRemapping = PortRemappingSerializer.Deserialize(info.Value);
                }
            }, true);

            executor.AddExecutor("Computer.ExternalCounterpart", (exec, info)
                                 => result.externalCounterpart = new ExternalCounterpart(info.Attributes.GetValue("name"),
                                                                                         ExternalCounterpart.getIPForServerName(info.Attributes.GetValue("id"))));

            executor.AddExecutor("Computer.Account", (exec, info) =>
            {
                byte type      = 0;
                string typeStr = info.Attributes.GetValueOrDefault("type", "admin").ToLower(),
                password       = info.Attributes.GetValueOrDefault("password", "ERROR", true),
                username       = info.Attributes.GetValueOrDefault("username", "ERROR", true);
                switch (typeStr)
                {
                case "admin": type = 0; break;

                case "all": type = 1; break;

                case "mail": type = 2; break;

                case "missionlist": type = 3; break;

                default:
                    if (char.IsDigit(typeStr[0]))
                    {
                        byte.TryParse(typeStr, out type);
                    }
                    break;
                }
                var addUser = true;
                for (int i = 0; i < result.users.Count; i++)
                {
                    var userDetail = result.users[i];
                    if (userDetail.name == username)
                    {
                        userDetail.pass = password;
                        userDetail.type = type;
                        result.users[i] = userDetail;
                        if (username == "admin")
                        {
                            result.adminPass = password;
                        }
                        addUser = false;
                    }
                }
                if (addUser)
                {
                    result.AddUserDetail(username, password, type);
                }
            });

            executor.AddExecutor("Computer.Tracker", (exec, info) => result.HasTracker = true);

            executor.AddExecutor("Computer.MissionListingServer", (exec, info) =>
            {
                result.AddDaemon <MissionListingServer>(
                    info.Attributes.GetValueOrDefault("name", "ERROR", true),
                    info.Attributes.GetValueOrDefault("group", "ERROR", true),
                    os,
                    info.Attributes.GetBool("public"),
                    info.Attributes.GetBool("assigner"));
            });

            executor.AddExecutor("Computer.VariableMissionListingServer", (exec, info) =>
            {
                var title = info.Attributes.GetValue("title", true);
                var missionListingServer = result.AddDaemon <MissionListingServer>(
                    info.Attributes.GetValue("name", true),
                    info.Attributes.GetValue("iconPath"),
                    info.Attributes.GetValue("articleFolderPath"),
                    Utility.GetColorFromString(info.Attributes.GetValue("color"), Color.IndianRed),
                    os,
                    info.Attributes.GetBool("public"),
                    info.Attributes.GetBool("assigner")
                    );
                if (title != null)
                {
                    missionListingServer.listingTitle = title;
                }
            });

            executor.AddExecutor("Computer.MissionHubServer", (exec, info) =>
            {
                var missionPath = info.Attributes.GetValueOrDefault("missionFolderPath", "").Replace('\\', '/');
                if (!missionPath.EndsWith("/", StringComparison.InvariantCulture))
                {
                    missionPath += "/";
                }
                var hubServer = result.AddDaemon <MissionHubServer>(
                    info.Attributes.GetValue("serviceName"),
                    info.Attributes.GetValueOrDefault("groupName", "", true),
                    os
                    );
                hubServer.MissionSourceFolderPath =
                    (Settings.IsInExtensionMode
                        ? ExtensionLoader.ActiveExtensionInfo.FolderPath + "/"
                        : "Content/Missions/") + missionPath;
                hubServer.themeColor           = info.Attributes.GetColor("themeColor", Color.PaleTurquoise);
                hubServer.themeColorBackground = info.Attributes.GetColor("backgroundColor", Color.PaleTurquoise);
                hubServer.themeColorLine       = info.Attributes.GetColor("line Color", Color.PaleTurquoise);
                hubServer.allowAbandon         = info.Attributes.GetBool("allowAbandon", true);
            });

            executor.AddExecutor("Computer.MailServer", (exec, info) =>
            {
                var mailServer = result.AddDaemon <MailServer>(
                    info.Attributes.GetValueOrDefault("name", "Mail Server"),
                    os);
                mailServer.shouldGenerateJunkEmails = info.Attributes.GetBool("generateJunk", true);
                var color = info.Attributes.GetColor("color", true);
                if (color.HasValue)
                {
                    mailServer.setThemeColor(color.Value);
                }
                foreach (var emailInfo in info.Children.Where((i) => i.Name.ToLower() == "email"))
                {
                    mailServer.AddEmailToServer(
                        emailInfo.Attributes.GetValue("sender"),
                        emailInfo.Attributes.GetValue("recipient"),
                        emailInfo.Attributes.GetValue("subject"),
                        emailInfo.Value
                        );
                }
            }, true);

            executor.AddExecutor("Computer.AddEmailDaemon", (exec, info)
                                 => result.AddDaemon <AddEmailDaemon>("Final Task", os));

            executor.AddExecutor("Computer.DeathRowDatabase", (exec, info)
                                 => result.AddDaemon <DeathRowDatabaseDaemon>("Death Row Database", os));

            executor.AddExecutor("Computer.AcademicDatabase", (exec, info)
                                 => result.AddDaemon <AcademicDatabaseDaemon>("International Academic Database", os));

            executor.AddExecutor("Computer.IspSystem", (exec, info)
                                 => result.AddDaemon <ISPDaemon>(os));

            executor.AddExecutor("Computer.MessageBoard", (exec, info) =>
            {
                var messageBoardDaemon       = result.AddDaemon <MessageBoardDaemon>(os);
                messageBoardDaemon.name      = info.Attributes.GetValueOrDefault("name", "Anonymous");
                messageBoardDaemon.BoardName = messageBoardDaemon.name;
                const string content         = "Content/Missions/";
                foreach (var threadInfo in info.Children.Where((cinfo) => cinfo.Name.ToLower() == "thread"))
                {
                    var threadLoc = threadInfo.Value ?? "UNKNOWN";
                    if (threadLoc.StartsWith(content, StringComparison.InvariantCulture))
                    {
                        threadLoc = threadLoc.Substring(content.Length);
                    }
                    messageBoardDaemon.AddThread(Utils.readEntireFile(
                                                     (Settings.IsInExtensionMode ?
                                                      ExtensionLoader.ActiveExtensionInfo.FolderPath + "/" :
                                                      content
                                                     ) + threadLoc
                                                     ));
                }
            }, true);

            executor.AddExecutor("Computer.AddAvconDemoEndDaemon", (exec, info)
                                 => result.AddDaemon <AvconDemoEndDaemon>("Demo End", os));

            executor.AddExecutor("Computer.AddWebServer", (exec, info) =>
                                 result.AddDaemon <WebServerDaemon>(
                                     info.Attributes.GetValueOrDefault("name", "Web Server"),
                                     os,
                                     info.Attributes.GetValue("url")
                                     ).registerAsDefaultBootDaemon());

            executor.AddExecutor("Computer.AddOnlineWebServer", (exec, info) =>
            {
                var webOnlineServerDaemon = result.AddDaemon <OnlineWebServerDaemon>(
                    info.Attributes.GetValueOrDefault("name", "Web Server"),
                    os);
                webOnlineServerDaemon.setURL(
                    info.Attributes.GetValueOrDefault("url", webOnlineServerDaemon.webURL));
                webOnlineServerDaemon.registerAsDefaultBootDaemon();
            });


            executor.AddExecutor("Computer.UploadServerDaemon", (exec, info) =>
            {
                var uploadServerDaemon = result.AddDaemon <UploadServerDaemon>(
                    info.Attributes.GetValueOrDefault("name", "File Upload Server"),
                    info.Attributes.GetColor("color", new Color(0, 94, 38)),
                    os,
                    info.Attributes.GetValue("folder"),
                    info.Attributes.GetBool("needsAuth")
                    );
                uploadServerDaemon.hasReturnViewButton = info.Attributes.GetBool("hasReturnViewButton");
                uploadServerDaemon.registerAsDefaultBootDaemon();
            });

            executor.AddExecutor("Computer.MedicalDatabase", (exec, info)
                                 => result.AddDaemon <MedicalDatabaseDaemon>(os));

            executor.AddExecutor("Computer.HeartMonitor", (exec, info)
                                 => result.AddDaemon <HeartMonitorDaemon>(os)
                                 .PatientID = info.Attributes.GetValueOrDefault("patient", "UNKNOWN"));

            executor.AddExecutor("Computer.PointClicker", (exec, info)
                                 => result.AddDaemon <PointClickerDaemon>("Point Clicker!", os));

            executor.AddExecutor("Computer.PorthackHeart", (exec, info)
                                 => result.AddDaemon <PorthackHeartDaemon>(os));

            executor.AddExecutor("Computer.SongChangerDaemon", (exec, info)
                                 => result.AddDaemon <SongChangerDaemon>(os));

            executor.AddExecutor("Computer.CustomConnectDisplayDaemon", (exec, info)
                                 => result.AddDaemon <CustomConnectDisplayDaemon>(os));

            executor.AddExecutor("Computer.DatabaseDaemon", (exec, info) =>
            {
                info.Name.ThrowNoLabyrinths();
                var emailAccount = info.Attributes.GetValue("AdminEmailAccount");

                var databaseColor = info.Attributes.GetColor("Color", true);
                if (!databaseColor.HasValue)
                {
                    databaseColor = os.highlightColor;
                }

                var databaseDaemon = result.AddDaemon <DatabaseDaemon>(
                    os,
                    info.Attributes.GetValueOrDefault("Name", "Database"),
                    DatabaseDaemon.GetDatabasePermissionsFromString(
                        info.Attributes.GetValueOrDefault("Permissions", "")
                        ),
                    info.Attributes.GetValue("DataType"),
                    info.Attributes.GetValueOrDefault("Foldername", "Database"),
                    databaseColor);
                if (!string.IsNullOrWhiteSpace(emailAccount))
                {
                    databaseDaemon.adminResetEmailHostID      = info.Attributes.GetValue("AdminEmailHostID");
                    databaseDaemon.adminResetPassEmailAccount = emailAccount;
                }
                if (info.Children.Count > 0)
                {
                    var dataset = databaseDaemon.GetDataset();
                    foreach (var e in info.Children)
                    {
                        if (e.Name == databaseDaemon.DataTypeIdentifier)
                        {
                            dataset.Add(new DatabaseDaemonHandler.DataInfo(e));
                        }
                    }
                }
            }, true);



            executor.AddExecutor("Computer.WhitelistAuthenticatorDaemon", (exec, info)
                                 => result.AddDaemon(
                                     new WhitelistConnectionDaemon(result, os)
            {
                RemoteSourceIP      = info.Attributes.GetValue("Remote"),
                AuthenticatesItself = info.Attributes.GetBool("SelfAuthenticating", true)
            }));


            executor.AddExecutor("Computer.MarkovTextDaemon", (exec, info)
                                 => result.AddDaemon <MarkovTextDaemon>(
                                     os,
                                     info.Attributes.GetValue("Name"),
                                     info.Attributes.GetValue("SourceFilesContentFolder")
                                     ));

            executor.AddExecutor("Computer.IrcDaemon", (exec, info) =>
            {
                var rCDaemon = result.AddDaemon <IRCDaemon>(
                    os,
                    info.Attributes.GetValueOrDefault("Remote", "IRC Server")
                    );
                rCDaemon.ThemeColor    = info.Attributes.GetColor("themeColor", new Color(184, 2, 141));
                rCDaemon.RequiresLogin = info.Attributes.GetBool("needsLogin");
                foreach (var cinfo in info.Children)
                {
                    switch (cinfo.Name.ToLower())
                    {
                    case "user":
                    case "agent":
                        var name = cinfo.Attributes.GetValue("name", true);
                        if (!string.IsNullOrWhiteSpace(name))
                        {
                            rCDaemon.UserColors.Add(name,
                                                    cinfo.Attributes.GetColor("color", Color.LightGreen));
                        }

                        break;

                    case "post":
                        var user = cinfo.Attributes.GetValue("user", true);
                        if (!string.IsNullOrWhiteSpace(user))
                        {
                            rCDaemon.StartingMessages.Add(
                                new KeyValuePair <string, string>(user, cinfo.Value?.HacknetFilter()));
                        }

                        break;
                    }
                }
            }, true);

            executor.AddExecutor("Computer.AircraftDaemon", (exec, info) =>
            {
                info.Name.ThrowNoLabyrinths();
                result.AddDaemon <AircraftDaemon>(
                    os,
                    info.Attributes.GetValue("Name"),
                    info.Attributes.GetVector2(defaultVal: Vector2.Zero),
                    info.Attributes.GetVector2("Dest", defaultVal: Vector2.One * 0.5f),
                    info.Attributes.GetFloat("Progress", 0.5f)
                    );
            });

            executor.AddExecutor("Computer.LogoCustomConnectDisplayDaemon", (exec, info)
                                 => result.AddDaemon <LogoCustomConnectDisplayDaemon>(
                                     os,
                                     info.Attributes.GetValue("logo"),
                                     info.Attributes.GetValue("title", true),
                                     info.Attributes.GetBool("overdrawLogo"),
                                     info.Attributes.GetValue("buttonAlignment")
                                     ));

            executor.AddExecutor("Computer.LogoDaemon", (exec, info)
                                 => result.AddDaemon(
                                     new LogoDaemon(
                                         result,
                                         os,
                                         result.name,
                                         info.Attributes.GetBool("ShowsTitle", true),
                                         info.Attributes.GetValue("LogoImagePath"))
            {
                TextColor = info.Attributes.GetColor("TextColor", Color.White),
                BodyText  = info.Value
            }
                                     ), true);

            executor.AddExecutor("Computer.DHSDaemon", (exec, info) =>
            {
                info.Name.ThrowNoLabyrinths();

                var groupName             = info.Attributes.GetValueOrDefault("groupName", "UNKNOWN");
                var addsFactionPoint      = info.Attributes.GetBool("addsFactionPointOnMissionComplete", true);
                var autoClearMissions     = info.Attributes.GetBool("autoClearMissionsOnPlayerComplete", true);
                var allowContractAbbandon = info.Attributes.GetBool("allowContractAbbandon");
                var themeColor            = info.Attributes.GetColor("themeColor", new Color(38, 201, 155));

                var dlcHubServer = result.AddDaemon <DLCHubServer>("DHS", groupName, os);
                dlcHubServer.AddsFactionPointForMissionCompleteion = addsFactionPoint;
                dlcHubServer.AutoClearMissionsOnSingleComplete     = autoClearMissions;
                dlcHubServer.AllowContractAbbandon = allowContractAbbandon;
                dlcHubServer.themeColor            = themeColor;

                foreach (var cinfo in info.Children.Where(v =>
                                                          v.Name.ToLower() == "user" || v.Name.ToLower() == "agent")
                         )
                {
                    var name     = cinfo.Attributes.GetValue("name", true);
                    var password = cinfo.Attributes.GetValueOrDefault("pass", "password");
                    var color    = cinfo.Attributes.GetColor("color", Color.LightGreen);
                    if (!string.IsNullOrWhiteSpace(name))
                    {
                        dlcHubServer.AddAgent(name, password, color);
                    }
                }
            }, true);

            void creditFunc(IExecutor exec, ElementInfo info)
            {
                var inputArr = new List <object>
                {
                    os,
                    info.Attributes.GetValue("Title", true),
                    info.Attributes.GetValue("ButtonText", true)
                }.Where((i) => i != null).ToArray();

                result.AddDaemon <DLCCreditsDaemon>(inputArr.ToArray())
                .ConditionalActionsToLoadOnButtonPress =
                    info.Attributes.GetValue("ConditionalActionSetToRunOnButtonPressPath");
            }

            executor.AddExecutor("Computer.DLCCredits", creditFunc);
            executor.AddExecutor("Computer.CreditsDaemon", creditFunc);

            executor.AddExecutor("Computer.FastActionHost", (exec, info)
                                 => result.AddDaemon <FastActionHost>(os, result.name));

            executor.AddExecutor("Computer.eosDevice", (exec, info)
                                 => AddEosComputer(info, result, os), true);

            HandlerListener.DaemonLoadListener(result, executor);

            foreach (var exec in ComputerLoaders)
            {
                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 += reader =>
            {
                if (!preventInitDaemons)
                {
                    result.initDaemons();
                }
                if (!preventAddingToNetmap)
                {
                    os.netMap.nodes.Add(result);
                }
            };

            executor.Parse();
            return(result);
        }
예제 #9
0
        public static bool RenderAttachment(string data, object osObj, Vector2 dpos, int startingButtonIndex, SoundEffect buttonSound)
        {
            OS os = (OS)osObj;

            string[] strArray = data.Split(AttachmentRenderer.spaceDelim, StringSplitOptions.RemoveEmptyEntries);
            if (strArray.Length < 1)
            {
                return(false);
            }
            if (strArray[0].Equals("link"))
            {
                Vector2  labelSize = TextItem.doMeasuredTinyLabel(dpos, LocaleTerms.Loc("LINK") + " : " + strArray[1] + "@" + strArray[2], new Color?());
                Computer computer  = Programs.getComputer(os, strArray[2]);
                if (!os.netMap.visibleNodes.Contains(os.netMap.nodes.IndexOf(computer)))
                {
                    AttachmentRenderer.DrawButtonGlow(dpos, labelSize, os);
                }
                if (Button.doButton(800009 + startingButtonIndex, (int)((double)dpos.X + (double)labelSize.X + 5.0), (int)dpos.Y, 20, 17, "+", new Color?()))
                {
                    if (computer == null)
                    {
                        os.write("ERROR: Linked target not found");
                    }
                    else
                    {
                        computer.highlightFlashTime = 1f;
                        os.netMap.discoverNode(computer);
                        SFX.addCircle(Programs.getComputer(os, strArray[2]).getScreenSpacePosition(), Color.White, 32f);
                        if (buttonSound != null && !Settings.soundDisabled)
                        {
                            buttonSound.Play();
                        }
                    }
                }
            }
            else if (strArray[0].Equals("account"))
            {
                Vector2 labelSize = TextItem.doMeasuredTinyLabel(dpos, LocaleTerms.Loc("ACCOUNT") + " : " + strArray[1] + " : User="******" Pass="******"+", new Color?()))
                {
                    Computer computer = Programs.getComputer(os, strArray[2]);
                    computer.highlightFlashTime = 1f;
                    os.netMap.discoverNode(computer);
                    computer.highlightFlashTime = 1f;
                    SFX.addCircle(computer.getScreenSpacePosition(), Color.White, 32f);
                    for (int index = 0; index < computer.users.Count; ++index)
                    {
                        UserDetail user = computer.users[index];
                        if (user.name.Equals(strArray[3]))
                        {
                            user.known            = true;
                            computer.users[index] = user;
                            break;
                        }
                    }
                    if (buttonSound != null && !Settings.soundDisabled)
                    {
                        buttonSound.Play();
                    }
                }
            }
            else
            {
                if (!strArray[0].Equals("note"))
                {
                    return(false);
                }
                Vector2 labelSize = TextItem.doMeasuredTinyLabel(dpos, LocaleTerms.Loc("NOTE") + " : " + strArray[1], new Color?());
                string  note      = LocalizedFileLoader.SafeFilterString(strArray[2]);
                if (!NotesExe.NoteExists(note, os))
                {
                    AttachmentRenderer.DrawButtonGlow(dpos, labelSize, os);
                }
                if (Button.doButton(800009 + startingButtonIndex, (int)((double)dpos.X + (double)labelSize.X + 5.0), (int)dpos.Y, 20, 17, "+", new Color?()))
                {
                    NotesExe.AddNoteToOS(note, os, false);
                }
            }
            return(true);
        }
예제 #10
0
        public static string TestMission(string missionName, object os_obj)
        {
            string str1 = "";
            OS     os   = (OS)os_obj;

            if (TestSuite.TestedMissionNames.Contains(missionName))
            {
                return(str1);
            }
            try
            {
                if (!File.Exists(missionName))
                {
                    str1 = str1 + "Invalid Mission Path! : " + missionName + "\r\n";
                }
                ActiveMission activeMission = (ActiveMission)ComputerLoader.readMission(missionName);
                TestSuite.ActiveObjectID = missionName;
                string str2 = "";
                for (int index = 0; index < activeMission.goals.Count; ++index)
                {
                    string str3 = activeMission.goals[index].TestCompletable();
                    if (str3 != null && str3.Length > 0)
                    {
                        str2 = str2 + missionName + " Goal[" + (object)index + "] " + activeMission.goals[index].ToString() + " :: " + str3 + "\r\n";
                    }
                }
                try
                {
                    if (!string.IsNullOrWhiteSpace(activeMission.startFunctionName))
                    {
                        if (!Utils.CheckStringIsRenderable(activeMission.startFunctionName))
                        {
                            str1 = str1 + "Mission " + missionName + " has unrenderable start function " + Utils.CleanStringToRenderable(activeMission.startFunctionName);
                        }
                        MissionFunctions.runCommand(activeMission.startFunctionValue, activeMission.startFunctionName);
                    }
                    if (!string.IsNullOrWhiteSpace(activeMission.endFunctionName))
                    {
                        if (!Utils.CheckStringIsRenderable(activeMission.endFunctionName))
                        {
                            str1 = str1 + "Mission " + missionName + " has unrenderable end function " + Utils.CleanStringToRenderable(activeMission.endFunctionName);
                        }
                        MissionFunctions.runCommand(activeMission.endFunctionValue, activeMission.endFunctionName);
                    }
                    string str3           = Directory.GetCurrentDirectory() + "/";
                    string fileLoadPrefix = Utils.GetFileLoadPrefix();
                    if (fileLoadPrefix == "Content/")
                    {
                        fileLoadPrefix += "Missions/";
                    }
                    else if (!fileLoadPrefix.StartsWith("Extensions"))
                    {
                        str3 = "";
                    }
                    string path = str3 + LocalizedFileLoader.GetLocalizedFilepath(fileLoadPrefix + activeMission.nextMission);
                    if (!(activeMission.nextMission == "NONE") && !File.Exists(path))
                    {
                        str1 = str1 + "\r\nNextMission Tag for mission \"" + missionName + "\" has nonexistent next mission path: " + activeMission.nextMission + "\r\n";
                    }
                }
                catch (Exception ex)
                {
                    str1 = str1 + "Error running start or end mission function of mission: " + missionName + "\r\nStart Func: " + activeMission.startFunctionName + "\r\nEnd Func: " + activeMission.endFunctionName;
                    str1 = str1 + "\r\n" + Utils.GenerateReportFromException(ex) + "\r\n";
                }
                if (str2.Length > 0)
                {
                    str1 = str1 + str2 + "--------------\r\n";
                }
                TestSuite.TestedMissionNames.Add(missionName);
                string str4 = "Content/Missions/";
                if (Settings.IsInExtensionMode)
                {
                    str4 = ExtensionLoader.ActiveExtensionInfo.FolderPath + "/";
                }
                List <ActiveMission> activeMissionList = new List <ActiveMission>();
                for (int index = 0; index < os.branchMissions.Count; ++index)
                {
                    activeMissionList.Add(os.branchMissions[index]);
                }
                if (activeMission.nextMission != null && activeMission.nextMission.ToLower() != "none")
                {
                    str1 += TestSuite.TestMission(str4 + activeMission.nextMission, (object)os);
                }
                for (int index = 0; index < activeMissionList.Count; ++index)
                {
                    string localizedFilepath = LocalizedFileLoader.GetLocalizedFilepath(activeMissionList[index].reloadGoalsSourceFile);
                    if (!TestSuite.TestedMissionNames.Contains(localizedFilepath))
                    {
                        Console.WriteLine("testing Branch Mission " + localizedFilepath);
                        str1 += TestSuite.TestMission(localizedFilepath, (object)os);
                    }
                }
            }
            catch (Exception ex)
            {
                str1 = str1 + "Error Loading " + missionName + "\r\n" + ex.ToString();
            }
            return(str1);
        }