Skip to content

Commit

Permalink
[ProfilesExtended] Add the ability to keep current parameters across …
Browse files Browse the repository at this point in the history
…avatar changes/game restarts.
  • Loading branch information
kafeijao committed Oct 29, 2022
1 parent 25173ff commit b17ceda
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
76 changes: 63 additions & 13 deletions ProfilesExtended/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ABI_RC.Core;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Core.Player;
using ABI.CCK.Components;
using ABI.CCK.Scripts;
Expand All @@ -9,8 +10,11 @@ namespace ProfilesExtended;

public class ProfilesExtended : MelonMod {

private static string[] _paramTags;
private static string[] _profileTags;
private static string _paramTag;
private static string _profileTag;

private static bool _autoProfileEnabled;
private static string _autoProfileName;

public override void OnApplicationStart() {

Expand All @@ -24,16 +28,43 @@ public override void OnApplicationStart() {

var cat = MelonPreferences.CreateCategory(nameof(ProfilesExtended));

var ignoreTagParamConfig = cat.CreateEntry("IgnoreTagParam", new[] {"*"},
description: "Which tags should be added to the AAS param name (not animator param name) so it is" +
"ignored by the profile changes (default always overrides).");
_paramTags = ignoreTagParamConfig.Value;
ignoreTagParamConfig.OnValueChangedUntyped += () => _paramTags = ignoreTagParamConfig.Value;
var ignoreTagParamConfig = cat.CreateEntry("BlacklistParamTag", "*",
description: "Which tag should be added to the AAS param name (not animator param name) to blacklist" +
"the parameter from being affected by profile changes. Requires restart.");
_paramTag = ignoreTagParamConfig.Value;
ignoreTagParamConfig.OnValueChangedUntyped += () => _paramTag = ignoreTagParamConfig.Value;

var ignoreTagProfileConfig = cat.CreateEntry("BlacklistBypassProfileTag", "*",
description: "Which tag should be added to the profile name to bypass the blacklist (forcing all params" +
"to change. Requires restart.");
_profileTag = ignoreTagProfileConfig.Value;
ignoreTagProfileConfig.OnValueChangedUntyped += () => _profileTag = ignoreTagProfileConfig.Value;

var useAutoProfile = cat.CreateEntry("RememberParams", true,
description: "Whether the mod will remember the latest parameter settings across avatar changes or game " +
"restarts or not. It will create a new profile while keeping it updated with current values.");
_autoProfileEnabled = useAutoProfile.Value;
useAutoProfile.OnValueChangedUntyped += () => {
_autoProfileEnabled = useAutoProfile.Value;
OnParameterChangedViaMenu();
};

var autoProfileName = cat.CreateEntry("RememberParamsProfileName", "Auto",
description: "Profile name save the parameters to remember. You can use the BlacklistBypassProfileTag on " +
"this profile name to indicate where you want load ALL parameters (including the blacklisted ones)." +
" Requires restart.");
_autoProfileName = autoProfileName.Value;
autoProfileName.OnValueChangedUntyped += () => {
_autoProfileName = autoProfileName.Value;
OnParameterChangedViaMenu();
};
}

private static void OnParameterChangedViaMenu() {
if (!_autoProfileEnabled) return;

var ignoreTagProfileConfig = cat.CreateEntry("ForceTagProfile", new[] {"*"},
description: "Which tags should be added to the profile name to force all params to change when chanted into.");
_profileTags = ignoreTagProfileConfig.Value;
ignoreTagProfileConfig.OnValueChangedUntyped += () => _profileTags = ignoreTagProfileConfig.Value;
// Saves current parameters to profile and sets it as the default
PlayerSetup.Instance.SaveCurrentAvatarSettingsProfile(_autoProfileName);
}

[HarmonyPatch]
Expand All @@ -51,7 +82,7 @@ private static void AfterLoadProfile(string profileName, CVRAnimatorManager anim
[HarmonyPatch(typeof(CVRAnimatorManager), nameof(CVRAnimatorManager.ApplyAdvancedSettingsFileProfile))]
private static void AfterApplyAdvancedSettingsFileProfile(ref List<CVRAdvancedSettingsFileProfileValue> values) {

if (_profileTags.Any(tag => _loadingProfile.Contains(tag))) {
if (_loadingProfile.Contains(_profileTag)) {
// The profile name is forcing all parameters to change
MelonLogger.Msg($"Loaded profile {_loadingProfile} which contains a tag that forces all params to change.");
return;
Expand All @@ -64,9 +95,28 @@ private static void AfterApplyAdvancedSettingsFileProfile(ref List<CVRAdvancedSe
// Remove all values which their AAS name includes the character *
var removedCount = values.RemoveAll(value =>
settings.Any(setting =>
setting.machineName == value.name && _paramTags.Any(tag => setting.name.Contains(tag))));
setting.machineName == value.name && setting.name.Contains(_paramTag)));

MelonLogger.Msg($"Loaded profile {_loadingProfile} while ignoring {removedCount} parameters.");
}

[HarmonyPostfix]
[HarmonyPatch(typeof(CVR_MenuManager), nameof(CVR_MenuManager.HandleSystemCall))]
private static void AfterCVR_MenuManagerHandleSystemCall(string type, string param1, string param2) {
// We're detecting the Quick Menu parameter change events here
if (type is "AppChangeAnimatorParam" or "ChangeAnimatorParam") OnParameterChangedViaMenu();
}

[HarmonyPrefix]
[HarmonyPatch(typeof(ViewManager), nameof(ViewManager.RegisterEvents))]
private static void BeforeViewManagerRegisterEvents(ViewManager __instance) {
// We're detecting the Main Menu change parameter events here
// Lets bind this before the game binds it, otherwise we can't overwrite it later
__instance.gameMenuView.View.BindCall("CVRAppCallChangeAnimatorParam", (string name, float value) => {
// Call the original function
PlayerSetup.Instance.changeAnimatorParam(name, value);
OnParameterChangedViaMenu();
});
}
}
}
2 changes: 1 addition & 1 deletion ProfilesExtended/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace ProfilesExtended.Properties;
internal static class AssemblyInfoParams {
public const string Version = "1.0.0";
public const string Version = "1.0.1";
public const string Author = "kafeijao";
}

19 changes: 7 additions & 12 deletions ProfilesExtended/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# ProfilesExtended

This mod allows you to extend the current profiles system (of the avatar parameters).
This mod adds more functionality to the avatar profiles system.

### Features:
1. Ignore parameters that have `*` in their name (not the parameter name in the animator, but the one in the AAS)
2. Force parameter changes by having `*` in the profile name
1. Blacklist parameters from changing that include `*` in their name (not the parameter name in the animator, but the
one in the AAS)
2. Bypass the said blacklist by having `*` in the profile name
3. Remember current parameters across avatar changes or game restarts

![image of where to set the parameter name](AAS_parameter_name.png)

### Configuration:
You can **define your own tags**, for both parameters and profiles. To configure it install the mod, and run the
You can **define your own tags**, for both parameters and profiles. To configure you can either use `UIExpansionKit` or
manually edit the configuration file. To configure manually you need to install the mod, and run the
game at least one time so the configuration gets generated. After that you can go to (this might change if you
have the game installed somewhere else):

Expand All @@ -20,14 +23,6 @@ C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\UserData\MelonPreferenc
You can then edit and look for `[ProfilesExtended]` line, bellow it there should be all configurations with a little
description. You **can** edit whether the game is running or not, they should take effect as soon as you save the file.

#### Example
```markdown
[ProfilesExtended]
# Which tags should be added to the AAS param name (not animator param name) so it isignored by the profile changes (default always overrides).
IgnoreTagParam = [ "*", "**", ]
# Which tags should be added to the profile name to force all params to change when chanted into.
ForceTagProfile = [ "*", "WOO", ]
```

---

Expand Down

0 comments on commit b17ceda

Please sign in to comment.