mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 16:13:31 +08:00
Dustbin v1.1.0 release
This commit is contained in:
@@ -1,8 +1,44 @@
|
||||
using BepInEx;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Dustbin;
|
||||
|
||||
class IsDusbinIndexer
|
||||
{
|
||||
private bool[] store = new bool[256];
|
||||
|
||||
public bool this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index >= store.Length) return false;
|
||||
return store[index];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index >= store.Length)
|
||||
{
|
||||
var oldLen = store.Length;
|
||||
var newLen = oldLen * 2;
|
||||
var oldArr = store;
|
||||
store = new bool[newLen];
|
||||
Array.Copy(oldArr, store, oldLen);
|
||||
}
|
||||
store[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
store = new bool[256];
|
||||
}
|
||||
}
|
||||
|
||||
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
|
||||
public class Dustbin : BaseUnityPlugin
|
||||
{
|
||||
@@ -10,8 +46,8 @@ public class Dustbin : BaseUnityPlugin
|
||||
BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME);
|
||||
|
||||
private bool _cfgEnabled = true;
|
||||
private static readonly int[] SandsFactors = { 0, 1, 5, 10, 100 };
|
||||
private static readonly bool[] IsFluid = new bool[2000];
|
||||
public static readonly int[] SandsFactors = { 0, 1, 5, 10, 100 };
|
||||
public static bool[] IsFluid;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -22,55 +58,25 @@ public class Dustbin : BaseUnityPlugin
|
||||
SandsFactors[3] = Config.Bind("General", "SandsPerSilicon", SandsFactors[3], "Sands gathered from silicon ores").Value;
|
||||
SandsFactors[4] = Config.Bind("General", "SandsPerFractal", SandsFactors[4], "Sands gathered from fractal silicon ores").Value;
|
||||
Harmony.CreateAndPatchAll(typeof(Dustbin));
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(GameDesc))]
|
||||
[HarmonyPatch(typeof(DSPGame), "StartGame", typeof(string))]
|
||||
private static void OnGameStart()
|
||||
{
|
||||
foreach (var data in LDB.items.dataArray)
|
||||
{
|
||||
if (data.ID < 2000 && data.IsFluid)
|
||||
{
|
||||
IsFluid[data.ID] = true;
|
||||
}
|
||||
}
|
||||
Harmony.CreateAndPatchAll(typeof(StoragePatch));
|
||||
Harmony.CreateAndPatchAll(typeof(TankPatch));
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(StorageComponent), "AddItem",
|
||||
new[] { typeof(int), typeof(int), typeof(int), typeof(int), typeof(bool) },
|
||||
new[]
|
||||
{
|
||||
ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Normal, ArgumentType.Out, ArgumentType.Normal
|
||||
})]
|
||||
public static bool AbandonItems(ref int __result, StorageComponent __instance, int itemId, int count, int inc,
|
||||
out int remainInc, bool useBan = false)
|
||||
[HarmonyPatch(typeof(GameMain), "Start")]
|
||||
private static void GameMain_Start_Prefix()
|
||||
{
|
||||
remainInc = inc;
|
||||
if (!useBan || count == 0 || __instance.id != __instance.top) return true;
|
||||
var size = __instance.size;
|
||||
if (size == 0 || size != __instance.bans || __instance.grids[0].count > 0) return true;
|
||||
__result = count;
|
||||
var isFluid = itemId < 2000 && IsFluid[itemId];
|
||||
var sandsPerItem = SandsFactors[isFluid
|
||||
? 0
|
||||
: itemId switch
|
||||
{
|
||||
1005 => 2,
|
||||
1003 => 3,
|
||||
1013 => 4,
|
||||
_ => 1,
|
||||
}];
|
||||
if (sandsPerItem <= 0) return false;
|
||||
var player = GameMain.mainPlayer;
|
||||
var addCount = count * sandsPerItem;
|
||||
player.sandCount += addCount;
|
||||
GameMain.history.OnSandCountChange(player.sandCount, addCount);
|
||||
/* Following line crashes game, seems that it should not be called in this working thread:
|
||||
* UIRoot.instance.uiGame.OnSandCountChanged(player.sandCount, addCount);
|
||||
*/
|
||||
return false;
|
||||
StoragePatch.Reset();
|
||||
TankPatch.Reset();
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(VFPreload), "InvokeOnLoadWorkEnded")]
|
||||
private static void VFPreload_InvokeOnLoadWorkEnded_Postfix()
|
||||
{
|
||||
var maxId = ItemProto.fluids.Max();
|
||||
IsFluid = new bool[maxId + 1];
|
||||
foreach (var id in ItemProto.fluids)
|
||||
IsFluid[id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user