Example #1
0
        public CCAPI()
        {
            RegistryKey Key = Registry
                              .CurrentUser
                              .OpenSubKey(@"Software\FrenchModdingTeam\CCAPI\InstallFolder");

            if (Key != null)
            {
                //string Path = Key.GetValue("path") as String;
                string Path = ".\\APIs\\CCAPI 2.80";
                programPath = Path;
                if (!string.IsNullOrEmpty(Path))
                {
                    string DllUrl = Path + @"\CCAPI.dll";
                    if (File.Exists(DllUrl))
                    {
                        if (BitConverter.ToString(MD5.Create()
                                                  .ComputeHash(File.ReadAllBytes(DllUrl)))
                            .Replace("-", "").Equals(CCAPIHASH))

                        {
                            if (libModule == IntPtr.Zero)
                            {
                                libModule = LoadLibrary(DllUrl);
                            }

                            if (libModule != IntPtr.Zero)
                            {
                                this.connectConsole      = (CCAPI.CCAPIConnectConsole_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIConnectConsole"), typeof(CCAPI.CCAPIConnectConsole_t));
                                this.disconnectConsole   = (CCAPI.CCAPIDisconnectConsole_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIDisconnectConsole"), typeof(CCAPI.CCAPIDisconnectConsole_t));
                                this.getConnectionStatus = (CCAPI.CCAPIGetConnectionStatus_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetConnectionStatus"), typeof(CCAPI.CCAPIGetConnectionStatus_t));
                                this.getConsoleInfo      = (CCAPI.CCAPIGetConsoleInfo_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetConsoleInfo"), typeof(CCAPI.CCAPIGetConsoleInfo_t));
                                this.getDllVersion       = (CCAPI.CCAPIGetDllVersion_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetDllVersion"), typeof(CCAPI.CCAPIGetDllVersion_t));
                                this.getFirmwareInfo     = (CCAPI.CCAPIGetFirmwareInfo_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetFirmwareInfo"), typeof(CCAPI.CCAPIGetFirmwareInfo_t));
                                this.getNumberOfConsoles = (CCAPI.CCAPIGetNumberOfConsoles_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetNumberOfConsoles"), typeof(CCAPI.CCAPIGetNumberOfConsoles_t));
                                this.getProcessList      = (CCAPI.CCAPIGetProcessList_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetProcessList"), typeof(CCAPI.CCAPIGetProcessList_t));
                                this.getProcessMemory    = (CCAPI.CCAPIGetMemory_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetMemory"), typeof(CCAPI.CCAPIGetMemory_t));
                                this.getProcessName      = (CCAPI.CCAPIGetProcessName_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetProcessName"), typeof(CCAPI.CCAPIGetProcessName_t));
                                this.getTemperature      = (CCAPI.CCAPIGetTemperature_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIGetTemperature"), typeof(CCAPI.CCAPIGetTemperature_t));
                                this.notify            = (CCAPI.CCAPIVshNotify_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIVshNotify"), typeof(CCAPI.CCAPIVshNotify_t));
                                this.ringBuzzer        = (CCAPI.CCAPIRingBuzzer_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIRingBuzzer"), typeof(CCAPI.CCAPIRingBuzzer_t));
                                this.setBootConsoleIds = (CCAPI.CCAPISetBootConsoleIds_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPISetBootConsoleIds"), typeof(CCAPI.CCAPISetBootConsoleIds_t));
                                this.setConsoleIds     = (CCAPI.CCAPISetConsoleIds_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPISetConsoleIds"), typeof(CCAPI.CCAPISetConsoleIds_t));
                                this.setConsoleLed     = (CCAPI.CCAPISetConsoleLed_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPISetConsoleLed"), typeof(CCAPI.CCAPISetConsoleLed_t));
                                this.setProcessMemory  = (CCAPI.CCAPISetMemory_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPISetMemory"), typeof(CCAPI.CCAPISetMemory_t));
                                this.shutdown          = (CCAPI.CCAPIShutdown_t)Marshal.GetDelegateForFunctionPointer(CCAPI.GetProcAddress(this.libModule, "CCAPIShutdown"), typeof(CCAPI.CCAPIShutdown_t));
                            }
                            else
                            {
                                MessageBox.Show("Impossible to load CCAPI.dll version 2.80.", "CCAPI.dll cannot be load", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show("You're not using the right CCAPI.dll please install the version 2.80.", "CCAPI.dll version incorrect", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("You need to install CCAPI to use this library.", "CCAPI.dll not found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid CCAPI folder, please re-install it.", "CCAPI not installed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("You need to install CCAPI to use this library.", "CCAPI not installed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }