Beispiel #1
0
 internal BHF4()
 {
     Timestamp = SFUtil.DateToBinderTimestamp(DateTime.Now);
     Flag1     = false;
     Flag2     = false;
     Unicode   = true;
     Format    = Binder.Format.x74;
     Extended  = 4;
 }
Beispiel #2
0
 public static ESD ReadWithContext(string path, EzSembleContext context)
 {
     using (FileStream stream = File.OpenRead(path))
     {
         BinaryReaderEx br   = new BinaryReaderEx(false, stream);
         ESD            file = new ESD();
         br = SFUtil.GetDecompressedBR(br, out file.Compression);
         file.ReadWithContext(br, context);
         return(file);
     }
 }
Beispiel #3
0
        public CommandHandler(ControlInterface ctrlInterface, GlobalConfig config)
        {
            this.commandQueue  = new CommandQueue(ctrlInterface);
            this.ctrlInterface = ctrlInterface;
            this.config        = config;

            eventCallback       = LuaEventHandler;
            luaEventCallbackPtr = Marshal.GetFunctionPointerForDelegate(eventCallback);
            frameName           = SFUtil.GetRandomAsciiString(5);

            ResolveEndSceneAddress();
            RegisterFunctions();
        }
Beispiel #4
0
 private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         SFUtil.Backup(DrbPath);
         Drb.Write(DrbPath);
         SystemSounds.Asterisk.Play();
     }
     catch (Exception ex)
     {
         ShowError($"Failed to save DRB:\n{DrbPath}\n\n{ex}");
     }
 }
Beispiel #5
0
        public void InitializeLuaEventFrameHandler_W()
        {
            if (luaEventFunctionName != null)
            {
                return;
            }

            luaEventFunctionName = config.LuaPlugFunctionName ?? SFUtil.GetRandomAsciiString(4);

            FrameScript__RegisterFunction(luaEventFunctionName, luaEventCallbackPtr);
            FrameScript__Execute($"if not {frameName} then  {frameName} = CreateFrame('Frame'); end; {frameName}:SetScript('OnEvent', function(self, eventName, ...) {luaEventFunctionName}(eventName, ...) end); {frameName}:RegisterAllEvents();", 0, 0);

            wardenScan = false;
        }
Beispiel #6
0
        // Overrides bnd, relative to current dir, and outputs to other file
        public void OverrideBndRel <T>(string path, string outPath, Dictionary <string, T> diffData, Func <T, byte[]> writer, string fileExt = null)
        {
            if (Spec.Dcx == DCX.Type.Unknown)
            {
                throw new Exception("DCX encoding not provided");
            }
            string  fname = Path.GetFileName(path);
            IBinder bnd   = ReadBnd(path);

            foreach (BinderFile file in bnd.Files)
            {
                if (fileExt != null && !file.Name.EndsWith(fileExt))
                {
                    continue;
                }
                string bndName = BaseName(file.Name);
                if (!diffData.ContainsKey(bndName) || diffData[bndName] == null)
                {
                    continue;
                }
                try
                {
                    file.Bytes = writer(diffData[bndName]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to load {path}: {bndName}: {ex}");
                }
            }
            if (bnd is BND4 bnd4)
            {
                if (Spec.Game == FromGame.DS3 && outPath.EndsWith("Data0.bdt"))
                {
                    SFUtil.EncryptDS3Regulation(outPath, bnd4);
                    if (new FileInfo(outPath).Length > 0x10000C)
                    {
                        File.Delete(outPath);
                        throw new Exception($"You must set loadLooseParams=1 in modengine.ini. Otherwise Data0.bdt is too large and will permanently corrupt your save file.");
                    }
                }
                else
                {
                    bnd4.Write(outPath, Spec.Dcx);
                }
            }
            if (bnd is BND3 bnd3)
            {
                bnd3.Write(outPath, Spec.Dcx);
            }
        }
Beispiel #7
0
        public static void WriteWithBackup <T>(string gamedir, string moddir, string assetpath, T item, bool ds3reg = false) where T : SoulsFile <T>, new()
        {
            var assetgamepath = $@"{gamedir}\{assetpath}";
            var assetmodpath  = $@"{moddir}\{assetpath}";

            if (moddir != null)
            {
                if (!Directory.Exists(Path.GetDirectoryName(assetmodpath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(assetmodpath));
                }
            }

            // Make a backup of the original file if a mod path doesn't exist
            if (moddir == null && !File.Exists($@"{assetgamepath}.bak") && File.Exists(assetgamepath))
            {
                File.Copy(assetgamepath, $@"{assetgamepath}.bak", true);
            }

            var writepath = (moddir == null) ? assetgamepath : assetmodpath;

            try
            {
                if (File.Exists(writepath + ".temp"))
                {
                    File.Delete(writepath + ".temp");
                }
                if (ds3reg && item is BND4 bnd)
                {
                    SFUtil.EncryptDS3Regulation(writepath + ".temp", bnd);
                }
                else
                {
                    item.Write(writepath + ".temp");
                }

                if (File.Exists(writepath))
                {
                    File.Copy(writepath, writepath + ".prev", true);
                    File.Delete(writepath);
                }
                File.Move(writepath + ".temp", writepath);
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error saving file: " + writepath + "\nOther files will be saved.", "Error Saving", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.None);
            }
        }
        public static void CombineDragonTpfs()
        {
            // Utility for creating Divine Dragon texbnd. Requires using Yabber to unpack these bnds, and repack after done.
            string gamePath = GameSpec.ForGame(GameSpec.FromGame.SDT).GameDir;
            string mainPath = $@"{gamePath}\chr\c5200-texbnd-dcx\chr\c5200\c5200.tpf";

            SFUtil.Backup(mainPath);
            TPF dragon = TPF.Read(mainPath);

            foreach (string p in Directory.GetFiles($@"{gamePath}\map\m25\m25_0000-tpfbhd", "m25_Dragon*.tpf.dcx"))
            {
                TPF t = TPF.Read(p);
                dragon.Textures.AddRange(t.Textures);
            }
            dragon.Write(mainPath);
        }
Beispiel #9
0
        public static void WriteWithBackup <T>(string gamedir, string moddir, string assetpath, T item, bool ds3reg = false) where T : SoulsFile <T>, new()
        {
            var assetgamepath = $@"{gamedir}\{assetpath}";
            var assetmodpath  = $@"{moddir}\{assetpath}";

            if (moddir != null)
            {
                if (!Directory.Exists(Path.GetDirectoryName(assetmodpath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(assetmodpath));
                }
            }

            // Make a backup of the original file if a mod path doesn't exist
            if (moddir == null && !File.Exists($@"{assetgamepath}.bak") && File.Exists(assetgamepath))
            {
                File.Copy(assetgamepath, $@"{assetgamepath}.bak", true);
            }

            var writepath = (moddir == null) ? assetgamepath : assetmodpath;

            if (File.Exists(writepath + ".temp"))
            {
                File.Delete(writepath + ".temp");
            }
            if (ds3reg && item is BND4 bnd)
            {
                SFUtil.EncryptDS3Regulation(writepath + ".temp", bnd);
            }
            else
            {
                item.Write(writepath + ".temp");
            }

            if (File.Exists(writepath))
            {
                File.Copy(writepath, writepath + ".prev", true);
                File.Delete(writepath);
            }
            File.Move(writepath + ".temp", writepath);
        }
Beispiel #10
0
        public void InitializeLuaEventFrameHandler()
        {
            if (luaEventFunctionName != null)
            {
                return;
            }

            while (wardenScan)
            {
                Thread.Sleep(200);
            }

            luaEventFunctionName = config.LuaPlugFunctionName ?? SFUtil.GetRandomAsciiString(4);

            commandQueue.Submit <object>((() =>
            {
                FrameScript__RegisterFunction(luaEventFunctionName, luaEventCallbackPtr);
                FrameScript__Execute($"if not {frameName} then  {frameName} = CreateFrame('Frame'); end; {frameName}:SetScript('OnEvent', function(self, eventName, ...) {luaEventFunctionName}(eventName, ...) end); {frameName}:RegisterAllEvents();", 0, 0);

                return(null);
            }));
        }
Beispiel #11
0
    public static void SaveParams()
    {
        if (GameType != DarkSoulsTools.GameType.DarkSoulsIII || DS3Param == null)
        {
            return;
        }

        BND4 paramBnd = SFUtil.DecryptDS3Regulation(DarkSoulsTools.GetOverridenPath(ParamPath));
        var  param    = paramBnd.Files.Find(x => Path.GetFileName(x.Name) == "ItemLotParam.param");

        param.Bytes = DS3Param.Write();

        // Save a backup if one doesn't exist
        if (!File.Exists(ParamPath + ".backup"))
        {
            File.Copy(ParamPath, ParamPath + ".backup");
        }

        string paramPath = ParamPath;

        if (DarkSoulsTools.GetModProjectPathForFile(ParamPath) != null)
        {
            paramPath = DarkSoulsTools.GetModProjectPathForFile(ParamPath);
        }

        // Write as a temporary file to make sure there are no errors before overwriting current file
        if (File.Exists(paramPath + ".temp"))
        {
            File.Delete(paramPath + ".temp");
        }
        SFUtil.EncryptDS3Regulation(paramPath + ".temp", paramBnd);

        // Make a copy of the previous map
        File.Copy(paramPath, paramPath + ".prev", true);

        // Move temp file as new map file
        File.Delete(paramPath);
        File.Move(paramPath + ".temp", paramPath);
    }
Beispiel #12
0
        public static bool LoadParamBND(bool forceReload)
        {
            string interroot = GameDataManager.InterrootPath;

            bool justNowLoadedParamBND = false;

            if (forceReload || !ParamBNDs.ContainsKey(GameDataManager.GameType))
            {
                ParamBNDs.Add(GameDataManager.GameType, null);

                if (GameDataManager.GameType == GameDataManager.GameTypes.DS1)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND3.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == GameDataManager.GameTypes.BB)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == GameDataManager.GameTypes.DS3)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam_dlc2.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\param\\GameParam\\GameParam_dlc2.parambnd.dcx");
                    }
                    else if (File.Exists($"{interroot}\\Data0.bdt"))
                    {
                        ParamBNDs[GameDataManager.GameType] = SFUtil.DecryptDS3Regulation($"{interroot}\\Data0.bdt");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }

                justNowLoadedParamBND = true;
            }

            if (justNowLoadedParamBND || forceReload || GameTypeCurrentLoadedParamsAreFrom != GameDataManager.GameType)
            {
                LoadStuffFromParamBND();
            }

            return(true);
        }
Beispiel #13
0
 public PathHash(int index, string path)
 {
     Index = index;
     Hash  = SFUtil.FromPathHash(path);
 }
Beispiel #14
0
            internal void Write(BinaryWriterEx bw, List <BinderFile> files)
            {
                bw.BigEndian = BigEndian;
                bw.WriteASCII("BHF4");
                bw.WriteBoolean(Flag1);
                bw.WriteBoolean(Flag2);
                bw.WriteByte(0);
                bw.WriteByte(0);
                bw.WriteInt32(0x10000);
                bw.WriteInt32(files.Count);
                bw.WriteInt64(0x40);
                bw.WriteFixStr(Timestamp, 8);
                bw.WriteInt64(Binder.FileHeaderSize(Format));
                bw.WriteInt64(0);

                bw.WriteBoolean(Unicode);
                bw.WriteByte((byte)Format);
                bw.WriteByte(Extended);
                bw.WriteByte(0);

                bw.WriteInt32(0);
                if (Extended == 4)
                {
                    bw.ReserveInt64("HashGroups");
                }
                else
                {
                    bw.WriteInt64(0);
                }

                for (int i = 0; i < files.Count; i++)
                {
                    FileHeader.Write(bw, files[i], i, Format);
                }

                for (int i = 0; i < files.Count; i++)
                {
                    BinderFile file = files[i];
                    bw.FillUInt32($"FileName{i}", (uint)bw.Position);
                    if (Unicode)
                    {
                        bw.WriteUTF16(file.Name, true);
                    }
                    else
                    {
                        bw.WriteShiftJIS(file.Name, true);
                    }
                }

                if (Extended == 4)
                {
                    uint groupCount = 0;
                    for (uint p = (uint)files.Count / 7; p <= 100000; p++)
                    {
                        if (SFUtil.IsPrime(p))
                        {
                            groupCount = p;
                            break;
                        }
                    }

                    if (groupCount == 0)
                    {
                        throw new InvalidOperationException("Hash group count not determined in BXF4.");
                    }

                    var hashLists = new List <PathHash> [groupCount];
                    for (int i = 0; i < groupCount; i++)
                    {
                        hashLists[i] = new List <PathHash>();
                    }

                    for (int i = 0; i < files.Count; i++)
                    {
                        var  pathHash = new PathHash(i, files[i].Name);
                        uint group    = pathHash.Hash % groupCount;
                        hashLists[group].Add(pathHash);
                    }

                    for (int i = 0; i < groupCount; i++)
                    {
                        hashLists[i].Sort((ph1, ph2) => ph1.Hash.CompareTo(ph2.Hash));
                    }

                    var hashGroups = new List <HashGroup>();
                    var pathHashes = new List <PathHash>();

                    int count = 0;
                    foreach (List <PathHash> hashList in hashLists)
                    {
                        int index = count;
                        foreach (PathHash pathHash in hashList)
                        {
                            pathHashes.Add(pathHash);
                            count++;
                        }

                        hashGroups.Add(new HashGroup(index, count - index));
                    }

                    bw.Pad(0x8);
                    bw.FillInt64("HashGroups", bw.Position);
                    bw.ReserveInt64("PathHashes");
                    bw.WriteUInt32(groupCount);
                    bw.WriteInt32(0x00080810);

                    foreach (HashGroup hashGroup in hashGroups)
                    {
                        hashGroup.Write(bw);
                    }

                    // No padding after section 1
                    bw.FillInt64("PathHashes", bw.Position);
                    foreach (PathHash pathHash in pathHashes)
                    {
                        pathHash.Write(bw);
                    }
                }
            }
Beispiel #15
0
 public static string GetRelativeOutputDir(string path)
 {
     return($@"{Path.GetDirectoryName(path)}\{SFUtil.GetRealFileName(path)}");
 }
Beispiel #16
0
        private static void SaveParamsDS3(bool loose)
        {
            var dir = AssetLocator.GameRootDirectory;
            var mod = AssetLocator.GameModDirectory;

            if (!File.Exists($@"{dir}\Data0.bdt"))
            {
                MessageBox.Show("Could not find DS3 regulation file. Cannot save.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Load params
            var param = $@"{mod}\Data0.bdt";

            if (!File.Exists(param))
            {
                param = $@"{dir}\Data0.bdt";
            }
            BND4 paramBnd = SFUtil.DecryptDS3Regulation(param);

            // Replace params with edited ones
            foreach (var p in paramBnd.Files)
            {
                if (_params.ContainsKey(Path.GetFileNameWithoutExtension(p.Name)))
                {
                    p.Bytes = _params[Path.GetFileNameWithoutExtension(p.Name)].Write();
                }
            }

            // If not loose write out the new regulation
            if (!loose)
            {
                Utils.WriteWithBackup(dir, mod, @"Data0.bdt", paramBnd, true);
            }
            else
            {
                // Otherwise write them out as parambnds
                BND4 paramBND = new BND4
                {
                    BigEndian   = false,
                    Compression = DCX.Type.DCX_DFLT_10000_44_9,
                    Extended    = 0x04,
                    Unk04       = false,
                    Unk05       = false,
                    Format      = Binder.Format.Compression | Binder.Format.Flag6 | Binder.Format.LongOffsets | Binder.Format.Names1,
                    Unicode     = true,
                    Files       = paramBnd.Files.Where(f => f.Name.EndsWith(".param")).ToList()
                };

                BND4 stayBND = new BND4
                {
                    BigEndian   = false,
                    Compression = DCX.Type.DCX_DFLT_10000_44_9,
                    Extended    = 0x04,
                    Unk04       = false,
                    Unk05       = false,
                    Format      = Binder.Format.Compression | Binder.Format.Flag6 | Binder.Format.LongOffsets | Binder.Format.Names1,
                    Unicode     = true,
                    Files       = paramBnd.Files.Where(f => f.Name.EndsWith(".stayparam")).ToList()
                };

                Utils.WriteWithBackup(dir, mod, @"param\gameparam\gameparam_dlc2.parambnd.dcx", paramBND);
                Utils.WriteWithBackup(dir, mod, @"param\gameparam\stayparam.parambnd.dcx", stayBND);
            }
        }
Beispiel #17
0
        private void LoadFile(string path, bool silent = false)
        {
            statusStripMTDPath.Text = "";
            if (!File.Exists(path))
            {
                ShowError($"File not found:\r\n{path}", silent);
                return;
            }

            string filename  = Path.GetFileName(path);
            string extension = SFUtil.GetRealExtension(filename);

            cmbMTD.Enabled = false;
            cmbMTD.Items.Clear();

            mtdBnd = null;
            mtd    = null;

            var mtdItems = new List <MTDWrapper>();

            try
            {
                if (MTD.Is(path))
                {
                    mtdItems.Add(new MTDWrapper(MTD.Read(path), filename));
                }
                else if (BND3.Is(path))
                {
                    mtdBnd = BND3.Read(path);
                    foreach (BinderFile file in mtdBnd.Files)
                    {
                        if (MTD.Is(file.Bytes))
                        {
                            mtdItems.Add(new MTDWrapper(MTD.Read(file.Bytes), file.Name));
                        }
                    }
                }
                else if (BND4.Is(path))
                {
                    mtdBnd = BND4.Read(path);
                    foreach (BinderFile file in mtdBnd.Files)
                    {
                        if (MTD.Is(file.Bytes))
                        {
                            mtdItems.Add(new MTDWrapper(MTD.Read(file.Bytes), file.Name));
                        }
                    }
                }
                else
                {
                    ShowError($"Unrecognized file type:\r\n{path}", silent);
                    return;
                }
            }
            catch (Exception ex)
            {
                ShowError($"Failed to load file:\r\n{path}\r\n{ex}", silent);
                return;
            }

            statusStripMTDPath.Text = path;
            mtdItems.Sort((i1, i2) => i1.Name.CompareTo(i2.Name));
            cmbMTD.Items.AddRange(mtdItems.ToArray());
            cmbMTD.SelectedIndex = 0;

            if (mtdItems.Count > 1)
            {
                cmbMTD.Enabled = true;
            }
        }
Beispiel #18
0
        public static LoadParamsResult LoadParams(string paramPath, Dictionary <string, ParamInfo> paramInfo,
                                                  Dictionary <string, PARAM64.Layout> layouts, bool hideUnusedParams)
        {
            if (!File.Exists(paramPath))
            {
                ShowError($"Parambnd not found:\r\n{paramPath}\r\nPlease browse to the Data0.bdt or parambnd you would like to edit.");
                return(null);
            }

            var result = new LoadParamsResult();

            try
            {
                if (BND4.Is(paramPath))
                {
                    result.ParamBND  = BND4.Read(paramPath);
                    result.Encrypted = false;
                }
                else
                {
                    result.ParamBND  = SFUtil.DecryptDS3Regulation(paramPath);
                    result.Encrypted = true;
                }
            }
            catch (DllNotFoundException ex) when(ex.Message.Contains("oo2core_6_win64.dll"))
            {
                ShowError("In order to load Sekiro params, you must copy oo2core_6_win64.dll from Sekiro into Yapped's lib folder.");
                return(null);
            }
            catch (Exception ex)
            {
                ShowError($"Failed to load parambnd:\r\n{paramPath}\r\n\r\n{ex}");
                return(null);
            }

            result.ParamWrappers = new List <ParamWrapper>();
            foreach (BinderFile file in result.ParamBND.Files.Where(f => f.Name.EndsWith(".param")))
            {
                string name = Path.GetFileNameWithoutExtension(file.Name);
                if (paramInfo.ContainsKey(name))
                {
                    if (paramInfo[name].Blocked || paramInfo[name].Hidden && hideUnusedParams)
                    {
                        continue;
                    }
                }

                try
                {
                    PARAM64 param = PARAM64.Read(file.Bytes);
                    if (layouts.ContainsKey(param.ID))
                    {
                        PARAM64.Layout layout = layouts[param.ID];
                        if (layout.Size == param.DetectedSize)
                        {
                            string description = null;
                            if (paramInfo.ContainsKey(name))
                            {
                                description = paramInfo[name].Description;
                            }

                            var wrapper = new ParamWrapper(name, param, layout, description);
                            result.ParamWrappers.Add(wrapper);
                        }
                        else
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                    ShowError($"Failed to load param file: {name}.param\r\n\r\n{ex}");
                }
            }

            result.ParamWrappers.Sort();
            return(result);
        }
Beispiel #19
0
        public static bool LoadParamBND(bool forceReload)
        {
            string interroot = GameDataManager.InterrootPath;

            bool justNowLoadedParamBND = false;

            if (forceReload)
            {
                ParamBNDs.Clear();
                LoadedParams.Clear();

                BehaviorParam?.Clear();
                BehaviorParam_PC?.Clear();
                AtkParam_Pc?.Clear();
                AtkParam_Npc?.Clear();
                NpcParam?.Clear();
                EquipParamWeapon?.Clear();
                EquipParamProtector?.Clear();
                WepAbsorpPosParam?.Clear();
            }

            if (forceReload || !ParamBNDs.ContainsKey(GameDataManager.GameType))
            {
                ParamBNDs.Add(GameDataManager.GameType, null);

                if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DS1)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND3.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DS1R)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND3.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DES)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParamNA.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND3.Read($"{interroot}\\param\\GameParam\\GameParamNA.parambnd.dcx");
                    }
                    else if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND3.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.BB ||
                         GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.SDT)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") && File.Exists($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\param\\GameParam\\GameParam.parambnd.dcx");
                    }
                    else if (Directory.Exists($"{interroot}\\..\\param\\GameParam\\") && File.Exists($"{interroot}\\..\\param\\GameParam\\GameParam.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\..\\param\\GameParam\\GameParam.parambnd.dcx");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DS3)
                {
                    if (Directory.Exists($"{interroot}\\param\\GameParam\\") &&
                        File.Exists($"{interroot}\\param\\GameParam\\GameParam_dlc2.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\param\\GameParam\\GameParam_dlc2.parambnd.dcx");
                    }
                    else if (File.Exists($"{interroot}\\Data0.bdt"))
                    {
                        ParamBNDs[GameDataManager.GameType] = SFUtil.DecryptDS3Regulation($"{interroot}\\Data0.bdt");
                    }
                    else if (Directory.Exists($"{interroot}\\..\\param\\GameParam\\") &&
                             File.Exists($"{interroot}\\..\\param\\GameParam\\GameParam_dlc2.parambnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = BND4.Read($"{interroot}\\..\\param\\GameParam\\GameParam_dlc2.parambnd.dcx");
                    }
                    else if (File.Exists($"{interroot}\\..\\Data0.bdt"))
                    {
                        ParamBNDs[GameDataManager.GameType] = SFUtil.DecryptDS3Regulation($"{interroot}\\..\\Data0.bdt");
                    }
                    else
                    {
                        return(false);
                    }
                }
                else if (GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DS2SOTFS)
                {
                    if (File.Exists($"{interroot}\\enc_regulation.bnd.dcx"))
                    {
                        ParamBNDs[GameDataManager.GameType] = DarkSouls2.DS2GameParamUtil.DecryptDS2Regulation($"{interroot}\\enc_regulation.bnd.dcx");
                    }
                    else
                    {
                        return(false);
                    }
                    //System.Windows.Forms.MessageBox.Show("DS2 Params not supported yet.");
                    //LoadStuffFromParamBND(isClearAll: true);
                    //return true;
                }
                else
                {
                    throw new NotImplementedException();
                }

                justNowLoadedParamBND = true;
            }

            if (justNowLoadedParamBND || forceReload || GameTypeCurrentLoadedParamsAreFrom != GameDataManager.GameType)
            {
                LoadStuffFromParamBND(isDS2: GameDataManager.GameType == SoulsAssetPipeline.SoulsGames.DS2SOTFS);
            }

            return(true);
        }
Beispiel #20
0
        public static bool HasValidExtension(string path)
        {
            string ext = SFUtil.GetRealExtension(path);

            return(ValidExtensions.Contains(ext.ToLower()));
        }
Beispiel #21
0
        private void btnDump_Click(object sender, EventArgs e)
        {
            BND4 bnd;

            try
            {
                bnd = SFUtil.DecryptDS3Regulation(txtRegulation.Text);
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Failed to load regulation:\r\n\r\n{txtRegulation.Text}\r\n\r\n{ex}");
                return;
            }

            var translations = new Dictionary <string, string>();
            var xml          = new XmlDocument();

            xml.Load("translations.xml");

            foreach (XmlNode text in xml.SelectNodes("translations/text"))
            {
                string jp = text.SelectSingleNode("jp").InnerText;
                string en = text.SelectSingleNode("en").InnerText;
                translations[WebUtility.HtmlDecode(jp)] = WebUtility.HtmlDecode(en);
            }

            var package = new ExcelPackage();

            foreach (BinderFile file in bnd.Files)
            {
                if (Path.GetExtension(file.Name) == ".param")
                {
                    PARAM64 param      = PARAM64.Read(file.Bytes);
                    string  layoutPath = $"Layouts\\{param.ID}.xml";

                    txtStatus.AppendText(file.Name + "\r\n");

                    var worksheet = package.Workbook.Worksheets.Add(Path.GetFileNameWithoutExtension(file.Name));

                    PARAM64.Layout layout;
                    if (File.Exists(layoutPath))
                    {
                        layout = PARAM64.Layout.ReadXMLFile(layoutPath);
                        if (layout.Size != param.DetectedSize)
                        {
                            layout = new PARAM64.Layout();
                            for (int i = 0; i < param.DetectedSize / 4; i++)
                            {
                                layout.Add(new PARAM64.Layout.Entry(CellType.u32, $"unk0x{i * 4:X4}", (uint)0));
                            }
                            for (int i = 0; i < param.DetectedSize % 4; i++)
                            {
                                layout.Add(new PARAM64.Layout.Entry(CellType.u8, "unkb" + i, (byte)0));
                            }
                        }
                    }
                    else
                    {
                        layout = new PARAM64.Layout();
                    }

                    param.SetLayout(layout);
                    List <PARAM64.Row> rows = param.Rows;

                    worksheet.Cells[1, 1].Value = "ID";
                    worksheet.Cells[1, 2].Value = "Name";
                    worksheet.Cells[1, 3].Value = "Translated";
                    int columnCount = 3;
                    foreach (PARAM64.Layout.Entry lv in layout)
                    {
                        if (lv.Type != CellType.dummy8)
                        {
                            worksheet.Cells[1, ++columnCount].Value = lv.Name;
                        }
                    }

                    for (int i = 0; i < rows.Count; i++)
                    {
                        PARAM64.Row row = rows[i];
                        worksheet.Cells[i + 2, 1].Value = row.ID;
                        if (row.Name != null)
                        {
                            if (translations.ContainsKey(row.Name))
                            {
                                worksheet.Cells[i + 2, 2].Value = row.Name;
                                worksheet.Cells[i + 2, 3].Value = translations[row.Name];
                            }
                            else if (row.Name.Contains(" -- "))
                            {
                                worksheet.Cells[i + 2, 2].Value = row.Name.Substring(row.Name.IndexOf(" -- ") + 4);
                                worksheet.Cells[i + 2, 3].Value = row.Name.Substring(0, row.Name.IndexOf(" -- "));
                            }
                        }
                        else
                        {
                            worksheet.Cells[i + 2, 2].Value = row.Name;
                        }
                        columnCount = 3;

                        foreach (PARAM64.Cell cell in row.Cells)
                        {
                            CellType type = cell.Type;
                            if (type != CellType.dummy8)
                            {
                                var range = worksheet.Cells[i + 2, ++columnCount];
                                if (type == CellType.f32)
                                {
                                    range.Value = (double)(float)cell.Value;
                                }
                                else if (type == CellType.b8 || type == CellType.b32)
                                {
                                    bool b = (bool)cell.Value;
                                    range.Value = b.ToString();
                                    range.Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                                    range.Style.Fill.BackgroundColor.SetColor(b ? Color.LightGreen : Color.LightPink);
                                }
                                else if (type == CellType.x8)
                                {
                                    range.Value = $"0x{cell.Value:X2}";
                                    range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right;
                                }
                                else if (type == CellType.x16)
                                {
                                    range.Value = $"0x{cell.Value:X4}";
                                    range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right;
                                }
                                else if (type == CellType.x32)
                                {
                                    range.Value = $"0x{cell.Value:X8}";
                                    range.Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Right;
                                }
                                else
                                {
                                    range.Value = cell.Value;
                                }
                            }
                        }
                    }

                    worksheet.Row(1).Style.Font.Bold    = true;
                    worksheet.Column(1).Style.Font.Bold = true;
                    worksheet.View.FreezePanes(2, 4);
                    worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
                }
            }

            FileInfo f = new FileInfo(Path.Combine(txtOutput.Text, "dump.xlsx"));

            package.SaveAs(f);
        }
Beispiel #22
0
        public static LoadParamsResult LoadParams(string paramPath, Dictionary <string, ParamInfo> paramInfo,
                                                  Dictionary <string, PARAM.Layout> layouts, Dictionary <BinderFile, ParamWrapper> fileWrapperCache, GameMode gameMode, bool hideUnusedParams)
        {
            if (!File.Exists(paramPath))
            {
                ShowError($"Parambnd类型文件 {paramPath} 不存在!\r\n请选定要给要编辑的Data0.bdt文件或Parambnd类型文件。");
                return(null);
            }

            var result = new LoadParamsResult();

            try
            {
                if (BND4.Is(paramPath))
                {
                    result.ParamBND  = BND4.Read(paramPath);
                    result.Encrypted = false;
                }
                else if (BND3.Is(paramPath))
                {
                    result.ParamBND  = BND3.Read(paramPath);
                    result.Encrypted = false;
                }
                else if (gameMode.Game == GameMode.GameType.DarkSouls2)
                {
                    result.ParamBND  = DecryptDS2Regulation(paramPath);
                    result.Encrypted = true;
                }
                else if (gameMode.Game == GameMode.GameType.DarkSouls3)
                {
                    result.ParamBND  = SFUtil.DecryptDS3Regulation(paramPath);
                    result.Encrypted = true;
                }
                else
                {
                    throw new FormatException("无法识别文件的数据格式!");
                }
            }
            catch (DllNotFoundException ex) when(ex.Message.Contains("oo2core_6_win64.dll"))
            {
                ShowError("为了加载Sekiro参数,必须将文件oo2core_6_win64.dll从Sekiro复制到文件DSParamEditor.exe的同一目录中。");
                return(null);
            }
            catch (Exception ex)
            {
                ShowError($"加载Parambnd类型文件失败!\r\n{paramPath}\r\n\r\n{ex}");
                return(null);
            }

            fileWrapperCache.Clear();
            result.ParamWrappers = new List <ParamWrapper>();
            foreach (var file in result.ParamBND.Files.Where(f => f.Name.EndsWith(".param")))
            {
                var name = Path.GetFileNameWithoutExtension(file.Name);
                if (paramInfo.ContainsKey(name))
                {
                    if (paramInfo[name].Blocked || paramInfo[name].Hidden && hideUnusedParams)
                    {
                        continue;
                    }
                }

                try
                {
                    var          param  = PARAM.Read(file.Bytes);
                    PARAM.Layout layout = null;
                    if (layouts.ContainsKey(param.ParamType))
                    {
                        layout = layouts[param.ParamType];
                    }

                    string description = null;
                    if (paramInfo.ContainsKey(name))
                    {
                        description = paramInfo[name].Description;
                    }

                    var wrapper = new ParamWrapper(name, param, layout, description);
                    result.ParamWrappers.Add(wrapper);
                    fileWrapperCache[file] = wrapper;
                }
                catch (Exception ex)
                {
                    ShowError($"加载参数文件:{name}.param失败!\r\n\r\n{ex}");
                }
            }

            result.ParamWrappers.Sort();
            return(result);
        }