mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 06:13:36 +08:00
Work in progress
This commit is contained in:
98
OverclockEverything/BeltFix.cs
Normal file
98
OverclockEverything/BeltFix.cs
Normal file
@@ -0,0 +1,98 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Emit;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace OverclockEverything;
|
||||
|
||||
[HarmonyPatch]
|
||||
public static class BeltFix
|
||||
{
|
||||
private static CodeInstruction[] LdcInstrs = new[]
|
||||
{
|
||||
new CodeInstruction(OpCodes.Ldc_I4_0), new CodeInstruction(OpCodes.Ldc_I4_1), new CodeInstruction(OpCodes.Ldc_I4_2),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_3), new CodeInstruction(OpCodes.Ldc_I4_4), new CodeInstruction(OpCodes.Ldc_I4_5),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_6), new CodeInstruction(OpCodes.Ldc_I4_7), new CodeInstruction(OpCodes.Ldc_I4_8),
|
||||
new CodeInstruction(OpCodes.Ldc_I4_S, 9), new CodeInstruction(OpCodes.Ldc_I4_S, 10)
|
||||
};
|
||||
[HarmonyTranspiler, HarmonyPatch(typeof(CargoTraffic), "AlterBeltRenderer")]
|
||||
public static IEnumerable<CodeInstruction> CargoTraffic_AlterBeltRenderer_Transpiler(IEnumerable<CodeInstruction> instructions)
|
||||
{
|
||||
bool lastIsSpeed = false;
|
||||
foreach (var instr in instructions)
|
||||
{
|
||||
if (lastIsSpeed)
|
||||
{
|
||||
lastIsSpeed = false;
|
||||
if (instr.opcode == OpCodes.Ldc_I4_1)
|
||||
{
|
||||
yield return LdcInstrs[Patch.beltSpeed[0]];
|
||||
}
|
||||
else if (instr.opcode == OpCodes.Ldc_I4_2)
|
||||
{
|
||||
yield return LdcInstrs[Patch.beltSpeed[1]];
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return instr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastIsSpeed = instr.opcode == OpCodes.Ldfld &&
|
||||
instr.OperandIs(AccessTools.Field(typeof(BeltComponent), nameof(BeltComponent.speed)));
|
||||
yield return instr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(ConnGizmoRenderer), "AddBlueprintBeltMajorPoint")]
|
||||
[HarmonyPatch(typeof(ConnGizmoRenderer), "AddBlueprintBeltPoint")]
|
||||
[HarmonyPatch(typeof(ConnGizmoRenderer), "AddBlueprintBeltConn")]
|
||||
public static void ConnGizmoRenderer_AddBlueprintBelt_Prefix(ref ConnGizmoRenderer __instance, ref uint color)
|
||||
{
|
||||
var bspeed = Patch.beltSpeed;
|
||||
color = color >= bspeed[2] ? 3u : color >= bspeed[1] ? 2u : 1u;
|
||||
}
|
||||
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(ConnGizmoRenderer), "Update")]
|
||||
public static IEnumerable<CodeInstruction> ConnGizmoRenderer_Update_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
bool lastIsLdcI4_3 = false;
|
||||
foreach (var instr in instructions)
|
||||
{
|
||||
if (lastIsLdcI4_3)
|
||||
{
|
||||
lastIsLdcI4_3 = false;
|
||||
yield return instr;
|
||||
if (instr.opcode == OpCodes.Stfld && instr.OperandIs(AccessTools.Field(typeof(ConnGizmoObj), nameof(ConnGizmoObj.color))))
|
||||
{
|
||||
var label1 = generator.DefineLabel();
|
||||
var label2 = generator.DefineLabel();
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_S, 6);
|
||||
yield return LdcInstrs[Patch.beltSpeed[1]];
|
||||
yield return new CodeInstruction(OpCodes.Bne_Un_S, label1);
|
||||
yield return new CodeInstruction(OpCodes.Ldloca_S, 0);
|
||||
yield return new CodeInstruction(OpCodes.Ldc_I4_2);
|
||||
yield return new CodeInstruction(OpCodes.Stfld,
|
||||
AccessTools.Field(typeof(ConnGizmoObj), nameof(ConnGizmoObj.color)));
|
||||
yield return new CodeInstruction(OpCodes.Br, label2);
|
||||
yield return new CodeInstruction(OpCodes.Ldloc_S, 6).WithLabels(label1);
|
||||
yield return LdcInstrs[Patch.beltSpeed[0]];
|
||||
yield return new CodeInstruction(OpCodes.Bne_Un_S, label2);
|
||||
yield return new CodeInstruction(OpCodes.Ldloca_S, 0);
|
||||
yield return new CodeInstruction(OpCodes.Ldc_I4_1);
|
||||
yield return new CodeInstruction(OpCodes.Stfld,
|
||||
AccessTools.Field(typeof(ConnGizmoObj), nameof(ConnGizmoObj.color)));
|
||||
yield return new CodeInstruction(OpCodes.Nop).WithLabels(label2);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastIsLdcI4_3 = instr.opcode == OpCodes.Ldc_I4_3;
|
||||
yield return instr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
103
OverclockEverything/OverclockEverything.cs
Normal file
103
OverclockEverything/OverclockEverything.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace OverclockEverything;
|
||||
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
public class Patch : BaseUnityPlugin
|
||||
{
|
||||
private new static readonly BepInEx.Logging.ManualLogSource Logger =
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private bool _cfgEnabled = true;
|
||||
public static uint[] beltSpeed = {
|
||||
2, 5, 10
|
||||
};
|
||||
private static int inserterSpeedMultiplier = 2;
|
||||
private static int assembleSpeedMultiplier = 2;
|
||||
private static int powerConsumptionMultiplier = 2;
|
||||
private static long powerGenerationMultiplier = 4;
|
||||
private static long powerFuelConsumptionMultiplier = 1;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_cfgEnabled = Config.Bind("General", "Enabled", _cfgEnabled, "enable/disable this plugin").Value;
|
||||
if (!_cfgEnabled) return;
|
||||
beltSpeed[0] = Config.Bind("Belt", "MkI_Speed", beltSpeed[0],
|
||||
new ConfigDescription("Speed for Belt Mk.I.\n 1: 6/s\n 2: 12/s\n 3: 15/s(Displayed as 18/s)\n 4: 20/s(Displayed as 24/s)\n 5+: 6*n/s", new AcceptableValueRange<uint>(1, 10))).Value;
|
||||
beltSpeed[1] = Config.Bind("Belt", "MkII_Speed", beltSpeed[1],
|
||||
new ConfigDescription("Speed for Belt Mk.II", new AcceptableValueRange<uint>(1, 10))).Value;
|
||||
beltSpeed[2] = Config.Bind("Belt", "MkIII_Speed", beltSpeed[2],
|
||||
new ConfigDescription("Speed for Belt Mk.III", new AcceptableValueRange<uint>(1, 10))).Value;
|
||||
inserterSpeedMultiplier = Config.Bind("Inserter", "SpeedMultiplier", inserterSpeedMultiplier,
|
||||
new ConfigDescription("Speed multiplier for Inserters", new AcceptableValueRange<int>(1, 5))).Value;
|
||||
assembleSpeedMultiplier = Config.Bind("Assemble", "SpeedMultiplier", assembleSpeedMultiplier,
|
||||
new ConfigDescription("Speed multiplier for Smelters and Assembling Machines", new AcceptableValueRange<int>(1, 10))).Value;
|
||||
powerConsumptionMultiplier = Config.Bind("Assemble", "PowerConsumptionMultiplier", powerConsumptionMultiplier,
|
||||
new ConfigDescription("Power consumption multiplier for Smelters and Assembling Machines", new AcceptableValueRange<int>(1, 100))).Value;
|
||||
powerGenerationMultiplier = Config.Bind("Power", "GenerationMultiplier", powerGenerationMultiplier,
|
||||
new ConfigDescription("Power generation multiplier for all power providers", new AcceptableValueRange<long>(1, 10))).Value;
|
||||
powerFuelConsumptionMultiplier = Config.Bind("Power", "FuelConsumptionMultiplier", powerFuelConsumptionMultiplier,
|
||||
new ConfigDescription("Fuel consumption multiplier for all fuel-consuming power providers", new AcceptableValueRange<long>(1, 10))).Value;
|
||||
Harmony.CreateAndPatchAll(typeof(Patch));
|
||||
Harmony.CreateAndPatchAll(typeof(BeltFix));
|
||||
}
|
||||
|
||||
private static void BoostAssembler(int id)
|
||||
{
|
||||
var prefabDesc = LDB.items.Select(id).prefabDesc;
|
||||
prefabDesc.assemblerSpeed *= assembleSpeedMultiplier;
|
||||
prefabDesc.idleEnergyPerTick *= powerConsumptionMultiplier;
|
||||
prefabDesc.workEnergyPerTick *= powerConsumptionMultiplier;
|
||||
}
|
||||
|
||||
private static void BoostPower(int id)
|
||||
{
|
||||
var prefabDesc = LDB.items.Select(id).prefabDesc;
|
||||
prefabDesc.genEnergyPerTick *= powerGenerationMultiplier;
|
||||
prefabDesc.useFuelPerTick *= powerFuelConsumptionMultiplier;
|
||||
}
|
||||
|
||||
[HarmonyPostfix, HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||
{
|
||||
// Belts
|
||||
LDB.items.Select(2001).prefabDesc.beltSpeed = (int)beltSpeed[0];
|
||||
LDB.items.Select(2002).prefabDesc.beltSpeed = (int)beltSpeed[1];
|
||||
LDB.items.Select(2003).prefabDesc.beltSpeed = (int)beltSpeed[2];
|
||||
|
||||
// Inserters
|
||||
LDB.items.Select(2011).prefabDesc.inserterSTT /= inserterSpeedMultiplier;
|
||||
LDB.items.Select(2012).prefabDesc.inserterSTT /= inserterSpeedMultiplier;
|
||||
LDB.items.Select(2013).prefabDesc.inserterSTT /= inserterSpeedMultiplier;
|
||||
|
||||
// Smelters
|
||||
BoostAssembler(2302);
|
||||
BoostAssembler(2315);
|
||||
// Assemblers
|
||||
BoostAssembler(2303);
|
||||
BoostAssembler(2304);
|
||||
BoostAssembler(2305);
|
||||
// Chemical Plants
|
||||
BoostAssembler(2309);
|
||||
BoostAssembler(2317);
|
||||
// Refiner
|
||||
BoostAssembler(2308);
|
||||
// Collider
|
||||
BoostAssembler(2310);
|
||||
|
||||
// Thermal
|
||||
BoostPower(2204);
|
||||
// Fusion
|
||||
BoostPower(2211);
|
||||
// Artificial Star
|
||||
BoostPower(2210);
|
||||
// Wind Turbine
|
||||
BoostPower(2203);
|
||||
// Solar Panel
|
||||
BoostPower(2205);
|
||||
// Geothermal
|
||||
BoostPower(2213);
|
||||
}
|
||||
}
|
||||
28
OverclockEverything/OverclockEverything.csproj
Normal file
28
OverclockEverything/OverclockEverything.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<BepInExPluginGuid>org.soardev.overclockeverything</BepInExPluginGuid>
|
||||
<Description>DSP MOD - OverclockEverything</Description>
|
||||
<Version>1.0.0</Version>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<PackageId>OverclockEverything</PackageId>
|
||||
<RootNamespace>OverclockEverything</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BepInEx.Core" Version="5.*" />
|
||||
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
|
||||
<PackageReference Include="DysonSphereProgram.GameLibs" Version="*-r.*" />
|
||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="del /F /Q package\$(ProjectName)-$(Version).zip
zip -9 -j package/$(ProjectName)-$(Version).zip $(TargetPath) package/icon.png package/manifest.json README.md" />
|
||||
</Target>
|
||||
</Project>
|
||||
12
OverclockEverything/README.md
Normal file
12
OverclockEverything/README.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# OverclockEverything
|
||||
|
||||
#### Boost nearly all structures
|
||||
#### 加速几乎所有建筑功能
|
||||
|
||||
## Usage
|
||||
|
||||
* Boost power generation, assembling speed, belt and sorter speed.
|
||||
|
||||
## 使用说明
|
||||
|
||||
* 加快发电,制造,传送带和分拣器速度。
|
||||
BIN
OverclockEverything/package/icon.png
Normal file
BIN
OverclockEverything/package/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
9
OverclockEverything/package/manifest.json
Normal file
9
OverclockEverything/package/manifest.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "OverclockEverything",
|
||||
"version_number": "1.0.0",
|
||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/OverclockEverything",
|
||||
"description": "Overclock everything in game / 加速游戏中的所有建筑",
|
||||
"dependencies": [
|
||||
"xiaoye97-BepInEx-5.4.17"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user