public static void RedirectCalls(List <RedirectCallsState> callStates, Type from, Type to, string methodName, int parametersLength) { MethodInfo originalMethod = from.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).FirstOrDefault(m => m.Name == methodName && m.GetParameters().Length == parametersLength); MethodInfo replacementMethod = to.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).FirstOrDefault(m => m.Name == methodName && m.GetParameters().Length == parametersLength); if (originalMethod != null && replacementMethod != null) { RedirectCallsState callState = RedirectionHelper.RedirectCalls(originalMethod, replacementMethod); if (callStates != null) { callStates.Add(callState); } } else { DebugOutputPanel.AddMessage(PluginManager.MessageType.Message, String.Format("Failed RedirectCalls:" + methodName)); } }
public override void OnUpdate(float realTimeDelta, float simulationTimeDelta) { if (_terminated) { return; } if (!_helper.GameLoaded) { return; } try { if (!_initialized) { if (!Helper.IsOverwatched()) { _helper.NotifyPlayer("Skylines Overwatch not found. Terminating..."); _terminated = true; return; } SkylinesOverwatch.Settings.Instance.Enable.BuildingMonitor = true; SkylinesOverwatch.Settings.Instance.Enable.VehicleMonitor = true; _landfills = new Dictionary <ushort, Landfill>(); _master = new Dictionary <ushort, Claimant>(); _updated = new HashSet <ushort>(); _oldtargets = new Dictionary <ushort, HashSet <ushort> >(); _lasttargets = new Dictionary <ushort, ushort>(); _lastchangetimes = new Dictionary <ushort, DateTime>(); _PathfindCount = new Dictionary <ushort, ushort>(); RedirectionHelper.RedirectCalls(Loader.m_redirectionStates, typeof(GarbageTruckAI), typeof(CustomGarbageTruckAI), "SetTarget", 3); _initialized = true; _helper.NotifyPlayer("Initialized"); } else if (!_baselined) { CreateBaseline(); } else { ProcessNewLandfills(); ProcessRemovedLandfills(); ProcessNewPickups(); if (!SimulationManager.instance.SimulationPaused) { ProcessIdleGarbageTrucks(); } UpdateGarbageTrucks(); _lastProcessedFrame = Singleton <SimulationManager> .instance.m_currentFrameIndex; } } catch (Exception e) { string error = String.Format("Failed to {0}\r\n", !_initialized ? "initialize" : "update"); error += String.Format("Error: {0}\r\n", e.Message); error += "\r\n"; error += "==== STACK TRACE ====\r\n"; error += e.StackTrace; _helper.Log(error); if (!_initialized) { _terminated = true; } } base.OnUpdate(realTimeDelta, simulationTimeDelta); }