Files
test/agent-skills/02-type-mappings.md
T
2026-02-24 09:50:08 +07:00

6.0 KiB

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++:

A3DVECTOR3 vPos;
vPos.x = 1.0f;
vPos.y = 2.0f;
vPos.z = 3.0f;

C#:

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:

// 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++:

A3DSkillGfxComposer* m_pComposer;
CGfxMoveBase* m_pMoveMethod;
void SetComposer(A3DSkillGfxComposer* pComposer);

C#:

A3DSkillGfxComposer m_pComposer;
CGfxMoveBase m_pMoveMethod;
void SetComposer(A3DSkillGfxComposer pComposer);

Struct Types

GFX_SKILL_PARAM

C++:

struct GFX_SKILL_PARAM
{
    union
    {
        bool bVal;
        int nVal;
        float fVal;
    };
    bool m_bArea;
    EmitShape m_Shape;
    A3DVECTOR3 m_vSize;
};

C#:

[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:

// 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++:

bool TickMove(DWORD dwDeltaTime, const A3DVECTOR3& vHostPos, const A3DVECTOR3& vTargetPos);
void SetParam(const GFX_SKILL_PARAM* param);

C#:

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++:

CGfxMoveBase* CreateMoveMethod(GfxMoveMode mode);
const A3DVECTOR3& GetPos() const;

C#:

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++:

const A3DVECTOR3& GetPos() const;
bool IsReverse() const;

C#:

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++:

CGfxMoveBase* pMove = new CGfxLinearMove(mode);
delete pMove;

C#:

CGfxMoveBase pMove = new CGfxLinearMove(mode);
// Automatic garbage collection, or implement IDisposable if needed

Static Constants

C++:

static const float _fly_speed = 20.0f / 1000.0f;
static const float _gravity = 9.8e-6f;

C#:

private const float _fly_speed = 20.0f / 1000.0f;
private const float _gravity = 9.8e-6f;

Helper Functions

Normalize

C++:

float Normalize(A3DVECTOR3& v)
{
    float mag = v.Magnitude();
    if (mag < 1e-6f) { v = _unit_zero; return 0f; }
    v /= mag;
    return mag;
}

C#:

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++:

void CalcRange(const A3DVECTOR3& vDir);
bool GetTargetDirAndUp(A3DVECTOR3& vDir, A3DVECTOR3& vUp);

C#:

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<T> List<T>
std::list<T> List<T> or LinkedList<T>
std::map<K,V> Dictionary<K,V>
T[] T[]

Type Conversion Checklist

When converting a method:

  • DWORDuint
  • A3DVECTOR3Vector3
  • T*T (remove pointer)
  • const T&T (remove const and reference)
  • const T*T (remove const and pointer)
  • char*string
  • clientid_tlong
  • Union access: param.fValparam.value.fVal
  • A3DVECTOR3 struct fields → Vector3 constructor