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

Added MemoryAccess class #191

Closed
wants to merge 7 commits into from
Closed

Conversation

Sergeeeek
Copy link
Contributor

@Sergeeeek Sergeeeek commented Jun 10, 2015

And a few functions to World class to read entities directly from
memory. I'm a bit of a C++ noob so code will probably have to be
refactored... Should fix #13

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 10, 2015

Whoops, build fails. You should update ScriptHook version, it has a new function to get game version. Or instead implement it without ScriptHook...

@AnotherSymbiote
Copy link

AnotherSymbiote commented Jun 10, 2015

Very nice!

(Typo: MemoryAccess::GetEtityHandleList() is missing an 'n'.)

@njames93
Copy link
Collaborator

njames93 commented Jun 10, 2015

They store all entities in one pool... Understandable with all these entity natives


for (int i = 0; i < entities->Length; i++)
{
if (Native::Function::Call<bool>(Native::Hash::DOES_ENTITY_EXIST, entities[i]))
Copy link
Contributor

@IncoCode IncoCode Jun 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, you should use IS_ENTITY_AN_OBJECT ?

@JohnnyCrazy
Copy link
Collaborator

JohnnyCrazy commented Jun 11, 2015

Scripthook version is updated, can you try building again @crosire?

@IncoCode
Copy link
Contributor

IncoCode commented Jun 11, 2015

Did address change after last patch?

@IncoCode
Copy link
Contributor

IncoCode commented Jun 11, 2015

@JohnnyCrazy , today released the new version of scripthook.

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 11, 2015

Need to mention that I don't have the steam version and I took the memory offset from this thread: http://gtaforums.com/topic/795898-is-there-a-way-to-get-all-vehiclespeds-yet/?p=1067571965 So it might not work on steam version.

@njames93
Copy link
Collaborator

njames93 commented Jun 11, 2015

May suggest waiting til the new pool offsets are found before committing this

@IncoCode
Copy link
Contributor

IncoCode commented Jun 11, 2015

By the way, do we need GetAllPeds/Vehicles/Props? I think GetAllEntities is enough, for everything else, there's Mastercard.

Vehicle[] allVeh = World.GetAllEntities().Where( ent => Function.Call<bool>( Hash.IS_ENTITY_A_VEHICLE, ent.Handle ) ).Cast<Vehicle>().ToArray();

and etc

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 11, 2015

If someone can find memory dumps of all the different versions I could try to find offsets.

@njames93
Copy link
Collaborator

njames93 commented Jun 12, 2015

Having get all peds, props, vehicles and entities is the best bet. It's quicker getting a list of vehicles through memory access class than it is to get a list of entities, then check each one to see if it's a vehicle then make a new list for vehicles

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

But all entities including are in one list, unlike previous GTA games. So I think putting a few functions like GetAllVehicles etc. for convinience is a good idea.

Edit: and, considering this pool contains the maximum of 300 entities it shouldn't affect performance.

@IncoCode
Copy link
Contributor

IncoCode commented Jun 12, 2015

Any thought @crosire , @JohnnyCrazy ?

@JohnnyCrazy
Copy link
Collaborator

JohnnyCrazy commented Jun 12, 2015

I agree, there is a lot of boilerplate code.
But we should still provide methods (GetAllPeds GetAllVehicles GetAllProps)

Since there are no anonymous lambdas in c++ CLI, what about following approach:

array<Ped ^> ^World::GetAllPeds()
{
    array<Entity ^> ^entities = GetAllPeds();
    return System::Array::FindAll(entities, gcnew System::Predicate<Entity ^>(Entity::IsPed));
}
//And so on for Props/Vehicles

This would just require 3 Functions in the Entity-class (IsPed, IsVehicle, IsProp) which would be good to have anyway.

But wait for @crosire first :)

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

@JohnnyCrazy should I add these functions to the Entity class? Sounds like we really need them.

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

Oh and btw, I am working on a signature scanning solution so we don't have to hardcode offsets for each version.

@njames93
Copy link
Collaborator

njames93 commented Jun 12, 2015

@Sergeeeek You wouldnt be able to add functions for peds/props/vehicles to the entity class as they reference the entity class

@njames93
Copy link
Collaborator

njames93 commented Jun 12, 2015

@Sergeeeek will need checking RW - 0x2A08808, Steam - 0x2A0DE50

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

@Zorg93 nvm, gonna add signature scanning in the next commit.

@njames93
Copy link
Collaborator

njames93 commented Jun 12, 2015

is that not going to be rather slow

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

@Zorg93 it's done only once per launch and only creates a minor lag spike, haven't measured it but it's hard to spot in the game.

@njames93
Copy link
Collaborator

njames93 commented Jun 12, 2015

Ah, makes sense, May try and figure a way to automatically get global address pointer aswell

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 12, 2015

So I though I could add methods like IsPed, IsVehicle and such as static methods to the Entity class. Is that a good idea? And should I do it in separate pull request?

@JohnnyCrazy
Copy link
Collaborator

JohnnyCrazy commented Jun 12, 2015

@Sergeeeek
I would go with this approach, this will remove a lot of boilerplate code from the 3 GetAllPeds/GetAllVehicles/GetAllProps methods and they will be used often in other places too. But let's wait for crosires thoughts first :)

@JohnnyCrazy JohnnyCrazy mentioned this pull request Jun 13, 2015
@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 13, 2015

Also, could someone test if signature scanning works with different game versions? I tested with 1.0.350.2 nosteam version. It should be fine but it's better to test it anyway.

Sergeeeek added 4 commits Jun 13, 2015
And a few functions to World class to read entities directly from
memory. I'm a bit of a C++ noob so code will probably have to be
refactored...
No need to hardcode offsets anymore.
@njames93
Copy link
Collaborator

njames93 commented Jun 13, 2015

Once the appveyor builds I'll test with 1.0.372.2 NOSTEAM, how should I test, just call get all entities and see how many it finds?

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 13, 2015

@Zorg93 yeah, just call one of the new functions and see if it returns anything.

@njames93
Copy link
Collaborator

njames93 commented Jun 13, 2015

Yeah seems to be working
image

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 13, 2015

@Zorg93 awesome! 😄

@njames93
Copy link
Collaborator

njames93 commented Jun 13, 2015

Just need someone to test on one of the steam builds, I've looked at the code in ida and it looks identical so i see no reason for it to fail

@Sergeeeek Sergeeeek mentioned this pull request Jun 13, 2015
@IncoCode
Copy link
Contributor

IncoCode commented Jun 13, 2015

Works fine on latest steam version.

@IncoCode
Copy link
Contributor

IncoCode commented Jun 15, 2015

Sooo, @crosire ?

{
if (Native::Function::Call<bool>(Native::Hash::DOES_ENTITY_EXIST, entities[i]))
{
Entity^ ent = (Entity ^)gcnew Prop(entities[i]);
Copy link
Collaborator

@JohnnyCrazy JohnnyCrazy Jun 15, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this is wrong, we shouldnt do this. Will write more tomorrow.

Copy link
Owner

@crosire crosire Jun 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that makes all returned entites props, which (according to the function name) isn't the case. There could be peds or vehicles in there too.

Copy link
Collaborator

@njames93 njames93 Jun 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this would be better
if (Native::Function::Call(Native::Hash::DOES_ENTITY_EXIST, entities[i]))
{
if (Native::Function::Call(Native::Hash::IS_ENTITY_A_PED, entities[i]))
{
ents->Add(gcnew Ped(entities[i]));
}
else if (Native::Function::Call(Native::Hash::IS_ENTITY_A_VEHICLE, entities[i]))
{
ents->Add(gcnew Vehicle(entities[i]));
}
else if (Native::Function::Call(Native::Hash::IS_ENTITY_AN_OBJECT, entities[i]))
{
ents->Add(gcnew Prop(entities[i]));
}
}

Copy link
Collaborator

@JohnnyCrazy JohnnyCrazy Jun 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, then we also don't need Entity.IsVehicle (...) methods, since we can use ent is Vehicle.

Copy link
Contributor Author

@Sergeeeek Sergeeeek Jun 16, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnnyCrazy ok, sounds like a good idea. I did it in the first place because you can't create Entity because it's abstract and Prop only has a constructor redefined and no additional properties or functions.

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 17, 2015

Ok, I think I used the wrong pool address. The current pool this code uses only has entities like peds and vehicles (no objects) what are also not that far away. So basically you can't just get ALL entities from this pool.

I think I found the right one though, gonna investigate more.

@njames93
Copy link
Collaborator

njames93 commented Jun 17, 2015

I noticed this address has issues, but It did find some props.

@Sergeeeek
Copy link
Contributor Author

Sergeeeek commented Jun 17, 2015

@Zorg93 oh, maybe it's only objects with activated physics then. I've made some tests with getting all entities and applying force to them, not all entities reacted (peds don't react at all until you push them, aka activate physics on them). Especially noticeable on objects that are about 30-40 meters in front of you, they are never affected by this.

@njames93
Copy link
Collaborator

njames93 commented Jun 17, 2015

@Sergeeeek Its not just that, Things like Police helicopters I could never find, sometimes police swap guys would be found other times they wouldnt, It seemed random, even when they were close to me

crosire added a commit that referenced this pull request Jul 3, 2015
@crosire
Copy link
Owner

crosire commented Jul 3, 2015

Merged (even though Github fails to see that) =).

@crosire crosire closed this Jul 3, 2015
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

Successfully merging this pull request may close these issues.

None yet

6 participants