| 902 | //----------------------------------------------------------------------------- |
| 903 | |
| 904 | void SimObject::setDataField(StringTableEntry slotName, const char *array, const char *value) |
| 905 | { |
| 906 | // first search the static fields if enabled |
| 907 | if(mFlags.test(ModStaticFields)) |
| 908 | { |
| 909 | const AbstractClassRep::Field *fld = findField(slotName); |
| 910 | if(fld) |
| 911 | { |
| 912 | // Skip the special field types as they are not data. |
| 913 | if ( fld->type >= AbstractClassRep::ARCFirstCustomField ) |
| 914 | return; |
| 915 | |
| 916 | S32 array1 = array ? dAtoi(array) : 0; |
| 917 | |
| 918 | if(array1 >= 0 && array1 < fld->elementCount && fld->elementCount >= 1) |
| 919 | { |
| 920 | // If the set data notify callback returns true, then go ahead and |
| 921 | // set the data, otherwise, assume the set notify callback has either |
| 922 | // already set the data, or has deemed that the data should not |
| 923 | // be set at all. |
| 924 | FrameTemp<char> buffer(2048); |
| 925 | FrameTemp<char> bufferSecure(2048); // This buffer is used to make a copy of the data |
| 926 | // so that if the prep functions or any other functions use the string stack, the data |
| 927 | // is not corrupted. |
| 928 | |
| 929 | ConsoleBaseType *cbt = ConsoleBaseType::getType( fld->type ); |
| 930 | AssertFatal( cbt != NULL, "Could not resolve Type Id." ); |
| 931 | |
| 932 | const char* szBuffer = cbt->prepData( value, buffer, 2048 ); |
| 933 | dMemset( bufferSecure, 0, 2048 ); |
| 934 | dMemcpy( bufferSecure, szBuffer, dStrlen( szBuffer ) ); |
| 935 | |
| 936 | if( (*fld->setDataFn)( this, array, bufferSecure ) ) |
| 937 | Con::setData(fld->type, (void *) (((const char *)this) + fld->offset), array1, 1, &value, fld->table); |
| 938 | |
| 939 | if(fld->validator) |
| 940 | fld->validator->validateType(this, (void *) (((const char *)this) + fld->offset)); |
| 941 | |
| 942 | onStaticModified( slotName, value ); |
| 943 | |
| 944 | return; |
| 945 | } |
| 946 | |
| 947 | if(fld->validator) |
| 948 | fld->validator->validateType(this, (void *) (((const char *)this) + fld->offset)); |
| 949 | |
| 950 | onStaticModified( slotName, value ); |
| 951 | return; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | if(mFlags.test(ModDynamicFields)) |
| 956 | { |
| 957 | if(!mFieldDictionary) |
| 958 | mFieldDictionary = new SimFieldDictionary; |
| 959 | |
| 960 | if(!array) |
| 961 | { |
no test coverage detected