using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("art0007i")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0+befc17de43f36cc05b8d4cdc19812561eb9428d0")]
[assembly: AssemblyProduct("AlwaysResetLocalHome")]
[assembly: AssemblyTitle("AlwaysResetLocalHome")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/AlwaysResetLocalHome")]
[assembly: AssemblyVersion("2.0.0.0")]
[module: RefSafetyRules(11)]
namespace AlwaysResetLocalHome;
[ResonitePlugin("art0007i.AlwaysResetLocalHome", "AlwaysResetLocalHome", "2.0.0", "art0007i", "https://github.com/art0007i/AlwaysResetLocalHome")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
[HarmonyPatch(typeof(WorldPresets), "LocalWorld")]
private class LocalHomeAlternateFilePatch
{
[CompilerGenerated]
private sealed class <Transpiler>d__0 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
{
private int <>1__state;
private CodeInstruction <>2__current;
private int <>l__initialThreadId;
private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;
public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;
private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap1;
private CodeInstruction <code>5__3;
CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object global::System.Collections.IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <Transpiler>d__0(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void global::System.IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || (uint)(num - 1) <= 1u)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<>7__wrap1 = null;
<code>5__3 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Expected O, but got Unknown
try
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>7__wrap1 = codes.GetEnumerator();
<>1__state = -3;
break;
case 1:
<>1__state = -3;
if (CodeInstructionExtensions.Is(<code>5__3, OpCodes.Ldstr, (object)"Local.bin"))
{
<>2__current = new CodeInstruction(OpCodes.Call, (object)typeof(LocalHomeAlternateFilePatch).GetMethod("GetValidHomePath"));
<>1__state = 2;
return true;
}
goto IL_00c6;
case 2:
{
<>1__state = -3;
goto IL_00c6;
}
IL_00c6:
<code>5__3 = null;
break;
}
if (((global::System.Collections.IEnumerator)<>7__wrap1).MoveNext())
{
<code>5__3 = <>7__wrap1.Current;
<>2__current = <code>5__3;
<>1__state = 1;
return true;
}
<>m__Finally1();
<>7__wrap1 = null;
return false;
}
catch
{
//try-fault
((global::System.IDisposable)this).Dispose();
throw;
}
}
bool global::System.Collections.IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<>7__wrap1 != null)
{
((global::System.IDisposable)<>7__wrap1).Dispose();
}
}
[DebuggerHidden]
void global::System.Collections.IEnumerator.Reset()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
throw new NotSupportedException();
}
[DebuggerHidden]
global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
{
<Transpiler>d__0 <Transpiler>d__;
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
<Transpiler>d__ = this;
}
else
{
<Transpiler>d__ = new <Transpiler>d__0(0);
}
<Transpiler>d__.codes = <>3__codes;
return <Transpiler>d__;
}
[DebuggerHidden]
global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
{
return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
}
}
[IteratorStateMachine(typeof(<Transpiler>d__0))]
public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <Transpiler>d__0(-2)
{
<>3__codes = codes
};
}
public static string GetValidHomePath(string orig)
{
if (File.Exists(Path.Combine(Engine.Current.AppPath, "RuntimeData", "LocalModded.bin")))
{
return "LocalModded.bin";
}
return orig;
}
}
[HarmonyPatch(typeof(Userspace), "OpenLocalHomeAsync")]
private class AlwaysResetLocalHomePatch
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static Action <>9__0_0;
internal void <Prefix>b__0_0()
{
World val = Userspace.StartUtilityWorld(WorldPresets.LocalHome(), (DataTreeDictionary)null);
val.AssignNewRecord("M-" + val.Engine.LocalDB.MachineID, "R-Home");
val.CorrespondingRecord.Name = "Local";
val.Name = val.CorrespondingRecord.Name;
}
}
public static bool Prefix(ref global::System.Threading.Tasks.Task __result)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
if (!Enabled.Value)
{
return true;
}
object obj = <>c.<>9__0_0;
if (obj == null)
{
Action val = delegate
{
World val2 = Userspace.StartUtilityWorld(WorldPresets.LocalHome(), (DataTreeDictionary)null);
val2.AssignNewRecord("M-" + val2.Engine.LocalDB.MachineID, "R-Home");
val2.CorrespondingRecord.Name = "Local";
val2.Name = val2.CorrespondingRecord.Name;
};
<>c.<>9__0_0 = val;
obj = (object)val;
}
__result = global::System.Threading.Tasks.Task.Run((Action)obj);
return false;
}
}
internal static ManualLogSource Log;
public static ConfigEntry<bool> Enabled;
public override void Load()
{
Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "If true local home will be reset every restart.");
Log = ((BasePlugin)this).Log;
((BasePlugin)this).HarmonyInstance.PatchAll();
}
}
public static class PluginMetadata
{
public const string GUID = "art0007i.AlwaysResetLocalHome";
public const string NAME = "AlwaysResetLocalHome";
public const string VERSION = "2.0.0";
public const string AUTHORS = "art0007i";
public const string REPOSITORY_URL = "https://github.com/art0007i/AlwaysResetLocalHome";
}