# Dumpcs2Protobuf Architectural Specification & Schema Reconstruction Deep Dive
This technical specification provides an exhaustive, code-level analysis of **`Dumpcs2Protobuf`** (by Hiro420), a specialized C# (.NET 8.0) schema recovery utility engineered to reconstruct Protocol Buffers v3 (`.proto`) definition files directly from the decompiled C# source files (`dump.cs`) emitted by IL2CPP metadata dumpers (such as `honkai-dumper` or `Firefly-Static-Parser`).
---
## 1. Executive Summary & Architectural Role
### 1.1 The Protocol Recovery Gap
In modern IL2CPP game research, obtaining usable network protocol schemas involves bridging a critical semantic gap:
3. Manually translating thousands of obfuscated C# packet classes into `.proto` files is infeasible.
### 1.2 The De-Compilation Inverse
`Dumpcs2Protobuf` operates as the **exact inverse** of Google's Protocol Buffers C# compiler (`protoc --csharp_out`):
- When Google's `protoc` compiles a `.proto` file into C#, it generates deterministic structural signatures (constant field numbers, `RepeatedField<T>`, `MapField<K, V>`, `OneofCase` enums, and `OriginalNameAttribute`).
-`Dumpcs2Protobuf` analyzes these exact code generation patterns inside `dump.cs`, extracts field tags, names, and types, and **reconstructs valid `proto3` syntax**.
Even if the class name (`FGEMFOPIADP`) and field constant (`PNKKDKOGMOM`) are obfuscated, **the metadata attribute preserves the original protocol identifier `CmdCityShopInfoScNotify` and its integer value `1533`!**
---
## 3. Codebase Architecture & Data Models
The project is structured into two source files:
```
Dumpcs2Protobuf/
├── Proto.cs # Abstract Syntax Tree (AST) data models
└── MainApp.cs # File chunker, regex extractors, type mapper, and proto serializer
1. It identifies the discriminator property (e.g. `public ChoiceOneofCase ChoiceCase { get; }`).
2. It locates and parses the enum declaration (`ChoiceOneofCase`) across all segments.
3. For each field, if its wire tag number matches an entry in `oneofEnum.valDict`, it is placed inside `oneof <oneofName> { ... }`.
4. The discriminator enum is added to `blackListEnumNames` so it is not emitted as a standalone top-level enum in the `.proto` file.
### 4.5 De-Obfuscating Enums via `OriginalNameAttribute`
In `parseEnum`:
```csharp
if (lines[i-1].Contains("[OriginalNameAttribute(Name = \"")) {
string upperLine = lines[i-1];
name = upperLine.Split("[OriginalNameAttribute(Name = \"").Last().Split("\"").First();
} else {
name = line.Split($"{enumName} ").Last().Split("=").First().Trim();
}
```
If an enum constant is obfuscated (e.g. `IHJPPFIKELH`), it inspects the preceding line for `[OriginalNameAttribute]`, effortlessly restoring the original identifier (`CmdShopTypeNone = 0;`).
---
## 5. Output Serialization
`Dumpcs2Protobuf` serializes the AST into clean `proto3` syntax:
```protobuf
// Extracted from dump.cs using Dumpcs2Protobuf
syntax = "proto3";
message SceneEntityInfo {
uint32 entity_id = 1;
uint32 group_id = 2;
uint32 inst_id = 3;
MotionInfo motion = 4;
oneof entity {
ActorInfo actor = 5;
NpcInfo npc = 6;
MonsterInfo monster = 7;
}
}
enum CmdCityShopInfoScNotify {
CmdShopTypeNone = 0;
CmdCityShopInfoScNotify = 1533;
}
```
---
## 6. The Complete 6-Tool Unified Star Rail Protocol Toolchain
We can now map how all 6 repositories analyzed in this session interact to form an end-to-end, automated protocol engineering pipeline:
## 7. Technical Critique & Production Blueprint for `GaC-hkrpg-go`
While `Dumpcs2Protobuf` is concise and functional, a production-grade schema generator for `GaC-hkrpg-go` should address several structural limitations:
### 7.1 Limitations of the Regex Implementation
1. **Single Output File**: Dumps everything into a single monolithic `output.proto` file, leading to circular dependency and compilation issues.
2. **Missing Imports**: Does not generate `import "OtherMessage.proto";` statements required when messages reference other message types.
3. **Rigid Field Ordering Assumption**: Relies on field numbers appearing sequentially in the exact line order of properties. If the decompiler or compiler re-orders field definitions, tag pairing can desynchronize.
### 7.2 Production Go Implementation Blueprint
A robust schema extractor in Go for `GaC-hkrpg-go` can parse the C# definitions and emit properly modularized proto files: