source: Daodan/src/Daodan_BSL.c@ 441

Last change on this file since 441 was 441, checked in by gumby, 15 years ago
File size: 4.9 KB
RevLine 
[440]1#include <time.h>
2
[439]3#include "Daodan_BSL.h"
4#include "BFW_ScriptingLanguage.h"
[441]5#include <stdio.h>
6#include "Oni.h"
7#include "Oni_Character.h"
[440]8#include "dSFMT\dSFMT.h"
9
[439]10uint16_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
[441]19uint16_t ONICALL bsl_getkills(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
20{
21
22 //void* GS = (short int**)(ONgGameState);
23
24 //if (numargs < 2)
25 // return 1;
26
27 //fix the AC struct :(
28 //ret->value_int32 = ((ActiveCharacter *)(ONgGameState+0xB6268))->NumberOfKills;
29 //short int index =;
30 //char temp_bitset[2];
31 int index2;
32 if (numargs == 0) index2 = 0;
33 else index2 = args[0].value_int32;
34 char* active_index = ONgGameState + index2 * 0x16A0 + 0x1260 + 2;
35 //index = *(*()+ 0x1260 +2);
36 //ret->value_int32 = *((signed int*)(ONgGameState)) +0xB6268+(*(((signed int*)(ONgGameState)) + 0xAC)+2)*0x2838+0x1670;
37 //ret->value_int32 = *(int*)(ONgGameState +0xB6268 + index2 * 0x2838 + 0x1670);
38
39 //TODO: Clean up this mess...
40// ret->value_int32 = *active_index;
41
42 ret->value_int32 = ((uint32_t*)(ONgGameState +0xB6268+(int)(*active_index)*0x2838+0x1670));
43
44 ret->type = sl_int32;
45 return 0;
46}
47
48
[439]49uint16_t ONICALL bsl_mul(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
50{
51 if (numargs < 2)
52 return 1;
53
54 double val1;
55 double val2;
56
57 if (args[0].type == sl_int32)
58 val1 = args[0].value_int32;
59 else
60 val1 = args[0].value_float;
61
62 if (args[1].type == sl_int32)
63 val2 = args[1].value_int32;
64 else
65 val2 = args[1].value_float;
66
67 ret->value_float = (float)(val1 * val2);
68 ret->type = sl_float;
69 return 0;
70}
71
72uint16_t ONICALL bsl_int32div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
73{
74 if (numargs < 2)
75 return 1;
76 ret->value_int32 = args[0].value_int32 / args[1].value_int32;
77 ret->type = sl_int32;
78 return 0;
79}
80
81uint16_t ONICALL bsl_div(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
82{
83 if (numargs < 2)
84 return 1;
85
86 double val1;
87 double val2;
88
89 if (args[0].type == sl_int32)
90 val1 = args[0].value_int32;
91 else
92 val1 = args[0].value_float;
93
94 if (args[1].type == sl_int32)
95 val2 = args[1].value_int32;
96 else
97 val2 = args[1].value_float;
98
99 ret->value_float = (float)(val1 / val2);
100 ret->type = sl_float;
101 return 0;
102}
[441]103uint16_t ONICALL bsl_sprintf(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
104{
105 if (numargs < 2)
106 return 1;
107
[439]108
[441]109<<<<<<< .mine
110 char output[255];
111 char temp[255];
112 int i = 1;
113 for(i; i < numargs; i++) {
114 sprintf(output, args[0].value_str32, args[i].value_str32);/*
115 if(args[i].type == sl_int32 || args[i].type == sl_bool) {
116 sprintf(temp, "%i",args[i].value_int32);
117 sprintf(output, args[0].value_str32, temp); }
118 else if(args[i].type == sl_float) {
119 sprintf(temp, "%f",args[i].value_float);
120 sprintf(output, args[0].value_str32, temp); }
121 else */
122 }
123
124 ret->value_str32 = output;
125 ret->type = sl_str32;
126 return 0;
127}
128
129
[440]130uint16_t ONICALL bsl_int32rand(void* dontuse0, uint32_t numargs, sl_arg args[], void* dontuse1, void* dontuse2, sl_arg* ret)
131{
132 if (numargs < 2)
133 return 1;
134
135 int32_t start = 0;
136 int32_t end = 0;
137
138 if (args[0].value_int32 == args[1].value_int32)
139 return 1;
140 else if (args[0].value_int32 > args[1].value_int32)
141 {
142 start = args[1].value_int32;
143 end = args[0].value_int32;
144 }
145 else
146 {
147 start = args[0].value_int32;
148 end = args[1].value_int32;
149 }
150
151 ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1));
152 ret->type = sl_int32;
153 return 0;
154}
155
[441]156
[439]157void SLrDaodan_Initalize()
158{
159 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
160 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
161
162 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
163 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
[441]164
[440]165
[441]166 SLrScript_Command_Register_ReturnType("sprintf", "sprintf", "str1:format str2:value [str3:...]", sl_str32, bsl_sprintf);
167
168 SLrScript_Command_Register_ReturnType("getkills","Gets the number of kills", "[n1:int]", sl_int32, bsl_getkills);
169
170
[440]171 dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
172 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
[441]173>>>>>>> .r440
[439]174}
Note: See TracBrowser for help on using the repository browser.