Skip to content

Commit

Permalink
Update for 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
kinsi55 committed Mar 11, 2022
1 parent c107371 commit 3a15bca
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
15 changes: 10 additions & 5 deletions HarmonyPatches/AttemptTwo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,27 @@ public static IEnumerator Init() {
* First, to find out what actually is lit in the current Env when static lights is on,
* act as tho we are on static lights!
*/
var controller = Resources.FindObjectsOfTypeAll<BeatmapObjectCallbackController>().FirstOrDefault();
yield return null;
var bcu = Object.FindObjectOfType<BeatmapCallbacksUpdater>();
if(bcu == null)
yield break;

var controller = IPA.Utilities.ReflectionUtil.GetField<BeatmapCallbacksController, BeatmapCallbacksUpdater>(bcu, "_beatmapCallbacksController");

if(controller == null)
yield break;

ForceColorOnInit.enable = true;
yield return 0;
yield return null;

if(BasegameStaticLights.enabled) {
ForceColorOnInit.enable = false;
yield break;
}

// See BeatmapDataLoader::GetBeatmapDataFromBeatmapSaveData
controller.SendBeatmapEventDidTriggerEvent(new BeatmapEventData(0, BeatmapEventType.Event0, 1, 1));
controller.SendBeatmapEventDidTriggerEvent(new BeatmapEventData(0, BeatmapEventType.Event4, 1, 1));
controller.TriggerBeatmapEvent(new BasicBeatmapEventData(0, BasicBeatmapEventType.Event0, 1, 1));
controller.TriggerBeatmapEvent(new BasicBeatmapEventData(0, BasicBeatmapEventType.Event4, 1, 1));

ForceColorOnInit.enable = false;

Expand Down Expand Up @@ -136,7 +141,7 @@ public static IEnumerator Init() {
staticPositionBackup = new Vector3[staticRotationBackup.Length];

// We need to wait one more frame for these to be in the positions they should be
yield return 0;
yield return null;

fixedPositionThings = _fixedPositionThings;
staticRotations = _fixedPositionThings.Select(x => x.rotation).ToArray();
Expand Down
50 changes: 24 additions & 26 deletions HarmonyPatches/FilterBeatmapLightEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,41 @@ static void Postfix(ref IReadonlyBeatmapData __result) {
return;

if(Config.Instance.disableBackLasers || Config.Instance.disableCenterLights || Config.Instance.disableRingLights || Config.Instance.disableRotatingLasers) {
var x = (List<BeatmapEventData>)__result.beatmapEventsData;

for(var i = x.Count; i-- > 0;) {
/*
* Break affects the switchcase and removes the event
* Continue is for the For loop and leaves the event
*/
switch(x[i].type) {
case BeatmapEventType.Event0:
if(!Config.Instance.disableBackLasers) continue;
__result.GetFilteredCopy(x => {
if(!(x is BasicBeatmapEventData bbed))
return x;

switch(bbed.basicBeatmapEventType) {
case BasicBeatmapEventType.Event0:
if(Config.Instance.disableBackLasers) return null;
break;
case BeatmapEventType.Event1:
if(!Config.Instance.disableBackLasers) continue;
case BasicBeatmapEventType.Event1:
if(Config.Instance.disableBackLasers) return null;
break;
case BeatmapEventType.Event2:
case BeatmapEventType.Event3:
case BeatmapEventType.Event12:
case BeatmapEventType.Event13:
if(!Config.Instance.disableRotatingLasers) continue;
case BasicBeatmapEventType.Event2:
case BasicBeatmapEventType.Event3:
case BasicBeatmapEventType.Event12:
case BasicBeatmapEventType.Event13:
if(Config.Instance.disableRotatingLasers) return null;
break;
case BeatmapEventType.Event4:
if(!Config.Instance.disableCenterLights) continue;
case BasicBeatmapEventType.Event4:
if(Config.Instance.disableCenterLights) return null;
break;
default:
continue;
}
x.RemoveAt(i);
}
return x;
});
}

endedUpWithAnyLights = false;

if(Config.Instance.staticWhenNoLights) {
foreach(var beatmapEventData in __result.beatmapEventsData) {
var lType = (int)beatmapEventData.type;
foreach(var x in __result.allBeatmapDataItems) {
if(!(x is BasicBeatmapEventData bbed))
continue;

var lType = (int)bbed.basicBeatmapEventType;

if(lType >= 0 && lType < 8 && (beatmapEventData.value > 0 || beatmapEventData.floatValue > 0)) {
if(lType >= 0 && lType < 8 && (bbed.value > 0 || bbed.floatValue > 0)) {
endedUpWithAnyLights = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions LightAdapters/LightmapLightsWithIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class UnifiedLightmapLightsWithIds : ILightAdapter {
LightmapLightsWithIds t;

// Why is this private? Whats the getter for?!
FieldAccessor<LightmapLightsWithIds, LightmapLightsWithIds.LightIntensitiesData[]>.Accessor FIELD_lightIntensityData =
FieldAccessor<LightmapLightsWithIds, LightmapLightsWithIds.LightIntensitiesData[]>.GetAccessor("_lightIntensityData");
FieldAccessor<LightmapLightsWithIds, LightmapLightsWithIds.LightIntensitiesWithId[]>.Accessor FIELD_lightIntensityData =
FieldAccessor<LightmapLightsWithIds, LightmapLightsWithIds.LightIntensitiesWithId[]>.GetAccessor("_lightIntensityData");

Action<LightmapLightsWithIds> METHOD_HandleLightManagerDidChangeSomeColorsThisFrame =
MethodAccessor<LightmapLightsWithIds, Action<LightmapLightsWithIds>>.GetDelegate("HandleLightManagerDidChangeSomeColorsThisFrame");
MethodAccessor<LightWithIds, Action<LightWithIds>>.GetDelegate("HandleLightManagerDidChangeSomeColorsThisFrame");

LightmapLightsWithIds.LightIntensitiesData[] _lightIntensityData;
LightmapLightsWithIds.LightIntensitiesWithId[] _lightIntensityData;
Color[] backupColors;

public UnifiedLightmapLightsWithIds(LightmapLightsWithIds t) {
Expand Down
2 changes: 1 addition & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void SceneManager_activeSceneChanged(Scene arg0, Scene arg1) {

[OnExit]
public void OnApplicationQuit() {
harmony.UnpatchAll(harmony.Id);
harmony.UnpatchSelf();
}
}
}
5 changes: 2 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/bsmg/BSIPA-MetadataFileSchema/master/Schema.json",
"id": "ImBlindedByTheLights",
"name": "ImBlindedByTheLights",
"author": "Kinsi55",
"version": "0.0.4",
"version": "0.0.5",
"description": "Allows you to have Static Lights in VR while keeping the normal Lightshow on the Desktop",
"gameVersion": "1.17.0",
"gameVersion": "1.20.0",
"dependsOn": {
"BSIPA": "^4.0.5",
"BeatSaberMarkupLanguage": "^1.5.5"
Expand Down

0 comments on commit 3a15bca

Please sign in to comment.