Exemplo n.º 1
0
Arquivo: Game.cs Projeto: BigETI/CGLL
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="gameProcess">Game process</param>
 /// <param name="gameLaunchOptions">Game launch options</param>
 /// <param name="lastResourcesState">Last resources state</param>
 /// <param name="lastSessionLogData">Last session log data</param>
 protected Game(Process gameProcess, GameLaunchOptionsDataContract gameLaunchOptions, ResourcesState lastResourcesState, SessionLogDataContract <T> lastSessionLogData)
 {
     GameProcess        = gameProcess;
     GameLaunchOptions  = gameLaunchOptions;
     LastResourcesState = lastResourcesState;
     LastSessionLogData = lastSessionLogData;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="path">Path</param>
 /// <param name="sessionLogData">Session log data</param>
 /// <param name="archiveFileStream">Archive file stream</param>
 /// <param name="archive">Archive</param>
 private SessionLog(string path, SessionLogDataContract <T> sessionLogData, FileStream archiveFileStream, ZipArchive archive)
 {
     this.path              = path;
     this.sessionLogData    = sessionLogData;
     this.archiveFileStream = archiveFileStream;
     this.archive           = archive;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Load session
        /// </summary>
        /// <param name="path">Path</param>
        /// <returns>Session if successful, otherwise "null"</returns>
        public static SessionLog <T> Load(string path)
        {
            SessionLog <T> ret = null;

            try
            {
                if (path != null)
                {
                    if (File.Exists(path))
                    {
                        FileStream      file_stream = File.Open(path, FileMode.Open, FileAccess.Read);
                        ZipArchive      archive     = new ZipArchive(file_stream, ZipArchiveMode.Read);
                        ZipArchiveEntry entry       = archive.GetEntry("meta.json");
                        if (entry != null)
                        {
                            using (Stream stream = entry.Open())
                            {
                                SessionLogDataContract <T> session_data = serializer.ReadObject(stream) as SessionLogDataContract <T>;
                                if (session_data != null)
                                {
                                    ret = new SessionLog <T>(path, session_data, file_stream, archive);
                                }
                                else
                                {
                                    archive.Dispose();
                                    file_stream.Dispose();
                                }
                            }
                        }
                        else
                        {
                            archive.Dispose();
                            file_stream.Dispose();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
            }
            return(ret);
        }
Exemplo n.º 4
0
        /// <summary>
        /// aunh game
        /// </summary>
        /// <typeparam name="T">Session log user data type</typeparam>
        /// <param name="gameLaunchOptions">Game launch options</param>
        /// <param name="userData">User data</param>
        /// <returns>Game</returns>
        public static Game <T> LaunchGame <T>(GameLaunchOptionsDataContract gameLaunchOptions, T userData)
        {
            Game <T> ret = null;

            if (gameLaunchOptions != null)
            {
                IntPtr mh = Kernel32.GetModuleHandle("kernel32.dll");
                if (mh != IntPtr.Zero)
                {
                    IntPtr load_library_w = Kernel32.GetProcAddress(mh, "LoadLibraryW");
                    if (load_library_w != IntPtr.Zero)
                    {
                        Kernel32.PROCESS_INFORMATION process_info;
                        Kernel32.STARTUPINFO         startup_info = new Kernel32.STARTUPINFO();
                        if (IsGameRunning(Path.GetFileNameWithoutExtension(gameLaunchOptions.GamePath)))
                        {
                            ResourcesState             last_resource_state;
                            SessionLogDataContract <T> last_session_log_data;
                            if (gameLaunchOptions.CreateSessionLog)
                            {
                                last_resource_state   = new ResourcesState(gameLaunchOptions.SessionLogResourcePaths);
                                last_session_log_data = new SessionLogDataContract <T>(DateTime.Now, TimeSpan.Zero, userData);
                            }
                            if (Kernel32.CreateProcess(gameLaunchOptions.GamePath, gameLaunchOptions.LaunchParameters, IntPtr.Zero, IntPtr.Zero, false, /* DETACHED_PROCESS */ 0x8 | /* CREATE_SUSPENDED */ 0x4, IntPtr.Zero, gameLaunchOptions.WorkingDirectory, ref startup_info, out process_info))
                            {
                                foreach (string plugin_path in gameLaunchOptions.Plugins)
                                {
                                    if (plugin_path != null)
                                    {
                                        InjectPlugin(plugin_path, process_info.hProcess, load_library_w);
                                    }
                                }
                                Kernel32.ResumeThread(process_info.hThread);
                                Kernel32.CloseHandle(process_info.hProcess);
                            }
                        }
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create session
        /// </summary>
        /// <param name="path">Path</param>
        /// <param name="dateTime">Date and time</param>
        /// <param name="timeSpan">Time span</param>
        /// <param name="gameVersion">Game version</param>
        /// <param name="username">Username</param>
        /// <param name="ipPort">IP and port</param>
        /// <param name="hostname">Hostname</param>
        /// <param name="mode">Mode</param>
        /// <param name="language">Language</param>
        /// <param name="screenshotPaths">Screenshot paths</param>
        /// <param name="chatlogPath">Chatlog path</param>
        /// <param name="savedPositionsPath">Saved positions path</param>
        /// <returns>New session</returns>
        public static SessionLog <T> Create(string path, DateTime dateTime, TimeSpan timeSpan, T userData, SessionLogResourcePathDataContract[] resourcePaths)
        {
            SessionLog <T> ret = null;

            if (path != null)
            {
                if (path != null)
                {
                    SessionLogDataContract <T> session_data = new SessionLogDataContract <T>(dateTime, timeSpan, userData);
                    try
                    {
                        if (File.Exists(path))
                        {
                            File.Delete(path);
                        }
                        FileStream      file_stream = File.Open(path, FileMode.Create);
                        ZipArchive      archive     = new ZipArchive(file_stream, ZipArchiveMode.Create);
                        ZipArchiveEntry entry       = archive.CreateEntry("meta.json");
                        if (entry != null)
                        {
                            using (Stream stream = entry.Open())
                            {
                                serializer.WriteObject(stream, session_data);
                            }
                        }
                        if (resourcePaths != null)
                        {
                            foreach (SessionLogResourcePathDataContract resource_path in resourcePaths)
                            {
                                if (resource_path != null)
                                {
                                    if (File.Exists(resource_path.Path))
                                    {
                                        try
                                        {
                                            using (FileStream resource_file_stream = File.Open(resource_path.Path, FileMode.Open))
                                            {
                                                // TODO
                                                // Add support for sub entries
                                                entry = archive.CreateEntry(resource_path.DataType.ToString().ToLower() + "/" + System.IO.Path.GetFileName(resource_path.Path), CompressionLevel.Optimal);
                                                if (entry != null)
                                                {
                                                    using (Stream entry_stream = entry.Open())
                                                    {
                                                        if (entry_stream != null)
                                                        {
                                                            resource_file_stream.CopyTo(entry_stream);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            Console.Error.WriteLine(e);
                                        }
                                    }
                                }
                            }
                        }
                        ret = new SessionLog <T>(path, session_data, file_stream, archive);
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine(e);
                    }
                }
            }
            return(ret);
        }