SHARE
TWEET

Untitled

a guest Mar 27th, 2015 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <windows.h>
  7. #include <time.h>
  8. #include <fmodex/fmod.h>
  9.  
  10. bool v = true;
  11.  
  12. const int PixelsToRead = 9;
  13. int PreviousRandom;
  14. using namespace std;
  15. typedef struct {
  16.         int r;
  17.         int g;
  18.         int b;
  19. } rgbcolor;
  20.  
  21. //################################# Functions for read value from pixels #################################
  22.  
  23. bool approx(rgbcolor pixelRef, rgbcolor pixel, int a){
  24.         if (abs(pixelRef.r - pixel.r) < a && abs(pixelRef.g - pixel.g) < a && abs(pixelRef.b - pixel.b) < a) {
  25.                 return true;
  26.         }
  27.         return false;
  28. }
  29.  
  30. rgbcolor GetPixelColor(HDC hdc1, int x, int y) {
  31.         rgbcolor pixel;
  32.         COLORREF Color = GetPixel(hdc1, x, y);
  33.         pixel.r = GetRValue(Color);
  34.         pixel.g = GetGValue(Color);
  35.         pixel.b = GetBValue(Color);
  36.         return pixel;
  37. }
  38.  
  39. int ColorToBinary(rgbcolor *pixel, int c){
  40.         if (approx(pixel[0], pixel[c], 3)){
  41.                 return 1;
  42.         }
  43.         else {
  44.                 return 0;
  45.         }
  46. }
  47.  
  48. int BinaryToDecimal(int *bit, int nbit){
  49.         int x = 0;
  50.         if (v) cout <<"  ";
  51.         for (int i = nbit-1; i >= 0; i--){
  52.                 if (v) cout <<bit[i];
  53.                 if (bit[i] == 1) x = int( x+pow(2,(nbit-1-i)) );
  54.         }
  55.         if (v) cout <<" -> " << x << "\n";
  56.         return x;
  57. }
  58.  
  59. int GetScreenLink(HDC hdc1){
  60.         if (v) cout <<"Reading " << PixelsToRead << " pixels plus one for the reference\n  ";
  61.         rgbcolor pixel[PixelsToRead+1];
  62.         for (int i = 0; i <= 9; i++){
  63.                 pixel[i] = GetPixelColor(hdc1, i, 0);
  64.         }
  65.         if (v) cout <<"Converting pixels to binary number\n";
  66.         int bitT[PixelsToRead];
  67.         for (int i = 0; i < PixelsToRead; i++){
  68.                 bitT[i] = ColorToBinary(pixel, i+1);
  69.         }
  70.         return BinaryToDecimal(bitT, PixelsToRead);
  71. }
  72.  
  73. //####################################### Functions for play music #######################################
  74.  
  75. char *GetMapFolder(int n) {
  76.         if (n == 2) return ".\\Music\\Daggerfall\\Glenumbra\\";
  77.         if (n == 4) return ".\\Music\\Daggerfall\\Stormhaven\\";
  78.         if (n == 5) return ".\\Music\\Daggerfall\\Rivenspire\\";
  79.         if (n == 9) return ".\\Music\\Ebonheart\\Stonefalls\\";
  80.         if (n == 11) return ".\\Music\\Ebonheart\\Deshaan\\";
  81.         if (n == 12) return ".\\Music\\Aldmeri\\Malabal Tor\\";
  82.         if (n == 15) return ".\\Music\\Daggerfall\\Bangkorai\\";
  83.         if (n == 16) return ".\\Music\\Ebonheart\\Eastmarch\\";
  84.         if (n == 17) return ".\\Music\\Ebonheart\\The Rift\\";
  85.         if (n == 18) return ".\\Music\\Daggerfall\\Alik'r Desert\\";
  86.         if (n == 19) return ".\\Music\\Aldmeri\\Greenshade\\";
  87.         if (n == 20) return ".\\Music\\Ebonheart\\Shadowfen\\";
  88.         if (n == 38) return ".\\Music\\Common\\Cyrodiil\\";
  89.         if (n == 110) return ".\\Music\\Ebonheart\\Bleakrock Isle\\";
  90.         if (n == 111) return ".\\Music\\Ebonheart\\Bal Foyen\\";
  91.         if (n == 155) return ".\\Music\\Common\\Coldharbour\\";
  92.         if (n == 179) return ".\\Music\\Aldmeri\\Auridon\\";
  93.         if (n == 180) return ".\\Music\\Aldmeri\\Reaper's March\\";
  94.         if (n == 181) return ".\\Music\\Aldmeri\\Grahtwood\\";
  95.         if (n == 294) return ".\\Music\\Daggerfall\\Betnikh\\";
  96.         if (n == 295) return ".\\Music\\Aldmeri\\Khenarthi's Roost\\";
  97.         if (n == 480) return ".\\Music\\Common\\Battle\\";
  98.         if (n == 481) return ".\\Music\\Common\\EPIC\\";
  99.         return ".\\Music\\Common\\Dungeon\\";
  100. }
  101.  
  102. char *SelectRandomTrack(int mapID, string playlistName){
  103.         char* MapFolder = GetMapFolder(mapID);
  104.         string Playlist = MapFolder + playlistName;
  105.  
  106.         string audioFile[255];
  107.         int audioFileNumber = 0;
  108.  
  109.         ifstream fichier(Playlist, ios::in);
  110.         if (fichier)
  111.         {
  112.                 string ligne;
  113.                 while (getline(fichier, ligne))
  114.                 {
  115.                         if (ligne.find("#") == string::npos)
  116.                         {
  117.                                 audioFile[audioFileNumber] = ligne;
  118.                                 audioFileNumber++;
  119.                         }
  120.  
  121.                 }
  122.                 fichier.close();
  123.         }
  124.         else {
  125.                 cerr << "Error : Can't open " << Playlist << "\n" << endl;
  126.                 Sleep(5000);
  127.                 return "*error*";
  128.         }
  129.         int random = rand() % audioFileNumber;
  130.         while (random == PreviousRandom && audioFileNumber > 1) {
  131.                 random = rand() % audioFileNumber;
  132.         }
  133.         PreviousRandom = random;
  134.         string S_FiletoPlay = audioFile[random];
  135.         char FileToPlay[1024];
  136.         strcpy(FileToPlay, S_FiletoPlay.c_str());
  137.  
  138.         return FileToPlay;
  139. }
  140.  
  141. //################################################# MAIN #################################################
  142.  
  143. int _tmain(int argc, _TCHAR* argv[])
  144. {
  145.         HDC hdc1 = ::GetDC(0);
  146.         FMOD_SYSTEM *fsystem;
  147.         FMOD_SOUND *music;
  148.         FMOD_RESULT result;
  149.         FMOD_CHANNEL *channel;
  150.         FMOD_System_Create(&fsystem);
  151.         FMOD_System_Init(fsystem, 1, FMOD_INIT_NORMAL, NULL);
  152.  
  153.         srand(time(NULL));
  154.         unsigned int length;
  155.         int mapID, time, CheckID;
  156.         float tmpVolume;
  157.         int Intvolume = GetPrivateProfileInt(L"General", L"volume", 5, L".\\ESO-CMP.ini");
  158.         int useEsoLauncher = GetPrivateProfileInt(L"General", L"useEsoLauncher", 0, L".\\ESO-CMP.ini");
  159.         float volume = (float)Intvolume / 10;
  160.         if (v) cout <<"Volume : "  << volume << "\n";
  161.         if (useEsoLauncher == 1) {
  162.                 system("ESOLauncher.exe");
  163.         }
  164.         else {
  165.                 system("eso.exe");
  166.         }
  167.        
  168.         cout <<"Connecting to ScreenLink...\n";
  169.         read:
  170.         // Read map ID
  171.         mapID = GetScreenLink(hdc1);
  172.         while (mapID > 300 && GetPixelColor(hdc1, 0, 0).r < 220 && mapID != 480 && mapID != 481) {
  173.                 Sleep(2000);
  174.                 mapID = GetScreenLink(hdc1);
  175.         }
  176.         // select a track corresponding to the map
  177.         char *FileToPlay = SelectRandomTrack(mapID, "playlist.m3u");
  178.         // play selected music
  179.         result = FMOD_System_CreateSound(fsystem, FileToPlay, FMOD_SOFTWARE | FMOD_2D, 0, &music); // | FMOD_CREATESTREAM
  180.         if (result != FMOD_OK) {
  181.                 cout <<"Error : Can't open " << FileToPlay << "\n";
  182.                 Sleep(5000);
  183.                 goto read;
  184.         }
  185.         FMOD_Sound_SetLoopCount(music, 1);
  186.         FMOD_System_PlaySound(fsystem, FMOD_CHANNEL_FREE, music, 0, NULL);
  187.         FMOD_System_GetChannel(fsystem, 0, &channel);
  188.         FMOD_Channel_SetVolume(channel, volume );
  189.         // Get music length
  190.         FMOD_Sound_GetLength(music, &length, FMOD_TIMEUNIT_MS);
  191.         // wait until the music is finished...
  192.         time = (int)length + 1000;
  193.         cout <<"Playing " << FileToPlay << " for " << (time - 5000) / 1000 << "s\n";
  194.         // and check if mapID change during the track
  195.         Sleep(50000);
  196.         CheckID = GetScreenLink(hdc1);
  197.         while (mapID == CheckID && time > 0) {
  198.                 Sleep(2000);
  199.                 time = time - 2000;
  200.                 CheckID = GetScreenLink(hdc1);
  201.         }
  202.         tmpVolume = volume;
  203.         // Reduce volume before release
  204.         while (tmpVolume >= 0){
  205.                 tmpVolume = tmpVolume - (volume / 10);
  206.                 FMOD_Channel_SetVolume(channel, tmpVolume);
  207.                 Sleep(500);
  208.         }
  209.         FMOD_Sound_Release(music);
  210.         Sleep(1000);
  211.         goto read;
  212.  
  213.         FMOD_System_Close(fsystem);
  214.         FMOD_System_Release(fsystem);
  215. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top