From b3d0fcb2083143dc21c751adafd2523c3555e5d2 Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 13 Mar 2013 19:35:20 +0100 Subject: - some more safety checks in the ini-limit removal code - some code cleanup and minor bug fixes based on results from static code analysis - added naemfilter for the esp list - bsa changes are now stored automatically but delayed by up to 0.5 seconds (for performance reasons) - bugfix: buffer overrun when certain functions are called with empty file names - bugfix: reroute for the ini-limit fix was placed in the data segment - bugfix: mod list got mixed up when the mod directory was changed externally - bugfix: plugins.txt reroute on skyrim didn't work on winXP - bugfix: MO could become unresponsive if the tutorial script couldn't be interpreted --- src/shared/skyriminfo.cpp | 12 +++++++++++- src/shared/skyriminfo.h | 4 ++++ src/shared/util.cpp | 7 +++++++ src/shared/util.h | 3 ++- 4 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/shared') diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index 6302cef3..26395e67 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -27,6 +27,7 @@ along with Mod Organizer. If not, see . #include "error_report.h" #define WIN32_LEAN_AND_MEAN #include +#include #include namespace MOShared { @@ -36,6 +37,11 @@ SkyrimInfo::SkyrimInfo(const std::wstring &omoDirectory, const std::wstring &gam : GameInfo(omoDirectory, gameDirectory) { identifyMyGamesDirectory(L"skyrim"); + + wchar_t appDataPath[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath))) { + m_AppData = appDataPath; + } } bool SkyrimInfo::identifyGame(const std::wstring &searchPath) @@ -258,8 +264,12 @@ bool SkyrimInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPa } } +if (_wcsicmp(fileName, L"plugins.txt") == 0) { + log("plugins.txt expected in \"%ls\", got \"%ls\"", m_AppData.c_str(), fullPath); +} + if ((_wcsicmp(fileName, L"plugins.txt") == 0) && - (wcsstr(fullPath, L"AppData") != NULL)){ + (m_AppData.empty() || (StrStrIW(fullPath, m_AppData.c_str()) != NULL))) { return true; } diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index b12a5d58..024d0395 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -97,6 +97,10 @@ private: static bool identifyGame(const std::wstring &searchPath); +private: + + std::wstring m_AppData; + }; } // namespace MOShared diff --git a/src/shared/util.cpp b/src/shared/util.cpp index a6378a74..e61ae8a6 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -79,6 +79,13 @@ std::string &ToLower(std::string &text) return text; } +std::string ToLower(const std::string &text) +{ + std::string temp = text; + + std::transform(temp.begin(), temp.end(), temp.begin(), tolower); + return temp; +} std::wstring &ToLower(std::wstring &text) { diff --git a/src/shared/util.h b/src/shared/util.h index 9c59f6db..80983cb0 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -39,8 +39,9 @@ std::string ToString(const std::wstring &source, bool utf8); std::wstring ToWString(const std::string &source, bool utf8); std::string &ToLower(std::string &text); -std::wstring &ToLower(std::wstring &text); +std::string ToLower(const std::string &text); +std::wstring &ToLower(std::wstring &text); std::wstring ToLower(const std::wstring &text); VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName); -- cgit v1.3.1 From 8b31996525de06bcb0ff519be42a732c85f532c9 Mon Sep 17 00:00:00 2001 From: Tannin Date: Mon, 18 Mar 2013 20:03:46 +0100 Subject: - bugfix: invalid ini file name when creating profile for oblivion from default settings - bugfix: archives.txt file was potentially not generated if there were no bsas - bugfix: static __declspec(thread) declaration causes crashes in windows versions before vista - logger class in hook.dll now tries alternative names for the log file if it can't access the regular file - path-environment variable for mo-spawned processes now contains the path to MO, in case the hook.dll needs to find the msvc-dlls - stack-search in ini-limit hack now starts searching on local stack. This should find the right stack position for the hack more reliable --- src/mainwindow.cpp | 5 +++++ src/mainwindow.h | 1 + src/shared/inject.cpp | 1 + src/shared/oblivioninfo.cpp | 1 - src/shared/skyriminfo.cpp | 4 ---- src/spawn.cpp | 23 +++++++++++++++++++++++ 6 files changed, 30 insertions(+), 5 deletions(-) (limited to 'src/shared') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2d00580e..5bc339d3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -528,6 +528,11 @@ bool MainWindow::saveCurrentLists() reportError(tr("failed to save load order: %1").arg(e.what())); } + // ensure the archive list exists + if (!QFile::exists(m_CurrentProfile->getArchivesFileName())) { + saveArchiveList(); + } + return true; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 075c6247..89e29685 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -171,6 +171,7 @@ private: void installMod(const QString &fileName); void installMod(); bool modifyExecutablesDialog(); + void modOpenNext(); void displayModInformation(ModInfo::Ptr modInfo, unsigned int index, int tab); void displayModInformation(int row, int tab = 0); void testExtractBSA(int modIndex); diff --git a/src/shared/inject.cpp b/src/shared/inject.cpp index 9fea7fc8..5a111c4a 100644 --- a/src/shared/inject.cpp +++ b/src/shared/inject.cpp @@ -136,6 +136,7 @@ void injectDLL(HANDLE processHandle, HANDLE threadHandle, const std::string &dll (written != sizeof(stubLocal))) { throw windows_error("failed to write stub to target process"); } + // finally, make the stub the new next thing for the thread to execute threadContext.Eip = (ULONG)stubRemote; if (::SetThreadContext(threadHandle, &threadContext) == 0) { diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp index 1c714072..73e841a7 100644 --- a/src/shared/oblivioninfo.cpp +++ b/src/shared/oblivioninfo.cpp @@ -134,7 +134,6 @@ void OblivionInfo::createProfile(const std::wstring &directory, bool useDefaults if (!FileExists(target.str())) { std::wostringstream source; - source << getMyGamesDirectory() << L"\\Oblivion\\oblivion.ini"; if (useDefaults) { source << getGameDirectory() << L"\\oblivion_default.ini"; } else { diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index 26395e67..1c13effb 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -264,10 +264,6 @@ bool SkyrimInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPa } } -if (_wcsicmp(fileName, L"plugins.txt") == 0) { - log("plugins.txt expected in \"%ls\", got \"%ls\"", m_AppData.c_str(), fullPath); -} - if ((_wcsicmp(fileName, L"plugins.txt") == 0) && (m_AppData.empty() || (StrStrIW(fullPath, m_AppData.c_str()) != NULL))) { return true; diff --git a/src/spawn.cpp b/src/spawn.cpp index 39bd2af9..e83c8e21 100644 --- a/src/spawn.cpp +++ b/src/spawn.cpp @@ -20,6 +20,7 @@ along with Mod Organizer. If not, see . #include "spawn.h" #include "report.h" #include "utility.h" +#include #include #include #include @@ -31,6 +32,8 @@ using namespace MOBase; using namespace MOShared; +static const int BUFSIZE = 4096; + bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool suspended, HANDLE& processHandle, HANDLE& threadHandle) { STARTUPINFO si; @@ -44,7 +47,25 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus } else { commandLine = new wchar_t[length]; _snwprintf(commandLine, length, L"\"%ls\"", binary); + } + QString moPath = QCoreApplication::applicationDirPath(); + + boost::scoped_array oldPath(new TCHAR[BUFSIZE]); + DWORD offset = ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), BUFSIZE); + if (offset > BUFSIZE) { + oldPath.reset(new TCHAR[offset]); + ::GetEnvironmentVariable(TEXT("PATH"), oldPath.get(), offset); + } + + { + boost::scoped_array newPath(new TCHAR[offset + moPath.length() + 2]); + _tcsncpy(newPath.get(), oldPath.get(), offset - 1); + newPath.get()[offset - 1] = L'\0'; + _tcsncat(newPath.get(), TEXT(";"), 1); + _tcsncat(newPath.get(), ToWString(QDir::toNativeSeparators(moPath)).c_str(), moPath.length()); + + ::SetEnvironmentVariable(TEXT("PATH"), newPath.get()); } PROCESS_INFORMATION pi; @@ -58,6 +79,8 @@ bool spawn(LPCWSTR binary, LPCWSTR arguments, LPCWSTR currentDirectory, bool sus &si, &pi // startup and process information ); + ::SetEnvironmentVariable(TEXT("PATH"), oldPath.get()); + delete [] commandLine; if (!success) { -- cgit v1.3.1