Exemplo n.º 1
0
        private static void CallRaw(string identifier, params Parameter[] parameters)
        {
            // push arguments
            foreach (var parameter in parameters.Reverse())
            {
                parameter.PushValue();
            }

            // call the function
            if (!GameInterface.Script_Call(identifier.ToLowerInvariant(), _entRef, parameters.Length))
            {
                SetEntRef(-1);
                throw new ScriptException("Could not find function " + identifier);
            }

            // reset the entref to 0
            SetEntRef(-1);

            // check for return values
            _returnValue = null;

            if (GameInterface.Notify_NumArgs() == 1)
            {
                switch (GameInterface.Script_GetType(0))
                {
                case VariableType.Entity:
                    _returnValue = Entity.GetEntity(GameInterface.Script_GetEntRef(0));
                    break;

                case VariableType.Integer:
                    _returnValue = GameInterface.Script_GetInt(0);
                    break;

                case VariableType.Float:
                    _returnValue = GameInterface.Script_GetFloat(0);
                    break;

                case VariableType.String:
                    _returnValue = GameInterface.Script_GetString(0);
                    break;

                case VariableType.Vector:
                    Vector3 outValue;
                    GameInterface.Script_GetVector(0, out outValue);
                    _returnValue = outValue;
                    break;
                }
            }

            GameInterface.Script_CleanReturnStack();
        }
Exemplo n.º 2
0
        private static Parameter[] CollectParameters(int numArgs)
        {
            var paras = new Parameter[numArgs];

            for (int i = 0; i < numArgs; i++)
            {
                var    ptype = GameInterface.Script_GetType(i);
                object value = null;

                switch (ptype)
                {
                case VariableType.Integer:
                    value = GameInterface.Script_GetInt(i);
                    break;

                case VariableType.String:
                    value = Marshal.PtrToStringAnsi(GameInterface.Script_GetString(i));
                    break;

                case VariableType.Float:
                    value = GameInterface.Script_GetFloat(i);
                    break;

                case VariableType.Entity:
                    value = Entity.GetEntity(GameInterface.Script_GetEntRef(i));
                    break;

                case VariableType.Vector:
                    Vector3 v;
                    GameInterface.Script_GetVector(i, out v);
                    value = v;
                    break;

                default:
                    break;
                }

                paras[i] = new Parameter(ptype, value);
            }

            return(paras);
        }
Exemplo n.º 3
0
        public T GetField <T>(string name)
        {
            name = name.ToLowerInvariant();

            if (!_fieldNames.ContainsKey(name))
            {
                return((T)_privateFields[name]);
            }

            object returnValue = null;
            int    fieldID     = _fieldNames[name];

            GameInterface.Script_GetField(_entRef, fieldID);

            switch (GameInterface.Script_GetType(0))
            {
            case VariableType.Integer:
                returnValue = GameInterface.Script_GetInt(0);
                break;

            case VariableType.Float:
                returnValue = GameInterface.Script_GetFloat(0);
                break;

            case VariableType.String:
                returnValue = GameInterface.Script_GetString(0);
                break;

            case VariableType.Vector:
                Vector3 outValue;
                GameInterface.Script_GetVector(0, out outValue);
                returnValue = outValue;
                break;
            }

            GameInterface.Script_CleanReturnStack();

            return((T)Convert.ChangeType(returnValue, typeof(T)));
        }