Beispiel #1
0
        public static Section_AHDR GetAsset(AssetHeader a, out bool success)
        {
            DialogResult d = a.ShowDialog();

            if (d == DialogResult.OK)
            {
                AHDRFlags flags =
                    (a.checkSourceFile.Checked ? AHDRFlags.SOURCE_FILE : 0) |
                    (a.checkSourceVirtual.Checked ? AHDRFlags.SOURCE_VIRTUAL : 0) |
                    (a.checkReadT.Checked ? AHDRFlags.READ_TRANSFORM : 0) |
                    (a.checkWriteT.Checked ? AHDRFlags.WRITE_TRANSFORM : 0);

                Section_ADBG ADBG = new Section_ADBG(0, a.assetName, a.assetFileName, a.checksum);

                Section_AHDR AHDR = new Section_AHDR(a.assetID, a.assetType, flags, ADBG, a.data)
                {
                    fileSize  = a.data.Length,
                    plusValue = 0
                };

                success = true;
                return(AHDR);
            }
            else
            {
                success = false;
                return(null);
            }
        }
Beispiel #2
0
        public static List <Section_AHDR> GetAssets(out bool success)
        {
            AddMultipleAssets a = new AddMultipleAssets();
            DialogResult      d = a.ShowDialog();

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

                for (int i = 0; i < a.assetNames.Count; i++)
                {
                    Section_ADBG ADBG = new Section_ADBG(0, a.assetNames[i], "", 0);

                    Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(a.assetNames[i]), a.assetType, a.AHDRflags, ADBG, a.assetData[i])
                    {
                        fileSize = a.assetData[i].Length
                    };

                    AHDRs.Add(AHDR);
                }

                success = true;
                return(AHDRs);
            }
            else
            {
                success = false;
                return(null);
            }
        }
        public static (List <Section_AHDR> AHDRs, bool overwrite) GetAssets()
        {
            AddMultipleAssets a = new AddMultipleAssets();
            DialogResult      d = a.ShowDialog();

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

                for (int i = 0; i < a.assetNames.Count; i++)
                {
                    Section_ADBG ADBG = new Section_ADBG(0, a.assetNames[i], "", 0);

                    Section_AHDR AHDR = new Section_AHDR(Functions.BKDRHash(a.assetNames[i]), a.assetType, a.AHDRflags, ADBG, a.assetData[i])
                    {
                        fileSize = a.assetData[i].Length
                    };

                    AHDRs.Add(AHDR);
                }

                return(AHDRs, a.checkBoxOverwrite.Checked);
            }
            return(null, false);
        }
Beispiel #4
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 #5
0
        public static Section_AHDR GetAsset(AssetHeader a, out bool success, out bool setPosition)
        {
            DialogResult d = a.ShowDialog();

            if (d == DialogResult.OK)
            {
                AHDRFlags flags =
                    (a.checkSourceFile.Checked ? AHDRFlags.SOURCE_FILE : 0) |
                    (a.checkSourceVirtual.Checked ? AHDRFlags.SOURCE_VIRTUAL : 0) |
                    (a.checkReadT.Checked ? AHDRFlags.READ_TRANSFORM : 0) |
                    (a.checkWriteT.Checked ? AHDRFlags.WRITE_TRANSFORM : 0);

                Section_ADBG ADBG = new Section_ADBG(0, a.assetName, a.assetFileName, a.checksum);

                Section_AHDR AHDR = new Section_AHDR(a.assetID, a.assetType, flags, ADBG, a.data)
                {
                    fileSize  = a.data.Length,
                    plusValue = 0
                };

                int alignment = 16;
                if (Functions.currentGame == Game.BFBB)
                {
                    if (AHDR.assetType == AssetType.CSN |
                        AHDR.assetType == AssetType.SND |
                        AHDR.assetType == AssetType.SNDS)
                    {
                        alignment = 32;
                    }
                    else if (AHDR.assetType == AssetType.CRDT)
                    {
                        alignment = 4;
                    }
                }

                int value = AHDR.fileSize % alignment;
                if (value != 0)
                {
                    AHDR.plusValue = alignment - value;
                }

                setPosition = a.setPosition;
                success     = true;
                return(AHDR);
            }
            else
            {
                success     = false;
                setPosition = 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 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;
        }
Beispiel #8
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 #9
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);
            }
        }
Beispiel #10
0
        public Patch Commit(string root)
        {
            Patch uninstall = new Patch();

            uninstall.isUninstall = true;

            Console.WriteLine();
            Console.WriteLine("Patching...");
            Console.WriteLine();

            foreach (AddedFile file in addedFiles)
            {
                string path = root + file.path;

                DeletedFile backup = new DeletedFile(file.path);
                uninstall.deletedFiles.Add(backup);

                File.WriteAllBytes(path, file.data);

                PrintFile(PatchType.ADD, file.path);
            }

            foreach (ModifiedFile file in modifiedFiles)
            {
                string path = root + file.path;

                if (File.Exists(path))
                {
                    byte[]       data   = File.ReadAllBytes(path);
                    ModifiedFile backup = new ModifiedFile(file.path, data);
                    uninstall.modifiedFiles.Add(backup);
                }

                File.WriteAllBytes(path, file.data);

                PrintFile(PatchType.MODIFY, file.path);
            }

            foreach (DeletedFile file in deletedFiles)
            {
                string path = root + file.path;

                if (File.Exists(path))
                {
                    byte[]    data   = File.ReadAllBytes(path);
                    AddedFile backup = new AddedFile(file.path, data);
                    uninstall.addedFiles.Add(backup);
                }

                File.Delete(path);

                PrintFile(PatchType.DELETE, file.path);
            }

            foreach (HipFile file in hipFiles)
            {
                string path = root + file.path;

                HipFile      backup = new HipFile(file.path);
                HipSection[] hip    = HipFileToHipArray(path);

                Section_HIPA hipa = (Section_HIPA)hip[0];
                Section_PACK pack = (Section_PACK)hip[1];
                Section_DICT dict = (Section_DICT)hip[2];
                Section_STRM strm = (Section_STRM)hip[3];

                List <Section_AHDR> ahdrList = dict.ATOC.AHDRList;
                List <Section_LHDR> lhdrList = dict.LTOC.LHDRList;

                Dictionary <uint, Section_AHDR> ahdrDict = ahdrList.ToDictionary(s => s.assetID);

                PrintFile(PatchType.MODIFY, file.path);

                foreach (AddedAsset asset in file.addedAssets)
                {
                    Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum);
                    Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg);

                    ahdr.data = asset.data;

                    DeletedAsset backupAsset = new DeletedAsset(asset);
                    backup.deletedAssets.Add(backupAsset);

                    ahdrList.Add(ahdr);

                    Section_LHDR lhdr = lhdrList[asset.layer];
                    lhdr.assetIDlist.Add(asset.id);

                    PrintAsset(PatchType.ADD, asset.name);
                }

                foreach (ModifiedAsset asset in file.modifiedAssets)
                {
                    if (!ahdrDict.ContainsKey(asset.id))
                    {
                        break;
                    }

                    Section_ADBG adbg = new Section_ADBG(asset.alignment, asset.name, asset.filename, asset.checksum);
                    Section_AHDR ahdr = new Section_AHDR(asset.id, new string(asset.type), (AHDRFlags)asset.flags, adbg);

                    ahdr.data = asset.data;

                    Section_AHDR oldAHDR = ahdrDict[asset.id];
                    ahdrList.Remove(oldAHDR);
                    ahdrList.Add(ahdr);

                    ModifiedAsset backupAsset = new ModifiedAsset(oldAHDR, hip);
                    backup.modifiedAssets.Add(backupAsset);

                    PrintAsset(PatchType.MODIFY, asset.name);
                }

                foreach (DeletedAsset asset in file.deletedAssets)
                {
                    if (!ahdrDict.ContainsKey(asset.id))
                    {
                        break;
                    }

                    Section_AHDR ahdr = ahdrDict[asset.id];

                    ahdrList.Remove(ahdr);

                    AddedAsset backupAsset = new AddedAsset(ahdr, hip);
                    backup.addedAssets.Add(backupAsset);

                    Section_LHDR lhdr = lhdrList[asset.layer];
                    lhdr.assetIDlist.Remove(asset.id);

                    PrintAsset(PatchType.DELETE, asset.name);
                }

                pack.PCNT.AHDRCount = ahdrList.Count;

                hip = SetupStream(ref hipa, ref pack, ref dict, ref strm);
                File.WriteAllBytes(path, HipArrayToFile(hip));

                uninstall.hipFiles.Add(backup);
            }

            Console.WriteLine("Done patching.");
            Console.WriteLine();

            return(uninstall);
        }