public void Awake()
        {
            #region Automation Hooks
            MethodInfo onEnable                 = typeof(TransportToolOverrides).GetMethod("OnEnable", allFlags);
            MethodInfo onDisable                = typeof(TransportToolOverrides).GetMethod("OnDisable", allFlags);
            MethodInfo AfterEveryAction         = typeof(TransportToolOverrides).GetMethod("AfterEveryAction", allFlags);
            MethodInfo AfterEveryActionZeroable = typeof(TransportToolOverrides).GetMethod("AfterEveryActionZeroable", allFlags);

            LogUtils.DoLog($"Loading TransportToolOverrides Hook");
            try
            {
                var tt = new TransportTool();
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("OnEnable", allFlags), null, onEnable);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("OnDisable", allFlags), onDisable);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("NewLine", allFlags).Invoke(tt, new object[0]).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryAction);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("AddStop", allFlags).Invoke(tt, new object[0]).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryAction);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("RemoveStop", allFlags).Invoke(tt, new object[0]).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryActionZeroable);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("CancelPrevStop", allFlags).Invoke(tt, new object[0]).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryActionZeroable);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("CancelMoveStop", allFlags).Invoke(tt, new object[0]).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryActionZeroable);
                RedirectorInstance.AddRedirect(typeof(TransportTool).GetMethod("MoveStop", allFlags).Invoke(tt, new object[] { false }).GetType().GetMethod("MoveNext", RedirectorUtils.allFlags), AfterEveryAction);
                Destroy(tt);
            }
            catch (Exception e)
            {
                LogUtils.DoErrorLog("ERRO AO CARREGAR HOOKS: {0}\n{1}", e.Message, e.StackTrace);
            }

            #endregion
        }
Esempio n. 2
0
        public void Awake()
        {
            #region Automation Hooks
            MethodInfo doAutomation    = typeof(TransportLineOverrides).GetMethod("DoAutomation", allFlags);
            MethodInfo preDoAutomation = typeof(TransportLineOverrides).GetMethod("PreDoAutomation", allFlags);

            TLMUtils.doLog("Loading AutoColor & AutoName Hook");
            RedirectorInstance.AddRedirect(typeof(TransportLine).GetMethod("AddStop", allFlags), preDoAutomation, doAutomation);
            #endregion


            #region Ticket Override Hooks
            MethodInfo GetTicketPriceTranspile = typeof(TransportLineOverrides).GetMethod("TicketPriceTranspilerEnterVehicle", allFlags);

            TLMUtils.doLog("Loading Ticket Override Hooks");
            RedirectorInstance.AddRedirect(typeof(HumanAI).GetMethod("EnterVehicle", allFlags), null, null, GetTicketPriceTranspile);
            #endregion
            #region Bus Spawn Unbunching
            MethodInfo BusUnbuncher = typeof(TransportLineOverrides).GetMethod("BusUnbuncher", allFlags);
            RedirectorInstance.AddRedirect(typeof(TransportLine).GetMethod("AddVehicle", allFlags), null, BusUnbuncher);
            #endregion



            #region Color Override Hooks
            MethodInfo TranspileGetColor = typeof(TransportLineOverrides).GetMethod("TranspileGetColor", allFlags);

            List <Type> allVehicleAI = ReflectionUtils.GetSubtypesRecursive(typeof(VehicleAI), typeof(VehicleAI));
            TLMUtils.doLog($"allVehicleAI size = {allVehicleAI.Count}");
            foreach (Type ai in allVehicleAI)
            {
                MethodInfo colorMethod = ai.GetMethod("GetColor", allFlags, null, new Type[] { typeof(ushort), typeof(Vehicle).MakeByRefType(), typeof(InfoManager.InfoMode) }, null);
                if (colorMethod == null)
                {
                    continue;
                }

                TLMUtils.doLog($"Loading Color Override Hooks for {ai}");
                RedirectorInstance.AddRedirect(colorMethod, null, null, TranspileGetColor);
            }
            #endregion

            #region Budget Override Hooks

            MethodInfo TranspileSimulationStepLine = typeof(TransportLineOverrides).GetMethod("TranspileSimulationStepLine", allFlags);
            MethodInfo TranspileSimulationStepAI   = typeof(TransportLineOverrides).GetMethod("TranspileSimulationStepAI", allFlags);
            TLMUtils.doLog("Loading SimulationStepPre Hook");
            RedirectorInstance.AddRedirect(typeof(TransportLine).GetMethod("SimulationStep", allFlags), null, null, TranspileSimulationStepLine);
            RedirectorInstance.AddRedirect(typeof(TransportLineAI).GetMethod("SimulationStep", allFlags, null, new Type[] { typeof(ushort), typeof(NetNode).MakeByRefType() }, null), null, null, TranspileSimulationStepAI);
            #endregion
        }
Esempio n. 3
0
        public void Awake()
        {
            MethodInfo OpenDetailPanel           = typeof(PublicTransportInfoViewPanelOverrides).GetMethod("OpenDetailPanel", allFlags);
            MethodInfo OpenDetailPanelDefaultTab = typeof(PublicTransportInfoViewPanelOverrides).GetMethod("OpenDetailPanelDefaultTab", allFlags);

            TLMUtils.doLog($"Loading PublicTransportInfoViewPanel Hooks!");
            RedirectorInstance.AddRedirect(typeof(PublicTransportInfoViewPanel).GetMethod("OpenDetailPanel", allFlags), OpenDetailPanel);
            RedirectorInstance.AddRedirect(typeof(PublicTransportInfoViewPanel).GetMethod("OpenDetailPanelDefaultTab", allFlags), OpenDetailPanelDefaultTab);
            RedirectorInstance.AddRedirect(typeof(PublicTransportInfoViewPanel).GetMethod("Start", RedirectorUtils.allFlags), typeof(PublicTransportInfoViewPanelOverrides).GetMethod("AfterAwake", RedirectorUtils.allFlags));
            RedirectorInstance.AddRedirect(typeof(ToursInfoViewPanel).GetMethod("OpenDetailPanel", allFlags), OpenDetailPanel);

            MethodInfo preventDefault = typeof(Redirector).GetMethod("PreventDefault", allFlags);
            MethodInfo from3          = typeof(PublicTransportLineInfo).GetMethod("RefreshData", allFlags);

            TLMUtils.doLog("Muting PublicTransportLineInfo: {0} ({1}=>{2})", typeof(PublicTransportLineInfo), from3, preventDefault);
            RedirectorInstance.AddRedirect(from3, preventDefault);
        }