public static void SetBlock(Type pType, Vector3i pPosition, UserSession pSession = null, Vector3i?pSourcePosition = null, Block pSourceBlock = null, byte[] pData = null) { if (pType == null || pType.DerivesFrom <PickupableBlock>()) { pType = typeof(EmptyBlock); } WorldObjectBlock worldObjectBlock = Eco.World.World.GetBlock(pPosition) as WorldObjectBlock; if (worldObjectBlock != null) { if (worldObjectBlock.WorldObjectHandle.Object.Position3i == pPosition) { worldObjectBlock.WorldObjectHandle.Object.Destroy(); } } if (pType == typeof(EmptyBlock)) { Eco.World.World.DeleteBlock(pPosition); return; } var constuctor = pType.GetConstructor(Type.EmptyTypes); if (constuctor != null) { Eco.World.World.SetBlock(pType, pPosition); return; } Type[] types = new Type[1]; types[0] = typeof(WorldPosition3i); constuctor = pType.GetConstructor(types); if (constuctor != null) { object obj = null; if (pData != null) { MemoryStream ms = new MemoryStream(pData); obj = EcoSerializer.Deserialize(ms); } if (pType.DerivesFrom <PlantBlock>()) { PlantSpecies ps = null; Plant pb = null; if (obj != null) { pb = (Plant)obj; ps = pb.Species; } else { ps = WorldUtils.GetPlantSpecies(pType); if (pSourceBlock != null) { pb = PlantBlock.GetPlant(pPosition); } } Plant newplant = EcoSim.PlantSim.SpawnPlant(ps, pPosition); if (pb != null) { newplant.YieldPercent = pb.YieldPercent; newplant.Dead = pb.Dead; newplant.DeadType = pb.DeadType; newplant.GrowthPercent = pb.GrowthPercent; newplant.DeathTime = pb.DeathTime; newplant.Tended = pb.Tended; } return; } AsphaltLog.WriteLine("Unknown Type: " + pType); } types[0] = typeof(WorldObject); constuctor = pType.GetConstructor(types); if (constuctor != null) { WorldObject wObject = null; if (pSourceBlock != null) { wObject = ((WorldObjectBlock)pSourceBlock).WorldObjectHandle.Object; //if this is not the "main block" of an object do nothing if (wObject.Position3i != pSourcePosition.Value) { return; } } else if (pData != null) { MemoryStream ms = new MemoryStream(pData); var obj = EcoSerializer.Deserialize(ms); if (obj is WorldObject) { wObject = obj as WorldObject; } else { throw new InvalidOperationException("obj is not WorldObjectBlock"); } } if (wObject == null) { return; } // WorldObject newObject = WorldObjectUtil.Spawn(wObject.GetType().Name, wObject.Creator.User, pPosition); // newObject.Rotation = wObject.Rotation; WorldObject newObject = (WorldObject)Activator.CreateInstance(wObject.GetType(), true); newObject = WorldObjectManager.Add(newObject, wObject.Creator.User, pPosition, wObject.Rotation); { StorageComponent newSC = newObject.GetComponent <StorageComponent>(); if (newSC != null) { StorageComponent oldPSC = wObject.GetComponent <StorageComponent>(); newSC.Inventory.AddItems(oldPSC.Inventory.Stacks); // newSC.Inventory.OnChanged.Invoke(null); } } { CustomTextComponent newTC = newObject.GetComponent <CustomTextComponent>(); if (newTC != null) { CustomTextComponent oldTC = wObject.GetComponent <CustomTextComponent>(); typeof(CustomTextComponent).GetProperty("Text", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).SetValue(newTC, oldTC.Text); } } return; } AsphaltLog.WriteLine("Unknown Type: " + pType); }
void Initialize() { instance = this; ModConsole.Log("[MOP] Loading MOP..."); // Initialize the worldObjectManager list worldObjectManager = new WorldObjectManager(); // Looking for player and yard player = GameObject.Find("PLAYER").transform; // Add GameFixes MonoBehaviour. try { gameObject.AddComponent <GameFixes>(); } catch (Exception ex) { ExceptionManager.New(ex, false, $"GAME_FIXES_INITIALIZAITON | {ex}"); } // Loading vehicles vehicleManager = new VehicleManager(); // World Objects try { worldObjectManager.Add("CABIN", DisableOn.Distance | DisableOn.IgnoreInQualityMode); worldObjectManager.Add("COTTAGE", DisableOn.Distance, 400); worldObjectManager.Add("DANCEHALL", DisableOn.Distance, 500); worldObjectManager.Add("PERAJARVI", DisableOn.Distance | DisableOn.IgnoreInQualityMode, 400); worldObjectManager.Add("SOCCER", DisableOn.Distance); worldObjectManager.Add("WATERFACILITY", DisableOn.Distance, 300); worldObjectManager.Add("DRAGRACE", DisableOn.Distance, 1100); worldObjectManager.Add("StrawberryField", DisableOn.Distance, 400); worldObjectManager.Add("MAP/Buildings/DINGONBIISI", DisableOn.Distance, 400); worldObjectManager.Add("RALLY/PartsSalesman", DisableOn.Distance, 400); worldObjectManager.Add("LakeSmallBottom1", DisableOn.Distance, 500); worldObjectManager.Add("machine", DisableOn.Distance, 200, silent: true); ModConsole.Log("[MOP] World objects (1) loaded"); } catch (Exception ex) { ExceptionManager.New(ex, false, "WORLD_OBJECTS_1_INITIALIZAITON_FAIL"); } // Initialize places. placeManager = new PlaceManager(); // Fixes GameFixes.Instance.MainFixes(); //Things that should be enabled when out of proximity of the house try { worldObjectManager.Add("NPC_CARS", DisableOn.PlayerInHome); worldObjectManager.Add("TRAFFIC", DisableOn.PlayerInHome); worldObjectManager.Add("TRAIN", DisableOn.PlayerInHome | DisableOn.IgnoreInQualityMode); worldObjectManager.Add("Buildings", DisableOn.PlayerInHome); worldObjectManager.Add("TrafficSigns", DisableOn.PlayerInHome); worldObjectManager.Add("StreetLights", DisableOn.PlayerInHome); worldObjectManager.Add("HUMANS", DisableOn.PlayerInHome); worldObjectManager.Add("TRACKFIELD", DisableOn.PlayerInHome); worldObjectManager.Add("SkijumpHill", DisableOn.PlayerInHome | DisableOn.IgnoreInQualityMode); worldObjectManager.Add("Factory", DisableOn.PlayerInHome); worldObjectManager.Add("WHEAT", DisableOn.PlayerInHome); worldObjectManager.Add("RAILROAD", DisableOn.PlayerInHome); worldObjectManager.Add("AIRPORT", DisableOn.PlayerInHome); worldObjectManager.Add("RAILROAD_TUNNEL", DisableOn.PlayerInHome); worldObjectManager.Add("PierDancehall", DisableOn.PlayerInHome); worldObjectManager.Add("PierRiver", DisableOn.PlayerInHome); worldObjectManager.Add("PierStore", DisableOn.PlayerInHome); worldObjectManager.Add("BRIDGE_dirt", DisableOn.PlayerInHome); worldObjectManager.Add("BRIDGE_highway", DisableOn.PlayerInHome); worldObjectManager.Add("BirdTower", DisableOn.Distance, 400); worldObjectManager.Add("RYKIPOHJA", DisableOn.PlayerInHome); worldObjectManager.Add("COMPUTER", DisableOn.PlayerAwayFromHome); ModConsole.Log("[MOP] World objects (2) loaded"); } catch (Exception ex) { ExceptionManager.New(ex, false, "WORLD_OBJECTS_2_INITIALIZAITON_FAIL"); } // Adding area check if Satsuma is in the inspection's area try { SatsumaInArea inspectionArea = GameObject.Find("INSPECTION").AddComponent <SatsumaInArea>(); inspectionArea.Initialize(new Vector3(20, 20, 20)); } catch (Exception ex) { ExceptionManager.New(ex, false, "SATSUMA_AREA_CHECK_INSPECTION_FAIL"); } // Check for when Satsuma is on the lifter try { SatsumaInArea lifterArea = GameObject.Find("REPAIRSHOP/Lifter/Platform").AddComponent <SatsumaInArea>(); lifterArea.Initialize(new Vector3(5, 5, 5)); } catch (Exception ex) { ExceptionManager.New(ex, false, "SATSUMA_AREA_CHECK_REPAIRSHOP_FAIL"); } // Area for the parc ferme. try { GameObject parcFermeTrigger = new GameObject("MOP_ParcFermeTrigger"); parcFermeTrigger.transform.parent = GameObject.Find("RALLY").transform.Find("Scenery"); parcFermeTrigger.transform.position = new Vector3(-1383f, 3f, 1260f); SatsumaInArea parcFerme = parcFermeTrigger.AddComponent <SatsumaInArea>(); parcFerme.Initialize(new Vector3(41, 12, 35)); } catch (Exception ex) { ExceptionManager.New(ex, false, "PARC_FERME_TRIGGER_FAIL"); } ModConsole.Log("[MOP] Satsuma triggers loaded"); // Jokke's furnitures. // Only renderers are going to be toggled. try { if (GameObject.Find("tv(Clo01)")) { string[] furnitures = { "tv(Clo01)", "chair(Clo02)", "chair(Clo05)", "bench(Clo01)", "bench(Clo02)", "table(Clo02)", "table(Clo03)", "table(Clo04)", "table(Clo05)", "desk(Clo01)", "arm chair(Clo01)" }; foreach (string furniture in furnitures) { GameObject g = GameObject.Find(furniture); if (g) { g.transform.parent = null; worldObjectManager.Add(g, DisableOn.Distance, 100, ToggleModes.Renderer); } } ModConsole.Log("[MOP] Jokke's furnitures found and loaded"); } } catch (Exception ex) { ExceptionManager.New(ex, false, "JOKKE_FURNITURE_ERROR"); } // Haybales. // First we null out the prevent it from reloading the position of haybales. try { GameObject haybalesParent = GameObject.Find("JOBS/HayBales"); if (haybalesParent != null) { haybalesParent.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false; // And now we add all child haybale to world objects. foreach (Transform haybale in haybalesParent.transform.GetComponentInChildren <Transform>()) { worldObjectManager.Add(haybale.gameObject.name, DisableOn.Distance | DisableOn.IgnoreInQualityMode, 120); } } } catch (Exception ex) { ExceptionManager.New(ex, false, "HAYBALES_FIX_ERROR"); } // Logwalls try { foreach (GameObject wall in Resources.FindObjectsOfTypeAll <GameObject>().Where(g => g.name == "LogwallLarge")) { worldObjectManager.Add(wall, DisableOn.Distance, 300); } } catch (Exception ex) { ExceptionManager.New(ex, false, "LOGWALL_LOAD_ERROR"); } // Perajarvi Church. try { if (MopSettings.Mode != PerformanceMode.Performance) { GameObject church = GameObject.Find("PERAJARVI").transform.Find("CHURCH").gameObject; church.transform.parent = null; GameObject churchLOD = church.transform.Find("LOD").gameObject; church.GetComponent <PlayMakerFSM>().enabled = false; worldObjectManager.Add(churchLOD, DisableOn.Distance, 300); } } catch (Exception ex) { ExceptionManager.New(ex, false, "CHURCH_LOD_ERROR"); } // Lake houses. try { if (MopSettings.Mode == PerformanceMode.Quality) { GameObject.Find("PERAJARVI").transform.Find("TerraceHouse").transform.parent = null; } } catch (Exception ex) { ExceptionManager.New(ex, false, "LAKE_HOUSE_ERROR"); } // VehiclesHighway renderers. try { Transform vehiclesHighway = GameObject.Find("TRAFFIC").transform.Find("VehiclesHighway"); foreach (var f in vehiclesHighway.GetComponentsInChildren <Transform>(true).Where(f => f.parent == vehiclesHighway)) { worldObjectManager.Add(f.gameObject, DisableOn.Distance, 600, ToggleModes.MultipleRenderers); } // Also we gonna fix the lag on initial traffic load. vehiclesHighway.gameObject.SetActive(true); } catch (Exception ex) { ExceptionManager.New(ex, false, "TRAFFIC_VEHICLES_ERROR"); } // FITTAN renderers. try { worldObjectManager.Add(GameObject.Find("TRAFFIC").transform.Find("VehiclesDirtRoad/Rally/FITTAN").gameObject, DisableOn.Distance, 600, ToggleModes.MultipleRenderers); } catch (Exception ex) { ExceptionManager.New(ex, false, "FITTAN_RENDERERS_ERROR"); } // Initialize Items class try { new ItemsManager(); ItemsManager.Instance.Initialize(); ModConsole.Log("[MOP] Items class initialized"); } catch (Exception ex) { ExceptionManager.New(ex, true, "ITEMS_CLASS_ERROR"); } try { DateTime now = DateTime.Now; if (now.Day == 1 && now.Month == 4) { GameObject fpsObject = GameObject.Find("GUI").transform.Find("HUD/FPS/HUDValue").gameObject; PlayMakerFSM[] fsms = fpsObject.GetComponents <PlayMakerFSM>(); foreach (var fsm in fsms) { fsm.enabled = false; } fpsObject.GetComponent <TextMesh>().text = "99999999 :)"; fpsObject.transform.Find("HUDValueShadow").GetComponent <TextMesh>().text = "99999999 :)"; } } catch { } HookPreSaveGame(); ModConsole.Log("[MOP] Loading rules..."); foreach (ToggleRule v in RulesManager.Instance.ToggleRules) { try { switch (v.ToggleMode) { default: ModConsole.LogError($"[MOP] Unrecognized toggle mode for {v.ObjectName}: {v.ToggleMode}."); break; case ToggleModes.Simple: if (GameObject.Find(v.ObjectName) == null) { ModConsole.LogError($"[MOP] Couldn't find world object {v.ObjectName}"); continue; } worldObjectManager.Add(v.ObjectName, DisableOn.Distance); break; case ToggleModes.Renderer: if (GameObject.Find(v.ObjectName) == null) { ModConsole.LogError($"[MOP] Couldn't find world object {v.ObjectName}"); continue; } worldObjectManager.Add(v.ObjectName, DisableOn.Distance, 200, ToggleModes.Renderer); break; case ToggleModes.Item: GameObject g = GameObject.Find(v.ObjectName); if (g == null) { ModConsole.LogError($"[MOP] Couldn't find item {v.ObjectName}"); continue; } if (g.GetComponent <ItemBehaviour>() == null) { g.AddComponent <ItemBehaviour>(); } break; case ToggleModes.Vehicle: if (RulesManager.Instance.SpecialRules.IgnoreModVehicles) { continue; } if (GameObject.Find(v.ObjectName) == null) { ModConsole.LogError($"[MOP] Couldn't find vehicle {v.ObjectName}"); continue; } vehicleManager.Add(new Vehicle(v.ObjectName)); break; case ToggleModes.VehiclePhysics: if (RulesManager.Instance.SpecialRules.IgnoreModVehicles) { continue; } if (GameObject.Find(v.ObjectName) == null) { ModConsole.LogError($"[MOP] Couldn't find vehicle {v.ObjectName}"); continue; } vehicleManager.Add(new Vehicle(v.ObjectName)); Vehicle veh = vehicleManager[vehicleManager.Count - 1]; veh.Toggle = veh.ToggleUnityCar; break; } } catch (Exception ex) { ExceptionManager.New(ex, false, "TOGGLE_RULES_LOAD_ERROR"); } } ModConsole.Log("[MOP] Rules loading complete!"); // Initialzie sector manager try { gameObject.AddComponent <SectorManager>(); } catch (Exception ex) { ExceptionManager.New(ex, true, "SECTOR_MANAGER_ERROR"); } // Add DynamicDrawDistance component. try { gameObject.AddComponent <DynamicDrawDistance>(); } catch (Exception ex) { ExceptionManager.New(ex, false, "DYNAMIC_DRAW_DISTANCE_ERROR"); } try { if (MopSettings.Mode != PerformanceMode.Safe) { ToggleAll(false, ToggleAllMode.OnLoad); } } catch (Exception ex) { ExceptionManager.New(ex, true, "TOGGLE_ALL_ERROR"); } // Initialize the coroutines. currentLoop = LoopRoutine(); StartCoroutine(currentLoop); currentControlCoroutine = ControlCoroutine(); StartCoroutine(currentControlCoroutine); ModConsole.Log("<color=green>[MOP] MOD LOADED SUCCESFULLY!</color>"); Resources.UnloadUnusedAssets(); GC.Collect(); // If generate-list command is set to true, generate the list of items that are disabled by MOP. if (MopSettings.GenerateToggledItemsListDebug) { if (System.IO.File.Exists("world.txt")) { System.IO.File.Delete("world.txt"); } string world = ""; foreach (var w in worldObjectManager.GetList()) { if (world.Contains(w.GetName())) { continue; } world += w.GetName() + ", "; } System.IO.File.WriteAllText("world.txt", world); System.Diagnostics.Process.Start("world.txt"); if (System.IO.File.Exists("vehicle.txt")) { System.IO.File.Delete("vehicle.txt"); } string vehiclez = ""; foreach (var w in vehicleManager.List()) { vehiclez += w.gameObject.name + ", "; } System.IO.File.WriteAllText("vehicle.txt", vehiclez); System.Diagnostics.Process.Start("vehicle.txt"); if (System.IO.File.Exists("items.txt")) { System.IO.File.Delete("items.txt"); } string items = ""; foreach (var w in ItemsManager.Instance.All()) { if (items.Contains(w.gameObject.name)) { continue; } items += w.gameObject.name + ", "; } System.IO.File.WriteAllText("items.txt", items); System.Diagnostics.Process.Start("items.txt"); if (System.IO.File.Exists("place.txt")) { System.IO.File.Delete("place.txt"); } string place = ""; foreach (var w in placeManager.GetList()) { place += w.GetName() + ": "; foreach (var f in w.GetDisableableChilds()) { if (place.Contains(f.gameObject.name)) { continue; } place += f.gameObject.name + ", "; } place += "\n\n"; } System.IO.File.WriteAllText("place.txt", place); System.Diagnostics.Process.Start("place.txt"); } }