Skip to content

Commit

Permalink
Changes for 1.29
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCSUser committed Dec 6, 2021
1 parent 0423946 commit f0bf19e
Show file tree
Hide file tree
Showing 32 changed files with 436 additions and 54 deletions.
6 changes: 1 addition & 5 deletions Compatibility/BOBModDisabledCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ namespace com.github.TheCSUser.HideItBobby.Compatibility
{
internal sealed class BOBModDisabledCheck : ModDisabledCheck
{
public BOBModDisabledCheck(IModContext context) : base(
context,
(pluginInfo) => pluginInfo?.name == "2197863850"
)
{ }
public BOBModDisabledCheck(IModContext context) : base(context, "2197863850") { }
}
}
4 changes: 2 additions & 2 deletions Compatibility/Base/ModDisabledCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ internal abstract class ModDisabledCheck : CompatibilityCheck

private readonly Func<PluginManager.PluginInfo, bool> _predicate;

public ModDisabledCheck(IModContext context, string name) : this(context, (p) => p.name == name) { }
public ModDisabledCheck(IModContext context, Func<string, bool> namePredicate) : this(context, (p) => namePredicate(p.name)) { }
public ModDisabledCheck(IModContext context, string name) : this(context, (p) => p?.name == name) { }
public ModDisabledCheck(IModContext context, Func<string, bool> namePredicate) : this(context, (p) => namePredicate(p?.name)) { }
public ModDisabledCheck(IModContext context, Func<PluginManager.PluginInfo, bool> predicate) : base(context)
{
_predicate = predicate;
Expand Down
10 changes: 10 additions & 0 deletions Compatibility/SubtleBulldozingModDisabledCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using com.github.TheCSUser.HideItBobby.Compatibility.Base;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Compatibility
{
internal sealed class SubtleBulldozingModDisabledCheck : ModDisabledCheck
{
public SubtleBulldozingModDisabledCheck(IModContext context) : base(context, "768213484") { }
}
}
6 changes: 1 addition & 5 deletions Compatibility/UIResolutionModEnabledCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ namespace com.github.TheCSUser.HideItBobby.Compatibility
{
internal sealed class UIResolutionModEnabledCheck : ModEnabledCheck
{
public UIResolutionModEnabledCheck(IModContext context) : base(
context,
(pluginInfo) => pluginInfo?.name == "2487213155"
)
{ }
public UIResolutionModEnabledCheck(IModContext context) : base(context, "2487213155") { }
}
}
41 changes: 41 additions & 0 deletions Features/Effects/DisableBulldozingEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using com.github.TheCSUser.HideItBobby.Compatibility;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
{
internal sealed class DisableBulldozingEffect : FeatureBase
{
public override FeatureKey Key => FeatureKey.DisableBulldozingEffect;

private readonly ICheck _compatibilityCheck;
public override bool IsAvailable => _compatibilityCheck.Result;

public DisableBulldozingEffect(IModContext context) : base(context)
{
_compatibilityCheck = context.Resolve<SubtleBulldozingModDisabledCheck>();
}

protected override bool OnInitialize()
{
Patcher.Patch(DispatchPlacementEffectProxy.Patches);
return true;
}
protected override bool OnTerminate()
{
Patcher.Unpatch(DispatchPlacementEffectProxy.Patches);
return true;
}

protected override bool OnEnable()
{
DispatchPlacementEffectProxy.DisableBulldozingEffect = true;
return true;
}
protected override bool OnDisable()
{
DispatchPlacementEffectProxy.DisableBulldozingEffect = false;
return true;
}
}
}
41 changes: 41 additions & 0 deletions Features/Effects/DisablePlacementEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using com.github.TheCSUser.HideItBobby.Compatibility;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
{
internal sealed class DisablePlacementEffect : FeatureBase
{
public override FeatureKey Key => FeatureKey.DisablePlacementEffect;

private readonly ICheck _compatibilityCheck;
public override bool IsAvailable => _compatibilityCheck.Result;

public DisablePlacementEffect(IModContext context) : base(context)
{
_compatibilityCheck = context.Resolve<SubtleBulldozingModDisabledCheck>();
}

protected override bool OnInitialize()
{
Patcher.Patch(DispatchPlacementEffectProxy.Patches);
return true;
}
protected override bool OnTerminate()
{
Patcher.Unpatch(DispatchPlacementEffectProxy.Patches);
return true;
}

protected override bool OnEnable()
{
DispatchPlacementEffectProxy.DisablePlacementEffect = true;
return true;
}
protected override bool OnDisable()
{
DispatchPlacementEffectProxy.DisablePlacementEffect = false;
return true;
}
}
}
2 changes: 1 addition & 1 deletion Features/Effects/HideBurnedAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideDestroyedAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideFertilityAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideForestAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideOilAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideOreAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HidePollutedAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideSandAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
2 changes: 1 addition & 1 deletion Features/Effects/HideShoreAreaEffect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches;
using com.github.TheCSUser.HideItBobby.Features.Effects.Shared;
using com.github.TheCSUser.Shared.Common;

namespace com.github.TheCSUser.HideItBobby.Features.Effects
Expand Down
175 changes: 175 additions & 0 deletions Features/Effects/Shared/DispatchPlacementEffectProxy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
using ColossalFramework;
using ColossalFramework.Math;
using ColossalFramework.UI;
using com.github.TheCSUser.HideItBobby.Properties;
using com.github.TheCSUser.Shared.Common;
using com.github.TheCSUser.Shared.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine;

namespace com.github.TheCSUser.HideItBobby.Features.Effects.Shared
{
[SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "Personal preference")]
internal static class DispatchPlacementEffectProxy
{
public static bool DisablePlacementEffect;
public static bool DisableBulldozingEffect;

public static IEnumerable<PatchData> Patches
{
get
{
yield return BuildingToolDispatchPlacementEffectPatch;
yield return DisasterToolDispatchPlacementEffectPatch;
yield return NetToolDispatchPlacementEffectPatch;
yield return PropToolDispatchPlacementEffectPatch;
yield return TreeToolDispatchPlacementEffectPatch;
}
}

#region PatchData
public static readonly PatchData BuildingToolDispatchPlacementEffectPatch = new PatchData(
patchId: $"{nameof(DispatchPlacementEffectProxy)}.{nameof(BuildingToolDispatchPlacementEffectPatch)}",
target: () => typeof(BuildingTool).GetMethod(
"DispatchPlacementEffect",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof(BuildingInfo), typeof(ushort), typeof(Vector3), typeof(float), typeof(int), typeof(int), typeof(bool), typeof(bool) },
null),
prefix: () => typeof(DispatchPlacementEffectProxy).GetMethod(nameof(BuildingToolDispatchPlacementEffect), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
);

public static readonly PatchData DisasterToolDispatchPlacementEffectPatch = new PatchData(
patchId: $"{nameof(DispatchPlacementEffectProxy)}.{nameof(DisasterToolDispatchPlacementEffectPatch)}",
target: () => typeof(DisasterTool).GetMethod(
"DispatchPlacementEffect",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof(Vector3), typeof(bool) },
null),
prefix: () => typeof(DispatchPlacementEffectProxy).GetMethod(nameof(DisasterToolDispatchPlacementEffect), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
);

public static readonly PatchData NetToolDispatchPlacementEffectPatch = new PatchData(
patchId: $"{nameof(DispatchPlacementEffectProxy)}.{nameof(NetToolDispatchPlacementEffectPatch)}",
target: () => typeof(NetTool).GetMethod(
"DispatchPlacementEffect",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(Vector3), typeof(float), typeof(bool) },
null),
prefix: () => typeof(DispatchPlacementEffectProxy).GetMethod(nameof(NetToolDispatchPlacementEffect), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
);

public static readonly PatchData PropToolDispatchPlacementEffectPatch = new PatchData(
patchId: $"{nameof(DispatchPlacementEffectProxy)}.{nameof(PropToolDispatchPlacementEffectPatch)}",
target: () => typeof(PropTool).GetMethod(
"DispatchPlacementEffect",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof(Vector3), typeof(bool) },
null),
prefix: () => typeof(DispatchPlacementEffectProxy).GetMethod(nameof(PropToolDispatchPlacementEffect), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
);

public static readonly PatchData TreeToolDispatchPlacementEffectPatch = new PatchData(
patchId: $"{nameof(DispatchPlacementEffectProxy)}.{nameof(TreeToolDispatchPlacementEffectPatch)}",
target: () => typeof(TreeTool).GetMethod(
"DispatchPlacementEffect",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof(Vector3), typeof(bool) },
null),
prefix: () => typeof(DispatchPlacementEffectProxy).GetMethod(nameof(TreeToolDispatchPlacementEffect), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static)
);
#endregion

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool BuildingToolDispatchPlacementEffect(BuildingTool __instance, BuildingInfo info, ushort buildingID, Vector3 pos, float angle, int width, int length, bool bulldozing, bool collapsed)
{
if (bulldozing ? !DisableBulldozingEffect : !DisablePlacementEffect) return true;
if (!Singleton<BuildingManager>.exists) return false;

var properties = Singleton<BuildingManager>.instance.m_properties;
var effect = bulldozing ? properties.m_bulldozeEffect : properties.m_placementEffect;
DispatchSoundEffect(effect, pos);
return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool DisasterToolDispatchPlacementEffect(BuildingTool __instance, Vector3 pos, bool bulldozing)
{
if (bulldozing ? !DisableBulldozingEffect : !DisablePlacementEffect) return true;
if (!Singleton<PropManager>.exists) return false;

var properties = Singleton<PropManager>.instance.m_properties;
var effect = bulldozing ? properties.m_bulldozeEffect : properties.m_placementEffect;
DispatchSoundEffect(effect, pos);
return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool NetToolDispatchPlacementEffect(BuildingTool __instance, Vector3 startPos, Vector3 middlePos1, Vector3 middlePos2, Vector3 endPos, float halfWidth, bool bulldozing)
{
if (bulldozing ? !DisableBulldozingEffect : !DisablePlacementEffect) return true;
if (!Singleton<NetManager>.exists) return false;

var properties = Singleton<NetManager>.instance.m_properties;
var effect = bulldozing ? properties.m_bulldozeEffect : properties.m_placementEffect;
DispatchSoundEffect(effect, (startPos + middlePos1 + middlePos2 + endPos) / 4);
return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool PropToolDispatchPlacementEffect(BuildingTool __instance, Vector3 pos, bool bulldozing)
{
if (bulldozing ? !DisableBulldozingEffect : !DisablePlacementEffect) return true;
if (!Singleton<PropManager>.exists) return false;

var properties = Singleton<PropManager>.instance.m_properties;
var effect = bulldozing ? properties.m_bulldozeEffect : properties.m_placementEffect;
DispatchSoundEffect(effect, pos);
return false;
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static bool TreeToolDispatchPlacementEffect(BuildingTool __instance, Vector3 pos, bool bulldozing)
{
if (bulldozing ? !DisableBulldozingEffect : !DisablePlacementEffect) return true;
if (!Singleton<TreeManager>.exists) return false;

var properties = Singleton<TreeManager>.instance.m_properties;
var effect = bulldozing ? properties.m_bulldozeEffect : properties.m_placementEffect;
DispatchSoundEffect(effect, pos);
return false;
}

private static void DispatchSoundEffect(EffectInfo effect, Vector3 pos)
{
if (effect is null) return;

var soundEffect = GetSoundEffect(effect);
var spawnArea = new EffectInfo.SpawnArea(pos, Vector3.up, 1f);
Singleton<EffectManager>.instance.DispatchEffect(soundEffect, spawnArea, Vector3.zero, 0.0f, 1f, Singleton<AudioManager>.instance.DefaultGroup, 0U, true);
}

private static EffectInfo GetSoundEffect(EffectInfo effect)
{
if (effect is MultiEffect multiEffect)
{
return multiEffect
.m_effects
.Where(x => x.m_probability > 0.0f)
.Select(x => x.m_effect)
.FirstOrDefault(x => x is SoundEffect);
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using UnityEngine;

namespace com.github.TheCSUser.HideItBobby.Features.Effects.Shared.Patches
namespace com.github.TheCSUser.HideItBobby.Features.Effects.Shared
{
internal static class NaturalResourceManagerProxy
{
Expand Down
2 changes: 2 additions & 0 deletions Features/FeatureKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ internal sealed class FeatureKey : StringEnum<FeatureKey>
public static readonly FeatureKey HideVolumeFog = Create(nameof(HideVolumeFog));
public static readonly FeatureKey HideDistanceFog = Create(nameof(HideDistanceFog));
public static readonly FeatureKey HideEdgeFog = Create(nameof(HideEdgeFog));
public static readonly FeatureKey DisablePlacementEffect = Create(nameof(DisablePlacementEffect));
public static readonly FeatureKey DisableBulldozingEffect = Create(nameof(DisableBulldozingEffect));

//GroundAndWaterColor
public static readonly FeatureKey DisableGrassFertilityGroundColor = Create(nameof(DisableGrassFertilityGroundColor));
Expand Down
Loading

0 comments on commit f0bf19e

Please sign in to comment.