private void LinkSection(ILNode node, BlockSection section)
        {
            bool useProxy1   = _random.NextBool();
            var  nextSibling = GetNextSiblingIgnoreNop(node);
            var  proxy       = useProxy1 ? section.Proxy1 : section.Proxy2;

            if (object.ReferenceEquals(nextSibling, proxy.Node))
            {
                proxy = useProxy1 ? section.Proxy2 : section.Proxy1;
            }

            // ldc.i4.X / ldslfd X
            int value = _random.Next(proxy.MinValue, proxy.MaxValue);

            if (_doNotUseFieldNumber)
            {
                node = node.AddNext(Instruction.GetLdc(value));
            }
            else
            {
                node = node.AddNext(OpCodes.Ldsfld, GetIntFieldRef(value));
            }

            // br [proxy]
            var targetLabel = new ILLabel();

            proxy.Node.AddPrevious(targetLabel);
            node = node.AddNext(OpCodes.Br, targetLabel);
        }
示例#2
0
    public Wheel SetPiece(BlockSection section, int index = 0)
    {
        GameObject prefab;
        prefab = section == BlockSection.Mid ? WheelBlock.Mid[index] : WheelBlock.End[index];

        //Debug.Log(section.ToString() + " " + prefab.GetComponent<Wheel>().Section);

        Vector3 offset = Vector3.zero;
        if (section == BlockSection.Right)
            offset.x++;
        else if (section == BlockSection.Mid)
            offset.x --;

        GameObject go = GameObject.Instantiate(prefab, transform.position + offset, Quaternion.identity) as GameObject;

        if (section == BlockSection.Right)
        {
            Vector3 localScale = go.transform.localScale;
            localScale.x *= -1;
            go.transform.localScale = localScale;
        }

        Wheel wheel = go.GetComponent<Wheel>();
        wheel.Section = section;
        wheel.Parent = Parent;
        go.transform.parent = transform.parent;

        DestroyImmediate(gameObject);

        return wheel;
    }
        private Block CreateBlock(BlockLoadState blockState, int nextInstructionCount, ref int totalBranchCount)
        {
            // Calculate branch count for block
            int branchCount            = 0;
            int zeroStackSizeNodeCount = blockState.ZeroStackSizeNodes.Count;

            do
            {
                branchCount++;
                zeroStackSizeNodeCount--;
                totalBranchCount--;
                blockState.InstructionCount /= 2;
            }while (totalBranchCount > 0 && zeroStackSizeNodeCount > 0 && blockState.InstructionCount > nextInstructionCount);

            var block = new Block();

            block.Node = blockState.Node;

            // Sections
            int sectionCount = branchCount + 1;
            var sections     = new BlockSection[sectionCount];

            // Create
            for (int i = 0; i < sectionCount; i++)
            {
                sections[i] = new BlockSection();
            }

            // Init
            var firstSection = sections[0];

            firstSection.ProxyNode = blockState.Node.FirstChild.AddPrevious(OpCodes.Nop);
            firstSection.CodeNode  = firstSection.ProxyNode.AddNext(OpCodes.Nop);

            var lastSection = sections[sectionCount - 1];

            lastSection.LastNode = blockState.Node.LastChild.AddNext(OpCodes.Nop);

            int sectionOffsetSize = blockState.ZeroStackSizeNodes.Count / sectionCount;

            for (int i = 0; i < branchCount; i++)
            {
                var section1 = sections[i];
                var section2 = sections[i + 1];

                int branchIndex       = (sectionOffsetSize * (i + 1));
                var branchInstruction = blockState.ZeroStackSizeNodes[branchIndex];

                section1.Next      = section2;
                section1.LastNode  = branchInstruction.AddPrevious(OpCodes.Nop);
                section2.ProxyNode = section1.LastNode.AddNext(OpCodes.Nop);
                section2.CodeNode  = section2.ProxyNode.AddNext(OpCodes.Nop);
            }

            block.Sections     = sections;
            block.FirstSection = sections[0];

            return(block);
        }
        private void ShuffleSections(Block block, int[] map)
        {
            var sections = block.Sections;
            int count    = sections.Length;

            var newSections = new BlockSection[count];

            for (int i = 0; i < count; i++)
            {
                newSections[map[i]] = sections[i];
            }

            block.Sections = newSections;
        }