You've already forked KemoFureApi
refactor
This commit is contained in:
45
modules/Shared/convert.py
Normal file
45
modules/Shared/convert.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import io
|
||||
import os
|
||||
import UnityPy
|
||||
from UnityPy import enums
|
||||
from UnityPy.files import ObjectReader
|
||||
from PIL import Image
|
||||
|
||||
def convert(input_path : str, output_path : str, platform = enums.BuildTarget.WebGL, enable_read = False):
|
||||
env = UnityPy.load(input_path)
|
||||
|
||||
for item in env.assets:
|
||||
item._m_target_platform = int(platform)
|
||||
|
||||
for obj in env.objects:
|
||||
if obj.type == enums.ClassIDType.Texture2D:
|
||||
convert_texture(obj, platform)
|
||||
if enable_read and obj.type == enums.ClassIDType.Mesh:
|
||||
data = obj.read()
|
||||
data.m_IsReadable = True
|
||||
data.save()
|
||||
|
||||
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
||||
with open(output_path, "wb") as f:
|
||||
f.write(env.file.save(packer="lz4"))
|
||||
|
||||
def extract(input_path : str, output_path : str):
|
||||
env = UnityPy.load(input_path)
|
||||
|
||||
for obj in env.objects:
|
||||
if obj.type == enums.ClassIDType.Texture2D:
|
||||
os.makedirs(output_path, exist_ok=True)
|
||||
data = obj.read()
|
||||
data.image.save(output_path + data.name + ".png", format="PNG")
|
||||
|
||||
def convert_texture(obj : ObjectReader, target_platform : enums.BuildTarget):
|
||||
if target_platform == enums.BuildTarget.WebGL:
|
||||
data = obj.read()
|
||||
with io.BytesIO() as output:
|
||||
data.image.save(output, format="PNG")
|
||||
if data.image.width % 4 == 0 and data.image.height % 4 == 0:
|
||||
data.m_TextureFormat = enums.TextureFormat.DXT5
|
||||
else:
|
||||
data.m_TextureFormat = enums.TextureFormat.ARGB32
|
||||
data.image = Image.open(output)
|
||||
data.save()
|
||||
9
modules/Shared/downloading.py
Normal file
9
modules/Shared/downloading.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import aiohttp
|
||||
|
||||
async def download_bytes(url, session : aiohttp.ClientSession):
|
||||
async with session.get(url) as resp:
|
||||
return await resp.read()
|
||||
|
||||
async def download_text(url, session : aiohttp.ClientSession):
|
||||
async with session.get(url) as resp:
|
||||
return await resp.text()
|
||||
3
modules/Shared/utility.py
Normal file
3
modules/Shared/utility.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def divide_chunks(l, n):
|
||||
for i in range(0, len(l), n):
|
||||
yield l[i:i + n]
|
||||
Reference in New Issue
Block a user