Search Unity

Modifying IL2CPP stringliterals

Discussion in 'iOS and tvOS' started by brianasu, Jun 29, 2017.

  1. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    After I compile to XCode I sometimes directly modify the il2cpp code so I don't have to do a full recompile to test something. I'm just wondering if there is an easy way to modify a string literal to have a different value.

    Thanks/
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    I don't think that this is possible. IL2CPP encodes all of the string literal data in a binary file named global-metadata.dat. It is not something you can easily edit.

    Note that a change to a string literal should not cause the generated C++ code to recompile. The il2cpp.exe utility will run again, but it should not change any of the generated C++ code (so long as you are using the Append option for the iOS build). Then Xcode should not need to compile anything again.

    If you are seeing different behavior, there is a some bug in the incremental build process, and we would like to know about it.
     
  3. brianasu

    brianasu

    Joined:
    Mar 9, 2010
    Posts:
    369
    Ok thanks for the info. I guess I could just construct an IL2CPP String_t and pass it in. It looks like a utf16 chars.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    You can have a look at the Il2CppString class in the headers shipped with the Unity editor to understand the layout of the string structure. Indeed, the characters are stored as 2-byte UTF16 encoded values.
     
  5. ashikns

    ashikns

    Joined:
    Nov 23, 2016
    Posts:
    8
    The string_t struct has a single wchar_t variable. How can I create my own string_t and assign a string to it? How do I assign a string value to a single wchar_t variable?
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    It isn't really possible to do this. The implementation of the managed System.String object in native code generated by IL2CPP is not something that you want to be depending on. It could change in a future version, so we don't provide any support for constructor it manually.

    What is your end goal? Maybe there is a better way to achieve it that is supported.
     
  7. ernesb

    ernesb

    Joined:
    Feb 12, 2017
    Posts:
    32
    @JoshPeterson hi, sorry for raising an old thread, I could imagine some goal for this

    Let just say we want to change some id to init some third party plugins (ads, network, etc.) this might be a time saver for us to quickly change in xcode directly rather than waiting to export from unity again.

    A quick check before reexporting from unity to xcode could take a minute while in il2cpp before an xcode projects finish exported.

    In short, we want to change the string literal directly
    __this->set_ThirdPartyKey_8(_stringLiteral49240314);

    any idea on how to create a string_t so we could replace the string literal in xcode?
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,929
    The IL2CPP headers in the Xcode project contain a type named Il2CppString, which has the same layout as String_t. I'm not entirely sure what you are trying to do, but that type might be useful.

    In general though, I don't think that modification of the generated code is something that we can support.