public static void Patch() { var version = QuickLogger.GetAssemblyVersion(Assembly.GetExecutingAssembly()); QuickLogger.Info($"Started patching. Version: {version}"); #if DEBUG QuickLogger.DebugLogsEnabled = true; QuickLogger.Debug("Debug logs enabled"); #endif try { GlobalBundle = FcAssetBundlesService.PublicAPI.GetAssetBundleByName(FcAssetBundlesService.PublicAPI.GlobalBundleName); if (GlobalBundle == null) { QuickLogger.Error("Global Bundle has returned null stopping patching"); throw new FileNotFoundException("Bundle failed to load"); } AddItemsToTechFabricator(); GaspodCollectorBuildable.PatchHelper(); Configuration = Mod.LoadConfiguration(); var harmony = HarmonyInstance.Create("com.gaspodcollector.fcstudios"); harmony.PatchAll(Assembly.GetExecutingAssembly()); QuickLogger.Info("Finished patching"); } catch (Exception ex) { QuickLogger.Error(ex); } }
public override bool CanDeconstruct(out string reason) { if (IsBeaconAttached()) { reason = GaspodCollectorBuildable.RemoveBeacon(); return(false); } if (GaspodCollectorStorage != null && GaspodCollectorStorage.GetStorageAmount() > 0) { reason = GaspodCollectorBuildable.NotEmpty(); return(false); } if (PowerManager != null && PowerManager.HasPower()) { reason = GaspodCollectorBuildable.HasBatteries(); return(false); } reason = string.Empty; return(true); }
internal void Setup(GaspodCollectorController mono) { _mono = mono; var equipmentRoot = new GameObject("BEquipmentRoot"); equipmentRoot.transform.SetParent(gameObject.transform, false); equipmentRoot.AddComponent <ChildObjectIdentifier>(); equipmentRoot.SetActive(false); _equipment = new Equipment(gameObject, equipmentRoot.transform); _equipment.SetLabel(GaspodCollectorBuildable.EquipmentContainerLabel()); Type equipmentType = typeof(Equipment); EventInfo onEquipInfo = equipmentType.GetEvent("onEquip", BindingFlags.Public | BindingFlags.Instance); EventInfo onUnequipInfo = equipmentType.GetEvent("onUnequip", BindingFlags.Public | BindingFlags.Instance); Type powerManagerType = typeof(GasopdCollectorPowerManager); MethodInfo myOnEquipMethod = powerManagerType.GetMethod("OnEquip", BindingFlags.Instance | BindingFlags.NonPublic); MethodInfo myOnUnequipMethod = powerManagerType.GetMethod("OnUnequip", BindingFlags.Instance | BindingFlags.NonPublic); var onEquipDelegate = Delegate.CreateDelegate(typeof(Equipment.OnEquip), this, myOnEquipMethod); var onUnequipDelegate = Delegate.CreateDelegate(typeof(Equipment.OnUnequip), this, myOnUnequipMethod); onEquipInfo.AddEventHandler(_equipment, onEquipDelegate); onUnequipInfo.AddEventHandler(_equipment, onUnequipDelegate); _equipment.AddSlot(Slot1); _equipment.AddSlot(Slot2); if (_equipment == null) { QuickLogger.Error("Equipment is null on creation"); } }
public override bool FindAllComponents() { try { if (_isInitialized) { return(true); } #region Canvas var canvasGameObject = gameObject.GetComponentInChildren <Canvas>()?.gameObject; if (canvasGameObject == null) { QuickLogger.Error("Canvas cannot be found"); return(false); } #endregion #region Home var home = InterfaceHelpers.FindGameObject(canvasGameObject, "Home"); #endregion #region Amount _amountOfPodsCount = InterfaceHelpers.FindGameObject(home, "AmountOfPodsCount")?.GetComponent <Text>(); #endregion #region GasPodButton var gasPodButtonObj = InterfaceHelpers.FindGameObject(home, "GasPodButton"); InterfaceHelpers.CreateButton(gasPodButtonObj, "GasPodBTN", InterfaceButtonMode.Background, OnButtonClick, Color.black, Color.white, MAX_INTERACTION_DISTANCE, GaspodCollectorBuildable.TakeGaspod()); var image = gasPodButtonObj.transform.Find("Image"); var guiIcon = image.gameObject.EnsureComponent <uGUI_Icon>(); guiIcon.sprite = SpriteManager.Get(TechType.GasPod); #endregion #region DumpBTNButton var dumpBTNButtonObj = InterfaceHelpers.FindGameObject(home, "DumpBTN"); InterfaceHelpers.CreateButton(dumpBTNButtonObj, "DumpBTN", InterfaceButtonMode.Background, OnButtonClick, Color.black, Color.white, MAX_INTERACTION_DISTANCE, GaspodCollectorBuildable.DumpPull(), GaspodCollectorBuildable.DumpMessage()); #endregion #region Messages InterfaceHelpers.FindGameObject(home, "AmountOfPods").GetComponent <Text>().text = GaspodCollectorBuildable.AmountOfPodsMessage(); InterfaceHelpers.FindGameObject(home, "ClickToTake").GetComponent <Text>().text = GaspodCollectorBuildable.InstructionsMessage(); InterfaceHelpers.FindGameObject(home, "Battery (1)").FindChild("Battery Label").GetComponent <Text>().text = $"{GaspodCollectorBuildable.Battery()} 1"; InterfaceHelpers.FindGameObject(home, "Battery (2)").FindChild("Battery Label").GetComponent <Text>().text = $"{GaspodCollectorBuildable.Battery()} 2"; #endregion #region ColorPicker Button var colorBTN = InterfaceHelpers.FindGameObject(home, "ColorBTN"); InterfaceHelpers.CreateButton(colorBTN, "ColorBTN", InterfaceButtonMode.Background, OnButtonClick, _startColor, _hoverColor, MAX_INTERACTION_DISTANCE, GaspodCollectorBuildable.ColorPicker()); #endregion #region Battery Button var batteryBTN = InterfaceHelpers.FindGameObject(home, "BatteryBTN").FindChild("Fill"); InterfaceHelpers.CreateButton(batteryBTN, "BatteryBTN", InterfaceButtonMode.Background, OnButtonClick, _greenColor, _fireBrickColor, MAX_INTERACTION_DISTANCE, GaspodCollectorBuildable.BatteryReceptacle()); #endregion #region ColorPicker var colorPicker = InterfaceHelpers.FindGameObject(canvasGameObject, "ColorPicker"); #endregion #region Color Paginator var _colorPaginator = InterfaceHelpers.FindGameObject(colorPicker, "Paginator"); #endregion #region Color Grid var _colorGrid = InterfaceHelpers.FindGameObject(colorPicker, "Grid"); #endregion #region ColorPage _colorPage.SetupGrid(66, GaspodCollectorBuildable.ColorItemPrefab, _colorGrid, _colorPaginator.GetComponent <Text>(), OnButtonClick); #endregion #region Prev Color Button var prevColorBtn = InterfaceHelpers.FindGameObject(colorPicker, "PrevBTN"); InterfaceHelpers.CreatePaginator(prevColorBtn, -1, _colorPage.ChangeColorPageBy, _startColor, _hoverColor); #endregion #region Next Color Button var nextColorBtn = InterfaceHelpers.FindGameObject(colorPicker, "NextBTN"); InterfaceHelpers.CreatePaginator(nextColorBtn, 1, _colorPage.ChangeColorPageBy, _startColor, _hoverColor); #endregion #region HomeButton var homeBTN = InterfaceHelpers.FindGameObject(colorPicker, "HomeBTN"); InterfaceHelpers.CreateButton(homeBTN, "HomeBTN", InterfaceButtonMode.Background, OnButtonClick, _startColor, _hoverColor, MAX_INTERACTION_DISTANCE, GaspodCollectorBuildable.GoHome()); #endregion #region Batteries var b1 = InterfaceHelpers.FindGameObject(home, "Battery (1)"); var b2 = InterfaceHelpers.FindGameObject(home, "Battery (2)"); _b1Fill = InterfaceHelpers.FindGameObject(b1, "Fill")?.GetComponent <Image>(); _b2Fill = InterfaceHelpers.FindGameObject(b2, "Fill")?.GetComponent <Image>(); _b1Amount = InterfaceHelpers.FindGameObject(b1, "Amount")?.GetComponent <Text>(); _b2Amount = InterfaceHelpers.FindGameObject(b2, "Amount")?.GetComponent <Text>(); #endregion return(true); } catch (Exception e) { QuickLogger.Error <GasopodCollectorDisplayManager>($"{e.Message}\n{e.StackTrace}"); return(false); } }