mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-08 19:33:27 +08:00
work in progress
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Random = UnityEngine.Random;
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace CheatEnabler.Functions;
|
namespace CheatEnabler.Functions;
|
||||||
|
|
||||||
public static class PlanetFunctions
|
public static class PlanetFunctions
|
||||||
{
|
{
|
||||||
public static void BuryAllVeins(bool bury)
|
public static void BuryAllVeins(bool bury)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using HarmonyLib;
|
|||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
|
||||||
namespace CheatEnabler.Patches;
|
namespace CheatEnabler.Patches;
|
||||||
|
|
||||||
public static class PlanetPatch
|
public static class PlanetPatch
|
||||||
{
|
{
|
||||||
public static ConfigEntry<bool> WaterPumpAnywhereEnabled;
|
public static ConfigEntry<bool> WaterPumpAnywhereEnabled;
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ class BlueprintTweaks
|
|||||||
new CodeMatch(OpCodes.Callvirt)
|
new CodeMatch(OpCodes.Callvirt)
|
||||||
).RemoveInstructions(5);
|
).RemoveInstructions(5);
|
||||||
matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0),
|
matcher.InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0),
|
||||||
Transpilers.EmitDelegate((UIBuildingGrid grid) => {
|
Transpilers.EmitDelegate((UIBuildingGrid grid) =>
|
||||||
|
{
|
||||||
grid.material.SetFloat(reformMode, 0f);
|
grid.material.SetFloat(reformMode, 0f);
|
||||||
grid.material.SetFloat(zMin, -0.5f);
|
grid.material.SetFloat(zMin, -0.5f);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Reflection.Emit;
|
using System.Reflection.Emit;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Networking;
|
||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
|
||||||
namespace UXAssist.Patches;
|
namespace UXAssist.Patches;
|
||||||
@@ -170,4 +172,157 @@ public class PersistPatch : PatchImpl<PersistPatch>
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Cluster Upload Result
|
||||||
|
|
||||||
|
const int ClusterUploadResultKeepCount = 100;
|
||||||
|
private static readonly ClusterUploadResult[] _clusterUploadResults = new ClusterUploadResult[ClusterUploadResultKeepCount];
|
||||||
|
private static readonly object _clusterUploadResultsLock = new();
|
||||||
|
private static int _clusterUploadResultsHead = 0;
|
||||||
|
private static int _clusterUploadResultsCount = 0;
|
||||||
|
private static ClusterPlayerData[] _topTenPlayerData = null;
|
||||||
|
|
||||||
|
private struct ClusterUploadResult
|
||||||
|
{
|
||||||
|
public DateTime UploadTime;
|
||||||
|
public int Result;
|
||||||
|
public float RequestTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AddClusterUploadResult(int result, float requestTime)
|
||||||
|
{
|
||||||
|
lock (_clusterUploadResultsLock)
|
||||||
|
{
|
||||||
|
if (_clusterUploadResultsCount >= ClusterUploadResultKeepCount)
|
||||||
|
{
|
||||||
|
_clusterUploadResults[_clusterUploadResultsHead] = new ClusterUploadResult { UploadTime = DateTime.Now, Result = result, RequestTime = requestTime };
|
||||||
|
_clusterUploadResultsHead = (_clusterUploadResultsHead + 1) % ClusterUploadResultKeepCount;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_clusterUploadResults[(_clusterUploadResultsHead + _clusterUploadResultsCount) % ClusterUploadResultKeepCount] = new ClusterUploadResult { UploadTime = DateTime.Now, Result = result, RequestTime = requestTime };
|
||||||
|
_clusterUploadResultsCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExportClusterUploadResults(BinaryWriter w)
|
||||||
|
{
|
||||||
|
lock (_clusterUploadResultsLock)
|
||||||
|
{
|
||||||
|
w.Write(_clusterUploadResultsCount);
|
||||||
|
w.Write(_clusterUploadResultsHead);
|
||||||
|
for (var i = 0; i < _clusterUploadResultsCount; i++)
|
||||||
|
{
|
||||||
|
ref var result = ref _clusterUploadResults[(i + _clusterUploadResultsHead) % ClusterUploadResultKeepCount];
|
||||||
|
w.Write(result.UploadTime.ToBinary());
|
||||||
|
w.Write(result.Result);
|
||||||
|
w.Write(result.RequestTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ImportClusterUploadResults(BinaryReader r)
|
||||||
|
{
|
||||||
|
lock (_clusterUploadResultsLock)
|
||||||
|
{
|
||||||
|
_clusterUploadResultsCount = r.ReadInt32();
|
||||||
|
_clusterUploadResultsHead = r.ReadInt32();
|
||||||
|
for (var i = 0; i < _clusterUploadResultsCount; i++)
|
||||||
|
{
|
||||||
|
ref var result = ref _clusterUploadResults[(i + _clusterUploadResultsHead) % ClusterUploadResultKeepCount];
|
||||||
|
result.UploadTime = DateTime.FromBinary(r.ReadInt64());
|
||||||
|
result.Result = r.ReadInt32();
|
||||||
|
result.RequestTime = r.ReadSingle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(MilkyWayWebClient), nameof(MilkyWayWebClient.OnUploadLoginErrored))]
|
||||||
|
private static void MilkyWayWebClient_OnUploadLoginErrored_Postfix(MilkyWayWebClient __instance, DSPWeb.HTTP_ERROR_TYPE errorType, string errorInfo, int errorCode)
|
||||||
|
{
|
||||||
|
switch (errorType)
|
||||||
|
{
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.NETWORK_ERROR:
|
||||||
|
AddClusterUploadResult(-10001, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.HTTP_ERROR:
|
||||||
|
AddClusterUploadResult(-10010 - errorCode, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.USER_ABORT:
|
||||||
|
AddClusterUploadResult(-10003, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.UNEXPECTED_ERROR:
|
||||||
|
AddClusterUploadResult(-10004, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(MilkyWayWebClient), nameof(MilkyWayWebClient.OnUploadErrored))]
|
||||||
|
private static void MilkyWayWebClient_OnUploadErrored_Postfix(MilkyWayWebClient __instance, DSPWeb.HTTP_ERROR_TYPE errorType, string errorInfo, int errorCode)
|
||||||
|
{
|
||||||
|
switch (errorType)
|
||||||
|
{
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.NETWORK_ERROR:
|
||||||
|
AddClusterUploadResult(-101, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.HTTP_ERROR:
|
||||||
|
AddClusterUploadResult(-110 - errorCode, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.USER_ABORT:
|
||||||
|
AddClusterUploadResult(-103, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
case DSPWeb.HTTP_ERROR_TYPE.UNEXPECTED_ERROR:
|
||||||
|
AddClusterUploadResult(-104, (float)__instance.uploadRequest.reqTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPostfix]
|
||||||
|
[HarmonyPatch(typeof(MilkyWayWebClient), nameof(MilkyWayWebClient.OnUploadSucceed))]
|
||||||
|
private static void MilkyWayWebClient_OnUploadSucceed_Postfix(MilkyWayWebClient __instance, DownloadHandler handler)
|
||||||
|
{
|
||||||
|
if (!int.TryParse(handler.text, out var rcode))
|
||||||
|
rcode = -1;
|
||||||
|
AddClusterUploadResult(rcode, (float)__instance.uploadRequest.reqTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyTranspiler]
|
||||||
|
[HarmonyPatch(typeof(MilkyWayCache), nameof(MilkyWayCache.LoadTopTenPlayerData))]
|
||||||
|
private static IEnumerable<CodeInstruction> MilkyWayCache_LoadTopTenPlayerData_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||||
|
{
|
||||||
|
var matcher = new CodeMatcher(instructions, generator);
|
||||||
|
|
||||||
|
matcher.MatchForward(false,
|
||||||
|
new CodeMatch(OpCodes.Ldarg_1),
|
||||||
|
new CodeMatch(OpCodes.Callvirt, AccessTools.PropertyGetter(typeof(BinaryReader), nameof(BinaryReader.ReadInt32)))
|
||||||
|
).Advance(2).InsertAndAdvance(
|
||||||
|
new CodeInstruction(OpCodes.Dup),
|
||||||
|
Transpilers.EmitDelegate((int count) => _topTenPlayerData = new ClusterPlayerData[count])
|
||||||
|
);
|
||||||
|
|
||||||
|
matcher.MatchForward(false,
|
||||||
|
new CodeMatch(OpCodes.Ldloca_S),
|
||||||
|
new CodeMatch(OpCodes.Ldarg_1),
|
||||||
|
new CodeMatch(OpCodes.Callvirt),
|
||||||
|
new CodeMatch(OpCodes.Stfld, AccessTools.Field(typeof(ClusterPlayerData), nameof(ClusterPlayerData.isAnon)))
|
||||||
|
);
|
||||||
|
var objloc = matcher.Operand;
|
||||||
|
matcher.Advance(4);
|
||||||
|
var iinstr = matcher.Instruction.Clone();
|
||||||
|
matcher.InsertAndAdvance(
|
||||||
|
iinstr,
|
||||||
|
new CodeInstruction(OpCodes.Ldloca_S, objloc),
|
||||||
|
Transpilers.EmitDelegate((int index, ref ClusterPlayerData playerData) =>
|
||||||
|
{
|
||||||
|
if (index < _topTenPlayerData.Length) _topTenPlayerData[index] = playerData;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return matcher.InstructionEnumeration();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using HarmonyLib;
|
|||||||
using UXAssist.Common;
|
using UXAssist.Common;
|
||||||
|
|
||||||
namespace UXAssist.Patches;
|
namespace UXAssist.Patches;
|
||||||
|
|
||||||
public static class PlanetPatch
|
public static class PlanetPatch
|
||||||
{
|
{
|
||||||
public static ConfigEntry<bool> PlayerActionsInGlobeViewEnabled;
|
public static ConfigEntry<bool> PlayerActionsInGlobeViewEnabled;
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ public static class UIConfigWindow
|
|||||||
PressShiftToTakeWholeBeltItemsEnabledChanged(null, null);
|
PressShiftToTakeWholeBeltItemsEnabledChanged(null, null);
|
||||||
|
|
||||||
void PressShiftToTakeWholeBeltItemsEnabledChanged(object o, EventArgs e)
|
void PressShiftToTakeWholeBeltItemsEnabledChanged(object o, EventArgs e)
|
||||||
{
|
{
|
||||||
includeBranches.SetEnable(FactoryPatch.PressShiftToTakeWholeBeltItemsEnabled.Value);
|
includeBranches.SetEnable(FactoryPatch.PressShiftToTakeWholeBeltItemsEnabled.Value);
|
||||||
includeInserters.SetEnable(FactoryPatch.PressShiftToTakeWholeBeltItemsEnabled.Value);
|
includeInserters.SetEnable(FactoryPatch.PressShiftToTakeWholeBeltItemsEnabled.Value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,12 +33,13 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
|||||||
private readonly Harmony _harmony = new(PluginInfo.PLUGIN_GUID);
|
private readonly Harmony _harmony = new(PluginInfo.PLUGIN_GUID);
|
||||||
|
|
||||||
#region IModCanSave
|
#region IModCanSave
|
||||||
private const ushort ModSaveVersion = 1;
|
private const ushort ModSaveVersion = 2;
|
||||||
|
|
||||||
public void Export(BinaryWriter w)
|
public void Export(BinaryWriter w)
|
||||||
{
|
{
|
||||||
w.Write(ModSaveVersion);
|
w.Write(ModSaveVersion);
|
||||||
FactoryPatch.Export(w);
|
FactoryPatch.Export(w);
|
||||||
|
PersistPatch.ExportClusterUploadResults(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Import(BinaryReader r)
|
public void Import(BinaryReader r)
|
||||||
@@ -46,6 +47,10 @@ public class UXAssist : BaseUnityPlugin, IModCanSave
|
|||||||
var version = r.ReadUInt16();
|
var version = r.ReadUInt16();
|
||||||
if (version <= 0) return;
|
if (version <= 0) return;
|
||||||
FactoryPatch.Import(r);
|
FactoryPatch.Import(r);
|
||||||
|
if (version > 1)
|
||||||
|
{
|
||||||
|
PersistPatch.ImportClusterUploadResults(r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IntoOtherSave()
|
public void IntoOtherSave()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using HarmonyLib;
|
|||||||
using GameLogicProc = UXAssist.Common.GameLogic;
|
using GameLogicProc = UXAssist.Common.GameLogic;
|
||||||
|
|
||||||
namespace UniverseGenTweaks;
|
namespace UniverseGenTweaks;
|
||||||
|
|
||||||
public static class BirthPlanetPatch
|
public static class BirthPlanetPatch
|
||||||
{
|
{
|
||||||
public static ConfigEntry<bool> SitiVeinsOnBirthPlanet;
|
public static ConfigEntry<bool> SitiVeinsOnBirthPlanet;
|
||||||
|
|||||||
Reference in New Issue
Block a user