public static void Deploy() { if (!deployed) { _ZoneBlock_SimulationStep_original = typeof(ZoneBlock).GetMethod("SimulationStep", BindingFlags.Public | BindingFlags.Instance); _ZoneBlock_SimulationStep_detour = typeof(ZoneBlockDetour).GetMethod("SimulationStep", BindingFlags.Static | BindingFlags.Public); _ZoneBlock_SimulationStep_state = RedirectionHelper.RedirectCalls(_ZoneBlock_SimulationStep_original, _ZoneBlock_SimulationStep_detour); _CheckBlock = typeof(ZoneBlock).GetMethod("CheckBlock", BindingFlags.NonPublic | BindingFlags.Instance); _IsGoodPlace = typeof(ZoneBlock).GetMethod("IsGoodPlace", BindingFlags.NonPublic | BindingFlags.Instance); if (Util.IsModActive(BuildingThemesMod.EIGHTY_ONE_MOD)) { _zoneGridResolution = EIGHTY_ONE_ZONEGRID_RESOLUTION; _zoneGridHalfResolution = EIGHTY_ONE_HALF_ZONEGRID_RESOLUTION; } deployed = true; Debugger.Log("Building Themes: ZoneBlock Methods detoured!"); } }
// Detours public int AddResource(ImmaterialResourceManager.Resource resource, int rate, Vector3 positionArg, float radius) { if (Debugger.Enabled && debugCounter < 10) { debugCounter++; Debugger.Log("Building Themes: Detoured ImmaterialResource.AddResource was called."); } // Catch the position of the abandoned building if (resource == ImmaterialResourceManager.Resource.Abandonment) { BuildingManagerDetour.position = positionArg; } // Call the original method RedirectionHelper.RevertRedirect(_ImmaterialResourceManager_AddResource_original, _ImmaterialResourceManager_AddResource_state); var result = Singleton <ImmaterialResourceManager> .instance.AddResource(resource, rate, positionArg, radius); RedirectionHelper.RedirectCalls(_ImmaterialResourceManager_AddResource_original, _ImmaterialResourceManager_AddResource_detour); return(result); }
private void RefreshPanel() { // We have to remove the custom tab before the original RefreshPanel method is called // RefreshPanel() checks for every policy button if the assigned policy is loaded // Our fake policy buttons are not related to a game policy GUI.ThemePolicyTab.RemoveThemesTab(); // Call the original method RedirectionHelper.RevertRedirect(_PoliciesPanel_RefreshPanel_original, _PoliciesPanel_RefreshPanel_state); try { _PoliciesPanel_RefreshPanel_original.Invoke(this, new object[] { }); } catch (Exception e) { Debugger.LogException(e); } RedirectionHelper.RedirectCalls(_PoliciesPanel_RefreshPanel_original, _PoliciesPanel_RefreshPanel_detour); // After the method call, add our custom tab again GUI.ThemePolicyTab.AddThemesTab(); }
public new virtual void InitializePrefab() { bool growable = this.m_class.GetZone() != ItemClass.Zone.None; if (growable) { //Debugger.Log("InitializePrefab called: " + this.name); } RedirectionHelper.RevertRedirect(_InitializePrefab_original, _InitializePrefab_state); base.InitializePrefab(); RedirectionHelper.RedirectCalls(_InitializePrefab_original, _InitializePrefab_detour); if (growable) { var prefabVariations = Singleton <BuildingVariationManager> .instance.CreateVariations(this).Values.ToArray <BuildingInfo>(); if (prefabVariations.Length > 0) { PrefabCollection <BuildingInfo> .InitializePrefabs("BetterUpgrade", prefabVariations, null); } //Debugger.Log("InitializePrefab done: " + this.name); } }