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

Get Dictionary values #595

Open
jorcadet009 opened this issue Jan 21, 2025 · 3 comments
Open

Get Dictionary values #595

jorcadet009 opened this issue Jan 21, 2025 · 3 comments
Labels
question A question about anything

Comments

@jorcadet009
Copy link

I'm trying to get the values of this field

// GameManager
// Token: 0x0400023C RID: 572
[Token(Token = "0x400023C")]
[FieldOffset(Offset = "0x98")]
private Dictionary<int, string> adjustConversationLevels;

It's System.Collections.Generic.Dictionary`2[System.Int32,System.String]

and this is my code

  let unityframework = Il2Cpp.domain.assembly("Assembly-CSharp");
  const GameManager = unityframework.image.class("GameManager");
  let adjustConversationLevels = GameManager.field("adjustConversationLevels");
  let OpenLevel = GameManager.method("OpenLevel");

  OpenLevel.implementation = function (this: any, level: any) {
    //trying to call adjustConversationLevels from here
    this.method(OpenLevel.name, 1).invoke(level);
  };

but there's no Il2Cpp.Dictionary so how to get those values?

@vfsfitvnm vfsfitvnm added the question A question about anything label Jan 22, 2025
@vfsfitvnm
Copy link
Owner

It's a Il2Cpp.Object. That's how I would write the script:

  const AssemblyCSharp = Il2Cpp.domain.assembly("Assembly-CSharp").image;
  const GameManager = AssemblyCSharp.class("GameManager");
  
  // @ts-ignore
  GameManager.method("OpenLevel").implementation = function (this: Il2Cpp.Object | Il2Cpp.Class, level: any): any {
    const adjustConversationLevels = this.field<Il2Cpp.Object>("adjustConversationLevels").value;
    
    // do whatever you want with adjustConversationLevels, it's a Il2Cpp.Object
    // let's print its class
    console.log(adjustConversationLevels.class);

    return this.method("OpenLevel", 1).invoke(level);
  };

@jorcadet009
Copy link
Author

It's a Il2Cpp.Object. That's how I would write the script:

const AssemblyCSharp = Il2Cpp.domain.assembly("Assembly-CSharp").image;
const GameManager = AssemblyCSharp.class("GameManager");

// @ts-ignore
GameManager.method("OpenLevel").implementation = function (this: Il2Cpp.Object | Il2Cpp.Class, level: any): any {
const adjustConversationLevels = this.field<Il2Cpp.Object>("adjustConversationLevels").value;

// do whatever you want with adjustConversationLevels, it's a Il2Cpp.Object
// let's print its class
console.log(adjustConversationLevels.class);

return this.method("OpenLevel", 1).invoke(level);

};

Thank you but I mean adjustConversationLevels contain the values I wanna get but I don't know how to get those

@EduModsS
Copy link

EduModsS commented Feb 13, 2025

its a object of

System.Collections.Generic.Dictionary<TKey,TValue>

to get/set/add/resize etc... just read the class things.

eg:

get_Item(TKey key);
set_Item(TKey key, TValue value);

and call it in script.

to iterate it you can use

System.Collections.Generic.Dictionary.Enumerator<TKey,TValue> GetEnumerator();

ex to iterate:

const enumerator = adjustConversationLevels.method("GetEnumerator").Invoke<Il2Cpp.ValueType>();
while (enumerator.method("MoveNext").invoke<bool>())
{
    const current = enumerator.method("get_Current").invoke<Il2Cpp.ValueType>();
    const key = current.method("get_Key").invoke<int>(); // as the key type is "int" according to your dump
    const value = current.method("get_Value").invoke<Il2Cpp.String>(); // as the value type is "string" according to your dump

    // just use console.log to read values in your console
}

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

No branches or pull requests

3 participants