private void ReloadTracks(SourceGame Game) { if (System.IO.Directory.Exists(Game.Libraryname)) { Game.Tracks.Clear(); foreach (var File in System.IO.Directory.GetFiles(Game.Libraryname)) { if (Game.FileExtension == Path.GetExtension(File)) { Track track1 = new Track(); track1.Name = Path.GetFileNameWithoutExtension(File); Game.Tracks.Add(track1); } } CreateTags(Game); LoadTrackKeys(Game); SaveTrackKeys(Game); //To prune hotkeys from non-existing tracks } else { System.IO.Directory.CreateDirectory(Game.Libraryname); } }
private void RefreshTrackList() { mTracks_lst.Items.Clear(); SourceGame Game = GetCurrentGame(); foreach (var Track in Game.Tracks) { string trimmed = ""; if (Track.Endpos > 0) { trimmed = "Yes"; } mTracks_lst.Items.Add(new ListViewItem(new string[] { "False", Track.Name, Track.Hotkey, Track.Volume + "%", trimmed, "\"" + string.Join("\", \"", Track.Tags) + "\"" })); } mTracks_lst.AutoResizeColumn(0, ColumnHeaderAutoResizeStyle.HeaderSize); mTracks_lst.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent); mTracks_lst.AutoResizeColumn(2, ColumnHeaderAutoResizeStyle.HeaderSize); mTracks_lst.AutoResizeColumn(3, ColumnHeaderAutoResizeStyle.HeaderSize); mTracks_lst.AutoResizeColumn(4, ColumnHeaderAutoResizeStyle.HeaderSize); mTracks_lst.AutoResizeColumn(5, ColumnHeaderAutoResizeStyle.ColumnContent); }
private void SaveTrackKeys(SourceGame Game) { List <Track> SettingsList = new List <Track>(); string SettingsFile = Path.Combine(Game.Libraryname, "TrackSettings.xml"); foreach (var Track in Game.Tracks) { if (!string.IsNullOrEmpty(Track.Hotkey) | !(Track.Volume == 100) | Track.Endpos > 0) { SettingsList.Add(Track); } } if (SettingsList.Count > 0) { using (StreamWriter writer = new StreamWriter(SettingsFile)) { writer.Write(XmlSerialization.Serialize(SettingsList)); } } else { if (File.Exists(SettingsFile)) { File.Delete(SettingsFile); } } }
private void LoadTrackKeys(SourceGame Game) { List <Track> SettingsList = new List <Track>(); string SettingsFile = Path.Combine(Game.Libraryname, "TrackSettings.xml"); if (File.Exists(SettingsFile)) { string XmlFile = null; using (StreamReader reader = new StreamReader(SettingsFile)) { XmlFile = reader.ReadToEnd(); } SettingsList = XmlSerialization.Deserialize <List <Track> >(XmlFile); } foreach (var Track in Game.Tracks) { foreach (var SetTrack in SettingsList) { if (Track.Name == SetTrack.Name) { //Please tell me that there is a better way to do the following... Track.Hotkey = SetTrack.Hotkey; Track.Volume = SetTrack.Volume; Track.Startpos = SetTrack.Startpos; Track.Endpos = SetTrack.Endpos; } } } }
private void GoToToolStripMenuItem_Click(object sender, EventArgs e) { SourceGame Games = GetCurrentGame(); string FilePath = Path.Combine(Games.Libraryname, Games.Tracks[mTracks_lst.SelectedItems[0].Index].Name + Games.FileExtension); string Args = string.Format("/Select, \"{0}\"", FilePath); ProcessStartInfo pfi = new ProcessStartInfo("Explorer.exe", Args); System.Diagnostics.Process.Start(pfi); }
private void WaveCreator(string File, string outputFile, SourceGame Game) { MediaFoundationReader reader = new MediaFoundationReader(File); var outFormat = new WaveFormat(Game.Samplerate, Game.Bits, Game.Channels); var resampler = new MediaFoundationResampler(reader, outFormat); resampler.ResamplerQuality = 60; WaveFileWriter.CreateWaveFile(outputFile, resampler); resampler.Dispose(); }
public string UserDataCFG(SourceGame Game, string UserdataPath) { if (System.IO.Directory.Exists(UserdataPath)) { foreach (string userdir in System.IO.Directory.GetDirectories(UserdataPath)) { string CFGPath = Path.Combine(userdir, Game.Id.ToString()) + "\\local\\cfg\\slam_relay.cfg"; if (File.Exists(CFGPath)) { return(CFGPath); } } } return(Constants.vbNullString); }
private void TrimToolStripMenuItem_Click(object sender, EventArgs e) { SourceGame Game = GetCurrentGame(); TrimForm TrimDialog = new TrimForm(); TrimDialog.WavFile = Path.Combine(Game.Libraryname, Game.Tracks[mTracks_lst.SelectedIndices[0]].Name + Game.FileExtension); TrimDialog.startpos = Game.Tracks[mTracks_lst.SelectedIndices[0]].Startpos; TrimDialog.endpos = Game.Tracks[mTracks_lst.SelectedIndices[0]].Endpos; if (TrimDialog.ShowDialog() == DialogResult.OK) { Game.Tracks[mTracks_lst.SelectedIndices[0]].Startpos = TrimDialog.startpos; Game.Tracks[mTracks_lst.SelectedIndices[0]].Endpos = TrimDialog.endpos; SaveTrackKeys(GetCurrentGame()); ReloadTracks(GetCurrentGame()); RefreshTrackList(); } }
private void RenameToolStripMenuItem_Click(object sender, EventArgs e) { SourceGame Game = GetCurrentGame(); RenameForm RenameDialog = new RenameForm(); SourceGame.Track SelectedTrack = GetCurrentGame().Tracks[mTracks_lst.SelectedIndices[0]]; RenameDialog.filename = SelectedTrack.Name; if (RenameDialog.ShowDialog() == DialogResult.OK) { try { FileSystem.Rename(Game.Libraryname + SelectedTrack.Name + Game.FileExtension, Game.Libraryname + RenameDialog.filename + Game.FileExtension); GetCurrentGame().Tracks[mTracks_lst.SelectedIndices[0]].Name = RenameDialog.filename; SaveTrackKeys(GetCurrentGame()); ReloadTracks(GetCurrentGame()); RefreshTrackList(); } catch (Exception ex) { switch (ex.HResult) { case -2147024809: MessageBox.Show("\"" + RenameDialog.filename + "\" contains invalid characters.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case -2146232800: MessageBox.Show("A track with that name already exists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; default: MessageBox.Show(ex.Message + " See errorlog.txt for more info.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } } }
private void DeleteCFGs(SourceGame Game, string SteamappsPath) { string GameDir = Path.Combine(SteamappsPath, Game.Directory); string GameCfgFolder = Path.Combine(GameDir, Game.ToCfg); string[] SlamFiles = { "slam.cfg", "slam_tracklist.cfg", "slam_relay.cfg", "slam_curtrack.cfg", "slam_saycurtrack.cfg", "slam_sayteamcurtrack.cfg" }; string voicefile = Path.Combine(SteamappsPath, Game.Directory) + "voice_input.wav"; try { if (File.Exists(voicefile)) { File.Delete(voicefile); } foreach (var FileName in SlamFiles) { if (File.Exists(GameCfgFolder + FileName)) { File.Delete(GameCfgFolder + FileName); } } } catch (Exception ex) { LogError(ex); } }
private void CreateTags(SourceGame Game) { Dictionary <string, int> NameWords = new Dictionary <string, int>(); int index = 0; foreach (var Track in Game.Tracks) { List <string> Words = Track.Name.Split(new char[] { ' ', '.', '-', '_' }).ToList(); foreach (var Word in Words) { if (!Information.IsNumeric(Word) & !Game.Blacklist.Contains(Word.ToLower()) & Word.Length < 32) { if (NameWords.ContainsKey(Word)) { NameWords.Remove(Word); } else { NameWords.Add(Word, index); } } } index += 1; } foreach (KeyValuePair <string, int> Tag in NameWords) { Game.Tracks.ElementAt(Tag.Value).Tags.Add(Tag.Key); } }
private void ContextDelete_Click(object sender, EventArgs e) { SourceGame game = GetCurrentGame(); List <string> SelectedNames = new List <string>(); foreach (ListViewItem item in mTracks_lst.SelectedItems) { SelectedNames.Add(item.SubItems[1].Text); } if (MessageBox.Show(string.Format("Are you sure you want to delete {0}?", string.Join(", ", SelectedNames)), "Delete Track?", MessageBoxButtons.YesNo) == DialogResult.Yes) { foreach (var item in SelectedNames) { string FilePath = Path.Combine(game.Libraryname, item + game.FileExtension); if (File.Exists(FilePath)) { try { File.Delete(FilePath); } catch (Exception ex) { LogError(ex); Interaction.MsgBox(string.Format("Failed to delete {0}.", FilePath)); } } } } ReloadTracks(GetCurrentGame()); RefreshTrackList(); }
private void WavWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { SourceGame Game = (e.Argument as object[])[0] as SourceGame; string[] Files = (e.Argument as object[])[1] as string[]; List <string> FailedFiles = new List <string>(); foreach (var File in Files) { try { string OutFile = Path.Combine(Game.Libraryname, Path.GetFileNameWithoutExtension(File) + ".wav"); WaveCreator(File, OutFile, Game); } catch (Exception ex) { LogError(ex); FailedFiles.Add(File); } mImportSong_wrk.ReportProgress(0); } e.Result = FailedFiles; }
private bool LoadTrack(SourceGame Game, int index) { Track Track = default(Track); if (Game.Tracks.Count > index) { Track = Game.Tracks[index]; string voicefile = Path.Combine(SteamAppsPath, Game.Directory) + "voice_input.wav"; try { if (File.Exists(voicefile)) { File.Delete(voicefile); } string trackfile = Game.Libraryname + Track.Name + Game.FileExtension; if (File.Exists(trackfile)) { if (Track.Volume == 100 & Track.Startpos == -1 & Track.Endpos == -1) { File.Copy(trackfile, voicefile); } else { WaveChannel32 WaveFloat = new WaveChannel32(new WaveFileReader(trackfile)); if (!(Track.Volume == 100)) { WaveFloat.Volume = (float)Math.Pow((Track.Volume / 100), 6); } if (!(Track.Startpos == Track.Endpos) & Track.Endpos > 0) { byte[] bytes = new byte[(Track.Endpos - Track.Startpos) * 4 + 1]; WaveFloat.Position = Track.Startpos * 4; WaveFloat.Read(bytes, 0, (Track.Endpos - Track.Startpos) * 4); WaveFloat = new WaveChannel32(new RawSourceWaveStream(new MemoryStream(bytes), WaveFloat.WaveFormat)); } WaveFloat.PadWithZeroes = false; var outFormat = new WaveFormat(Game.Samplerate, Game.Bits, Game.Channels); var resampler = new MediaFoundationResampler(WaveFloat, outFormat); resampler.ResamplerQuality = 60; WaveFileWriter.CreateWaveFile(voicefile, resampler); resampler.Dispose(); WaveFloat.Dispose(); } string GameCfgFolder = Path.Combine(SteamAppsPath, Game.Directory, Game.ToCfg); using (StreamWriter slam_curtrack = new StreamWriter(GameCfgFolder + "slam_curtrack.cfg")) { slam_curtrack.WriteLine("echo \"[SLAM] Track name: {0}\"", Track.Name); } using (StreamWriter slam_saycurtrack = new StreamWriter(GameCfgFolder + "slam_saycurtrack.cfg")) { slam_saycurtrack.WriteLine("say \"[SLAM] Track name: {0}\"", Track.Name); } using (StreamWriter slam_sayteamcurtrack = new StreamWriter(GameCfgFolder + "slam_sayteamcurtrack.cfg")) { slam_sayteamcurtrack.WriteLine("say_team \"[SLAM] Track name: {0}\"", Track.Name); } } } catch (Exception ex) { LogError(ex); return(false); } } else { return(false); } return(true); }
private void CreateCfgFiles(SourceGame Game, string SteamappsPath) { string GameDir = Path.Combine(SteamappsPath, Game.Directory); string GameCfgFolder = Path.Combine(GameDir, Game.ToCfg); if (!System.IO.Directory.Exists(GameCfgFolder)) { throw new System.Exception("Steamapps folder is incorrect. Disable \"override folder detection\", or select a correct folder."); } //slam.cfg using (StreamWriter slam_cfg = new StreamWriter(GameCfgFolder + "slam.cfg")) { slam_cfg.WriteLine("alias slam_listtracks \"exec slam_tracklist.cfg\""); slam_cfg.WriteLine("alias list slam_listtracks"); slam_cfg.WriteLine("alias tracks slam_listtracks"); slam_cfg.WriteLine("alias la slam_listtracks"); slam_cfg.WriteLine("alias slam_play slam_play_on"); slam_cfg.WriteLine("alias slam_play_on \"alias slam_play slam_play_off; voice_inputfromfile 1; voice_loopback 1; +voicerecord\""); slam_cfg.WriteLine("alias slam_play_off \"-voicerecord; voice_inputfromfile 0; voice_loopback 0; alias slam_play slam_play_on\""); slam_cfg.WriteLine("alias slam_updatecfg \"host_writeconfig slam_relay\""); if (SLAM.Properties.Settings.Default.HoldToPlay) { slam_cfg.WriteLine("alias +slam_hold_play slam_play_on"); slam_cfg.WriteLine("alias -slam_hold_play slam_play_off"); slam_cfg.WriteLine("bind {0} +slam_hold_play", SLAM.Properties.Settings.Default.PlayKey); } else { slam_cfg.WriteLine("bind {0} slam_play", SLAM.Properties.Settings.Default.PlayKey); } slam_cfg.WriteLine("alias slam_curtrack \"exec slam_curtrack.cfg\""); slam_cfg.WriteLine("alias slam_saycurtrack \"exec slam_saycurtrack.cfg\""); slam_cfg.WriteLine("alias slam_sayteamcurtrack \"exec slam_sayteamcurtrack.cfg\""); foreach (var Track in Game.Tracks) { int index = Game.Tracks.IndexOf(Track); slam_cfg.WriteLine("alias {0} \"bind {1} {0}; slam_updatecfg; echo Loaded: {2}\"", index + 1, SLAM.Properties.Settings.Default.RelayKey, Track.Name); foreach (var TrackTag in Track.Tags) { slam_cfg.WriteLine("alias {0} \"bind {1} {2}; slam_updatecfg; echo Loaded: {3}\"", TrackTag, SLAM.Properties.Settings.Default.RelayKey, index + 1, Track.Name); } if (!string.IsNullOrEmpty(Track.Hotkey)) { slam_cfg.WriteLine("bind {0} \"bind {1} {2}; slam_updatecfg; echo Loaded: {3}\"", Track.Hotkey, SLAM.Properties.Settings.Default.RelayKey, index + 1, Track.Name); } } string CfgData = null; CfgData = "voice_enable 1; voice_modenable 1; voice_forcemicrecord 0; con_enable 1"; if (Game.VoiceFadeOut) { CfgData = CfgData + "; voice_fadeouttime 0.0"; } slam_cfg.WriteLine(CfgData); } //slam_tracklist.cfg using (StreamWriter slam_tracklist_cfg = new StreamWriter(GameCfgFolder + "slam_tracklist.cfg")) { slam_tracklist_cfg.WriteLine("echo \"You can select tracks either by typing a tag, or their track number.\""); slam_tracklist_cfg.WriteLine("echo \"--------------------Tracks--------------------\""); foreach (var Track in Game.Tracks) { int index = Game.Tracks.IndexOf(Track); if (SLAM.Properties.Settings.Default.WriteTags) { slam_tracklist_cfg.WriteLine("echo \"{0}. {1} [{2}]\"", index + 1, Track.Name, "'" + string.Join("', '", Track.Tags) + "'"); } else { slam_tracklist_cfg.WriteLine("echo \"{0}. {1}\"", index + 1, Track.Name); } } slam_tracklist_cfg.WriteLine("echo \"----------------------------------------------\""); } }
private void Form1_Load(object sender, EventArgs e) { RefreshPlayKey(); if (SLAM.Properties.Settings.Default.PlayKey == SLAM.Properties.Settings.Default.RelayKey) { SLAM.Properties.Settings.Default.RelayKey = "="; SLAM.Properties.Settings.Default.Save(); } SourceGame csgo = new SourceGame(); csgo.Name = "Counter-Strike: Global Offensive"; csgo.Id = 730; csgo.Directory = "common\\Counter-Strike Global Offensive\\"; csgo.ToCfg = "csgo\\cfg\\"; csgo.Libraryname = "csgo\\"; csgo.Exename = "csgo"; csgo.Samplerate = 22050; csgo.Blacklist.AddRange(new string[] { "drop", "buy", "go", "fallback", "sticktog", "holdpos", "followme", "coverme", "regroup", "roger", "negative", "cheer", "compliment", "thanks", "enemydown", "reportingin", "enemyspot", "takepoint", "sectorclear", "inposition", "takingfire", "report", "getout" }); csgo.VoiceFadeOut = false; Games.Add(csgo); SourceGame css = new SourceGame(); css.Name = "Counter-Strike: Source"; css.Directory = "common\\Counter-Strike Source\\"; css.ToCfg = "cstrike\\cfg\\"; css.Libraryname = "css\\"; Games.Add(css); SourceGame tf2 = new SourceGame(); tf2.Name = "Team Fortress 2"; tf2.Directory = "common\\Team Fortress 2\\"; tf2.ToCfg = "tf\\cfg\\"; tf2.Libraryname = "tf2\\"; tf2.Samplerate = 22050; Games.Add(tf2); SourceGame gmod = new SourceGame(); gmod.Name = "Garry's Mod"; gmod.Directory = "common\\GarrysMod\\"; gmod.ToCfg = "garrysmod\\cfg\\"; gmod.Libraryname = "gmod\\"; Games.Add(gmod); SourceGame hl2dm = new SourceGame(); hl2dm.Name = "Half-Life 2 Deathmatch"; hl2dm.Directory = "common\\half-life 2 deathmatch\\"; hl2dm.ToCfg = "hl2mp\\cfg\\"; hl2dm.Libraryname = "hl2dm\\"; Games.Add(hl2dm); SourceGame l4d = new SourceGame(); l4d.Name = "Left 4 Dead"; l4d.Directory = "common\\Left 4 Dead\\"; l4d.ToCfg = "left4dead\\cfg\\"; l4d.Libraryname = "l4d\\"; l4d.Exename = "left4dead"; Games.Add(l4d); SourceGame l4d2 = new SourceGame(); l4d2.Name = "Left 4 Dead 2"; l4d2.Directory = "common\\Left 4 Dead 2\\"; l4d2.ToCfg = "left4dead2\\cfg\\"; l4d2.Libraryname = "l4d2\\"; l4d2.Exename = "left4dead2"; l4d2.VoiceFadeOut = false; Games.Add(l4d2); SourceGame dods = new SourceGame(); dods.Name = "Day of Defeat Source"; dods.Directory = "common\\day of defeat source\\"; dods.ToCfg = "dod\\cfg\\"; dods.Libraryname = "dods\\"; Games.Add(dods); //NEEDS EXENAME!!! //Dim goldeye As New SourceGame //goldeye.name = "Goldeneye Source" //goldeye.directory = "sourcemods\" //goldeye.ToCfg = "gesource\cfg\" //goldeye.libraryname = "goldeye\" //Games.Add(goldeye) SourceGame insurg = new SourceGame(); insurg.Name = "Insurgency"; insurg.Directory = "common\\insurgency2\\"; insurg.ToCfg = "insurgency\\cfg\\"; insurg.Libraryname = "insurgen\\"; insurg.Exename = "insurgency"; Games.Add(insurg); foreach (var Game in Games) { mGameSelector_combo.Items.Add(Game.Name); } if (mGameSelector_combo.Items.Contains(SLAM.Properties.Settings.Default.LastGame)) { mGameSelector_combo.Text = mGameSelector_combo.Items[mGameSelector_combo.Items.IndexOf(SLAM.Properties.Settings.Default.LastGame)].ToString(); } else { mGameSelector_combo.Text = mGameSelector_combo.Items[0].ToString(); } ReloadTracks(GetCurrentGame()); RefreshTrackList(); if (SLAM.Properties.Settings.Default.StartEnabled) { StartPoll(); } }
private void PollRelayWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { mPollRelay_wrk.ReportProgress(SEARCHING); //Report that SLAM is searching. SourceGame Game = e.Argument as SourceGame; string GameDir = Game.Directory + Game.Exename + ".exe"; SteamAppsPath = Constants.vbNullString; string UserDataPath = Constants.vbNullString; try { if (!SLAM.Properties.Settings.Default.OverrideFolders) { while (!mPollRelay_wrk.CancellationPending) { string GameProcess = GetFilepath(Game.Exename); if (!string.IsNullOrEmpty(GameProcess) && GameProcess.EndsWith(GameDir)) { SteamAppsPath = GameProcess.Remove(GameProcess.Length - GameDir.Length); } string SteamProcess = GetFilepath("Steam"); if (!string.IsNullOrEmpty(SteamProcess)) { UserDataPath = SteamProcess.Remove(SteamProcess.Length - "Steam.exe".Length) + "userdata\\"; } if (System.IO.Directory.Exists(SteamAppsPath)) { if (!(Game.Id == 0)) { if (System.IO.Directory.Exists(UserDataPath)) { break; // TODO: might not be correct. Was : Exit Do } } else { break; // TODO: might not be correct. Was : Exit Do } } Thread.Sleep(Game.PollInterval); } } else { SteamAppsPath = SLAM.Properties.Settings.Default.steamapps; if (System.IO.Directory.Exists(SLAM.Properties.Settings.Default.userdata)) { UserDataPath = SLAM.Properties.Settings.Default.userdata; } else { throw new System.Exception("Userdata folder does not exist. Disable \"override folder detection\", or select a correct folder."); } } if (!string.IsNullOrEmpty(SteamAppsPath)) { CreateCfgFiles(Game, SteamAppsPath); } } catch (Exception ex) { LogError(ex); e.Result = ex; return; } mPollRelay_wrk.ReportProgress(WORKING); //Report that SLAM is working. while (!mPollRelay_wrk.CancellationPending) { try { string GameFolder = Path.Combine(SteamAppsPath, Game.Directory); string GameCfg = Path.Combine(GameFolder, Game.ToCfg) + "slam_relay.cfg"; if (!(Game.Id == 0)) { GameCfg = UserDataCFG(Game, UserDataPath); } if (File.Exists(GameCfg)) { string RelayCfg = null; using (StreamReader reader = new StreamReader(GameCfg)) { RelayCfg = reader.ReadToEnd(); } string command = recog(RelayCfg, string.Format("bind \"{0}\" \"(.*?)\"", SLAM.Properties.Settings.Default.RelayKey)); if (!string.IsNullOrEmpty(command)) { //load audiofile if (Information.IsNumeric(command)) { if (LoadTrack(Game, Convert.ToInt32(command) - 1)) { mPollRelay_wrk.ReportProgress(Convert.ToInt32(command) - 1); } } File.Delete(GameCfg); } } Thread.Sleep(Game.PollInterval); } catch (Exception ex) { //-2147024864 = "System.IO.IOException: The process cannot access the file because it is being used by another process." if (!(ex.HResult == -2147024864)) { LogError(ex); e.Result = ex; return; } } } if (!string.IsNullOrEmpty(SteamAppsPath)) { DeleteCFGs(Game, SteamAppsPath); } }