Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Commands/Data/Buildings/BuildingUpdateFlagsCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ProtoBuf;

namespace CSM.Commands.Data.Buildings
{
/// <summary>
/// Called when any building needs to update its flags (Construction Status, Needs Status)
/// </summary>
/// Sent by:
/// - BuildingHandler
[ProtoContract]
public class BuildingUpdateFlagsCommand : CommandBase
{
/// <summary>
/// The id of the building that was rebuilt.
/// </summary>
[ProtoMember(1)]
public ushort Building { get; set; }

/// <summary>
/// The Mask of Flags that is passed to UpdateFlags function
/// </summary>
[ProtoMember(2)]
public Building.Flags ChangeMask { get; set; }
}
}
19 changes: 19 additions & 0 deletions src/Commands/Handler/Buildings/BuildingUpdateFlagsHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using CSM.Commands.Data.Buildings;
using CSM.Helpers;
using CSM.Injections;

namespace CSM.Commands.Handler.Buildings
{
public class BuildingUpdateFlagsHandler : CommandHandler<BuildingUpdateFlagsCommand>
{
protected override void Handle(BuildingUpdateFlagsCommand command)
{
IgnoreHelper.StartIgnore();

BuildingManager.instance.UpdateFlags(command.Building, command.ChangeMask);

IgnoreHelper.EndIgnore();
}
}
}
36 changes: 36 additions & 0 deletions src/Injections/BuildingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CSM.Helpers;
using HarmonyLib;
using UnityEngine;
using ColossalFramework;

namespace CSM.Injections
{
Expand Down Expand Up @@ -398,4 +399,39 @@ public static void Prefix(ushort buildingID, ref Building data, bool historical,
});
}
}

[HarmonyPatch(typeof(BuildingManager))]
[HarmonyPatch("UpdateFlags")]
public class UpgradeFlags
{
public static void Prefix(ushort building, ref Building.Flags changeMask, out bool __state)
{
if (IgnoreHelper.IsIgnored())
{
__state = false;
return;
}

__state = true;


ArrayHandler.StartCollecting();
IgnoreHelper.StartIgnore();
}

public static void Postfix(ushort building, ref Building.Flags changeMask, ref bool __state)
{
if (!__state)
return;

IgnoreHelper.EndIgnore();
ArrayHandler.StopCollecting();

Command.SendToAll(new BuildingUpdateFlagsCommand()
{
Building = building,
ChangeMask = changeMask
});
}
}
}