Spyro 1 Reverse Engineering
Decompilation of functions from Spyro 1 into human readable C
 
Loading...
Searching...
No Matches
gem_home_in.c
Go to the documentation of this file.
1#include <custom_types.h>
2#include <common.h>
3#include <shapes.h>
4#include <moby.h>
5#include <vector.h>
6#include <spyro.h>
7
8
9
10
11//*********************************************
12// ** Parent Function: Artisans_MobyUpdateLoop
13// ** Scope Replacing: If-Else for Gem Home In
14// ** Address of Scope Replacing: 0x8008013c
15// ** Need to redirect after return?: Yes - 80080218
16// ** Hook File: gem_home_in_hook.s
17//*********************************************
18/*
19 * Part of function that handles the gem home in
20*/
22{
23 //Define Registers as variables
24 register void* s1 asm("$s1");
25 register void* s3 asm("$s3");
26
27 Vec3 gemToSpyroDistanceVec = {0};
28 unsigned int gemOriginToSpyroLength = 0;
29
30 //* Since we are replacing a branch (if), this is that equivalent branch
31 if (*((char*)s1 + 0xf) < 0x20)
32 {
33 Vec3Subtract(&gemToSpyroDistanceVec, &_spyro.position, (Vec3*)s1); // Subtract spyro's position from gem origin to get distance vec
34 Vec3ScaleDownByPowerOfTwo(&gemToSpyroDistanceVec, 5); // Scale down result by 32
35 const int FLAG_3D = 1;
36 gemOriginToSpyroLength = Vec3CalculateLengthE(&gemToSpyroDistanceVec, FLAG_3D); // Calculate length of distance vector
37
38 const int MINIMUM_DISTANCE_FROM_GEM = 0x1e1;
39
40 if (gemOriginToSpyroLength < MINIMUM_DISTANCE_FROM_GEM)
41 {
42 Vec3Scale(&gemToSpyroDistanceVec,&gemToSpyroDistanceVec, *((char*)s1 + 0xf));
43 Vec3Add(&((Moby*)s3)->position, s1, &gemToSpyroDistanceVec); // Add origin to distance vec to get new location from 0,0,0
44 const int SINE_WAVE_SPEED = 4 ; // 4 is the speed required to get 1 half circle (128 steps through the 256 array)
45 ((Moby*)s3)->position.z = ((Moby*)s3)->position.z + (_sinArray[*((char*)s1 + 0xf) * SINE_WAVE_SPEED] / 12);
46 }
47
48 else
49 {
50 Vec3Copy(&((Moby*)s3)->position, &_spyro.position); // Set gem position to spyro's position
51 *((char*)s1 + 0xf) = 0x20; // Set gem hoam timer to near end
52 }
53 }
54
55 else
56 {
57 Vec3Copy(&((Moby*)s3)->position, &_spyro.position);
58 }
59 return;
60}
void GemHomeIn()
Definition gem_home_in.c:21
short _sinArray[256]
A scaled up sin lookup table Address: 0x8006cbf8.
Spyro _spyro
This is where the 1 instance of the spyro struct is. Address: 0x80078A58.
void Vec3Add(int *result, int *a, int *b)
Adds vector 'a' and vector 'b' together, and stores the resulting vector in 'result'.
Definition vector.c:20
void Vec3Copy(int *dst, int *src)
Copies the 'src' Vector to the 'dst' Vector.
Definition vector.c:47
This is the main moby/object struct.
Definition moby.h:151
struct Vec3 position
Definition spyro.h:57
Definition vector.h:9
void Vec3ScaleDownByPowerOfTwo(Vec3 *vector, unsigned int pot)
void Vec3Subtract(Vec3 *destVector, Vec3 *a, Vec3 *b)
void Vec3Scale(Vec3 *result, Vec3 *vector, int multiplier)
unsigned int Vec3CalculateLengthE(Vec3 *vector, bool flag3D)