Skip to content

Commit

Permalink
update: various tweaks/fixes
Browse files Browse the repository at this point in the history
- add 'Import Movie' in Tools context menu
- MovieImportViewModel created to contain logic related to importing movies from disc
- Game Launcher Settings Window UI tweaked to resize better with other languages
- sfx/music volume now pulled from registry when opening game launcher settings window
- sfx/music volume now saved directly to registry when saving game launcher settings
- added option in Controls window to toggle the trigger/dpad support
- fix main window title not refreshing on language change
- fix game launcher looking for game disc after mounting to retry multiple times before failing (since wincdemu takes 1-2 sec to mount)
- updated YARR message
  • Loading branch information
rodriada000 committed May 18, 2020
1 parent 2611755 commit 68d97f5
Show file tree
Hide file tree
Showing 27 changed files with 769 additions and 441 deletions.
12 changes: 7 additions & 5 deletions 7thHeaven.Code/LaunchSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public class LaunchSettings
public bool LogarithmicVolumeControl { get; set; }
public Guid SelectedSoundDevice { get; set; }
public string SelectedMidiDevice { get; set; }
public int MusicVolume { get; set; }
public int SfxVolume { get; set; }

public int SelectedRenderer { get; set; }
public bool UseRiva128GraphicsOption { get; set; }
Expand All @@ -39,6 +37,11 @@ public class LaunchSettings

public bool EnablePs4ControllerService { get; set; }

/// <summary>
/// True means that the launcher will poll for input from a gamepad to intercept trigger/dpad presses
/// </summary>
public bool EnableGamepadPolling { get; set; }



/// <summary>
Expand All @@ -61,8 +64,6 @@ public static LaunchSettings DefaultSettings()
LogarithmicVolumeControl = true,
SelectedMidiDevice = "GENERAL_MIDI",
SelectedRenderer = 3,
MusicVolume = 100,
SfxVolume = 100,
UseRiva128GraphicsOption = false,
UseTntGraphicsOption = false,
QuarterScreenMode = false,
Expand All @@ -72,7 +73,8 @@ public static LaunchSettings DefaultSettings()
HasDisplayedOggMusicWarning = false,
HasDisplayedMovieWarning = false,
EnablePs4ControllerService = false,
MountingOption = MountDiscOption.MountWithPowerShell
MountingOption = MountDiscOption.MountWithPowerShell,
EnableGamepadPolling = true
};
}
}
Expand Down
30 changes: 30 additions & 0 deletions 7thHeaven.Code/RegistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,5 +326,35 @@ public static bool DeleteValueFromKey(string keyPath, string valueName)
return false;
}
}

/// <summary>
/// Update Registry with new value if it has changed from the current value in the Registry.
/// Returns true if changed.
/// </summary>
public static bool SetValueIfChanged(string regKeyPath, string regValueName, object newValue, RegistryValueKind valueKind = RegistryValueKind.String)
{
object currentValue = GetValue(regKeyPath, regValueName, null);
bool isValuesEqual;

if (newValue is byte[])
{
string currentConverted = currentValue == null ? "" : BitConverter.ToString(currentValue as byte[]);
string newConverted = newValue == null ? "" : BitConverter.ToString(newValue as byte[]);

isValuesEqual = currentConverted != null && currentConverted.Equals(newConverted);
}
else
{
isValuesEqual = currentValue != null && currentValue.Equals(newValue);
}

if (!isValuesEqual)
{
SetValue(regKeyPath, regValueName, newValue, valueKind);
return true;
}

return false;
}
}
}
4 changes: 4 additions & 0 deletions 7thHeaven.Code/StringKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -615,5 +615,9 @@ public enum StringKey
Italian,
StartingPS4ControllerService,
ServiceAlreadyRunning,
AllMovieFilesAlreadyImported,
MountDiscWithPowershell,
MountDiscWithWinCDEmu,
LoadingDevices,
}
}
20 changes: 11 additions & 9 deletions SeventhHeavenUI/Classes/ControllerInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,8 @@ internal Task PollForGamepadInput()
rightIsExtended = loadedConfig.KeyboardInputs[GameControl.Right].KeyIsExtended;
}
PlayerIndex? connectedController = GetConnectedController();
if (connectedController.HasValue)
{
// controller is connected so send a little "buzz" for user feedback
GamePad.SetVibration(connectedController.Value, 0.75f, 0.75f);
Thread.Sleep(750);
GamePad.SetVibration(connectedController.Value, 0f, 0f);
}
while (PollingInput)
{
if (connectedController == null)
Expand Down Expand Up @@ -251,5 +242,16 @@ internal Task PollForGamepadInput()

}

internal static void SendVibrationToConnectedController(int lengthInMilliseconds = 750)
{
PlayerIndex? connectedController = GetConnectedController();

if (connectedController.HasValue)
{
GamePad.SetVibration(connectedController.Value, 0.75f, 0.75f);
Thread.Sleep(lengthInMilliseconds);
GamePad.SetVibration(connectedController.Value, 0f, 0f);
}
}
}
}
2 changes: 0 additions & 2 deletions SeventhHeavenUI/Classes/GameDiscMounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ private bool MountWithWinCDEmu(string isoPath)
InstallWinCDEmuDriver();
RunWinCDEmuWithArguments(isoPath);

Thread.Sleep(1000); // sleep for a second after mounting since it takes a second for Windows to recognize the iso as a drive letter

return true;
}
catch (Exception e)
Expand Down
89 changes: 45 additions & 44 deletions SeventhHeavenUI/Classes/GameLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,23 @@ public static bool LaunchGame(bool varDump, bool debug, bool launchWithNoMods =

Instance.DidMountVirtualDisc = true;
Instance.RaiseProgressChanged(ResourceHelper.Get(StringKey.LookingForGameDiscAfterMounting));
Instance.DriveLetter = GetDriveLetter();

// when mounting with WinCDEmu it can take a few seconds (anywhere from 1 to 3 seconds from my experience) so add a fallback here to try mounting multiple times instead of once
int maxMountAttempts = 5;
int currentAttempt = 0;

do
{
Instance.DriveLetter = GetDriveLetter();
currentAttempt++;

if (string.IsNullOrEmpty(Instance.DriveLetter))
{
System.Threading.Thread.Sleep(1000); // sleep for a second before looking for the drive letter again
}

} while (string.IsNullOrEmpty(Instance.DriveLetter) && currentAttempt < maxMountAttempts);


if (string.IsNullOrEmpty(Instance.DriveLetter))
{
Expand Down Expand Up @@ -502,12 +518,25 @@ public static bool LaunchGame(bool varDump, bool debug, bool launchWithNoMods =
}

//
// Initialize the controller input interceptor and DS4Win service to recognize playstation 4 controller as xbox 360 controller (XInput support)
// Initialize the controller input interceptor
//

if (Instance._controllerInterceptor == null)
if (Sys.Settings.GameLaunchSettings.EnableGamepadPolling)
{
Instance._controllerInterceptor = new ControllerInterceptor();
Instance.RaiseProgressChanged("Beginning to poll for gamepad input ...");

if (Instance._controllerInterceptor == null)
{
Instance._controllerInterceptor = new ControllerInterceptor();
}

Instance._controllerInterceptor.PollForGamepadInput().ContinueWith((result) =>
{
if (result.IsFaulted)
{
Logger.Error(result.Exception);
}
});
}


Expand Down Expand Up @@ -695,7 +724,7 @@ public static bool LaunchGame(bool varDump, bool debug, bool launchWithNoMods =
Instance.RaiseProgressChanged(ResourceHelper.Get(StringKey.SettingUpFf7ExeToStopPluginsAndModPrograms));
ff7Proc.Exited += (o, e) =>
{
if (!IsFF7Running())
if (!IsFF7Running() && Instance._controllerInterceptor != null)
{
// stop polling for input once all ff7 procs are closed (could be multiple instances open)
Instance._controllerInterceptor.PollingInput = false;
Expand Down Expand Up @@ -762,15 +791,6 @@ public static bool LaunchGame(bool varDump, bool debug, bool launchWithNoMods =
EnableOrDisableReunionMod(doEnable: true);
}

Instance.RaiseProgressChanged("Beginning to poll for gamepad input ...");
Instance._controllerInterceptor.PollForGamepadInput().ContinueWith((result) =>
{
if (result.IsFaulted)
{
Logger.Error(result.Exception);
}
});

// ensure ff7 window is active at end of launching
if (ff7Proc.MainWindowHandle != IntPtr.Zero)
{
Expand All @@ -789,7 +809,9 @@ public static bool LaunchGame(bool varDump, bool debug, bool launchWithNoMods =
ff7Proc.Refresh();
}

SetForegroundWindow(ff7Proc.MainWindowHandle); // activate window again so it
ControllerInterceptor.SendVibrationToConnectedController();

SetForegroundWindow(ff7Proc.MainWindowHandle); // activate window again
}

return true;
Expand Down Expand Up @@ -1003,7 +1025,7 @@ internal static bool LaunchFF7Exe()
{
try
{
if (!IsFF7Running())
if (!IsFF7Running() && Instance._controllerInterceptor != null)
{
// stop polling for input once all ff7 procs are closed (could be multiple instances open)
Instance._controllerInterceptor.PollingInput = false;
Expand All @@ -1028,7 +1050,7 @@ internal static bool LaunchFF7Exe()
}
};

Instance._controllerInterceptor.PollForGamepadInput();
ControllerInterceptor.SendVibrationToConnectedController();

return true;
}
Expand Down Expand Up @@ -1472,9 +1494,6 @@ public void SetRegistryValues()
SetValueIfChanged(midiKeyPath, "MIDI_data", Sys.Settings.GameLaunchSettings.SelectedMidiDevice);
SetValueIfChanged(midiVirtualKeyPath, "MIDI_data", Sys.Settings.GameLaunchSettings.SelectedMidiDevice);

SetValueIfChanged(midiKeyPath, "MusicVolume", Sys.Settings.GameLaunchSettings.MusicVolume, RegistryValueKind.DWord);
SetValueIfChanged(midiVirtualKeyPath, "MusicVolume", Sys.Settings.GameLaunchSettings.MusicVolume, RegistryValueKind.DWord);

if (Sys.Settings.GameLaunchSettings.LogarithmicVolumeControl)
{
SetValueIfChanged(midiKeyPath, "Options", 0x00000001, RegistryValueKind.DWord);
Expand All @@ -1495,9 +1514,6 @@ public void SetRegistryValues()
SetValueIfChanged(soundKeyPath, "Sound_GUID", soundGuidBytes, RegistryValueKind.Binary);
SetValueIfChanged(soundVirtualKeyPath, "Sound_GUID", soundGuidBytes, RegistryValueKind.Binary);

SetValueIfChanged(soundKeyPath, "SFXVolume", Sys.Settings.GameLaunchSettings.SfxVolume, RegistryValueKind.DWord);
SetValueIfChanged(soundVirtualKeyPath, "SFXVolume", Sys.Settings.GameLaunchSettings.SfxVolume, RegistryValueKind.DWord);

if (Sys.Settings.GameLaunchSettings.ReverseSpeakers)
{
SetValueIfChanged(soundKeyPath, "Options", 0x00000001, RegistryValueKind.DWord);
Expand All @@ -1514,33 +1530,18 @@ public void SetRegistryValues()
/// Update Registry with new value if it has changed from the current value in the Registry.
/// Logs the changed value.
/// </summary>
/// <param name="regKeyPath"></param>
/// <param name="regValueName"></param>
/// <param name="newValue"></param>
/// <param name="valueKind"></param>
private void SetValueIfChanged(string regKeyPath, string regValueName, object newValue, RegistryValueKind valueKind = RegistryValueKind.String)
{
object currentValue = RegistryHelper.GetValue(regKeyPath, regValueName, null);
string valueFormatted = newValue?.ToString(); // used to display the object value correctly in the log e.g. for a byte[] convert it to readable string
bool isValuesEqual;

if (newValue is byte[])
if (RegistryHelper.SetValueIfChanged(regKeyPath, regValueName, newValue, valueKind))
{
string currentConverted = currentValue == null ? "" : BitConverter.ToString(currentValue as byte[]);
string newConverted = newValue == null ? "" : BitConverter.ToString(newValue as byte[]);
string valueFormatted = newValue?.ToString(); // used to display the object value correctly in the log i.e. for a byte[] convert it to readable string

isValuesEqual = currentConverted != null && currentConverted.Equals(newConverted);
valueFormatted = newConverted;
}
else
{
isValuesEqual = currentValue != null && currentValue.Equals(newValue);
}
if (newValue is byte[])
{
valueFormatted = newValue == null ? "" : BitConverter.ToString(newValue as byte[]);
}

if (!isValuesEqual)
{
Instance.RaiseProgressChanged($"\t {regKeyPath}::{regValueName} = {valueFormatted}");
RegistryHelper.SetValue(regKeyPath, regValueName, newValue, valueKind);
}
}

Expand Down
17 changes: 17 additions & 0 deletions SeventhHeavenUI/Resources/Languages/StringResources.br.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1196,4 +1196,21 @@ Você quer aplicar essa configuração e tentar de novo?</system:String>

<system:String x:Key="RetryInstallTooltip">Retry Installing Mod</system:String>

<system:String x:Key="MovieImporter">Movie Importer...</system:String>
<system:String x:Key="AllMovieFilesAlreadyImported" xml:space="preserve">Use this tool in the future to import movie files from the original game discs.

All movies already imported!</system:String>

<system:String x:Key="ImportMoviesFromDisc">Import Movies From Disc</system:String>

<system:String x:Key="EnableTriggerDpadSupport">Enable DPad and Trigger Support</system:String>
<system:String x:Key="TriggerDpadSupportTooltip">Enables DPad and trigger support in-game. (Disable if using a third party mapping tool)</system:String>

<system:String x:Key="MountDiscWithPowershell">Mount Disc With PowerShell</system:String>
<system:String x:Key="MountDiscWithWinCDEmu">Mount Disc With WinCDEmu</system:String>

<system:String x:Key="LoadingDevices">Loading Devices ...</system:String>

<system:String x:Key="MountOptionToolTip">Select how to mount the virtual FF7DISC1 game disc. Windows 7 can only use the 'Mount Disc With WinCDEmu' option.</system:String>

</ResourceDictionary>
16 changes: 16 additions & 0 deletions SeventhHeavenUI/Resources/Languages/StringResources.de.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1196,5 +1196,21 @@ Do you want to apply the setting and try again?</system:String>

<system:String x:Key="RetryInstallTooltip">Retry Installing Mod</system:String>

<system:String x:Key="MovieImporter">Movie Importer...</system:String>
<system:String x:Key="AllMovieFilesAlreadyImported" xml:space="preserve">Use this tool in the future to import movie files from the original game discs.

All movies already imported!</system:String>

<system:String x:Key="ImportMoviesFromDisc">Import Movies From Disc</system:String>

<system:String x:Key="EnableTriggerDpadSupport">Enable DPad and Trigger Support</system:String>
<system:String x:Key="TriggerDpadSupportTooltip">Enables DPad and trigger support in-game. (Disable if using a third party mapping tool)</system:String>

<system:String x:Key="MountDiscWithPowershell">Mount Disc With PowerShell</system:String>
<system:String x:Key="MountDiscWithWinCDEmu">Mount Disc With WinCDEmu</system:String>

<system:String x:Key="LoadingDevices">Loading Devices ...</system:String>

<system:String x:Key="MountOptionToolTip">Select how to mount the virtual FF7DISC1 game disc. Windows 7 can only use the 'Mount Disc With WinCDEmu' option.</system:String>

</ResourceDictionary>
16 changes: 16 additions & 0 deletions SeventhHeavenUI/Resources/Languages/StringResources.es.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,22 @@ Por último, si quieres usar archivos .OGG de alta calidad, cambia la opción de
<system:String x:Key="ServiceAlreadyRunning">service already running ...</system:String>

<system:String x:Key="RetryInstallTooltip">Retry Installing Mod</system:String>

<system:String x:Key="MovieImporter">Movie Importer...</system:String>
<system:String x:Key="AllMovieFilesAlreadyImported" xml:space="preserve">Use this tool in the future to import movie files from the original game discs.

All movies already imported!</system:String>

<system:String x:Key="ImportMoviesFromDisc">Import Movies From Disc</system:String>

<system:String x:Key="EnableTriggerDpadSupport">Enable DPad and Trigger Support</system:String>
<system:String x:Key="TriggerDpadSupportTooltip">Enables DPad and trigger support in-game. (Disable if using a third party mapping tool)</system:String>

<system:String x:Key="MountDiscWithPowershell">Mount Disc With PowerShell</system:String>
<system:String x:Key="MountDiscWithWinCDEmu">Mount Disc With WinCDEmu</system:String>

<system:String x:Key="LoadingDevices">Loading Devices ...</system:String>

<system:String x:Key="MountOptionToolTip">Select how to mount the virtual FF7DISC1 game disc. Windows 7 can only use the 'Mount Disc With WinCDEmu' option.</system:String>

</ResourceDictionary>
17 changes: 17 additions & 0 deletions SeventhHeavenUI/Resources/Languages/StringResources.fr.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1197,4 +1197,21 @@ Do you want to apply the setting and try again?</system:String>

<system:String x:Key="RetryInstallTooltip">Retry Installing Mod</system:String>

<system:String x:Key="MovieImporter">Movie Importer...</system:String>
<system:String x:Key="AllMovieFilesAlreadyImported" xml:space="preserve">Use this tool in the future to import movie files from the original game discs.

All movies already imported!</system:String>

<system:String x:Key="ImportMoviesFromDisc">Import Movies From Disc</system:String>

<system:String x:Key="EnableTriggerDpadSupport">Enable DPad and Trigger Support</system:String>
<system:String x:Key="TriggerDpadSupportTooltip">Enables DPad and trigger support in-game. (Disable if using a third party mapping tool)</system:String>

<system:String x:Key="MountDiscWithPowershell">Mount Disc With PowerShell</system:String>
<system:String x:Key="MountDiscWithWinCDEmu">Mount Disc With WinCDEmu</system:String>

<system:String x:Key="LoadingDevices">Loading Devices ...</system:String>

<system:String x:Key="MountOptionToolTip">Select how to mount the virtual FF7DISC1 game disc. Windows 7 can only use the 'Mount Disc With WinCDEmu' option.</system:String>

</ResourceDictionary>
Loading

0 comments on commit 68d97f5

Please sign in to comment.