diff --git a/BoomboxController/BoomboxController.cs b/BoomboxController/BoomboxController.cs index a30594f..2b990e7 100644 --- a/BoomboxController/BoomboxController.cs +++ b/BoomboxController/BoomboxController.cs @@ -1,8 +1,10 @@ using BepInEx; +using BepInEx.Bootstrap; using BepInEx.Configuration; using DunGen; using GameNetcodeStuff; using HarmonyLib; +using Mono.Cecil; using Newtonsoft.Json; using System; using System.Collections; @@ -73,6 +75,7 @@ public class Cache public static string[] sumbols = { "+" }; public static KeyControl up = null; public static KeyControl down = null; + private static bool blockcompatibility = false; #region Стартеры @@ -83,10 +86,16 @@ public static void OnEnable_GameNetworkManager(GameNetworkManager __instance) using (StreamWriter sw = new StreamWriter(@"BoomboxController\logReport.txt")) { sw.WriteLine($"Game Version: {__instance.gameVersionNum}"); - sw.WriteLine($"Plugins: {new DirectoryInfo(@"BepInEx\plugins").GetFiles().Length}"); - foreach (var item in new DirectoryInfo(@"BepInEx\plugins").GetFiles()) + sw.WriteLine($"Plugins: {Chainloader.PluginInfos.Count}"); + foreach (var item in Chainloader.PluginInfos) { - sw.WriteLine(item.Name); + if (item.Key == "BoomboxSyncFix") + { + Plugin.instance.Log("Чтобы мод работал, удалите мод BoomboxSyncFix."); + Plugin.instance.Log("For the mod to work, uninstall the BoomboxSyncFix mod."); + blockcompatibility = true; + } + sw.WriteLine(item.Key + " " + item.Value.Location); } } } @@ -519,12 +528,113 @@ public static async void AddChatMessageMain(HUDManager __instance, string chatMe } break; case "bplay": + if (vs.Length == 1) break; Regex regex = new Regex("^https?:\\/\\/(?:www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b(?:[-a-zA-Z0-9()@:%_\\+.~#?&\\/=]*)$"); if (regex.IsMatch(vs[1])) { var url = vs[1].Remove(0, 8); switch (url.Substring(0, url.IndexOf('/'))) { + case "youtu.be": + boomboxItem.boomboxAudio.Stop(); + boomboxItem.boomboxAudio.PlayOneShot(boomboxItem.stopAudios[UnityEngine.Random.Range(0, boomboxItem.stopAudios.Length)]); + timesPlayedWithoutTurningOff = 0; + boomboxItem.isPlayingMusic = false; + boomboxItem.isBeingUsed = false; + LoadingMusicBoombox = true; + FileInfo[] files = new DirectoryInfo(@"BoomboxController\other").GetFiles("*.mp3"); + if (files.Length == 1) + { + File.Delete(@$"BoomboxController\other\{files[0].Name}"); + } + DrawString(__instance, Plugin.config.GetLang().main_7.Value, "Boombox YouTube", nameOfUserWhoTyped); + if (!isplayList) + { + isplayList = true; + await Task.Run(() => + { + bool succeeded = false; + bool part = false; + Process info = new Process(); + info.StartInfo.FileName = @"BoomboxController\other\yt-dlp.exe"; + info.StartInfo.UseShellExecute = false; + info.StartInfo.Arguments = $"-f bestaudio --extract-audio --ignore-config --audio-format mp3 --audio-quality 0 {vs[1]}"; + info.StartInfo.WorkingDirectory = @$"BoomboxController\other"; + info.StartInfo.CreateNoWindow = true; + info.Start(); + Id = info.Id; + while (!succeeded) + { + if (part) + { + if (File.Exists(@$"BoomboxController\other\{NameTrack}")) + { + succeeded = true; + break; + } + } + else + { + foreach (FileInfo f in new DirectoryInfo(@"BoomboxController\other").GetFiles("*.mp3")) + { + if (f.Exists) + { + NameTrack = f.Name; + } + } + if (Process.GetProcessById(info.Id).HasExited) + { + if (File.Exists(@$"BoomboxController\other\{NameTrack}")) + { + part = true; + } + else + { + DrawString(__instance, Plugin.config.GetLang().main_11.Value, "Boombox YouTube", nameOfUserWhoTyped); + break; + } + } + } + System.Threading.Thread.Sleep(1000); + } + }); + if (!File.Exists(@$"BoomboxController\other\{NameTrack}")) + { + LoadingMusicBoombox = false; + isplayList = false; + break; + } + bool sumbBlock = false; + List sumbol = new List(); + FileInfo ext = new FileInfo(@$"BoomboxController\other\{NameTrack}"); + foreach (string sumb in sumbols) + { + if (ext.Name.Contains(sumb)) + { + sumbol.Add(sumb); + sumbBlock = true; + } + } + if (sumbBlock) + { + string NameFile = String.Empty; + foreach (string sumb in sumbol) + { + NameFile = NameTrack.Replace(sumb, ""); + ext.MoveTo(@$"BoomboxController\other\{NameTrack.Replace(sumb, "")}"); + } + currectTrack = 0; + bom.Start(bom.GetAudioClip(@"file:///" + Paths.GameRootPath + @$"\BoomboxController\other\{NameFile}", boomboxItem, AudioType.MPEG)); + DrawString(__instance, Plugin.config.GetLang().main_8.Value, "Boombox YouTube", nameOfUserWhoTyped); + } + else + { + currectTrack = 0; + bom.Start(bom.GetAudioClip(@"file:///" + Paths.GameRootPath + @$"\BoomboxController\other\{NameTrack}", boomboxItem, AudioType.MPEG)); + DrawString(__instance, Plugin.config.GetLang().main_8.Value, "Boombox YouTube", nameOfUserWhoTyped); + } + } + break; case "www.youtube.com": if (vs[1].Contains("search_query")) { @@ -802,6 +912,7 @@ public static async void AddChatMessageMain(HUDManager __instance, string chatMe } break; case "btime": + if (vs.Length == 1) break; string[] arg = vs[1].Split(':'); switch (arg.Length) { @@ -925,6 +1036,7 @@ public static async void AddChatMessageMain(HUDManager __instance, string chatMe } break; case "bvolume": + if (vs.Length == 1) break; float volume = boomboxItem.boomboxAudio.volume; float correct_volume = (Convert.ToInt32(vs[1]) / 10) * 0.1f; if (volume == correct_volume) break; @@ -935,6 +1047,7 @@ public static async void AddChatMessageMain(HUDManager __instance, string chatMe } break; case "btrack": + if (vs.Length == 1) break; if (Convert.ToInt32(vs[1]) > 0) { if (Convert.ToInt32(vs[1]) <= totalTack) @@ -976,7 +1089,10 @@ private static void SubmitChat_performed_HUDManager(HUDManager __instance, ref I } else { - if (IsCommand(__instance.chatTextField.text, new string[] { "bhelp", "bplay", "btime", "bvolume", "btrack" })) SubmitChat(__instance); + if (!blockcompatibility) + { + if (IsCommand(__instance.chatTextField.text, new string[] { "bhelp", "bplay", "btime", "bvolume", "btrack" })) SubmitChat(__instance); + } } } diff --git a/BoomboxController/Configs.cs b/BoomboxController/Configs.cs index c43b633..10deb65 100644 --- a/BoomboxController/Configs.cs +++ b/BoomboxController/Configs.cs @@ -55,7 +55,7 @@ public void GetConfigRU() { var customFile = new ConfigFile(@"BoomboxController\lang\boombox_ru.cfg", true); main_1 = customFile.Bind("General", "Main_1", "Пожалуйста, подождите, загружаются дополнительные библиотеки, чтобы модификация заработала."); - main_2 = customFile.Bind("General", "Main_2", "Взять BoomBox[1.1.6] : [E]\n@2 - @3\n@1 громкость\nСейчас играет: @4\nДоступных треков: @5"); + main_2 = customFile.Bind("General", "Main_2", "Взять BoomBox[1.1.7] : [E]\n@2 - @3\n@1 громкость\nСейчас играет: @4\nДоступных треков: @5"); main_3 = customFile.Bind("General", "Main_3", "Все дополнительные библиотеки загружены, теперь вы можете использовать команды для бумбокса."); main_4 = customFile.Bind("General", "Main_4", "Подождите, трек еще загружается!"); main_5 = customFile.Bind("General", "Main_5", "Команды:\n/bplay - Проиграть музыку\n/btime - Изменить позицию песни\n/bvolume - Изменить громкость трека"); @@ -74,7 +74,7 @@ public void GetConfigEN() { var customFile = new ConfigFile(@"BoomboxController\lang\boombox_en.cfg", true); main_1 = customFile.Bind("General", "Main_1", "Please wait, additional libraries are being loaded for the modification to work."); - main_2 = customFile.Bind("General", "Main_2", "Pickup BoomBox[1.1.6] : [E]\n@2 - @3\n@1 volume\nNow playing: @4\nAvailable tracks: @5"); + main_2 = customFile.Bind("General", "Main_2", "Pickup BoomBox[1.1.7] : [E]\n@2 - @3\n@1 volume\nNow playing: @4\nAvailable tracks: @5"); main_3 = customFile.Bind("General", "Main_3", "All libraries have loaded, now you can use the boombox commands."); main_4 = customFile.Bind("General", "Main_4", "Another track is being uploaded to the boombox!"); main_5 = customFile.Bind("General", "Main_5", "Commands:\n/bplay - Play music\n/btime - Change the position of the song\n/bvolume - Change Boombox volume"); diff --git a/BoomboxController/Plugin.cs b/BoomboxController/Plugin.cs index 8a8ebb6..cdfa917 100644 --- a/BoomboxController/Plugin.cs +++ b/BoomboxController/Plugin.cs @@ -1,4 +1,5 @@ using BepInEx; +using BepInEx.Bootstrap; using BepInEx.Configuration; using DunGen; using GameNetcodeStuff; @@ -41,7 +42,7 @@ namespace BoomboxController { - [BepInPlugin("KoderTech.BoomboxController", "BoomboxController", "1.1.6")] + [BepInPlugin("KoderTech.BoomboxController", "BoomboxController", "1.1.7")] public class Plugin : BaseUnityPlugin { public static Plugin instance; diff --git a/BoomboxController/WinApi.cs b/BoomboxController/WinApi.cs index 7476e38..12319f3 100644 --- a/BoomboxController/WinApi.cs +++ b/BoomboxController/WinApi.cs @@ -9,15 +9,38 @@ namespace BoomboxController { public class WinApi { + public enum MessageBoxResult // https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox#return-value + { + Error = 0, + Abort = 3, // The Abort button was selected. + Cancel = 2, // The Cancel button was selected. + Continue = 11, // The Continue button was selected. + Ignore = 5, // The Ignore button was selected. + No = 7, // The No button was selected. + OK = 1, // The OK button was selected. + Retry = 4, // The Retry button was selected. + TryAgain = 10, // The Try Again button was selected. + Yes = 6 // The Yes button was selected. + } + [DllImport("kernel32.dll", SetLastError = true)] private static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll", SetLastError = true)] private static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern MessageBoxResult MessageBox(IntPtr hwnd, string text, string caption, uint type); + public void SizeConsole(int width, int height) { MoveWindow(GetConsoleWindow(), 200, 200, width, height, true); } + + public static MessageBoxResult SendMessageBox(string text, string caption, uint type) + { + MessageBoxResult result = MessageBox(GetConsoleWindow(), text, caption, type); + return result; + } } } diff --git a/BoomboxController/obj/Debug/net46/BoomboxController.dll b/BoomboxController/obj/Debug/net46/BoomboxController.dll index 1756aa6..a24b607 100644 Binary files a/BoomboxController/obj/Debug/net46/BoomboxController.dll and b/BoomboxController/obj/Debug/net46/BoomboxController.dll differ diff --git a/BoomboxController/obj/Debug/net46/BoomboxController.pdb b/BoomboxController/obj/Debug/net46/BoomboxController.pdb index 37a4336..fe2429f 100644 Binary files a/BoomboxController/obj/Debug/net46/BoomboxController.pdb and b/BoomboxController/obj/Debug/net46/BoomboxController.pdb differ