1.7.0.0 update: moved audio fetch logic to Util.cs and added old gun sound feature

This commit is contained in:
Kim, Jimin 2021-10-19 14:02:48 +09:00
parent b1c5289a9d
commit 14782ba2f9
3 changed files with 89 additions and 29 deletions

View file

@ -1,12 +1,28 @@
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.Text;
using System.IO;
using System.Threading.Tasks;
using System.Runtime.Serialization.Json;
namespace WBM
{
public class Util
{
public async static Task<AudioClip> fetchAudioClip(string where)
{
using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip("file://" + where, AudioType.WAV))
{
uwr.SendWebRequest();
while (!uwr.isDone) await Task.Delay(10);
return DownloadHandlerAudioClip.GetContent(uwr);
}
}
public static string data2JSON(Data.SerializableData data)
{
MemoryStream stream = new MemoryStream();

View file

@ -4,15 +4,13 @@ using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
using System;
using System.IO;
using System.Threading.Tasks;
namespace WBM
{
[BepInPlugin("com.developomp.wbm", "War Brokers Mods", "1.6.1.0")]
[BepInPlugin("com.developomp.wbm", "War Brokers Mods", "1.7.0.0")]
public partial class WBM : BaseUnityPlugin
{
private void Awake()
@ -45,6 +43,10 @@ namespace WBM
this.clearMessagesFuncRef = webguyType.GetMethod("IOCHBBACKFA", bindFlags);
this.drawChatMessageFuncRef = webguyType.GetMethod("EBDKFEJMEMB", bindFlags);
this.oldGunSoundRef = webguyType.GetField("PINGEJAHHDI", bindFlags);
this.AKSoundRef = webguyType.GetField("BJFBGCMEELH", bindFlags);
this.SMGSoundRef = webguyType.GetField("HKDDIMFIHCE", bindFlags);
// Configurations
this.showGUI = Config.Bind("Config", "show GUI", true);
this.showGUIShortcut = Config.Bind("Hotkeys", "show GUI Shortcut", new KeyboardShortcut(KeyCode.A, KeyCode.RightShift));
@ -86,6 +88,9 @@ namespace WBM
this.clearChatShortcut = Config.Bind("Hotkeys", "clear chat", new KeyboardShortcut(KeyCode.Z, KeyCode.RightShift));
this.clearDeathLogShortcut = Config.Bind("Hotkeys", "clear messages", new KeyboardShortcut(KeyCode.X, KeyCode.RightShift));
this.useOldGunSoundConf = Config.Bind("Config", "use old gun sound", true);
this.useOldGunSoundConf.SettingChanged += this.useOldGunSoundChanged;
// Audio
this.killStreakAudioSource = this.gameObject.AddComponent<AudioSource>();
@ -100,31 +105,16 @@ namespace WBM
{
Logger.LogDebug("Loading AudioClip " + Path.GetFileNameWithoutExtension(fileName));
using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip("file://" + Path.Combine(this.audioPath, fileName), AudioType.WAV))
{
uwr.SendWebRequest();
try
{
while (!uwr.isDone) await Task.Delay(5);
if (uwr.result == UnityWebRequest.Result.ProtocolError) Logger.LogError($"{uwr.error}");
else
{
this.killStreakAudioDict.Add(
Path.GetFileNameWithoutExtension(fileName),
DownloadHandlerAudioClip.GetContent(uwr)
);
}
}
catch (Exception err)
{
Logger.LogError($"{err.Message}, {err.StackTrace}");
}
}
this.AudioDict.Add(
Path.GetFileNameWithoutExtension(fileName),
await Util.fetchAudioClip(Path.Combine(this.audioPath, fileName))
);
}
this.oldGunSound = this.oldGunSoundRaw;
this.newAKSound = this.AKSoundRaw.ADCOCHNNCHM;
this.newSMGSound = this.SMGSoundRaw.ADCOCHNNCHM;
// Websocket
server = new WebSocketSharp.Server.WebSocketServer($"ws://127.0.0.1:{this.serverPort}");
@ -226,7 +216,7 @@ kill streak SFX: {this.killStreakSFX.Value} ({this.killStreakSFXShortcut.Value})
new Rect(this.GUIOffsetX.Value, this.GUIOffsetY.Value, 220, 60),
@"War Brokers Mods
Made by [LP] POMP
v1.6.1.0"
v1.7.0.0"
);
if (this.data.localPlayerIndex >= 0)

View file

@ -72,8 +72,27 @@ namespace WBM
private ConfigEntry<KeyboardShortcut> clearChatShortcut;
private ConfigEntry<KeyboardShortcut> clearDeathLogShortcut;
private ConfigEntry<bool> useOldGunSoundConf;
private void useOldGunSoundChanged(object sender, EventArgs e)
{
if (this.useOldGunSoundConf.Value)
{
this.AKSoundRaw.ADCOCHNNCHM = this.oldGunSound;
this.SMGSoundRaw.ADCOCHNNCHM = this.oldGunSound;
}
else
{
this.AKSoundRaw.ADCOCHNNCHM = this.newAKSound;
this.SMGSoundRaw.ADCOCHNNCHM = this.newSMGSound;
}
}
// Audio
private Dictionary<string, AudioClip> killStreakAudioDict = new Dictionary<string, AudioClip>();
private AudioClip oldGunSound;
private AudioClip newAKSound;
private AudioClip newSMGSound;
private Dictionary<string, AudioClip> AudioDict = new Dictionary<string, AudioClip>();
private string audioPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "assets/audio");
private AudioSource killStreakAudioSource;
private Dictionary<int, string> killStreakSFXDictionary = new Dictionary<int, string>()
@ -235,6 +254,41 @@ namespace WBM
}
}
private FieldInfo oldGunSoundRef;
private AudioClip oldGunSoundRaw
{
get
{
return ((LPJKBALIFCC)this.oldGunSoundRef.GetValue(this.webguy)).ADCOCHNNCHM;
}
}
private FieldInfo AKSoundRef;
private LPJKBALIFCC AKSoundRaw
{
get
{
return (LPJKBALIFCC)this.AKSoundRef.GetValue(this.webguy);
}
set
{
this.AKSoundRef.SetValue(this.webguy, value);
}
}
private FieldInfo SMGSoundRef;
private LPJKBALIFCC SMGSoundRaw
{
get
{
return (LPJKBALIFCC)this.SMGSoundRef.GetValue(this.webguy);
}
set
{
this.SMGSoundRef.SetValue(this.webguy, value);
}
}
// Methods
private MethodInfo addMessageFuncRef;
private MethodInfo clearMessagesFuncRef;
@ -265,7 +319,7 @@ namespace WBM
{
if (this.killStreakSFX.Value && this.killStreakSFXDictionary.ContainsKey(this.killStreak))
{
this.killStreakAudioSource.clip = this.killStreakAudioDict[this.killStreakSFXDictionary[this.killStreak]];
this.killStreakAudioSource.clip = this.AudioDict[this.killStreakSFXDictionary[this.killStreak]];
this.killStreakAudioSource.Play();
this.addMessageFuncRef.Invoke(this.webguy, new object[] { $"You are on a {this.killStreak} kill streak", -1 });