diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3692290..f102479a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,30 +51,3 @@ jobs: build/bin/Win32/${{matrix.configuration}}/iw4x.dll build/bin/Win32/${{matrix.configuration}}/iw4x.pdb - deploy: - name: Deploy artifacts - needs: build - runs-on: ubuntu-latest - if: github.event_name == 'push' && (github.ref == 'refs/heads/develop') - steps: - - name: Setup develop environment - if: github.ref == 'refs/heads/develop' - run: echo "DIAMANTE_MASTER_PATH=${{ secrets.DIAMANTE_MASTER_SSH_PATH }}" >> $GITHUB_ENV - - - name: Download Release binaries - uses: actions/download-artifact@v3.0.2 - with: - name: Release binaries - - # Set up committer info and GPG key - - name: Install SSH key - uses: shimataro/ssh-key-action@v2.5.1 - with: - key: ${{ secrets.DIAMANTE_MASTER_SSH_PRIVATE_KEY }} - known_hosts: 'just-a-placeholder-so-we-dont-get-errors' - - - name: Add known hosts - run: ssh-keyscan -H ${{ secrets.DIAMANTE_MASTER_SSH_ADDRESS }} >> ~/.ssh/known_hosts - - - name: Upload iw4x-client binary - run: rsync -avz iw4x.dll ${{ secrets.DIAMANTE_MASTER_SSH_USER }}@${{ secrets.DIAMANTE_MASTER_SSH_ADDRESS }}:${{ env.DIAMANTE_MASTER_PATH }}/legacy/ diff --git a/deps/GSL b/deps/GSL index 4300304e..e64c97fc 160000 --- a/deps/GSL +++ b/deps/GSL @@ -1 +1 @@ -Subproject commit 4300304ef24c247b3db0255763f46b9f95c3a83d +Subproject commit e64c97fc2cfc11992098bb38eda932de275e3f4d diff --git a/deps/iw4-open-formats b/deps/iw4-open-formats index 700a2ae8..f174f1c4 160000 --- a/deps/iw4-open-formats +++ b/deps/iw4-open-formats @@ -1 +1 @@ -Subproject commit 700a2ae858c27568d95e21ce8c5f941d36c4a6c4 +Subproject commit f174f1c4c4c465c337166b92e03b355695c5bc93 diff --git a/deps/libtommath b/deps/libtommath index 3746c58f..8314bde5 160000 --- a/deps/libtommath +++ b/deps/libtommath @@ -1 +1 @@ -Subproject commit 3746c58f29a1ebea15046932bbc9dacc35b4b214 +Subproject commit 8314bde5e5c8e5d9331460130a9d1066e324f091 diff --git a/src/Components/Modules/AssetHandler.cpp b/src/Components/Modules/AssetHandler.cpp index ae538b8b..b76def14 100644 --- a/src/Components/Modules/AssetHandler.cpp +++ b/src/Components/Modules/AssetHandler.cpp @@ -224,6 +224,18 @@ namespace Components void AssetHandler::ModifyAsset(Game::XAssetType type, Game::XAssetHeader asset, const std::string& name) { +#ifdef DEBUG + if (type == Game::XAssetType::ASSET_TYPE_IMAGE && name[0] != ',') + { + const auto image = asset.image; + const auto cat = static_cast(image->category); + if (cat == Game::ImageCategory::IMG_CATEGORY_UNKNOWN) + { + Logger::Warning(Game::CON_CHANNEL_GFX, "Image {} has wrong category IMG_CATEGORY_UNKNOWN, this is an IMPORTANT ISSUE that should be fixed!\n", name); + } + } +#endif + if (type == Game::ASSET_TYPE_MATERIAL && (name == "gfx_distortion_knife_trail" || name == "gfx_distortion_heat_far" || name == "gfx_distortion_ring_light" || name == "gfx_distortion_heat") && asset.material->info.sortKey >= 43) { if (Zones::Version() >= VERSION_ALPHA2) diff --git a/src/Components/Modules/AssetInterfaces/IWeapon.cpp b/src/Components/Modules/AssetInterfaces/IWeapon.cpp index e256ebcd..dc27bef7 100644 --- a/src/Components/Modules/AssetInterfaces/IWeapon.cpp +++ b/src/Components/Modules/AssetInterfaces/IWeapon.cpp @@ -396,6 +396,7 @@ namespace Assets continue; } + buffer->align(Utils::Stream::ALIGN_4); buffer->saveMax(sizeof(Game::snd_alias_list_t*)); buffer->saveString(def->bounceSound[i]->aliasName); } @@ -525,7 +526,7 @@ namespace Assets if (def->physCollmap) { - dest->physCollmap = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSCOLLMAP, def->overlayMaterialEMPLowRes).physCollmap; + dest->physCollmap = builder->saveSubAsset(Game::XAssetType::ASSET_TYPE_PHYSCOLLMAP, def->physCollmap).physCollmap; } if (def->projectileModel) diff --git a/src/Components/Modules/Renderer.cpp b/src/Components/Modules/Renderer.cpp index 03cd72ca..191b82f5 100644 --- a/src/Components/Modules/Renderer.cpp +++ b/src/Components/Modules/Renderer.cpp @@ -382,7 +382,7 @@ namespace Components auto world = gfxAsset->asset.header.gfxWorld; auto drawDistance = r_playerDrawDebugDistance.get(); - auto sqrDist = drawDistance * drawDistance; + auto sqrDist = drawDistance * static_cast(drawDistance); switch (val) { diff --git a/src/Components/Modules/StructuredData.cpp b/src/Components/Modules/StructuredData.cpp index 7036559e..34f9e6c9 100644 --- a/src/Components/Modules/StructuredData.cpp +++ b/src/Components/Modules/StructuredData.cpp @@ -73,12 +73,12 @@ namespace Components // Sort alphabetically qsort(indices, dataVector.size(), sizeof(Game::StructuredDataEnumEntry), [](void const* first, void const* second) - { - const Game::StructuredDataEnumEntry* entry1 = reinterpret_cast(first); - const Game::StructuredDataEnumEntry* entry2 = reinterpret_cast(second); + { + const Game::StructuredDataEnumEntry* entry1 = reinterpret_cast(first); + const Game::StructuredDataEnumEntry* entry2 = reinterpret_cast(second); - return std::string(entry1->string).compare(entry2->string); - }); + return std::string(entry1->string).compare(entry2->string); + }); // Apply our patches dataEnum->entryCount = dataVector.size(); @@ -117,7 +117,7 @@ namespace Components } } - bool StructuredData::UpdateVersionOffsets(Game::StructuredDataDefSet *set, Game::StructuredDataBuffer *buffer, Game::StructuredDataDef *whatever) + bool StructuredData::UpdateVersionOffsets(Game::StructuredDataDefSet* set, Game::StructuredDataBuffer* buffer, Game::StructuredDataDef* whatever) { Game::StructuredDataDef* newDef = &set->defs[0]; Game::StructuredDataDef* oldDef = &set->defs[0]; @@ -149,10 +149,165 @@ namespace Components { if (Dedicated::IsEnabled()) return; - // Correctly upgrade stats - Utils::Hook(0x42F088, StructuredData::UpdateVersionOffsets, HOOK_CALL).install()->quick(); + // Do not execute this when building zones + if (!ZoneBuilder::IsEnabled()) + { + // Correctly upgrade stats + Utils::Hook(0x42F088, StructuredData::UpdateVersionOffsets, HOOK_CALL).install()->quick(); - // 15 or more custom classes - Utils::Hook::Set(0x60A2FE, NUM_CUSTOM_CLASSES); + // 15 or more custom classes + Utils::Hook::Set(0x60A2FE, NUM_CUSTOM_CLASSES); + + return; + } + + + // TODO: Since all of the following is zonebuilder-only code, move it to IW4OF or IStructuredDataDefSet.cpp + AssetHandler::OnLoad([](Game::XAssetType type, Game::XAssetHeader asset, const std::string& filename, bool* /*restrict*/) + { + if (ZoneBuilder::IsDumpingZone()) { + return; + } + + // Only intercept playerdatadef loading + if (type != Game::ASSET_TYPE_STRUCTURED_DATA_DEF || filename != "mp/playerdata.def") return; + + // Store asset + Game::StructuredDataDefSet* data = asset.structuredDataDefSet; + if (!data) return; + + if (data->defCount != 1) + { + Logger::Error(Game::ERR_FATAL, "PlayerDataDefSet contains more than 1 definition!"); + return; + } + + if (data->defs[0].version != 155) + { + Logger::Error(Game::ERR_FATAL, "Initial PlayerDataDef is not version 155, patching not possible!"); + return; + } + + std::unordered_map>> patchDefinitions; + std::unordered_map> otherPatchDefinitions; + + // First check if all versions are present + for (int i = 156;; ++i) + { + // We're on DB thread (OnLoad) so use DB thread for FS + FileSystem::File definition(std::format("{}/{}.json", filename, i), Game::FsThread::FS_THREAD_DATABASE); + if (!definition.exists()) break; + + std::vector> enumContainer; + std::unordered_map otherPatches; + + nlohmann::json defData; + try + { + defData = nlohmann::json::parse(definition.getBuffer()); + } + catch (const nlohmann::json::parse_error& ex) + { + Logger::PrintError(Game::CON_CHANNEL_ERROR, "JSON Parse Error: {}\n", ex.what()); + return; + } + + if (!defData.is_object()) + { + Logger::Error(Game::ERR_FATAL, "PlayerDataDef patch for version {} is invalid!", i); + return; + } + + for (auto pType = 0; pType < StructuredData::PlayerDataType::COUNT; ++pType) + { + auto enumData = defData[StructuredData::EnumTranslation[pType]]; + + std::vector entryData; + + if (enumData.is_array()) + { + for (const auto& rawEntry : enumData) + { + if (rawEntry.is_string()) + { + entryData.push_back(rawEntry.get()); + } + } + } + + enumContainer.push_back(entryData); + } + + auto other = defData["other"]; + + if (other.is_object()) + { + for (auto& item : other.items()) + { + if (item.value().is_string()) + { + otherPatches[item.key()] = item.value().get(); + } + } + } + + patchDefinitions[i] = enumContainer; + otherPatchDefinitions[i] = otherPatches; + } + + // Nothing to patch + if (patchDefinitions.empty()) return; + + // Reallocate the definition + auto* newData = StructuredData::MemAllocator.allocateArray(data->defCount + patchDefinitions.size()); + std::memcpy(&newData[patchDefinitions.size()], data->defs, sizeof Game::StructuredDataDef * data->defCount); + + // Prepare the buffers + for (unsigned int i = 0; i < patchDefinitions.size(); ++i) + { + std::memcpy(&newData[i], data->defs, sizeof Game::StructuredDataDef); + newData[i].version = (patchDefinitions.size() - i) + 155; + + // Reallocate the enum array + auto* newEnums = StructuredData::MemAllocator.allocateArray(data->defs->enumCount); + std::memcpy(newEnums, data->defs->enums, sizeof Game::StructuredDataEnum * data->defs->enumCount); + newData[i].enums = newEnums; + } + + // Apply new data + data->defs = newData; + data->defCount += patchDefinitions.size(); + + // Patch the definition + for (unsigned int i = 0; i < data->defCount; ++i) + { + // No need to patch version 155 + if (newData[i].version == 155) continue; + + if (patchDefinitions.contains(newData[i].version)) + { + auto patchData = patchDefinitions[newData[i].version]; + auto otherData = otherPatchDefinitions[newData[i].version]; + + // Invalid patch data + if (patchData.size() != StructuredData::PlayerDataType::COUNT) + { + Logger::Error(Game::ERR_FATAL, "PlayerDataDef patch for version {} wasn't parsed correctly!", newData[i].version); + continue; + } + + // Apply the patch data + for (auto pType = 0; pType < StructuredData::PlayerDataType::COUNT; ++pType) + { + if (!patchData[pType].empty()) + { + StructuredData::PatchPlayerDataEnum(&newData[i], static_cast(pType), patchData[pType]); + } + } + + StructuredData::PatchAdditionalData(&newData[i], otherData); + } + } + }); } } diff --git a/src/Components/Modules/ZoneBuilder.hpp b/src/Components/Modules/ZoneBuilder.hpp index c6fb46b6..1450faef 100644 --- a/src/Components/Modules/ZoneBuilder.hpp +++ b/src/Components/Modules/ZoneBuilder.hpp @@ -129,6 +129,7 @@ namespace Components #endif static bool IsEnabled(); + static bool IsDumpingZone() { return DumpingZone.length() > 0; }; static std::string TraceZone; static std::vector> TraceAssets; @@ -142,7 +143,7 @@ namespace Components static iw4of::api* GetExporter(); private: - static int StoreTexture(Game::GfxImageLoadDef **loadDef, Game::GfxImage *image); + static int StoreTexture(Game::GfxImageLoadDef** loadDef, Game::GfxImage* image); static void ReleaseTexture(Game::XAssetHeader header); static std::string FindMaterialByTechnique(const std::string& name);