Skip to content

Commit

Permalink
Fully optimize for release 1.1, I kinda impulsively released this wit…
Browse files Browse the repository at this point in the history
…h some unoptimized parts or parts that made no sense, and also tried to document Program.cs to the best of my ability ^-^
  • Loading branch information
h3llo-wor1d committed Dec 14, 2022
1 parent 1adc8f2 commit 17308c3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 163 deletions.
7 changes: 1 addition & 6 deletions CircleRGB_v2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<ApplicationIcon>rgb.ico</ApplicationIcon>
<ApplicationIcon>bp_icon.ico</ApplicationIcon>
<DebugType>None</DebugType>
<DebugSymbols>false</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Buttplug" Version="2.0.6" />
<PackageReference Include="Device.Net" Version="4.2.1" />
<PackageReference Include="Device.Net.LibUsb" Version="4.2.1" />
<PackageReference Include="Hid.Net" Version="4.2.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="OpenRGB.NET" Version="1.7.0" />
<PackageReference Include="OsuMemoryDataProvider" Version="0.8.9" />
<PackageReference Include="Usb.Net" Version="4.2.1" />
</ItemGroup>

</Project>
130 changes: 63 additions & 67 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,28 @@
using OsuMemoryDataProvider.OsuMemoryModels.Direct;
using System.Diagnostics;
using Buttplug;
using System.Threading.Tasks;
using System.Collections.Generic;
using System;
using System.IO;
using System;
using System.Timers;

namespace CircleBP
{
public class EnvelopeGenerator
{

}

internal class Program

{
private static StructuredOsuMemoryReader _sreader = StructuredOsuMemoryReader.Instance.GetInstanceForWindowTitleHint("");
private static ButtplugClient client = new ButtplugClient("CircleBP v1.0 (PRIVATE BETA!!!) by Willow");
private static ButtplugClient client = new ButtplugClient("CircleBP v1.1 Alpha by Wrench");
private static ButtplugClientDevice device = null;
private static string ip = $"ws://{ReadIP()}";

private static System.Timers.Timer aTimer;

public double envValue; // The actual value of the envelope ATM.
public int tickRate = 60;
public int currentTime = 0;
public double decay = .5;
public int runTime = 0;

// Envelope Generator Tests
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
if (currentTime < runTime)
{
currentTime++;
envValue = (double)currentTime / (double)runTime;
device.SendVibrateCmd(envValue);
}
else
{
aTimer.Enabled = false;
}
}

public void Run()
{
envValue = 0;
currentTime = 0;
runTime = (int)(decay * 60);
aTimer = new System.Timers.Timer(10);
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}

public static string ReadIP()
{
/*
* Read Previously Configured IP, if it exists.
* Otherwise, create a new file called ip.config in the working directory,
* and set the port to 127.0.0.1 (localhost)
*
* The IP file should (i forgot if I actually did this tho) include the port as well?
*/

string path = Directory.GetCurrentDirectory() + "/ip.config";
if (File.Exists(path))
{
Expand All @@ -75,6 +39,9 @@ public static string ReadIP()
}
public static async Task ExecuteVibrate(int i)
{
// This is literally refactored from CircleRGB.
// The strength dict matches the value of <int> i to a double value for the vibration intensity
// TODO: why the fuck is there no 1.0 strength? Did I remove it or smf?
var strengthDict = new Dictionary<int, double>()
{
{1, .75 },
Expand All @@ -87,9 +54,11 @@ public static async Task ExecuteVibrate(int i)

public static async Task Main()
{

var currentScore = new string[4];
var currentScore = new int[4]; // This is now int because why the fuck was it a string array
Console.WriteLine($"Using IP {ip}");

// Connect to buttplug remote ip.
// The program will basically crash or not do anything until it does such.
var connector = new ButtplugWebsocketConnectorOptions(
new Uri(ip));
try
Expand All @@ -104,15 +73,15 @@ public static async Task Main()
await client.StopScanningAsync();
device = client.Devices[0];

Console.WriteLine("CircleBP v1.0 (PRIVATE BETA) || By Willow \n\nPlease Keep This Window Open!!!");
Console.WriteLine("CircleBP v1.1 Alpha || By Wrench\n\nPlease Keep This Window Open!!!");

await Task.Run(async () =>
{
Stopwatch stopwatch;
_sreader.WithTimes = true;
var baseAddresses = new OsuBaseAddresses();
bool devicePlay = false;
string curComboColor = "";
bool devicePlay = false; // Keep track of whether it's a restarted level or not (?)
int curComboValue = 0; // Changed to 16-bit integer for optimization + rename to curComboValue
while (true)
Expand All @@ -123,8 +92,11 @@ await Task.Run(async () =>
if (baseAddresses.GeneralData.OsuStatus == OsuMemoryStatus.SongSelect)
{
currentScore = new string[4];
curComboColor = "";
// Reinitialize everything on SongSelect screen
currentScore = new int[4];
curComboValue = 0;
// Set vibration intensity to 0.0
device.SendVibrateCmd(0.0);
if (devicePlay)
{
Expand All @@ -139,58 +111,82 @@ await Task.Run(async () =>
{
if (devicePlay)
{
// Set vibration intensity to 0.0 and reset everything on ResultsScreen as well.
device.SendVibrateCmd(0.0);
currentScore = new string[4];
curComboColor = "";
curComboValue = 0;
currentScore = new int[4];
devicePlay = false;
}
}
if (baseAddresses.GeneralData.OsuStatus == OsuMemoryStatus.Playing)
{
// This is something I wrote for restarting levels iirc.
// osumemoryreader is kinda weird, and this was like a quick patch that worked
// very efficiently to fix the issues I had
if (!devicePlay)
{
devicePlay = true;
device.SendVibrateCmd(0.0);
}
// Keep track of our 4 important values lol
// Hit 300, 100, 50, and miss change the vibration intensity.
_sreader.TryReadProperty(baseAddresses.Player, nameof(Player.Hit300), out var hit300);
_sreader.TryReadProperty(baseAddresses.Player, nameof(Player.Hit100), out var hit100);
_sreader.TryReadProperty(baseAddresses.Player, nameof(Player.Hit50), out var hit50);
_sreader.TryReadProperty(baseAddresses.Player, nameof(Player.HitMiss), out var hitmiss);
try
{
List<String> testList = new List<String>();
testList.Add(hit300.ToString());
testList.Add(hit100.ToString());
testList.Add(hit50.ToString());
testList.Add(hitmiss.ToString());
// Optimized to List<int> idk why the fuck this was a string list that's so weird
List<int> testList = new List<int>();
testList.Add((int)hit300);
testList.Add((int)hit100);
testList.Add((int)hit50);
testList.Add((int)hitmiss);
for (int i = 0; i < testList.Count; i++)
{
if (currentScore[i] != testList[i])
{
// Compare the temp currentScore at [i] for the array of hit values
// to the testList of hit values. If new values are there, sync the arrays and
// update the vibrator, unless if it's 0, which we ignore.
currentScore[i] = testList[i];
if (testList[i] != "0")
if (testList[i] != 0)
{
if (i.ToString() != curComboColor)
// Right yeah curComboValue was originally for CircleRGB
// (obv by the name, it kept track of the combo color)
if (i != curComboValue)
{
// i is actually an int, and it's a list index,
// so it's like 0-3, so I add 1 for some reason, which
// is like really inefficient, I should probably change it lol
// oh yeah it was bc I think I did something stupid while making this lol
// i should fix it eventually, tbh it's fine for now I think
await ExecuteVibrate(i + 1);
curComboColor = i.ToString();
// also yeah like I said, keeps track of the value.
// it was more efficient to just make it a string at this point rather than
// to convert it every time I want to compare shit.
curComboValue = i;
}
}
}
}
}
catch
{
// Also iirc this was another thing that caught restarted levels and resets everything (?)
if (devicePlay)
{
currentScore = new string[4];
currentScore = new int[4];
devicePlay = false;
curComboColor = "";
curComboValue = 0;
device.SendVibrateCmd(0.0);
}
}
Expand All @@ -200,7 +196,7 @@ await Task.Run(async () =>
{
if (devicePlay)
{
currentScore = new string[4];
currentScore = new int[4];
devicePlay = false;
device.SendVibrateCmd(0.0);
}
Expand All @@ -209,7 +205,7 @@ await Task.Run(async () =>
stopwatch.Stop();
_sreader.ReadTimes.Clear();
await Task.Delay(33);
await Task.Delay(33); // Only check every 33ms for value changes, so the computer doesn't fucking blow up lol
}
});
}
Expand Down
File renamed without changes.
90 changes: 0 additions & 90 deletions simpad.cs

This file was deleted.

0 comments on commit 17308c3

Please sign in to comment.