Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Update 1.3 Release Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Arion-Kun authored and Arion-Kun committed Feb 18, 2021
1 parent 712f98b commit 3bfac69
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 49 deletions.
43 changes: 14 additions & 29 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,11 @@ namespace Dawn
{
internal static class Core
{
internal static ApiWorld currentRoom()
{
#if Unobfuscated
return RoomManager.currentRoom; //field_Internal_Static_ApiWorld_0
#else
return FindInstance(typeof(RoomManager), typeof(ApiWorld)).TryCast<ApiWorld>(); //Used to be RoomManager.field_Internal_Static_ApiWorld_0
#endif
}
internal static ApiWorldInstance currentWorldInstance()
{
#if Unobfuscated
return RoomManager.currentWorldInstance; //field_Internal_Static_ApiWorldInstance_0
#else
return FindInstance(typeof(RoomManager), typeof(ApiWorldInstance)).TryCast<ApiWorldInstance>(); //Used to be RoomManager.field_Internal_Static_ApiWorldInstance_0
#endif
}
internal static bool IsInWorld()
{
return currentRoom() != null || currentWorldInstance() != null;
}
internal static ApiWorld currentRoom => FindInstance(typeof(RoomManager), typeof(ApiWorld)).TryCast<ApiWorld>();

internal static ApiWorldInstance currentWorldInstance => FindInstance(typeof(RoomManager), typeof(ApiWorldInstance)).TryCast<ApiWorldInstance>();

internal static bool IsInWorld => currentRoom != null || currentWorldInstance != null;
private static float infoIndex;
internal static float userVolumeThreshold
{
Expand Down Expand Up @@ -76,7 +61,7 @@ internal static IEnumerator WorldJoinedCoroutine()
{
var sw = new Stopwatch();
sw.Start();
if (CurrentUser != null && IsInWorld())
if (CurrentUser != null && IsInWorld)
{
yield return new WaitForSeconds(1);
{
Expand All @@ -88,7 +73,7 @@ internal static IEnumerator WorldJoinedCoroutine()

if (sw.Elapsed.Seconds >= 100) // This should never happen but a check for it is in place just in case.
{
Log("WorldJoinedCoroutine took too long and was stopped.");
MelonLogger.Warning("WorldJoinedCoroutine took too long and was stopped.");
yield break;
}
yield return new WaitForSeconds(1);
Expand All @@ -103,15 +88,15 @@ internal static Il2CppSystem.Object FindInstance(Type WhereLooking, Type WhatLoo
{
return (Il2CppSystem.Object)methodInfo.Invoke(null, null);
}
MelonLogger.LogError("[FindInstance] MethodInfo for " + WhatLooking.Name + " is null");
MelonLogger.Error("[FindInstance] MethodInfo for " + WhatLooking.Name + " is null");
}
catch (Exception e)
{
MelonLogger.LogError($"[FindInstance] {e}");
MelonLogger.Error($"[FindInstance] {e}");
}
return null;
}
internal static PropertyInfo GetInfo(string originalValue)
private static PropertyInfo GetInfo(string originalValue)
{
Log($"Caching USpeaker PropertyInfo {infoIndex+1} "); infoIndex =+ 1;
var uPropInfos = typeof(USpeaker).GetProperties().Where(p => p.PropertyType == typeof(float));
Expand All @@ -124,19 +109,19 @@ internal static PropertyInfo GetInfo(string originalValue)
internal static USpeaker uInstance => CurrentUser.field_Private_USpeaker_0;
internal static void InternalConfigRefresh() //The Divide by 10k sets it back to a managable float number
{
MicSensitivityValue = MelonPrefs.GetFloat("MicSensitivity", "Mic - Microphone Sensitivity") / 10000;
UseMod = MelonPrefs.GetBool("MicSensitivity", "Mic - Enable Mic Sensitivity Mod");
SensitivityValue = MelonPreferences.GetEntryValue<float>("MicSensitivity", "Mic - Microphone Sensitivity") / 10000;
UseMod = MelonPreferences.GetEntryValue<bool>("MicSensitivity", "Mic - Enable Mic Sensitivity Mod");
}
/// <summary>
/// Log an object to the MelonConsole
/// </summary>
/// <param name="obj"></param>
internal static void Log(object obj)
{
MelonLogger.Log(obj);
MelonLogger.Msg(obj);
}
/// <summary>
/// Current User Instance.
/// Current User Instance Cache.
/// </summary>
private static VRCPlayer CurrentUserInstance;
/// <summary>
Expand Down
27 changes: 13 additions & 14 deletions MicSensitivity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MelonLoader;
using Harmony;
using MelonLoader;
using static Dawn.Core;

namespace Dawn.Mic
Expand All @@ -8,15 +9,15 @@ internal class MicSensitivity : MelonMod
#region MelonMod Native
public override void OnApplicationStart()
{
MelonPrefs.RegisterCategory("MicSensitivity", "Mic Sensitivity");
MelonPrefs.RegisterBool("MicSensitivity", "Mic - Enable Mic Sensitivity Mod", false);
MelonPrefs.RegisterFloat("MicSensitivity", "Mic - Microphone Sensitivity", 100);
MelonPreferences.CreateCategory("MicSensitivity", "Mic Sensitivity");
MelonPreferences.CreateEntry("MicSensitivity", "Mic - Enable Mic Sensitivity Mod", false);
MelonPreferences.CreateEntry("MicSensitivity", "Mic - Microphone Sensitivity", 100f);
InternalConfigRefresh();
Log("On App Finished.");
} //Settings Registration and Refresh
public override void OnLevelWasLoaded(int level) // World Join

public override void OnSceneWasLoaded(int buildIndex, string sceneName) // World Join
{
switch (level) //Prevents being called 3x
switch (buildIndex) //Prevents being called 3x
{
case 0:
case 1:
Expand All @@ -26,29 +27,27 @@ public override void OnLevelWasLoaded(int level) // World Join
break;
}
}
public override void OnModSettingsApplied()

public override void OnPreferencesSaved()
{
InternalConfigRefresh();
SensitivitySetup();
if (UseMod) return;
userVolumeThreshold = DefaultPeak; //Defaulted if Mod is not used.
userVolumePeak = DefaultThreshold; //Defaulted if Mod is not used.
}

#endregion
#region The Actual Mod
internal static bool UseMod;
internal static float MicSensitivityValue = 0;
internal static float SensitivityValue = 0;
private const float DefaultThreshold = 0.01f;
private const float DefaultPeak = 0.02f;

internal static void SensitivitySetup()
{
if (!UseMod) return;
#if Unobfuscated
CurrentUser._uSpeaker.VolumeThresholdRMS = MicSensitivityValue; CurrentUser.field_Private_USpeaker_0.VolumeThresholdPeak = (MicSensitivityValue * 2); //field_Private_USpeaker_0 }
#else
userVolumeThreshold = MicSensitivityValue; userVolumePeak = (MicSensitivityValue * 2); }
#endif
userVolumeThreshold = SensitivityValue; userVolumePeak = (SensitivityValue * 2); }
#endregion
}

Expand Down
12 changes: 6 additions & 6 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;
using AssemblyInfo = Dawn.Update.AssemblyInfo;
using static Dawn.Update.AssemblyInfo;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
Expand All @@ -19,8 +19,8 @@
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("67FF3596-F54F-4788-BA8E-4C9B30AE829A")]

[assembly: AssemblyTitle(AssemblyInfo.Name)]
[assembly: AssemblyDescription(AssemblyInfo.Description)]
[assembly: AssemblyProduct(AssemblyInfo.Name)]
[assembly: AssemblyVersion(AssemblyInfo.Version)]
[assembly: AssemblyFileVersion(AssemblyInfo.Version)]
[assembly: AssemblyTitle(Name)]
[assembly: AssemblyDescription(Description)]
[assembly: AssemblyProduct(Name)]
[assembly: AssemblyVersion(Version)]
[assembly: AssemblyFileVersion(Version)]

0 comments on commit 3bfac69

Please sign in to comment.