> For the complete documentation index, see [llms.txt](https://help.diarkis.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.diarkis.io/diarkis-client/game-engine-integration/ue/packet-manipulator-noi.md).

# Packet Manipulator の使い方

## 概要

本ページでは UE プラグインから Packet Manipulator を使用する方法を説明します。Packet Manipulator の基本的な使い方については [Packet Manipulator](/diarkis-client/runtime-library/packet-manipulator.md) をご参照ください。

## インスタンスの取得

UE プラグインで Packet Manipulator のインスタンスを取得するには `DiarkisGetPacketManipulator()` を使用します。libdiarkis の `Diarkis::System::PacketManipulator::DiarkisGetPacketManipulator()` を直接使用すると意図しないインスタンスが返されるためご注意ください。

```cpp
#include "DiarkisFunctions.h"

...

Diarkis::System::PacketManipulator::IPacketManipulator* pacman = DiarkisGetPacketManipulator();
```

## サンプル実装

本セクションでは Diarkis プラグインの Zombie サンプルに Packet Manipulator を追加して効果を確認する方法について説明します。

<figure><img src="https://669307705-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlFJ89PMX2ike3NyauXNM%2Fuploads%2FSK68Up5R9HMjTbbjrzfC%2Fimage.png?alt=media&amp;token=e0a1a9ed-d85c-458f-a13b-42b099df2dd6" alt=""><figcaption></figcaption></figure>

### プリセットフィルタの追加

以下のコードでアプリの開始時にパケット遅延のプリセットフィルタを設定します。

```cpp
#include "DiarkisFunctions.h"

...

void AGameManager::OnGameInstStart(const GameInstStartEventArgs& args)
{
    auto pacman = DiarkisGetPacketManipulator();
    // Diarkis の UDP パケットすべてにフィルタを適用します。
    auto rawUdpRecvFilterSet = pacman->GetOrAllocFilterSet(Diarkis::System::PacketManipulator::FilterApplyPoint::RawUdpReceive);

    if (auto rawUdpRecvFilterSetPtr = rawUdpRecvFilterSet.lock())
    {
        // 新たに設定する前に既存のフィルタをリセットします。
        rawUdpRecvFilterSetPtr->ClearFilters();
        // すべてのパケットに 200 - 300 ms の遅延が発生する設定です。
        // RTT としてはこの設定値の 2 倍の値となります。
        rawUdpRecvFilterSetPtr->AddPacketDelayFilter(1.0f, 200, 300);
    }
    ...
```

### Packet Manipulator の更新処理の追加

Packet Manipulator が管理するフィルタの状態を更新するために定期的に `IPacketManipulator::Update()` を実行する必要があります。本サンプル実装では Tick にて定期的に実行していますが、アプリ全体で一度実行すればよい処理となりますので、ご都合に合わせて適切な場所で実行するようにしてください。

```cpp
void AGameManager::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    DiarkisGetPacketManipulator()->Update();
    ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://help.diarkis.io/diarkis-client/game-engine-integration/ue/packet-manipulator-noi.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
