static bool Prefix(ref bool __result, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } __result = true; return(false); }
static bool Prefix(Region __instance, Area area, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } for (int i = 0; i < area.Length; i++) { if (!__instance.IsValidCell(area[i])) { return(false); } } return(true); }
static bool Prefix(Unit item, ref ItemPutInfo __result, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } Slot slot = outsideUnits.Values.ToList().Find((Slot e) => e.unit == item); if (slot != null) { Dbgl($"Got outside put info"); __result = slot.info; return(false); } return(true); }
static bool Prefix(HomeItemSelector __instance, Vector3 pos, Rotation newPlayerRotation, bool includeLockArea, List <SelectorItem> ___selectorItems, ItemHomeSystemUnitCmpt ___systemCmpt, ItemObject ___previewItem, PreviewItemType ___previewItemType) { if (!enabled || Module <ScenarioModule> .Self.CurrentScenarioName != "Main") { return(true); } CellIndex newIndex = CellIndex.Invalid; string newFocusWallName = null; ISelector newSelector = null; float num = float.MaxValue; for (int i = 0; i < ___selectorItems.Count; i++) { HomeRegionType regionType = ___selectorItems[i].selector.GetRegionType(); bool intendPutDown = ___previewItem != null && ___previewItemType != PreviewItemType.Axe; if (!intendPutDown || (regionType == HomeRegionType.InWall && ___systemCmpt.ContainsRegionType(HomeRegionType.InWall)) || (regionType != HomeRegionType.InWall && (___systemCmpt.ContainsRegionType(HomeRegionType.InFloor) || ___systemCmpt.ContainsRegionType(HomeRegionType.OutFloor) || ___systemCmpt.ContainsRegionType(HomeRegionType.Farm)))) { float num2; CellIndex cellIndex = ___selectorItems[i].selector.GetPosCell(pos, true, out num2); if (cellIndex == CellIndex.Invalid && intendPutDown) { Vector3 vector = (___selectorItems[i].selector as RegionViewer).transform.InverseTransformPoint(pos); float ceilWidth = AccessTools.FieldRefAccess <RegionViewer, float>((___selectorItems[i].selector as RegionViewer), "ceilWidth"); cellIndex = new CellIndex((int)(vector.x / ceilWidth), (int)(-vector.z / ceilWidth)); } if (num2 > 2f || num2 < -1f) { cellIndex = CellIndex.Invalid; } num2 = Mathf.Abs(num2); if (cellIndex != CellIndex.Invalid && num2 < num) { num = num2; newIndex = cellIndex; newFocusWallName = ___selectorItems[i].wallName; newSelector = ___selectorItems[i].selector; } } } typeof(HomeItemSelector).GetMethod("SetFocusInfo", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { newIndex, newSelector, newFocusWallName, newPlayerRotation }); return(false); }
static bool Prefix(Region __instance, Area area, ref bool __result, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } for (int i = 0; i < area.Length; i++) { if (!__instance.IsValidCell(area[i])) { __result = false; return(false); } } if (settings.allowOverlapInWorkshop) { __result = false; return(false); } return(true); }
static void Prefix(Region __instance, Unit unit, ItemPutInfo info, ItemObject item, bool immobile, HomeRegionType ___regionType, int fromArchive = -1) { if (!enabled || ___regionType != HomeRegionType.Farm || __instance.IsValidCell(info.cellIndex)) { return; } ItemHomeSystemUnitCmpt component = item.GetComponent <ItemHomeSystemUnitCmpt>(); Area area = Module <UnitFactory> .Self.GetArea(info.cellIndex, info.areaRot, component, component.Rotate > 0, fromArchive); Slot slot = new Slot { unit = unit, info = info, immobile = immobile, unitObjInfo = new UnitObjInfo(item, area) }; if (outsideUnits.ContainsKey(info.cellIndex)) { outsideUnits[info.cellIndex] = slot; } else { outsideUnits.Add(info.cellIndex, slot); } }
static bool Prefix(Region __instance, CellIndex index, ref ItemObject __result, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } if (!__instance.IsValidCell(index)) { //Dbgl($"Getting outside item ({outsideUnits.Count})"); if (outsideUnits.ContainsKey(index)) { Dbgl("Got outside item"); __result = outsideUnits[index].unitObjInfo.Item; return(false); } } return(true); }
static bool Prefix(Region __instance, ref bool __result, UnitHandle unitHandle, ItemPutInfo putInfo, bool changed, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm) { return(true); } Slot slot = CreateSlotFromRSlot(unitHandle); if (slot == null) { Dbgl("slot is null"); return(true); } if (__instance.IsValidCell(putInfo.cellIndex)) { Dbgl("valid cell"); return(true); } CellIndex oldSlot = slot.info.cellIndex; slot.info = putInfo; ItemHomeSystemUnitCmpt component = slot.unitObjInfo.Item.GetComponent <ItemHomeSystemUnitCmpt>(); if (changed) { slot.unit.PutDownVersion = 71; } Area area = Module <UnitFactory> .Self.GetArea(putInfo.cellIndex, putInfo.areaRot, component, component.Rotate > 0, slot.unit.PutDownVersion); if (area == null) { __result = false; return(false); } slot.area = area; slot.unitObjInfo = new UnitObjInfo(slot.unitObjInfo.Item, area); outsideUnits.Remove(oldSlot); if (!outsideUnits.ContainsKey(slot.info.cellIndex)) { outsideUnits.Add(slot.info.cellIndex, slot); } else { outsideUnits[slot.info.cellIndex] = slot; } var mySlot = CreateRSlotFromSlot(slot); typeof(Region).GetMethod("AddSlot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { mySlot }); __result = true; return(false); }
static bool Region_TakeUpItem_Prefix(Region __instance, ref ItemObject __result, CellIndex index, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm || !outsideUnits.ContainsKey(index)) { return(true); } Slot slot = outsideUnits[index]; if (slot.unit != null) { if (slot.unit.IsLimitCount) { typeof(Region).GetProperty("LimitUnitCount").SetValue(__instance, (int)typeof(Region).GetProperty("LimitUnitCount").GetValue(__instance, null) - 1, null); } slot.unit.TakeUp(delegate(int id, int number) { if (id >= 0) { Module <Player> .Self.bag.AddItem(id, number, true, AddItemMode.Default); } else { Module <Player> .Self.bag.ChangeMoney(number, true, 0); } }); } var mySlot = AccessTools.FieldRefAccess <Region, List <object> >(__instance, "slots").Find((object o) => typeof(Region).GetNestedType("Slot", BindingFlags.NonPublic | BindingFlags.Instance).GetField("unit").GetValue(o) == slot.unit); if (mySlot != null) { typeof(Region).GetMethod("RemoveSlot", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(__instance, new object[] { mySlot }); } if (slot.unit != null && slot.unit.NeedUpdate) { Module <HomeUnitUpdater> .Self.RemoveUpdateableUnit(slot.unit); } outsideUnits.Remove(index); __result = slot.unitObjInfo.Item; return(false); }
static bool Prefix(ref bool __result, CellIndex index, ref string reason, HomeRegionType ___regionType) { if (!enabled || ___regionType != HomeRegionType.Farm || !outsideUnits.ContainsKey(index)) { return(true); } __result = false; reason = string.Empty; return(false); }