mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 03:33:29 +08:00
Dustbin v1.4.0
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
@@ -14,7 +13,6 @@ public static class BeltSignal
|
|||||||
private static HashSet<int>[] _signalBelts;
|
private static HashSet<int>[] _signalBelts;
|
||||||
private static int _signalBeltsCapacity;
|
private static int _signalBeltsCapacity;
|
||||||
private static bool _initialized;
|
private static bool _initialized;
|
||||||
private static AssetBundle _bundle;
|
|
||||||
private static Harmony _patch;
|
private static Harmony _patch;
|
||||||
|
|
||||||
public static void Enable(bool on)
|
public static void Enable(bool on)
|
||||||
@@ -33,13 +31,40 @@ public static class BeltSignal
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static byte[] LoadEmbeddedResource(string path, Assembly assembly = null)
|
||||||
|
{
|
||||||
|
if (assembly == null)
|
||||||
|
{
|
||||||
|
assembly = Assembly.GetCallingAssembly();
|
||||||
|
}
|
||||||
|
var info = assembly.GetName();
|
||||||
|
var name = info.Name;
|
||||||
|
using var stream = assembly.GetManifestResourceStream($"{name}.{path.Replace('/', '.')}")!;
|
||||||
|
var buffer = new byte[stream.Length];
|
||||||
|
_ = stream.Read(buffer, 0, buffer.Length);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Texture2D LoadEmbeddedTexture(string path, Assembly assembly = null)
|
||||||
|
{
|
||||||
|
var fileData = LoadEmbeddedResource(path, assembly);
|
||||||
|
var tex = new Texture2D(2, 2);
|
||||||
|
tex.LoadImage(fileData);
|
||||||
|
return tex;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Sprite LoadEmbeddedSprite(string path, Assembly assembly = null)
|
||||||
|
{
|
||||||
|
var tex = LoadEmbeddedTexture(path, assembly);
|
||||||
|
return Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||||||
|
}
|
||||||
|
|
||||||
[HarmonyPostfix, HarmonyPriority(Priority.Last)]
|
[HarmonyPostfix, HarmonyPriority(Priority.Last)]
|
||||||
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||||
{
|
{
|
||||||
if (_initialized) return;
|
if (_initialized) return;
|
||||||
var pluginfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
_bundle = AssetBundle.LoadFromFile($"{pluginfolder}/dustbin.assetbundle");
|
|
||||||
var signals = LDB._signals;
|
var signals = LDB._signals;
|
||||||
var index = signals.dataArray.Length;
|
var index = signals.dataArray.Length;
|
||||||
var p = new SignalProto
|
var p = new SignalProto
|
||||||
@@ -48,7 +73,7 @@ public static class BeltSignal
|
|||||||
Name = "DUSTBIN",
|
Name = "DUSTBIN",
|
||||||
GridIndex = 3110,
|
GridIndex = 3110,
|
||||||
IconPath = "Assets/signal-410.png",
|
IconPath = "Assets/signal-410.png",
|
||||||
_iconSprite = _bundle.LoadAsset<Sprite>("Assets/signal-410.png"),
|
_iconSprite = LoadEmbeddedSprite("assets/icon/signal-410.png", assembly),
|
||||||
SID = ""
|
SID = ""
|
||||||
};
|
};
|
||||||
p.name = p.Name.Translate();
|
p.name = p.Name.Translate();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<TargetFramework>net472</TargetFramework>
|
<TargetFramework>net472</TargetFramework>
|
||||||
<BepInExPluginGuid>org.soardev.dustbin</BepInExPluginGuid>
|
<BepInExPluginGuid>org.soardev.dustbin</BepInExPluginGuid>
|
||||||
<Description>DSP MOD - Dustbin</Description>
|
<Description>DSP MOD - Dustbin</Description>
|
||||||
<Version>1.3.3</Version>
|
<Version>1.4.0</Version>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<PackageId>Dustbin</PackageId>
|
<PackageId>Dustbin</PackageId>
|
||||||
@@ -21,6 +21,9 @@
|
|||||||
<PackageReference Include="DysonSphereProgram.Modding.NebulaMultiplayerModApi" Version="2.0.0" />
|
<PackageReference Include="DysonSphereProgram.Modding.NebulaMultiplayerModApi" Version="2.0.0" />
|
||||||
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
<PackageReference Include="UnityEngine.Modules" Version="2018.4.12" IncludeAssets="compile" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="assets/icon/signal-410.png" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
|
||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="all" />
|
||||||
|
|||||||
@@ -3,36 +3,6 @@
|
|||||||
#### Can turn Storages and Tanks into Dustbin(Destroy incoming items)
|
#### Can turn Storages and Tanks into Dustbin(Destroy incoming items)
|
||||||
#### 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)
|
#### 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)
|
||||||
|
|
||||||
## Changelog
|
|
||||||
* 1.3.3
|
|
||||||
+ Support for NebulaMultiplayerModApi 2.0.0
|
|
||||||
|
|
||||||
* 1.3.2
|
|
||||||
+ Fix a display issue that the dustbin checkbox is overlapped with the filter button in storage UI.
|
|
||||||
|
|
||||||
* 1.3.1
|
|
||||||
+ Support for game version 0.10.28.20759
|
|
||||||
|
|
||||||
* 1.3.0
|
|
||||||
+ Add a belt signal(you can find it in first tab of signal selection panel) as dustbin, which is the simplest way to destroy items.
|
|
||||||
+ Reworked dustbin support for Tanks, to improve performance and resolve known bugs.
|
|
||||||
- Be note that the whole tank logic is optimized which may get a slight better performance even if you don't use them as dustbin.
|
|
||||||
+ Config entry for soil piless gain from destroyed items are changed to a more flexible format.
|
|
||||||
+ [Nebula Mupltiplayer Mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/) and bug fixes from [ModFixerOne](https://dsp.thunderstore.io/package/starfi5h/ModFixerOne/) by [starfi5h](https://github.com/starfi5h/).
|
|
||||||
|
|
||||||
* 1.2.1
|
|
||||||
+ Fix dynamic array bug in codes, which causes various bugs and errors.
|
|
||||||
|
|
||||||
* 1.2.0
|
|
||||||
+ Use [DSPModSave](https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/) to save dustbin specified data now, which fixes [#1](https://github.com/soarqin/DSP_Mods/issues/1).
|
|
||||||
+ Fix issue for storages on multiple planets.
|
|
||||||
+ Fix issue for multi-level tanks.
|
|
||||||
+ Add a note in README for known bug on tank.
|
|
||||||
|
|
||||||
* 1.1.0
|
|
||||||
+ Rewrite whole plugin, make a checkbox on UI so that you can turn storages into dustbin by just ticking it.
|
|
||||||
+ Can turn tank into dustbin now.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
* A checkbox is added to Storages and Tanks UI, which turns them into dustbins.
|
* A checkbox is added to Storages and Tanks UI, which turns them into dustbins.
|
||||||
@@ -40,36 +10,6 @@
|
|||||||
* Can get soil piless from destroyed items, configurable through a json encoded config entry.
|
* Can get soil piless from destroyed items, configurable through a json encoded config entry.
|
||||||
+ You can get item ID list [here](https://dsp-wiki.com/Modding:Items_IDs).
|
+ You can get item ID list [here](https://dsp-wiki.com/Modding:Items_IDs).
|
||||||
|
|
||||||
## 更新日志
|
|
||||||
* 1.3.3
|
|
||||||
+ 支持NebulaMultiplayerModApi 2.0.0
|
|
||||||
|
|
||||||
* 1.3.2
|
|
||||||
+ 修正了储物仓UI中的垃圾桶勾选框与筛选按钮重叠的显示问题
|
|
||||||
|
|
||||||
* 1.3.1
|
|
||||||
+ 支持游戏版本 0.10.28.20759
|
|
||||||
|
|
||||||
* 1.3.0
|
|
||||||
+ 添加了一个传送带信号(可以在信号选择面板的第一个页签中找到)作为垃圾桶,这是目前销毁物品最简单的方法
|
|
||||||
+ 重写了储液罐的垃圾桶实现,以提高性能并解决已知的bug
|
|
||||||
- 注意:整个储液罐逻辑都被优化了,即使你不把他们作为垃圾桶使用,也可能会获得轻微的性能提升
|
|
||||||
+ 从销毁的物品中获得沙子的配置已变为更灵活的设置项格式
|
|
||||||
+ [Nebula Mupltiplayer Mod](https://dsp.thunderstore.io/package/nebula/NebulaMultiplayerMod/)支持和Bug修正来自[starfi5h](https://github.com/starfi5h/)的[ModFixerOne](https://dsp.thunderstore.io/package/starfi5h/ModFixerOne/)
|
|
||||||
|
|
||||||
* 1.2.1
|
|
||||||
+ 修正了代码中的动态数组Bug,该Bug可能导致各种问题
|
|
||||||
|
|
||||||
* 1.2.0
|
|
||||||
+ 现在使用[DSPModSave](https://dsp.thunderstore.io/package/CommonAPI/DSPModSave/)来保存垃圾桶的数据,修正了[#1](https://github.com/soarqin/DSP_Mods/issues/1)
|
|
||||||
+ 修正了多星球上的储物仓问题
|
|
||||||
+ 修正了多层储液罐的问题
|
|
||||||
+ 在README中添加了一个已知储液罐Bug的说明
|
|
||||||
|
|
||||||
* 1.1.0
|
|
||||||
+ 重写了整个插件,现在可以在仓储类建筑的UI上勾选来将其转变为垃圾桶
|
|
||||||
+ 现在可以将储液罐转变为垃圾桶
|
|
||||||
|
|
||||||
## 使用说明
|
## 使用说明
|
||||||
|
|
||||||
* 在储物仓和储液罐上增加一个垃圾桶的勾选框。
|
* 在储物仓和储液罐上增加一个垃圾桶的勾选框。
|
||||||
|
|||||||
@@ -183,94 +183,68 @@ public static class TankPatch
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private static void TankComponentUpdateBelt(ref TankComponent thisTank, int belt, bool isOutput, ref CargoTraffic cargoTraffic, ref TankComponent[] tankPool)
|
private static void TankComponentUpdateBelt(ref TankComponent thisTank, int belt, bool isOutput, ref CargoTraffic cargoTraffic, ref TankComponent[] tankPool)
|
||||||
{
|
{
|
||||||
switch (isOutput)
|
if (isOutput)
|
||||||
{
|
{
|
||||||
case true when thisTank.outputSwitch:
|
if (thisTank.outputSwitch)
|
||||||
{
|
{
|
||||||
if (thisTank.fluidId <= 0 || thisTank.fluidCount <= 0) return;
|
if (thisTank.fluidId <= 0 || thisTank.fluidCount <= 0) return;
|
||||||
var inc = thisTank.fluidInc == 0 ? 0 : thisTank.fluidInc / thisTank.fluidCount;
|
var inc = thisTank.fluidInc == 0 ? 0 : thisTank.fluidInc / thisTank.fluidCount;
|
||||||
if (!cargoTraffic.TryInsertItemAtHead(belt, thisTank.fluidId, 1, (byte)inc)) return;
|
if (!cargoTraffic.TryInsertItemAtHead(belt, thisTank.fluidId, 1, (byte)inc)) return;
|
||||||
thisTank.fluidCount--;
|
thisTank.fluidCount--;
|
||||||
thisTank.fluidInc -= inc;
|
thisTank.fluidInc -= inc;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
case false when thisTank.inputSwitch:
|
|
||||||
{
|
|
||||||
byte stack;
|
|
||||||
byte inc;
|
|
||||||
switch (thisTank.fluidId)
|
|
||||||
{
|
|
||||||
case > 0 when thisTank.fluidCount < thisTank.fluidCapacity && cargoTraffic.TryPickItemAtRear(belt, thisTank.fluidId, null, out stack, out inc) > 0 &&
|
|
||||||
!thisTank.IsDustbin:
|
|
||||||
thisTank.fluidCount += stack;
|
|
||||||
thisTank.fluidInc += inc;
|
|
||||||
return;
|
|
||||||
case 0:
|
|
||||||
{
|
|
||||||
var count = cargoTraffic.TryPickItemAtRear(belt, 0, ItemProto.fluids, out stack, out inc);
|
|
||||||
if (count <= 0 || thisTank.IsDustbin) return;
|
|
||||||
thisTank.fluidId = count;
|
|
||||||
thisTank.fluidCount += stack;
|
|
||||||
thisTank.fluidInc += inc;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (thisTank.fluidCount < thisTank.fluidCapacity || cargoTraffic.GetItemIdAtRear(belt) != thisTank.fluidId || thisTank.nextTankId <= 0) return;
|
|
||||||
ref var targetTank = ref tankPool[thisTank.nextTankId];
|
|
||||||
while (targetTank.fluidCount >= targetTank.fluidCapacity)
|
|
||||||
{
|
|
||||||
ref var lastTank = ref tankPool[targetTank.lastTankId];
|
|
||||||
if (targetTank.fluidId != lastTank.fluidId)
|
|
||||||
{
|
|
||||||
if (lastTank.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return;
|
|
||||||
targetTank = ref lastTank;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!targetTank.inputSwitch)
|
|
||||||
{
|
|
||||||
if (lastTank.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return;
|
|
||||||
targetTank = ref lastTank;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (targetTank.nextTankId <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
targetTank = ref tankPool[targetTank.nextTankId];
|
|
||||||
}
|
|
||||||
|
|
||||||
ref var lastTank2 = ref tankPool[targetTank.lastTankId];
|
|
||||||
if (!targetTank.inputSwitch)
|
|
||||||
{
|
|
||||||
targetTank = ref lastTank2;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var fluidId = targetTank.fluidId;
|
if (thisTank.inputSwitch)
|
||||||
if (fluidId != 0 && fluidId != lastTank2.fluidId)
|
|
||||||
{
|
{
|
||||||
if (lastTank2.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return;
|
byte stack;
|
||||||
targetTank = ref lastTank2;
|
byte inc;
|
||||||
}
|
var thisFluidId = thisTank.fluidId;
|
||||||
else if (!lastTank2.outputSwitch)
|
if (thisTank.fluidCount <= 0)
|
||||||
{
|
{
|
||||||
|
var fluidId = cargoTraffic.TryPickItemAtRear(belt, 0, ItemProto.fluids, out stack, out inc);
|
||||||
|
if (fluidId <= 0 || thisTank.IsDustbin) return;
|
||||||
|
thisTank.fluidId = fluidId;
|
||||||
|
thisTank.fluidCount = stack;
|
||||||
|
thisTank.fluidInc = inc;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
if (thisTank.fluidCount < thisTank.fluidCapacity || thisTank.IsDustbin)
|
||||||
|
|
||||||
if (cargoTraffic.TryPickItemAtRear(belt, thisTank.fluidId, null, out stack, out inc) <= 0 || targetTank.IsDustbin) return;
|
|
||||||
if (targetTank.fluidCount == 0)
|
|
||||||
{
|
{
|
||||||
targetTank.fluidId = thisTank.fluidId;
|
if (cargoTraffic.GetItemIdAtRear(belt) != thisFluidId || thisTank.nextTankId <= 0) return;
|
||||||
|
if (cargoTraffic.TryPickItemAtRear(belt, thisFluidId, null, out stack, out inc) <= 0 || thisTank.IsDustbin) return;
|
||||||
|
thisTank.fluidCount += stack;
|
||||||
|
thisTank.fluidInc += inc;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (thisTank.nextTankId <= 0) return;
|
||||||
|
ref var targetTank = ref tankPool[thisTank.nextTankId];
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (targetTank.fluidCount < targetTank.fluidCapacity || targetTank.IsDustbin)
|
||||||
|
{
|
||||||
|
if (!targetTank.inputSwitch) return;
|
||||||
|
var targetFluidId = targetTank.fluidId;
|
||||||
|
if (targetFluidId != 0 && targetFluidId != thisFluidId) return;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (targetTank.nextTankId <= 0) return;
|
||||||
|
targetTank = ref tankPool[targetTank.nextTankId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cargoTraffic.TryPickItemAtRear(belt, thisFluidId, null, out stack, out inc) <= 0 || targetTank.IsDustbin) return;
|
||||||
|
if (targetTank.fluidCount <= 0)
|
||||||
|
{
|
||||||
|
targetTank.fluidId = thisFluidId;
|
||||||
|
targetTank.fluidCount = stack;
|
||||||
|
targetTank.fluidInc = inc;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
targetTank.fluidCount += stack;
|
targetTank.fluidCount += stack;
|
||||||
targetTank.fluidInc += inc;
|
targetTank.fluidInc += inc;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "Dustbin",
|
"name": "Dustbin",
|
||||||
"version_number": "1.3.3",
|
"version_number": "1.4.0",
|
||||||
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/Dustbin",
|
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/Dustbin",
|
||||||
"description": "Can turn Storages and Tanks into Dustbin(Destroy incoming items) / 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)",
|
"description": "Can turn Storages and Tanks into Dustbin(Destroy incoming items) / 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)",
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user