using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.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 HoverCoord
{
[BepInPlugin("dsh.hovercoord", "HoverCoord", "1.10.11")]
public class HoverCoordPlugin : BaseUnityPlugin
{
private struct NearbyScanResult
{
public bool anyNearby;
public bool hasGapX;
public float gapXCells;
public bool hasGapZ;
public float gapZCells;
public bool hasSameTower;
public float towerCenterCells;
}
private struct CachedBuilding
{
public Vector3 pos;
public int protoId;
public float lonGrid;
public float latGrid;
public string towerCategory;
}
public const string Guid = "dsh.hovercoord";
private const float LayerHeight = 1.3333333f;
private const float GroundOffset = 0.2f;
private const float DetectInterval = 0.75f;
private const float RebuildInterval = 0.1f;
private const float OutputMargin = 0.005f;
private bool active;
private ConfigEntry<KeyboardShortcut> hotkeyConfig;
private ConfigEntry<bool> startEnabledConfig;
private static readonly StringBuilder builder = new StringBuilder(256);
private static readonly Dictionary<int, string> nameCache = new Dictionary<int, string>(64);
private HoverCoordRenderer renderer;
private PlanetData lastPlanet;
private EntityData lastEntity;
private bool visible;
private float nextDetectTime;
private float lastBuildTime;
private bool toastActive;
private float toastUntil;
private bool errorLogged;
private static PlanetData cachedScanPlanet;
private static readonly Dictionary<int, CachedBuilding> buildingCache = new Dictionary<int, CachedBuilding>(4096);
private void Awake()
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
hotkeyConfig = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "开关快捷键", new KeyboardShortcut((KeyCode)107, (KeyCode[])(object)new KeyCode[2]
{
(KeyCode)306,
(KeyCode)304
}), "切换指针坐标显示的快捷键(格式:主键+修饰键,如 K+LeftControl+LeftShift)");
startEnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "默认开启", false, "游戏启动后指针坐标显示是否默认开启(当前默认关闭)");
active = startEnabledConfig.Value;
renderer = CreateRenderer();
renderer.Hide();
((BaseUnityPlugin)this).Logger.LogInfo((object)"HoverCoord 1.10.9 loaded (debug). Author: 妙妙在路上 (抖音@妙妙在路上)");
}
private HoverCoordRenderer CreateRenderer()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("HoverCoordRenderer");
val.transform.SetParent(((Component)this).transform, false);
return val.AddComponent<HoverCoordRenderer>();
}
private void Update()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)renderer == (Object)null)
{
renderer = CreateRenderer();
renderer.Hide();
visible = false;
}
KeyboardShortcut value = hotkeyConfig.Value;
if (((KeyboardShortcut)(ref value)).IsDown())
{
active = !active;
ShowToast(active ? "指针坐标:开" : "指针坐标:关");
nextDetectTime = 0f;
}
if (toastActive)
{
if (Time.unscaledTime < toastUntil)
{
return;
}
toastActive = false;
HideTip();
nextDetectTime = 0f;
}
if (!active)
{
if (visible)
{
HideTip();
}
}
else
{
if (!(Time.unscaledTime >= nextDetectTime))
{
return;
}
nextDetectTime = Time.unscaledTime + 0.75f;
try
{
UpdateHover();
}
catch (Exception ex)
{
HideTip();
if (!errorLogged)
{
errorLogged = true;
((BaseUnityPlugin)this).Logger.LogWarning((object)("HoverCoord: " + ex));
}
}
}
}
private static bool ControlHeld()
{
if (!Input.GetKey((KeyCode)306))
{
return Input.GetKey((KeyCode)305);
}
return true;
}
private static bool ShiftHeld()
{
if (!Input.GetKey((KeyCode)304))
{
return Input.GetKey((KeyCode)303);
}
return true;
}
private void UpdateHover()
{
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_0114: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
if (!Application.isFocused || VFInput.onGUI || VFInput.inFullscreenGUI || !VFInput.inScreen || (Object)(object)GameMain.instance == (Object)null || GameMain.isPaused || !GameMain.isRunning)
{
HideTip();
return;
}
PlanetData localPlanet = GameMain.localPlanet;
if (localPlanet == null || !localPlanet.factoryLoaded)
{
HideTip();
return;
}
PlanetPhysics physics = localPlanet.physics;
if (physics == null)
{
HideTip();
return;
}
RaycastLogic raycastLogic = physics.raycastLogic;
if (raycastLogic == null || !raycastLogic.castSucceed)
{
HideTip();
return;
}
EntityData castEntity = raycastLogic.castEntity;
if (castEntity.id <= 0)
{
HideTip();
}
else if ((!visible || castEntity.id != lastEntity.id || localPlanet != lastPlanet || !(castEntity.pos == lastEntity.pos)) && (!visible || !(Time.unscaledTime - lastBuildTime < 0.1f)))
{
if (!BuildTip(localPlanet, castEntity))
{
HideTip();
return;
}
lastBuildTime = Time.unscaledTime;
lastPlanet = localPlanet;
lastEntity = castEntity;
}
}
private bool BuildTip(PlanetData planet, EntityData entity)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0265: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: 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)
Vector3 pos = entity.pos;
float magnitude = ((Vector3)(ref pos)).magnitude;
if (magnitude < 0.001f)
{
return false;
}
Vector3 val = pos / magnitude;
int num = 200;
PlanetAuxData aux = planet.aux;
if (aux != null && aux.mainGrid != null && aux.mainGrid.segment > 0)
{
num = aux.mainGrid.segment;
}
float latitudeRad = BlueprintUtils.GetLatitudeRad(val);
float longitudeRad = BlueprintUtils.GetLongitudeRad(val);
float latitudeGridIdx = BlueprintUtils.GetLatitudeGridIdx(val, num);
float longitudeGridIdx = BlueprintUtils.GetLongitudeGridIdx(val, num);
float value = (magnitude - planet.realRadius - 0.2f) / 1.3333333f;
float num2 = (float)Math.PI * 2f * planet.realRadius / ((float)num * 5f);
Vector3 size;
bool num3 = TryGetCollisionSize(entity, out size);
string itemName = GetItemName(entity.protoId);
string towerCategory = GetTowerCategory(itemName);
float spacingUnits = 0f;
if (towerCategory != null)
{
TryGetTowerSpacing(itemName, entity, towerCategory, out spacingUnits);
}
builder.Length = 0;
if (!string.IsNullOrEmpty(itemName))
{
builder.Append(itemName);
}
builder.Append(" #").Append(entity.id).Append('\n');
builder.Append("经度 ").Append(F4(longitudeRad * 57.29578f)).Append("°");
builder.Append(" 纬度 ").Append(F4(latitudeRad * 57.29578f)).Append("°\n");
builder.Append("X ").Append(F4(longitudeGridIdx));
builder.Append(" Y ").Append(F4(latitudeGridIdx));
builder.Append(" Z ").Append(F4(value));
if (num3)
{
builder.Append('\n');
builder.Append("当前模型体积 长 ").Append(F4(size.z / num2)).Append("格");
builder.Append(" 宽 ").Append(F4(size.x / num2)).Append("格");
builder.Append(" 高 ").Append(F4(size.y / 1.3333333f)).Append("层");
}
NearbyScanResult nearbyScanResult = ScanNearby(planet, entity, longitudeGridIdx, latitudeGridIdx, num, num2, towerCategory);
if (nearbyScanResult.hasGapX || nearbyScanResult.hasGapZ)
{
builder.Append('\n').Append("最近模型碰撞距离 ");
builder.Append("X轴 ").Append(nearbyScanResult.hasGapX ? (F4(nearbyScanResult.gapXCells) + "格") : "无");
builder.Append(" Y轴 ").Append(nearbyScanResult.hasGapZ ? (F4(nearbyScanResult.gapZCells) + "格") : "无");
}
if (towerCategory != null)
{
builder.Append('\n').Append(towerCategory).Append(" 最小间距 ")
.Append(F4(spacingUnits / num2))
.Append("格");
if (nearbyScanResult.hasSameTower)
{
builder.Append(" 最近同类中心 ").Append(F4(nearbyScanResult.towerCenterCells)).Append("格");
if (nearbyScanResult.towerCenterCells < spacingUnits / num2)
{
builder.Append(" (相隔太近)");
}
}
}
ShowTip(builder.ToString());
return true;
}
private static bool TryGetCollisionSize(EntityData entity, out Vector3 size)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
size = Vector3.zero;
PrefabDesc prefabDesc = GetPrefabDesc(entity);
if (prefabDesc == null)
{
return false;
}
if (prefabDesc.buildCollider.ext != Vector3.zero)
{
size = prefabDesc.buildCollider.ext * 2f;
return ((Vector3)(ref size)).sqrMagnitude > 0f;
}
if ((Object)(object)prefabDesc.mesh != (Object)null)
{
Bounds bounds = prefabDesc.mesh.bounds;
size = ((Bounds)(ref bounds)).size;
if (((Vector3)(ref size)).sqrMagnitude > 0f)
{
return true;
}
}
if (prefabDesc.meshes != null)
{
bool flag = false;
Bounds val = default(Bounds);
for (int i = 0; i < prefabDesc.meshes.Length; i++)
{
Mesh val2 = prefabDesc.meshes[i];
if (!((Object)(object)val2 == (Object)null))
{
if (!flag)
{
val = val2.bounds;
flag = true;
}
else
{
((Bounds)(ref val)).Encapsulate(val2.bounds);
}
}
}
if (flag)
{
size = ((Bounds)(ref val)).size;
return ((Vector3)(ref size)).sqrMagnitude > 0f;
}
}
if (prefabDesc.roughWidth > 0f)
{
size = new Vector3(prefabDesc.roughWidth, Mathf.Max(1f, prefabDesc.roughHeight), prefabDesc.roughWidth);
return true;
}
return false;
}
private static PrefabDesc GetPrefabDesc(EntityData entity)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
PrefabDesc[] prefabDescByModelIndex = PlanetFactory.PrefabDescByModelIndex;
int modelIndex = entity.modelIndex;
if (prefabDescByModelIndex == null || modelIndex < 0 || modelIndex >= prefabDescByModelIndex.Length)
{
return null;
}
return prefabDescByModelIndex[modelIndex];
}
private static Vector3 HorizontalDir(Vector3 v)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
v.y = 0f;
float magnitude = ((Vector3)(ref v)).magnitude;
if (!(magnitude < 1E-05f))
{
return v / magnitude;
}
return Vector3.zero;
}
private static CachedBuilding GetCachedBuilding(PlanetData planet, EntityData entity, int segment)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
if (cachedScanPlanet != planet)
{
buildingCache.Clear();
cachedScanPlanet = planet;
}
if (buildingCache.TryGetValue(entity.id, out var value) && value.protoId == entity.protoId && value.pos == entity.pos)
{
return value;
}
value = new CachedBuilding
{
pos = entity.pos,
protoId = entity.protoId
};
Vector3 val = ((((Vector3)(ref entity.pos)).sqrMagnitude > 0f) ? ((Vector3)(ref entity.pos)).normalized : Vector3.zero);
value.lonGrid = BlueprintUtils.GetLongitudeGridIdx(val, segment);
value.latGrid = BlueprintUtils.GetLatitudeGridIdx(val, segment);
value.towerCategory = GetTowerCategory(GetItemName(entity.protoId));
buildingCache[entity.id] = value;
return value;
}
private static bool IsBeltOrSorter(int protoId)
{
if (protoId < 2001 || protoId > 2003)
{
if (protoId >= 2011)
{
return protoId <= 2013;
}
return false;
}
return true;
}
private static NearbyScanResult ScanNearby(PlanetData planet, EntityData entity, float selfLonGrid, float selfLatGrid, int segment, float cellSize, string towerCategory)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: 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)
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: 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_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0151: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: 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_0200: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_020f: Unknown result type (might be due to invalid IL or missing references)
//IL_0216: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_0231: Unknown result type (might be due to invalid IL or missing references)
//IL_023e: Unknown result type (might be due to invalid IL or missing references)
//IL_0245: Unknown result type (might be due to invalid IL or missing references)
//IL_0247: Unknown result type (might be due to invalid IL or missing references)
//IL_025c: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
NearbyScanResult result = default(NearbyScanResult);
PlanetFactory factory = planet.factory;
if (factory == null)
{
return result;
}
EntityData[] entityPool = factory.entityPool;
if (entityPool == null)
{
return result;
}
int num = factory.entityCursor;
if (num > entityPool.Length)
{
num = entityPool.Length;
}
Vector3 val = ((((Vector3)(ref entity.pos)).sqrMagnitude > 0f) ? ((Vector3)(ref entity.pos)).normalized : Vector3.zero);
float num2 = Mathf.Sqrt(Mathf.Max(0f, 1f - val.y * val.y));
int num3 = BlueprintUtils.GetLongitudeSegmentCount(val, segment);
if (num3 <= 0)
{
num3 = segment;
}
float num4 = cellSize * ((float)segment / (float)num3) * num2;
Vector3 val2 = HorizontalDir(entity.rot * Vector3.right);
Vector3 val3 = HorizontalDir(entity.rot * Vector3.forward);
Vector3 val4 = Vector3.zero;
PrefabDesc prefabDesc = GetPrefabDesc(entity);
if (prefabDesc != null)
{
val4 = prefabDesc.buildCollider.ext;
}
float num5 = float.MaxValue;
float num6 = float.MaxValue;
float num7 = float.MaxValue;
bool anyNearby = false;
for (int i = 1; i < num; i++)
{
EntityData val5 = entityPool[i];
if (val5.id <= 0 || val5.id == entity.id || IsBeltOrSorter(val5.protoId))
{
continue;
}
Vector3 val6 = val5.pos - entity.pos;
float sqrMagnitude = ((Vector3)(ref val6)).sqrMagnitude;
if (!(sqrMagnitude > 3600f))
{
anyNearby = true;
CachedBuilding cachedBuilding = GetCachedBuilding(planet, val5, segment);
float num8 = Mathf.Abs(cachedBuilding.lonGrid - selfLonGrid);
float num9 = Mathf.Abs(cachedBuilding.latGrid - selfLatGrid);
Vector3 val7 = Vector3.zero;
PrefabDesc prefabDesc2 = GetPrefabDesc(val5);
if (prefabDesc2 != null)
{
val7 = prefabDesc2.buildCollider.ext;
}
Vector3 val8 = HorizontalDir(val5.rot * Vector3.right);
Vector3 val9 = HorizontalDir(val5.rot * Vector3.forward);
float num10 = val7.x * Mathf.Abs(Vector3.Dot(val8, val2)) + val7.z * Mathf.Abs(Vector3.Dot(val9, val2));
float num11 = val7.x * Mathf.Abs(Vector3.Dot(val8, val3)) + val7.z * Mathf.Abs(Vector3.Dot(val9, val3));
bool num12 = num9 * cellSize <= val4.z + num11;
float num13 = num8 * num4 - val4.x - num10;
if (num12 && num13 < num5)
{
num5 = num13;
}
bool num14 = num8 * num4 <= val4.x + num10;
float num15 = num9 * cellSize - val4.z - num11;
if (num14 && num15 < num6)
{
num6 = num15;
}
if (towerCategory != null && !(cachedBuilding.towerCategory != towerCategory) && sqrMagnitude < num7)
{
num7 = sqrMagnitude;
}
}
}
result.anyNearby = anyNearby;
if (num5 != float.MaxValue)
{
result.hasGapX = true;
result.gapXCells = num5 / cellSize - 0.005f;
}
if (num6 != float.MaxValue)
{
result.hasGapZ = true;
result.gapZCells = num6 / cellSize - 0.005f;
}
if (num7 != float.MaxValue)
{
result.hasSameTower = true;
result.towerCenterCells = Mathf.Sqrt(num7) / cellSize;
}
return result;
}
private static bool TryGetCollisionBox(EntityData entity, out Vector3 center, out Quaternion rotation, out Vector3 extents)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
center = entity.pos;
rotation = entity.rot;
extents = Vector3.zero;
PrefabDesc prefabDesc = GetPrefabDesc(entity);
if (prefabDesc == null)
{
return false;
}
ColliderData buildCollider = prefabDesc.buildCollider;
if (buildCollider.ext == Vector3.zero)
{
return false;
}
Quaternion val = buildCollider.q;
if (val.x == 0f && val.y == 0f && val.z == 0f && val.w == 0f)
{
val = Quaternion.identity;
}
center = entity.pos + entity.rot * buildCollider.pos;
rotation = entity.rot * val;
extents = buildCollider.ext;
return true;
}
private void ShowTip(string text)
{
visible = true;
lastBuildTime = Time.unscaledTime;
renderer.Show(text);
}
private void ShowToast(string text)
{
toastActive = true;
toastUntil = Time.unscaledTime + 1.2f;
ShowTip(text);
}
private void HideTip()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (visible)
{
visible = false;
lastPlanet = null;
lastEntity = default(EntityData);
renderer.Hide();
}
}
private static string GetItemName(short protoId)
{
if (nameCache.TryGetValue(protoId, out var value))
{
return value;
}
string text = null;
try
{
ItemProto val = ((ProtoSet<ItemProto>)(object)LDB.items).Select((int)protoId);
if (val != null)
{
text = ((Proto)val).name;
}
}
catch
{
}
nameCache[protoId] = text;
return text;
}
private static string GetTowerCategory(string name)
{
if (string.IsNullOrEmpty(name))
{
return null;
}
if (name.IndexOf("轨道弹射", StringComparison.Ordinal) >= 0)
{
return "弹射器";
}
if (name.IndexOf("风力涡轮", StringComparison.Ordinal) >= 0)
{
return "风力涡轮机";
}
if (name.IndexOf("物流", StringComparison.Ordinal) >= 0)
{
if (name.IndexOf("星际", StringComparison.Ordinal) < 0)
{
return "行星物流";
}
return "星际物流";
}
if (name.IndexOf("感应塔", StringComparison.Ordinal) >= 0 || name.IndexOf("无线输电", StringComparison.Ordinal) >= 0 || name.IndexOf("卫星配电", StringComparison.Ordinal) >= 0)
{
return "电力设施";
}
return null;
}
private static bool TryGetTowerSpacing(string name, EntityData entity, string category, out float spacingUnits)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
spacingUnits = 0f;
switch (category)
{
case "弹射器":
{
ColliderData val = default(ColliderData);
PrefabDesc prefabDesc = GetPrefabDesc(entity);
if (prefabDesc != null)
{
val = prefabDesc.buildCollider;
}
float num = Mathf.Sqrt(val.ext.x * val.ext.x + val.ext.z * val.ext.z);
spacingUnits = 7.2f + num;
return true;
}
case "风力涡轮机":
spacingUnits = 10.5f;
return true;
case "星际物流":
spacingUnits = 29f;
return true;
case "行星物流":
spacingUnits = 15f;
return true;
case "电力设施":
spacingUnits = 3.5f;
return true;
default:
return false;
}
}
private static string F4(float value)
{
return value.ToString("0.0000", CultureInfo.InvariantCulture);
}
private static string F3(float value)
{
return value.ToString("0.###", CultureInfo.InvariantCulture);
}
private static string V3(Vector3 v)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
return "(" + F3(v.x) + "," + F3(v.y) + "," + F3(v.z) + ")";
}
private static string Q(Quaternion q)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
return "(" + F3(q.x) + "," + F3(q.y) + "," + F3(q.z) + "," + F3(q.w) + ")";
}
}
public sealed class HoverCoordRenderer : MonoBehaviour
{
private const int FontSize = 14;
private readonly GUIContent content = new GUIContent();
private Vector2 contentSize;
private int textVersion;
private int measuredVersion = -1;
private GUIStyle style;
private Texture2D background;
private bool fontFailed;
private bool visible;
public void Show(string text)
{
content.text = text;
textVersion++;
visible = true;
if (!((Behaviour)this).enabled)
{
((Behaviour)this).enabled = true;
}
}
public void Hide()
{
visible = false;
if (((Behaviour)this).enabled)
{
((Behaviour)this).enabled = false;
}
}
private void OnDestroy()
{
if ((Object)(object)background != (Object)null)
{
Object.Destroy((Object)(object)background);
}
}
private void OnGUI()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Invalid comparison between Unknown and I4
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
if (visible && Event.current != null && (int)Event.current.type == 7 && EnsureStyle())
{
if (measuredVersion != textVersion)
{
contentSize = style.CalcSize(content);
measuredVersion = textVersion;
}
float x = Input.mousePosition.x;
float num = (float)Screen.height - Input.mousePosition.y;
float num2 = contentSize.x + 14f;
float num3 = contentSize.y + 10f;
float num4 = x + 22f;
float num5 = num - 18f - num3;
if (num4 + num2 > (float)Screen.width)
{
num4 = x - 22f - num2;
}
if (num5 < 0f)
{
num5 = num + 18f;
}
num4 = Mathf.Clamp(num4, 0f, Mathf.Max(0f, (float)Screen.width - num2));
num5 = Mathf.Clamp(num5, 0f, Mathf.Max(0f, (float)Screen.height - num3));
GUI.DrawTexture(new Rect(num4, num5, num2, num3), (Texture)(object)background);
GUI.Label(new Rect(num4 + 7f, num5 + 5f, contentSize.x + 1f, contentSize.y), content, style);
}
}
private bool EnsureStyle()
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Expected O, but got Unknown
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Expected O, but got Unknown
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Expected O, but got Unknown
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
if (style != null)
{
return true;
}
if (fontFailed)
{
return false;
}
Font val = CreateFont();
if ((Object)(object)val == (Object)null)
{
fontFailed = true;
return false;
}
style = new GUIStyle(GUI.skin.label);
style.font = val;
style.fontSize = 14;
style.alignment = (TextAnchor)0;
style.wordWrap = false;
style.richText = false;
style.padding = new RectOffset(0, 0, 0, 0);
style.margin = new RectOffset(0, 0, 0, 0);
style.normal.textColor = new Color(1f, 0.93f, 0.55f, 1f);
background = new Texture2D(1, 1, (TextureFormat)5, false);
background.SetPixel(0, 0, new Color(0f, 0f, 0f, 0.61960787f));
background.Apply();
return true;
}
private static Font CreateFont()
{
try
{
Font val = Font.CreateDynamicFontFromOSFont(new string[5] { "Microsoft YaHei", "微软雅黑", "SimHei", "SimSun", "Arial" }, 14);
if ((Object)(object)val != (Object)null)
{
return val;
}
}
catch
{
}
try
{
return Resources.GetBuiltinResource<Font>("Arial.ttf");
}
catch
{
return null;
}
}
}
}