Skip to content

Commit

Permalink
v1.0.1 - Fixed Spectator Bug
Browse files Browse the repository at this point in the history
Fixed bug where the volume would be changed dependant on the state of the player you were spectating.
  • Loading branch information
DiNitride committed May 21, 2018
1 parent c3ca490 commit e6215c0
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 40 deletions.
57 changes: 44 additions & 13 deletions CSGOMusicController/ControlWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ private void RefreshAudioSessions()
foreach (var audioSession in AudioController.DefaultPlaybackDevice.GetCapability<IAudioSessionController>())
{
String name = audioSession.DisplayName;
if (name == null)
{
continue;
}
if (!(name.Equals("")))
{
AudioDevicesList.Items.Add(name);
Expand Down Expand Up @@ -270,21 +274,31 @@ private void OnAlive()

private int GetHealth(HttpListenerRequest r)
{
System.IO.Stream body = r.InputStream;
Stream body = r.InputStream;
System.Text.Encoding encoding = r.ContentEncoding;
System.IO.StreamReader reader = new System.IO.StreamReader(body, encoding);
StreamReader reader = new StreamReader(body, encoding);
DataJson d;
string s = reader.ReadToEnd();
Console.WriteLine("===== NEW JSON DATA =====\n{0}\n=========================", s);
body.Close();
reader.Close();
DataJson d = JsonConvert.DeserializeObject<DataJson>(s);
try
{
return d.Player.State.Health;
} catch (NullReferenceException)
d = JsonConvert.DeserializeObject<DataJson>(s);
if (d.Player.ID == d.Provider.ID)
{
return 0;
try
{
return d.Player.State.Health;
}
catch (NullReferenceException)
{
return 0;
}
} else {
Console.WriteLine("INFO -> Player is spectating, ID's do not match");
return 1000;
}


}

delegate void StringArgReturningVoidDelegate(string state);
Expand Down Expand Up @@ -332,12 +346,16 @@ private void PollForData()
if (request.HttpMethod != "POST") { continue; }
health = GetHealth(request);
Console.WriteLine("Player Health: {0}", health);
if (health > 0)
{
OnAlive();
} else
if (health != 1000)
{
OnDeath();
if (health > 0)
{
OnAlive();
}
else
{
OnDeath();
}
}
response = context.Response;
response.Close();
Expand Down Expand Up @@ -393,6 +411,7 @@ private void StartStopToggle_Click(object sender, EventArgs e)

private void UpdateVolumeManually()
{
if (health == 1000) { return; }
if (health > 0)
{
OnAlive();
Expand Down Expand Up @@ -438,12 +457,18 @@ public class DataJson

[JsonProperty("previously")]
public PreviouslyJson Previosuly { get; set; }

[JsonProperty("provider")]
public ProviderJson Provider { get; set; }
}

public class PlayerJson
{
[JsonProperty("state")]
public StateJson State { get; set; }

[JsonProperty("steamid")]
public String ID { get; set; }
}

public class PreviouslyJson
Expand All @@ -458,4 +483,10 @@ public class StateJson
public int Health { get; set; }
}

public class ProviderJson
{
[JsonProperty("steamid")]
public String ID { get; set; }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
"uri" "http://127.0.0.1:5659"
"data" {
"player_state" "1" // player state for this current round such as health, armor, kills this round, etc.
}
"provider" "1"
"player_id" "1"
}
}
77 changes: 51 additions & 26 deletions Setup/Setup.vdproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
}
"Entry"
{
"MsmKey" = "8:_94826115F0764C82A6B8BA0015065CEA"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_A2B0D6E5E0E648EEB8C73DBBFFEE8BBE"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
Expand All @@ -63,12 +69,6 @@
}
"Entry"
{
"MsmKey" = "8:_EFAB7DFC779647998568CD8466154FD1"
"OwnerKey" = "8:_UNDEFINED"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
"OwnerKey" = "8:_A2B0D6E5E0E648EEB8C73DBBFFEE8BBE"
"MsmSig" = "8:_UNDEFINED"
Expand Down Expand Up @@ -205,6 +205,11 @@
"AssemblyAsmDisplayName" = "8:AudioSwitcher.AudioApi.CoreAudio, Version=4.0.0.308, Culture=neutral, PublicKeyToken=fda5729e2db3a64f, processorArchitecture=MSIL"
"ScatterAssemblies"
{
"_4E27A5228F9AB93F8B6BF2FB87549A0D"
{
"Name" = "8:AudioSwitcher.AudioApi.CoreAudio.dll"
"Attributes" = "3:512"
}
}
"SourcePath" = "8:AudioSwitcher.AudioApi.CoreAudio.dll"
"TargetName" = "8:"
Expand All @@ -231,6 +236,11 @@
"AssemblyAsmDisplayName" = "8:Gameloop.Vdf, Version=0.4.4.0, Culture=neutral, processorArchitecture=MSIL"
"ScatterAssemblies"
{
"_58BEAC4E0A3E3BDDD8B25FDD48CD5E5F"
{
"Name" = "8:Gameloop.Vdf.dll"
"Attributes" = "3:512"
}
}
"SourcePath" = "8:Gameloop.Vdf.dll"
"TargetName" = "8:"
Expand All @@ -257,6 +267,11 @@
"AssemblyAsmDisplayName" = "8:System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ScatterAssemblies"
{
"_5A8069E119B4B529F2A319CC0EF55AD2"
{
"Name" = "8:System.Net.Http.dll"
"Attributes" = "3:512"
}
}
"SourcePath" = "8:System.Net.Http.dll"
"TargetName" = "8:"
Expand Down Expand Up @@ -296,16 +311,10 @@
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_AA77B3DA2C90CBBDE0B0E7F6E594F56E"
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_94826115F0764C82A6B8BA0015065CEA"
{
"AssemblyRegister" = "3:1"
"AssemblyIsInGAC" = "11:FALSE"
"AssemblyAsmDisplayName" = "8:Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
"ScatterAssemblies"
{
}
"SourcePath" = "8:Newtonsoft.Json.dll"
"TargetName" = "8:"
"SourcePath" = "8:..\\CSGOMusicController\\resources\\gamestate_integration_musicControllApp.cfg"
"TargetName" = "8:gamestate_integration_musicControllApp.cfg"
"Tag" = "8:"
"Folder" = "8:_7C2AA65F5B2A4C3E992A6268B3E6611F"
"Condition" = "8:"
Expand All @@ -319,18 +328,23 @@
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsDependency" = "11:FALSE"
"IsolateTo" = "8:"
}
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_D5C3E3BCA0721F81F6A7A8D08C89F9E8"
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_AA77B3DA2C90CBBDE0B0E7F6E594F56E"
{
"AssemblyRegister" = "3:1"
"AssemblyIsInGAC" = "11:FALSE"
"AssemblyAsmDisplayName" = "8:AudioSwitcher.AudioApi, Version=4.0.0.308, Culture=neutral, PublicKeyToken=fda5729e2db3a64f, processorArchitecture=MSIL"
"AssemblyAsmDisplayName" = "8:Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"
"ScatterAssemblies"
{
"_AA77B3DA2C90CBBDE0B0E7F6E594F56E"
{
"Name" = "8:Newtonsoft.Json.dll"
"Attributes" = "3:512"
}
}
"SourcePath" = "8:AudioSwitcher.AudioApi.dll"
"SourcePath" = "8:Newtonsoft.Json.dll"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_7C2AA65F5B2A4C3E992A6268B3E6611F"
Expand All @@ -348,10 +362,21 @@
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
"{1FB2D0AE-D3B9-43D4-B9DD-F88EC61E35DE}:_EFAB7DFC779647998568CD8466154FD1"
"{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_D5C3E3BCA0721F81F6A7A8D08C89F9E8"
{
"SourcePath" = "8:..\\CSGOMusicController\\resources\\gamestate_integration_musicControllApp.cfg"
"TargetName" = "8:gamestate_integration_musicControllApp.cfg"
"AssemblyRegister" = "3:1"
"AssemblyIsInGAC" = "11:FALSE"
"AssemblyAsmDisplayName" = "8:AudioSwitcher.AudioApi, Version=4.0.0.308, Culture=neutral, PublicKeyToken=fda5729e2db3a64f, processorArchitecture=MSIL"
"ScatterAssemblies"
{
"_D5C3E3BCA0721F81F6A7A8D08C89F9E8"
{
"Name" = "8:AudioSwitcher.AudioApi.dll"
"Attributes" = "3:512"
}
}
"SourcePath" = "8:AudioSwitcher.AudioApi.dll"
"TargetName" = "8:"
"Tag" = "8:"
"Folder" = "8:_7C2AA65F5B2A4C3E992A6268B3E6611F"
"Condition" = "8:"
Expand All @@ -365,7 +390,7 @@
"PackageAs" = "3:1"
"Register" = "3:1"
"Exclude" = "11:FALSE"
"IsDependency" = "11:FALSE"
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
}
Expand Down Expand Up @@ -424,15 +449,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:CSGO Automatic Music Control"
"ProductCode" = "8:{D530159E-4B2A-4751-B06A-CA1A07385928}"
"PackageCode" = "8:{BE361407-1A4C-44D6-A928-6A19064DEBC6}"
"ProductCode" = "8:{377EB726-DD8A-487D-8051-96698FEE7A7F}"
"PackageCode" = "8:{FC541714-858B-43E9-9618-39C8C320A3CC}"
"UpgradeCode" = "8:{70601B69-FEEE-473C-8A56-0D497552E7C3}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:0.0.9"
"ProductVersion" = "8:1.0.1"
"Manufacturer" = "8:DiNitride"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:https://github.com/DiNitride/CSGOAutoMusicVolume"
Expand Down

0 comments on commit e6215c0

Please sign in to comment.