Beispiel #1
0
    TitleSequence * LoadTitleSequence(const utf8 * path)
    {
        size_t scriptLength;
        char * script;
        std::vector<utf8 *> saves;
        bool isZip;

        log_verbose("Loading title sequence: %s", path);

        const utf8 * ext = Path::GetExtension(path);
        if (String::Equals(ext, TITLE_SEQUENCE_EXTENSION))
        {
            IZipArchive * zip = Zip::TryOpen(path, ZIP_ACCESS_READ);
            if (zip == nullptr)
            {
                Console::Error::WriteLine("Unable to open '%s'", path);
                return nullptr;
            }

            script = (char *)zip->GetFileData("script.txt", &scriptLength);
            if (script == nullptr)
            {
                Console::Error::WriteLine("Unable to open script.txt in '%s'", path);
                delete zip;
                return nullptr;
            }

            saves = GetSaves(zip);
            isZip = true;

            delete zip;
        }
        else
        {
            utf8 scriptPath[MAX_PATH];
            String::Set(scriptPath, sizeof(scriptPath), path);
            Path::Append(scriptPath, sizeof(scriptPath), "script.txt");
            script = (char *)ReadScriptFile(scriptPath, &scriptLength);
            if (script == nullptr)
            {
                Console::Error::WriteLine("Unable to open '%s'", scriptPath);
                return nullptr;
            }

            saves = GetSaves(path);
            isZip = false;
        }

        std::vector<TitleCommand> commands = LegacyScriptRead(script, scriptLength, saves);

        TitleSequence * seq = CreateTitleSequence();
        seq->Name = Path::GetFileNameWithoutExtension(path);
        seq->Path = String::Duplicate(path);
        seq->NumSaves = saves.size();
        seq->Saves = Collections::ToArray(saves);
        seq->NumCommands = commands.size();
        seq->Commands = Collections::ToArray(commands);
        seq->IsZip = isZip;
        return seq;
    }
Beispiel #2
0
TitleSequence* LoadTitleSequence(const utf8* path)
{
    std::vector<uint8_t> script;
    std::vector<utf8*> saves;
    bool isZip;

    log_verbose("Loading title sequence: %s", path);

    const utf8* ext = Path::GetExtension(path);
    if (String::Equals(ext, TITLE_SEQUENCE_EXTENSION))
    {
        auto zip = std::unique_ptr<IZipArchive>(Zip::TryOpen(path, ZIP_ACCESS::READ));
        if (zip == nullptr)
        {
            Console::Error::WriteLine("Unable to open '%s'", path);
            return nullptr;
        }

        script = zip->GetFileData("script.txt");
        if (script.empty())
        {
            Console::Error::WriteLine("Unable to open script.txt in '%s'", path);
            return nullptr;
        }

        saves = GetSaves(zip.get());
        isZip = true;
    }
    else
    {
        utf8 scriptPath[MAX_PATH];
        String::Set(scriptPath, sizeof(scriptPath), path);
        Path::Append(scriptPath, sizeof(scriptPath), "script.txt");
        script = ReadScriptFile(scriptPath);
        if (script.empty())
        {
            Console::Error::WriteLine("Unable to open '%s'", scriptPath);
            return nullptr;
        }

        saves = GetSaves(path);
        isZip = false;
    }

    auto commands = LegacyScriptRead((utf8*)script.data(), script.size(), saves);

    TitleSequence* seq = CreateTitleSequence();
    seq->Name = Path::GetFileNameWithoutExtension(path);
    seq->Path = String::Duplicate(path);
    seq->NumSaves = saves.size();
    seq->Saves = Collections::ToArray(saves);
    seq->NumCommands = commands.size();
    seq->Commands = Collections::ToArray(commands);
    seq->IsZip = isZip;
    return seq;
}