[HarmonyPrefix] // We're attempting to replace the geometry building method public static bool Prefix(ref Base __instance, Int3 cell) { Int3 v = Base.CellSize[7]; Int3.Bounds bounds = new Int3.Bounds(cell, cell + v - 1); BaseDeconstructable parent = null; if (__instance.GetCellMask(cell)) { Transform transform = __instance.SpawnPiece(Base.Piece.Moonpool, cell); parent = BaseDeconstructable.MakeCellDeconstructable(transform, bounds, TechType.BaseMoonpool); transform.tag = "MainPieceGeometry"; } for (int i = 0; i < Base.moonpoolFaces.Length; i++) { Base.RoomFace roomFace = Base.moonpoolFaces[i]; Base.Face face = new Base.Face(cell + roomFace.offset, roomFace.direction); if (__instance.GetFaceMask(face)) { Base.FaceType face2 = __instance.GetFace(face); Base.Piece moonpoolPiece = __instance.GetMoonpoolPiece(face, face2); if (moonpoolPiece != Base.Piece.Invalid) { Transform transform2 = __instance.SpawnPiece(moonpoolPiece, cell, roomFace.rotation, null); transform2.localPosition = Int3.Scale(roomFace.offset, Base.cellSize) + roomFace.localOffset; if (face2 != Base.FaceType.Solid) { TechType recipe = Base.FaceToRecipe[(int)face2]; BaseDeconstructable baseDeconstructable = BaseDeconstructable.MakeFaceDeconstructable(transform2, bounds, face, face2, recipe); if (!__instance.isGhost) { transform2.GetComponentsInChildren <IBaseModuleGeometry>(true, Base.sBaseModulesGeometry); int j = 0; int count = Base.sBaseModulesGeometry.Count; while (j < count) { IBaseModuleGeometry baseModuleGeometry = Base.sBaseModulesGeometry[j]; baseModuleGeometry.geometryFace = face; j++; } Base.sBaseModulesGeometry.Clear(); if (face2 == Base.FaceType.UpgradeConsole) { baseDeconstructable.LinkModule(new Base.Face?(new Base.Face(face.cell - __instance.anchor, face.direction))); } } } else if (!__instance.isGhost) { BaseExplicitFace.MakeFaceDeconstructable(transform2, face, parent); } } } } return(false); }
private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata) { BaseGhost component = ghostModel.GetComponent <BaseGhost>(); if (component == null) { Log.Error("Was unable to apply rotation metadata - no BaseGhost found"); } else if (component.GetType() != rotationMetadata.GhostType) { Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType); } else if (component is BaseAddCorridorGhost corridor) { Log.Info("Placing BaseAddCorridorGhost Rotation Metadata"); CorridorRotationMetadata corridorRotationMetadata = (CorridorRotationMetadata)rotationMetadata; corridor.rotation = corridorRotationMetadata.Rotation; int corridorType = corridor.CalculateCorridorType(); corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.RebuildGhostGeometry(); } else if (component is BaseAddMapRoomGhost mapRoom) { Log.Info("Placing MapRoomRotationMetadata Rotation Metadata"); MapRoomRotationMetadata mapRoomRotationMetadata = (MapRoomRotationMetadata)rotationMetadata; mapRoom.cellType = (Base.CellType)mapRoomRotationMetadata.CellType; mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask; mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.RebuildGhostGeometry(); } else if (component is BaseAddModuleGhost ghost) { BaseModuleRotationMetadata baseModuleRotationMetadata = (BaseModuleRotationMetadata)rotationMetadata; ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); ghost.RebuildGhostGeometry(); } else if (component is BaseAddFaceGhost faceGhost) { AnchoredFaceRotationMetadata baseModuleRotationMetadata = (AnchoredFaceRotationMetadata)rotationMetadata; Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata); Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; faceGhost.ghostBase.SetFace(face, faceType); faceGhost.RebuildGhostGeometry(); } }
private static void ApplyRotationMetadata(BaseGhost baseGhost, BuilderMetadata builderMetadata) { switch (baseGhost) { case BaseAddCorridorGhost corridor when builderMetadata is CorridorBuilderMetadata corridorRotationMetadata: { corridor.rotation = corridorRotationMetadata.Rotation; int corridorType = corridor.CalculateCorridorType(); corridor.ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.RebuildGhostGeometry(); break; } case BaseAddMapRoomGhost mapRoom when builderMetadata is MapRoomBuilderMetadata mapRoomRotationMetadata: { mapRoom.cellType = (Base.CellType)mapRoomRotationMetadata.CellType; mapRoom.connectionMask = mapRoomRotationMetadata.ConnectionMask; mapRoom.ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.RebuildGhostGeometry(); break; } case BaseAddModuleGhost ghost when builderMetadata is BaseModuleBuilderMetadata baseModuleRotationMetadata: { ghost.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); ghost.RebuildGhostGeometry(); break; } case BaseAddFaceGhost faceGhost when builderMetadata is AnchoredFaceBuilderMetadata baseModuleRotationMetadata: { Base.Face face = new(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; faceGhost.ghostBase.SetFace(face, faceType); faceGhost.RebuildGhostGeometry(); break; } default: Log.Error($"Was unable to apply rotation metadata for {baseGhost.GetType()} and {builderMetadata}"); break; } }
private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadata rotationMetadata) { BaseGhost component = ghostModel.GetComponent <BaseGhost>(); if (component == null) { Log.Error("Was unable to apply rotation metadata - no BaseGhost found"); } else if (component.GetType() != rotationMetadata.GhostType) { Log.Error("Was unable to apply rotation metadata - " + component.GetType() + " did not match " + rotationMetadata.GhostType); } else if (component is BaseAddCorridorGhost) { Log.Info("Placing BaseAddCorridorGhost Rotation Metadata"); CorridorRotationMetadata corridorRotationMetadata = (rotationMetadata as CorridorRotationMetadata); BaseAddCorridorGhost corridor = (component as BaseAddCorridorGhost); corridor.ReflectionSet("rotation", corridorRotationMetadata.Rotation); int corridorType = (int)corridor.ReflectionCall("CalculateCorridorType"); Base ghostBase = (Base)corridor.ReflectionGet("ghostBase"); ghostBase.SetCorridor(Int3.zero, corridorType, corridor.isGlass); corridor.ReflectionCall("RebuildGhostGeometry"); } else if (component is BaseAddMapRoomGhost) { Log.Info("Placing MapRoomRotationMetadata Rotation Metadata"); MapRoomRotationMetadata mapRoomRotationMetadata = (rotationMetadata as MapRoomRotationMetadata); BaseAddMapRoomGhost mapRoom = (component as BaseAddMapRoomGhost); mapRoom.ReflectionSet("cellType", mapRoomRotationMetadata.CellType); mapRoom.ReflectionSet("connectionMask", mapRoomRotationMetadata.ConnectionMask); Base ghostBase = (Base)mapRoom.ReflectionGet("ghostBase"); ghostBase.SetCell(Int3.zero, (Base.CellType)mapRoomRotationMetadata.CellType); mapRoom.ReflectionCall("RebuildGhostGeometry"); } else if (component is BaseAddModuleGhost) { BaseModuleRotationMetadata baseModuleRotationMetadata = (rotationMetadata as BaseModuleRotationMetadata); BaseAddModuleGhost module = (component as BaseAddModuleGhost); module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); module.ReflectionCall("RebuildGhostGeometry"); } else if (component is BaseAddFaceGhost) { AnchoredFaceRotationMetadata baseModuleRotationMetadata = (rotationMetadata as AnchoredFaceRotationMetadata); BaseAddFaceGhost faceGhost = (component as BaseAddFaceGhost); Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata); Base.Face face = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction); faceGhost.anchoredFace = face; Base ghostBase = (Base)faceGhost.ReflectionGet("ghostBase"); Base.FaceType faceType = (Base.FaceType)baseModuleRotationMetadata.FaceType; ghostBase.SetFace(face, faceType); faceGhost.ReflectionCall("RebuildGhostGeometry"); } }
private static BaseDeconstructable FindBaseDeconstructable(string guid, string baseGuid, Base.FaceType faceType, Base.Face face, Int3.Bounds bounds) { var baseObject = GuidHelper.Find(baseGuid); if (baseObject != null) { foreach (var item in baseObject.GetAllComponentsInChildren <BaseDeconstructable>()) { if (item.faceType != faceType) { continue; } if (item.bounds != bounds) { continue; } if (item.face.GetValueOrDefault() != face) { continue; } GuidHelper.Set(item.gameObject, guid); return(item); } } if (string.IsNullOrEmpty(guid) == false) { Log.Warn("Couldn't find base deconstructable: " + guid); } return(null); }