Skip to content

Commit

Permalink
Null check whenever reading gameplay width or height
Browse files Browse the repository at this point in the history
  • Loading branch information
maddie480 authored Nov 7, 2024
1 parent 50a7087 commit a935a88
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 39 deletions.
7 changes: 4 additions & 3 deletions Effects/AllSideTentacles.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Mono.Cecil.Cil;
using Monocle;
using MonoMod.Cil;
Expand Down Expand Up @@ -37,9 +38,9 @@ private static void modTentaclesUpdate(ILContext il) {

if (player != null) {
if (allSideSelf.side == Side.Left) {
return (player.X - camera.X) - (GameplayBuffers.Gameplay.Width / 2f);
return (player.X - camera.X) - (MaxHelpingHandModule.GameplayWidth / 2f);
} else if (allSideSelf.side == Side.Top) {
return player.Y - camera.Y - GameplayBuffers.Gameplay.Height;
return player.Y - camera.Y - MaxHelpingHandModule.GameplayHeight;
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions Effects/CustomStars.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Monocle;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -62,7 +63,7 @@ public CustomStars(int? starCount, Color? tint, string spriteDirectory, float wr
stars = new Star[starCount ?? 100];
for (int i = 0; i < stars.Length; i++) {
stars[i] = new Star {
Position = new Vector2(Calc.Random.NextFloat(GameplayBuffers.Gameplay.Width), Calc.Random.NextFloat(wrapHeight)),
Position = new Vector2(Calc.Random.NextFloat(MaxHelpingHandModule.GameplayWidth), Calc.Random.NextFloat(wrapHeight)),
Timer = Calc.Random.NextFloat((float) Math.PI * 2f),
Rate = 2f + Calc.Random.NextFloat(2f),
TextureSet = Calc.Random.Next(textures.Count)
Expand Down Expand Up @@ -90,7 +91,7 @@ public override void Update(Scene scene) {
public override void Render(Scene scene) {
float fadeAlpha = GetFadeAlpha(scene);

Draw.Rect(0f, 0f, GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height, Color.Black * bgAlpha);
Draw.Rect(0f, 0f, MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight, Color.Black * bgAlpha);
Level level = scene as Level;
Color color = (tint * (starAlpha ?? 1f)) ?? (level.Session.Dreaming ? Color.Teal * (starAlpha ?? 0.7f) : Color.White);
int count = starCount ?? (level.Session.Dreaming ? 100 : 50);
Expand All @@ -105,9 +106,9 @@ public override void Render(Scene scene) {

// parallax X
position.X -= level.Camera.X * effectiveScroll.X;
position.X %= GameplayBuffers.Gameplay.Width;
position.X %= MaxHelpingHandModule.GameplayWidth;
if (position.X < 0f) {
position.X += GameplayBuffers.Gameplay.Width;
position.X += MaxHelpingHandModule.GameplayWidth;
}

// parallax Y
Expand All @@ -117,7 +118,7 @@ public override void Render(Scene scene) {
if (position.Y < 0f) {
position.Y += wrapHeight;
}
position.Y -= (wrapHeight - GameplayBuffers.Gameplay.Height) / 2;
position.Y -= (wrapHeight - MaxHelpingHandModule.GameplayHeight) / 2;

if (level.Session.Dreaming) {
for (int j = 0; j < colors.Length; j++) {
Expand Down
16 changes: 8 additions & 8 deletions Entities/CustomizableGlassBlockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,16 @@ public override void Awake(Scene scene) {
// initialize stars and rays from scratch like vanilla does.
List<MTexture> starTextures = GFX.Game.GetAtlasSubtextures("particles/stars/");
for (int i = 0; i < stars.Length; i++) {
stars[i].Position.X = Calc.Random.Next(GameplayBuffers.Gameplay.Width);
stars[i].Position.Y = Calc.Random.Next(GameplayBuffers.Gameplay.Height);
stars[i].Position.X = Calc.Random.Next(MaxHelpingHandModule.GameplayWidth);
stars[i].Position.Y = Calc.Random.Next(MaxHelpingHandModule.GameplayHeight);
stars[i].Texture = Calc.Random.Choose(starTextures);
stars[i].Color = Calc.Random.Choose(starColors);
stars[i].Scroll = Vector2.One * Calc.Random.NextFloat(0.05f);
}

for (int j = 0; j < rays.Length; j++) {
rays[j].Position.X = Calc.Random.Next(GameplayBuffers.Gameplay.Width);
rays[j].Position.Y = Calc.Random.Next(GameplayBuffers.Gameplay.Height);
rays[j].Position.X = Calc.Random.Next(MaxHelpingHandModule.GameplayWidth);
rays[j].Position.Y = Calc.Random.Next(MaxHelpingHandModule.GameplayHeight);
rays[j].Width = Calc.Random.Range(4f, 16f);
rays[j].Length = Calc.Random.Choose(48, 96, 128);
rays[j].Color = Color.White * Calc.Random.Range(0.2f, 0.4f);
Expand All @@ -156,9 +156,9 @@ public override void Awake(Scene scene) {
}

private void ensureBufferIsCorrect() {
if (starsTarget == null || starsTarget.Width != GameplayBuffers.Gameplay.Width || starsTarget.Height != GameplayBuffers.Gameplay.Height) {
if (starsTarget == null || starsTarget.Width != MaxHelpingHandModule.GameplayWidth || starsTarget.Height != MaxHelpingHandModule.GameplayHeight) {
starsTarget?.Dispose();
starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height);
starsTarget = VirtualContent.CreateRenderTarget("customizable-glass-block-surfaces", MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
}
}

Expand All @@ -170,8 +170,8 @@ private void BeforeRender() {
}

Camera camera = (Scene as Level).Camera;
int screenWidth = GameplayBuffers.Gameplay.Width;
int screenHeight = GameplayBuffers.Gameplay.Height;
int screenWidth = MaxHelpingHandModule.GameplayWidth;
int screenHeight = MaxHelpingHandModule.GameplayHeight;

// draw stars
ensureBufferIsCorrect();
Expand Down
3 changes: 2 additions & 1 deletion Entities/FancyTextTutorial.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.RuntimeDetour;
Expand Down Expand Up @@ -90,7 +91,7 @@ public override void Render() {
Camera camera = SceneAs<Level>().Camera;
Vector2 drawPosition = Position - camera.Position.Floor();
if (SaveData.Instance != null && SaveData.Instance.Assists.MirrorMode) {
drawPosition.X = GameplayBuffers.Gameplay.Width - drawPosition.X;
drawPosition.X = MaxHelpingHandModule.GameplayWidth - drawPosition.X;
}
drawPosition *= 6f;

Expand Down
3 changes: 2 additions & 1 deletion Entities/FlagSwitchGate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Monocle;
Expand Down Expand Up @@ -172,7 +173,7 @@ public override void Awake(Scene scene) {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool InView() {
Camera camera = (Scene as Level).Camera;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + GameplayBuffers.Gameplay.Width && Position.Y < camera.Y + GameplayBuffers.Gameplay.Height;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + MaxHelpingHandModule.GameplayWidth && Position.Y < camera.Y + MaxHelpingHandModule.GameplayHeight;
}

public override void Render() {
Expand Down
3 changes: 2 additions & 1 deletion Entities/MultiNodeFlagSwitchGate.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Celeste;
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Monocle;
Expand Down Expand Up @@ -161,7 +162,7 @@ public override void Awake(Scene scene) {
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool InView() {
Camera camera = (Scene as Level).Camera;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + GameplayBuffers.Gameplay.Width && Position.Y < camera.Y + GameplayBuffers.Gameplay.Height;
return Position.X + Width > camera.X - 16f && Position.Y + Height > camera.Y - 16f && Position.X < camera.X + MaxHelpingHandModule.GameplayWidth && Position.Y < camera.Y + MaxHelpingHandModule.GameplayHeight;
}

public override void Render() {
Expand Down
4 changes: 2 additions & 2 deletions Entities/SeekerBarrierColorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ internal static bool HasControllerOnNextScreen() {
}

private void ensureBufferIsCorrect() {
if (levelRenderTarget == null || levelRenderTarget.Width != GameplayBuffers.Gameplay.Width || levelRenderTarget.Height != GameplayBuffers.Gameplay.Height) {
if (levelRenderTarget == null || levelRenderTarget.Width != MaxHelpingHandModule.GameplayWidth || levelRenderTarget.Height != MaxHelpingHandModule.GameplayHeight) {
levelRenderTarget?.Dispose();
levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + entityID, GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height);
levelRenderTarget = VirtualContent.CreateRenderTarget("helping-hand-seeker-barrier-color-controller-" + entityID, MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
}
}

Expand Down
17 changes: 9 additions & 8 deletions Entities/SidewaysLava.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Celeste.Mod.MaxHelpingHand.Triggers;
using Microsoft.Xna.Framework;
using Monocle;
Expand Down Expand Up @@ -82,13 +83,13 @@ public SidewaysLava(EntityData data, Vector2 offset) {

if (lavaMode == LavaMode.LeftToRight) {
// one hitbox on the left.
Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, -GameplayBuffers.Gameplay.Height - 20f);
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, -MaxHelpingHandModule.GameplayHeight - 20f);
} else if (lavaMode == LavaMode.RightToLeft) {
// one hitbox on the right.
Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, GameplayBuffers.Gameplay.Width);
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, MaxHelpingHandModule.GameplayWidth);
} else {
// hitboxes on both sides, 280px apart.
Collider = new ColliderList(new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, -GameplayBuffers.Gameplay.Width - 20f), new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, GameplayBuffers.Gameplay.Width - 40f));
Collider = new ColliderList(new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, -MaxHelpingHandModule.GameplayWidth - 20f), new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, MaxHelpingHandModule.GameplayWidth - 40f));
}

Visible = false;
Expand All @@ -97,7 +98,7 @@ public SidewaysLava(EntityData data, Vector2 offset) {
Add(loopSfx = new SoundSource());

// lava can travel at up to 40 px/s * speedMultiplier, and we want it to extend enough so that you don't see it scrolling past the screen.
float lavaWidth = GameplayBuffers.Gameplay.Width + speedMultiplier * 80f;
float lavaWidth = MaxHelpingHandModule.GameplayWidth + speedMultiplier * 80f;

if (lavaMode != LavaMode.RightToLeft) {
// add the left lava rect, just off-screen (it is 340px wide)
Expand All @@ -108,7 +109,7 @@ public SidewaysLava(EntityData data, Vector2 offset) {
if (lavaMode != LavaMode.LeftToRight) {
// add the right lava rect, just off-screen (the screen is 320px wide)
Add(rightRect = new SidewaysLavaRect(lavaWidth, 200f, 4, SidewaysLavaRect.OnlyModes.OnlyRight));
rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? GameplayBuffers.Gameplay.Width - 40f : GameplayBuffers.Gameplay.Width, 0f);
rightRect.Position = new Vector2(lavaMode == LavaMode.Sandwich ? MaxHelpingHandModule.GameplayWidth - 40f : MaxHelpingHandModule.GameplayWidth, 0f);
rightRect.SmallWaveAmplitude = 2f;
}

Expand Down Expand Up @@ -174,9 +175,9 @@ public override void Added(Scene scene) {

} else if (lavaMode == LavaMode.RightToLeft) {
// same, except the lava is offset by 320px. That gives Right - 320 + 16.
X = SceneAs<Level>().Bounds.Right - GameplayBuffers.Gameplay.Width + 16;
X = SceneAs<Level>().Bounds.Right - MaxHelpingHandModule.GameplayWidth + 16;
// sound comes from the right side.
loopSfx.Position = new Vector2(GameplayBuffers.Gameplay.Width, Height / 2f);
loopSfx.Position = new Vector2(MaxHelpingHandModule.GameplayWidth, Height / 2f);

} else {
// the position should be set on the first Update call, in case the level starts with a room with lava in it
Expand Down Expand Up @@ -320,7 +321,7 @@ public override void Update() {
target = player.X - 32f;
} else {
// stop 32px to the right of the player. since lava is offset by 320px, that gives 320 - 32.
target = player.X - GameplayBuffers.Gameplay.Width + 32;
target = player.X - MaxHelpingHandModule.GameplayWidth + 32;
}

if (!intro && player != null && player.JustRespawned && !player.CollideCheck<InstantLavaBlockerTrigger>()) {
Expand Down
5 changes: 3 additions & 2 deletions Entities/StylegroundFadeController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Mono.Cecil.Cil;
Expand Down Expand Up @@ -81,9 +82,9 @@ public override void SceneEnd(Scene scene) {
}

private static void ensureBufferIsCorrect() {
if (tempRenderTarget == null || tempRenderTarget.Width != GameplayBuffers.Gameplay.Width || tempRenderTarget.Height != GameplayBuffers.Gameplay.Height) {
if (tempRenderTarget == null || tempRenderTarget.Width != MaxHelpingHandModule.GameplayWidth || tempRenderTarget.Height != MaxHelpingHandModule.GameplayHeight) {
tempRenderTarget?.Dispose();
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height);
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
}
}

Expand Down
4 changes: 4 additions & 0 deletions Module/MaxHelpingHandModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class MaxHelpingHandModule : EverestModule {
public override Type SessionType => typeof(MaxHelpingHandSession);
public MaxHelpingHandSession Session => (MaxHelpingHandSession) _Session;

// size of the screen, taking zooming out into account (Extended Camera Dynamics mod)
public static int GameplayWidth => GameplayBuffers.Gameplay?.Width ?? 320;
public static int GameplayHeight => GameplayBuffers.Gameplay?.Height ?? 180;

private static Hook modRegister = null;

public MaxHelpingHandModule() {
Expand Down
2 changes: 1 addition & 1 deletion Triggers/GradientDustTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static void onDustEdgesBeforeRender(On.Celeste.DustEdges.orig_BeforeRend
// draw our image in ""substractive"" mode over the resort dust layer.
float shift = (Engine.Scene.TimeActive * speed) % image.Width;
Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, substractive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity);
for (float offset = -shift; offset < GameplayBuffers.Gameplay.Width; offset += image.Width) {
for (float offset = -shift; offset < MaxHelpingHandModule.GameplayWidth; offset += image.Width) {
Draw.SpriteBatch.Draw(image.Texture.Texture, new Vector2(offset, 0), Color.White);
}
Draw.SpriteBatch.End();
Expand Down
13 changes: 7 additions & 6 deletions Triggers/OneWayCameraTrigger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Celeste.Mod.Entities;
using Celeste.Mod.MaxHelpingHand.Module;
using Microsoft.Xna.Framework;
using Monocle;
using MonoMod.Cil;
Expand Down Expand Up @@ -51,16 +52,16 @@ public override void OnEnter(Player player) {
if (blockPlayer) {
Level level = SceneAs<Level>();
if (!left) {
Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, GameplayBuffers.Gameplay.Height));
Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, MaxHelpingHandModule.GameplayHeight));
}
if (!right) {
Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width, 8, GameplayBuffers.Gameplay.Height));
Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * MaxHelpingHandModule.GameplayWidth, 8, MaxHelpingHandModule.GameplayHeight));
}
if (!up) {
Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, GameplayBuffers.Gameplay.Width, 8));
Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, MaxHelpingHandModule.GameplayWidth, 8));
}
if (!down) {
Scene.Add(lowerBound = new Killbox(new EntityData { Width = GameplayBuffers.Gameplay.Width }, level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6)));
Scene.Add(lowerBound = new Killbox(new EntityData { Width = MaxHelpingHandModule.GameplayWidth }, level.Camera.Position + Vector2.UnitY * (MaxHelpingHandModule.GameplayHeight + 6)));
}
}
}
Expand Down Expand Up @@ -88,13 +89,13 @@ public override void OnStay(Player player) {
leftBound.Position = level.Camera.Position - Vector2.UnitX * 9;
}
if (rightBound != null) {
rightBound.Position = level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width;
rightBound.Position = level.Camera.Position + Vector2.UnitX * MaxHelpingHandModule.GameplayWidth;
}
if (upperBound != null) {
upperBound.Position = level.Camera.Position - Vector2.UnitY * 9;
}
if (lowerBound != null) {
lowerBound.Position = level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6f);
lowerBound.Position = level.Camera.Position + Vector2.UnitY * (MaxHelpingHandModule.GameplayHeight + 6f);
}
}

Expand Down

0 comments on commit a935a88

Please sign in to comment.