| 1 | #include <stdio.h>
|
|---|
| 2 | #include <time.h>
|
|---|
| 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(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
|
|---|
| 14 | {
|
|---|
| 15 | if (numargs < 2)
|
|---|
| 16 | return 1;
|
|---|
| 17 | ret->value_int32 = args[0].value_int32 * args[1].value_int32;
|
|---|
| 18 | ret->type = sl_int32;
|
|---|
| 19 | return 0;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 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;
|
|---|
| 26 |
|
|---|
| 27 | double val1;
|
|---|
| 28 | double val2;
|
|---|
| 29 |
|
|---|
| 30 | if (args[0].type == sl_int32)
|
|---|
| 31 | val1 = args[0].value_int32;
|
|---|
| 32 | else
|
|---|
| 33 | val1 = args[0].value_float;
|
|---|
| 34 |
|
|---|
| 35 | if (args[1].type == sl_int32)
|
|---|
| 36 | val2 = args[1].value_int32;
|
|---|
| 37 | else
|
|---|
| 38 | val2 = args[1].value_float;
|
|---|
| 39 |
|
|---|
| 40 | ret->value_float = (float)(val1 * val2);
|
|---|
| 41 | ret->type = sl_float;
|
|---|
| 42 | return 0;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 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;
|
|---|
| 49 | ret->value_int32 = args[0].value_int32 / args[1].value_int32;
|
|---|
| 50 | ret->type = sl_int32;
|
|---|
| 51 | return 0;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 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;
|
|---|
| 58 |
|
|---|
| 59 | double val1;
|
|---|
| 60 | double val2;
|
|---|
| 61 |
|
|---|
| 62 | if (args[0].type == sl_int32)
|
|---|
| 63 | val1 = args[0].value_int32;
|
|---|
| 64 | else
|
|---|
| 65 | val1 = args[0].value_float;
|
|---|
| 66 |
|
|---|
| 67 | if (args[1].type == sl_int32)
|
|---|
| 68 | val2 = args[1].value_int32;
|
|---|
| 69 | else
|
|---|
| 70 | val2 = args[1].value_float;
|
|---|
| 71 |
|
|---|
| 72 | ret->value_float = (float)(val1 / val2);
|
|---|
| 73 | ret->type = sl_float;
|
|---|
| 74 | return 0;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 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;
|
|---|
| 81 |
|
|---|
| 82 | int32_t start = 0;
|
|---|
| 83 | int32_t end = 0;
|
|---|
| 84 |
|
|---|
| 85 | if (args[0].value_int32 == args[1].value_int32)
|
|---|
| 86 | return 1;
|
|---|
| 87 | else if (args[0].value_int32 > args[1].value_int32)
|
|---|
| 88 | {
|
|---|
| 89 | start = args[1].value_int32;
|
|---|
| 90 | end = args[0].value_int32;
|
|---|
| 91 | }
|
|---|
| 92 | else
|
|---|
| 93 | {
|
|---|
| 94 | start = args[0].value_int32;
|
|---|
| 95 | end = args[1].value_int32;
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1));
|
|---|
| 99 | ret->type = sl_int32;
|
|---|
| 100 | return 0;
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 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;
|
|---|
| 107 | else index = args[0].value_int32;
|
|---|
| 108 | int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;
|
|---|
| 109 | ret->value_int32 = *killcount;
|
|---|
| 110 | ret->type = sl_int32;
|
|---|
| 111 | return 0;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 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;
|
|---|
| 118 | else index = args[0].value_int32;
|
|---|
| 119 | int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674;
|
|---|
| 120 | ret->value_int32 = *killcount;
|
|---|
| 121 | ret->type = sl_int32;
|
|---|
| 122 | return 0;
|
|---|
| 123 | }
|
|---|
| 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 | 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 | uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
|
|---|
| 142 | {
|
|---|
| 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];
|
|---|
| 150 |
|
|---|
| 151 | ffi_args[0] = &ffi_type_pointer;
|
|---|
| 152 | values[0] = &str;
|
|---|
| 153 | ffi_args[1] = &ffi_type_uint32;
|
|---|
| 154 | values[1] = &size;
|
|---|
| 155 |
|
|---|
| 156 | int i;
|
|---|
| 157 | for(i = 2; i < numargs + 2; i ++)
|
|---|
| 158 | {
|
|---|
| 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 | 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 | 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 | }
|
|---|
| 185 |
|
|---|
| 186 | void SLrDaodan_Initalize()
|
|---|
| 187 | {
|
|---|
| 188 | SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
|
|---|
| 189 | SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
|
|---|
| 190 |
|
|---|
| 191 | SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
|
|---|
| 192 | SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
|
|---|
| 193 |
|
|---|
| 194 | dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
|
|---|
| 195 | SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
|
|---|
| 196 |
|
|---|
| 197 | SLrScript_Command_Register_ReturnType("chr_getkills","Gets the number of kills a character has", "[chrindex:int]", sl_int32, bsl_getkills);
|
|---|
| 198 | SLrScript_Command_Register_ReturnType("chr_getdamage","Gets the amount of damage a character has caused", "[chrindex:int]", sl_int32, bsl_getdamage);
|
|---|
| 199 |
|
|---|
| 200 | SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "str1:format", sl_str32, bsl_sprintf);
|
|---|
| 201 | }
|
|---|