using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("yijianpusediji")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("yijianpusediji")]
[assembly: AssemblyTitle("yijianpusediji")]
[assembly: AssemblyVersion("1.3.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace DSPFoundationTool
{
internal sealed class FoundationPaver
{
public const int FoundationItemId = 1131;
private const int MaxBrushSize = 10;
private const float BrushRadiusFactor = 0.990946f;
public static readonly string[] SpeedNames = new string[4] { "慢速", "标准", "快速", "极速" };
private readonly Vector3[] _points = (Vector3[])(object)new Vector3[100];
private readonly int[] _indices = new int[100];
private PlanetData _planet;
private int _cursor;
private int _placedThisRun;
private int _currentTarget = -1;
private bool _running;
private int _speedLevel = 1;
private bool _instantFillMode;
private string _status = "按 Alt+3 打开界面,点击按钮开始。";
public bool Running => _running;
public string Status => _status;
public int SpeedLevel => _speedLevel;
public bool InstantFillMode => _instantFillMode;
public void SetSpeed(int level)
{
_speedLevel = Mathf.Clamp(level, 0, SpeedNames.Length - 1);
}
public void RefreshStatus()
{
if (!_running)
{
Player mainPlayer = GameMain.mainPlayer;
if (!GameMain.isRunning || mainPlayer == null || GameMain.localPlanet == null)
{
_status = "请先进入游戏并降落到一颗星球上。";
return;
}
int availableFoundations = GetAvailableFoundations(mainPlayer);
_status = ((availableFoundations > 0) ? ("准备就绪:身上有 " + availableFoundations + " 个地基。") : "身上没有地基,请先补充地基。");
}
}
public void StartOrContinue()
{
_instantFillMode = false;
if (!GameMain.isRunning || GameMain.mainPlayer == null || GameMain.localPlanet == null)
{
_status = "请先进入游戏并降落到一颗星球上。";
return;
}
PlanetData localPlanet = GameMain.localPlanet;
if (GameMain.mainPlayer.planetData == null || GameMain.mainPlayer.planetData.id != localPlanet.id)
{
_status = "请先降落到当前星球表面再铺设。";
return;
}
if (localPlanet.factory == null || !localPlanet.factoryLoaded || localPlanet.factory.platformSystem == null || localPlanet.aux == null)
{
_status = "当前星球的工厂还没有加载完成,请稍后再试。";
return;
}
PlatformSystem platformSystem = localPlanet.factory.platformSystem;
platformSystem.EnsureReformData();
if (platformSystem.reformData == null || platformSystem.reformData.Length < platformSystem.maxReformCount)
{
_status = "当前星球的地基数据不完整,无法安全铺设。";
return;
}
if (_planet != localPlanet)
{
_planet = localPlanet;
_cursor = 0;
_placedThisRun = 0;
}
else if (_cursor >= platformSystem.maxReformCount)
{
_cursor = 0;
}
if (GetAvailableFoundations(GameMain.mainPlayer) <= 0)
{
_status = "身上没有地基,请先补充地基。";
return;
}
_running = true;
_status = "正在铺设地基……";
FoundationToolPlugin.Log.LogInfo((object)("Foundation paving started on planet " + localPlanet.displayName + "."));
}
public void FillAllInstantly()
{
if (!_running)
{
StartOrContinue();
}
if (_running)
{
_instantFillMode = true;
_status = "正在瞬间填充:本次携带的地基会在一帧内全部铺完……";
FoundationToolPlugin.Log.LogInfo((object)"Instant foundation fill started.");
}
}
public void Stop(string message)
{
_instantFillMode = false;
if (_running)
{
FoundationToolPlugin.Log.LogInfo((object)("Foundation paving stopped: " + message));
}
_running = false;
if (!string.IsNullOrEmpty(message))
{
_status = message;
}
}
public void Tick()
{
if (!_running || !GameMain.isRunning || GameMain.isPaused)
{
return;
}
Player mainPlayer = GameMain.mainPlayer;
if (mainPlayer == null)
{
Stop("玩家数据不可用,铺设停止。");
return;
}
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet == null || localPlanet != _planet || mainPlayer.planetData == null || mainPlayer.planetData.id != localPlanet.id)
{
Stop("已经离开当前星球,铺设停止。");
}
else if (localPlanet.factory == null || !localPlanet.factoryLoaded || localPlanet.factory.platformSystem == null || localPlanet.aux == null)
{
Stop("当前星球的工厂未加载,铺设停止。");
}
else if (_instantFillMode)
{
FillAllInstant(mainPlayer, localPlanet);
}
else
{
if (_speedLevel == 0 && (Time.frameCount & 1) != 0)
{
return;
}
int num = ((_speedLevel >= 3) ? 4 : ((_speedLevel != 2) ? 1 : 2));
for (int i = 0; i < num; i++)
{
if (!_running)
{
break;
}
try
{
ProcessOneBrush(mainPlayer, localPlanet);
}
catch (Exception ex)
{
_cursor = ((_currentTarget >= 0) ? _currentTarget : Math.Max(0, _cursor - 1));
Stop("铺设过程中发生错误,已停止。请查看日志。");
FoundationToolPlugin.Log.LogError((object)ex);
break;
}
}
}
}
private void FillAllInstant(Player player, PlanetData planet)
{
int num = 0;
int num2 = planet.factory.platformSystem.maxReformCount + 1;
while (_running && num++ < num2)
{
try
{
ProcessOneBrush(player, planet);
}
catch (Exception ex)
{
_cursor = ((_currentTarget >= 0) ? _currentTarget : Math.Max(0, _cursor - 1));
Stop("铺设过程中发生错误,已停止。请查看日志。");
FoundationToolPlugin.Log.LogError((object)ex);
break;
}
}
if (_running)
{
Stop("瞬间填充达到安全上限,已停止。");
}
}
private void ProcessOneBrush(Player player, PlanetData planet)
{
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_013d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
PlanetFactory factory = planet.factory;
PlatformSystem platformSystem = factory.platformSystem;
platformSystem.EnsureReformData();
int num = -1;
int maxReformCount = platformSystem.maxReformCount;
int num2 = default(int);
while (_cursor < maxReformCount)
{
num2 = _cursor++;
int num3 = num2;
if (platformSystem.reformData == null || num3 >= platformSystem.reformData.Length)
{
_cursor = maxReformCount;
break;
}
if (platformSystem.GetReformType(num3) == 0 && !IsBanned(platformSystem, num3))
{
num = (_currentTarget = num3);
break;
}
}
if (num < 0)
{
Stop("当前星球已经没有需要铺设的地基格了。");
return;
}
int availableFoundations = GetAvailableFoundations(player);
if (availableFoundations <= 0)
{
_cursor = num;
Stop(_instantFillMode ? "身上的地基已经全部用完。" : "地基不足,请补充地基后再点一次按钮。");
return;
}
BuildTool_Reform val = (((Object)(object)player.controller != (Object)null) ? player.controller.actionBuild : null)?.reformTool;
int num4 = ((val != null) ? Mathf.Clamp(val.brushColor, 0, 31) : 0);
int num5 = ((val == null) ? 1 : Mathf.Clamp(val.brushType, 1, 6));
Vector3 val2 = CellCenter(planet, platformSystem, num);
int num6 = 0;
int num7 = 0;
Vector3 val3 = Vector3.zero;
for (int num8 = 10; num8 >= 1; num8--)
{
int num9 = planet.aux.ReformSnap(val2, 0, num8, num5, num4, _points, _indices, platformSystem, ref val3);
if (num9 > 0 && num9 <= availableFoundations && num9 == num8 * num8 && Contains(_indices, num9, num) && !AnyBanned(platformSystem, _indices, num9))
{
num6 = num8;
num7 = num9;
break;
}
if (num8 == 1)
{
num6 = 1;
num7 = 1;
val3 = val2;
_points[0] = val2;
_indices[0] = num;
break;
}
}
if (num6 <= 0 || num7 <= 0)
{
_status = "遇到无法定位的地基格,已跳过。";
return;
}
int num10 = 0;
int num11 = 0;
float num12 = 0.990946f * (float)num6;
factory.ComputeFlattenTerrainReform(_points, val3, num12, num7, ref num10, ref num11, 3f, 1f);
int num13 = num10 - num11;
if (num13 > 0 && player.sandCount < num13)
{
_cursor = num;
Stop("沙土不足,铺设停止。请补充沙土后再点一次按钮。");
return;
}
factory.FlattenTerrainReform(val3, num12, num6, false, 3f);
for (int i = 0; i < num7; i++)
{
int num14 = _indices[i];
if (num14 >= 0)
{
platformSystem.SetReformType(num14, num5);
platformSystem.SetReformColor(num14, num4);
}
}
int num15 = num7;
int num16 = Math.Min((player.inhandItemId == 1131) ? player.inhandItemCount : 0, num15);
if (num16 > 0)
{
player.UseHandItems(num16, ref num2);
num15 -= num16;
}
if (num15 > 0)
{
int num17 = 1131;
player.package.TakeTailItems(ref num17, ref num15, ref num2, false);
}
int num18 = num7 - num15;
if (num18 < num7)
{
FoundationToolPlugin.Log.LogWarning((object)("Foundation item shortfall: needed " + num7 + ", consumed " + num18 + "."));
}
if (num13 != 0)
{
player.SetSandCount(player.sandCount - num13, (ESandSource)0);
}
try
{
GameMain.statistics.production.factoryStatPool[factory.index].consumeRegister[1131] += num7;
}
catch (Exception)
{
}
if (GameMain.history != null)
{
GameMain.history.MarkItemBuilt(1131, num7);
}
if (GameMain.gameScenario != null)
{
GameMain.gameScenario.NotifyOnBuild(planet.id, 1131, 0);
}
_placedThisRun += num7;
_status = "正在铺设:本次已铺 " + _placedThisRun + " 格,剩余地基 " + GetAvailableFoundations(player) + "。";
}
private static int GetAvailableFoundations(Player player)
{
int num = ((player.package != null) ? player.package.GetItemCount(1131) : 0);
if (player.inhandItemId == 1131)
{
num += player.inhandItemCount;
}
return num;
}
private static bool IsBanned(PlatformSystem platform, int index)
{
if (index >= 0 && platform.reformState != null && index < platform.reformState.Length)
{
return platform.IsReformBanned(index);
}
return false;
}
private static bool AnyBanned(PlatformSystem platform, int[] indices, int count)
{
for (int i = 0; i < count; i++)
{
if (IsBanned(platform, indices[i]))
{
return true;
}
}
return false;
}
private static bool Contains(int[] indices, int count, int target)
{
for (int i = 0; i < count; i++)
{
if (indices[i] == target)
{
return true;
}
}
return false;
}
private static Vector3 CellCenter(PlanetData planet, PlatformSystem platform, int index)
{
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
int[] reformOffsets = platform.reformOffsets;
int num = 0;
int num2 = reformOffsets.Length - 1;
while (num + 1 < num2)
{
int num3 = num + num2 >> 1;
if (reformOffsets[num3] <= index)
{
num = num3;
}
else
{
num2 = num3;
}
}
int num4 = num;
int num5 = reformOffsets[num4 + 1] - reformOffsets[num4];
int num6 = index - reformOffsets[num4];
int num7 = num5 / 2;
float num8 = ((num6 < num7) ? (((float)num6 + 0.5f) / 5f) : (((float)(num7 - num6) - 0.5f) / 5f));
int num9 = platform.latitudeCount / 2;
float num10 = ((num4 < num9) ? (((float)num4 + 0.5f) / 5f) : (((float)(num9 - num4) - 0.5f) / 5f)) / (float)platform.segment * (MathF.PI * 2f);
int num11 = Math.Max(1, num5 / 5);
float num12 = num8 / (float)num11 * (MathF.PI * 2f);
float num13 = Mathf.Cos(num10);
return new Vector3(num13 * Mathf.Sin(num12), Mathf.Sin(num10), num13 * (0f - Mathf.Cos(num12))) * (planet.radius + 0.2f);
}
}
[BepInPlugin("leidapao.yijianpusediji", "yijianpusediji", "1.3.0")]
public sealed class FoundationToolPlugin : BaseUnityPlugin
{
public const string PluginGuid = "leidapao.yijianpusediji";
public const string PluginName = "yijianpusediji";
public const string PluginVersion = "1.3.0";
internal static ManualLogSource Log;
private FoundationPaver _paver;
private bool _windowVisible;
private bool _inputBlocked;
private Rect _windowRect = new Rect(80f, 80f, 390f, 410f);
private ConfigEntry<int> _speedConfig;
private Font _font;
private GUIStyle _windowStyle;
private GUIStyle _labelStyle;
private GUIStyle _buttonStyle;
private GUIStyle _speedButtonStyle;
private void Awake()
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
_paver = new FoundationPaver();
_speedConfig = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SpeedLevel", 1, new ConfigDescription("0=slow, 1=standard, 2=fast, 3=extreme", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 3), Array.Empty<object>()));
_paver.SetSpeed(_speedConfig.Value);
Log.LogInfo((object)"yijianpusediji loaded. Press Alt+3 to open the foundation window.");
}
private void Update()
{
if ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && (Input.GetKeyDown((KeyCode)51) || Input.GetKeyDown((KeyCode)259)) && !VFInput.inputing)
{
_windowVisible = !_windowVisible;
if (_windowVisible)
{
_paver.RefreshStatus();
}
}
if (_windowVisible)
{
VFInput.onGUI = true;
VFInput.onGUIOperate = true;
UICursor.SetLockCursorDirect(false);
_inputBlocked = true;
}
else if (_inputBlocked)
{
VFInput.onGUI = false;
VFInput.onGUIOperate = false;
_inputBlocked = false;
}
if (_paver != null)
{
_paver.Tick();
}
}
private void OnGUI()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
if (_windowVisible && !((Object)(object)GameMain.instance == (Object)null))
{
EnsureStyles();
if ((Object)(object)_font != (Object)null)
{
GUI.skin.font = _font;
}
_windowRect = GUI.Window(114514, _windowRect, new WindowFunction(DrawWindow), "地基铺设工具", _windowStyle);
}
}
private void DrawWindow(int id)
{
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010a: Unknown result type (might be due to invalid IL or missing references)
//IL_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Unknown result type (might be due to invalid IL or missing references)
Player mainPlayer = GameMain.mainPlayer;
PlanetData localPlanet = GameMain.localPlanet;
GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
GUILayout.Space(4f);
if (!GameMain.isRunning || mainPlayer == null)
{
GUILayout.Label("请先进入游戏并降落到一颗星球上。", _labelStyle, Array.Empty<GUILayoutOption>());
}
else
{
string text = ((localPlanet != null) ? localPlanet.displayName : "未知");
int num = ((mainPlayer.package != null) ? mainPlayer.package.GetItemCount(1131) : 0);
if (mainPlayer.inhandItemId == 1131)
{
num += mainPlayer.inhandItemCount;
}
GUILayout.Label("当前星球:" + text, _labelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Label("身上地基:" + num + " 沙土:" + mainPlayer.sandCount, _labelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Space(4f);
GUILayout.Label("铺设速度(越高越吃 CPU)", _labelStyle, Array.Empty<GUILayoutOption>());
GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
for (int i = 0; i < FoundationPaver.SpeedNames.Length; i++)
{
Color backgroundColor = GUI.backgroundColor;
if (_paver.SpeedLevel == i)
{
GUI.backgroundColor = new Color(0.45f, 0.85f, 0.45f);
}
if (GUILayout.Button(FoundationPaver.SpeedNames[i], _speedButtonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
{
_paver.SetSpeed(i);
_speedConfig.Value = i;
}
GUI.backgroundColor = backgroundColor;
}
GUILayout.EndHorizontal();
GUILayout.Space(6f);
if (GUILayout.Button("一键铺设地基", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(42f) }))
{
if (_paver.Running)
{
_paver.Stop("已停止。");
}
else
{
_paver.StartOrContinue();
}
}
GUILayout.Space(4f);
Color backgroundColor2 = GUI.backgroundColor;
if (_paver.InstantFillMode)
{
GUI.backgroundColor = new Color(0.45f, 0.85f, 0.45f);
}
if (GUILayout.Button("瞬间填充", _buttonStyle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(36f) }))
{
_paver.FillAllInstantly();
}
GUI.backgroundColor = backgroundColor2;
GUILayout.Label("瞬间填充会在一帧内把身上的地基全部铺完;地基很多时可能卡顿。", _labelStyle, Array.Empty<GUILayoutOption>());
GUILayout.Space(6f);
GUILayout.Label(_paver.Status, _labelStyle, Array.Empty<GUILayoutOption>());
}
GUILayout.FlexibleSpace();
GUILayout.Label("Alt+3 打开/关闭", _labelStyle, Array.Empty<GUILayoutOption>());
GUILayout.EndVertical();
GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
}
private void EnsureStyles()
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Expected O, but got Unknown
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Expected O, but got Unknown
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Expected O, but got Unknown
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Expected O, but got Unknown
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Expected O, but got Unknown
if ((Object)(object)_font == (Object)null)
{
try
{
_font = Font.CreateDynamicFontFromOSFont(new string[4] { "Microsoft YaHei UI", "Microsoft YaHei", "SimHei", "Arial Unicode MS" }, 16);
}
catch (Exception)
{
_font = null;
}
if ((Object)(object)_font == (Object)null)
{
_font = GUI.skin.font;
}
}
if (_windowStyle == null)
{
_windowStyle = new GUIStyle(GUI.skin.window);
_windowStyle.font = _font;
_windowStyle.fontSize = 15;
_windowStyle.padding = new RectOffset(10, 10, 24, 10);
}
if (_labelStyle == null)
{
_labelStyle = new GUIStyle(GUI.skin.label);
_labelStyle.font = _font;
_labelStyle.fontSize = 15;
_labelStyle.wordWrap = true;
}
if (_buttonStyle == null)
{
_buttonStyle = new GUIStyle(GUI.skin.button);
_buttonStyle.font = _font;
_buttonStyle.fontSize = 18;
}
if (_speedButtonStyle == null)
{
_speedButtonStyle = new GUIStyle(GUI.skin.button);
_speedButtonStyle.font = _font;
_speedButtonStyle.fontSize = 14;
}
}
private void OnDestroy()
{
if (_paver != null)
{
_paver.Stop("模组已卸载。");
}
}
}
}