protected override void InitializeMonitor() { ModLogger.Debug("Initializing prop monitor"); try { // Clear any existing data from the overwatch container OverwatchPropContainer.Instance.ClearCache(); // Process the list of existing props when initializing to make sure the list is up-to-date var capacity = Singleton <PropManager> .instance.m_props.m_buffer.Count(); Enumerable.Range(0, capacity).DoAll(i => ProcessProp((ushort)i)); // Store a reference to the current frame index so we know from which frame we need to process on the next update cycle MarkFrame(); // Mark the monitor as initialized and spinning MarkInitialized(); OverwatchControl.Instance.PropMonitorSpun = true; ModLogger.Debug("Prop monitor initialized"); } catch (Exception ex) { ModLogger.Error("An error occured while initializing the prop monitor"); ModLogger.Exception(ex); MarkTerminated(); } }
public List <IUIWorkshopAssetRowData> GetCurrentList() { try { ModLogger.Debug("Creating workshop item list with filter {0} and sortfield {1}", _currentFilter, _currentSortField); // Filter the current list and sort it var result = WorkshopAssetMonitor.Instance.GetWorkshopAssets() .Where(a => (a.AssetType & _currentFilter) == a.AssetType) .Cast <IUIWorkshopAssetRowData>() .ToList(); result.Sort(new WorkshopAssetComparer(_currentSortField, _descending)); ModLogger.Debug("Created workshop item list with {0} items after filter", result.Count()); return(result); } catch (Exception ex) { ModLogger.Debug("An unexpected error occured while creating a filtered and sorted list of workshop items"); ModLogger.Exception(ex); return(new List <IUIWorkshopAssetRowData>()); } }
public override void OnLevelUnloading() { // Don't unload in asset and map editor if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame) { return; } try { ModLogger.Debug("Destroying main window"); // Destroy the mainwindow when unloading to make sure a fresh new window is used for the next game if (_mainWindow != null) { GameObject.Destroy(_mainWindow.gameObject); } ModLogger.Debug("Main window destroyed"); } catch (Exception ex) { ModLogger.Error("An error occured while destroying the main window"); ModLogger.Exception(ex); } }
public sealed override void OnLevelLoaded(LoadMode mode) { _mode = mode; // Don't load in asset and map editor if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame) { return; } try { ModLogger.Debug("Creating main window"); // Get a handle to the main game view UIView aView = UIView.GetAView(); // Create the gameobject and attach a mainwindow instance GameObject goMainWindow = new GameObject(WorkshopMonitorMainWindowGameObjectName); _mainWindow = goMainWindow.AddComponent <UIMainWindow>(); _mainWindow.transform.parent = aView.transform; ModLogger.Debug("Main window created"); } catch (Exception ex) { ModLogger.Error("An error occured while creating the main window"); ModLogger.Exception(ex); } }
public void RemoveRow(IUIWorkshopAssetRowData workshopAssetRowData) { try { ModLogger.Debug("Trying to remove row"); var row = _rows.FirstOrDefault(r => r.WorkshopId == workshopAssetRowData.WorkshopId); if (row != null) { ModLogger.Debug("Removing row '{0}'", workshopAssetRowData.ReadableName); _scrollablePanel.RemoveUIComponent(row); _rows.Remove(row); } else { ModLogger.Debug("Row '{0}' not found", workshopAssetRowData.ReadableName); } ClearWorkshopAssets(); PopulateWorkshopAssets(); } catch (Exception ex) { ModLogger.Exception(ex); } }
private void RunUpdateCycle() { try { // Get a reference to the current frame int end = GetFrame(); // Process all frames between the previous frame marker and the current frame while (_lastProcessedFrame != end) { _lastProcessedFrame = GetFrame(_lastProcessedFrame + 1); int[] boundaries = GetFrameBoundaries(_lastProcessedFrame); for (int i = boundaries[0]; i <= boundaries[1]; i++) { CheckAssetExistence((ushort)i); } } } catch (Exception ex) { ModLogger.Error("An unexpected error occured while running an update cycle in the building monitor"); ModLogger.Exception(ex); MarkTerminated(); } }
public void TestException() { Exception e = new Exception(); logger.Exception("An exception was thrown", e); innerLogger.Received().Exception("[MyMod] An exception was thrown", e); }
public override void OnBeforeSimulationTick() { // Exit if the monitor was terminated because of an error occured when updating overwatch data if (Terminated) { return; } // Exit if the prop monitor has not been loaded yet by the overwatch loader (prevents issues when the loader is not started yet but the monitor is) if (!OverwatchControl.Instance.PropMonitorSpun) { MarkUninitialized(); return; } // Exit if the prop monitor has not been initialized yet (initialization happens in OnUpdate) if (!Initialized) { return; } // Exit if no prop changes occured since the previous tick if (!Singleton <PropManager> .instance.m_propsUpdated) { return; } try { for (int i = 0; i < Singleton <PropManager> .instance.m_updatedProps.Length; i++) { ulong updatedPropId = Singleton <PropManager> .instance.m_updatedProps[i]; if (updatedPropId != 0) { for (int j = 0; j < 64; j++) { if ((updatedPropId & (ulong)1 << j) != 0) { ushort id = (ushort)(i << 6 | j); ProcessProp(id); } } } } } catch (Exception ex) { ModLogger.Error("An error occured while updating prop information"); ModLogger.Exception(ex); MarkTerminated(); } base.OnBeforeSimulationTick(); }
private void filterPanel_FilterChanged(object sender, FilterChangedEventArgs e) { try { ModLogger.Debug("Changing filter to {0}", e.NewFilter); ClearWorkshopAssets(); _workshopAssetListState.SetFilter(e.NewFilter); PopulateWorkshopAssets(); ModLogger.Debug("Changed filter to {0}", e.NewFilter); } catch (Exception ex) { ModLogger.Exception(ex); throw; } }
public void Update() { try { int workshopAssetCount = _workshopAssets.Count(); ModLogger.Debug("WorkshopAssetMonitor is updating {0} workshop assets", workshopAssetCount); foreach (var item in _workshopAssets) { item.UpdateInstanceCount(); } ModLogger.Debug("WorkshopMonitor updated {0} workshop assets", workshopAssetCount); } catch (Exception ex) { ModLogger.Error("An error occured while updating the workshop item list, the numbers displayed could be incorrect"); ModLogger.Exception(ex); } }
public override void OnLevelUnloading() { // Don't stop in asset and map editor if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame) { return; } try { ModLogger.Debug("Stopping WorkshopAssetMonitor"); WorkshopAssetMonitor.Instance.Stop(); ModLogger.Debug("WorkshopAssetMonitor stopped"); } catch (Exception ex) { ModLogger.Error("An error occured while stopping the WorkshopAssetMonitor"); ModLogger.Exception(ex); } }
public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { // Exit if the monitor was terminated because of an error occured when updating overwatch data if (_terminated) { return; } // Exit if the monitor has not been loaded yet by the overwatch loader when a game is loaded (prevents issues when the loader is not started yet but the monitor is) if (!OverwatchControl.Instance.GameLoaded) { return; } try { // Initialize the monitor if it wasn't initialized yet if (!_initialized) { InitializeMonitor(); } // Run an update cycle if the simulation is not currently paused else if (!SimulationManager.instance.SimulationPaused) { RunUpdateCycle(); } } catch (Exception ex) { ModLogger.Error(string.Format("An unexpected error occured while updating the {0}", _monitorType)); ModLogger.Exception(ex); _terminated = true; } base.OnUpdate(realTimeDelta, simulationTimeDelta); }
public void Start() { try { ModLogger.Debug("WorkshopAssetMonitor is loading workshop assets"); // The package manager monitors the list of workshop assets, so retrieve the packageid from each item var workshopIds = PackageManager .FilterAssets(UserAssetType.CustomAssetMetaData) .Where(a => a.isWorkshopAsset) .Select(a => new { Asset = a, Metadata = a.Instantiate <CustomAssetMetaData>() }) .Select(a => ulong.Parse(a.Asset.package.packageName)) .Distinct(); // The PrefabCollections monitor the list of all prefabs available in the game, which includes the default CS prefabs and the custom prefabs from workshop assets // Try to match the prefabs with the workshop packageid list to make sure only workshopassets are loaded. for (int i = 0; i < PrefabCollection <PropInfo> .PrefabCount(); i++) { PropInfo propPrefab = PrefabCollection <PropInfo> .GetPrefab((uint)i); if (propPrefab != null) { var workshopPropMatch = Regex.Match(propPrefab.name, RegexExpression.BuildingName, RegexOptions.IgnoreCase); if (workshopPropMatch.Success) { var workshopPropId = ulong.Parse(workshopPropMatch.Groups["packageid"].Value); if (workshopIds.Any(id => id == workshopPropId)) { _workshopAssets.Add(new WorkshopProp(workshopPropId, workshopPropMatch.Groups["prefabname"].Value, propPrefab.name)); } } } } for (int i = 0; i < PrefabCollection <TreeInfo> .PrefabCount(); i++) { TreeInfo treePrefab = PrefabCollection <TreeInfo> .GetPrefab((uint)i); if (treePrefab != null) { var workshopTreeMatch = Regex.Match(treePrefab.name, RegexExpression.BuildingName, RegexOptions.IgnoreCase); if (workshopTreeMatch.Success) { var workshopPropId = ulong.Parse(workshopTreeMatch.Groups["packageid"].Value); if (workshopIds.Any(id => id == workshopPropId)) { _workshopAssets.Add(new WorkshopTree(workshopPropId, workshopTreeMatch.Groups["prefabname"].Value, treePrefab.name)); } } } } for (int i = 0; i < PrefabCollection <BuildingInfo> .PrefabCount(); i++) { BuildingInfo buildingPrefab = PrefabCollection <BuildingInfo> .GetPrefab((uint)i); if (buildingPrefab != null) { var workshopBuildingMatch = Regex.Match(buildingPrefab.name, RegexExpression.BuildingName, RegexOptions.IgnoreCase); if (workshopBuildingMatch.Success) { var workshopBuildingId = ulong.Parse(workshopBuildingMatch.Groups["packageid"].Value); if (workshopIds.Any(id => id == workshopBuildingId)) { _workshopAssets.Add(new WorkshopBuilding(workshopBuildingId, workshopBuildingMatch.Groups["prefabname"].Value, buildingPrefab.name, buildingPrefab.GetService().ToAssetType())); } } } } ModLogger.Debug("WorkshopAssetMonitor loaded {0} workshop assets", GetWorkshopAssetCount()); } catch (Exception ex) { ModLogger.Error("An error occured while starting the workshop monitor, no workshop assets where loaded"); ModLogger.Exception(ex); } }