Ejemplo n.º 1
0
        public async Task <DataContent> GetContentAsync()
        {
            if (VirtualAddress == 0 || Size == 0)
            {
                return(null);
            }

            switch (DirectoryType)
            {
            case DataDirectoryType.LoadConfigTable:
                return(await LoadConfigurationDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.TLSTable:
                return(await TLSDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.CertificateTable:
                return(await Certificate.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.CLRRuntimeHeader:
                return(await CLR.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.Debug:
                return(await DebugDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.BaseRelocationTable:
                return(await RelocationTable.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.ExportTable:
                return(await ExportDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.ImportTable:
                return(await ImportDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.DelayImportDescriptor:
                return(await DelayedImportDirectory.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.ExceptionTable:
                return(await ExceptionTable.GetAsync(_image).ConfigureAwait(false));

            case DataDirectoryType.ResourceTable:
                return(await ResourceDirectory.GetAsync(_image).ConfigureAwait(false));

            default:
            {
                var calc       = _image.GetCalculator();
                var fileOffset = calc.RVAToOffset(VirtualAddress);
                var va         = _imageBase + VirtualAddress;
                var location   = new Location(_image, fileOffset, VirtualAddress, va, Size, Size);

                return(new DataContent(_image, this, location));
            }
            }
        }
Ejemplo n.º 2
0
        protected override async UniTask Load()
        {
            try {
                if (gameDataBinFolder == null || gameDataBinFolder.Trim().Equals(""))
                {
                    throw new Exception("GAMEDATABIN folder doesn't exist");
                }
                if (lvlName == null || lvlName.Trim() == "")
                {
                    throw new Exception("No level name specified!");
                }
                globals            = new Globals();
                gameDataBinFolder += "/";
                await FileSystem.CheckDirectory(gameDataBinFolder);

                if (!FileSystem.DirectoryExists(gameDataBinFolder))
                {
                    throw new Exception("GAMEDATABIN folder doesn't exist");
                }

                loadingState = "Initializing files";
                await WaitIfNecessary();

                string gameDsbPath = gameDataBinFolder + ConvertCase("Game.dsb", Settings.CapsType.DSB);
                if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                {
                    gameDsbPath = gameDataBinFolder + ConvertCase("gamedsc.bin", Settings.CapsType.DSB);
                }
                else if (Settings.s.game == Settings.Game.TTSE)
                {
                    gameDsbPath = gameDataBinFolder + ConvertCase("GAME.DSC", Settings.CapsType.DSB);
                }
                await PrepareFile(gameDsbPath);

                gameDsb = new DSB("Game", gameDsbPath);
                if (FileSystem.mode != FileSystem.Mode.Web)
                {
                    gameDsb.Save(gameDataBinFolder + ConvertCase("Game_dsb.dmp", Settings.CapsType.DSB));
                }
                gameDsb.ReadAllSections();
                gameDsb.Dispose();

                await CreateCNT();

                if (Settings.s.game == Settings.Game.R2)
                {
                    string comportsPath = gameDataBinFolder + "R2DC_Comports.json";
                    await PrepareFile(comportsPath);
                }

                if (lvlName.EndsWith(".exe"))
                {
                    if (!Settings.s.hasMemorySupport)
                    {
                        throw new Exception("This game does not have memory support.");
                    }
                    Settings.s.loadFromMemory = true;
                    MemoryFile mem = new MemoryFile(lvlName);
                    files_array[0] = mem;
                    await WaitIfNecessary();
                    await LoadMemory();
                }
                else
                {
                    hasTransit = false;
                    DAT    dat             = null;
                    string levelsSubFolder = ConvertCase(ConvertPath(gameDsb.levelsDataPath), Settings.CapsType.All) + "/";
                    string levelsFolder    = gameDataBinFolder + levelsSubFolder;
                    string langDataPath    = gameDataBinFolder
                                             + ConvertCase("../LangData/English/", Settings.CapsType.All)
                                             + levelsSubFolder;
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                    {
                        await FileSystem.CheckDirectory(langDataPath);

                        if (FileSystem.mode != FileSystem.Mode.Web && !FileSystem.DirectoryExists(langDataPath))
                        {
                            string langPath = gameDataBinFolder + ConvertCase("../LangData/", Settings.CapsType.All);
                            await FileSystem.CheckDirectory(langPath);

                            if (FileSystem.DirectoryExists(langPath))
                            {
                                DirectoryInfo dirInfo   = new DirectoryInfo(langPath);
                                DirectoryInfo firstLang = dirInfo.GetDirectories().FirstOrDefault();
                                if (firstLang != null)
                                {
                                    langDataPath = firstLang.FullName + "/" + levelsSubFolder;
                                    await FileSystem.CheckDirectory(langDataPath);
                                }
                            }
                        }
                    }

                    await WaitIfNecessary();

                    bool hasRelocationFiles = true;
                    if (Settings.s.mode == Settings.Mode.Rayman2PC || Settings.s.mode == Settings.Mode.DonaldDuckPC)
                    {
                        string dataPath = levelsFolder + "LEVELS0.DAT";
                        await PrepareBigFile(dataPath, 512 *1024);

                        if (FileSystem.FileExists(dataPath))
                        {
                            dat = new DAT("LEVELS0", gameDsb, dataPath);
                            hasRelocationFiles = false;
                        }
                    }

                    // Prepare folder names
                    string lvlFolder     = ConvertCase(lvlName + "/", Settings.CapsType.LevelFolder);
                    string langLvlFolder = ConvertCase(lvlName + "/", Settings.CapsType.LangLevelFolder);

                    // Prepare paths
                    paths["fix.sna"] = levelsFolder + ConvertCase("Fix.sna", Settings.CapsType.Fix);
                    paths["fix.rtb"] = levelsFolder + ConvertCase("Fix.rtb", Settings.CapsType.FixRelocation);
                    paths["fix.gpt"] = levelsFolder + ConvertCase("Fix.gpt", Settings.CapsType.Fix);
                    paths["fix.rtp"] = levelsFolder + ConvertCase("Fix.rtp", Settings.CapsType.FixRelocation);
                    paths["fix.ptx"] = levelsFolder + ConvertCase("Fix.ptx", Settings.CapsType.Fix);
                    paths["fix.rtt"] = levelsFolder + ConvertCase("Fix.rtt", Settings.CapsType.FixRelocation);
                    if (Settings.s.engineVersion < Settings.EngineVersion.R2)
                    {
                        paths["fixlvl.rtb"] = levelsFolder + lvlFolder + ConvertCase("FixLvl.rtb", Settings.CapsType.FixLvl);
                    }
                    else
                    {
                        paths["fixlvl.rtb"] = null;
                    }
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                    {
                        paths["fix.sda"]    = levelsFolder + ConvertCase("Fix.sda", Settings.CapsType.Fix);
                        paths["fix.lng"]    = langDataPath + ConvertCase("Fix.lng", Settings.CapsType.LangFix);
                        paths["fix.rtg"]    = langDataPath + ConvertCase("Fix.rtg", Settings.CapsType.FixRelocation);
                        paths["fix.dlg"]    = langDataPath + ConvertCase("Fix.dlg", Settings.CapsType.LangFix);
                        paths["fix.rtd"]    = langDataPath + ConvertCase("Fix.rtd", Settings.CapsType.FixRelocation);
                        paths["fixlvl.rtg"] = langDataPath + langLvlFolder + ConvertCase("FixLvl.rtg", Settings.CapsType.FixLvl);
                    }
                    else
                    {
                        paths["fix.sda"]    = null;
                        paths["fix.lng"]    = null;
                        paths["fix.rtg"]    = null;
                        paths["fix.dlg"]    = null;
                        paths["fix.rtd"]    = null;
                        paths["fixlvl.rtg"] = null;
                    }

                    paths["lvl.sna"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".sna", Settings.CapsType.LevelFile);
                    paths["lvl.gpt"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".gpt", Settings.CapsType.LevelFile);
                    paths["lvl.ptx"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".ptx", Settings.CapsType.LevelFile);
                    if (hasRelocationFiles)
                    {
                        paths["lvl.rtb"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".rtb", Settings.CapsType.LevelRelocation);
                        paths["lvl.rtp"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".rtp", Settings.CapsType.LevelRelocation);
                        paths["lvl.rtt"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".rtt", Settings.CapsType.LevelRelocation);
                    }
                    else
                    {
                        paths["lvl.rtb"] = null;
                        paths["lvl.rtp"] = null;
                        paths["lvl.rtt"] = null;
                    }
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal)
                    {
                        paths["lvl.sda"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".sda", Settings.CapsType.LevelFile);
                        paths["lvl.lng"] = langDataPath + langLvlFolder + ConvertCase(lvlName + ".lng", Settings.CapsType.LangLevelFile);
                        paths["lvl.rtg"] = langDataPath + langLvlFolder + ConvertCase(lvlName + ".rtg", Settings.CapsType.LangLevelFile);
                        paths["lvl.dlg"] = langDataPath + langLvlFolder + ConvertCase(lvlName + ".dlg", Settings.CapsType.LangLevelFile);
                        paths["lvl.rtd"] = langDataPath + langLvlFolder + ConvertCase(lvlName + ".rtd", Settings.CapsType.LangLevelRelocation);
                    }
                    else
                    {
                        paths["lvl.sda"] = null;
                        paths["lvl.lng"] = null;
                        paths["lvl.rtg"] = null;
                        paths["lvl.dlg"] = null;
                        paths["lvl.rtd"] = null;
                    }
                    paths["lvl.dsb"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".dsb", Settings.CapsType.DSB);
                    if (Settings.s.engineVersion < Settings.EngineVersion.R2)
                    {
                        paths["lvl.dsb"] = levelsFolder + lvlFolder + ConvertCase(lvlName + ".dsc", Settings.CapsType.DSB);
                    }

                    // Download files
                    foreach (KeyValuePair <string, string> path in paths)
                    {
                        if (path.Value != null)
                        {
                            await PrepareFile(path.Value);
                        }
                    }

                    // LEVEL DSB
                    await WaitIfNecessary();

                    if (FileSystem.FileExists(paths["lvl.dsb"]))
                    {
                        lvlDsb = new DSB(lvlName + ".dsc", paths["lvl.dsb"]);
                        if (FileSystem.mode != FileSystem.Mode.Web)
                        {
                            lvlDsb.Save(levelsFolder + lvlFolder + lvlName + "_dsb.dmp");
                        }
                        //lvlDsb.ReadAllSections();
                        lvlDsb.Dispose();
                    }

                    // FIX
                    RelocationTable fixRtb = new RelocationTable(paths["fix.rtb"], dat, "Fix", RelocationType.RTB);
                    await fixRtb.Init();

                    if (FileSystem.FileExists(paths["fixlvl.rtb"]))
                    {
                        // Fix -> Lvl pointers for Tonic Trouble
                        RelocationTable fixLvlRtb = new RelocationTable(paths["fixlvl.rtb"], dat, lvlName + "Fix", RelocationType.RTB);
                        await fixLvlRtb.Init();

                        fixRtb.Add(fixLvlRtb);
                    }
                    SNA fixSna = new SNA("Fix", paths["fix.sna"], fixRtb);
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal && FileSystem.DirectoryExists(langDataPath))
                    {
                        RelocationTable fixLangRTG = new RelocationTable(paths["fix.rtg"], dat, "fixLang", RelocationType.RTG);
                        await fixLangRTG.Init();

                        if (FileSystem.FileExists(paths["fixlvl.rtg"]))
                        {
                            RelocationTable fixLvlRTG = new RelocationTable(paths["fixlvl.rtg"], dat, lvlName + "FixLang", RelocationType.RTG);
                            await fixLvlRTG.Init();

                            fixLangRTG.Add(fixLvlRTG);
                        }
                        SNA fixLangSna = new SNA("fixLang", paths["fix.lng"], fixLangRTG);
                        await WaitIfNecessary();

                        fixSna.AddSNA(fixLangSna);

                        await WaitIfNecessary();

                        RelocationTable fixRtd = new RelocationTable(paths["fix.rtd"], dat, "fixLang", RelocationType.RTD);
                        await fixRtd.Init();

                        fixSna.ReadDLG(paths["fix.dlg"], fixRtd);
                    }
                    RelocationTable fixRtp = new RelocationTable(paths["fix.rtp"], dat, "fix", RelocationType.RTP);
                    await fixRtp.Init();

                    fixSna.ReadGPT(paths["fix.gpt"], fixRtp);

                    RelocationTable fixRtt = new RelocationTable(paths["fix.rtt"], dat, "fix", RelocationType.RTT);
                    await fixRtt.Init();

                    fixSna.ReadPTX(paths["fix.ptx"], fixRtt);

                    if (FileSystem.FileExists(paths["fix.sda"]))
                    {
                        fixSna.ReadSDA(paths["fix.sda"]);
                    }

                    // LEVEL
                    RelocationTable lvlRtb = new RelocationTable(paths["lvl.rtb"], dat, lvlName, RelocationType.RTB);
                    await lvlRtb.Init();

                    SNA lvlSna = new SNA(lvlName, paths["lvl.sna"], lvlRtb);
                    if (Settings.s.engineVersion == Settings.EngineVersion.Montreal && FileSystem.DirectoryExists(langDataPath))
                    {
                        RelocationTable lvlLangRTG = new RelocationTable(paths["lvl.rtg"], dat, lvlName + "Lang", RelocationType.RTG);
                        await lvlLangRTG.Init();

                        SNA lvlLangSna = new SNA(lvlName + "Lang", paths["lvl.lng"], lvlLangRTG);
                        await WaitIfNecessary();

                        lvlSna.AddSNA(lvlLangSna);
                        await WaitIfNecessary();

                        RelocationTable lvlRtd = new RelocationTable(paths["lvl.rtd"], dat, lvlName + "Lang", RelocationType.RTD);
                        await lvlRtd.Init();

                        lvlSna.ReadDLG(paths["lvl.dlg"], lvlRtd);
                    }

                    if (Settings.s.engineVersion > Settings.EngineVersion.TT)
                    {
                        RelocationTable lvlRtp = new RelocationTable(paths["lvl.rtp"], dat, lvlName, RelocationType.RTP);
                        await lvlRtp.Init();

                        lvlSna.ReadGPT(paths["lvl.gpt"], lvlRtp);
                        RelocationTable lvlRtt = new RelocationTable(paths["lvl.rtt"], dat, lvlName, RelocationType.RTT);
                        await lvlRtt.Init();

                        lvlSna.ReadPTX(paths["lvl.ptx"], lvlRtt);
                    }
                    else
                    {
                        lvlSna.ReadGPT(paths["lvl.gpt"], null);
                        lvlSna.ReadPTX(paths["lvl.ptx"], null);
                    }
                    if (FileSystem.FileExists(paths["lvl.sda"]))
                    {
                        await WaitIfNecessary();

                        lvlSna.ReadSDA(paths["lvl.sda"]);
                    }

                    await WaitIfNecessary();

                    fixSna.CreatePointers();
                    await WaitIfNecessary();

                    lvlSna.CreatePointers();

                    files_array[0] = fixSna;
                    files_array[1] = lvlSna;
                    files_array[2] = dat;

                    if (FileSystem.mode != FileSystem.Mode.Web)
                    {
                        await WaitIfNecessary();

                        fixSna.CreateMemoryDump(levelsFolder + "fix.dmp", true);
                        await WaitIfNecessary();

                        lvlSna.CreateMemoryDump(levelsFolder + lvlFolder + lvlName + ".dmp", true);
                    }

                    await LoadFIXSNA();
                    await LoadLVLSNA();

                    await WaitIfNecessary();

                    fixSna.Dispose();
                    lvlSna.Dispose();
                    if (dat != null)
                    {
                        dat.Dispose();
                    }
                }
            } finally {
                for (int i = 0; i < files_array.Length; i++)
                {
                    if (files_array[i] != null)
                    {
                        if (!(files_array[i] is MemoryFile))
                        {
                            files_array[i].Dispose();
                        }
                    }
                }
                if (cnt != null)
                {
                    cnt.Dispose();
                }
            }
            await WaitIfNecessary();

            InitModdables();
        }
Ejemplo n.º 3
0
 public RelocInfo(RelocationTable relocations) => Relocations = relocations;