| 3 |
|
#include <ffi.h> |
| 4 |
|
|
| 5 |
|
#include "Daodan_BSL.h" |
| 6 |
+ |
#include "Daodan_Utility.h" |
| 7 |
+ |
#include "Daodan_Console.h" |
| 8 |
|
#include "BFW_ScriptingLanguage.h" |
| 9 |
|
#include "Oni.h" |
| 10 |
|
#include "Oni_Character.h" |
| 11 |
|
#include "dSFMT\dSFMT.h" |
| 12 |
|
|
| 13 |
< |
uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 13 |
> |
uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 14 |
|
{ |
| 15 |
|
if (numargs < 2) |
| 16 |
|
return 1; |
| 19 |
|
return 0; |
| 20 |
|
} |
| 21 |
|
|
| 22 |
< |
uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 22 |
> |
uint16_t ONICALL bsl_mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 23 |
|
{ |
| 24 |
|
if (numargs < 2) |
| 25 |
|
return 1; |
| 42 |
|
return 0; |
| 43 |
|
} |
| 44 |
|
|
| 45 |
< |
uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 45 |
> |
uint16_t ONICALL bsl_int32div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 46 |
|
{ |
| 47 |
|
if (numargs < 2) |
| 48 |
|
return 1; |
| 51 |
|
return 0; |
| 52 |
|
} |
| 53 |
|
|
| 54 |
< |
uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 54 |
> |
uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 55 |
|
{ |
| 56 |
|
if (numargs < 2) |
| 57 |
|
return 1; |
| 74 |
|
return 0; |
| 75 |
|
} |
| 76 |
|
|
| 77 |
< |
uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 77 |
> |
uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 78 |
|
{ |
| 79 |
|
if (numargs < 2) |
| 80 |
|
return 1; |
| 100 |
|
return 0; |
| 101 |
|
} |
| 102 |
|
|
| 103 |
< |
uint16_t ONICALL bsl_getkills(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 103 |
> |
uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 104 |
|
{ |
| 105 |
|
int index; |
| 106 |
|
if (numargs == 0) index = 0; |
| 111 |
|
return 0; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
< |
uint16_t ONICALL bsl_getdamage(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 114 |
> |
uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 115 |
|
{ |
| 116 |
|
int index; |
| 117 |
|
if (numargs == 0) index = 0; |
| 121 |
|
ret->type = sl_int32; |
| 122 |
|
return 0; |
| 123 |
|
} |
| 124 |
< |
|
| 125 |
< |
uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 124 |
> |
/* |
| 125 |
> |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 126 |
|
{ |
| 127 |
|
if (numargs < 2) |
| 128 |
|
return 1; |
| 129 |
|
|
| 130 |
|
char output[255]; |
| 131 |
< |
char temp[255]; |
| 132 |
< |
int i = 1; |
| 133 |
< |
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*/ |
| 131 |
> |
int i; |
| 132 |
> |
for(i = 1; i < numargs; i++) { |
| 133 |
> |
sprintf(output, args[0].value_str32, args[i].value_str32); |
| 134 |
|
} |
| 135 |
|
|
| 136 |
|
ret->value_str32 = output; |
| 137 |
|
ret->type = sl_str32; |
| 138 |
|
return 0; |
| 139 |
|
} |
| 140 |
< |
/* |
| 141 |
< |
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) |
| 140 |
> |
*/ |
| 141 |
> |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 142 |
|
{ |
| 143 |
< |
if (!sprintf_return) |
| 144 |
< |
sprintf_return = malloc(4096); |
| 143 |
> |
int ffi_ret; |
| 144 |
> |
char* str = NULL; |
| 145 |
> |
int size = 0; |
| 146 |
|
|
| 147 |
|
ffi_cif cif; |
| 148 |
< |
ffi_type *ffi_args[256]; |
| 149 |
< |
void *values[256]; |
| 156 |
< |
int ffi_ret; |
| 148 |
> |
ffi_type* ffi_args[256]; |
| 149 |
> |
void* values[256]; |
| 150 |
|
|
| 151 |
|
ffi_args[0] = &ffi_type_pointer; |
| 152 |
< |
values[0] = sprintf_return; |
| 152 |
> |
values[0] = &str; |
| 153 |
|
ffi_args[1] = &ffi_type_uint32; |
| 154 |
< |
values[1] = (void*)4095; |
| 154 |
> |
values[1] = &size; |
| 155 |
|
|
| 156 |
|
int i; |
| 157 |
|
for(i = 2; i < numargs + 2; i ++) |
| 158 |
|
{ |
| 159 |
< |
ffi_args[i] = &ffi_type_pointer; |
| 160 |
< |
values[i] = args[i - 2].value; |
| 159 |
> |
if (args[i - 2].type == sl_float) |
| 160 |
> |
{ |
| 161 |
> |
float value_float = args[i - 2].value_float; |
| 162 |
> |
double* value_double = (double*)&(args[i - 2]); |
| 163 |
> |
*value_double = value_float; |
| 164 |
> |
|
| 165 |
> |
ffi_args[i] = &ffi_type_double; |
| 166 |
> |
values[i] = value_double; |
| 167 |
> |
} |
| 168 |
> |
else |
| 169 |
> |
{ |
| 170 |
> |
ffi_args[i] = &ffi_type_pointer; |
| 171 |
> |
values[i] = &(args[i - 2].value); |
| 172 |
> |
} |
| 173 |
|
} |
| 174 |
|
|
| 175 |
< |
ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args); |
| 175 |
> |
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK) |
| 176 |
> |
MessageBox(0, "", "", 0); |
| 177 |
|
ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values); |
| 178 |
< |
|
| 179 |
< |
ret->value_str32 = sprintf_return; |
| 178 |
> |
str = malloc(ffi_ret + 1); |
| 179 |
> |
size = ffi_ret + 1; |
| 180 |
> |
ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values); |
| 181 |
> |
ret->value_str32 = str; |
| 182 |
|
ret->type = sl_str32; |
| 183 |
|
return 0; |
| 184 |
|
} |
| 177 |
– |
*/ |
| 185 |
|
|
| 186 |
|
void SLrDaodan_Initalize() |
| 187 |
|
{ |