Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple the decode functions from BlockData #42

Open
nikitalita opened this issue Nov 5, 2024 · 3 comments
Open

Decouple the decode functions from BlockData #42

nikitalita opened this issue Nov 5, 2024 · 3 comments

Comments

@nikitalita
Copy link

The fact that the decoding functions are coupled to BlockData makes it impossible to use them to decode a buffer in memory rather than a file. Is it possible to split these out into their own module so that they can be used outside of BlockData?

@K0lb3
Copy link

K0lb3 commented Nov 14, 2024

You can hack around the issue until a solution might be implemented in etcpak.

Mind that the hack is basically black magic that should never be used in protection.

#define _ALLOW_KEYWORD_MACROS
#define protected public
#define private public
#include "BlockData.hpp"
#undef protected
#undef private
#undef _ALLOW_KEYWORD_MACROS

The _ALLOW_KEYWORD_MACROS is for msvc, as it otherwise complaines about the short term redefinition of protected and public.

With this you can completely use BlockData in your own code.
e.g.

    v2i size(width, height);
    BlockData blockData(size, false, blockDataType);
    memcpy(
        blockData.m_data + blockData.m_dataOffset,
        data,
        data_size);

    BitmapPtr decodedBitmap = blockData.Decode();

    PyObject *res = Py_BuildValue(
        "y#",
        decodedBitmap->m_data,
        decodedBitmap->m_size.x * decodedBitmap->m_size.y * 4);

@nikitalita
Copy link
Author

To be clear, I’ve already done this myself; I’m just wondering if you would accept a PR

@wolfpld
Copy link
Owner

wolfpld commented Nov 15, 2024

Probably yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants