• Stars
    star
    153
  • Rank 242,472 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Texture2D exporter, kind of

Unity Texture Toolkit

written in PHP

What's this for

I wrote this for automatic game resource updating and dumping to png/webp, it's currently deployed on my server https://redive.estertion.win/
Main codes are highly inspired by AssetStudio

Requirement

php-ext-lz4 ( For decompressing the bundle )
astcenc ( For decompressing ASTC texture format )
ffmpeg ( For reencoding )
astcenc and ffmepg need to be placed under PATH, like /usr/bin (cron may not search for /usr/local/bin, or you can configure it)

Limitation

Current supported format:

  • ASTC compressed 2d image
  • Raw rgb ( e.g. RGB24 RGB565 RGBA4444 etc )

I've only met these formats so far

How to use

require_once 'UnityAsset.php'; // This will require UnityBundle.php as it needs FileStream

$bundleFileName = 'bundle_name.unity3d'; // This is the bundle file with file header "UnityFS"
$bundleFileStream = new FileStream($bundleFileName); // Create a read stream
$assetsList = extractBundle($bundleFileStream); // This will extract assets to disk
unset($bundleFileStream); // Free the handle

foreach ($assetsList as $asset) {
  if (substr($asset, -4,4) == '.resS') continue; // .resS file is external data storage file
  $asset = new AssetFile($asset);

  foreach ($asset->preloadTable as &$item) {
    if ($item->typeString == 'Texture2D') {
      $item = new Texture2D($item, true); // Parse and read data
      $item->exportTo($item->name, 'webp', '-lossless 1'); // export to format, with additional encode parameters
      // $item->exportTo($item->name, 'png');
      unset($item); // Free up memory
    }
  }
  $asset->__desctruct();
  unset($asset); // Free up memory
}
foreach ($assetsList as $asset) {
  unlink($asset); // clean up files
}

What's in the sub directory

These are the files I'm croning on my server for automatic update
There are different versions, as I wrote the Princess Connect Re:dive first, its code has least feature, and cgss is the current latest
They all share the same UnityBundle.php

Implementation detail

  1. UnityBundle.php

class FileStream($filename) and MemoryStream($data):
Two similar stream reader, FileStream accepts filename, MemoryStream accepts string as binary.
Reading value can perform either function $stream->readInt32() or property $stream->ulong
Property position can get current and set to seek point
Property littleEndian determine either use little endian reading or not
Function write($newData) will always write to the end for MemoryStream, but can overwrite current data position for FileStream

function extractBundle($bundleStream):
Accepts a stream, may throw exception if is invalid file, or chunk is LZMA compressed, or something wrong happened
Returns a list of asset file names extracted

  1. UnityAsset.php

class AssetFile($assetFileName):
Accepts a filename, may throw exception if something is not supported
Can get resource info through property preloadTable

class Texture2D($preloadData, $readSwitch = false):
Accepts an AssetPreloadData item from preloadTable, may throw an exception if format not supported
Second parameter determine weither read data or not, if you only want to get the information
Can call member function exportTo($saveTo, $format = 'png', $extraEncodeParam = '') to export supported texture

More Repositories

1

Youku-HTML5-Player

一个适配优酷的简单易用的HTML5播放器
JavaScript
757
star
2

AcFun-HTML5-Player

一个装B播放器,送给缺B乐的各位
JavaScript
335
star
3

redive_master_db_diff

Diff repo to show the master database difference between TruthVersion change for game 《プリコネR》 Subscribe update pushes at https://redive.estertion.win/masterdb_subscription/
122
star
4

Brokenithm-iOS

Objective-C
76
star
5

BiliBili_crc2mid

Lighing quick instance for turning crc back to integer
HTML
73
star
6

CriWare-Key-Logger

Intercept and log CriWare hca key, both console and alert menu, as an iOS tweak. 拦截并记录CriWare hca密钥,同时输出至控制台与屏幕提示显示。iOS越狱扩展
Logos
32
star
7

ReplayKitEverywhere

Record app screen, everywhere, with the convenience of ReplayKit
Logos
26
star
8

bangdream_master_db_diff

Diff repo to show the master database difference between version change for game 《ガルバ》Game HP: https://bang-dream.bushimo.jp/. Subscribe update pushes at https://redive.estertion.win/masterdb_subscription/. Proto exportation: http://t.cn/RmSko4b
25
star
9

cgss_master_db_diff

Diff repo to show the master database difference between TruthVersion change for game 《デレステ》Game HP: http://cinderella.idolmaster.jp/sl-stage/. Subscribe update pushes at https://redive.estertion.win/masterdb_subscription/
20
star
10

JiNALE-NET

Player homepage for JiNALE @ https://my-aime.cn/
Vue
18
star
11

yumesute_master_db_diff

Diff repo to show the master database difference between version change for game 《ワールドダイスター 夢のステラリウム》Game HP: https://world-dai-star.com/game/
18
star
12

MercuryPlayer

某激烈脱水的滚筒洗衣机游戏的谱面播放器
JavaScript
16
star
13

UsmDemuxer

Simply demux the usm stream
C#
12
star
14

rizline_ios_assets

©PigeonGames 2022
6
star
15

MercuryConverter

JavaScript
5
star
16

hlsjs-mediaInfo-module

MediaInfo observer for hls.js
JavaScript
4
star
17

llas_master_db_diff

*Discontinued*《スクスタ》Game HP: https://lovelive-as.bushimo.jp/
3
star
18

BiliPlus-Processed-Log-Data

3
star
19

live_html5_lib

lib for live_html.user.js at https://greasyfork.org/zh-CN/scripts/27759-bilibili-html5-live
JavaScript
2
star
20

LightWeightMusicPlayer

A light weight music player for html5
JavaScript
2
star
21

bilibili-9th-anni-probe-data

b站九周年 陈睿补偿抽奖 中奖名单用户的转发动态爬取结果
PHP
2
star
22

bilibili-live-silver

Auto Live Silver - Shell
Shell
2
star
23

jbme933

mirror of https://jbme.qwertyoruiop.com/ @ https://estertion.github.io/jbme933/
HTML
2
star
24

estertion.github.io

https://estertion.github.io
2
star
25

tw_redive_master_db_diff

Diff repo to show the master database difference between TruthVersion change for game 《公主連結R》 Game HP: http://www.princessconnect.so-net.tw/. Subscribe update pushes at https://redive.estertion.win/masterdb_subscription/
TSQL
2
star
26

sbr_master_db_diff

Diff repo to show the master database difference between version change for game 《SHOW BY ROCK!! Fes A Live》Game HP: https://showbyrock-fes.com/.
1
star
27

BiliBili-pb_danmaku-reader

JavaScript
1
star
28

hatsunes_notes_notice

notice json for Hatsune's Notes app
1
star
29

pvrtc-decompress

Direct pvrtc decompress
C
1
star
30

yumesute-calc

*WIP* score calculator for ユメステ @ https://redive.estertion.win/wds/calc/
JavaScript
1
star