Lua Scripting (#1334)

Closes #83
Fixes #1309
Fixes #1287
Fixes #1129 (actually fixed now)
This commit is contained in:
maybegreat48
2023-06-06 07:40:40 +00:00
committed by GitHub
parent 35bb398c01
commit 03c1a96b67
201 changed files with 156682 additions and 838 deletions
-12
View File
@@ -1,12 +0,0 @@
#pragma once
#include "blip.hpp"
#include "entity.hpp"
#include "math.hpp"
#include "mobile.hpp"
#include "notify.hpp"
#include "player.hpp"
#include "session.hpp"
#include "system.hpp"
#include "teleport.hpp"
#include "vehicle.hpp"
#include "water.hpp"
+16 -16
View File
@@ -114,7 +114,7 @@ namespace big::scripts
return;
}
launcher->m_context.m_state = rage::eThreadState::unk_3;// prevent bad things from happening to the thread in the meantime
launcher->m_context.m_state = rage::eThreadState::unk_3; // prevent bad things from happening to the thread in the meantime
// 3) Remove players from that annoying waiting stage
if (check_players_in_state(launcher, 5))
@@ -122,13 +122,13 @@ namespace big::scripts
for (int i = 0; check_players_in_state(launcher, 5); i++)
{
if (i > 200)
break;// 3F) Timeout
break; // 3F) Timeout
*scr_globals::launcher_global.at(3).at(1).as<int*>() = 0;
*scr_globals::launcher_global.at(2).as<int*>() = 6;
script::get_current()->yield(10ms);
}
}// State should now be 6 or 0
} // State should now be 6 or 0
// 4) Check if a script is already being executed, and unstuck from that state if so
if (check_players_in_state(launcher, 6))
@@ -136,13 +136,13 @@ namespace big::scripts
for (int i = 0; check_players_in_state(launcher, 6); i++)
{
if (i > 200)
break;// 4F) Timeout
break; // 4F) Timeout
*scr_globals::launcher_global.at(3).at(1).as<int*>() = 0;
*scr_globals::launcher_global.at(2).as<int*>() = 7;
script::get_current()->yield(10ms);
}
}// State should now be 7 or 0
} // State should now be 7 or 0
// 5) Get everyone out of state 7
if (check_players_in_state(launcher, 7))
@@ -150,16 +150,16 @@ namespace big::scripts
for (int i = 0; check_players_in_state(launcher, 7); i++)
{
if (i > 200)
break;// 5F) Timeout
break; // 5F) Timeout
*scr_globals::launcher_global.at(2).as<int*>() = 0;
script::get_current()->yield(10ms);
}
}// State should now be 0
} // State should now be 0
// 6) Actually get the script to start
misc::set_bit(scr_globals::launcher_global.at(1).as<int*>(), 1);// run immediately
*scr_globals::launcher_global.at(2).as<int*>() = 6;// will change to 7 shortly but that's fine as players are guaranteed not to be in the waiting stage
misc::set_bit(scr_globals::launcher_global.at(1).as<int*>(), 1); // run immediately
*scr_globals::launcher_global.at(2).as<int*>() = 6; // will change to 7 shortly but that's fine as players are guaranteed not to be in the waiting stage
*script_local(launcher->m_stack, 232).at(self::id, 3).at(2).as<int*>() = 6;
*scr_globals::launcher_global.at(3).at(1).as<int*>() = script_id;
@@ -236,24 +236,24 @@ namespace big::scripts
patch_script(program,
get_code_location_by_pattern(program, "2D 02 04 00 ? 38 01 38 00 42 13"),
{
0x72,// PUSH_CONST_1
0x00 // NOP
0x72, // PUSH_CONST_1
0x00 // NOP
},
5);// place anywhere
5); // place anywhere
patch_script(program, get_code_location_by_pattern(program, "71 08 2A 56 ? ? 2C ? ? ? 1F 56 ? ? 72"), {0x00, 0x00, 0x00, 0x00, 0x00}, 0xE);// don't bail on network mode
patch_script(program, get_code_location_by_pattern(program, "71 08 2A 56 ? ? 2C ? ? ? 1F 56 ? ? 72"), {0x00, 0x00, 0x00, 0x00, 0x00}, 0xE); // don't bail on network mode
if (auto loc = get_code_location_by_pattern(program, "39 04 5D ? ? ? 71"))
{
patch_script(program,
read_uint24_t(program->get_code_address(loc.value() + 3)),
{
0x73,// PUSH_CONST_2 0 = mp, 2 = creator, 999 = singleplayer
0x73, // PUSH_CONST_2 0 = mp, 2 = creator, 999 = singleplayer
0x2E,
0x00,
0x01// LEAVE 0 1
0x01 // LEAVE 0 1
},
5);// allow fast zoom in mp
5); // allow fast zoom in mp
}
}
+5 -16
View File
@@ -35,7 +35,7 @@ namespace big::session
inline void join_type(eSessionType session)
{
*script_global(2695915).as<int*>() = (session == eSessionType::SC_TV ? 1 : 0);// If SC TV Then Enable Spectator Mode
*script_global(2695915).as<int*>() = (session == eSessionType::SC_TV ? 1 : 0); // If SC TV Then Enable Spectator Mode
if (session == eSessionType::LEAVE_ONLINE)
*script_global(1574589).at(2).as<int*>() = -1;
@@ -47,17 +47,6 @@ namespace big::session
*script_global(1574589).as<int*>() = 0;
}
static constexpr char const* weathers[] = {"EXTRASUNNY", "CLEAR", "CLOUDS", "SMOG", "FOGGY", "OVERCAST", "RAIN", "THUNDER", "CLEARING", "NEUTRAL", "SNOW", "BLIZZARD", "SNOWLIGHT", "XMAS", "HALLOWEEN"};
inline void local_weather()
{
MISC::CLEAR_OVERRIDE_WEATHER();
MISC::SET_OVERRIDE_WEATHER(weathers[g.session.local_weather]);
*script_global(262145).at(4752).as<bool*>() = g.session.local_weather == 13;
}
inline void set_fm_event_index(int index)
{
int idx = index / 32;
@@ -150,11 +139,11 @@ namespace big::session
int64_t args[arg_count] = {
(int64_t)eRemoteEvent::GiveCollectible,
(int64_t)self::id,
(int64_t)col, // iParam0
(int64_t)index,// iParam1
!uncomplete, // bParam2
(int64_t)col, // iParam0
(int64_t)index, // iParam1
!uncomplete, // bParam2
true,
0// bParam3
0 // bParam3
};
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << target);
+8 -3
View File
@@ -39,9 +39,10 @@ namespace big::teleport
ENTITY::SET_ENTITY_COLLISION(hnd, false, false);
ENTITY::FREEZE_ENTITY_POSITION(hnd, true);
g.m_tp_position = {coords.x, coords.y, coords.z};
g.m_tp_player_net_id = player->get_ped()->m_net_object->m_object_id;
g.m_tp_veh_net_id = g_pointers->m_gta.m_handle_to_ptr(hnd)->m_net_object->m_object_id;
auto obj_id = player->get_ped()->m_net_object->m_object_id;
remote_player_teleport remote_tp = {obj_id, {coords.x, coords.y, coords.z}};
g.m_remote_player_teleports.emplace(g_pointers->m_gta.m_handle_to_ptr(hnd)->m_net_object->m_object_id, remote_tp);
if ((player->is_valid() && PED::IS_PED_IN_ANY_VEHICLE(PLAYER::GET_PLAYER_PED_SCRIPT_INDEX(player->id()), false))
|| PLAYER::IS_REMOTE_PLAYER_IN_NON_CLONED_VEHICLE(player->id()))
@@ -62,6 +63,10 @@ namespace big::teleport
entity::delete_entity(hnd);
std::erase_if(g.m_remote_player_teleports, [obj_id](auto& obj) {
return obj.first == obj_id;
});
return true;
}
}
+13 -5
View File
@@ -24,25 +24,33 @@ namespace big::train
if (train != 0)
{
entity::take_control_of(train);
PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), train, -1);
if (auto ped = VEHICLE::GET_PED_IN_VEHICLE_SEAT(train, -1, true))
TASK::CLEAR_PED_TASKS_IMMEDIATELY(ped);
PED::SET_PED_INTO_VEHICLE(PLAYER::PLAYER_PED_ID(), train, -1);
g_notification_service->push_success("HIJACK_TRAIN"_T.data(), "HIJACK_TRAIN_FOUND_TRAIN"_T.data());
}
else
{
g_notification_service->push_warning("HIJACK_TRAIN"_T.data(), "Cannot find any trains nearby");
}
}
inline void delete_train()
{
if (!PED::IS_PED_IN_ANY_VEHICLE(PLAYER::PLAYER_PED_ID(), false) && get_closest_train() != 0)
if (!self::veh && get_closest_train() != 0)
{
VEHICLE::DELETE_ALL_TRAINS();
g_notification_service->push_error("HIJACK_TRAIN"_T.data(), "HIJACK_TRAIN_DELETED_TRAIN"_T.data());
}
else
{
g_notification_service->push_warning("HIJACK_TRAIN"_T.data(), "Cannot find any trains nearby");
}
}
inline void exit_train()
{
if (PED::IS_PED_IN_ANY_VEHICLE(PLAYER::PLAYER_PED_ID(), false))
if (self::veh && VEHICLE::IS_THIS_MODEL_A_TRAIN(ENTITY::GET_ENTITY_MODEL(self::veh)))
TASK::CLEAR_PED_TASKS_IMMEDIATELY(PLAYER::PLAYER_PED_ID());
}
+4 -3
View File
@@ -1,4 +1,5 @@
#pragma once
#include "core/scr_globals.hpp"
#include "gta/enums.hpp"
#include "pointers.hpp"
#include "script_global.hpp"
@@ -29,10 +30,10 @@ namespace big::troll
0,
0,
0,
*script_global(1923597).at(9).as<int64_t*>(),
*script_global(1923597).at(10).as<int64_t*>()};
*scr_globals::gsbd_fm_events.at(9).as<int*>(),
*scr_globals::gsbd_fm_events.at(10).as<int*>()};
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, 1 << target->id());
g_pointers->m_gta.m_trigger_script_event(1, args, arg_count, -1);
}
}
+1 -1
View File
@@ -154,7 +154,7 @@ namespace big::vehicle
inline bool repair(Vehicle veh)
{
if (!ENTITY::IS_ENTITY_A_VEHICLE(veh) || !entity::take_control_of(veh))
if (!ENTITY::IS_ENTITY_A_VEHICLE(veh) || !entity::take_control_of(veh, 0))
{
return false;
}