Exemple #1
0
        public NodeData InsertNode(NetTool.ControlPoint controlPoint, NodeTypeT nodeType = NodeTypeT.Crossing)
        {
            if (ToolBase.ToolErrors.None != NetUtil.InsertNode(controlPoint, out ushort nodeID))
            {
                return(null);
            }
            HelpersExtensions.Assert(nodeID != 0, "nodeID");

            foreach (var segmentID in NetUtil.IterateNodeSegments(nodeID))
            {
                var segEnd = new SegmentEndData(segmentID, nodeID);
                SegmentEndManager.Instance.SetAt(segmentID: segmentID, nodeID: nodeID, value: segEnd);
            }

            var  info      = controlPoint.m_segment.ToSegment().Info;
            int  nPedLanes = info.CountPedestrianLanes();
            bool isRoad    = info.m_netAI is RoadBaseAI;

            if (nodeType == NodeTypeT.Crossing && (nPedLanes < 2 || !isRoad))
            {
                buffer[nodeID] = new NodeData(nodeID);
            }
            else
            {
                buffer[nodeID] = new NodeData(nodeID, nodeType);
            }

            return(buffer[nodeID]);
        }
        private NetInfo GetFinalNetInfo()
        {
            int e1 = StartNode.elevation;
            int e2 = EndNode.elevation;

            HelpersExtensions.Assert(!(e1 == 0 && e2 < 0), "Underground road is oppostie way arround");
            int nElevated = 0;

            if (e1 != 0)
            {
                nElevated++;
            }
            if (e2 != 0)
            {
                nElevated++;
            }

            switch (nElevated)
            {
            case 0: return(ControlCenter.Info);

            case 1: return(ControlCenter.Info1);

            case 2: return(ControlCenter.Info2);

            default: throw new Exception("Unreachable code");
            }
        }
        }     // end method

        public static CodeInstruction BuildSegnentLDLocFromPrevSTLoc(List <CodeInstruction> codes, int index, int counter = 1)
        {
            HelpersExtensions.Assert(mGetSegment != null, "mGetSegment!=null");
            index = SearchInstruction(codes, new CodeInstruction(OpCodes.Call, mGetSegment), index, counter: counter, dir: -1);

            var code = codes[index + 1];

            HelpersExtensions.Assert(IsStLoc(code), $"IsStLoc(code) | code={code}");

            return(BuildLdLocFromStLoc(code));
        }
Exemple #4
0
        /// <summary>
        /// reteurns a copy of the texture with the differenc that: mipmap=false, linear=false, readable=true;
        /// </summary>
        public static Texture2D GetReadableCopy(this Texture2D tex, bool linear = false)
        {
            HelpersExtensions.Assert(tex != null, "tex!=null");
            HelpersExtensions.Assert(tex is Texture2D, $"tex is Texture2D");
            Texture2D ret = tex.MakeReadable(linear);

            ret.name       = tex.name;
            ret.anisoLevel = tex.anisoLevel;
            ret.filterMode = tex.filterMode;
            return(ret);
        }
Exemple #5
0
 static MethodBase TargetMethod() {
     var ret = Target;
     HelpersExtensions.Assert(ret != null, "did not manage to find original function to patch");
     Log("aquired method " + ret);
     return ret;
 }
        public static void PatchCheckFlags(List <CodeInstruction> codes, int occurance, MethodInfo method)
        {
            HelpersExtensions.Assert(mDrawMesh != null, "mDrawMesh!=null failed");
            HelpersExtensions.Assert(fNodeMaterial != null, "fNodeMaterial!=null failed");
            HelpersExtensions.Assert(fNodeMesh != null, "fNodeMesh!=null failed");
            HelpersExtensions.Assert(mCalculateMaterial != null, "mCalculateMaterial!=null failed");
            HelpersExtensions.Assert(mCalculateMesh != null, "mCalculateMesh!=null failed");
            HelpersExtensions.Assert(mCheckRenderDistance != null, "mCheckRenderDistance!=null failed");
            HelpersExtensions.Assert(mShouldContinueMedian != null, "mShouldContinueMedian!=null failed");

            int index = 0;

            // returns the position of First DrawMesh after index.
            index = SearchInstruction(codes, new CodeInstruction(OpCodes.Call, mDrawMesh), index, counter: occurance);
            HelpersExtensions.Assert(index != 0, "index!=0");


            // find ldfld node.m_nodeMaterial
            index = SearchInstruction(codes, new CodeInstruction(OpCodes.Ldfld, fNodeMaterial), index, dir: -1);
            int insertIndex3 = index + 1;

            // fine node.m_NodeMesh

            /*  IL_07ac: ldloc.s      node_V_16
             *  IL_07ae: ldfld        class [UnityEngine]UnityEngine.Mesh NetInfo/Node::m_nodeMesh
             */
            index = SearchInstruction(codes, new CodeInstruction(OpCodes.Ldfld, fNodeMesh), index, dir: -1);
            int insertIndex2 = index + 1;

            // find: if (cameraInfo.CheckRenderDistance(data.m_position, node.m_lodRenderDistance))

            /* IL_0627: callvirt instance bool RenderManager CameraInfo::CheckRenderDistance(Vector3, float32)
             * IL_062c brfalse      IL_07e2 */
            index = SearchInstruction(codes, new CodeInstruction(OpCodes.Callvirt, mCheckRenderDistance), index, dir: -1);
            int insertIndex1 = index + 1;                                                               // at this point boloean is in stack

            CodeInstruction LDArg_NodeID    = GetLDArg(method, "nodeID");                               // push nodeID into stack
            CodeInstruction LDLoc_segmentID = BuildSegnentLDLocFromPrevSTLoc(codes, index, counter: 1); // push segmentID into stack

            {                                                                                           // Insert material = CalculateMaterial(material, nodeID, segmentID)
                var newInstructions = new[] {
                    LDArg_NodeID,
                    LDLoc_segmentID,
                    new CodeInstruction(OpCodes.Call, mCalculateMaterial), // call Material CalculateMaterial(material, nodeID, segmentID).
                };
                InsertInstructions(codes, newInstructions, insertIndex3);
            }

            { // Insert material = CalculateMesh(mesh, nodeID, segmentID)
                var newInstructions = new[] {
                    LDArg_NodeID,
                    LDLoc_segmentID,
                    new CodeInstruction(OpCodes.Call, mCalculateMesh), // call Mesh CalculateMesh(mesh, nodeID, segmentID).
                };
                InsertInstructions(codes, newInstructions, insertIndex2);
            }

            { // Insert ShouldHideCrossing(nodeID, segmentID)
                var newInstructions = new[] {
                    LDArg_NodeID,
                    LDLoc_segmentID,
                    new CodeInstruction(OpCodes.Call, mShouldContinueMedian), // call Material mShouldHideCrossing(nodeID, segmentID).
                    new CodeInstruction(OpCodes.Or)
                };

                InsertInstructions(codes, newInstructions, insertIndex1);
            } // end block
        }     // end method