From e458f42f4abffc4f713bd84d82d3404fa141cf60 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Tue, 25 Mar 2025 20:38:01 +0800 Subject: [PATCH] Dustbin v1.4.0 --- Dustbin/BeltSignal.cs | 35 ++++++- Dustbin/Dustbin.csproj | 5 +- Dustbin/README.md | 60 ------------ Dustbin/TankPatch.cs | 100 ++++++++------------ Dustbin/package/manifest.json | 2 +- Dustbin/package/plugins/dustbin.assetbundle | Bin 4103 -> 0 bytes 6 files changed, 72 insertions(+), 130 deletions(-) delete mode 100644 Dustbin/package/plugins/dustbin.assetbundle diff --git a/Dustbin/BeltSignal.cs b/Dustbin/BeltSignal.cs index 5014e8b..d0063c7 100644 --- a/Dustbin/BeltSignal.cs +++ b/Dustbin/BeltSignal.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -14,7 +13,6 @@ public static class BeltSignal private static HashSet[] _signalBelts; private static int _signalBeltsCapacity; private static bool _initialized; - private static AssetBundle _bundle; private static Harmony _patch; 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)] [HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")] private static void VFPreload_InvokeOnLoadWorkEnded_Postfix() { if (_initialized) return; - var pluginfolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - _bundle = AssetBundle.LoadFromFile($"{pluginfolder}/dustbin.assetbundle"); + var assembly = Assembly.GetExecutingAssembly(); var signals = LDB._signals; var index = signals.dataArray.Length; var p = new SignalProto @@ -48,7 +73,7 @@ public static class BeltSignal Name = "DUSTBIN", GridIndex = 3110, IconPath = "Assets/signal-410.png", - _iconSprite = _bundle.LoadAsset("Assets/signal-410.png"), + _iconSprite = LoadEmbeddedSprite("assets/icon/signal-410.png", assembly), SID = "" }; p.name = p.Name.Translate(); diff --git a/Dustbin/Dustbin.csproj b/Dustbin/Dustbin.csproj index 8633170..e734706 100644 --- a/Dustbin/Dustbin.csproj +++ b/Dustbin/Dustbin.csproj @@ -5,7 +5,7 @@ net472 org.soardev.dustbin DSP MOD - Dustbin - 1.3.3 + 1.4.0 true latest Dustbin @@ -21,6 +21,9 @@ + + + diff --git a/Dustbin/README.md b/Dustbin/README.md index 61270ad..ae56a4a 100644 --- a/Dustbin/README.md +++ b/Dustbin/README.md @@ -3,36 +3,6 @@ #### 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 * 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. + 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上勾选来将其转变为垃圾桶 - + 现在可以将储液罐转变为垃圾桶 - ## 使用说明 * 在储物仓和储液罐上增加一个垃圾桶的勾选框。 diff --git a/Dustbin/TankPatch.cs b/Dustbin/TankPatch.cs index 81f3162..a31d676 100644 --- a/Dustbin/TankPatch.cs +++ b/Dustbin/TankPatch.cs @@ -183,94 +183,68 @@ public static class TankPatch [MethodImpl(MethodImplOptions.AggressiveInlining)] 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; var inc = thisTank.fluidInc == 0 ? 0 : thisTank.fluidInc / thisTank.fluidCount; if (!cargoTraffic.TryInsertItemAtHead(belt, thisTank.fluidId, 1, (byte)inc)) return; thisTank.fluidCount--; thisTank.fluidInc -= inc; - return; } - case false when thisTank.inputSwitch: + } + else + { + if (thisTank.inputSwitch) { byte stack; byte inc; - switch (thisTank.fluidId) + var thisFluidId = thisTank.fluidId; + if (thisTank.fluidCount <= 0) { - 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; - } + 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; } - - 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) + if (thisTank.fluidCount < thisTank.fluidCapacity || thisTank.IsDustbin) { - ref var lastTank = ref tankPool[targetTank.lastTankId]; - if (targetTank.fluidId != lastTank.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 (lastTank.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return; - targetTank = ref lastTank; + if (!targetTank.inputSwitch) return; + var targetFluidId = targetTank.fluidId; + if (targetFluidId != 0 && targetFluidId != thisFluidId) return; break; } - - if (!targetTank.inputSwitch) - { - if (lastTank.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return; - targetTank = ref lastTank; - break; - } - - if (targetTank.nextTankId <= 0) - { - break; - } - + if (targetTank.nextTankId <= 0) return; targetTank = ref tankPool[targetTank.nextTankId]; } - ref var lastTank2 = ref tankPool[targetTank.lastTankId]; - if (!targetTank.inputSwitch) + if (cargoTraffic.TryPickItemAtRear(belt, thisFluidId, null, out stack, out inc) <= 0 || targetTank.IsDustbin) return; + if (targetTank.fluidCount <= 0) { - targetTank = ref lastTank2; + targetTank.fluidId = thisFluidId; + targetTank.fluidCount = stack; + targetTank.fluidInc = inc; } else { - var fluidId = targetTank.fluidId; - if (fluidId != 0 && fluidId != lastTank2.fluidId) - { - if (lastTank2.id == thisTank.id || targetTank.fluidCount >= targetTank.fluidCapacity) return; - targetTank = ref lastTank2; - } - else if (!lastTank2.outputSwitch) - { - return; - } + targetTank.fluidCount += stack; + targetTank.fluidInc += inc; } - - if (cargoTraffic.TryPickItemAtRear(belt, thisTank.fluidId, null, out stack, out inc) <= 0 || targetTank.IsDustbin) return; - if (targetTank.fluidCount == 0) - { - targetTank.fluidId = thisTank.fluidId; - } - - targetTank.fluidCount += stack; - targetTank.fluidInc += inc; - return; } } } diff --git a/Dustbin/package/manifest.json b/Dustbin/package/manifest.json index 5fd8365..6ccd9c8 100644 --- a/Dustbin/package/manifest.json +++ b/Dustbin/package/manifest.json @@ -1,6 +1,6 @@ { "name": "Dustbin", - "version_number": "1.3.3", + "version_number": "1.4.0", "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/Dustbin", "description": "Can turn Storages and Tanks into Dustbin(Destroy incoming items) / 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)", "dependencies": [ diff --git a/Dustbin/package/plugins/dustbin.assetbundle b/Dustbin/package/plugins/dustbin.assetbundle deleted file mode 100644 index f77faecdf07cc5bd68ea2f75150631c0515841a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4103 zcmV+i5cuy^ZfSIRMpFO)000IxE_g0@05UK!I4(3UF*0T`000000000G2LJ#7K>z>% zTL1t6LmmJD0I~r90E5&301uP^K@I>29RL6t0Pq+91VceWEoNakI5{(6F=04nH!?J4 zI5jXbWHdB2GGQ}eG&V3fHvnA#00;m80AO$=AJ}mWpwa@dwG!?zO() zUWbIPy@#4z>hYhdRzkIdXXqN>^-BzR3};<^Eg&=NpmlL%Ygax}Dn9tF1}i~`JYl+Q zp!>ip#&-JY?9*Ug4--6hbj4njH(foYuWJ{Ayl2vAK)DW}Emfq;l@YoNHtcBdeU&uB zh!+3;Bjep(e1{i^JgECjfRl~Y;{EN9_=>CvcD!_N95y$V&t?;5iD{I3nATzI1y*&m zhmByxcO6w>txQIZxXmc5)=iT4BpUfdyPrBpqmlG3S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