Example #1
0
    public static void Launch()
    {
        string text = Amplitude.Unity.Framework.Path.GetFullPath("Public/Tutorial");
        string a;

        if (global::Application.ResolveChineseLanguage(out a))
        {
            if (a == "schinese")
            {
                text += "/SChinese";
            }
            else if (a == "tchinese")
            {
                text += "/TChinese";
            }
        }
        GameSaveDescriptor gameSaveDescriptor = (from element in TutorialManager.GetListOfGameSaveDescritors(text)
                                                 orderby element.SourceFileName
                                                 select element).FirstOrDefault <GameSaveDescriptor>();

        if (gameSaveDescriptor != null)
        {
            TutorialManager.Launch(gameSaveDescriptor);
        }
    }
    private void SetupSaveLineSlot(AgeTransform tableitem, int index, GameSaveDescriptor gameSaveDescriptor)
    {
        tableitem.DirtyPosition = true;
        tableitem.Enable        = true;
        if (index % 20 == 0)
        {
            tableitem.StartNewMesh = true;
        }
        SaveLineSlot component = tableitem.GetComponent <SaveLineSlot>();

        component.RefreshContent(index, gameSaveDescriptor, base.gameObject);
    }
Example #3
0
    public static void Launch(string fileNameWithoutExtension)
    {
        string fullPath = Amplitude.Unity.Framework.Path.GetFullPath("Public/Tutorial");
        IEnumerable <GameSaveDescriptor> source = from element in TutorialManager.GetListOfGameSaveDescritors(fullPath)
                                                  orderby element.SourceFileName
                                                  select element;
        GameSaveDescriptor gameSaveDescriptor = source.FirstOrDefault((GameSaveDescriptor element) => System.IO.Path.GetFileNameWithoutExtension(element.SourceFileName).Equals(fileNameWithoutExtension, StringComparison.InvariantCultureIgnoreCase));

        if (gameSaveDescriptor != null)
        {
            TutorialManager.Launch(gameSaveDescriptor);
        }
    }
Example #4
0
    public static void Launch(GameSaveDescriptor gameSaveDescriptor)
    {
        if (gameSaveDescriptor == null)
        {
            throw new ArgumentNullException("gameSaveDescriptor");
        }
        IRuntimeService service = Services.GetService <IRuntimeService>();

        if (service != null)
        {
            if (service.Runtime == null)
            {
                throw new InvalidOperationException("Cannnot launch the tutorial when there is no runtime.");
            }
            service.Runtime.FiniteStateMachine.PostStateChange(typeof(RuntimeState_Lobby), new object[]
            {
                gameSaveDescriptor
            });
        }
    }
Example #5
0
    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);
                    }
                }
            }
        }
    }
Example #6
0
    public static IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(string path)
    {
        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer serializer = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        List <string> fileNames  = new List <string>();

        fileNames.AddRange(Directory.GetFiles(path, "*.zip"));
        fileNames.AddRange(Directory.GetFiles(path, "*.sav"));
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;

        foreach (string fileName in fileNames)
        {
            gameSaveDescriptor = null;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    XmlReaderSettings xmlReaderSettings = new XmlReaderSettings
                    {
                        IgnoreComments   = true,
                        IgnoreWhitespace = true,
                        CloseInput       = true
                    };
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch
            {
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null)
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Example #7
0
 public bool TryExtractGameSaveDescriptorFromFile(string outputFilePath, out GameSaveDescriptor gameSaveDescriptor, bool makeCurrent)
 {
     gameSaveDescriptor = null;
     if (File.Exists(outputFilePath))
     {
         Archive archive = null;
         try
         {
             archive = Archive.Open(outputFilePath, ArchiveMode.Open);
             MemoryStream stream = null;
             if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
             {
                 XmlReaderSettings settings = new XmlReaderSettings
                 {
                     CloseInput     = true,
                     IgnoreComments = true,
                     IgnoreProcessingInstructions = true,
                     IgnoreWhitespace             = true
                 };
                 using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                 {
                     if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                     {
                         ISerializationService service = Services.GetService <ISerializationService>();
                         XmlSerializer         xmlSerializer;
                         if (service != null)
                         {
                             xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                         }
                         else
                         {
                             xmlSerializer = new XmlSerializer(typeof(GameSaveDescriptor));
                         }
                         gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                         gameSaveDescriptor.SourceFileName = outputFilePath;
                         if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                         {
                             Diagnostics.LogError("Invalid game save; application version does not match.");
                             gameSaveDescriptor = null;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             Diagnostics.LogWarning("Exception caught: " + ex.ToString());
             gameSaveDescriptor = null;
         }
         finally
         {
             if (archive != null)
             {
                 archive.Close();
             }
         }
         if (gameSaveDescriptor != null)
         {
             if (makeCurrent)
             {
                 this.GameSaveDescriptor = gameSaveDescriptor;
             }
             return(true);
         }
     }
     return(false);
 }
Example #8
0
    public IEnumerator SaveGameAsync(string title, string outputFileName, GameSaveOptions gameSaveOptions)
    {
        if (string.IsNullOrEmpty(outputFileName))
        {
            throw new ArgumentException("outputFileName");
        }
        string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(outputFileName);
        string fileNameExtension        = System.IO.Path.GetExtension(outputFileName);
        string path = System.IO.Path.GetDirectoryName(outputFileName);

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        if ((gameSaveOptions & GameSaveOptions.QuickSave) == GameSaveOptions.QuickSave)
        {
            title = "%QuickSaveFileName";
            fileNameWithoutExtension = "QuickSave";
        }
        if ((gameSaveOptions & GameSaveOptions.AutoSave) == GameSaveOptions.AutoSave)
        {
            title = "%AutoSaveFileName";
            fileNameWithoutExtension = "AutoSave";
            if (global::GameManager.maximumNumberOfAutoSaveFiles == 0)
            {
                yield break;
            }
            if ((gameSaveOptions & GameSaveOptions.Incremental) == GameSaveOptions.Incremental)
            {
                int number = this.ProcessIncremental(path, fileNameWithoutExtension);
                fileNameWithoutExtension = string.Format("{0} {1}", fileNameWithoutExtension, number);
            }
        }
        outputFileName = System.IO.Path.Combine(path, string.Format("{0}{1}", fileNameWithoutExtension, fileNameExtension));
        MemoryStream stream = new MemoryStream();

        try
        {
            this.SaveGame(stream);
            ISessionService sessionService = Services.GetService <ISessionService>();
            Diagnostics.Assert(sessionService != null);
            Diagnostics.Assert(sessionService.Session != null);
            if (this.GameSaveDescriptor == null)
            {
                this.GameSaveDescriptor = new GameSaveDescriptor();
                using (WorldGenerator worldGenerator = new WorldGenerator())
                {
                    this.GameSaveDescriptor.SourceFileName = worldGenerator.GetOuputPath();
                    if (File.Exists(this.GameSaveDescriptor.SourceFileName))
                    {
                        this.GameSaveDescriptor.Source = File.ReadAllBytes(this.GameSaveDescriptor.SourceFileName);
                    }
                }
                Diagnostics.Assert(this.Game is global::Game);
                Diagnostics.Assert(sessionService.Session != null);
                global::Game game = this.Game as global::Game;
                int          turn = Math.Max(0, game.Turn - 1);
                this.GameSaveDescriptor.GameSaveSessionDescriptor.TrackUserPresence(game, sessionService.Session, turn);
                this.GameSaveDescriptor.GUID = Guid.NewGuid();
            }
            this.GameSaveDescriptor.DateTime = DateTime.Now;
            this.GameSaveDescriptor.Title    = title;
            this.GameSaveDescriptor.Version  = Amplitude.Unity.Framework.Application.Version;
            this.GameSaveDescriptor.Turn     = (this.Game as global::Game).Turn;
            if ((gameSaveOptions & GameSaveOptions.Closed) == GameSaveOptions.Closed)
            {
                this.GameSaveDescriptor.Closed = true;
            }
            IRuntimeService runtimeService = Services.GetService <IRuntimeService>();
            if (runtimeService != null && runtimeService.Runtime != null)
            {
                Diagnostics.Assert(runtimeService.Runtime.RuntimeModules != null);
                this.GameSaveDescriptor.RuntimeModules = (from runtimeModule in runtimeService.Runtime.RuntimeModules
                                                          select runtimeModule.Name).ToArray <string>();
            }
            this.GameSaveDescriptor.GameSaveSessionDescriptor.SessionMode = sessionService.Session.SessionMode;
            this.GameSaveDescriptor.GameSaveSessionDescriptor.SetLobbyData(sessionService.Session);
            outputFileName = System.IO.Path.ChangeExtension(outputFileName, "sav");
            if (File.Exists(this.GameSaveDescriptor.SourceFileName))
            {
                try
                {
                    if (outputFileName != this.GameSaveDescriptor.SourceFileName)
                    {
                        File.Copy(this.GameSaveDescriptor.SourceFileName, outputFileName, true);
                    }
                }
                catch (Exception ex)
                {
                    Exception exception = ex;
                    if (!(exception is IOException))
                    {
                        throw;
                    }
                    if (!File.Exists(outputFileName))
                    {
                        throw;
                    }
                }
            }
            else
            {
                if (this.GameSaveDescriptor.Source == null)
                {
                    throw new FileNotFoundException("The source file is missing; it may have been deleted?", this.GameSaveDescriptor.SourceFileName);
                }
                try
                {
                    Diagnostics.LogWarning("Using binary source to restore the game archive...");
                    File.WriteAllBytes(outputFileName, this.GameSaveDescriptor.Source);
                }
                catch
                {
                    throw;
                }
            }
            using (Archive archive = Archive.Open(outputFileName, ArchiveMode.OpenOrCreate))
            {
                archive.Add(global::GameManager.GameFileName, stream, CompressionMethod.Compressed);
                stream.Seek(0L, SeekOrigin.Begin);
                stream.SetLength(0L);
                this.SaveGameDescriptor(stream);
                if (stream.Length > 0L)
                {
                    archive.Add(global::GameManager.GameSaveDescriptorFileName, stream, CompressionMethod.Compressed);
                }
                if (this.GameSaving != null)
                {
                    this.GameSaving(this, new GameSavingEventArgs(archive));
                }
            }
            this.GameSaveDescriptor.SourceFileName = outputFileName;
        }
        catch
        {
            throw;
        }
        if (stream != null)
        {
            stream.Close();
            stream = null;
        }
        yield break;
    }
Example #9
0
    public IEnumerable <GameSaveDescriptor> GetListOfGameSaveDescritors(bool withAutoSave)
    {
        string path = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(path))
        {
            yield break;
        }
        if (!Directory.Exists(path))
        {
            yield break;
        }
        ISerializationService serializationService = Services.GetService <ISerializationService>();

        if (serializationService == null)
        {
            yield break;
        }
        XmlSerializer   serializer      = serializationService.GetXmlSerializer <GameSaveDescriptor>();
        DirectoryInfo   directory       = new DirectoryInfo(path);
        List <FileInfo> compatibleFiles = new List <FileInfo>();

        compatibleFiles.AddRange(directory.GetFiles("*.zip"));
        compatibleFiles.AddRange(directory.GetFiles("*.sav"));
        FileInfo[] files = (from f in compatibleFiles
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        Archive            archive            = null;
        GameSaveDescriptor gameSaveDescriptor = null;
        XmlReaderSettings  xmlReaderSettings  = new XmlReaderSettings
        {
            CloseInput     = true,
            IgnoreComments = true,
            IgnoreProcessingInstructions = true,
            IgnoreWhitespace             = true
        };

        for (int i = 0; i < files.Length; i++)
        {
            gameSaveDescriptor = null;
            string fileName = files[i].FullName;
            try
            {
                archive = Archive.Open(fileName, ArchiveMode.Open);
                MemoryStream stream = null;
                if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                {
                    using (System.Xml.XmlReader reader = System.Xml.XmlReader.Create(stream, xmlReaderSettings))
                    {
                        if (reader.ReadToDescendant("GameSaveDescriptor"))
                        {
                            gameSaveDescriptor = (serializer.Deserialize(reader) as GameSaveDescriptor);
                            gameSaveDescriptor.SourceFileName = fileName;
                            if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                            {
                                gameSaveDescriptor = null;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Exception exception = ex;
                Diagnostics.LogWarning("Exception caught: " + exception.ToString());
                gameSaveDescriptor = null;
            }
            finally
            {
                if (archive != null)
                {
                    archive.Close();
                }
            }
            if (gameSaveDescriptor != null && gameSaveDescriptor.Closed)
            {
                gameSaveDescriptor = null;
            }
            if (gameSaveDescriptor != null && (withAutoSave || !gameSaveDescriptor.Title.StartsWith(global::GameManager.AutoSaveFileName)))
            {
                yield return(gameSaveDescriptor);
            }
        }
        yield break;
    }
Example #10
0
    public GameSaveDescriptor GetMostRecentGameSaveDescritor()
    {
        string gameSaveDirectory = global::Application.GameSaveDirectory;

        if (string.IsNullOrEmpty(gameSaveDirectory))
        {
            return(null);
        }
        if (!Directory.Exists(gameSaveDirectory))
        {
            return(null);
        }
        ISerializationService service = Services.GetService <ISerializationService>();

        if (service == null)
        {
            return(null);
        }
        List <string>   list     = null;
        IRuntimeService service2 = Services.GetService <IRuntimeService>();

        if (service2 != null)
        {
            Diagnostics.Assert(service2.Runtime != null);
            Diagnostics.Assert(service2.Runtime.RuntimeModules != null);
            list = (from runtimeModule in service2.Runtime.RuntimeModules
                    select runtimeModule.Name).ToList <string>();
        }
        DirectoryInfo   directoryInfo = new DirectoryInfo(gameSaveDirectory);
        List <FileInfo> list2         = new List <FileInfo>();

        list2.AddRange(directoryInfo.GetFiles("*.zip"));
        list2.AddRange(directoryInfo.GetFiles("*.sav"));
        FileInfo[] array = (from f in list2
                            orderby f.LastWriteTime descending
                            select f).ToArray <FileInfo>();
        GameSaveDescriptor gameSaveDescriptor = null;

        if (array != null)
        {
            foreach (FileInfo fileInfo in array)
            {
                Archive archive = null;
                try
                {
                    archive = Archive.Open(fileInfo.FullName, ArchiveMode.Open);
                    MemoryStream stream = null;
                    if (archive.TryGet(global::GameManager.GameSaveDescriptorFileName, out stream))
                    {
                        XmlReaderSettings settings = new XmlReaderSettings
                        {
                            CloseInput     = true,
                            IgnoreComments = true,
                            IgnoreProcessingInstructions = true,
                            IgnoreWhitespace             = true
                        };
                        using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stream, settings))
                        {
                            if (xmlReader.ReadToDescendant("GameSaveDescriptor"))
                            {
                                XmlSerializer xmlSerializer = service.GetXmlSerializer <GameSaveDescriptor>();
                                gameSaveDescriptor = (xmlSerializer.Deserialize(xmlReader) as GameSaveDescriptor);
                                gameSaveDescriptor.SourceFileName = fileInfo.FullName;
                                if (gameSaveDescriptor.Version.Serial != Amplitude.Unity.Framework.Application.Version.Serial)
                                {
                                    gameSaveDescriptor = null;
                                }
                                if (gameSaveDescriptor != null)
                                {
                                    if (gameSaveDescriptor.RuntimeModules == null)
                                    {
                                        if (service2 != null)
                                        {
                                            if (list.Count != 1 || !(list[0] == service2.VanillaModuleName))
                                            {
                                                gameSaveDescriptor = null;
                                            }
                                        }
                                        else
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                    else
                                    {
                                        List <string> list3 = list.Except(gameSaveDescriptor.RuntimeModules).ToList <string>();
                                        List <string> list4 = gameSaveDescriptor.RuntimeModules.Except(list).ToList <string>();
                                        if (list3.Count + list4.Count != 0)
                                        {
                                            gameSaveDescriptor = null;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Diagnostics.LogWarning("Exception caught: " + ex.ToString());
                    gameSaveDescriptor = null;
                }
                finally
                {
                    if (archive != null)
                    {
                        archive.Close();
                    }
                }
                if (gameSaveDescriptor != null)
                {
                    break;
                }
            }
        }
        return(gameSaveDescriptor);
    }