Ejemplo n.º 1
0
        /// <summary>
        /// Prints a structure´s parameters to the console.
        /// </summary>
        /// <param name="parameters">The console input.</param>
        private void printStructureParams_console(ParameterCollection parameters)
        {
            if (parameters.Count == 0)
            {
                Game.Console.Print("usage: si_printparams <structure name>");
                return;
            }

            string structName = parameters.ToString(0);

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            Game.Console.Print("Listing parameters for structure \"" + structName + "\":");

            SParameter tempParameter = new SParameter();

            for (int i = 0; i < tempStruct.NumParams; i++)
            {
                tempStruct.GetGenericParamByIndex(i, out tempParameter);
                Game.Console.Print(tempParameter.ParamName.ToString() + "  " + "0x" + String.Format("{0:X}", tempParameter.Offset) + "  " + tempParameter.Type.ToString() + "  " + tempParameter.MinVal.ToString() + "  " + tempParameter.MaxVal.ToString());
            }
        }
Ejemplo n.º 2
0
        private void getParamName_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            // si_getparamnum <call identifier> <structure name> <param index>
            if (parameters.Count < 3)
            {
                // Error code -1: invalid parameter count
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert <string>(1);

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code -3: invalid struct name
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 3);
                return;
            }

            int paramIndex = parameters.Convert <int>(2);

            if (paramIndex < 0 || paramIndex >= tempStruct.NumParams)
            {
                // Error code -4: invalid parameter index
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 4);
            }

            SParameter tempParameter = new SParameter();

            tempStruct.GetGenericParamByIndex(paramIndex, out tempParameter);

            SendScriptCommand(sender, "si_getelementsnum_response", parameters[0], tempParameter.ParamName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a parameter's value.
        /// </summary>
        /// <param name="index">The parameter's index.</param>
        /// <returns>A string representing the parameter's value.</returns>
        private string getParamValue(int index)
        {
            SParameter      tempParam  = new SParameter();
            CEditableStruct tempStruct = GlobalVars.Structures[this.currentStructIndex];

            tempStruct.GetGenericParamByIndex(index, out tempParam);

            if (tempParam.Type == typeof(float))
            {
                float value = 0f;

                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(string))
            {
                string value = string.Empty;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value);
            }
            else if (tempParam.Type == typeof(char))
            {
                char value = '\0';
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(int))
            {
                int value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(short))
            {
                short value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(double))
            {
                double value = 0f;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }
            else if (tempParam.Type == typeof(long))
            {
                long value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return(value.ToString());
            }

            return(string.Empty);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a generic parameter by it's index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="parameter">The found parameter.</param>
        /// <returns>On success: 0. On no parameter found: 1.</returns>
        public int GetGenericParamByIndex(int index, out SParameter parameter)
        {
            if (index < 0 || index >= this._numParams)
            {
                parameter = new SParameter();
                return(1);
            }

            parameter = this._parameters[index];
            return(0);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Finds a parameter by it's name.
        /// </summary>
        /// <param name="paramName">Name of the parameter.</param>
        /// <param name="foundParam">The found parameter.</param>
        /// <returns>On success: 0. On no found parameter: 1.</returns>
        public int GetGenericParamByName(string paramName, ref SParameter foundParam)
        {
            for (int i = 0; i < this._parameters.Count; i++)
            {
                if (this._parameters[i].ParamName == paramName)
                {
                    foundParam = this._parameters[i];
                    return(0);
                }
            }

            return(1);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Reloads the parameters and values.
        /// </summary>
        private void reloadParams()
        {
            this.listBox.Items.Clear();
            this.listBox_values.Items.Clear();

            SParameter tempParam = new SParameter();

            // We load in the parameters
            for (int i = 0; i < GlobalVars.Structures[this.currentStructIndex].NumParams; i++)
            {
                GlobalVars.Structures[this.currentStructIndex].GetGenericParamByIndex(i, out tempParam);
                this.listBox.Items.Add(new ListboxItem(), tempParam.ParamName);

                this.listBox_values.Items.Add(new ListboxItem(), this.getParamValue(i));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Reloads the parameters and values.
        /// </summary>
        private void reloadParams()
        {
            this.listBox.Items.Clear();
            this.listBox_values.Items.Clear();

            SParameter tempParam = new SParameter();

            // We load in the parameters
            for (int i = 0; i < GlobalVars.Structures[this.currentStructIndex].NumParams; i++)
            {
                GlobalVars.Structures[this.currentStructIndex].GetGenericParamByIndex(i, out tempParam);
                this.listBox.Items.Add(new ListboxItem(), tempParam.ParamName);

                this.listBox_values.Items.Add(new ListboxItem(), this.getParamValue(i));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handles the Click event of the editValBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GTA.MouseEventArgs"/> instance containing the event data.</param>
        void editValBtn_Click(object sender, MouseEventArgs e)
        {
            SParameter tempParam = new SParameter();
            GlobalVars.Structures[this.currentStructIndex].GetGenericParamByIndex(this.listBox.SelectedIndex, out tempParam);

            int selectedIndex = this.listBox_values.SelectedIndex;

            if (tempParam.Type == typeof(int))
            {
                int newVal = 0;
                if (Int32.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint newVal = 0;
                if (uint.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, this.newVal.Text);
            }
            else if (tempParam.Type == typeof(char))
            {
                char newVal = this.newVal.Text.ToCharArray()[0];
                GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = 0;
                if (float.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = 0;
                if (double.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = 0;
                if (short.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = 0;
                if (long.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }

            this.reloadParams();
            this.listBox_values.SelectedIndex = selectedIndex;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets a parameter's value.
        /// </summary>
        /// <param name="index">The parameter's index.</param>
        /// <returns>A string representing the parameter's value.</returns>
        private string getParamValue(int index)
        {
            SParameter tempParam = new SParameter();
            CEditableStruct tempStruct = GlobalVars.Structures[this.currentStructIndex];
            tempStruct.GetGenericParamByIndex(index, out tempParam);

            if (tempParam.Type == typeof(float))
            {
                float value = 0f;

                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(string))
            {
                string value = string.Empty;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value;
            }
            else if (tempParam.Type == typeof(char))
            {
                char value = '\0';
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(int))
            {
                int value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(short))
            {
                short value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(double))
            {
                double value = 0f;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }
            else if (tempParam.Type == typeof(long))
            {
                long value = 0;
                tempStruct.GetParamValue(this.currentElementIndex, index, ref value);
                return value.ToString();
            }

            return string.Empty;
        }
Ejemplo n.º 10
0
        private void setParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            if (parameters.Count < 5)
            {
                // Error code 1: invalid parameter count
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert<string>(1);

            int index = 0;

            if (!int.TryParse(parameters.Convert<string>(2), out index))
            {
                // Error code 2: invalid index
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 2);
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code 3: invalid struct name
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 3);
                return;
            }

            string paramName = parameters.Convert<string>(3);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                // Error code 4: invalid param name
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 4);
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int newVal = parameters.Convert<int>(4);
                int retVal = tempStruct.SetParamValue<int>(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                string newVal = parameters.Convert<string>(4);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
                else if (retVal == -3)
                {
                    // Error code 6: input string too long
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6);
                    return;
                }
            }
            else if (tempParam.Type == typeof(char))
            {
                string newValString = parameters.Convert<string>(4);
                char newVal = '\0';
                int retVal = 0;

                if (newValString != string.Empty)
                {
                    newVal = newValString[0];
                    if (retVal == -1)
                    {
                        // Error code 5: invalid param index number
                        SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                        return;
                    }
                }
                else
                {
                    // Error code 6: invalid character entered
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6);
                    return;
                }
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = parameters.Convert<float>(4);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = parameters.Convert<float>(4);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = parameters.Convert<short>(4);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = parameters.Convert<long>(4);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }

            // Success! :D
            SendScriptCommand(sender, "si_setparamvalue_respons", parameters[0], 0);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Edits a structure's parameter value, using the console input.
        /// </summary>
        /// <param name="parameters">The console input..</param>
        private void editStructureParam_console(ParameterCollection parameters)
        {
            if (parameters.Count < 4)
            {
                Game.Console.Print("usage: si_editparam <structure name> <element index> <param name> <new value>");
                return;
            }

            string structName = parameters.ToString(0);

            int index = 0;

            if (!int.TryParse(parameters.ToString(1), out index))
            {
                Game.Console.Print("Invalid index specified!");
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            string paramName = parameters.ToString(2);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                Game.Console.Print("No parameter found with name \"" + paramName + "\"!");
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int newVal = parameters.ToInteger(3);
                int retVal = tempStruct.SetParamValue<int>(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint newVal = uint.Parse(parameters.ToString(3));
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                string newVal = parameters.ToString(3);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else if (retVal == -3)
                {
                    Game.Console.Print("Input string too long! Max size: " + tempParam.StringSize.ToString() + ", your input: " + newVal.Length);
                    return;
                }
            }
            else if (tempParam.Type == typeof(char))
            {
                string newValString = parameters.ToString(3);
                char newVal = '\0';
                int retVal = 0;

                if (newValString != string.Empty)
                {
                    newVal = newValString[0];
                    if (retVal == -1)
                    {
                        Game.Console.Print("Invalid parameter index number");
                        return;
                    }
                    else
                    {
                        Game.Console.Print("Parameter changed");
                    }
                }
                else
                {
                    Game.Console.Print("Invalid char entered!");
                    return;
                }
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = parameters.ToFloat(3);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = parameters.ToFloat(3);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = (short)parameters.ToInteger(3);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = parameters.ToInteger(3);
                int retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Prints a structure´s parameters to the console.
        /// </summary>
        /// <param name="parameters">The console input.</param>
        private void printStructureParams_console(ParameterCollection parameters)
        {
            if (parameters.Count == 0)
            {
                Game.Console.Print("usage: si_printparams <structure name>");
                return;
            }

            string structName = parameters.ToString(0);

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            Game.Console.Print("Listing parameters for structure \"" + structName + "\":");

            SParameter tempParameter = new SParameter();

            for (int i = 0; i < tempStruct.NumParams; i++)
            {
                tempStruct.GetGenericParamByIndex(i, out tempParameter);
                Game.Console.Print(tempParameter.ParamName.ToString() + "  " + "0x" + String.Format("{0:X}", tempParameter.Offset) + "  " + tempParameter.Type.ToString() + "  " + tempParameter.MinVal.ToString() + "  " + tempParameter.MaxVal.ToString());
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Prints a structure´s parameter values to the console.
        /// </summary>
        /// <param name="parameters">The console input.</param>
        private void printStructureValues_console(ParameterCollection parameters)
        {
            if (parameters.Count < 2)
            {
                Game.Console.Print("usage: si_printvalues <structure name> <element index>");
                return;
            }

            string structName = parameters.ToString(0);
            int index = 0;

            if (!int.TryParse(parameters.ToString(1), out index))
            {
                Game.Console.Print("Invalid index specified!");
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            SParameter tempParam = new SParameter();

            for (int i = 0; i < tempStruct.NumParams; i++)
            {
                tempStruct.GetGenericParamByIndex(i, out tempParam);

                if (tempParam.Type == typeof(float))
                {
                    float value = 0f;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(uint))
                {
                    uint value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(string))
                {
                    string value = string.Empty;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value);
                }
                else if (tempParam.Type == typeof(char))
                {
                    char value = '\0';
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value);
                }
                else if (tempParam.Type == typeof(int))
                {
                    int value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(short))
                {
                    short value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(double))
                {
                    double value = 0f;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(long))
                {
                    long value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(char[]))
                {
                    int value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Gets the value of a parameter.
        /// </summary>
        /// <typeparam name="T">The type of the parameter</typeparam>
        /// <param name="index">The paramter index.</param>
        /// <param name="paramIndex">Index of the parameter.</param>
        /// <param name="paramValue">The parameter value.</param>
        /// <returns>On success: 0. On invalid index number: -1. On unsupported param type: -2. On invalid paramter index number: -3.</returns>
        public int GetParamValue <T>(int index, int paramIndex, ref T paramValue)
        {
            if (index >= this._numElements || index < 0)
            {
                // Error code -1: invalid index number.
                return(-1);
            }

            SParameter tempParam = new SParameter();

            if (paramIndex < 0 || paramIndex >= this._numParams)
            {
                // Error code -3: invalid param index number
                return(-3);
            }

            tempParam = this._parameters[paramIndex];

            int paramAddress = this.GetElementAddress(index) + tempParam.Offset;

            if (typeof(T) == typeof(int))
            {
                paramValue = (T)(object)*(int *)(paramAddress);
            }
            else if (typeof(T) == typeof(uint))
            {
                paramValue = (T)(object)*(uint *)(paramAddress);
            }
            else if (typeof(T) == typeof(string))
            {
                string paramString = string.Empty;
                byte[] charArray   = new byte[tempParam.StringSize];

                // We load in the characters one by one
                for (int i = 0; i < tempParam.StringSize; i++)
                {
                    charArray[i] = *(byte *)(paramAddress + i);
                }

                paramString = Encoding.ASCII.GetString(charArray);
                paramValue  = (T)(object)paramString;
            }
            else if (typeof(T) == typeof(char))
            {
                paramValue = (T)(object)*(char *)(paramAddress);
            }
            else if (typeof(T) == typeof(short))
            {
                paramValue = (T)(object)*(short *)(paramAddress);
            }
            else if (typeof(T) == typeof(float))
            {
                paramValue = (T)(object)*(float *)(paramAddress);
            }
            else if (typeof(T) == typeof(double))
            {
                paramValue = (T)(object)*(double *)(paramAddress);
            }
            else if (typeof(T) == typeof(long))
            {
                paramValue = (T)(object)*(long *)(paramAddress);
            }
            else if (typeof(T) == typeof(char[]))
            {
                paramValue = (T)(object)*(char *)(paramAddress);
            }
            else
            {
                // Error code -2: unsupported parameter type
                return(-2);
            }

            return(0);
        }
Ejemplo n.º 15
0
        private void getParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            // si_getparamvalue <call identifier> <structure name> <element index> <parameter name>
            if (parameters.Count < 4)
            {
                // Error code 1: invalid parameter count
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert <string>(1);

            int index = 0;

            if (!int.TryParse(parameters.Convert <string>(2), out index))
            {
                // Error code 2: invalid index
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 2);
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code 3: invalid struct name
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 3);
                return;
            }

            string     paramName = parameters.Convert <string>(3);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                // Error code 4: invalid param name
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 4);
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(string))
            {
                string retVal = string.Empty;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(char))
            {
                char retVal = char.MinValue;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(float))
            {
                float retVal = 0f;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(double))
            {
                double retVal = 0f;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(short))
            {
                short retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(long))
            {
                long retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }

            return;
        }
Ejemplo n.º 16
0
        private void setParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            if (parameters.Count < 5)
            {
                // Error code 1: invalid parameter count
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert <string>(1);

            int index = 0;

            if (!int.TryParse(parameters.Convert <string>(2), out index))
            {
                // Error code 2: invalid index
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 2);
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code 3: invalid struct name
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 3);
                return;
            }

            string     paramName = parameters.Convert <string>(3);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                // Error code 4: invalid param name
                SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 4);
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int newVal = parameters.Convert <int>(4);
                int retVal = tempStruct.SetParamValue <int>(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                string newVal = parameters.Convert <string>(4);
                int    retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
                else if (retVal == -3)
                {
                    // Error code 6: input string too long
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6);
                    return;
                }
            }
            else if (tempParam.Type == typeof(char))
            {
                string newValString = parameters.Convert <string>(4);
                char   newVal       = '\0';
                int    retVal       = 0;

                if (newValString != string.Empty)
                {
                    newVal = newValString[0];
                    if (retVal == -1)
                    {
                        // Error code 5: invalid param index number
                        SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                        return;
                    }
                }
                else
                {
                    // Error code 6: invalid character entered
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 6);
                    return;
                }
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = parameters.Convert <float>(4);
                int   retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = parameters.Convert <float>(4);
                int    retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = parameters.Convert <short>(4);
                int   retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = parameters.Convert <long>(4);
                int  retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    // Error code 5: invalid param index number
                    SendScriptCommand(sender, "si_setparamvalue_response", parameters[0], 5);
                    return;
                }
            }

            // Success! :D
            SendScriptCommand(sender, "si_setparamvalue_respons", parameters[0], 0);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Edits a structure's parameter value, using the console input.
        /// </summary>
        /// <param name="parameters">The console input..</param>
        private void editStructureParam_console(ParameterCollection parameters)
        {
            if (parameters.Count < 4)
            {
                Game.Console.Print("usage: si_editparam <structure name> <element index> <param name> <new value>");
                return;
            }

            string structName = parameters.ToString(0);

            int index = 0;

            if (!int.TryParse(parameters.ToString(1), out index))
            {
                Game.Console.Print("Invalid index specified!");
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            string     paramName = parameters.ToString(2);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                Game.Console.Print("No parameter found with name \"" + paramName + "\"!");
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int newVal = parameters.ToInteger(3);
                int retVal = tempStruct.SetParamValue <int>(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint newVal = uint.Parse(parameters.ToString(3));
                int  retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                string newVal = parameters.ToString(3);
                int    retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else if (retVal == -3)
                {
                    Game.Console.Print("Input string too long! Max size: " + tempParam.StringSize.ToString() + ", your input: " + newVal.Length);
                    return;
                }
            }
            else if (tempParam.Type == typeof(char))
            {
                string newValString = parameters.ToString(3);
                char   newVal       = '\0';
                int    retVal       = 0;

                if (newValString != string.Empty)
                {
                    newVal = newValString[0];
                    if (retVal == -1)
                    {
                        Game.Console.Print("Invalid parameter index number");
                        return;
                    }
                    else
                    {
                        Game.Console.Print("Parameter changed");
                    }
                }
                else
                {
                    Game.Console.Print("Invalid char entered!");
                    return;
                }
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = parameters.ToFloat(3);
                int   retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = parameters.ToFloat(3);
                int    retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = (short)parameters.ToInteger(3);
                int   retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = parameters.ToInteger(3);
                int  retVal = tempStruct.SetParamValue(index, paramName, newVal);

                if (retVal == -1)
                {
                    Game.Console.Print("Invalid parameter index number");
                    return;
                }
                else
                {
                    Game.Console.Print("Parameter changed");
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Handles the Click event of the editValBtn control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="GTA.MouseEventArgs"/> instance containing the event data.</param>
        void editValBtn_Click(object sender, MouseEventArgs e)
        {
            SParameter tempParam = new SParameter();

            GlobalVars.Structures[this.currentStructIndex].GetGenericParamByIndex(this.listBox.SelectedIndex, out tempParam);

            int selectedIndex = this.listBox_values.SelectedIndex;

            if (tempParam.Type == typeof(int))
            {
                int newVal = 0;
                if (Int32.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(uint))
            {
                uint newVal = 0;
                if (uint.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(string))
            {
                GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, this.newVal.Text);
            }
            else if (tempParam.Type == typeof(char))
            {
                char newVal = this.newVal.Text.ToCharArray()[0];
                GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
            }
            else if (tempParam.Type == typeof(float))
            {
                float newVal = 0;
                if (float.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(double))
            {
                double newVal = 0;
                if (double.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(short))
            {
                short newVal = 0;
                if (short.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }
            else if (tempParam.Type == typeof(long))
            {
                long newVal = 0;
                if (long.TryParse(this.newVal.Text, out newVal))
                {
                    GlobalVars.Structures[this.currentStructIndex].SetParamValue(this.currentElementIndex, this.listBox.SelectedIndex, newVal);
                }
            }

            this.reloadParams();
            this.listBox_values.SelectedIndex = selectedIndex;
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new CEditableStruct from an input file.
        /// </summary>
        /// <param name="filePath">The file path to the input file.</param>
        /// <param name="structure">The structure to create.</param>
        /// <param name="errorLine">The error line. When an error has occured this value will be adjusted accordingly.</param>
        /// <returns>0: success.
        /// 1: invalid number of elements in file header.
        /// 2: error parsing element 2 of file header (invalid integer).
        /// 3: error parsing element 3 of file header (invalid integer).
        /// 4: error parsing element 4 of file header (invalid integer).
        /// 5: invalid number of elements in parameter-describing line.
        /// 6: error parsing element 1 of parameter-line (invalid integer).
        /// 7: invalid parameter type
        /// 8: invalid float value for parameter.
        /// 9: invalid 4th element (invalid float)
        /// 10: failed to open input file
        /// 11: invalid parameter type 'char[]': invalid string length specified.</returns>
        public static int CreateStructure(string filePath, ref CEditableStruct structure, ref int errorLine)
        {
            string structName = string.Empty;

            int structSize = 0, structOffset = 0, numElements = 0;
            List <SParameter> parameters = new List <SParameter>();

            System.IO.StreamReader sr;
            try
            {
                sr = new StreamReader(filePath);
            }
            catch (SystemException se)
            {
                // Failed to open the file! :O Error code 10
                return(10);
            }

            string line = string.Empty;

            int numLines     = 0;
            int numRealLines = 0;

            char[] delimiter = new char[1];
            delimiter[0] = ' ';

            while (line != null)
            {
                line = sr.ReadLine();
                numLines++;

                if (!IgnoreLine(line))
                {
                    numRealLines++;

                    // We have the header, hopefully :)
                    if (numRealLines == 1)
                    {
                        string[] elements = line.Split(delimiter, StringSplitOptions.None);

                        if (elements.Length != 4)
                        {
                            // We are expecting 4 elements
                            errorLine = numLines;

                            // Error code 1: invalid number of elements in file header.
                            sr.Close();
                            return(1);
                        }

                        structName = elements[0];

                        // If integer parsing failed...

                        if (!TryParseInteger(elements[1], ref structSize))
                        {
                            errorLine = numLines;
                            // Error code 2: error parsing parameter 2 of file header (invalid integer).
                            sr.Close();
                            return(2);
                        }

                        if (!TryParseInteger(elements[2], ref structOffset))
                        {
                            errorLine = numLines;
                            // Error code 3: error parsing parameter 3 of file header (invalid integer).
                            sr.Close();
                            return(3);
                        }

                        if (!TryParseInteger(elements[3], ref numElements))
                        {
                            errorLine = numLines;
                            // Error code 4: error parsing parameter 4 of file header (invalid integer).
                            sr.Close();
                            return(4);
                        }
                    }
                    else
                    {
                        // We are loading in parameters :)
                        SParameter tempParam = new SParameter();

                        string[] elements = line.Split(delimiter, StringSplitOptions.None);

                        if (elements.Length != 5)
                        {
                            // We are expecting 5 elements
                            errorLine = numLines;

                            // Error code 5: invalid number of elements in parameter line.
                            sr.Close();
                            return(5);
                        }

                        tempParam.ParamName = elements[0];

                        if (!TryParseInteger(elements[1], ref tempParam.Offset))
                        {
                            errorLine = numLines;

                            // Error code 6: error parsing parameter 1 of a parameter (invalid integer)
                            sr.Close();
                            return(6);
                        }

                        if (elements[2].Contains("CHAR["))
                        {
                            // Cleanup
                            elements[2] = elements[2].Replace("CHAR", string.Empty);
                            elements[2] = elements[2].Replace("[", string.Empty);
                            elements[2] = elements[2].Replace("]", string.Empty);
                            // Done

                            if (!int.TryParse(elements[2], out tempParam.StringSize))
                            {
                                // Error code 11: invalid parameter type 'CHAR[]': invalid string length specified.
                                sr.Close();
                                return(11);
                            }

                            tempParam.Type = typeof(string);
                        }
                        else
                        {
                            switch (elements[2])
                            {
                            case "INT":
                                tempParam.Type = typeof(int);
                                break;

                            case "UINT":
                                tempParam.Type = typeof(uint);
                                break;

                            case "FLOAT":
                                tempParam.Type = typeof(float);
                                break;

                            case "SHORT":
                                tempParam.Type = typeof(short);
                                break;

                            case "LONG":
                                tempParam.Type = typeof(long);
                                break;

                            case "DOUBLE":
                                tempParam.Type = typeof(double);
                                break;

                            case "CHAR":
                                tempParam.Type       = typeof(char);
                                tempParam.StringSize = 1;
                                break;

                            default:
                                errorLine = numLines;

                                // Error code 7: invalid parameter type
                                sr.Close();
                                return(7);
                            }

                            tempParam.StringSize = 0;
                        }

                        if (elements[3] == "NONE")
                        {
                            tempParam.MinVal = 0xCAFED00D;
                        }
                        else
                        {
                            if (!float.TryParse(elements[3], out tempParam.MinVal))
                            {
                                errorLine = numLines;

                                // Error code 8: invalid parameter 3 (invalid float)
                                sr.Close();
                                return(8);
                            }
                        }

                        if (elements[4] == "NONE")
                        {
                            tempParam.MaxVal = 0xCAFED00D;
                        }
                        else
                        {
                            if (!float.TryParse(elements[3], out tempParam.MaxVal))
                            {
                                errorLine = numLines;

                                // Error code 8: invalid parameter 4 (invalid float)
                                sr.Close();
                                return(9);
                            }
                        }

                        parameters.Add(tempParam);
                    }
                }
            }

            structure = new CEditableStruct(structName, GlobalVars.BaseAddress, structOffset, structSize, numElements, parameters);
            sr.Close();
            return(0);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Prints a structure´s parameter values to the console.
        /// </summary>
        /// <param name="parameters">The console input.</param>
        private void printStructureValues_console(ParameterCollection parameters)
        {
            if (parameters.Count < 2)
            {
                Game.Console.Print("usage: si_printvalues <structure name> <element index>");
                return;
            }

            string structName = parameters.ToString(0);
            int    index      = 0;

            if (!int.TryParse(parameters.ToString(1), out index))
            {
                Game.Console.Print("Invalid index specified!");
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                Game.Console.Print("No struct found with name \"" + structName + "\"!");
                return;
            }

            SParameter tempParam = new SParameter();

            for (int i = 0; i < tempStruct.NumParams; i++)
            {
                tempStruct.GetGenericParamByIndex(i, out tempParam);

                if (tempParam.Type == typeof(float))
                {
                    float value = 0f;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(uint))
                {
                    uint value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(string))
                {
                    string value = string.Empty;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value);
                }
                else if (tempParam.Type == typeof(char))
                {
                    char value = '\0';
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value);
                }
                else if (tempParam.Type == typeof(int))
                {
                    int value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(short))
                {
                    short value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(double))
                {
                    double value = 0f;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(long))
                {
                    long value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
                else if (tempParam.Type == typeof(char[]))
                {
                    int value = 0;
                    tempStruct.GetParamValue(index, i, ref value);
                    Game.Console.Print(tempParam.ParamName + " " + value.ToString());
                }
            }
        }
Ejemplo n.º 21
0
        private void getParamName_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            // si_getparamnum <call identifier> <structure name> <param index>
            if (parameters.Count < 3)
            {
                // Error code -1: invalid parameter count
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert<string>(1);

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code -3: invalid struct name
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 3);
                return;
            }

            int paramIndex = parameters.Convert<int>(2);
            if (paramIndex < 0 || paramIndex >= tempStruct.NumParams)
            {
                // Error code -4: invalid parameter index
                SendScriptCommand(sender, "si_getparamname_response", parameters[0], 4);
            }

            SParameter tempParameter = new SParameter();
            tempStruct.GetGenericParamByIndex(paramIndex, out tempParameter);

            SendScriptCommand(sender, "si_getelementsnum_response", parameters[0], tempParameter.ParamName);
        }
Ejemplo n.º 22
0
        private void getParamValue_scriptCmd(GTA.Script sender, GTA.ObjectCollection parameters)
        {
            // si_getparamvalue <call identifier> <structure name> <element index> <parameter name>
            if (parameters.Count < 4)
            {
                // Error code 1: invalid parameter count
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 1);
                return;
            }

            string structName = parameters.Convert<string>(1);

            int index = 0;

            if (!int.TryParse(parameters.Convert<string>(2), out index))
            {
                // Error code 2: invalid index
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 2);
                return;
            }

            CEditableStruct tempStruct = GlobalVars.Structures.Find(x => x.Name == structName);

            if (tempStruct == null)
            {
                // Error code 3: invalid struct name
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 3);
                return;
            }

            string paramName = parameters.Convert<string>(3);
            SParameter tempParam = new SParameter();

            if (tempStruct.GetGenericParamByName(paramName, ref tempParam) != 0)
            {
                // Error code 4: invalid param name
                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 4);
                return;
            }

            if (tempParam.Type == typeof(int))
            {
                int retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(string))
            {
                string retVal = string.Empty;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(char))
            {
                char retVal = char.MinValue;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(float))
            {
                float retVal = 0f;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(double))
            {
                double retVal = 0f;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(short))
            {
                short retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }
            else if (tempParam.Type == typeof(long))
            {
                long retVal = 0;
                tempStruct.GetParamValue(index, paramName, ref retVal);

                SendScriptCommand(sender, "si_getparamvalue_response", parameters[0], 0, retVal);
            }

            return;
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Changes a parameter's value by it's index.
        /// </summary>
        /// <typeparam name="T">The new value's type.</typeparam>
        /// <param name="index">The element index.</param>
        /// <param name="paramIndex">The parameter index.</param>
        /// <param name="newVal">The new value.</param>
        /// <returns>On success: 0. On invalid index number: -1. On unsupported parameter type: -2. On string length too long: -3. On invalid param index number: -4. On new value too large: -5. On new value too small: -6.</returns>
        public int SetParamValue <T>(int index, int paramIndex, T newVal)
        {
            if (index >= this._numElements || index < 0)
            {
                // Error code -1: invalid index number.
                return(-1);
            }

            SParameter tempParam = new SParameter();

            if (paramIndex >= this.NumParams || index < 0)
            {
                // Error code -4: invalid param index number
                return(-4);
            }

            tempParam = this._parameters[paramIndex];

            int paramAddress = this.GetElementAddress(index) + tempParam.Offset;

            if (typeof(T) == typeof(int))
            {
                if ((int)(object)newVal > (int)tempParam.MaxVal || (int)(object)newVal < (int)tempParam.MinVal)
                {
                    return(-4);
                }

                int *tempPtr = (int *)paramAddress;
                *    tempPtr = (int)(object)newVal;
            }
            else if (typeof(T) == typeof(uint))
            {
                if ((uint)(object)newVal > (uint)tempParam.MaxVal || (uint)(object)newVal < (uint)tempParam.MinVal)
                {
                    return(-4);
                }

                uint *tempPtr = (uint *)(paramAddress);
                *     tempPtr = (uint)(object)newVal;
            }
            else if (typeof(T) == typeof(string))
            {
                string newString = (string)(object)newVal;

                if (newString.Length > tempParam.StringSize)
                {
                    // Error code -3: string length too long
                    return(-3);
                }

                // Paste in the characters one by one
                for (int i = 0; i < tempParam.StringSize; i++)
                {
                    char *tempPtr = (char *)(paramAddress + i * sizeof(char));
                    *     tempPtr = newString[i];
                }
            }
            else if (typeof(T) == typeof(char))
            {
                char *tempPtr = (char *)paramAddress;
                *     tempPtr = (char)(object)newVal;
            }
            else if (typeof(T) == typeof(short))
            {
                if ((short)(object)newVal > (short)tempParam.MaxVal || (short)(object)newVal < (short)tempParam.MinVal)
                {
                    return(-4);
                }

                short *tempPtr = (short *)paramAddress;
                *      tempPtr = (short)(object)newVal;
            }
            else if (typeof(T) == typeof(float))
            {
                if ((float)(object)newVal > tempParam.MaxVal || (float)(object)newVal < tempParam.MinVal)
                {
                    return(-4);
                }

                float *tempPtr = (float *)paramAddress;
                *      tempPtr = (float)(object)newVal;
            }
            else if (typeof(T) == typeof(double))
            {
                if ((double)(object)newVal > tempParam.MaxVal || (double)(object)newVal < tempParam.MinVal)
                {
                    return(-4);
                }

                double *tempPtr = (double *)paramAddress;
                *       tempPtr = (double)(object)newVal;
            }
            else if (typeof(T) == typeof(long))
            {
                if ((long)(object)newVal > tempParam.MaxVal || (long)(object)newVal < tempParam.MinVal)
                {
                    return(-4);
                }

                long *tempPtr = (long *)paramAddress;
                *     tempPtr = (long)(object)newVal;
            }
            else if (typeof(T) == typeof(char[]))
            {
                char *tempPtr = (char *)paramAddress;
                *     tempPtr = (char)(object)newVal;
            }
            else
            {
                // Error code -2: unsupported parameter type
                return(-2);
            }

            return(0);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Creates a new CEditableStruct from an input file.
        /// </summary>
        /// <param name="filePath">The file path to the input file.</param>
        /// <param name="structure">The structure to create.</param>
        /// <param name="errorLine">The error line. When an error has occured this value will be adjusted accordingly.</param>
        /// <returns>0: success. 
        /// 1: invalid number of elements in file header. 
        /// 2: error parsing element 2 of file header (invalid integer). 
        /// 3: error parsing element 3 of file header (invalid integer).
        /// 4: error parsing element 4 of file header (invalid integer).
        /// 5: invalid number of elements in parameter-describing line.
        /// 6: error parsing element 1 of parameter-line (invalid integer).
        /// 7: invalid parameter type
        /// 8: invalid float value for parameter.
        /// 9: invalid 4th element (invalid float)
        /// 10: failed to open input file
        /// 11: invalid parameter type 'char[]': invalid string length specified.</returns>
        public static int CreateStructure(string filePath, ref CEditableStruct structure, ref int errorLine)
        {
            string structName = string.Empty;

            int structSize = 0, structOffset = 0, numElements = 0;
            List<SParameter> parameters = new List<SParameter>();

            System.IO.StreamReader sr;
            try
            {
                sr = new StreamReader(filePath);
            }
            catch (SystemException se)
            {
                // Failed to open the file! :O Error code 10
                return 10;
            }

            string line = string.Empty;

            int numLines = 0;
            int numRealLines = 0;

            char[] delimiter = new char[1];
            delimiter[0] = ' ';

            while (line != null)
            {
                line = sr.ReadLine();
                numLines++;

                if (!IgnoreLine(line))
                {
                    numRealLines++;

                    // We have the header, hopefully :)
                    if (numRealLines == 1)
                    {
                        string[] elements = line.Split(delimiter, StringSplitOptions.None);

                        if (elements.Length != 4)
                        {
                            // We are expecting 4 elements
                            errorLine = numLines;

                            // Error code 1: invalid number of elements in file header.
                            sr.Close();
                            return 1;
                        }

                        structName = elements[0];

                        // If integer parsing failed...

                        if (!TryParseInteger(elements[1], ref structSize))
                        {
                            errorLine = numLines;
                            // Error code 2: error parsing parameter 2 of file header (invalid integer).
                            sr.Close();
                            return 2;
                        }

                        if (!TryParseInteger(elements[2], ref structOffset))
                        {
                            errorLine = numLines;
                            // Error code 3: error parsing parameter 3 of file header (invalid integer).
                            sr.Close();
                            return 3;
                        }

                        if (!TryParseInteger(elements[3], ref numElements))
                        {
                            errorLine = numLines;
                            // Error code 4: error parsing parameter 4 of file header (invalid integer).
                            sr.Close();
                            return 4;
                        }
                    }
                    else
                    {
                        // We are loading in parameters :)
                        SParameter tempParam = new SParameter();

                        string[] elements = line.Split(delimiter, StringSplitOptions.None);

                        if (elements.Length != 5)
                        {
                            // We are expecting 5 elements
                            errorLine = numLines;

                            // Error code 5: invalid number of elements in parameter line.
                            sr.Close();
                            return 5;
                        }

                        tempParam.ParamName = elements[0];

                        if (!TryParseInteger(elements[1], ref tempParam.Offset))
                        {
                            errorLine = numLines;

                            // Error code 6: error parsing parameter 1 of a parameter (invalid integer)
                            sr.Close();
                            return 6;
                        }

                        if (elements[2].Contains("CHAR["))
                        {
                            // Cleanup
                            elements[2] = elements[2].Replace("CHAR", string.Empty);
                            elements[2] = elements[2].Replace("[", string.Empty);
                            elements[2] = elements[2].Replace("]", string.Empty);
                            // Done

                            if (!int.TryParse(elements[2], out tempParam.StringSize))
                            {

                                // Error code 11: invalid parameter type 'CHAR[]': invalid string length specified.
                                sr.Close();
                                return 11;
                            }

                            tempParam.Type = typeof(string);
                        }
                        else
                        {
                            switch (elements[2])
                            {
                                case "INT":
                                    tempParam.Type = typeof(int);
                                    break;
                                case "UINT":
                                    tempParam.Type = typeof(uint);
                                    break;
                                case "FLOAT":
                                    tempParam.Type = typeof(float);
                                    break;
                                case "SHORT":
                                    tempParam.Type = typeof(short);
                                    break;
                                case "LONG":
                                    tempParam.Type = typeof(long);
                                    break;
                                case "DOUBLE":
                                    tempParam.Type = typeof(double);
                                    break;
                                case "CHAR":
                                    tempParam.Type = typeof(char);
                                    tempParam.StringSize = 1;
                                    break;
                                default:
                                    errorLine = numLines;

                                    // Error code 7: invalid parameter type
                                    sr.Close();
                                    return 7;
                            }

                            tempParam.StringSize = 0;
                        }

                        if (elements[3] == "NONE")
                        {
                            tempParam.MinVal = 0xCAFED00D;
                        }
                        else
                        {
                            if (!float.TryParse(elements[3], out tempParam.MinVal))
                            {
                                errorLine = numLines;

                                // Error code 8: invalid parameter 3 (invalid float)
                                sr.Close();
                                return 8;
                            }
                        }

                        if (elements[4] == "NONE")
                        {
                            tempParam.MaxVal = 0xCAFED00D;
                        }
                        else
                        {
                            if (!float.TryParse(elements[3], out tempParam.MaxVal))
                            {
                                errorLine = numLines;

                                // Error code 8: invalid parameter 4 (invalid float)
                                sr.Close();
                                return 9;
                            }
                        }

                        parameters.Add(tempParam);
                    }
                }
            }

            structure = new CEditableStruct(structName, GlobalVars.BaseAddress, structOffset, structSize, numElements, parameters);
            sr.Close();
            return 0;
        }