@@ -26,6 +26,10 @@ FunctionPatch s_functions[] =
2626 TEST_FUNC (MATH_VectorNormalize ),
2727 TEST_FUNC (MATH_CombineMatrixTransformation ),
2828 TEST_FUNC (MATH_MatrixMultiplication ),
29+ TEST_FUNC (RNG_Rand ),
30+ TEST_FUNC (RNG_RandInt ),
31+ TEST_FUNC (RNG_PseudoRand ),
32+ TEST_FUNC (RNG_Random ),
2933};
3034
3135void LoadTestPatches ()
@@ -65,108 +69,162 @@ static u32 PatchFunction_End(u32 index)
6569 * (s_functions [index ].address + 1 ) = s_functions [index ].secondNewInst ;
6670}
6771
68- static u32 PrintSVectorDiff (const char * name , const SVec3 * expected , const SVec3 * res )
72+ static u32 PrintSVectorDiff (const char * name , const SVec3 * expected , const SVec3 * ret )
6973{
7074 u32 failed = 0 ;
7175 for (u32 i = 0 ; i < 3 ; i ++ )
7276 {
73- if (expected -> v [i ] != res -> v [i ])
77+ if (expected -> v [i ] != ret -> v [i ])
7478 {
7579 failed = 1 ;
76- ND_printf ("[%s] Test Failed:\nv[%d] = %d, got %d\n" , name , i , expected -> v [i ], res -> v [i ]);
80+ ND_printf ("[%s] Test Failed:\nv[%d] = %d, got %d\n" , name , i , expected -> v [i ], ret -> v [i ]);
7781 }
7882 }
7983 return failed ;
8084}
8185
82- static u32 PrintMatrixDiff (const char * name , const Matrix * expected , const Matrix * res , u32 cmpTrans )
86+ static u32 PrintMatrixDiff (const char * name , const Matrix * expected , const Matrix * ret , u32 cmpTrans )
8387{
8488 u32 failed = 0 ;
8589 for (u32 i = 0 ; i < 3 ; i ++ )
8690 {
8791 for (u32 j = 0 ; j < 3 ; j ++ )
8892 {
89- if (expected -> m [i ][j ] != res -> m [i ][j ])
93+ if (expected -> m [i ][j ] != ret -> m [i ][j ])
9094 {
9195 failed = 1 ;
92- ND_printf ("[%s] Test Failed:\nm[%d][%d] = %d, got %d\n" , name , i , j , expected -> m [i ][j ], res -> m [i ][j ]);
96+ ND_printf ("[%s] Test Failed:\nm[%d][%d] = %d, got %d\n" , name , i , j , expected -> m [i ][j ], ret -> m [i ][j ]);
9397 }
9498 }
95- if ((cmpTrans ) && (expected -> t .v [i ] != res -> t .v [i ]))
99+ if ((cmpTrans ) && (expected -> t .v [i ] != ret -> t .v [i ]))
96100 {
97101 failed = 1 ;
98- ND_printf ("[%s] Test Failed:\nt[%d] = %d, got %d\n" , name , i , expected -> t .v [i ], res -> t .v [i ]);
102+ ND_printf ("[%s] Test Failed:\nt[%d] = %d, got %d\n" , name , i , expected -> t .v [i ], ret -> t .v [i ]);
99103 }
100104 }
101105 return failed ;
102106}
103107
104108#ifdef TEST_MATH_IMPL
105- void TEST_MATH_Sin (u32 angle , s32 res )
109+
110+ void TEST_MATH_Sin (u32 angle , s32 ret )
106111{
107112 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_Sin ));
108113 const s32 expected = ND_MATH_Sin (angle );
109- if (expected != res ) { ND_printf ("[MATH_Sin] Test Failed:\nInput: %d\nExpected: %d\nResult :%d\n" , angle , expected , res ); }
114+ if (expected != ret ) { ND_printf ("[MATH_Sin] Test Failed:\nInput: %d\nExpected: %d\nResult:%d\n" , angle , expected , ret ); }
110115 PatchFunction_End (index );
111116}
112117
113- void TEST_MATH_Cos (u32 angle , s32 res )
118+ void TEST_MATH_Cos (u32 angle , s32 ret )
114119{
115120 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_Cos ));
116121 const s32 expected = ND_MATH_Cos (angle );
117- if (expected != res ) { ND_printf ("[MATH_Cos] Test Failed:\nInput: %d\nExpected: %d\nResult :%d\n" , angle , expected , res ); }
122+ if (expected != ret ) { ND_printf ("[MATH_Cos] Test Failed:\nInput: %d\nExpected: %d\nResult:%d\n" , angle , expected , ret ); }
118123 PatchFunction_End (index );
119124}
120125
121- void TEST_MATH_Sqrt (u32 n , u32 shift , u32 res )
126+ void TEST_MATH_Sqrt (u32 n , u32 shift , u32 ret )
122127{
123128 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_Sqrt ));
124129 const u32 expected = ND_MATH_Sqrt (n , shift );
125- if (expected != res ) { ND_printf ("[MATH_Sqrt] Test Failed:\nInput: %d %d\nExpected: %d\nResult :%d\n" , n , shift , expected , res ); }
130+ if (expected != ret ) { ND_printf ("[MATH_Sqrt] Test Failed:\nInput: %d %d\nExpected: %d\nResult:%d\n" , n , shift , expected , ret ); }
126131 PatchFunction_End (index );
127132}
128133
129- void TEST_MATH_GetInverseMatrixTransformation (const Matrix * matrix , const Matrix * res )
134+ void TEST_MATH_GetInverseMatrixTransformation (const Matrix * matrix , const Matrix * ret )
130135{
131136 Matrix out ;
132137 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_GetInverseMatrixTransformation ));
133138 ND_MATH_GetInverseMatrixTransformation (& out , matrix );
134- PrintMatrixDiff ("MATH_GetInverseMatrixTransformation" , & out , res , true);
139+ PrintMatrixDiff ("MATH_GetInverseMatrixTransformation" , & out , ret , true);
135140 PatchFunction_End (index );
136141}
137142
138- void TEST_MATH_VectorLength (const SVec3 * vector , s32 res )
143+ void TEST_MATH_VectorLength (const SVec3 * vector , s32 ret )
139144{
140145 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_VectorLength ));
141146 const s32 expected = ND_MATH_VectorLength (vector );
142- if (expected != res ) { ND_printf ("[MATH_VectorLength] Test Failed:\nInput: %d %d %d\nExpected: %d\nResult :%d\n" , vector -> x , vector -> y , vector -> z , expected , res ); }
147+ if (expected != ret ) { ND_printf ("[MATH_VectorLength] Test Failed:\nInput: %d %d %d\nExpected: %d\nResult:%d\n" , vector -> x , vector -> y , vector -> z , expected , ret ); }
143148 PatchFunction_End (index );
144149}
145150
146- void TEST_MATH_VectorNormalize (SVec3 * vector , const SVec3 * res )
151+ void TEST_MATH_VectorNormalize (SVec3 * vector , const SVec3 * ret )
147152{
148153 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_VectorNormalize ));
149154 ND_MATH_VectorNormalize (vector );
150- PrintSVectorDiff ("MATH_VectorNormalize" , vector , res );
155+ PrintSVectorDiff ("MATH_VectorNormalize" , vector , ret );
151156 PatchFunction_End (index );
152157}
153158
154- void TEST_MATH_CombineMatrixTransformation (const Matrix * m , const Matrix * n , const Matrix * res )
159+ void TEST_MATH_CombineMatrixTransformation (const Matrix * m , const Matrix * n , const Matrix * ret )
155160{
156161 Matrix expected ;
157162 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_CombineMatrixTransformation ));
158163 ND_MATH_CombineMatrixTransformation (& expected , m , n );
159- PrintMatrixDiff ("MATH_CombineMatrixTransformation" , & expected , res , true);
164+ PrintMatrixDiff ("MATH_CombineMatrixTransformation" , & expected , ret , true);
160165 PatchFunction_End (index );
161166}
162167
163- void TEST_MATH_MatrixMultiplication (const Matrix * m , const Matrix * n , const Matrix * res )
168+ void TEST_MATH_MatrixMultiplication (const Matrix * m , const Matrix * n , const Matrix * ret )
164169{
165170 Matrix expected ;
166171 const u32 index = PatchFunction_Beg ((u32 * )(& ND_MATH_MatrixMultiplication ));
167172 ND_MATH_MatrixMultiplication (& expected , m , n );
168- PrintMatrixDiff ("MATH_MatrixMultiplication" , & expected , res , false);
173+ PrintMatrixDiff ("MATH_MatrixMultiplication" , & expected , ret , false);
174+ PatchFunction_End (index );
175+ }
176+
177+ #endif // TEST_MATH_IMPL
178+
179+ #ifdef TEST_RNG_IMPL
180+
181+ void BACKUP_RNG_Rand ()
182+ {
183+ u32 * seedAddr = (u32 * ) BACKUP_ADDR ;
184+ * seedAddr = e_seed ;
185+ }
186+
187+ void TEST_RNG_Rand ()
188+ {
189+ const u32 index = PatchFunction_Beg ((u32 * )(& ND_RNG_Rand ));
190+ const u32 ret = e_seed ;
191+ e_seed = * (u32 * ) BACKUP_ADDR ;
192+ ND_RNG_Rand ();
193+ if (e_seed != ret ) { ND_printf ("[RNG_Rand] Test Failed:\nExpected: %d\nResult: %d\n" , e_seed , ret ); }
194+ PatchFunction_End (index );
195+ }
196+
197+ void BACKUP_RNG_RandInt ()
198+ {
199+ RNGSeed * seedAddr = (RNGSeed * ) BACKUP_ADDR ;
200+ * seedAddr = e_gameTrackerSeed ;
201+ }
202+
203+ void TEST_RNG_RandInt (u32 n , s32 ret )
204+ {
205+ const u32 index = PatchFunction_Beg ((u32 * )(& ND_RNG_RandInt ));
206+ e_gameTrackerSeed = * (RNGSeed * ) BACKUP_ADDR ;
207+ const s32 expected = ND_RNG_RandInt (n );
208+ if (expected != ret ) { ND_printf ("[RNG_RandInt] Test Failed:\nExpected: %d\nResult: %d\n" , expected , ret ); }
209+ PatchFunction_End (index );
210+ }
211+
212+ void TEST_RNG_PseudoRand (u16 n , u16 ret )
213+ {
214+ const u32 index = PatchFunction_Beg ((u32 * )(& ND_RNG_PseudoRand ));
215+ const u16 expected = ND_RNG_PseudoRand (n );
216+ if (expected != ret ) { ND_printf ("[RNG_PseudoRand] Test Failed:\nExpected: %d\nResult: %d\n" , expected , ret ); }
217+ PatchFunction_End (index );
218+ }
219+
220+ void TEST_RNG_Random (RNGSeed * seed , const RNGSeed * ret )
221+ {
222+ const u32 index = PatchFunction_Beg ((u32 * )(& ND_RNG_Random ));
223+ const u32 expected = ND_RNG_Random (seed );
224+ if (seed -> a != ret -> a ) { ND_printf ("[RNG_Random] Test Failed:\nseed->a: %d\nret->a: %d\n" , seed -> a , ret -> a ); }
225+ if (seed -> b != ret -> b ) { ND_printf ("[RNG_Random] Test Failed:\nseed->b: %d\nret->b: %d\n" , seed -> b , ret -> b ); }
226+ if (expected != ret -> b ) { ND_printf ("[RNG_Random] Test Failed:\nExpected: %d\nret: %d\n" , expected , ret -> b ); }
169227 PatchFunction_End (index );
170228}
171229
172- #endif // TEST_MATH_IMPL
230+ #endif // TEST_RNG_IMPL
0 commit comments