Code Monkey home page Code Monkey logo

wzlibcpp's Introduction

wzlibcpp

modern first, more easier, cleaner api and support cross-platform

Status

⬜️ utf8 formatted string with std::string

⬜️ remove all of older (deprecated) api - [[deprecated]] attribute is currently marked.

☑️ modern api

☑️ cross-platform

Dependencies

  • zlib
  • mio - for mmap (aka file mapping in windows)

Usage

#include <iostream>

#include <pystring.h>
#include <algorithm>

#include <wz/Wz.hpp>
#include <wz/Node.hpp>
#include <wz/File.hpp>
#include <wz/Directory.hpp>

template<typename T>
constexpr auto string(T iterable) {
    return std::wstring{iterable.begin(), iterable.end()};
}

template<typename T>
constexpr auto back(T iterable) {
    return std::string{iterable.begin(), iterable.end()};
}

template<typename T>
T pop(std::vector<T>& vec) {
    auto last = vec.back();
    vec.pop_back();
    return last;
}

wz::WzMap find_from_path(wz::Node* root, const std::wstring& path) {
    std::vector<std::string> next{};
    std::string s{};
    s.assign(path.begin(), path.end());
    pystring::split(s, next, "/");
    std::reverse(next.begin(), next.end());
    const auto current = string(pop(next));
    for (const auto& it : *root) {
        if (it.first == current) {
            if (next.empty()) {
                return root->get_children();
            }

            std::reverse(next.begin(), next.end());
            return find_from_path(root, string(pystring::join("/", next)));
        }
    }
    return {};
}

#define U8 static_cast<u8>
#define IV4(A,B,C,D) {U8(A),U8(B),U8(C),U8(D)}

int main() {

    const auto iv = IV4(0x45, 0x50, 0x33, 0x01);
    wz::File file(iv, "C:/classic maple/Character_original.wz");

    if (file.parse()) {
        auto node = find_from_path(file.get_root(), L"00002000.img");

        for (const auto& it : node) {
            std::wcout << it.first << ", " << it.second.size() << std::endl;
            auto* dir = dynamic_cast<wz::Directory*>(it.second[0]);
            if (dir && dir->is_image()) {
                auto* image = new wz::Node();
                dir->parse_image(image);

                for (const auto& n : *image) {
                    std::wcout << n.first << std::endl;
                }
            }
        }
    }

    return 0;
}

output

https://gist.github.com/SeaniaTwix/f8b7e7cc34c5761e9679efa491816b63

wzlibcpp's People

Contributors

pshocker avatar ellipsi2 avatar seania avatar anydream avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.