Skip to content

Commit

Permalink
tweak volume, add crc checks, add link to wiki
Browse files Browse the repository at this point in the history
  • Loading branch information
Deinonychus71 committed Dec 27, 2020
1 parent f9f3c54 commit 64f2502
Show file tree
Hide file tree
Showing 21 changed files with 260 additions and 23 deletions.
96 changes: 96 additions & 0 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Helpers/GameResourcesCrcHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Sm5sh.ResourceProviders.Constants;
using System.Collections.Generic;

namespace Sm5sh.Mods.Music.Helpers
{
public class GameResourcesCrcHelper
{
public static List<GameCrcSet> VersionCrcSets = new List<GameCrcSet>()
{
new GameCrcSet()
{
Version = 10.0,
CrcResources = new Dictionary<string, uint>()
{
{ BgmPropertyFileConstants.BGM_PROPERTY_PATH, 0x5DA473DC },
{ PrcExtConstants.PRC_UI_BGM_DB_PATH, 0x0B40201B },
{ PrcExtConstants.PRC_UI_GAMETITLE_DB_PATH, 0x64A6B3F2 },
{ PrcExtConstants.PRC_UI_STAGE_DB_PATH, 0xBEC70A05 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_de"), 0x5ACB4CD9 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_en"), 0xBB7D6832 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_es"), 0xBC2DFC42 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_fr"), 0xCA1466A3 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_it"), 0x6929D1A6 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_nl"), 0xB7BE4024 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_ru"), 0x17FE6AA8 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "jp_ja"), 0x4E871500 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "kr_ko"), 0xAAA93540 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_en"), 0x62BBB2A9 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_es"), 0x86AA1535 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_fr"), 0xACFFA15E },
{ string.Format(MsbtExtConstants.MSBT_BGM, "zh_cn"), 0x109189D2 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "zh_tw"), 0x47BD1B25 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_de"), 0x7671A994 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_en"), 0x8819E6D4 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_es"), 0x42F6A770 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_fr"), 0xA3373FD7 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_it"), 0xDA270DB7 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_nl"), 0x1D7F72C3 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_ru"), 0x2A8F96FC },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "jp_ja"), 0xA3AD4A34 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "kr_ko"), 0x64252510 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_en"), 0x773E88AC },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_es"), 0x73F11E85 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_fr"), 0x07C29D63 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "zh_cn"), 0x17BCC77D },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "zh_tw"), 0x6E8482F9 }
}
},
new GameCrcSet()
{
Version = 10.1,
CrcResources = new Dictionary<string, uint>()
{
{ BgmPropertyFileConstants.BGM_PROPERTY_PATH, 0x5DA473DC },
{ PrcExtConstants.PRC_UI_BGM_DB_PATH, 0x83C7244A },
{ PrcExtConstants.PRC_UI_GAMETITLE_DB_PATH, 0x64A6B3F2 },
{ PrcExtConstants.PRC_UI_STAGE_DB_PATH, 0xBEC70A05 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_de"), 0x5ACB4CD9 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_en"), 0xBB7D6832 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_es"), 0xBC2DFC42 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_fr"), 0xCA1466A3 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_it"), 0x6929D1A6 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_nl"), 0xB7BE4024 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "eu_ru"), 0x17FE6AA8 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "jp_ja"), 0x4E871500 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "kr_ko"), 0xAAA93540 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_en"), 0x62BBB2A9 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_es"), 0x86AA1535 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "us_fr"), 0xACFFA15E },
{ string.Format(MsbtExtConstants.MSBT_BGM, "zh_cn"), 0x109189D2 },
{ string.Format(MsbtExtConstants.MSBT_BGM, "zh_tw"), 0x47BD1B25 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_de"), 0x88394D04 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_en"), 0x481B25B8 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_es"), 0x6431BB7F },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_fr"), 0x090AD9CB },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_it"), 0xFE5BC0B2 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_nl"), 0x350A6DD3 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "eu_ru"), 0x51E6AC28 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "jp_ja"), 0x7185EFAE },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "kr_ko"), 0x85E1CC5C },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_en"), 0xFC6E27E0 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_es"), 0x02EECC25 },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "us_fr"), 0xFDF911CC },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "zh_cn"), 0xC086A18E },
{ string.Format(MsbtExtConstants.MSBT_TITLE, "zh_tw"), 0xA817D5A3 }
}
},
};
}

public class GameCrcSet
{
public double Version { get; set; }
public Dictionary<string, uint> CrcResources { get; set; }
}
}
3 changes: 3 additions & 0 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Helpers/MusicConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
{
public class MusicConstants
{
public const double VersionSm5shMusic = 0.9;
public const double VersionSm5shMusicOverride = 0.9;

public class MusicModFiles
{
public const string MUSIC_MOD_METADATA_JSON_FILE = "metadata_mod.json";
Expand Down
2 changes: 2 additions & 0 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Interfaces/IAudioStateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface IAudioStateService
IEnumerable<string> GetLocales();
IEnumerable<PlaylistEntry> GetPlaylists();

double GameVersion { get; }

bool CanAddBgmDbRootEntry(string uiBgmId);
bool CanAddBgmStreamSetEntry(string streamSetId);
bool CanAddBgmAssignedInfoEntry(string infoId);
Expand Down
38 changes: 38 additions & 0 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Services/AudioStateService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoMapper;
using Force.Crc32;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Sm5sh.Data;
Expand Down Expand Up @@ -37,6 +38,8 @@ public class AudioStateService : IAudioStateService
private readonly Dictionary<string, PlaylistEntry> _playlistsEntries;
private readonly Dictionary<string, StageEntry> _stageEntries;

public double GameVersion { get; private set; }

public AudioStateService(IOptions<Sm5shMusicOptions> config, IMapper mapper, IStateManager state, ILogger<IAudioStateService> logger)
{
_config = config;
Expand Down Expand Up @@ -577,6 +580,8 @@ public bool SaveBgmEntriesToStateManager()
#region Private
public void InitBgmEntriesFromStateManager()
{
GuessGameVersion();

//Make sure resources are unloaded
_state.UnloadResources();
_bgmDbRootEntries.Clear();
Expand Down Expand Up @@ -693,6 +698,39 @@ public void InitBgmEntriesFromStateManager()
}
}

public void GuessGameVersion()
{
var gameCrcSets = GameResourcesCrcHelper.VersionCrcSets;
GameVersion = 0.0;
foreach(var versionCrcSet in gameCrcSets)
{
bool allMatch = true;
foreach(var resource in versionCrcSet.CrcResources)
{
var file = Path.Combine(_config.Value.GameResourcesPath, resource.Key);
if (File.Exists(file))
{
var hash = Crc32Algorithm.Compute(File.ReadAllBytes(file));
if (hash != resource.Value)
{
_logger.LogDebug("CRC Check: File {File} did not match expected CRC32 hash for Version {Version}. Expected: 0x{ExpectedHash:x}, Was: 0x{ActualHash:x}", file, versionCrcSet.Version, resource.Value, hash);
allMatch = false;
break;
}
}
else
{
_logger.LogDebug("CRC Check: File {File} could not be found", file);
}
}
if (allMatch)
{
GameVersion = versionCrcSet.Version;
break;
}
}
}

#region Utils
private string GetNewNameId()
{
Expand Down
1 change: 1 addition & 0 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Sm5sh.Mods.Music.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
<PackageReference Include="Crc32.NET" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Sm5shMusic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class Sm5shMusic : BaseSm5shMod
private readonly IAudioStateService _audioStateService;
private readonly IMusicModManagerService _musicModManagerService;
private readonly INus3AudioService _nus3AudioService;
private const double Version = 0.9;

public override string ModName => "Sm5shMusic";

Expand All @@ -34,7 +33,7 @@ public Sm5shMusic(IOptions<Sm5shMusicOptions> config, IMusicModManagerService mu
public override bool Init()
{
_logger.LogInformation("Sm5shMusic Path: {MusicModPath}", _config.Value.Sm5shMusic.ModPath);
_logger.LogInformation("Sm5shMusic Version: {Version}", Version);
_logger.LogInformation("Sm5shMusic Version: {Version}", MusicConstants.VersionSm5shMusic);
_logger.LogInformation("Audio Conversion Format: {AudioConversionFormat}", _config.Value.Sm5shMusic.AudioConversionFormat);
_logger.LogInformation("Resources Path: {ResourcesPath}", _config.Value.Sm5shMusic.EnableAudioCaching ? "Enabled - If songs are mismatched try to clear the cache!" : "Disabled");
_logger.LogInformation("Cache Path: {CachePath}", _config.Value.Sm5shMusic.CachePath);
Expand Down
3 changes: 1 addition & 2 deletions Sm5sh/Mods/Sm5sh.Mods.Music/Sm5shMusicOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class Sm5shMusicOverride : BaseSm5shMod, ISm5shMusicOverride
private readonly IAudioStateService _audioStateService;
private const Formatting _defaultFormatting = Formatting.Indented;
private MusicOverrideConfig _musicOverrideConfig;
private const double Version = 0.9;

public override string ModName => "Sm5shMusicOverride";

Expand All @@ -40,7 +39,7 @@ public Sm5shMusicOverride(IOptions<Sm5shMusicOverrideOptions> config, IStateMana
public override bool Init()
{
_logger.LogInformation("Sm5shMusic Override Path: {MusicModPath}", _config.Value.Sm5shMusicOverride.ModPath);
_logger.LogInformation("Sm5shMusic Override Version: {Version}", Version);
_logger.LogInformation("Sm5shMusic Override Version: {Version}", MusicConstants.VersionSm5shMusicOverride);

//Load Music Override
_logger.LogInformation("Loading Sm5shMusic Override Config");
Expand Down
36 changes: 36 additions & 0 deletions Sm5shMusic.GUI/Helpers/WebBrowserHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Sm5shMusic.GUI.Helpers
{
public static class WebBrowserHelper
{
public static void OpenBrowser(string url)
{
try
{
Process.Start(url);
}
catch
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw;
}
}
}
}
}
4 changes: 4 additions & 0 deletions Sm5shMusic.GUI/Interfaces/IGUIStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ public interface IGUIStateManager
Task<bool> UpdateGlobalSettings(ApplicationSettings appSettings);
Task<bool> WipeAudioCache();
Task<bool> ReorderSongs();

string GameVersion { get; }

bool IsGameVersionFound { get; }
}
}
1 change: 1 addition & 0 deletions Sm5shMusic.GUI/Models/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Sm5shMusicGuiOptionsSection
public string DefaultMSBTLocale { get; set; }
public bool CopyToEmptyLocales { get; set; }
public ushort PlaylistIncidenceDefault { get; set; }
public bool SkipWarningGameVersion { get; set; }
}
}
}
4 changes: 3 additions & 1 deletion Sm5shMusic.GUI/Models/AutoMapper/MappingViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public MappingViewModels()
DefaultGUILocale = p.DefaultGUILocale,
DefaultMSBTLocale = p.DefaultMSBTLocale,
CopyToEmptyLocales = p.CopyToEmptyLocales,
PlaylistIncidenceDefault = p.PlaylistIncidenceDefault
PlaylistIncidenceDefault = p.PlaylistIncidenceDefault,
SkipWarningGameVersion = p.SkipWarningGameVersion
}))
.ForMember(i => i.Sm5shMusicOverride, me => me.MapFrom(p => new Sm5shMusicOverrideOptions.Sm5shMusicOverrideOptionsSection()
{
Expand All @@ -59,6 +60,7 @@ public MappingViewModels()
.ForMember(i => i.DefaultMSBTLocale, me => me.MapFrom(p => p.Sm5shMusicGUI.DefaultMSBTLocale))
.ForMember(i => i.CopyToEmptyLocales, me => me.MapFrom(p => p.Sm5shMusicGUI.CopyToEmptyLocales))
.ForMember(i => i.PlaylistIncidenceDefault, me => me.MapFrom(p => p.Sm5shMusicGUI.PlaylistIncidenceDefault))
.ForMember(i => i.SkipWarningGameVersion, me => me.MapFrom(p => p.Sm5shMusicGUI.SkipWarningGameVersion))
.ForMember(i => i.ModOverridePath, me => me.MapFrom(p => p.Sm5shMusicOverride.ModPath))
.ForMember(i => i.TempPath, me => me.MapFrom(p => p.TempPath))
.ForMember(i => i.ToolsPath, me => me.MapFrom(p => p.ToolsPath));
Expand Down
1 change: 1 addition & 0 deletions Sm5shMusic.GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private static Dictionary<string, string> GetDefaultConfiguration()
{ "Sm5shMusicGUI:CopyToEmptyLocales", "true" },
{ "Sm5shMusicGUI:DefaultMSBTLocale", "us_en" },
{ "Sm5shMusicGUI:PlaylistIncidenceDefault", "0" },
{ "Sm5shMusicGUI:SkipWarningGameVersion", "false" },
{ "Sm5shMusicOverride:ModPath", $"Mods{Path.DirectorySeparatorChar}MusicOverride" },
};
}
Expand Down
16 changes: 16 additions & 0 deletions Sm5shMusic.GUI/Services/GUIStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,22 @@ await Dispatcher.UIThread.InvokeAsync(async () =>
}
#endregion

public string GameVersion
{
get
{
return _audioState.GameVersion == 0 ? "?? (custom)" : _audioState.GameVersion.ToString();
}
}

public bool IsGameVersionFound
{
get
{
return _audioState.GameVersion != 0;
}
}

public async Task<bool> UpdateGlobalSettings(ApplicationSettings appSettings)
{
bool result;
Expand Down
Loading

0 comments on commit 64f2502

Please sign in to comment.