Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <stdio.h>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <windows.h>
- #include <time.h>
- #include <fmodex/fmod.h>
- bool v = true;
- const int PixelsToRead = 9;
- int PreviousRandom;
- using namespace std;
- typedef struct {
- int r;
- int g;
- int b;
- } rgbcolor;
- //################################# Functions for read value from pixels #################################
- bool approx(rgbcolor pixelRef, rgbcolor pixel, int a){
- if (abs(pixelRef.r - pixel.r) < a && abs(pixelRef.g - pixel.g) < a && abs(pixelRef.b - pixel.b) < a) {
- return true;
- }
- return false;
- }
- rgbcolor GetPixelColor(HDC hdc1, int x, int y) {
- rgbcolor pixel;
- COLORREF Color = GetPixel(hdc1, x, y);
- pixel.r = GetRValue(Color);
- pixel.g = GetGValue(Color);
- pixel.b = GetBValue(Color);
- return pixel;
- }
- int ColorToBinary(rgbcolor *pixel, int c){
- if (approx(pixel[0], pixel[c], 3)){
- return 1;
- }
- else {
- return 0;
- }
- }
- int BinaryToDecimal(int *bit, int nbit){
- int x = 0;
- if (v) cout <<" ";
- for (int i = nbit-1; i >= 0; i--){
- if (v) cout <<bit[i];
- if (bit[i] == 1) x = int( x+pow(2,(nbit-1-i)) );
- }
- if (v) cout <<" -> " << x << "\n";
- return x;
- }
- int GetScreenLink(HDC hdc1){
- if (v) cout <<"Reading " << PixelsToRead << " pixels plus one for the reference\n ";
- rgbcolor pixel[PixelsToRead+1];
- for (int i = 0; i <= 9; i++){
- pixel[i] = GetPixelColor(hdc1, i, 0);
- }
- if (v) cout <<"Converting pixels to binary number\n";
- int bitT[PixelsToRead];
- for (int i = 0; i < PixelsToRead; i++){
- bitT[i] = ColorToBinary(pixel, i+1);
- }
- return BinaryToDecimal(bitT, PixelsToRead);
- }
- //####################################### Functions for play music #######################################
- char *GetMapFolder(int n) {
- if (n == 2) return ".\\Music\\Daggerfall\\Glenumbra\\";
- if (n == 4) return ".\\Music\\Daggerfall\\Stormhaven\\";
- if (n == 5) return ".\\Music\\Daggerfall\\Rivenspire\\";
- if (n == 9) return ".\\Music\\Ebonheart\\Stonefalls\\";
- if (n == 11) return ".\\Music\\Ebonheart\\Deshaan\\";
- if (n == 12) return ".\\Music\\Aldmeri\\Malabal Tor\\";
- if (n == 15) return ".\\Music\\Daggerfall\\Bangkorai\\";
- if (n == 16) return ".\\Music\\Ebonheart\\Eastmarch\\";
- if (n == 17) return ".\\Music\\Ebonheart\\The Rift\\";
- if (n == 18) return ".\\Music\\Daggerfall\\Alik'r Desert\\";
- if (n == 19) return ".\\Music\\Aldmeri\\Greenshade\\";
- if (n == 20) return ".\\Music\\Ebonheart\\Shadowfen\\";
- if (n == 38) return ".\\Music\\Common\\Cyrodiil\\";
- if (n == 110) return ".\\Music\\Ebonheart\\Bleakrock Isle\\";
- if (n == 111) return ".\\Music\\Ebonheart\\Bal Foyen\\";
- if (n == 155) return ".\\Music\\Common\\Coldharbour\\";
- if (n == 179) return ".\\Music\\Aldmeri\\Auridon\\";
- if (n == 180) return ".\\Music\\Aldmeri\\Reaper's March\\";
- if (n == 181) return ".\\Music\\Aldmeri\\Grahtwood\\";
- if (n == 294) return ".\\Music\\Daggerfall\\Betnikh\\";
- if (n == 295) return ".\\Music\\Aldmeri\\Khenarthi's Roost\\";
- if (n == 480) return ".\\Music\\Common\\Battle\\";
- if (n == 481) return ".\\Music\\Common\\EPIC\\";
- return ".\\Music\\Common\\Dungeon\\";
- }
- char *SelectRandomTrack(int mapID, string playlistName){
- char* MapFolder = GetMapFolder(mapID);
- string Playlist = MapFolder + playlistName;
- string audioFile[255];
- int audioFileNumber = 0;
- ifstream fichier(Playlist, ios::in);
- if (fichier)
- {
- string ligne;
- while (getline(fichier, ligne))
- {
- if (ligne.find("#") == string::npos)
- {
- audioFile[audioFileNumber] = ligne;
- audioFileNumber++;
- }
- }
- fichier.close();
- }
- else {
- cerr << "Error : Can't open " << Playlist << "\n" << endl;
- Sleep(5000);
- return "*error*";
- }
- int random = rand() % audioFileNumber;
- while (random == PreviousRandom && audioFileNumber > 1) {
- random = rand() % audioFileNumber;
- }
- PreviousRandom = random;
- string S_FiletoPlay = audioFile[random];
- char FileToPlay[1024];
- strcpy(FileToPlay, S_FiletoPlay.c_str());
- return FileToPlay;
- }
- //################################################# MAIN #################################################
- int _tmain(int argc, _TCHAR* argv[])
- {
- HDC hdc1 = ::GetDC(0);
- FMOD_SYSTEM *fsystem;
- FMOD_SOUND *music;
- FMOD_RESULT result;
- FMOD_CHANNEL *channel;
- FMOD_System_Create(&fsystem);
- FMOD_System_Init(fsystem, 1, FMOD_INIT_NORMAL, NULL);
- srand(time(NULL));
- unsigned int length;
- int mapID, time, CheckID;
- float tmpVolume;
- int Intvolume = GetPrivateProfileInt(L"General", L"volume", 5, L".\\ESO-CMP.ini");
- int useEsoLauncher = GetPrivateProfileInt(L"General", L"useEsoLauncher", 0, L".\\ESO-CMP.ini");
- float volume = (float)Intvolume / 10;
- if (v) cout <<"Volume : " << volume << "\n";
- if (useEsoLauncher == 1) {
- system("ESOLauncher.exe");
- }
- else {
- system("eso.exe");
- }
- cout <<"Connecting to ScreenLink...\n";
- read:
- // Read map ID
- mapID = GetScreenLink(hdc1);
- while (mapID > 300 && GetPixelColor(hdc1, 0, 0).r < 220 && mapID != 480 && mapID != 481) {
- Sleep(2000);
- mapID = GetScreenLink(hdc1);
- }
- // select a track corresponding to the map
- char *FileToPlay = SelectRandomTrack(mapID, "playlist.m3u");
- // play selected music
- result = FMOD_System_CreateSound(fsystem, FileToPlay, FMOD_SOFTWARE | FMOD_2D, 0, &music); // | FMOD_CREATESTREAM
- if (result != FMOD_OK) {
- cout <<"Error : Can't open " << FileToPlay << "\n";
- Sleep(5000);
- goto read;
- }
- FMOD_Sound_SetLoopCount(music, 1);
- FMOD_System_PlaySound(fsystem, FMOD_CHANNEL_FREE, music, 0, NULL);
- FMOD_System_GetChannel(fsystem, 0, &channel);
- FMOD_Channel_SetVolume(channel, volume );
- // Get music length
- FMOD_Sound_GetLength(music, &length, FMOD_TIMEUNIT_MS);
- // wait until the music is finished...
- time = (int)length + 1000;
- cout <<"Playing " << FileToPlay << " for " << (time - 5000) / 1000 << "s\n";
- // and check if mapID change during the track
- Sleep(50000);
- CheckID = GetScreenLink(hdc1);
- while (mapID == CheckID && time > 0) {
- Sleep(2000);
- time = time - 2000;
- CheckID = GetScreenLink(hdc1);
- }
- tmpVolume = volume;
- // Reduce volume before release
- while (tmpVolume >= 0){
- tmpVolume = tmpVolume - (volume / 10);
- FMOD_Channel_SetVolume(channel, tmpVolume);
- Sleep(500);
- }
- FMOD_Sound_Release(music);
- Sleep(1000);
- goto read;
- FMOD_System_Close(fsystem);
- FMOD_System_Release(fsystem);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement