Skip to content

Commit a935a88

Browse files
authored
Null check whenever reading gameplay width or height
1 parent 50a7087 commit a935a88

12 files changed

+51
-39
lines changed

Effects/AllSideTentacles.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Xna.Framework;
1+
using Celeste.Mod.MaxHelpingHand.Module;
2+
using Microsoft.Xna.Framework;
23
using Mono.Cecil.Cil;
34
using Monocle;
45
using MonoMod.Cil;
@@ -37,9 +38,9 @@ private static void modTentaclesUpdate(ILContext il) {
3738

3839
if (player != null) {
3940
if (allSideSelf.side == Side.Left) {
40-
return (player.X - camera.X) - (GameplayBuffers.Gameplay.Width / 2f);
41+
return (player.X - camera.X) - (MaxHelpingHandModule.GameplayWidth / 2f);
4142
} else if (allSideSelf.side == Side.Top) {
42-
return player.Y - camera.Y - GameplayBuffers.Gameplay.Height;
43+
return player.Y - camera.Y - MaxHelpingHandModule.GameplayHeight;
4344
}
4445
}
4546
}

Effects/CustomStars.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Xna.Framework;
1+
using Celeste.Mod.MaxHelpingHand.Module;
2+
using Microsoft.Xna.Framework;
23
using Monocle;
34
using System;
45
using System.Collections.Generic;
@@ -62,7 +63,7 @@ public CustomStars(int? starCount, Color? tint, string spriteDirectory, float wr
6263
stars = new Star[starCount ?? 100];
6364
for (int i = 0; i < stars.Length; i++) {
6465
stars[i] = new Star {
65-
Position = new Vector2(Calc.Random.NextFloat(GameplayBuffers.Gameplay.Width), Calc.Random.NextFloat(wrapHeight)),
66+
Position = new Vector2(Calc.Random.NextFloat(MaxHelpingHandModule.GameplayWidth), Calc.Random.NextFloat(wrapHeight)),
6667
Timer = Calc.Random.NextFloat((float) Math.PI * 2f),
6768
Rate = 2f + Calc.Random.NextFloat(2f),
6869
TextureSet = Calc.Random.Next(textures.Count)
@@ -90,7 +91,7 @@ public override void Update(Scene scene) {
9091
public override void Render(Scene scene) {
9192
float fadeAlpha = GetFadeAlpha(scene);
9293

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

106107
// parallax X
107108
position.X -= level.Camera.X * effectiveScroll.X;
108-
position.X %= GameplayBuffers.Gameplay.Width;
109+
position.X %= MaxHelpingHandModule.GameplayWidth;
109110
if (position.X < 0f) {
110-
position.X += GameplayBuffers.Gameplay.Width;
111+
position.X += MaxHelpingHandModule.GameplayWidth;
111112
}
112113

113114
// parallax Y
@@ -117,7 +118,7 @@ public override void Render(Scene scene) {
117118
if (position.Y < 0f) {
118119
position.Y += wrapHeight;
119120
}
120-
position.Y -= (wrapHeight - GameplayBuffers.Gameplay.Height) / 2;
121+
position.Y -= (wrapHeight - MaxHelpingHandModule.GameplayHeight) / 2;
121122

122123
if (level.Session.Dreaming) {
123124
for (int j = 0; j < colors.Length; j++) {

Entities/CustomizableGlassBlockController.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ public override void Awake(Scene scene) {
138138
// initialize stars and rays from scratch like vanilla does.
139139
List<MTexture> starTextures = GFX.Game.GetAtlasSubtextures("particles/stars/");
140140
for (int i = 0; i < stars.Length; i++) {
141-
stars[i].Position.X = Calc.Random.Next(GameplayBuffers.Gameplay.Width);
142-
stars[i].Position.Y = Calc.Random.Next(GameplayBuffers.Gameplay.Height);
141+
stars[i].Position.X = Calc.Random.Next(MaxHelpingHandModule.GameplayWidth);
142+
stars[i].Position.Y = Calc.Random.Next(MaxHelpingHandModule.GameplayHeight);
143143
stars[i].Texture = Calc.Random.Choose(starTextures);
144144
stars[i].Color = Calc.Random.Choose(starColors);
145145
stars[i].Scroll = Vector2.One * Calc.Random.NextFloat(0.05f);
146146
}
147147

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

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

@@ -170,8 +170,8 @@ private void BeforeRender() {
170170
}
171171

172172
Camera camera = (Scene as Level).Camera;
173-
int screenWidth = GameplayBuffers.Gameplay.Width;
174-
int screenHeight = GameplayBuffers.Gameplay.Height;
173+
int screenWidth = MaxHelpingHandModule.GameplayWidth;
174+
int screenHeight = MaxHelpingHandModule.GameplayHeight;
175175

176176
// draw stars
177177
ensureBufferIsCorrect();

Entities/FancyTextTutorial.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.MaxHelpingHand.Module;
23
using Microsoft.Xna.Framework;
34
using Monocle;
45
using MonoMod.RuntimeDetour;
@@ -90,7 +91,7 @@ public override void Render() {
9091
Camera camera = SceneAs<Level>().Camera;
9192
Vector2 drawPosition = Position - camera.Position.Floor();
9293
if (SaveData.Instance != null && SaveData.Instance.Assists.MirrorMode) {
93-
drawPosition.X = GameplayBuffers.Gameplay.Width - drawPosition.X;
94+
drawPosition.X = MaxHelpingHandModule.GameplayWidth - drawPosition.X;
9495
}
9596
drawPosition *= 6f;
9697

Entities/FlagSwitchGate.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.MaxHelpingHand.Module;
23
using Microsoft.Xna.Framework;
34
using Microsoft.Xna.Framework.Graphics;
45
using Monocle;
@@ -172,7 +173,7 @@ public override void Awake(Scene scene) {
172173
[MethodImpl(MethodImplOptions.AggressiveInlining)]
173174
private bool InView() {
174175
Camera camera = (Scene as Level).Camera;
175-
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;
176+
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;
176177
}
177178

178179
public override void Render() {

Entities/MultiNodeFlagSwitchGate.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Celeste;
22
using Celeste.Mod.Entities;
3+
using Celeste.Mod.MaxHelpingHand.Module;
34
using Microsoft.Xna.Framework;
45
using Microsoft.Xna.Framework.Graphics;
56
using Monocle;
@@ -161,7 +162,7 @@ public override void Awake(Scene scene) {
161162
[MethodImpl(MethodImplOptions.AggressiveInlining)]
162163
private bool InView() {
163164
Camera camera = (Scene as Level).Camera;
164-
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;
165+
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;
165166
}
166167

167168
public override void Render() {

Entities/SeekerBarrierColorController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ internal static bool HasControllerOnNextScreen() {
9595
}
9696

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

Entities/SidewaysLava.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.MaxHelpingHand.Module;
23
using Celeste.Mod.MaxHelpingHand.Triggers;
34
using Microsoft.Xna.Framework;
45
using Monocle;
@@ -82,13 +83,13 @@ public SidewaysLava(EntityData data, Vector2 offset) {
8283

8384
if (lavaMode == LavaMode.LeftToRight) {
8485
// one hitbox on the left.
85-
Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, -GameplayBuffers.Gameplay.Height - 20f);
86+
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, -MaxHelpingHandModule.GameplayHeight - 20f);
8687
} else if (lavaMode == LavaMode.RightToLeft) {
8788
// one hitbox on the right.
88-
Collider = new Hitbox(GameplayBuffers.Gameplay.Width + 20f, GameplayBuffers.Gameplay.Height + 20f, GameplayBuffers.Gameplay.Width);
89+
Collider = new Hitbox(MaxHelpingHandModule.GameplayWidth + 20f, MaxHelpingHandModule.GameplayHeight + 20f, MaxHelpingHandModule.GameplayWidth);
8990
} else {
9091
// hitboxes on both sides, 280px apart.
91-
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));
92+
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));
9293
}
9394

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

99100
// 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.
100-
float lavaWidth = GameplayBuffers.Gameplay.Width + speedMultiplier * 80f;
101+
float lavaWidth = MaxHelpingHandModule.GameplayWidth + speedMultiplier * 80f;
101102

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

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

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

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

326327
if (!intro && player != null && player.JustRespawned && !player.CollideCheck<InstantLavaBlockerTrigger>()) {

Entities/StylegroundFadeController.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.MaxHelpingHand.Module;
23
using Microsoft.Xna.Framework;
34
using Microsoft.Xna.Framework.Graphics;
45
using Mono.Cecil.Cil;
@@ -81,9 +82,9 @@ public override void SceneEnd(Scene scene) {
8182
}
8283

8384
private static void ensureBufferIsCorrect() {
84-
if (tempRenderTarget == null || tempRenderTarget.Width != GameplayBuffers.Gameplay.Width || tempRenderTarget.Height != GameplayBuffers.Gameplay.Height) {
85+
if (tempRenderTarget == null || tempRenderTarget.Width != MaxHelpingHandModule.GameplayWidth || tempRenderTarget.Height != MaxHelpingHandModule.GameplayHeight) {
8586
tempRenderTarget?.Dispose();
86-
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", GameplayBuffers.Gameplay.Width, GameplayBuffers.Gameplay.Height);
87+
tempRenderTarget = VirtualContent.CreateRenderTarget("max-helping-hand-styleground-fade-controller", MaxHelpingHandModule.GameplayWidth, MaxHelpingHandModule.GameplayHeight);
8788
}
8889
}
8990

Module/MaxHelpingHandModule.cs

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public class MaxHelpingHandModule : EverestModule {
2727
public override Type SessionType => typeof(MaxHelpingHandSession);
2828
public MaxHelpingHandSession Session => (MaxHelpingHandSession) _Session;
2929

30+
// size of the screen, taking zooming out into account (Extended Camera Dynamics mod)
31+
public static int GameplayWidth => GameplayBuffers.Gameplay?.Width ?? 320;
32+
public static int GameplayHeight => GameplayBuffers.Gameplay?.Height ?? 180;
33+
3034
private static Hook modRegister = null;
3135

3236
public MaxHelpingHandModule() {

Triggers/GradientDustTrigger.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private static void onDustEdgesBeforeRender(On.Celeste.DustEdges.orig_BeforeRend
142142
// draw our image in ""substractive"" mode over the resort dust layer.
143143
float shift = (Engine.Scene.TimeActive * speed) % image.Width;
144144
Draw.SpriteBatch.Begin(SpriteSortMode.Deferred, substractive, SamplerState.PointClamp, DepthStencilState.None, RasterizerState.CullNone, null, Matrix.Identity);
145-
for (float offset = -shift; offset < GameplayBuffers.Gameplay.Width; offset += image.Width) {
145+
for (float offset = -shift; offset < MaxHelpingHandModule.GameplayWidth; offset += image.Width) {
146146
Draw.SpriteBatch.Draw(image.Texture.Texture, new Vector2(offset, 0), Color.White);
147147
}
148148
Draw.SpriteBatch.End();

Triggers/OneWayCameraTrigger.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Celeste.Mod.Entities;
2+
using Celeste.Mod.MaxHelpingHand.Module;
23
using Microsoft.Xna.Framework;
34
using Monocle;
45
using MonoMod.Cil;
@@ -51,16 +52,16 @@ public override void OnEnter(Player player) {
5152
if (blockPlayer) {
5253
Level level = SceneAs<Level>();
5354
if (!left) {
54-
Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, GameplayBuffers.Gameplay.Height));
55+
Scene.Add(leftBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitX * 9, 8, MaxHelpingHandModule.GameplayHeight));
5556
}
5657
if (!right) {
57-
Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width, 8, GameplayBuffers.Gameplay.Height));
58+
Scene.Add(rightBound = new InvisibleBarrier(level.Camera.Position + Vector2.UnitX * MaxHelpingHandModule.GameplayWidth, 8, MaxHelpingHandModule.GameplayHeight));
5859
}
5960
if (!up) {
60-
Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, GameplayBuffers.Gameplay.Width, 8));
61+
Scene.Add(upperBound = new InvisibleBarrier(level.Camera.Position - Vector2.UnitY * 9, MaxHelpingHandModule.GameplayWidth, 8));
6162
}
6263
if (!down) {
63-
Scene.Add(lowerBound = new Killbox(new EntityData { Width = GameplayBuffers.Gameplay.Width }, level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6)));
64+
Scene.Add(lowerBound = new Killbox(new EntityData { Width = MaxHelpingHandModule.GameplayWidth }, level.Camera.Position + Vector2.UnitY * (MaxHelpingHandModule.GameplayHeight + 6)));
6465
}
6566
}
6667
}
@@ -88,13 +89,13 @@ public override void OnStay(Player player) {
8889
leftBound.Position = level.Camera.Position - Vector2.UnitX * 9;
8990
}
9091
if (rightBound != null) {
91-
rightBound.Position = level.Camera.Position + Vector2.UnitX * GameplayBuffers.Gameplay.Width;
92+
rightBound.Position = level.Camera.Position + Vector2.UnitX * MaxHelpingHandModule.GameplayWidth;
9293
}
9394
if (upperBound != null) {
9495
upperBound.Position = level.Camera.Position - Vector2.UnitY * 9;
9596
}
9697
if (lowerBound != null) {
97-
lowerBound.Position = level.Camera.Position + Vector2.UnitY * (GameplayBuffers.Gameplay.Height + 6f);
98+
lowerBound.Position = level.Camera.Position + Vector2.UnitY * (MaxHelpingHandModule.GameplayHeight + 6f);
9899
}
99100
}
100101

0 commit comments

Comments
 (0)