1
0
mirror of https://github.com/soarqin/DSP_Mods.git synced 2025-12-08 21:33:28 +08:00

Dustbin v1.2.1, fixes #2

This commit is contained in:
2022-12-07 17:04:53 +08:00
parent 264748e6fa
commit 97af764e92
4 changed files with 31 additions and 11 deletions

View File

@@ -4,7 +4,7 @@
<TargetFramework>net472</TargetFramework>
<BepInExPluginGuid>org.soardev.dustbin</BepInExPluginGuid>
<Description>DSP MOD - Dustbin</Description>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<PackageId>Dustbin</PackageId>

View File

@@ -5,6 +5,9 @@
## Updates
* 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.

View File

@@ -1,6 +1,7 @@
using System;
using System.IO;
using HarmonyLib;
using HarmonyLib.Tools;
namespace Dustbin;
@@ -8,7 +9,7 @@ using IsDustbinIndexer = DynamicObjectArray<DynamicObjectArray<DynamicValueArray
public class DynamicValueArray<T> where T: struct
{
private T[] _store = new T[16];
private T[] _store = new T[64];
public T this[int index]
{
@@ -21,7 +22,12 @@ public class DynamicValueArray<T> where T: struct
{
if (index >= _store.Length)
{
Array.Resize(ref _store, _store.Length * 2);
var count = index | (index >> 1);
count |= count >> 2;
count |= count >> 4;
count |= count >> 8;
count |= count >> 16;
Array.Resize(ref _store, count + 1);
}
_store[index] = value;
}
@@ -51,13 +57,21 @@ public class DynamicObjectArray<T> where T: class, new()
{
get
{
if (index < 0 || index >= _store.Length) return null;
var result = _store[index];
if (result == null)
if (index < 0) return null;
if (index >= _store.Length)
{
result = new T();
_store[index] = result;
var count = index | (index >> 1);
count |= count >> 2;
count |= count >> 4;
count |= count >> 8;
count |= count >> 16;
Array.Resize(ref _store, count + 1);
}
T result = _store[index];
if (result != null)
return result;
result = new T();
_store[index] = result;
return result;
}
}
@@ -129,10 +143,13 @@ public static class TankPatch
{
r.ReadByte();
var planetId = r.ReadInt32();
var data = tankIsDustbin[planetId / 100][planetId % 100];
var data = tankIsDustbin[15];
data[0][0] = true;
data = tankIsDustbin[20];
data[0][0] = true;
for (var count = r.ReadInt32(); count > 0; count--)
{
data[r.ReadInt32()] = true;
tankIsDustbin[planetId / 100][planetId % 100][r.ReadInt32()] = true;
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "Dustbin",
"version_number": "1.2.0",
"version_number": "1.2.1",
"website_url": "https://github.com/soarqin/DSP_Mods/tree/master/Dustbin",
"description": "Can turn Storages and Tanks into Dustbin(Destroy incoming items) / 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品)",
"dependencies": [