| 1 |
+ |
#include <stdio.h> |
| 2 |
|
#include <time.h> |
| 3 |
+ |
#include <ffi.h> |
| 4 |
|
|
| 5 |
|
#include "Daodan_BSL.h" |
| 6 |
|
#include "BFW_ScriptingLanguage.h" |
| 5 |
– |
#include <stdio.h> |
| 7 |
|
#include "Oni.h" |
| 8 |
|
#include "Oni_Character.h" |
| 9 |
|
#include "dSFMT\dSFMT.h" |
| 17 |
|
return 0; |
| 18 |
|
} |
| 19 |
|
|
| 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 |
– |
} |
| 44 |
– |
|
| 20 |
|
uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 21 |
|
{ |
| 22 |
|
if (numargs < 2) |
| 71 |
|
ret->type = sl_float; |
| 72 |
|
return 0; |
| 73 |
|
} |
| 74 |
< |
uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 74 |
> |
|
| 75 |
> |
uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 76 |
|
{ |
| 77 |
|
if (numargs < 2) |
| 78 |
|
return 1; |
| 79 |
|
|
| 80 |
+ |
int32_t start = 0; |
| 81 |
+ |
int32_t end = 0; |
| 82 |
+ |
|
| 83 |
+ |
if (args[0].value_int32 == args[1].value_int32) |
| 84 |
+ |
return 1; |
| 85 |
+ |
else if (args[0].value_int32 > args[1].value_int32) |
| 86 |
+ |
{ |
| 87 |
+ |
start = args[1].value_int32; |
| 88 |
+ |
end = args[0].value_int32; |
| 89 |
+ |
} |
| 90 |
+ |
else |
| 91 |
+ |
{ |
| 92 |
+ |
start = args[0].value_int32; |
| 93 |
+ |
end = args[1].value_int32; |
| 94 |
+ |
} |
| 95 |
+ |
|
| 96 |
+ |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
| 97 |
+ |
ret->type = sl_int32; |
| 98 |
+ |
return 0; |
| 99 |
+ |
} |
| 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; |
| 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 */ |
| 139 |
> |
else*/ |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
ret->value_str32 = output; |
| 143 |
|
ret->type = sl_str32; |
| 144 |
|
return 0; |
| 145 |
|
} |
| 146 |
< |
|
| 147 |
< |
|
| 148 |
< |
uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 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 (numargs < 2) |
| 151 |
< |
return 1; |
| 150 |
> |
if (!sprintf_return) |
| 151 |
> |
sprintf_return = malloc(4096); |
| 152 |
|
|
| 153 |
< |
int32_t start = 0; |
| 154 |
< |
int32_t end = 0; |
| 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 |
< |
if (args[0].value_int32 == args[1].value_int32) |
| 164 |
< |
return 1; |
| 134 |
< |
else if (args[0].value_int32 > args[1].value_int32) |
| 163 |
> |
int i; |
| 164 |
> |
for(i = 2; i < numargs + 2; i ++) |
| 165 |
|
{ |
| 166 |
< |
start = args[1].value_int32; |
| 167 |
< |
end = args[0].value_int32; |
| 138 |
< |
} |
| 139 |
< |
else |
| 140 |
< |
{ |
| 141 |
< |
start = args[0].value_int32; |
| 142 |
< |
end = args[1].value_int32; |
| 166 |
> |
ffi_args[i] = &ffi_type_pointer; |
| 167 |
> |
values[i] = args[i - 2].value; |
| 168 |
|
} |
| 169 |
|
|
| 170 |
< |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
| 171 |
< |
ret->type = sl_int32; |
| 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 |
< |
|
| 177 |
> |
*/ |
| 178 |
|
|
| 179 |
|
void SLrDaodan_Initalize() |
| 180 |
|
{ |
| 183 |
|
|
| 184 |
|
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
| 185 |
|
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
| 158 |
– |
|
| 186 |
|
|
| 187 |
< |
SLrScript_Command_Register_ReturnType("sprintf", "sprintf", "str1:format str2:value [str3:...]", sl_str32, bsl_sprintf); |
| 188 |
< |
|
| 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 |
> |
|
| 190 |
|
SLrScript_Command_Register_ReturnType("chr_getkills","Gets the number of kills a character has", "[chrindex:int]", sl_int32, bsl_getkills); |
| 191 |
|
SLrScript_Command_Register_ReturnType("chr_getdamage","Gets the amount of damage a character has caused", "[chrindex:int]", sl_int32, bsl_getdamage); |
| 192 |
|
|
| 193 |
< |
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); |
| 194 |
|
} |