Skip to content

Commit

Permalink
Update 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Koder-Teh committed Jan 11, 2024
1 parent d6d353a commit 7fad1d7
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 7 deletions.
124 changes: 120 additions & 4 deletions BoomboxController/BoomboxController.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 Стартеры

Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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<string> sumbol = new List<string>();
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"))
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions BoomboxController/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 - Изменить громкость трека");
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion BoomboxController/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using DunGen;
using GameNetcodeStuff;
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions BoomboxController/WinApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Binary file modified BoomboxController/obj/Debug/net46/BoomboxController.dll
Binary file not shown.
Binary file modified BoomboxController/obj/Debug/net46/BoomboxController.pdb
Binary file not shown.

0 comments on commit 7fad1d7

Please sign in to comment.