using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Threading.Tasks; using BepInEx; using HarmonyLib; using MapMagic; using Photon; using SideLoader; using TinyHelper; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.0.0.0")] namespace SynchronizedWorldObjects; [BepInPlugin("com.ehaugw.synchronizedworldobjects", "Synchronized World Objects", "1.0.3")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency("com.ehaugw.tinyhelper", "4.8.2")] public class SynchronizedWorldObjects : BaseUnityPlugin { public const string GUID = "com.ehaugw.synchronizedworldobjects"; public const string VERSION = "1.0.3"; public const string NAME = "Synchronized World Objects"; internal void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown GameObject val = new GameObject("SynchronizedWorldObjectsRPC"); Object.DontDestroyOnLoad((Object)(object)val); val.AddComponent(); SynchronizedWorldObjectManager.SyncedWorldObjects = new List(); SL.OnPacksLoaded += OnPackLoaded; SL.OnSceneLoaded += OnSceneLoaded; Harmony val2 = new Harmony("com.ehaugw.synchronizedworldobjects"); val2.PatchAll(); } private void OnPackLoaded() { } private void OnSceneLoaded() { SynchronizedWorldObjectManager.OnSceneLoaded(); } } public abstract class SynchronizedWorldObject { public string IdentifierName; public string SceneIdentifierName; public int RPCListenerID; public string Uid; public SynchronizedWorldObject(string identifierName, int rpcListenerID) { IdentifierName = identifierName; RPCListenerID = rpcListenerID; SynchronizedWorldObjectManager.SyncedWorldObjects.Add(this); } public virtual bool ShouldBeSpawned() { return SceneManagerHelper.ActiveSceneName == SceneIdentifierName; } public abstract bool OnSceneLoaded(); public abstract bool OnGuestJoined(string guestUID); public abstract object SetupClientSide(int rpcListenerID, string instanceUID, int sceneViewID, int recursionCount, string rpcMeta); } internal class SynchronizedWorldObjectManager : MonoBehaviour { public static SynchronizedWorldObjectManager Instance; public static List SyncedWorldObjects; public static void OnSceneLoaded() { foreach (SynchronizedWorldObject syncedWorldObject in SyncedWorldObjects) { syncedWorldObject.OnSceneLoaded(); } } internal void Start() { Instance = this; PhotonView val = ((Component)this).gameObject.AddComponent(); val.viewID = 951; Debug.Log((object)("Registered SynchronizedWorldObjectManager with ViewID " + ((MonoBehaviour)this).photonView.viewID)); } [PunRPC] public void SetupClientSide(int rpcListenerID, string instanceUID, int sceneViewID, int recursionCount, string rpcMeta) { foreach (SynchronizedWorldObject syncedWorldObject in SyncedWorldObjects) { syncedWorldObject.SetupClientSide(rpcListenerID, instanceUID, sceneViewID, recursionCount, rpcMeta); } } } public class SynchronizedDeployable : SynchronizedEquipment { public SynchronizedDeployable(int itemID) : base(itemID) { } public override object SetupClientSide(int rpcListenerID, string instanceUID, int sceneViewID, int recursionCount, string rpcMeta) { return null; } public override Item SetupServerSide() { Item val = base.SetupServerSide(); val.IsPickable = false; val.HasPhysicsWhenWorld = false; Deployable component = ((Component)val).GetComponent(); component.StartDeployAnimation(); Dropable component2 = ((Component)val).GetComponent(); if (Object.op_Implicit((Object)(object)component2)) { component2.GenerateContents(); } FueledContainer component3 = ((Component)val).GetComponent(); if (Object.op_Implicit((Object)(object)component3)) { component3.TryKindle = true; } return val; } } public class SynchronizedEquipment : SynchronizedWorldObject { public Vector3 Position; public Vector3 Rotation; public Vector3 Scale; public int ItemID; public bool IsPickable = false; public SynchronizedEquipment(int itemID) : base("-1", -1) { ItemID = itemID; } public void AddToScene(string scene, Vector3 position, Vector3 rotation, Vector3 scale) { //IL_0009: 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) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: 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) SceneIdentifierName = scene; Position = position; Rotation = rotation; Scale = scale; } public override bool OnGuestJoined(string guestUID) { return false; } public override bool OnSceneLoaded() { if (ShouldBeSpawned()) { if (!PhotonNetwork.isNonMasterClientInRoom) { SetupServerSide(); } return true; } return false; } public override object SetupClientSide(int rpcListenerID, string instanceUID, int sceneViewID, int recursionCount, string rpcMeta) { return null; } public virtual Item SetupServerSide() { //IL_0015: 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_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) Item val = ItemManager.Instance.GenerateItemNetwork(ItemID); val.ChangeParent((Transform)null, Position, Extensions.EulerToQuat(Rotation)); val.SetForceSyncPos(); val.SaveType = (SaveTypes)2; val.IsPickable = false; val.HasPhysicsWhenWorld = true; return val; } } public class SynchronizedNPCScene { public string Scene; public Vector3 Position; public Vector3 Rotation; public Factions? Faction; public bool Sheathed; public SpellCastType Pose; public string RPCMeta; public int[] DefaultEquipment; public int[] ModdedEquipment; public Func ShouldSpawnInScene; public SynchronizedNPCScene(string scene, Vector3 position, Vector3 rotation, Factions? faction = null, bool sheathed = true, SpellCastType pose = -1, string rpcMeta = null, int[] defaultEquipment = null, int[] moddedEquipment = null, Func shouldSpawnInScene = null) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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_0030: Unknown result type (might be due to invalid IL or missing references) Scene = scene; Position = position; Rotation = rotation; Faction = faction; Sheathed = sheathed; Pose = pose; RPCMeta = rpcMeta; DefaultEquipment = defaultEquipment; ModdedEquipment = moddedEquipment; ShouldSpawnInScene = shouldSpawnInScene ?? ((Func)(() => true)); } } public class SynchronizedNPC : SynchronizedWorldObject { public enum HairColors { BrownMedium, BrownBright, BrownDark, Black, Blonde, White, Red, Blue, Green, Orange, Purple } public enum HairStyles { Bald, Basic, PonyTail, Wild, CombedBack, PonyTailBraids, BraidsBack, Bun, MaleShort, MaleMedium, MaleLong, CornrowsMedium, CornrowsLong, CornrowsShort, Ball } public int[] DefaultEquipment = new int[0]; public int[] ModdedEquipment = new int[0]; public Vector3 Scale; public string RPCMeta; public Factions Faction; private Character localCharacter; private AIRoot aiRoot; public VisualData VisualData; public List Scenes = new List(); public SynchronizedNPCScene ActiveScene; public SynchronizedNPC(string identifierName, int rpcListenerID, int[] defaultEquipment = null, int[] moddedEquipment = null, Vector3? scale = null, Factions? faction = null, VisualData visualData = null) : base(identifierName, rpcListenerID) { //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_0073: 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) DefaultEquipment = defaultEquipment ?? new int[0]; ModdedEquipment = moddedEquipment ?? new int[0]; Scale = (Vector3)(((??)scale) ?? Vector3.one); Faction = faction.GetValueOrDefault(); VisualData = visualData; } public void AddToScene(SynchronizedNPCScene scene) { Scenes.Add(scene); } public void AssignAI(AIRoot aiRoot) { this.aiRoot = aiRoot; } public GameObject GetGameObject() { return GameObject.Find("UNPC_" + IdentifierName); } public object GetSynchronizedObject(string instanceUID) { return CharacterManager.Instance.GetCharacter(instanceUID); } public override bool ShouldBeSpawned() { foreach (SynchronizedNPCScene scene in Scenes) { if (scene.ShouldSpawnInScene() && scene.Scene == SceneManagerHelper.ActiveSceneName) { ActiveScene = scene; return true; } } return false; } public override bool OnSceneLoaded() { if (ShouldBeSpawned()) { if (!PhotonNetwork.isNonMasterClientInRoom) { int num = PhotonNetwork.AllocateSceneViewID(); GameObject gameObject = GetGameObject(); if ((Object)(object)gameObject == (Object)null) { SetupServerSide(); ((MonoBehaviour)SynchronizedWorldObjectManager.Instance).photonView.RPC("SetupClientSide", (PhotonTargets)0, new object[5] { RPCListenerID, Uid, num, 0, ActiveScene.RPCMeta }); return true; } } } else { GameObject gameObject2 = GetGameObject(); if (gameObject2 != null) { Object.DestroyImmediate((Object)(object)gameObject2); } } return false; } public override bool OnGuestJoined(string guestUID) { if (ShouldBeSpawned()) { if (!PhotonNetwork.isNonMasterClientInRoom) { int num = PhotonNetwork.AllocateSceneViewID(); GameObject gameObject = GetGameObject(); if ((Object)(object)gameObject == (Object)null) { ((MonoBehaviour)SynchronizedWorldObjectManager.Instance).photonView.RPC("SetupClientSide", (PhotonTargets)0, new object[5] { RPCListenerID, Uid, num, 0, ActiveScene.RPCMeta }); return true; } } } else { GameObject gameObject2 = GetGameObject(); if (gameObject2 != null) { Object.DestroyImmediate((Object)(object)gameObject2); } } return false; } public override object SetupClientSide(int rpcListenerID, string instanceUID, int sceneViewID, int recursionCount, string rpcMeta) { //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Expected O, but got Unknown //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_012e: 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_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) if (RPCListenerID != rpcListenerID) { return null; } ActiveScene = Scenes.FirstOrDefault((SynchronizedNPCScene x) => x.RPCMeta == rpcMeta); int num = 200; object synchronizedObject = GetSynchronizedObject(instanceUID); Character val = (Character)((synchronizedObject is Character) ? synchronizedObject : null); if ((Object)(object)val == (Object)null) { if (recursionCount * num < 20000) { DelayedTask.GetTask(num).ContinueWith((Task _) => SetupClientSide(rpcListenerID, instanceUID, sceneViewID, recursionCount + 1, rpcMeta)); Console.Read(); return null; } Debug.Log((object)("SynchronizedNPC with UID " + instanceUID + " could not fetched from server")); return null; } GameObject val2 = new GameObject("UNPC_" + IdentifierName); val2.transform.position = ActiveScene.Position; val2.transform.rotation = Quaternion.Euler(ActiveScene.Rotation); GameObject gameObject = ((Component)val).gameObject; if (VisualData != null) { ((MonoBehaviour)TinyHelper.Instance).StartCoroutine(SL_Character.SetVisuals(val, ((object)VisualData).ToString())); } gameObject.transform.parent = val2.transform; gameObject.transform.position = val2.transform.position; gameObject.transform.rotation = val2.transform.rotation; gameObject.transform.localScale = Scale; Object.DestroyImmediate((Object)(object)gameObject.GetComponent()); ((Behaviour)val.Stats).enabled = false; Weapon currentWeapon = val.CurrentWeapon; if (currentWeapon != null && ((Equipment)currentWeapon).TwoHanded) { val.LeftHandEquipment = (Equipment)(object)val.CurrentWeapon; val.LeftHandChanged(); } if ((Object)(object)val.CurrentWeapon != (Object)null) { val.Sheathed = ActiveScene.Sheathed; } localCharacter = val; return val; } public void AITick() { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Expected I4, but got Unknown DelayedTask.GetTask(1000).ContinueWith(delegate { AITick(); }); Console.Read(); if ((Object)(object)localCharacter != (Object)null) { SpellCastType[] array = (SpellCastType[])(object)new SpellCastType[2] { (SpellCastType)55, (SpellCastType)41 }; if (UnityEngineExtensions.Contains(array, ActiveScene.Pose) && localCharacter.InLocomotion) { localCharacter.Animator.SetInteger("SpellType", (int)ActiveScene.Pose); localCharacter.Animator.SetTrigger("Spell"); } } } public object SetupServerSide() { //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_001c: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) UID val = UID.Generate(); string text = ((object)(UID)(ref val)).ToString(); GameObject gameObject = ((Component)TinyCharacterManager.SpawnCharacter(text, ActiveScene.Position, ActiveScene.Rotation)).gameObject; gameObject.transform.rotation = Quaternion.Euler(ActiveScene.Rotation); Character component = gameObject.GetComponent(); At.SetField(component, "m_instantiationType", (object)(CharacterInstantiationTypes)2); int[] array = ActiveScene.DefaultEquipment ?? DefaultEquipment; foreach (int num in array) { ? val2 = component.Inventory.Equipment; Item itemPrefab = ResourcesPrefabManager.Instance.GetItemPrefab(num); ((CharacterEquipment)val2).EquipInstantiate((Equipment)(object)((itemPrefab is Equipment) ? itemPrefab : null)); } int[] array2 = ActiveScene.ModdedEquipment ?? ModdedEquipment; for (int j = 0; j < array2.Length; j++) { int num2 = array2[j]; if (ResourcesPrefabManager.Instance.ContainsItemPrefab(num2.ToString())) { Item obj = ItemManager.Instance.GenerateItemNetwork(num2); Equipment val3 = (Equipment)(object)((obj is Equipment) ? obj : null); component.Inventory.TakeItem(((Item)val3).UID); At.Invoke(component.Inventory.Equipment, "EquipWithoutAssociating", new Type[2] { typeof(Equipment), typeof(bool) }, new object[2] { val3, false }); } } Weapon currentWeapon = component.CurrentWeapon; if (currentWeapon != null && ((Equipment)currentWeapon).TwoHanded) { component.LeftHandEquipment = (Equipment)(object)component.CurrentWeapon; component.LeftHandChanged(); } if ((Object)(object)component.CurrentWeapon != (Object)null) { component.Sheathed = ActiveScene.Sheathed; } component.ChangeFaction((Factions)(((??)ActiveScene.Faction) ?? Faction), true); gameObject.SetActive(true); DelayedTask.GetTask(1000).ContinueWith(delegate { AITick(); }); Console.Read(); Uid = text; return text; } }