using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DarkFogTweaks")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.4.0")]
[module: UnverifiableCode]
namespace DarkFogTweaks;
public class EnemyUnitScale
{
private static readonly List<int> whiteListIds = new List<int>();
private static readonly List<EnemyUnitDesc> oEnemyUnitDescs = new List<EnemyUnitDesc>();
private static readonly List<int> oModelIds = new List<int>();
private static ConfigEntry<string> whiteListProtoIds;
private static ConfigEntry<float> hpMax;
private static ConfigEntry<float> hpInc;
private static ConfigEntry<float> hpRecover;
private static ConfigEntry<float> movementSpeed;
private static ConfigEntry<float> sensorRange;
private static ConfigEntry<float> engageRange;
private static ConfigEntry<float> attackRange;
private static ConfigEntry<float> attackDamage;
private static ConfigEntry<float> attackDamageInc;
private static ConfigEntry<float> attackCoolDownSpeed;
private static ConfigEntry<float> attackCoolDownSpeedInc;
public static void ApplyAll()
{
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Invalid comparison between Unknown and I4
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Expected O, but got Unknown
oEnemyUnitDescs.Clear();
oModelIds.Clear();
whiteListIds.Clear();
string[] array = whiteListProtoIds.Value.Split(' ', ',');
for (int i = 0; i < array.Length; i++)
{
if (int.TryParse(array[i], out var result))
{
whiteListIds.Add(result);
}
}
if (!string.IsNullOrEmpty(whiteListProtoIds.Value))
{
Plugin.Log.LogDebug((object)("white list count: " + whiteListIds.Count));
}
ModelProto[] dataArray = ((ProtoSet<ModelProto>)(object)LDB.models).dataArray;
foreach (ModelProto val in dataArray)
{
if ((int)val.ObjectType == 4 && val.prefabDesc.isEnemyUnit && (whiteListIds.Count <= 0 || whiteListIds.Contains(((Proto)val).ID)))
{
EnemyUnitDesc val2 = new EnemyUnitDesc();
BackUp(val.prefabDesc, val2);
oModelIds.Add(((Proto)val).ID);
oEnemyUnitDescs.Add(val2);
Apply(val);
}
}
Plugin.Log.LogDebug((object)("EnemyUnit count: " + oModelIds.Count));
}
public static void RestoreAll()
{
for (int i = 0; i < oModelIds.Count; i++)
{
Restore(((ProtoSet<ModelProto>)(object)LDB.models).Select(oModelIds[i]).prefabDesc, oEnemyUnitDescs[i]);
}
}
private static void BackUp(PrefabDesc prefabDesc, EnemyUnitDesc enemyUnitDesc)
{
enemyUnitDesc.maxMovementSpeed = prefabDesc.unitMaxMovementSpeed;
enemyUnitDesc.maxMovementAcceleration = prefabDesc.unitMaxMovementAcceleration;
enemyUnitDesc.marchMovementSpeed = prefabDesc.unitMarchMovementSpeed;
enemyUnitDesc.assaultArriveRange = prefabDesc.unitAssaultArriveRange;
enemyUnitDesc.engageArriveRange = prefabDesc.unitEngageArriveRange;
enemyUnitDesc.sensorRange = prefabDesc.unitSensorRange;
enemyUnitDesc.attackRange0 = prefabDesc.unitAttackRange0;
enemyUnitDesc.attackInterval0 = prefabDesc.unitAttackInterval0;
enemyUnitDesc.attackHeat0 = prefabDesc.unitAttackHeat0;
enemyUnitDesc.attackDamage0 = prefabDesc.unitAttackDamage0;
enemyUnitDesc.attackDamageInc0 = prefabDesc.unitAttackDamageInc0;
enemyUnitDesc.attackRange1 = prefabDesc.unitAttackRange1;
enemyUnitDesc.attackInterval1 = prefabDesc.unitAttackInterval1;
enemyUnitDesc.attackHeat1 = prefabDesc.unitAttackHeat1;
enemyUnitDesc.attackDamage1 = prefabDesc.unitAttackDamage1;
enemyUnitDesc.attackDamageInc1 = prefabDesc.unitAttackDamageInc1;
enemyUnitDesc.attackRange2 = prefabDesc.unitAttackRange2;
enemyUnitDesc.attackInterval2 = prefabDesc.unitAttackInterval2;
enemyUnitDesc.attackHeat2 = prefabDesc.unitAttackHeat2;
enemyUnitDesc.attackDamage2 = prefabDesc.unitAttackDamage2;
enemyUnitDesc.attackDamageInc2 = prefabDesc.unitAttackDamageInc2;
enemyUnitDesc.coldSpeed = prefabDesc.unitColdSpeed;
enemyUnitDesc.coldSpeedInc = prefabDesc.unitColdSpeedInc;
}
private static void Restore(PrefabDesc prefabDesc, EnemyUnitDesc enemyUnitDesc)
{
prefabDesc.unitMaxMovementSpeed = enemyUnitDesc.maxMovementSpeed;
prefabDesc.unitMaxMovementAcceleration = enemyUnitDesc.maxMovementAcceleration;
prefabDesc.unitMarchMovementSpeed = enemyUnitDesc.marchMovementSpeed;
prefabDesc.unitAssaultArriveRange = enemyUnitDesc.assaultArriveRange;
prefabDesc.unitEngageArriveRange = enemyUnitDesc.engageArriveRange;
prefabDesc.unitSensorRange = enemyUnitDesc.sensorRange;
prefabDesc.unitAttackRange0 = enemyUnitDesc.attackRange0;
prefabDesc.unitAttackInterval0 = enemyUnitDesc.attackInterval0;
prefabDesc.unitAttackHeat0 = enemyUnitDesc.attackHeat0;
prefabDesc.unitAttackDamage0 = enemyUnitDesc.attackDamage0;
prefabDesc.unitAttackDamageInc0 = enemyUnitDesc.attackDamageInc0;
prefabDesc.unitAttackRange1 = enemyUnitDesc.attackRange1;
prefabDesc.unitAttackInterval1 = enemyUnitDesc.attackInterval1;
prefabDesc.unitAttackHeat1 = enemyUnitDesc.attackHeat1;
prefabDesc.unitAttackDamage1 = enemyUnitDesc.attackDamage1;
prefabDesc.unitAttackDamageInc1 = enemyUnitDesc.attackDamageInc1;
prefabDesc.unitAttackRange2 = enemyUnitDesc.attackRange2;
prefabDesc.unitAttackInterval2 = enemyUnitDesc.attackInterval2;
prefabDesc.unitAttackHeat2 = enemyUnitDesc.attackHeat2;
prefabDesc.unitAttackDamage2 = enemyUnitDesc.attackDamage2;
prefabDesc.unitAttackDamageInc2 = enemyUnitDesc.attackDamageInc2;
prefabDesc.unitColdSpeed = enemyUnitDesc.coldSpeed;
prefabDesc.unitColdSpeedInc = enemyUnitDesc.coldSpeedInc;
}
public static void LoadConfigs(ConfigFile configFile)
{
whiteListProtoIds = configFile.Bind<string>("EnemyUnitFactor", "WhiteListProtoIds", "", "If not null, the modifications will only apply to the whiltelist ids, separated by comma.\nProtoIds: 300 Raider, 301 Ranger, 302 Guardian, 285 Lancer, 284 Humpback, 283 Eclipse Fortress");
hpMax = configFile.Bind<float>("EnemyUnitFactor", "HpMax", 1f, (ConfigDescription)null);
hpInc = configFile.Bind<float>("EnemyUnitFactor", "HpInc", 1f, "Hp upgrade per level");
hpRecover = configFile.Bind<float>("EnemyUnitFactor", "HpRecover", 1f, "Hp recovery overtime");
movementSpeed = configFile.Bind<float>("EnemyUnitFactor", "MovementSpeed", 1f, "Including base speed, max speed and acceleration");
sensorRange = configFile.Bind<float>("EnemyUnitFactor", "SensorRange", 1f, "");
engageRange = configFile.Bind<float>("EnemyUnitFactor", "EngageRange", 1f, "The distance to engage and keep on firing");
attackRange = configFile.Bind<float>("EnemyUnitFactor", "AttackRange", 1f, "");
attackDamage = configFile.Bind<float>("EnemyUnitFactor", "AttackDamage", 1f, "");
attackDamageInc = configFile.Bind<float>("EnemyUnitFactor", "AttackDamageInc", 1f, "Damage upgrade per level");
attackCoolDownSpeed = configFile.Bind<float>("EnemyUnitFactor", "AttackCoolDownSpeed", 1f, "");
attackCoolDownSpeedInc = configFile.Bind<float>("EnemyUnitFactor", "AttackCoolDownSpeedInc", 1f, "Damage cooldown speed upgrade per level");
}
private static void Apply(ModelProto modelProto)
{
int iD = ((Proto)modelProto).ID;
SkillSystem.HpMaxByModelIndex[iD] = (int)((float)SkillSystem.HpMaxByModelIndex[iD] * hpMax.Value + 0.5f);
SkillSystem.HpUpgradeByModelIndex[iD] = (int)((float)SkillSystem.HpUpgradeByModelIndex[iD] * hpInc.Value + 0.5f);
SkillSystem.HpRecoverByModelIndex[iD] = (int)((float)SkillSystem.HpRecoverByModelIndex[iD] * hpRecover.Value + 0.5f);
PrefabDesc prefabDesc = modelProto.prefabDesc;
prefabDesc.unitMaxMovementSpeed *= movementSpeed.Value;
prefabDesc.unitMaxMovementAcceleration *= movementSpeed.Value;
prefabDesc.unitMarchMovementSpeed *= movementSpeed.Value;
prefabDesc.unitSensorRange *= sensorRange.Value;
prefabDesc.unitAssaultArriveRange *= engageRange.Value;
prefabDesc.unitEngageArriveRange *= engageRange.Value;
prefabDesc.unitAttackRange0 *= attackRange.Value;
prefabDesc.unitAttackRange1 *= attackRange.Value;
prefabDesc.unitAttackRange2 *= attackRange.Value;
prefabDesc.unitAttackDamage0 = (int)((float)prefabDesc.unitAttackDamage0 * attackDamage.Value + 0.5f);
prefabDesc.unitAttackDamage1 = (int)((float)prefabDesc.unitAttackDamage1 * attackDamage.Value + 0.5f);
prefabDesc.unitAttackDamage2 = (int)((float)prefabDesc.unitAttackDamage2 * attackDamage.Value + 0.5f);
prefabDesc.unitAttackDamageInc0 = (int)((float)prefabDesc.unitAttackDamageInc0 * attackDamageInc.Value + 0.5f);
prefabDesc.unitAttackDamageInc1 = (int)((float)prefabDesc.unitAttackDamageInc1 * attackDamageInc.Value + 0.5f);
prefabDesc.unitAttackDamageInc2 = (int)((float)prefabDesc.unitAttackDamageInc2 * attackDamageInc.Value + 0.5f);
prefabDesc.unitColdSpeed = (int)((float)prefabDesc.unitColdSpeed * attackCoolDownSpeed.Value + 0.5f);
prefabDesc.unitColdSpeedInc = (int)((float)prefabDesc.unitColdSpeedInc * attackCoolDownSpeedInc.Value + 0.5f);
}
public static void Print(ModelProto modelProto)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("");
stringBuilder.AppendLine("Id: " + ((Proto)modelProto).ID);
stringBuilder.AppendLine("name: " + ((Proto)modelProto).name);
stringBuilder.AppendLine("displayName: " + modelProto.displayName);
stringBuilder.AppendLine("HpMax: " + modelProto.HpMax);
stringBuilder.AppendLine("HpRecover: " + modelProto.HpRecover);
stringBuilder.AppendLine("HpUpgrade: " + modelProto.HpUpgrade);
PrefabDesc prefabDesc = modelProto.prefabDesc;
stringBuilder.AppendLine("unitMaxMovementSpeed: " + prefabDesc.unitMaxMovementSpeed);
stringBuilder.AppendLine("unitMaxMovementAcceleration: " + prefabDesc.unitMaxMovementAcceleration);
stringBuilder.AppendLine("unitMarchMovementSpeed: " + prefabDesc.unitMarchMovementSpeed);
stringBuilder.AppendLine("unitAssaultArriveRange: " + prefabDesc.unitAssaultArriveRange);
stringBuilder.AppendLine("unitEngageArriveRange : " + prefabDesc.unitEngageArriveRange);
stringBuilder.AppendLine("unitSensorRange: " + prefabDesc.unitSensorRange);
stringBuilder.AppendLine("unitAttackRange0: " + prefabDesc.unitAttackRange0);
stringBuilder.AppendLine("unitAttackInterval0: " + prefabDesc.unitAttackInterval0);
stringBuilder.AppendLine("unitAttackHeat0: " + prefabDesc.unitAttackHeat0);
stringBuilder.AppendLine("unitAttackDamage0: " + prefabDesc.unitAttackDamage0);
stringBuilder.AppendLine("unitAttackDamageInc0: " + prefabDesc.unitAttackDamageInc0);
stringBuilder.AppendLine("unitAttackRange1: " + prefabDesc.unitAttackRange1);
stringBuilder.AppendLine("unitAttackInterval1: " + prefabDesc.unitAttackInterval1);
stringBuilder.AppendLine("unitAttackHeat1: " + prefabDesc.unitAttackHeat1);
stringBuilder.AppendLine("unitAttackDamage1: " + prefabDesc.unitAttackDamage1);
stringBuilder.AppendLine("unitAttackDamageInc1: " + prefabDesc.unitAttackDamageInc1);
stringBuilder.AppendLine("unitAttackRange2: " + prefabDesc.unitAttackRange2);
stringBuilder.AppendLine("unitAttackInterval2: " + prefabDesc.unitAttackInterval2);
stringBuilder.AppendLine("unitAttackHeat2: " + prefabDesc.unitAttackHeat2);
stringBuilder.AppendLine("unitAttackDamage2: " + prefabDesc.unitAttackDamage2);
stringBuilder.AppendLine("unitAttackDamageInc2: " + prefabDesc.unitAttackDamageInc2);
stringBuilder.AppendLine("unitColdSpeed: " + prefabDesc.unitColdSpeed);
stringBuilder.AppendLine("unitColdSpeedInc: " + prefabDesc.unitColdSpeedInc);
Plugin.Log.LogDebug((object)stringBuilder.ToString());
}
}
internal class Patch_Behavior
{
private static ConfigEntry<bool> Relay_FillPitFirst;
private static ConfigEntry<bool> Relay_ToPlayerPlanetFirst;
private static ConfigEntry<int> Hive_AssaultUnitCount;
private static ConfigEntry<float> Hive_AssaultUnitFactor;
private static ConfigEntry<int> Base_AssaultUnitCount;
private static ConfigEntry<float> Base_AssaultUnitFactor;
private static ConfigEntry<float> Space_ThreatFactor;
private static ConfigEntry<float> All_ExpFactor;
public static void LoadConfigs(ConfigFile configFile)
{
Base_AssaultUnitCount = configFile.Bind<int>("Behavior", "Base_AssaultUnitCount", 0, "Send as many unit as this overwritten value when base assault (max: 180)");
Base_AssaultUnitFactor = configFile.Bind<float>("Behavior", "Base_AssaultUnitFactor", 1f, "Scale the original assaulting unit count");
Hive_AssaultUnitCount = configFile.Bind<int>("Behavior", "Hive_AssaultUnitCount", 0, "Send as many unit as this overwritten value when hive assault (max: 1440)");
Hive_AssaultUnitFactor = configFile.Bind<float>("Behavior", "Hive_AssaultUnitFactor", 1f, "Scale the original assaulting unit count");
Relay_FillPitFirst = configFile.Bind<bool>("Behavior", "Relay_FillPitFirst", false, "Relay will try to land on base first");
Relay_ToPlayerPlanetFirst = configFile.Bind<bool>("Behavior", "Relay_ToPlayerPlanetFirst", false, "Relay will try to land on player's local planet first");
Space_ThreatFactor = configFile.Bind<float>("Behavior", "Space_ThreatFactor", 1f, "Multiplier of threat increase when attacking space enemies");
All_ExpFactor = configFile.Bind<float>("Behavior", "All_ExpFactor", 1f, "Extra multiplier to exp gain");
}
[HarmonyPrefix]
[HarmonyPriority(800)]
[HarmonyPatch(typeof(DFGBaseComponent), "LaunchAssault")]
private static void LaunchAssault_Prefix(ref int unitCount0, ref int unitCount1)
{
unitCount0 = (int)((float)unitCount0 * Base_AssaultUnitFactor.Value + 0.5f);
unitCount1 = (int)((float)unitCount1 * Base_AssaultUnitFactor.Value + 0.5f);
if (Base_AssaultUnitCount.Value != 0)
{
unitCount0 = Base_AssaultUnitCount.Value;
}
if (Base_AssaultUnitCount.Value != 0)
{
unitCount1 = Base_AssaultUnitCount.Value;
}
}
[HarmonyPrefix]
[HarmonyPriority(800)]
[HarmonyPatch(typeof(EnemyDFHiveSystem), "LaunchLancerAssault")]
private static void LaunchLancerAssault_Prefix(ref int unitCount0)
{
unitCount0 = (int)((float)unitCount0 * Hive_AssaultUnitFactor.Value + 0.5f);
if (Hive_AssaultUnitCount.Value != 0)
{
unitCount0 = Hive_AssaultUnitCount.Value;
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(SkillSystem), "CollectTempStates")]
private static void CollectTempStates_Postfix(SkillSystem __instance)
{
__instance.combatSettingsTmp.battleExpFactor *= All_ExpFactor.Value;
}
[HarmonyPrefix]
[HarmonyPriority(800)]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static void AddSpaceEnemyHatred_Prefix(SkillSystem __instance)
{
__instance.combatSettingsTmp.battleThreatFactor = GameMain.history.combatSettings.battleThreatFactor * Space_ThreatFactor.Value;
}
[HarmonyPostfix]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static void AddSpaceEnemyHatred_Postfix(SkillSystem __instance)
{
__instance.combatSettingsTmp.battleThreatFactor = GameMain.history.combatSettings.battleThreatFactor;
}
[HarmonyPrefix]
[HarmonyPriority(0)]
[HarmonyPatch(typeof(DFRelayComponent), "SearchTargetPlaceProcess")]
private static void SearchTargetPlaceProcess(DFRelayComponent __instance, ref bool __runOriginal)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Invalid comparison between Unknown and I4
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_010e: Unknown result type (might be due to invalid IL or missing references)
if (!__runOriginal || __instance.searchAstroId != 0)
{
return;
}
StarData starData = __instance.hive.starData;
int planetCount = starData.planetCount;
for (int i = 0; i < planetCount; i++)
{
if ((int)starData.planets[i].type == 5)
{
continue;
}
PlanetFactory factory = starData.planets[i].factory;
if (factory == null)
{
continue;
}
if (Relay_FillPitFirst.Value)
{
EnemyDFGroundSystem enemySystem = factory.enemySystem;
DFGBaseComponent[] buffer = enemySystem.bases.buffer;
int cursor = enemySystem.bases.cursor;
for (int j = 1; j < cursor; j++)
{
if (buffer[j] != null && buffer[j].id == j && buffer[j].relayId == 0 && buffer[j].hiveAstroId == 0)
{
__instance.searchBaseId = j;
__instance.searchLPos = VectorLF3.op_Implicit(factory.enemyPool[buffer[j].enemyId].pos);
__instance.searchLPos += ((Vector3)(ref __instance.searchLPos)).normalized * 70f;
buffer[j].hiveAstroId = __instance.hiveAstroId;
__runOriginal = false;
Plugin.Log.LogDebug((object)("Relay_FillPitFirst " + starData.planets[i].displayName));
return;
}
}
}
if (Relay_ToPlayerPlanetFirst.Value && starData.planets[i] == GameMain.localPlanet)
{
__instance.searchAstroId = starData.planets[i].astroId;
__instance.searchChance = 5;
Plugin.Log.LogDebug((object)("Relay_ToPlayerPlanetFirst " + starData.planets[i].displayName));
break;
}
}
}
}
public class Patch_Building
{
private static ConfigEntry<int> BuildingSpeedFactor;
private static ConfigEntry<int> BaseMatterGen;
private static ConfigEntry<int> BaseEnergyGen;
private static ConfigEntry<int> HiveMatterGen;
private static ConfigEntry<int> HiveEnergyGen;
public static void LoadConfigs(ConfigFile configFile)
{
BuildingSpeedFactor = configFile.Bind<int>("Buildings", "BuildingSpeedFactor", 1, "Increase building speed and reduce cost");
BaseMatterGen = configFile.Bind<int>("Buildings", "BaseExtraMatterGen", 0, "vanilla: +180");
BaseEnergyGen = configFile.Bind<int>("Buildings", "BaseExtraEnergyGen", 0, "vanilla: -5400 (5.4MW)");
HiveMatterGen = configFile.Bind<int>("Buildings", "HiveExtraMatterGen", 0, "vanilla: +0");
HiveEnergyGen = configFile.Bind<int>("Buildings", "HiveExtraEnergyGen", 0, "vanilla: +480000 (480MW)");
}
[HarmonyPrefix]
[HarmonyPriority(800)]
[HarmonyPatch(typeof(EnemyBuilderComponent), "LogicTick")]
private static bool EnemyBuilderComponent_LogicTick_Prefix(ref EnemyBuilderComponent __instance)
{
if (__instance.sp >= __instance.spMax)
{
return true;
}
__instance.state = 0;
if (__instance.energy >= __instance.spEnergy && __instance.matter >= __instance.spMatter)
{
__instance.sp += BuildingSpeedFactor.Value;
__instance.energy -= __instance.spEnergy;
__instance.matter -= __instance.spMatter;
if (__instance.sp >= __instance.spMax)
{
__instance.sp = __instance.spMax;
__instance.buildCDTime = 0;
}
}
return false;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(DFGBaseComponent), "LogicTick")]
private static void DFGBaseComponent_LogicTick_Prefix(ref EnemyBuilderComponent builder)
{
if (builder.state > 0)
{
builder.matter += BaseMatterGen.Value;
builder.matter = ((builder.matter < builder.maxMatter) ? builder.matter : builder.maxMatter);
builder.energy += BaseEnergyGen.Value;
builder.energy = ((builder.energy < builder.maxEnergy) ? builder.energy : builder.maxEnergy);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(DFSCoreComponent), "LogicTick")]
private static void DFSCoreComponent_LogicTick_Prefix(ref DFSCoreComponent __instance, EnemyDFHiveSystem hive)
{
if (hive != null)
{
ref EnemyBuilderComponent reference = ref hive.builders.buffer[__instance.builderId];
if (reference.state > 0)
{
reference.matter += HiveMatterGen.Value;
reference.matter = ((reference.matter < reference.maxMatter) ? reference.matter : reference.maxMatter);
reference.energy += HiveEnergyGen.Value;
reference.energy = ((reference.energy < reference.maxEnergy) ? reference.energy : reference.maxEnergy);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(EnemyBriefInfo), "SetBriefInfo")]
private static void EnemyBriefInfo_SetBriefInfo_Prefix(EnemyBriefInfo __instance, SpaceSector _sector)
{
try
{
if (_sector == null || __instance.enemyClusterId > 0 || __instance.enemyId <= 0)
{
return;
}
if (__instance.astroId > 1000000)
{
if (__instance.enemyId < _sector.enemyPool.Length)
{
ref EnemyData reference = ref _sector.enemyPool[__instance.enemyId];
if (reference.id == __instance.enemyId && reference.dfSCoreId > 0)
{
__instance.matterChange += HiveMatterGen.Value;
__instance.energyChange += HiveEnergyGen.Value;
}
}
}
else
{
if (__instance.astroId <= 100 || __instance.astroId > 204899 || __instance.astroId % 100 <= 0 || __instance.astroId >= _sector.skillSystem.astroFactories.Length)
{
return;
}
PlanetFactory val = _sector.skillSystem.astroFactories[__instance.astroId];
if (val != null && __instance.enemyId < val.enemyPool.Length)
{
ref EnemyData reference2 = ref val.enemyPool[__instance.enemyId];
if (reference2.id == __instance.enemyId && reference2.dfGBaseId > 0)
{
__instance.matterChange += BaseMatterGen.Value;
__instance.energyChange += BaseEnergyGen.Value;
}
}
}
}
catch
{
}
}
}
public class Patch_Common
{
private static int[] HpMaxByModelIndex;
private static int[] HpUpgradeByModelIndex;
private static int[] HpRecoverByModelIndex;
public static void SaveHPArray()
{
HpMaxByModelIndex = new int[SkillSystem.HpMaxByModelIndex.Length];
Array.Copy(SkillSystem.HpMaxByModelIndex, HpMaxByModelIndex, HpMaxByModelIndex.Length);
HpUpgradeByModelIndex = new int[SkillSystem.HpUpgradeByModelIndex.Length];
Array.Copy(SkillSystem.HpUpgradeByModelIndex, HpUpgradeByModelIndex, HpUpgradeByModelIndex.Length);
HpRecoverByModelIndex = new int[SkillSystem.HpRecoverByModelIndex.Length];
Array.Copy(SkillSystem.HpRecoverByModelIndex, HpRecoverByModelIndex, HpRecoverByModelIndex.Length);
}
public static void RestoreArray()
{
if (HpMaxByModelIndex != null)
{
Array.Copy(HpMaxByModelIndex, SkillSystem.HpMaxByModelIndex, HpMaxByModelIndex.Length);
Array.Copy(HpUpgradeByModelIndex, SkillSystem.HpUpgradeByModelIndex, HpUpgradeByModelIndex.Length);
Array.Copy(HpRecoverByModelIndex, SkillSystem.HpRecoverByModelIndex, HpRecoverByModelIndex.Length);
}
}
[HarmonyPostfix]
[HarmonyPriority(0)]
[HarmonyPatch(typeof(SkillSystem), "Init")]
public static void BackupAndApply()
{
SaveHPArray();
EnemyUnitScale.RestoreAll();
EnemyUnitScale.ApplyAll();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(UIOptionWindow), "OnApplyClick")]
public static void OnApplyClick()
{
((BaseUnityPlugin)Plugin.Instance).Config.Reload();
RestoreArray();
SaveHPArray();
EnemyUnitScale.RestoreAll();
EnemyUnitScale.ApplyAll();
}
}
[BepInPlugin("starfi5h.plugin.DarkFogTweaks", "DarkFogTweaks", "0.0.4")]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "starfi5h.plugin.DarkFogTweaks";
public const string NAME = "DarkFogTweaks";
public const string VERSION = "0.0.4";
public static ManualLogSource Log;
public static Plugin Instance;
private static Harmony harmony;
public void Awake()
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Instance = this;
harmony = new Harmony("starfi5h.plugin.DarkFogTweaks");
Patch_Behavior.LoadConfigs(((BaseUnityPlugin)this).Config);
Patch_Building.LoadConfigs(((BaseUnityPlugin)this).Config);
EnemyUnitScale.LoadConfigs(((BaseUnityPlugin)this).Config);
harmony.PatchAll(typeof(Patch_Behavior));
harmony.PatchAll(typeof(Patch_Building));
harmony.PatchAll(typeof(Patch_Common));
}
}