public void SetVertexColors(Vector4 color, Operation operation)
        {
            RWSection[] sections = ReadFileMethods.ReadRenderWareFile(Data);
            renderWareVersion = sections[0].renderWareVersion;

            foreach (RWSection rws in sections)
                if (rws is Clump_0010 clump)
                    for (int i = 0; i < clump.geometryList.geometryList.Count; i++)
                        if (clump.geometryList.geometryList[i].geometryStruct.vertexColors != null)
                            for (int j = 0; j < clump.geometryList.geometryList[i].geometryStruct.vertexColors.Length; j++)
                            {
                                var oldColor = clump.geometryList.geometryList[i].geometryStruct.vertexColors[j];

                                var newColor = PerformOperationAndClamp(
                                    new Vector4((float)oldColor.R / 255, (float)oldColor.G / 255, (float)oldColor.B / 255, (float)oldColor.A / 255), 
                                    color, operation);

                                clump.geometryList.geometryList[i].geometryStruct.vertexColors[j] = new RenderWareFile.Color(
                                        (byte)(newColor.X * 255),
                                        (byte)(newColor.Y * 255),
                                        (byte)(newColor.Z * 255),
                                        (byte)(newColor.W * 255));
                            }

            Data = ReadFileMethods.ExportRenderWareFile(sections, renderWareVersion);
            Setup(Program.MainForm.renderer);
        }
Beispiel #2
0
        public void SetForRendering(SharpDevice device, RWSection[] rwChunkList, byte[] rwByteArray)
        {
            rwSectionArray = rwChunkList;

            if (rwByteArray == null)
            {
                rwSectionByteArray = ReadFileMethods.ExportRenderWareFile(rwSectionArray, 0x1400FFFF);

                if (rwSectionByteArray.Length > 450 * 1024)
                {
                    System.Windows.Forms.MessageBox.Show(fileName + " is larger than 450 kb. I will still import it for you, but be warned that files too large might make the game crash.");
                }
            }
            else
            {
                rwSectionByteArray = rwByteArray;
            }
            meshList = new List <SharpMesh>();

            vertexListG        = new List <Vector3>();
            triangleList       = new List <Triangle>();
            triangleListOffset = 0;

            foreach (RWSection rwSection in rwSectionArray)
            {
                if (rwSection is World_000B w)
                {
                    vertexAmount   = w.worldStruct.numVertices;
                    triangleAmount = w.worldStruct.numTriangles;

                    foreach (Material_0007 m in w.materialList.materialList)
                    {
                        if (m.texture != null)
                        {
                            MaterialList.Add(m.texture.diffuseTextureName.stringString);
                        }
                        else
                        {
                            MaterialList.Add(DefaultTexture);
                        }
                    }
                    if (w.firstWorldChunk is AtomicSector_0009 a)
                    {
                        AddAtomic(device, a);
                    }
                    else if (w.firstWorldChunk is PlaneSector_000A p)
                    {
                        AddPlane(device, p);
                    }
                }
                else if (rwSection is Clump_0010 c)
                {
                    for (int g = 0; g < c.geometryList.geometryList.Count; g++)
                    {
                        AddGeometry(device, c.geometryList.geometryList[g], CreateMatrix(c.frameList, c.atomicList[g].atomicStruct.frameIndex));
                    }
                }
            }
        }
Beispiel #3
0
        private bool PerformTextureConversion()
        {
            lock (locker)
            {
                Dictionary <uint, Section_AHDR> dataDict = new Dictionary <uint, Section_AHDR>();

                if (!Directory.Exists(tempPcTxdsDir))
                {
                    Directory.CreateDirectory(tempPcTxdsDir);
                }
                if (!Directory.Exists(tempGcTxdsDir))
                {
                    Directory.CreateDirectory(tempGcTxdsDir);
                }

                try
                {
                    ExportTextureDictionary(pathToPcTXD, CheckState.Checked);
                    PerformTXDConversionExternal(platform, false);
                    foreach (var AHDR in GetAssetsFromTextureDictionary(pathToGcTXD, true))
                    {
                        dataDict.Add(AHDR.assetID, AHDR);
                    }

                    ExportTextureDictionary(pathToPcTXD, CheckState.Unchecked);
                    PerformTXDConversionExternal(platform, false);
                    foreach (var AHDR in GetAssetsFromTextureDictionary(pathToGcTXD, false))
                    {
                        dataDict.Add(AHDR.assetID, AHDR);
                    }
                }
                catch
                {
                    File.Delete(pathToGcTXD);
                    File.Delete(pathToPcTXD);
                    return(false);
                }

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

                ReadFileMethods.treatStuffAsByteArray = true;

                foreach (var rwtx in assetDictionary.Values.OfType <AssetRWTX>())
                {
                    rwtx.Data =
                        ReadFileMethods.ExportRenderWareFile(
                            ReadFileMethods.ReadRenderWareFile(
                                dataDict[rwtx.assetID].data),
                            Models.BSP_IO_Shared.modelRenderWareVersion(game));
                    rwtx.game       = game;
                    rwtx.endianness = platform.Endianness();
                }

                ReadFileMethods.treatStuffAsByteArray = false;
                return(true);
            }
        }
Beispiel #4
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;
        }
Beispiel #5
0
        public static List <Section_AHDR> GetAssets(out bool success, out bool overwrite)
        {
            ImportTextures a = new ImportTextures();

            if (a.ShowDialog() == DialogResult.OK)
            {
                ReadFileMethods.treatStuffAsByteArray = true;

                List <Section_AHDR> AHDRs = new List <Section_AHDR>();

                for (int i = 0; i < a.filePaths.Count; i++)
                {
                    if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".rwtex"))
                    {
                        byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                        {
                            textureDictionaryStruct = new TextureDictionaryStruct_0001()
                            {
                                textureCount = 1, unknown = 0
                            },
                            textureNativeList = new List <TextureNative_0015>()
                            {
                                new TextureNative_0015().FromBytes(File.ReadAllBytes(a.filePaths[i]))
                            },
                            textureDictionaryExtension = new Extension_0003()
                        }, ArchiveEditorFunctions.currentTextureVersion);

                        string assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]) + (a.checkBoxRW3.Checked ? ".RW3" : "");

                        Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0);
                        Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(assetName), AssetType.RWTX, ArchiveEditorFunctions.AHDRFlagsFromAssetType(AssetType.RWTX), ADBG, data);

                        AHDRs.Add(AHDR);
                    }
                    else
                    {
                        AHDRs.Add(ArchiveEditorFunctions.CreateRWTXFromBitmap(a.filePaths[i], a.checkBoxRW3.Checked, a.checkBoxFlipTextures.Checked, a.checkBoxMipmaps.Checked, a.checkBoxCompress.Checked));
                    }
                }

                ReadFileMethods.treatStuffAsByteArray = false;

                success   = true;
                overwrite = a.checkBoxOverwrite.Checked;
                return(AHDRs);
            }
            else
            {
                success   = false;
                overwrite = false;
                return(null);
            }
        }
Beispiel #6
0
        public List <Section_AHDR> GetAssetsFromTextureDictionary(string fileName, bool RW3)
        {
            ReadFileMethods.treatStuffAsByteArray = true;

            List <Section_AHDR> AHDRs = new List <Section_AHDR>();

            foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(fileName))
            {
                if (rw is TextureDictionary_0016 td)
                {
                    // For each texture in the dictionary...
                    foreach (TextureNative_0015 tn in td.textureNativeList)
                    {
                        string textureName = tn.textureNativeStruct.textureName;
                        if (RW3 && !textureName.Contains(".RW3"))
                        {
                            textureName += ".RW3";
                        }

                        // Create a new dictionary that has only that texture.
                        byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                        {
                            textureDictionaryStruct = new TextureDictionaryStruct_0001()
                            {
                                textureCount = 1, unknown = 0
                            },
                            textureDictionaryExtension = new Extension_0003(),
                            textureNativeList          = new List <TextureNative_0015>()
                            {
                                tn
                            }
                        }, tn.renderWareVersion);

                        if (game == Game.Scooby)
                        {
                            FixTextureForScooby(ref data);
                        }

                        // And add the new dictionary as an asset.
                        Section_ADBG ADBG = new Section_ADBG(0, textureName, "", 0);
                        Section_AHDR AHDR = new Section_AHDR(BKDRHash(textureName), AssetType.RWTX, AHDRFlags.SOURCE_VIRTUAL | AHDRFlags.READ_TRANSFORM, ADBG, data);


                        AHDRs.Add(AHDR);
                    }
                }
            }
            ReadFileMethods.treatStuffAsByteArray = false;

            return(AHDRs);
        }
Beispiel #7
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;
        }
Beispiel #8
0
        private void buttonImport_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog a = new OpenFileDialog()
            {
                Filter = asset.AHDR.assetType == HipHopFile.AssetType.BSP ?
                         "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*" :
                         "All supported types|*.dae;*.obj;*.dff|DAE Files|*.dae|OBJ Files|*.obj|DFF Files|*.dff|All files|*.*"
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                archive.UnsavedChanges = true;

                string i = a.FileName;

                ModelConverterData m;

                if (Path.GetExtension(i).ToLower() == ".obj")
                {
                    m = ReadOBJFile(i);
                }
                else if (Path.GetExtension(i).ToLower() == ".dae")
                {
                    m = ConvertDataFromDAEObject(ReadDAEFile(i), false);
                }
                else
                {
                    asset.GetRenderWareModelFile().Dispose();
                    asset.Data = File.ReadAllBytes(i);
                    asset.Setup(Program.MainForm.renderer);
                    return;
                }

                RWSection[] rws;

                if (asset.AHDR.assetType == HipHopFile.AssetType.BSP)
                {
                    rws = CreateBSPFile(m, true);
                }
                else
                {
                    rws = CreateDFFFile(m, true);
                }

                asset.GetRenderWareModelFile().Dispose();
                asset.Data = ReadFileMethods.ExportRenderWareFile(rws, currentRenderWareVersion);
                asset.Setup(Program.MainForm.renderer);
            }
        }
Beispiel #9
0
        public static void ExportSingleTextureToRWTEX(byte[] data, string fileName)
        {
            ReadFileMethods.treatStuffAsByteArray = true;

            foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(data))
            {
                if (rw is TextureDictionary_0016 td)
                {
                    foreach (TextureNative_0015 tn in td.textureNativeList)
                    {
                        File.WriteAllBytes(fileName, ReadFileMethods.ExportRenderWareFile(tn, tn.renderWareVersion));
                    }
                }
            }

            ReadFileMethods.treatStuffAsByteArray = false;
        }
        private void buttonImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog a = new OpenFileDialog()
            {
                Filter = ImportTextures.filter
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                archive.UnsavedChanges = true;

                string i = a.FileName;

                if (Path.GetExtension(i).ToLower().Equals(".rwtex"))
                {
                    asset.Data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                    {
                        textureDictionaryStruct = new TextureDictionaryStruct_0001()
                        {
                            textureCount = 1, unknown = 0
                        },
                        textureNativeList = new List <TextureNative_0015>()
                        {
                            new TextureNative_0015().FromBytes(File.ReadAllBytes(i))
                        },
                        textureDictionaryExtension = new Extension_0003()
                    }, currentTextureVersion(archive.game));
                }
                else
                {
                    asset.Data = CreateRWTXFromBitmap(archive.game, archive.platform, i, false, checkBoxFlipTextures.Checked,
                                                      checkBoxMipmaps.Checked, checkBoxCompress.Checked, checkBoxTransFix.Checked).data;
                }

                if (asset.game == HipHopFile.Game.Scooby)
                {
                    byte[] data = asset.Data;
                    FixTextureForScooby(ref data);
                    asset.Data = data;
                }

                RefreshPropertyGrid();
                archive.EnableTextureForDisplay(asset);
            }
        }
Beispiel #11
0
        public Dictionary <string, Bitmap> GetTexturesAsBitmaps(string[] textureNames)
        {
            List <TextureNative_0015> textures = new List <TextureNative_0015>();

            ReadFileMethods.treatStuffAsByteArray = true;

            foreach (string t in textureNames)
            {
                AssetRWTX RWTX;

                uint assetID = BKDRHash(t + ".RW3");
                if (ContainsAsset(assetID))
                {
                    RWTX = (AssetRWTX)GetFromAssetID(assetID);
                }
                else
                {
                    assetID = BKDRHash(t);
                    if (ContainsAsset(assetID))
                    {
                        RWTX = (AssetRWTX)GetFromAssetID(assetID);
                    }
                    else
                    {
                        continue;
                    }
                }

                foreach (TextureNative_0015 texture in ((TextureDictionary_0016)ReadFileMethods.ReadRenderWareFile(RWTX.Data)[0]).textureNativeList)
                {
                    texture.textureNativeStruct.textureName = t;
                    textures.Add(texture);
                }
            }

            return(ExportTXDToBitmap(ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
            {
                textureDictionaryStruct = new TextureDictionaryStruct_0001()
                {
                    textureCount = (short)textures.Count, unknown = 0
                },
                textureNativeList = textures,
                textureDictionaryExtension = new Extension_0003()
            }, currentTextureVersion(game))));
        }
Beispiel #12
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;
        }
        private void ConvertAllAssetTypes(Platform previousPlatform, Game previousGame, out List <uint> unsupported)
        {
            unsupported = new List <uint>();

            foreach (Asset asset in assetDictionary.Values)
            {
                try
                {
                    if (asset is AssetRenderWareModel MODL && !MODL.IsNativeData)
                    {
                        MODL.Data =
                            ReadFileMethods.ExportRenderWareFile(
                                ReadFileMethods.ReadRenderWareFile(asset.Data),
                                Models.BSP_IO_Shared.modelRenderWareVersion(game));
                    }
                    else
                    {
                        asset.AHDR = ConvertAssetType(asset.AHDR, EndianConverter.PlatformEndianness(previousPlatform), EndianConverter.PlatformEndianness(platform), previousGame, game);
                    }

                    asset.SetGamePlatform(game, platform);
                }
Beispiel #14
0
        private void buttonImport_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog a = new OpenFileDialog()
            {
                Filter = ImportTextures.filter
            };

            if (a.ShowDialog() == DialogResult.OK)
            {
                archive.UnsavedChanges = true;

                string i = a.FileName;

                if (Path.GetExtension(i).ToLower().Equals(".rwtex"))
                {
                    asset.Data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                    {
                        textureDictionaryStruct = new TextureDictionaryStruct_0001()
                        {
                            textureCount = 1, unknown = 0
                        },
                        textureNativeList = new List <TextureNative_0015>()
                        {
                            new TextureNative_0015().FromBytes(File.ReadAllBytes(i))
                        },
                        textureDictionaryExtension = new Extension_0003()
                    }, ArchiveEditorFunctions.currentTextureVersion);
                }
                else
                {
                    asset.Data = ArchiveEditorFunctions.CreateRWTXFromBitmap(i, false, false, true, true).data;
                }

                archive.EnableTextureForDisplay(asset);
            }
        }
Beispiel #15
0
        public static (List <Section_AHDR> AHDRs, bool overwrite) GetAssets(Game game, Platform platform)
        {
            ImportTextures a = new ImportTextures();

            if (a.ShowDialog() == DialogResult.OK)
            {
                ReadFileMethods.treatStuffAsByteArray = true;

                List <Section_AHDR> AHDRs = new List <Section_AHDR>();

                List <string> forBitmap = new List <string>();

                for (int i = 0; i < a.filePaths.Count; i++)
                {
                    if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".rwtex"))
                    {
                        byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                        {
                            textureDictionaryStruct = new TextureDictionaryStruct_0001()
                            {
                                textureCount = 1, unknown = 0
                            },
                            textureNativeList = new List <TextureNative_0015>()
                            {
                                new TextureNative_0015().FromBytes(File.ReadAllBytes(a.filePaths[i]))
                            },
                            textureDictionaryExtension = new Extension_0003()
                        }, currentTextureVersion(game));

                        string assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]) + (a.checkBoxRW3.Checked ? ".RW3" : "");

                        Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0);
                        Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(assetName), AssetType.RWTX, ArchiveEditorFunctions.AHDRFlagsFromAssetType(AssetType.RWTX), ADBG, data);

                        AHDRs.Add(AHDR);
                    }
                    else
                    {
                        forBitmap.Add(a.filePaths[i]);
                    }
                }

                AHDRs.AddRange(CreateRWTXsFromBitmaps(game, platform, forBitmap, a.checkBoxRW3.Checked, a.checkBoxFlipTextures.Checked,
                                                      a.checkBoxMipmaps.Checked, a.checkBoxCompress.Checked, a.checkBoxTransFix.Checked));

                ReadFileMethods.treatStuffAsByteArray = false;

                if (game == Game.Scooby)
                {
                    for (int i = 0; i < AHDRs.Count; i++)
                    {
                        byte[] data = AHDRs[i].data;
                        FixTextureForScooby(ref data);
                        AHDRs[i].data = data;
                    }
                }

                return(AHDRs, a.checkBoxOverwrite.Checked);
            }
            return(null, false);
        }
Beispiel #16
0
        public static List <Section_AHDR> GetAssets(out bool success)
        {
            ImportModel a = new ImportModel();

            if (a.ShowDialog() == DialogResult.OK)
            {
                List <Section_AHDR> AHDRs = new List <Section_AHDR>();

                for (int i = 0; i < a.filePaths.Count; i++)
                {
                    ModelConverterData m;

                    if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".obj"))
                    {
                        m = ReadOBJFile(a.filePaths[i]);
                    }
                    else if (Path.GetExtension(a.filePaths[i]).ToLower().Equals(".dae"))
                    {
                        m = ConvertDataFromDAEObject(ReadDAEFile(a.filePaths[i]), false);
                    }
                    else
                    {
                        MessageBox.Show("Unknown file format for " + a.filePaths[i] + ", skipping");
                        continue;
                    }

                    byte[]    data;
                    AssetType assetType;
                    string    assetName = Path.GetFileNameWithoutExtension(a.filePaths[i]); // + ".dff";

                    //switch (a.comboBoxAssetTypes.SelectedIndex)
                    //{
                    //    case 0:
                    //        assetType = AssetType.BSP;
                    //        data = ReadFileMethods.ExportRenderWareFile(CreateBSPFile(m, a.checkBoxFlipUVs.Checked), scoobyRenderWareVersion);
                    //        break;
                    //    case 1:
                    //        assetType = AssetType.MODL; // scooby
                    //        data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), scoobyRenderWareVersion);
                    //        break;
                    //    case 2:
                    //        assetType = AssetType.MODL; // bfbb
                    //        data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), bfbbRenderWareVersion);
                    //        break;
                    //    default:
                    //        assetType = AssetType.MODL; // movie
                    //        data = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), tssmRenderWareVersion);
                    //        break;
                    //}

                    assetType = AssetType.MODL;
                    data      = ReadFileMethods.ExportRenderWareFile(CreateDFFFile(m, a.checkBoxFlipUVs.Checked), currentRenderWareVersion);

                    Section_ADBG ADBG = new Section_ADBG(0, assetName, "", 0);
                    Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(assetName), assetType, ArchiveEditorFunctions.AHDRFlagsFromAssetType(assetType), ADBG, data);

                    AHDRs.Add(AHDR);
                }

                success = true;
                return(AHDRs);
            }
            else
            {
                success = false;
                return(null);
            }
        }
        public void SetForRendering(SharpDevice device, RWSection[] rwChunkList, byte[] rwByteArray)
        {
            rwSectionArray = rwChunkList;

            if (rwByteArray == null)
            {
                rwSectionByteArray = ReadFileMethods.ExportRenderWareFile(rwSectionArray, isShadowCollision ? LevelEditor.BSP_IO_ShadowCollision.shadowRenderWareVersion : LevelEditor.BSP_IO_Heroes.heroesRenderWareVersion);

#if RELEASE
                if (fileSizeCheck && rwSectionByteArray.Length > 450 * 1024)
                {
                    System.Windows.Forms.MessageBox.Show(fileName + " is a very large file. It might crash the game if you don't use TONER mod to enable the game to load bigger files than normally.");
                }
#endif
            }
            else
            {
                rwSectionByteArray = rwByteArray;
            }
            meshList = new List <SharpMesh>();

            vertexListG        = new List <Vector3>();
            triangleList       = new List <Triangle>();
            triangleListOffset = 0;

            foreach (RWSection rwSection in rwSectionArray)
            {
                if (rwSection is World_000B w)
                {
                    vertexAmount   = w.worldStruct.numVertices;
                    triangleAmount = w.worldStruct.numTriangles;

                    foreach (Material_0007 m in w.materialList.materialList)
                    {
                        if (isShadowCollision)
                        {
                            MaterialList.Add(m.materialStruct.color.ToString());
                        }
                        else if (m.texture != null)
                        {
                            MaterialList.Add(m.texture.diffuseTextureName.stringString);
                        }
                        else
                        {
                            MaterialList.Add(DefaultTexture);
                        }
                    }
                    if (w.firstWorldChunk is AtomicSector_0009 a)
                    {
                        AddAtomic(device, a);
                    }
                    else if (w.firstWorldChunk is PlaneSector_000A p)
                    {
                        AddPlane(device, p);
                    }
                }
                else if (rwSection is Clump_0010 c)
                {
                    for (int g = 0; g < c.geometryList.geometryList.Count; g++)
                    {
                        AddGeometry(device, c.geometryList.geometryList[g], CreateMatrix(c.frameList, c.atomicList[g].atomicStruct.frameIndex));
                    }
                }
            }
        }
        private void SetupForModel(AssetRenderWareModel asset)
        {
            AddRow();
            AddRow();
            AddRow();
            AddRow();

            Button buttonSetVertexColors = new Button()
            {
                Dock = DockStyle.Fill, Text = "Set Vertex Colors", AutoSize = true
            };

            buttonSetVertexColors.Click += (object sender, EventArgs e) =>
            {
                var(color, operation) = ApplyVertexColors.GetColor();

                if (color.HasValue)
                {
                    asset.SetVertexColors(color.Value, operation);
                    archive.UnsavedChanges = true;
                }
            };
            buttonSetVertexColors.Enabled = !asset.IsNativeData;
            tableLayoutPanel1.Controls.Add(buttonSetVertexColors, 0, 2);

            CheckBox ignoreMeshColors = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Ignore Mesh Colors", AutoSize = true
            };

            ignoreMeshColors.Checked = true;
            tableLayoutPanel1.Controls.Add(ignoreMeshColors, 0, 3);
            CheckBox flipUVs = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Flip UVs", AutoSize = true
            };

            tableLayoutPanel1.Controls.Add(flipUVs, 0, 4);

            Button buttonImport = new Button()
            {
                Dock = DockStyle.Fill, Text = "Import", AutoSize = true
            };

            buttonImport.Click += (object sender, EventArgs e) =>
            {
                OpenFileDialog openFile = new OpenFileDialog()
                {
                    Filter = GetImportFilter(), // "All supported types|*.dae;*.obj;*.bsp|DAE Files|*.dae|OBJ Files|*.obj|BSP Files|*.bsp|All files|*.*",
                };

                if (openFile.ShowDialog() == DialogResult.OK)
                {
                    if (asset.AHDR.assetType == HipHopFile.AssetType.MODL)
                    {
                        asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".dff") ?
                                     File.ReadAllBytes(openFile.FileName) :
                                     ReadFileMethods.ExportRenderWareFile(CreateDFFFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game));
                    }

                    if (asset.AHDR.assetType == HipHopFile.AssetType.BSP)
                    {
                        asset.Data = Path.GetExtension(openFile.FileName).ToLower().Equals(".bsp") ?
                                     File.ReadAllBytes(openFile.FileName) :
                                     ReadFileMethods.ExportRenderWareFile(CreateBSPFromAssimp(openFile.FileName, flipUVs.Checked, ignoreMeshColors.Checked), modelRenderWareVersion(asset.game));
                    }

                    asset.Setup(Program.MainForm.renderer);

                    archive.UnsavedChanges = true;
                }
            };
            tableLayoutPanel1.Controls.Add(buttonImport, 0, 5);

            CheckBox exportTextures = new CheckBox()
            {
                Dock = DockStyle.Fill, Text = "Export Textures", AutoSize = true
            };

            tableLayoutPanel1.Controls.Add(exportTextures, 1, 4);

            Button buttonExport = new Button()
            {
                Dock = DockStyle.Fill, Text = "Export", AutoSize = true
            };

            buttonExport.Click += (object sender, EventArgs e) =>
            {
                (Assimp.ExportFormatDescription format, string textureExtension) = ChooseTarget.GetTarget();

                if (format != null)
                {
                    SaveFileDialog a = new SaveFileDialog()
                    {
                        Filter = format == null ? "RenderWare BSP|*.bsp" : format.Description + "|*." + format.FileExtension,
                    };

                    if (a.ShowDialog() == DialogResult.OK)
                    {
                        if (format == null)
                        {
                            File.WriteAllBytes(a.FileName, asset.Data);
                        }
                        else if (format.FileExtension.ToLower().Equals("obj") && asset.AHDR.assetType == HipHopFile.AssetType.BSP)
                        {
                            ConvertBSPtoOBJ(a.FileName, ReadFileMethods.ReadRenderWareFile(asset.Data), true);
                        }
                        else
                        {
                            ExportAssimp(Path.ChangeExtension(a.FileName, format.FileExtension), ReadFileMethods.ReadRenderWareFile(asset.Data), true, format, textureExtension, Matrix.Identity);
                        }

                        if (exportTextures.Checked)
                        {
                            string folderName = Path.GetDirectoryName(a.FileName);
                            var    bitmaps    = archive.GetTexturesAsBitmaps(asset.Textures);
                            ReadFileMethods.treatStuffAsByteArray = false;
                            foreach (string textureName in bitmaps.Keys)
                            {
                                bitmaps[textureName].Save(folderName + "/" + textureName + ".png", System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }
                    }
                }
            };

            tableLayoutPanel1.Controls.Add(buttonExport, 1, 5);
        }
Beispiel #19
0
        public static (List <Section_AHDR> AHDRs, bool overwrite, bool simps, bool ledgeGrab, bool piptVColors) GetModels(Game game)
        {
            using (ImportModel a = new ImportModel())
                if (a.ShowDialog() == DialogResult.OK)
                {
                    List <Section_AHDR> AHDRs = new List <Section_AHDR>();

                    AssetType assetType = (AssetType)a.comboBoxAssetTypes.SelectedItem;

                    bool simps = false, ledgeGrab = false, piptVColors = false;

                    if (assetType == AssetType.MODL)
                    {
                        piptVColors = a.checkBoxEnableVcolors.Checked;
                        simps       = a.checkBoxGenSimps.Checked;
                        ledgeGrab   = a.checkBoxLedgeGrab.Checked;

                        if (simps)
                        {
                            MessageBox.Show("a SIMP for each imported MODL will be generated and placed on a new DEFAULT layer.");
                        }
                    }

                    foreach (string filePath in a.filePaths)
                    {
                        string assetName;

                        byte[] assetData;

                        ReadFileMethods.treatStuffAsByteArray = false;

                        if (assetType == AssetType.MODL)
                        {
                            assetName = Path.GetFileNameWithoutExtension(filePath) + ".dff";

                            assetData = Path.GetExtension(filePath).ToLower().Equals(".dff") ?
                                        File.ReadAllBytes(filePath) :
                                        ReadFileMethods.ExportRenderWareFile(
                                CreateDFFFromAssimp(filePath,
                                                    a.checkBoxFlipUVs.Checked,
                                                    a.checkBoxIgnoreMeshColors.Checked),
                                modelRenderWareVersion(game));
                        }
                        else if (assetType == AssetType.BSP)
                        {
                            assetName = Path.GetFileNameWithoutExtension(filePath) + ".bsp";

                            assetData = Path.GetExtension(filePath).ToLower().Equals(".bsp") ?
                                        File.ReadAllBytes(filePath) :
                                        ReadFileMethods.ExportRenderWareFile(
                                CreateBSPFromAssimp(filePath,
                                                    a.checkBoxFlipUVs.Checked,
                                                    a.checkBoxIgnoreMeshColors.Checked),
                                modelRenderWareVersion(game));
                        }
                        else
                        {
                            throw new ArgumentException();
                        }

                        AHDRs.Add(new Section_AHDR(
                                      Functions.BKDRHash(assetName),
                                      assetType,
                                      ArchiveEditorFunctions.AHDRFlagsFromAssetType(assetType),
                                      new Section_ADBG(0, assetName, "", 0),
                                      assetData));
                    }

                    return(AHDRs, a.checkBoxOverwrite.Checked, simps, ledgeGrab, piptVColors);
                }

            return(null, false, false, false, false);
        }
Beispiel #20
0
        public void SetForRendering(RWSection[] rwChunkList, byte[] rwByteArray)
        {
            rwSectionArray = rwChunkList;

            if (rwByteArray == null)
            {
                rwSectionByteArray = ReadFileMethods.ExportRenderWareFile(rwSectionArray, isShadowCollision ? LevelEditor.LevelEditorFunctions.shadowRenderWareVersion : LevelEditor.LevelEditorFunctions.renderWareVersion);

                if (rwSectionByteArray.Length > 450 * 1024)
                {
                    System.Windows.Forms.MessageBox.Show(fileName + " is larger than 450 kb. I will still import it for you, but be warned that files too large might make the game crash.");
                }
            }
            else
            {
                rwSectionByteArray = rwByteArray;
            }
            meshList = new List <SharpMesh>();

            vertexList   = new List <Vector3>();
            triangleList = new List <Triangle>();

            foreach (RWSection rwSection in rwSectionArray)
            {
                if (rwSection is World_000B w)
                {
                    vertexAmount   = w.worldStruct.numVertices;
                    triangleAmount = w.worldStruct.numTriangles;

                    foreach (Material_0007 m in w.materialList.materialList)
                    {
                        if (isShadowCollision)
                        {
                            MaterialList.Add(m.materialStruct.color.ToString());
                        }
                        else if (m.texture != null)
                        {
                            MaterialList.Add(m.texture.diffuseTextureName.stringString);
                        }
                        else
                        {
                            MaterialList.Add(DefaultTexture);
                        }
                    }
                    if (w.firstWorldChunk is AtomicSector_0009 a)
                    {
                        AddAtomic(a);
                    }
                    else if (w.firstWorldChunk is PlaneSector_000A p)
                    {
                        AddPlane(p);
                    }
                }
                else if (rwSection is Clump_0010 c)
                {
                    foreach (Geometry_000F g in c.geometryList.geometryList)
                    {
                        AddGeometry(g);
                    }
                }
            }
        }
Beispiel #21
0
        public static List <Section_AHDR> CreateRWTXsFromBitmaps
            (Game game, Platform platform, List <string> fileNames, bool appendRW3, bool flip, bool mipmaps, bool compress, bool transFix)
        {
            lock (locker)
            {
                if (transFix)
                {
                    compress = false;
                }

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

                foreach (string fileName in fileNames)
                {
                    string textureName = Path.GetFileNameWithoutExtension(fileName);
                    Bitmap bitmap      = new Bitmap(fileName);

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

                    if (flip)
                    {
                        bitmap.RotateFlip(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);
                        }
                    }

                    textureNativeList.Add(
                        new TextureNative_0015()
                    {
                        textureNativeStruct = new TextureNativeStruct_0001()
                        {
                            textureName       = textureName + (appendRW3 ? ".RW3" : ""),
                            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()
                    }
                        );

                    bitmap.Dispose();
                }

                if (!Directory.Exists(tempPcTxdsDir))
                {
                    Directory.CreateDirectory(tempPcTxdsDir);
                }
                if (!Directory.Exists(tempGcTxdsDir))
                {
                    Directory.CreateDirectory(tempGcTxdsDir);
                }

                File.WriteAllBytes(pathToPcTXD, ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                {
                    textureDictionaryStruct = new TextureDictionaryStruct_0001()
                    {
                        textureCount = (short)textureNativeList.Count, unknown = 0
                    },
                    textureNativeList          = textureNativeList,
                    textureDictionaryExtension = new Extension_0003()
                }, currentTextureVersion(game)));

                PerformTXDConversionExternal(platform, false, compress, mipmaps);

                ReadFileMethods.treatStuffAsByteArray = true;

                List <Section_AHDR> AHDRs = new List <Section_AHDR>();

                foreach (TextureNative_0015 texture in ((TextureDictionary_0016)ReadFileMethods.ReadRenderWareFile(pathToGcTXD)[0]).textureNativeList)
                {
                    AHDRs.Add(new Section_AHDR(BKDRHash(texture.textureNativeStruct.textureName), AssetType.RWTX, ArchiveEditorFunctions.AHDRFlagsFromAssetType(AssetType.RWTX),
                                               new Section_ADBG(0, texture.textureNativeStruct.textureName, "", 0),
                                               ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                    {
                        textureDictionaryStruct = new TextureDictionaryStruct_0001()
                        {
                            textureCount = 1, unknown = 0
                        },
                        textureNativeList = new List <TextureNative_0015>()
                        {
                            texture
                        },
                        textureDictionaryExtension = new Extension_0003()
                    }, currentTextureVersion(game))));
                }

                // fix for apparent transparency issue
                if (transFix && platform == Platform.GameCube)
                {
                    foreach (var AHDR in AHDRs)
                    {
                        AHDR.data[0x9B] = 0x01;
                    }
                }

                ReadFileMethods.treatStuffAsByteArray = false;

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

                return(AHDRs);
            }
        }
Beispiel #22
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);
        }
Beispiel #23
0
        public void AddTextureDictionary(string fileName, bool RW3)
        {
            UnsavedChanges = true;
            int layerIndex = 0;

            List <Section_LHDR> LHDRs = new List <Section_LHDR>
            {
                new Section_LHDR()
                {
                    layerType   = 1,
                    assetIDlist = new List <uint>(),
                    LDBG        = new Section_LDBG(-1)
                }
            };

            LHDRs.AddRange(DICT.LTOC.LHDRList);
            DICT.LTOC.LHDRList = LHDRs;

            ReadFileMethods.treatStuffAsByteArray = true;

            foreach (RWSection rw in ReadFileMethods.ReadRenderWareFile(fileName))
            {
                if (rw is TextureDictionary_0016 td)
                {
                    // For each texture in the dictionary...
                    foreach (TextureNative_0015 tn in td.textureNativeList)
                    {
                        string textureName = tn.textureNativeStruct.textureName;
                        if (RW3 && !textureName.Contains(".RW3"))
                        {
                            textureName += ".RW3";
                        }

                        // Create a new dictionary that has only that texture.
                        byte[] data = ReadFileMethods.ExportRenderWareFile(new TextureDictionary_0016()
                        {
                            textureDictionaryStruct = new TextureDictionaryStruct_0001()
                            {
                                textureCount = 1, unknown = 0
                            },
                            textureDictionaryExtension = new Extension_0003(),
                            textureNativeList          = new List <TextureNative_0015>()
                            {
                                tn
                            }
                        }, tn.renderWareVersion);

                        // And add the new dictionary as an asset.
                        Section_ADBG ADBG = new Section_ADBG(0, textureName, "", 0);
                        Section_AHDR AHDR = new Section_AHDR(BKDRHash(textureName), AssetType.RWTX, AHDRFlags.SOURCE_VIRTUAL | AHDRFlags.READ_TRANSFORM, ADBG, data);

                        if (ContainsAsset(AHDR.assetID))
                        {
                            RemoveAsset(AHDR.assetID);
                        }

                        AddAsset(layerIndex, AHDR);
                    }
                }
            }

            ReadFileMethods.treatStuffAsByteArray = false;
        }