public static uint Get_FourCC_FromTellale(T3SurfaceFormat format)
        {
            switch (format)
            {
            default:
                return(ByteFunctions.Convert_String_To_UInt32("DXT1"));

            case Telltale.T3SurfaceFormat.eSurface_DXT1:
                return(ByteFunctions.Convert_String_To_UInt32("DXT1"));

            case Telltale.T3SurfaceFormat.eSurface_DXT3:
                return(ByteFunctions.Convert_String_To_UInt32("DXT3"));

            case Telltale.T3SurfaceFormat.eSurface_DXT5:
                return(ByteFunctions.Convert_String_To_UInt32("DXT5"));

            case Telltale.T3SurfaceFormat.eSurface_DXN:
                return(ByteFunctions.Convert_String_To_UInt32("ATI2"));

            case Telltale.T3SurfaceFormat.eSurface_DXT5A:
                return(ByteFunctions.Convert_String_To_UInt32("ATI1"));

            case Telltale.T3SurfaceFormat.eSurface_A8:
                return(0);
            }
        }
Ejemplo n.º 2
0
        public static string Get2Bytes(byte[] bytesin, int local)
        {
            string get2BytesRet = default;

            get2BytesRet = ByteFunctions.MakeProperByte(bytesin[local]) + ByteFunctions.MakeProperByte(bytesin[local + 1]);
            return(get2BytesRet);
        }
 public static T3SurfaceFormat Get_T3Format_FromFourCC(uint fourCC)
 {
     if (fourCC == ByteFunctions.Convert_String_To_UInt32("DXT1"))
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXT1);
     }
     else if (fourCC == ByteFunctions.Convert_String_To_UInt32("DXT3"))
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXT3);
     }
     else if (fourCC == ByteFunctions.Convert_String_To_UInt32("DXT5"))
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXT5);
     }
     else if (fourCC == ByteFunctions.Convert_String_To_UInt32("ATI2"))
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXN);
     }
     else if (fourCC == ByteFunctions.Convert_String_To_UInt32("ATI1"))
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXT5A);
     }
     else
     {
         return(Telltale.T3SurfaceFormat.eSurface_DXT1);
     }
 }
Ejemplo n.º 4
0
        private void Button3_Click(object sender, EventArgs e)
        {
            string localReverseHEX()
            {
                string argHEXData = Strings.Right("0000" + Conversion.Hex(ByteFunctions.SpeciestoDexNum(ComboBox3.SelectedIndex + 1)), 4); var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
            }

            int    argStart = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexSmallestTable", ""), System.Globalization.NumberStyles.HexNumber) + ListBox3.SelectedIndex * 2;
            string argData  = localReverseHEX();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart, ref argData);
            int refreshvar;
            int refreshvar2;

            refreshvar  = ListBox3.SelectedIndex;
            refreshvar2 = ComboBox3.SelectedIndex;
            if (ListBox3.SelectedIndex == 0)
            {
                ListBox3.SelectedIndex = ListBox3.SelectedIndex + 1;
            }
            else
            {
                ListBox3.SelectedIndex = ListBox3.SelectedIndex - 1;
            }

            ListBox3.Items.Insert(refreshvar, GetNameFunctions.GetPokemonName(refreshvar2 + 1));
            ListBox3.Items.RemoveAt(refreshvar + 1);
            ListBox3.SelectedIndex = refreshvar;
        }
        public void TEST_WriteDDSToDisk(string destinationPath)
        {
            //THIS WORKS
            string extension = Path.GetExtension(destinationPath);
            string newPath   = destinationPath.Remove(destinationPath.Length - extension.Length, extension.Length);

            newPath += "_parseTest" + extension;

            byte[] finalData = new byte[0];

            //turn our header data into bytes to be written into a file
            byte[] dds_header = ByteFunctions.Combine(ByteFunctions.GetBytes("DDS "), DDS_Functions.GetHeaderBytes(header));

            //copy the dds header to the file
            finalData = ByteFunctions.Combine(finalData, dds_header);

            //copy the images
            for (int i = 0; i <= textureData.Count - 1; i++)
            {
                finalData = ByteFunctions.Combine(finalData, textureData[i]);
            }

            //write the file to the disk
            File.WriteAllBytes(newPath, finalData);
        }
Ejemplo n.º 6
0
        public void WriteBinaryData(BinaryWriter writer)
        {
            writer.Write(mVersion);                         //mVersion [4 bytes]
            writer.Write(mSamplerState_BlockSize);          //mSamplerState Block Size [4 bytes]
            writer.Write(mSamplerState.mData);              //mSamplerState mData [4 bytes]
            writer.Write(mPlatform_BlockSize);              //mPlatform Block Size [4 bytes]
            writer.Write((int)mPlatform);                   //mPlatform [4 bytes]
            writer.Write(mName_BlockSize);                  //mName Block Size [4 bytes] //mName block size (size + string len)
            ByteFunctions.WriteString(writer, mName);       //mName [x bytes]
            writer.Write(mImportName_BlockSize);            //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
            ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
            writer.Write(mImportScale);                     //mImportScale [4 bytes]
            writer.Write(mToolProps.mbHasProps);            //mToolProps mbHasProps [1 byte]
            writer.Write(mNumMipLevels);                    //mNumMipLevels [4 bytes]
            writer.Write(mWidth);                           //mWidth [4 bytes]
            writer.Write(mHeight);                          //mHeight [4 bytes]
            writer.Write((int)mSurfaceFormat);              //mSurfaceFormat [4 bytes]
            writer.Write((int)mResourceUsage);              //mResourceUsage [4 bytes]
            writer.Write((int)mType);                       //mType [4 bytes]
            writer.Write(mNormalMapFormat);                 //mNormalMapFormat [4 bytes]
            writer.Write(mHDRLightmapScale);                //mHDRLightmapScale [4 bytes]
            writer.Write(mToonGradientCutoff);              //mToonGradientCutoff [4 bytes]
            writer.Write((int)mAlphaMode);                  //mAlphaMode [4 bytes]
            writer.Write((int)mColorMode);                  //mColorMode [4 bytes]
            writer.Write(mUVOffset.x);                      //mUVOffset X [4 bytes]
            writer.Write(mUVOffset.y);                      //mUVOffset Y [4 bytes]
            writer.Write(mUVScale.x);                       //mUVScale X [4 bytes]
            writer.Write(mUVScale.y);                       //mUVScale Y [4 bytes]

            writer.Write(mToonRegions_ArrayCapacity);       //mToonRegions DCArray Capacity [4 bytes]
            writer.Write(mToonRegions_ArrayLength);         //mToonRegions DCArray Length [4 bytes]
            for (int i = 0; i < mToonRegions_ArrayLength; i++)
            {
                writer.Write(mToonRegions[i].mColor.r); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.g); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.b); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.a); //[4 bytes]
                writer.Write(mToonRegions[i].mSize);    //[4 bytes]
            }

            writer.Write(mStreamHeader.mRegionCount);   //mRegionCount [4 bytes]
            writer.Write(mStreamHeader.mAuxDataCount);  //mAuxDataCount [4 bytes]
            writer.Write(mStreamHeader.mTotalDataSize); //mTotalDataSize [4 bytes]

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                writer.Write(mRegionHeaders[i].mFaceIndex);  //[4 bytes]
                writer.Write(mRegionHeaders[i].mMipIndex);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mMipCount);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mDataSize);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mPitch);      //[4 bytes]
                writer.Write(mRegionHeaders[i].mSlicePitch); //[4 bytes]
            }

            for (int i = 0; i < mPixelData.Count; i++)
            {
                writer.Write(mPixelData[i]);
            }
        }
Ejemplo n.º 7
0
        private static async Task <byte[]> FileStreamToByte(FuncionarioRequest funcionarios)
        {
            using (var fileStream = new FileStream(funcionarios.InputFile.FileName, FileMode.Create))
            {
                await funcionarios.InputFile.CopyToAsync(fileStream);

                return(await ByteFunctions.ConverteStreamToByteArray(funcionarios.InputFile.OpenReadStream()));
            }
        }
Ejemplo n.º 8
0
        public static void SaveTrainerSpriteToFreeSpace(int index, byte[] sprite, Color[] pallete)
        {
            var    sOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "TrainerImageTable", ""), System.Globalization.NumberStyles.HexNumber) + index * 8;
            var    pOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "TrainerPaletteTable", ""), System.Globalization.NumberStyles.HexNumber) + index * 8;
            string imgString;
            string palString;

            byte[] imgBytes;
            byte[] palBytes;
            string imgNewOffset;
            string palNewOffset;

            string LocalCompressLz77String()
            {
                var argsrcString = WichuRomFunctions.ConvertByteArrayToString(ref sprite); var ret = WichuRomFunctions.CompressLz77String(ref argsrcString); return(ret);
            }

            var argstr = LocalCompressLz77String();

            imgBytes = WichuRomFunctions.ConvertStringToByteArray(ref argstr);
            string LocalCompressLz77String1()
            {
                var argsrcString = WichuSpriteFunctions.ConvertPaletteToString(ref pallete); var ret = WichuRomFunctions.CompressLz77String(ref argsrcString); return(ret);
            }

            var argstr1 = LocalCompressLz77String1();

            palBytes     = WichuRomFunctions.ConvertStringToByteArray(ref argstr1);
            imgString    = ByteFunctions.ByteArrayToHexString(imgBytes);
            palString    = ByteFunctions.ByteArrayToHexString(palBytes);
            imgNewOffset = modSearchFreeSpace.SearchFreeSpaceFourAligned(MainObject.LoadedRom, 0xFF, (long)(Strings.Len(imgString) / 2d), Conversions.ToLong("&H" + Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "StartSearchingForSpaceOffset", "800000"))).ToString();
            var argStart = Conversions.ToInteger(imgNewOffset);

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart, ref imgString);
            string LocalReverseHex()
            {
                var argHexData = Conversion.Hex(Conversions.ToDouble(imgNewOffset) + 134217728d); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argData = LocalReverseHex();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref sOffset, ref argData);
            palNewOffset = modSearchFreeSpace.SearchFreeSpaceFourAligned(MainObject.LoadedRom, 0xFF, (long)(Strings.Len(palString) / 2d), Conversions.ToLong("&H" + Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "StartSearchingForSpaceOffset", "800000"))).ToString();
            var argStart1 = Conversions.ToInteger(palNewOffset);

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart1, ref palString);
            string LocalReverseHex1()
            {
                var argHexData = Conversion.Hex(Conversions.ToDouble(palNewOffset) + 134217728d); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argData1 = LocalReverseHex1();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref pOffset, ref argData1);
        }
 public static DDS_HEADER GetBlankHeader()
 {
     return(new DDS_HEADER()
     {
         dwSize = 124,
         ddspf = new DDS_PIXELFORMAT()
         {
             dwSize = 32,
             dwFourCC = ByteFunctions.Convert_String_To_UInt32("DXT1"),
         },
     });
 }
Ejemplo n.º 10
0
        public void ModifyD3DTX(DDS_Master dds)                                                //ISSUE HERE WITH DXT5 AND MIP MAPS WITH UPSCALED TEXTURES
        {
            mWidth         = dds.header.dwWidth;                                               //this is correct
            mHeight        = dds.header.dwHeight;                                              //this is correct
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC); //this is correct
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = dds.textureData;

            ddsData.Reverse();

            mPixelData.Clear();   //this is correct
            mPixelData = ddsData; //this is correct


            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,                         //this is correct
                mAuxDataCount  = mStreamHeader.mAuxDataCount,                           //this is correct
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;                                                //this is correct

            List <RegionStreamHeader> regionStreamHeader = new List <RegionStreamHeader>(); //this is correct

            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                RegionStreamHeader region = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                          //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (mStreamHeader.mRegionCount - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[mStreamHeader.mRegionCount - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                       //this is correct
                };

                regionStreamHeader.Add(region);
            }

            regionStreamHeader.Reverse();
            mRegionHeaders = regionStreamHeader.ToArray();

            UpdateArrayCapacities();
            PrintConsole();
        }
Ejemplo n.º 11
0
        private void ListBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            string localReadHEX()
            {
                int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexSmallestTable", ""), System.Globalization.NumberStyles.HexNumber) + ListBox3.SelectedIndex * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string localReverseHEX()
            {
                string argHEXData = "hs58434bdf19ed48f38f3040598eedaa65()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
            }

            ComboBox3.SelectedIndex = Conversions.ToInteger(Operators.SubtractObject(ByteFunctions.PokedexNumbertoSpecies(int.Parse(localReverseHEX(), System.Globalization.NumberStyles.HexNumber)), 1));
        }
Ejemplo n.º 12
0
        private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string localReadHEX()
            {
                int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexAlphabetTable", ""), System.Globalization.NumberStyles.HexNumber) + ListBox1.SelectedIndex * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string localReverseHEX()
            {
                string argHEXData = "hsf8dbc22cf9934c8ca5406a8f7013a2fb()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
            }

            ComboBox1.SelectedIndex = Conversions.ToInteger(Operators.SubtractObject(ByteFunctions.PokedexNumbertoSpecies(int.Parse(localReverseHEX(), System.Globalization.NumberStyles.HexNumber)), 1));
        }
        public void Modify_D3DTX(DDS_Master dds)
        {
            if (d3dtx4 != null)
            {
                d3dtx4.ModifyD3DTX(dds);

                if (msv5 != null)
                {
                    msv5.mDefaultSectionChunkSize = d3dtx4.GetHeaderByteSize();
                    msv5.mAsyncSectionChunkSize   = ByteFunctions.Get2DByteArrayTotalSize(d3dtx4.mPixelData);
                }
                else if (msv6 != null)
                {
                    msv6.mDefaultSectionChunkSize = d3dtx4.GetHeaderByteSize();
                    msv6.mAsyncSectionChunkSize   = ByteFunctions.Get2DByteArrayTotalSize(d3dtx4.mPixelData);
                }
            }
            else if (d3dtx5 != null)
            {
                d3dtx5.ModifyD3DTX(dds);
            }
            else if (d3dtx6 != null)
            {
                d3dtx6.ModifyD3DTX(dds);
            }
            else if (d3dtx7 != null)
            {
                d3dtx7.ModifyD3DTX(dds);
            }
            else if (d3dtx8 != null)
            {
                d3dtx8.ModifyD3DTX(dds);
            }
            else if (d3dtx9 != null)
            {
                d3dtx9.ModifyD3DTX(dds);

                if (msv5 != null)
                {
                    msv5.mDefaultSectionChunkSize = d3dtx9.GetHeaderByteSize();
                    msv5.mAsyncSectionChunkSize   = ByteFunctions.Get2DByteArrayTotalSize(d3dtx9.mPixelData);
                }
                else if (msv6 != null)
                {
                    msv6.mDefaultSectionChunkSize = d3dtx9.GetHeaderByteSize();
                    msv6.mAsyncSectionChunkSize   = ByteFunctions.Get2DByteArrayTotalSize(d3dtx9.mPixelData);
                }
            }
        }
        /// <summary>
        /// Converts the data of this object into a byte array.
        /// </summary>
        /// <returns></returns>
        public void GetByteData(BinaryWriter writer)
        {
            ByteFunctions.WriteFixedString(writer, mMetaStreamVersion); //Meta Stream Keyword [4 bytes]
            writer.Write(mClassNamesLength);                            //mClassNamesLength [4 bytes]

            //--------------------------mClassNames--------------------------
            for (int i = 0; i < mClassNames.Length; i++)
            {
                //symbol
                writer.Write(mClassNames[i].mTypeNameCRC.mCrc64);

                //version crc
                writer.Write(mClassNames[i].mVersionCRC);
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Converts the data of this object into a byte array.
        /// </summary>
        /// <returns></returns>
        public void GetByteData(BinaryWriter writer)
        {
            ByteFunctions.WriteFixedString(writer, mMetaStreamVersion); //Meta Stream Keyword [4 bytes]
            writer.Write(mDefaultSectionChunkSize);                     //Default Section Chunk Size [4 bytes] default section chunk size
            writer.Write(mDebugSectionChunkSize);                       //Debug Section Chunk Size [4 bytes] debug section chunk size (always zero)
            writer.Write(mAsyncSectionChunkSize);                       //Async Section Chunk Size [4 bytes] async section chunk size (size of the bytes after the file header)
            writer.Write(mClassNamesLength);                            //mClassNamesLength [4 bytes]

            //--------------------------mClassNames--------------------------
            for (int i = 0; i < mClassNames.Length; i++)
            {
                writer.Write(mClassNames[i].mTypeNameCRC.mCrc64); //symbol
                writer.Write(mClassNames[i].mVersionCRC);         //version crc
            }
        }
        public void ModifyD3DTX(DDS_Master dds)
        {
            mWidth         = dds.header.dwWidth;
            mHeight        = dds.header.dwHeight;
            mSurfaceFormat = DDS_Functions.Get_T3Format_FromFourCC(dds.header.ddspf.dwFourCC);
            mDepth         = dds.header.dwDepth;
            mNumMipLevels  = dds.header.dwMipMapCount;

            List <byte[]> ddsData = new List <byte[]>(dds.textureData); //this is correct

            ddsData.Reverse();                                          //this is correct

            mPixelData.Clear();                                         //this is correct
            mPixelData = ddsData;                                       //this is correct

            StreamHeader newStreamHeader = new StreamHeader()
            {
                mRegionCount   = (int)dds.header.dwMipMapCount,
                mAuxDataCount  = mStreamHeader.mAuxDataCount,
                mTotalDataSize = (int)ByteFunctions.Get2DByteArrayTotalSize(mPixelData) //this is correct
            };

            mStreamHeader = newStreamHeader;

            RegionStreamHeader[] regionStreamHeader = new RegionStreamHeader[mStreamHeader.mRegionCount];
            uint[,] mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(mNumMipLevels, mWidth, mHeight);
            bool blockSizeDouble = DDS_Functions.DDS_CompressionBool(dds.header);

            for (int i = 0; i < regionStreamHeader.Length; i++)
            {
                regionStreamHeader[i] = new RegionStreamHeader()
                {
                    mDataSize   = (uint)mPixelData[i].Length,
                    mFaceIndex  = 0,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipCount   = 1,                                                                                                         //NOTE: for cubemap textures this will need to change
                    mMipIndex   = (regionStreamHeader.Length - 1) - i,                                                                       //mMipIndex = (regionStreamHeader.Length - 1) - i,
                    mPitch      = DDS_Functions.DDS_ComputePitchValue(mipMapResolutions[regionStreamHeader.Length - i, 0], blockSizeDouble), //this is correct
                    mSlicePitch = mPixelData[i].Length,                                                                                      //this is correct
                };
            }

            mRegionHeaders = regionStreamHeader;

            UpdateArrayCapacities();
            //PrintConsole();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Parses the Meta Header from a byte array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bytePointerPosition"></param>
        /// <param name="showConsole"></param>
        public MSV5(BinaryReader reader, bool showConsole = true)
        {
            mMetaStreamVersion      += ByteFunctions.ReadFixedString(reader, 4); //Meta Stream Keyword [4 bytes]
            mDefaultSectionChunkSize = reader.ReadUInt32();                      //Default Section Chunk Size [4 bytes] //default section chunk size
            mDebugSectionChunkSize   = reader.ReadUInt32();                      //Debug Section Chunk Size [4 bytes] //debug section chunk size (always zero)
            mAsyncSectionChunkSize   = reader.ReadUInt32();                      //Async Section Chunk Size [4 bytes] //async section chunk size (size of the bytes after the file header)
            mClassNamesLength        = reader.ReadUInt32();                      //mClassNamesLength [4 bytes]

            //--------------------------mClassNames--------------------------
            mClassNames = new ClassNames[mClassNamesLength];

            for (int i = 0; i < mClassNames.Length; i++)
            {
                mClassNames[i] = new ClassNames()
                {
                    mTypeNameCRC = new Symbol()
                    {
                        mCrc64 = reader.ReadUInt64()
                    },
                    mVersionCRC = reader.ReadUInt32()
                };
            }

            MetaHeaderLength = (4 * 5) + (12 * mClassNamesLength);

            if (showConsole)
            {
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Cyan);
                Console.WriteLine("||||||||||| Meta Header |||||||||||");
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
                Console.WriteLine("Meta Stream Keyword = {0}", mMetaStreamVersion);
                Console.WriteLine("Meta Default Section Chunk Size = {0}", mDefaultSectionChunkSize);
                Console.WriteLine("Meta Debug Section Chunk Size = {0}", mDebugSectionChunkSize);
                Console.WriteLine("Meta Async Section Chunk Size = {0}", mAsyncSectionChunkSize);
                Console.WriteLine("Meta mClassNamesLength = {0}", mClassNamesLength);

                for (int i = 0; i < mClassNames.Length; i++)
                {
                    Console.WriteLine("Meta mClassName {0} = {1}", i, mClassNames[i]);
                }
            }
        }
Ejemplo n.º 18
0
        public static void SaveAnimationSpriteToFreeSpace(int pokemonindex, byte[] sprite)
        {
            var    sOffset = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokemonAnimations", ""), System.Globalization.NumberStyles.HexNumber) + pokemonindex * 8; // Pointer to Pokemon front sprites, + 8 = Bulbasaur.
            string imgString;

            byte[] imgBytes;
            string imgNewOffset;

            string LocalCompressLz77String()
            {
                var argsrcString = WichuRomFunctions.ConvertByteArrayToString(ref sprite);
                var ret          = WichuRomFunctions.CompressLz77String(ref argsrcString);

                return(ret);
            }

            var argstr = LocalCompressLz77String();

            imgBytes     = WichuRomFunctions.ConvertStringToByteArray(ref argstr);
            imgString    = ByteFunctions.ByteArrayToHexString(imgBytes);
            imgNewOffset = modSearchFreeSpace.SearchFreeSpaceFourAligned(MainObject.LoadedRom, 0xFF, (long)(Strings.Len(imgString) / 2d), Conversions.ToLong("&H" + Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "StartSearchingForSpaceOffset", "800000"))).ToString();


            var argStart = Conversions.ToInteger(imgNewOffset);

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart, ref imgString);

            string LocalReverseHex()
            {
                var argHexData = Conversion.Hex(Conversions.ToDouble(imgNewOffset) + 134217728d);
                var ret        = HexFunctions.ReverseHex(ref argHexData);

                return(ret);
            }

            var argData = LocalReverseHex();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref sOffset, ref argData);
        }
 public static DDS_HEADER GetPresetHeader()
 {
     return(new DDS_HEADER()
     {
         dwSize = 124,
         dwFlags = 528391,
         dwHeight = 1024,
         dwWidth = 1024,
         dwPitchOrLinearSize = 8192,
         dwDepth = 0,
         dwMipMapCount = 0,
         ddspf = new DDS_PIXELFORMAT()
         {
             dwSize = 32,
             dwFlags = 4,
             dwFourCC = ByteFunctions.Convert_String_To_UInt32("DXT1"),
             dwRGBBitCount = 0,
         },
         dwCaps = 4096,
         dwCaps2 = 0,
         dwCaps3 = 0,
         dwCaps4 = 0,
     });
 }
        /// <summary>
        /// Parses the Meta Header from a byte array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bytePointerPosition"></param>
        /// <param name="showConsole"></param>
        public MTRE(BinaryReader reader, bool showConsole = true)
        {
            mMetaStreamVersion += ByteFunctions.ReadFixedString(reader, 4); //Meta Stream Keyword [4 bytes]
            mClassNamesLength   = reader.ReadUInt32();                      //mClassNamesLength [4 bytes]

            //--------------------------mClassNames--------------------------
            mClassNames = new ClassNames[mClassNamesLength];

            for (int i = 0; i < mClassNames.Length; i++)
            {
                mClassNames[i] = new ClassNames()
                {
                    mTypeNameCRC = new Symbol()
                    {
                        mCrc64 = reader.ReadUInt64()
                    },
                    mVersionCRC = reader.ReadUInt32()
                };
            }

            MetaHeaderLength = (4 * 5) + (12 * mClassNamesLength);

            if (showConsole)
            {
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.Cyan);
                Console.WriteLine("||||||||||| Meta Header |||||||||||");
                ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
                Console.WriteLine("Meta Stream Keyword = {0}", mMetaStreamVersion);
                Console.WriteLine("Meta mClassNamesLength = {0}", mClassNamesLength);

                for (int i = 0; i < mClassNames.Length; i++)
                {
                    Console.WriteLine("Meta mClassName {0} = {1}", i, mClassNames[i]);
                }
            }
        }
Ejemplo n.º 21
0
        public static bool SaveCry(Cry crytosave, int cryTable)
        {
            if (crytosave.Offset == 0)
            {
                return(false);
            }
            // var lookup = new byte[] { 0x0, 0x1, 0x4, 0x9, 0x10, 0x19, 0x24, 0x31, 0xC0, 0xCF, 0xDC, 0xE7, 0xF0, 0xF7, 0xFC, 0xFF };
            var lookup = new sbyte[] { 0, 1, 4, 9, 16, 25, 36, 49, -64, -49, -36, -25, -16, -9, -4, -1 };

            crytosave.Compressed = false;

            // copy cry data to be written
            var data = new List <byte>();

            if (crytosave.Compressed)
            {
                //Interaction.MsgBox("This should not be enabled!");
                Environment.Exit(0);
            }

            // ' data is compressed in blocks of 1 + 0x20 bytes at a time
            // ' first byte is normal signed PCM data
            // ' following 0x20 bytes are compressed based on previous value
            // ' (for a value not in lookup table, closest value will be chosen instead)
            // 'Console.WriteLine("compressed");

            // ' each block has 0x40 samples
            // Dim blockCount = crytosave.Data.Length / &H40
            // If crytosave.Data.Length Mod &H40 > 0 Then
            // blockCount += 1
            // End If

            // ' truncates the length of the last block
            // ' so we don't waste space
            // Dim lastBlockSize = crytosave.Data.Length - crytosave.Data.Length / &H40 * &H40
            // If lastBlockSize = 0 Then
            // lastBlockSize = &H21
            // Else
            // lastBlockSize = 1 + (lastBlockSize / 2) + (If(lastBlockSize Mod 2 = 0, 0, 1))
            // End If

            // Dim blocks = New Byte(blockCount - 1)() {}
            // For n As Integer = 0 To blockCount - 1
            // ' create new block
            // If n < blockCount - 1 Then
            // blocks(n) = New Byte(32) {}
            // Else
            // blocks(n) = New Byte(lastBlockSize - 1) {}
            // End If

            // Dim i As Integer = n * &H40
            // Dim k As Integer = 0

            // If i < crytosave.Data.Length Then
            // ' set first value
            // blocks(n)(k) = BitConverter.GetBytes(crytosave.Data(i))(0)
            // End If

            // k = k + 1

            // Dim pcm As SByte

            // If i < crytosave.Data.Length Then

            // pcm = crytosave.Data(i)

            // End If

            // i = i + 1

            // Dim j As Integer = 1
            // While j < &H40 And i < crytosave.Data.Length
            // ' get current sample
            // Dim sample As SByte = crytosave.Data(i)

            // i = i + 1

            // ' difference between previous sample and this
            // Dim diff As Integer = sample - pcm

            // ' check for a perfect match in lookup table
            // Dim lookupI = -1
            // For x As Integer = 0 To 15
            // If lookup(x) = diff Then
            // lookupI = x
            // Exit For
            // End If
            // Next

            // ' search for the closest match in the table
            // If lookupI = -1 Then
            // Dim bestDiff As Integer = 255
            // For x As Integer = 0 To 15
            // If Math.Abs(CInt(lookup(x)) - diff) < bestDiff Then
            // lookupI = x
            // bestDiff = Math.Abs(lookup(x) - diff)
            // End If
            // Next
            // End If

            // ' set value in block
            // ' on an odd value, increase position in block
            // If j Mod 2 = 0 Then
            // blocks(n)(k) = blocks(n)(k) Or CByte(lookupI << 4)
            // Else
            // blocks(n)(k) = blocks(n)(k) Or CByte(lookupI)

            // k = k + 1

            // End If

            // ' set previous
            // pcm = sample
            // j += 1
            // End While
            // Next

            // For n As Integer = 0 To blockCount - 1
            // data.AddRange(blocks(n))
            // Next
            else
            {
                // uncompressed, copy directly to data
                // Console.WriteLine("uncompressed");
                foreach (var s in crytosave.Data)
                {
                    data.Add((byte)(s & 0xFF));
                }
            }

            //// determine if cry requires repointing
            //if (crytosave.Size < data.Count)
            //{
            //    var result = MessageBox.Show("The Cry will be written to free space and the pointer will be repointed. Would you like to do that?", "Repoint?", MessageBoxButtons.YesNo);
            //    if (result == DialogResult.Yes)
            //    {
            //        var result2 = MessageBox.Show("Fill the old cry with free space?", "Delete old cry?", MessageBoxButtons.YesNo);
            //        if (result2 == DialogResult.Yes)
            //        {
            //            string argData = Conversions.ToString(MainObject.MakeFreeSpaceString(crytosave.Size + 16));
            //            HexFunctions.WriteHEX(ref MainObject.LoadedRom, ref crytosave.Offset, ref argData);
            //        }

            //        // set new cry offset
            //        crytosave.Offset = (int)modSearchFreeSpace.SearchFreeSpaceFourAligned(MainObject.LoadedRom, 0xFF, data.Count, Conversions.ToLong("&H" + INI.GetString(Conversions.ToString(MainObject.GetIniFileLocation()), MainObject.Header, "StartSearchingForSpaceOffset", "800000")));
            //    }
            //    else
            //    {
            //        return false;
            //    }
            //}

            // write cry


            string LocalReverseHex()
            {
                var argHexData = Strings.Right("0000" + (ushort)(crytosave.Compressed ? 1 : 0), 4); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argData1 = LocalReverseHex();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref crytosave.Offset, ref argData1);
            string LocalReverseHex1()
            {
                var argHexData = Strings.Right("0000" + (ushort)(crytosave.Looped ? 0x4000 : 0), 4); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart = crytosave.Offset + 2;
            var argData2 = LocalReverseHex1();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart, ref argData2);
            string LocalReverseHex2()
            {
                var argHexData = Strings.Right("00000000" + (crytosave.SampleRate << 10), 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart1 = crytosave.Offset + 4;
            var argData3  = LocalReverseHex2();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart1, ref argData3);
            string LocalReverseHex3()
            {
                var argHexData = Strings.Right("00000000" + crytosave.LoopStart, 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart2 = crytosave.Offset + 8;
            var argData4  = LocalReverseHex3();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart2, ref argData4);
            string LocalReverseHex4()
            {
                var argHexData = Strings.Right("00000000" + (crytosave.Data.Length - 1), 8); var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var argStart3 = crytosave.Offset + 12;
            var argData5  = LocalReverseHex4();

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart3, ref argData5);

            // WriteHEX(LoadedROM, crytosave.Offset, ReverseHEX(VB.Right("0000" & CUShort(If(crytosave.Compressed, 1, 0)), 4)))
            // WriteHEX(LoadedROM, crytosave.Offset + 2, ReverseHEX(VB.Right("0000" & CUShort(If(crytosave.Looped, &H4000, 0)), 4)))
            // WriteHEX(LoadedROM, crytosave.Offset + 4, ReverseHEX(VB.Right("00000000" & (crytosave.SampleRate << 10), 8)))
            // WriteHEX(LoadedROM, crytosave.Offset + 8, ReverseHEX(VB.Right("00000000" & (crytosave.LoopStart), 8)))
            // WriteHEX(LoadedROM, crytosave.Offset + 12, ReverseHEX(VB.Right("00000000" & (crytosave.Data.Length - 1), 8)))

            var tempbuff  = ByteFunctions.ByteArrayToHexString(data.ToArray());
            var argStart4 = crytosave.Offset + 16;

            HexFunctions.WriteHex(ref MainObject.LoadedRom, ref argStart4, ref tempbuff);

            // write cry table entry

            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12), ReverseHEX(If(crytosave.Compressed, "00003C20", "00003C00")))
            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12) + 4, ReverseHEX(VB.Right("00000000" & Hex(crytosave.Offset), 8)))
            // WriteHEX(LoadedROM, cryTable + (crytosave.Index * 12) + 8, "FF00FF")


            // rom.WriteUInt16(CUShort(If(Cry.Compressed, 1, 0)))
            // rom.WriteUInt16(CUShort(If(Cry.Looped, &H4000, 0)))
            // rom.WriteInt32(Cry.SampleRate << 10)
            // rom.WriteInt32(Cry.LoopStart)
            // rom.WriteInt32(Cry.Data.Length - 1)
            // rom.WriteBytes(data.ToArray())

            // ' write cry table entry
            // rom.Seek(cryTable + Cry.Index * 12)
            // rom.WriteUInt32(If(Cry.Compressed, &H3C20UI, &H3C00UI))
            // rom.WritePointer(Cry.Offset)
            // rom.WriteUInt32(&HFF00FFUI)

            // ' write growl table entry
            // rom.Seek(growlTable + Cry.Index * 12)
            // rom.WriteUInt32(If(Cry.Compressed, &H3C30UI, &H3C00UI))
            // ' !!! not sure if 00 should be used for uncompressed
            // rom.WritePointer(Cry.Offset)
            // rom.WriteUInt32(&HFF00FFUI)
            return(true);
        }
Ejemplo n.º 22
0
        public static Cry LoadCry(int index, int cryTable)
        {
            var cryToLoad = new Cry();

            // If ledrom Is Nothing Then
            // Return False
            // End If

            // load cry table entry
            // ledrom.Seek(cryTable + index * 12)

            // Dim someValue = ledrom.ReadInt32()
            // Dim cryOffset = ledrom.ReadPointer()
            // Dim cryShape = ledrom.ReadInt32()

            string LocalReadHex()
            {
                var argStart2 = cryTable + index * 12; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex()
            {
                var argHexData = "hs114971a3962f4785bb1199029f740d9a()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var someValue = int.Parse(LocalReverseHex(), System.Globalization.NumberStyles.HexNumber);

            string LocalReadHex1()
            {
                var argStart2 = cryTable + index * 12 + 4; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex1()
            {
                var argHexData = "hs42097b91af9a4cb7bf85297615b2b82c()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var cryOffset = int.Parse(LocalReverseHex1(), System.Globalization.NumberStyles.HexNumber) - 0x8000000;

            string LocalReadHex2()
            {
                var argStart2 = cryTable + index * 12 + 8; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex2()
            {
                var argHexData = "hs636c588e252f49388e9b7cfd50d62ae5()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            var cryShape = int.Parse(LocalReverseHex2(), System.Globalization.NumberStyles.HexNumber);


            // If cryOffset = 0 Then
            // Return False
            // End If

            // load cry data
            // ledrom.Seek(cryOffset)

            cryToLoad.Offset = cryOffset;
            cryToLoad.Index  = index;


            // CryToLoad.Compressed = ledrom.ReadUInt16() = &H1
            // CryToLoad.Looped = ledrom.ReadUInt16() = &H4000
            // CryToLoad.SampleRate = ledrom.ReadInt32() >> 10
            // CryToLoad.LoopStart = ledrom.ReadInt32()
            // CryToLoad.Size = ledrom.ReadInt32() + 1

            string LocalReadHex3()
            {
                var argStart2 = cryOffset + 0; var argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex3()
            {
                var argHexData = "hs228b8612293b47259bd1ddc81cc475da()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Compressed = short.Parse(LocalReverseHex3(), System.Globalization.NumberStyles.HexNumber) == 0x1;
            string LocalReadHex4()
            {
                var argStart2 = cryOffset + 2; var argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex4()
            {
                var argHexData = "hs1356c430d68a4b5c97b50286fa9e623c()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Looped = short.Parse(LocalReverseHex4(), System.Globalization.NumberStyles.HexNumber) == 0x4000;
            string LocalReadHex5()
            {
                var argStart2 = cryOffset + 4; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex5()
            {
                var argHexData = "hsdf6fddefae014a00ae3654bb21c3d239()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.SampleRate = int.Parse(LocalReverseHex5(), System.Globalization.NumberStyles.HexNumber) >> 10;
            string LocalReadHex6()
            {
                var argStart2 = cryOffset + 8; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex6()
            {
                var argHexData = "hs8b94dd1b930547378b53e2d5ed2df7c4()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.LoopStart = int.Parse(LocalReverseHex6(), System.Globalization.NumberStyles.HexNumber);
            string LocalReadHex7()
            {
                var argStart2 = cryOffset + 12; var argLength = 4; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
            }

            string LocalReverseHex7()
            {
                var argHexData = "hs29971bab56db428e81f7e305c6e4d9da()"; var ret = HexFunctions.ReverseHex(ref argHexData); return(ret);
            }

            cryToLoad.Size = int.Parse(LocalReverseHex7(), System.Globalization.NumberStyles.HexNumber) + 1;
            if (!cryToLoad.Compressed)
            {
                // uncompressed, 1 sample per 1 byte of size
                cryToLoad.Data = new sbyte[cryToLoad.Size];
                for (int g = 0, loopTo = cryToLoad.Size - 1; g <= loopTo; g++)
                {
                    string LocalReadHex8()
                    {
                        var argStart2 = cryOffset + 16 + g; var argLength = 1; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                    }

                    cryToLoad.Data[g] = (sbyte)ByteFunctions.ByteToSignedInteger(Conversions.ToByte("&H" + LocalReadHex8()));
                }
            }
            else
            {
                // compressed, a bit of a hassle
                var lookup = new sbyte[] { 0, 1, 4, 9, 16, 25, 36, 49, -64, -49, -36, -25, -16, -9, -4, -1 };

                var   start     = cryOffset + 16;
                var   offtrack  = cryOffset + 16;
                var   alignment = 0;
                var   size      = 0;
                sbyte pcmLevel  = 0;
                var   data      = new List <sbyte>();
                while (true)
                {
                    if (alignment == 0)
                    {
                        var argLength = 1;
                        pcmLevel  = (sbyte)ByteFunctions.ByteToSignedInteger(Conversions.ToByte("&H" + HexFunctions.ReadHex(ref MainObject.LoadedRom, ref offtrack, ref argLength)));
                        offtrack += 1;
                        data.Add(pcmLevel);
                        alignment = 0x20;
                    }

                    var argLength1 = 1;
                    var input      = Conversions.ToByte("&H" + HexFunctions.ReadHex(ref MainObject.LoadedRom, ref offtrack, ref argLength1));
                    offtrack += 1;
                    if (alignment < 0x20)
                    {
                        // first nybble
                        pcmLevel += lookup[input >> 4];
                        data.Add(pcmLevel);
                    }

                    // second nybble
                    pcmLevel += lookup[input & 0xF];
                    data.Add(pcmLevel);

                    // exit when currentSize >= cry.Size
                    size += 2;
                    if (size >= cryToLoad.Size)
                    {
                        break;
                    }

                    alignment -= 1;
                }

                cryToLoad.Data = data.ToArray();
                // bytes needed to recompress
                cryToLoad.Size = offtrack - start;
            }

            return(cryToLoad);
        }
Ejemplo n.º 23
0
        private void PokedexListEditor_Load(object sender, EventArgs e)
        {
            int LoopVar;

            if (MainObject.Header2 == "BPE" | MainObject.Header2 == "BPR" | MainObject.Header2 == "BPG")
            {
                if (MainObject.Header2 != "BPE")
                {
                    GroupBox4.Enabled = true;
                }
                else
                {
                    GroupBox4.Enabled = false;
                }

                ComboBox1.Items.Clear();
                ComboBox2.Items.Clear();
                ComboBox3.Items.Clear();
                ComboBox4.Items.Clear();
                LoopVar = 0;
                while (LoopVar < Conversions.ToDouble(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "NumberOfPokemon", "")) - 1d == true)
                {
                    LoopVar = LoopVar + 1;
                    ComboBox1.Items.Add(GetNameFunctions.GetPokemonName(LoopVar));
                    ComboBox2.Items.Add(GetNameFunctions.GetPokemonName(LoopVar));
                    ComboBox3.Items.Add(GetNameFunctions.GetPokemonName(LoopVar));
                    ComboBox4.Items.Add(GetNameFunctions.GetPokemonName(LoopVar));
                }

                ListBox1.Items.Clear();
                ListBox2.Items.Clear();
                ListBox3.Items.Clear();
                ListBox4.Items.Clear();
                LoopVar = 0;
                while (LoopVar < Conversions.ToDouble(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "NumberOfPokemon", "")) - 1d == true)
                {
                    string localReadHEX()
                    {
                        int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexAlphabetTable", ""), System.Globalization.NumberStyles.HexNumber) + LoopVar * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                    }

                    string localReverseHEX()
                    {
                        string argHEXData = "hsd4e41ad50eae4354a61ac37a2cd57a45()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
                    }

                    ListBox1.Items.Add(GetNameFunctions.GetPokemonName(Conversions.ToInteger(ByteFunctions.PokedexNumbertoSpecies(int.Parse(localReverseHEX(), System.Globalization.NumberStyles.HexNumber)))));
                    if (MainObject.Header2 != "BPE")
                    {
                        string localReadHEX1()
                        {
                            int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexTypeTable", ""), System.Globalization.NumberStyles.HexNumber) + LoopVar * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                        }

                        string localReverseHEX1()
                        {
                            string argHEXData = "hs13991fce0c324b8b918d905f8babb6a1()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
                        }

                        ListBox4.Items.Add(GetNameFunctions.GetPokemonName(int.Parse(localReverseHEX1(), System.Globalization.NumberStyles.HexNumber)));
                    }

                    LoopVar = LoopVar + 1;
                }

                LoopVar = 0;
                while (LoopVar < Conversions.ToDouble(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "NumberOfDexEntries", "")) - 1d)
                {
                    string localReadHEX2()
                    {
                        int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexLightestTable", ""), System.Globalization.NumberStyles.HexNumber) + LoopVar * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                    }

                    string localReverseHEX2()
                    {
                        string argHEXData = "hse19d2278defd46c3a6c05fad62508a9a()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
                    }

                    ListBox2.Items.Add(GetNameFunctions.GetPokemonName(Conversions.ToInteger(ByteFunctions.PokedexNumbertoSpecies(int.Parse(localReverseHEX2(), System.Globalization.NumberStyles.HexNumber)))));
                    string localReadHEX3()
                    {
                        int argStart2 = int.Parse(Ini.GetString(Conversions.ToString(MMainFunctions.GetIniFileLocation()), MainObject.Header, "PokedexSmallestTable", ""), System.Globalization.NumberStyles.HexNumber) + LoopVar * 2; int argLength = 2; var ret = HexFunctions.ReadHex(ref MainObject.LoadedRom, ref argStart2, ref argLength); return(ret);
                    }

                    string localReverseHEX3()
                    {
                        string argHEXData = "hsdda2192684f249da9ffbe9dd46f9aada()"; var ret = HexFunctions.ReverseHex(ref argHEXData); return(ret);
                    }

                    ListBox3.Items.Add(GetNameFunctions.GetPokemonName(Conversions.ToInteger(ByteFunctions.PokedexNumbertoSpecies(int.Parse(localReverseHEX3(), System.Globalization.NumberStyles.HexNumber)))));
                    LoopVar = LoopVar + 1;
                }

                ListBox1.SelectedIndex = 0;
                ListBox2.SelectedIndex = 0;
                ListBox3.SelectedIndex = 0;
                if (MainObject.Header2 != "BPE")
                {
                    ListBox4.SelectedIndex = 0;
                }
            }
            else
            {
                //Interaction.MsgBox("Not supported!");
                Close();
            }
        }
        /// <summary>
        /// Deserializes a D3DTX Object from a byte array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bytePointerPosition"></param>
        public D3DTX_V5(BinaryReader reader, bool showConsole = false)
        {
            mVersion = reader.ReadInt32();                      //mVersion [4 bytes]
            mSamplerState_BlockSize = reader.ReadInt32();       //mSamplerState Block Size [4 bytes]
            mSamplerState           = new T3SamplerStateBlock() //mSamplerState [4 bytes]
            {
                mData = reader.ReadUInt32()
            };
            mPlatform_BlockSize = reader.ReadInt32();                                   //mPlatform Block Size [4 bytes]
            mPlatform           = EnumPlatformType.GetPlatformType(reader.ReadInt32()); //mPlatform [4 bytes]
            mName_BlockSize     = reader.ReadInt32();                                   //mName Block Size [4 bytes] //mName block size (size + string len)
            mName = ByteFunctions.ReadString(reader);                                   //mName [x bytes]
            mImportName_BlockSize = reader.ReadInt32();                                 //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
            mImportName           = ByteFunctions.ReadString(reader);                   //mImportName [x bytes] (this is always 0)
            mImportScale          = reader.ReadSingle();                                //mImportScale [4 bytes]
            Unknown0   = reader.ReadInt32();                                            //Unknown 0 [4 bytes] always zero (tool props byte structure size?)
            mToolProps = new ToolProps()                                                //mToolProps [1 byte]
            {
                mbHasProps = reader.ReadBoolean()
            };
            mNumMipLevels          = reader.ReadUInt32();                                          //mNumMipLevels [4 bytes]
            mWidth                 = reader.ReadUInt32();                                          //mWidth [4 bytes]
            mHeight                = reader.ReadUInt32();                                          //mHeight [4 bytes]
            mSurfaceFormat         = T3TextureBase_Functions.GetSurfaceFormat(reader.ReadInt32()); //mSurfaceFormat [4 bytes]
            mResourceUsage         = T3TextureBase_Functions.GetResourceUsage(reader.ReadInt32()); //mResourceUsage [4 bytes]
            Unknown1               = reader.ReadInt32();                                           //Unknown 1 [4 bytes]
            Unknown2               = reader.ReadInt32();                                           //Unknown 2 [4 bytes]
            Unknown3               = reader.ReadInt32();                                           //Unknown 3 [4 bytes]
            Unknown4               = reader.ReadInt32();                                           //Unknown 4 [4 bytes]
            mSpecularGlossExponent = reader.ReadSingle();                                          //mSpecularGlossExponent [4 bytes]
            mHDRLightmapScale      = reader.ReadSingle();                                          //mHDRLightmapScale [4 bytes]
            mToonGradientCutoff    = reader.ReadSingle();                                          //mToonGradientCutoff [4 bytes]
            mAlphaMode             = T3Texture_Functions.GetAlphaMode(reader.ReadInt32());         //mAlphaMode [4 bytes]
            mColorMode             = T3Texture_Functions.GetColorMode(reader.ReadInt32());         //mColorMode [4 bytes]
            mUVOffset              = new Vector2()                                                 //mUVOffset [8 bytes]
            {
                x = reader.ReadSingle(),                                                           //[4 bytes]
                y = reader.ReadSingle()                                                            //[4 bytes]
            };
            mUVScale = new Vector2()                                                               //mUVScale [8 bytes]
            {
                x = reader.ReadSingle(),                                                           //[4 bytes]
                y = reader.ReadSingle()                                                            //[4 bytes]
            };

            //--------------------------mToonRegions--------------------------
            mToonRegions_ArrayCapacity = reader.ReadUInt32(); //mToonRegions DCArray Capacity [4 bytes]
            mToonRegions_ArrayLength   = reader.ReadInt32();  //mToonRegions DCArray Length [4 bytes]
            mToonRegions = new T3ToonGradientRegion[mToonRegions_ArrayLength];

            for (int i = 0; i < mToonRegions_ArrayLength; i++)
            {
                mToonRegions[i] = new T3ToonGradientRegion()
                {
                    mColor = new Color()
                    {
                        r = reader.ReadSingle(), //[4 bytes]
                        g = reader.ReadSingle(), //[4 bytes]
                        b = reader.ReadSingle(), //[4 bytes]
                        a = reader.ReadSingle()  //[4 bytes]
                    },

                    mSize = reader.ReadSingle() //[4 bytes]
                };
            }

            //--------------------------StreamHeader--------------------------
            mStreamHeader = new StreamHeader()
            {
                mRegionCount   = reader.ReadInt32(), //[4 bytes]
                mAuxDataCount  = reader.ReadInt32(), //[4 bytes]
                mTotalDataSize = reader.ReadInt32()  //[4 bytes]
            };

            //--------------------------mRegionHeaders--------------------------
            mRegionHeaders = new RegionStreamHeader[mStreamHeader.mRegionCount];
            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                mRegionHeaders[i] = new RegionStreamHeader()
                {
                    mFaceIndex = reader.ReadInt32(),  //[4 bytes]
                    mMipIndex  = reader.ReadInt32(),  //[4 bytes]
                    mMipCount  = reader.ReadInt32(),  //[4 bytes]
                    mDataSize  = reader.ReadUInt32(), //[4 bytes]
                    mPitch     = reader.ReadInt32(),  //[4 bytes]
                };
            }
            //-----------------------------------------D3DTX HEADER END-----------------------------------------
            //--------------------------STORING D3DTX IMAGE DATA--------------------------
            mPixelData = new List <byte[]>();

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                int    dataSize  = (int)mRegionHeaders[i].mDataSize;
                byte[] imageData = reader.ReadBytes(dataSize);

                mPixelData.Add(imageData);
            }

            if (showConsole)
            {
                PrintConsole();
            }
        }
        /// <summary>
        /// Deserializes a D3DTX Object from a byte array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="bytePointerPosition"></param>
        public D3DTX_V7(BinaryReader reader, bool showConsole = false)
        {
            mVersion = reader.ReadInt32();                      //mVersion [4 bytes]
            mSamplerState_BlockSize = reader.ReadInt32();       //mSamplerState Block Size [4 bytes]
            mSamplerState           = new T3SamplerStateBlock() //mSamplerState [4 bytes]
            {
                mData = reader.ReadUInt32()
            };
            mPlatform_BlockSize = reader.ReadInt32();                                   //mPlatform Block Size [4 bytes]
            mPlatform           = EnumPlatformType.GetPlatformType(reader.ReadInt32()); //mPlatform [4 bytes]
            mName_BlockSize     = reader.ReadInt32();                                   //mName Block Size [4 bytes] //mName block size (size + string len)
            mName = ByteFunctions.ReadString(reader);                                   //mName [x bytes]
            mImportName_BlockSize = reader.ReadInt32();                                 //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
            mImportName           = ByteFunctions.ReadString(reader);                   //mImportName [x bytes] (this is always 0)
            mImportScale          = reader.ReadSingle();                                //mImportScale [4 bytes]
            mToolProps            = new ToolProps()                                     //mToolProps [1 byte]
            {
                mbHasProps = reader.ReadBoolean()
            };
            mNumMipLevels = reader.ReadUInt32();                                                     //mNumMipLevels [4 bytes]
            mWidth        = reader.ReadUInt32();                                                     //mWidth [4 bytes]
            mHeight       = reader.ReadUInt32();                                                     //mHeight [4 bytes]

            mSurfaceFormat      = T3TextureBase_Functions.GetSurfaceFormat(reader.ReadInt32());      //mSurfaceFormat [4 bytes]
            mTextureLayout      = T3TextureBase_Functions.GetTextureLayout(reader.ReadInt32());      //mTextureLayout [4 bytes]
            mSurfaceGamma       = T3TextureBase_Functions.GetSurfaceGamma(reader.ReadInt32());       //mSurfaceGamma [4 bytes]
            mSurfaceMultisample = T3TextureBase_Functions.GetSurfaceMultisample(reader.ReadInt32()); //mSurfaceMultisample [4 bytes]
            mResourceUsage      = T3TextureBase_Functions.GetResourceUsage(reader.ReadInt32());      //mResourceUsage [4 bytes]
            mType        = T3Texture_Functions.GetTextureType(reader.ReadInt32());                   //mType [4 bytes]
            mSwizzleSize = reader.ReadInt32();                                                       //mSwizzleSize [4 bytes]
            mSwizzle     = new RenderSwizzleParams()                                                 //mSwizzle [4 bytes]
            {
                mSwizzle1 = (char)reader.ReadByte(),
                mSwizzle2 = (char)reader.ReadByte(),
                mSwizzle3 = (char)reader.ReadByte(),
                mSwizzle4 = (char)reader.ReadByte()
            };
            mNormalMapFormat    = reader.ReadInt32();                                   //mNormalMapFormat [4 bytes]
            mHDRLightmapScale   = reader.ReadSingle();                                  //mHDRLightmapScale [4 bytes]
            mToonGradientCutoff = reader.ReadSingle();                                  //mToonGradientCutoff [4 bytes]
            mAlphaMode          = T3Texture_Functions.GetAlphaMode(reader.ReadInt32()); //mAlphaMode [4 bytes]
            mColorMode          = T3Texture_Functions.GetColorMode(reader.ReadInt32()); //mColorMode [4 bytes]
            mUVOffset           = new Vector2()                                         //mUVOffset [8 bytes]
            {
                x = reader.ReadSingle(),                                                //[4 bytes]
                y = reader.ReadSingle()                                                 //[4 bytes]
            };
            mUVScale = new Vector2()                                                    //mUVScale [8 bytes]
            {
                x = reader.ReadSingle(),                                                //[4 bytes]
                y = reader.ReadSingle()                                                 //[4 bytes]
            };

            //--------------------------mArrayFrameNames--------------------------
            mArrayFrameNames_ArrayCapacity = reader.ReadUInt32(); //mArrayFrameNames DCArray Capacity [4 bytes]
            mArrayFrameNames_ArrayLength   = reader.ReadInt32();  //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0
            mArrayFrameNames = new List <Symbol>();
            for (int i = 0; i < mArrayFrameNames_ArrayLength; i++)
            {
                Symbol newSymbol = new Symbol()
                {
                    mCrc64 = reader.ReadUInt64()
                };

                mArrayFrameNames.Add(newSymbol);
            }

            //--------------------------mToonRegions--------------------------
            mToonRegions_ArrayCapacity = reader.ReadUInt32(); //mToonRegions DCArray Capacity [4 bytes]
            mToonRegions_ArrayLength   = reader.ReadInt32();  //mToonRegions DCArray Length [4 bytes]
            mToonRegions = new T3ToonGradientRegion[mToonRegions_ArrayLength];

            for (int i = 0; i < mToonRegions_ArrayLength; i++)
            {
                mToonRegions[i] = new T3ToonGradientRegion()
                {
                    mColor = new Color()
                    {
                        r = reader.ReadSingle(), //[4 bytes]
                        g = reader.ReadSingle(), //[4 bytes]
                        b = reader.ReadSingle(), //[4 bytes]
                        a = reader.ReadSingle()  //[4 bytes]
                    },

                    mSize = reader.ReadSingle() //[4 bytes]
                };
            }

            //--------------------------StreamHeader--------------------------
            mStreamHeader = new StreamHeader()
            {
                mRegionCount   = reader.ReadInt32(), //[4 bytes]
                mAuxDataCount  = reader.ReadInt32(), //[4 bytes]
                mTotalDataSize = reader.ReadInt32()  //[4 bytes]
            };

            //--------------------------mRegionHeaders--------------------------
            mRegionHeaders = new RegionStreamHeader[mStreamHeader.mRegionCount];
            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                mRegionHeaders[i] = new RegionStreamHeader()
                {
                    mFaceIndex  = reader.ReadInt32(),  //[4 bytes]
                    mMipIndex   = reader.ReadInt32(),  //[4 bytes]
                    mMipCount   = reader.ReadInt32(),  //[4 bytes]
                    mDataSize   = reader.ReadUInt32(), //[4 bytes]
                    mPitch      = reader.ReadInt32(),  //[4 bytes]
                    mSlicePitch = reader.ReadInt32()   //[4 bytes]
                };
            }
            //-----------------------------------------D3DTX HEADER END-----------------------------------------
            //--------------------------STORING D3DTX IMAGE DATA--------------------------
            mPixelData = new List <byte[]>();

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                int    dataSize  = (int)mRegionHeaders[i].mDataSize;
                byte[] imageData = reader.ReadBytes(dataSize);

                mPixelData.Add(imageData);
            }

            if (showConsole)
            {
                PrintConsole();
            }
        }
Ejemplo n.º 26
0
        public void WriteBinaryData(BinaryWriter writer)
        {
            writer.Write(mVersion);                         //mVersion [4 bytes]
            writer.Write(mSamplerState_BlockSize);          //mSamplerState Block Size [4 bytes]
            writer.Write(mSamplerState.mData);              //mSamplerState mData [4 bytes]
            writer.Write(mPlatform_BlockSize);              //mPlatform Block Size [4 bytes]
            writer.Write((int)mPlatform);                   //mPlatform [4 bytes]
            writer.Write(mName_BlockSize);                  //mName Block Size [4 bytes] //mName block size (size + string len)
            ByteFunctions.WriteString(writer, mName);       //mName [x bytes]
            writer.Write(mImportName_BlockSize);            //mImportName Block Size [4 bytes] //mImportName block size (size + string len)
            ByteFunctions.WriteString(writer, mImportName); //mImportName [x bytes] (this is always 0)
            writer.Write(mImportScale);                     //mImportScale [4 bytes]
            //writer.Write(mToolProps.mbHasProps); //mToolProps mbHasProps [1 byte]
            writer.Write('0');
            writer.Write(mNumMipLevels);                  //mNumMipLevels [4 bytes]
            writer.Write(mWidth);                         //mWidth [4 bytes]
            writer.Write(mHeight);                        //mHeight [4 bytes]
            writer.Write(mDepth);                         //mDepth [4 bytes]
            writer.Write(mArraySize);                     //mArraySize [4 bytes]
            writer.Write((int)mSurfaceFormat);            //mSurfaceFormat [4 bytes]
            writer.Write((int)mTextureLayout);            //mTextureLayout [4 bytes]
            writer.Write((int)mSurfaceGamma);             //mSurfaceGamma [4 bytes]
            writer.Write((int)mSurfaceMultisample);       //mSurfaceMultisample [4 bytes]
            writer.Write((int)mResourceUsage);            //mResourceUsage [4 bytes]
            writer.Write((int)mType);                     //mType [4 bytes]
            writer.Write(mSwizzleSize);                   //mSwizzleSize [4 bytes]
            writer.Write(mSwizzle.mSwizzle1);             //mSwizzle A [1 byte]
            writer.Write(mSwizzle.mSwizzle1);             //mSwizzle B [1 byte]
            writer.Write(mSwizzle.mSwizzle1);             //mSwizzle C [1 byte]
            writer.Write(mSwizzle.mSwizzle1);             //mSwizzle D [1 byte]
            writer.Write(mSpecularGlossExponent);         //mSpecularGlossExponent [4 bytes]
            writer.Write(mHDRLightmapScale);              //mHDRLightmapScale [4 bytes]
            writer.Write(mToonGradientCutoff);            //mToonGradientCutoff [4 bytes]
            writer.Write((int)mAlphaMode);                //mAlphaMode [4 bytes]
            writer.Write((int)mColorMode);                //mColorMode [4 bytes]
            writer.Write(mUVOffset.x);                    //mUVOffset X [4 bytes]
            writer.Write(mUVOffset.y);                    //mUVOffset Y [4 bytes]
            writer.Write(mUVScale.x);                     //mUVScale X [4 bytes]
            writer.Write(mUVScale.y);                     //mUVScale Y [4 bytes]

            writer.Write(mArrayFrameNames_ArrayCapacity); //mArrayFrameNames DCArray Capacity [4 bytes]
            writer.Write(mArrayFrameNames_ArrayLength);   //mArrayFrameNames DCArray Length [4 bytes] //ADD 1 BECAUSE COUNTING STARTS AT 0
            for (int i = 0; i < mArrayFrameNames_ArrayLength; i++)
            {
                writer.Write(mArrayFrameNames[i].mCrc64); //Symbol [8 bytes]
            }

            writer.Write(mToonRegions_ArrayCapacity); //mToonRegions DCArray Capacity [4 bytes]
            writer.Write(mToonRegions_ArrayLength);   //mToonRegions DCArray Length [4 bytes]
            for (int i = 0; i < mToonRegions_ArrayLength; i++)
            {
                writer.Write(mToonRegions[i].mColor.r); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.g); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.b); //[4 bytes]
                writer.Write(mToonRegions[i].mColor.a); //[4 bytes]
                writer.Write(mToonRegions[i].mSize);    //[4 bytes]
            }

            writer.Write(mStreamHeader.mRegionCount);   //mRegionCount [4 bytes]
            writer.Write(mStreamHeader.mAuxDataCount);  //mAuxDataCount [4 bytes]
            writer.Write(mStreamHeader.mTotalDataSize); //mTotalDataSize [4 bytes]

            for (int i = 0; i < mStreamHeader.mRegionCount; i++)
            {
                writer.Write(mRegionHeaders[i].mFaceIndex);  //[4 bytes]
                writer.Write(mRegionHeaders[i].mMipIndex);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mMipCount);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mDataSize);   //[4 bytes]
                writer.Write(mRegionHeaders[i].mPitch);      //[4 bytes]
                writer.Write(mRegionHeaders[i].mSlicePitch); //[4 bytes]
            }

            for (int i = 0; i < mPixelData.Count; i++)
            {
                writer.Write(mPixelData[i]);
            }
        }
Ejemplo n.º 27
0
        public Connection ConnectPlc(ConnectionConfig config)
        {
            //eine eindeutige connection id erzeugen
            //in der connection eine liste der pdus pflegen, auf welche noch gewartet wird.
            //für die pdu welche asynchron kommt nummer 0 verwenden!

            S7OexchangeBlock fdr = new S7OexchangeBlock();
            S7OexchangeBlock rec = new S7OexchangeBlock();
            int len = Marshal.SizeOf(fdr);

            byte[]   buffer = new byte[len];
            IntPtr   ptr;
            GCHandle handle;

            Connection retVal;


            while (ConnectionsList.ContainsKey(connNr))
            {
                connNr++;
                if (connNr >= ushort.MaxValue)
                {
                    connNr = 1;
                }
            }
            retVal = new Connection(this, config, 0);
            retVal.ConnectionNumber = connNr;
            ConnectionsList.Add(connNr, retVal);

            //Todo:
            //Im Feld fdr.user für jede Connection einen eigenen Wert verwenden, so das bei empfangen Daten auch
            //Festgestellt werden kann für welche Connection die sind.
            //Dann muss eine Liste geführt werden, in der die IDs und die zugehörige Connection gespeichert ist.
            //Wenn dann auf der ID was empfangen wird, wird das an die Connection weitergeleitet!

            if (!config.ConnectionToEthernet)
            {
                #region Telegramm 1
                fdr.subsystem    = 0x22;
                fdr.response     = 0xFF;
                fdr.user         = connNr;//0xFF;
                fdr.seg_length_1 = 0x80;
                fdr.priority     = 1;
                fdr.application_block_service = (ushort)service_code.fdl_life_list_create_remote;

                SendData(fdr);
                rec = RecieveData(connNr);
                #endregion

                #region Telegramm 2
                fdr.seg_length_1 = 0xF2;
                fdr.application_block_service = (ushort)service_code.fdl_read_value;

                SendData(fdr);
                rec = RecieveData(connNr);
                #endregion
            }

            #region Telegramm 3 (Ethernet 1)

            fdr           = new S7OexchangeBlock();
            fdr.user      = connNr;
            fdr.response  = 255;
            fdr.subsystem = 0x40;
            SendData(fdr);
            rec = RecieveData(connNr);

            retVal.application_block_opcode    = rec.application_block_opcode;
            retVal.application_block_subsystem = rec.application_block_subsystem;
            #endregion

            #region Telegramm 4 (Ethernet 2)

            fdr = new S7OexchangeBlock();

            fdr.user                     = connNr;// 111;
            fdr.subsystem                = 64;
            fdr.opcode                   = 1;
            fdr.response                 = 255;
            fdr.fill_length_1            = 126;
            fdr.seg_length_1             = 126;
            fdr.application_block_opcode = retVal.application_block_opcode;
            fdr.application_block_ssap   = 2;
            fdr.application_block_remote_address_station = 114;
            fdr.application_block_subsystem = retVal.application_block_subsystem; //When this is One it is a MPI Connection, zero means TCP Connection!
            UserDataConnectionConfig ud_cfg = new UserDataConnectionConfig(true);
            ud_cfg.rack_slot       = (byte)(config.Slot + config.Rack * 32);
            ud_cfg.connection_type = (byte)config.ConnectionType;
            if (config.ConnectionToEthernet)
            {
                ud_cfg.destination_1 = config.IPAddress.GetAddressBytes()[0];
                ud_cfg.destination_2 = config.IPAddress.GetAddressBytes()[1];
                ud_cfg.destination_3 = config.IPAddress.GetAddressBytes()[2];
                ud_cfg.destination_4 = config.IPAddress.GetAddressBytes()[3];
            }
            else
            {
                ud_cfg.destination_1 = (byte)config.MPIAddress;
            }

            if (config.Routing)
            {
                ud_cfg.routing_enabled       = 0x01;
                ud_cfg.rack_slot             = (byte)(config.RoutingSlot + config.RoutingRack * 32);
                ud_cfg.size_of_subnet        = 0x06;
                ud_cfg.routing_destination_1 = (byte)((config.RoutingSubnet1 >> 8) & 0xFF);
                ud_cfg.routing_destination_2 = (byte)((config.RoutingSubnet1) & 0xFF);
                ud_cfg.routing_destination_3 = (byte)((config.RoutingSubnet2 >> 8) & 0xFF);
                ud_cfg.routing_destination_4 = (byte)((config.RoutingSubnet2) & 0xFF);

                if (!config.RoutingToEthernet)
                {
                    ud_cfg.size_of_routing_destination = 0x01;
                    ud_cfg.routing_destination_1       = (byte)config.RoutingMPIAddres;
                    ud_cfg.size_to_end = 0x09;
                }
                else
                {
                    ud_cfg.size_of_routing_destination = 0x04;
                    ud_cfg.routing_destination_1       = config.RoutingIPAddress.GetAddressBytes()[0];
                    ud_cfg.routing_destination_2       = config.RoutingIPAddress.GetAddressBytes()[1];
                    ud_cfg.routing_destination_3       = config.RoutingIPAddress.GetAddressBytes()[2];
                    ud_cfg.routing_destination_4       = config.RoutingIPAddress.GetAddressBytes()[3];
                    ud_cfg.size_to_end = 0x0C;
                }
            }
            ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ud_cfg));
            Marshal.StructureToPtr(ud_cfg, ptr, true);
            fdr.user_data_1 = new byte[260];
            Marshal.Copy(ptr, fdr.user_data_1, 0, Marshal.SizeOf(ud_cfg));
            Marshal.FreeHGlobal(ptr);
            SendData(fdr);
            rec = RecieveData(connNr);
            if (rec.response != 0x01)
            {
                throw new S7OnlineException("S7Online: Error Connection to PLC");
            }

            #endregion

            #region Telegramm 5 (Ethernet 3) (this Telegramm sends a PDU)
            //5th Telegramm / TCP(3rd)
            Pdu pdu = new Pdu(1);
            pdu.Param.AddRange(new byte[] { 0xF0, 0, 0, 1, 0, 1, 3, 0xc0 });
            SendPdu(pdu, retVal);
            Pdu recPdu = RecievePdu(connNr);
            #endregion

            #region Telegramm 6 (Ethernet 4) (get PDU size)
            fdr                             = new S7OexchangeBlock();
            fdr.user                        = connNr;//0;
            fdr.subsystem                   = 64;
            fdr.opcode                      = 7;
            fdr.response                    = 16642;
            fdr.seg_length_1                = 480;
            fdr.application_block_opcode    = retVal.application_block_opcode;
            fdr.application_block_subsystem = retVal.application_block_subsystem;
            SendData(fdr);
            recPdu         = RecievePdu(connNr);
            retVal.PduSize = ByteFunctions.getU16from(recPdu.Param.ToArray(), 6);
            #endregion

            retVal.ConnectionEstablished = true;

            return(retVal);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Parses the data from a DDS byte array. (Can also read just the header only)
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="headerOnly"></param>
        private void GetData(byte[] fileData, bool headerOnly)
        {
            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
            Console.WriteLine("Total Source Texture Byte Size = {0}", fileData.Length);

            //which byte offset we are on for the source texture (will be changed as we go through the file)
            byte[] headerBytes = ByteFunctions.AllocateBytes(124, fileData, 4); //skip past the 'DDS '

            //this will automatically read all of the byte data in the header
            header = DDS_Functions.GetHeaderFromBytes(headerBytes);

            ConsoleFunctions.SetConsoleColor(ConsoleColor.Black, ConsoleColor.White);
            Console.WriteLine("DDS Height = {0}", header.dwHeight);
            Console.WriteLine("DDS Width = {0}", header.dwWidth);
            Console.WriteLine("DDS Mip Map Count = {0}", header.dwMipMapCount);
            Console.WriteLine("DDS Compression = {0}", header.ddspf.dwFourCC);

            if (headerOnly)
            {
                return;
            }

            //--------------------------EXTRACT DDS TEXTURE DATA--------------------------
            //calculate dds header length (we add 4 because we skipped the 4 bytes which contain the ddsPrefix, it isn't necessary to parse this data)
            uint ddsHeaderLength = 4 + header.dwSize;

            //calculate the length of just the dds texture data
            uint ddsTextureDataLength = (uint)sourceFileData.Length - ddsHeaderLength;

            //allocate a byte array of dds texture length
            byte[] ddsTextureData = new byte[ddsTextureDataLength];

            //copy the data from the source byte array past the header (so we are only getting texture data)
            Array.Copy(sourceFileData, ddsHeaderLength, ddsTextureData, 0, ddsTextureData.Length);

            //if there are no mip maps
            if (header.dwMipMapCount <= 1)
            {
                textureData = new();
                textureData.Add(ddsTextureData);
                Console.WriteLine("DDS Texture Byte Size = {0}", textureData[0].Length);
            }
            else //if there are mip maps
            {
                //get mip resolutions
                //calculated mip resolutions [Pixel Value, Width or Height (0 or 1)]
                mipMapResolutions = DDS_Functions.DDS_CalculateMipResolutions(header.dwMipMapCount, header.dwWidth, header.dwHeight);

                //get byte sizes
                uint[] byteSizes = DDS_Functions.DDS_GetImageByteSizes(mipMapResolutions, DDS_Functions.DDS_CompressionBool(header));

                textureData = new();
                int test   = ddsTextureData.Length;
                int offset = 0;

                for (int i = 0; i < byteSizes.Length; i++)
                {
                    byte[] temp = new byte[byteSizes[i]];

                    //issue length
                    Array.Copy(ddsTextureData, offset, temp, 0, temp.Length);

                    offset += temp.Length - 1;

                    textureData.Add(temp);

                    test -= (int)byteSizes[i];
                }
            }
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Writes a D3DTX into a DDS file on the disk.
        /// </summary>
        /// <param name="d3dtx"></param>
        /// <param name="destinationPath"></param>
        public void Write_D3DTX_AsDDS(D3DTX_Master d3dtx, string destinationPath)
        {
            byte[] finalData = new byte[0];

            //turn our header data into bytes to be written into a file
            byte[] dds_header = ByteFunctions.Combine(ByteFunctions.GetBytes("DDS "), DDS_Functions.GetHeaderBytes(header));

            //copy the dds header to the file
            finalData = ByteFunctions.Combine(finalData, dds_header);

            if (d3dtx.d3dtx4 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx4.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx4.mPixelData[i]);
                }
            }
            else if (d3dtx.d3dtx5 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx5.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx5.mPixelData[i]);
                }
            }
            else if (d3dtx.d3dtx6 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx6.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx6.mPixelData[i]);
                }
            }
            else if (d3dtx.d3dtx7 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx7.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx7.mPixelData[i]);
                }
            }
            else if (d3dtx.d3dtx8 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx8.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx8.mPixelData[i]);
                }
            }
            else if (d3dtx.d3dtx9 != null)
            {
                //copy the images
                for (int i = d3dtx.d3dtx9.mPixelData.Count - 1; i >= 0; i--)
                {
                    finalData = ByteFunctions.Combine(finalData, d3dtx.d3dtx9.mPixelData[i]);
                }
            }

            //write the file to the disk
            File.WriteAllBytes(destinationPath, finalData);
        }
Ejemplo n.º 30
0
        public void ConvertStreamToByteWithNullValue()
        {
            var result = ByteFunctions.ConverteStreamToByteArray(null);

            Assert.NotNull(result);
        }