Changeset 443 for Daodan/src
- Timestamp:
- Jul 18, 2009, 8:31:46 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Daodan/src/Daodan_BSL.c
r442 r443 1 #include <stdio.h> 1 2 #include <time.h> 3 #include <ffi.h> 2 4 3 5 #include "Daodan_BSL.h" 4 6 #include "BFW_ScriptingLanguage.h" 5 #include <stdio.h>6 7 #include "Oni.h" 7 8 #include "Oni_Character.h" … … 15 16 ret->type = sl_int32; 16 17 return 0; 17 }18 19 uint16_t ONICALL bsl_getkills(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)20 {21 22 int index;23 if (numargs == 0) index = 0;24 else index = args[0].value_int32;25 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;26 ret->value_int32 = *killcount;27 ret->type = sl_int32;28 return 0;29 30 }31 32 uint16_t ONICALL bsl_getdamage(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)33 {34 35 int index;36 if (numargs == 0) index = 0;37 else index = args[0].value_int32;38 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674;39 ret->value_int32 = *killcount;40 ret->type = sl_int32;41 return 0;42 43 18 } 44 19 … … 97 72 return 0; 98 73 } 99 uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)100 {101 if (numargs < 2)102 return 1;103 104 char output[255];105 char temp[255];106 int i = 1;107 for(i; i < numargs; i++) {108 sprintf(output, args[0].value_str32, args[i].value_str32);/*109 if(args[i].type == sl_int32 || args[i].type == sl_bool) {110 sprintf(temp, "%i",args[i].value_int32);111 sprintf(output, args[0].value_str32, temp); }112 else if(args[i].type == sl_float) {113 sprintf(temp, "%f",args[i].value_float);114 sprintf(output, args[0].value_str32, temp); }115 else */116 }117 118 ret->value_str32 = output;119 ret->type = sl_str32;120 return 0;121 }122 123 74 124 75 uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) … … 148 99 } 149 100 101 uint16_t ONICALL bsl_getkills(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) 102 { 103 int index; 104 if (numargs == 0) index = 0; 105 else index = args[0].value_int32; 106 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670; 107 ret->value_int32 = *killcount; 108 ret->type = sl_int32; 109 return 0; 110 } 111 112 uint16_t ONICALL bsl_getdamage(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) 113 { 114 int index; 115 if (numargs == 0) index = 0; 116 else index = args[0].value_int32; 117 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674; 118 ret->value_int32 = *killcount; 119 ret->type = sl_int32; 120 return 0; 121 } 122 123 uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) 124 { 125 if (numargs < 2) 126 return 1; 127 128 char output[255]; 129 char temp[255]; 130 int i = 1; 131 for(i; i < numargs; i++) { 132 sprintf(output, args[0].value_str32, args[i].value_str32);/* 133 if(args[i].type == sl_int32 || args[i].type == sl_bool) { 134 sprintf(temp, "%i",args[i].value_int32); 135 sprintf(output, args[0].value_str32, temp); } 136 else if(args[i].type == sl_float) { 137 sprintf(temp, "%f",args[i].value_float); 138 sprintf(output, args[0].value_str32, temp); } 139 else*/ 140 } 141 142 ret->value_str32 = output; 143 ret->type = sl_str32; 144 return 0; 145 } 146 /* 147 char* sprintf_return = NULL; 148 uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) 149 { 150 if (!sprintf_return) 151 sprintf_return = malloc(4096); 152 153 ffi_cif cif; 154 ffi_type *ffi_args[256]; 155 void *values[256]; 156 int ffi_ret; 157 158 ffi_args[0] = &ffi_type_pointer; 159 values[0] = sprintf_return; 160 ffi_args[1] = &ffi_type_uint32; 161 values[1] = (void*)4095; 162 163 int i; 164 for(i = 2; i < numargs + 2; i ++) 165 { 166 ffi_args[i] = &ffi_type_pointer; 167 values[i] = args[i - 2].value; 168 } 169 170 ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args); 171 ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values); 172 173 ret->value_str32 = sprintf_return; 174 ret->type = sl_str32; 175 return 0; 176 } 177 */ 150 178 151 179 void SLrDaodan_Initalize() … … 156 184 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); 157 185 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); 158 159 186 160 SLrScript_Command_Register_ReturnType("sprintf", "sprintf", "str1:format str2:value [str3:...]", sl_str32, bsl_sprintf); 161 187 dsfmt_gv_init_gen_rand((uint32_t)time(NULL)); 188 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand); 189 162 190 SLrScript_Command_Register_ReturnType("chr_getkills","Gets the number of kills a character has", "[chrindex:int]", sl_int32, bsl_getkills); 163 191 SLrScript_Command_Register_ReturnType("chr_getdamage","Gets the amount of damage a character has caused", "[chrindex:int]", sl_int32, bsl_getdamage); 164 192 165 dsfmt_gv_init_gen_rand((uint32_t)time(NULL)); 166 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand); 167 193 SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "str1:format", sl_str32, bsl_sprintf); 168 194 }
Note:
See TracChangeset
for help on using the changeset viewer.