private void setSOVisible(SOTreeNode soNode, bool visible)
        {
            SuperObject soStruct = GetStructure <SuperObject>(processHandle, soNode.superObjectAddress);

            soStruct.renderBits = SuperObject.setVisibleBit(soStruct.renderBits, visible);
            WriteStructure(processHandle, soNode.superObjectAddress, soStruct);
        }
        private void removeFromHierarchy(SOTreeNode so)
        {
            so.name = "REMOVED FROM HIERARCHY " + so.name;
            SuperObject prevBrother = GetStructure <SuperObject>(processHandle, so.superObject.prevBrother);

            prevBrother.nextBrother = so.superObject.nextBrother;

            WriteStructure(processHandle, so.superObject.prevBrother, prevBrother);
        }
        private void retrieveHierarchy(object sender, RoutedEventArgs e)
        {
            expandDong.Clear();
            var items = treeView.Items;

            foreach (TreeViewItem oldItem in items)
            {
                checkExpandedDongs(oldItem);
            }

            items.Clear();

            Process process;

            if (Process.GetProcessesByName("Rayman2").Length > 0)
            {
                process       = Process.GetProcessesByName("Rayman2")[0];
                processHandle = MemoryRead.OpenProcess(MemoryRead.PROCESS_WM_READ | MemoryRead.PROCESS_VM_WRITE | MemoryRead.PROCESS_VM_OPERATION, false, process.Id).ToInt32();

                int dynamicWorldAddress = ReadIntFromMemory(processHandle, 0x500FD0);
                int staticWorldAddress  = ReadIntFromMemory(processHandle, 0x500FC0);

                int mainCharacterObjectAddress = ReadIntFromMemory(processHandle, 0x4FF764);

                SuperObject dynamicWorld = GetStructure <SuperObject>(processHandle, dynamicWorldAddress);
                SuperObject staticWorld  = GetStructure <SuperObject>(processHandle, staticWorldAddress);

                SOTreeNode dynamicTreeRoot = new SOTreeNode();
                dynamicTreeRoot.name        = "Dynamic World Root";
                dynamicTreeRoot.superObject = dynamicWorld;
                retrieveHierarchyRecursive(dynamicTreeRoot, mainCharacterObjectAddress, 0);

                int mainSectorAddress         = ReadIntFromMemory(processHandle, 0x500FB0);
                int previousMainSectorAddress = ReadIntFromMemory(processHandle, 0x500FC8);

                SOTreeNode staticTreeRoot = new SOTreeNode();
                staticTreeRoot.name        = "Static World Root";
                staticTreeRoot.superObject = staticWorld;
                retrieveHierarchyRecursive(staticTreeRoot, mainSectorAddress, previousMainSectorAddress);

                TreeViewItem dynamicTreeViewItemRoot = new TreeViewItem()
                {
                    Header = "Dynamic World"
                };
                dynamicTreeViewItemRoot.ExpandSubtree();

                TreeViewItem staticTreeViewItemRoot = new TreeViewItem()
                {
                    Header = "Static World"
                };
                staticTreeViewItemRoot.ExpandSubtree();

                b = 0;
                fillTree(dynamicTreeRoot, dynamicTreeViewItemRoot);
                fillTree(staticTreeRoot, staticTreeViewItemRoot);

                items.Add(dynamicTreeViewItemRoot);
                items.Add(staticTreeViewItemRoot);

                Console.WriteLine(process);
            }
            else
            {
                Console.WriteLine("Rayman2.exe not found");
            }
        }
        private void retrieveHierarchyRecursive(SOTreeNode parent, int mainCharacterAddress, int previousMainSectorAddress)
        {
            int nextBrother = parent.superObject.firstChild; // First brother is the child of the parent object

            if (nextBrother == 0)
            {
                return;
            }
            do
            {
                SuperObject so = GetStructure <SuperObject>(processHandle, nextBrother);

                bool isMainChar       = (mainCharacterAddress == nextBrother) ? true : false;
                bool isPreviousSector = (previousMainSectorAddress == nextBrother) ? true : false;

                string          name           = "SO Type " + so.type + " address 0x" + nextBrother.ToString("X");
                SuperObjectInfo soInfo         = GetStructure <SuperObjectInfo>(processHandle, so.info);
                int             someInfoStruct = soInfo.standardGameStruct;
                int             string1address = someInfoStruct + 0x50;
                int             string2address = someInfoStruct + 0x84;
                int             string3address = someInfoStruct + 0xAC;
                string          string1        = ReadString(processHandle, string1address, 32);
                string          string2        = ReadString(processHandle, string2address, 32);
                string          string3        = ReadString(processHandle, string3address, 32);

                bool visible = SuperObject.getVisibleBit(so.renderBits);
                if (!visible)
                {
                    name = "(INVIS) " + name;
                }

                if (so.type == 2)
                {
                    name += "(" + string1 + ", " + string2 + ", " + string3 + ")";
                }

                if (isMainChar)
                {
                    if (so.type == 2)
                    {
                        name = "(M) " + name;
                    }
                    else
                    {
                        name = "(ACTIVE) " + name;
                    }
                }

                if (isPreviousSector)
                {
                    name = "(PREV ACTIVE) " + name;
                }

                var childNode = new SOTreeNode()
                {
                    name               = name,
                    superObject        = so,
                    superObjectAddress = nextBrother,
                    isMainCharacter    = isMainChar
                };

                retrieveHierarchyRecursive(childNode, mainCharacterAddress, previousMainSectorAddress);
                parent.subitems.Add(childNode);
                nextBrother = so.nextBrother;
            } while (nextBrother != 0);
        }