unnamed / creative

A resource-pack library for Minecraft: Java Edition
https://unnamed.team/docs/creative
MIT License
114 stars 13 forks source link

Anti-Unzip and better compressing #6

Closed Codestech1 closed 1 year ago

Codestech1 commented 1 year ago

If you can - please make this in this library https://github.com/ComunidadAylas/PackSquash

dev-hydrogen commented 1 year ago

that program is written in rust and practically impossible to integrate


From: HEROOSTECH @.> Sent: Tuesday, October 11, 2022 8:31:47 PM To: unnamed/creative @.> Cc: Subscribed @.***> Subject: [unnamed/creative] Anti-Unzip and better compressing (Issue #6)

If you can - please make this in this library https://github.com/ComunidadAylas/PackSquash

— Reply to this email directly, view it on GitHubhttps://github.com/unnamed/creative/issues/6, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXCAPNI27SERZFQ4J4JCYNDWCWQAHANCNFSM6AAAAAARCQJWEI. You are receiving this because you are subscribed to this thread.Message ID: @.***>

pixeldev commented 1 year ago

that program is written in rust and practically impossible to integrate ____ From: HEROOSTECH @.> Sent: Tuesday, October 11, 2022 8:31:47 PM To: unnamed/creative @.> Cc: Subscribed @.> Subject: [unnamed/creative] Anti-Unzip and better compressing (Issue #6) If you can - please make this in this library https://github.com/ComunidadAylas/PackSquash — Reply to this email directly, view it on GitHub<#6>, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AXCAPNI27SERZFQ4J4JCYNDWCWQAHANCNFSM6AAAAAARCQJWEI. You are receiving this because you are subscribed to this thread.Message ID: @.>

It's not impossible since JVM allow you to write native code, so, you can execute Rust code but it's a very bad idea.

Codestech1 commented 1 year ago

Just look to code and port this to java. ItemsAdder spigot plugin made this. I can help if you want. (I can't rust)

dev-hydrogen commented 1 year ago

Just look to code and port this to java. ItemsAdder spigot plugin made this. I can help if you want. (I can't rust)

it isnt as easy as "just looking at the code", especially when itemsadder is closed-source+paid and the program you provided is in rust. Compression of the zip that creative makes is a valid concern, but it would be somewhat complicated to implement, and as the maintainer of creative hasnt worked on the project for a while, all you can really do right now is to implement it yourself and make a pull request

Septicuss commented 1 year ago

Oraxen has done the simplest of resource pack protections as seen here. Can be done by playing around with Javas default zip utils.

                zipEntry.setCrc(bytes.length);
                zipEntry.setSize(new BigInteger(bytes).mod(BigInteger.valueOf(Long.MAX_VALUE)).longValue());
yusshu commented 1 year ago

"Protection" can now be done using the new ZipEntryLifecycleHandler, part of the serializer-minecraft subproject (Protection code inspired on Oraxen, only included in this example)

class ProtectingZipEntryLifecycleHandler implements ZipEntryLifecycleHandler {

    private final Random random = new Random();

    @Override
    public ZipEntry create(String path) {
        return ZipEntryLifecycleHandler.DEFAULT.create(path);
    }

    @Override
    public void onClose(ZipEntry entry) {
        // from Oraxen
        byte[] bytes = new byte[1024];
        random.nextBytes(bytes);
        entry.setCrc(bytes.length);
        entry.setSize(new BigInteger(bytes).mod(BigInteger.valueOf(Long.MAX_VALUE)).longValue());;
    }
}

And then using it when you create a FileTreeWriter

try (FileTreeWriter writer = FileTreeWriter.zip(
        new ZipOutputStream(...),
        new ProtectingZipEntryLifecycleHandler()
)) {
   ...
}

Compressing is already done for most resources. Users can minify Texture and Sound too by using some library like pngtastic for textures and another library for sounds (OGGS), maybe port one to Java?