Ejemplo n.º 1
0
        private static unsafe bool ContainsApplication(IntPtr session, IntPtr profile, SOP.Profile profileDescriptor, ushort[] unicodeApplicationName, out SOP.Application application)
        {
            application = new SOP.Application();
            if ((int)profileDescriptor.numOfApps == 0)
            {
                return(false);
            }
            SOP.Application[] applicationArray = new SOP.Application[(IntPtr)profileDescriptor.numOfApps];
            uint appCount = profileDescriptor.numOfApps;

            fixed(SOP.Application *allApplications = applicationArray)
            {
                allApplications->version = 147464U;
                if (SOP.CheckForError(SOP.EnumApplications(session, profile, 0U, ref appCount, allApplications)))
                {
                    return(false);
                }
                for (uint index = 0U; index < appCount; ++index)
                {
                    // ISSUE: reference to a compiler-generated field
                    if (SOP.UnicodeStringCompare(&((SOP.Application *)((IntPtr)allApplications + (IntPtr)((long)index * (long)sizeof(SOP.Application))))->appName.FixedElementField, unicodeApplicationName))
                    {
                        application = *(SOP.Application *)((IntPtr)allApplications + (IntPtr)((long)index * (long)sizeof(SOP.Application)));
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
 private static bool GetProcs()
 {
     if (IntPtr.Size != 4)
     {
         return(false);
     }
     if (SOP.LoadLibrary("nvapi.dll") == IntPtr.Zero)
     {
         return(false);
     }
     try
     {
         SOP.CreateApplication = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(1128770014U), typeof(SOP.CreateApplicationDelegate)) as SOP.CreateApplicationDelegate;
         SOP.CreateProfile     = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(3424084072U), typeof(SOP.CreateProfileDelegate)) as SOP.CreateProfileDelegate;
         SOP.CreateSession     = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(110417198U), typeof(SOP.CreateSessionDelegate)) as SOP.CreateSessionDelegate;
         SOP.DeleteProfile     = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(386478598U), typeof(SOP.DeleteProfileDelegate)) as SOP.DeleteProfileDelegate;
         SOP.DestroySession    = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(3671707640U), typeof(SOP.DestroySessionDelegate)) as SOP.DestroySessionDelegate;
         SOP.EnumApplications  = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(2141329210U), typeof(SOP.EnumApplicationsDelegate)) as SOP.EnumApplicationsDelegate;
         SOP.FindProfileByName = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(2118818315U), typeof(SOP.FindProfileByNameDelegate)) as SOP.FindProfileByNameDelegate;
         SOP.GetProfileInfo    = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(1640853462U), typeof(SOP.GetProfileInfoDelegate)) as SOP.GetProfileInfoDelegate;
         SOP.Initialize        = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(22079528U), typeof(SOP.InitializeDelegate)) as SOP.InitializeDelegate;
         SOP.LoadSettings      = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(928890219U), typeof(SOP.LoadSettingsDelegate)) as SOP.LoadSettingsDelegate;
         SOP.SaveSettings      = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(4240211476U), typeof(SOP.SaveSettingsDelegate)) as SOP.SaveSettingsDelegate;
         SOP.SetSetting        = Marshal.GetDelegateForFunctionPointer(SOP.QueryInterface(1467863554U), typeof(SOP.SetSettingDelegate)) as SOP.SetSettingDelegate;
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        public static SOP.ResultCodes SOP_RemoveProfile(string profileName)
        {
            int    num = 0;
            IntPtr session;

            if (!SOP.GetProcs() || SOP.CheckForError(SOP.Initialize()) || (SOP.CheckForError(SOP.CreateSession(out session)) || SOP.CheckForError(SOP.LoadSettings(session))))
            {
                return(SOP.ResultCodes.Error);
            }
            SOP.GetUnicodeString(profileName);
            IntPtr profile;

            SOP.ResultCodes resultCodes;
            switch (SOP.FindProfileByName(session, profileName, out profile))
            {
            case 0:
                if (SOP.CheckForError(SOP.DeleteProfile(session, profile)) || SOP.CheckForError(SOP.SaveSettings(session)))
                {
                    return(SOP.ResultCodes.Error);
                }
                resultCodes = SOP.ResultCodes.Change;
                break;

            case -163:
                resultCodes = SOP.ResultCodes.NoChange;
                break;

            default:
                return(SOP.ResultCodes.Error);
            }
            num = SOP.DestroySession(session);
            return(resultCodes);
        }
Ejemplo n.º 4
0
        private static int Main()
        {
            string executableName = Program.GetExecutableName();

            try
            {
                SOP.ResultCodes resultCodes1 = SOP.SOP_RemoveProfile("FEZ");
                SOP.ResultCodes resultCodes2 = SOP.SOP_SetProfile("FEZ", executableName);
                if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FEZ")))
                {
                    Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "FEZ"));
                }
                using (FileStream fileStream = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FEZ\\Debug Log.txt", FileMode.Append))
                {
                    using (StreamWriter streamWriter = new StreamWriter((Stream)fileStream))
                    {
                        streamWriter.WriteLine("({0}) [{1}] {2}", (object)DateTime.Now.ToString("HH:mm:ss.fff"), (object)"Optimus Fix", (object)string.Concat(new object[4]
                        {
                            (object)"SOP_Remove returned ",
                            (object)resultCodes1,
                            (object)" for ",
                            (object)executableName
                        }));
                        streamWriter.WriteLine("({0}) [{1}] {2}", (object)DateTime.Now.ToString("HH:mm:ss.fff"), (object)"Optimus Fix", (object)string.Concat(new object[4]
                        {
                            (object)"SOP_Set returned ",
                            (object)resultCodes2,
                            (object)" for ",
                            (object)executableName
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                using (FileStream fileStream = File.Open(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FEZ\\Debug Log.txt", FileMode.Append))
                {
                    using (StreamWriter streamWriter = new StreamWriter((Stream)fileStream))
                        streamWriter.WriteLine("({0}) [{1}] {2}", (object)DateTime.Now.ToString("HH:mm:ss.fff"), (object)"Optimus Fix", (object)string.Concat(new object[4]
                        {
                            (object)"SOP raised exception : ",
                            (object)ex,
                            (object)" for ",
                            (object)executableName
                        }));
                }
            }
            return(0);
        }
Ejemplo n.º 5
0
        public static bool SOP_CheckProfile(string profileName)
        {
            IntPtr session;

            if (!SOP.GetProcs() || SOP.CheckForError(SOP.Initialize()) || (SOP.CheckForError(SOP.CreateSession(out session)) || SOP.CheckForError(SOP.LoadSettings(session))))
            {
                return(false);
            }
            SOP.GetUnicodeString(profileName);
            IntPtr profile;
            bool   flag = SOP.FindProfileByName(session, profileName, out profile) == 0;
            int    num  = SOP.DestroySession(session);

            return(flag);
        }
Ejemplo n.º 6
0
Archivo: SOP.cs Proyecto: Zeludon/FEZ
 private static unsafe bool ContainsApplication(IntPtr session, IntPtr profile, SOP.Profile profileDescriptor, ushort[] unicodeApplicationName, out SOP.Application application)
 {
     application = new SOP.Application();
       if ((int) profileDescriptor.numOfApps == 0)
     return false;
       SOP.Application[] applicationArray = new SOP.Application[(IntPtr) profileDescriptor.numOfApps];
       uint appCount = profileDescriptor.numOfApps;
       fixed (SOP.Application* allApplications = applicationArray)
       {
     allApplications->version = 147464U;
     if (SOP.CheckForError(SOP.EnumApplications(session, profile, 0U, ref appCount, allApplications)))
       return false;
     for (uint index = 0U; index < appCount; ++index)
     {
       // ISSUE: reference to a compiler-generated field
       if (SOP.UnicodeStringCompare(&((SOP.Application*) ((IntPtr) allApplications + (IntPtr) ((long) index * (long) sizeof (SOP.Application))))->appName.FixedElementField, unicodeApplicationName))
       {
     application = *(SOP.Application*) ((IntPtr) allApplications + (IntPtr) ((long) index * (long) sizeof (SOP.Application)));
     return true;
       }
     }
       }
       return false;
 }
Ejemplo n.º 7
0
        public static unsafe SOP.ResultCodes SOP_SetProfile(string profileName, string applicationName)
        {
            SOP.ResultCodes resultCodes = SOP.ResultCodes.NoChange;
            int             num         = 0;
            IntPtr          session;

            if (!SOP.GetProcs() || SOP.CheckForError(SOP.Initialize()) || (SOP.CheckForError(SOP.CreateSession(out session)) || SOP.CheckForError(SOP.LoadSettings(session))))
            {
                return(SOP.ResultCodes.Error);
            }
            ushort[] unicodeString1 = SOP.GetUnicodeString(profileName);
            ushort[] unicodeString2 = SOP.GetUnicodeString(applicationName);
            IntPtr   profile;
            int      status = SOP.FindProfileByName(session, profileName, out profile);

            if (status == -163)
            {
                SOP.Profile profileInfo = new SOP.Profile();
                profileInfo.version      = 69652U;
                profileInfo.isPredefined = 0U;
                for (int index = 0; index < 2048; ++index)
                {
                    // ISSUE: reference to a compiler-generated field
                    (&profileInfo.profileName.FixedElementField)[index] = unicodeString1[index];
                }

                fixed(uint *numPtr = new uint[32])
                {
                    profileInfo.gpuSupport = numPtr;
                    *profileInfo.gpuSupport = 1U;
                }

                if (SOP.CheckForError(SOP.CreateProfile(session, ref profileInfo, out profile)))
                {
                    return(SOP.ResultCodes.Error);
                }
                if (SOP.CheckForError(SOP.SetSetting(session, profile, ref new SOP.Setting()
                {
                    version = 77856U,
                    settingID = 284810369U,
                    u32CurrentValue = 17U
                })))
                {
                    return(SOP.ResultCodes.Error);
                }
            }
            else if (SOP.CheckForError(status))
            {
                return(SOP.ResultCodes.Error);
            }
            SOP.Profile profileInfo1 = new SOP.Profile();
            profileInfo1.version = 69652U;
            if (SOP.CheckForError(SOP.GetProfileInfo(session, profile, ref profileInfo1)))
            {
                return(SOP.ResultCodes.Error);
            }
            SOP.Application application = new SOP.Application();
            if (!SOP.ContainsApplication(session, profile, profileInfo1, SOP.GetUnicodeString(applicationName.ToLower(CultureInfo.InvariantCulture)), out application))
            {
                application.version      = 147464U;
                application.isPredefined = 0U;
                for (int index = 0; index < 2048; ++index)
                {
                    // ISSUE: reference to a compiler-generated field
                    (&application.appName.FixedElementField)[index] = unicodeString2[index];
                }
                if (SOP.CheckForError(SOP.CreateApplication(session, profile, ref application)) || SOP.CheckForError(SOP.SaveSettings(session)))
                {
                    return(SOP.ResultCodes.Error);
                }
                resultCodes = SOP.ResultCodes.Change;
            }
            num = SOP.DestroySession(session);
            return(resultCodes);
        }