Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the sound resetting after a battle. #84

Merged
merged 1 commit into from Sep 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
132 changes: 80 additions & 52 deletions Assembly-CSharp/Global/AllSoundDispatchPlayer.cs
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = System.Object;
Expand Down Expand Up @@ -200,31 +200,37 @@ public void FF9SOUND_SONG_PLAY(Int32 ObjNo, Int32 vol = 127)
{
this.CreateSound(soundProfile);
soundProfile.SoundVolume = AllSoundDispatchPlayer.NormalizeVolume(vol);
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Start(soundProfile.SoundID, 0);
if (this.suspendSongID != -1 && this.suspendSongID == soundProfile.SoundIndex)
{
int offsetTimeMSec = Convert.ToInt32(this.suspendSongTimeMs);
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Start(soundProfile.SoundID, offsetTimeMSec);
}
else
{
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Start(soundProfile.SoundID, 0);
}
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, soundProfile.SoundVolume * this.musicPlayerVolume, 0);
this.currentMusicID = ObjNo;
if (PersistenSingleton<EventEngine>.Instance.gMode == 1 && FF9Snd.sndFuncPtr == new FF9Snd.SoundDispatchDelegate(FF9Snd.FF9FieldSoundDispatch))
{
this.suspendSongID = -1;
}
});
return;
}
else
this.CreateSoundProfileIfNotExist(ObjNo, SoundProfileType.Music, delegate(SoundProfile soundProfile)
{
this.CreateSoundProfileIfNotExist(ObjNo, SoundProfileType.Music, delegate(SoundProfile soundProfile)
if (soundProfile != null)
{
if (soundProfile != null)
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetPause(soundProfile.SoundID, 0, 0);
soundProfile.SoundVolume = AllSoundDispatchPlayer.NormalizeVolume(vol);
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, soundProfile.SoundVolume * this.musicPlayerVolume, 0);
if (PersistenSingleton<EventEngine>.Instance.gMode == 1 && FF9Snd.sndFuncPtr == new FF9Snd.SoundDispatchDelegate(FF9Snd.FF9FieldSoundDispatch))
{
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetPause(soundProfile.SoundID, 0, 0);
soundProfile.SoundVolume = AllSoundDispatchPlayer.NormalizeVolume(vol);
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_SetVolume(soundProfile.SoundID, soundProfile.SoundVolume * this.musicPlayerVolume, 0);
if (PersistenSingleton<EventEngine>.Instance.gMode == 1 && FF9Snd.sndFuncPtr == new FF9Snd.SoundDispatchDelegate(FF9Snd.FF9FieldSoundDispatch))
{
this.suspendSongID = -1;
}
this.suspendSongID = -1;
}
});
}
}
});
}

public Int32 GetSuspendSongID()
Expand All @@ -241,6 +247,8 @@ public void FF9SOUND_SONG_SUSPEND(Int32 ObjNo)
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Stop(soundProfile.SoundID, 0);
this.suspendSongID = ObjNo;
this.suspendSongVolume = AllSoundDispatchPlayer.ReverseNormalizeVolume(soundProfile.SoundVolume);
this.suspendSongTimeMs = soundProfile.StartPlayTime;

}
});
}
Expand Down Expand Up @@ -454,9 +462,9 @@ public void FF9SOUND_SONG_SKIPPHRASE_MILLISEC(Int32 ObjNo, Int32 offsetTimeMSec)

public void FF9SOUND_SNDEFFECT_PLAY(Int32 ObjNo, Int32 attr, Int32 pos, Int32 vol)
{
this.LimitPlayingSfxByObjNo(ObjNo, 2295, 1);
this.LimitPlayingSfxByObjNo(ObjNo, 1966, 3);
this.CreateSoundProfileIfNotExist(ObjNo, SoundProfileType.SoundEffect, delegate(SoundProfile soundProfile)
this.LimitPlayingSfxByObjNo(ObjNo, 2295, 1);
this.LimitPlayingSfxByObjNo(ObjNo, 1966, 3);
this.CreateSoundProfileIfNotExist(ObjNo, SoundProfileType.SoundEffect, delegate(SoundProfile soundProfile)
{
this.CreateSound(soundProfile);
soundProfile.Pitch = 1f;
Expand All @@ -472,40 +480,40 @@ public void FF9SOUND_SNDEFFECT_PLAY(Int32 ObjNo, Int32 attr, Int32 pos, Int32 vo
playingSfx.SndEffectVol = vol;
playingSfx.Pitch = soundProfile.Pitch;
playingSfx.IsFastForwardedPitch = (HonoBehaviorSystem.Instance.GetFastForwardFactor() != 1);
playingSfx.StartPlayTime = Time.time;
this.sfxChanels.Add(playingSfx);
playingSfx.StartPlayTime = Time.time;
this.sfxChanels.Add(playingSfx);
});
}

private void LimitPlayingSfxByObjNo(int ObjNo, int limitObjNo, int limitNumber)
{
if (ObjNo == limitObjNo)
{
AllSoundDispatchPlayer.PlayingSfx playingSfx = (AllSoundDispatchPlayer.PlayingSfx)null;
float num = float.MaxValue;
int num2 = 0;
for (int i = 0; i < this.sfxChanels.Count; i++)
{
AllSoundDispatchPlayer.PlayingSfx playingSfx2 = this.sfxChanels[i];
if (playingSfx2.ObjNo == ObjNo)
{
num2++;
if (playingSfx2.StartPlayTime < num)
{
playingSfx = playingSfx2;
num = playingSfx2.StartPlayTime;
}
}
}
if (num2 >= limitNumber)
{
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Stop(playingSfx.SoundID, 0);
this.sfxChanels.Remove(playingSfx);
}
}
}

private Int32 TuneUpSoundEffectByObjNo(Int32 ObjNo, SoundProfile soundProfile)
private void LimitPlayingSfxByObjNo(int ObjNo, int limitObjNo, int limitNumber)
{
if (ObjNo == limitObjNo)
{
AllSoundDispatchPlayer.PlayingSfx playingSfx = (AllSoundDispatchPlayer.PlayingSfx)null;
float num = float.MaxValue;
int num2 = 0;
for (int i = 0; i < this.sfxChanels.Count; i++)
{
AllSoundDispatchPlayer.PlayingSfx playingSfx2 = this.sfxChanels[i];
if (playingSfx2.ObjNo == ObjNo)
{
num2++;
if (playingSfx2.StartPlayTime < num)
{
playingSfx = playingSfx2;
num = playingSfx2.StartPlayTime;
}
}
}
if (num2 >= limitNumber)
{
ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_Stop(playingSfx.SoundID, 0);
this.sfxChanels.Remove(playingSfx);
}
}
}

private Int32 TuneUpSoundEffectByObjNo(Int32 ObjNo, SoundProfile soundProfile)
{
if (ObjNo == 1748)
{
Expand Down Expand Up @@ -1307,6 +1315,24 @@ public void ResumeAllSounds()

public override void Update()
{
if (this.currentMusicID != -1)
{
this.GetSoundProfileIfExist(this.currentMusicID, SoundProfileType.Music, delegate(SoundProfile soundProfile)
{
if (soundProfile != null)
{
soundProfile.StartPlayTime += 20f;
if (soundProfile.StartPlayTime > 245000f)
{
soundProfile.StartPlayTime %= 245000f;
}

}

});

}

foreach (AllSoundDispatchPlayer.PlayingSfx playingSfx in this.sfxChanels)
{
if (ISdLibAPIProxy.Instance.SdSoundSystem_SoundCtrl_IsExist(playingSfx.SoundID) == 0)
Expand Down Expand Up @@ -1373,6 +1399,8 @@ public void UpdatePlayingSoundEffectPitchFollowingGameSpeed()

private Int32 suspendSongVolume;

private float suspendSongTimeMs;

private List<AllSoundDispatchPlayer.PlayingSfx> sfxChanels = new List<AllSoundDispatchPlayer.PlayingSfx>();

public AllSoundDispatchPlayer.OnSndEffectResPlay onSndEffectResPlay;
Expand Down Expand Up @@ -1421,8 +1449,8 @@ public PlayingSfx()
this.IsSuspend = false;
this.Pitch = 1f;
this.IsFastForwardedPitch = false;
this.StartPlayTime = 0f;
}
this.StartPlayTime = 0f;
}

public Int32 ObjNo;

Expand All @@ -1440,8 +1468,8 @@ public PlayingSfx()

public Boolean IsFastForwardedPitch;

public float StartPlayTime;
}
public float StartPlayTime;
}

public delegate void OnSndEffectResPlay(Int32 slot, Int32 ObjNo, Int32 attr, Int32 pos, Int32 vol);

Expand Down
11 changes: 4 additions & 7 deletions Assembly-CSharp/Global/WM/WMScriptDirector.cs
Expand Up @@ -211,11 +211,9 @@ public void HonoUpdate20FPS()
}
else if (this.FF9Sys.mode == 2)
{
EventEngine eventEngine = PersistenSingleton<EventEngine>.Instance;
Obj objUID = eventEngine.GetObjUID(250);
PosObj posObj = (PosObj)objUID;
EventInput.IsProcessingInput = false;
SoundLib.StopAllSounds();
PosObj posObj = (PosObj)PersistenSingleton<EventEngine>.Instance.GetObjUID(250);
EventInput.IsProcessingInput = false;
SoundLib.SuspendSoundSystem();
SFX_Rush.SetCenterPosition(1);
SceneDirector.Replace("BattleMap", SceneTransition.SwirlInBlack, true);
}
Expand Down Expand Up @@ -244,8 +242,7 @@ public void HonoUpdate20FPS()
{
if (objList2.obj.cid == 4)
{
WMActor wmActor2 = ((Actor)objList2.obj).wmActor;
wmActor2.LateUpdateFunction();
((Actor)objList2.obj).wmActor.LateUpdateFunction();
}
}
}
Expand Down