Merge pull request #4 from ProfessorFartsalot/mvm-expand-audio-functionality

Implemented the proposed changes.
This commit is contained in:
2025-08-23 12:16:43 -04:00
committed by GitHub
3 changed files with 62 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
//Fartsy's Scene Enhancer (Inspired by Mrbt0907/Weather2Remastered) //Fartsy's Scene Enhancer (Inspired by Mrbt0907/Weather2Remastered)
char FSE_VER[8] = "2.0.0"; char FSE_VER[8] = "2.1.0";
//All background music //All background music
enum struct BGM { enum struct BGM {
char realPath[64]; char realPath[64];
@@ -55,11 +55,16 @@ enum struct AUDIOMANAGER {
char cachedPath[128]; char cachedPath[128];
char songName[128]; char songName[128];
float timeSeconds; float timeSeconds;
float savedTimeSeconds;
float loopSeconds; float loopSeconds;
float savedLoopSeconds;
float introSeconds; float introSeconds;
float savedIntroSeconds;
int Client; int Client;
int savedIndexBGM;
int indexBGM; int indexBGM;
int loops; int loops;
int savedLoops;
int VIPBGM; int VIPBGM;
bool isEventMode() { bool isEventMode() {
return this.EventMode; return this.EventMode;
@@ -73,23 +78,46 @@ enum struct AUDIOMANAGER {
* @param instant - True = stops music NOW and changes, False = play current song then change * @param instant - True = stops music NOW and changes, False = play current song then change
**/ **/
void ChangeBGM(int bgm, bool instant) { void ChangeBGM(int bgm, bool instant) {
if (instant) { this.indexBGM = this.VIPBGM > 0 ? this.VIPBGM : bgm == 0 ? g_indexBGM : bgm;
//this.ticksBGM = -2; PrintToChatAll("%i = %i >=0 ? %i : %i == 0 ? %i : %i", this.indexBGM, this.VIPBGM, this.VIPBGM, bgm, g_indexBGM, bgm);
this.timeSeconds = GetEngineTime() - this.loopSeconds; if (instant) { this.timeSeconds = GetEngineTime() - this.loopSeconds; }
}
this.indexBGM = (this.VIPBGM >= 0 ? this.VIPBGM : bgm == 0 ? g_indexBGM : bgm);
this.shouldTick = true; this.shouldTick = true;
this.hasTimeOffset = BGMArray[this.indexBGM].introSeconds > 0 ? true : false; this.hasTimeOffset = BGMArray[this.indexBGM].introSeconds > 0 ? true : false;
this.stopBGM = (!StrEqual(this.cachedPath, BGMArray[this.indexBGM].realPath) ? true : false); this.stopBGM = !StrEqual(this.cachedPath, BGMArray[this.indexBGM].realPath) && !this.EventMode ? true : false;
this.bgmPlaying = true; this.bgmPlaying = true;
CreateTimer(1.0, SyncMusic, this.Client);
//if (this.indexBGM >= 20) for (int i = 0; i < MaxClients; i++) for (int s = 19; s < bgm; s++) StopSound(i, this.chanBGM, BGMArray[s].realPath); //Very quick, very dirty, very suboptimal, but gets the job done... This stops all boss music. //if (this.indexBGM >= 20) for (int i = 0; i < MaxClients; i++) for (int s = 19; s < bgm; s++) StopSound(i, this.chanBGM, BGMArray[s].realPath); //Very quick, very dirty, very suboptimal, but gets the job done... This stops all boss music.
} }
void EnterEventMode(int bgm) {
PrintToChat(this.Client, "Saving %i for you", this.indexBGM);
this.savedIndexBGM = this.indexBGM;
this.savedTimeSeconds = this.timeSeconds;
this.savedLoopSeconds = this.loopSeconds;
this.savedIntroSeconds = this.introSeconds;
this.savedLoops = this.loops;
this.EventMode = true;
CSEClient(this.Client, BGMArray[this.indexBGM].realPath, BGMArray[this.indexBGM].SNDLVL, true, 1, 0.05, 100);
this.ChangeBGM(bgm, true);
PrintToServer("[AudioManager] Entering event mode with song %s", BGMArray[bgm].songName);
}
void ExitEventMode() {
StopSound(this.Client, g_chanBGM, BGMArray[this.indexBGM].realPath);
this.indexBGM = this.savedIndexBGM;
this.loops = this.savedLoops;
this.introSeconds = this.savedIntroSeconds;
this.loopSeconds = this.savedLoopSeconds;
this.timeSeconds = this.savedTimeSeconds;
CSEClient(this.Client, BGMArray[this.indexBGM].realPath, BGMArray[this.indexBGM].SNDLVL, true, 1, 1.0, 100);
this.EventMode = false;
CreateTimer(1.0, SyncMusic, this.Client);
PrintToServer("[AudioManager] Exiting event mode with song %s", BGMArray[this.indexBGM].songName);
}
void Reset() { void Reset() {
this.stopBGM = true; this.stopBGM = true;
this.loops = 0; this.loops = 0;
this.indexBGM = 0; this.indexBGM = 0;
this.timeSeconds = 0.0; this.timeSeconds = 0.0;
if (IsValidClient(this.Client)) for (int s = this.indexBGM; s < sizeof(BGMArray); s++) StopSound(this.Client, g_chanBGM, BGMArray[s].realPath); //Very quick, very dirty, very suboptimal, but gets the job done... This stops all boss music. if (IsValidClient(this.Client)) for (int s = this.indexBGM; s < sizeof(BGMArray); s++) StopSound(this.Client, g_chanBGM, BGMArray[s].realPath);
AssLogger(LOGLVL_DEBUG, "AudioManager has been reset!"); AssLogger(LOGLVL_DEBUG, "AudioManager has been reset!");
} }
void SetInEvent(bool inEvent){ void SetInEvent(bool inEvent){
@@ -108,6 +136,15 @@ enum struct AUDIOMANAGER {
this.Stop(); this.Stop();
return; return;
} }
if (this.EventMode) {
if (this.savedIndexBGM != g_indexBGM && this.VIPBGM <= 0) this.savedIndexBGM = g_indexBGM;
if (this.engineSecondsAdjusted() > this.savedTimeSeconds + this.savedLoopSeconds) {
this.savedTimeSeconds = GetEngineTime();
this.savedLoops++;
this.savedIntroSeconds = this.savedLoops >= 1 ? BGMArray[this.savedIndexBGM].introSeconds : 0.0;
this.savedLoopSeconds = BGMArray[this.savedIndexBGM].loopSeconds;
}
}
if (this.indexBGM == 0) this.indexBGM = g_indexBGM; if (this.indexBGM == 0) this.indexBGM = g_indexBGM;
if (this.engineSecondsAdjusted() > this.timeSeconds + this.loopSeconds) { if (this.engineSecondsAdjusted() > this.timeSeconds + this.loopSeconds) {
this.timeSeconds = GetEngineTime(); this.timeSeconds = GetEngineTime();
@@ -121,19 +158,16 @@ enum struct AUDIOMANAGER {
strcopy(this.songName, sizeof(this.songName), BGMArray[this.indexBGM].songName); strcopy(this.songName, sizeof(this.songName), BGMArray[this.indexBGM].songName);
this.introSeconds = this.loops >= 1 ? BGMArray[this.indexBGM].introSeconds : 0.0; this.introSeconds = this.loops >= 1 ? BGMArray[this.indexBGM].introSeconds : 0.0;
this.loopSeconds = BGMArray[this.indexBGM].loopSeconds; this.loopSeconds = BGMArray[this.indexBGM].loopSeconds;
CreateTimer(1.0, SyncMusic, this.Client);
} }
} }
/**When a client joins the server, set this audio manager to theirs */ /**When a client joins the server, set this audio manager to theirs */
void OnClientConnected(int client) { void OnClientConnected(int client) {
this.Client = client; this.Client = client;
this.clientIsFresh = true; this.clientIsFresh = true;
PrintToServer("Handling new client: %N", client);
} }
/**When a client respawns */ /**When a client respawns */
void OnClientRespawned() { void OnClientRespawned() {
if (this.clientIsFresh) { if (this.clientIsFresh) {
PrintToServer("Client respawned, %N", this.Client);
if (soundPreference[this.Client] == 1 || soundPreference[this.Client] == 3) CPrintToChat(this.Client, "[AudioManager v%s] Welcome! We are listening to %s", FSE_VER, BGMArray[g_indexBGM].songName); if (soundPreference[this.Client] == 1 || soundPreference[this.Client] == 3) CPrintToChat(this.Client, "[AudioManager v%s] Welcome! We are listening to %s", FSE_VER, BGMArray[g_indexBGM].songName);
this.ChangeBGM(g_indexBGM, true); this.ChangeBGM(g_indexBGM, true);
this.clientIsFresh = false; this.clientIsFresh = false;
@@ -157,12 +191,10 @@ enum struct AUDIOCONTROLLER {
AudioManager[i].songName = "null"; AudioManager[i].songName = "null";
AudioManager[i].indexBGM = 0; AudioManager[i].indexBGM = 0;
AudioManager[i].loopSeconds = 0.0; AudioManager[i].loopSeconds = 0.0;
if (IsValidClient(i)){ if (IsValidClient(i)) {
AudioManager[i].Client = i; AudioManager[i].Client = i;
for (int x = 0; x < sizeof(BGMArray); ++x) StopSound(i, g_chanBGM, BGMArray[x].realPath); for (int x = 0; x < sizeof(BGMArray); ++x) StopSound(i, g_chanBGM, BGMArray[x].realPath);
} }
//this.shouldTick = true;
//this.UpdateBGM();
} }
g_indexBGM = GetRandomInt(1, 4); g_indexBGM = GetRandomInt(1, 4);
this.VIPBGM = -1; this.VIPBGM = -1;
@@ -170,7 +202,7 @@ enum struct AUDIOCONTROLLER {
this.UpdateBGM(); this.UpdateBGM();
CreateTimer(1.0, EnableAudio); CreateTimer(1.0, EnableAudio);
} }
void Reset(){ void Reset() {
g_indexBGM = GetGameMode() < 2 ? GetRandomInt(1, 4) : 28; g_indexBGM = GetGameMode() < 2 ? GetRandomInt(1, 4) : 28;
for (int i = 0; i < MaxClients; ++i) AudioManager[i].Reset(); for (int i = 0; i < MaxClients; ++i) AudioManager[i].Reset();
} }
@@ -178,14 +210,14 @@ enum struct AUDIOCONTROLLER {
g_indexBGM = bgm == 0 ? GetRandomInt(1,4) : bgm; g_indexBGM = bgm == 0 ? GetRandomInt(1,4) : bgm;
for (int i = 0; i < MaxClients; ++i) AudioManager[i].ChangeBGM(bgm, instant); for (int i = 0; i < MaxClients; ++i) AudioManager[i].ChangeBGM(bgm, instant);
} }
void Stop(){ void Stop() {
for (int i = 0; i < MaxClients; ++i) AudioManager[i].Stop(); for (int i = 0; i < MaxClients; ++i) AudioManager[i].Stop();
} }
void Tick(){ void Tick() {
for (int i = 0; i < MaxClients; ++i) if (IsValidClient(i) && AudioManager[i].shouldTick) AudioManager[i].TickBGM(); for (int i = 0; i < MaxClients; ++i) if (IsValidClient(i) && AudioManager[i].shouldTick) AudioManager[i].TickBGM();
} }
/** Sets EVERYONE'S BGM in sync! Unless they're in an event... */ /** Sets EVERYONE'S BGM in sync! Unless they're in an event... */
void UpdateBGM(){ void UpdateBGM() {
for (int i = 0; i < MaxClients; ++i) if (IsValidClient(i)) { for (int i = 0; i < MaxClients; ++i) if (IsValidClient(i)) {
if (AudioManager[i].isEventMode() || !IsValidClient(i)) continue; if (AudioManager[i].isEventMode() || !IsValidClient(i)) continue;
AudioManager[i].ChangeBGM(this.VIPBGM > 0 ? this.VIPBGM : AudioManager[i].indexBGM == 0 ? g_indexBGM : AudioManager[i].indexBGM, true); AudioManager[i].ChangeBGM(this.VIPBGM > 0 ? this.VIPBGM : AudioManager[i].indexBGM == 0 ? g_indexBGM : AudioManager[i].indexBGM, true);
@@ -286,14 +318,6 @@ public int MenuHandlerFartsy(Menu menu, MenuAction action, int param1, int param
} else if (action == MenuAction_End) CloseHandle(menu); } else if (action == MenuAction_End) CloseHandle(menu);
return 0; return 0;
} }
//Restart music for the new client
public Action RefireMusicForClient(Handle timer, int client) {
if (IsValidClient(client)) {
if (GetClientTeam(client) == 0) CreateTimer(1.0, RefireMusicForClient, client);
else if (GetClientTeam(client) == 2) CSEClient(client, BGMArray[AudioManager[client].indexBGM].realPath, BGMArray[AudioManager[client].indexBGM].SNDLVL, true, 1, 1.0, 100);
}
return Plugin_Stop;
}
//Light Entities //Light Entities
bool g_PowerOutage; bool g_PowerOutage;

View File

@@ -1111,7 +1111,8 @@ void RegisterAndPrecacheAllFiles(){
public Action SyncMusic(Handle timer, int client) { public Action SyncMusic(Handle timer, int client) {
int index = AudioManager[client].indexBGM; int index = AudioManager[client].indexBGM;
AudioManager[client].cachedPath = BGMArray[index].realPath; AudioManager[client].cachedPath = BGMArray[index].realPath;
AssLogger(LOGLVL_INFO, "[AudioManager for %N]: We are on wave %i, now playing: %s (from %s) for %f seconds. It will start looping in %f seconds.", client, core.curWave, BGMArray[index].songName, BGMArray[index].realPath, BGMArray[index].loopSeconds, BGMArray[index].introSeconds); AudioManager[client].songName = BGMArray[index].songName;
AssLogger(LOGLVL_INFO, "[AudioManager for %N]: We are on wave %i, now playing: %s (from %s) for %f seconds. It will start looping at %f seconds after the first cycle.", client, core.curWave, AudioManager[client].songName, AudioManager[client].cachedPath, AudioManager[client].loopSeconds, BGMArray[index].introSeconds);
return Plugin_Stop; return Plugin_Stop;
} }

View File

@@ -1,4 +1,4 @@
public char PLUGIN_VERSION[8] = "8.4.0"; public char PLUGIN_VERSION[8] = "8.4.1";
void sudo(int task) { void sudo(int task) {
AssLogger(LOGLVL_DEBUG, "Calling sudo with %i", task); AssLogger(LOGLVL_DEBUG, "Calling sudo with %i", task);
switch (task) { switch (task) {
@@ -893,6 +893,14 @@ void sudo(int task) {
case 20000:{ case 20000:{
BossHandler.EmitSpawnSound(2); BossHandler.EmitSpawnSound(2);
} }
case 21000:{
int i = FindTarget(0, "Professor", true, false);
AudioManager[i].EnterEventMode(30);
}
case 22000:{
int i = FindTarget(0, "Professor", true, false);
AudioManager[i].ExitEventMode();
}
// WAVE NULL Init // WAVE NULL Init
case 40000: { case 40000: {
UpdateGamemode(); UpdateGamemode();
@@ -910,6 +918,7 @@ void sudo(int task) {
float hwn = GetRandomFloat(core.HWNMin, core.HWNMax); float hwn = GetRandomFloat(core.HWNMin, core.HWNMax);
CreateTimer(hwn, HWBosses); CreateTimer(hwn, HWBosses);
GlobalAudio.setBGM(29, true); GlobalAudio.setBGM(29, true);
PrintToChatAll("index 29 should be sound\\fartsy\\music\\wavenull_intro.mp3, waves should be timed so that the music changes right at the end of this intro.");
return; return;
} }
case 42690:{ case 42690:{