예제 #1
0
 public string Mine()
 {
     byte[] s = null;
     do
     {
         s = ComputeObjectHash().ToByteArray(StringEncoding.Base85Check);
     } while (NodeHash.ToByteArray().CompareDiff());
     return(s.ToBase58Check());
 }
예제 #2
0
        public bool Equals(DestinyTalentNode input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     NodeIndex == input.NodeIndex ||
                     (NodeIndex.Equals(input.NodeIndex))
                     ) &&
                 (
                     NodeHash == input.NodeHash ||
                     (NodeHash.Equals(input.NodeHash))
                 ) &&
                 (
                     State == input.State ||
                     (State != null && State.Equals(input.State))
                 ) &&
                 (
                     IsActivated == input.IsActivated ||
                     (IsActivated != null && IsActivated.Equals(input.IsActivated))
                 ) &&
                 (
                     StepIndex == input.StepIndex ||
                     (StepIndex.Equals(input.StepIndex))
                 ) &&
                 (
                     MaterialsToUpgrade == input.MaterialsToUpgrade ||
                     (MaterialsToUpgrade != null && MaterialsToUpgrade.SequenceEqual(input.MaterialsToUpgrade))
                 ) &&
                 (
                     ActivationGridLevel == input.ActivationGridLevel ||
                     (ActivationGridLevel.Equals(input.ActivationGridLevel))
                 ) &&
                 (
                     ProgressPercent == input.ProgressPercent ||
                     (ProgressPercent.Equals(input.ProgressPercent))
                 ) &&
                 (
                     Hidden == input.Hidden ||
                     (Hidden != null && Hidden.Equals(input.Hidden))
                 ) &&
                 (
                     NodeStatsBlock == input.NodeStatsBlock ||
                     (NodeStatsBlock != null && NodeStatsBlock.Equals(input.NodeStatsBlock))
                 ));
        }
예제 #3
0
 public bool Verify()
 {
     if (NodeHash != ComputeObjectHash())
     {
         return(false);
     }
     if (NodeHash.ToByteArray().CompareDiff())
     {
         return(false);
     }
     if (!Tx.ISSigntureVerified())
     {
         return(false);
     }
     return(true);
 }
예제 #4
0
파일: SARC.cs 프로젝트: TROguz/BotWUnpacker
        public static string[] CalculateHashAndSort(string[] files) //Calculate Hash and Sort
        {
            NodeHash[] hashesUnsorted = new NodeHash[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                hashesUnsorted[i] = new NodeHash(CalcHash(files[i]), i, files[i]); //Store and calculate unsorted hashes
            }
            uint lastHash;

            bool[]     hashSortedFlag = new bool[hashesUnsorted.Length];
            NodeHash[] hashes         = new NodeHash[hashesUnsorted.Length];
            int        dhi            = 0;

            for (int i = 0; i < hashes.Length; i++) //sort nodes by hash calculation
            {
                lastHash = uint.MaxValue;
                for (int j = 0; j < hashesUnsorted.Length; j++)
                {
                    if (hashSortedFlag[j])
                    {
                        continue;
                    }
                    if (hashesUnsorted[j].hash < lastHash)
                    {
                        dhi      = j;
                        lastHash = hashesUnsorted[j].hash;
                    }
                }
                hashSortedFlag[dhi] = true;
                hashes[i]           = hashesUnsorted[dhi];
            }
            for (int i = 0; i < files.Length; i++)
            {
                files[i] = hashes[i].fileName;
            }
            return(files);
        }
예제 #5
0
파일: SARC.cs 프로젝트: TROguz/BotWUnpacker
        public static bool Build(string inDir, string outFile, uint dataFixedOffset) //BUILD ----------------------------------------------------------------------
        {
            try
            {
                //Setup
                string[]   inDirFiles = System.IO.Directory.GetFiles(inDir == "" ? System.Environment.CurrentDirectory : inDir, "*.*", System.IO.SearchOption.AllDirectories);
                NodeInfo[] nodeInfo   = new NodeInfo[inDirFiles.Length];

                //Node storage logic
                uint totalNamesLength = 0;
                uint numFiles         = (uint)inDirFiles.Length;
                for (int i = 0; i < numFiles; i++) //collect node information
                {
                    string realname = inDirFiles[i];
                    string fileName = inDirFiles[i].Replace(inDir + System.IO.Path.DirectorySeparatorChar.ToString(), "");
                    fileName = fileName.Replace("\\", "/"); //HURP DERP NINTENDUR (This fixes the hash calculation!)
                    uint namesize = (uint)fileName.Length;
                    namesize         += (4 - (namesize % 4));
                    totalNamesLength += namesize;
                    nodeInfo[i]       = new NodeInfo(fileName, realname, namesize);
                }
                uint namePaddingToAdd = 0;
                if (totalNamesLength % 0x10 != 0)
                {
                    namePaddingToAdd  = 0x10 % (totalNamesLength % 0x10); //padding to add for
                    totalNamesLength += namePaddingToAdd;
                }

                //Node hash calculation and sorting logic
                NodeHash[] hashesUnsorted = new NodeHash[numFiles];
                for (int i = 0; i < numFiles; i++)
                {
                    hashesUnsorted[i] = new NodeHash(CalcHash(nodeInfo[i].filename), i, ""); //Store and calculate unsorted hashes
                }
                uint       lastHash;
                bool[]     hashSortedFlag = new bool[hashesUnsorted.Length];
                NodeHash[] hashes         = new NodeHash[hashesUnsorted.Length];
                int        dhi            = 0;
                for (int i = 0; i < hashes.Length; i++) //sort nodes by hash calculation
                {
                    lastHash = uint.MaxValue;
                    for (int j = 0; j < hashesUnsorted.Length; j++)
                    {
                        if (hashSortedFlag[j])
                        {
                            continue;
                        }
                        if (hashesUnsorted[j].hash < lastHash)
                        {
                            dhi      = j;
                            lastHash = hashesUnsorted[j].hash;
                        }
                    }
                    hashSortedFlag[dhi] = true;
                    hashes[i]           = hashesUnsorted[dhi];
                }

                //Node data build and position logic
                NodeData[] nodeData     = new NodeData[numFiles];
                uint       nodePosition = 0;
                for (int i = 0; i < numFiles; i++)
                {
                    nodeData[hashes[i].index].startPos = nodePosition; //start position after padding
                    nodeData[hashes[i].index].data     = System.IO.File.ReadAllBytes(nodeInfo[hashes[i].index].realname);
                    nodePosition += (uint)nodeData[hashes[i].index].data.Length;
                    nodeData[hashes[i].index].endPos = nodePosition; //end position before padding
                    if (i != numFiles - 1)                           //As long as it's not the last node, add padding data
                    {
                        if ((nodeData[hashes[i].index].data.Length % 4) != 0)
                        {
                            nodeData[hashes[i].index].padding = 4 - (uint)(nodeData[hashes[i].index].data.Length % 4);
                        }
                    }
                    nodePosition += nodeData[hashes[i].index].padding;
                }


                uint fileSize = 0;
                fileSize += 0x20;                    //SARC + SFAT reserve
                fileSize += 0x10 * (uint)numFiles;   //nodeInfo reserve
                fileSize += 0x08;                    //SFNT reserve
                fileSize += totalNamesLength;        //names of files
                uint nodeDataStart = fileSize;       //node data table offset
                if (dataFixedOffset > nodeDataStart) //if fixed data offset is larger than generated start...
                {
                    namePaddingToAdd += (dataFixedOffset - nodeDataStart);
                    fileSize         += (dataFixedOffset - nodeDataStart);
                    nodeDataStart     = dataFixedOffset;
                }
                for (int i = 0; i < numFiles; i++)
                {
                    fileSize += (uint)(nodeData[hashes[i].index].data.Length);
                    fileSize += nodeData[hashes[i].index].padding;
                }

                //Write logic
                System.IO.StreamWriter stream = new System.IO.StreamWriter(outFile);
                //SARC ---
                stream.BaseStream.Write(new byte[] { 83, 65, 82, 67, 0x00, 0x14, 0xFE, 0xFF }, 0, 8);              //Write Fixed SARC Big Endian header
                stream.BaseStream.Write(Breaku32(fileSize), 0, 4);                                                 //Write 0x08 split bytes of file size
                stream.BaseStream.Write(Breaku32(nodeDataStart), 0, 4);                                            //Write 0x0C split bytes of data table start offset
                //SFAT ---
                stream.BaseStream.Write(new byte[] { 0x01, 0x00, 0x00, 0x00, 83, 70, 65, 84, 0x00, 0x0C }, 0, 10); //Write Fixed SFAT header
                stream.BaseStream.Write(Breaku16((ushort)numFiles), 0, 2);                                         //Write 0x1A split bytes of number of nodes/files
                stream.BaseStream.Write(Breaku32(0x65), 0, 4);                                                     //Write Fixed Hash Multiplier
                uint strpos = 0;
                //Node ---
                for (int i = 0; i < numFiles; i++)
                {
                    stream.BaseStream.Write(Breaku32(hashes[i].hash), 0, 4);                     //Node Hash
                    stream.BaseStream.WriteByte(0x01);                                           //Node Fixed Unknown
                    stream.BaseStream.Write(Breaku32((strpos >> 2)), 1, 3);                      //Node filename offset position (divided by 4)
                    strpos += nodeInfo[hashes[i].index].namesize;
                    stream.BaseStream.Write(Breaku32(nodeData[hashes[i].index].startPos), 0, 4); //Node start data offset position
                    stream.BaseStream.Write(Breaku32(nodeData[hashes[i].index].endPos), 0, 4);   //Node end data offset position
                }
                GC.Collect();
                //SFNT ---
                stream.BaseStream.Write(new byte[] { 83, 70, 78, 84, 0x00, 0x08, 0x00, 0x00 }, 0, 8); //Write fixed SFNT header
                for (int i = 0; i < numFiles; i++)
                {
                    string fileName = nodeInfo[hashes[i].index].filename;
                    for (int j = 0; j < fileName.Length; j++)
                    {
                        stream.BaseStream.WriteByte((byte)fileName[j]);                                                    //Write file names
                    }
                    int namePadding = (int)nodeInfo[hashes[i].index].namesize - nodeInfo[hashes[i].index].filename.Length; //short padding for file offset location (to be divisible by 4)
                    if ((i == numFiles - 1) && (namePadding == 4))                                                         //if the last filename conveniently ended at 0x0F, then do not add any padding
                    {
                        namePadding = 0;
                    }
                    for (int j = 0; j < namePadding; j++)
                    {
                        stream.BaseStream.WriteByte(0);
                    }
                }

                for (int i = 0; i < namePaddingToAdd; i++)
                {
                    stream.BaseStream.WriteByte(0); //pad end of names
                }



                //Data ---
                for (int i = 0; i < numFiles; i++)
                {
                    stream.BaseStream.Write(nodeData[hashes[i].index].data, 0, nodeData[hashes[i].index].data.Length);
                    if (nodeData[hashes[i].index].padding != 0)
                    {
                        for (int j = 0; j < nodeData[hashes[i].index].padding; j++)
                        {
                            stream.BaseStream.WriteByte(0);
                        }
                    }
                }

                stream.Close();
                stream.Dispose();
                GC.Collect();
            }
            catch (System.Exception e)
            {
                lerror = "An error occurred: " + e.Message;
                return(false);
            }

            return(true);
        } //--------------------------------------------------------------------------------------------------------------------------------------------
예제 #6
0
        public Isomorphism(IGraph firstGraph, IGraph secondGraph, int maxIterations = 16)
        {
            FirstGraph    = firstGraph;
            SecondGraph   = secondGraph;
            FirstToSecond = null;

            if (firstGraph.NodeCount() != secondGraph.NodeCount() ||
                firstGraph.ArcCount() != secondGraph.ArcCount() ||
                firstGraph.ArcCount(ArcFilter.Edge) != secondGraph.ArcCount(ArcFilter.Edge))
            {
                Isomorphic = false;
            }
            else
            {
                ConnectedComponents firstCC  = new ConnectedComponents(firstGraph, ConnectedComponents.Flags.CreateComponents);
                ConnectedComponents secondCC = new ConnectedComponents(secondGraph, ConnectedComponents.Flags.CreateComponents);
                if (firstCC.Count != secondCC.Count ||
                    !firstCC.Components.Select(s => s.Count).OrderBy(x => x).SequenceEqual(
                        secondCC.Components.Select(s => s.Count).OrderBy(x => x)))
                {
                    Isomorphic = false;
                }
                else
                {
                    NodeHash firstHash  = new NodeHash(firstGraph);
                    NodeHash secondHash = new NodeHash(secondGraph);
                    if (firstHash.ColoringHash != secondHash.ColoringHash)
                    {
                        // degree distribution not equal
                        Isomorphic = false;
                    }
                    else if (firstHash.RegularGraph && secondHash.RegularGraph &&
                             firstHash.ColoringHash == secondHash.ColoringHash)
                    {
                        // TODO do something with regular graphs
                        // maybe spectral test
                        Isomorphic = null;
                    }
                    else
                    {
                        Isomorphic = null;
                        for (int i = 0; i < maxIterations; ++i)
                        {
                            firstHash.Iterate();
                            secondHash.Iterate();
                            if (firstHash.ColoringHash != secondHash.ColoringHash)
                            {
                                Isomorphic = false;
                                break;
                            }
                        }

                        if (Isomorphic == null)
                        {
                            // graphs are very probably isomorphic (or tricky), try to find the mapping
                            var firstColor  = firstHash.GetSortedColoring();
                            var secondColor = secondHash.GetSortedColoring();

                            // is the canonical coloring the same, and does it uniquely identify nodes?
                            Isomorphic = true;
                            for (int i = 0; i < firstColor.Count; ++i)
                            {
                                if (firstColor[i].Value != secondColor[i].Value)
                                {
                                    // unlikely because the hashes matched
                                    Isomorphic = false;
                                    break;
                                }
                                else if (i > 0 && firstColor[i].Value == firstColor[i - 1].Value)
                                {
                                    // two nodes colored the same way (this may happen)
                                    // TODO handle this case. Else we won't work for graphs with symmetries.
                                    Isomorphic = null;
                                    break;
                                }
                            }

                            if (Isomorphic == true)
                            {
                                FirstToSecond = new Dictionary <Node, Node>(firstColor.Count);
                                for (int i = 0; i < firstColor.Count; ++i)
                                {
                                    FirstToSecond[firstColor[i].Key] = secondColor[i].Key;
                                }
                            }
                        }
                    }
                }
            }
        }
        public bool Equals(DestinyTalentNodeDefinition input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     NodeIndex == input.NodeIndex ||
                     (NodeIndex.Equals(input.NodeIndex))
                     ) &&
                 (
                     NodeHash == input.NodeHash ||
                     (NodeHash.Equals(input.NodeHash))
                 ) &&
                 (
                     Row == input.Row ||
                     (Row.Equals(input.Row))
                 ) &&
                 (
                     Column == input.Column ||
                     (Column.Equals(input.Column))
                 ) &&
                 (
                     PrerequisiteNodeIndexes == input.PrerequisiteNodeIndexes ||
                     (PrerequisiteNodeIndexes != null && PrerequisiteNodeIndexes.SequenceEqual(input.PrerequisiteNodeIndexes))
                 ) &&
                 (
                     BinaryPairNodeIndex == input.BinaryPairNodeIndex ||
                     (BinaryPairNodeIndex.Equals(input.BinaryPairNodeIndex))
                 ) &&
                 (
                     AutoUnlocks == input.AutoUnlocks ||
                     (AutoUnlocks != null && AutoUnlocks.Equals(input.AutoUnlocks))
                 ) &&
                 (
                     LastStepRepeats == input.LastStepRepeats ||
                     (LastStepRepeats != null && LastStepRepeats.Equals(input.LastStepRepeats))
                 ) &&
                 (
                     IsRandom == input.IsRandom ||
                     (IsRandom != null && IsRandom.Equals(input.IsRandom))
                 ) &&
                 (
                     RandomActivationRequirement == input.RandomActivationRequirement ||
                     (RandomActivationRequirement != null && RandomActivationRequirement.Equals(input.RandomActivationRequirement))
                 ) &&
                 (
                     IsRandomRepurchasable == input.IsRandomRepurchasable ||
                     (IsRandomRepurchasable != null && IsRandomRepurchasable.Equals(input.IsRandomRepurchasable))
                 ) &&
                 (
                     Steps == input.Steps ||
                     (Steps != null && Steps.SequenceEqual(input.Steps))
                 ) &&
                 (
                     ExclusiveWithNodeHashes == input.ExclusiveWithNodeHashes ||
                     (ExclusiveWithNodeHashes != null && ExclusiveWithNodeHashes.SequenceEqual(input.ExclusiveWithNodeHashes))
                 ) &&
                 (
                     RandomStartProgressionBarAtProgression == input.RandomStartProgressionBarAtProgression ||
                     (RandomStartProgressionBarAtProgression.Equals(input.RandomStartProgressionBarAtProgression))
                 ) &&
                 (
                     LayoutIdentifier == input.LayoutIdentifier ||
                     (LayoutIdentifier != null && LayoutIdentifier.Equals(input.LayoutIdentifier))
                 ) &&
                 (
                     GroupHash == input.GroupHash ||
                     (GroupHash.Equals(input.GroupHash))
                 ) &&
                 (
                     LoreHash == input.LoreHash ||
                     (LoreHash.Equals(input.LoreHash))
                 ) &&
                 (
                     NodeStyleIdentifier == input.NodeStyleIdentifier ||
                     (NodeStyleIdentifier != null && NodeStyleIdentifier.Equals(input.NodeStyleIdentifier))
                 ) &&
                 (
                     IgnoreForCompletion == input.IgnoreForCompletion ||
                     (IgnoreForCompletion != null && IgnoreForCompletion.Equals(input.IgnoreForCompletion))
                 ));
        }