public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { base.RenderOverlay(cameraInfo); if (!enabled) { return; } if (np_hoveredObject.NetSegment != 0) { NetSegment hoveredSegment = np_hoveredObject.NetSegment.S(); NetTool.RenderOverlay(cameraInfo, ref hoveredSegment, _hovc, new Color(1f, 0f, 0f, 1f)); } else if (np_hoveredObject.NetNode != 0 && np_hoveredObject.NetNode < 32768) { NetNode hoveredNode = np_hoveredObject.NetNode.N(); RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, _hovc, hoveredNode.m_position, Mathf.Max(6f, hoveredNode.Info.m_halfWidth * 2f), -1f, 1280f, false, true); } else if (np_hoveredObject.Building != 0) { Building hoveredBuilding = np_hoveredObject.Building.B(); BuildingTool.RenderOverlay(cameraInfo, ref hoveredBuilding, _hovc, _hovc); } else if (np_hoveredObject.Tree != 0) { TreeInstance hoveredTree = np_hoveredObject.Tree.T(); TreeTool.RenderOverlay(cameraInfo, hoveredTree.Info, hoveredTree.Position, hoveredTree.Info.m_minScale, _hovc); } else if (np_hoveredObject.Prop != 0) { PropInstance hoveredTree = np_hoveredObject.Prop.P(); PropTool.RenderOverlay(cameraInfo, hoveredTree.Info, hoveredTree.Position, hoveredTree.Info.m_minScale, hoveredTree.Angle, _hovc); } }
/// <summary> /// Intended for internal accurate rendering only. /// </summary> /// <param name="cameraInfo"></param> /// <param name="container"></param> private static void RenderProp(RenderManager.CameraInfo cameraInfo, PropContainer container) { if ((container.propInstance.m_flags & 68) != 0) { return; } PropInfo info = container.propInstance.Info; Vector3 inaccuratePosition = container.propInstance.Position; Vector3 position = new Vector3(container.extras["accx"], inaccuratePosition.y, container.extras["accz"]); if (!cameraInfo.CheckRenderDistance(position, info.m_maxRenderDistance) || !cameraInfo.Intersect(position, info.m_generatedInfo.m_size.y * info.m_maxScale)) { return; } float angle = container.propInstance.Angle; Randomizer r = new Randomizer(0); float scale = info.m_minScale + (float)((double)r.Int32(10000U) * ((double)info.m_maxScale - (double)info.m_minScale) * 9.99999974737875E-05); Color color = info.GetColor(ref r); Vector4 objectIndex = new Vector4(1f / 512f, 1f / 384f, 0.0f, 0.0f); InstanceID id = new InstanceID(); if (info.m_requireHeightMap) { Texture _HeightMap; Vector4 _HeightMapping; Vector4 _SurfaceMapping; TerrainManager.instance.GetHeightMapping(position, out _HeightMap, out _HeightMapping, out _SurfaceMapping); PropInstance.RenderInstance(cameraInfo, info, id, position, scale, angle, color, objectIndex, true, _HeightMap, _HeightMapping, _SurfaceMapping); } else { PropInstance.RenderInstance(cameraInfo, info, id, position, scale, angle, color, objectIndex, true); } }
private static Matrix4x4 RenderProp(ushort refId, float refAngleRad, RenderManager.CameraInfo cameraInfo, PropInfo propInfo, Color propColor, Vector3 position, Vector4 dataVector, int idx, Vector3 rotation, Vector3 scale, int layerMask, out bool rendered, InstanceID propRenderID2) { rendered = false; var randomizer = new Randomizer((refId << 6) | (idx + 32)); Matrix4x4 matrix = default; matrix.SetTRS(position, Quaternion.AngleAxis(rotation.y + (refAngleRad * Mathf.Rad2Deg), Vector3.down) * Quaternion.AngleAxis(rotation.x, Vector3.left) * Quaternion.AngleAxis(rotation.z, Vector3.back), scale); if (propInfo != null) { propInfo = propInfo.GetVariation(ref randomizer); if (cameraInfo.CheckRenderDistance(position, propInfo.m_maxRenderDistance * scale.sqrMagnitude)) { int oldLayerMask = cameraInfo.m_layerMask; float oldRenderDist = propInfo.m_lodRenderDistance; propInfo.m_lodRenderDistance *= scale.sqrMagnitude; cameraInfo.m_layerMask = 0x7FFFFFFF; try { PropInstance.RenderInstance(cameraInfo, propInfo, propRenderID2, matrix, position, scale.y, refAngleRad + (rotation.y * Mathf.Deg2Rad), propColor, dataVector, true); } finally { propInfo.m_lodRenderDistance = oldRenderDist; cameraInfo.m_layerMask = oldLayerMask; } rendered = true; } } return(matrix); }
public static void set_Blocked(ref PropInstance prop, bool value) { if (!value) { prop.m_flags = (ushort)((uint)prop.m_flags & 4294967231U); } }
/// <summary> /// Replaces a map prop. /// </summary> /// <param name="target">Prop to replace</param> /// <param name="replacement">Replacement prop</param> private void ReplaceProps(PropInfo target, PropInfo replacement) { // Check for valid parameters. if (target != null && replacement != null) { // Local references. PropManager propManager = Singleton <PropManager> .instance; PropInstance[] props = propManager.m_props.m_buffer; Logging.Message("replacing tree ", target.name, " with ", replacement.name); // Iterate through each tree in map. for (uint propIndex = 0; propIndex < props.Length; ++propIndex) { // Local reference. PropInstance prop = props[propIndex]; // Skip non-existent trees (those with no flags). if (prop.m_flags == (ushort)PropInstance.Flags.None) { continue; } // If tree matches, replace! if (prop.Info == target) { props[propIndex].Info = replacement; // Refresh tree render (to update LOD). propManager.UpdatePropRenderer((ushort)propIndex, true); } } } }
public static void PopulateGroupData(ref PropInstance prop, ushort propID, int layer, ref int vertexIndex, ref int triangleIndex, Vector3 groupPosition, RenderGroup.MeshData data, ref Vector3 min, ref Vector3 max, ref float maxRenderDistance, ref float maxInstanceDistance) { if (prop.Blocked) { return; } PropInfo info = prop.Info; //add null check //begin mod if (info == null) { return; } //end mod Vector3 position = prop.Position; Randomizer r = new Randomizer((int)propID); float scale = info.m_minScale + (float)((double)r.Int32(10000U) * ((double)info.m_maxScale - (double)info.m_minScale) * 9.99999974737875E-05); float angle = prop.Angle; Color color = info.GetColor(ref r); PropInstance.PopulateGroupData(info, layer, new InstanceID() { Prop = propID }, position, scale, angle, color, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance); }
public override void RenderGeometry(RenderManager.CameraInfo cameraInfo) { PropInfo info = this.m_propInfo; if (info != null && (this.m_placementErrors == ToolBase.ToolErrors.None && !this.m_toolController.IsInsideUI) && Cursor.visible) { Randomizer r1 = this.m_randomizer; Randomizer r2 = new Randomizer((int)Singleton <PropManager> .instance.m_props.NextFreeItem(ref r1)); float scale = info.m_minScale + (float)((double)r2.Int32(10000U) * ((double)info.m_maxScale - (double)info.m_minScale) * 9.99999974737875E-05); Color color = info.GetColor(ref r2); InstanceID id = new InstanceID(); if (info.m_requireHeightMap) { Texture _HeightMap; Vector4 _HeightMapping; Vector4 _SurfaceMapping; Singleton <TerrainManager> .instance.GetHeightMapping(this.m_cachedPosition, out _HeightMap, out _HeightMapping, out _SurfaceMapping); PropInstance.RenderInstance(cameraInfo, info, id, this.m_cachedPosition, scale, this.m_cachedAngle, color, RenderManager.DefaultColorLocation, true, _HeightMap, _HeightMapping, _SurfaceMapping); } else { PropInstance.RenderInstance(cameraInfo, info, id, this.m_cachedPosition, scale, this.m_cachedAngle, color, RenderManager.DefaultColorLocation, true); } } base.RenderGeometry(cameraInfo); }
public static void RenderCloneGeometryImplementation(InstanceState instanceState, ref Matrix4x4 matrix4x, Vector3 deltaPosition, float deltaAngle, Vector3 center, bool followTerrain, RenderManager.CameraInfo cameraInfo) { InstanceID id = instanceState.instance.id; PropInfo info = instanceState.Info.Prefab as PropInfo; Randomizer randomizer = new Randomizer(id.Prop); float scale = info.m_minScale + (float)randomizer.Int32(10000u) * (info.m_maxScale - info.m_minScale) * 0.0001f; Vector3 newPosition = matrix4x.MultiplyPoint(instanceState.position - center); newPosition.y = instanceState.position.y + deltaPosition.y; if (followTerrain) { newPosition.y = newPosition.y - instanceState.terrainHeight + TerrainManager.instance.SampleOriginalRawHeightSmooth(newPosition); } float newAngle = instanceState.angle + deltaAngle; if (info.m_requireHeightMap) { TerrainManager.instance.GetHeightMapping(newPosition, out Texture heightMap, out Vector4 heightMapping, out Vector4 surfaceMapping); PropInstance.RenderInstance(cameraInfo, info, id, newPosition, scale, newAngle, info.GetColor(ref randomizer), RenderManager.DefaultColorLocation, true, heightMap, heightMapping, surfaceMapping); } else { PropInstance.RenderInstance(cameraInfo, info, id, newPosition, scale, newAngle, info.GetColor(ref randomizer), RenderManager.DefaultColorLocation, true); } }
public override void Draw(RenderManager.CameraInfo cameraInfo, RenderManager.Instance data) { var instance = new InstanceID() { }; foreach (var item in Items) { PropInstance.RenderInstance(cameraInfo, Info, instance, item.Position, item.Scale, item.Angle, item.Color, new Vector4(), true); } }
public void TouchProps() { int bufferLen = Math.Min(ushort.MaxValue, Singleton <PropManager> .instance.m_props.m_buffer.Length); for (ushort i = 0; i < bufferLen; i++) { ref PropInstance prop = ref Singleton <PropManager> .instance.m_props.m_buffer[i]; if (((PropInstance.Flags)prop.m_flags & PropInstance.Flags.Created) == PropInstance.Flags.Created) { SimulationManager.instance.AddAction(() => { Singleton <PropManager> .instance.UpdateProp(i); }); } }
public static void Postfix(ref RenderManager.CameraInfo cameraInfo) { ItemClass.Availability availability = ToolManager.instance.m_properties.m_mode; FastList <RenderGroup> fastList = RenderManager.instance.m_renderedGroups; int num1 = 1 << LayerMask.NameToLayer("Props") | 1 << RenderManager.instance.lightSystem.m_lightLayer; for (int index1 = 0; index1 < fastList.m_size; ++index1) { RenderGroup renderGroup = fastList.m_buffer[index1]; if ((renderGroup.m_instanceMask & num1) != 0) { int minX = renderGroup.m_x * 270 / 45; int minZ = renderGroup.m_z * 270 / 45; int maxX = (renderGroup.m_x + 1) * 270 / 45 - 1; int maxZ = (renderGroup.m_z + 1) * 270 / 45 - 1; for (int index2 = minZ; index2 <= maxZ; ++index2) { for (int index3 = minX; index3 <= maxX; ++index3) { int gridKey = index2 * 270 + index3; List <PropContainer> list = PropUnlimiterManager.instance.GetPropsInGrid(gridKey); if (list != null) { foreach (PropContainer instance in list) { if (instance.extras.ContainsKey("accx") && instance.extras.ContainsKey("accy") && instance.extras.ContainsKey("accz")) { RenderProp(cameraInfo, instance); } else { instance.propInstance.RenderInstance(cameraInfo, 0, renderGroup.m_instanceMask); } } } } } } } for (int index = 0; index < PrefabCollection <PropInfo> .PrefabCount(); ++index) { PropInfo prefab = PrefabCollection <PropInfo> .GetPrefab((uint)index); if (prefab != null && prefab.m_lodCount != 0) { PropInstance.RenderLod(cameraInfo, prefab); } } }
public static bool Prefix(BulldozeTool __instance, ref RenderManager.CameraInfo cameraInfo) { if (ContainerHolder.instance != null) { PropInstance propInstance = ContainerHolder.instance.propInstance; float size = Mathf.Max(propInstance.Info.m_generatedInfo.m_size.x, propInstance.Info.m_generatedInfo.m_size.z) * 1; Vector3 position = propInstance.Position; ++ToolManager.instance.m_drawCallData.m_overlayCalls; RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, toolColor, position, size, position.y - 100f, position.y + 100f, false, true); return(false); } return(true); }
public static PropWrapper GeneratePropWrapper(PropContainer propContainer) { PropWrapper retVal = new PropWrapper(); PropInstance instance = propContainer.propInstance; Dictionary <string, float> extras = propContainer.extras; retVal.infoIndex = instance.m_infoIndex; retVal.positionX = instance.m_posX; retVal.positionY = instance.m_posY; retVal.positionZ = instance.m_posZ; retVal.angle = instance.Angle; retVal.single = instance.Single; retVal.extraJson = JsonMapper.ToJson(extras); return(retVal); }
public static void Postfix(bool __result, ref ushort prop, Vector3 position, float angle, bool single) { if (__result) { PropInstance propInstance = Singleton <PropManager> .instance.m_props.m_buffer[prop]; Command.SendToAll(new PropCreateCommand { position = position, PropID = prop, single = single, angle = angle, infoindex = propInstance.m_infoIndex }); } }
public static PropMessage PrepareProp(ushort id) { if (!ManagersUtil.ExistsProp(id)) { return(null); } PropInstance prop = ManagersUtil.Prop(id); return(new PropMessage() { id = id, position = prop.Position.FromUnity(), prefab_name = prop.Info.name, angle = prop.Angle }); }
public Prop[] GenerateSupComProps() { int count = PropsInstances.Count; Prop[] Props = new Prop[count]; int i = 0; foreach (Prop PropInstance in PropsInstances) { PropInstance.Bake(); Props[i] = PropInstance; i++; } return(Props); }
private bool TryGetProp(ushort propInstanceId, out PropInstance propInstance) { bool result = false; propInstance = default(PropInstance); var tryProp = Singleton <PropManager> .instance.m_props.m_buffer[(int)propInstanceId]; if (tryProp.Info != null && ((PropInstance.Flags)tryProp.m_flags & PropInstance.Flags.Created) != PropInstance.Flags.None) { propInstance = tryProp; result = true; } return(result); }
public static bool Prefix() { if (Event.current.type == EventType.MouseDown && Event.current.button == (int)UIMouseButton.None) { if (ContainerHolder.instance != null) { PropInstance propInstance = ContainerHolder.instance.propInstance; PropUnlimiterManager.instance.DeleteProp(ContainerHolder.gridKey, ContainerHolder.instance); PropTool.DispatchPlacementEffect(propInstance.Position, true); ContainerHolder.instance = null; ContainerHolder.gridKey = -1; return(false); } } return(true); }
private static void CheckOverlap(ref PropInstance prop, ushort propID) //this method reproduces original code for most part to prevent exceptions { PropInfo info = prop.Info; if (info == null) { return; } ItemClass.CollisionType collisionType = ((int)prop.m_flags & 32) != 0 ? ItemClass.CollisionType.Elevated : ItemClass.CollisionType.Terrain; Randomizer randomizer = new Randomizer((int)propID); float num1 = info.m_minScale + (float)((double)randomizer.Int32(10000U) * ((double)info.m_maxScale - (double)info.m_minScale) * 9.99999974737875E-05); float num2 = info.m_generatedInfo.m_size.y * num1; Vector3 position = prop.Position; float minY = position.y; float maxY = position.y + num2; float num3 = !prop.Single ? 4.5f : 0.3f; Quad2 quad = new Quad2(); Vector2 vector2 = VectorUtils.XZ(position); quad.a = vector2 + new Vector2(-num3, -num3); quad.b = vector2 + new Vector2(-num3, num3); quad.c = vector2 + new Vector2(num3, num3); quad.d = vector2 + new Vector2(num3, -num3); bool flag = false; if (info.m_class != null) { if (Singleton <NetManager> .instance.OverlapQuad(quad, minY, maxY, collisionType, info.m_class.m_layer, (ushort)0, (ushort)0, (ushort)0)) { flag = true; } if (Singleton <BuildingManager> .instance.OverlapQuad(quad, minY, maxY, collisionType, info.m_class.m_layer, (ushort)0, (ushort)0, (ushort)0)) { flag = true; } } //begin mod if (!OptionsWrapper <Options> .Options.unhideAllPropsOnLevelLoading) { return; } prop.Blocked = false; //end mod }
public static void AfterTerrainUpdated(ref PropInstance prop, ushort propID, float minX, float minZ, float maxX, float maxZ) { if (((int)prop.m_flags & 3) != 1 || ((int)prop.m_flags & 32) != 0) { return; } Vector3 position = prop.Position; position.y = Singleton <TerrainManager> .instance.SampleDetailHeight(position); ushort num = (ushort)Mathf.Clamp(Mathf.RoundToInt(position.y * 64f), 0, (int)ushort.MaxValue); if ((int)num == (int)prop.m_posY) { return; } bool blocked1 = prop.Blocked; //begin mod if (ToolsModifierControl.GetCurrentTool <TerrainTool>() == null || OptionsWrapper <Options> .Options.dontUpdateYOnTerrainModification) { prop.m_posY = (OptionsWrapper <Options> .Options.allowToSubmerge || prop.m_posY > num) ? prop.m_posY : num; } else { prop.m_posY = num; } //end mod bool blocked2 = prop.Blocked; if (blocked2 != blocked1) { Singleton <PropManager> .instance.UpdateProp(propID); } else { if (blocked2) { return; } Singleton <PropManager> .instance.UpdatePropRenderer(propID, true); } }
public static void Postfix(bool __result, ref ushort prop, Vector3 position, float angle, bool single) { if (IgnoreHelper.IsIgnored()) { return; } if (__result) { PropInstance propInstance = Singleton <PropManager> .instance.m_props.m_buffer[prop]; Command.SendToAll(new PropCreateCommand { Position = position, PropId = prop, Single = single, Angle = angle, InfoIndex = propInstance.m_infoIndex }); } }
public void CheckPropStillExists() { ushort _propID = propPlacementInfo.propID; PropInstance _propInstance = Singleton <PropManager> .instance.m_props.m_buffer[(int)((UIntPtr)_propID)]; //pre-PropPrecision: //bool _samePosition = _propInstance.Position.EqualOnGameShortGridXZ(propPlacementInfo.position); //post-PropPrecision: //bool _samePosition = _propInstance.Position.NearlyEqualOnGameShortGridXZ(propPlacementInfo.position); bool _samePosition = _propInstance.Position.NearlyEqualOnGameShortGridXZ(propPlacementInfo.meshPosition); bool _sameAngle = true; bool _flagsNotEmpty = _propInstance.m_flags != 0; if (_samePosition == true && _sameAngle == true && _flagsNotEmpty == true) { stillExists = true; } else { stillExists = false; } }
public override void RenderOverlay(RenderManager.CameraInfo cameraInfo) { base.RenderOverlay(cameraInfo); if (!enabled) { return; } if (hoveredId.NetSegment != 0) { NetSegment hoveredSegment = hoveredId.NetSegment.S(); NetTool.RenderOverlay(cameraInfo, ref hoveredSegment, hoverColor, hoverColor); } //else if (hoveredObject.NetNode != 0 && hoveredObject.NetNode < 32768) //{ // NetNode hoveredNode = hoveredObject.NetNode.N(); // RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, hoverColor, hoveredNode.m_position, Mathf.Max(6f, hoveredNode.Info.m_halfWidth * 2f), -1f, 1280f, false, true); //} else if (hoveredId.Building != 0) { Building hoveredBuilding = hoveredId.Building.B(); BuildingTool.RenderOverlay(cameraInfo, ref hoveredBuilding, hoverColor, hoverColor); while (hoveredBuilding.m_subBuilding > 0) { hoveredBuilding = BuildingManager.instance.m_buildings.m_buffer[hoveredBuilding.m_subBuilding]; BuildingTool.RenderOverlay(cameraInfo, ref hoveredBuilding, hoverColor, hoverColor); } } else if (hoveredId.Tree != 0) { TreeInstance hoveredTree = hoveredId.Tree.T(); TreeTool.RenderOverlay(cameraInfo, hoveredTree.Info, hoveredTree.Position, hoveredTree.Info.m_minScale, hoverColor); } else if (hoveredId.Prop != 0) { PropInstance hoveredProp = hoveredId.Prop.P(); PropTool.RenderOverlay(cameraInfo, hoveredProp.Info, hoveredProp.Position, hoveredProp.Info.m_minScale, hoveredProp.Angle, hoverColor); } }
public static void Postfix(TerrainArea heightArea, TerrainArea surfaceArea, TerrainArea zoneArea) { float minX = heightArea.m_min.x; float minZ = heightArea.m_min.z; float maxX = heightArea.m_max.x; float maxZ = heightArea.m_max.z; int minGridX = Mathf.Max((int)(((double)minX - 8.0) / 64.0 + 135.0), 0); int minGridZ = Mathf.Max((int)(((double)minZ - 8.0) / 64.0 + 135.0), 0); int maxGridX = Mathf.Min((int)(((double)maxX + 8.0) / 64.0 + 135.0), 269); int maxGridZ = Mathf.Min((int)(((double)maxZ + 8.0) / 64.0 + 135.0), 269); for (int index1 = minGridZ; index1 <= maxGridZ; ++index1) { for (int index2 = minGridX; index2 <= maxGridX; ++index2) { int gridKey = index1 * 270 + index2; List <PropContainer> list = PropUnlimiterManager.instance.GetPropsInGrid(gridKey); if (list != null) { for (int i = 0; i < list.Count; i++) { PropInstance instance = list[i].propInstance; instance.TerrainUpdated(0, minX, minZ, maxX, maxZ); Vector3 position = instance.Position; position.y = TerrainManager.instance.SampleDetailHeight(position); ushort num = (ushort)Mathf.Clamp(Mathf.RoundToInt(position.y * 64f), 0, (int)ushort.MaxValue); instance.m_posY = num; list[i].propInstance = instance; PropManager.instance.UpdateProp(0); PropManager.instance.UpdatePropRenderer(0, true); } } } } }
internal bool CalculateGroupData(ushort nodeID, int layer, ref int vertexCount, ref int triangleCount, ref int objectCount, ref RenderGroup.VertexArrays vertexArrays) { var result = false; for (int y = 0; y < Data.BoardsContainers.GetLength(1); y++) { for (int z = 0; z < Data.BoardsContainers.GetLength(2); z++) { ref CacheRoadNodeItem item = ref Data.BoardsContainers[nodeID, y, z]; if (item?.m_renderPlate ?? false) { ref BoardInstanceRoadNodeXml targetDescriptor = ref item.m_currentDescriptor; if (targetDescriptor?.Descriptor?.PropName == null) { continue; } WTSDynamicTextRenderingRules.GetColorForRule(nodeID, y, z, targetDescriptor.Descriptor, targetDescriptor, out bool rendered); if (rendered && !(item.m_currentDescriptor.Descriptor?.CachedProp is null)) { result = PropInstance.CalculateGroupData(item.m_currentDescriptor.Descriptor.CachedProp, layer, ref vertexCount, ref triangleCount, ref objectCount, ref vertexArrays); } } }
public static bool Prefix(MoveItTool __instance, ref Instance ___m_hoverInstance, ref int ___m_nextAction) { if (__instance == null) { //Debug.Log("Null instance!"); return(true); } if (Mod.mode != Mod.Mode.Off) { float angle; if (___m_hoverInstance is MoveableBuilding mb) { Building building = Singleton <BuildingManager> .instance.m_buildings.m_buffer[mb.id.Building]; angle = building.m_angle; } else if (___m_hoverInstance is MoveableProp mp) { PropInstance prop = Singleton <PropManager> .instance.m_props.m_buffer[mp.id.Prop]; angle = prop.Angle; } else if (___m_hoverInstance is MoveableSegment ms) { PropInstance segment = Singleton <PropManager> .instance.m_props.m_buffer[ms.id.Prop]; NetSegment[] segmentBuffer = NetManager.instance.m_segments.m_buffer; Vector3 startPos = NetManager.instance.m_nodes.m_buffer[segmentBuffer[ms.id.NetSegment].m_startNode].m_position; Vector3 endPos = NetManager.instance.m_nodes.m_buffer[segmentBuffer[ms.id.NetSegment].m_endNode].m_position; //Debug.Log($"Vector:{endNode.x - startNode.x},{endNode.z - startNode.z} Start:{startNode.x},{startNode.z} End:{endNode.x},{endNode.z}"); angle = (float)Math.Atan2(endPos.z - startPos.z, endPos.x - startPos.x); } else { //Debug.Log($"Wrong hover asset type <{___m_hoverInstance.GetType()}>"); return(Mod.Deactivate()); } // Add action to queue, also enables Undo/Redo AlignRotationAction action; switch (Mod.mode) { case Mod.Mode.All: action = new AlignGroupRotationAction(); break; default: action = new AlignEachRotationAction(); break; } action.newAngle = angle; action.followTerrain = MoveItTool.followTerrain; ActionQueue.instance.Push(action); ___m_nextAction = Mod.TOOL_ACTION_DO; //Debug.Log($"Angle:{angle}, from {___m_hoverInstance}"); return(Mod.Deactivate(false)); } return(true); }
public OverwatchPropWrapper(ushort propInstanceId, PropInstance propInstance) { PropId = propInstanceId; SourcePackageId = ParsePackageId(propInstance.Info); TechnicalName = propInstance.Info.name; }
public void PopulateGroupData( ushort segmentID, uint laneID, NetInfo.Lane laneInfo, bool destroyed, NetNode.Flags startFlags, NetNode.Flags endFlags, float startAngle, float endAngle, bool invert, bool terrainHeight, int layer, ref int vertexIndex, ref int triangleIndex, Vector3 groupPosition, RenderGroup.MeshData data, ref Vector3 min, ref Vector3 max, ref float maxRenderDistance, ref float maxInstanceDistance, ref bool hasProps) { NetLaneProps laneProps = laneInfo.m_laneProps; if (laneProps?.m_props == null) { return; } bool backward = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool reverse = backward != invert; if (backward) //swap { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } int nProps = laneProps.m_props.Length; for (int i = 0; i < nProps; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (!prop.CheckFlags(m_flags, startFlags, endFlags) || m_length < prop.m_minLength) { continue; } int repeatCountTimes2 = 2; if (prop.m_repeatDistance > 1f) { repeatCountTimes2 *= Mathf.Max(1, Mathf.RoundToInt(m_length / prop.m_repeatDistance)); } float halfSegmentOffset = prop.m_segmentOffset * 0.5f; if (m_length != 0f) { halfSegmentOffset = Mathf.Clamp(halfSegmentOffset + prop.m_position.z / m_length, -0.5f, 0.5f); } if (reverse) { halfSegmentOffset = 0f - halfSegmentOffset; } PropInfo finalProp = prop.m_finalProp; if ((object)finalProp != null) { hasProps = true; if (finalProp.m_prefabDataLayer == layer || finalProp.m_effectLayer == layer) { Color color = Color.white; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= repeatCountTimes2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float t = halfSegmentOffset + (float)j / (float)repeatCountTimes2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } if (!variation.m_isDecal && destroyed) { continue; } Vector3 pos = m_bezier.Position(t); Vector3 tan = m_bezier.Tangent(t); if (!(tan != Vector3.zero)) { continue; } if (reverse) { tan = -tan; } tan.y = 0f; if (prop.m_position.x != 0f) { tan = Vector3.Normalize(tan); pos.x += tan.z * prop.m_position.x; pos.z -= tan.x * prop.m_position.x; } float normalAngle = Mathf.Atan2(tan.x, 0f - tan.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float angleDiff = endAngle - startAngle; if (angleDiff > Mathf.PI) { angleDiff -= Mathf.PI * 2f; } if (angleDiff < -Mathf.PI) { angleDiff += Mathf.PI * 2f; } var angle2 = startAngle + angleDiff * t - normalAngle; if (angle2 > Mathf.PI) { angle2 -= Mathf.PI * 2f; } if (angle2 < -Mathf.PI) { angle2 += Mathf.PI * 2f; } normalAngle += angle2 * prop.m_cornerAngle; if (angle2 != 0f && prop.m_position.x != 0f) { float d = Mathf.Tan(angle2); pos.x += tan.x * d * prop.m_position.x; pos.z += tan.z * d * prop.m_position.x; } } if (terrainHeight) { if (variation.m_requireWaterMap) { pos.y = Singleton <TerrainManager> .instance.SampleRawHeightSmoothWithWater(pos, timeLerp : false, 0f); } else { pos.y = Singleton <TerrainManager> .instance.SampleDetailHeight(pos); } } pos.y += prop.m_position.y; InstanceID id = default(InstanceID); id.NetSegment = segmentID; PropInstance.PopulateGroupData(angle: normalAngle + prop.m_angle * (Mathf.PI / 180f), info: variation, layer: layer, id: id, position: pos, scale: scale, color: color, vertexIndex: ref vertexIndex, triangleIndex: ref triangleIndex, groupPosition: groupPosition, data: data, min: ref min, max: ref max, maxRenderDistance: ref maxRenderDistance, maxInstanceDistance: ref maxInstanceDistance); } } } if (destroyed) { continue; } TreeInfo finalTree = prop.m_finalTree; if ((object)finalTree == null) { continue; } hasProps = true; if (finalTree.m_prefabDataLayer != layer) { continue; } Randomizer r2 = new Randomizer((int)laneID + i); for (int k = 1; k <= repeatCountTimes2; k += 2) { if (r2.Int32(100u) >= prop.m_probability) { continue; } float t = halfSegmentOffset + (float)k / (float)repeatCountTimes2; TreeInfo variation2 = finalTree.GetVariation(ref r2); float scale2 = variation2.m_minScale + (float)r2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f; float brightness = variation2.m_minBrightness + (float)r2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f; Vector3 vector3 = m_bezier.Position(t); if (prop.m_position.x != 0f) { Vector3 vector4 = m_bezier.Tangent(t); if (reverse) { vector4 = -vector4; } vector4.y = 0f; vector4 = Vector3.Normalize(vector4); vector3.x += vector4.z * prop.m_position.x; vector3.z -= vector4.x * prop.m_position.x; } if (terrainHeight) { vector3.y = Singleton <TerrainManager> .instance.SampleDetailHeight(vector3); } vector3.y += prop.m_position.y; TreeInstance.PopulateGroupData(variation2, vector3, scale2, brightness, RenderManager.DefaultColorLocation, ref vertexIndex, ref triangleIndex, groupPosition, data, ref min, ref max, ref maxRenderDistance, ref maxInstanceDistance); } } }
private bool TryGetProp(ushort propInstanceId, out PropInstance propInstance) { bool result = false; propInstance = default(PropInstance); var tryProp = Singleton<PropManager>.instance.m_props.m_buffer[(int)propInstanceId]; if (tryProp.Info != null && ((PropInstance.Flags)tryProp.m_flags & PropInstance.Flags.Created) != PropInstance.Flags.None) { propInstance = tryProp; result = true; } return result; }
public static bool RenderDestroyedInstancePrefix(NetLane __instance, RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo netInfo, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; if (laneProps != null && laneProps.m_props != null) { bool flag = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool flag2 = flag != invert; if (flag) { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } int num = laneProps.m_props.Length; for (int i = 0; i < num; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (__instance.m_length < prop.m_minLength) { continue; } int num2 = 2; if (prop.m_repeatDistance > 1f) { num2 *= Mathf.Max(1, Mathf.RoundToInt(__instance.m_length / prop.m_repeatDistance)); } int num3 = propIndex; if (propIndex != -1) { propIndex = num3 + (num2 + 1 >> 1); } if (!prop.CheckFlags((NetLane.Flags)__instance.m_flags, startFlags, endFlags)) { continue; } float num4 = prop.m_segmentOffset * 0.5f; if (__instance.m_length != 0f) { num4 = Mathf.Clamp(num4 + prop.m_position.z / __instance.m_length, -0.5f, 0.5f); } if (flag2) { num4 = 0f - num4; } PropInfo finalProp = prop.m_finalProp; if (!(finalProp != null) || (layerMask & (1 << finalProp.m_prefabDataLayer)) == 0) { continue; } Color color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= num2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float num5 = num4 + (float)j / (float)num2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } if (!variation.m_isDecal && !variation.m_surviveCollapse) { continue; } Vector3 vector = __instance.m_bezier.Position(num5); if (propIndex != -1) { vector.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } vector.y += prop.m_position.y; if (!cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance)) { continue; } Vector3 vector2 = __instance.m_bezier.Tangent(num5); if (!(vector2 != Vector3.zero)) { continue; } if (flag2) { vector2 = -vector2; } vector2.y = 0f; if (prop.m_position.x != 0f) { vector2 = Vector3.Normalize(vector2); vector.x += vector2.z * prop.m_position.x; vector.z -= vector2.x * prop.m_position.x; } float num6 = Mathf.Atan2(vector2.x, 0f - vector2.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float num7 = endAngle - startAngle; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } float num8 = startAngle + num7 * num5; num7 = num8 - num6; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } num6 += num7 * prop.m_cornerAngle; if (num7 != 0f && prop.m_position.x != 0f) { float num9 = Mathf.Tan(num7); vector.x += vector2.x * num9 * prop.m_position.x; vector.z += vector2.z * num9 * prop.m_position.x; } } Vector4 objectIndex3 = (!(num5 > 0.5f)) ? objectIndex1 : objectIndex2; num6 += prop.m_angle * ((float)Math.PI / 180f); InstanceID id = default(InstanceID); id.NetSegment = segmentID; #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true); #endif } } } if ((laneInfo.m_laneType & (NetInfo.LaneType.Vehicle | NetInfo.LaneType.Parking | NetInfo.LaneType.CargoVehicle | NetInfo.LaneType.TransportVehicle)) == 0 && ((laneInfo.m_laneType & NetInfo.LaneType.Pedestrian) == 0 || netInfo.m_vehicleTypes != 0)) { return(false); } bool flag3 = (laneInfo.m_vehicleType & ~VehicleInfo.VehicleType.Bicycle) == 0 || laneInfo.m_verticalOffset >= 0.5f; Randomizer r2 = new Randomizer(laneID); int num10 = Mathf.RoundToInt(__instance.m_length * 0.07f); for (int k = 0; k < num10; k++) { PropInfo randomPropInfo = Singleton <PropManager> .instance.GetRandomPropInfo(ref r2, ItemClass.Service.Road); randomPropInfo = randomPropInfo.GetVariation(ref r2); float num11 = randomPropInfo.m_minScale + (float)r2.Int32(10000u) * (randomPropInfo.m_maxScale - randomPropInfo.m_minScale) * 0.0001f; Color color2 = randomPropInfo.GetColor(ref r2); float num12 = (float)r2.Int32(1000u) * 0.001f; float angle = (float)r2.Int32(1000u) * 0.006283186f; if (!randomPropInfo.m_isDecal) { if (flag3) { continue; } if (netInfo.m_netAI.IsOverground()) { float num13 = netInfo.m_halfWidth - Mathf.Abs(laneInfo.m_position); float num14 = Mathf.Max(randomPropInfo.m_generatedInfo.m_size.x, randomPropInfo.m_generatedInfo.m_size.z) * num11 * 0.5f - 0.5f; if (num13 < num14) { continue; } } } Vector3 position = __instance.m_bezier.Position(num12); Vector4 objectIndex4 = (!(num12 > 0.5f)) ? objectIndex1 : objectIndex2; InstanceID id2 = default(InstanceID); id2.NetSegment = segmentID; if (!randomPropInfo.m_requireHeightMap) { #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, randomPropInfo, id2, position, num11, angle, color2, objectIndex4, active: true)); #else PropInstance.RenderInstance(cameraInfo, randomPropInfo, id2, position, num11, angle, color2, objectIndex4, active: true); #endif } } return(false); }
public static bool RenderInstancePrefix(NetLane __instance, RenderManager.CameraInfo cameraInfo, ushort segmentID, uint laneID, NetInfo.Lane laneInfo, NetNode.Flags startFlags, NetNode.Flags endFlags, Color startColor, Color endColor, float startAngle, float endAngle, bool invert, int layerMask, Vector4 objectIndex1, Vector4 objectIndex2, ref RenderManager.Instance data, ref int propIndex) { NetLaneProps laneProps = laneInfo.m_laneProps; if (!(laneProps != null) || laneProps.m_props == null) { return(false); } bool flag = (laneInfo.m_finalDirection & NetInfo.Direction.Both) == NetInfo.Direction.Backward || (laneInfo.m_finalDirection & NetInfo.Direction.AvoidBoth) == NetInfo.Direction.AvoidForward; bool flag2 = flag != invert; if (flag) { NetNode.Flags flags = startFlags; startFlags = endFlags; endFlags = flags; } Texture _HeightMap = null; Vector4 _HeightMapping = Vector4.zero; Vector4 _SurfaceMapping = Vector4.zero; Texture _HeightMap2 = null; Vector4 _HeightMapping2 = Vector4.zero; Vector4 _SurfaceMapping2 = Vector4.zero; int num = laneProps.m_props.Length; for (int i = 0; i < num; i++) { NetLaneProps.Prop prop = laneProps.m_props[i]; if (__instance.m_length < prop.m_minLength) { continue; } int num2 = 2; if (prop.m_repeatDistance > 1f) { num2 *= Mathf.Max(1, Mathf.RoundToInt(__instance.m_length / prop.m_repeatDistance)); } int num3 = propIndex; if (propIndex != -1) { propIndex = num3 + (num2 + 1 >> 1); } if (!prop.CheckFlags((NetLane.Flags)__instance.m_flags, startFlags, endFlags)) { continue; } float num4 = prop.m_segmentOffset * 0.5f; if (__instance.m_length != 0f) { num4 = Mathf.Clamp(num4 + prop.m_position.z / __instance.m_length, -0.5f, 0.5f); } if (flag2) { num4 = 0f - num4; } PropInfo finalProp = prop.m_finalProp; if (finalProp != null && (layerMask & (1 << finalProp.m_prefabDataLayer)) != 0) { Color color = (prop.m_colorMode != NetLaneProps.ColorMode.EndState) ? startColor : endColor; Randomizer r = new Randomizer((int)laneID + i); for (int j = 1; j <= num2; j += 2) { if (r.Int32(100u) >= prop.m_probability) { continue; } float num5 = num4 + (float)j / (float)num2; PropInfo variation = finalProp.GetVariation(ref r); float scale = variation.m_minScale + (float)r.Int32(10000u) * (variation.m_maxScale - variation.m_minScale) * 0.0001f; if (prop.m_colorMode == NetLaneProps.ColorMode.Default) { color = variation.GetColor(ref r); } Vector3 vector = __instance.m_bezier.Position(num5); if (propIndex != -1) { vector.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } vector.y += prop.m_position.y; if (!cameraInfo.CheckRenderDistance(vector, variation.m_maxRenderDistance)) { continue; } Vector3 vector2 = __instance.m_bezier.Tangent(num5); if (!(vector2 != Vector3.zero)) { continue; } if (flag2) { vector2 = -vector2; } vector2.y = 0f; if (prop.m_position.x != 0f) { vector2 = Vector3.Normalize(vector2); vector.x += vector2.z * prop.m_position.x; vector.z -= vector2.x * prop.m_position.x; } float num6 = Mathf.Atan2(vector2.x, 0f - vector2.z); if (prop.m_cornerAngle != 0f || prop.m_position.x != 0f) { float num7 = endAngle - startAngle; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } float num8 = startAngle + num7 * num5; num7 = num8 - num6; if (num7 > (float)Math.PI) { num7 -= (float)Math.PI * 2f; } if (num7 < -(float)Math.PI) { num7 += (float)Math.PI * 2f; } num6 += num7 * prop.m_cornerAngle; if (num7 != 0f && prop.m_position.x != 0f) { float num9 = Mathf.Tan(num7); vector.x += vector2.x * num9 * prop.m_position.x; vector.z += vector2.z * num9 * prop.m_position.x; } } Vector4 objectIndex3 = (!(num5 > 0.5f)) ? objectIndex1 : objectIndex2; num6 += prop.m_angle * ((float)Math.PI / 180f); InstanceID id = default(InstanceID); id.NetSegment = segmentID; if (variation.m_requireWaterMap) { if (_HeightMap == null) { Singleton <TerrainManager> .instance.GetHeightMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap, out _HeightMapping, out _SurfaceMapping); } if (_HeightMap2 == null) { Singleton <TerrainManager> .instance.GetWaterMapping(Singleton <NetManager> .instance.m_segments.m_buffer[segmentID].m_middlePosition, out _HeightMap2, out _HeightMapping2, out _SurfaceMapping2); } #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true, _HeightMap, _HeightMapping, _SurfaceMapping, _HeightMap2, _HeightMapping2, _SurfaceMapping2); #endif } else if (!variation.m_requireHeightMap) { #if UseTask Patcher.Dispatcher.Add(() => PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true)); #else PropInstance.RenderInstance(cameraInfo, variation, id, vector, scale, num6, color, objectIndex3, active: true); #endif } } } TreeInfo finalTree = prop.m_finalTree; if (!(finalTree != null) || (layerMask & (1 << finalTree.m_prefabDataLayer)) == 0) { continue; } Randomizer r2 = new Randomizer((int)laneID + i); for (int k = 1; k <= num2; k += 2) { if (r2.Int32(100u) >= prop.m_probability) { continue; } float t = num4 + (float)k / (float)num2; TreeInfo variation2 = finalTree.GetVariation(ref r2); float scale2 = variation2.m_minScale + (float)r2.Int32(10000u) * (variation2.m_maxScale - variation2.m_minScale) * 0.0001f; float brightness = variation2.m_minBrightness + (float)r2.Int32(10000u) * (variation2.m_maxBrightness - variation2.m_minBrightness) * 0.0001f; Vector3 position = __instance.m_bezier.Position(t); if (propIndex != -1) { position.y = (float)(int)data.m_extraData.GetUShort(num3++) * 0.015625f; } position.y += prop.m_position.y; if (prop.m_position.x != 0f) { Vector3 vector3 = __instance.m_bezier.Tangent(t); if (flag2) { vector3 = -vector3; } vector3.y = 0f; vector3 = Vector3.Normalize(vector3); position.x += vector3.z * prop.m_position.x; position.z -= vector3.x * prop.m_position.x; } #if UseTask Patcher.Dispatcher.Add(() => TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation)); #else TreeInstance.RenderInstance(cameraInfo, variation2, position, scale2, brightness, RenderManager.DefaultColorLocation); #endif } } return(false); }