Add some basic safeguards around RenderPlayer.set.
This commit is contained in:
@@ -68,6 +68,20 @@ namespace OpenRA
|
|||||||
public Shroud Shroud;
|
public Shroud Shroud;
|
||||||
public World World { get; private set; }
|
public World World { get; private set; }
|
||||||
|
|
||||||
|
readonly bool inMissionMap;
|
||||||
|
readonly IUnlocksRenderPlayer[] unlockRenderPlayer;
|
||||||
|
|
||||||
|
public bool UnlockedRenderPlayer
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (unlockRenderPlayer.Any(x => x.RenderPlayerUnlocked))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return WinState != WinState.Undefined && !inMissionMap;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readonly StanceColors stanceColors;
|
readonly StanceColors stanceColors;
|
||||||
|
|
||||||
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
|
static FactionInfo ChooseFaction(World world, string name, bool requireSelectable = true)
|
||||||
@@ -105,6 +119,8 @@ namespace OpenRA
|
|||||||
InternalName = pr.Name;
|
InternalName = pr.Name;
|
||||||
PlayerReference = pr;
|
PlayerReference = pr;
|
||||||
|
|
||||||
|
inMissionMap = world.Map.Visibility.HasFlag(MapVisibility.MissionSelector);
|
||||||
|
|
||||||
// Real player or host-created bot
|
// Real player or host-created bot
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
@@ -156,6 +172,8 @@ namespace OpenRA
|
|||||||
stanceColors.Allies = ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
|
stanceColors.Allies = ChromeMetrics.Get<Color>("PlayerStanceColorAllies");
|
||||||
stanceColors.Enemies = ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
|
stanceColors.Enemies = ChromeMetrics.Get<Color>("PlayerStanceColorEnemies");
|
||||||
stanceColors.Neutrals = ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
|
stanceColors.Neutrals = ChromeMetrics.Get<Color>("PlayerStanceColorNeutrals");
|
||||||
|
|
||||||
|
unlockRenderPlayer = PlayerActor.TraitsImplementing<IUnlocksRenderPlayer>().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|||||||
@@ -467,4 +467,7 @@ namespace OpenRA.Traits
|
|||||||
return playerName + " " + BoolValues[newValue] + " " + Name + ".";
|
return playerName + " " + BoolValues[newValue] + " " + Name + ".";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface IUnlocksRenderPlayer { bool RenderPlayerUnlocked { get; } }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,16 @@ namespace OpenRA
|
|||||||
Player renderPlayer;
|
Player renderPlayer;
|
||||||
public Player RenderPlayer
|
public Player RenderPlayer
|
||||||
{
|
{
|
||||||
get { return renderPlayer == null || (renderPlayer.WinState != WinState.Undefined && !Map.Visibility.HasFlag(MapVisibility.MissionSelector)) ? null : renderPlayer; }
|
get
|
||||||
set { renderPlayer = value; }
|
{
|
||||||
|
return renderPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (LocalPlayer == null || LocalPlayer.UnlockedRenderPlayer)
|
||||||
|
renderPlayer = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FogObscures(Actor a) { return RenderPlayer != null && !a.CanBeViewedByPlayer(RenderPlayer); }
|
public bool FogObscures(Actor a) { return RenderPlayer != null && !a.CanBeViewedByPlayer(RenderPlayer); }
|
||||||
@@ -101,7 +109,9 @@ namespace OpenRA
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
LocalPlayer = localPlayer;
|
LocalPlayer = localPlayer;
|
||||||
RenderPlayer = LocalPlayer;
|
|
||||||
|
// Set the property backing field directly
|
||||||
|
renderPlayer = LocalPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly Actor WorldActor;
|
public readonly Actor WorldActor;
|
||||||
@@ -412,6 +422,11 @@ namespace OpenRA
|
|||||||
// Hash the shared random number generator.
|
// Hash the shared random number generator.
|
||||||
ret += SharedRandom.Last;
|
ret += SharedRandom.Last;
|
||||||
|
|
||||||
|
// Hash player RenderPlayer status
|
||||||
|
foreach (var p in Players)
|
||||||
|
if (p.UnlockedRenderPlayer)
|
||||||
|
ret += Sync.HashPlayer(p);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
|
public object Create(ActorInitializer init) { return new DeveloperMode(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeveloperMode : IResolveOrder, ISync, INotifyCreated
|
public class DeveloperMode : IResolveOrder, ISync, INotifyCreated, IUnlocksRenderPlayer
|
||||||
{
|
{
|
||||||
readonly DeveloperModeInfo info;
|
readonly DeveloperModeInfo info;
|
||||||
public bool Enabled { get; private set; }
|
public bool Enabled { get; private set; }
|
||||||
@@ -245,5 +245,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
Game.Debug("Cheat used: {0} by {1}", order.OrderString, self.Owner.PlayerName);
|
Game.Debug("Cheat used: {0} by {1}", order.OrderString, self.Owner.PlayerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IUnlocksRenderPlayer.RenderPlayerUnlocked { get { return Enabled; } }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user