Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to get textual representation of MonoBehaviour type? #13

Closed
UserUnknownFactor opened this issue Aug 19, 2020 · 3 comments
Closed

Comments

@UserUnknownFactor
Copy link
Contributor

For example UABE can show the type like this: 0xFFFFFFFF (MonoBehaviour : UnityEngine.UI.Image (UnityEngine.UI.dll)).
Is there a way to reproduce this with UnityPy?
I don't really know specifics of the storage so I couldn't find where this information is...

@K0lb3
Copy link
Owner

K0lb3 commented Aug 20, 2020

I'm not sure how UABE links to the dlls and I never bothered with it, since most modern games use il2cpp.

Usually, MonoBehaviour objects contain a custom type tree that is used as a variable input for specific functions.
The use is quite diverse, e.g. as instruction set for how to assemble and transform multiple images for a UI, as a list for all game asset files, .....

@K0lb3
Copy link
Owner

K0lb3 commented Aug 20, 2020

image

The reference to a function of a dll isn't necessary either and if it exists, it's saved as a string.

@UserUnknownFactor
Copy link
Contributor Author

UserUnknownFactor commented Sep 2, 2020

Yay, found it. It turns out UABE shows namespace and assembly_name of the underlying MonoScript object there. That got me confused. And the MonoScript always have them so they can be used like that. It's nice to know that MonoBehaviours can contain TypeName though.

Here is the code for AssetBatchConverter.py I used to extract MonoBehaviours into separate folders by their corresponding namespace:

def export_obj(obj, fpath: str, asset: str) -> list:
  format = obj.type
  if format not in TYPES: return []

  data = obj.read()
  name = data.name if (data.name is not None and data.name != '') else "unnamed asset"
  fname, extension = os.path.splitext(name)

  name = "%s-%s-%d" % (fname, asset, obj.path_id)
  fp = os.path.join(fpath, name)
  elif format == 'MonoBehaviour':
    extension = ".dat"
    script = data.script.read()
    if not script: return [obj.path_id]
    fp = os.path.join(fpath, script.namespace, script.class_name, name)
    os.makedirs(os.path.dirname(fp), exist_ok=True)
    with open(f"{fp}{extension}", "wb") as f: f.write(data.get_raw_data())
    return [obj.path_id]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants