Out.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "Main.h"
  2. #include "../nu/AutoChar.h"
  3. #include "../nu/AutoWide.h"
  4. extern LARGE_INTEGER freq;
  5. Out_Module* out_modules[32] = { 0 };
  6. Out_Module* out_mod = 0;
  7. typedef struct _PLUGINORDER
  8. {
  9. LPCWSTR name;
  10. bool found;
  11. } PLUGINORDER;
  12. static PLUGINORDER preload[] =
  13. {
  14. { L"out_ds.dll", false },
  15. { L"out_wave.dll", false },
  16. { L"out_disk.dll", false }
  17. };
  18. int LoadOutputPlugin(const wchar_t* plugin_filename, int index)
  19. {
  20. wchar_t file[MAX_PATH] = { 0 };
  21. PathCombineW(file, PLUGINDIR, plugin_filename);
  22. HINSTANCE hLib = LoadLibraryW(file);
  23. if ( hLib == NULL )
  24. return index;
  25. Out_Module* (*pr)();
  26. pr = (Out_Module * (__cdecl*)(void)) GetProcAddress(hLib, "winampGetOutModule");
  27. if ( !pr )
  28. return index;
  29. Out_Module* mod = pr();
  30. if ( mod && (mod->version == OUT_VER || mod->version == OUT_VER_U) )
  31. {
  32. AutoChar narrowFn(plugin_filename);
  33. size_t fileNameSize = lstrlenA(narrowFn);
  34. if ( g_safeMode )
  35. {
  36. if ( !(mod->id == 1471482036 || mod->id == 426119909 || mod->id == 203968848) )
  37. {
  38. FreeModule(hLib);
  39. return index;
  40. }
  41. }
  42. mod->hDllInstance = hLib;
  43. mod->hMainWindow = hMainWindow;
  44. mod->id = (intptr_t)GlobalAlloc(GPTR, fileNameSize + 1);
  45. StringCchCopyA((char*)mod->id, fileNameSize + 1, narrowFn);
  46. mod->Init();
  47. out_modules[index] = mod;
  48. return index + 1;
  49. }
  50. return index;
  51. }
  52. void out_init()
  53. {
  54. int index = 0, i = 0, count = sizeof(preload) / sizeof(PLUGINORDER);
  55. for ( ; i < count; i++ ) index = LoadOutputPlugin(preload[i].name, index);
  56. WIN32_FIND_DATAW d = { 0 };
  57. wchar_t dirstr[MAX_PATH] = { 0 };
  58. PathCombineW(dirstr, PLUGINDIR, L"OUT_*.DLL");
  59. HANDLE h = FindFirstFileW(dirstr, &d);
  60. if ( h != INVALID_HANDLE_VALUE )
  61. {
  62. do
  63. {
  64. for ( i = 0; i < count && (preload[i].found || lstrcmpiW(preload[i].name, d.cFileName)); i++ );
  65. if ( i == count ) index = LoadOutputPlugin(d.cFileName, index);
  66. else preload[i].found = true;
  67. } while ( FindNextFileW(h, &d) && index < 31 );
  68. FindClose(h);
  69. }
  70. }
  71. void out_setwnd(void)
  72. {
  73. for ( int x = 0; out_modules[x]; x++ )
  74. {
  75. out_modules[x]->hMainWindow = hMainWindow;
  76. }
  77. }
  78. void out_changed(HINSTANCE hLib, int enabled)
  79. {
  80. typedef void(__cdecl* OutModeChange)(int);
  81. OutModeChange modeChange = (OutModeChange)GetProcAddress(hLib, "winampGetOutModeChange");
  82. if ( modeChange )
  83. {
  84. modeChange(enabled);
  85. }
  86. }
  87. void out_deinit()
  88. {
  89. for ( int x = 0; out_modules[x]; x++ )
  90. {
  91. //HINSTANCE hLib = out_modules[x]->hDllInstance;
  92. out_modules[x]->Quit();
  93. GlobalFree((HGLOBAL)out_modules[x]->id);
  94. out_modules[x]->id = 0;
  95. //FreeLibrary(hLib); // benski> we're just going to let it leak because it might be subclassing
  96. out_modules[x] = 0;
  97. }
  98. }