public bool New()
        {
            HipFile hipFile = NewArchive.GetNewArchive(out bool OK, out bool addDefaultAssets);

            if (OK)
            {
                Dispose();

                currentlySelectedAssets = new List <Asset>();
                currentlyOpenFilePath   = null;
                assetDictionary.Clear();

                this.hipFile = hipFile;

                if (platform == Platform.Unknown)
                {
                    new ChoosePlatformDialog().ShowDialog();
                }

                foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
                {
                    AddAssetToDictionary(AHDR, true);
                }

                if (addDefaultAssets)
                {
                    PlaceDefaultAssets();
                }

                UnsavedChanges = true;
                RecalculateAllMatrices();
            }

            return(OK);
        }
        public void Dispose(bool showProgress = true)
        {
            autoCompleteSource.Clear();

            List <uint> assetList = new List <uint>();

            assetList.AddRange(assetDictionary.Keys);

            if (assetList.Count == 0)
            {
                return;
            }

            ProgressBar progressBar = new ProgressBar("Closing Archive");

            if (showProgress)
            {
                progressBar.Show();
            }
            progressBar.SetProgressBar(0, assetList.Count, 1);

            foreach (uint assetID in assetList)
            {
                DisposeOfAsset(assetID);
                progressBar.PerformStep();
            }

            hipFile = null;
            currentlyOpenFilePath = null;

            progressBar.Close();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            SendMessage("HipHopTool v0.5.0 by igorseabra4");

            if (args.Length == 0)
            {
                ShowNoArgsMenu();
            }
            else if (!PerformArgsSelection(args))
            {
                foreach (string s in args)
                {
                    if (Path.GetExtension(s).ToLower() == ".hip" || Path.GetExtension(s).ToLower() == ".hop")
                    {
                        SendMessage("File: " + s);
                        SendMessage("Destination: " + s + ".d");

                        var hip = HipFile.FromPath(s);
                        hip.Item1.ToIni(hip.Item2, s + ".d", true, false);

                        SendMessage("Success");
                    }
                }
            }
        }
 public void ImportHip(string fileName, bool forceOverwrite, List <uint> assetIDs = null)
 {
     if (Path.GetExtension(fileName).ToLower() == ".hip" || Path.GetExtension(fileName).ToLower() == ".hop")
     {
         ImportHip(HipFile.FromPath(fileName), forceOverwrite, assetIDs);
     }
     else if (Path.GetExtension(fileName).ToLower() == ".ini")
     {
         ImportHip(HipFile.FromINI(fileName), forceOverwrite, assetIDs);
     }
     else
     {
         MessageBox.Show("Invalid file: " + fileName);
     }
 }
Exemplo n.º 5
0
    public override void OnImportAsset(AssetImportContext ctx)
    {
        int    pos            = ctx.assetPath.LastIndexOf("/") + 1;
        string LevelExtension = ctx.assetPath.Substring(pos, ctx.assetPath.Length - pos);
        string LevelName      = LevelExtension.Substring(0, LevelExtension.IndexOf("."));
        var    hipFile        = new HipFile(ctx.assetPath);

        if (!AssetDatabase.IsValidFolder("Assets/" + LevelName))
        {
            AssetDatabase.CreateFolder("Assets", LevelName);
            foreach (var AHDR in hipFile.DICT.ATOC.AHDRList)
            {
                if (AHDR.assetType == AssetType.MODL)
                {
                    var model = ReadFileMethods.ReadRenderWareFile(AHDR.data)[0];
                }
            }
        }
    }
        public void ImportHip(HipFile hip, bool forceOverwrite, List <uint> missingAssets)
        {
            UnsavedChanges  = true;
            forceOverwrite |= missingAssets != null;

            foreach (Section_AHDR AHDR in hip.DICT.ATOC.AHDRList)
            {
                if (AHDR.assetType == AssetType.COLL && ContainsAssetWithType(AssetType.COLL))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergeCOLL(AHDR, hip.game, hip.platform);
                    continue;
                }
                else if (AHDR.assetType == AssetType.JAW && ContainsAssetWithType(AssetType.JAW))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergeJAW(AHDR, hip.game, hip.platform);
                    continue;
                }
                else if (AHDR.assetType == AssetType.LODT && ContainsAssetWithType(AssetType.LODT))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergeLODT(AHDR, hip.game, hip.platform);
                    continue;
                }
                else if (AHDR.assetType == AssetType.PIPT && ContainsAssetWithType(AssetType.PIPT))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergePIPT(AHDR, hip.game, hip.platform);
                    continue;
                }
                else if (AHDR.assetType == AssetType.SHDW && ContainsAssetWithType(AssetType.SHDW))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergeSHDW(AHDR, hip.game, hip.platform);
                    continue;
                }
                else if (AHDR.assetType == AssetType.SNDI && ContainsAssetWithType(AssetType.SNDI))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }

                    MergeSNDI(AHDR, hip.game, hip.platform);
                    continue;
                }

                if (missingAssets != null && !missingAssets.Contains(AHDR.assetID))
                {
                    foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                    {
                        LHDR.assetIDlist.Remove(AHDR.assetID);
                    }
                    continue;
                }

                if (ContainsAsset(AHDR.assetID) && (missingAssets == null || missingAssets.Contains(AHDR.assetID)))
                {
                    DialogResult result = forceOverwrite ? DialogResult.Yes :
                                          MessageBox.Show($"Asset [{AHDR.assetID.ToString("X8")}] {AHDR.ADBG.assetName} already present in archive. Do you wish to overwrite it?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (result == DialogResult.Yes)
                    {
                        RemoveAsset(AHDR.assetID, false);
                        DICT.ATOC.AHDRList.Add(AHDR);
                        AddAssetToDictionary(AHDR, forceOverwrite, forceOverwrite);
                    }
                    else
                    {
                        foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
                        {
                            LHDR.assetIDlist.Remove(AHDR.assetID);
                        }
                    }
                    if (missingAssets != null)
                    {
                        missingAssets.Remove(AHDR.assetID);
                    }
                }
                else if (missingAssets == null)
                {
                    DICT.ATOC.AHDRList.Add(AHDR);
                    AddAssetToDictionary(AHDR, forceOverwrite, forceOverwrite);
                }
            }

            foreach (Section_LHDR LHDR in hip.DICT.LTOC.LHDRList)
            {
                if (LHDR.assetIDlist.Count != 0)
                {
                    DICT.LTOC.LHDRList.Add(LHDR);
                }
            }

            DICT.LTOC.LHDRList = DICT.LTOC.LHDRList.OrderBy(f => f.layerType, new LHDRComparer(game)).ToList();

            if (!forceOverwrite)
            {
                RecalculateAllMatrices();
            }
        }
Exemplo n.º 7
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            OK = true;

            Section_HIPA HIPA = new Section_HIPA();
            Section_PACK PACK = new Section_PACK();
            Section_DICT DICT = new Section_DICT
            {
                ATOC = new Section_ATOC()
                {
                    AINF = new Section_AINF(0)
                },
                LTOC = new Section_LTOC()
                {
                    LINF = new Section_LINF(0)
                },
            };
            Section_STRM STRM = new Section_STRM
            {
                DHDR = new Section_DHDR(-1),
                DPAK = new Section_DPAK()
            };

            PACK.PMOD = new Section_PMOD((int)dateTimePicker1.Value.ToBinary());
            PACK.PCRT = new Section_PCRT((int)dateTimePicker1.Value.ToBinary(), textBoxPCRT.Text);
            PACK.PCNT = new Section_PCNT(0, 0, 0, 0, 0);
            PACK.PFLG = new Section_PFLG(46);

            if (game != Game.Scooby)
            {
                PACK.PVER = new Section_PVER(2, 655375, 1);
                PACK.PLAT = new Section_PLAT
                {
                    regionFormat = "NTSC"
                };
            }

            switch (game)
            {
            case Game.Scooby:
                PACK.PVER = new Section_PVER(2, 262150, 1);
                break;

            case Game.BFBB:
                PACK.PLAT.language   = "US Common";
                PACK.PLAT.targetGame = "Sponge Bob";
                switch (platform)
                {
                case Platform.GameCube:
                    PACK.PFLG = new Section_PFLG(36241454);
                    PACK.PLAT.targetPlatform     = "GC";
                    PACK.PLAT.targetPlatformName = "GameCube";
                    break;

                case Platform.PS2:
                    PACK.PFLG = new Section_PFLG(36438062);
                    PACK.PLAT.targetPlatform     = "P2";
                    PACK.PLAT.targetPlatformName = "PlayStation 2";
                    break;

                case Platform.Xbox:
                    PACK.PFLG = new Section_PFLG(36306990);
                    PACK.PLAT.targetPlatform     = "XB";
                    PACK.PLAT.targetPlatformName = "Xbox";
                    break;
                }
                break;

            case Game.Incredibles:
                PACK.PLAT.language   = "US";
                PACK.PLAT.targetGame = "Incredibles";
                switch (platform)
                {
                case Platform.Xbox:
                    PACK.PLAT.targetPlatform = "BX";
                    break;

                case Platform.GameCube:
                    PACK.PLAT.targetPlatform = "GC";
                    break;

                case Platform.PS2:
                    PACK.PLAT.targetPlatform = "PS2";
                    break;
                }
                break;
            }

            result = new HipFile(HIPA, PACK, DICT, STRM);

            Close();
        }
        public void OpenFile(string fileName, bool displayProgressBar, Platform platform, bool skipTexturesAndModels = false)
        {
            allowRender = false;

            Dispose();

            ProgressBar progressBar = new ProgressBar("Opening Archive");

            if (displayProgressBar)
            {
                progressBar.Show();
            }

            assetDictionary = new Dictionary <uint, Asset>();

            currentlySelectedAssets = new List <Asset>();
            currentlyOpenFilePath   = fileName;

            try
            {
                hipFile = new HipFile(fileName);
            }
            catch (Exception e)
            {
                progressBar.Close();
                throw e;
            }

            progressBar.SetProgressBar(0, DICT.ATOC.AHDRList.Count, 1);

            if (this.platform == Platform.Unknown)
            {
                hipFile.platform = platform;
            }
            while (this.platform == Platform.Unknown)
            {
                hipFile.platform = ChoosePlatformDialog.GetPlatform();
            }

            string assetsWithError = "";

            List <string> autoComplete = new List <string>(DICT.ATOC.AHDRList.Count);

            foreach (Section_AHDR AHDR in DICT.ATOC.AHDRList)
            {
                string error = AddAssetToDictionary(AHDR, true, skipTexturesAndModels || standalone, false);

                if (error != null)
                {
                    assetsWithError += error + "\n";
                }

                autoComplete.Add(AHDR.ADBG.assetName);

                progressBar.PerformStep();
            }

            if (assetsWithError != "")
            {
                MessageBox.Show("There was an error loading the following assets and editing has been disabled for them:\n" + assetsWithError);
            }

            autoCompleteSource.AddRange(autoComplete.ToArray());

            if (!(skipTexturesAndModels || standalone) && ContainsAssetWithType(AssetType.RWTX))
            {
                SetupTextureDisplay();
            }

            RecalculateAllMatrices();

            if (!skipTexturesAndModels && ContainsAssetWithType(AssetType.PIPT) && ContainsAssetWithType(AssetType.MODL))
            {
                foreach (var asset in assetDictionary.Values)
                {
                    if (asset is AssetPIPT PIPT)
                    {
                        PIPT.UpdateDictionary();
                    }
                }
            }

            progressBar.Close();

            allowRender = true;
        }
Exemplo n.º 9
0
        private static bool PerformArgsSelection(string[] args)
        {
            Option option = Option.None;

            string hipToUnpack  = "null";
            string outputPath   = "null";
            string iniToCreate  = "null";
            bool   multiFolder  = true;
            bool   alphabetical = false;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].ToLower() == "-extract" | args[i].ToLower() == "-e" | args[i].ToLower() == "-unpack" | args[i].ToLower() == "-u")
                {
                    hipToUnpack = args[i + 1];
                    option      = Option.ExtractHIP;
                }
                else if (args[i].ToLower() == "-dest" | args[i].ToLower() == "-d")
                {
                    outputPath = args[i + 1];
                }
                else if (args[i].ToLower() == "-mode" | args[i].ToLower() == "-m")
                {
                    if (args[i + 1].ToLower().Contains("single"))
                    {
                        multiFolder = false;
                    }
                    else if (args[i + 1].ToLower().Contains("multi"))
                    {
                        multiFolder = true;
                    }
                }
                else if (args[i].ToLower() == "-alphabetical" | args[i].ToLower() == "-alpha" | args[i].ToLower() == "-a")
                {
                    alphabetical = true;
                }
                else if (args[i].ToLower() == "-create" | args[i].ToLower() == "-c")
                {
                    iniToCreate = args[i + 1];
                    option      = Option.CreateHIP;
                }
            }

            if (option == Option.ExtractHIP)
            {
                SendMessage("File: " + hipToUnpack);

                if (outputPath == "null")
                {
                    outputPath = hipToUnpack + ".d";
                }

                SendMessage("Destination: " + outputPath);

                var hip = HipFile.FromPath(hipToUnpack);
                hip.Item1.ToIni(hip.Item2, outputPath, multiFolder, alphabetical);

                SendMessage("Success");
            }
            else if (option == Option.CreateHIP)
            {
                SendMessage("File: " + iniToCreate);

                if (outputPath == "null")
                {
                    outputPath = Path.ChangeExtension(iniToCreate, ".HIP");
                }

                SendMessage("Destination: " + outputPath);

                var hip = HipFile.FromINI(iniToCreate);

                File.WriteAllBytes(outputPath, hip.Item1.ToBytes(hip.Item2, hip.Item3));

                SendMessage("Success");
            }

            return(option != Option.None);
        }
Exemplo n.º 10
0
        private static void ShowNoArgsMenu()
        {
            Option option = Option.None;

            while (option != Option.Close)
            {
                SendMessage();
                SendMessage("Usage: drag HIP/HOP files into the executable to extract them, check readme for command line options, or choose one of the options below.");
                SendMessage("Type 0 to extract a HIP/HOP file.");
                SendMessage("Type 1 to create a HIP/HOP file.");
                SendMessage("Type 2 to close.");

                try
                {
                    option = (Option)Convert.ToInt32(Console.ReadLine());
                }
                catch
                {
                    option = Option.None;
                }

                if (option == Option.ExtractHIP)
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog()
                    {
                        Title  = "Select a file to unpack",
                        Filter = "HIP/HOP files|*.hip;*.hop"
                    };

                    if (openFileDialog.ShowDialog(new Form()
                    {
                        TopMost = true, TopLevel = true
                    }) == DialogResult.OK)
                    {
                        SendMessage("File: " + openFileDialog.FileName);

                        var hip = HipFile.FromPath(openFileDialog.FileName);
                        hip.Item1.ToIni(hip.Item2, openFileDialog.FileName + ".d", true, false);
                    }
                }
                else if (option == Option.CreateHIP)
                {
                    OpenFileDialog openFileDialog = new OpenFileDialog()
                    {
                        Title  = "Select an INI file",
                        Filter = "INI files|*.ini"
                    };
                    if (openFileDialog.ShowDialog(new Form()
                    {
                        TopMost = true, TopLevel = true
                    }) == DialogResult.OK)
                    {
                        SaveFileDialog saveFileDialog = new SaveFileDialog()
                        {
                            Title  = "Save as...",
                            Filter = "HIP/HOP files|*.hip;*.hop"
                        };
                        if (saveFileDialog.ShowDialog(new Form()
                        {
                            TopMost = true, TopLevel = true
                        }) == DialogResult.OK)
                        {
                            var hip = HipFile.FromINI(openFileDialog.FileName);
                            File.WriteAllBytes(saveFileDialog.FileName, hip.Item1.ToBytes(hip.Item2, hip.Item3));
                        }
                    }
                }
            }
        }