Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #4 from Luxusio/develop
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
Luxusio authored Jun 21, 2021
2 parents 0c9a2f3 + e5c8176 commit 4854a9e
Show file tree
Hide file tree
Showing 9 changed files with 1,225 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Id": "NoStopMod",
"DisplayName": "NoStopMod",
"Author": "Luxus",
"Version": "1.1.0",
"Version": "1.2.1",
"ManagerVersion": "0.23.4.0",
"AssemblyName": "NoStopMod.dll",
"EntryMethod": "NoStopMod.NoStopMod.Load"
Expand Down
38 changes: 10 additions & 28 deletions InputFixer/InputFixerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using UnityEngine;
using UnityModManagerNet;
using NoStopMod.InputFixer.SyncFixer;

namespace NoStopMod.InputFixer
{
Expand All @@ -15,11 +16,9 @@ class InputFixerManager

private static Thread thread;
public static Queue<Tuple<long, List<KeyCode>>> keyQueue = new Queue<Tuple<long, List<KeyCode>>>();


public static long currTick;
public static long prevTick;

public static long offsetTick;
//public static long offsetTick;
public static long currPressTick;

public static bool jumpToOtherClass = false;
Expand All @@ -36,13 +35,11 @@ public static void Init()

settings = new InputFixerSettings();
Settings.settings.Add(settings);

prevTick = DateTime.Now.Ticks;
currTick = prevTick;

mask = Enumerable.Repeat(false, 1024).ToArray();

HitIgnoreManager.Init();
SyncFixerManager.Init();
}

private static void OnGUI(UnityModManager.ModEntry modEntry)
Expand All @@ -67,7 +64,6 @@ private static void UpdateEnableAsync(bool value)
public static void Start()
{
Stop();
adjustOffsetTick();
if (settings.enableAsync) {
thread = new Thread(Run);
thread.Start();
Expand Down Expand Up @@ -106,10 +102,11 @@ private static bool GetKeyDown(int idx)

private static void Run()
{
long prevTick = DateTime.Now.Ticks;
while (true)
long prevTick, currTick;
prevTick = DateTime.Now.Ticks;
while (settings.enableAsync)
{
long currTick = DateTime.Now.Ticks;
currTick = DateTime.Now.Ticks;
if (currTick > prevTick)
{
prevTick = currTick;
Expand Down Expand Up @@ -160,28 +157,13 @@ public static double getSongPosition(scrConductor __instance, long nowTick)
{
if (!GCS.d_oldConductor && !GCS.d_webglConductor)
{
return ((nowTick / 10000000.0 - scrConductor.calibration_i) * __instance.song.pitch) - __instance.addoffset;
return ((nowTick / 10000000.0 - SyncFixerManager.newScrConductor.dspTimeSong - scrConductor.calibration_i) * __instance.song.pitch) - __instance.addoffset;
}
else
{
return (__instance.song.time - scrConductor.calibration_i) - __instance.addoffset / __instance.song.pitch;
}
}

public static void adjustOffsetTick()
{
if (scrConductor.instance != null)
{
long prevOffset = offsetTick;
InputFixerManager.jumpToOtherClass = true;
scrConductor.instance.Start();
}
}

public static void adjustOffsetTick(scrConductor __instance, double ___dspTimeSong)
{
offsetTick = currTick - (long)((__instance.dspTime - ___dspTimeSong) * 10000000);
}


}
}
102 changes: 7 additions & 95 deletions InputFixer/InputFixerPatches.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using DG.Tweening;
using HarmonyLib;
using NoStopMod.InputFixer.HitIgnore;
using NoStopMod.InputFixer.SyncFixer;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,49 +11,25 @@ namespace NoStopMod.InputFixer
{
public static class AsyncInputPatches
{

//public static string s(double d, int to = 6)
//{
// try
// {
// return ("" + d).Substring(0, to);
// }
// catch
// {
// return "" + d;
// }
//}

[HarmonyPatch(typeof(scrController), "Awake")]
private static class scrController_Awake_Patch
{
public static void Postfix(scrController __instance)
{
InputFixerManager.jumpToOtherClass = true;
__instance.conductor.Start();
InputFixerManager.Start();
}
}

[HarmonyPatch(typeof(scrConductor), "Update")]
private static class scrConductor_Update_Patch_Time
{
public static void Prefix(scrConductor __instance)
{
InputFixerManager.prevTick = InputFixerManager.currTick;
InputFixerManager.currTick = DateTime.Now.Ticks;
}

public static void Postfix(scrConductor __instance, double ___dspTimeSong)
public static void Postfix(scrConductor __instance)
{
if (AudioListener.pause)
{
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
}

if (!InputFixerManager.settings.enableAsync)
{
InputFixerManager.UpdateKeyQueue(InputFixerManager.currTick);
InputFixerManager.UpdateKeyQueue(NoStopMod.CurrFrameTick());
}

while (InputFixerManager.keyQueue.Any())
Expand All @@ -71,7 +48,7 @@ public static void Postfix(scrConductor __instance, double ___dspTimeSong)
if (++count > 4) break;
}

InputFixerManager.currPressTick = tick - InputFixerManager.offsetTick;
InputFixerManager.currPressTick = tick - SyncFixerManager.newScrConductor.offsetTick;
controller.keyBufferCount += count;
while (controller.keyBufferCount > 0)
{
Expand Down Expand Up @@ -112,7 +89,7 @@ public static bool Prefix(scrPlanet __instance, ref double ___snappedLastAngle)

if (!GCS.d_stationary)
{
long nowTick = InputFixerManager.currTick - InputFixerManager.offsetTick;
long nowTick = NoStopMod.CurrFrameTick() - SyncFixerManager.newScrConductor.offsetTick;
__instance.angle = InputFixerManager.getAngle(__instance, ___snappedLastAngle, nowTick);

if (__instance.shouldPrint)
Expand Down Expand Up @@ -157,72 +134,7 @@ public static bool Prefix(scrPlanet __instance, ref double ___snappedLastAngle)
return false;
}
}

[HarmonyPatch(typeof(scrController), "OnMusicScheduled")]
private static class scrController_Rewind_Patch
{
public static void Postfix(scrController __instance)
{
InputFixerManager.jumpToOtherClass = true;
__instance.conductor.Start();
}
}

[HarmonyPatch(typeof(scrConductor), "Start")]
private static class scrConductor_Start_Patch
{
public static bool Prefix(scrConductor __instance, double ___dspTimeSong)
{
if (InputFixerManager.jumpToOtherClass)
{
InputFixerManager.jumpToOtherClass = false;
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
return false;
}
return true;
}
}

[HarmonyPatch(typeof(scrConductor), "Rewind")]
private static class scrConductor_Rewind_Patch
{
public static void Postfix(scrConductor __instance, double ___dspTimeSong)
{
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
//NoStopMod.mod.Logger.Log("Rewind");
}
}

[HarmonyPatch(typeof(scrConductor), "StartMusicCo")]
private static class scrConductor_StartMusicCo_Patch
{
public static void Prefix(scrConductor __instance, double ___dspTimeSong)
{
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
//NoStopMod.mod.Logger.Log("StartMusicCo");
}
}

[HarmonyPatch(typeof(scrConductor), "ScrubMusicToTile")]
private static class scrConductor_ScrubMusicToTile_Patch
{
public static void Postfix(scrConductor __instance, double ___dspTimeSong)
{
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
//NoStopMod.mod.Logger.Log("ScrubMusicToTile");
}
}

[HarmonyPatch(typeof(scrConductor), "DesyncFix")]
private static class scrConductor_DesyncFix_Patch
{
public static void Postfix(scrConductor __instance, double ___dspTimeSong)
{
InputFixerManager.adjustOffsetTick(__instance, ___dspTimeSong);
//NoStopMod.mod.Logger.Log("DesyncFix");
}
}




}
}
1 change: 0 additions & 1 deletion InputFixer/InputFixerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public void Load(ref JSONNode json)
enableAsync = node["enableAsync"].AsBool;
enableKeyLimit = node["enableKeyLimit"].AsBool;
JSONArray array = node["LimitKeys"].AsArray;

}

public void Save(ref JSONNode json)
Expand Down
21 changes: 21 additions & 0 deletions InputFixer/SyncFixer/SyncFixerManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NoStopMod.InputFixer.SyncFixer
{
class SyncFixerManager
{

public static newScrConductor newScrConductor;

public static void Init()
{
newScrConductor = new newScrConductor();
if (newScrConductor.instance != null) newScrConductor.FixOffsetTick();
}

}
}
Loading

0 comments on commit 4854a9e

Please sign in to comment.