Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release MW3Path Method (C#)
#1
Tongue 
So this is a method wich just, basically, well what the title says, it says you where MW3 is installed. All is explained in the code and in the end of the post you have an exmaple. All this code is made 99% by me. ( Just searched in google for help Wink )

CSHARP Code
  1. using System.IO;
  2. using Microsoft.Win32;
  3.  
  4. private string MW3Path()
  5. {
  6. //this searches the game in the registry (steam)
  7. RegistryKey regKey = Registry.CurrentUser;
  8. regKey = regKey.OpenSubKey(@"Software\Valve\Steam");
  9. bool canFindSteamPath = false;
  10. string steamInstallPath;
  11. string MW3Directory = String.Empty;
  12. //if the registry key exists then we probably know the MW3 directory
  13. if (regKey != null)
  14. {
  15. steamInstallPath = regKey.GetValue("SteamPath").ToString();
  16. MW3Directory = steamInstallPath + "/steamapps/common/call of duty modern warfare 3";
  17. //this checks if some needed file exists so the mod can be installed, and if all this exists then we found the MW3 directory
  18. if (File.Exists(MW3Directory + "/main/iw_00.iwd")) { canFindSteamPath = true; }
  19. //if it does not exist, then we did not find it
  20. else { canFindSteamPath = false; }
  21. }
  22. else { canFindSteamPath = false; }
  23. //if we cant find the folder automatically, then a folderbrowserdialog shows up
  24. if (!canFindSteamPath)
  25. {
  26. MessageBox.Show("Cant find Steam path, please select the MW3 folder");
  27. FolderBrowserDialog MW3Folder = new FolderBrowserDialog();
  28. DialogResult result = MW3Folder.ShowDialog();
  29. if (result == DialogResult.OK) { MW3Directory = MW3Folder.SelectedPath; }
  30. //if the user hits cancel in the folderbrowserdialog then the MW3Directory will be NULL
  31. else { MW3Directory = null; }
  32. }
  33. return MW3Directory;
  34. }


Example:

CSHARP Code
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. string MW3Directory = MW3Path();
  4. if (MW3Directory != null)
  5. {
  6. if (Directory.Exists(MW3Directory))
  7. {
  8. MessageBox.Show("Your mw3 directory is " + MW3Directory);
  9. }
  10. else
  11. {
  12. MessageBox.Show("Invalid folder");
  13. }
  14. }
  15. else
  16. {
  17. MessageBox.Show("You didnt select any folder");
  18. }
  19. }


You can remake this for any game
Everyone can use this if you want Blush

#2
Seems useful some some

P.S. You forgot to close the registry key (Unless if C# automatically does this?...)
[Image: b_560_95_1.png]

#3
(07-19-2012, 19:10)Nukem Wrote: Seems useful some some, thanks

P.S. You forgot to close the registry key (Unless if C# automatically does this?...)

Hmm I dont really know but im using this in my background changer and I havent seen any problem related with what you are saying Wink

#4
Not that useful, but might be interesting for lazy people.
+1

#5
In theory it could check your HDD if there is a map called "pr0n".

#6
Was already posted
[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]

#7
heres my mfc c++ way with config edit
might be helpfull, lol would never have posted this unless i seen this thread

Code:
BOOL Is64BitWindows()
{
#if defined(_WIN64)
    return TRUE;  // 64-bit programs run only on Win64
#elif defined(_WIN32)
    // 32-bit programs run on both 32-bit and 64-bit Windows
    // so must sniff
    BOOL f64 = FALSE;
    return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
    return FALSE; // Win64 does not support Win16
#endif
}




BOOL IsWow64()
{
    typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

    LPFN_ISWOW64PROCESS fnIsWow64Process;

    BOOL bIsWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            //handle error
        }
    }
    return bIsWow64;
}



void CTokenHackDlg::OnBnClickedButton3()
{

    

    //return;


    
    //HKEY hKey = 0;
    HKEY hKey;
    char m_buf[255] = {0};
    DWORD dwType = 0;
    DWORD dwBufSize = sizeof(m_buf);

    if(Is64BitWindows())
    {
        const char*    m_subkey = "SOFTWARE\\Wow6432Node\\Valve\\Steam";    

        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,m_subkey, 0, KEY_QUERY_VALUE + KEY_WRITE , &hKey)==ERROR_SUCCESS)
            //if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
        {
            dwType = REG_SZ;
            if( RegQueryValueEx(hKey,TEXT("InstallPath"),0, &dwType, (BYTE*)m_buf, &dwBufSize) == ERROR_SUCCESS)
            {
                //cout << "key value is '" << buf << "'\n";
                // m_editbox.SetWindowText(buf);
            }
            else
                //cout << "can not query for key value\n";
                m_editbox.SetWindowText("failed can not query for key value");
            RegCloseKey(hKey);

        }
        else
            //cout << "Can not open key\n";
            m_editbox.SetWindowText("failed cannot open key");

        //return;

        //m_editbox.SetWindowText(buf);


        CString m_config;
        m_config =  "\\steamapps\\common\\call of duty modern warfare 3\\players2\\config_mp.cfg";
        m_editbox2.SetWindowText(m_buf + m_config);

        // m_editbox.SetWindowText(buf + m_config);

        FILE *m_pFile ;  
        CString m_strLine , m_strText;
        char line [1000] = "" ;  
        m_pFile = fopen ( m_buf + m_config , "r" ) ;
        if ( m_pFile != NULL )
        {      
            // read each line in the file      
            while(fgets(line,sizeof(line),m_pFile) != NULL)  
            {        
                // convert the line to a CString  

                m_strLine = line ;

                m_strLine.Replace(_T("\n"), _T("\r\n"));

                //m_strLine.Replace(_T("//"), _T("")); //how to remove everythigng in a line after //
                //m_strLine.Replace(_T("\n"), _T("\r\n"));        
                // store each line to the text string        
                m_strText += m_strLine ;
            }  
        }    
        // write all the text to the edit box at once  

        m_editbox.SetWindowText(m_strText + "\nseta cg_ScoresPing_MaxBars \"10\" \r\nseta cg_ScoresPing_Interval \"20\" \r\n" );  

        MessageBeep(MB_ICONINFORMATION);
        // close the file  

        fclose ( m_pFile );
    }
    else
    {
        const char* m_subkey = "SOFTWARE\\Valve\\Steam";

        //const char* m_subkey = "SOFTWARE\\Wow6432Node\\Valve\\Steam";

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,m_subkey, 0, KEY_QUERY_VALUE + KEY_WRITE , &hKey)==ERROR_SUCCESS)
    //if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
    {
        dwType = REG_SZ;
        if( RegQueryValueEx(hKey,TEXT("InstallPath"),0, &dwType, (BYTE*)m_buf, &dwBufSize) == ERROR_SUCCESS)
        {
            //cout << "key value is '" << buf << "'\n";
            // m_editbox.SetWindowText(buf);
        }
        else
            //cout << "can not query for key value\n";
            m_editbox.SetWindowText("failed can not query for key value");
        RegCloseKey(hKey);

    }
    else
        //cout << "Can not open key\n";
        m_editbox.SetWindowText("failed cannot open key");

    //return;

    //m_editbox.SetWindowText(buf);
    
    
    CString m_config;
     m_config =  "\\steamapps\\common\\call of duty modern warfare 3\\players2\\config_mp.cfg";
     m_editbox2.SetWindowText(m_buf + m_config);

    // m_editbox.SetWindowText(buf + m_config);

    FILE *m_pFile ;  
    CString m_strLine , m_strText;
    char line [1000] = "" ;  
    m_pFile = fopen ( m_buf + m_config , "r" ) ;
    if ( m_pFile != NULL )
    {      
        // read each line in the file      
        while(fgets(line,sizeof(line),m_pFile) != NULL)  
        {        
            // convert the line to a CString  

            m_strLine = line ;

            m_strLine.Replace(_T("\n"), _T("\r\n"));

            //m_strLine.Replace(_T("//"), _T("")); //how to remove everythigng in a line after //
            //m_strLine.Replace(_T("\n"), _T("\r\n"));        
            // store each line to the text string        
            m_strText += m_strLine ;
        }  
    }    
    // write all the text to the edit box at once  

    m_editbox.SetWindowText(m_strText + "\nseta cg_ScoresPing_MaxBars \"10\" \r\nseta cg_ScoresPing_Interval \"20\" \r\n" );  

     MessageBeep(MB_ICONINFORMATION);
    // close the file  

    fclose ( m_pFile );

    }

}

#8
(07-20-2012, 00:33)rotceh_dnih Wrote: heres my mfc c++ way with config edit
might be helpfull, lol would never have posted this unless i seen this thread

Code:
BOOL Is64BitWindows()
{
#if defined(_WIN64)
    return TRUE;  // 64-bit programs run only on Win64
#elif defined(_WIN32)
    // 32-bit programs run on both 32-bit and 64-bit Windows
    // so must sniff
    BOOL f64 = FALSE;
    return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
    return FALSE; // Win64 does not support Win16
#endif
}




BOOL IsWow64()
{
    typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

    LPFN_ISWOW64PROCESS fnIsWow64Process;

    BOOL bIsWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            //handle error
        }
    }
    return bIsWow64;
}



void CTokenHackDlg::OnBnClickedButton3()
{

    

    //return;


    
    //HKEY hKey = 0;
    HKEY hKey;
    char m_buf[255] = {0};
    DWORD dwType = 0;
    DWORD dwBufSize = sizeof(m_buf);

    if(Is64BitWindows())
    {
        const char*    m_subkey = "SOFTWARE\\Wow6432Node\\Valve\\Steam";    

        if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,m_subkey, 0, KEY_QUERY_VALUE + KEY_WRITE , &hKey)==ERROR_SUCCESS)
            //if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
        {
            dwType = REG_SZ;
            if( RegQueryValueEx(hKey,TEXT("InstallPath"),0, &dwType, (BYTE*)m_buf, &dwBufSize) == ERROR_SUCCESS)
            {
                //cout << "key value is '" << buf << "'\n";
                // m_editbox.SetWindowText(buf);
            }
            else
                //cout << "can not query for key value\n";
                m_editbox.SetWindowText("failed can not query for key value");
            RegCloseKey(hKey);

        }
        else
            //cout << "Can not open key\n";
            m_editbox.SetWindowText("failed cannot open key");

        //return;

        //m_editbox.SetWindowText(buf);


        CString m_config;
        m_config =  "\\steamapps\\common\\call of duty modern warfare 3\\players2\\config_mp.cfg";
        m_editbox2.SetWindowText(m_buf + m_config);

        // m_editbox.SetWindowText(buf + m_config);

        FILE *m_pFile ;  
        CString m_strLine , m_strText;
        char line [1000] = "" ;  
        m_pFile = fopen ( m_buf + m_config , "r" ) ;
        if ( m_pFile != NULL )
        {      
            // read each line in the file      
            while(fgets(line,sizeof(line),m_pFile) != NULL)  
            {        
                // convert the line to a CString  

                m_strLine = line ;

                m_strLine.Replace(_T("\n"), _T("\r\n"));

                //m_strLine.Replace(_T("//"), _T("")); //how to remove everythigng in a line after //
                //m_strLine.Replace(_T("\n"), _T("\r\n"));        
                // store each line to the text string        
                m_strText += m_strLine ;
            }  
        }    
        // write all the text to the edit box at once  

        m_editbox.SetWindowText(m_strText + "\nseta cg_ScoresPing_MaxBars \"10\" \r\nseta cg_ScoresPing_Interval \"20\" \r\n" );  

        MessageBeep(MB_ICONINFORMATION);
        // close the file  

        fclose ( m_pFile );
    }
    else
    {
        const char* m_subkey = "SOFTWARE\\Valve\\Steam";

        //const char* m_subkey = "SOFTWARE\\Wow6432Node\\Valve\\Steam";

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,m_subkey, 0, KEY_QUERY_VALUE + KEY_WRITE , &hKey)==ERROR_SUCCESS)
    //if( RegOpenKey(HKEY_LOCAL_MACHINE,subkey,&hKey) == ERROR_SUCCESS)
    {
        dwType = REG_SZ;
        if( RegQueryValueEx(hKey,TEXT("InstallPath"),0, &dwType, (BYTE*)m_buf, &dwBufSize) == ERROR_SUCCESS)
        {
            //cout << "key value is '" << buf << "'\n";
            // m_editbox.SetWindowText(buf);
        }
        else
            //cout << "can not query for key value\n";
            m_editbox.SetWindowText("failed can not query for key value");
        RegCloseKey(hKey);

    }
    else
        //cout << "Can not open key\n";
        m_editbox.SetWindowText("failed cannot open key");

    //return;

    //m_editbox.SetWindowText(buf);
    
    
    CString m_config;
     m_config =  "\\steamapps\\common\\call of duty modern warfare 3\\players2\\config_mp.cfg";
     m_editbox2.SetWindowText(m_buf + m_config);

    // m_editbox.SetWindowText(buf + m_config);

    FILE *m_pFile ;  
    CString m_strLine , m_strText;
    char line [1000] = "" ;  
    m_pFile = fopen ( m_buf + m_config , "r" ) ;
    if ( m_pFile != NULL )
    {      
        // read each line in the file      
        while(fgets(line,sizeof(line),m_pFile) != NULL)  
        {        
            // convert the line to a CString  

            m_strLine = line ;

            m_strLine.Replace(_T("\n"), _T("\r\n"));

            //m_strLine.Replace(_T("//"), _T("")); //how to remove everythigng in a line after //
            //m_strLine.Replace(_T("\n"), _T("\r\n"));        
            // store each line to the text string        
            m_strText += m_strLine ;
        }  
    }    
    // write all the text to the edit box at once  

    m_editbox.SetWindowText(m_strText + "\nseta cg_ScoresPing_MaxBars \"10\" \r\nseta cg_ScoresPing_Interval \"20\" \r\n" );  

     MessageBeep(MB_ICONINFORMATION);
    // close the file  

    fclose ( m_pFile );

    }

}

code much? Confused

#9
lol well if you take out all the commented out lines + anyhting todo with the editbox and config stuff then it is small but also c# is a much higher language there for is eazer i guess :/

#10
Isn't it that C++?
Anyway, VB is still best Troll
[Image: r212360a129ce9b84444093b6cd2699013a1fbn155.png]



Possibly Related Threads…
Thread Author Replies Views Last Post
Rainbow [Request] Is there any way to send data safe without using OOB method? Nekochan 0 1,943 09-26-2013, 12:42
Last Post: Nekochan
  [News] Infinite food method discovered kokole 4 3,114 01-24-2012, 16:42
Last Post: Rendflex

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.