|
5 | 5 |
|
6 | 6 | namespace Celeste.Mod.MaxHelpingHand.Effects {
|
7 | 7 | public class SnowCustomColors : Snow {
|
8 |
| - private static MethodInfo particleInit = typeof(Snow).GetNestedType("Particle", BindingFlags.NonPublic).GetMethod("Init"); |
| 8 | + private static readonly Type particleType = typeof(Snow).GetNestedType("Particle", BindingFlags.NonPublic); |
| 9 | + private static readonly MethodInfo particleInit = particleType.GetMethod("Init"); |
9 | 10 |
|
10 |
| - public SnowCustomColors(Color[] colors, float speedMin, float speedMax) : base(false) { |
11 |
| - DynData<Snow> selfData = new DynData<Snow>(this); |
| 11 | + public SnowCustomColors(Color[] colors, float speedMin, float speedMax, int particleCount) : base(false) { |
| 12 | + var selfData = new DynData<Snow>(this); |
12 | 13 |
|
13 | 14 | // redo the same operations as the vanilla constructor, but with our custom set of colors.
|
14 | 15 | selfData["colors"] = colors;
|
15 | 16 | selfData["blendedColors"] = new Color[colors.Length];
|
16 |
| - Array particles = selfData.Get<Array>("particles"); |
| 17 | + |
| 18 | + // recreate the particles array with the correct length |
| 19 | + var particles = Array.CreateInstance(particleType, particleCount); |
| 20 | + selfData["particles"] = particles; |
| 21 | + |
17 | 22 | for (int i = 0; i < particles.Length; i++) {
|
18 | 23 | // Particle is a private struct, so getting it gets a copy that we should set back afterwards.
|
19 |
| - object particle = particles.GetValue(i); |
20 |
| - particleInit.Invoke(particle, new object[] { colors.Length, speedMin, speedMax }); |
| 24 | + var particle = particles.GetValue(i); |
| 25 | + particleInit.Invoke(particle, [colors.Length, speedMin, speedMax]); |
21 | 26 | particles.SetValue(particle, i);
|
22 | 27 | }
|
23 | 28 | }
|
|
0 commit comments