Skip to content

Commit 7e82aed

Browse files
author
Niko
committed
AltMods refactor
1 parent 23a4f91 commit 7e82aed

File tree

18 files changed

+625
-618
lines changed

18 files changed

+625
-618
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
void ui16by9_ViewProj(struct PushBuffer* pb)
2+
{
3+
// Y axis is already scaled 512/216 x 0x360/0x600 -> 4x3
4+
// X axis correction for 16x9 must be 9/16 x 4/3 -> 0.75
5+
// 16x9 is 0.75, 20x9 is 0.6, etc
6+
7+
// 600 / 1000 for 20x9
8+
// 750 / 1000 for 16x9
9+
// 1000 / 1000 for 4x3
10+
11+
pb->matrix_ViewProj.t[0] =
12+
pb->matrix_ViewProj.t[0] * 750 / 1000;
13+
14+
pb->matrix_ViewProj.m[0][0] =
15+
pb->matrix_ViewProj.m[0][0] * 750 / 1000;
16+
17+
pb->matrix_ViewProj.m[0][1] =
18+
pb->matrix_ViewProj.m[0][1] * 750 / 1000;
19+
20+
pb->matrix_ViewProj.m[0][2] =
21+
pb->matrix_ViewProj.m[0][2] * 750 / 1000;
22+
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
void ui16BY9_DrawPolyFT4(struct Icon* icon, short posX, short posY, struct PrimMem* primMem, u_long* ot, char transparency, short scale)
2+
{
3+
if (!icon) return;
4+
5+
POLY_FT4* p = (POLY_FT4*)primMem->curr;
6+
addPolyFT4(ot, p);
7+
8+
unsigned int width = icon->texLayout.u1 - icon->texLayout.u0;
9+
unsigned int height = icon->texLayout.v2 - icon->texLayout.v0;
10+
unsigned int bottomY = posY + FP_Mult(height, scale);
11+
unsigned int rightX = posX + FP_Mult(width, scale);
12+
13+
setXY4(p, posX, posY, rightX, posY, posX, bottomY, rightX, bottomY);
14+
setIconUV(p, icon);
15+
16+
// this function doesn't support coloring the primitives
17+
setShadeTex(p, true);
18+
19+
if (transparency)
20+
{
21+
setTransparency(p, transparency);
22+
}
23+
24+
// widescreen, need to scale X by 75%,
25+
// so subtract 12% from left and 12% from right
26+
int len = ((p->x1 - p->x0) * 125) / 1000;
27+
p->x0 += len;
28+
p->x2 += len;
29+
p->x1 -= len;
30+
p->x3 -= len;
31+
32+
primMem->curr = p + 1;
33+
}
34+
35+
void ui16BY9_DrawWeapon(struct Icon* icon, short posX, short posY, struct PrimMem* primMem, u_long* ot, char transparency, short scale, char rot)
36+
{
37+
#if BUILD > SepReview
38+
if (!icon) return;
39+
#endif
40+
41+
POLY_FT4* p = (POLY_FT4*)primMem->curr;
42+
addPolyFT4(ot, p);
43+
44+
unsigned int width = icon->texLayout.u1 - icon->texLayout.u0;
45+
unsigned int height = icon->texLayout.v2 - icon->texLayout.v0;
46+
unsigned int rightX = posX + FP_Mult(width, scale);
47+
unsigned int bottomY = posY + FP_Mult(height, scale);
48+
unsigned int sidewaysX = posX + FP_Mult(height, scale);
49+
unsigned int sidewaysY = posY + FP_Mult(width, scale);
50+
51+
if (!(rot & 1))
52+
{
53+
if (rot == 0)
54+
{
55+
setXY4(p, (u_short)posX, posY, (u_short)rightX, posY, (u_short)posX, bottomY, (u_short)rightX, bottomY);
56+
}
57+
else
58+
{
59+
setXY4(p, (u_short)rightX, bottomY, (u_short)posX, bottomY, (u_short)rightX, posY, (u_short)posX, posY);
60+
}
61+
}
62+
else
63+
{
64+
if (rot == 1)
65+
{
66+
setXY4(p, (u_short)posX, sidewaysY, (u_short)posX, posY, (u_short)sidewaysX, sidewaysY, (u_short)sidewaysX, posY);
67+
}
68+
else
69+
{
70+
setXY4(p, (u_short)sidewaysX, posY, (u_short)sidewaysX, sidewaysY, (u_short)posX, posY, (u_short)posX, sidewaysY);
71+
}
72+
}
73+
74+
75+
setIconUV(p, icon);
76+
77+
// this function doesn't support coloring the primitives
78+
setShadeTex(p, true);
79+
80+
if (transparency)
81+
{
82+
setTransparency(p, transparency);
83+
}
84+
85+
// widescreen, need to scale X by 75%,
86+
// so subtract 12% from left and 12% from right
87+
int len = ((p->x2 - p->x0) * 125) / 1000;
88+
p->x0 += len;
89+
p->x1 += len;
90+
p->x2 -= len;
91+
p->x3 -= len;
92+
93+
primMem->curr = p + 1;
94+
}
95+
96+
void ui16BY9_DrawPolyGT4(
97+
struct Icon* icon, short posX, short posY, struct PrimMem* primMem, u_long* ot,
98+
u_int color0, u_int color1, u_int color2, u_int color3, char transparency, short scale)
99+
{
100+
#if BUILD > SepReview
101+
if (!icon) return;
102+
#endif
103+
104+
// setInt32RGB4 needs to go before addPolyGT4
105+
// for more information check "include/gpu.h"
106+
POLY_GT4* p = (POLY_GT4*)primMem->curr;
107+
setInt32RGB4(p, color0, color1, color2, color3);
108+
addPolyGT4(ot, p);
109+
110+
unsigned int width = icon->texLayout.u1 - icon->texLayout.u0;
111+
unsigned int height = icon->texLayout.v2 - icon->texLayout.v0;
112+
unsigned int bottomY = posY + FP_Mult(height, scale);
113+
unsigned int rightX = posX + FP_Mult(width, scale);
114+
115+
setXY4(p, posX, posY, rightX, posY, posX, bottomY, rightX, bottomY);
116+
setIconUV(p, icon);
117+
118+
if (transparency)
119+
{
120+
setTransparency(p, transparency);
121+
}
122+
123+
// widescreen, need to scale X by 75%,
124+
// so subtract 12% from left and 12% from right
125+
int len = ((p->x1 - p->x0) * 125) / 1000;
126+
p->x0 += len;
127+
p->x2 += len;
128+
p->x1 -= len;
129+
p->x3 -= len;
130+
131+
primMem->curr = p + 1;
132+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
#ifndef REBUILD_PC
2+
3+
#define JMP(dest) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0x8000000)
4+
#define JAL(dest) (((unsigned long)dest & 0x3FFFFFF) >> 2 | 0xC000000)
5+
6+
int BoolCheckExhaust(struct Driver* d)
7+
{
8+
// 30fps PASS conditions:
9+
// humans:
10+
// 1P: every frame
11+
// 2P: driverID == gGT->timer&1
12+
// 3P4P: driverID == gGT->timer&3
13+
// bots:
14+
// driverID&3 == gGT->timer&3
15+
16+
// 60fps FAIL conditions:
17+
// humans:
18+
// 1P: gGT->timer&1
19+
// 2P: gGT->timer&2
20+
// 3P4P: gGT->timer&4
21+
// bots:
22+
// gGT->timer&4
23+
24+
struct GameTracker* gGT = sdata->gGT;
25+
int numPlyr = gGT->numPlyrCurrGame;
26+
int timer = gGT->timer;
27+
28+
// human
29+
if(d->driverID < numPlyr)
30+
{
31+
if(numPlyr == 1)
32+
{
33+
if((timer&1) != 0)
34+
return 0;
35+
}
36+
37+
else if(numPlyr == 2)
38+
{
39+
if((timer&2) != 0)
40+
return 0;
41+
}
42+
43+
// 3p/4p
44+
else
45+
{
46+
if((timer&4) != 0)
47+
return 0;
48+
}
49+
}
50+
51+
// AI
52+
else
53+
{
54+
if((timer&4) != 0)
55+
return 0;
56+
}
57+
58+
return 1;
59+
}
60+
61+
// This executes one time, before the
62+
// Crash Team Racing exe boots
63+
void ui60_entryHook()
64+
{
65+
u_int i;
66+
67+
// replace call to LIST_RemoveFront inside Particle_Init,
68+
// this alternative version is stored in Mods7.c
69+
struct Particle* NewParticleInit(struct LinkedList* param_1);
70+
*(unsigned int*)0x80040348 = JAL(NewParticleInit);
71+
72+
// Gravity
73+
{
74+
#ifndef USE_ONLINE
75+
// decrease from 900 to xxx,
76+
// otherwise Hot Air Skyway C-T-R token is impossible,
77+
// and some shortcuts are impossible (HAS USF jump to startline)
78+
for(int i = 0; i < NUM_CLASSES; i++)
79+
data.metaPhys[0].value[i] = 850;
80+
#else
81+
// Online Multiplayer doesnt need C-T-R token letters,
82+
// make the rest of the game feel more accurate
83+
for(int i = 0; i < NUM_CLASSES; i++)
84+
data.metaPhys[0].value[i] = 875;
85+
#endif
86+
}
87+
88+
// SelectProfile flashing orange/red
89+
// for strings SAVE/LOAD/WARNING
90+
{
91+
*(short*)0x8004A5C8 = FPS_DOUBLE(4);
92+
}
93+
94+
// Starting line
95+
{
96+
// Intro Camera Fly-in
97+
// Need to fix camera zoom to player
98+
99+
// these are in FollowDriver_Normal
100+
*(unsigned short*)0x8001AF6C = 0x14A;
101+
*(unsigned short*)0x8001AF80 = 0x12D;
102+
*(unsigned short*)0x8001AF8C = 0x12C;
103+
*(unsigned short*)0x8001AF90 = 0x12C;
104+
}
105+
106+
// AI cooldown
107+
{
108+
// nextDriver->weaponCooldown
109+
*(short*)0x800412ac = FPS_DOUBLE(0xFF);
110+
*(short*)0x800412b0 = FPS_DOUBLE(0xF0);
111+
112+
// nextDriver->weaponCooldown (same func, different place)
113+
*(short*)0x8004149c = FPS_DOUBLE(0xFF);
114+
*(short*)0x800414a0 = FPS_DOUBLE(0xF0);
115+
116+
// BOTS_GotoStartingLine cooldown
117+
*(short*)0x80017144 = FPS_DOUBLE(0xFF);
118+
*(short*)0x80017148 = FPS_DOUBLE(0x12c);
119+
}
120+
121+
// Boss cooldown
122+
{
123+
// 8008d8e4 needs to be doubled, after being set
124+
125+
struct MetaDataBOSS* x;
126+
127+
for(
128+
x = &data.BossWeaponOxide[0];
129+
x < &data.bossWeaponMetaPtr[0];
130+
x++
131+
)
132+
{
133+
// double min cooldown
134+
x->weaponCooldown = FPS_DOUBLE(x->weaponCooldown);
135+
}
136+
137+
// double & 0x10
138+
// double + 0xc
139+
// double <<2 to <<4
140+
*(unsigned short*)0x80040c24 = FPS_DOUBLE(0x10);
141+
*(unsigned short*)0x80040c40 = FPS_DOUBLE(0xC);
142+
*(int*)0x80040c50 = 0x31900;
143+
144+
// double & 0x10
145+
// double + 0xc
146+
// double <<2 to <<4
147+
*(unsigned short*)0x80040f4c = FPS_DOUBLE(0x10);
148+
*(unsigned short*)0x80040f68 = FPS_DOUBLE(0xC);
149+
*(int*)0x80040f78 = 0x31900;
150+
}
151+
152+
// Inject new hooks, these are stored in Mods7.c
153+
void NewCallback231();
154+
void NewCallback233();
155+
data.overlayCallbackFuncs[1] = NewCallback231;
156+
data.overlayCallbackFuncs[3] = NewCallback233;
157+
return;
158+
}
159+
160+
#endif
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef REBUILD_PC
2+
3+
void NewCallback231()
4+
{
5+
// start banner
6+
{
7+
// 800b57c0 and 800b57d0
8+
*(unsigned int*)0x800b57c0 = 0x240B0001; // (t3) 0001
9+
*(unsigned int*)0x800b57d0 = 0xA08b0018; // a0 offset 0x18, write t3
10+
11+
// set thread->cooldown to 1 frame,
12+
// run thread at 30fps, in 60fps gameplay
13+
}
14+
15+
DECOMP_LOAD_Callback_Overlay_231();
16+
}
17+
18+
void NewCallback233()
19+
{
20+
// 233 patches here...
21+
22+
// set in Podium_Prize_ThTick1
23+
*(short*)0x800afdb4 = 0xf * 2;
24+
25+
// prize spin podium
26+
*(unsigned short*)0x800af7e4 = 50; // 100/2 (not hex)
27+
28+
DECOMP_LOAD_Callback_Overlay_233();
29+
}
30+
31+
struct Particle* NewParticleInit(struct LinkedList* param_1)
32+
{
33+
// NOTE: Need to add workaround for RB_Explosion_InitPotion,
34+
// VehEmitter_DriverMain, when those functions are rewritten,
35+
// can't do VehEmitter_Sparks_Ground due to byte budget
36+
37+
// Workaround, use unused variable to force particles on "any"
38+
// frame. This is required for effects that spawn 10x particles
39+
// on the same frame (MaskGrab, AkuHints, SpitTire, VehEmitter)
40+
if (sdata->UnusedPadding1 == 0)
41+
{
42+
// do 2 instead of 1,
43+
// that way timer & 1 works with SetLeft and SetRight,
44+
// see VehEmitter_DriverMain and call to VehEmitter_Terrain_Ground
45+
if (sdata->gGT->timer & 2) return 0;
46+
}
47+
48+
struct Particle* p =
49+
(struct Particle*)LIST_RemoveFront(param_1);
50+
51+
// remove patching for 60fps
52+
p->axis[0x9].startVal = 0;
53+
p->axis[0xA].startVal = 0;
54+
55+
return p;
56+
}
57+
58+
#endif

0 commit comments

Comments
 (0)