Posts: 1,519
Threads: 107
Joined: Dec 2011
Reputation:
48
07-19-2012, 18:53
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 )
CSHARP Code
using System.IO; using Microsoft.Win32; private string MW3Path() { //this searches the game in the registry (steam) RegistryKey regKey = Registry.CurrentUser; regKey = regKey.OpenSubKey(@"Software\Valve\Steam"); bool canFindSteamPath = false; string steamInstallPath; string MW3Directory = String.Empty; //if the registry key exists then we probably know the MW3 directory if (regKey != null) { steamInstallPath = regKey.GetValue("SteamPath").ToString(); MW3Directory = steamInstallPath + "/steamapps/common/call of duty modern warfare 3"; //this checks if some needed file exists so the mod can be installed, and if all this exists then we found the MW3 directory if (File.Exists(MW3Directory + "/main/iw_00.iwd")) { canFindSteamPath = true; } //if it does not exist, then we did not find it else { canFindSteamPath = false; } } else { canFindSteamPath = false; } //if we cant find the folder automatically, then a folderbrowserdialog shows up if (!canFindSteamPath) { MessageBox.Show("Cant find Steam path, please select the MW3 folder"); FolderBrowserDialog MW3Folder = new FolderBrowserDialog (); DialogResult result = MW3Folder.ShowDialog(); if (result == DialogResult.OK) { MW3Directory = MW3Folder.SelectedPath; } //if the user hits cancel in the folderbrowserdialog then the MW3Directory will be NULL else { MW3Directory = null; } } return MW3Directory; }
Example:
CSHARP Code
private void button1_Click(object sender, EventArgs e) { string MW3Directory = MW3Path(); if (MW3Directory != null) { if (Directory.Exists(MW3Directory)) { MessageBox.Show("Your mw3 directory is " + MW3Directory); } else { MessageBox.Show("Invalid folder"); } } else { MessageBox.Show("You didnt select any folder"); } }
You can remake this for any game
Everyone can use this if you want
Posts: 619
Threads: 30
Joined: Oct 2010
Reputation:
85
07-19-2012, 19:10
(This post was last modified: 07-19-2012, 19:38 by Nukem.)
Seems useful some some
P.S. You forgot to close the registry key (Unless if C# automatically does this?...)
Posts: 1,519
Threads: 107
Joined: Dec 2011
Reputation:
48
(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
Posts: 5,320
Threads: 300
Joined: Feb 2011
Reputation:
149
Not that useful, but might be interesting for lazy people.
+1
Posts: 2,509
Threads: 96
Joined: Nov 2010
Reputation:
38
In theory it could check your HDD if there is a map called "pr0n".
Posts: 3,054
Threads: 268
Joined: Feb 2011
Reputation:
63
Posts: 993
Threads: 86
Joined: Feb 2011
Reputation:
49
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 );
}
}
Posts: 1,519
Threads: 107
Joined: Dec 2011
Reputation:
48
(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?
Posts: 993
Threads: 86
Joined: Feb 2011
Reputation:
49
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 :/
Posts: 3,054
Threads: 268
Joined: Feb 2011
Reputation:
63
|