Decompiled source of CustomVehiclePathfind v1.0.2

CustomVehiclePathfind.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Game.Prefabs;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Entities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CustomVehiclePathfind")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Changing vehicle behaviors by configuring their pathfinding costs")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+dc637882006955a5fff8e5af654e9cc8386384af")]
[assembly: AssemblyProduct("CustomVehiclePathfind")]
[assembly: AssemblyTitle("CustomVehiclePathfind")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomVehiclePathfind
{
	[BepInPlugin("CustomVehiclePathfind", "CustomVehiclePathfind", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<int> m_unsafe_punishment;

		public static ConfigEntry<int> m_lane_punishment;

		public static ConfigEntry<float> m_driving_punishment;

		public static ConfigEntry<bool> enabled_unsafe_punishment;

		public static ConfigEntry<bool> enabled_lane_punishment;

		public static ConfigEntry<bool> enabled_driving_punishment;

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CustomVehiclePathfind is loaded!");
			Harmony val = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "CustomVehiclePathfind_Cities2Harmony");
			MethodBase[] array = val.GetPatchedMethods().ToArray();
			enabled_unsafe_punishment = ((BaseUnityPlugin)this).Config.Bind<bool>("UnsafeBehaviorPunishmentEnabled", "UnsafeBehaviorPunishmentEnabled", true, "是否开启不安全行为寻路惩罚 | Enable unsafe behaviors punishment | 填true表示开启,false表示关闭 | true for enabled and false for disabled");
			enabled_lane_punishment = ((BaseUnityPlugin)this).Config.Bind<bool>("LaneChangingPunishmentEnabled", "LaneChangingPunishmentEnabled", false, "是否开启变道寻路惩罚 | Enable lane changing punishment | 填true表示开启,false表示关闭 | true for enabled and false for disabled");
			enabled_driving_punishment = ((BaseUnityPlugin)this).Config.Bind<bool>("DrivingPunishmentEnabled", "DrivingPunishmentEnabled", false, "是否开启车辆行驶寻路惩罚 | Enable vehicle usage punishment | 填true表示开启,false表示关闭 | true for enabled and false for disabled");
			m_unsafe_punishment = ((BaseUnityPlugin)this).Config.Bind<int>("UnsafeBehaviorPunishment", "UnsafeBehaviorPunishment", 10000, "不安全行为寻路惩罚值 | Punishment value of unsafe behaviors in vehicle pathfinding | 需填整数 |  INTEGER needed");
			m_lane_punishment = ((BaseUnityPlugin)this).Config.Bind<int>("LaneChangingPunishment", "LaneChangingPunishment", 5, "变道寻路惩罚值 | Punishment value of lane changing in vehicle pathfinding | 需填整数 | INTEGER needed");
			m_driving_punishment = ((BaseUnityPlugin)this).Config.Bind<float>("DrivingPunishment", "DrivingPunishment", 1f, "车辆行驶惩罚值 | Punishment value of vehicle driving in vehicle pathfinding | 需填浮点数 | FLOAT needed");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin CustomVehiclePathfind made patches! Patched methods: " + array.Length));
			MethodBase[] array2 = array;
			foreach (MethodBase methodBase in array2)
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched method: " + methodBase.Module.Name + ":" + methodBase.Name));
			}
		}
	}
	[HarmonyPatch]
	internal class Patches
	{
		[HarmonyPatch(typeof(CarPathfind), "Initialize")]
		[HarmonyPrefix]
		private static bool Prefix(ref EntityManager entityManager, ref Entity entity, CarPathfind __instance)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			float num = Plugin.m_unsafe_punishment.Value;
			float num2 = Plugin.m_lane_punishment.Value;
			float value = Plugin.m_driving_punishment.Value;
			bool value2 = Plugin.enabled_unsafe_punishment.Value;
			bool value3 = Plugin.enabled_lane_punishment.Value;
			bool value4 = Plugin.enabled_driving_punishment.Value;
			PathfindCostInfo unsafeUTurnCost = default(PathfindCostInfo);
			PathfindCostInfo forbiddenCost = default(PathfindCostInfo);
			if (value2)
			{
				((PathfindCostInfo)(ref unsafeUTurnCost))..ctor(num, num, num, num);
				((PathfindCostInfo)(ref forbiddenCost))..ctor(num, num, num, num);
			}
			else
			{
				unsafeUTurnCost = __instance.m_UnsafeUTurnCost;
				forbiddenCost = __instance.m_ForbiddenCost;
			}
			PathfindCostInfo laneCrossCost = default(PathfindCostInfo);
			if (value3)
			{
				((PathfindCostInfo)(ref laneCrossCost))..ctor(num2, num2, 0f, num2);
			}
			else
			{
				laneCrossCost = __instance.m_LaneCrossCost;
			}
			PathfindCostInfo drivingCost = default(PathfindCostInfo);
			if (value4)
			{
				((PathfindCostInfo)(ref drivingCost))..ctor(0f, 0f, value, 0f);
			}
			else
			{
				drivingCost = __instance.m_DrivingCost;
			}
			((EntityManager)(ref entityManager)).SetComponentData<PathfindCarData>(entity, new PathfindCarData
			{
				m_DrivingCost = ((PathfindCostInfo)(ref drivingCost)).ToPathfindCosts(),
				m_TurningCost = ((PathfindCostInfo)(ref __instance.m_TurningCost)).ToPathfindCosts(),
				m_UTurnCost = ((PathfindCostInfo)(ref __instance.m_UTurnCost)).ToPathfindCosts(),
				m_UnsafeUTurnCost = ((PathfindCostInfo)(ref unsafeUTurnCost)).ToPathfindCosts(),
				m_LaneCrossCost = ((PathfindCostInfo)(ref laneCrossCost)).ToPathfindCosts(),
				m_ParkingCost = ((PathfindCostInfo)(ref __instance.m_ParkingCost)).ToPathfindCosts(),
				m_SpawnCost = ((PathfindCostInfo)(ref __instance.m_SpawnCost)).ToPathfindCosts(),
				m_ForbiddenCost = ((PathfindCostInfo)(ref forbiddenCost)).ToPathfindCosts()
			});
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CustomVehiclePathfind";

		public const string PLUGIN_NAME = "CustomVehiclePathfind";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}