diff --git a/ReadMe.txt b/ReadMe.txt index d3f4906..b89ba68 100644 --- a/ReadMe.txt +++ b/ReadMe.txt @@ -1,4 +1,4 @@ -Silent's ASI Loader 1.3 +Silent's ASI Loader 1.4 Source code @@ -6,7 +6,8 @@ CREDITS & LICENSE Firstly, thanks to NTAuthority for sharing his code snippet, and also for Stanislav "listener" Golovin for sharing his ASI Loader source, which acted as a base for my version of the tool. - As the following tool is open source, it's under the Silent's License. + Modified by fastman92, added loading of ASI plugins according to their names alphabetically. + As the following tool is open source (source is NOT included in this package), it's under the Silent's License. It means that the source code is for learning purposes, as all source code is. You may only use it for your own projects but NOT to recreate or build on the original work. diff --git a/vorbisFile.cpp b/vorbisFile.cpp index 1e06e94..2b3862d 100644 --- a/vorbisFile.cpp +++ b/vorbisFile.cpp @@ -2,10 +2,15 @@ // Written by Silent // Based on ASI Loader by Stanislav "listener" Golovin // Initialization part made by NTAuthority +// Modified by fastman92 to add sorting of ASI files by their name #include #include +#include +#include +#include + BYTE originalCode[5]; BYTE* originalEP = 0; HINSTANCE hExecutableInstance; @@ -126,9 +131,18 @@ void ExcludedEntriesListFree(ExcludedEntriesList* list) } } -void FindFiles(WIN32_FIND_DATA* fd, ExcludedEntriesList* list) +struct tPluginToBeLoaded +{ + std::string dirPath; + std::string pluginFilename; +}; + +void FindFiles(std::deque& pluginPaths, WIN32_FIND_DATAA* fd, ExcludedEntriesList* list) { - HANDLE asiFile = FindFirstFile ("*.asi", fd); + char curDir[MAX_PATH]; + GetCurrentDirectoryA(_countof(curDir), curDir); + + HANDLE asiFile = FindFirstFileA ("*.asi", fd); if (asiFile != INVALID_HANDLE_VALUE) { @@ -143,19 +157,25 @@ void FindFiles(WIN32_FIND_DATA* fd, ExcludedEntriesList* list) (fd->cFileName[pos-2] == 's' || fd->cFileName[pos-2] == 'S') && (fd->cFileName[pos-1] == 'i' || fd->cFileName[pos-1] == 'I')) { - if ( !list || !ExcludedEntriesListHasEntry(list, fd->cFileName) ) - LoadLibrary (fd->cFileName); + if (!list || !ExcludedEntriesListHasEntry(list, fd->cFileName)) + { + tPluginToBeLoaded plugin; + plugin.dirPath = curDir; + plugin.pluginFilename = fd->cFileName; + + pluginPaths.push_back(plugin); + } } } - } while (FindNextFile (asiFile, fd)); + } while (FindNextFileA (asiFile, fd)); FindClose (asiFile); } } void LoadPlugins() { - HMODULE vorbisHooked = LoadLibrary ("vorbishooked"); + HMODULE vorbisHooked = LoadLibraryA ("vorbishooked"); if ( vorbisHooked ) { __ov_open_callbacks = GetProcAddress (vorbisHooked, "ov_open_callbacks"); @@ -168,14 +188,16 @@ void LoadPlugins() __ov_time_seek_page = GetProcAddress (vorbisHooked, "ov_time_seek_page"); // Regular ASI Loader - WIN32_FIND_DATA fd; + WIN32_FIND_DATAA fd; + std::deque pluginsToBeLoaded; + char moduleName[MAX_PATH]; char preparedPath[128]; // stores scripts\*exename*\settings.ini char* tempPointer; int nWantsToLoadPlugins; int nThatExeWantsPlugins; - GetModuleFileName(NULL, moduleName, MAX_PATH); + GetModuleFileNameA(NULL, moduleName, MAX_PATH); tempPointer = strrchr(moduleName, '.'); *tempPointer = '\0'; @@ -185,9 +207,9 @@ void LoadPlugins() strcat(preparedPath, "\\settings.ini"); // Before we load any ASI files, let's see if user wants to do it at all - nWantsToLoadPlugins = GetPrivateProfileInt("globalsets", "loadplugins", TRUE, "scripts\\global.ini"); + nWantsToLoadPlugins = GetPrivateProfileIntA("globalsets", "loadplugins", TRUE, "scripts\\global.ini"); // Or perhaps this EXE wants to override global settings? - nThatExeWantsPlugins = GetPrivateProfileInt("exclusivesets", "loadplugins", -1, preparedPath); + nThatExeWantsPlugins = GetPrivateProfileIntA("exclusivesets", "loadplugins", -1, preparedPath); if ( nThatExeWantsPlugins ) // Will not process only if this EXE wishes not to load anything but its exclusive plugins { @@ -223,17 +245,17 @@ void LoadPlugins() fclose(iniFile); } - FindFiles(&fd, &excludes); - if ( SetCurrentDirectory("scripts\\") ) + FindFiles(pluginsToBeLoaded, &fd, &excludes); + if ( SetCurrentDirectoryA("scripts\\") ) { - FindFiles(&fd, &excludes); - if ( SetCurrentDirectory(tempPointer + 1) ) + FindFiles(pluginsToBeLoaded, &fd, &excludes); + if ( SetCurrentDirectoryA(tempPointer + 1) ) { - FindFiles(&fd, NULL); // Exclusive plugins are not being excluded - SetCurrentDirectory("..\\..\\"); + FindFiles(pluginsToBeLoaded, &fd, NULL); // Exclusive plugins are not being excluded + SetCurrentDirectoryA("..\\..\\"); } else - SetCurrentDirectory("..\\"); + SetCurrentDirectoryA("..\\"); } // Free the remaining excludes @@ -246,12 +268,23 @@ void LoadPlugins() // We need to cut settings.ini from the path again tempPointer = strrchr(preparedPath, '\\'); tempPointer[1] = '\0'; - if ( SetCurrentDirectory(preparedPath) ) + if ( SetCurrentDirectoryA(preparedPath) ) { - FindFiles(&fd, NULL); - SetCurrentDirectory("..\\..\\"); + FindFiles(pluginsToBeLoaded, &fd, NULL); + SetCurrentDirectoryA("..\\..\\"); } } + + // Load ASI plugins + std::sort(pluginsToBeLoaded.begin(), pluginsToBeLoaded.end(), [](tPluginToBeLoaded& a, tPluginToBeLoaded& b) { return a.pluginFilename < b.pluginFilename; }); + + for (auto& plugin : pluginsToBeLoaded) + { + char pluginPath[MAX_PATH]; + sprintf(pluginPath, "%s\\%s", plugin.dirPath.c_str(), plugin.pluginFilename.c_str()); + // MessageBoxA(NULL, pluginPath, "Test", MB_OK); + LoadLibraryA(pluginPath); + } } // Unprotect the module NOW (CLEO 4.1.1.30f crash fix)