separated logic to dedicated files/directories

This commit is contained in:
Kim, Jimin 2022-03-12 10:25:37 +09:00
parent 0317053e4c
commit beabe6b56a
20 changed files with 645 additions and 505 deletions

View file

@ -1,128 +0,0 @@
using UnityEngine;
namespace WBM
{
public partial class WBM
{
private void handleKeyPresses()
{
this.moveUIOnKeyPress();
this.resetUIOnKeyPress();
this.toggleUIOnKeyPress();
this.toggleShiftToCrouchOnKeyPress();
this.toggleKillStreakSFXOnKeyPress();
this.togglePlayerStatsOnKeyPress();
this.toggleWeaponStatsOnKeyPress();
this.toggleTeamStatsOnKeyPress();
this.toggleLeaderboardEloOnKeyPress();
this.toggleSquadServerOnKeyPress();
this.toggleTestingServerOnKeyPress();
this.clearChatOnKeyPress();
this.clearDeathLogOnKeyPress();
this.showConfigOnKeyPress();
this.crouchOnKeyPress();
}
private void moveUIOnKeyPress()
{
if (Input.GetKey(KeyCode.LeftControl))
{
// move GUI
if (Input.GetKey(KeyCode.LeftShift))
{
if (Input.GetKey(KeyCode.UpArrow)) this.GUIOffsetY.Value -= 1;
if (Input.GetKey(KeyCode.DownArrow)) this.GUIOffsetY.Value += 1;
if (Input.GetKey(KeyCode.LeftArrow)) this.GUIOffsetX.Value -= 1;
if (Input.GetKey(KeyCode.RightArrow)) this.GUIOffsetX.Value += 1;
}
else
{
if (Input.GetKeyDown(KeyCode.UpArrow)) this.GUIOffsetY.Value -= 1;
if (Input.GetKeyDown(KeyCode.DownArrow)) this.GUIOffsetY.Value += 1;
if (Input.GetKeyDown(KeyCode.LeftArrow)) this.GUIOffsetX.Value -= 1;
if (Input.GetKeyDown(KeyCode.RightArrow)) this.GUIOffsetX.Value += 1;
}
}
}
private void resetUIOnKeyPress()
{
if (this.resetGUIShortcut.Value.IsDown())
{
this.GUIOffsetX.Value = (int)this.GUIOffsetX.DefaultValue;
this.GUIOffsetY.Value = (int)this.GUIOffsetY.DefaultValue;
}
}
private void toggleUIOnKeyPress()
{
if (this.showGUIShortcut.Value.IsDown()) this.showGUI.Value = !this.showGUI.Value;
}
private void toggleShiftToCrouchOnKeyPress()
{
if (this.shiftToCrouchShortcut.Value.IsDown()) this.shiftToCrouch.Value = !this.shiftToCrouch.Value;
}
private void toggleKillStreakSFXOnKeyPress()
{
if (this.killStreakSFXShortcut.Value.IsDown()) this.killStreakSFX.Value = !this.killStreakSFX.Value;
}
private void togglePlayerStatsOnKeyPress()
{
if (this.showPlayerStatsShortcut.Value.IsDown()) this.showPlayerStats.Value = !this.showPlayerStats.Value;
}
private void toggleWeaponStatsOnKeyPress()
{
if (this.showWeaponStatsShortcut.Value.IsDown()) this.showWeaponStats.Value = !this.showWeaponStats.Value;
}
private void toggleTeamStatsOnKeyPress()
{
if (this.showTeamStatsShortcut.Value.IsDown()) this.showTeamStats.Value = !this.showTeamStats.Value;
}
private void toggleLeaderboardEloOnKeyPress()
{
if (this.showEloOnLeaderboardShortcut.Value.IsDown()) this.showEloOnLeaderboard.Value = !this.showEloOnLeaderboard.Value;
}
private void toggleSquadServerOnKeyPress()
{
if (this.showSquadServerShortcut.Value.IsDown()) this.showSquadServer.Value = !this.showSquadServer.Value;
}
private void toggleTestingServerOnKeyPress()
{
if (this.showTestingServerShortcut.Value.IsDown()) this.showTestingServer.Value = !this.showTestingServer.Value;
}
private void clearChatOnKeyPress()
{
if (this.clearChatShortcut.Value.IsDown()) this.clearChat();
}
private void clearDeathLogOnKeyPress()
{
if (this.clearDeathLogShortcut.Value.IsDown()) this.clearMessagesFuncRef.Invoke(this.webguy, new object[] { });
}
private void showConfigOnKeyPress()
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightShift)) this._showConfig = true;
if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightShift)) this._showConfig = false;
}
private void crouchOnKeyPress()
{
// only if right buttton is not held
if (this.shiftToCrouch.Value && !Input.GetMouseButton(1))
{
if (Input.GetKeyDown(KeyCode.LeftShift)) OMOJPGNNKFN.NEELEHFDKBP.EGACOOOGDDC = true;
if (Input.GetKeyUp(KeyCode.LeftShift)) OMOJPGNNKFN.NEELEHFDKBP.EGACOOOGDDC = false;
}
}
}
}

View file

@ -1,16 +0,0 @@
namespace WBM
{
class PrefNames
{
public const string showSquadServer = "showSquadServer";
public const string showTestingServer = "showTestingServer";
public const string GUIOffsetX = "GUIOffsetX";
public const string GUIOffsetY = "GUIOffsetY";
public const string showGUI = "showGUI";
public const string showPlayerStats = "showPlayerStats";
public const string showWeaponStats = "showWeaponStats";
public const string showTeammateStats = "showTeammateStats";
public const string showElo = "showElo";
public const string shiftToCrouch = "shiftToCrouch";
}
}

View file

@ -1,79 +1,70 @@
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
using System;
using System.IO;
namespace WBM
{
/// <summary>
/// Class <c>WBM</c> is a regular unity script component (<c>GameObject</c>).
/// The functions <c>Awake</c>, <c>Start</c>, <c>Update</c>, <c>OnGUI</c>, and <c>onDestroy</c>
/// are event functions that gets called on specific stages of the component's lifecycle.
/// More information can be found in the <see href="https://docs.unity3d.com/Manual/ExecutionOrder.html">unity's documentation page</see>.
/// </summary>
[BepInPlugin("com.developomp.wbm", "War Brokers Mods", "1.7.1.0")]
public partial class WBM : BaseUnityPlugin
{
/// This function is called as soon as the component becomes active.
/// It is the first event function that's called during the component's lifecycle.
private void Awake()
{
this.harmony = new Harmony("com.developomp.wbm");
this.harmony.PatchAll();
}
private async void Start()
{
Logger.LogDebug("Initializing");
this.webguy = FindObjectOfType<webguy>();
this.initCore();
}
System.Type webguyType = typeof(webguy);
/// This function is called only once before the first frame update.
/// The component is more or less initialized at this point,
/// and it is this function that completes the initialization process.
private async void Start()
{
await this.setupCore();
this.fetchReferences(webguyType);
this.setupConfiguration();
//
// Audio
//
this.killStreakAudioSource = this.gameObject.AddComponent<AudioSource>();
if (!Directory.Exists(this.audioPath))
{
Logger.LogError($"Directory {this.audioPath} does not exist. Aborting!");
GameObject.Destroy(this);
}
foreach (string fileName in Directory.GetFiles(this.audioPath))
{
Logger.LogDebug("Loading AudioClip " + Path.GetFileNameWithoutExtension(fileName));
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}");
server.AddWebSocketService<WSJSONService>("/json");
server.Start();
this.setupOldGunSound();
this.setupWSSever();
this.setupClearChatOnKeyPress();
this.setupShiftToCrouch();
this.setupShowEloOnLeaderBoard();
this.setupShowSquadServer();
this.setupShowTestingServer();
this.setupKillStreakSFX();
StartCoroutine(UpdateValuesFunction());
Logger.LogDebug("Ready!");
}
/// This function is called on each frame.
private void Update()
{
this.handleKeyPresses();
this.moveUIOnKeyPress();
this.resetUIOnKeyPress();
this.toggleUIOnKeyPress();
this.toggleKillStreakSFXOnKeyPress();
this.togglePlayerStatsOnKeyPress();
this.toggleWeaponStatsOnKeyPress();
this.toggleTeamStatsOnKeyPress();
this.toggleLeaderboardEloOnKeyPress();
this.toggleShowSquadServerOnKeyPress();
this.toggleTestingServerOnKeyPress();
this.clearChatOnKeyPress();
this.clearDeathLogOnKeyPress();
this.showConfigOnKeyPress();
this.toggleShiftToCrouchOnKeyPress();
this.crouchOnKeyPress();
}
/// Called multiple times per frame in response to GUI events.
/// The Layout and Repaint events are processed first,
/// followed by a Layout and keyboard/mouse event for each input event.
private void OnGUI()
{
this.setupGUI();
@ -92,84 +83,11 @@ namespace WBM
this.drawTeamStats();
}
/// This function is called after the component has been disabled and is ready to be destroyed.
/// It is the last event function that's called during the component's lifecycle.
private void onDestroy()
{
// properly stop websocket server
this.server.Stop();
}
//
// setup functions
//
private void fetchReferences(System.Type webguyType)
{
this.showEloOnLeaderboardRef = webguyType.GetField("KDOBENAOLLF", bindFlags);
this.showSquadServerRef = webguyType.GetField("PHPIBBCFKFI", bindFlags);
this.showTestingServerRef = webguyType.GetField("LHHEGFHLNJE", bindFlags);
this.playerStatsArrayRef = webguyType.GetField("NAFCGDLLFJC", bindFlags);
this.currentAreaRef = webguyType.GetField("FLJLJNLDFAM", bindFlags);
this.teamListRef = webguyType.GetField("MNEJLPDLMBH", bindFlags);
this.localPlayerIndexRef = webguyType.GetField("ALEJJPEPFOG", bindFlags);
this.personGunRef = webguyType.GetField("IEGLIMLBDPH", bindFlags);
this.nickListRef = webguyType.GetField("CLLDJOMEKIP", bindFlags);
this.gameStateRef = webguyType.GetField("MCGMEPGBCKK", bindFlags);
this.chatListRef = webguyType.GetField("MOOBJBOCANE", bindFlags);
this.addMessageFuncRef = webguyType.GetMethod("NBPKLIOLLEI", bindFlags);
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);
}
private void setupConfiguration()
{
this.showGUI = Config.Bind("Config", "show GUI", true);
this.showGUIShortcut = Config.Bind("Hotkeys", "show GUI Shortcut", new KeyboardShortcut(KeyCode.A, KeyCode.RightShift));
this.GUIOffsetX = Config.Bind("Config", "GUI Horizontal position", 38, new ConfigDescription("WBM GUI Horizontal position", new AcceptableValueRange<int>(0, Screen.width)));
this.GUIOffsetY = Config.Bind("Config", "GUI Vertical position", 325, new ConfigDescription("WBM GUI Vertical position", new AcceptableValueRange<int>(0, Screen.height)));
this.resetGUIShortcut = Config.Bind("Hotkeys", "reset GUI position", new KeyboardShortcut(KeyCode.R, KeyCode.LeftControl));
this.shiftToCrouch = Config.Bind("Config", "shift to crouch", true);
this.shiftToCrouchShortcut = Config.Bind("Hotkeys", "shift to crouch", new KeyboardShortcut(KeyCode.C, KeyCode.RightShift));
this.killStreakSFX = Config.Bind("Config", "kill streak sound effect", true);
this.killStreakSFXShortcut = Config.Bind("Hotkeys", "kill streak sound effect", new KeyboardShortcut(KeyCode.F, KeyCode.RightShift));
this.showPlayerStats = Config.Bind("Config", "show player statistics", true);
this.showPlayerStatsShortcut = Config.Bind("Hotkeys", "show player statistics", new KeyboardShortcut(KeyCode.P, KeyCode.RightShift));
this.showWeaponStats = Config.Bind("Config", "show weapon statistics", true);
this.showWeaponStatsShortcut = Config.Bind("Hotkeys", "show weapon statistics", new KeyboardShortcut(KeyCode.W, KeyCode.RightShift));
this.showTeamStats = Config.Bind("Config", "show team statistics", true);
this.showTeamStatsShortcut = Config.Bind("Hotkeys", "show team statistics", new KeyboardShortcut(KeyCode.L, KeyCode.RightShift));
this.showEloOnLeaderboard = Config.Bind("Config", "show Elo on leaderboard", true);
this.showEloOnLeaderboard.SettingChanged += this.showEloOnLeaderboardChanged;
this.showEloOnLeaderboardShortcut = Config.Bind("Hotkeys", "show Elo on leaderboard", new KeyboardShortcut(KeyCode.E, KeyCode.RightShift));
this.showEloOnLeaderboardRaw = this.showEloOnLeaderboard.Value;
this.showSquadServer = Config.Bind("Config", "show squad server", true);
this.showSquadServer.SettingChanged += this.showSquadServerChanged;
this.showSquadServerShortcut = Config.Bind("Hotkeys", "show squad server", new KeyboardShortcut(KeyCode.S, KeyCode.RightShift));
this.showSquadServerRaw = this.showSquadServer.Value;
this.showTestingServer = Config.Bind("Config", "show testing server", true);
this.showTestingServer.SettingChanged += this.showTestingServerChanged;
this.showTestingServerShortcut = Config.Bind("Hotkeys", "show testing server", new KeyboardShortcut(KeyCode.T, KeyCode.RightShift));
this.showTestingServerRaw = this.showTestingServer.Value;
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;
this.useOldGunSoundChanged(new object(), new EventArgs());
this.destroyWSSever();
}
}
}

View file

@ -1,6 +0,0 @@
namespace WBM
{
public class WSJSONService : WebSocketSharp.Server.WebSocketBehavior
{
}
}

0
WBM/features/BRStats.cs Normal file
View file

26
WBM/features/WSServer.cs Normal file
View file

@ -0,0 +1,26 @@
namespace WBM
{
public partial class WBM
{
private WebSocketSharp.Server.WebSocketServer server;
private ushort serverPort = 24601;
private Data.SerializableData data = new Data.SerializableData();
private void setupWSSever()
{
server = new WebSocketSharp.Server.WebSocketServer($"ws://127.0.0.1:{this.serverPort}");
server.AddWebSocketService<WSJSONService>("/json");
server.Start();
}
private void destroyWSSever()
{
// properly stop websocket server
this.server.Stop();
}
}
public class WSJSONService : WebSocketSharp.Server.WebSocketBehavior
{
}
}

32
WBM/features/clearChat.cs Normal file
View file

@ -0,0 +1,32 @@
using BepInEx.Configuration;
using UnityEngine;
using System.Reflection;
namespace WBM
{
partial class WBM
{
private MethodInfo drawChatMessageFuncRef;
private ConfigEntry<KeyboardShortcut> clearChatShortcut;
private void setupClearChatOnKeyPress()
{
this.drawChatMessageFuncRef = webguyType.GetMethod("EBDKFEJMEMB", bindFlags);
this.clearChatShortcut = Config.Bind("Hotkeys", "clear chat", new KeyboardShortcut(KeyCode.Z, KeyCode.RightShift));
}
private void clearChatOnKeyPress()
{
if (this.clearChatShortcut.Value.IsDown()) this.clearChat();
}
private void clearChat()
{
for (int i = 0; i < this.chatListRaw.Length; i++) this.chatListRaw[i] = string.Empty;
this.drawChatMessageFuncRef.Invoke(this.webguy, new object[] { "" });
}
}
}

View file

@ -0,0 +1,14 @@
using BepInEx.Configuration;
namespace WBM
{
partial class WBM
{
private ConfigEntry<KeyboardShortcut> clearDeathLogShortcut;
private void clearDeathLogOnKeyPress()
{
if (this.clearDeathLogShortcut.Value.IsDown()) this.clearMessagesFuncRef.Invoke(this.webguy, new object[] { });
}
}
}

View file

@ -12,157 +12,88 @@ using System.Collections.Generic;
namespace WBM
{
public partial class WBM
partial class WBM
{
//
// important boy
//
private webguy webguy;
private System.Type webguyType;
private Harmony harmony;
private IEnumerator UpdateValues;
//
// websocket data stuff
//
private WebSocketSharp.Server.WebSocketServer server;
private ushort serverPort = 24601;
private Data.SerializableData data = new Data.SerializableData();
//
// internal or temporary
//
private bool _showConfig;
//
// Configurations
//
private ConfigEntry<bool> showGUI;
private ConfigEntry<KeyboardShortcut> showGUIShortcut;
private ConfigEntry<int> GUIOffsetX;
private ConfigEntry<int> GUIOffsetY;
private ConfigEntry<KeyboardShortcut> resetGUIShortcut;
private ConfigEntry<bool> shiftToCrouch;
private ConfigEntry<KeyboardShortcut> shiftToCrouchShortcut;
private ConfigEntry<bool> killStreakSFX;
private ConfigEntry<KeyboardShortcut> killStreakSFXShortcut;
private ConfigEntry<bool> showPlayerStats;
private ConfigEntry<KeyboardShortcut> showPlayerStatsShortcut;
private ConfigEntry<bool> showWeaponStats;
private ConfigEntry<KeyboardShortcut> showWeaponStatsShortcut;
private ConfigEntry<bool> showTeamStats;
private ConfigEntry<KeyboardShortcut> showTeamStatsShortcut;
private ConfigEntry<bool> showEloOnLeaderboard;
private void showEloOnLeaderboardChanged(object sender, EventArgs e)
{
this.showEloOnLeaderboardRaw = this.showEloOnLeaderboard.Value;
}
private ConfigEntry<KeyboardShortcut> showEloOnLeaderboardShortcut;
private ConfigEntry<bool> showSquadServer;
private void showSquadServerChanged(object sender, EventArgs e)
{
this.showSquadServerRaw = this.showSquadServer.Value;
}
private ConfigEntry<KeyboardShortcut> showSquadServerShortcut;
private ConfigEntry<bool> showTestingServer;
private void showTestingServerChanged(object sender, EventArgs e)
{
this.showTestingServerRaw = this.showTestingServer.Value;
}
private ConfigEntry<KeyboardShortcut> showTestingServerShortcut;
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 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>()
{
{10, "rampage"},
{20, "killing spree"},
{30, "unstoppable"},
{50, "godlike"},
{69, "nice"},
};
//
// memory stuff
//
private static BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static;
private FieldInfo showEloOnLeaderboardRef;
private bool showEloOnLeaderboardRaw
//
// Methods
//
private MethodInfo addMessageFuncRef;
private IEnumerator UpdateValuesFunction()
{
get
try
{
return (bool)this.showEloOnLeaderboardRef.GetValue(this.webguy);
this.data.localPlayerIndex = this.localPlayerIndexRaw;
if (this.data.localPlayerIndex >= 0)
{
this.data.playerStatsArray = this.playerStatsArrayRaw;
this.myPlayerStats = this.data.playerStatsArray[this.data.localPlayerIndex];
this.teamList = this.teamListRaw;
this.myTeam = this.teamList[this.data.localPlayerIndex];
this.personGun = this.personGunRaw;
this.data.nickList = this.nickListRaw;
this.data.gameState = this.gameStateRaw;
// check if deaths has changed since the last value update
if (this.prevDeaths == this.myPlayerStats.deaths)
{
this.killStreak = this.myPlayerStats.kills - this.killCountBeforeDeath;
if (this.prevKills != this.myPlayerStats.kills)
{
if (this.killStreakSFX.Value && this.killStreakSFXDictionary.ContainsKey(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 });
}
}
}
else
{
// reset kill streak when death count changes
this.killCountBeforeDeath = this.myPlayerStats.kills;
this.prevDeaths = this.myPlayerStats.deaths;
this.killStreak = 0;
}
this.prevKills = this.myPlayerStats.kills;
}
this.server.WebSocketServices["/json"].Sessions.Broadcast(Util.data2JSON(data));
}
set
catch (Exception e)
{
this.showEloOnLeaderboardRef.SetValue(this.webguy, value);
Logger.LogError(e);
}
yield return new WaitForSeconds(0.1f);
this.UpdateValues = UpdateValuesFunction();
StartCoroutine(this.UpdateValues);
}
private FieldInfo showSquadServerRef;
private bool showSquadServerRaw
{
get
{
return (bool)this.showSquadServerRef.GetValue(this.webguy);
}
set
{
this.showSquadServerRef.SetValue(this.webguy, value);
}
}
private FieldInfo showTestingServerRef;
private bool showTestingServerRaw
{
get
{
return (bool)this.showTestingServerRef.GetValue(this.webguy);
}
set
{
this.showTestingServerRef.SetValue(this.webguy, value);
}
}
private MethodInfo clearMessagesFuncRef;
private FieldInfo playerStatsArrayRef;
private Data.PlayerStatsStruct[] playerStatsArrayRaw
@ -200,7 +131,6 @@ namespace WBM
private int prevDeaths = 0;
private int prevKills = 0;
private int killCountBeforeDeath = 0;
private int killStreak = 0;
private FieldInfo currentAreaRef;
private int currentAreaRaw
@ -272,110 +202,83 @@ 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
// Audio
//
private MethodInfo addMessageFuncRef;
private MethodInfo clearMessagesFuncRef;
private MethodInfo drawChatMessageFuncRef;
private Dictionary<string, AudioClip> AudioDict = new Dictionary<string, AudioClip>();
private string audioPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "assets/audio");
private IEnumerator UpdateValuesFunction()
private void initCore()
{
try
{
this.data.localPlayerIndex = this.localPlayerIndexRaw;
if (this.data.localPlayerIndex >= 0)
{
this.data.playerStatsArray = this.playerStatsArrayRaw;
this.myPlayerStats = this.data.playerStatsArray[this.data.localPlayerIndex];
this.teamList = this.teamListRaw;
this.myTeam = this.teamList[this.data.localPlayerIndex];
this.personGun = this.personGunRaw;
this.data.nickList = this.nickListRaw;
this.data.gameState = this.gameStateRaw;
// check if deaths has changed since the last value update
if (this.prevDeaths == this.myPlayerStats.deaths)
{
this.killStreak = this.myPlayerStats.kills - this.killCountBeforeDeath;
if (this.prevKills != this.myPlayerStats.kills)
{
if (this.killStreakSFX.Value && this.killStreakSFXDictionary.ContainsKey(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 });
}
}
}
else
{
// reset kill streak when death count changes
this.killCountBeforeDeath = this.myPlayerStats.kills;
this.prevDeaths = this.myPlayerStats.deaths;
this.killStreak = 0;
}
this.prevKills = this.myPlayerStats.kills;
}
this.server.WebSocketServices["/json"].Sessions.Broadcast(Util.data2JSON(data));
}
catch (Exception e)
{
Logger.LogError(e);
}
yield return new WaitForSeconds(0.1f);
this.UpdateValues = UpdateValuesFunction();
StartCoroutine(this.UpdateValues);
this.harmony = new Harmony("com.developomp.wbm");
this.harmony.PatchAll();
}
private void clearChat()
private async System.Threading.Tasks.Task setupCore()
{
Logger.LogDebug($"clear1 {chatListRaw.Length}");
for (int i = 0; i < this.chatListRaw.Length; i++) this.chatListRaw[i] = string.Empty;
this.drawChatMessageFuncRef.Invoke(this.webguy, new object[] { "" });
this.webguy = FindObjectOfType<webguy>();
this.webguyType = typeof(webguy);
//
// References
//
this.playerStatsArrayRef = webguyType.GetField("NAFCGDLLFJC", bindFlags);
this.currentAreaRef = webguyType.GetField("FLJLJNLDFAM", bindFlags);
this.teamListRef = webguyType.GetField("MNEJLPDLMBH", bindFlags);
this.localPlayerIndexRef = webguyType.GetField("ALEJJPEPFOG", bindFlags);
this.personGunRef = webguyType.GetField("IEGLIMLBDPH", bindFlags);
this.nickListRef = webguyType.GetField("CLLDJOMEKIP", bindFlags);
this.gameStateRef = webguyType.GetField("MCGMEPGBCKK", bindFlags);
this.chatListRef = webguyType.GetField("MOOBJBOCANE", bindFlags);
this.addMessageFuncRef = webguyType.GetMethod("NBPKLIOLLEI", bindFlags);
this.clearMessagesFuncRef = webguyType.GetMethod("IOCHBBACKFA", bindFlags);
//
// Configurations
//
this.showGUI = Config.Bind("Config", "show GUI", true);
this.showGUIShortcut = Config.Bind("Hotkeys", "show GUI Shortcut", new KeyboardShortcut(KeyCode.A, KeyCode.RightShift));
this.GUIOffsetX = Config.Bind("Config", "GUI Horizontal position", 38, new ConfigDescription("WBM GUI Horizontal position", new AcceptableValueRange<int>(0, Screen.width)));
this.GUIOffsetY = Config.Bind("Config", "GUI Vertical position", 325, new ConfigDescription("WBM GUI Vertical position", new AcceptableValueRange<int>(0, Screen.height)));
this.resetGUIShortcut = Config.Bind("Hotkeys", "reset GUI position", new KeyboardShortcut(KeyCode.R, KeyCode.LeftControl));
this.showPlayerStats = Config.Bind("Config", "show player statistics", true);
this.showPlayerStatsShortcut = Config.Bind("Hotkeys", "show player statistics", new KeyboardShortcut(KeyCode.P, KeyCode.RightShift));
this.showWeaponStats = Config.Bind("Config", "show weapon statistics", true);
this.showWeaponStatsShortcut = Config.Bind("Hotkeys", "show weapon statistics", new KeyboardShortcut(KeyCode.W, KeyCode.RightShift));
this.showTeamStats = Config.Bind("Config", "show team statistics", true);
this.showTeamStatsShortcut = Config.Bind("Hotkeys", "show team statistics", new KeyboardShortcut(KeyCode.L, KeyCode.RightShift));
this.clearDeathLogShortcut = Config.Bind("Hotkeys", "clear messages", new KeyboardShortcut(KeyCode.X, KeyCode.RightShift));
//
// Audio
//
this.killStreakAudioSource = this.gameObject.AddComponent<AudioSource>();
if (!Directory.Exists(this.audioPath))
{
Logger.LogError($"Directory {this.audioPath} does not exist. Aborting!");
GameObject.Destroy(this);
}
foreach (string fileName in Directory.GetFiles(this.audioPath))
{
Logger.LogDebug("Loading AudioClip " + Path.GetFileNameWithoutExtension(fileName));
this.AudioDict.Add(
Path.GetFileNameWithoutExtension(fileName),
await Util.fetchAudioClip(Path.Combine(this.audioPath, fileName))
);
}
}
}
}

View file

@ -1,12 +1,20 @@
using BepInEx.Configuration;
using UnityEngine;
using System;
namespace WBM
{
public partial class WBM
partial class WBM
{
private ConfigEntry<bool> showGUI;
private ConfigEntry<KeyboardShortcut> showGUIShortcut;
private ConfigEntry<int> GUIOffsetX;
private ConfigEntry<int> GUIOffsetY;
private ConfigEntry<KeyboardShortcut> resetGUIShortcut;
private void setupGUI()
{
GUI.skin.box.fontSize = 15;
@ -154,5 +162,47 @@ total kills: {teamTotalKills}"
Logger.LogError(e);
}
}
private void moveUIOnKeyPress()
{
if (Input.GetKey(KeyCode.LeftControl))
{
// move GUI
if (Input.GetKey(KeyCode.LeftShift))
{
if (Input.GetKey(KeyCode.UpArrow)) this.GUIOffsetY.Value -= 1;
if (Input.GetKey(KeyCode.DownArrow)) this.GUIOffsetY.Value += 1;
if (Input.GetKey(KeyCode.LeftArrow)) this.GUIOffsetX.Value -= 1;
if (Input.GetKey(KeyCode.RightArrow)) this.GUIOffsetX.Value += 1;
}
else
{
if (Input.GetKeyDown(KeyCode.UpArrow)) this.GUIOffsetY.Value -= 1;
if (Input.GetKeyDown(KeyCode.DownArrow)) this.GUIOffsetY.Value += 1;
if (Input.GetKeyDown(KeyCode.LeftArrow)) this.GUIOffsetX.Value -= 1;
if (Input.GetKeyDown(KeyCode.RightArrow)) this.GUIOffsetX.Value += 1;
}
}
}
private void resetUIOnKeyPress()
{
if (this.resetGUIShortcut.Value.IsDown())
{
this.GUIOffsetX.Value = (int)this.GUIOffsetX.DefaultValue;
this.GUIOffsetY.Value = (int)this.GUIOffsetY.DefaultValue;
}
}
private void toggleUIOnKeyPress()
{
if (this.showGUIShortcut.Value.IsDown()) this.showGUI.Value = !this.showGUI.Value;
}
private void showConfigOnKeyPress()
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightShift)) this._showConfig = true;
if (!Input.GetKey(KeyCode.LeftControl) && !Input.GetKey(KeyCode.RightShift)) this._showConfig = false;
}
}
}

View file

@ -0,0 +1,37 @@
using BepInEx.Configuration;
using UnityEngine;
using System.Collections.Generic;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> killStreakSFX;
private ConfigEntry<KeyboardShortcut> killStreakSFXShortcut;
private int killStreak = 0;
private AudioSource killStreakAudioSource;
private Dictionary<int, string> killStreakSFXDictionary = new Dictionary<int, string>()
{
{10, "rampage"},
{20, "killing spree"},
{30, "unstoppable"},
{50, "godlike"},
{69, "nice"},
};
private void setupKillStreakSFX()
{
this.killStreakSFX = Config.Bind("Config", "kill streak sound effect", true);
this.killStreakSFXShortcut = Config.Bind("Hotkeys", "kill streak sound effect", new KeyboardShortcut(KeyCode.F, KeyCode.RightShift));
}
private void toggleKillStreakSFXOnKeyPress()
{
if (this.killStreakSFXShortcut.Value.IsDown()) this.killStreakSFX.Value = !this.killStreakSFX.Value;
}
}
}

View file

@ -0,0 +1,81 @@
using BepInEx.Configuration;
using UnityEngine;
using System;
using System.Reflection;
namespace WBM
{
public partial class WBM
{
private ConfigEntry<bool> useOldGunSoundConf;
private FieldInfo oldGunSoundRef;
private AudioClip oldGunSoundRaw
{
get
{
return ((LPJKBALIFCC)this.oldGunSoundRef.GetValue(this.webguy)).ADCOCHNNCHM;
}
}
private AudioClip oldGunSound;
private FieldInfo AKSoundRef;
private LPJKBALIFCC AKSoundRaw
{
get
{
return (LPJKBALIFCC)this.AKSoundRef.GetValue(this.webguy);
}
set
{
this.AKSoundRef.SetValue(this.webguy, value);
}
}
private AudioClip newAKSound;
private FieldInfo SMGSoundRef;
private LPJKBALIFCC SMGSoundRaw
{
get
{
return (LPJKBALIFCC)this.SMGSoundRef.GetValue(this.webguy);
}
set
{
this.SMGSoundRef.SetValue(this.webguy, value);
}
}
private AudioClip newSMGSound;
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;
}
}
private void setupOldGunSound()
{
this.oldGunSoundRef = webguyType.GetField("PINGEJAHHDI", bindFlags);
this.AKSoundRef = webguyType.GetField("BJFBGCMEELH", bindFlags);
this.SMGSoundRef = webguyType.GetField("HKDDIMFIHCE", bindFlags);
this.useOldGunSoundConf = Config.Bind("Config", "use old gun sound", true);
this.useOldGunSoundConf.SettingChanged += this.useOldGunSoundChanged;
this.useOldGunSoundChanged(new object(), new EventArgs());
this.oldGunSound = this.oldGunSoundRaw;
this.newAKSound = this.AKSoundRaw.ADCOCHNNCHM;
this.newSMGSound = this.SMGSoundRaw.ADCOCHNNCHM;
}
}
}

View file

@ -0,0 +1,15 @@
using BepInEx.Configuration;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showPlayerStats;
private ConfigEntry<KeyboardShortcut> showPlayerStatsShortcut;
private void togglePlayerStatsOnKeyPress()
{
if (this.showPlayerStatsShortcut.Value.IsDown()) this.showPlayerStats.Value = !this.showPlayerStats.Value;
}
}
}

View file

@ -0,0 +1,40 @@
using BepInEx.Configuration;
using UnityEngine;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> shiftToCrouch;
private ConfigEntry<KeyboardShortcut> shiftToCrouchShortcut;
private void setupShiftToCrouch()
{
this.shiftToCrouch = Config.Bind("Config", "shift to crouch", true);
this.shiftToCrouchShortcut = Config.Bind("Hotkeys", "shift to crouch", new KeyboardShortcut(KeyCode.C, KeyCode.RightShift));
}
private void crouchOnKeyPress()
{
// Skip if this setting is not activated
if (!this.shiftToCrouch.Value) return;
// Skip if right buttton is being pressed (if weapon is zoomed)
if (Input.GetMouseButton(1)) return;
if (Input.GetKeyDown(KeyCode.LeftShift)) setCrouchState(true);
if (Input.GetKeyUp(KeyCode.LeftShift)) setCrouchState(false);
}
private void toggleShiftToCrouchOnKeyPress()
{
if (this.shiftToCrouchShortcut.Value.IsDown()) this.shiftToCrouch.Value = !this.shiftToCrouch.Value;
}
private void setCrouchState(bool crouchState)
{
OMOJPGNNKFN.NEELEHFDKBP.EGACOOOGDDC = crouchState;
}
}
}

View file

@ -0,0 +1,48 @@
using BepInEx.Configuration;
using UnityEngine;
using System;
using System.Reflection;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showEloOnLeaderboard;
private ConfigEntry<KeyboardShortcut> showEloOnLeaderboardShortcut;
private FieldInfo showEloOnLeaderboardRef;
private bool showEloOnLeaderboardRaw
{
get
{
return (bool)this.showEloOnLeaderboardRef.GetValue(this.webguy);
}
set
{
this.showEloOnLeaderboardRef.SetValue(this.webguy, value);
}
}
private void setupShowEloOnLeaderBoard()
{
this.showEloOnLeaderboardRef = webguyType.GetField("KDOBENAOLLF", bindFlags);
this.showEloOnLeaderboard = Config.Bind("Config", "show Elo on leaderboard", true);
this.showEloOnLeaderboard.SettingChanged += this.onShowEloOnLeaderboardChanged;
this.showEloOnLeaderboardShortcut = Config.Bind("Hotkeys", "show Elo on leaderboard", new KeyboardShortcut(KeyCode.E, KeyCode.RightShift));
this.showEloOnLeaderboardRaw = this.showEloOnLeaderboard.Value;
}
private void toggleLeaderboardEloOnKeyPress()
{
if (this.showEloOnLeaderboardShortcut.Value.IsDown()) this.showEloOnLeaderboard.Value = !this.showEloOnLeaderboard.Value;
}
private void onShowEloOnLeaderboardChanged(object sender, EventArgs e)
{
this.showEloOnLeaderboardRaw = this.showEloOnLeaderboard.Value;
}
}
}

View file

@ -0,0 +1,48 @@
using BepInEx.Configuration;
using UnityEngine;
using System;
using System.Reflection;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showSquadServer;
private ConfigEntry<KeyboardShortcut> showSquadServerShortcut;
private FieldInfo showSquadServerRef;
private bool showSquadServerRaw
{
get
{
return (bool)this.showSquadServerRef.GetValue(this.webguy);
}
set
{
this.showSquadServerRef.SetValue(this.webguy, value);
}
}
private void setupShowSquadServer()
{
this.showSquadServerRef = webguyType.GetField("PHPIBBCFKFI", bindFlags);
this.showSquadServer = Config.Bind("Config", "show squad server", true);
this.showSquadServer.SettingChanged += this.onShowSquadServerChanged;
this.showSquadServerShortcut = Config.Bind("Hotkeys", "show squad server", new KeyboardShortcut(KeyCode.S, KeyCode.RightShift));
this.showSquadServerRaw = this.showSquadServer.Value;
}
private void toggleShowSquadServerOnKeyPress()
{
if (this.showSquadServerShortcut.Value.IsDown()) this.showSquadServer.Value = !this.showSquadServer.Value;
}
private void onShowSquadServerChanged(object sender, EventArgs e)
{
this.showSquadServerRaw = this.showSquadServer.Value;
}
}
}

View file

@ -0,0 +1,48 @@
using BepInEx.Configuration;
using UnityEngine;
using System;
using System.Reflection;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showTestingServer;
private ConfigEntry<KeyboardShortcut> showTestingServerShortcut;
private FieldInfo showTestingServerRef;
private bool showTestingServerRaw
{
get
{
return (bool)this.showTestingServerRef.GetValue(this.webguy);
}
set
{
this.showTestingServerRef.SetValue(this.webguy, value);
}
}
private void setupShowTestingServer()
{
this.showTestingServerRef = webguyType.GetField("LHHEGFHLNJE", bindFlags);
this.showTestingServer = Config.Bind("Config", "show testing server", true);
this.showTestingServer.SettingChanged += this.onShowTestingServerChanged;
this.showTestingServerShortcut = Config.Bind("Hotkeys", "show testing server", new KeyboardShortcut(KeyCode.T, KeyCode.RightShift));
this.showTestingServerRaw = this.showTestingServer.Value;
}
private void toggleTestingServerOnKeyPress()
{
if (this.showTestingServerShortcut.Value.IsDown()) this.showTestingServer.Value = !this.showTestingServer.Value;
}
private void onShowTestingServerChanged(object sender, EventArgs e)
{
this.showTestingServerRaw = this.showTestingServer.Value;
}
}
}

15
WBM/features/teamStats.cs Normal file
View file

@ -0,0 +1,15 @@
using BepInEx.Configuration;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showTeamStats;
private ConfigEntry<KeyboardShortcut> showTeamStatsShortcut;
private void toggleTeamStatsOnKeyPress()
{
if (this.showTeamStatsShortcut.Value.IsDown()) this.showTeamStats.Value = !this.showTeamStats.Value;
}
}
}

View file

@ -0,0 +1,15 @@
using BepInEx.Configuration;
namespace WBM
{
partial class WBM
{
private ConfigEntry<bool> showWeaponStats;
private ConfigEntry<KeyboardShortcut> showWeaponStatsShortcut;
private void toggleWeaponStatsOnKeyPress()
{
if (this.showWeaponStatsShortcut.Value.IsDown()) this.showWeaponStats.Value = !this.showWeaponStats.Value;
}
}
}