using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppSystem.Collections.Generic;
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("SoDFurnitureFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("SoDFurnitureFix")]
[assembly: AssemblyTitle("SoDFurnitureFix")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 SoDFurnitureFix
{
[BepInPlugin("sm3gm.sod.invisiblefurniturefix", "Invisible Furniture Fix", "1.0.0")]
public sealed class Plugin : BasePlugin
{
public const string VER = "1.0.0";
internal static ManualLogSource L;
internal static ConfigEntry<int> RoomsPerFrame;
internal static ConfigEntry<bool> LogFixes;
public override void Load()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Expected O, but got Unknown
L = ((BasePlugin)this).Log;
RoomsPerFrame = ((BasePlugin)this).Config.Bind<int>("General", "RoomsPerFrame", 40, "How many of the city's rooms are looked at each frame (only visible ones are checked).");
LogFixes = ((BasePlugin)this).Config.Bind<bool>("Debug", "LogFixes", false, "Every 10 s, write how many pieces were switched on and what the checks cost to the log.");
((BasePlugin)this).AddComponent<Sweep>();
ManualLogSource l = L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Invisible Furniture Fix ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
}
l.LogInfo(val);
}
}
public class Sweep : MonoBehaviour
{
private int cursor;
private int fixedSince;
private int fixedTotal;
private int frames;
private int roomsChecked;
private float nextReport;
private float nextOwnRoom;
private double workMs;
private double workMax;
public Sweep(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Expected O, but got Unknown
try
{
if ((Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.startedGame)
{
return;
}
ObjectPoolingController instance = ObjectPoolingController.Instance;
List<NewRoom> val = (((Object)(object)CityData.Instance != (Object)null) ? CityData.Instance.roomDirectory : null);
if ((Object)(object)instance == (Object)null || val == null || val.Count == 0)
{
return;
}
long timestamp = Stopwatch.GetTimestamp();
if (Time.unscaledTime >= nextOwnRoom)
{
nextOwnRoom = Time.unscaledTime + 0.25f;
NewRoom val2 = (((Object)(object)Player.Instance != (Object)null) ? ((Actor)Player.Instance).currentRoom : null);
if ((Object)(object)val2 != (Object)null)
{
Check(instance, val2);
}
}
int num = Math.Max(1, Plugin.RoomsPerFrame.Value);
for (int i = 0; i < num; i++)
{
if (cursor >= val.Count)
{
cursor = 0;
}
NewRoom val3 = val[cursor++];
if (!((Object)(object)val3 == (Object)null) && val3.isVisible && val3.geometryLoaded)
{
Check(instance, val3);
}
}
double num2 = (double)(Stopwatch.GetTimestamp() - timestamp) * 1000.0 / (double)Stopwatch.Frequency;
workMs += num2;
frames++;
if (num2 > workMax)
{
workMax = num2;
}
if (!(Time.unscaledTime >= nextReport))
{
return;
}
nextReport = Time.unscaledTime + 10f;
if (Plugin.LogFixes.Value)
{
ManualLogSource l = Plugin.L;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(113, 6, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[FURNFIX] switched on ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(fixedSince);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" pieces (");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(fixedTotal);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" this session); cost ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<double>(workMs / (double)Math.Max(1, frames), "0.000");
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" ms per frame, ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<double>(workMax, "0.00");
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(" ms worst; visible rooms checked ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(roomsChecked);
((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", city rooms ");
((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<int>(val.Count);
}
l.LogInfo(val4);
}
fixedSince = 0;
workMs = (workMax = 0.0);
frames = 0;
roomsChecked = 0;
}
catch (Exception ex)
{
Plugin.L.LogInfo((object)("[FURNFIX] " + ex.Message));
}
}
private void Check(ObjectPoolingController op, NewRoom room)
{
roomsChecked++;
List<FurnitureLocation> individualFurniture = room.individualFurniture;
if (individualFurniture == null)
{
return;
}
float num = default(float);
for (int i = 0; i < individualFurniture.Count; i++)
{
FurnitureLocation val = individualFurniture[i];
try
{
if (val == null || (Object)(object)val.spawnedObject == (Object)null)
{
continue;
}
List<MeshRenderer> meshes = val.meshes;
if (meshes == null || meshes.Count == 0)
{
continue;
}
bool flag = false;
for (int j = 0; j < meshes.Count; j++)
{
MeshRenderer val2 = meshes[j];
if ((Object)(object)val2 != (Object)null && ((Renderer)val2).enabled)
{
flag = true;
break;
}
}
if (flag || !op.SpawnRangeCheck(val, ref num))
{
continue;
}
for (int k = 0; k < meshes.Count; k++)
{
MeshRenderer val3 = meshes[k];
if ((Object)(object)val3 != (Object)null)
{
((Renderer)val3).enabled = true;
}
}
fixedSince++;
fixedTotal++;
}
catch
{
}
}
}
}
}