Exemple #1
0
        public void ExportTextureDictionary(string fileName, CheckState RW3)
        {
            ReadFileMethods.treatStuffAsByteArray = true;

            List <TextureNative_0015> textNativeList = new List <TextureNative_0015>();

            int fileVersion = 0;

            foreach (Section_AHDR AHDR in GetAHDRsOfType(AssetType.RWTX))
            {
                if ((RW3 == CheckState.Indeterminate) || ((RW3 == CheckState.Checked) && AHDR.ADBG.assetName.Contains(".RW3")) || ((RW3 == CheckState.Unchecked) && !AHDR.ADBG.assetName.Contains(".RW3")))
                {
                    try
                    {
                        foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(AHDR.data))
                        {
                            if (rw is TextureDictionary_0016 td)
                            {
                                foreach (TextureNative_0015 tn in td.textureNativeList)
                                {
                                    fileVersion = tn.renderWareVersion;
                                    tn.textureNativeStruct.textureName = AHDR.ADBG.assetName.Replace(".RW3", "");
                                    textNativeList.Add(tn);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show($"Unable to add RWTX asset {GetFromAssetID(AHDR.assetID).ToString()} to TXD archive: {ex.Message}");
                    }
                }
            }

            TextureDictionary_0016 rws = new TextureDictionary_0016()
            {
                textureDictionaryStruct = new TextureDictionaryStruct_0001()
                {
                    textureCount = (short)textNativeList.Count(),
                    unknown      = 0
                },
                textureNativeList          = textNativeList,
                textureDictionaryExtension = new Extension_0003()
                {
                    extensionSectionList = new List <RWSection>()
                }
            };

            rws.textureNativeList = rws.textureNativeList.OrderBy(f => f.textureNativeStruct.textureName).ToList();

            File.WriteAllBytes(fileName, ReadFileMethods.ExportRenderWareFile(rws, fileVersion));

            ReadFileMethods.treatStuffAsByteArray = false;
        }
Exemple #2
0
        public void ExportTextureDictionary(string fileName, bool RW3)
        {
            ReadFileMethods.treatStuffAsByteArray = true;

            List <TextureNative_0015> textNativeList = new List <TextureNative_0015>();

            int fileVersion = 0;

            foreach (Asset a in assetDictionary.Values)
            {
                if (a is AssetRWTX RWTX)
                {
                    if ((RW3 && RWTX.AHDR.ADBG.assetName.Contains(".RW3")) || (!RW3 && !RWTX.AHDR.ADBG.assetName.Contains(".RW3")))
                    {
                        foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(RWTX.Data))
                        {
                            if (rw is TextureDictionary_0016 td)
                            {
                                foreach (TextureNative_0015 tn in td.textureNativeList)
                                {
                                    fileVersion = tn.renderWareVersion;
                                    tn.textureNativeStruct.textureName = RWTX.AHDR.ADBG.assetName.Replace(".RW3", "");
                                    textNativeList.Add(tn);
                                }
                            }
                        }
                    }
                }
            }

            TextureDictionary_0016 rws = new TextureDictionary_0016()
            {
                textureDictionaryStruct = new TextureDictionaryStruct_0001()
                {
                    textureCount = (short)textNativeList.Count(),
                    unknown      = 0
                },
                textureNativeList          = textNativeList,
                textureDictionaryExtension = new Extension_0003()
                {
                    extensionSectionList = new List <RWSection>()
                }
            };

            rws.textureNativeList = rws.textureNativeList.OrderBy(f => f.textureNativeStruct.textureName).ToList();

            File.WriteAllBytes(fileName, ReadFileMethods.ExportRenderWareFile(rws, fileVersion));

            ReadFileMethods.treatStuffAsByteArray = false;
        }
Exemple #3
0
        public static void ExportSingleTextureToDictionary(string fileName, byte[] data, string textureName)
        {
            ReadFileMethods.treatStuffAsByteArray = true;

            List <TextureNative_0015> textNativeList = new List <TextureNative_0015>();

            int fileVersion = 0;

            foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(data))
            {
                if (rw is TextureDictionary_0016 td)
                {
                    foreach (TextureNative_0015 tn in td.textureNativeList)
                    {
                        fileVersion = tn.renderWareVersion;
                        tn.textureNativeStruct.textureName = textureName;
                        textNativeList.Add(tn);
                    }
                }
            }

            TextureDictionary_0016 rws = new TextureDictionary_0016()
            {
                textureDictionaryStruct = new TextureDictionaryStruct_0001()
                {
                    textureCount = (short)textNativeList.Count(),
                    unknown      = 0
                },
                textureNativeList          = textNativeList,
                textureDictionaryExtension = new Extension_0003()
                {
                    extensionSectionList = new List <RWSection>()
                }
            };

            rws.textureNativeList = rws.textureNativeList.OrderBy(f => f.textureNativeStruct.textureName).ToList();

            File.WriteAllBytes(fileName, ReadFileMethods.ExportRenderWareFile(rws, fileVersion));

            ReadFileMethods.treatStuffAsByteArray = false;
        }
Exemple #4
0
        public static Section_AHDR CreateRWTXFromBitmap(string fileName, bool appendRW3, bool flip, bool mipmaps, bool compress)
        {
            string textureName = Path.GetFileNameWithoutExtension(fileName);

            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(fileName);

            List <byte> bitmapData = new List <byte>(bitmap.Width * bitmap.Height * 4);

            if (flip)
            {
                bitmap.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
            }

            for (int j = 0; j < bitmap.Height; j++)
            {
                for (int i = 0; i < bitmap.Width; i++)
                {
                    bitmapData.Add(bitmap.GetPixel(i, j).B);
                    bitmapData.Add(bitmap.GetPixel(i, j).G);
                    bitmapData.Add(bitmap.GetPixel(i, j).R);
                    bitmapData.Add(bitmap.GetPixel(i, j).A);
                }
            }

            TextureDictionary_0016 td = new TextureDictionary_0016()
            {
                textureDictionaryStruct = new TextureDictionaryStruct_0001()
                {
                    textureCount = 1, unknown = 0
                },
                textureNativeList = new List <TextureNative_0015>()
                {
                    new TextureNative_0015()
                    {
                        textureNativeStruct = new TextureNativeStruct_0001()
                        {
                            textureName       = textureName,
                            alphaName         = "",
                            height            = (short)bitmap.Height,
                            width             = (short)bitmap.Width,
                            mipMapCount       = 1,
                            addressModeU      = TextureAddressMode.TEXTUREADDRESSWRAP,
                            addressModeV      = TextureAddressMode.TEXTUREADDRESSWRAP,
                            filterMode        = TextureFilterMode.FILTERLINEAR,
                            bitDepth          = 32,
                            platformType      = 8,
                            compression       = 0,
                            hasAlpha          = false,
                            rasterFormatFlags = TextureRasterFormat.RASTER_C8888,
                            type    = 4,
                            mipMaps = new MipMapEntry[] { new MipMapEntry(bitmapData.Count, bitmapData.ToArray()) },
                        },
                        textureNativeExtension = new Extension_0003()
                    }
                },
                textureDictionaryExtension = new Extension_0003()
            };

            bitmap.Dispose();

            // created PC txd, now will convert to gamecube.
            if (!Directory.Exists(tempPcTxdsDir))
            {
                Directory.CreateDirectory(tempPcTxdsDir);
            }
            if (!Directory.Exists(tempGcTxdsDir))
            {
                Directory.CreateDirectory(tempGcTxdsDir);
            }

            ExportSingleTextureToDictionary(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(td, currentTextureVersion), textureName);

            PerformTXDConversionExternal(false, compress, mipmaps);

            string assetName = textureName + (appendRW3 ? ".RW3" : "");

            ReadFileMethods.treatStuffAsByteArray = true;

            Section_AHDR AHDR = new Section_AHDR(BKDRHash(assetName), AssetType.RWTX, AHDRFlagsFromAssetType(AssetType.RWTX),
                                                 new Section_ADBG(0, assetName, "", 0), ReadFileMethods.ExportRenderWareFile(ReadFileMethods.ReadRenderWareFile(pathToGcTXD), currentTextureVersion));

            ReadFileMethods.treatStuffAsByteArray = false;

            File.Delete(pathToGcTXD);
            File.Delete(pathToPcTXD);

            return(AHDR);
        }