Skip to content

Commit c5c4c64

Browse files
committed
Changed native function calling to use hash enumeration instead of strings
1 parent 9a68f10 commit c5c4c64

File tree

14 files changed

+4211
-4194
lines changed

14 files changed

+4211
-4194
lines changed

ScriptHookVDotNet.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<ClInclude Include="src\Matrix.hpp" />
103103
<ClInclude Include="src\Model.hpp" />
104104
<ClInclude Include="src\Native.hpp" />
105+
<ClInclude Include="src\NativeHashes.hpp" />
105106
<ClInclude Include="src\Ped.hpp" />
106107
<ClInclude Include="src\Player.hpp" />
107108
<ClInclude Include="src\Quaternion.hpp" />

ScriptHookVDotNet.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
<ClInclude Include="src\Native.hpp">
6060
<Filter>Core</Filter>
6161
</ClInclude>
62+
<ClInclude Include="src\NativeHashes.hpp">
63+
<Filter>Core</Filter>
64+
</ClInclude>
6265
<ClInclude Include="src\Script.hpp">
6366
<Filter>Core</Filter>
6467
</ClInclude>

src/Entity.cpp

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,117 +13,117 @@ namespace GTA
1313
}
1414
Vector3 Entity::Position::get()
1515
{
16-
return Native::Function::Call<Vector3>("GET_ENTITY_COORDS", this->ID, 0);
16+
return Native::Function::Call<Vector3>(Native::Hash::GET_ENTITY_COORDS, this->ID, 0);
1717
}
1818
void Entity::Position::set(Vector3 value)
1919
{
20-
Native::Function::Call("SET_ENTITY_COORDS", this->ID, value.X, value.Y, value.Z, 0, 0, 0, 1);
20+
Native::Function::Call(Native::Hash::SET_ENTITY_COORDS, this->ID, value.X, value.Y, value.Z, 0, 0, 0, 1);
2121
}
2222
float Entity::Heading::get()
2323
{
24-
return Native::Function::Call<float>("GET_ENTITY_HEADING", this->ID);
24+
return Native::Function::Call<float>(Native::Hash::GET_ENTITY_HEADING, this->ID);
2525
}
2626
void Entity::Heading::set(float value)
2727
{
28-
Native::Function::Call<float>("SET_ENTITY_HEADING", this->ID, value);
28+
Native::Function::Call<float>(Native::Hash::SET_ENTITY_HEADING, this->ID, value);
2929
}
3030
Vector3 Entity::Rotation::get()
3131
{
32-
return Native::Function::Call<Vector3>("GET_ENTITY_ROTATION", this->ID, 0);
32+
return Native::Function::Call<Vector3>(Native::Hash::GET_ENTITY_ROTATION, this->ID, 0);
3333
}
3434
Vector3 Entity::Velocity::get()
3535
{
36-
return Native::Function::Call<Vector3>("GET_ENTITY_VELOCITY", this->ID);
36+
return Native::Function::Call<Vector3>(Native::Hash::GET_ENTITY_VELOCITY, this->ID);
3737
}
3838
void Entity::Velocity::set(Vector3 value)
3939
{
40-
Native::Function::Call("SET_ENTITY_VELOCITY", this->ID, value.X, value.Y, value.Z);
40+
Native::Function::Call(Native::Hash::SET_ENTITY_VELOCITY, this->ID, value.X, value.Y, value.Z);
4141
}
4242
int Entity::Health::get()
4343
{
44-
return Native::Function::Call<int>("GET_ENTITY_HEALTH", this->ID);
44+
return Native::Function::Call<int>(Native::Hash::GET_ENTITY_HEALTH, this->ID);
4545
}
4646
void Entity::Health::set(int value)
4747
{
48-
Native::Function::Call("SET_ENTITY_HEALTH", this->ID, value);
48+
Native::Function::Call(Native::Hash::SET_ENTITY_HEALTH, this->ID, value);
4949
}
5050
GTA::Model Entity::Model::get()
5151
{
52-
return GTA::Model(Native::Function::Call<int>("GET_ENTITY_MODEL", this->ID));
52+
return GTA::Model(Native::Function::Call<int>(Native::Hash::GET_ENTITY_MODEL, this->ID));
5353
}
5454
bool Entity::IsDead::get()
5555
{
56-
return Native::Function::Call<bool>("IS_ENTITY_DEAD", this->ID);
56+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_DEAD, this->ID);
5757
}
5858
bool Entity::IsAlive::get()
5959
{
6060
return !IsDead;
6161
}
6262
void Entity::IsInvincible::set(bool value)
6363
{
64-
Native::Function::Call("SET_ENTITY_INVINCIBLE", this->ID, value);
64+
Native::Function::Call(Native::Hash::SET_ENTITY_INVINCIBLE, this->ID, value);
6565
}
6666
bool Entity::IsVisible::get()
6767
{
68-
return Native::Function::Call<bool>("IS_ENTITY_VISIBLE", this->ID);
68+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_VISIBLE, this->ID);
6969
}
7070
void Entity::IsVisible::set(bool value)
7171
{
72-
Native::Function::Call("SET_ENTITY_VISIBLE", this->ID, value);
72+
Native::Function::Call(Native::Hash::SET_ENTITY_VISIBLE, this->ID, value);
7373
}
7474
bool Entity::IsOccluded::get()
7575
{
76-
return Native::Function::Call<bool>("IS_ENTITY_OCCLUDED", this->ID);
76+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_OCCLUDED, this->ID);
7777
}
7878
bool Entity::IsOnScreen::get()
7979
{
80-
return Native::Function::Call<bool>("IS_ENTITY_ON_SCREEN", this->ID);
80+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_ON_SCREEN, this->ID);
8181
}
8282
bool Entity::IsUpright::get()
8383
{
84-
return Native::Function::Call<bool>("IS_ENTITY_UPRIGHT", this->ID);
84+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_UPRIGHT, this->ID);
8585
}
8686
bool Entity::IsUpsideDown::get()
8787
{
88-
return Native::Function::Call<bool>("IS_ENTITY_UPSIDEDOWN", this->ID);
88+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_UPSIDEDOWN, this->ID);
8989
}
9090
bool Entity::IsInAir::get()
9191
{
92-
return Native::Function::Call<bool>("IS_PED_GETTING_INTO_A_VEHICLE", this->ID);
92+
return Native::Function::Call<bool>(Native::Hash::IS_PED_GETTING_INTO_A_VEHICLE, this->ID);
9393
}
9494
bool Entity::IsInWater::get()
9595
{
96-
return Native::Function::Call<bool>("IS_ENTITY_IN_WATER", this->ID);
96+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_IN_WATER, this->ID);
9797
}
9898
bool Entity::IsOnFire::get()
9999
{
100-
return Native::Function::Call<bool>("IS_ENTITY_ON_FIRE", this->ID);
100+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_ON_FIRE, this->ID);
101101
}
102102
void Entity::IsOnFire::set(bool value)
103103
{
104104
if (value)
105105
{
106-
Native::Function::Call("START_ENTITY_FIRE", this->ID);
106+
Native::Function::Call(Native::Hash::START_ENTITY_FIRE, this->ID);
107107
}
108108
else
109109
{
110-
Native::Function::Call("STOP_ENTITY_FIRE", this->ID);
110+
Native::Function::Call(Native::Hash::STOP_ENTITY_FIRE, this->ID);
111111
}
112112
}
113113
bool Entity::IsRequiredForMission::get()
114114
{
115-
return Native::Function::Call<bool>("IS_ENTITY_A_MISSION_ENTITY", this->ID);
115+
return Native::Function::Call<bool>(Native::Hash::IS_ENTITY_A_MISSION_ENTITY, this->ID);
116116
}
117117
void Entity::IsRequiredForMission::set(bool value)
118118
{
119119
if (value)
120120
{
121-
Native::Function::Call("SET_ENTITY_AS_MISSION_ENTITY", this->ID, true, false);
121+
Native::Function::Call(Native::Hash::SET_ENTITY_AS_MISSION_ENTITY, this->ID, true, false);
122122
}
123123
else
124124
{
125125
int handle = this->ID;
126-
Native::Function::Call("SET_ENTITY_AS_NO_LONGER_NEEDED", &handle);
126+
Native::Function::Call(Native::Hash::SET_ENTITY_AS_NO_LONGER_NEEDED, &handle);
127127
}
128128
}
129129

@@ -133,6 +133,6 @@ namespace GTA
133133
}
134134
bool Entity::Exists(Entity ^entity)
135135
{
136-
return Native::Function::Call<bool>("DOES_ENTITY_EXIST", entity->ID);
136+
return Native::Function::Call<bool>(Native::Hash::DOES_ENTITY_EXIST, entity->ID);
137137
}
138138
}

src/Game.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,47 @@ namespace GTA
55
{
66
Player ^GTA::Game::Player::get()
77
{
8-
return gcnew GTA::Player(Native::Function::Call<int>("PLAYER_ID"));
8+
return gcnew GTA::Player(Native::Function::Call<int>(Native::Hash::PLAYER_ID));
99
}
1010
int Game::GameTime::get()
1111
{
12-
return Native::Function::Call<int>("GET_GAME_TIMER");
12+
return Native::Function::Call<int>(Native::Hash::GET_GAME_TIMER);
1313
}
1414
float Game::LastFrameTime::get()
1515
{
16-
return Native::Function::Call<float>("GET_FRAME_TIME");
16+
return Native::Function::Call<float>(Native::Hash::GET_FRAME_TIME);
1717
}
1818
float Game::FPS::get()
1919
{
2020
return (1.0f / LastFrameTime);
2121
}
2222
bool Game::IsPaused::get()
2323
{
24-
return Native::Function::Call<bool>("IS_PAUSE_MENU_ACTIVE");
24+
return Native::Function::Call<bool>(Native::Hash::IS_PAUSE_MENU_ACTIVE);
2525
}
2626
void Game::IsPaused::set(bool value)
2727
{
28-
Native::Function::Call("SET_PAUSE_MENU_ACTIVE", value);
28+
Native::Function::Call(Native::Hash::SET_PAUSE_MENU_ACTIVE, value);
2929
}
3030
GTA::RadioStation Game::RadioStation::get()
3131
{
32-
return static_cast<GTA::RadioStation>(Native::Function::Call<int>("GET_PLAYER_RADIO_STATION_INDEX"));
32+
return static_cast<GTA::RadioStation>(Native::Function::Call<int>(Native::Hash::GET_PLAYER_RADIO_STATION_INDEX));
3333
}
3434
void Game::RadioStation::set(GTA::RadioStation value)
3535
{
36-
Native::Function::Call("SET_RADIO_TO_STATION_INDEX", static_cast<int>(value));
36+
Native::Function::Call(Native::Hash::SET_RADIO_TO_STATION_INDEX, static_cast<int>(value));
3737
}
3838
void Game::RadarZoom::set(float value)
3939
{
40-
Native::Function::Call("SET_RADAR_ZOOM", value);
40+
Native::Function::Call(Native::Hash::SET_RADAR_ZOOM, value);
4141
}
4242
void Game::TimeScale::set(float value)
4343
{
44-
Native::Function::Call("SET_TIME_SCALE", value);
44+
Native::Function::Call(Native::Hash::SET_TIME_SCALE, value);
4545
}
4646
void Game::WantedMultiplier::set(float value)
4747
{
48-
Native::Function::Call("SET_WANTED_LEVEL_MULTIPLIER", value);
48+
Native::Function::Call(Native::Hash::SET_WANTED_LEVEL_MULTIPLIER, value);
4949
}
5050

5151
void Game::Pause()
@@ -58,18 +58,18 @@ namespace GTA
5858
}
5959
void Game::DoAutoSave()
6060
{
61-
Native::Function::Call("DO_AUTO_SAVE");
61+
Native::Function::Call(Native::Hash::DO_AUTO_SAVE);
6262
}
6363
void Game::ShowSaveMenu()
6464
{
65-
Native::Function::Call("SET_SAVE_MENU_ACTIVE", true);
65+
Native::Function::Call(Native::Hash::SET_SAVE_MENU_ACTIVE, true);
6666
}
6767
void Game::FadeScreenIn(int time)
6868
{
69-
Native::Function::Call("DO_SCREEN_FADE_IN", time);
69+
Native::Function::Call(Native::Hash::DO_SCREEN_FADE_IN, time);
7070
}
7171
void Game::FadeScreenOut(int time)
7272
{
73-
Native::Function::Call("DO_SCREEN_FADE_OUT", time);
73+
Native::Function::Call(Native::Hash::DO_SCREEN_FADE_OUT, time);
7474
}
7575
}

src/Model.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GTA
66
Model::Model(int hash) : mHash(hash)
77
{
88
}
9-
Model::Model(System::String ^name) : mHash(Native::Function::Call<int>("GET_HASH_KEY", name))
9+
Model::Model(System::String ^name) : mHash(Native::Function::Call<int>(Native::Hash::GET_HASH_KEY, name))
1010
{
1111
}
1212

@@ -17,39 +17,35 @@ namespace GTA
1717

1818
bool Model::IsBicycle::get()
1919
{
20-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_BICYCLE", this->mHash);
20+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_BICYCLE, this->mHash);
2121
}
2222
bool Model::IsBike::get()
2323
{
24-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_BIKE", this->mHash);
24+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_BIKE, this->mHash);
2525
}
2626
bool Model::IsBoat::get()
2727
{
28-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_BOAT", this->mHash);
28+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_BOAT, this->mHash);
2929
}
3030
bool Model::IsCar::get()
3131
{
32-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_CAR", this->mHash);
32+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_CAR, this->mHash);
3333
}
3434
bool Model::IsHelicopter::get()
3535
{
36-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_HELI", this->mHash);
37-
}
38-
bool Model::IsPed::get()
39-
{
40-
return !IsVehicle;
36+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_HELI, this->mHash);
4137
}
4238
bool Model::IsPlane::get()
4339
{
44-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_PLANE", this->mHash);
40+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_PLANE, this->mHash);
4541
}
4642
bool Model::IsQuadbike::get()
4743
{
48-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_QUADBIKE", this->mHash);
44+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_QUADBIKE, this->mHash);
4945
}
5046
bool Model::IsTrain::get()
5147
{
52-
return Native::Function::Call<bool>("IS_THIS_MODEL_A_TRAIN", this->mHash);
48+
return Native::Function::Call<bool>(Native::Hash::IS_THIS_MODEL_A_TRAIN, this->mHash);
5349
}
5450
bool Model::IsVehicle::get()
5551
{

src/Model.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ namespace GTA
3333
{
3434
bool get();
3535
}
36-
property bool IsPed
37-
{
38-
bool get();
39-
}
4036
property bool IsPlane
4137
{
4238
bool get();

0 commit comments

Comments
 (0)