Skip to content

Commit acd3887

Browse files
authored
Add files via upload
1 parent 4ca05d5 commit acd3887

File tree

2 files changed

+56
-22
lines changed

2 files changed

+56
-22
lines changed

ReadMe.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
Silent's ASI Loader 1.3
1+
Silent's ASI Loader 1.4
22
Source code
33

44

55
CREDITS & LICENSE
66

77
Firstly, thanks to NTAuthority for sharing his code snippet, and also for Stanislav "listener" Golovin for sharing his
88
ASI Loader source, which acted as a base for my version of the tool.
9-
As the following tool is open source, it's under the Silent's License.
9+
Modified by fastman92, added loading of ASI plugins according to their names alphabetically.
10+
As the following tool is open source (source is NOT included in this package), it's under the Silent's License.
1011
It means that the source code is for learning purposes, as all source code is. You may only use it for your own projects
1112
but NOT to recreate or build on the original work.
1213

vorbisFile.cpp

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
// Written by Silent
33
// Based on ASI Loader by Stanislav "listener" Golovin
44
// Initialization part made by NTAuthority
5+
// Modified by fastman92 to add sorting of ASI files by their name
56

67
#include <windows.h>
78
#include <iostream>
89

10+
#include <algorithm>
11+
#include <deque>
12+
#include <string>
13+
914
BYTE originalCode[5];
1015
BYTE* originalEP = 0;
1116
HINSTANCE hExecutableInstance;
@@ -126,9 +131,18 @@ void ExcludedEntriesListFree(ExcludedEntriesList* list)
126131
}
127132
}
128133

129-
void FindFiles(WIN32_FIND_DATA* fd, ExcludedEntriesList* list)
134+
struct tPluginToBeLoaded
135+
{
136+
std::string dirPath;
137+
std::string pluginFilename;
138+
};
139+
140+
void FindFiles(std::deque<tPluginToBeLoaded>& pluginPaths, WIN32_FIND_DATAA* fd, ExcludedEntriesList* list)
130141
{
131-
HANDLE asiFile = FindFirstFile ("*.asi", fd);
142+
char curDir[MAX_PATH];
143+
GetCurrentDirectoryA(_countof(curDir), curDir);
144+
145+
HANDLE asiFile = FindFirstFileA ("*.asi", fd);
132146
if (asiFile != INVALID_HANDLE_VALUE)
133147
{
134148

@@ -143,19 +157,25 @@ void FindFiles(WIN32_FIND_DATA* fd, ExcludedEntriesList* list)
143157
(fd->cFileName[pos-2] == 's' || fd->cFileName[pos-2] == 'S') &&
144158
(fd->cFileName[pos-1] == 'i' || fd->cFileName[pos-1] == 'I'))
145159
{
146-
if ( !list || !ExcludedEntriesListHasEntry(list, fd->cFileName) )
147-
LoadLibrary (fd->cFileName);
160+
if (!list || !ExcludedEntriesListHasEntry(list, fd->cFileName))
161+
{
162+
tPluginToBeLoaded plugin;
163+
plugin.dirPath = curDir;
164+
plugin.pluginFilename = fd->cFileName;
165+
166+
pluginPaths.push_back(plugin);
167+
}
148168
}
149169
}
150170

151-
} while (FindNextFile (asiFile, fd));
171+
} while (FindNextFileA (asiFile, fd));
152172
FindClose (asiFile);
153173
}
154174
}
155175

156176
void LoadPlugins()
157177
{
158-
HMODULE vorbisHooked = LoadLibrary ("vorbishooked");
178+
HMODULE vorbisHooked = LoadLibraryA ("vorbishooked");
159179
if ( vorbisHooked )
160180
{
161181
__ov_open_callbacks = GetProcAddress (vorbisHooked, "ov_open_callbacks");
@@ -168,14 +188,16 @@ void LoadPlugins()
168188
__ov_time_seek_page = GetProcAddress (vorbisHooked, "ov_time_seek_page");
169189

170190
// Regular ASI Loader
171-
WIN32_FIND_DATA fd;
191+
WIN32_FIND_DATAA fd;
192+
std::deque<tPluginToBeLoaded> pluginsToBeLoaded;
193+
172194
char moduleName[MAX_PATH];
173195
char preparedPath[128]; // stores scripts\*exename*\settings.ini
174196
char* tempPointer;
175197
int nWantsToLoadPlugins;
176198
int nThatExeWantsPlugins;
177199

178-
GetModuleFileName(NULL, moduleName, MAX_PATH);
200+
GetModuleFileNameA(NULL, moduleName, MAX_PATH);
179201
tempPointer = strrchr(moduleName, '.');
180202
*tempPointer = '\0';
181203

@@ -185,9 +207,9 @@ void LoadPlugins()
185207
strcat(preparedPath, "\\settings.ini");
186208

187209
// Before we load any ASI files, let's see if user wants to do it at all
188-
nWantsToLoadPlugins = GetPrivateProfileInt("globalsets", "loadplugins", TRUE, "scripts\\global.ini");
210+
nWantsToLoadPlugins = GetPrivateProfileIntA("globalsets", "loadplugins", TRUE, "scripts\\global.ini");
189211
// Or perhaps this EXE wants to override global settings?
190-
nThatExeWantsPlugins = GetPrivateProfileInt("exclusivesets", "loadplugins", -1, preparedPath);
212+
nThatExeWantsPlugins = GetPrivateProfileIntA("exclusivesets", "loadplugins", -1, preparedPath);
191213

192214
if ( nThatExeWantsPlugins ) // Will not process only if this EXE wishes not to load anything but its exclusive plugins
193215
{
@@ -223,17 +245,17 @@ void LoadPlugins()
223245

224246
fclose(iniFile);
225247
}
226-
FindFiles(&fd, &excludes);
227-
if ( SetCurrentDirectory("scripts\\") )
248+
FindFiles(pluginsToBeLoaded, &fd, &excludes);
249+
if ( SetCurrentDirectoryA("scripts\\") )
228250
{
229-
FindFiles(&fd, &excludes);
230-
if ( SetCurrentDirectory(tempPointer + 1) )
251+
FindFiles(pluginsToBeLoaded, &fd, &excludes);
252+
if ( SetCurrentDirectoryA(tempPointer + 1) )
231253
{
232-
FindFiles(&fd, NULL); // Exclusive plugins are not being excluded
233-
SetCurrentDirectory("..\\..\\");
254+
FindFiles(pluginsToBeLoaded, &fd, NULL); // Exclusive plugins are not being excluded
255+
SetCurrentDirectoryA("..\\..\\");
234256
}
235257
else
236-
SetCurrentDirectory("..\\");
258+
SetCurrentDirectoryA("..\\");
237259
}
238260

239261
// Free the remaining excludes
@@ -246,12 +268,23 @@ void LoadPlugins()
246268
// We need to cut settings.ini from the path again
247269
tempPointer = strrchr(preparedPath, '\\');
248270
tempPointer[1] = '\0';
249-
if ( SetCurrentDirectory(preparedPath) )
271+
if ( SetCurrentDirectoryA(preparedPath) )
250272
{
251-
FindFiles(&fd, NULL);
252-
SetCurrentDirectory("..\\..\\");
273+
FindFiles(pluginsToBeLoaded, &fd, NULL);
274+
SetCurrentDirectoryA("..\\..\\");
253275
}
254276
}
277+
278+
// Load ASI plugins
279+
std::sort(pluginsToBeLoaded.begin(), pluginsToBeLoaded.end(), [](tPluginToBeLoaded& a, tPluginToBeLoaded& b) { return a.pluginFilename < b.pluginFilename; });
280+
281+
for (auto& plugin : pluginsToBeLoaded)
282+
{
283+
char pluginPath[MAX_PATH];
284+
sprintf(pluginPath, "%s\\%s", plugin.dirPath.c_str(), plugin.pluginFilename.c_str());
285+
// MessageBoxA(NULL, pluginPath, "Test", MB_OK);
286+
LoadLibraryA(pluginPath);
287+
}
255288
}
256289

257290
// Unprotect the module NOW (CLEO 4.1.1.30f crash fix)

0 commit comments

Comments
 (0)