├── .gitignore ├── AcademicDatabaseDaemon.cs ├── AchievementsManager.cs ├── ActionDelayer.cs ├── ActiveMission.cs ├── AddEmailDaemon.cs ├── Administrator.cs ├── AdvancedTutorial.cs ├── AssemblyInfo.cs ├── AuthenticatingDaemon.cs ├── AvconDemoEndDaemon.cs ├── BackgroundObject.cs ├── BasicAdministrator.cs ├── BoatMail.cs ├── ClockExe.cs ├── CollidableRectangle.cs ├── CollidableTriangle.cs ├── Computer.cs ├── ComputerLoader.cs ├── ComputerTypeInfo.cs ├── ConnectedNodeEffect.cs ├── CoreModule.cs ├── Corporation.cs ├── CrashModule.cs ├── Daemon.cs ├── Daemons └── Helpers │ ├── BasicMedicalMonitor.cs │ └── IMedicalMonitor.cs ├── DeathRowDatabaseDaemon.cs ├── DebugLog.cs ├── DecypherExe.cs ├── DecypherTrackExe.cs ├── Degree.cs ├── DelayedInput.cs ├── DisplayModule.cs ├── EOSAppGenerator.cs ├── EOSComp.cs ├── EOSDeviceScannerExe.cs ├── Effects ├── AudioVisualizer.cs ├── BarcodeEffect.cs ├── Cube3D.cs ├── FlickeringTextEffect.cs ├── HexGridBackground.cs ├── MovingBarsEffect.cs ├── NodeBounceEffect.cs ├── PortHackCubeSequence.cs ├── ThinBarcode.cs ├── TraceDangerSequence.cs └── WebpageLoadingEffect.cs ├── EndingSequenceModule.cs ├── ExeModule.cs ├── ExternalCounterpart.cs ├── ExternalCounterparts └── ExternalNetworkedServer.cs ├── FTPBounceExe.cs ├── Faction.cs ├── Factions ├── AllFactions.cs ├── EntropyFaction.cs └── HubFaction.cs ├── FastBasicAdministrator.cs ├── FileEncrypter.cs ├── FileEntry.cs ├── FileSanitiser.cs ├── FileSystem.cs ├── FileType.cs ├── Firewall.cs ├── Folder.cs ├── ForkBombExe.cs ├── Game1.cs ├── GameSaver.cs ├── GameScreen.cs ├── GenerationStatics.cs ├── Gui ├── Button.cs ├── CheckBox.cs ├── DraggableRectangle.cs ├── RenderedRectangle.cs ├── ScrollBar.cs ├── ScrollablePanel.cs ├── SelectableTextList.cs ├── SliderBar.cs ├── TextBox.cs └── TextItem.cs ├── GuiData.cs ├── HTTPExploitExe.cs ├── HackerScriptExecuter.cs ├── Hacknet.csproj ├── Hacknet.sln ├── HeartMonitorDaemon.cs ├── Helpfile.cs ├── HexClockExe.cs ├── ISPDaemon.cs ├── Input ├── Stack`1.cs └── TextInputHook.cs ├── InputMap.cs ├── InputMapping.cs ├── InputState.cs ├── InputStates.cs ├── IntroTextModule.cs ├── KeyboardAndGamePad.cs ├── LevelState.cs ├── LevelType.cs ├── LoadedTexture.cs ├── Magic └── NAT.cs ├── MailIcon.cs ├── MailResponder.cs ├── MailServer.cs ├── MainMenu.cs ├── MedicalDatabaseDaemon.cs ├── MedicalPortExe.cs ├── MedicalRecord.cs ├── MessageBoardDaemon.cs ├── MessageBoardPost.cs ├── MessageBoardPostImage.cs ├── MessageBoardThread.cs ├── MessageBoxScreen.cs ├── Microsoft └── Xna │ └── Framework.RuntimeProfile ├── Misc ├── DemoEndScreen.cs ├── HSLColor.cs └── TestSuite.cs ├── Mission ├── AddDegreeMission.cs ├── BootLoadList.cs ├── CheckFlagSetMission.cs ├── DeathRowRecordModifyMission.cs ├── DeathRowRecordRemovalMission.cs ├── DelayMission.cs ├── FileChangeMission.cs ├── FileDeletionMission.cs ├── FileDownloadMission.cs ├── FileUploadMission.cs ├── GetAdminMission.cs ├── GetStringMission.cs ├── MisisonGoal.cs ├── SendEmailMission.cs └── WipeDegreesMission.cs ├── MissionFunctions.cs ├── MissionGenerationParser.cs ├── MissionGenerator.cs ├── MissionHubServer.cs ├── MissionListingServer.cs ├── MissionSerializer.cs ├── Module.cs ├── Modules ├── Helpers │ └── DisplayModuleLSHelper.cs └── Overlays │ └── IncomingConnectionOverlay.cs ├── Multiplayer.cs ├── MultiplayerGameOverScreen.cs ├── MultiplayerLobby.cs ├── MusicManager.cs ├── NameGenerator.cs ├── NetworkMap.cs ├── NotesExe.cs ├── OS.cs ├── OSTheme.cs ├── ObjectState.cs ├── OldSystemSaveFileManifest.cs ├── OnlineWebServerDaemon.cs ├── OptionsMenu.cs ├── PatternDrawer.cs ├── People.cs ├── PeopleAssets.cs ├── Person.cs ├── PlatformAPI └── Storage │ ├── BasicStorageMethod.cs │ ├── IStorageMethod.cs │ ├── LocalDocumentsStorageMethod.cs │ ├── OldSystemStorageMethod.cs │ ├── SaveAccountData.cs │ ├── SaveFileManager.cs │ ├── SaveFileManifest.cs │ └── SteamCloudStorageMethod.cs ├── PlatformAPISettings.cs ├── PlayerBonuses.cs ├── PlayerIndexEventArgs.cs ├── PointClickerDaemon.cs ├── PortExploits.cs ├── PortHackExe.cs ├── PorthackHeartDaemon.cs ├── PostProcessor.cs ├── Program.cs ├── ProgramList.cs ├── ProgramRunner.cs ├── Programs.cs ├── ProgressionFlags.cs ├── README.md ├── RamModule.cs ├── RemoteSaveStorage.cs ├── SFX.cs ├── SMTPoverflowExe.cs ├── SQLExploitExe.cs ├── SSHCrackExe.cs ├── SaveData.cs ├── ScreenManagement └── MessagePopup.cs ├── ScreenManager.cs ├── ScreenState.cs ├── SecurityTraceExe.cs ├── SequencerExe.cs ├── ServerScreen.cs ├── Services.cs ├── Settings.cs ├── SettingsLoader.cs ├── ShellExe.cs ├── SongChangerDaemon.cs ├── SpritePlacementData.cs ├── StatsManager.cs ├── Terminal.cs ├── TextureBank.cs ├── ThemeChangerExe.cs ├── ThemeManager.cs ├── TraceKillExe.cs ├── TraceTracker.cs ├── TraiLoadingSpinnerEffect.cs ├── TutorialExe.cs ├── UIUtils ├── AnimatedSpriteExporter.cs ├── AttractModeMenuScreen.cs ├── AudioUtils.cs ├── CLinkBuffer`1.cs ├── FancyOutlines.cs ├── GetStringUIControl.cs ├── LCG.cs ├── SavefileLoginScreen.cs ├── ScrollableSectionedPanel.cs └── WaveformRenderer.cs ├── UploadServerDaemon.cs ├── UserDetail.cs ├── UsernameGenerator.cs ├── Utils.cs ├── VehicleInfo.cs ├── VehicleRegistration.cs ├── VehicleType.cs ├── WebRenderer.cs ├── WebServerDaemon.cs ├── WorldLocation.cs └── WorldLocationLoader.cs /AchievementsManager.cs: -------------------------------------------------------------------------------- 1 | using Steamworks; 2 | 3 | namespace Hacknet 4 | { 5 | public static class AchievementsManager 6 | { 7 | public static bool Unlock(string name, bool recordAndCheckFlag = false) 8 | { 9 | try 10 | { 11 | var flag = name + "_Unlocked"; 12 | if (recordAndCheckFlag && OS.currentInstance.Flags.HasFlag(flag)) 13 | return false; 14 | SteamUserStats.SetAchievement(name); 15 | if (!SteamUserStats.StoreStats()) 16 | return false; 17 | OS.currentInstance.Flags.AddFlag(flag); 18 | return true; 19 | } 20 | catch 21 | { 22 | return false; 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /ActionDelayer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet 5 | { 6 | internal class ActionDelayer 7 | { 8 | public delegate bool Condition(ActionDelayer messagePump); 9 | 10 | private readonly List nextPairs = new List(); 11 | private readonly List pairs = new List(); 12 | 13 | public DateTime Time { get; private set; } 14 | 15 | public void Pump() 16 | { 17 | Time = DateTime.Now; 18 | pairs.AddRange(nextPairs); 19 | nextPairs.Clear(); 20 | for (var index = 0; index < pairs.Count; ++index) 21 | { 22 | var pair = pairs[index]; 23 | if (pair.Condition(this)) 24 | { 25 | pair.Action(); 26 | pairs.RemoveAt(index--); 27 | } 28 | } 29 | } 30 | 31 | public void RunAllDelayedActions() 32 | { 33 | pairs.AddRange(nextPairs); 34 | nextPairs.Clear(); 35 | Time = DateTime.MaxValue; 36 | for (var index = 0; index < pairs.Count; ++index) 37 | { 38 | var pair = pairs[index]; 39 | if (pair.Condition(this)) 40 | { 41 | pair.Action(); 42 | pairs.RemoveAt(index--); 43 | } 44 | } 45 | } 46 | 47 | public void Post(Condition condition, Action action) 48 | { 49 | nextPairs.Add(new Pair 50 | { 51 | Condition = condition, 52 | Action = action 53 | }); 54 | } 55 | 56 | public void PostAnimation(IEnumerator animation) 57 | { 58 | Action tick = null; 59 | tick = () => 60 | { 61 | if (!animation.MoveNext()) 62 | return; 63 | Post(animation.Current, tick); 64 | }; 65 | tick(); 66 | } 67 | 68 | public static Condition WaitUntil(DateTime time) 69 | { 70 | return x => x.Time >= time; 71 | } 72 | 73 | public static Condition Wait(double time) 74 | { 75 | return WaitUntil(DateTime.Now + TimeSpan.FromSeconds(time)); 76 | } 77 | 78 | public static Condition NextTick() 79 | { 80 | return x => true; 81 | } 82 | 83 | public static Condition FileDeleted(Folder f, string filename) 84 | { 85 | return x => !f.containsFile(filename); 86 | } 87 | 88 | private struct Pair 89 | { 90 | public Condition Condition; 91 | public Action Action; 92 | } 93 | } 94 | } -------------------------------------------------------------------------------- /Administrator.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal class Administrator 4 | { 5 | public bool IsSuper; 6 | public bool ResetsPassword; 7 | 8 | public virtual void disconnectionDetected(Computer c, OS os) 9 | { 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | [assembly: AssemblyCopyright("Copyright © 2011")] 5 | [assembly: AssemblyTrademark("")] 6 | [assembly: ComVisible(false)] 7 | [assembly: AssemblyCompany("")] 8 | [assembly: AssemblyProduct("Hacknet")] 9 | [assembly: Guid("42666cc8-b272-430b-a9cf-122fe0eba16e")] 10 | [assembly: AssemblyTitle("Hacknet")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyVersion("1.0.0.0")] -------------------------------------------------------------------------------- /AvconDemoEndDaemon.cs: -------------------------------------------------------------------------------- 1 | using Hacknet.Gui; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace Hacknet 6 | { 7 | internal class AvconDemoEndDaemon : Daemon 8 | { 9 | private bool confirmed; 10 | 11 | public AvconDemoEndDaemon(Computer c, string name, OS os) 12 | : base(c, name, os) 13 | { 14 | this.name = "Complete Demo"; 15 | } 16 | 17 | public override void navigatedTo() 18 | { 19 | base.navigatedTo(); 20 | confirmed = false; 21 | } 22 | 23 | public override void draw(Rectangle bounds, SpriteBatch sb) 24 | { 25 | base.draw(bounds, sb); 26 | if (Button.doButton(byte.MaxValue, bounds.X + bounds.Width/4, bounds.Y + bounds.Height/4, bounds.Width/2, 35, 27 | "Back", new Color?())) 28 | os.display.command = "connect"; 29 | if ( 30 | !Button.doButton(258, bounds.X + bounds.Width/4, bounds.Y + bounds.Height/4 + 40, bounds.Width/2, 35, 31 | !confirmed ? "End Session" : "Confirm End", confirmed ? Color.Red : Color.DarkRed)) 32 | return; 33 | if (confirmed) 34 | endDemo(); 35 | else 36 | confirmed = true; 37 | } 38 | 39 | public override string getSaveString() 40 | { 41 | return ""; 42 | } 43 | 44 | private void endDemo() 45 | { 46 | os.ScreenManager.AddScreen(new MainMenu()); 47 | os.ExitScreen(); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /BackgroundObject.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet 5 | { 6 | public struct BackgroundObject 7 | { 8 | public Vector2 pos { get; set; } 9 | 10 | public float Alpha { get; set; } 11 | 12 | public float Rotation { get; set; } 13 | 14 | public float VX { get; set; } 15 | 16 | public float VY { get; set; } 17 | 18 | public string SpritePath { get; set; } 19 | 20 | public float XScale { get; set; } 21 | 22 | public float YScale { get; set; } 23 | 24 | public Texture2D Texture { get; set; } 25 | 26 | public Color Colour { get; set; } 27 | 28 | public float Z { get; set; } 29 | } 30 | } -------------------------------------------------------------------------------- /BasicAdministrator.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal class BasicAdministrator : Administrator 4 | { 5 | public override void disconnectionDetected(Computer c, OS os) 6 | { 7 | base.disconnectionDetected(c, os); 8 | var time = 20.0*Utils.random.NextDouble(); 9 | os.delayer.Post(ActionDelayer.Wait(time), () => 10 | { 11 | if (os.connectedComp != null && !(os.connectedComp.ip != c.ip)) 12 | return; 13 | for (var index = 0; index < c.ports.Count; ++index) 14 | c.closePort(c.ports[index], "LOCAL_ADMIN"); 15 | if (ResetsPassword) 16 | c.setAdminPassword(PortExploits.getRandomPassword()); 17 | c.adminIP = c.ip; 18 | if (c.firewall == null) 19 | return; 20 | c.firewall.solved = false; 21 | c.firewall.resetSolutionProgress(); 22 | }); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /BoatMail.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet 5 | { 6 | internal class BoatMail : MailServer 7 | { 8 | public static string JunkEmail = 9 | "HOr$e Exp@nding R0Lexxxx corp\n\nHello Mister Mott,\nI am but a humble nigerian prince who is crippled by the instability in my country, and require a transfer of 5000 united states dollar in order to rid my country of the scourge of the musclebeasts which roam our plains and ravage our villages\nPlease send these funds to real_nigerian_prince_the_third@boatmail.com\nYours in jegus,\nNigerian Prince"; 10 | 11 | public Texture2D logo; 12 | 13 | public BoatMail(Computer c, string name, OS os) 14 | : base(c, name, os) 15 | { 16 | oddLine = Color.White; 17 | evenLine = Color.White; 18 | setThemeColor(new Color(155, 155, 230)); 19 | seperatorLineColor = new Color(22, 22, 22, 150); 20 | panel = TextureBank.load("BoatmailHeader", os.content); 21 | logo = TextureBank.load("BoatmailLogo", os.content); 22 | textColor = Color.Black; 23 | } 24 | 25 | public override void drawBackingGradient(Rectangle boundsTo, SpriteBatch sb) 26 | { 27 | } 28 | 29 | public override void doInboxHeader(Rectangle bounds, SpriteBatch sb) 30 | { 31 | } 32 | 33 | public override void drawTopBar(Rectangle bounds, SpriteBatch sb) 34 | { 35 | os.postFXDrawActions += () => 36 | { 37 | var destinationRectangle = new Rectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height); 38 | sb.Draw(Utils.white, destinationRectangle, Color.White); 39 | destinationRectangle.Height = panel.Height; 40 | sb.Draw(panel, destinationRectangle, Color.White); 41 | destinationRectangle.Width = destinationRectangle.Height = 36; 42 | destinationRectangle.X += 30; 43 | destinationRectangle.Y += 10; 44 | sb.Draw(logo, destinationRectangle, Color.White); 45 | }; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /ClockExe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace Hacknet 6 | { 7 | internal class ClockExe : ExeModule 8 | { 9 | public ClockExe(Rectangle location, OS operatingSystem, string[] p) 10 | : base(location, operatingSystem) 11 | { 12 | name = "Clock"; 13 | ramCost = 60; 14 | IdentifierName = "Clock"; 15 | targetIP = os.thisComputer.ip; 16 | AchievementsManager.Unlock("clock_run", false); 17 | } 18 | 19 | public override void Draw(float t) 20 | { 21 | base.Draw(t); 22 | drawOutline(); 23 | drawTarget("app:"); 24 | var now = DateTime.Now; 25 | TextItem.doFontLabel(new Vector2(bounds.X + 2, bounds.Y + 12), 26 | (now.Hour%12).ToString("00") + " : " + now.Minute.ToString("00") + " : " + now.Second.ToString("00"), 27 | GuiData.titlefont, RamModule.USED_RAM_COLOR, bounds.Width - 15, bounds.Height - 10); 28 | TextItem.doFontLabel(new Vector2(bounds.X + bounds.Width - 28, bounds.Y + bounds.Height - 38), 29 | now.Hour > 12 ? "PM" : "AM", GuiData.titlefont, RamModule.USED_RAM_COLOR, 30f, 26f); 30 | var width = bounds.Width - 2; 31 | var destinationRectangle = new Rectangle(bounds.X + 1, bounds.Y + bounds.Height - 1 - 6, width, 1); 32 | var num1 = now.Millisecond/1000f; 33 | var num2 = 0.0f; 34 | if (num1 < 0.5) 35 | num2 = (float) (1.0 - num1*2.0); 36 | spriteBatch.Draw(Utils.white, destinationRectangle, os.moduleColorSolidDefault*0.2f*num2); 37 | destinationRectangle.Width = (int) (width*(double) num1); 38 | spriteBatch.Draw(Utils.white, destinationRectangle, os.moduleColorSolidDefault*0.2f); 39 | var num3 = (now.Second + num1)/60f; 40 | destinationRectangle.Width = (int) (width*(double) num3); 41 | destinationRectangle.Y += 2; 42 | spriteBatch.Draw(Utils.white, destinationRectangle, os.moduleColorStrong); 43 | var num4 = now.Minute/60f; 44 | var num5 = now.Hour/60.0; 45 | destinationRectangle.Width = (int) (width*(double) num4); 46 | destinationRectangle.Y += 2; 47 | spriteBatch.Draw(Utils.white, destinationRectangle, os.moduleColorSolid); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /CollidableRectangle.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | public struct CollidableRectangle 6 | { 7 | private static readonly CollidableRectangle z = new CollidableRectangle(0.0f, 0.0f, Vector2.Zero); 8 | public Vector2 position; 9 | private float b_width; 10 | private float b_height; 11 | public Rectangle ck; 12 | 13 | public static CollidableRectangle Zero 14 | { 15 | get { return z; } 16 | } 17 | 18 | public Vector2 pos 19 | { 20 | get { return position; } 21 | set 22 | { 23 | position = value; 24 | ck.X = (int) pos.X; 25 | ck.Y = (int) pos.Y; 26 | } 27 | } 28 | 29 | public float Width 30 | { 31 | get { return b_width; } 32 | set 33 | { 34 | b_width = value; 35 | ck.Width = (int) value; 36 | } 37 | } 38 | 39 | public float Height 40 | { 41 | get { return b_height; } 42 | set 43 | { 44 | b_height = value; 45 | ck.Height = (int) value; 46 | } 47 | } 48 | 49 | public Rectangle checkable 50 | { 51 | get { return ck; } 52 | } 53 | 54 | public CollidableRectangle(float w, float h, Vector2 p) 55 | { 56 | b_width = w; 57 | b_height = h; 58 | position = p; 59 | ck = new Rectangle(); 60 | } 61 | 62 | public override bool Equals(object obj) 63 | { 64 | if (!(obj is CollidableRectangle)) 65 | return false; 66 | return ((CollidableRectangle) obj).checkable.Equals(checkable); 67 | } 68 | 69 | public override int GetHashCode() 70 | { 71 | return base.GetHashCode(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /CollidableTriangle.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | public struct CollidableTriangle 6 | { 7 | public Vector2 p1 { get; set; } 8 | 9 | public Vector2 p2 { get; set; } 10 | 11 | public Vector2 p3 { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /ComputerTypeInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public class ComputerTypeInfo 4 | { 5 | public static string getDefaultBootDaemonFilename(object c) 6 | { 7 | return "DefaultBootModule.txt"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /ConnectedNodeEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet 7 | { 8 | internal class ConnectedNodeEffect 9 | { 10 | private const int NUMBER_OF_SEGMENTS = 7; 11 | private const float MIN_DISTANCE = 18f; 12 | private const float MAX_DISTANCE = 30f; 13 | private static List textures; 14 | public Color color; 15 | private float[] distance; 16 | public bool Intense; 17 | private float[] offset; 18 | private Vector2 origin; 19 | private readonly OS os; 20 | public float ScaleFactor = 1f; 21 | private int[] tex; 22 | private float[] timescale; 23 | 24 | public ConnectedNodeEffect(OS os) 25 | { 26 | this.os = os; 27 | init(false); 28 | } 29 | 30 | public ConnectedNodeEffect(OS os, bool intense) 31 | { 32 | this.os = os; 33 | Intense = intense; 34 | init(intense); 35 | } 36 | 37 | private void init(bool intesne = false) 38 | { 39 | if (textures == null) 40 | { 41 | textures = new List(); 42 | textures.Add(os.content.Load("rotator")); 43 | textures.Add(os.content.Load("rotator2")); 44 | textures.Add(os.content.Load("rotator3")); 45 | textures.Add(os.content.Load("rotator4")); 46 | textures.Add(os.content.Load("rotator5")); 47 | } 48 | origin = new Vector2(textures[0].Width/2, textures[0].Height/2); 49 | var length = (intesne ? 2 : 1)*7; 50 | tex = new int[length]; 51 | distance = new float[length]; 52 | offset = new float[length]; 53 | timescale = new float[length]; 54 | color = new Color(140, 12, 12, 50); 55 | reset(); 56 | } 57 | 58 | public void reset() 59 | { 60 | var num = Intense ? 1.5f : 1f; 61 | for (var index = 0; index < 7; ++index) 62 | { 63 | tex[index] = Utils.random.Next(textures.Count - 1); 64 | distance[index] = (float) (Utils.random.NextDouble()*(30.0*num - 18.0/num) + 18.0/num); 65 | offset[index] = (float) (Utils.random.NextDouble()*(2.0*Math.PI)); 66 | timescale[index] = (float) Utils.random.NextDouble(); 67 | } 68 | } 69 | 70 | public void draw(SpriteBatch sb, Vector2 pos) 71 | { 72 | for (var index = 0; index < 7; ++index) 73 | { 74 | var origin = this.origin + new Vector2(0.0f, distance[index]); 75 | var rotation = 76 | (float) (os.timer*timescale[index]*0.200000002980232%1.0*(2.0*Math.PI)*(index%2 == 0 ? 1.0 : -1.0)) + 77 | offset[index]; 78 | var scale = 79 | new Vector2( 80 | (float) (distance[index]/(30.0*(Intense ? 1.5 : 1.0))*0.699999988079071 + 0.300000011920929), 1f); 81 | scale *= ScaleFactor; 82 | sb.Draw(textures[tex[index]], pos, new Rectangle?(), color, rotation, origin, scale, SpriteEffects.None, 83 | 0.5f); 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /CoreModule.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet 5 | { 6 | internal class CoreModule : Module 7 | { 8 | private static Texture2D LockSprite; 9 | private bool guiInputLockStatus; 10 | public bool inputLocked; 11 | 12 | public CoreModule(Rectangle location, OS operatingSystem) 13 | : base(location, operatingSystem) 14 | { 15 | } 16 | 17 | public override void LoadContent() 18 | { 19 | base.LoadContent(); 20 | if (LockSprite != null) 21 | return; 22 | LockSprite = os.content.Load("Lock"); 23 | } 24 | 25 | public override void PreDrawStep() 26 | { 27 | base.PreDrawStep(); 28 | if (!inputLocked) 29 | return; 30 | guiInputLockStatus = GuiData.blockingInput; 31 | GuiData.blockingInput = true; 32 | } 33 | 34 | public override void PostDrawStep() 35 | { 36 | base.PostDrawStep(); 37 | if (!inputLocked) 38 | return; 39 | GuiData.blockingInput = false; 40 | GuiData.blockingInput = guiInputLockStatus; 41 | var destinationRectangle = bounds; 42 | if (!destinationRectangle.Contains(GuiData.getMousePoint())) 43 | return; 44 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, Color.Gray*0.5f); 45 | var position = new Vector2(destinationRectangle.X + destinationRectangle.Width/2 - LockSprite.Width/2, 46 | destinationRectangle.Y + destinationRectangle.Height/2 - LockSprite.Height/2); 47 | GuiData.spriteBatch.Draw(LockSprite, position, Color.White); 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /Daemon.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet 5 | { 6 | internal class Daemon 7 | { 8 | public Computer comp; 9 | public bool isListed; 10 | public string name; 11 | public OS os; 12 | 13 | public Daemon(Computer computer, string serviceName, OS opSystem) 14 | { 15 | name = serviceName; 16 | isListed = true; 17 | comp = computer; 18 | os = opSystem; 19 | } 20 | 21 | public virtual void initFiles() 22 | { 23 | } 24 | 25 | public virtual void draw(Rectangle bounds, SpriteBatch sb) 26 | { 27 | } 28 | 29 | public virtual void navigatedTo() 30 | { 31 | } 32 | 33 | public virtual void userAdded(string name, string pass, byte type) 34 | { 35 | } 36 | 37 | public virtual string getSaveString() 38 | { 39 | return ""; 40 | } 41 | 42 | public virtual void loadInit() 43 | { 44 | } 45 | 46 | public static bool validUser(byte type) 47 | { 48 | if (type != 1) 49 | return type == 0; 50 | return true; 51 | } 52 | 53 | public void registerAsDefaultBootDaemon() 54 | { 55 | if (!comp.AllowsDefaultBootModule) 56 | return; 57 | var fileEntry = 58 | comp.files.root.searchForFolder("sys") 59 | .searchForFile(ComputerTypeInfo.getDefaultBootDaemonFilename(this)); 60 | if (fileEntry != null) 61 | { 62 | if (!(fileEntry.data != "[Locked]")) 63 | return; 64 | fileEntry.data = name; 65 | } 66 | else 67 | comp.files.root.searchForFolder("sys") 68 | .files.Add(new FileEntry(name, ComputerTypeInfo.getDefaultBootDaemonFilename(this))); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /Daemons/Helpers/IMedicalMonitor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet.Daemons.Helpers 5 | { 6 | public interface IMedicalMonitor 7 | { 8 | void HeartBeat(float beatTime); 9 | 10 | void Update(float dt); 11 | 12 | void Draw(Rectangle bounds, SpriteBatch sb, Color c, float timeRollback); 13 | } 14 | } -------------------------------------------------------------------------------- /DebugLog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet 4 | { 5 | public static class DebugLog 6 | { 7 | public static char[] delimiters = new char[2] 8 | { 9 | '\n', 10 | '\r' 11 | }; 12 | 13 | public static List data = new List(64); 14 | 15 | public static void add(string s) 16 | { 17 | var strArray = s.Split(delimiters); 18 | for (var index = 0; index < strArray.Length; ++index) 19 | { 20 | if (!strArray[index].Equals("")) 21 | data.Add(strArray[index]); 22 | } 23 | } 24 | 25 | public static string GetDump() 26 | { 27 | var str = ""; 28 | for (var index = 0; index < data.Count; ++index) 29 | str = str + data[index] + "\r\n"; 30 | return str; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Degree.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct Degree 4 | { 5 | public string name; 6 | public string uni; 7 | public float GPA; 8 | 9 | public Degree(string degreeName, string uniName, float degreeGPA) 10 | { 11 | name = degreeName; 12 | uni = uniName; 13 | GPA = degreeGPA; 14 | } 15 | 16 | public override string ToString() 17 | { 18 | return name + " from " + uni + ". GPA: " + GPA; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /DelayedInput.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct DelayedInput 4 | { 5 | public double Delay { get; set; } 6 | 7 | public InputMap inputs { get; set; } 8 | 9 | public float xPos { get; set; } 10 | 11 | public float yPos { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Effects/AudioVisualizer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using Microsoft.Xna.Framework; 6 | using Microsoft.Xna.Framework.Graphics; 7 | using Microsoft.Xna.Framework.Media; 8 | 9 | namespace Hacknet.Effects 10 | { 11 | public class AudioVisualizer 12 | { 13 | private List> samplesHistory; 14 | private readonly VisualizationData visData = new VisualizationData(); 15 | 16 | public void Draw(Rectangle bounds, SpriteBatch sb) 17 | { 18 | if (samplesHistory == null) 19 | { 20 | samplesHistory = new List>(); 21 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 22 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 23 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 24 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 25 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 26 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 27 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 28 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 29 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 30 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 31 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 32 | samplesHistory.Add(new ReadOnlyCollection(new float[0])); 33 | } 34 | if (MediaPlayer.State == MediaState.Playing) 35 | { 36 | MediaPlayer.IsVisualizationEnabled = true; 37 | MediaPlayer.GetVisualizationData(visData); 38 | } 39 | if (visData == null) 40 | return; 41 | var num1 = bounds.Height/(float) visData.Frequencies.Count; 42 | var vector2 = new Vector2(bounds.X, bounds.Y); 43 | for (var index1 = 0; index1 < visData.Frequencies.Count; ++index1) 44 | { 45 | var index2 = index1; 46 | sb.Draw(Utils.white, 47 | new Rectangle((int) vector2.X, (int) vector2.Y, 48 | (int) (bounds.Width*(double) visData.Frequencies[index2]), Math.Max(1, (int) num1)), 49 | OS.currentInstance.highlightColor*(float) (0.200000002980232 + visData.Frequencies[index2]/2.0)*0.2f); 50 | vector2.Y += num1; 51 | } 52 | samplesHistory.Add(new ReadOnlyCollection(visData.Samples.ToArray())); 53 | samplesHistory.RemoveAt(0); 54 | for (var index1 = 0; index1 < samplesHistory.Count; ++index1) 55 | { 56 | var num2 = index1/(float) (samplesHistory.Count - 1); 57 | vector2.Y = bounds.Y; 58 | for (var index2 = 0; index2 < samplesHistory[index1].Count; ++index2) 59 | { 60 | var color = index1 >= samplesHistory.Count - 1 61 | ? Utils.AddativeWhite*0.7f 62 | : OS.currentInstance.highlightColor; 63 | sb.Draw(Utils.white, 64 | new Vector2( 65 | bounds.X + (float) (samplesHistory[index1][index2]*(bounds.Width/4.0) + bounds.Width*0.75) + 66 | index1*2 - samplesHistory.Count, vector2.Y), new Rectangle?(), 67 | color*0.6f*(0.01f + num2)*0.4f); 68 | vector2.Y += num1; 69 | } 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Effects/HexGridBackground.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.UIUtils; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Content; 5 | using Microsoft.Xna.Framework.Graphics; 6 | 7 | namespace Hacknet.Effects 8 | { 9 | public class HexGridBackground 10 | { 11 | public enum ColoringAlgorithm 12 | { 13 | NegaitiveSinWash, 14 | CorrectedSinWash, 15 | OutlinedSinWash 16 | } 17 | 18 | public bool HasRedFlashyOnes; 19 | private readonly Texture2D Hex; 20 | public float HexScale = 0.1f; 21 | private readonly LCG lcg = new LCG(false); 22 | private readonly Texture2D Outline; 23 | private float timer; 24 | 25 | public HexGridBackground(ContentManager content) 26 | { 27 | Hex = content.Load("Sprites/Misc/Hexagon"); 28 | Outline = content.Load("Sprites/Misc/HexOutline"); 29 | } 30 | 31 | public void Update(float dt) 32 | { 33 | timer += dt; 34 | } 35 | 36 | public void Draw(Rectangle dest, SpriteBatch sb, Color first, Color second, 37 | ColoringAlgorithm algorithm = ColoringAlgorithm.CorrectedSinWash, float angle = 0.0f) 38 | { 39 | var num1 = 2f; 40 | float x = dest.X; 41 | float y = dest.Y; 42 | var num2 = HexScale*Hex.Width; 43 | var num3 = HexScale*Hex.Height; 44 | var seed = 10; 45 | var flag1 = true; 46 | while (x + (double) num2 < dest.X + dest.Width) 47 | { 48 | while (y + (double) num3 < dest.Y + dest.Height) 49 | { 50 | lcg.reSeed(seed); 51 | var num4 = lcg.NextFloat(); 52 | var flag2 = false; 53 | var color = second; 54 | if (HasRedFlashyOnes && num4 <= 1.0/1000.0) 55 | { 56 | color = Utils.AddativeRed*0.5f; 57 | flag2 = true; 58 | } 59 | float amount; 60 | switch (algorithm) 61 | { 62 | case ColoringAlgorithm.NegaitiveSinWash: 63 | amount = (float) Math.Sin(num4 + timer*(double) lcg.NextFloat()); 64 | break; 65 | default: 66 | amount = 67 | Math.Abs( 68 | (float) 69 | Math.Sin(num4 + timer*(double) Math.Abs(lcg.NextFloat()*(flag2 ? 1f : 0.3f)))); 70 | break; 71 | } 72 | sb.Draw(Hex, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(), 73 | Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale), SpriteEffects.None, 74 | 0.4f); 75 | if (algorithm == ColoringAlgorithm.OutlinedSinWash) 76 | { 77 | if (flag2) 78 | color = Utils.AddativeRed; 79 | sb.Draw(Outline, Utils.RotatePoint(new Vector2(x, y), angle), new Rectangle?(), 80 | Color.Lerp(first, color, amount), angle, Vector2.Zero, new Vector2(HexScale), 81 | SpriteEffects.None, 0.4f); 82 | } 83 | ++seed; 84 | y += num3 + num1; 85 | } 86 | x += num2 - 60f*HexScale + num1; 87 | y = dest.Y; 88 | ++seed; 89 | if (flag1) 90 | y -= num3/2f; 91 | flag1 = !flag1; 92 | } 93 | } 94 | } 95 | } -------------------------------------------------------------------------------- /Effects/MovingBarsEffect.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace Hacknet.Effects 6 | { 7 | public class MovingBarsEffect 8 | { 9 | public bool IsInverted; 10 | private readonly List Lines = new List(); 11 | public float MaxLineChangeTime = 2f; 12 | public float MinLineChangeTime = 0.2f; 13 | 14 | public void Update(float dt) 15 | { 16 | for (var index = 0; index < Lines.Count; ++index) 17 | { 18 | var barLine = Lines[index]; 19 | barLine.TimeRemaining -= dt; 20 | if (barLine.TimeRemaining <= 0.0) 21 | { 22 | barLine.Current = barLine.Next; 23 | barLine.Next = Utils.randm(1f); 24 | barLine.TotalTimeThisStep = MinLineChangeTime + Utils.randm(MaxLineChangeTime - MinLineChangeTime); 25 | barLine.TimeRemaining = barLine.TotalTimeThisStep; 26 | } 27 | Lines[index] = barLine; 28 | } 29 | } 30 | 31 | public void Draw(SpriteBatch sb, Rectangle bounds, float minHeight, float lineWidth, float lineSeperation, 32 | Color drawColor) 33 | { 34 | var num1 = 0; 35 | var num2 = 0.0f; 36 | while (num2 + (double) lineWidth < bounds.Width) 37 | { 38 | ++num1; 39 | num2 += lineWidth + lineSeperation; 40 | } 41 | var flag = false; 42 | while (Lines.Count - 1 < num1) 43 | { 44 | Lines.Add(new BarLine 45 | { 46 | TimeRemaining = -1f 47 | }); 48 | flag = true; 49 | } 50 | if (flag) 51 | Update(0.0f); 52 | float num3 = bounds.X; 53 | for (var index = 0; index < num1; ++index) 54 | { 55 | var barLine = Lines[index]; 56 | var num4 = 57 | Utils.QuadraticOutCurve((float) (1.0 - barLine.TimeRemaining/(double) barLine.TotalTimeThisStep)); 58 | var num5 = barLine.Current + (barLine.Next - barLine.Current)*num4; 59 | var num6 = bounds.Height - minHeight; 60 | var height = (int) (minHeight + num6*(double) num5); 61 | var destinationRectangle = new Rectangle((int) num3, bounds.Y + bounds.Height - height, (int) lineWidth, 62 | height); 63 | if (IsInverted) 64 | destinationRectangle.Y = bounds.Y; 65 | sb.Draw(Utils.white, destinationRectangle, drawColor); 66 | num3 += lineWidth + lineSeperation; 67 | } 68 | } 69 | 70 | private struct BarLine 71 | { 72 | public float Current; 73 | public float Next; 74 | public float TimeRemaining; 75 | public float TotalTimeThisStep; 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Effects/NodeBounceEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet.Effects 7 | { 8 | public class NodeBounceEffect 9 | { 10 | private float delayTillNextBounce; 11 | private readonly List locations = new List(); 12 | public int maxNodes = 200; 13 | public float NodeHitDelay = 0.2f; 14 | public float TimeBetweenBounces = 0.07f; 15 | private float timeToNextBounce; 16 | 17 | public NodeBounceEffect() 18 | { 19 | locations.Add(new Vector2(Utils.rand(), Utils.rand())); 20 | locations.Add(new Vector2(Utils.rand(), Utils.rand())); 21 | } 22 | 23 | public void Update(float t, Action nodeHitAction = null) 24 | { 25 | timeToNextBounce -= t; 26 | if (timeToNextBounce > 0.0) 27 | return; 28 | if (delayTillNextBounce <= 0.0) 29 | { 30 | if (nodeHitAction != null) 31 | nodeHitAction(locations[locations.Count - 1]); 32 | locations.Add(new Vector2(Utils.rand(), Utils.rand())); 33 | timeToNextBounce = TimeBetweenBounces; 34 | delayTillNextBounce = NodeHitDelay; 35 | while (locations.Count > maxNodes) 36 | locations.RemoveAt(0); 37 | } 38 | else 39 | { 40 | delayTillNextBounce -= t; 41 | timeToNextBounce = 0.0f; 42 | } 43 | } 44 | 45 | public void Draw(SpriteBatch spriteBatch, Rectangle bounds, Color lineColor, Color nodeColor) 46 | { 47 | var vector2_1 = locations[0]; 48 | var vector2_2 = new Vector2(bounds.X + 2f, bounds.Y + 26f); 49 | var vector2_3 = new Vector2(bounds.Width - 4f, bounds.Height - 30f); 50 | if (vector2_3.X <= 0.0 || vector2_3.Y <= 0.0) 51 | return; 52 | for (var index = 1; index < locations.Count; ++index) 53 | { 54 | var vector2_4 = locations[index]; 55 | if (index == locations.Count - 1) 56 | vector2_4 = Vector2.Lerp(vector2_1, vector2_4, 57 | (float) (1.0 - timeToNextBounce/(double) TimeBetweenBounces)); 58 | Utils.drawLine(spriteBatch, vector2_2 + vector2_1*vector2_3, vector2_2 + vector2_4*vector2_3, 59 | Vector2.Zero, lineColor*(index/(float) locations.Count), 0.4f); 60 | vector2_1 = locations[index]; 61 | } 62 | for (var index = 1; index < locations.Count; ++index) 63 | spriteBatch.Draw(Utils.white, locations[index]*vector2_3 + vector2_2, nodeColor); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Effects/ThinBarcode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet.Effects 7 | { 8 | public class ThinBarcode 9 | { 10 | private readonly List gaps = new List(); 11 | private List gapsLast = new List(); 12 | private readonly int height; 13 | private readonly int oldW; 14 | private readonly List widths = new List(); 15 | private List widthsLast = new List(); 16 | 17 | public ThinBarcode(int w, int height) 18 | { 19 | oldW = w; 20 | this.height = height; 21 | regenerate(); 22 | widthsLast = widths; 23 | gapsLast = gaps; 24 | } 25 | 26 | public void regenerate() 27 | { 28 | var num1 = oldW; 29 | widthsLast = widths; 30 | gapsLast = gaps; 31 | widths.Clear(); 32 | gaps.Clear(); 33 | var num2 = 0; 34 | while (num2 < num1) 35 | { 36 | var num3 = Math.Min(num1 - num2, Utils.random.Next(1, 20)); 37 | if (num3 > 0) 38 | { 39 | var num4 = Utils.random.Next(3, 11); 40 | widths.Add(num3); 41 | gaps.Add(num4); 42 | num2 += num3 + num4; 43 | } 44 | } 45 | } 46 | 47 | public void Draw(SpriteBatch sb, int posX, int posY, Color c) 48 | { 49 | var destinationRectangle = new Rectangle(posX, posY, 0, height); 50 | for (var index = 0; index < widths.Count; ++index) 51 | { 52 | destinationRectangle.Width = widths[index]; 53 | sb.Draw(Utils.white, destinationRectangle, c); 54 | destinationRectangle.X += widths[index]; 55 | destinationRectangle.X += gaps[index]; 56 | } 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Effects/WebpageLoadingEffect.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet.Effects 7 | { 8 | public static class WebpageLoadingEffect 9 | { 10 | public static void DrawLoadingEffect(Rectangle bounds, SpriteBatch sb, object OS_obj, 11 | bool drawLoadingText = true) 12 | { 13 | var os = (OS) OS_obj; 14 | var rectangle = new Rectangle(bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2, 2, 70); 15 | var num1 = (float) Math.Abs(Math.Sin(os.timer*0.200000002980232)*100.0); 16 | var origin = new Vector2(2f, 10f); 17 | var num2 = 6.283185f/num1; 18 | var rotation = 0.0f; 19 | var num3 = 0; 20 | while (rotation < 6.28318548202515) 21 | { 22 | var destinationRectangle = rectangle; 23 | destinationRectangle.Height = 24 | Math.Abs((int) (rectangle.Height*Math.Sin(2.0*os.timer + num3*0.200000002980232))) + 10; 25 | origin.Y = 1.6f; 26 | sb.Draw(Utils.white, destinationRectangle, new Rectangle?(), os.highlightColor, rotation, origin, 27 | SpriteEffects.FlipVertically, 0.6f); 28 | ++num3; 29 | rotation += num2; 30 | } 31 | if (!drawLoadingText) 32 | return; 33 | TextItem.doFontLabelToSize(new Rectangle(bounds.X, bounds.Y + 20, bounds.Width, 30), "Loading...", 34 | GuiData.font, Utils.AddativeWhite); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /ExternalCounterpart.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | using System.Threading; 7 | 8 | namespace Hacknet 9 | { 10 | public class ExternalCounterpart 11 | { 12 | private static Dictionary networkIPList; 13 | private static ASCIIEncoding encoder; 14 | private byte[] buffer; 15 | private TcpClient connection; 16 | public string connectionIP; 17 | public string idName; 18 | public bool isConnected; 19 | 20 | public ExternalCounterpart(string idName, string ipEndpoint) 21 | { 22 | this.idName = idName; 23 | connectionIP = ipEndpoint; 24 | buffer = new byte[4096]; 25 | if (encoder != null) 26 | return; 27 | encoder = new ASCIIEncoding(); 28 | } 29 | 30 | public static string getIPForServerName(string serverName) 31 | { 32 | if (networkIPList == null) 33 | loadNetIPList(); 34 | if (networkIPList.ContainsKey(serverName)) 35 | return networkIPList[serverName]; 36 | throw new InvalidOperationException("Server Name Not Found"); 37 | } 38 | 39 | private static void loadNetIPList() 40 | { 41 | networkIPList = new Dictionary(); 42 | var str1 = Utils.readEntireFile("Content/Network/NetworkIPList.txt"); 43 | var separator = new string[2] 44 | { 45 | "\n\r", 46 | "\r\n" 47 | }; 48 | var num = 1; 49 | foreach (var str2 in str1.Split(separator, (StringSplitOptions) num)) 50 | { 51 | var strArray = str2.Split(Utils.spaceDelim); 52 | networkIPList.Add(strArray[0], strArray[1]); 53 | } 54 | } 55 | 56 | public void sendMessage(string message) 57 | { 58 | if (!isConnected) 59 | return; 60 | writeMessage(message); 61 | } 62 | 63 | public void disconnect() 64 | { 65 | if (!isConnected) 66 | return; 67 | writeMessage("Disconnecting"); 68 | connection.Close(); 69 | isConnected = false; 70 | } 71 | 72 | public void testConnection() 73 | { 74 | establishConnection(); 75 | while (!isConnected) 76 | Thread.Sleep(5); 77 | writeMessage("Test Message From " + idName); 78 | } 79 | 80 | public void establishConnection() 81 | { 82 | var tcpClient = new TcpClient(); 83 | tcpClient.BeginConnect(IPAddress.Parse(connectionIP), Multiplayer.PORT, DoTcpConnectionCallback, tcpClient); 84 | } 85 | 86 | private void DoTcpConnectionCallback(IAsyncResult ar) 87 | { 88 | var tcpClient = ar.AsyncState as TcpClient; 89 | if (tcpClient == null || !tcpClient.Connected) 90 | return; 91 | isConnected = true; 92 | connection = tcpClient; 93 | tcpClient.EndConnect(ar); 94 | } 95 | 96 | public void writeMessage(string message) 97 | { 98 | if (isConnected) 99 | { 100 | var stream = connection.GetStream(); 101 | buffer = encoder.GetBytes(message); 102 | stream.BeginWrite(buffer, 0, buffer.Length, TCPWriteMessageCallback, stream); 103 | } 104 | else 105 | establishConnection(); 106 | } 107 | 108 | private void TCPWriteMessageCallback(IAsyncResult ar) 109 | { 110 | var networkStream = ar.AsyncState as NetworkStream; 111 | if (networkStream == null) 112 | return; 113 | try 114 | { 115 | networkStream.EndWrite(ar); 116 | } 117 | catch (Exception ex) 118 | { 119 | } 120 | } 121 | } 122 | } -------------------------------------------------------------------------------- /ExternalCounterparts/ExternalNetworkedServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net; 4 | using System.Net.Sockets; 5 | using System.Text; 6 | 7 | namespace Hacknet.ExternalCounterparts 8 | { 9 | public class ExternalNetworkedServer 10 | { 11 | private const int BUFFER_SIZE = 4096; 12 | private static ASCIIEncoding encoder; 13 | private readonly Dictionary buffers; 14 | private readonly List connections; 15 | private TcpListener listener; 16 | public Action messageReceived; 17 | 18 | public ExternalNetworkedServer() 19 | { 20 | connections = new List(); 21 | buffers = new Dictionary(); 22 | if (encoder != null) 23 | return; 24 | encoder = new ASCIIEncoding(); 25 | } 26 | 27 | public void initializeListener() 28 | { 29 | listener = new TcpListener(new IPEndPoint(IPAddress.Any, Multiplayer.PORT)); 30 | listener.AllowNatTraversal(true); 31 | listener.Start(); 32 | listener.BeginAcceptTcpClient(AcceptTcpConnectionCallback, listener); 33 | } 34 | 35 | public void closeServer() 36 | { 37 | listener.Stop(); 38 | foreach (var tcpClient in connections) 39 | { 40 | tcpClient.GetStream().Close(); 41 | tcpClient.Close(); 42 | } 43 | } 44 | 45 | private void AcceptTcpConnectionCallback(IAsyncResult ar) 46 | { 47 | var tcpListener = ar.AsyncState as TcpListener; 48 | if (tcpListener == null) 49 | return; 50 | try 51 | { 52 | var tcpClient = listener.EndAcceptTcpClient(ar); 53 | if (tcpClient == null) 54 | return; 55 | connections.Add(tcpClient); 56 | var stream = tcpClient.GetStream(); 57 | buffers.Add(stream, new byte[4096]); 58 | if (messageReceived != null) 59 | messageReceived("Connection"); 60 | tcpClient.GetStream().BeginRead(buffers[stream], 0, 4096, TcpReadCallback, stream); 61 | tcpListener.BeginAcceptTcpClient(AcceptTcpConnectionCallback, tcpListener); 62 | } 63 | catch (Exception ex) 64 | { 65 | } 66 | } 67 | 68 | private void TcpReadCallback(IAsyncResult ar) 69 | { 70 | var index = ar.AsyncState as NetworkStream; 71 | if (index == null) 72 | return; 73 | try 74 | { 75 | var count = index.EndRead(ar); 76 | if (count == 0) 77 | return; 78 | var bytes = buffers[index]; 79 | var @string = encoder.GetString(bytes, 0, count); 80 | if (messageReceived != null) 81 | messageReceived(@string); 82 | index.BeginRead(buffers[index], 0, 4096, TcpReadCallback, index); 83 | } 84 | catch (Exception ex) 85 | { 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /Factions/AllFactions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Xml; 3 | 4 | namespace Hacknet.Factions 5 | { 6 | internal class AllFactions 7 | { 8 | public string currentFaction; 9 | public Dictionary factions = new Dictionary(); 10 | 11 | public AllFactions() 12 | { 13 | currentFaction = "entropy"; 14 | } 15 | 16 | public void init() 17 | { 18 | var dictionary1 = factions; 19 | var key1 = "entropy"; 20 | var entropyFaction1 = new EntropyFaction("Entropy", 5); 21 | entropyFaction1.idName = "entropy"; 22 | var entropyFaction2 = entropyFaction1; 23 | dictionary1.Add(key1, entropyFaction2); 24 | factions.Add("lelzSec", new Faction("lelzSec", 1000) 25 | { 26 | idName = "lelzSec" 27 | }); 28 | var dictionary2 = factions; 29 | var key2 = "hub"; 30 | var hubFaction1 = new HubFaction("CSEC", 10); 31 | hubFaction1.idName = "hub"; 32 | var hubFaction2 = hubFaction1; 33 | dictionary2.Add(key2, hubFaction2); 34 | } 35 | 36 | public string getSaveString() 37 | { 38 | var str = "\n"; 39 | foreach (var keyValuePair in factions) 40 | str = str + "\t" + keyValuePair.Value.getSaveString(); 41 | return str + ""; 42 | } 43 | 44 | public void setCurrentFaction(string newFaction, OS os) 45 | { 46 | currentFaction = newFaction; 47 | os.currentFaction = factions[currentFaction]; 48 | } 49 | 50 | public static AllFactions loadFromSave(XmlReader xmlRdr) 51 | { 52 | var allFactions = new AllFactions(); 53 | while (xmlRdr.Name != "AllFactions") 54 | xmlRdr.Read(); 55 | if (xmlRdr.MoveToAttribute("current")) 56 | allFactions.currentFaction = xmlRdr.ReadContentAsString(); 57 | while (!(xmlRdr.Name == "AllFactions") || xmlRdr.IsStartElement()) 58 | { 59 | var faction = Faction.loadFromSave(xmlRdr); 60 | allFactions.factions.Add(faction.idName, faction); 61 | xmlRdr.Read(); 62 | } 63 | return allFactions; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Factions/EntropyFaction.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet.Factions 2 | { 3 | internal class EntropyFaction : Faction 4 | { 5 | public EntropyFaction(string _name, int _neededValue) 6 | : base(_name, _neededValue) 7 | { 8 | } 9 | 10 | public override void addValue(int value, object os) 11 | { 12 | var oldValue = playerValue; 13 | base.addValue(value, os); 14 | if (!valuePassedPoint(oldValue, 3)) 15 | return; 16 | ((OS) os).Flags.AddFlag("eosPathStarted"); 17 | ComputerLoader.loadMission("Content/Missions/Entropy/StartingSet/eosMissions/eosIntroDelayer.xml"); 18 | } 19 | 20 | public override void playerPassedValue(object os) 21 | { 22 | base.playerPassedValue(os); 23 | if (Settings.isAlphaDemoMode) 24 | ComputerLoader.loadMission("Content/Missions/Entropy/EntropyMission3.xml"); 25 | else 26 | ((OS) os).delayer.Post(ActionDelayer.Wait(1.7), 27 | () => ComputerLoader.loadMission("Content/Missions/Entropy/ThemeHackTransitionMission.xml")); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /FastBasicAdministrator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacknet 4 | { 5 | internal class FastBasicAdministrator : Administrator 6 | { 7 | public override void disconnectionDetected(Computer c, OS os) 8 | { 9 | base.disconnectionDetected(c, os); 10 | for (var index = 0; index < c.ports.Count; ++index) 11 | c.closePort(c.ports[index], "LOCAL_ADMIN"); 12 | if (c.firewall != null) 13 | { 14 | c.firewall.resetSolutionProgress(); 15 | c.firewall.solved = false; 16 | } 17 | if (c.hasProxy) 18 | { 19 | c.proxyActive = true; 20 | c.proxyOverloadTicks = c.startingOverloadTicks; 21 | } 22 | var time = 20.0*Utils.random.NextDouble(); 23 | Action action = () => 24 | { 25 | if (os.connectedComp != null && !(os.connectedComp.ip != c.ip)) 26 | return; 27 | for (var index = 0; index < c.ports.Count; ++index) 28 | c.closePort(c.ports[index], "LOCAL_ADMIN"); 29 | if (ResetsPassword) 30 | c.setAdminPassword(PortExploits.getRandomPassword()); 31 | c.adminIP = c.ip; 32 | if (c.firewall == null) 33 | return; 34 | c.firewall.resetSolutionProgress(); 35 | }; 36 | if (IsSuper) 37 | action(); 38 | else 39 | os.delayer.Post(ActionDelayer.Wait(time), action); 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /FileEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Content; 6 | 7 | namespace Hacknet 8 | { 9 | public class FileEntry : FileType 10 | { 11 | public static List filenames; 12 | public static List fileData; 13 | public string data; 14 | public string name; 15 | public int secondCreatedAt; 16 | public int size; 17 | 18 | public FileEntry() 19 | { 20 | var index = Utils.random.Next(0, filenames.Count - 1); 21 | name = filenames[index]; 22 | data = fileData[index]; 23 | size = data.Length*8; 24 | secondCreatedAt = (int) OS.currentElapsedTime; 25 | } 26 | 27 | public FileEntry(string dataEntry, string nameEntry) 28 | { 29 | nameEntry = nameEntry.Replace(" ", "_"); 30 | name = nameEntry; 31 | data = dataEntry; 32 | size = data.Length*8; 33 | secondCreatedAt = (int) OS.currentElapsedTime; 34 | } 35 | 36 | public string getName() 37 | { 38 | return name; 39 | } 40 | 41 | public string head() 42 | { 43 | var index = 0; 44 | var str = ""; 45 | for (; index < data.Length && data[index] != 10 && index < 50; ++index) 46 | str += data[index].ToString(); 47 | return str; 48 | } 49 | 50 | public static void init(ContentManager content) 51 | { 52 | filenames = new List(128); 53 | fileData = new List(128); 54 | var files = new DirectoryInfo(content.RootDirectory + "\\files").GetFiles("*.*"); 55 | for (var index = 0; index < files.Length; ++index) 56 | { 57 | filenames.Add(Path.GetFileNameWithoutExtension(files[index].Name)); 58 | var streamReader = 59 | new StreamReader(TitleContainer.OpenStream("Content/files/" + Path.GetFileName(files[index].Name))); 60 | fileData.Add(streamReader.ReadToEnd()); 61 | streamReader.Close(); 62 | } 63 | var strArray = 64 | new StreamReader(TitleContainer.OpenStream("Content/BashLogs.txt")).ReadToEnd().Split(new string[1] 65 | { 66 | "\n#" 67 | }, StringSplitOptions.RemoveEmptyEntries); 68 | for (var index = 0; index < strArray.Length; ++index) 69 | { 70 | strArray[index].Trim(); 71 | var length = strArray[index].Length; 72 | strArray[index].IndexOf("\r\n"); 73 | filenames.Add("IRC_Log:" + 74 | strArray[index].Substring(0, strArray[index].IndexOf("\r\n")) 75 | .Replace("- [X]", "") 76 | .Replace(" ", "")); 77 | fileData.Add( 78 | FileSanitiser.purifyStringForDisplay( 79 | strArray[index].Substring(strArray[index].IndexOf("\r\n")).Replace("\n ", "\n")) + 80 | "\n\nArchived Via : http://Bash.org"); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /FileSanitiser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacknet 4 | { 5 | public static class FileSanitiser 6 | { 7 | public static string purifyStringForDisplay(string data) 8 | { 9 | data = data.Replace("\t", " ").Replace("“", "\"").Replace("”", "\""); 10 | for (var index = 0; index < data.Length; ++index) 11 | { 12 | if ((data[index] < 32 || data[index] > sbyte.MaxValue) && (data[index] != 10 && data[index] != 11) && 13 | (data[index] != 12 && data[index] != 10)) 14 | data = data.Replace(data[index], ' '); 15 | if (GuiData.font != null && !GuiData.font.Characters.Contains(data[index]) && data[index] != 10) 16 | data = data.Replace(data[index], '_'); 17 | } 18 | return data; 19 | } 20 | 21 | public static void purifyVehicleFile(string path) 22 | { 23 | var data = Utils.readEntireFile(path).Replace('\t', '#').Replace("\r", ""); 24 | for (var index = 0; index < data.Length; ++index) 25 | { 26 | if (!GuiData.font.Characters.Contains(data[index]) && data[index] != 10) 27 | data = replaceChar(data, index, '_'); 28 | } 29 | Utils.writeToFile(data, "SanitisedFile.txt"); 30 | } 31 | 32 | public static string replaceChar(string data, int index, char replacer) 33 | { 34 | return data.Substring(0, index - 1) + replacer + data.Substring(index + 1, data.Length - index - 2); 35 | } 36 | 37 | public static void purifyNameFile(string path) 38 | { 39 | var strArray1 = Utils.readEntireFile(path).Split(Utils.newlineDelim); 40 | var data = ""; 41 | for (var index = 0; index < strArray1.Length; ++index) 42 | { 43 | var strArray2 = strArray1[index].Split(Utils.spaceDelim, StringSplitOptions.RemoveEmptyEntries); 44 | data = data + strArray2[0] + "\n"; 45 | } 46 | Utils.writeToFile(data, "SanitisedNameFile.txt"); 47 | } 48 | 49 | public static void purifyLocationFile(string path) 50 | { 51 | var str = Utils.readEntireFile(path); 52 | var separator = new char[1] 53 | { 54 | '\t' 55 | }; 56 | var strArray1 = str.Split(Utils.newlineDelim); 57 | var data = ""; 58 | for (var index1 = 1; index1 < strArray1.Length; ++index1) 59 | { 60 | var strArray2 = strArray1[index1].Split(separator, StringSplitOptions.RemoveEmptyEntries); 61 | for (var index2 = 1; index2 < strArray2.Length; ++index2) 62 | data = data + strArray2[index2].Trim() + "#"; 63 | data += "\n"; 64 | } 65 | Utils.writeToFile(data, "SanitisedLocFile.txt"); 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /FileSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | 4 | namespace Hacknet 5 | { 6 | internal class FileSystem 7 | { 8 | public Folder root; 9 | 10 | public FileSystem(bool empty) 11 | { 12 | } 13 | 14 | public FileSystem() 15 | { 16 | root = new Folder("/"); 17 | root.folders.Add(new Folder("home")); 18 | root.folders.Add(new Folder("log")); 19 | root.folders.Add(new Folder("bin")); 20 | root.folders.Add(new Folder("sys")); 21 | generateSystemFiles(); 22 | } 23 | 24 | public void generateSystemFiles() 25 | { 26 | var folder = root.searchForFolder("sys"); 27 | folder.files.Add(new FileEntry(ThemeManager.getThemeDataString(OSTheme.HacknetTeal), "x-server.sys")); 28 | folder.files.Add(new FileEntry(Computer.generateBinaryString(500), "os-config.sys")); 29 | folder.files.Add(new FileEntry(Computer.generateBinaryString(500), "bootcfg.dll")); 30 | folder.files.Add(new FileEntry(Computer.generateBinaryString(500), "netcfgx.dll")); 31 | } 32 | 33 | public string getSaveString() 34 | { 35 | return "\n" + root.getSaveString() + "\n"; 36 | } 37 | 38 | public static FileSystem load(XmlReader reader) 39 | { 40 | var fileSystem = new FileSystem(true); 41 | while (reader.Name != "filesystem") 42 | reader.Read(); 43 | fileSystem.root = Folder.load(reader); 44 | return fileSystem; 45 | } 46 | 47 | public string TestEquals(object obj) 48 | { 49 | var fileSystem = obj as FileSystem; 50 | if (fileSystem == null) 51 | throw new ArgumentNullException(); 52 | return root.TestEqualsFolder(fileSystem.root); 53 | } 54 | 55 | public override int GetHashCode() 56 | { 57 | return base.GetHashCode(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /FileType.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal interface FileType 4 | { 5 | string getName(); 6 | } 7 | } -------------------------------------------------------------------------------- /ForkBombExe.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | internal class ForkBombExe : ExeModule 6 | { 7 | public static float RAM_CHANGE_PS = 150f; 8 | public static string binary = ""; 9 | public int binaryScroll; 10 | public int charsWide; 11 | public bool frameSwitch; 12 | public string runnerIP = ""; 13 | private readonly int targetRamUse = 999999999; 14 | 15 | public ForkBombExe(Rectangle location, OS operatingSystem) 16 | : base(location, operatingSystem) 17 | { 18 | ramCost = 10; 19 | runnerIP = "UNKNOWN"; 20 | IdentifierName = "ForkBomb"; 21 | } 22 | 23 | public ForkBombExe(Rectangle location, OS operatingSystem, string ipFrom) 24 | : base(location, operatingSystem) 25 | { 26 | ramCost = 10; 27 | runnerIP = ipFrom; 28 | IdentifierName = "ForkBomb"; 29 | } 30 | 31 | public override void LoadContent() 32 | { 33 | base.LoadContent(); 34 | if (binary.Equals("")) 35 | binary = Computer.generateBinaryString(5064); 36 | charsWide = (int) (bounds.Width/7.69999980926514 + 0.5); 37 | } 38 | 39 | public override void Update(float t) 40 | { 41 | base.Update(t); 42 | if (frameSwitch) 43 | { 44 | binaryScroll = binaryScroll + 1; 45 | if (binaryScroll >= binary.Length - (charsWide + 1)) 46 | binaryScroll = 0; 47 | } 48 | frameSwitch = !frameSwitch; 49 | if (targetRamUse == ramCost) 50 | return; 51 | var num = (int) (t*(double) RAM_CHANGE_PS); 52 | if (os.ramAvaliable < num) 53 | { 54 | Completed(); 55 | } 56 | else 57 | { 58 | ramCost += num; 59 | if (ramCost <= targetRamUse) 60 | return; 61 | ramCost = targetRamUse; 62 | } 63 | } 64 | 65 | public override void Draw(float t) 66 | { 67 | base.Draw(t); 68 | drawOutline(); 69 | var num = 8f; 70 | var startIndex = binaryScroll; 71 | if (startIndex >= binary.Length - (charsWide + 1)) 72 | startIndex = 0; 73 | var position = new Vector2(bounds.X, bounds.Y); 74 | while (position.Y < bounds.Y + bounds.Height - (double) num) 75 | { 76 | spriteBatch.DrawString(GuiData.detailfont, binary.Substring(startIndex, charsWide), position, 77 | Color.White); 78 | startIndex += charsWide; 79 | if (startIndex >= binary.Length - (charsWide + 1)) 80 | startIndex = 0; 81 | position.Y += num; 82 | } 83 | } 84 | 85 | public override void Completed() 86 | { 87 | base.Completed(); 88 | os.thisComputer.crash(runnerIP); 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /GameSaver.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public static class GameSaver 4 | { 5 | public static string compSplitter = "@*7@632(27@&(*@)@&*#@HD(*@H$J("; 6 | 7 | public static void save(object osObj) 8 | { 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /GameScreen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace Hacknet 5 | { 6 | public abstract class GameScreen 7 | { 8 | private bool otherScreenHasFocus; 9 | 10 | public bool IsPopup { get; protected set; } 11 | 12 | public TimeSpan TransitionOnTime { get; protected set; } = TimeSpan.Zero; 13 | 14 | public TimeSpan TransitionOffTime { get; protected set; } = TimeSpan.Zero; 15 | 16 | public float TransitionPosition { get; protected set; } = 1f; 17 | 18 | public byte TransitionAlpha 19 | { 20 | get { return (byte) (byte.MaxValue - TransitionPosition*(double) byte.MaxValue); } 21 | } 22 | 23 | public ScreenState ScreenState { get; protected set; } 24 | 25 | public bool IsExiting { get; protected internal set; } 26 | 27 | public bool IsActive 28 | { 29 | get 30 | { 31 | if (otherScreenHasFocus) 32 | return false; 33 | if (ScreenState != ScreenState.TransitionOn) 34 | return ScreenState == ScreenState.Active; 35 | return true; 36 | } 37 | } 38 | 39 | public ScreenManager ScreenManager { get; internal set; } 40 | 41 | public PlayerIndex? ControllingPlayer { get; internal set; } 42 | 43 | public virtual void LoadContent() 44 | { 45 | } 46 | 47 | public virtual void UnloadContent() 48 | { 49 | } 50 | 51 | public virtual void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 52 | { 53 | this.otherScreenHasFocus = otherScreenHasFocus; 54 | if (IsExiting) 55 | { 56 | ScreenState = ScreenState.TransitionOff; 57 | if (UpdateTransition(gameTime, TransitionOffTime, 1)) 58 | return; 59 | ScreenManager.RemoveScreen(this); 60 | } 61 | else if (coveredByOtherScreen) 62 | { 63 | if (UpdateTransition(gameTime, TransitionOffTime, 1)) 64 | ScreenState = ScreenState.TransitionOff; 65 | else 66 | ScreenState = ScreenState.Hidden; 67 | } 68 | else if (UpdateTransition(gameTime, TransitionOnTime, -1)) 69 | ScreenState = ScreenState.TransitionOn; 70 | else 71 | ScreenState = ScreenState.Active; 72 | } 73 | 74 | private bool UpdateTransition(GameTime gameTime, TimeSpan time, int direction) 75 | { 76 | TransitionPosition += (!(time == TimeSpan.Zero) 77 | ? (float) (gameTime.ElapsedGameTime.TotalMilliseconds/time.TotalMilliseconds) 78 | : 1f)*direction; 79 | if ((direction >= 0 || TransitionPosition > 0.0) && (direction <= 0 || TransitionPosition < 1.0)) 80 | return true; 81 | TransitionPosition = MathHelper.Clamp(TransitionPosition, 0.0f, 1f); 82 | return false; 83 | } 84 | 85 | public virtual void HandleInput(InputState input) 86 | { 87 | } 88 | 89 | public virtual void Draw(GameTime gameTime) 90 | { 91 | } 92 | 93 | public void ExitScreen() 94 | { 95 | if (TransitionOffTime == TimeSpan.Zero) 96 | ScreenManager.RemoveScreen(this); 97 | else 98 | IsExiting = true; 99 | } 100 | 101 | public virtual void inputMethodChanged(bool usingGamePad) 102 | { 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /GenerationStatics.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public static class GenerationStatics 4 | { 5 | public static int CorportationsGenerated; 6 | } 7 | } -------------------------------------------------------------------------------- /Gui/CheckBox.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet.Gui 4 | { 5 | public static class CheckBox 6 | { 7 | public const int WIDTH = 20; 8 | public const int HEIGHT = 20; 9 | public const int INTERIOR_BORDER = 4; 10 | 11 | public static bool doCheckBox(int myID, int x, int y, bool isChecked, Color? selectedColor) 12 | { 13 | if (!selectedColor.HasValue) 14 | selectedColor = GuiData.Default_Selected_Color; 15 | if (GuiData.hot == myID && GuiData.active == myID && GuiData.mouseLeftUp()) 16 | { 17 | isChecked = !isChecked; 18 | GuiData.active = -1; 19 | } 20 | RenderedRectangle.doRectangleOutline(x, y, 20, 20, 2, 21 | GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color); 22 | RenderedRectangle.doRectangle(x + 4, y + 4, 12, 12, 23 | isChecked 24 | ? selectedColor 25 | : (GuiData.active == myID ? GuiData.Default_Unselected_Color : GuiData.Default_Backing_Color)); 26 | var rectangle = GuiData.tmpRect; 27 | rectangle.X = x; 28 | rectangle.Y = y; 29 | rectangle.Width = 20; 30 | rectangle.Height = 20; 31 | if (rectangle.Contains(GuiData.getMousePoint())) 32 | { 33 | GuiData.hot = myID; 34 | if (GuiData.isMouseLeftDown()) 35 | GuiData.active = myID; 36 | } 37 | else 38 | { 39 | if (GuiData.hot == myID) 40 | GuiData.hot = -1; 41 | if (GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID) 42 | GuiData.active = -1; 43 | } 44 | return isChecked; 45 | } 46 | 47 | public static bool doCheckBox(int myID, int x, int y, bool isChecked, Color? selectedColor, string text) 48 | { 49 | if (GuiData.hot == myID) 50 | TextItem.doSmallLabel(new Vector2(x + 20, y - 20), text, new Color?()); 51 | return doCheckBox(myID, x, y, isChecked, selectedColor); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /Gui/RenderedRectangle.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace Hacknet.Gui 5 | { 6 | public static class RenderedRectangle 7 | { 8 | public static void doRectangle(int x, int y, int width, int height, Color? color) 9 | { 10 | if (!color.HasValue) 11 | color = GuiData.Default_Backing_Color; 12 | if (width < 0) 13 | { 14 | x += width; 15 | width = Math.Abs(width); 16 | } 17 | if (height < 0) 18 | { 19 | y += height; 20 | height = Math.Abs(height); 21 | } 22 | var destinationRectangle = GuiData.tmpRect; 23 | destinationRectangle.X = x; 24 | destinationRectangle.Width = width; 25 | destinationRectangle.Y = y; 26 | destinationRectangle.Height = height; 27 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, color.Value); 28 | } 29 | 30 | public static void doRectangle(int x, int y, int width, int height, Color? color, bool blocking) 31 | { 32 | doRectangle(x, y, width, height, color); 33 | var rectangle = GuiData.tmpRect; 34 | rectangle.X = x; 35 | rectangle.Y = y; 36 | rectangle.Width = width; 37 | rectangle.Height = height; 38 | if (!blocking || !rectangle.Contains(GuiData.getMousePoint())) 39 | return; 40 | GuiData.blockingInput = true; 41 | } 42 | 43 | public static void doRectangleOutline(int x, int y, int width, int height, int thickness, Color? color) 44 | { 45 | if (!color.HasValue) 46 | color = GuiData.Default_Backing_Color; 47 | if (width < 0) 48 | { 49 | x += width; 50 | width = Math.Abs(width); 51 | } 52 | if (height < 0) 53 | { 54 | y += height; 55 | height = Math.Abs(height); 56 | } 57 | var destinationRectangle = GuiData.tmpRect; 58 | destinationRectangle.X = x; 59 | destinationRectangle.Width = width; 60 | destinationRectangle.Y = y; 61 | destinationRectangle.Height = thickness; 62 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, color.Value); 63 | destinationRectangle.X = x; 64 | destinationRectangle.Width = width; 65 | destinationRectangle.Y = y + height - thickness; 66 | destinationRectangle.Height = thickness; 67 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, color.Value); 68 | destinationRectangle.X = x; 69 | destinationRectangle.Width = thickness; 70 | destinationRectangle.Y = y; 71 | destinationRectangle.Height = height; 72 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, color.Value); 73 | destinationRectangle.X = x + width - thickness; 74 | destinationRectangle.Width = thickness; 75 | destinationRectangle.Y = y; 76 | destinationRectangle.Height = height; 77 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, color.Value); 78 | } 79 | } 80 | } -------------------------------------------------------------------------------- /Gui/ScrollBar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace Hacknet.Gui 5 | { 6 | public static class ScrollBar 7 | { 8 | public static float doVerticalScrollBar(int id, int xPos, int yPos, int drawWidth, int drawHeight, 9 | int contentHeight, float scroll) 10 | { 11 | if (drawHeight > contentHeight) 12 | contentHeight = drawHeight; 13 | var destinationRectangle = new Rectangle(xPos, yPos, drawWidth, drawHeight); 14 | if (destinationRectangle.Contains(GuiData.getMousePoint()) || GuiData.active == id) 15 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, Color.Gray*0.1f); 16 | var num1 = scroll; 17 | float num2 = contentHeight - drawHeight; 18 | var num3 = drawHeight/(float) contentHeight*drawHeight; 19 | var num4 = scroll/num2*(drawHeight - num3); 20 | var num5 = 21 | DraggableRectangle.doDraggableRectangle(id, xPos, yPos + num4, drawWidth, (int) num3, drawWidth, 22 | Color.White, Color.Gray, true, false, xPos, yPos + drawHeight - num3, xPos, yPos).Y; 23 | if (Math.Abs(num5) > 0.100000001490116) 24 | num1 = (float) ((num4 + (double) num5)/(drawHeight - (double) num3))*num2; 25 | return num1; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Gui/SliderBar.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | 6 | namespace Hacknet.Gui 7 | { 8 | public static class SliderBar 9 | { 10 | public const int SELECTOR_BAR_WIDTH = 8; 11 | public const int BOARDER = 2; 12 | public const int SLIDE_BAR_HEIGHT = 10; 13 | 14 | public static float doSliderBar(int myID, int x, int y, int width, int height, float maxValue, float minValue, 15 | float currentValue, float barStep) 16 | { 17 | var num1 = -1f; 18 | var val1 = currentValue; 19 | if (GuiData.hot == myID) 20 | { 21 | if (GuiData.isMouseLeftDown()) 22 | GuiData.active = myID; 23 | else if (GuiData.active == myID) 24 | GuiData.active = -1; 25 | if (GuiData.active == myID) 26 | { 27 | num1 = Math.Min(Math.Max((GuiData.mouse.X - x)/(float) width, 0.0f), 1f); 28 | val1 = minValue + num1*(maxValue - minValue); 29 | } 30 | val1 += barStep*GuiData.getMouseWheelScroll(); 31 | } 32 | if (num1 == -1.0) 33 | { 34 | var num2 = maxValue - minValue; 35 | num1 = currentValue/num2; 36 | if (minValue < 0.0) 37 | num1 += 0.5f; 38 | } 39 | GuiData.tmpRect.X = x; 40 | GuiData.tmpRect.Y = y; 41 | GuiData.tmpRect.Width = width; 42 | GuiData.tmpRect.Height = height; 43 | if (GuiData.tmpRect.Contains(GuiData.getMousePoint())) 44 | GuiData.hot = myID; 45 | else if (GuiData.hot == myID && GuiData.mouse.LeftButton == ButtonState.Released) 46 | { 47 | GuiData.hot = -1; 48 | if (GuiData.active == myID) 49 | GuiData.active = -1; 50 | } 51 | var num3 = Math.Min(Math.Max(val1, minValue), maxValue); 52 | GuiData.tmpRect.Width = width; 53 | GuiData.tmpRect.X = x; 54 | GuiData.tmpRect.Height = 10; 55 | GuiData.tmpRect.Y = y + height/4; 56 | GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Backing_Color); 57 | GuiData.tmpRect.Width -= 4; 58 | GuiData.tmpRect.X += 2; 59 | GuiData.tmpRect.Height -= 4; 60 | GuiData.tmpRect.Y += 2; 61 | GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, GuiData.Default_Dark_Background_Color); 62 | GuiData.tmpRect.Width = 8; 63 | GuiData.tmpRect.X = (int) (x + num1*(double) width) - 4; 64 | GuiData.tmpRect.Y = y - 5; 65 | GuiData.tmpRect.Height = height; 66 | GuiData.spriteBatch.Draw(Utils.white, GuiData.tmpRect, 67 | GuiData.active != myID 68 | ? (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Selected_Color) 69 | : GuiData.Default_Unselected_Color); 70 | if (GuiData.active == myID || GuiData.hot == myID) 71 | { 72 | var format = "0.000"; 73 | var text = num3.ToString(format) ?? ""; 74 | text.TrimEnd('0'); 75 | GuiData.temp.X = (int) (x + num1*(double) width) + 4; 76 | GuiData.temp.Y = y - GuiData.smallfont.MeasureString(text).Y*0.8f; 77 | GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp + Vector2.One, Color.Gray, 0.0f, 78 | Vector2.Zero, 0.8f, SpriteEffects.None, 0.51f); 79 | GuiData.spriteBatch.DrawString(GuiData.smallfont, text, GuiData.temp, Color.White, 0.0f, Vector2.Zero, 80 | 0.8f, SpriteEffects.None, 0.5f); 81 | } 82 | return num3; 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /Hacknet.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hacknet", "Hacknet.csproj", "{61A71D16-DD12-46C1-97F4-C3612E13C55D}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x86 = Debug|x86 12 | Release|Any CPU = Release|Any CPU 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Debug|x86.ActiveCfg = Debug|x86 19 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Debug|x86.Build.0 = Debug|x86 20 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Release|x86.ActiveCfg = Release|x86 23 | {61A71D16-DD12-46C1-97F4-C3612E13C55D}.Release|x86.Build.0 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /Helpfile.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | 4 | namespace Hacknet 5 | { 6 | internal class Helpfile 7 | { 8 | private static readonly int ITEMS_PER_PAGE = 10; 9 | 10 | public static string prefix = 11 | "---------------------------------\nCommand List - Page [PAGENUM] of [TOTALPAGES]:\n"; 12 | 13 | private static readonly string postfix = 14 | "help [PAGE NUMBER]\n Displays the specified page of commands.\n---------------------------------\n"; 15 | 16 | public static List help; 17 | 18 | public static void init() 19 | { 20 | help = new List(); 21 | var str = "\n "; 22 | help.Add("help [PAGE NUMBER]" + str + "Displays the specified page of commands."); 23 | help.Add("scp [filename] [OPTIONAL: destination]" + str + 24 | "Copies file named [filename] from remote machine to specified local folder (/bin default)"); 25 | help.Add("scan" + str + "Scans for links on the connected machine and adds them to the Map"); 26 | help.Add("rm [filename (or use * for all files in folder)]" + str + "Deletes specified file(s)"); 27 | help.Add("ps" + str + "Lists currently running processes"); 28 | help.Add("kill [PID]" + str + "Kills Process number [PID]"); 29 | help.Add("ls" + str + "Lists all files in current directory"); 30 | help.Add("cd [foldername]" + str + "Moves current working directory to the specified folder"); 31 | help.Add("mv [FILE] [DESTINATION]" + str + "Moves or renames [FILE] to [DESTINATION]" + str + 32 | "(i.e: mv hi.txt ../bin/hi.txt)"); 33 | help.Add("connect [ip]" + str + "Connect to an External Computer"); 34 | help.Add("probe" + str + "Scans the connected machine for" + str + "active ports and security level"); 35 | help.Add("exe" + str + 36 | "Lists all available executables in the local /bin/ folder (Includes hidden and embedded executables)"); 37 | help.Add("disconnect" + str + "Terminate the current open connection. ALT: \"dc\""); 38 | help.Add("cat [filename]" + str + "Displays contents of file"); 39 | help.Add("openCDTray" + str + "Opens the connected Computer's CD Tray"); 40 | help.Add("closeCDTray" + str + "Closes the connected Computer's CD Tray"); 41 | help.Add("reboot [OPTIONAL: -i]" + str + "Reboots the connected computer. The -i flag reboots instantly"); 42 | help.Add("replace [filename] \"target\" \"replacement\"" + str + 43 | "Replaces the target text in the file with the replacement"); 44 | help.Add("analyze" + str + "Performs an analysis pass on the firewall of the target machine"); 45 | help.Add("solve [FIREWALL SOLUTION]" + str + 46 | "Attempts to solve the firewall of target machine to allow UDP Traffic"); 47 | help.Add("login" + str + "Requests a username and password to log in to the connected system"); 48 | help.Add("upload [LOCAL FILE PATH]" + str + 49 | "Uploads the indicated file on your local machine to the current connected directory"); 50 | help.Add("clear" + str + "Clears the terminal"); 51 | } 52 | 53 | public static void writeHelp(OS os, int page = 0) 54 | { 55 | if (page == 0) 56 | page = 1; 57 | var num = (page - 1)*ITEMS_PER_PAGE; 58 | if (num >= help.Count) 59 | num = 0; 60 | var stringBuilder = new StringBuilder(); 61 | stringBuilder.Append( 62 | prefix.Replace("[PAGENUM]", string.Concat(page)) 63 | .Replace("[TOTALPAGES]", string.Concat(getNumberOfPages())) + "\n"); 64 | for (var index = num; index < help.Count && index < num + ITEMS_PER_PAGE; ++index) 65 | stringBuilder.Append((index == 0 ? " " : "") + help[index] + "\n \n "); 66 | os.write(stringBuilder.ToString() + "\n" + postfix); 67 | } 68 | 69 | public static int getNumberOfPages() 70 | { 71 | return help.Count/ITEMS_PER_PAGE + 1; 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /HexClockExe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace Hacknet 6 | { 7 | internal class HexClockExe : ExeModule 8 | { 9 | private OSTheme theme; 10 | 11 | public HexClockExe(Rectangle location, OS operatingSystem, string[] p) 12 | : base(location, operatingSystem) 13 | { 14 | name = "HexClock"; 15 | ramCost = 55; 16 | IdentifierName = "HexClock"; 17 | targetIP = os.thisComputer.ip; 18 | theme = ThemeManager.currentTheme; 19 | } 20 | 21 | public override void Killed() 22 | { 23 | base.Killed(); 24 | } 25 | 26 | public override void Draw(float t) 27 | { 28 | base.Draw(t); 29 | drawOutline(); 30 | drawTarget("app:"); 31 | var now = DateTime.Now; 32 | var str = "#" + now.Hour.ToString("00") + now.Minute.ToString("00") + now.Second.ToString("00"); 33 | var color = Utils.ColorFromHexString(str); 34 | AutoUpdateTheme(color); 35 | var contentAreaDest = GetContentAreaDest(); 36 | spriteBatch.Draw(Utils.white, contentAreaDest, color); 37 | var width = (int) (bounds.Width*0.800000011920929); 38 | var height = 30; 39 | TextItem.doFontLabelToSize( 40 | new Rectangle(contentAreaDest.X + (contentAreaDest.Width/2 - width/2), 41 | contentAreaDest.Y + (contentAreaDest.Height/2 - height/2), width, height), str, GuiData.font, 42 | Utils.AddativeWhite); 43 | } 44 | 45 | private void AutoUpdateTheme(Color c) 46 | { 47 | var c1 = c; 48 | double h1; 49 | double s; 50 | double l1; 51 | Utils.RGB2HSL(c, out h1, out s, out l1); 52 | var sl = Math.Min(0.7, s); 53 | var num = Math.Max(0.2, l1); 54 | c = Utils.HSL2RGB(h1, sl, num); 55 | var l2 = Math.Max(0.35, num); 56 | var h2 = h1 - 0.5; 57 | if (h2 < 0.0) 58 | ++h2; 59 | Utils.HSL2RGB(h2, sl, l2); 60 | os.defaultHighlightColor = Utils.GetComplimentaryColor(c1); 61 | os.defaultTopBarColor = new Color(0, 0, 0, 60); 62 | os.highlightColor = os.defaultHighlightColor; 63 | os.highlightColor = os.defaultHighlightColor; 64 | os.moduleColorSolid = Color.Lerp(c, Utils.AddativeWhite, 0.5f); 65 | os.moduleColorSolidDefault = os.moduleColorSolid; 66 | os.moduleColorStrong = c; 67 | os.moduleColorStrong.A = 80; 68 | os.topBarColor = os.defaultTopBarColor; 69 | os.exeModuleTopBar = new Color(32, 22, 40, 80); 70 | os.exeModuleTitleText = new Color(91, 132, 207, 0); 71 | os.netmapToolTipColor = new Color(213, 245, byte.MaxValue, 0); 72 | os.netmapToolTipBackground = new Color(0, 0, 0, 70); 73 | os.displayModuleExtraLayerBackingColor = new Color(0, 0, 0, 60); 74 | os.thisComputerNode = new Color(95, 220, 83); 75 | os.scanlinesColor = new Color(byte.MaxValue, byte.MaxValue, byte.MaxValue, 15); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /Input/Stack`1.cs: -------------------------------------------------------------------------------- 1 | // Decompiled with JetBrains decompiler 2 | // Type: Hacknet.Input.Stack`1 3 | // Assembly: Hacknet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 4 | // MVID: 48C62A5D-184B-4610-A7EA-84B38D090891 5 | // Assembly location: C:\Program Files (x86)\Steam\SteamApps\common\Hacknet\Hacknet.exe 6 | 7 | using System; 8 | 9 | namespace Hacknet.Input 10 | { 11 | public class Stack 12 | { 13 | private T[] stack; 14 | 15 | public Stack() 16 | : this(32) 17 | { 18 | } 19 | 20 | public Stack(int capacity) 21 | { 22 | if (capacity < 0) 23 | capacity = 0; 24 | stack = new T[capacity]; 25 | } 26 | 27 | public int Capacity 28 | { 29 | get { return stack.Length; } 30 | } 31 | 32 | public int Count { get; private set; } 33 | 34 | public void Push(ref T item) 35 | { 36 | if (Count == stack.Length) 37 | { 38 | var objArray = new T[stack.Length << 1]; 39 | Array.Copy(stack, 0, objArray, 0, stack.Length); 40 | stack = objArray; 41 | } 42 | stack[Count] = item; 43 | ++Count; 44 | } 45 | 46 | public void Pop(out T item) 47 | { 48 | if (Count <= 0) 49 | throw new InvalidOperationException(); 50 | item = stack[Count]; 51 | stack[Count] = default(T); 52 | --Count; 53 | } 54 | 55 | public void PopSegment(out ArraySegment segment) 56 | { 57 | segment = new ArraySegment(stack, 0, Count); 58 | Count = 0; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /InputMap.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct InputMap 4 | { 5 | private static readonly InputMap e = new InputMap(); 6 | public InputStates now; 7 | public InputStates last; 8 | 9 | public static InputMap Empty 10 | { 11 | get 12 | { 13 | var inputMap = e; 14 | return e; 15 | } 16 | } 17 | 18 | public InputMap(InputStates last, InputStates now) 19 | { 20 | this.last = last; 21 | this.now = now; 22 | } 23 | 24 | public static bool operator ==(InputMap self, InputMap other) 25 | { 26 | return self.now == other.now && self.last == other.last; 27 | } 28 | 29 | public static bool operator !=(InputMap self, InputMap other) 30 | { 31 | return !(self.now == other.now) || !(self.last == other.last); 32 | } 33 | 34 | public override bool Equals(object obj) 35 | { 36 | return base.Equals(obj); 37 | } 38 | 39 | public override int GetHashCode() 40 | { 41 | return base.GetHashCode(); 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /InputMapping.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Input; 2 | 3 | namespace Hacknet 4 | { 5 | public class InputMapping 6 | { 7 | private static InputStates ret; 8 | private static InputMap map; 9 | private static InputStates lastCalculatedState; 10 | 11 | public static InputStates getStatesFromKeys(KeyboardState keys, GamePadState pad, GamePadThumbSticks sticks) 12 | { 13 | var inputStates = ret; 14 | ret.movement = keys.IsKeyDown(Keys.Right) || pad.DPad.Right == ButtonState.Pressed 15 | ? 1f 16 | : (keys.IsKeyDown(Keys.Left) || pad.DPad.Left == ButtonState.Pressed 17 | ? -1f 18 | : sticks.Left.X == 0.0 ? 0.0f : sticks.Left.X); 19 | var buttons1 = pad.Buttons; 20 | ret.jumping = buttons1.A == ButtonState.Pressed || keys.IsKeyDown(Keys.Up); 21 | var buttons2 = pad.Buttons; 22 | ret.useItem = buttons2.B == ButtonState.Pressed || keys.IsKeyDown(Keys.RightShift); 23 | ret.wmovement = keys.IsKeyDown(Keys.D) || pad.DPad.Right == ButtonState.Pressed 24 | ? 1f 25 | : (keys.IsKeyDown(Keys.A) || pad.DPad.Left == ButtonState.Pressed 26 | ? -1f 27 | : sticks.Left.X == 0.0 ? 0.0f : sticks.Left.X); 28 | ret.wjumping = pad.Buttons.A == ButtonState.Pressed || keys.IsKeyDown(Keys.W) || keys.IsKeyDown(Keys.Space) || 29 | pad.Triggers.Left > 0.0; 30 | var buttons3 = pad.Buttons; 31 | ret.wuseItem = buttons3.B == ButtonState.Pressed || keys.IsKeyDown(Keys.LeftShift); 32 | lastCalculatedState = ret; 33 | return ret; 34 | } 35 | 36 | public static InputMap getMapFromKeys(KeyboardState keys, GamePadState pad) 37 | { 38 | map.last = lastCalculatedState; 39 | map.now = getStatesFromKeys(keys, pad, pad.ThumbSticks); 40 | return map; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /InputStates.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct InputStates 4 | { 5 | public float movement; 6 | public bool jumping; 7 | public bool useItem; 8 | public float wmovement; 9 | public bool wjumping; 10 | public bool wuseItem; 11 | 12 | public static bool operator ==(InputStates self, InputStates other) 13 | { 14 | return self.movement == (double) other.movement && self.jumping == other.jumping && 15 | (self.useItem == other.useItem && self.wmovement == (double) other.wmovement) && 16 | (self.wjumping == other.wjumping && self.wuseItem == other.wuseItem); 17 | } 18 | 19 | public static bool operator !=(InputStates self, InputStates other) 20 | { 21 | return self.movement != (double) other.movement || self.jumping != other.jumping || 22 | (self.useItem != other.useItem || self.wmovement != (double) other.wmovement) || 23 | (self.wjumping != other.wjumping || self.wuseItem != other.wuseItem); 24 | } 25 | 26 | public override bool Equals(object obj) 27 | { 28 | return obj is InputStates && (InputStates) obj == this; 29 | } 30 | 31 | public override int GetHashCode() 32 | { 33 | return base.GetHashCode(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /KeyboardAndGamePad.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Input; 2 | 3 | namespace Hacknet 4 | { 5 | public struct KeyboardAndGamePad 6 | { 7 | public KeyboardState keyboard; 8 | public GamePadState gamepad; 9 | } 10 | } -------------------------------------------------------------------------------- /LevelState.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet 4 | { 5 | public struct LevelState 6 | { 7 | public double TimeTaken { get; set; } 8 | 9 | public List BackgroundObjects { get; set; } 10 | 11 | public List UpdatableObjects { get; set; } 12 | 13 | public ObjectState PlayerState { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /LevelType.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct LevelType 4 | { 5 | public int NumOfPuzzles; 6 | public int NumOfBackgrounds; 7 | public string name; 8 | 9 | public LevelType(int puzzles, int bgs, string lvlname) 10 | { 11 | NumOfPuzzles = puzzles; 12 | NumOfBackgrounds = bgs; 13 | name = lvlname; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /LoadedTexture.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework.Graphics; 2 | 3 | namespace Hacknet 4 | { 5 | public struct LoadedTexture 6 | { 7 | public string path { get; set; } 8 | 9 | public Texture2D tex { get; set; } 10 | 11 | public int retainCount { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /MailResponder.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal interface MailResponder 4 | { 5 | void mailSent(string mail, string userTo); 6 | 7 | void mailReceived(string mail, string userTo); 8 | } 9 | } -------------------------------------------------------------------------------- /MessageBoardPost.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal struct MessageBoardPost 4 | { 5 | public string text; 6 | public MessageBoardPostImage img; 7 | } 8 | } -------------------------------------------------------------------------------- /MessageBoardPostImage.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | internal enum MessageBoardPostImage 4 | { 5 | None, 6 | Circle, 7 | Academic, 8 | Sun, 9 | Snake, 10 | Duck, 11 | Page, 12 | Speech, 13 | Mod, 14 | Chip 15 | } 16 | } -------------------------------------------------------------------------------- /MessageBoardThread.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet 4 | { 5 | internal struct MessageBoardThread 6 | { 7 | public string id; 8 | public List posts; 9 | } 10 | } -------------------------------------------------------------------------------- /Microsoft/Xna/Framework.RuntimeProfile: -------------------------------------------------------------------------------- 1 | Windows.v4.0.HiDef 2 | -------------------------------------------------------------------------------- /Misc/DemoEndScreen.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | using Hacknet.Effects; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Audio; 5 | using Microsoft.Xna.Framework.Input; 6 | using Microsoft.Xna.Framework.Media; 7 | 8 | namespace Hacknet.Misc 9 | { 10 | public class DemoEndScreen : GameScreen 11 | { 12 | private Rectangle Fullscreen; 13 | private SoundEffect spinDownSound; 14 | private double timeOnThisScreen; 15 | 16 | public override void LoadContent() 17 | { 18 | base.LoadContent(); 19 | Fullscreen = new Rectangle(0, 0, ScreenManager.GraphicsDevice.Viewport.Width, 20 | ScreenManager.GraphicsDevice.Viewport.Height); 21 | MediaPlayer.Stop(); 22 | PostProcessor.EndingSequenceFlashOutActive = false; 23 | PostProcessor.EndingSequenceFlashOutPercentageComplete = 0.0f; 24 | PostProcessor.dangerModeEnabled = false; 25 | } 26 | 27 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 28 | { 29 | base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); 30 | if (!otherScreenHasFocus && !coveredByOtherScreen) 31 | timeOnThisScreen += gameTime.ElapsedGameTime.TotalSeconds; 32 | if (timeOnThisScreen > 5.0 && Keyboard.GetState().GetPressedKeys().Length > 0) 33 | { 34 | if (Settings.isConventionDemo) 35 | { 36 | OS.currentInstance.ScreenManager.AddScreen(new MainMenu()); 37 | OS.currentInstance.ExitScreen(); 38 | } 39 | else 40 | Application.Exit(); 41 | } 42 | else if (timeOnThisScreen > 20.0) 43 | { 44 | if (Settings.isConventionDemo) 45 | { 46 | OS.currentInstance.ScreenManager.AddScreen(new MainMenu()); 47 | OS.currentInstance.ExitScreen(); 48 | ExitScreen(); 49 | MainMenu.resetOS(); 50 | } 51 | else 52 | Application.Exit(); 53 | } 54 | PostProcessor.EndingSequenceFlashOutActive = false; 55 | PostProcessor.EndingSequenceFlashOutPercentageComplete = 0.0f; 56 | PostProcessor.dangerModeEnabled = false; 57 | } 58 | 59 | public override void Draw(GameTime gameTime) 60 | { 61 | base.Draw(gameTime); 62 | PostProcessor.begin(); 63 | GuiData.startDraw(); 64 | GuiData.spriteBatch.Draw(Utils.white, Fullscreen, Color.Black); 65 | var dest = Utils.InsetRectangle(Fullscreen, 200); 66 | dest.Y = dest.Y + dest.Height/2 - 200; 67 | dest.Height = 400; 68 | var destinationRectangle = new Rectangle(Fullscreen.X, dest.Y + 50, Fullscreen.Width, dest.Height - 148); 69 | GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, Utils.AddativeRed*(0.5f + Utils.randm(0.1f))); 70 | var text = "HACKNET"; 71 | FlickeringTextEffect.DrawLinedFlickeringText(dest, text, 18f, 0.7f, GuiData.titlefont, null, Color.White, 6); 72 | dest.Y += 400; 73 | dest.Height = 120; 74 | FlickeringTextEffect.DrawFlickeringText(dest, Utils.FlipRandomChars("MORE SOON", 0.008), -8f, 0.7f, 75 | GuiData.titlefont, null, Color.Gray); 76 | FlickeringTextEffect.DrawFlickeringText(dest, Utils.FlipRandomChars("MORE SOON", 0.03), -8f, 0.7f, 77 | GuiData.titlefont, null, Utils.AddativeWhite*0.15f); 78 | GuiData.endDraw(); 79 | PostProcessor.end(); 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /Misc/HSLColor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace Hacknet.Misc 5 | { 6 | public class HSLColor 7 | { 8 | public float Hue; 9 | public float Luminosity; 10 | public float Saturation; 11 | 12 | public HSLColor(float H, float S, float L) 13 | { 14 | Hue = H; 15 | Saturation = S; 16 | Luminosity = L; 17 | } 18 | 19 | public static HSLColor FromRGB(Color Clr) 20 | { 21 | return FromRGB(Clr.R, Clr.G, Clr.B); 22 | } 23 | 24 | public static HSLColor FromRGB(byte R, byte G, byte B) 25 | { 26 | var val1 = R/(float) byte.MaxValue; 27 | var val2_1 = G/(float) byte.MaxValue; 28 | var val2_2 = B/(float) byte.MaxValue; 29 | var num1 = Math.Min(Math.Min(val1, val2_1), val2_2); 30 | var num2 = Math.Max(Math.Max(val1, val2_1), val2_2); 31 | var num3 = num2 - num1; 32 | var H = 0.0f; 33 | var S = 0.0f; 34 | var L = (float) ((num2 + (double) num1)/2.0); 35 | if (num3 != 0.0) 36 | { 37 | S = L >= 0.5 ? num3/(2f - num2 - num1) : num3/(num2 + num1); 38 | if (val1 == (double) num2) 39 | H = (val2_1 - val2_2)/num3; 40 | else if (val2_1 == (double) num2) 41 | H = (float) (2.0 + (val2_2 - (double) val1)/num3); 42 | else if (val2_2 == (double) num2) 43 | H = (float) (4.0 + (val1 - (double) val2_1)/num3); 44 | } 45 | return new HSLColor(H, S, L); 46 | } 47 | 48 | private float Hue_2_RGB(float v1, float v2, float vH) 49 | { 50 | if (vH < 0.0) 51 | ++vH; 52 | if (vH > 1.0) 53 | --vH; 54 | if (6.0*vH < 1.0) 55 | return v1 + (float) ((v2 - (double) v1)*6.0)*vH; 56 | if (2.0*vH < 1.0) 57 | return v2; 58 | if (3.0*vH < 2.0) 59 | return v1 + (float) ((v2 - (double) v1)*(0.0 - vH)*6.0); 60 | return v1; 61 | } 62 | 63 | public Color ToRGB() 64 | { 65 | byte num1; 66 | byte num2; 67 | byte num3; 68 | if (Saturation == 0.0) 69 | { 70 | num1 = (byte) Math.Round(Luminosity*(double) byte.MaxValue); 71 | num2 = (byte) Math.Round(Luminosity*(double) byte.MaxValue); 72 | num3 = (byte) Math.Round(Luminosity*(double) byte.MaxValue); 73 | } 74 | else 75 | { 76 | var num4 = Hue/6.0; 77 | var t2 = Luminosity >= 0.5 78 | ? Luminosity + (double) Saturation - Luminosity*(double) Saturation 79 | : Luminosity*(1.0 + Saturation); 80 | var t1 = 2.0*Luminosity - t2; 81 | var c1 = num4 + 1.0/3.0; 82 | var c2 = num4; 83 | var c3 = num4 - 1.0/3.0; 84 | var num5 = ColorCalc(c1, t1, t2); 85 | var num6 = ColorCalc(c2, t1, t2); 86 | var num7 = ColorCalc(c3, t1, t2); 87 | num1 = (byte) Math.Round(num5*byte.MaxValue); 88 | num2 = (byte) Math.Round(num6*byte.MaxValue); 89 | num3 = (byte) Math.Round(num7*byte.MaxValue); 90 | } 91 | return new Color 92 | { 93 | R = num1, 94 | G = num2, 95 | B = num3, 96 | A = byte.MaxValue 97 | }; 98 | } 99 | 100 | private static double ColorCalc(double c, double t1, double t2) 101 | { 102 | if (c < 0.0) 103 | ++c; 104 | if (c > 1.0) 105 | --c; 106 | if (6.0*c < 1.0) 107 | return t1 + (t2 - t1)*6.0*c; 108 | if (2.0*c < 1.0) 109 | return t2; 110 | if (3.0*c < 2.0) 111 | return t1 + (t2 - t1)*(2.0/3.0 - c)*6.0; 112 | return t1; 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /Mission/AddDegreeMission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet.Mission 5 | { 6 | internal class AddDegreeMission : MisisonGoal 7 | { 8 | public AcademicDatabaseDaemon database; 9 | private readonly string degreeName; 10 | private readonly float desiredGPA; 11 | private readonly string ownerName; 12 | private readonly string uniName; 13 | 14 | public AddDegreeMission(string targetName, string degreeName, string uniName, float desiredGPA, OS _os) 15 | { 16 | var addDegreeMission = this; 17 | ownerName = targetName; 18 | this.degreeName = degreeName; 19 | this.uniName = uniName; 20 | this.desiredGPA = desiredGPA; 21 | Action init = null; 22 | init = () => 23 | { 24 | if (_os.netMap.academicDatabase == null) 25 | _os.delayer.Post(ActionDelayer.NextTick(), init); 26 | else 27 | database = 28 | (AcademicDatabaseDaemon) _os.netMap.academicDatabase.getDaemon(typeof (AcademicDatabaseDaemon)); 29 | }; 30 | init(); 31 | } 32 | 33 | public override bool isComplete(List additionalDetails = null) 34 | { 35 | return database.doesDegreeExist(ownerName, degreeName, uniName, desiredGPA); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /Mission/BootLoadList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet.Mission 5 | { 6 | public static class BootLoadList 7 | { 8 | public static List getList() 9 | { 10 | return getListFromData(Utils.readEntireFile("Content/Computers/BootLoadList.txt")); 11 | } 12 | 13 | public static List getDemoList() 14 | { 15 | return getListFromData(Utils.readEntireFile("Content/Computers/DemoLoadList.txt")); 16 | } 17 | 18 | public static List getAdventureList() 19 | { 20 | return getListFromData(Utils.readEntireFile("Content/AdventureNetwork/AdventureLoadList.txt")); 21 | } 22 | 23 | private static List getListFromData(string data) 24 | { 25 | var separator = new string[2] 26 | { 27 | "\n\r", 28 | "\r\n" 29 | }; 30 | var strArray = data.Split(separator, StringSplitOptions.RemoveEmptyEntries); 31 | var list = new List(); 32 | for (var index = 0; index < strArray.Length; ++index) 33 | { 34 | if (!strArray[index].StartsWith("#") && strArray[index].Length > 1) 35 | list.Add(strArray[index]); 36 | } 37 | return list; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Mission/CheckFlagSetMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class CheckFlagSetMission : MisisonGoal 6 | { 7 | private readonly OS os; 8 | public string target; 9 | 10 | public CheckFlagSetMission(string targetFlagName, OS _os) 11 | { 12 | target = targetFlagName; 13 | os = _os; 14 | } 15 | 16 | public override bool isComplete(List additionalDetails = null) 17 | { 18 | return os.Flags.HasFlag(target); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Mission/DeathRowRecordModifyMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class DeathRowRecordModifyMission : MisisonGoal 6 | { 7 | public Folder container; 8 | public Computer deathRowDatabase; 9 | public string fname; 10 | public string lastWords; 11 | public string lname; 12 | public OS os; 13 | 14 | public DeathRowRecordModifyMission(string firstName, string lastName, string lastWords, OS _os) 15 | { 16 | os = _os; 17 | fname = firstName; 18 | lname = lastName; 19 | this.lastWords = lastWords; 20 | var computer = Programs.getComputer(os, "deathRow"); 21 | deathRowDatabase = computer; 22 | container = computer.getFolderFromPath("dr_database/Records", false); 23 | } 24 | 25 | public override bool isComplete(List additionalDetails = null) 26 | { 27 | var recordForName = 28 | ((DeathRowDatabaseDaemon) deathRowDatabase.getDaemon(typeof (DeathRowDatabaseDaemon))).GetRecordForName( 29 | fname, lname); 30 | if (recordForName.RecordNumber == null) 31 | return false; 32 | if (lastWords == null) 33 | return true; 34 | var str1 = recordForName.Statement.ToLower().Replace("\r", "").Replace(",", "").Replace(".", ""); 35 | var str2 = lastWords.ToLower().Replace("\r", "").Replace(",", "").Replace(".", ""); 36 | if (str1.Contains(str2) || str1 == str2 || !str1.StartsWith(str2)) 37 | ; 38 | return true; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Mission/DeathRowRecordRemovalMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class DeathRowRecordRemovalMission : MisisonGoal 6 | { 7 | public Folder container; 8 | public Computer deathRowDatabase; 9 | public string fname; 10 | public string lname; 11 | public OS os; 12 | 13 | public DeathRowRecordRemovalMission(string firstName, string lastName, OS _os) 14 | { 15 | os = _os; 16 | fname = firstName; 17 | lname = lastName; 18 | var computer = Programs.getComputer(os, "deathRow"); 19 | deathRowDatabase = computer; 20 | container = computer.getFolderFromPath("dr_database/Records", false); 21 | } 22 | 23 | public override bool isComplete(List additionalDetails = null) 24 | { 25 | return 26 | !((DeathRowDatabaseDaemon) deathRowDatabase.getDaemon(typeof (DeathRowDatabaseDaemon))) 27 | .ContainsRecordForName(fname, lname); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Mission/DelayMission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet.Mission 5 | { 6 | internal class DelayMission : MisisonGoal 7 | { 8 | private DateTime? firstRequest = new DateTime?(); 9 | public float time; 10 | 11 | public DelayMission(float time) 12 | { 13 | this.time = time; 14 | } 15 | 16 | public override bool isComplete(List additionalDetails = null) 17 | { 18 | if (firstRequest.HasValue) 19 | return (DateTime.Now - firstRequest.Value).TotalSeconds >= time; 20 | firstRequest = DateTime.Now; 21 | return false; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Mission/FileChangeMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class FileChangeMission : MisisonGoal 6 | { 7 | public Folder container; 8 | public bool isRemoval; 9 | public OS os; 10 | public string target; 11 | public Computer targetComp; 12 | public string targetData; 13 | public string targetKeyword; 14 | 15 | public FileChangeMission(string path, string filename, string computerIP, string targetKeyword, OS _os, 16 | bool isRemoval = false) 17 | { 18 | target = filename; 19 | this.targetKeyword = targetKeyword.ToLower(); 20 | this.isRemoval = isRemoval; 21 | os = _os; 22 | var computer = Programs.getComputer(os, computerIP); 23 | targetComp = computer; 24 | container = computer.getFolderFromPath(path, false); 25 | for (var index = 0; index < container.files.Count; ++index) 26 | { 27 | if (container.files[index].name.Equals(target)) 28 | targetData = container.files[index].data; 29 | } 30 | } 31 | 32 | public override bool isComplete(List additionalDetails = null) 33 | { 34 | for (var index = 0; index < container.files.Count; ++index) 35 | { 36 | if (container.files[index].name.Equals(target) && 37 | container.files[index].data.ToLower().Contains(targetKeyword)) 38 | return !isRemoval; 39 | } 40 | return isRemoval; 41 | } 42 | 43 | public override string TestCompletable() 44 | { 45 | var str = ""; 46 | if (container.searchForFile(target) != null) 47 | str = str + "File to change (" + container.name + "/" + target + ") does not exist!"; 48 | return str; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Mission/FileDeletionMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class FileDeletionMission : MisisonGoal 6 | { 7 | public Folder container; 8 | public OS os; 9 | public string target; 10 | public Computer targetComp; 11 | public string targetData; 12 | 13 | public FileDeletionMission(string path, string filename, string computerIP, OS _os) 14 | { 15 | target = filename; 16 | os = _os; 17 | var computer = Programs.getComputer(os, computerIP); 18 | targetComp = computer; 19 | container = computer.getFolderFromPath(path, false); 20 | for (var index = 0; index < container.files.Count; ++index) 21 | { 22 | if (container.files[index].name.Equals(target)) 23 | targetData = container.files[index].data; 24 | } 25 | } 26 | 27 | public override bool isComplete(List additionalDetails = null) 28 | { 29 | for (var index = 0; index < container.files.Count; ++index) 30 | { 31 | if (container.files[index].name.Equals(target) && 32 | (container.files[index].data.Equals(targetData) || targetData == null)) 33 | return false; 34 | } 35 | return true; 36 | } 37 | 38 | public override string TestCompletable() 39 | { 40 | var str = ""; 41 | if (container.searchForFile(target) == null) 42 | str = str + "File to delete (" + container.name + "/" + target + ") does not exist!"; 43 | return str; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Mission/FileDownloadMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class FileDownloadMission : FileDeletionMission 6 | { 7 | public FileDownloadMission(string path, string filename, string computerIP, OS os) 8 | : base(path, filename, computerIP, os) 9 | { 10 | } 11 | 12 | public override bool isComplete(List additionalDetails = null) 13 | { 14 | var folder = os.thisComputer.files.root; 15 | for (var index = 0; index < folder.folders.Count; ++index) 16 | { 17 | if (folder.folders[index].containsFile(target, targetData)) 18 | return true; 19 | } 20 | return false; 21 | } 22 | 23 | public override string TestCompletable() 24 | { 25 | var str = ""; 26 | if (container.searchForFile(target) == null) 27 | str = str + "File to download (" + container.name + "/" + target + ") does not exist!"; 28 | return str; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Mission/FileUploadMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class FileUploadMission : MisisonGoal 6 | { 7 | public Folder container; 8 | public Folder destinationFolder; 9 | public OS os; 10 | public string target; 11 | public Computer targetComp; 12 | public string targetData; 13 | public Computer uploadTargetComp; 14 | 15 | public FileUploadMission(string path, string filename, string computerWithFileIP, string computerToUploadToIP, 16 | string destToUploadToPath, OS _os, bool needsDecrypt = false, string decryptPass = "") 17 | { 18 | target = filename; 19 | os = _os; 20 | var computer1 = Programs.getComputer(os, computerWithFileIP); 21 | targetComp = computer1; 22 | container = computer1.getFolderFromPath(path, false); 23 | for (var index = 0; index < container.files.Count; ++index) 24 | { 25 | if (container.files[index].name.Equals(target)) 26 | { 27 | targetData = container.files[index].data; 28 | if (needsDecrypt) 29 | targetData = FileEncrypter.DecryptString(targetData, decryptPass)[2]; 30 | } 31 | } 32 | var computer2 = Programs.getComputer(os, computerToUploadToIP); 33 | uploadTargetComp = computer2; 34 | destinationFolder = computer2.getFolderFromPath(destToUploadToPath, false); 35 | } 36 | 37 | public override bool isComplete(List additionalDetails = null) 38 | { 39 | for (var index = 0; index < destinationFolder.files.Count; ++index) 40 | { 41 | if (destinationFolder.files[index].data.Equals(targetData)) 42 | return true; 43 | } 44 | return false; 45 | } 46 | 47 | public override string TestCompletable() 48 | { 49 | var str = ""; 50 | if (container.searchForFile(target) == null) 51 | str = str + "File to upload (" + container.name + "/" + target + ") does not exist!"; 52 | return str; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /Mission/GetAdminMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class GetAdminMission : MisisonGoal 6 | { 7 | public OS os; 8 | public Computer target; 9 | 10 | public GetAdminMission(string compIP, OS _os) 11 | { 12 | os = _os; 13 | target = Programs.getComputer(os, compIP); 14 | } 15 | 16 | public override bool isComplete(List additionalDetails = null) 17 | { 18 | return target.adminIP.Equals(os.thisComputer.ip); 19 | } 20 | 21 | public override void reset() 22 | { 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Mission/GetStringMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class GetStringMission : MisisonGoal 6 | { 7 | public string target; 8 | 9 | public GetStringMission(string targetData) 10 | { 11 | target = targetData; 12 | } 13 | 14 | public override bool isComplete(List additionalDetails = null) 15 | { 16 | if (additionalDetails == null) 17 | return false; 18 | for (var index = 0; index < additionalDetails.Count; ++index) 19 | { 20 | if (additionalDetails[index].Contains(target)) 21 | return true; 22 | } 23 | return false; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Mission/MisisonGoal.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | public class MisisonGoal 6 | { 7 | public virtual bool isComplete(List additionalDetails = null) 8 | { 9 | return true; 10 | } 11 | 12 | public virtual void reset() 13 | { 14 | } 15 | 16 | public virtual string TestCompletable() 17 | { 18 | return ""; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Mission/SendEmailMission.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet.Mission 4 | { 5 | internal class SendEmailMission : MisisonGoal 6 | { 7 | private readonly string mailRecipient; 8 | private readonly string mailSubject; 9 | private readonly MailServer server; 10 | 11 | public SendEmailMission(string mailServerID, string mailRecipient, string proposedEmailSubject, OS _os) 12 | { 13 | server = (MailServer) Programs.getComputer(_os, mailServerID).getDaemon(typeof (MailServer)); 14 | mailSubject = proposedEmailSubject; 15 | this.mailRecipient = mailRecipient; 16 | } 17 | 18 | public override bool isComplete(List additionalDetails = null) 19 | { 20 | if (server == null) 21 | return true; 22 | return server.MailWithSubjectExists(mailRecipient, mailSubject); 23 | } 24 | 25 | public override void reset() 26 | { 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Mission/WipeDegreesMission.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet.Mission 5 | { 6 | internal class WipeDegreesMission : MisisonGoal 7 | { 8 | public AcademicDatabaseDaemon database; 9 | private readonly string ownerName; 10 | 11 | public WipeDegreesMission(string targetName, OS _os) 12 | { 13 | var wipeDegreesMission = this; 14 | ownerName = targetName; 15 | Action init = null; 16 | init = () => 17 | { 18 | if (_os.netMap.academicDatabase == null) 19 | _os.delayer.Post(ActionDelayer.NextTick(), init); 20 | else 21 | database = 22 | (AcademicDatabaseDaemon) _os.netMap.academicDatabase.getDaemon(typeof (AcademicDatabaseDaemon)); 23 | }; 24 | init(); 25 | } 26 | 27 | public override bool isComplete(List additionalDetails = null) 28 | { 29 | return !database.hasDegrees(ownerName); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /MissionGenerationParser.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public static class MissionGenerationParser 4 | { 5 | public static string Path; 6 | public static string File; 7 | public static string Comp; 8 | public static string Client; 9 | public static string Target; 10 | public static string Other; 11 | 12 | public static void init() 13 | { 14 | string str; 15 | Target = str = "UNKNOWN"; 16 | Client = str; 17 | File = str; 18 | Path = str; 19 | Comp = "firstGeneratedNode"; 20 | } 21 | 22 | public static string parse(string input) 23 | { 24 | return 25 | input.Replace("#PATH#", Path) 26 | .Replace("#FILE#", File) 27 | .Replace("#COMP#", Comp) 28 | .Replace("#CLIENT#", Client) 29 | .Replace("#TARGET#", Target) 30 | .Replace("#OTHER#", Other) 31 | .Replace("#LC_CLIENT#", Client.Replace(' ', '_').ToLower()); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Module.cs: -------------------------------------------------------------------------------- 1 | using Hacknet.Gui; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace Hacknet 6 | { 7 | internal class Module 8 | { 9 | public static int PANEL_HEIGHT = 15; 10 | private static Rectangle tmpRect; 11 | public Rectangle bounds; 12 | public string name = "Unknown"; 13 | public OS os; 14 | public SpriteBatch spriteBatch; 15 | public bool visible = true; 16 | 17 | public Module(Rectangle location, OS operatingSystem) 18 | { 19 | location.Y += PANEL_HEIGHT; 20 | location.Height -= PANEL_HEIGHT; 21 | bounds = location; 22 | os = operatingSystem; 23 | spriteBatch = os.ScreenManager.SpriteBatch; 24 | } 25 | 26 | public Rectangle Bounds 27 | { 28 | get { return bounds; } 29 | set 30 | { 31 | bounds = value; 32 | bounds.Y += PANEL_HEIGHT; 33 | bounds.Height -= PANEL_HEIGHT; 34 | } 35 | } 36 | 37 | public virtual void LoadContent() 38 | { 39 | } 40 | 41 | public virtual void Update(float t) 42 | { 43 | } 44 | 45 | public virtual void PreDrawStep() 46 | { 47 | } 48 | 49 | public virtual void Draw(float t) 50 | { 51 | drawFrame(); 52 | } 53 | 54 | public virtual void PostDrawStep() 55 | { 56 | } 57 | 58 | public void drawFrame() 59 | { 60 | tmpRect = bounds; 61 | tmpRect.Y -= PANEL_HEIGHT; 62 | tmpRect.Height += PANEL_HEIGHT; 63 | spriteBatch.Draw(Utils.white, tmpRect, os.moduleColorBacking); 64 | RenderedRectangle.doRectangleOutline(tmpRect.X, tmpRect.Y, tmpRect.Width, tmpRect.Height, 1, 65 | os.moduleColorSolid); 66 | tmpRect.Height = PANEL_HEIGHT; 67 | spriteBatch.Draw(Utils.white, tmpRect, os.moduleColorStrong); 68 | spriteBatch.DrawString(GuiData.detailfont, name, new Vector2(tmpRect.X + 2, tmpRect.Y + 2), os.semiTransText); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /MultiplayerGameOverScreen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet 7 | { 8 | internal class MultiplayerGameOverScreen : GameScreen 9 | { 10 | private Rectangle contentRect; 11 | private SpriteFont font; 12 | private readonly bool isWinner; 13 | private Color lossBacking; 14 | private Color lossPattern; 15 | private int screenHeight; 16 | private int screenWidth; 17 | private Color winBacking; 18 | private Color winPattern; 19 | 20 | public MultiplayerGameOverScreen(bool winner) 21 | { 22 | isWinner = winner; 23 | TransitionOnTime = TimeSpan.FromSeconds(3.5); 24 | TransitionOffTime = TimeSpan.FromSeconds(0.200000002980232); 25 | IsPopup = true; 26 | } 27 | 28 | public override void LoadContent() 29 | { 30 | base.LoadContent(); 31 | winBacking = new Color(5, 30, 8); 32 | lossBacking = new Color(34, 8, 5); 33 | winPattern = new Color(11, 66, 23); 34 | lossPattern = new Color(86, 11, 11); 35 | screenWidth = ScreenManager.GraphicsDevice.Viewport.Width; 36 | screenHeight = ScreenManager.GraphicsDevice.Viewport.Height; 37 | contentRect = new Rectangle(0, screenHeight/6, screenWidth, screenHeight - screenHeight/3); 38 | font = ScreenManager.Game.Content.Load("Kremlin"); 39 | } 40 | 41 | public override void HandleInput(InputState input) 42 | { 43 | base.HandleInput(input); 44 | GuiData.doInput(input); 45 | } 46 | 47 | public override void Draw(GameTime gameTime) 48 | { 49 | base.Draw(gameTime); 50 | ScreenManager.FadeBackBufferToBlack(Math.Min(TransitionAlpha, (byte) 150)); 51 | GuiData.startDraw(); 52 | var num = 1f - TransitionPosition; 53 | PatternDrawer.draw(contentRect, 1f, (isWinner ? winBacking : lossBacking)*num, 54 | (isWinner ? winPattern : lossPattern)*num, GuiData.spriteBatch); 55 | var text = isWinner ? "VICTORY" : "DEFEAT"; 56 | var pos = font.MeasureString(text); 57 | pos.X = contentRect.X + contentRect.Width/2 - pos.X/2f; 58 | pos.Y = contentRect.Y + contentRect.Height/2 - pos.Y/2f; 59 | TextItem.DrawShadow = false; 60 | TextItem.doFontLabel(pos, text, font, Color.White*num, float.MaxValue, float.MaxValue); 61 | if (Button.doButton(1008, contentRect.X + 10, contentRect.Y + contentRect.Height - 60, 230, 55, "Exit", 62 | Color.Black)) 63 | { 64 | if (OS.currentInstance != null) 65 | OS.currentInstance.ExitScreen(); 66 | ExitScreen(); 67 | ScreenManager.AddScreen(new MainMenu()); 68 | } 69 | GuiData.endDraw(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /NameGenerator.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet 4 | { 5 | internal static class NameGenerator 6 | { 7 | public static List main; 8 | public static List postfix; 9 | 10 | public static void init() 11 | { 12 | main = new List(); 13 | main.Add("Holopoint"); 14 | main.Add("Ascendant"); 15 | main.Add("Enabled"); 16 | main.Add("Subversion"); 17 | main.Add("Introversion"); 18 | main.Add("Photonic"); 19 | main.Add("Enlightened"); 20 | main.Add("Software"); 21 | main.Add("Facespace"); 22 | main.Add("Mott"); 23 | main.Add("Starchip"); 24 | main.Add("Macrosoft"); 25 | main.Add("Oppol"); 26 | main.Add("Octovision"); 27 | main.Add("tijital"); 28 | main.Add("Valence"); 29 | main.Add("20%Cooler"); 30 | main.Add("Celestia"); 31 | main.Add("Manic"); 32 | main.Add("Dengler"); 33 | main.Add("Beagle"); 34 | main.Add("Warden"); 35 | main.Add("Phoenix"); 36 | main.Add("Banished Stallion"); 37 | postfix = new List(); 38 | postfix.Add(" Inc"); 39 | postfix.Add(" Interactive"); 40 | postfix.Add(".com"); 41 | postfix.Add(" Internal"); 42 | postfix.Add(" Software"); 43 | postfix.Add(" Technologies"); 44 | postfix.Add(" Tech"); 45 | postfix.Add(" Solutions"); 46 | postfix.Add(" Enterprises"); 47 | postfix.Add(" Studios"); 48 | postfix.Add(" Consortium"); 49 | postfix.Add(" Communications"); 50 | } 51 | 52 | public static string generateName() 53 | { 54 | return "" + main[Utils.random.Next(0, main.Count)] + postfix[Utils.random.Next(0, postfix.Count)]; 55 | } 56 | 57 | public static string[] generateCompanyName() 58 | { 59 | return new string[2] 60 | { 61 | main[Utils.random.Next(0, main.Count)], 62 | postfix[Utils.random.Next(0, postfix.Count)] 63 | }; 64 | } 65 | 66 | public static string getRandomMain() 67 | { 68 | return main[Utils.random.Next(0, main.Count)]; 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /OSTheme.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public enum OSTheme 4 | { 5 | TerminalOnlyBlack, 6 | HacknetBlue, 7 | HacknetTeal, 8 | HacknetYellow, 9 | HackerGreen, 10 | HacknetWhite, 11 | HacknetPurple, 12 | HacknetMint 13 | } 14 | } -------------------------------------------------------------------------------- /ObjectState.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | public struct ObjectState 6 | { 7 | public Vector2 Position { get; set; } 8 | 9 | public float VX { get; set; } 10 | 11 | public float VY { get; set; } 12 | 13 | public int state { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /OnlineWebServerDaemon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace Hacknet 5 | { 6 | internal class OnlineWebServerDaemon : WebServerDaemon 7 | { 8 | private static readonly string DEFAULT_PAGE_URL = "http://www.google.com"; 9 | private string lastRequestedURL; 10 | public string webURL = DEFAULT_PAGE_URL; 11 | 12 | public OnlineWebServerDaemon(Computer computer, string serviceName, OS opSystem) 13 | : base(computer, serviceName, opSystem, "Content/Web/BaseImageWebPage.html") 14 | { 15 | } 16 | 17 | public void setURL(string url) 18 | { 19 | webURL = url; 20 | } 21 | 22 | public override void LoadWebPage(string url = null) 23 | { 24 | if (url == null || url == "index.html") 25 | url = webURL; 26 | var webClient = new WebClient(); 27 | webClient.DownloadStringAsync(new Uri(url)); 28 | webClient.DownloadStringCompleted += web_DownloadStringCompleted; 29 | lastRequestedURL = url; 30 | } 31 | 32 | private void web_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) 33 | { 34 | if (!e.Cancelled && e.Error == null) 35 | instantiateWebPage(e.Result); 36 | else 37 | instantiateWebPage(FileSanitiser.purifyStringForDisplay(Utils.readEntireFile("Content/Web/404Page.html"))); 38 | } 39 | 40 | private void instantiateWebPage(string body) 41 | { 42 | var str1 = FileSanitiser.purifyStringForDisplay(body); 43 | var str2 = lastRequestedURL; 44 | var fileEntry = root.searchForFile(str2); 45 | if (fileEntry == null) 46 | { 47 | fileEntry = root.searchForFile("index.html"); 48 | str2 = "index.html"; 49 | } 50 | if (fileEntry != null) 51 | fileEntry.data = str1; 52 | base.LoadWebPage(str2); 53 | } 54 | 55 | public override string getSaveString() 56 | { 57 | return ""; 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /PeopleAssets.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacknet 4 | { 5 | internal class PeopleAssets 6 | { 7 | private static readonly string[] degreeTitles = new string[3] 8 | { 9 | "Bachelor of ", 10 | "Masters in ", 11 | "PHD in " 12 | }; 13 | 14 | private static readonly string[] degreeNames = new string[12] 15 | { 16 | "Computer Science", 17 | "Buisness", 18 | "Electrical Engineering", 19 | "Finance", 20 | "Marketing", 21 | "The Arts", 22 | "Computer Graphics", 23 | "Design", 24 | "Medicine", 25 | "Pharmacy", 26 | "Information Technology", 27 | "Psychology" 28 | }; 29 | 30 | private static readonly string[] hackerDegreeNames = new string[5] 31 | { 32 | "Computer Science", 33 | "Digital Security", 34 | "Computer Networking", 35 | "Information Technology", 36 | "Computer Graphics" 37 | }; 38 | 39 | public static Degree getRandomDegree(WorldLocation origin) 40 | { 41 | var degree = new Degree(); 42 | degree.name = randOf(degreeTitles) + randOf(degreeNames); 43 | degree.GPA = (float) (3.0 + 3.0*(Utils.random.NextDouble() - 0.5)*0.5); 44 | while (degree.GPA > 4.0) 45 | degree.GPA -= Utils.randm(0.4f); 46 | degree.uni = "University of " + origin.name; 47 | if (Utils.flipCoin()) 48 | degree.uni = origin.name + " University"; 49 | return degree; 50 | } 51 | 52 | public static Degree getRandomHackerDegree(WorldLocation origin) 53 | { 54 | var degree = new Degree(); 55 | degree.name = randOf(degreeTitles) + randOf(hackerDegreeNames); 56 | degree.GPA = (float) (3.0 + 5.0*(Utils.random.NextDouble() - 0.5)*0.5); 57 | degree.uni = "University of " + origin.name; 58 | if (Utils.flipCoin()) 59 | degree.uni = origin.name + " University"; 60 | return degree; 61 | } 62 | 63 | public static string randOf(string[] array) 64 | { 65 | var index = (int) (Math.Max(0.0001, Utils.random.NextDouble())*array.Length - 1.0); 66 | return array[index]; 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /Person.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet 5 | { 6 | public class Person 7 | { 8 | public WorldLocation birthplace; 9 | public DateTime DateOfBirth = DateTime.Now; 10 | public List degrees; 11 | public string firstName; 12 | public string handle; 13 | public bool isHacker; 14 | public bool isMale = true; 15 | public string lastName; 16 | public MedicalRecord medicalRecord; 17 | public List vehicles; 18 | 19 | public Person(string fName, string lName, bool male, bool isHacker = false, string handle = null) 20 | { 21 | firstName = fName; 22 | lastName = lName; 23 | isMale = male; 24 | this.handle = handle; 25 | this.isHacker = isHacker; 26 | birthplace = WorldLocationLoader.getRandomLocation(); 27 | vehicles = new List(); 28 | degrees = new List(); 29 | addRandomDegrees(); 30 | addRandomVehicles(); 31 | var num1 = 18; 32 | var num2 = 72; 33 | if (isHacker) 34 | num2 = 45; 35 | DateOfBirth = DateTime.Now - 36 | TimeSpan.FromDays(num1*365 + (int) (Utils.random.NextDouble()*(num2 - num1)*365.0)); 37 | medicalRecord = new MedicalRecord(birthplace, DateOfBirth); 38 | } 39 | 40 | public string FullName 41 | { 42 | get { return firstName + " " + lastName; } 43 | } 44 | 45 | public void addRandomDegrees() 46 | { 47 | var num = 0.6; 48 | if (isHacker) 49 | num = 0.9; 50 | while (Utils.random.NextDouble() < num) 51 | { 52 | if (isHacker) 53 | degrees.Add(PeopleAssets.getRandomHackerDegree(birthplace)); 54 | else 55 | degrees.Add(PeopleAssets.getRandomDegree(birthplace)); 56 | num *= num; 57 | if (isHacker) 58 | num *= 0.36; 59 | } 60 | } 61 | 62 | public void addRandomVehicles() 63 | { 64 | var num = 0.7; 65 | while (Utils.random.NextDouble() < num) 66 | { 67 | vehicles.Add(VehicleInfo.getRandomRegistration()); 68 | num *= num; 69 | if (isHacker) 70 | num *= num; 71 | } 72 | } 73 | 74 | public override string ToString() 75 | { 76 | return firstName + " " + lastName + "\n Gender: " + (isMale ? "Male " : "Female ") + "Born: " + 77 | birthplace.ToString() + "\n" + getDegreeString() + " " + getVehicleRegString() + "\n" + medicalRecord; 78 | } 79 | 80 | private string getDegreeString() 81 | { 82 | var str = "Degrees:\n"; 83 | for (var index = 0; index < degrees.Count; ++index) 84 | str = str + " -" + degrees[index] + "\n"; 85 | return str; 86 | } 87 | 88 | private string getVehicleRegString() 89 | { 90 | var str = "Vehicle Registrations:\n"; 91 | for (var index = 0; index < vehicles.Count; ++index) 92 | str = str + " -" + vehicles[index].ToString() + "\n"; 93 | return str; 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /PlatformAPI/Storage/IStorageMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Hacknet.PlatformAPI.Storage 5 | { 6 | public interface IStorageMethod 7 | { 8 | bool ShouldWrite { get; } 9 | 10 | bool DidDeserialize { get; } 11 | 12 | void Load(); 13 | 14 | SaveFileManifest GetSaveManifest(); 15 | 16 | Stream GetFileReadStream(string filename); 17 | 18 | bool FileExists(string filename); 19 | 20 | void WriteFileData(string filename, string data); 21 | 22 | void WriteFileData(string filename, byte[] data); 23 | 24 | void WriteSaveFileData(string filename, string username, string data, DateTime utcSaveFileTime); 25 | 26 | void UpdateDataFromOtherManager(IStorageMethod otherMethod); 27 | } 28 | } -------------------------------------------------------------------------------- /PlatformAPI/Storage/LocalDocumentsStorageMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Hacknet.PlatformAPI.Storage 5 | { 6 | public class LocalDocumentsStorageMethod : BasicStorageMethod 7 | { 8 | private bool deserialized; 9 | private string FolderPath; 10 | 11 | public override bool ShouldWrite 12 | { 13 | get { return true; } 14 | } 15 | 16 | public override bool DidDeserialize 17 | { 18 | get { return deserialized; } 19 | } 20 | 21 | public override void Load() 22 | { 23 | FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/My Games/Hacknet/Accounts/"; 24 | if (!Directory.Exists(FolderPath)) 25 | Directory.CreateDirectory(FolderPath); 26 | try 27 | { 28 | manifest = SaveFileManifest.Deserialize(this); 29 | } 30 | catch (FormatException ex) 31 | { 32 | manifest = null; 33 | } 34 | catch (NullReferenceException ex) 35 | { 36 | manifest = null; 37 | } 38 | if (manifest == null) 39 | { 40 | manifest = new SaveFileManifest(); 41 | manifest.Save(this); 42 | } 43 | else 44 | deserialized = true; 45 | } 46 | 47 | public override bool FileExists(string filename) 48 | { 49 | return File.Exists(FolderPath + filename); 50 | } 51 | 52 | public override Stream GetFileReadStream(string filename) 53 | { 54 | return File.OpenRead(FolderPath + filename); 55 | } 56 | 57 | public override void WriteFileData(string filename, byte[] data) 58 | { 59 | if (!Directory.Exists(FolderPath)) 60 | Directory.CreateDirectory(FolderPath); 61 | Utils.SafeWriteToFile(data, FolderPath + filename); 62 | } 63 | 64 | public override void WriteFileData(string filename, string data) 65 | { 66 | if (!Directory.Exists(FolderPath)) 67 | Directory.CreateDirectory(FolderPath); 68 | Utils.SafeWriteToFile(data, FolderPath + filename); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /PlatformAPI/Storage/OldSystemStorageMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Hacknet.PlatformAPI.Storage 5 | { 6 | public class OldSystemStorageMethod : IStorageMethod 7 | { 8 | private readonly SaveFileManifest manifest; 9 | 10 | public OldSystemStorageMethod(SaveFileManifest manifest) 11 | { 12 | this.manifest = manifest; 13 | } 14 | 15 | public bool ShouldWrite 16 | { 17 | get { return false; } 18 | } 19 | 20 | public bool DidDeserialize 21 | { 22 | get { return false; } 23 | } 24 | 25 | public void Load() 26 | { 27 | } 28 | 29 | public SaveFileManifest GetSaveManifest() 30 | { 31 | return manifest; 32 | } 33 | 34 | public Stream GetFileReadStream(string filename) 35 | { 36 | return File.OpenRead(filename); 37 | } 38 | 39 | public bool FileExists(string filename) 40 | { 41 | return File.Exists(filename); 42 | } 43 | 44 | public void WriteFileData(string filename, byte[] data) 45 | { 46 | Utils.SafeWriteToFile(data, filename); 47 | } 48 | 49 | public void WriteFileData(string filename, string data) 50 | { 51 | Utils.SafeWriteToFile(data, filename); 52 | } 53 | 54 | public void UpdateDataFromOtherManager(IStorageMethod otherMethod) 55 | { 56 | throw new NotImplementedException(); 57 | } 58 | 59 | public void WriteSaveFileData(string filename, string username, string data, DateTime utcSaveFileTime) 60 | { 61 | throw new NotImplementedException(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /PlatformAPI/Storage/SaveAccountData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | namespace Hacknet.PlatformAPI.Storage 5 | { 6 | public struct SaveAccountData 7 | { 8 | private static readonly string[] Delimiter = new string[1] 9 | { 10 | "\r\n__" 11 | }; 12 | 13 | public string Username; 14 | public string Password; 15 | public string FileUsername; 16 | public DateTime LastWriteTime; 17 | 18 | public static SaveAccountData ParseFromString(string input) 19 | { 20 | var strArray = input.Split(Delimiter, StringSplitOptions.RemoveEmptyEntries); 21 | if (strArray.Length <= 3) 22 | return new SaveAccountData 23 | { 24 | Username = strArray[0], 25 | Password = FileEncrypter.DecryptString(strArray[1], "")[2], 26 | FileUsername = strArray[2] 27 | }; 28 | return new SaveAccountData 29 | { 30 | Username = strArray[0], 31 | Password = FileEncrypter.DecryptString(strArray[1], "")[2], 32 | LastWriteTime = DateTime.Parse(strArray[2], CultureInfo.InvariantCulture), 33 | FileUsername = strArray[3] 34 | }; 35 | } 36 | 37 | public string Serialize() 38 | { 39 | return "" + Username + Delimiter[0] + FileEncrypter.EncryptString(Password, "", "", "", null) + Delimiter[0] + 40 | LastWriteTime.ToString(CultureInfo.InvariantCulture) + Delimiter[0] + FileUsername; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /PlatformAPI/Storage/SteamCloudStorageMethod.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using Steamworks; 5 | 6 | namespace Hacknet.PlatformAPI.Storage 7 | { 8 | public class SteamCloudStorageMethod : BasicStorageMethod 9 | { 10 | private bool deserialized; 11 | 12 | public override bool ShouldWrite 13 | { 14 | get { return true; } 15 | } 16 | 17 | public override bool DidDeserialize 18 | { 19 | get { return deserialized; } 20 | } 21 | 22 | public override void Load() 23 | { 24 | if (!PlatformAPISettings.Running) 25 | return; 26 | manifest = SaveFileManifest.Deserialize(this); 27 | if (manifest == null) 28 | { 29 | manifest = new SaveFileManifest(); 30 | manifest.Save(this); 31 | } 32 | else 33 | deserialized = true; 34 | } 35 | 36 | public override bool FileExists(string filename) 37 | { 38 | if (!PlatformAPISettings.Running) 39 | return false; 40 | return SteamRemoteStorage.FileExists(filename); 41 | } 42 | 43 | public override Stream GetFileReadStream(string filename) 44 | { 45 | if (!PlatformAPISettings.Running) 46 | return null; 47 | var cubDataToRead = 2000000; 48 | var numArray = new byte[cubDataToRead]; 49 | if (!SteamRemoteStorage.FileExists(filename)) 50 | return null; 51 | var count = SteamRemoteStorage.FileRead(filename, numArray, cubDataToRead); 52 | Encoding.UTF8.GetString(numArray); 53 | return new MemoryStream(numArray, 0, count); 54 | } 55 | 56 | public override void WriteFileData(string filename, byte[] data) 57 | { 58 | if (!PlatformAPISettings.Running || SteamRemoteStorage.FileWrite(filename, data, data.Length)) 59 | return; 60 | Console.WriteLine("Failed to write to steam"); 61 | } 62 | 63 | public override void WriteFileData(string filename, string data) 64 | { 65 | var bytes = Encoding.UTF8.GetBytes(data); 66 | WriteFileData(filename, bytes); 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /PlatformAPISettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Steamworks; 3 | 4 | namespace Hacknet 5 | { 6 | public static class PlatformAPISettings 7 | { 8 | public static string Report = ""; 9 | public static bool Running; 10 | public static bool RemoteStorageRunning; 11 | 12 | public static void InitPlatformAPI() 13 | { 14 | if (Settings.isConventionDemo) 15 | return; 16 | Running = true; // SteamAPI.Init(); 17 | if (!Running) 18 | { 19 | Report = "First Init Failed. "; 20 | Console.WriteLine("Steam Init Failed!"); 21 | Running = SteamAPI.InitSafe(); 22 | Report = Report + " Second init Running = " + Running; 23 | } 24 | else 25 | Report = "Steam API Running :" + Running; 26 | if (!Running) 27 | return; 28 | RemoteStorageRunning = false; // SteamRemoteStorage.IsCloudEnabledForAccount(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /PlayerBonuses.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct PlayerBonuses 4 | { 5 | public float max_velocity; 6 | public float acceleration; 7 | public float dash_regen_rate; 8 | public float max_dash_range; 9 | public float gravity_factor; 10 | public float jump_height_factor; 11 | public float dash_velocity_retain_factor; 12 | public int control_invert; 13 | public int screen_invert; 14 | } 15 | } -------------------------------------------------------------------------------- /PlayerIndexEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | 4 | namespace Hacknet 5 | { 6 | internal class PlayerIndexEventArgs : EventArgs 7 | { 8 | public PlayerIndexEventArgs(PlayerIndex playerIndex) 9 | { 10 | PlayerIndex = playerIndex; 11 | } 12 | 13 | public PlayerIndex PlayerIndex { get; } 14 | } 15 | } -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Hacknet 4 | { 5 | internal static class Program 6 | { 7 | public static string GraphicsDeviceResetLog = ""; 8 | 9 | [STAThread] 10 | private static void Main(string[] args) 11 | { 12 | using (var game1 = new Game1()) 13 | { 14 | try 15 | { 16 | game1.Run(); 17 | } 18 | catch (Exception ex1) 19 | { 20 | var str1 = Utils.GenerateReportFromException(ex1); 21 | try 22 | { 23 | if (OS.currentInstance != null) 24 | { 25 | str1 = str1 + "\r\n\r\n" + OS.currentInstance.Flags.GetSaveString() + "\r\n\r\n"; 26 | str1 = string.Concat(str1, "Timer : ", (float) (OS.currentInstance.timer/60.0), "mins\r\n"); 27 | str1 = str1 + "Display cache : " + OS.currentInstance.displayCache + "\r\n"; 28 | str1 = str1 + "String Cache : " + OS.currentInstance.getStringCache + "\r\n"; 29 | str1 = str1 + "Terminal--------------\r\n" + 30 | OS.currentInstance.terminal.GetRecentTerminalHistoryString() + "-------------\r\n"; 31 | } 32 | else 33 | str1 += "\r\n\r\nOS INSTANCE NULL\r\n\r\n"; 34 | str1 = str1 + "\r\nMenuErrorCache: " + MainMenu.AccumErrors + "\r\n"; 35 | } 36 | catch (Exception ex2) 37 | { 38 | } 39 | var str2 = str1 + "\r\n\r\nPlatform API: " + PlatformAPISettings.Report + 40 | "\r\n\r\nGraphics Device Reset Log: " + GraphicsDeviceResetLog + "\r\n\r\nCurrent Time: " + 41 | DateTime.Now.ToShortTimeString() + "\r\n"; 42 | Utils.writeToFile(str2, "CrashReport_" + Guid.NewGuid().ToString().Replace(" ", "_") + ".txt"); 43 | Utils.SendRealWorldEmail( 44 | "Hackent " + MainMenu.OSVersion + " Crash " + DateTime.Now.ToShortDateString() + " " + 45 | DateTime.Now.ToShortTimeString(), "hacknetbugs+Hacknet@gmail.com", str2); 46 | } 47 | } 48 | } 49 | } 50 | } -------------------------------------------------------------------------------- /ProgramList.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Hacknet 4 | { 5 | internal static class ProgramList 6 | { 7 | public static List programs; 8 | 9 | public static void init() 10 | { 11 | programs = new List(); 12 | programs.Add("ls"); 13 | programs.Add("cd"); 14 | programs.Add("probe"); 15 | programs.Add("scan"); 16 | programs.Add("ps"); 17 | programs.Add("kill"); 18 | programs.Add("connect"); 19 | programs.Add("dc"); 20 | programs.Add("disconnect"); 21 | programs.Add("help"); 22 | programs.Add("exe"); 23 | programs.Add("cat"); 24 | programs.Add("scp"); 25 | programs.Add("rm"); 26 | programs.Add("openCDTray"); 27 | programs.Add("closeCDTray"); 28 | programs.Add("login"); 29 | programs.Add("reboot"); 30 | programs.Add("mv"); 31 | programs.Add("upload"); 32 | programs.Add("analyze"); 33 | programs.Add("solve"); 34 | programs.Add("addNote"); 35 | } 36 | 37 | public static List getExeList(OS os) 38 | { 39 | var list = new List(); 40 | list.Add("PortHack"); 41 | list.Add("ForkBomb"); 42 | list.Add("Shell"); 43 | list.Add("Tutorial"); 44 | list.Add("Notes"); 45 | var folder = os.thisComputer.files.root.folders[2]; 46 | for (var index = 0; index < folder.files.Count; ++index) 47 | list.Add(folder.files[index].name.Replace(".exe", "")); 48 | return list; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /ProgressionFlags.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Xml; 5 | 6 | namespace Hacknet 7 | { 8 | public class ProgressionFlags 9 | { 10 | private readonly List Flags = new List(); 11 | 12 | public bool HasFlag(string flag) 13 | { 14 | return Flags.Contains(flag); 15 | } 16 | 17 | public void AddFlag(string flag) 18 | { 19 | if (HasFlag(flag)) 20 | return; 21 | Flags.Add(flag); 22 | } 23 | 24 | public void RemoveFlag(string flag) 25 | { 26 | Flags.Remove(flag); 27 | } 28 | 29 | public void Load(XmlReader rdr) 30 | { 31 | Flags.Clear(); 32 | while (!(rdr.Name == "Flags") || !rdr.IsStartElement()) 33 | { 34 | rdr.Read(); 35 | if (rdr.EOF) 36 | throw new InvalidOperationException("XML reached End of file too fast!"); 37 | } 38 | var num1 = (int) rdr.MoveToContent(); 39 | var str1 = rdr.ReadElementContentAsString(); 40 | var separator = new char[1] 41 | { 42 | ',' 43 | }; 44 | var num2 = 1; 45 | foreach (var str2 in str1.Split(separator, (StringSplitOptions) num2)) 46 | Flags.Add(str2.Replace("[%%COMMAREPLACED%%]", ",")); 47 | } 48 | 49 | public string GetSaveString() 50 | { 51 | var stringBuilder = new StringBuilder(); 52 | for (var index = 0; index < Flags.Count; ++index) 53 | { 54 | stringBuilder.Append(Flags[index].Replace(",", "[%%COMMAREPLACED%%]")); 55 | stringBuilder.Append(","); 56 | } 57 | if (stringBuilder.Length > 0) 58 | stringBuilder.Remove(stringBuilder.Length - 1, 1); 59 | return "" + stringBuilder + "\r\n"; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenHacknet 2 | 3 | OpenHacknet is a decompile of Hacknet, a game written in C# and XNA. 4 | 5 | OpenHacknet is supposed to support modding of Hacknet, not to encourage piracy. 6 | 7 | To acquire the game resource files, buy Hacknet on Steam. 8 | 9 | # Setup 10 | Create a new folder lib/ in the same folder as the Hacknet.sln. Go to the Hacknet game content folder in the 11 | steamapps/common folder and copy Steamworks.NET.dll into lib/. Then, copy CSteamworks.dll and steam_api.dll 12 | into the bin/x86/Release and bin/x86/Debug folders. Finally, either copy the Content folder to the same 13 | directories or create a directory junction using mklink. 14 | 15 | # Contributing 16 | Please do not contribute your own mods to the master branch. If you wish to modify Hacknet's functionality 17 | (other than fixing typos), create a fork. Contributions should consist of source cleanups or typo fixes only 18 | and should not change the gameplay or functionality of Hacknet. 19 | 20 | Please support the developer by purchasing Hacknet on Steam. 21 | -------------------------------------------------------------------------------- /RamModule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace Hacknet 6 | { 7 | internal class RamModule : CoreModule 8 | { 9 | public static int contentStartOffset = 16; 10 | public static int MODULE_WIDTH = 252; 11 | public static Color USED_RAM_COLOR = new Color(60, 60, 67); 12 | public static float FLASH_TIME = 3f; 13 | private Rectangle infoBar; 14 | private Rectangle infoBarUsedRam; 15 | private string infoString = ""; 16 | private Vector2 infoStringPos; 17 | private float OutOfMemoryFlashTime; 18 | 19 | public RamModule(Rectangle location, OS operatingSystem) 20 | : base(location, operatingSystem) 21 | { 22 | } 23 | 24 | public override void LoadContent() 25 | { 26 | base.LoadContent(); 27 | infoBar = new Rectangle(bounds.X + 1, bounds.Y + 1, bounds.Width - 2, contentStartOffset); 28 | infoBarUsedRam = new Rectangle(bounds.X + 1, bounds.Y + 1, bounds.Width - 2, contentStartOffset); 29 | infoStringPos = new Vector2(infoBar.X, infoBar.Y); 30 | } 31 | 32 | public override void Update(float t) 33 | { 34 | base.Update(t); 35 | infoBar = new Rectangle(bounds.X + 1, bounds.Y + 1, bounds.Width - 2, contentStartOffset); 36 | infoString = "USED RAM: " + (os.totalRam - os.ramAvaliable) + "mb / " + os.totalRam + "mb"; 37 | infoBarUsedRam = new Rectangle(bounds.X + 1, bounds.Y + 1, bounds.Width - 2, contentStartOffset); 38 | if (OutOfMemoryFlashTime <= 0.0) 39 | return; 40 | OutOfMemoryFlashTime -= t; 41 | } 42 | 43 | public void FlashMemoryWarning() 44 | { 45 | OutOfMemoryFlashTime = FLASH_TIME; 46 | } 47 | 48 | public override void Draw(float t) 49 | { 50 | base.Draw(t); 51 | spriteBatch.Draw(Utils.white, infoBar, os.indentBackgroundColor); 52 | infoBarUsedRam.Width = (int) (infoBar.Width*(1.0 - os.ramAvaliable/(double) os.totalRam)); 53 | spriteBatch.Draw(Utils.white, infoBarUsedRam, USED_RAM_COLOR); 54 | spriteBatch.DrawString(GuiData.detailfont, infoString, new Vector2(infoBar.X, infoBar.Y), Color.White); 55 | spriteBatch.DrawString(GuiData.detailfont, string.Concat(os.exes.Count), 56 | new Vector2(bounds.X + bounds.Width - (os.exes.Count >= 10 ? 24 : 12), infoBar.Y), Color.White); 57 | if (OutOfMemoryFlashTime <= 0.0) 58 | return; 59 | var num = Math.Min(1f, OutOfMemoryFlashTime); 60 | var amount = Math.Max(0.0f, OutOfMemoryFlashTime - (FLASH_TIME - 1f)); 61 | PatternDrawer.draw(bounds, 0.0f, Color.Transparent, 62 | Color.Lerp(os.lockedColor, Utils.AddativeRed, amount)*num, spriteBatch, PatternDrawer.errorTile); 63 | var height = 40; 64 | var rectangle = new Rectangle(bounds.X, bounds.Y + bounds.Height - height - 1, bounds.Width, height); 65 | spriteBatch.Draw(Utils.white, Utils.InsetRectangle(rectangle, 4), Color.Black*0.75f); 66 | --rectangle.X; 67 | var text = " ^ INSUFFICIENT MEMORY ^ "; 68 | TextItem.doFontLabelToSize(rectangle, text, GuiData.font, Color.Black*num); 69 | rectangle.X += 2; 70 | TextItem.doFontLabelToSize(rectangle, text, GuiData.font, Color.Black*num); 71 | --rectangle.X; 72 | TextItem.doFontLabelToSize(rectangle, text, GuiData.font, Color.White*num); 73 | } 74 | 75 | public virtual void drawOutline() 76 | { 77 | var destinationRectangle = bounds; 78 | spriteBatch.Draw(Utils.white, destinationRectangle, os.outlineColor); 79 | ++destinationRectangle.X; 80 | ++destinationRectangle.Y; 81 | destinationRectangle.Width -= 2; 82 | destinationRectangle.Height -= 2; 83 | spriteBatch.Draw(Utils.white, destinationRectangle, os.darkBackgroundColor); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /RemoteSaveStorage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | using Microsoft.Xna.Framework; 5 | using Steamworks; 6 | 7 | namespace Hacknet 8 | { 9 | public static class RemoteSaveStorage 10 | { 11 | public static string BASE_SAVE_FILE_NAME = "save"; 12 | public static string SAVE_FILE_EXT = ".xml"; 13 | public static string Standalone_FolderPath = "Accounts/"; 14 | 15 | public static bool FileExists(string playerID, bool forceLocal = false) 16 | { 17 | var pchFile = BASE_SAVE_FILE_NAME + playerID + SAVE_FILE_EXT; 18 | if (!forceLocal && PlatformAPISettings.Running) 19 | return SteamRemoteStorage.FileExists(pchFile); 20 | return File.Exists(Standalone_FolderPath + pchFile); 21 | } 22 | 23 | public static Stream GetSaveReadStream(string playerID, bool forceLocal = false) 24 | { 25 | var pchFile = BASE_SAVE_FILE_NAME + playerID + SAVE_FILE_EXT; 26 | if (!forceLocal && PlatformAPISettings.Running) 27 | { 28 | var cubDataToRead = 2000000; 29 | var numArray = new byte[cubDataToRead]; 30 | if (!SteamRemoteStorage.FileExists(pchFile)) 31 | return null; 32 | var count = SteamRemoteStorage.FileRead(pchFile, numArray, cubDataToRead); 33 | if (count == 0) 34 | return null; 35 | Encoding.UTF8.GetString(numArray); 36 | return new MemoryStream(numArray, 0, count); 37 | } 38 | if (File.Exists(Standalone_FolderPath + pchFile)) 39 | return TitleContainer.OpenStream(Standalone_FolderPath + pchFile); 40 | return null; 41 | } 42 | 43 | public static void WriteSaveData(string saveData, string playerID, bool forcelocal = false) 44 | { 45 | var pchFile = BASE_SAVE_FILE_NAME + playerID + SAVE_FILE_EXT; 46 | if (!forcelocal || !PlatformAPISettings.Running) 47 | { 48 | var bytes = Encoding.UTF8.GetBytes(saveData); 49 | if (!SteamRemoteStorage.FileWrite(pchFile, bytes, bytes.Length)) 50 | Console.WriteLine("Failed to write to steam"); 51 | try 52 | { 53 | Utils.SafeWriteToFile(saveData, Standalone_FolderPath + pchFile); 54 | } 55 | catch (Exception ex) 56 | { 57 | Utils.AppendToErrorFile(Utils.GenerateReportFromException(ex)); 58 | } 59 | } 60 | else 61 | Utils.SafeWriteToFile(saveData, Standalone_FolderPath + pchFile); 62 | } 63 | 64 | public static void Delete(string playerID) 65 | { 66 | var pchFile = BASE_SAVE_FILE_NAME + playerID + SAVE_FILE_EXT; 67 | if (PlatformAPISettings.Running) 68 | { 69 | SteamRemoteStorage.FileDelete(pchFile); 70 | } 71 | else 72 | { 73 | if (!Directory.Exists(Standalone_FolderPath) || !File.Exists(Standalone_FolderPath + pchFile)) 74 | return; 75 | File.Delete(Standalone_FolderPath + pchFile); 76 | } 77 | } 78 | 79 | public static bool CanLoad(string playerID) 80 | { 81 | var pchFile = BASE_SAVE_FILE_NAME + playerID + SAVE_FILE_EXT; 82 | if (PlatformAPISettings.Running) 83 | return SteamRemoteStorage.FileExists(pchFile); 84 | return File.Exists(Standalone_FolderPath + pchFile); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /SFX.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Content; 5 | using Microsoft.Xna.Framework.Graphics; 6 | 7 | namespace Hacknet 8 | { 9 | public static class SFX 10 | { 11 | private static readonly List circlePos = new List(); 12 | private static readonly List circleRadius = new List(); 13 | private static readonly List circleExpand = new List(); 14 | private static readonly List circleColor = new List(); 15 | private static Texture2D circleTex; 16 | private static Vector2 circleOrigin; 17 | 18 | public static void init(ContentManager content) 19 | { 20 | circleTex = content.Load("CircleOutlineLarge"); 21 | circleOrigin = new Vector2(circleTex.Width/2, circleTex.Height/2); 22 | } 23 | 24 | public static void addCircle(Vector2 pos, Color color, float radius) 25 | { 26 | circlePos.Add(pos); 27 | circleColor.Add(color); 28 | circleExpand.Add(0.0f); 29 | circleRadius.Add(radius/256f); 30 | } 31 | 32 | public static void Update(float t) 33 | { 34 | for (var index1 = 0; index1 < circlePos.Count; ++index1) 35 | { 36 | List list; 37 | int index2; 38 | (list = circleExpand)[index2 = index1] = list[index2] + t; 39 | if (circleExpand[index1] >= 3.0) 40 | { 41 | circlePos.RemoveAt(index1); 42 | circleColor.RemoveAt(index1); 43 | circleExpand.RemoveAt(index1); 44 | circleRadius.RemoveAt(index1); 45 | --index1; 46 | } 47 | } 48 | } 49 | 50 | public static void Draw(SpriteBatch sb) 51 | { 52 | try 53 | { 54 | for (var index = 0; index < circlePos.Count; ++index) 55 | { 56 | var num1 = circleExpand[index]/3f; 57 | var num2 = num1 >= 0.200000002980232 ? 1f - num1 : num1/0.2f; 58 | sb.Draw(circleTex, circlePos[index], new Rectangle?(), circleColor[index]*num2, 0.0f, circleOrigin, 59 | Vector2.One*circleRadius[index]*circleExpand[index], SpriteEffects.None, 0.2f); 60 | } 61 | } 62 | catch (IndexOutOfRangeException ex) 63 | { 64 | } 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /SaveData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet 5 | { 6 | [Serializable] 7 | public class SaveData 8 | { 9 | private ActiveMission mission; 10 | private List nodes; 11 | 12 | public void addNodes(object nodesToAdd) 13 | { 14 | nodes = (List) nodesToAdd; 15 | } 16 | 17 | public void setMission(object missionToAdd) 18 | { 19 | mission = (ActiveMission) missionToAdd; 20 | } 21 | 22 | public object getNodes() 23 | { 24 | return nodes; 25 | } 26 | 27 | public object getMission() 28 | { 29 | return mission; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ScreenManagement/MessagePopup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | using Microsoft.Xna.Framework.Input; 5 | 6 | namespace Hacknet.ScreenManagement 7 | { 8 | internal class MessagePopup : GameScreen 9 | { 10 | private static readonly int BOX_WIDTH = 500; 11 | private static readonly int BOX_HEIGHT = 350; 12 | private Texture2D blankTexture; 13 | private readonly string messageContent = ""; 14 | 15 | public MessagePopup(string message) 16 | { 17 | TransitionOnTime = TimeSpan.FromSeconds(0.5); 18 | TransitionOffTime = TimeSpan.FromSeconds(0.5); 19 | messageContent = message; 20 | } 21 | 22 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 23 | { 24 | } 25 | 26 | public override void HandleInput(InputState input) 27 | { 28 | var state = Keyboard.GetState(); 29 | if (!state.IsKeyDown(Keys.Space) && !state.IsKeyDown(Keys.Up) && 30 | (!state.IsKeyDown(Keys.Z) && !state.IsKeyDown(Keys.Left)) && 31 | (!state.IsKeyDown(Keys.Right) && !state.IsKeyDown(Keys.X))) 32 | return; 33 | ExitScreen(); 34 | } 35 | 36 | public override void Draw(GameTime gameTime) 37 | { 38 | var spriteBatch = ScreenManager.SpriteBatch; 39 | var viewport = ScreenManager.GraphicsDevice.Viewport; 40 | var rectangle = new Rectangle(0, 0, viewport.Width, viewport.Height); 41 | var destinationRectangle = new Rectangle(viewport.Width/2 - BOX_WIDTH/2, viewport.Height/2 - BOX_HEIGHT/2, 42 | BOX_WIDTH, BOX_HEIGHT); 43 | var transitionAlpha = TransitionAlpha; 44 | spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive); 45 | spriteBatch.Draw(Utils.white, destinationRectangle, 46 | new Color(transitionAlpha, transitionAlpha, transitionAlpha)); 47 | var font = ScreenManager.Font; 48 | var origin = new Vector2(0.0f, font.LineSpacing/2); 49 | var position = new Vector2(destinationRectangle.X, destinationRectangle.Y); 50 | spriteBatch.DrawString(font, messageContent, position, Color.White, 0.0f, origin, 1f, SpriteEffects.None, 51 | 0.0f); 52 | spriteBatch.End(); 53 | } 54 | 55 | public override void UnloadContent() 56 | { 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /ScreenState.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public enum ScreenState 4 | { 5 | TransitionOn, 6 | Active, 7 | TransitionOff, 8 | Hidden 9 | } 10 | } -------------------------------------------------------------------------------- /SecurityTraceExe.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | internal class SecurityTraceExe : ExeModule 6 | { 7 | public SecurityTraceExe(Rectangle location, OS _os) 8 | : base(location, _os) 9 | { 10 | name = "SecurityTrace"; 11 | IdentifierName = "Security Tracer"; 12 | ramCost = 150; 13 | if (os.connectedComp == null) 14 | os.connectedComp = os.thisComputer; 15 | os.traceTracker.start(30f); 16 | os.warningFlash(); 17 | } 18 | 19 | public override void Killed() 20 | { 21 | base.Killed(); 22 | os.traceTracker.stop(); 23 | } 24 | 25 | public override void Draw(float t) 26 | { 27 | base.Draw(t); 28 | drawOutline(); 29 | drawTarget("app:"); 30 | var dest = bounds; 31 | dest.X += 2; 32 | dest.Width -= 4; 33 | dest.Height -= PANEL_HEIGHT + 1; 34 | dest.Y += PANEL_HEIGHT; 35 | PatternDrawer.draw(dest, -1f, Color.Transparent, os.darkBackgroundColor, spriteBatch); 36 | PatternDrawer.draw(dest, 3f, Color.Transparent, os.lockedColor, spriteBatch, PatternDrawer.errorTile); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /ServerScreen.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Hacknet.ExternalCounterparts; 3 | using Hacknet.Gui; 4 | using Microsoft.Xna.Framework; 5 | 6 | namespace Hacknet 7 | { 8 | internal class ServerScreen : GameScreen 9 | { 10 | private readonly Color backgroundColor = new Color(6, 6, 6); 11 | private bool canCloseServer; 12 | public bool drawingWithEffects; 13 | private string mainIP; 14 | private readonly List messages; 15 | private readonly ExternalNetworkedServer server; 16 | 17 | public ServerScreen() 18 | { 19 | mainIP = MultiplayerLobby.getLocalIP(); 20 | messages = new List(); 21 | server = new ExternalNetworkedServer(); 22 | server.initializeListener(); 23 | server.messageReceived += parseMessage; 24 | } 25 | 26 | public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) 27 | { 28 | base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); 29 | canCloseServer = !otherScreenHasFocus && !coveredByOtherScreen; 30 | } 31 | 32 | public override void HandleInput(InputState input) 33 | { 34 | base.HandleInput(input); 35 | GuiData.doInput(input); 36 | } 37 | 38 | public void parseMessage(string msg) 39 | { 40 | addDisplayMessage(msg); 41 | var chArray = new char[2] 42 | { 43 | ' ', 44 | '\n' 45 | }; 46 | var strArray = msg.Split(chArray); 47 | if (!strArray[0].Equals("cCDDrive")) 48 | return; 49 | if (strArray[2].Equals("open")) 50 | Programs.cdDrive(true); 51 | else 52 | Programs.cdDrive(false); 53 | } 54 | 55 | public void addDisplayMessage(string msg) 56 | { 57 | messages.Add(msg); 58 | } 59 | 60 | public override void Draw(GameTime gameTime) 61 | { 62 | base.Draw(gameTime); 63 | if (drawingWithEffects) 64 | PostProcessor.begin(); 65 | GuiData.startDraw(); 66 | var viewport = ScreenManager.GraphicsDevice.Viewport; 67 | GuiData.spriteBatch.Draw(Utils.white, new Rectangle(0, 0, viewport.Width, viewport.Height), backgroundColor); 68 | var x = 80; 69 | var num1 = 80; 70 | TextItem.doFontLabel(new Vector2(x, num1), "HACKNET RELAY SERVER", GuiData.titlefont, new Color?(), 500f, 71 | 50f); 72 | var y1 = num1 + 55; 73 | if (canCloseServer && Button.doButton(800, x, y1, 160, 30, "Shut Down Server", new Color?())) 74 | { 75 | server.closeServer(); 76 | ExitScreen(); 77 | } 78 | var num2 = y1 + 35; 79 | for (var index = 0; index < MultiplayerLobby.allLocalIPs.Count; ++index) 80 | { 81 | TextItem.doFontLabel(new Vector2(x, num2), "IP: " + MultiplayerLobby.allLocalIPs[index], 82 | GuiData.smallfont, new Color?(), float.MaxValue, float.MaxValue); 83 | num2 += 20; 84 | } 85 | var y2 = num2 + 30; 86 | drawMessageLog(x, y2); 87 | GuiData.endDraw(); 88 | if (!drawingWithEffects) 89 | return; 90 | PostProcessor.end(); 91 | } 92 | 93 | public void drawMessageLog(int x, int y) 94 | { 95 | var num = 1f; 96 | var pos = new Vector2(x, y); 97 | for (var index = 0; index < 20 && index < messages.Count; ++index) 98 | { 99 | if (index > 10) 100 | num = (float) (1.0 - (index - 10)/10.0); 101 | TextItem.doTinyLabel(pos, messages[messages.Count - 1 - index], Color.White*num); 102 | pos.Y += 13f; 103 | } 104 | } 105 | } 106 | } -------------------------------------------------------------------------------- /Services.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public static class Services 4 | { 5 | public const int ADMIN = 0; 6 | public const int ALL = 1; 7 | public const int MAIL = 2; 8 | public const int MISSIONLIST = 3; 9 | } 10 | } -------------------------------------------------------------------------------- /Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | 4 | namespace Hacknet 5 | { 6 | public static class Settings 7 | { 8 | public static bool MenuStartup = true; 9 | public static bool slowOSStartup = true; 10 | public static bool osStartsWithTutorial = slowOSStartup; 11 | public static bool isAlphaDemoMode = false; 12 | public static bool soundDisabled = false; 13 | public static bool debugCommandsEnabled = false; 14 | public static bool testingMenuItemsEnabled = false; 15 | public static bool debugDrawEnabled = false; 16 | public static bool forceCompleteEnabled = debugCommandsEnabled; 17 | public static bool FastBootText = false; 18 | public static bool AllowAdventureMode = false; 19 | public static bool initShowsTutorial = osStartsWithTutorial; 20 | public static bool windowed = false; 21 | public static bool IsInAdventureMode = false; 22 | public static bool isDemoMode = false; 23 | public static bool isPressBuildDemo = false; 24 | public static bool isConventionDemo = false; 25 | public static bool isLockedDemoMode = false; 26 | public static bool isSpecialTestBuild = false; 27 | public static bool lighterColorHexBackground = false; 28 | public static string ConventionLoginName = "SurpriseAttack"; 29 | public static bool IsExpireLocked = false; 30 | public static DateTime ExpireTime = DateTime.Parse("10/8/2020 12:01:36 PM", new CultureInfo("en-au")); 31 | public static bool isServerMode = false; 32 | public static bool recoverFromErrorsSilently = true; 33 | } 34 | } -------------------------------------------------------------------------------- /SettingsLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace Hacknet 6 | { 7 | public static class SettingsLoader 8 | { 9 | public static bool isFullscreen; 10 | public static bool didLoad; 11 | public static bool hasEverSaved; 12 | public static int resWidth; 13 | public static int resHeight; 14 | 15 | public static void checkStatus() 16 | { 17 | if (!File.Exists("Settings.txt")) 18 | return; 19 | var strArray = new StreamReader(TitleContainer.OpenStream("Settings.txt")).ReadToEnd().Split(new string[2] 20 | { 21 | "\r\n", 22 | "\n" 23 | }, StringSplitOptions.None); 24 | resWidth = Convert.ToInt32(strArray[0]); 25 | resHeight = Convert.ToInt32(strArray[1]); 26 | isFullscreen = strArray[2].ToLower().Equals("true"); 27 | if (strArray.Length > 3) 28 | { 29 | PostProcessor.bloomEnabled = strArray[3].Substring(strArray[3].IndexOf(' ') + 1) == "true"; 30 | PostProcessor.scanlinesEnabled = strArray[4].Substring(strArray[4].IndexOf(' ') + 1) == "true"; 31 | } 32 | if (strArray.Length > 6) 33 | { 34 | MusicManager.isMuted = strArray[5].Substring(strArray[5].IndexOf(' ') + 1) == "true"; 35 | var str = strArray[6].Substring(strArray[6].IndexOf(' ') + 1).Trim(); 36 | MusicManager.getVolume(); 37 | try 38 | { 39 | MusicManager.setVolume((float) Convert.ToDouble(str)); 40 | } 41 | catch (FormatException ex) 42 | { 43 | } 44 | MusicManager.dataLoadedFromOutsideFile = true; 45 | } 46 | if (strArray.Length > 7) 47 | { 48 | var str = strArray[7].Substring(strArray[7].IndexOf(' ') + 1); 49 | GuiData.ActiveFontConfig.name = str; 50 | } 51 | if (strArray.Length > 8) 52 | hasEverSaved = strArray[8].Substring(strArray[8].IndexOf(' ') + 1) == "True"; 53 | didLoad = true; 54 | } 55 | 56 | public static void writeStatusFile() 57 | { 58 | var graphicsDevice = Game1.getSingleton().GraphicsDevice; 59 | Utils.writeToFile( 60 | string.Concat( 61 | string.Concat( 62 | (graphicsDevice.PresentationParameters.BackBufferWidth.ToString() + "\r\n" + 63 | graphicsDevice.PresentationParameters.BackBufferHeight + "\r\n" + 64 | (Game1.getSingleton().graphics.IsFullScreen ? "true" : "false") + "\r\n" + "bloom: " + 65 | (PostProcessor.bloomEnabled ? "true" : "false") + "\r\n" + "scanlines: " + 66 | (PostProcessor.scanlinesEnabled ? "true" : "false") + "\r\n" + "muted: " + 67 | (MusicManager.isMuted ? "true" : "false") + "\r\n"), "volume: ", 68 | MusicManager.getVolume(), "\r\n") + "fontConfig: " + 69 | GuiData.ActiveFontConfig.name + "\r\n", "hasSaved: ", hasEverSaved, "\r\n"), "Settings.txt"); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /SongChangerDaemon.cs: -------------------------------------------------------------------------------- 1 | using Hacknet.Effects; 2 | using Hacknet.Gui; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet 7 | { 8 | internal class SongChangerDaemon : Daemon 9 | { 10 | private readonly MovingBarsEffect botEffect; 11 | private readonly MovingBarsEffect topEffect; 12 | 13 | public SongChangerDaemon(Computer c, OS os) 14 | : base(c, "Music Changer", os) 15 | { 16 | topEffect = new MovingBarsEffect(); 17 | botEffect = new MovingBarsEffect 18 | { 19 | IsInverted = true 20 | }; 21 | } 22 | 23 | public override void draw(Rectangle bounds, SpriteBatch sb) 24 | { 25 | base.draw(bounds, sb); 26 | topEffect.Update((float) os.lastGameTime.ElapsedGameTime.TotalSeconds); 27 | botEffect.Update((float) os.lastGameTime.ElapsedGameTime.TotalSeconds); 28 | var height = 30; 29 | var rectangle1 = new Rectangle(bounds.X + 30, bounds.Y + bounds.Height/2 - height/2, bounds.Width - 60, 30 | height); 31 | var bounds1 = rectangle1; 32 | bounds1.Height = 60; 33 | bounds1.Y -= bounds1.Height; 34 | topEffect.Draw(sb, bounds1, 1f, 3f, 1f, os.highlightColor); 35 | if (Button.doButton(73518921, rectangle1.X, rectangle1.Y, rectangle1.Width, rectangle1.Height, 36 | "Shuffle Music", os.highlightColor)) 37 | { 38 | var maxValue = 12; 39 | MissionFunctions.runCommand(Utils.random.Next(maxValue) + 1, "changeSong"); 40 | } 41 | bounds1.Y += bounds1.Height + height; 42 | botEffect.Draw(sb, bounds1, 1f, 3f, 1f, os.highlightColor); 43 | var rectangle2 = new Rectangle(bounds.X + 4, bounds.Y + bounds.Height - 4 - 20, (int) (bounds.Width*0.5), 20); 44 | if ( 45 | !Button.doButton(73518924, rectangle2.X, rectangle2.Y, rectangle2.Width, rectangle2.Height, "Exit", 46 | os.lockedColor)) 47 | return; 48 | os.display.command = "connect"; 49 | } 50 | 51 | public override string getSaveString() 52 | { 53 | return ""; 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /SpritePlacementData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | 3 | namespace Hacknet 4 | { 5 | public struct SpritePlacementData 6 | { 7 | public Vector2 pos; 8 | public float depth; 9 | public Vector2 scale; 10 | public int spriteIndex; 11 | 12 | public BackgroundObject BackgroundObjectVersion 13 | { 14 | get 15 | { 16 | return new BackgroundObject 17 | { 18 | Alpha = 1f, 19 | Colour = Color.White, 20 | pos = pos, 21 | Rotation = 0.0f, 22 | SpritePath = "", 23 | Texture = null, 24 | VX = 0.0f, 25 | VY = 0.0f, 26 | XScale = scale.X, 27 | YScale = scale.Y, 28 | Z = depth 29 | }; 30 | } 31 | } 32 | 33 | public SpritePlacementData(Vector2 position, Vector2 scales, float layerDepth) 34 | { 35 | pos = position; 36 | scale = scales; 37 | depth = layerDepth; 38 | spriteIndex = 0; 39 | } 40 | 41 | public SpritePlacementData(Vector2 position, Vector2 scales, float layerDepth, int SpriteIndex) 42 | { 43 | pos = position; 44 | scale = scales; 45 | depth = layerDepth; 46 | spriteIndex = SpriteIndex; 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /StatsManager.cs: -------------------------------------------------------------------------------- 1 | using Steamworks; 2 | 3 | namespace Hacknet 4 | { 5 | public static class StatsManager 6 | { 7 | private static readonly bool HasReceivedUserStats = false; 8 | 9 | private static readonly StatData[] StatDefinitions = new StatData[1] 10 | { 11 | new StatData 12 | { 13 | Name = "commands_run" 14 | } 15 | }; 16 | 17 | private static Callback UserStatsCallback; 18 | 19 | public static void InitStats() 20 | { 21 | UserStatsCallback = Callback.Create(OnUserStatsReceived); 22 | } 23 | 24 | private static void OnUserStatsReceived(UserStatsReceived_t pCallback) 25 | { 26 | var num = 0; 27 | while (num < StatDefinitions.Length) 28 | ++num; 29 | } 30 | 31 | public static void IncrementStat(string statName, int valueChange) 32 | { 33 | if (!HasReceivedUserStats) 34 | return; 35 | SteamUserStats.SetStat(statName, valueChange); 36 | } 37 | 38 | public static void SaveStatProgress() 39 | { 40 | if (!HasReceivedUserStats) 41 | return; 42 | SteamUserStats.StoreStats(); 43 | } 44 | 45 | private struct StatData 46 | { 47 | public string Name; 48 | public int IntVal; 49 | public float FloatVal; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /TextureBank.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Xna.Framework.Content; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet 7 | { 8 | public static class TextureBank 9 | { 10 | public static List textures = new List(); 11 | 12 | public static Texture2D load(string filename, ContentManager content) 13 | { 14 | for (var index = 0; index < textures.Count; ++index) 15 | { 16 | if (textures[index].path.Equals(filename)) 17 | { 18 | if (textures[index].tex.IsDisposed) 19 | { 20 | textures.Remove(textures[index]); 21 | } 22 | else 23 | { 24 | var loadedTexture = textures[index]; 25 | ++loadedTexture.retainCount; 26 | textures[index] = loadedTexture; 27 | return loadedTexture.tex; 28 | } 29 | } 30 | } 31 | try 32 | { 33 | var texture2D = content.Load(filename); 34 | textures.Add(new LoadedTexture 35 | { 36 | tex = texture2D, 37 | path = filename, 38 | retainCount = 1 39 | }); 40 | return texture2D; 41 | } 42 | catch (Exception ex) 43 | { 44 | Console.WriteLine(string.Concat("File \"", filename, "\" Experienced an Error in Loading\n", ex)); 45 | return null; 46 | } 47 | } 48 | 49 | public static Texture2D getIfLoaded(string filename) 50 | { 51 | foreach (var loadedTexture in textures) 52 | { 53 | if (loadedTexture.path.Equals(filename)) 54 | { 55 | if (!loadedTexture.tex.IsDisposed) 56 | return loadedTexture.tex; 57 | textures.Remove(loadedTexture); 58 | } 59 | } 60 | return null; 61 | } 62 | 63 | public static void unload(Texture2D tex) 64 | { 65 | unloadWithoutRemoval(tex); 66 | } 67 | 68 | public static void unloadWithoutRemoval(Texture2D tex) 69 | { 70 | for (var index = 0; index < textures.Count; ++index) 71 | { 72 | if (textures[index].tex.Equals(tex)) 73 | { 74 | if (textures[index].tex.IsDisposed) 75 | { 76 | textures.Remove(textures[index]); 77 | } 78 | else 79 | { 80 | var loadedTexture = textures[index]; 81 | --loadedTexture.retainCount; 82 | textures[index] = loadedTexture; 83 | break; 84 | } 85 | } 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /TraceTracker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Audio; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet 7 | { 8 | internal class TraceTracker 9 | { 10 | private static SpriteFont font; 11 | private static SoundEffect beep; 12 | public bool active; 13 | private readonly string drawtext; 14 | private float lastFrameTime; 15 | private readonly OS os; 16 | private float startingTimer; 17 | private Computer target; 18 | public float timeDilation = 1f; 19 | private float timer; 20 | private readonly Color timerColor; 21 | public float timeSinceFreezeRequest; 22 | 23 | public TraceTracker(OS _os) 24 | { 25 | os = _os; 26 | timerColor = new Color(170, 0, 0); 27 | timer = 0.0f; 28 | active = false; 29 | if (font == null) 30 | { 31 | font = os.content.Load("Kremlin"); 32 | font.Spacing = 11f; 33 | beep = os.content.Load("SFX/beep"); 34 | SoundEffect.MasterVolume = 0.2f; 35 | } 36 | drawtext = "TRACE :"; 37 | } 38 | 39 | public void Update(float t) 40 | { 41 | var flag = false; 42 | timeSinceFreezeRequest += t; 43 | if (timeSinceFreezeRequest < 0.0) 44 | timeSinceFreezeRequest = 1f; 45 | if (timeSinceFreezeRequest < 0.200000002980232) 46 | flag = true; 47 | if (!active) 48 | return; 49 | if (os.connectedComp == null || !os.connectedComp.ip.Equals(target.ip)) 50 | { 51 | active = false; 52 | if (timer < 0.5) 53 | AchievementsManager.Unlock("trace_close", false); 54 | } 55 | else if (!flag) 56 | { 57 | timer -= t*timeDilation; 58 | if (timer <= 0.0) 59 | { 60 | timer = 0.0f; 61 | active = false; 62 | os.timerExpired(); 63 | } 64 | } 65 | var num1 = (float) (timer/(double) startingTimer*100.0); 66 | var num2 = num1 < 45.0 ? num1 < 15.0 ? 1f : 5f : 10f; 67 | if (num1%(double) num2 > lastFrameTime%(double) num2) 68 | { 69 | beep.Play(); 70 | os.warningFlash(); 71 | } 72 | lastFrameTime = num1; 73 | } 74 | 75 | public void start(float t) 76 | { 77 | if (active) 78 | return; 79 | startingTimer = t; 80 | timer = t; 81 | active = true; 82 | os.warningFlash(); 83 | target = os.connectedComp == null ? os.thisComputer : os.connectedComp; 84 | Console.WriteLine("Warning flash"); 85 | } 86 | 87 | public void stop() 88 | { 89 | active = false; 90 | } 91 | 92 | public void Draw(SpriteBatch sb) 93 | { 94 | if (!active) 95 | return; 96 | var text = ((float) (timer/(double) startingTimer*100.0)).ToString("00.00"); 97 | var vector2 = font.MeasureString(text); 98 | var position = new Vector2(10f, sb.GraphicsDevice.Viewport.Height - vector2.Y); 99 | sb.DrawString(font, text, position, timerColor); 100 | position.Y -= 25f; 101 | sb.DrawString(font, drawtext, position, timerColor, 0.0f, Vector2.Zero, new Vector2(0.3f), 102 | SpriteEffects.None, 0.5f); 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /UIUtils/AnimatedSpriteExporter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.Xna.Framework; 4 | using Microsoft.Xna.Framework.Graphics; 5 | 6 | namespace Hacknet.UIUtils 7 | { 8 | public static class AnimatedSpriteExporter 9 | { 10 | public static void ExportAnimation(string folderPath, string nameStarter, int width, int height, 11 | float framesPerSecond, float totalTime, GraphicsDevice gd, Action update, 12 | Action draw, int antialiasingMultiplier = 1) 13 | { 14 | var width1 = width*antialiasingMultiplier; 15 | var height1 = height*antialiasingMultiplier; 16 | var renderTarget = new RenderTarget2D(gd, width1, height1, false, SurfaceFormat.Rgba64, DepthFormat.Depth16, 17 | 8, RenderTargetUsage.PlatformContents); 18 | var spriteBatch1 = new SpriteBatch(gd); 19 | gd.PresentationParameters.MultiSampleCount = 8; 20 | var currentRenderTarget = Utils.GetCurrentRenderTarget(); 21 | gd.SetRenderTarget(renderTarget); 22 | var num1 = 1f/framesPerSecond; 23 | var num2 = 0.0f; 24 | var num3 = 0; 25 | if (!Directory.Exists(folderPath)) 26 | Directory.CreateDirectory(folderPath); 27 | var spriteBatch2 = GuiData.spriteBatch; 28 | GuiData.spriteBatch = spriteBatch1; 29 | var rectangle = new Rectangle(0, 0, width1, height1); 30 | while (num2 < (double) totalTime) 31 | { 32 | gd.Clear(Color.Transparent); 33 | spriteBatch1.Begin(); 34 | draw(spriteBatch1, rectangle); 35 | spriteBatch1.End(); 36 | update(num1); 37 | gd.SetRenderTarget(null); 38 | var str = string.Concat(nameStarter, "_", num3, ".png"); 39 | using (var fileStream = File.Create(folderPath + "/" + str)) 40 | renderTarget.SaveAsPng(fileStream, width, height); 41 | gd.SetRenderTarget(renderTarget); 42 | ++num3; 43 | num2 += num1; 44 | } 45 | GuiData.spriteBatch = spriteBatch2; 46 | gd.SetRenderTarget(currentRenderTarget); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /UIUtils/AttractModeMenuScreen.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Hacknet.Effects; 3 | using Hacknet.Gui; 4 | using Microsoft.Xna.Framework; 5 | using Microsoft.Xna.Framework.Graphics; 6 | 7 | namespace Hacknet.UIUtils 8 | { 9 | public class AttractModeMenuScreen 10 | { 11 | public Action Exit; 12 | public Action Start; 13 | 14 | public void Draw(Rectangle dest, SpriteBatch sb) 15 | { 16 | var width1 = (int) (dest.Width*0.5); 17 | var height1 = (int) (dest.Height*0.400000005960464); 18 | var dest1 = new Rectangle(dest.Width/2 - width1/2, (int) (dest.Y + dest.Height/2.5 - height1/2), width1, 19 | height1); 20 | var destinationRectangle1 = new Rectangle(dest.X, dest1.Y + 115, dest.Width, dest1.Height - 245); 21 | sb.Draw(Utils.white, destinationRectangle1, 22 | Color.Lerp(new Color(115, 0, 0), new Color(122, 0, 0), 23 | 0.0f + Utils.randm((float) (1.0 - Utils.randm(1f)*(double) Utils.randm(1f))))); 24 | dest1.Y += 12; 25 | TextItem.doFontLabelToSize(dest1, Utils.FlipRandomChars("HACKNET", 0.028), GuiData.titlefont, 26 | Color.White*0.12f); 27 | FlickeringTextEffect.DrawLinedFlickeringText(dest1, Utils.FlipRandomChars("HACKNET", 0.003), 11f, 0.7f, 28 | GuiData.titlefont, null, Color.White, 5); 29 | var y = destinationRectangle1.Y + dest1.Height - 80; 30 | var width2 = dest.Width/4; 31 | var num1 = 20; 32 | var num2 = (width2 - num1)/2; 33 | var height2 = 42; 34 | var destinationRectangle2 = new Rectangle(dest.X + dest.Width/2 - width2/2, y, width2, height2); 35 | sb.Draw(Utils.white, destinationRectangle2, Color.Black*0.8f); 36 | if ( 37 | !Button.doButton(18273302, destinationRectangle2.X, destinationRectangle2.Y, destinationRectangle2.Width, 38 | destinationRectangle2.Height, "New Session", new Color(124, 137, 149)) || Start == null) 39 | return; 40 | Start(); 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /UIUtils/AudioUtils.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace Hacknet.UIUtils 4 | { 5 | internal class AudioUtils 6 | { 7 | public static void openWav(string filename, out double[] left, out double[] right) 8 | { 9 | var numArray = File.ReadAllBytes(filename); 10 | int num1 = numArray[22]; 11 | int index1; 12 | int index2; 13 | int num2; 14 | for (index1 = 12; 15 | numArray[index1] != 100 || numArray[index1 + 1] != 97 || 16 | (numArray[index1 + 2] != 116 || numArray[index1 + 3] != 97); 17 | index1 = index2 + (4 + num2)) 18 | { 19 | index2 = index1 + 4; 20 | num2 = numArray[index2] + numArray[index2 + 1]*256 + numArray[index2 + 2]*65536 + 21 | numArray[index2 + 3]*16777216; 22 | } 23 | var index3 = index1 + 8; 24 | var length = (numArray.Length - index3)/2; 25 | if (num1 == 2) 26 | length /= 2; 27 | left = new double[length]; 28 | right = num1 != 2 ? null : new double[length]; 29 | var index4 = 0; 30 | while (index3 < numArray.Length) 31 | { 32 | left[index4] = bytesToDouble(numArray[index3], numArray[index3 + 1]); 33 | index3 += 2; 34 | if (num1 == 2) 35 | { 36 | right[index4] = bytesToDouble(numArray[index3], numArray[index3 + 1]); 37 | index3 += 2; 38 | } 39 | ++index4; 40 | } 41 | } 42 | 43 | private static double bytesToDouble(byte firstByte, byte secondByte) 44 | { 45 | return (short) (secondByte << 8 | firstByte)/32768.0; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /UIUtils/CLinkBuffer`1.cs: -------------------------------------------------------------------------------- 1 | // Decompiled with JetBrains decompiler 2 | // Type: Hacknet.UIUtils.CLinkBuffer`1 3 | // Assembly: Hacknet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null 4 | // MVID: 48C62A5D-184B-4610-A7EA-84B38D090891 5 | // Assembly location: C:\Program Files (x86)\Steam\SteamApps\common\Hacknet\Hacknet.exe 6 | 7 | namespace Hacknet.UIUtils 8 | { 9 | public class CLinkBuffer 10 | { 11 | private int currentIndex; 12 | private readonly T[] data; 13 | 14 | public CLinkBuffer(int BufferSize = 128) 15 | { 16 | data = new T[BufferSize]; 17 | } 18 | 19 | public T Get(int offset) 20 | { 21 | var index = currentIndex + offset; 22 | while (index < 0) 23 | index += data.Length; 24 | while (index >= data.Length) 25 | index -= data.Length; 26 | return data[index]; 27 | } 28 | 29 | public void Add(T added) 30 | { 31 | currentIndex = NextIndex(); 32 | data[currentIndex] = added; 33 | } 34 | 35 | public void AddOneAhead(T added) 36 | { 37 | data[NextIndex()] = added; 38 | } 39 | 40 | private int NextIndex() 41 | { 42 | var num = currentIndex + 1; 43 | if (num >= data.Length) 44 | num = 0; 45 | return num; 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /UIUtils/FancyOutlines.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Xna.Framework; 2 | using Microsoft.Xna.Framework.Graphics; 3 | 4 | namespace Hacknet.UIUtils 5 | { 6 | public static class FancyOutlines 7 | { 8 | public static void DrawCornerCutOutline(Rectangle bounds, SpriteBatch sb, float cornerCut, Color col) 9 | { 10 | var vector2_1 = new Vector2(bounds.X, bounds.Y + cornerCut); 11 | var vector2_2 = new Vector2(bounds.X + cornerCut, bounds.Y); 12 | Utils.drawLine(sb, vector2_1, vector2_2, Vector2.Zero, col, 0.6f); 13 | vector2_1 = new Vector2(bounds.X + bounds.Width - cornerCut, bounds.Y); 14 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 15 | vector2_2 = new Vector2(bounds.X + bounds.Width, bounds.Y + cornerCut); 16 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 17 | vector2_1 = new Vector2(bounds.X + bounds.Width, bounds.Y + bounds.Height - cornerCut); 18 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 19 | vector2_2 = new Vector2(bounds.X + bounds.Width - cornerCut, bounds.Y + bounds.Height); 20 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 21 | vector2_1 = new Vector2(bounds.X + cornerCut, bounds.Y + bounds.Height); 22 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 23 | vector2_2 = new Vector2(bounds.X, bounds.Y + bounds.Height - cornerCut); 24 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 25 | vector2_1 = new Vector2(bounds.X, bounds.Y + cornerCut); 26 | Utils.drawLine(sb, vector2_2, vector2_1, Vector2.Zero, col, 0.6f); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /UIUtils/LCG.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet.UIUtils 5 | { 6 | public class LCG 7 | { 8 | private int _state; 9 | 10 | public LCG(bool microsoft = true) 11 | { 12 | _state = (int) DateTime.Now.Ticks; 13 | Microsoft = microsoft; 14 | } 15 | 16 | public LCG(int n, bool microsoft = true) 17 | { 18 | _state = n; 19 | Microsoft = microsoft; 20 | } 21 | 22 | public bool Microsoft { get; set; } 23 | 24 | public bool BSD 25 | { 26 | get { return !Microsoft; } 27 | set { Microsoft = !value; } 28 | } 29 | 30 | public void reSeed(int seed) 31 | { 32 | _state = seed; 33 | } 34 | 35 | public int Next() 36 | { 37 | if (BSD) 38 | return _state = 1103515245*_state + 12345 & int.MaxValue; 39 | return ((_state = 214013*_state + 2531011) & int.MaxValue) >> 16; 40 | } 41 | 42 | public float NextFloat() 43 | { 44 | return Next()/(float) int.MaxValue; 45 | } 46 | 47 | public bool Flip() 48 | { 49 | if (BSD) 50 | return (_state = 1103515245*_state + 12345 & int.MaxValue) > 1073741823; 51 | return ((_state = 214013*_state + 2531011) & int.MaxValue) >> 16 > 1073741823; 52 | } 53 | 54 | public IEnumerable Seq() 55 | { 56 | while (true) 57 | yield return Next(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /UIUtils/WaveformRenderer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.Xna.Framework; 3 | using Microsoft.Xna.Framework.Graphics; 4 | 5 | namespace Hacknet.UIUtils 6 | { 7 | internal class WaveformRenderer 8 | { 9 | private readonly double[] left; 10 | private readonly double[] right; 11 | private int SecondBlockSize = 100; 12 | 13 | public WaveformRenderer(string filename) 14 | { 15 | AudioUtils.openWav(filename, out left, out right); 16 | } 17 | 18 | public void RenderWaveform(double time, double totalTime, SpriteBatch sb, Rectangle bounds) 19 | { 20 | time %= totalTime; 21 | SecondBlockSize = (int) (left.Length/totalTime); 22 | var num1 = SecondBlockSize/100; 23 | var num2 = (int) (time*SecondBlockSize); 24 | var num3 = Math.Min(left.Length - 1, num2 + num1) - num2; 25 | var num4 = bounds.Width/(double) num3; 26 | var num5 = 0; 27 | for (var index = 0; index < num3; ++index) 28 | { 29 | var num6 = left[num2 + index]; 30 | if (num6 == 0.0) 31 | ++num5; 32 | if (num5 == 20) 33 | Console.WriteLine("Zeroed at " + time); 34 | var num7 = num6*bounds.Height; 35 | var destinationRectangle = new Rectangle((int) (bounds.X + index*num4), 36 | bounds.Y + bounds.Height/2 - (int) (num7/2.0), (int) num4, (int) num7); 37 | sb.Draw(Utils.white, destinationRectangle, Color.White*0.4f); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /UserDetail.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | 3 | namespace Hacknet 4 | { 5 | public struct UserDetail 6 | { 7 | public string name; 8 | public string pass; 9 | public byte type; 10 | public bool known; 11 | 12 | public UserDetail(string user, string password, byte accountType) 13 | { 14 | name = user; 15 | pass = password; 16 | type = accountType; 17 | known = false; 18 | } 19 | 20 | public UserDetail(string user) 21 | { 22 | name = user; 23 | pass = PortExploits.getRandomPassword(); 24 | type = 1; 25 | known = false; 26 | } 27 | 28 | public string getSaveString() 29 | { 30 | return ""; 32 | } 33 | 34 | public static UserDetail loadUserDetail(XmlReader reader) 35 | { 36 | reader.MoveToAttribute("name"); 37 | var user = reader.ReadContentAsString(); 38 | reader.MoveToAttribute("pass"); 39 | var password = reader.ReadContentAsString(); 40 | reader.MoveToAttribute("type"); 41 | var accountType = (byte) reader.ReadContentAsInt(); 42 | reader.MoveToAttribute("known"); 43 | var flag = reader.ReadContentAsString().ToLower().Equals("true"); 44 | return new UserDetail(user, password, accountType) 45 | { 46 | known = flag 47 | }; 48 | } 49 | 50 | public override bool Equals(object obj) 51 | { 52 | var nullable = obj as UserDetail?; 53 | if (nullable.HasValue && name == nullable.Value.name && 54 | (pass == nullable.Value.pass && type == nullable.Value.type)) 55 | return known == nullable.Value.known; 56 | return false; 57 | } 58 | 59 | public override int GetHashCode() 60 | { 61 | return base.GetHashCode(); 62 | } 63 | } 64 | } -------------------------------------------------------------------------------- /UsernameGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using Microsoft.Xna.Framework; 4 | 5 | namespace Hacknet 6 | { 7 | public static class UsernameGenerator 8 | { 9 | private static readonly string[] delims = new string[1] 10 | { 11 | "\r\n\r\n" 12 | }; 13 | 14 | public static string[] names; 15 | private static int nameIndex; 16 | 17 | public static void init() 18 | { 19 | var streamReader = new StreamReader(TitleContainer.OpenStream("Content/Usernames.txt")); 20 | var str = streamReader.ReadToEnd(); 21 | streamReader.Close(); 22 | names = str.Split(delims, StringSplitOptions.RemoveEmptyEntries); 23 | nameIndex = (int) (Utils.random.NextDouble()*(names.Length - 1)); 24 | } 25 | 26 | public static string getName() 27 | { 28 | nameIndex = (nameIndex + 1)%(names.Length - 1); 29 | return names[nameIndex]; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /VehicleInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Text; 3 | 4 | namespace Hacknet 5 | { 6 | public static class VehicleInfo 7 | { 8 | public static List vehicleTypes; 9 | 10 | public static void init() 11 | { 12 | var strArray1 = Utils.readEntireFile("Content/files/VehicleTypes.txt").Split(Utils.newlineDelim); 13 | var chArray = new char[1] 14 | { 15 | '#' 16 | }; 17 | vehicleTypes = new List(strArray1.Length); 18 | for (var index = 0; index < strArray1.Length; ++index) 19 | { 20 | var strArray2 = strArray1[index].Split(chArray); 21 | vehicleTypes.Add(new VehicleType(strArray2[0], strArray2[1])); 22 | } 23 | } 24 | 25 | public static VehicleRegistration getRandomRegistration() 26 | { 27 | var index1 = Utils.random.Next(vehicleTypes.Count); 28 | var vehicleType = vehicleTypes[index1]; 29 | var plate = (Utils.getRandomLetter() + Utils.getRandomLetter() + Utils.getRandomLetter()).ToString() + 30 | "-" + Utils.getRandomLetter() + Utils.getRandomLetter() + Utils.getRandomLetter(); 31 | var stringBuilder = new StringBuilder(); 32 | var num1 = 12; 33 | var num2 = 4; 34 | for (var index2 = 0; index2 < num1; ++index2) 35 | { 36 | if (index2%num2 == 0 && index2 > 0) 37 | stringBuilder.Append('-'); 38 | else 39 | stringBuilder.Append(Utils.getRandomChar()); 40 | } 41 | var regNumber = stringBuilder.ToString(); 42 | return new VehicleRegistration(vehicleType, plate, regNumber); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /VehicleRegistration.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct VehicleRegistration 4 | { 5 | public VehicleType vehicle; 6 | public string licencePlate; 7 | public string licenceNumber; 8 | 9 | public VehicleRegistration(VehicleType vehicleType, string plate, string regNumber) 10 | { 11 | vehicle = vehicleType; 12 | licencePlate = plate; 13 | licenceNumber = regNumber; 14 | } 15 | 16 | public new string ToString() 17 | { 18 | return vehicle.maker + " " + vehicle.model + " | Plate: " + licencePlate + " Licence: " + licenceNumber; 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /VehicleType.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct VehicleType 4 | { 5 | public string model; 6 | public string maker; 7 | 8 | public VehicleType(string vModel, string vMaker) 9 | { 10 | model = vModel; 11 | maker = vMaker; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /WorldLocation.cs: -------------------------------------------------------------------------------- 1 | namespace Hacknet 2 | { 3 | public struct WorldLocation 4 | { 5 | public string country; 6 | public string name; 7 | public float educationLevel; 8 | public float lifeLevel; 9 | public float employerLevel; 10 | public float affordabilityLevel; 11 | 12 | public WorldLocation(string countryName, string locName, float education, float life, float employer, 13 | float affordability) 14 | { 15 | country = countryName; 16 | name = locName; 17 | educationLevel = education; 18 | lifeLevel = life; 19 | employerLevel = employer; 20 | affordabilityLevel = affordability; 21 | } 22 | 23 | public new string ToString() 24 | { 25 | return name + ", " + country; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /WorldLocationLoader.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Hacknet 5 | { 6 | public static class WorldLocationLoader 7 | { 8 | public static List locations; 9 | 10 | public static void init() 11 | { 12 | var strArray1 = Utils.readEntireFile("Content/PersonData/LocationData.txt").Split(Utils.newlineDelim); 13 | var chArray = new char[1] 14 | { 15 | '#' 16 | }; 17 | locations = new List(strArray1.Length); 18 | for (var index = 0; index < strArray1.Length; ++index) 19 | { 20 | var strArray2 = strArray1[index].Split(chArray); 21 | locations.Add(new WorldLocation(strArray2[1], strArray2[0], (float) Convert.ToDouble(strArray2[2]), 22 | (float) Convert.ToDouble(strArray2[3]), (float) Convert.ToDouble(strArray2[4]), 23 | (float) Convert.ToDouble(strArray2[5]))); 24 | } 25 | } 26 | 27 | public static WorldLocation getRandomLocation() 28 | { 29 | return locations[Utils.random.Next(locations.Count)]; 30 | } 31 | 32 | public static WorldLocation getClosestOrCreate(string name) 33 | { 34 | for (var index = 0; index < locations.Count; ++index) 35 | { 36 | if (locations[index].name.ToLower().Equals(name.ToLower())) 37 | return locations[index]; 38 | } 39 | var worldLocation = new WorldLocation(name, name, (float) Utils.random.NextDouble(), 40 | (float) Utils.random.NextDouble(), (float) Utils.random.NextDouble(), (float) Utils.random.NextDouble()); 41 | locations.Add(worldLocation); 42 | return worldLocation; 43 | } 44 | } 45 | } --------------------------------------------------------------------------------