private static void AddMissionGenComputer(object __result) { var comp = (Computer)__result; comp.idName = "Gen" + MissionGenerator.generationCount; ComputerLookup.Add(comp); }
public static Computer LoadComputer(ElementInfo info, OS os) { var name = info.Attributes.GetString("name"); var ip = info.Attributes.GetString("ip"); var type = info.Attributes.GetByte("type"); var spec = info.Attributes.GetString("spec"); var location = info.Children.GetElement("location"); var security = info.Children.GetElement("security"); var level = security.Attributes.GetInt("level"); Firewall firewall = null; if (info.Children.TryGetElement("firewall", out var firewallInfo)) { firewall = new Firewall( firewallInfo.Attributes.GetInt("complexity"), firewallInfo.Attributes.GetString("solution", null), firewallInfo.Attributes.GetFloat("additionalDelay") ); } ReplacementsCommon.isPathfinderComputer = true; var comp = new Computer(name, ip, location.Attributes.GetVector("x", "y", Vector2.Zero).Value, level, type, os) { idName = info.Attributes.GetString("id"), attatchedDeviceIDs = info.Attributes.GetString("devices", null), icon = info.Attributes.GetString("icon", null), HasTracker = info.Attributes.GetBool("tracker"), firewall = firewall, traceTime = security.Attributes.GetFloat("traceTime"), portsNeededForCrack = security.Attributes.GetInt("portsToCrack"), adminIP = security.Attributes.GetString("adminIP") }; ReplacementsCommon.isPathfinderComputer = false; var proxyTime = security.Attributes.GetFloat("proxyTime"); if (proxyTime > 0) { comp.addProxy(proxyTime); } else { comp.hasProxy = false; comp.proxyActive = false; } if (info.Children.TryGetElement("admin", out var adminInfo)) { Administrator.AdministratorManager.LoadAdministrator(adminInfo, comp, os); } foreach (var link in info.Children.GetElement("links").Content? .Split((char[])null, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]) { comp.links.Add(int.Parse(link)); } if (info.Children.TryGetElement("portsOpen", out var portsOpen)) { PortManager.LoadPortsFromStringVanilla(comp, portsOpen.Content); } if (info.Children.TryGetElement("portRemap", out var remap)) { PortManager.LoadPortRemapsFromStringVanilla(comp, remap.Content); } if (info.Children.TryGetElement("ports", out var ports)) { if (ports.Content != null) { foreach (var port in ports.Content.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { var parts = port.Split(':'); var record = PortManager.GetPortRecordFromProtocol(parts[0]); var displayName = parts[3].Replace('_', ' '); var portNum = int.Parse(parts[2]); if (record == null) { PortManager.RegisterPort(record = new PortRecord( parts[0], displayName, portNum, int.Parse(parts[1]) )); } comp.AddPort(record.CreateState( comp, displayName, portNum )); } } foreach (var port in ports.Children) { var record = PortManager.GetPortRecordFromProtocol(port.Name); var displayName = port.Children.GetElement("Display").Content; var portNum = int.Parse(port.Children.GetElement("Number").Content); if (record == null) { PortManager.RegisterPort(record = new PortRecord( port.Name, displayName, portNum, int.Parse(port.Children.GetElement("Original").Content) )); } comp.AddPort(record.CreateState( comp, displayName, portNum )); } } comp.users.Clear(); if (info.Children.TryGetElement("users", out var users)) { foreach (var user in users.Children.Where(x => x.Name == "user")) { var username = user.Attributes.GetString("name"); var pass = user.Attributes.GetString("pass"); var userDetail = new UserDetail( username, pass, user.Attributes.GetByte("type") ) { known = user.Attributes.GetBool("known") }; if (username.ToLower() == "admin") { comp.adminPass = pass; } comp.users.Add(userDetail); } } if (info.Children.TryGetElement("Memory", out var memory)) { comp.Memory = ReplacementsCommon.LoadMemoryContents(memory); } #region Daemons if (info.Children.TryGetElement("daemons", out var daemons)) { foreach (var daemon in daemons.Children) { if (Daemon.DaemonManager.TryLoadCustomDaemon(daemon, comp, os)) { continue; } switch (daemon.Name) { case "MailServer": var mailserver = new MailServer(comp, daemon.Attributes.GetString("name"), os); if (daemon.Attributes.TryGetValue("color", out var mail_color)) { mailserver.setThemeColor(Utils.convertStringToColor(mail_color)); } comp.daemons.Add(mailserver); break; case "MissionListingServer": var listing_name = daemon.Attributes.GetString("name"); var listing_group = daemon.Attributes.GetString("group"); var listing_isPublic = daemon.Attributes.GetBool("public"); var listing_isAssigner = daemon.Attributes.GetBool("assign"); var listing_articles = daemon.Attributes.GetString("articles"); MissionListingServer listingserver; if (daemon.Attributes.TryGetValue("icon", out var listing_icon) && daemon.Attributes.TryGetValue("color", out var listing_color)) { listingserver = new MissionListingServer(comp, listing_name, listing_icon, listing_articles, Utils.convertStringToColor(listing_color), os, listing_isPublic, listing_isAssigner); } else { listingserver = new MissionListingServer(comp, name, listing_group, os, listing_isPublic, listing_isAssigner); } comp.daemons.Add(listingserver); break; case "AddEmailServer": comp.daemons.Add(new AddEmailDaemon(comp, daemon.Attributes.GetString("name"), os)); break; case "MessageBoard": var messageboard = new MessageBoardDaemon(comp, os); messageboard.name = daemon.Attributes.GetString("name"); messageboard.BoardName = daemon.Attributes.GetString("boardName", messageboard.BoardName); comp.daemons.Add(messageboard); break; case "WebServer": comp.daemons.Add(new WebServerDaemon( comp, daemon.Attributes.GetString("name"), os, daemon.Attributes.GetString("url") )); break; case "OnlineWebServer": var onlinewebserver = new OnlineWebServerDaemon(comp, daemon.Attributes.GetString("name"), os); onlinewebserver.setURL(daemon.Attributes.GetString("url")); comp.daemons.Add(onlinewebserver); break; case "AcademicDatabse": comp.daemons.Add(new AcademicDatabaseDaemon( comp, daemon.Attributes.GetString("name"), os )); break; case "MissionHubServer": comp.daemons.Add(new MissionHubServer(comp, "unknown", "unknown", os)); break; case "DeathRowDatabase": comp.daemons.Add(new DeathRowDatabaseDaemon(comp, "Death Row Database", os)); break; case "MedicalDatabase": comp.daemons.Add(new MedicalDatabaseDaemon(comp, os)); break; case "HeartMonitor": var heartmon = new HeartMonitorDaemon(comp, os); heartmon.PatientID = daemon.Attributes.GetString("patient", "UNKNOWN"); comp.daemons.Add(heartmon); break; case "PointClicker": comp.daemons.Add(new PointClickerDaemon(comp, "Point Clicker!", os)); break; case "ispSystem": comp.daemons.Add(new ISPDaemon(comp, os)); break; case "porthackheart": comp.daemons.Add(new PorthackHeartDaemon(comp, os)); break; case "SongChangerDaemon": comp.daemons.Add(new SongChangerDaemon(comp, os)); break; case "UploadServerDaemon": var uploadserver = new UploadServerDaemon( comp, daemon.Attributes.GetString("name"), daemon.Attributes.GetColor("color", Color.White).Value, os, daemon.Attributes.GetString("foldername"), daemon.Attributes.GetBool("needsAuh") ); uploadserver.hasReturnViewButton = daemon.Attributes.GetBool("hasReturnViewButton"); comp.daemons.Add(uploadserver); break; case "DHSDaemon": comp.daemons.Add(new DLCHubServer(comp, "unknown", "unknown", os)); break; case "CustomConnectDisplayDaemon": comp.daemons.Add(new CustomConnectDisplayDaemon(comp, os)); break; case "DatabaseDaemon": var databaseserver = new DatabaseDaemon( comp, os, daemon.Attributes.GetString("Name", null), daemon.Attributes.GetString("Permissions"), daemon.Attributes.GetString("DataType"), daemon.Attributes.GetString("Foldername"), daemon.Attributes.GetColor("Color") ); databaseserver.adminResetEmailHostID = daemon.Attributes.GetString("AdminEmailHostID", null); databaseserver.adminResetPassEmailAccount = daemon.Attributes.GetString("AdminEmailAccount", null); comp.daemons.Add(databaseserver); break; case "WhitelistAuthenticatorDaemon": var whitelistserver = new WhitelistConnectionDaemon(comp, os); whitelistserver.AuthenticatesItself = daemon.Attributes.GetBool("SelfAuthenticating", true); comp.daemons.Add(whitelistserver); break; case "IRCDaemon": comp.daemons.Add(new IRCDaemon(comp, os, "LOAD ERROR")); break; case "MarkovTextDaemon": comp.daemons.Add(new MarkovTextDaemon( comp, os, daemon.Attributes.GetString("Name", null), daemon.Attributes.GetString("SourceFilesContentFolder", null) )); break; case "AircraftDaemon": comp.daemons.Add(new AircraftDaemon( comp, os, daemon.Attributes.GetString("Name", "Pacific Charter Flight"), daemon.Attributes.GetVector("OriginX", "OriginY", Vector2.Zero).Value, daemon.Attributes.GetVector("DestX", "DestY", Vector2.One * 0.5f).Value, daemon.Attributes.GetFloat("Progress") )); break; case "LogoCustomConnectDisplayDaemon": comp.daemons.Add(new LogoCustomConnectDisplayDaemon( comp, os, daemon.Attributes.GetString("logo", null), daemon.Attributes.GetString("title", null), daemon.Attributes.GetBool("overdrawLogo"), daemon.Attributes.GetString("buttonAlignment", null) )); break; case "LogoDaemon": comp.daemons.Add(new LogoDaemon( comp, os, name, daemon.Attributes.GetBool("ShowsTitle", true), daemon.Attributes.GetString("LogoImagePath") ) { TextColor = daemon.Attributes.GetColor("TextColor", Color.White).Value }); break; case "DLCCredits": DLCCreditsDaemon dlcdaemon = null; string credits_title, credits_button = null; if (daemon.Attributes.TryGetValue("Title", out credits_title) || daemon.Attributes.TryGetValue("Button", out credits_button)) { dlcdaemon = new DLCCreditsDaemon(comp, os, credits_title, credits_button); } else { dlcdaemon = new DLCCreditsDaemon(comp, os); } dlcdaemon.ConditionalActionsToLoadOnButtonPress = daemon.Attributes.GetString("Action", null); comp.daemons.Add(dlcdaemon); break; case "FastActionHost": comp.daemons.Add(new FastActionHost(comp, os, name)); break; } } } #endregion comp.files = new FileSystem(true) { root = LoadFolder(info.Children.GetElement("filesystem").Children.GetElement("folder")) }; switch (spec) { case "player": os.thisComputer = comp; break; case "mail": os.netMap.mailServer = comp; break; } if (EventManager <SaveComputerLoadedEvent> .InvokeAll(new SaveComputerLoadedEvent(os, comp, info)).Cancelled) { return(null); } ComputerLookup.Add(comp); return(comp); }
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); }); } ReplacementsCommon.isPathfinderComputer = true; if (!executor.TryParse(out var ex)) { ReplacementsCommon.isPathfinderComputer = false; throw new FormatException($"{filename}: {ex.Message}", ex); } ReplacementsCommon.isPathfinderComputer = false; var ret = comp; comp = null; if (ret == null) { return(null); } if (!ComputerExtensions.HasInitializedPorts(ret)) { PortManager.LoadPortsFromChildren(ret, ReplacementsCommon.defaultPorts, false); } if (!preventInitDaemons) { ret.initDaemons(); } if (!preventAddingToNetmap) { os.netMap.nodes.Add(ret); if (eos != null) { eos.links.Add(os.netMap.nodes.Count - 1); ComputerLookup.Add(eos); } ComputerLookup.Add(ret); } os = null; eos = null; holder = null; return(ret); }