Locate devmode code largely in the trait, reduce exploitability.
This commit is contained in:
@@ -20,13 +20,12 @@ namespace OpenRA.GameRules
|
||||
public class UserSettings
|
||||
{
|
||||
// Debug settings
|
||||
public bool UnitDebug = false;
|
||||
public bool PathDebug = false;
|
||||
public bool PerfDebug = false;
|
||||
public bool IndexDebug = false;
|
||||
public bool RecordSyncReports = true;
|
||||
public bool ShowGameTimer = true;
|
||||
public bool DeveloperMode = false;
|
||||
public bool UnitDebug = false;
|
||||
public bool IndexDebug = false;
|
||||
|
||||
// Window settings
|
||||
public WindowMode WindowMode = WindowMode.PseudoFullscreen;
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace OpenRA.Graphics
|
||||
Game.Renderer.LineRenderer.DrawLine(xY, xY + new float2(0, -4), c, c);
|
||||
Game.Renderer.LineRenderer.DrawLine(XY, XY + new float2(-4, 0), c, c);
|
||||
Game.Renderer.LineRenderer.DrawLine(XY, XY + new float2(0, -4), c, c);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawLocus(Color c, int2[] cells)
|
||||
{
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace OpenRA.Traits
|
||||
public int Cash = 20000;
|
||||
public bool FastBuild = false;
|
||||
public bool FastCharge = false;
|
||||
public bool DisableShroud = false;
|
||||
public bool PathDebug = false;
|
||||
|
||||
public object Create (ActorInitializer init) { return new DeveloperMode(this); }
|
||||
}
|
||||
@@ -26,31 +28,76 @@ namespace OpenRA.Traits
|
||||
[Sync]
|
||||
public bool FastCharge;
|
||||
public bool FastBuild;
|
||||
public bool DisableShroud;
|
||||
public bool PathDebug;
|
||||
|
||||
public DeveloperMode(DeveloperModeInfo info)
|
||||
{
|
||||
Info = info;
|
||||
FastBuild = Info.FastBuild;
|
||||
FastCharge = Info.FastCharge;
|
||||
DisableShroud = Info.DisableShroud;
|
||||
PathDebug = Info.PathDebug;
|
||||
}
|
||||
|
||||
public void ResolveOrder (Actor self, Order order)
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return;
|
||||
|
||||
switch(order.OrderString)
|
||||
{
|
||||
case "DevModeFastCharge":
|
||||
{
|
||||
FastCharge ^= true;
|
||||
break;
|
||||
}
|
||||
case "DevModeFastBuild":
|
||||
{
|
||||
FastBuild ^= true;
|
||||
break;
|
||||
}
|
||||
case "DevFastCharge":
|
||||
{
|
||||
FastCharge ^= true;
|
||||
IssueNotification(FastCharge);
|
||||
break;
|
||||
}
|
||||
case "DevFastBuild":
|
||||
{
|
||||
FastBuild ^= true;
|
||||
IssueNotification(FastBuild);
|
||||
break;
|
||||
}
|
||||
case "DevGiveCash":
|
||||
{
|
||||
self.traits.Get<PlayerResources>().GiveCash(Info.Cash);
|
||||
IssueNotification(true);
|
||||
break;
|
||||
}
|
||||
case "DevShroud":
|
||||
{
|
||||
DisableShroud ^= true;
|
||||
Game.world.LocalPlayer.Shroud.Disabled = DisableShroud;
|
||||
IssueNotification(DisableShroud);
|
||||
break;
|
||||
}
|
||||
case "DevPathDebug":
|
||||
{
|
||||
PathDebug ^= true;
|
||||
IssueNotification(PathDebug);
|
||||
break;
|
||||
}
|
||||
case "DevIndexDebug":
|
||||
{
|
||||
Game.Settings.IndexDebug ^= true;
|
||||
IssueNotification(Game.Settings.IndexDebug);
|
||||
break;
|
||||
}
|
||||
case "DevUnitDebug":
|
||||
{
|
||||
Game.Settings.UnitDebug ^= true;
|
||||
IssueNotification(Game.Settings.UnitDebug);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IssueNotification(bool enabled)
|
||||
{
|
||||
if (enabled)
|
||||
Game.IssueOrder(Order.Chat("I used a devmode option"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace OpenRA.Traits
|
||||
public object Create(ActorInitializer init) { return new PlayerResources(init.self); }
|
||||
}
|
||||
|
||||
public class PlayerResources : ITick, IResolveOrder
|
||||
public class PlayerResources : ITick
|
||||
{
|
||||
Player Owner;
|
||||
int AdviceInterval;
|
||||
@@ -187,22 +187,5 @@ namespace OpenRA.Traits
|
||||
TickPower();
|
||||
TickOre(self);
|
||||
}
|
||||
|
||||
public void ResolveOrder (Actor self, Order order)
|
||||
{
|
||||
switch (order.OrderString)
|
||||
{
|
||||
case "DevModeGiveCash":
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) break;
|
||||
self.World.AddFrameEndTask( w =>
|
||||
{
|
||||
var amt = order.Subject.Info.Traits.Get<DeveloperModeInfo>().Cash;
|
||||
GiveCash(amt);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace OpenRA.Traits
|
||||
if (unit == null || ! unit.Traits.Contains<BuildableInfo>())
|
||||
return 0;
|
||||
|
||||
if (self.traits.Get<DeveloperMode>().FastBuild) return 0;
|
||||
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get<DeveloperMode>().FastBuild) return 0;
|
||||
var ui = unit.Traits.Get<BuildableInfo>();
|
||||
var time = ui.Cost
|
||||
* self.Owner.PlayerActor.Info.Traits.Get<ProductionQueueInfo>().BuildSpeed /* todo: country-specific build speed bonus */
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace OpenRA.Traits
|
||||
|
||||
if (IsAvailable && (!Info.RequiresPower || IsPowered()))
|
||||
{
|
||||
if (self.traits.Get<DeveloperMode>().FastCharge) RemainingTime = 0;
|
||||
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.traits.Get<DeveloperMode>().FastCharge) RemainingTime = 0;
|
||||
if (RemainingTime > 0) --RemainingTime;
|
||||
if (!notifiedCharging)
|
||||
{
|
||||
|
||||
@@ -41,78 +41,60 @@ namespace OpenRA.Widgets.Delegates
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").Checked =
|
||||
() => Game.world.LocalPlayer.Shroud.Disabled;
|
||||
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().DisableShroud;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_SHROUD").OnMouseDown = mi =>
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return true;
|
||||
Game.world.LocalPlayer.Shroud.Disabled ^= true;
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevShroud", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_UNITDEBUG").Checked =
|
||||
() => {return Game.Settings.UnitDebug;};
|
||||
() => Game.Settings.UnitDebug;
|
||||
devmodeBG.GetWidget("SETTINGS_CHECKBOX_UNITDEBUG").OnMouseDown = mi =>
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return true;
|
||||
Game.Settings.UnitDebug ^= true;
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevUnitDebug", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_PATHDEBUG").Checked =
|
||||
() => {return Game.Settings.PathDebug;};
|
||||
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().PathDebug;
|
||||
devmodeBG.GetWidget("SETTINGS_CHECKBOX_PATHDEBUG").OnMouseDown = mi =>
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return true;
|
||||
Game.Settings.PathDebug ^= true;
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevPathDebug", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHECKBOX_INDEXDEBUG").Checked =
|
||||
() => {return Game.Settings.IndexDebug;};
|
||||
() => Game.Settings.IndexDebug;
|
||||
devmodeBG.GetWidget("SETTINGS_CHECKBOX_INDEXDEBUG").OnMouseDown = mi =>
|
||||
{
|
||||
if (!Game.LobbyInfo.GlobalSettings.AllowCheats) return true;
|
||||
Game.Settings.IndexDebug ^= true;
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevIndexDebug", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<ButtonWidget>("SETTINGS_GIVE_CASH").OnMouseUp = mi =>
|
||||
{
|
||||
Game.IssueOrder(new Order("DevModeGiveCash", Game.world.LocalPlayer.PlayerActor));
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevGiveCash", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").OnMouseDown = mi =>
|
||||
{
|
||||
Game.IssueOrder(new Order("DevModeFastBuild", Game.world.LocalPlayer.PlayerActor));
|
||||
TriggerCheatingMessage();
|
||||
return true;
|
||||
};
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").Checked =
|
||||
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().FastBuild;
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").OnMouseDown = mi =>
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_BUILD_SPEED").OnMouseDown = mi =>
|
||||
{
|
||||
TriggerCheatingMessage();
|
||||
Game.IssueOrder(new Order("DevModeFastCharge", Game.world.LocalPlayer.PlayerActor));
|
||||
Game.IssueOrder(new Order("DevFastBuild", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").Checked =
|
||||
() => Game.world.LocalPlayer.PlayerActor.traits.Get<DeveloperMode>().FastCharge;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("SETTINGS_CHARGE_TIME").OnMouseDown = mi =>
|
||||
{
|
||||
Game.IssueOrder(new Order("DevFastCharge", Game.world.LocalPlayer.PlayerActor));
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
devModeButton.IsVisible = () => { return Game.Settings.DeveloperMode; };
|
||||
}
|
||||
|
||||
void TriggerCheatingMessage()
|
||||
{
|
||||
var order = Order.Chat("I used a developer mode option");
|
||||
Game.IssueOrder(order);
|
||||
devModeButton.IsVisible = () => { return Game.LobbyInfo.GlobalSettings.AllowCheats; };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user