Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalet committed Aug 20, 2015
2 parents ae8c4b9 + e350206 commit d691fbc
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 93 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ bin/
*.psess
*.rar
*.TMP

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
Binary file modified Components/LiveSplit.Skyrim.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Components/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ if [ -z "$VERSION" ]; then
exit 1
fi

zip LiveSplit.Skyrim_v${VERSION}.zip LiveSplit.Skyrim.dll ../readme.txt
zip -j LiveSplit.Skyrim_v${VERSION}.zip LiveSplit.Skyrim.dll ../README.md
10 changes: 10 additions & 0 deletions Components/update.LiveSplit.Skyrim.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
<updates>
<update version="2.3">
<files>
<file path="Components/LiveSplit.Skyrim.dll" status="changed"/>
</files>
<changelog>
<change>
Compatibility with LiveSplit 1.6
</change>
</changelog>
</update>
<update version="2.2.1">
<files>
<file path="Components/LiveSplit.Skyrim.dll" status="changed"/>
Expand Down
43 changes: 16 additions & 27 deletions LiveSplit.Skyrim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\..\Program Files %28x86%29\LiveSplit\Components\</OutputPath>
<OutputPath>..\..\..\..\Program Files\LiveSplit\Components\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowedReferenceRelatedFileExtensions>
.pdb
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
Expand All @@ -28,15 +31,17 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowedReferenceRelatedFileExtensions>
.pdb
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
<ItemGroup>
<Reference Include="LiveSplit.Core">
<HintPath>..\..\..\..\Program Files (x86)\LiveSplit\LiveSplit.Core.dll</HintPath>
<HintPath>..\..\..\..\Program Files\LiveSplit\LiveSplit.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="LiveSplit.Sound, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Program Files (x86)\LiveSplit\Components\LiveSplit.Sound.dll</HintPath>
<Reference Include="NAudio">
<HintPath>packages\NAudio.1.7.3\lib\net35\NAudio.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -46,7 +51,7 @@
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="UpdateManager">
<HintPath>..\..\..\..\Program Files (x86)\LiveSplit\UpdateManager.dll</HintPath>
<HintPath>..\..\..\..\Program Files\LiveSplit\UpdateManager.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand All @@ -70,6 +75,7 @@
<Compile Include="GameMemory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SafeNativeMethods.cs" />
<Compile Include="MediaPlayer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
Expand All @@ -82,33 +88,16 @@
</ItemGroup>
<ItemGroup>
<None Include="license.txt" />
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\bearcart_short.mp3" />
</ItemGroup>
<ItemGroup>
<COMReference Include="MediaPlayer">
<Guid>{22D6F304-B0F6-11D0-94AB-0080C74C7E95}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
<COMReference Include="stdole">
<Guid>{00020430-0000-0000-C000-000000000046}</Guid>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>primary</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<Content Include="Components\update.LiveSplit.Skyrim.xml" />
<Content Include="Components\update.LiveSplit.Skyrim.xml">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
61 changes: 61 additions & 0 deletions MediaPlayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using LiveSplit.Options;
using NAudio.Wave;
using System;
using System.IO;
using System.Threading.Tasks;

namespace LiveSplit.Skyrim
{
public class MediaPlayer
{
public int GeneralVolume { get; set; }
protected WaveOut Player { get; private set; }

public MediaPlayer()
{
GeneralVolume = 100;

Player = new WaveOut();
}

public void Dispose()
{
Player.Stop();
}

public void PlaySound(String location, int volume)
{
Player.Stop();

if (File.Exists(location))
{
Task.Factory.StartNew(() =>
{
try
{
AudioFileReader audioFileReader = new AudioFileReader(location);
audioFileReader.Volume = (volume / 100f) * (GeneralVolume / 100f);

Player.DeviceNumber = -1;
Player.Init(audioFileReader);
Player.Play();
}
catch (Exception e)
{
Log.Error(e);
}
});
}
}

public void PlaySound(String location)
{
PlaySound(location, GeneralVolume);
}

public void Stop()
{
Player.Stop();
}
}
}
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.1.0")]
[assembly: AssemblyFileVersion("2.2.1.0")]
[assembly: AssemblyVersion("2.3.0.0")]
[assembly: AssemblyFileVersion("2.3.0.0")]

[assembly: ComponentFactory(typeof(SkyrimFactory))]
37 changes: 17 additions & 20 deletions SkyrimComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override string ComponentName
get { return "Skyrim"; }
}

public IComponent SoundComponent { get; set; }
public MediaPlayer MediaPlayer { get; set; }
public SkyrimSettings Settings { get; set; }
public Time BearCartSplit { get; private set; }

Expand All @@ -36,25 +36,22 @@ public SkyrimComponent(LiveSplitState state)
Trace.WriteLine($"[NoLoads] Using LiveSplit.Skyrim component version {Assembly.GetExecutingAssembly().GetName().Version} {(debug ? "Debug" : "Release")} build");
_state = state;

try { MediaPlayer = new MediaPlayer(); }
catch { MediaPlayer = null; }
this.Settings = new SkyrimSettings(this, state);

_timer = new TimerModel { CurrentState = state };

this.BearCartSplit = new Time();
IComponentFactory soundFactory;
if (ComponentManager.ComponentFactories.TryGetValue("LiveSplit.Sound.dll", out soundFactory))
{
SoundComponent = soundFactory.Create(_state) as SoundComponent;

this.BearCartDefaultSoundPath = System.IO.Path.GetTempPath() + @"LiveSplit.Skyrim\bearcart.mp3";
//extract embedded sound to temp folder
try
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(BearCartDefaultSoundPath));
System.IO.File.WriteAllBytes(BearCartDefaultSoundPath, Properties.Resources.bearcart_short);
}
catch (System.IO.IOException) { Trace.WriteLine("[NoLoads] Error when extracting bear cart sound to temp folder."); }
this.BearCartDefaultSoundPath = System.IO.Path.GetTempPath() + @"LiveSplit.Skyrim\bearcart.mp3";
//extract embedded sound to temp folder
try
{
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(BearCartDefaultSoundPath));
System.IO.File.WriteAllBytes(BearCartDefaultSoundPath, Properties.Resources.bearcart_short);
}
catch (System.IO.IOException) { Trace.WriteLine("[NoLoads] Error when extracting bear cart sound to temp folder."); }

_gameMemory = new GameMemory();
_gameMemory.OnStartSaveLoad += gameMemory_OnStartSaveLoad;
Expand All @@ -73,7 +70,7 @@ public override void Dispose()
_state.OnReset -= State_OnReset;

_gameMemory?.Stop();
SoundComponent?.Dispose();
MediaPlayer?.Dispose();
}

void State_OnStart(object sender, EventArgs e)
Expand Down Expand Up @@ -183,14 +180,14 @@ void gameMemory_OnBearCart(object sender, EventArgs e)
Settings.IsBearCartSecret = false;
Settings.SaveBearCartConfig();

if (SoundComponent != null && (Settings.IsBearCartSecret || Settings.PlayBearCartSound)) //force play if it isn't unlocked in case the splits were shared
if (Settings.IsBearCartSecret || Settings.PlayBearCartSound) //force play if it isn't unlocked in case the splits were shared
{
if (Settings.IsBearCartSecret || !Settings.PlayBearCartSoundOnlyOnPB || IsBearCartPB(BearCartSplit))
{
if (String.IsNullOrEmpty(Settings.BearCartSoundPath))
((SoundComponent)SoundComponent).PlaySound(BearCartDefaultSoundPath);
if (String.IsNullOrEmpty(Settings.BearCartSoundPath) || !System.IO.File.Exists(Settings.BearCartSoundPath))
MediaPlayer?.PlaySound(BearCartDefaultSoundPath);
else
((SoundComponent)SoundComponent).PlaySound(Settings.BearCartSoundPath);
MediaPlayer?.PlaySound(Settings.BearCartSoundPath);
}
}
}
Expand Down Expand Up @@ -227,8 +224,8 @@ void UpdateBearCartPB(bool silent = false)
}
}

if (SoundComponent != null && !silent)
((SoundComponent)SoundComponent).Player.Stop();
if (!silent)
MediaPlayer?.Stop();

BearCartSplit = new Time();
}
Expand Down
Loading

0 comments on commit d691fbc

Please sign in to comment.