Skip to content

Commit

Permalink
Settings rework
Browse files Browse the repository at this point in the history
  • Loading branch information
SDraw committed Aug 7, 2022
1 parent 422f3fa commit 8583034
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 118 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Merged set of MelonLoader mods for ChilloutVR.
| Avatar Change Info | ml_aci | 1.0.1 | Pending approval | Working |
| Desktop Reticle Switch | ml_drs | 1.0.0 | Yes | Working |
| Four Point Tracking | ml_fpt | 1.0.0 | Pending approval | Working |
| Leap Motion Extension | ml_lme | 1.1.0 | Pending approval | Working |
| Leap Motion Extension | ml_lme | 1.1.1 | Pending approval | Working |
1 change: 1 addition & 0 deletions ml_lme/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ System.Collections.IEnumerator WaitForMainMenuView()
ViewManager.Instance.gameMenuView.Listener.FinishLoad += (_) =>
{
ViewManager.Instance.gameMenuView.View.ExecuteScript(Scripts.GetEmbeddedScript("menu.js"));
ViewManager.Instance.RequestCurrentSettings();
};
}

Expand Down
6 changes: 3 additions & 3 deletions ml_lme/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Reflection;

[assembly: AssemblyTitle("LeapMotionExtension")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyVersion("1.1.1")]
[assembly: AssemblyFileVersion("1.1.1")]

[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.1.0", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonInfo(typeof(ml_lme.LeapMotionExtension), "LeapMotionExtension", "1.1.1", "SDraw", "https://github.com/SDraw/ml_mods_cvr")]
[assembly: MelonLoader.MelonGame(null, "ChilloutVR")]
[assembly: MelonLoader.MelonPlatform(MelonLoader.MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonLoader.MelonPlatformDomain(MelonLoader.MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
218 changes: 104 additions & 114 deletions ml_lme/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public enum LeapTrackingMode
HMD
}

public static readonly string[] ms_defaultSettings =
enum ModSetting
{
"InteractionLeapMotionTracking",
"InteractionLeapMotionTrackingDesktopX",
"InteractionLeapMotionTrackingDesktopY",
"InteractionLeapMotionTrackingDesktopZ",
"InteractionLeapMotionTrackingFingersOnly",
"InteractionLeapMotionTrackingModel",
"InteractionLeapMotionTrackingMode",
"InteractionLeapMotionTrackingAngle",
"InteractionLeapMotionTrackingHead",
"InteractionLeapMotionTrackingHeadX",
"InteractionLeapMotionTrackingHeadY",
"InteractionLeapMotionTrackingHeadZ"
InteractionLeapMotionTracking,
InteractionLeapMotionTrackingDesktopX,
InteractionLeapMotionTrackingDesktopY,
InteractionLeapMotionTrackingDesktopZ,
InteractionLeapMotionTrackingFingersOnly,
InteractionLeapMotionTrackingModel,
InteractionLeapMotionTrackingMode,
InteractionLeapMotionTrackingAngle,
InteractionLeapMotionTrackingHead,
InteractionLeapMotionTrackingHeadX,
InteractionLeapMotionTrackingHeadY,
InteractionLeapMotionTrackingHeadZ
};

static bool ms_enabled = false;
Expand All @@ -53,123 +53,113 @@ public static void Init(HarmonyLib.Harmony p_instance)
{
p_instance.Patch(
typeof(CVRSettings).GetMethod(nameof(CVRSettings.LoadSerializedSettings)),
new HarmonyLib.HarmonyMethod(typeof(Settings).GetMethod(nameof(BeforeSettingsLoad), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)),
new HarmonyLib.HarmonyMethod(typeof(Settings).GetMethod(nameof(LoadSerializedSettings_Prefix), System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)),
null
);
}

static void BeforeSettingsLoad(ref CVRSettings __instance)
static void LoadSerializedSettings_Prefix(ref CVRSettings __instance)
{
if(!ms_initialized && (__instance != null))
{
var l_settings = HarmonyLib.Traverse.Create(__instance)?.Field("_settings")?.GetValue<System.Collections.Generic.List<ABI_RC.Core.Savior.CVRSettingsValue>>();
if(l_settings != null)
{
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[0], false));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[1], 0));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[2], -45));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[3], 30));
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[4], false));
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[5], false));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[6], 1));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[7], 0));
l_settings.Add(new CVRSettingsBool(ms_defaultSettings[8], false));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[9], 0));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[10], 0));
l_settings.Add(new CVRSettingsInt(ms_defaultSettings[11], 0));
l_settings.Add(new CVRSettingsBool(ModSetting.InteractionLeapMotionTracking.ToString(), false));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingDesktopX.ToString(), 0));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingDesktopY.ToString(), -45));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingDesktopZ.ToString(), 30));
l_settings.Add(new CVRSettingsBool(ModSetting.InteractionLeapMotionTrackingFingersOnly.ToString(), false));
l_settings.Add(new CVRSettingsBool(ModSetting.InteractionLeapMotionTrackingModel.ToString(), false));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingMode.ToString(), 1));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingAngle.ToString(), 0));
l_settings.Add(new CVRSettingsBool(ModSetting.InteractionLeapMotionTrackingHead.ToString(), false));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingHeadX.ToString(), 0));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingHeadY.ToString(), 0));
l_settings.Add(new CVRSettingsInt(ModSetting.InteractionLeapMotionTrackingHeadZ.ToString(), 0));
}

// Enable tracking
__instance.settingBoolChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[0])
if(Enum.TryParse(name, out ModSetting l_setting))
{
ms_enabled = value;
EnabledChange?.Invoke();
}
});

// Desktop offsets
__instance.settingIntChanged.AddListener((name, value) =>
{
for(int i = 1; i <= 3; i++)
{
if(name == ms_defaultSettings[i])
switch(l_setting)
{
ms_desktopOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[1]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[2]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[3])
) * 0.01f;
DesktopOffsetChange?.Invoke();
case ModSetting.InteractionLeapMotionTracking:
{
ms_enabled = value;
EnabledChange?.Invoke();
}
break;
}
}
});
// Fingers tracking only
__instance.settingBoolChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[4])
{
ms_fingersOnly = value;
FingersOnlyChange?.Invoke();
}
});
case ModSetting.InteractionLeapMotionTrackingFingersOnly:
{
ms_fingersOnly = value;
FingersOnlyChange?.Invoke();
}
break;
// Model visibility
__instance.settingBoolChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[5])
{
ms_modelVisibility = value;
ModelVisibilityChange?.Invoke();
}
});
case ModSetting.InteractionLeapMotionTrackingModel:
{
ms_modelVisibility = value;
ModelVisibilityChange?.Invoke();
}
break;
// Tracking mode
__instance.settingIntChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[6])
{
ms_trackingMode = (LeapTrackingMode)value;
TrackingModeChange?.Invoke();
case ModSetting.InteractionLeapMotionTrackingHead:
{
ms_headAttach = value;
HeadAttachChange?.Invoke();
}
break;
}
}
});

// Root angle
__instance.settingIntChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[7])
if(Enum.TryParse(name, out ModSetting l_setting))
{
ms_rootAngle = value;
RootAngleChange?.Invoke();
}
});
switch(l_setting)
{
case ModSetting.InteractionLeapMotionTrackingDesktopX:
case ModSetting.InteractionLeapMotionTrackingDesktopY:
case ModSetting.InteractionLeapMotionTrackingDesktopZ:
{
ms_desktopOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopX.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopY.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopZ.ToString())
) * 0.01f;
DesktopOffsetChange?.Invoke();
}
break;
// Head attach
__instance.settingBoolChanged.AddListener((name, value) =>
{
if(name == ms_defaultSettings[8])
{
ms_headAttach = value;
HeadAttachChange?.Invoke();
}
});
case ModSetting.InteractionLeapMotionTrackingMode:
{
ms_trackingMode = (LeapTrackingMode)value;
TrackingModeChange?.Invoke();
}
break;
// Head offset
__instance.settingIntChanged.AddListener((name, value) =>
{
for(int i = 9; i <= 11; i++)
{
if(name == ms_defaultSettings[i])
{
ms_headOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[9]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[10]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[11])
) * 0.01f;
HeadOffsetChange?.Invoke();
case ModSetting.InteractionLeapMotionTrackingAngle:
{
ms_rootAngle = value;
RootAngleChange?.Invoke();
}
break;
case ModSetting.InteractionLeapMotionTrackingHeadX:
case ModSetting.InteractionLeapMotionTrackingHeadY:
case ModSetting.InteractionLeapMotionTrackingHeadZ:
{
ms_headOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadX.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadY.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadZ.ToString())
) * 0.01f;
HeadOffsetChange?.Invoke();
}
break;
}
}
Expand All @@ -181,21 +171,21 @@ static void BeforeSettingsLoad(ref CVRSettings __instance)

static public void Reload()
{
ms_enabled = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[0]);
ms_enabled = MetaPort.Instance.settings.GetSettingsBool(ModSetting.InteractionLeapMotionTracking.ToString());
ms_desktopOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[1]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[2]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[3])
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopX.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopY.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingDesktopZ.ToString())
) * 0.01f;
ms_fingersOnly = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[4]);
ms_modelVisibility = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[5]);
ms_trackingMode = (LeapTrackingMode)MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[6]);
ms_rootAngle = MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[7]);
ms_headAttach = MetaPort.Instance.settings.GetSettingsBool(ms_defaultSettings[8]);
ms_fingersOnly = MetaPort.Instance.settings.GetSettingsBool(ModSetting.InteractionLeapMotionTrackingFingersOnly.ToString());
ms_modelVisibility = MetaPort.Instance.settings.GetSettingsBool(ModSetting.InteractionLeapMotionTrackingModel.ToString());
ms_trackingMode = (LeapTrackingMode)MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingMode.ToString());
ms_rootAngle = MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingAngle.ToString());
ms_headAttach = MetaPort.Instance.settings.GetSettingsBool(ModSetting.InteractionLeapMotionTrackingHead.ToString());
ms_headOffset = new Vector3(
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[9]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[10]),
MetaPort.Instance.settings.GetSettingInt(ms_defaultSettings[11])
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadX.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadY.ToString()),
MetaPort.Instance.settings.GetSettingInt(ModSetting.InteractionLeapMotionTrackingHeadZ.ToString())
) * 0.01f;
}

Expand Down

0 comments on commit 8583034

Please sign in to comment.