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

Problem when calling natives that uses pointers in C# #3100

Open
gameplayoffert opened this issue Jan 25, 2025 · 14 comments
Open

Problem when calling natives that uses pointers in C# #3100

gameplayoffert opened this issue Jan 25, 2025 · 14 comments
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action

Comments

@gameplayoffert
Copy link

What happened?

Everytime i want to call a function that use pointers, i always get an error like "Invalid type (Int32) at stack for conversion operation. Numeric type expected at 0x0031^7".

I saw that some functions are available in the "API" class but i'm unable to find the code behind it. Is it on that repository ? Because i wanted to understand how we can call the functions with pointers without using the API class but i can't find the code that does it. What does it use ?

Expected result

The function should return the results inside the pointers.

Reproduction steps

It's really simple, you just need to write :

unsafe { int ret_value = 0; Function.Call(Hash.FunctionHere, &ret_value); }

Importancy

Crash

Area(s)

FiveM

Specific version(s)

Five M, Version : 12295

Additional information

No response

@gameplayoffert gameplayoffert added bug triage Needs a preliminary assessment to determine the urgency and required action labels Jan 25, 2025
@github-actions github-actions bot added the crash label Jan 25, 2025
@AvarianKnight
Copy link
Contributor

You can't use unsafe code on the client.

@gameplayoffert
Copy link
Author

You can't use unsafe code on the client.

Oh ok but why ? And how the API is working then ? Because unless i'm wrong, it should use something like this no ?

@AvarianKnight
Copy link
Contributor

Because... It's unsafe. Cfx is able to do it from their own API.

@gameplayoffert
Copy link
Author

Because... It's unsafe. Cfx is able to do it from their own API.

And do you know where is that API code ? Because i'm not sure that code is present on that repository.

@AvarianKnight
Copy link
Contributor

You would have to give an example of what you're trying to do. If there code you can't do because it requires raw pointer access (which should only be structs) you would need to open a pr to add it to the library.

You shouldn't need this for int refs though.

@gameplayoffert
Copy link
Author

You would have to give an example of what you're trying to do. If there code you can't do because it requires raw pointer access (which should only be structs) you would need to open a pr to add it to the library.

You shouldn't need this for int refs though.

I just wanted to know how it was working because apparently there is hidden code that isn't present on that github, nothing else. I just wanted to know what was the background code that makes the API functions working because they are not on that Github.

@AvarianKnight
Copy link
Contributor

Can you say what native/the native hash

@gameplayoffert
Copy link
Author

gameplayoffert commented Jan 26, 2025

Can you say what native/the native hash

So in my case it was on the function ADD_RELATIONSHIP_GROUP with hash 0xF372BC22FCB88606 that is supposed to return the handle inside the second parameter and it was on the function GET_VEHICLE_COLOURS with hash 0xA19435F193E081AC that is supposed to return the first and second color inside the 2 remaining parameters.

@AvarianKnight
Copy link
Contributor

Im not at a pc so I can't double check it this but you should be able to do this perfectly fine already.

int hashGroup = 0;
int unkRet = AddRelationShipGroup("name" , ref hashGroup);

@gameplayoffert
Copy link
Author

Im not at a pc so I can't double check it this but you should be able to do this perfectly fine already.

int hashGroup = 0;
int unkRet = AddRelationShipGroup("name" , ref hashGroup);

Yes, that will work because you are using the API.AddRelationShipGroup that implement the "ref" parameter. I wasn't clear on that post so i'm really sorry but in reality, i already found that the API can do it because they implemented it. I just want to know how they implemented it because i'm curious that's all. If you look carefully, the "API.AddRelationShipGroup" is nowhere inside the Github. I used a searching software that i made and in the whole repository, C#, C++ etc, there is a trace for that implementation only in the World.cs class if i remember correctly. If you know a place where i can ask that question or even where i can find the real source code for that implementation, i will be really happy :D, but like i said, it's just because i'm curious since i already found that the API can do it.

@AvarianKnight
Copy link
Contributor

When you download the Nuget packet the API wrapper will be in there, if you're using mono_v2 it should be in your CitizenFX.Natives.dll

@gameplayoffert
Copy link
Author

When you download the Nuget packet the API wrapper will be in there, if you're using mono_v2 it should be in your CitizenFX.Natives.dll

Yeah it should be inside that dll, the dll is inside the Five M folder but the source code of that dll isn't present on that Github, at least i don't think because i wasn't able to find it.

@AvarianKnight
Copy link
Contributor

No it won't be on GitHub, its done as a part of the FiveM build process.

@gameplayoffert
Copy link
Author

No it won't be on GitHub, its done as a part of the FiveM build process.

Oh ok but if it's a part of the build process, there is normally some files that manage everything no ? Because i was like i said, completely unable to find that files. Can we build Five M ourselves ? or there is missing files ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash triage Needs a preliminary assessment to determine the urgency and required action
Projects
None yet
Development

No branches or pull requests

2 participants