Skip to content

Commit 92e237a

Browse files
committed
TF2 fix, userdata & steamapps override...
* Fixed samplerate for TF2’s new CELT audio codec. * Option to override the automatic detection of steamapps and userdata folders (under “Settings”, “Advanced”). * Option to load tracks by right-clicking a track, then clicking “Load” (only while SLAM is “running”). * Error logs reported in UTC. * Play key and relay key now can’t be set to the same key.
1 parent 31ce7d1 commit 92e237a

7 files changed

Lines changed: 316 additions & 53 deletions

File tree

SLAM/App.config

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
<setting name="HoldToPlay" serializeAs="String">
3838
<value>False</value>
3939
</setting>
40+
<setting name="OverrideFolders" serializeAs="String">
41+
<value>False</value>
42+
</setting>
43+
<setting name="steamapps" serializeAs="String">
44+
<value>C:\Program Files (x86)\Steam\steamapps\</value>
45+
</setting>
46+
<setting name="userdata" serializeAs="String">
47+
<value>C:\Program Files (x86)\Steam\userdata\</value>
48+
</setting>
4049
</SLAM.My.MySettings>
4150
</userSettings>
4251
</configuration>

SLAM/Form1.Designer.vb

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SLAM/Form1.vb

Lines changed: 77 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ Public Class Form1
1313
Dim Games As New List(Of SourceGame)
1414
Dim running As Boolean = False
1515
Dim ClosePending As Boolean = False
16+
Dim SteamAppsPath As String
17+
Dim status As Integer = IDLE
18+
19+
Const IDLE = -1
20+
Const SEARCHING = -2
21+
Const WORKING = -3
22+
1623

1724
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
1825
RefreshPlayKey()
26+
If My.Settings.PlayKey = My.Settings.RelayKey Then
27+
My.Settings.RelayKey = "="
28+
My.Settings.Save()
29+
End If
1930

2031
If My.Settings.UpdateCheck Then
2132
CheckForUpdate()
@@ -45,6 +56,7 @@ Public Class Form1
4556
tf2.directory = "common\Team Fortress 2\"
4657
tf2.ToCfg = "tf\cfg\"
4758
tf2.libraryname = "tf2\"
59+
tf2.samplerate = 22050
4860
Games.Add(tf2)
4961

5062
Dim gmod As New SourceGame
@@ -214,7 +226,7 @@ Public Class Form1
214226
End Function
215227

216228
Private Sub ReloadTracks(Game As SourceGame)
217-
If System.IO.Directory.Exists(Game.libraryname) Then
229+
If IO.Directory.Exists(Game.libraryname) Then
218230

219231
Game.tracks.Clear()
220232
For Each File In System.IO.Directory.GetFiles(Game.libraryname)
@@ -295,6 +307,10 @@ Public Class Form1
295307
Dim GameDir As String = Path.Combine(SteamappsPath, Game.directory)
296308
Dim GameCfgFolder As String = Path.Combine(GameDir, Game.ToCfg)
297309

310+
If Not IO.Directory.Exists(GameCfgFolder) Then
311+
Throw New System.Exception("Steamapps folder is incorrect. Disable ""override folder detection"", or select a correct folder.")
312+
End If
313+
298314
'slam.cfg
299315
Using slam_cfg As StreamWriter = New StreamWriter(GameCfgFolder & "slam.cfg")
300316
slam_cfg.WriteLine("alias slam_listtracks ""exec slam_tracklist.cfg""")
@@ -357,11 +373,11 @@ Public Class Form1
357373

358374
End Sub
359375

360-
Private Function LoadTrack(ByVal Game As SourceGame, ByVal index As Integer, ByVal SteamappsPath As String) As Boolean
376+
Private Function LoadTrack(ByVal Game As SourceGame, ByVal index As Integer) As Boolean
361377
Dim Track As track
362378
If Game.tracks.Count > index Then
363379
Track = Game.tracks(index)
364-
Dim voicefile As String = Path.Combine(SteamappsPath, Game.directory) & "voice_input.wav"
380+
Dim voicefile As String = Path.Combine(SteamAppsPath, Game.directory) & "voice_input.wav"
365381
Try
366382
If File.Exists(voicefile) Then
367383
File.Delete(voicefile)
@@ -400,7 +416,7 @@ Public Class Form1
400416

401417
End If
402418

403-
Dim GameCfgFolder As String = Path.Combine(SteamappsPath, Game.directory, Game.ToCfg)
419+
Dim GameCfgFolder As String = Path.Combine(SteamAppsPath, Game.directory, Game.ToCfg)
404420
Using slam_curtrack As StreamWriter = New StreamWriter(GameCfgFolder & "slam_curtrack.cfg")
405421
slam_curtrack.WriteLine("echo ""[SLAM] Track name: {0}""", Track.name)
406422
End Using
@@ -432,41 +448,52 @@ Public Class Form1
432448
End Function
433449

434450
Private Sub PollRelayWorker_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles PollRelayWorker.DoWork
435-
PollRelayWorker.ReportProgress(-1) 'Report that SLAM is searching.
451+
PollRelayWorker.ReportProgress(SEARCHING) 'Report that SLAM is searching.
436452

437453
Dim Game As SourceGame = e.Argument
438454
Dim GameDir As String = Game.directory & Game.exename & ".exe"
439455

440-
Dim SteamAppsPath As String = vbNullString
456+
SteamAppsPath = vbNullString
441457
Dim UserDataPath As String = vbNullString
442458

443459
Try
444-
Do While Not PollRelayWorker.CancellationPending
460+
If Not My.Settings.OverrideFolders Then
445461

446-
Dim GameProcess As String = GetFilepath(Game.exename)
447-
If Not String.IsNullOrEmpty(GameProcess) AndAlso GameProcess.EndsWith(GameDir) Then
448-
SteamAppsPath = GameProcess.Remove(GameProcess.Length - GameDir.Length)
449-
End If
462+
Do While Not PollRelayWorker.CancellationPending
450463

451-
Dim SteamProcess As String = GetFilepath("Steam")
452-
If Not String.IsNullOrEmpty(SteamProcess) Then
453-
UserDataPath = SteamProcess.Remove(SteamProcess.Length - "Steam.exe".Length) & "userdata\"
454-
End If
464+
Dim GameProcess As String = GetFilepath(Game.exename)
465+
If Not String.IsNullOrEmpty(GameProcess) AndAlso GameProcess.EndsWith(GameDir) Then
466+
SteamAppsPath = GameProcess.Remove(GameProcess.Length - GameDir.Length)
467+
End If
468+
469+
Dim SteamProcess As String = GetFilepath("Steam")
470+
If Not String.IsNullOrEmpty(SteamProcess) Then
471+
UserDataPath = SteamProcess.Remove(SteamProcess.Length - "Steam.exe".Length) & "userdata\"
472+
End If
455473

456-
If System.IO.Directory.Exists(SteamAppsPath) Then
457-
If Not Game.id = 0 Then
474+
If IO.Directory.Exists(SteamAppsPath) Then
475+
If Not Game.id = 0 Then
458476

459-
If System.IO.Directory.Exists(UserDataPath) Then
477+
If IO.Directory.Exists(UserDataPath) Then
478+
Exit Do
479+
End If
480+
481+
Else
460482
Exit Do
461483
End If
462-
463-
Else
464-
Exit Do
465484
End If
466-
End If
467485

468-
Thread.Sleep(Game.PollInterval)
469-
Loop
486+
Thread.Sleep(Game.PollInterval)
487+
Loop
488+
489+
Else
490+
SteamAppsPath = My.Settings.steamapps
491+
If IO.Directory.Exists(My.Settings.userdata) Then
492+
UserDataPath = My.Settings.userdata
493+
Else
494+
Throw New System.Exception("Userdata folder does not exist. Disable ""override folder detection"", or select a correct folder.")
495+
End If
496+
End If
470497

471498
If Not String.IsNullOrEmpty(SteamAppsPath) Then
472499
CreateCfgFiles(Game, SteamAppsPath)
@@ -479,7 +506,7 @@ Public Class Form1
479506
End Try
480507

481508

482-
PollRelayWorker.ReportProgress(-2) 'Report that SLAM is working.
509+
PollRelayWorker.ReportProgress(WORKING) 'Report that SLAM is working.
483510

484511
Do While Not PollRelayWorker.CancellationPending
485512
Try
@@ -500,7 +527,7 @@ Public Class Form1
500527
If Not String.IsNullOrEmpty(command) Then
501528
'load audiofile
502529
If IsNumeric(command) Then
503-
If LoadTrack(Game, Convert.ToInt32(command) - 1, SteamAppsPath) Then
530+
If LoadTrack(Game, Convert.ToInt32(command) - 1) Then
504531
PollRelayWorker.ReportProgress(Convert.ToInt32(command) - 1)
505532
End If
506533
End If
@@ -526,7 +553,7 @@ Public Class Form1
526553
End Sub
527554

528555
Public Function UserDataCFG(Game As SourceGame, UserdataPath As String) As String
529-
If System.IO.Directory.Exists(UserdataPath) Then
556+
If IO.Directory.Exists(UserdataPath) Then
530557
For Each userdir As String In System.IO.Directory.GetDirectories(UserdataPath)
531558
Dim CFGPath As String = Path.Combine(userdir, Game.id.ToString) & "\local\cfg\slam_relay.cfg"
532559
If File.Exists(CFGPath) Then
@@ -545,7 +572,7 @@ Public Class Form1
545572
Using results = searcher.Get()
546573

547574
Dim Process As ManagementObject = results.Cast(Of ManagementObject)().FirstOrDefault()
548-
If Process IsNot Nothing Then
575+
If Process IsNot Nothing AndAlso Not String.IsNullOrEmpty(Process("ExecutablePath").ToString) Then
549576
Return Process("ExecutablePath").ToString
550577
End If
551578

@@ -557,9 +584,11 @@ Public Class Form1
557584

558585
Private Sub PollRelayWorker_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles PollRelayWorker.ProgressChanged
559586
Select Case e.ProgressPercentage
560-
Case -1
587+
Case SEARCHING
588+
status = SEARCHING
561589
StatusLabel.Text = "Status: Searching..."
562-
Case -2
590+
Case WORKING
591+
status = WORKING
563592
StatusLabel.Text = "Status: Working."
564593
Case Else
565594
DisplayLoaded(e.ProgressPercentage)
@@ -572,6 +601,7 @@ Public Class Form1
572601
StopPoll()
573602
End If
574603

604+
status = IDLE
575605
StatusLabel.Text = "Status: Idle."
576606

577607
If Not IsNothing(e.Result) Then 'Result is always an exception
@@ -698,10 +728,14 @@ Public Class Form1
698728
Else
699729
If running Then
700730
TrimToolStripMenuItem.Visible = True 'visible when only one selected AND is running
731+
If status = WORKING Then
732+
LoadToolStripMenuItem.Visible = True
733+
End If
701734
Else
702735
For Each Control In TrackContextMenu.Items 'visible when only one selected AND is not running (all)
703736
Control.visible = True
704737
Next
738+
LoadToolStripMenuItem.Visible = False
705739
End If
706740

707741
End If
@@ -896,9 +930,13 @@ Public Class Form1
896930
Private Sub PlayKeyButton_Click(sender As Object, e As EventArgs) Handles PlayKeyButton.Click
897931
Dim SelectKeyDialog As New SelectKey
898932
If SelectKeyDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
899-
My.Settings.PlayKey = SelectKeyDialog.ChosenKey
900-
My.Settings.Save()
901-
RefreshPlayKey()
933+
If Not SelectKeyDialog.ChosenKey = My.Settings.RelayKey Then
934+
My.Settings.PlayKey = SelectKeyDialog.ChosenKey
935+
My.Settings.Save()
936+
RefreshPlayKey()
937+
Else
938+
MessageBox.Show("Play key and relay key can not be the same!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
939+
End If
902940
End If
903941
End Sub
904942

@@ -909,7 +947,7 @@ Public Class Form1
909947
Private Sub LogError(ByVal ex As Exception)
910948
If My.Settings.LogError Then
911949
Using log As StreamWriter = New StreamWriter("errorlog.txt", True)
912-
log.WriteLine("--------------------{0}--------------------", DateTime.Now)
950+
log.WriteLine("--------------------{0} UTC--------------------", DateTime.Now.ToUniversalTime)
913951
log.WriteLine(ex.ToString)
914952
End Using
915953
End If
@@ -952,4 +990,9 @@ Public Class Form1
952990
e.Cancel = True
953991
End If
954992
End Sub
993+
994+
Private Sub LoadToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles LoadToolStripMenuItem.Click
995+
LoadTrack(GetCurrentGame, TrackList.SelectedItems(0).Index)
996+
DisplayLoaded(TrackList.SelectedItems(0).Index)
997+
End Sub
955998
End Class

SLAM/My Project/Settings.Designer.vb

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SLAM/My Project/Settings.settings

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,14 @@
2929
<Setting Name="HoldToPlay" Type="System.Boolean" Scope="User">
3030
<Value Profile="(Default)">False</Value>
3131
</Setting>
32+
<Setting Name="OverrideFolders" Type="System.Boolean" Scope="User">
33+
<Value Profile="(Default)">False</Value>
34+
</Setting>
35+
<Setting Name="steamapps" Type="System.String" Scope="User">
36+
<Value Profile="(Default)">C:\Program Files (x86)\Steam\steamapps\</Value>
37+
</Setting>
38+
<Setting Name="userdata" Type="System.String" Scope="User">
39+
<Value Profile="(Default)">C:\Program Files (x86)\Steam\userdata\</Value>
40+
</Setting>
3241
</Settings>
3342
</SettingsFile>

0 commit comments

Comments
 (0)