| 1 |
#include <time.h> |
| 2 |
|
| 3 |
#include "Daodan_BSL.h" |
| 4 |
#include "BFW_ScriptingLanguage.h" |
| 5 |
#include <stdio.h> |
| 6 |
#include "Oni.h" |
| 7 |
#include "Oni_Character.h" |
| 8 |
#include "dSFMT\dSFMT.h" |
| 9 |
|
| 10 |
uint16_t ONICALL bsl_int32mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 11 |
{ |
| 12 |
if (numargs < 2) |
| 13 |
return 1; |
| 14 |
ret->value_int32 = args[0].value_int32 * args[1].value_int32; |
| 15 |
ret->type = sl_int32; |
| 16 |
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 |
} |
| 44 |
|
| 45 |
uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 46 |
{ |
| 47 |
if (numargs < 2) |
| 48 |
return 1; |
| 49 |
|
| 50 |
double val1; |
| 51 |
double val2; |
| 52 |
|
| 53 |
if (args[0].type == sl_int32) |
| 54 |
val1 = args[0].value_int32; |
| 55 |
else |
| 56 |
val1 = args[0].value_float; |
| 57 |
|
| 58 |
if (args[1].type == sl_int32) |
| 59 |
val2 = args[1].value_int32; |
| 60 |
else |
| 61 |
val2 = args[1].value_float; |
| 62 |
|
| 63 |
ret->value_float = (float)(val1 * val2); |
| 64 |
ret->type = sl_float; |
| 65 |
return 0; |
| 66 |
} |
| 67 |
|
| 68 |
uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 69 |
{ |
| 70 |
if (numargs < 2) |
| 71 |
return 1; |
| 72 |
ret->value_int32 = args[0].value_int32 / args[1].value_int32; |
| 73 |
ret->type = sl_int32; |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 78 |
{ |
| 79 |
if (numargs < 2) |
| 80 |
return 1; |
| 81 |
|
| 82 |
double val1; |
| 83 |
double val2; |
| 84 |
|
| 85 |
if (args[0].type == sl_int32) |
| 86 |
val1 = args[0].value_int32; |
| 87 |
else |
| 88 |
val1 = args[0].value_float; |
| 89 |
|
| 90 |
if (args[1].type == sl_int32) |
| 91 |
val2 = args[1].value_int32; |
| 92 |
else |
| 93 |
val2 = args[1].value_float; |
| 94 |
|
| 95 |
ret->value_float = (float)(val1 / val2); |
| 96 |
ret->type = sl_float; |
| 97 |
return 0; |
| 98 |
} |
| 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 |
|
| 124 |
uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret) |
| 125 |
{ |
| 126 |
if (numargs < 2) |
| 127 |
return 1; |
| 128 |
|
| 129 |
int32_t start = 0; |
| 130 |
int32_t end = 0; |
| 131 |
|
| 132 |
if (args[0].value_int32 == args[1].value_int32) |
| 133 |
return 1; |
| 134 |
else if (args[0].value_int32 > args[1].value_int32) |
| 135 |
{ |
| 136 |
start = args[1].value_int32; |
| 137 |
end = args[0].value_int32; |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
start = args[0].value_int32; |
| 142 |
end = args[1].value_int32; |
| 143 |
} |
| 144 |
|
| 145 |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
| 146 |
ret->type = sl_int32; |
| 147 |
return 0; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
void SLrDaodan_Initalize() |
| 152 |
{ |
| 153 |
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
| 154 |
SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); |
| 155 |
|
| 156 |
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
| 157 |
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
| 158 |
|
| 159 |
|
| 160 |
SLrScript_Command_Register_ReturnType("sprintf", "sprintf", "str1:format str2:value [str3:...]", sl_str32, bsl_sprintf); |
| 161 |
|
| 162 |
SLrScript_Command_Register_ReturnType("chr_getkills","Gets the number of kills a character has", "[chrindex:int]", sl_int32, bsl_getkills); |
| 163 |
SLrScript_Command_Register_ReturnType("chr_getdamage","Gets the amount of damage a character has caused", "[chrindex:int]", sl_int32, bsl_getdamage); |
| 164 |
|
| 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 |
|
| 168 |
} |