| 1 |
#include <stdio.h> |
| 2 |
#include <time.h> |
| 3 |
#include <ffi.h> |
| 4 |
|
| 5 |
#include "Daodan_BSL.h" |
| 6 |
#include "BFW_ScriptingLanguage.h" |
| 7 |
#include "Oni.h" |
| 8 |
#include "Oni_Character.h" |
| 9 |
#include "dSFMT\dSFMT.h" |
| 10 |
|
| 11 |
uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 12 |
{ |
| 13 |
if (numargs < 2) |
| 14 |
return 1; |
| 15 |
ret->value_int32 = args[0].value_int32 * args[1].value_int32; |
| 16 |
ret->type = sl_int32; |
| 17 |
return 0; |
| 18 |
} |
| 19 |
|
| 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) |
| 23 |
return 1; |
| 24 |
|
| 25 |
double val1; |
| 26 |
double val2; |
| 27 |
|
| 28 |
if (args[0].type == sl_int32) |
| 29 |
val1 = args[0].value_int32; |
| 30 |
else |
| 31 |
val1 = args[0].value_float; |
| 32 |
|
| 33 |
if (args[1].type == sl_int32) |
| 34 |
val2 = args[1].value_int32; |
| 35 |
else |
| 36 |
val2 = args[1].value_float; |
| 37 |
|
| 38 |
ret->value_float = (float)(val1 * val2); |
| 39 |
ret->type = sl_float; |
| 40 |
return 0; |
| 41 |
} |
| 42 |
|
| 43 |
uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 44 |
{ |
| 45 |
if (numargs < 2) |
| 46 |
return 1; |
| 47 |
ret->value_int32 = args[0].value_int32 / args[1].value_int32; |
| 48 |
ret->type = sl_int32; |
| 49 |
return 0; |
| 50 |
} |
| 51 |
|
| 52 |
uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 53 |
{ |
| 54 |
if (numargs < 2) |
| 55 |
return 1; |
| 56 |
|
| 57 |
double val1; |
| 58 |
double val2; |
| 59 |
|
| 60 |
if (args[0].type == sl_int32) |
| 61 |
val1 = args[0].value_int32; |
| 62 |
else |
| 63 |
val1 = args[0].value_float; |
| 64 |
|
| 65 |
if (args[1].type == sl_int32) |
| 66 |
val2 = args[1].value_int32; |
| 67 |
else |
| 68 |
val2 = args[1].value_float; |
| 69 |
|
| 70 |
ret->value_float = (float)(val1 / val2); |
| 71 |
ret->type = sl_float; |
| 72 |
return 0; |
| 73 |
} |
| 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; |
| 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 |
*/ |
| 178 |
|
| 179 |
void SLrDaodan_Initalize() |
| 180 |
{ |
| 181 |
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
| 182 |
SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); |
| 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); |
| 186 |
|
| 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 |
SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "str1:format", sl_str32, bsl_sprintf); |
| 194 |
} |