Skip to content

Commit

Permalink
1.31 (Solo)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Aug 1, 2023
1 parent c93eeec commit f016308
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 66 deletions.
7 changes: 2 additions & 5 deletions GameLogic/BeatmapLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class BeatmapLoader {
static BeatmapLevelsModel beatmapLevelsModel;
static bool reloadLevelpacksOnExit = false;

static readonly IPA.Utilities.FieldAccessor<BeatmapLevelsModel, Dictionary<string, IPreviewBeatmapLevel>>.Accessor BeatmapLevelsModel_loadedPreviewBeatmapLevels =
IPA.Utilities.FieldAccessor<BeatmapLevelsModel, Dictionary<string, IPreviewBeatmapLevel>>.GetAccessor("_loadedPreviewBeatmapLevels");

public BeatmapLoader(
GameplayCoreSceneSetupData _sceneSetupData,
BeatmapLevelsModel beatmapLevelsModel
Expand All @@ -21,13 +18,13 @@ BeatmapLevelsModel beatmapLevelsModel
}

public static void AddBeatmapToLoadedPreviewBeatmaps(string levelId, IPreviewBeatmapLevel level) {
BeatmapLevelsModel_loadedPreviewBeatmapLevels(ref beatmapLevelsModel)[levelId] = level;
beatmapLevelsModel._loadedPreviewBeatmapLevels[levelId] = level;

reloadLevelpacksOnExit = true;
}

public static IPreviewBeatmapLevel GetPreviewBeatmapFromLevelId(string levelId) {
if(BeatmapLevelsModel_loadedPreviewBeatmapLevels(ref beatmapLevelsModel).TryGetValue(levelId, out var map))
if(beatmapLevelsModel._loadedPreviewBeatmapLevels.TryGetValue(levelId, out var map))
return map;

return null;
Expand Down
5 changes: 1 addition & 4 deletions GameLogic/BeatmapObjectDissolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ namespace Shaffuru.GameLogic {
class BeatmapObjectDissolver : IInitializable, IDisposable {
BeatmapObjectManager beatmapObjectManager;

static readonly IPA.Utilities.FieldAccessor<BeatmapObjectManager, List<IBeatmapObjectController>>.Accessor BeatmapObjectManager_allBeatmapObjects =
IPA.Utilities.FieldAccessor<BeatmapObjectManager, List<IBeatmapObjectController>>.GetAccessor("_allBeatmapObjects");

// I am very sorry for this misuse d̵̡͌ont u̴͕̽̇s̸̢̩͗e eveǹ̸̠͕͂̀t̷̻͆̌̚ś̷͈́ this w̴͔̦̥̆̈́̓͑̌a̷̡͊ỹ̴̢͍͚̘̺ nevè̷̙̒̈́̅̉͘͝r̴̨̧̜̳͖̥̓̿͋̒̀́̚ͅ ̸̗̩̣̈͋͌́͊̌̚ṕ̶͇̼͔̼͔̤͊͘l̵̢̺̻̻̪̟̽̓̾͌͠ease Ỏ̷͚͖̿̂̀̎Ḧ̶̤̮̫̱̖̭̟͔̰̖́̓̈́͆̍̚ ̶̞̤̪͕̱̻̳͍͒̑̽̿͂̂Ģ̶̧̛̱̯͊̑̍̓͒́̀̿͗͝O̴̘̙̔̌̓͗̀̂̓̎̉̋̀͝ͅD̴̲̼̯̿ ̸̧̙̖͙͔͔͖̹̈́̍̐̽͗̇͝͠T̸̡͎͉̠͖͈́͊̇Ĥ̷̢͂̅͐̊̈́̈́̏͋̌͘E̴̢̩̥͉͂͆̍̉̀́̌̌͒̃̀͠͝Y̶͖̲͚̿͋̐̃̇̋̈́̚͜ Ȃ̷͎̣̭̻̩̺̗̯̮̭̱͚̲̉̂̌ͅR̵̢̢̬͇̫͔̫̟̥̟̰̺͂̈́͜͝Ȩ̵̧͕̙̤̤͎̃͊̀̿̍̔̕͝ ̸̡̺̞̖̠̼̬̗͈͉̫̤̪͔̌̈́C̴̛̘͇͉̭̟͍̺̱̹͉̤̠̆̌̉̊̏̕͠͝O̶̡̝̰̗̗͔̿M̵̦͉̭̼̻̳̺̙̩̓̐̐̐̑̍͐̈͘͝I̵̦͉̟̝̺̳̙̬̭̱͚͖̥̣͕͓͍̒͌́̊̓N̸̡̛̰̞͍̩̝͖̠̠͈̂̀̐́̃̌̾͊̎͗̇̀̕͠Ğ̸̩͖̠͎̻́̇̾͌͑́̑̕̕͜
static event Action<float> doDissolve;

Expand All @@ -21,7 +18,7 @@ class BeatmapObjectDissolver : IInitializable, IDisposable {
}

public void DissolveAll(float dissolveTime) {
foreach(var boc in BeatmapObjectManager_allBeatmapObjects(ref beatmapObjectManager))
foreach(var boc in beatmapObjectManager._allBeatmapObjects)
boc.Dissolve(dissolveTime);
}

Expand Down
25 changes: 6 additions & 19 deletions GameLogic/BeatmapSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@

namespace Shaffuru.GameLogic {
class BeatmapSwitcher : IDisposable {
static readonly FieldInfo FIELD_BeatmapObjectSpawnController_beatmapObjectSpawnMovementData
= AccessTools.Field(typeof(BeatmapObjectSpawnController), "_beatmapObjectSpawnMovementData");
static readonly FieldInfo FIELD_BeatmapObjectSpawnController_disableSpawning
= AccessTools.Field(typeof(BeatmapObjectSpawnController), "_disableSpawning");

static readonly FieldInfo FIELD_BeatmapObjectCallbackController_callbacksInTimes = AccessTools.Field(typeof(BeatmapCallbacksController), "_callbacksInTimes");

static readonly IPA.Utilities.FieldAccessor<CallbacksInTime, Dictionary<Type, List<BeatmapDataCallbackWrapper>>>.Accessor FIELD_CallbacksInTime_callbacks
= IPA.Utilities.FieldAccessor<CallbacksInTime, Dictionary<Type, List<BeatmapDataCallbackWrapper>>>.GetAccessor("_callbacks");


static readonly MethodInfo SETTER_GameEnergyCounter_noFail = AccessTools.PropertySetter(typeof(GameEnergyCounter), nameof(GameEnergyCounter.noFail));

static readonly IPA.Utilities.FieldAccessor<BeatmapDataItem, float>.Accessor SETTER_BeatmapDataItem_time
= IPA.Utilities.FieldAccessor<BeatmapDataItem, float>.GetAccessor($"<{nameof(BeatmapDataItem.time)}>k__BackingField");
static readonly IPA.Utilities.FieldAccessor<SliderData, float>.Accessor SETTER_SliderData_tailTime
Expand Down Expand Up @@ -72,10 +59,10 @@ RamCleaner ramCleaner
this.ramCleaner = ramCleaner;

if(beatmapCallbacksController != null)
beatmapObjectCallbackController_callbacksInTimes = (Dictionary<float, CallbacksInTime>)FIELD_BeatmapObjectCallbackController_callbacksInTimes.GetValue(beatmapCallbacksController);
beatmapObjectCallbackController_callbacksInTimes = beatmapCallbacksController._callbacksInTimes;

if(beatmapObjectSpawnController != null) {
beatmapObjectSpawnMovementData = (BeatmapObjectSpawnMovementData)FIELD_BeatmapObjectSpawnController_beatmapObjectSpawnMovementData.GetValue(beatmapObjectSpawnController);
beatmapObjectSpawnMovementData = beatmapObjectSpawnController.beatmapObjectSpawnMovementData;
startBeatmapCallbackAheadTime = beatmapObjectSpawnMovementData.spawnAheadTime;
}
}
Expand All @@ -99,7 +86,7 @@ RamCleaner ramCleaner

void SetSpawningEnabled(bool enable) {
if(beatmapObjectSpawnController != null)
FIELD_BeatmapObjectSpawnController_disableSpawning.SetValue(beatmapObjectSpawnController, !enable);
beatmapObjectSpawnController._disableSpawning = !enable;
}

public void SwitchToDifferentBeatmap(IDifficultyBeatmap difficultyBeatmap, IReadonlyBeatmapData replacementBeatmapData, float startTime, float secondsToInsert = 0) {
Expand Down Expand Up @@ -234,7 +221,7 @@ RamCleaner ramCleaner
var aheadTime = v.aheadTime;
// I hate that i actually have to do this. Writes the correct / new aheadTime to the callbacks for the object spawns
if(x.Key == startBeatmapCallbackAheadTime) {
var cbs = FIELD_CallbacksInTime_callbacks(ref v);
var cbs = v._callbacks;
aheadTime = beatmapObjectSpawnMovementData.spawnAheadTime;
foreach(var cbl in cbs.Values) {
cbl.ForEach(cb => { SETTER_BeatmapDataCallbackWrapper_aheadTime(ref cb) = aheadTime; });
Expand Down Expand Up @@ -273,15 +260,15 @@ RamCleaner ramCleaner
yield break;

if(gameEnergyCounter != null)
SETTER_GameEnergyCounter_noFail.Invoke(gameEnergyCounter, new object[] { true });
gameEnergyCounter.noFail = true;

yield return new WaitForSeconds(Config.Instance.transition_gracePeriod);

if(audioTimeWrapper == null)
yield break;

if(gameEnergyCounter != null)
SETTER_GameEnergyCounter_noFail.Invoke(gameEnergyCounter, new object[] { false });
gameEnergyCounter.noFail = false;
}
}

Expand Down
58 changes: 23 additions & 35 deletions MenuLogic/Anlasser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Anlasser {
static int lastShaffuruMapLength = 0;
public readonly static BeatmapLevelSO beatmapLevel = ScriptableObject.CreateInstance<BeatmapLevelSO>();
readonly static BeatmapDataSO beatmapLevelData = ScriptableObject.CreateInstance<BeatmapDataSO>();
public readonly static BeatmapLevelSO.DifficultyBeatmap difficultyBeatmap = new BeatmapLevelSO.DifficultyBeatmap(beatmapLevel, BeatmapDifficulty.ExpertPlus, 0, 10, 0, beatmapLevelData);
public readonly static BeatmapLevelSO.DifficultyBeatmap difficultyBeatmap = new BeatmapLevelSO.DifficultyBeatmap(beatmapLevel, BeatmapDifficulty.ExpertPlus, 0, 10, 0, 0, beatmapLevelData);

static UBinder<Plugin, System.Random> rngSource;

Expand All @@ -31,7 +31,7 @@ class Anlasser {
PlayerDataModel playerDataModel,
CustomLevelLoader customLevelLoader,
[InjectOptional] MenuTransitionsHelper menuTransitionsHelper,
BeatmapCharacteristicCollectionSO beatmapCharacteristicCollectionSO,
BeatmapCharacteristicCollection beatmapCharacteristicCollection,
UBinder<Plugin, System.Random> rng
) {
this.playerDataModel = playerDataModel;
Expand All @@ -40,7 +40,7 @@ class Anlasser {
rngSource = rng;

defaultEnvironment ??= customLevelLoader.LoadEnvironmentInfo("", false);
standardCharacteristic = beatmapCharacteristicCollectionSO.GetBeatmapCharacteristicBySerializedName("Standard");
standardCharacteristic = beatmapCharacteristicCollection.GetBeatmapCharacteristicBySerializedName("Standard");
}

public event Action<LevelCompletionResults> finishedOrFailedCallback;
Expand All @@ -49,9 +49,6 @@ class Anlasser {
static readonly IPA.Utilities.FieldAccessor<BeatmapLevelData, AudioClip>.Accessor BeatmapLevelData_audioClip =
IPA.Utilities.FieldAccessor<BeatmapLevelData, AudioClip>.GetAccessor("_audioClip");

static readonly IPA.Utilities.FieldAccessor<BeatmapLevelSO, AudioClip>.Accessor BeatmapLevelSO_audioClip =
IPA.Utilities.FieldAccessor<BeatmapLevelSO, AudioClip>.GetAccessor("_audioClip");

static readonly IPA.Utilities.FieldAccessor<BeatmapLevelSO, string>.Accessor BeatmapLevelSO_songName =
IPA.Utilities.FieldAccessor<BeatmapLevelSO, string>.GetAccessor("_songName");

Expand All @@ -73,7 +70,7 @@ class Anlasser {

var audioClip = AudioClip.Create("", lengthSeconds * 1000, 1, 1000, false);

BeatmapLevelSO_audioClip(ref beatmapLevel) = audioClip;
beatmapLevel._audioClip = audioClip;
if(beatmapLevel.beatmapLevelData is BeatmapLevelData b)
BeatmapLevelData_audioClip(ref b) = audioClip;
lastShaffuruMapLength = lengthSeconds;
Expand Down Expand Up @@ -107,6 +104,7 @@ class Anlasser {
SongCore.Loader.defaultCoverImage,
defaultEnvironment,
defaultEnvironment,
new EnvironmentInfoSO[] { },
new[] { new BeatmapLevelSO.DifficultyBeatmapSet(standardCharacteristic, new[] { difficultyBeatmap }) }
);
}
Expand All @@ -120,34 +118,13 @@ class Anlasser {
x.GetParameters().Any(x => x.Name == "afterSceneSwitchCallback")
);

object[] StartStandardLevelReflectionArgsArray = null;

public void Start(int lengthSeconds, int rngSeed = 0) {
if(rngSeed != 0)
rngSource.Value = new System.Random(rngSeed);

UpdateFakeBeatmap(lengthSeconds);

// Using reflection here so I can target 1.21+ instead of 1.25 since they added a 14th argument to StartStandardLevel there (Thats the only thing that broke)
if(StartStandardLevelReflectionArgsArray == null) {
StartStandardLevelReflectionArgsArray = new object[StartStandardLevelMethod.GetParameters().Length];

StartStandardLevelReflectionArgsArray[0] = "Shaffuru";
StartStandardLevelReflectionArgsArray[1] = difficultyBeatmap;
StartStandardLevelReflectionArgsArray[2] = beatmapLevel;

StartStandardLevelReflectionArgsArray[7] = null;
StartStandardLevelReflectionArgsArray[8] = Localization.Get("BUTTON_MENU");
StartStandardLevelReflectionArgsArray[9] = false;
StartStandardLevelReflectionArgsArray[10] = false;
StartStandardLevelReflectionArgsArray[11] = null;
StartStandardLevelReflectionArgsArray[12] = null;

if(StartStandardLevelReflectionArgsArray.Length > 14)
StartStandardLevelReflectionArgsArray[14] = null;
}

StartStandardLevelReflectionArgsArray[13] = new Action<LevelScenesTransitionSetupDataSO, LevelCompletionResults>((a, b) => {
var endCallback = new Action<LevelScenesTransitionSetupDataSO, LevelCompletionResults>((a, b) => {
if(b.levelEndAction == LevelCompletionResults.LevelEndAction.Restart) {
Start(lengthSeconds);
return;
Expand All @@ -164,12 +141,23 @@ class Anlasser {
}
});

StartStandardLevelReflectionArgsArray[3] = playerDataModel.playerData.overrideEnvironmentSettings;
StartStandardLevelReflectionArgsArray[4] = playerDataModel.playerData.colorSchemesSettings.GetOverrideColorScheme();
StartStandardLevelReflectionArgsArray[5] = playerDataModel.playerData.gameplayModifiers;
StartStandardLevelReflectionArgsArray[6] = playerDataModel.playerData.playerSpecificSettings;

StartStandardLevelMethod.Invoke(menuTransitionsHelper, StartStandardLevelReflectionArgsArray);
menuTransitionsHelper.StartStandardLevel(
"Shaffuru",
difficultyBeatmap,
beatmapLevel,
playerDataModel.playerData.overrideEnvironmentSettings,
playerDataModel.playerData.colorSchemesSettings.GetOverrideColorScheme(),
playerDataModel.playerData.colorSchemesSettings.GetOverrideColorScheme(),
playerDataModel.playerData.gameplayModifiers,
playerDataModel.playerData.playerSpecificSettings,
null,
Localization.Get("BUTTON_MENU"),
false,
false,
null,
endCallback,
null
);
}
}
}
8 changes: 6 additions & 2 deletions Shaffuru.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="Main">
<Reference Include="Main" Publicize="true">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\Main.dll</HintPath>
</Reference>
<Reference Include="HMLib">
<Reference Include="HMLib" Publicize="true">
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\HMLib.dll</HintPath>
</Reference>
<Reference Include="HMUI">
Expand Down Expand Up @@ -169,6 +169,10 @@
<IncludeAssets>build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Update="System.Drawing" />
Expand Down
10 changes: 10 additions & 0 deletions Util/SharedCoroutineStarter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

public class SharedCoroutineStarter : MonoBehaviour {
static MonoBehaviour _instance = null;
public static MonoBehaviour instance => _instance ??= new GameObject().AddComponent<SharedCoroutineStarter>();

void Awake() {
GameObject.DontDestroyOnLoad(gameObject);
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "Shaffuru",
"name": "Shaffuru",
"author": "Kinsi55",
"version": "0.2.0",
"version": "0.2.1",
"description": "Endless Mode evolved - Allows you to play a randomly* picked list of songs in various different ways",
"gameVersion": "1.21.0",
"dependsOn": {
Expand Down

0 comments on commit f016308

Please sign in to comment.