private IEnumerator RunAsync() { IPlayerControllerRepositoryService playerControllerRepositoryService = base.GameServer.Game.GetService <IPlayerControllerRepositoryService>(); if (playerControllerRepositoryService != null) { for (int index = 0; index < base.GameServer.Game.Empires.Length; index++) { PlayerController playerController = new PlayerController(base.GameServer) { Empire = base.GameServer.Game.Empires[index], PlayerID = base.GameServer.Game.Empires[index].PlayerID }; playerControllerRepositoryService.Register(playerController); base.GameServer.Game.Empires[index].PlayerControllers.Server = playerController; } } if (playerControllerRepositoryService != null) { PlayerController playerController2 = new PlayerController(base.GameServer) { PlayerID = "server" }; playerControllerRepositoryService.Register(playerController2); } base.GameServer.BindMajorEmpires(); Diagnostics.Assert(base.GameServer != null); Diagnostics.Assert(base.GameServer.Session != null); switch (base.GameServer.Session.SessionMode) { case SessionMode.Private: case SessionMode.Protected: case SessionMode.Public: { IGameSerializationService gameSerializationService = Services.GetService <IGameSerializationService>(); if (gameSerializationService != null && gameSerializationService.GameSaveDescriptor == null) { Diagnostics.Log("Performing a quick save for the clients to download..."); string title = "%QuickSaveFileName"; string outputFileName = System.IO.Path.Combine(Amplitude.Unity.Framework.Application.TempDirectory, "Quicksave.sav"); yield return(gameSerializationService.SaveGameAsync(title, outputFileName, GameSaveOptions.QuickSave)); } yield return(this.SynchronizeOnClientConnections()); break; } } while (!base.VerifyGameClientStateSynchronization <GameClientState_GameLaunchedAndReady>()) { base.RespondToDownloadGameRequests(); yield return(null); } yield break; }
private IEnumerator ListGamesAsync(int listingNumber) { this.LoadSaveContainer.DestroyAllChildren(); IGameSerializationService service = Services.GetService <IGameSerializationService>(); if (service != null) { List <GameSaveDescriptor> gameSaveDescriptors = new List <GameSaveDescriptor>(); this.LoadSaveContainer.Height = 0f; IEnumerable <GameSaveDescriptor> listOfGameSaveDescritors = service.GetListOfGameSaveDescritors(!this.SaveMode); foreach (GameSaveDescriptor gameSaveDescriptor in listOfGameSaveDescritors) { gameSaveDescriptors.Add(gameSaveDescriptor); this.LoadSaveContainer.ReserveChildren(gameSaveDescriptors.Count, this.SaveLineSlotPrefab, "Item"); this.LoadSaveContainer.ArrangeChildren(); this.LoadSaveScrollView.OnPositionRecomputed(); int index = gameSaveDescriptors.Count - 1; AgeTransform ageTransform = this.LoadSaveContainer.GetChildren()[index]; this.SetupSaveLineSlot(ageTransform, index, gameSaveDescriptor); if (!Amplitude.Unity.Framework.Application.Preferences.EnableMultiplayer && gameSaveDescriptor.GameSaveSessionDescriptor.SessionMode != SessionMode.Single) { ageTransform.Enable = false; } else { SaveLineSlot component = ageTransform.GetComponent <SaveLineSlot>(); Diagnostics.Assert(component != null); if (component.GameSaveRuntimeConfigurationState == RuntimeModuleConfigurationState.Undefined) { ageTransform.Enable = false; } } yield return(null); if (this.ListingNumber > listingNumber) { yield break; } } IEnumerator <GameSaveDescriptor> enumerator = null; if (this.SortsContainer.SortButtons.Last <SortButton>() != null) { this.SortsContainer.SortButtons.Last <SortButton>().OnSortCB(null); this.SortsContainer.SortButtons.Last <SortButton>().OnSortCB(null); } gameSaveDescriptors = null; } this.listing = null; yield break; yield break; }
private IEnumerator SaveGameAsync(string title, string outputFileName) { IGameSerializationService gameSerializationService = Services.GetService <IGameSerializationService>(); if (gameSerializationService != null) { ISessionService sessionService = Services.GetService <ISessionService>(); Diagnostics.Assert(sessionService != null); global::Session session = sessionService.Session as global::Session; switch (session.SessionMode) { case SessionMode.Single: yield return(gameSerializationService.SaveGameAsync(title, outputFileName, GameSaveOptions.None)); break; case SessionMode.Private: case SessionMode.Protected: case SessionMode.Public: if (session.GameServer != null) { yield return(gameSerializationService.SaveGameAsync(title, outputFileName, GameSaveOptions.None)); } else { Message downloadGameMessage = new GameClientDownloadGameMessage(SaveType.OnUserRequest, title); session.GameClient.SendMessageToServer(ref downloadGameMessage); } break; default: throw new ArgumentOutOfRangeException(); } this.Hide(true); global::IGuiService guiService = Services.GetService <global::IGuiService>(); Amplitude.Unity.Gui.GuiPanel[] panels; if (guiService != null && guiService.TryGetGuiPanelByType(typeof(GameWorldScreen), out panels)) { panels[0].Show(new object[0]); } } this.saving = null; yield break; }
private IEnumerator LoadGeometry() { string pathToGameArchive = string.Empty; IGameSerializationService service = Amplitude.Unity.Framework.Services.GetService <IGameSerializationService>(); if (service != null && service.GameSaveDescriptor != null) { pathToGameArchive = service.GameSaveDescriptor.SourceFileName; } if (string.IsNullOrEmpty(pathToGameArchive)) { using (WorldGenerator worldGenerator3 = new WorldGenerator()) { pathToGameArchive = worldGenerator3.GetOuputPath(); } } string pathToGeometryArchive = pathToGameArchive; int geometryArchiveVersionIndex = 1; bool forceRegenerateGeometry = false; bool reloadOrRegenarateGeometry = false; bool flag = false; do { reloadOrRegenarateGeometry = false; using (Archive archive = Archive.Open(pathToGameArchive, ArchiveMode.Open)) { MemoryStream memoryStream = null; Guid guid = Guid.Empty; try { if (archive.TryGet("WorldGeneratorReport.xml", out memoryStream)) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); XmlNode xmlNode = xmlDocument.DocumentElement.SelectSingleNode("//GUID"); if (xmlNode != null) { guid = new Guid(xmlNode.InnerText); if (guid != Guid.Empty) { ISessionService service2 = Amplitude.Unity.Framework.Services.GetService <ISessionService>(); if (service2 != null) { Diagnostics.Assert(service2.Session != null); Diagnostics.Assert(service2.Session.IsOpened); IAdvancedVideoSettingsService service3 = Amplitude.Unity.Framework.Services.GetService <IAdvancedVideoSettingsService>(); Diagnostics.Assert(service3 != null); string worldGeometryType = service3.WorldGeometryType; pathToGeometryArchive = System.IO.Path.Combine(Amplitude.Unity.Framework.Application.TempDirectory, string.Format("{0}/{1}_V{2}.geo", guid, worldGeometryType, geometryArchiveVersionIndex)); } } } } } catch { guid = Guid.Empty; } finally { if (memoryStream != null) { memoryStream.Close(); memoryStream.Dispose(); memoryStream = null; } } if (!File.Exists(pathToGeometryArchive) || forceRegenerateGeometry) { forceRegenerateGeometry = true; using (WorldGenerator worldGenerator2 = new WorldGenerator()) { string fullPath = Amplitude.Unity.Framework.Path.GetFullPath(worldGenerator2.ConfigurationPath); XmlDocument xmlDocument2 = new XmlDocument(); if (archive.TryGet("WorldGeneratorConfiguration.xml", out memoryStream)) { xmlDocument2.Load(memoryStream); memoryStream.Close(); memoryStream.Dispose(); memoryStream = null; } else { worldGenerator2.WriteConfigurationFile(); xmlDocument2.Load(fullPath); } XmlNode xmlNode2 = xmlDocument2.SelectSingleNode("//OutputDirectory"); if (xmlNode2 == null) { xmlNode2 = xmlDocument2.CreateElement("OutputDirectory"); xmlDocument2.AppendChild(xmlNode2); } xmlNode2.InnerText = Amplitude.Unity.Framework.Application.TempDirectory; XmlNode xmlNode3 = xmlDocument2.SelectSingleNode("//OutputPath"); if (xmlNode3 == null) { xmlNode3 = xmlDocument2.CreateElement("OutputPath"); xmlDocument2.AppendChild(xmlNode3); } xmlNode3.InnerText = pathToGameArchive; XmlNode xmlNode4 = xmlDocument2.SelectSingleNode("//SettingsPath"); if (xmlNode4 == null) { xmlNode4 = xmlDocument2.CreateElement("SettingsPath"); xmlDocument2.AppendChild(xmlNode4); } WorldGeneratorConfiguration worldGeneratorConfiguration = new WorldGeneratorConfiguration(); xmlNode4.InnerText = worldGeneratorConfiguration.SettingsPath; IAdvancedVideoSettingsService service4 = Amplitude.Unity.Framework.Services.GetService <IAdvancedVideoSettingsService>(); Diagnostics.Assert(service4 != null); string worldGeometryType2 = service4.WorldGeometryType; XmlNode xmlNode5 = xmlDocument2.SelectSingleNode("//Properties"); Diagnostics.Assert(xmlNode5 != null); StaticString staticString = "Geometry"; XmlNode xmlNode6 = xmlNode5.SelectSingleNode(string.Format("//{0}", staticString)); Diagnostics.Assert(xmlNode6 != null); xmlNode6.InnerText = worldGeometryType2; OptionDefinition optionDefinition; if (Databases.GetDatabase <OptionDefinition>(false).TryGetValue(staticString, out optionDefinition) && optionDefinition.ItemDefinitions != null) { int num = -1; for (int i = 0; i < optionDefinition.ItemDefinitions.Length; i++) { if (optionDefinition.ItemDefinitions[i].Name == worldGeometryType2) { num = i; break; } } OptionDefinition.ItemDefinition itemDefinition = (num < 0) ? optionDefinition.Default : optionDefinition.ItemDefinitions[num]; for (int j = 0; j < itemDefinition.KeyValuePairs.Length; j++) { OptionDefinition.ItemDefinition.KeyValuePair keyValuePair = itemDefinition.KeyValuePairs[j]; XmlNode xmlNode7 = xmlNode5.SelectSingleNode(string.Format("//{0}", keyValuePair.Key)); if (xmlNode7 != null) { Diagnostics.Assert(xmlNode7 != null); xmlNode7.InnerText = itemDefinition.KeyValuePairs[j].Value; } else { Diagnostics.LogWarning("Missing property {0} in XMLDocument.", new object[] { keyValuePair.Key }); } } } XmlNode xmlNode8 = xmlDocument2.SelectSingleNode("//Scenario//DirectoryName"); if (xmlNode8 != null && !Directory.Exists(xmlNode8.InnerText)) { xmlNode8.InnerText = Amplitude.Unity.Framework.Path.FullPath + "../Public/WorldGenerator/Scenarios"; } XmlWriterSettings settings = new XmlWriterSettings { Encoding = Encoding.UTF8, Indent = true, IndentChars = " ", NewLineChars = "\r\n", NewLineHandling = NewLineHandling.Replace, OmitXmlDeclaration = false }; using (XmlWriter xmlWriter = XmlWriter.Create(fullPath, settings)) { xmlDocument2.WriteTo(xmlWriter); } archive.Close(); yield return(null); yield return(worldGenerator2.GenerateWorldGeometry()); flag = true; } WorldGenerator worldGenerator2 = null; } archive.Close(); } Archive archive = null; if (!File.Exists(pathToGeometryArchive)) { goto IL_7C3; } using (Archive archive2 = Archive.Open(pathToGeometryArchive, ArchiveMode.Open)) { MemoryStream input = null; if (!archive2.TryGet("Geometry2.bin", out input)) { throw new InvalidDataException("Archive does not contain the geometry binary."); } using (BinaryReader binaryReader = new BinaryReader(input)) { WorldMeshes worldMeshes = WorldMeshes.LoadFromFile(binaryReader); WorldData worldData = WorldData.LoadFromFile(binaryReader); if (this.CheckWorldDataUpToDate(worldData)) { this.WorldMeshes = worldMeshes; this.WorldData = worldData; if (this.PatchsData == null) { this.PatchsData = new DefaultWorldViewTechnique.PatchData[this.WorldMeshes.PatchCountX * this.WorldMeshes.PatchCountY]; for (int k = 0; k < this.WorldMeshes.PatchCountY; k++) { for (int l = 0; l < this.WorldMeshes.PatchCountX; l++) { this.PatchsData[l + k * this.WorldMeshes.PatchCountX] = new DefaultWorldViewTechnique.PatchData(); } } } DefaultWorldViewTechnique.PatchData[] patchsData = this.PatchsData; for (int m = 0; m < patchsData.Length; m++) { patchsData[m].InitMeshList(); } if (this.WorldMeshes.MeshList != null) { foreach (Mesh mesh in this.WorldMeshes.MeshList) { this.GetSurfacePatchData(mesh.PatchY, mesh.PatchX).MeshList.Add(mesh); } } if (this.WorldData.Cliffs != null) { foreach (WorldData.CliffData cliffData in this.WorldData.Cliffs) { this.GetSurfacePatchData(cliffData.PatchY, cliffData.PatchX).AddCliffData(cliffData); } } if (this.WorldData.WaterPOIs != null) { foreach (WorldData.WaterPOIData waterPOIData in this.WorldData.WaterPOIs) { this.GetSurfacePatchData(waterPOIData.PatchY, waterPOIData.PatchX).AddWaterPOIData(waterPOIData); } } } else { reloadOrRegenarateGeometry = true; forceRegenerateGeometry = true; if (flag) { throw new InvalidDataException("The WorldGenerator.exe currently used is not up to date and produces deprecated data. Please update."); } } } archive2.Close(); } }while (reloadOrRegenarateGeometry); yield break; IL_7C3: throw new FileNotFoundException(string.Format("The file containing the geometry data is missing. path: {0}", pathToGeometryArchive)); yield break; }
private void LoadGuiImage(params object[] parameters) { if (this.Background.Image != null) { AgeManager.Instance.ReleaseDynamicTexture(this.Background.Image.name); } string text = string.Empty; GameSaveDescriptor gameSaveDescriptor = null; if (parameters.Length > 0) { for (int i = 0; i < parameters.Length; i++) { if (parameters[i] is string) { text = (string)parameters[i]; this.Background.Image = (Resources.Load(text) as Texture2D); if (this.Background.Image != null) { break; } } if (parameters[i] is GameSaveDescriptor) { gameSaveDescriptor = (parameters[i] as GameSaveDescriptor); } } } if (string.IsNullOrEmpty(text)) { if (this.SessionService != null && this.SessionService.Session != null && this.SessionService.Session.IsOpened) { int num = 0; for (;;) { string x = string.Format("Empire{0}", num); string lobbyData = this.SessionService.Session.GetLobbyData <string>(x, null); if (string.IsNullOrEmpty(lobbyData)) { break; } if (lobbyData.Contains(this.SessionService.Session.SteamIDUser.ToString())) { goto Block_11; } num++; } goto IL_201; Block_11: string x2 = string.Format("Faction{0}", num); string lobbyData2 = this.SessionService.Session.GetLobbyData <string>(x2, null); if (!string.IsNullOrEmpty(lobbyData2)) { string[] array = lobbyData2.Split(Amplitude.String.Separators, StringSplitOptions.None); string x3 = array[3]; GuiElement guiElement = null; IDatabase <GuiElement> database = Databases.GetDatabase <GuiElement>(false); if (database != null && database.TryGetValue(x3, out guiElement)) { text = guiElement.Icons["MoodScore"]; this.Background.Image = (Resources.Load(text) as Texture2D); } } } IL_201: if (string.IsNullOrEmpty(text)) { if (gameSaveDescriptor == null) { IGameSerializationService service = Services.GetService <IGameSerializationService>(); if (service != null && service.GameSaveDescriptor != null) { gameSaveDescriptor = service.GameSaveDescriptor; } } if (gameSaveDescriptor != null) { int num2 = 0; for (;;) { string key = string.Format("Empire{0}", num2); string lobbyData3 = gameSaveDescriptor.GameSaveSessionDescriptor.GetLobbyData <string>(key, null); if (string.IsNullOrEmpty(lobbyData3)) { break; } Steamworks.SteamID steamID = Steamworks.SteamAPI.SteamUser.SteamID; bool flag = lobbyData3.Contains(steamID.ToString()); bool flag2 = !lobbyData3.StartsWith("AI"); if (flag || (flag2 && string.IsNullOrEmpty(text))) { string key2 = string.Format("Faction{0}", num2); string lobbyData4 = gameSaveDescriptor.GameSaveSessionDescriptor.GetLobbyData <string>(key2, null); if (!string.IsNullOrEmpty(lobbyData4)) { string[] array2 = lobbyData4.Split(Amplitude.String.Separators, StringSplitOptions.None); string x4 = array2[3]; GuiElement guiElement2 = null; IDatabase <GuiElement> database2 = Databases.GetDatabase <GuiElement>(false); if (database2 != null && database2.TryGetValue(x4, out guiElement2)) { text = guiElement2.Icons["MoodScore"]; this.Background.Image = (Resources.Load(text) as Texture2D); } } if (flag) { break; } } num2++; } } if (string.IsNullOrEmpty(text)) { if (this.validGuiElements != null && this.validGuiElements.Count != 0) { GuiElement guiElement3 = this.validGuiElements[UnityEngine.Random.Range(0, this.validGuiElements.Count)]; Texture2D image; if (base.GuiService.GuiPanelHelper.TryGetTextureFromIcon(guiElement3, global::GuiPanel.IconSize.MoodScore, out image)) { this.Background.Image = image; } } else { this.Background.Image = (Resources.Load("GUI/DynamicBitmaps/Backdrop/Pov_Auriga") as Texture2D); } } } } }