Skip to content

Commit

Permalink
feat: added some preference options
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljzd-PRO committed Apr 4, 2024
1 parent 1df84b3 commit 139a76f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
20 changes: 15 additions & 5 deletions ButtPlugReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,30 @@ namespace DeppartPrototypeHentaiPlayMod
{
public class ButtPlugReporter : BaseReporter
{
private readonly double _activeVibrateScalar;
private readonly ButtplugClient _buttplugClient;
private readonly Mutex _mutexLock = new Mutex();
private readonly double _shotVibrateScalar;
private double _baseVibrateScalar;

public ButtPlugReporter(HentaiPlayMod melonMod, Uri buttPlugServerUrl) : base(melonMod)
public ButtPlugReporter
(
HentaiPlayMod melonMod,
string buttPlugServerUrl,
double activeVibrateScalar = 0.5,
double shotVibrateScalar = 1
) : base(melonMod)
{
_activeVibrateScalar = activeVibrateScalar;
_shotVibrateScalar = shotVibrateScalar;
_buttplugClient = new ButtplugClient(MelonMod.Info.Name);
_buttplugClient.DeviceAdded +=
(sender, args) => MelonMod.LoggerInstance.Msg($"ButtPlug device added: {args.Device.Name}");
_buttplugClient.DeviceRemoved +=
(sender, args) => MelonMod.LoggerInstance.Msg($"ButtPlug device removed: {args.Device.Name}");
_buttplugClient.ScanningFinished += (sender, args) =>
MelonMod.LoggerInstance.Msg($"ButtPlug scanning finished: {args}");
var connector = new ButtplugWebsocketConnector(buttPlugServerUrl);
var connector = new ButtplugWebsocketConnector(new Uri(buttPlugServerUrl));
connector.Disconnected +=
(sender, args) => MelonMod.LoggerInstance.Msg($"ButtPlug scanning finished: {args}");
new Thread(() =>
Expand Down Expand Up @@ -80,11 +90,11 @@ public override void ReportActivateEvent(string eventName)
{ EventEnum.BulbBroken.ToString(), EventEnum.ZombieRun.ToString(), EventEnum.EnterLevel1.ToString() };
if (tempEvents.Contains(eventName))
{
SendCommand(new[] { 0.5, _baseVibrateScalar }, 5000);
SendCommand(new[] { _activeVibrateScalar, _baseVibrateScalar }, 5000);
}
else
{
_baseVibrateScalar = 0.5;
_baseVibrateScalar = _activeVibrateScalar;
SendCommand(new[] { _baseVibrateScalar });
}
}
Expand All @@ -111,7 +121,7 @@ public override void ReportGameExitEvent()
public override void ReportShot()
{
base.ReportShot();
SendCommand(new[] { 1, _baseVibrateScalar });
SendCommand(new[] { _shotVibrateScalar, _baseVibrateScalar });
}
}
}
33 changes: 27 additions & 6 deletions HentaiPlayMod.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using DeppartPrototypeHentaiPlayMod;
using MelonLoader;
Expand All @@ -23,7 +22,10 @@ public class HentaiPlayMod : MelonMod
{ EventEnum.PlayerDied.ToString(), false }
};

private MelonPreferences_Entry<Uri> _buttPlugServerUrlEntry;
private MelonPreferences_Entry<double> _buttPlugActiveVibrateScalar;

private MelonPreferences_Entry<string> _buttPlugServerUrlEntry;
private MelonPreferences_Entry<double> _buttPlugShotVibrateScalar;
private MelonPreferences_Entry<bool> _disableEventLogEntry;

private IEventReporter _eventReporter;
Expand All @@ -44,7 +46,8 @@ public override void OnInitializeMelon()
(
"EventReporterType",
nameof(ButtPlugReporter),
description: "Type of reporter that report events in game"
description: "Type of reporter that report events in game " +
$"(Available: {nameof(BaseReporter)}, {nameof(HttpReporter)}, {nameof(ButtPlugReporter)})"
);
_httpReporterUrlEntry = _preferencesCategory.CreateEntry
(
Expand All @@ -67,9 +70,21 @@ public override void OnInitializeMelon()
_buttPlugServerUrlEntry = _preferencesCategory.CreateEntry
(
"ButtPlugServerUrl",
new Uri("ws://localhost:12345"),
"ws://localhost:12345",
description: "Websocket URL of ButtPlug server (Intiface Central)"
);
_buttPlugActiveVibrateScalar = _preferencesCategory.CreateEntry
(
"ButtPlugActiveVibrateScalar",
0.5,
description: "Set the ButtPlug vibrate scalar when game events active"
);
_buttPlugShotVibrateScalar = _preferencesCategory.CreateEntry
(
"ButtPlugShotVibrateScalar",
1.0,
description: "Set the ButtPlug vibrate scalar when gun shot"
);
}

public override void OnLateInitializeMelon()
Expand Down Expand Up @@ -119,7 +134,13 @@ private void SetupEventReporter()
);
break;
case nameof(ButtPlugReporter):
_eventReporter = new ButtPlugReporter(this, _buttPlugServerUrlEntry.Value);
_eventReporter = new ButtPlugReporter
(
this,
_buttPlugServerUrlEntry.Value,
_buttPlugActiveVibrateScalar.Value,
_buttPlugShotVibrateScalar.Value
);
break;
}

Expand Down

0 comments on commit 139a76f

Please sign in to comment.