protected virtual void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing)
         {
             if (this.starfield != null)
                 this.starfield.Dispose();
             if (this.DeepSpaceDone != null)
                 this.DeepSpaceDone.Dispose();
             if (this.EmpireDone != null)
                 this.EmpireDone.Dispose();
             if (this.DeepSpaceGateKeeper != null)
                 this.DeepSpaceGateKeeper.Dispose();
             if (this.ItemsToBuild != null)
                 this.ItemsToBuild.Dispose();
             if (this.WorkerBeginEvent != null)
                 this.WorkerBeginEvent.Dispose();
             if (this.WorkerCompletedEvent != null)
                 this.WorkerCompletedEvent.Dispose();
             if (this.anomalyManager != null)
                 this.anomalyManager.Dispose();
             if (this.bloomComponent != null)
                 this.bloomComponent.Dispose();
             if (this.ShipGateKeeper != null)
                 this.ShipGateKeeper.Dispose();
             if (this.SystemThreadGateKeeper != null)
                 this.SystemThreadGateKeeper.Dispose();
             if (this.FogMap != null)
                 this.FogMap.Dispose();
             if (this.MasterShipList != null)
                 this.MasterShipList.Dispose();
             if (this.EmpireGateKeeper != null)
                 this.EmpireGateKeeper.Dispose();
             if (this.BombList != null)
                 this.BombList.Dispose();
             if (this.flash != null)
                 this.flash.Dispose();
             if (this.lightning != null)
                 this.lightning.Dispose();
             if (this.neb_particles != null)
                 this.neb_particles.Dispose();
             if (this.photonExplosionParticles != null)
                 this.photonExplosionParticles.Dispose();
             if (this.projectileTrailParticles != null)
                 this.projectileTrailParticles.Dispose();
             if (this.sceneMap != null)
                 this.sceneMap.Dispose();
             if (this.shipListInfoUI != null)
                 this.shipListInfoUI.Dispose();
             if (this.smokePlumeParticles != null)
                 this.smokePlumeParticles.Dispose();
             if (this.sparks != null)
                 this.sparks.Dispose();
             if (this.star_particles != null)
                 this.star_particles.Dispose();
             if (this.engineTrailParticles != null)
                 this.engineTrailParticles.Dispose();
             if (this.explosionParticles != null)
                 this.explosionParticles.Dispose();
             if (this.explosionSmokeParticles != null)
                 this.explosionSmokeParticles.Dispose();
             if (this.fireTrailParticles != null)
                 this.fireTrailParticles.Dispose();
             if (this.fireParticles != null)
                 this.fireParticles.Dispose();
             if (this.flameParticles != null)
                 this.flameParticles.Dispose();
             if (this.beamflashes != null)
                 this.beamflashes.Dispose();
             if (this.dsbw != null)
                 this.dsbw.Dispose();
             if (this.SelectedShipList != null)
                 this.SelectedShipList.Dispose();
             if (this.NotificationManager != null)
                 this.NotificationManager.Dispose();
             if (this.FogMapTarget != null)
                 this.FogMapTarget.Dispose();
         }
         this.starfield = null;
         this.DeepSpaceDone = null;
         this.EmpireDone = null;
         this.DeepSpaceGateKeeper = null;
         this.ItemsToBuild = null;
         this.WorkerBeginEvent = null;
         this.WorkerCompletedEvent = null;
         this.anomalyManager = null;
         this.bloomComponent = null;
         this.ShipGateKeeper = null;
         this.SystemThreadGateKeeper = null;
         this.FogMap = null;
         this.MasterShipList = null;
         this.EmpireGateKeeper = null;
         this.BombList = null;
         this.flash = null;
         this.lightning = null;
         this.neb_particles = null;
         this.photonExplosionParticles = null;
         this.projectileTrailParticles = null;
         this.sceneMap = null;
         this.shipListInfoUI = null;
         this.smokePlumeParticles = null;
         this.sparks = null;
         this.star_particles = null;
         this.engineTrailParticles = null;
         this.explosionParticles = null;
         this.explosionSmokeParticles = null;
         this.fireTrailParticles = null;
         this.fireParticles = null;
         this.flameParticles = null;
         this.beamflashes = null;
         this.dsbw = null;
         this.SelectedShipList = null;
         this.NotificationManager = null;
         this.FogMapTarget = null;
     }
 }
        public override void LoadContent()
        {
            GlobalStats.ResearchRootUIDToDisplay = "Colonization";
            SystemInfoUIElement.SysFont = Fonts.Arial12Bold;
            SystemInfoUIElement.DataFont = Fonts.Arial10;
            this.NotificationManager = new NotificationManager(this.ScreenManager, this);
            this.aw = new AutomationWindow(this.ScreenManager, this);
            for (int index = 0; (double)index < (double)this.Size.X / 5000.0; ++index)
            {
                NebulousOverlay nebulousOverlay = new NebulousOverlay();
                float z = RandomMath.RandomBetween(-200000f, -2E+07f);
                nebulousOverlay.Path = "Textures/smoke";
                nebulousOverlay.Position = new Vector3(RandomMath.RandomBetween(-0.5f * this.Size.X, this.Size.X + 0.5f * this.Size.X), RandomMath.RandomBetween(-0.5f * this.Size.X, this.Size.X + 0.5f * this.Size.X), z);
                float radians = RandomMath.RandomBetween(0.0f, 6.283185f);
                nebulousOverlay.Scale = RandomMath.RandomBetween(10f, 100f);
                nebulousOverlay.WorldMatrix = Matrix.CreateScale(50f) * Matrix.CreateScale(nebulousOverlay.Scale) * Matrix.CreateRotationZ(radians) * Matrix.CreateTranslation(nebulousOverlay.Position);
                this.Stars.Add(nebulousOverlay);
            }
            this.LoadGraphics();
            UniverseScreen.DeepSpaceManager.Setup((int)this.Size.X, (int)this.Size.Y, (int)(500000.0 * (double)this.GameScale), new Vector2(this.Size.X / 2f, this.Size.Y / 2f));
            UniverseScreen.ShipSpatialManager.Setup((int)this.Size.X, (int)this.Size.Y, (int)(500000.0 * (double)this.GameScale), new Vector2(this.Size.X / 2f, this.Size.Y / 2f));
            this.DoParticleLoad();
            this.bg3d = new Background3D(this);
            this.starfield = new Starfield(Vector2.Zero, this.ScreenManager.GraphicsDevice, this.ScreenManager.Content);
            this.starfield.LoadContent();
            GameplayObject.audioListener = this.listener;
            Weapon.audioListener = this.listener;
            GameplayObject.audioListener = this.listener;
            this.projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f, (float)this.ScreenManager.GraphicsDevice.Viewport.Width / (float)this.ScreenManager.GraphicsDevice.Viewport.Height, 1000f, 3E+07f);
            this.SetLighting(this.UseRealLights);
            foreach (SolarSystem solarSystem in UniverseScreen.SolarSystemList)
            {
                foreach (string FleetUID in solarSystem.DefensiveFleets)
                {
                    Fleet defensiveFleetAt = HelperFunctions.CreateDefensiveFleetAt(FleetUID, EmpireManager.GetEmpireByName("The Remnant"), solarSystem.PlanetList[0].Position);
                    MilitaryTask militaryTask = new MilitaryTask();
                    militaryTask.AO = solarSystem.PlanetList[0].Position;
                    militaryTask.AORadius = 120000f;
                    militaryTask.type = MilitaryTask.TaskType.DefendSystem;
                    defensiveFleetAt.Task = militaryTask;
                    defensiveFleetAt.TaskStep = 3;
                    militaryTask.WhichFleet = EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10;
                    EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().TryAdd(EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10, defensiveFleetAt);
                    EmpireManager.GetEmpireByName("The Remnant").GetGSAI().TaskList.Add(militaryTask);
                    militaryTask.Step = 2;
                }
                if (GlobalStats.ActiveModInfo != null && GlobalStats.ActiveModInfo.customRemnantElements)
                {
                    foreach (Planet p in solarSystem.PlanetList)
                    {
                        foreach (string FleetUID in p.PlanetFleets)
                        {
                            Fleet planetFleetAt = HelperFunctions.CreateDefensiveFleetAt(FleetUID, EmpireManager.GetEmpireByName("The Remnant"), p.Position);
                            MilitaryTask militaryTask = new MilitaryTask();
                            militaryTask.AO = solarSystem.PlanetList[0].Position;
                            militaryTask.AORadius = 120000f;
                            militaryTask.type = MilitaryTask.TaskType.DefendSystem;
                            planetFleetAt.Task = militaryTask;
                            planetFleetAt.TaskStep = 3;
                            militaryTask.WhichFleet = EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10;
                            EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().TryAdd(EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10, planetFleetAt);
                            EmpireManager.GetEmpireByName("The Remnant").GetGSAI().TaskList.Add(militaryTask);
                            militaryTask.Step = 2;
                        }
                    }
                }

                foreach (SolarSystem.FleetAndPos fleetAndPos in solarSystem.FleetsToSpawn)
                {
                    Fleet defensiveFleetAt = HelperFunctions.CreateDefensiveFleetAt(fleetAndPos.fleetname, EmpireManager.GetEmpireByName("The Remnant"), solarSystem.Position + fleetAndPos.Pos);
                    MilitaryTask militaryTask = new MilitaryTask();
                    militaryTask.AO = solarSystem.Position + fleetAndPos.Pos;
                    militaryTask.AORadius = 75000f;
                    militaryTask.type = MilitaryTask.TaskType.DefendSystem;
                    defensiveFleetAt.Task = militaryTask;
                    defensiveFleetAt.TaskStep = 3;
                    militaryTask.WhichFleet = EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10;
                    EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().TryAdd(EmpireManager.GetEmpireByName("The Remnant").GetFleetsDict().Count + 10, defensiveFleetAt);
                    EmpireManager.GetEmpireByName("The Remnant").GetGSAI().TaskList.Add(militaryTask);
                    militaryTask.Step = 2;
                }
                foreach (string key in solarSystem.ShipsToSpawn)
                    ResourceManager.CreateShipAt(key, EmpireManager.GetEmpireByName("The Remnant"), solarSystem.PlanetList[0], true);
                foreach (Planet p in solarSystem.PlanetList)
                {
                    if (p.Owner != null)
                    {
                        foreach (string key in p.Guardians)
                            ResourceManager.CreateShipAt(key, p.Owner, p, true);
                    }
                    else
                    {
                        //Added by McShooterz: alternate hostile fleets populate universe
                        if (GlobalStats.ActiveModInfo != null && ResourceManager.HostileFleets.Fleets.Count > 0)
                        {
                            if (p.Guardians.Count > 0)
                            {
                                int randomFleet = HelperFunctions.GetRandomIndex(ResourceManager.HostileFleets.Fleets.Count);
                                foreach (string ship in ResourceManager.HostileFleets.Fleets[randomFleet].Ships)
                                {
                                    ResourceManager.CreateShipAt(ship, EmpireManager.GetEmpireByName(ResourceManager.HostileFleets.Fleets[randomFleet].Empire), p, true);
                                }
                            }
                        }
                        else
                        {
                            foreach (string key in p.Guardians)
                                ResourceManager.CreateShipAt(key, EmpireManager.GetEmpireByName("The Remnant"), p, true);
                            if (p.CorsairPresence)
                            {
                                ResourceManager.CreateShipAt("Corsair Asteroid Base", EmpireManager.GetEmpireByName("Corsairs"), p, true).TetherToPlanet(p);
                                ResourceManager.CreateShipAt("Corsair", EmpireManager.GetEmpireByName("Corsairs"), p, true);
                                ResourceManager.CreateShipAt("Captured Gunship", EmpireManager.GetEmpireByName("Corsairs"), p, true);
                                ResourceManager.CreateShipAt("Captured Gunship", EmpireManager.GetEmpireByName("Corsairs"), p, true);
                            }
                        }
                    }
                }
                foreach (Anomaly anomaly in solarSystem.AnomaliesList)
                {
                    if (anomaly.type == "DP")
                        this.anomalyManager.AnomaliesList.Add((Anomaly)new DimensionalPrison(solarSystem.Position + anomaly.Position));
                }
            }
            float num = 10f;
            Matrix matrix = this.view;
            this.MaxCamHeight = 4E+07f;
            while ((double)num < (double)(this.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth + 50))
            {
                Vector2 vector2_1 = new Vector2(this.Size.X / 2f, this.Size.Y / 2f);
                Matrix view = Matrix.CreateTranslation(0.0f, 0.0f, 0.0f) * Matrix.CreateRotationY(MathHelper.ToRadians(180f)) * Matrix.CreateRotationX(MathHelper.ToRadians(0.0f)) * Matrix.CreateLookAt(new Vector3(-vector2_1.X, vector2_1.Y, this.MaxCamHeight), new Vector3(-vector2_1.X, vector2_1.Y, 0.0f), new Vector3(0.0f, -1f, 0.0f));
                Vector3 vector3_1 = this.ScreenManager.GraphicsDevice.Viewport.Project(Vector3.Zero, this.projection, view, Matrix.Identity);
                Vector2 vector2_2 = new Vector2(vector3_1.X, vector3_1.Y);
                Vector3 vector3_2 = this.ScreenManager.GraphicsDevice.Viewport.Project(new Vector3(this.Size, 0.0f), this.projection, view, Matrix.Identity);
                num = new Vector2(vector3_2.X, vector3_2.Y).X - vector2_2.X;
                if ((double)num < (double)(this.ScreenManager.GraphicsDevice.PresentationParameters.BackBufferWidth + 50))
                    this.MaxCamHeight -= 0.1f * this.MaxCamHeight;
            }
            if (MaxCamHeight > 23000000) MaxCamHeight = 23000000;
            if (!this.loading)
            {
                this.camPos.X = this.playerShip.Center.X;
                this.camPos.Y = this.playerShip.Center.Y;
                this.camHeight = 2750f;
            }
            this.transitionDestination = new Vector3(this.camPos.X, this.camPos.Y, this.camHeight);
            foreach (NebulousOverlay nebulousOverlay in this.Stars)
                this.star_particles.AddParticleThreadA(nebulousOverlay.Position, Vector3.Zero);
            if (this.MultiThread)
            {
                this.WorkerThread = new Thread(new ThreadStart(this.Worker));
                this.WorkerThread.IsBackground = true;
                this.WorkerThread.Start();
                //this.ShipUpdateThread = new Thread(new ThreadStart(this.ShipUpdater));
                //this.ShipUpdateThread.IsBackground = true;
            #if !ALTERTHREAD
                this.SystemResetEvents = new ManualResetEvent[4];
                this.SystemGateKeeper = new AutoResetEvent[4];
                List<SolarSystem> list1 = new List<SolarSystem>();
                List<SolarSystem> list2 = new List<SolarSystem>();
                List<SolarSystem> list3 = new List<SolarSystem>();
                List<SolarSystem> list4 = new List<SolarSystem>();
                Rectangle rect1 = new Rectangle(0, 0, (int)this.Size.X / 2, (int)this.Size.Y / 2);
                Rectangle rect2 = new Rectangle((int)this.Size.X / 2, 0, (int)this.Size.X / 2, (int)this.Size.Y / 2);
                Rectangle rect3 = new Rectangle(0, (int)this.Size.Y / 2, (int)this.Size.X / 2, (int)this.Size.Y / 2);
                Rectangle rect4 = new Rectangle((int)this.Size.X / 2, (int)this.Size.Y / 2, (int)this.Size.X / 2, (int)this.Size.Y / 2);
                this.SystemResetEvents[0] = new ManualResetEvent(false);
                this.SystemGateKeeper[0] = new AutoResetEvent(false);
                this.SystemResetEvents[1] = new ManualResetEvent(false);
                this.SystemGateKeeper[1] = new AutoResetEvent(false);
                this.SystemResetEvents[2] = new ManualResetEvent(false);
                this.SystemGateKeeper[2] = new AutoResetEvent(false);
                this.SystemResetEvents[3] = new ManualResetEvent(false);
                this.SystemGateKeeper[3] = new AutoResetEvent(false);
                for (int index = 0; index < UniverseScreen.SolarSystemList.Count; ++index)
                {
                    if (HelperFunctions.CheckIntersection(rect1, UniverseScreen.SolarSystemList[index].Position))
                    {
                        UniverseScreen.SolarSystemList[index].IndexOfResetEvent = 0;
                        list1.Add(UniverseScreen.SolarSystemList[index]);
                    }
                    if (HelperFunctions.CheckIntersection(rect2, UniverseScreen.SolarSystemList[index].Position))
                    {
                        UniverseScreen.SolarSystemList[index].IndexOfResetEvent = 1;
                        list2.Add(UniverseScreen.SolarSystemList[index]);
                    }
                    if (HelperFunctions.CheckIntersection(rect3, UniverseScreen.SolarSystemList[index].Position))
                    {
                        UniverseScreen.SolarSystemList[index].IndexOfResetEvent = 2;
                        list3.Add(UniverseScreen.SolarSystemList[index]);
                    }
                    if (HelperFunctions.CheckIntersection(rect4, UniverseScreen.SolarSystemList[index].Position))
                    {
                        UniverseScreen.SolarSystemList[index].IndexOfResetEvent = 3;
                        list4.Add(UniverseScreen.SolarSystemList[index]);
                    }
                }
                Thread thread1 = new Thread(new ParameterizedThreadStart(this.SystemUpdater));
                this.SystemUpdateThreadList.Add(thread1);
                thread1.Start((object)list1);
                thread1.IsBackground = true;
                Thread thread2 = new Thread(new ParameterizedThreadStart(this.SystemUpdater));
                this.SystemUpdateThreadList.Add(thread2);
                thread2.Start((object)list2);
                thread2.IsBackground = true;
                Thread thread3 = new Thread(new ParameterizedThreadStart(this.SystemUpdater));
                this.SystemUpdateThreadList.Add(thread3);
                thread3.Start((object)list3);
                thread3.IsBackground = true;
                Thread thread4 = new Thread(new ParameterizedThreadStart(this.SystemUpdater));
                this.SystemUpdateThreadList.Add(thread4);
                thread4.Start((object)list4);
                thread4.IsBackground = true;
            #endif
                //Thread thread5 = new Thread(new ThreadStart(this.DeepSpaceThread));
               // this.SystemUpdateThreadList.Add(thread5);
               // thread5.Start();
               // thread5.IsBackground = true;
                //Thread thread6 = new Thread(new ThreadStart(this.EmpireThread));
                //this.SystemUpdateThreadList.Add(thread6);
                //thread6.Start();
                //thread6.IsBackground = true;

            }
            this.PlanetsDict.Clear();
            this.SolarSystemDict.Clear();
            foreach (SolarSystem solarSystem in UniverseScreen.SolarSystemList)
            {
                this.SolarSystemDict.Add(solarSystem.guid, solarSystem);
                foreach (Planet planet in solarSystem.PlanetList)
                    this.PlanetsDict.Add(planet.guid, planet);
            }
            foreach (Ship ship in (List<Ship>)this.MasterShipList)
            {
                if (ship.TetherGuid != Guid.Empty)
                    ship.TetherToPlanet(this.PlanetsDict[ship.TetherGuid]);
            }
        }