fix convert task data
This commit is contained in:
@@ -9,7 +9,7 @@ When reading binary data from C++ files using `FileStream`, follow these convers
|
||||
## Important Type Mappings
|
||||
|
||||
- `unsigned long` in C++ → `uint` in C#
|
||||
- `bool` in C++ → 1 byte (same as C# in struct layout)
|
||||
- `bool` in C++ → 1 byte (read as `byte` in C#, then convert with `> 0`)
|
||||
- `wchar_t` on Windows → 2 bytes
|
||||
- `task_char` → `ushort`
|
||||
- Pointer size in C++ binary → typically 4 bytes (32-bit)
|
||||
@@ -32,13 +32,24 @@ float m_fLibraryTasksProbability;
|
||||
```csharp
|
||||
// Read value and assign to the field
|
||||
fixedData.m_ID = AAssit.ReadFromBinaryOf<uint>(fp, ref readBytes);
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<bool>(fp, ref readBytes);
|
||||
|
||||
// Special case for bool: read as byte and compare with > 0
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<byte>(fp, ref readBytes) > 0;
|
||||
fixedData.m_bChooseOne = AAssit.ReadFromBinaryOf<byte>(fp, ref readBytes) > 0;
|
||||
|
||||
// Other primitive types
|
||||
fixedData.m_lAvailFrequency = AAssit.ReadFromBinaryOf<int>(fp, ref readBytes);
|
||||
fixedData.m_fLibraryTasksProbability = AAssit.ReadFromBinaryOf<float>(fp, ref readBytes);
|
||||
```
|
||||
|
||||
**Rule**: Use `AAssit.ReadFromBinaryOf<T>(fp, ref readBytes)` where T is the C# equivalent type.
|
||||
|
||||
**Important for bool**: C++ bool is stored as 1 byte in binary files. Always read as `byte` and convert to C# bool using `> 0`:
|
||||
```csharp
|
||||
// Correct pattern for bool
|
||||
fixedData.m_boolField = AAssit.ReadFromBinaryOf<byte>(fp, ref readBytes) > 0;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Case 2: Fixed-Size Arrays (Inline Memory)
|
||||
@@ -195,8 +206,8 @@ task_tm* m_tmStart; // Only has data if m_ulTimetable > 0
|
||||
|
||||
**C# Conversion**:
|
||||
```csharp
|
||||
// First read the flag/count
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<bool>(fp, ref readBytes);
|
||||
// First read the flag/count (read bool as byte and convert with > 0)
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<byte>(fp, ref readBytes) > 0;
|
||||
|
||||
// Skip the pointer (Case 3)
|
||||
fp.Seek(4, SeekOrigin.Current);
|
||||
@@ -250,6 +261,20 @@ public static T[] ReadArrayFromBinary<T>(FileStream fp, int count, ref long read
|
||||
|
||||
## Common Mistakes to Avoid
|
||||
|
||||
❌ **Wrong**: Reading bool directly as bool type
|
||||
```csharp
|
||||
// C++: bool m_bHasSign
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<bool>(fp, ref readBytes); // Wrong!
|
||||
```
|
||||
|
||||
✅ **Correct**:
|
||||
```csharp
|
||||
// Read as byte and compare with > 0
|
||||
fixedData.m_bHasSign = AAssit.ReadFromBinaryOf<byte>(fp, ref readBytes) > 0; // Correct!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
❌ **Wrong**: Skipping pointer size instead of basic type size for Case 5
|
||||
```csharp
|
||||
// C++: ushort* m_pszSignature
|
||||
|
||||
Reference in New Issue
Block a user