1 Star 0 Fork 0

antoineli/UnityPy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
get_scriptable_texture.py 1.51 KB
一键复制 编辑 原始数据 按行查看 历史
K0lb3 提交于 4年前 . 1.5.2
"""
This example shows how to write a custom MonoBehaviour class.
The script is for a game that generates its encryption key based on a specific image.
This image is linked to by a MonoBheaviour called "ScriptableTexture2D".
It is linked to by a pointer after the default MonoBehaviour structure.
This intel was acquired from the assembly of the game.
Unfortunately, the asset doesn't have a type-tree, so the default MonoBehaviour class can't find the pointer.
So a custom MonoBehaviour class is required to get the pointer comfortably.
Doing so is simple, as seen in the following code.
"""
import os
import UnityPy
from UnityPy.classes import MonoBehaviour, PPtr
class ScriptableTexture2D(MonoBehaviour):
def __init__(self, reader):
# calls the default MonoBehaviour init
super().__init__(reader=reader)
# here goes the implementation of the extra data
self.texture = PPtr(reader)
# set the path for the target file
root = os.path.dirname(os.path.realpath(__file__))
fp = os.path.join(root,"data.unity3d")
env = UnityPy.load(fp)
# find the correct asset
for obj in env.objects:
if obj.type == "MonoBehaviour":
data = obj.read()
if data.name == "ScriptableTexture2D":
# correct obj found
# lets read it with the custom class
st = ScriptableTexture2D(obj)
# read the linked image and save it
tex = st.texture.read()
print(st.texture.read().name)
#tex.image.save(os.path.join(root, f"{tex.name}.png"))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/antoineli/unity-py.git
git@gitee.com:antoineli/unity-py.git
antoineli
unity-py
UnityPy
master

搜索帮助