mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 02:53:29 +08:00
CheatEnabler v2.2.3
This commit is contained in:
@@ -1,113 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using HarmonyLib;
|
||||
using System.Threading;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace CheatEnabler;
|
||||
public static class PlanetFunctions
|
||||
{
|
||||
/*
|
||||
private static Harmony _patch;
|
||||
private static PumpSource[] _pumpItemSources = new PumpSource[16];
|
||||
private static int _pumpItemSourcesLength = 16;
|
||||
|
||||
private class PumpSource
|
||||
{
|
||||
public Tuple<int, float>[] Items;
|
||||
public float[] Progress;
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
if (_patch != null) return;
|
||||
_patch = Harmony.CreateAndPatchAll(typeof(PlanetFunctions));
|
||||
}
|
||||
|
||||
public static void Uninit()
|
||||
{
|
||||
_patch?.UnpatchSelf();
|
||||
_patch = null;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))]
|
||||
private static void GameMain_Begin_Postfix()
|
||||
{
|
||||
InitItemSources();
|
||||
var factories = GameMain.data.factories;
|
||||
for (var i = GameMain.data.factoryCount - 1; i >= 0; i--)
|
||||
{
|
||||
if (factories[i].index != i) continue;
|
||||
UpdatePumpItemSources(factories[i]);
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(PlanetFactory), nameof(PlanetFactory.Init))]
|
||||
private static void PlanetFactory_Init_Postfix(PlanetFactory __instance)
|
||||
{
|
||||
const int waterItemId = 6006;
|
||||
__instance.planet.waterItemId = waterItemId;
|
||||
CheatEnabler.Logger.LogDebug($"Init PlanetFactory with waterItemId {waterItemId}");
|
||||
UpdatePumpItemSources(__instance);
|
||||
}
|
||||
|
||||
private static void UpdatePumpItemSources(PlanetFactory factory)
|
||||
{
|
||||
var index = factory.index;
|
||||
var waterItemId = factory.planet.waterItemId;
|
||||
if (waterItemId == 0 || !ItemSources.TryGetValue(waterItemId, out var itemSource) || itemSource.From == null)
|
||||
{
|
||||
if (index < _pumpItemSourcesLength)
|
||||
{
|
||||
_pumpItemSources[index] = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (index >= _pumpItemSourcesLength)
|
||||
{
|
||||
var newLength = _pumpItemSourcesLength * 2;
|
||||
while (index >= newLength)
|
||||
{
|
||||
newLength *= 2;
|
||||
}
|
||||
var newPumpItemSources = new PumpSource[newLength];
|
||||
Array.Copy(_pumpItemSources, newPumpItemSources, _pumpItemSourcesLength);
|
||||
_pumpItemSources = newPumpItemSources;
|
||||
_pumpItemSourcesLength = newLength;
|
||||
}
|
||||
var pump = _pumpItemSources[index];
|
||||
if (pump == null)
|
||||
{
|
||||
pump = new PumpSource();
|
||||
_pumpItemSources[index] = pump;
|
||||
}
|
||||
|
||||
var result = new Dictionary<int, float>();
|
||||
var extra = new Dictionary<int, float>();
|
||||
CalculateAllProductions(result, extra, waterItemId, 1f);
|
||||
foreach (var p in extra)
|
||||
{
|
||||
if (!result.TryGetValue(p.Key, out var cnt) || cnt < p.Value)
|
||||
{
|
||||
result[p.Key] = p.Value;
|
||||
}
|
||||
}
|
||||
|
||||
var count = result.Count;
|
||||
var items = new Tuple<int, float>[count];
|
||||
var progress = new float[count];
|
||||
foreach (var p in result)
|
||||
{
|
||||
items[--count] = Tuple.Create(p.Key, p.Value);
|
||||
}
|
||||
pump.Items = items;
|
||||
pump.Progress = progress;
|
||||
}
|
||||
*/
|
||||
|
||||
public static void DismantleAll(bool toBag)
|
||||
{
|
||||
var player = GameMain.mainPlayer;
|
||||
|
||||
Reference in New Issue
Block a user