diff --git a/src/SendCommands.cc b/src/SendCommands.cc index e87b2e18..7cc2c50a 100644 --- a/src/SendCommands.cc +++ b/src/SendCommands.cc @@ -1115,6 +1115,14 @@ static std::vector(scaled_f); }; + auto append_patch_entry = [&](std::string& out, uint32_t offset, uint32_t value, uint8_t size) { + append_u32l(out, offset); + out.push_back(static_cast(size)); + for (uint8_t x = 0; x < size; x++) { + out.push_back(static_cast((value >> (x * 8)) & 0xFF)); + } + }; + constexpr uint32_t last_needed_offset = ultimate_block_offset + ((num_bp_rows - 1) * stats_row_size) + ultimate_exp_row_offset + 4; if (vanilla_data.size() < last_needed_offset) { @@ -1140,12 +1148,7 @@ static std::vector(new_atp & 0xFF)); - patch_entry_count++; - - append_u32l(suffix, atp_patch_offset + 1); - suffix.push_back(static_cast((new_atp >> 8) & 0xFF)); + append_patch_entry(suffix, atp_patch_offset, new_atp, 2); patch_entry_count++; const uint32_t hp_file_offset = row_file_offset + ultimate_hp_row_offset; @@ -1153,12 +1156,7 @@ static std::vector(new_hp & 0xFF)); - patch_entry_count++; - - append_u32l(suffix, hp_patch_offset + 1); - suffix.push_back(static_cast((new_hp >> 8) & 0xFF)); + append_patch_entry(suffix, hp_patch_offset, new_hp, 2); patch_entry_count++; const uint32_t exp_file_offset = row_file_offset + ultimate_exp_row_offset; @@ -1166,11 +1164,8 @@ static std::vector((new_exp >> (x * 8)) & 0xFF)); - patch_entry_count++; - } + append_patch_entry(suffix, exp_patch_offset, new_exp, 4); + patch_entry_count++; } suffix[12] = static_cast(patch_entry_count & 0xFF); diff --git a/system/client-functions/PsoPeepsBrutalPeepsPC.s b/system/client-functions/PsoPeepsBrutalPeepsPC.s index be7e2012..62dbd5ea 100644 --- a/system/client-functions/PsoPeepsBrutalPeepsPC.s +++ b/system/client-functions/PsoPeepsBrutalPeepsPC.s @@ -48,7 +48,7 @@ next_candidate: jmp scan_again found_table: - # esi = BattleParamEntry_on.dat base + # esi = matched Ultimate BattleParam block base mov ecx, [ebx + 12] # patch entry count mov edi, [ebx + 8] # signature_size lea edi, [ebx + edi + 16] # patch entries after header+signature @@ -57,16 +57,27 @@ patch_again: test ecx, ecx jz done - mov edx, [edi] # offset from table base - mov al, [edi + 4] # byte value - mov [esi + edx], al + mov edx, [edi] # offset from matched block base + movzx ebp, byte [edi + 4] # byte count + add edi, 5 # edi = source bytes - add edi, 5 +copy_patch_bytes_again: + test ebp, ebp + jz patch_entry_done + + mov al, [edi] + mov [esi + edx], al + inc edi + inc edx + dec ebp + jmp copy_patch_bytes_again + +patch_entry_done: dec ecx jmp patch_again done: - mov eax, esi # return found table base + mov eax, esi # return found block base jmp return not_found: @@ -82,12 +93,13 @@ return: get_data_ptr: call get_data_ptr_ret -# Server suffix starts here: +# Server suffix: # uint32_t scan_start # uint32_t scan_end # uint32_t signature_size # uint32_t patch_entry_count -# signature bytes from table start -# repeated patch entries: +# signature bytes +# repeated compact patch entries: # uint32_t offset -# uint8_t value +# uint8_t size +# uint8_t data[size]