Cache hash mismatch while using snakeoil native

I’ve been trying the snakeoil feature provided through adhesive to mess around with adding extra encryption to assets, however, I keep running into this issue.

I made a simple xor cipher utilizing the snakeoil factory. I output the data to ensure it’s deciphering correctly, and confirmed it is. It seems the issue here though is that there’s a hash mismatch between the cached version and the snakeoil version of the YDR file.

ResourceCache::AddEntry: Saved cache:v1:18d3119ca5f5ee4ad9d22eddd006fa14803905d9 to the index cache.
ResourceCache::AddEntry: Saved cache:v1:145270405ba17b45f4d57d6288d9d88e478222a5 to the index cache.
initializing snakeoil on: cube.ydr
decrypting cube.ydr 637 bytes via xor cipher
resources::ResourceCacheDeviceV2::DoFetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5 - redownloading
ResourceCache::AddEntry: Saved cache:v1:145270405ba17b45f4d57d6288d9d88e478222a5 to the index cache.
initializing snakeoil on: cube.ydr
decrypting cube.ydr 637 bytes via xor cipher
resources::ResourceCacheDeviceV2::DoFetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5 - redownloading
ResourceCache::AddEntry: Saved cache:v1:145270405ba17b45f4d57d6288d9d88e478222a5 to the index cache.
initializing snakeoil on: cube.ydr
decrypting cube.ydr 637 bytes via xor cipher
resources::ResourceCacheDeviceV2::DoFetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5 - redownloading
ResourceCache::AddEntry: Saved cache:v1:145270405ba17b45f4d57d6288d9d88e478222a5 to the index cache.
initializing snakeoil on: cube.ydr
decrypting cube.ydr 637 bytes via xor cipher
resources::ResourceCacheDeviceV2::DoFetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5 - redownloading
ResourceCache::AddEntry: Saved cache:v1:145270405ba17b45f4d57d6288d9d88e478222a5 to the index cache.
Failed to request compcache_nb:/snaketest/cube.ydr: Failed to fetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5. 
Failed to request compcache_nb:/snaketest/cube.ydr: Failed to fetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5. 
Failed to request compcache_nb:/snaketest/cube.ydr: Failed to fetch: cube.ydr hash d1cd4ad1027d7eddb7b6929d0e10378f60d0bbd1 does not match 145270405ba17b45f4d57d6288d9d88e478222a5. 

Here’s the simple xor cipher snakeoil code:

snakeoil.js
class oil {

	initialize(data) {
		this.metadata = data.metadata;
		print("initializing snakeoil on: " + this.metadata);
	}

	seek(off) {
		print("seeking: " + off);
	}

	decrypt(data) {
		print("decrypting "+this.metadata+" "+data.length+" bytes via xor cipher");
		for(var i = 0; i < data.length; i++) {
			data[i] = data[i] ^ 128;
		}
		return data;
	}
}

snakeoil = () => new oil();
cl_main.lua
function SetSnakeoilForEntry(name, path, data)
	Citizen.InvokeNative(0xa7dd3209, name, path, data)
end

SetSnakeoilForEntry('cube.ydr', 'snakeoil.js', '{"metadata": "cube.ydr"}') -- returns 1

I believe this is a bug with adhesive/caching as it seems to be a hash mismatch.

Have you actually encrypted the file on the server as well, and made a .stream_raw with the RSC header (or a copy of the original file) to match?

yeah, the file’s encrypted with a simple xor cipher on the server-side. Just tried adding the original file as a .stream_raw, but it didn’t seem to effect anything.

OK, might be a regression caused by local double-checking being done after adhesive has made a pass at the file.

Is there any workaround or do we have to wait for an adhesive update?

Neither.

Then snakeoil has no use?

Huh?

There’s no ‘workaround’ at this time, and the fix for this issue would not be in adhesive as it’s a public component incorrectly assuming some state, not adhesive.