Example #1
0
File: Game.cs Project: 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;
 }
Example #2
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);
        }