Assets downloader
This commit is contained in:
parent
b877ff2dbc
commit
04883a7cd7
7
utils/assets-downloader/.gitignore
vendored
Normal file
7
utils/assets-downloader/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
# XMake
|
||||
build/
|
||||
.xmake/
|
||||
|
||||
# Assets
|
||||
assets/
|
||||
*.data
|
37
utils/assets-downloader/README.md
Normal file
37
utils/assets-downloader/README.md
Normal file
@ -0,0 +1,37 @@
|
||||
## About assets
|
||||
|
||||
The game itself downloads (through the launcher) further resources from
|
||||
|
||||
```text
|
||||
https://resources.download.minecraft.net/
|
||||
```
|
||||
|
||||
> ⚠️ http://resources.download.minecraft.net/ no longer works - you must use https
|
||||
|
||||
The asset index for each version is linked in the `<version>.json`. An example url to the asset index could look like this
|
||||
|
||||
```text
|
||||
https://launchermeta.mojang.com/mc/assets/1.12/67e29e024e664064c1f04c728604f83c24cbc218/1.12.json
|
||||
```
|
||||
|
||||
Each resource in the file has a name (the field name of the resource object), a SHA1 hash, and a file size. The client currently downloads all resources in the index from
|
||||
|
||||
```text
|
||||
https://resources.download.minecraft.net/<first 2 hex letters of hash>/<whole hash>
|
||||
```
|
||||
|
||||
and stores them in
|
||||
|
||||
```text
|
||||
.minecraft/assets/objects/<first 2 hex letters of hash>/<whole hash>
|
||||
```
|
||||
|
||||
and a copy is stored in
|
||||
|
||||
```text
|
||||
.minecraft/assets/virtual/legacy/
|
||||
```
|
||||
|
||||
in the old format for versions that don't support the new system (1.7 and below)
|
||||
|
||||
ℹ️ From: https://wiki.vg/Game_files#Assets
|
6
utils/assets-downloader/compile.sh
Executable file
6
utils/assets-downloader/compile.sh
Executable file
@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
# build utility
|
||||
echo "Build: assets-x86_64-linux.data"
|
||||
base64 -w 0 build/linux/x86_64/release/assets-parser > assets-x86_64-linux.data
|
||||
echo "Build complete"
|
34
utils/assets-downloader/download-assets.sh
Executable file
34
utils/assets-downloader/download-assets.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
|
||||
UTILITY=$(mktemp)
|
||||
base64 -d assets-x86_64-linux.data > $UTILITY
|
||||
chmod +x $UTILITY
|
||||
|
||||
ASSETS=$($UTILITY assets/indexes/1.19.json)
|
||||
FILES=$(echo "$ASSETS" | wc -w)
|
||||
ASSETS_DIR=assets/objects
|
||||
|
||||
mkdir -p $ASSETS_DIR
|
||||
|
||||
FILE_COUNTER=0
|
||||
for FILE in $ASSETS
|
||||
do
|
||||
HASH=$(echo $FILE | cut -d ":" -f 1)
|
||||
SIZE=$(echo $FILE | cut -d ":" -f 2)
|
||||
|
||||
HASH_DIR=$ASSETS_DIR/${HASH:0:2}
|
||||
mkdir -p $HASH_DIR
|
||||
|
||||
if ! [ -f $HASH_DIR/$HASH ]; then
|
||||
curl --silent -o $HASH_DIR/$HASH "https://resources.download.minecraft.net/${HASH:0:2}/$HASH"
|
||||
fi
|
||||
|
||||
FILE_SIZE=$(wc -c $HASH_DIR/$HASH | cut -d " " -f 1)
|
||||
if (( $FILE_SIZE != $SIZE )); then
|
||||
rm $HASH_DIR/$HASH
|
||||
echo "Error download: $HASH"
|
||||
fi
|
||||
|
||||
FILE_COUNTER=$(($FILE_COUNTER + 1))
|
||||
echo -e "Progress: $FILE_COUNTER/$FILES"
|
||||
done
|
55
utils/assets-downloader/src/main.c
Normal file
55
utils/assets-downloader/src/main.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cjson/cJSON.h>
|
||||
|
||||
#define VERSION "0.0.0"
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
// printf("Assets Downloader for Minecraft Batch Launcher %s\n", VERSION);
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <assets.json>\n", argv[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ... */
|
||||
if (argc == 2 && strcmp(argv[1], "--help") == 0) {
|
||||
printf("Help:\n");
|
||||
printf(" --help\tShow help\n");
|
||||
printf(" --version\tShow version\n");
|
||||
return 0;
|
||||
} else if (argc == 2 && strcmp(argv[1], "--version") == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *index_file;
|
||||
char str[900000];
|
||||
char buffer[100];
|
||||
|
||||
index_file = fopen(argv[1], "r");
|
||||
while (fgets(buffer, sizeof(buffer), index_file)) {
|
||||
strcat(str, buffer);
|
||||
}
|
||||
fclose(index_file);
|
||||
|
||||
cJSON *json = cJSON_Parse(str);
|
||||
cJSON *assets_objects = cJSON_GetObjectItem(json, "objects");
|
||||
unsigned int assets_objects_size = cJSON_GetArraySize(assets_objects);
|
||||
|
||||
if (assets_objects) {
|
||||
cJSON *object = assets_objects->child;
|
||||
|
||||
while (object) {
|
||||
char *hash = cJSON_GetStringValue(cJSON_GetObjectItem(object, "hash"));
|
||||
unsigned int size =
|
||||
cJSON_GetNumberValue(cJSON_GetObjectItem(object, "size"));
|
||||
printf("%s:%d\n", hash, size);
|
||||
|
||||
object = object->next;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
28
utils/assets-downloader/xmake.lua
Normal file
28
utils/assets-downloader/xmake.lua
Normal file
@ -0,0 +1,28 @@
|
||||
set_project("assets-parser")
|
||||
set_languages("c99")
|
||||
add_rules("mode.debug", "mode.release")
|
||||
|
||||
toolchain("tcc")
|
||||
set_kind("standalone")
|
||||
set_toolset("cc", "tcc")
|
||||
set_toolset("ld", "tcc")
|
||||
toolchain_end()
|
||||
|
||||
if is_mode("debug") then
|
||||
set_symbols("debug")
|
||||
set_optimize("none")
|
||||
end
|
||||
|
||||
set_toolchains("tcc")
|
||||
|
||||
add_requires("cjson 1.7.15")
|
||||
|
||||
target("assets-parser")
|
||||
set_kind("binary")
|
||||
add_files("src/*.c")
|
||||
add_packages("cjson")
|
||||
|
||||
after_build(function (target)
|
||||
-- os.exec("base64 -w 0 build/linux/x86_64/release/assets-parser > assets-x86_64-linux.data")
|
||||
os.exec("./compile.sh")
|
||||
end)
|
Loading…
Reference in New Issue
Block a user