Acessing private BasePlayer.firedProjectiles?Solved

Hi Guys,

Can anyone help with working code to access a private Dictionary firedProjectiles in the BasePlayer class using reflections? I need to get the initialPosition and initialVelocity values of the projectile. I tried to get at least some private data using the code from the link https://oxidemod.org/threads/noobguide-using-reflections-to-access-private-fields-of-an-object-c.28730/, but without success. The code returns an error (NullReferenceException: Object reference not set to an instance of an object).

private object OnPlayerLand(BasePlayer player)
		{
			PlayerLifeStory lifeStory = typeof(BasePlayer).GetField("lifeStory", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(player) as PlayerLifeStory;
			if(lifeStory.secondsAlive< 3)
			{
				Puts("Player has been alive for more than 3 seconds");
			}
			return null;
		}

Thank you in advance

BasePlayer.lifeStory is public, not private; no reflection necessary. BasePlayer.firedProjectiles can probably be made public too.

For now, using reflection (won't be possible eventually):
typeof(BasePlayer).GetField("firedProjectiles", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(player);
Thanks for the quick response, Wulf.

Can BasePlayer.firedProjectiles(and private struct FiredProjectile) be made public in the next uMod update? This will help me a lot.
Yes, it will be available today.
Thanks! 

But, it seems like it is still private for me in latest umod download.

Missed the commit in master, check back in about 2 minutes and it'll be fixed.

Edit: Might be a little more than 2 minutes.

Edit 2: Available now.
Now, I have another problem.I can't get the initialPosition and initialVelocity values from BasePlayer.firedProjectiles. I think this is because the struct BasePlayer.FiredProjectile is private. Can it be made public too?

error CS1061: Type `BasePlayer.FiredProjectile' does not contain a definition for `initialVelocity' and no extension method `initialVelocity' of type `BasePlayer.FiredProjectile' could be found. Are you missing an assembly reference?


		void OnPlayerAttack(BasePlayer attacker, HitInfo info)
        {
			if (attacker.HasFiredProjectile(info.ProjectileID))
			{
				Puts($"ProjectileID: {info.ProjectileID}, initialPosition: {init.firedProjectiles[attacker.ProjectileID].initialPosition}, initialVelocity: {attacker.firedProjectiles[info.ProjectileID].initialVelocity}");
			}
		}

Yes, it can be as well. :p
In the next uMod update?Or can this be added now in the development version?
The development build has it.
Locked automatically