Update for b3258 (#3288)

* fix: update script names
* fix: use original chat sender
* feat(tunables): fix tunable service
* fix: explode patch (thanks @Mr-X-GTA)
* fix: fix compile errors
* fix: use unique_ptr
* Added 1.69 vehicles.
* Added new weather for 1.69 and updated stack sizes.
* Fixed garage.
* Made Unload button a developer-only feature. (Disabled on Release)
* Redesigned Network tab to not be a giant mess.
* Added new json_serializer code from @tupoy-ya.
* chore: correct dependency

------

Co-authored-by: maybegreat48 <email@hostname>
Co-authored-by: Andreas Maerten <24669514+Yimura@users.noreply.github.com>
Co-authored-by: gir489returns <redacted@example.com>
This commit is contained in:
maybegreat48
2024-07-03 21:04:06 +00:00
committed by GitHub
parent 50da01eb22
commit 61ddba1634
50 changed files with 133419 additions and 132578 deletions

View File

@ -48,9 +48,12 @@ namespace big
if (!m_script_started)
{
SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH("tuneables_processing"_J);
SCRIPT::REQUEST_SCRIPT_WITH_NAME_HASH("tunables_registration"_J);
if (SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED("tuneables_processing"_J))
if (SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED("tuneables_processing"_J) && SCRIPT::HAS_SCRIPT_WITH_NAME_HASH_LOADED("tunables_registration"_J))
{
m_num_tunables = gta_util::find_script_program("tunables_registration"_J)->m_global_count - 0x40000;
uint64_t args[] = {6, 27}; // TODO: check args
int id = SYSTEM::START_NEW_SCRIPT_WITH_NAME_HASH_AND_ARGS("tuneables_processing"_J, (Any*)args, sizeof(args) / 8, DEFAULT_STACK_SIZE);
@ -61,29 +64,38 @@ namespace big
return;
}
SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED("tuneables_processing"_J);
m_script_started = true;
m_tunables_backup = std::make_unique<std::uint64_t[]>(m_num_tunables);
memcpy(m_tunables_backup.get(), script_global(0x40000).as<void*>(), m_num_tunables * 8);
g_script_patcher_service->add_patch({"tuneables_processing"_J, "tuneables_processing1", "2E ? ? 55 ? ? 38 06", 0, std::vector<uint8_t>(17, 0x0), &m_script_started}); // bool tunables registration hack
if (auto program = gta_util::find_script_program("tuneables_processing"_J))
g_script_patcher_service->on_script_load(program);
SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED("tuneables_processing"_J);
SCRIPT::SET_SCRIPT_WITH_NAME_HASH_AS_NO_LONGER_NEEDED("tunables_registration"_J);
m_script_started = true;
}
}
else
{
if (SCRIPT::GET_NUMBER_OF_THREADS_RUNNING_THE_SCRIPT_WITH_THIS_HASH("tuneables_processing"_J) == 0)
{
for (int i = 0; i < m_num_tunables; i++)
{
auto value = *script_global(0x40000).at(i).as<int*>();
if (auto it = m_junk_values.find(value); it != m_junk_values.end())
{
m_tunables.emplace(it->second, 0x40000 + i);
}
}
memcpy(script_global(0x40000).as<void*>(), m_tunables_backup.get(), m_num_tunables * 8);
if (m_tunables.size() == 0)
{
LOG(FATAL) << "Failed to cache tunables";
g_script_patcher_service->update();
return;
}
m_script_started = false;
m_initialized = true;
LOG(INFO) << "Saving " << m_tunables.size() << " tunables to cache";
g_script_patcher_service->update();
m_tunables_backup.release();
save();
}
}
@ -99,11 +111,11 @@ namespace big
*(uint32_t*)data_ptr = m_tunables.size();
data_ptr += sizeof(uint32_t);
for (auto& [hash, ptr] : m_tunables)
for (auto& [hash, val] : m_tunables)
{
auto save_struct = (tunable_save_struct*)data_ptr;
save_struct->hash = hash;
save_struct->offset = ((std::int64_t*)ptr) - g_pointers->m_gta.m_script_globals[1];
save_struct->offset = val;
data_ptr += sizeof(tunable_save_struct);
}
@ -122,7 +134,7 @@ namespace big
for (int i = 0; i < num_tunables; i++)
{
auto save_struct = (tunable_save_struct*)data;
m_tunables.emplace(save_struct->hash, (void*)(g_pointers->m_gta.m_script_globals[1] + save_struct->offset));
m_tunables.emplace(save_struct->hash, save_struct->offset);
data += sizeof(tunable_save_struct);
}