# Type Mappings - C++ to C# Conversions ## Primitive Types | C++ Type | C# Type | Notes | |----------|---------|-------| | `DWORD` | `uint` | 32-bit unsigned integer | | `bool` | `bool` | Boolean | | `int` | `int` | 32-bit signed integer | | `float` | `float` | 32-bit floating point | | `double` | `double` | 64-bit floating point | | `char*` | `string` | String (C# uses managed strings) | | `const char*` | `string` | Constant string | | `size_t` | `uint` or `ulong` | Size type (usually uint) | | `clientid_t` | `long` | Client ID type | ## Vector Types | C++ Type | C# Type | Conversion Notes | |----------|---------|------------------| | `A3DVECTOR3` | `Vector3` | Unity's Vector3 | | `A3DVECTOR3&` | `Vector3` (ref) | Pass by reference | | `const A3DVECTOR3&` | `Vector3` (ref) | Const reference | ### A3DVECTOR3 to Vector3 Conversion **C++:** ```cpp A3DVECTOR3 vPos; vPos.x = 1.0f; vPos.y = 2.0f; vPos.z = 3.0f; ``` **C#:** ```csharp Vector3 vPos = new Vector3(1.0f, 2.0f, 3.0f); // Or Vector3 vPos; vPos.x = 1.0f; vPos.y = 2.0f; vPos.z = 3.0f; ``` **When accessing from A3DVECTOR3 struct:** ```csharp // If param.m_vSize is A3DVECTOR3 m_vSize = new Vector3(param.m_vSize.x, param.m_vSize.y, param.m_vSize.z); ``` ## Pointer Types | C++ Type | C# Type | Notes | |----------|---------|-------| | `T*` | `T` (reference) | C# uses references, not pointers | | `T*&` | `ref T` | Reference to pointer → ref reference | | `const T*` | `T` (readonly) | Const pointer → readonly reference | | `T**` | `ref T` or `T[]` | Pointer to pointer → ref or array | ### Examples **C++:** ```cpp A3DSkillGfxComposer* m_pComposer; CGfxMoveBase* m_pMoveMethod; void SetComposer(A3DSkillGfxComposer* pComposer); ``` **C#:** ```csharp A3DSkillGfxComposer m_pComposer; CGfxMoveBase m_pMoveMethod; void SetComposer(A3DSkillGfxComposer pComposer); ``` ## Struct Types ### GFX_SKILL_PARAM **C++:** ```cpp struct GFX_SKILL_PARAM { union { bool bVal; int nVal; float fVal; }; bool m_bArea; EmitShape m_Shape; A3DVECTOR3 m_vSize; }; ``` **C#:** ```csharp [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct GFX_SKILL_PARAM { public ValueUnion value; // Union wrapped in struct public bool m_bArea; public EmitShape m_Shape; public A3DVECTOR3 m_vSize; // Note: Uses A3DVECTOR3, not Vector3 [StructLayout(LayoutKind.Explicit)] public struct ValueUnion { [FieldOffset(0)] public bool bVal; [FieldOffset(0)] public int nVal; [FieldOffset(0)] public float fVal; } } ``` **Access Pattern:** ```csharp // C++: param.fVal // C#: param.value.fVal m_fRadius = param.value.fVal; ``` ## Enum Types | C++ Enum | C# Enum | Notes | |----------|---------|-------| | `enum GfxMoveMode { ... }` | `public enum GfxMoveMode { ... }` | Same values | | `enum GfxHitPos { ... }` | `public enum GfxHitPos { ... }` | Same values | | `enum EmitShape { ... }` | `public enum EmitShape { ... }` | Same values | **Preserve exact enum value names and order!** ## Function Signatures ### Method Parameters **C++:** ```cpp bool TickMove(DWORD dwDeltaTime, const A3DVECTOR3& vHostPos, const A3DVECTOR3& vTargetPos); void SetParam(const GFX_SKILL_PARAM* param); ``` **C#:** ```csharp bool TickMove(uint dwDeltaTime, Vector3 vHostPos, Vector3 vTargetPos); void SetParam(GFX_SKILL_PARAM param); // Struct passed by value (or ref if needed) ``` ### Return Types **C++:** ```cpp CGfxMoveBase* CreateMoveMethod(GfxMoveMode mode); const A3DVECTOR3& GetPos() const; ``` **C#:** ```csharp static CGfxMoveBase CreateMoveMethod(GfxMoveMode mode); Vector3 GetPos(); // No const in C# ``` ## Const Correctness | C++ | C# Equivalent | |-----|---------------| | `const T&` | `T` (value type) or `readonly T` (reference) | | `const T*` | `T` (reference, readonly) | | `const` method | No equivalent (use `readonly` for fields) | **C++:** ```cpp const A3DVECTOR3& GetPos() const; bool IsReverse() const; ``` **C#:** ```csharp Vector3 GetPos(); // No const modifier needed bool IsReverse(); // No const modifier needed ``` ## Memory Management | C++ | C# | |-----|-----| | `new T()` | `new T()` | | `delete ptr` | Automatic GC (or `Dispose()` for IDisposable) | | `delete[] arr` | Automatic GC | | `malloc/free` | Automatic GC | **C++:** ```cpp CGfxMoveBase* pMove = new CGfxLinearMove(mode); delete pMove; ``` **C#:** ```csharp CGfxMoveBase pMove = new CGfxLinearMove(mode); // Automatic garbage collection, or implement IDisposable if needed ``` ## Static Constants **C++:** ```cpp static const float _fly_speed = 20.0f / 1000.0f; static const float _gravity = 9.8e-6f; ``` **C#:** ```csharp private const float _fly_speed = 20.0f / 1000.0f; private const float _gravity = 9.8e-6f; ``` ## Helper Functions ### Normalize **C++:** ```cpp float Normalize(A3DVECTOR3& v) { float mag = v.Magnitude(); if (mag < 1e-6f) { v = _unit_zero; return 0f; } v /= mag; return mag; } ``` **C#:** ```csharp protected static float Normalize(ref Vector3 v) { float mag = v.magnitude; if (mag < 1e-6f) { v = Vector3.zero; return 0f; } v /= mag; return mag; } ``` ## Common Patterns ### Passing by Reference **C++:** ```cpp void CalcRange(const A3DVECTOR3& vDir); bool GetTargetDirAndUp(A3DVECTOR3& vDir, A3DVECTOR3& vUp); ``` **C#:** ```csharp void CalcRange(Vector3 vDir); // Value type, passed by value bool GetTargetDirAndUp(out Vector3 vDir, out Vector3 vUp); // Use out/ref ``` ### Array/Container Types | C++ | C# | |-----|-----| | `std::vector` | `List` | | `std::list` | `List` or `LinkedList` | | `std::map` | `Dictionary` | | `T[]` | `T[]` | ## Type Conversion Checklist When converting a method: - [ ] `DWORD` → `uint` - [ ] `A3DVECTOR3` → `Vector3` - [ ] `T*` → `T` (remove pointer) - [ ] `const T&` → `T` (remove const and reference) - [ ] `const T*` → `T` (remove const and pointer) - [ ] `char*` → `string` - [ ] `clientid_t` → `long` - [ ] Union access: `param.fVal` → `param.value.fVal` - [ ] `A3DVECTOR3` struct fields → `Vector3` constructor