Skip to content

Commit

Permalink
OnlineCTR v1020 (CTR-tools#194)
Browse files Browse the repository at this point in the history
* onlinectr v1020 initial commit. some singleplayer testing seems to work, need to integrate with launcher, more multiplayer testing, update hosted assets, notify server hosts, write discord announcement.

* add back gpu defer.

* fix "load" screen crash when pressing select.

* Enable items on page 2.

* retrofueled working

* collisions no longer happen in itemless rooms.

* remove gpu defer

* disable online beta mode, fix launcher not applying settings.ini correctly.

* fix domain target

* bump launcher version

* some more testing, remove dead code, spectator mode now has player name at bottom of screen instead of jittery names3d

* special case to allow v1020 clients to connect to v1019 servers (they're compatible), change filehost domain, reduce client.exe startup delay by 2s

* uncomment USE_ONLINE from the merge.

* update filehost back to www.online-ctr.com
  • Loading branch information
TheUbMunster authored Nov 2, 2024
1 parent efe796e commit 9601b2b
Show file tree
Hide file tree
Showing 41 changed files with 737 additions and 1,552 deletions.
14 changes: 14 additions & 0 deletions decompile/General/AltMods/Mods2.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,27 @@
#include <common.h>

#ifdef USE_ONLINE
#include "../AltMods/OnlineCTR/global.h"
Color HsvToRgb(int h, int s, int v);

void FixReservesIncrement(struct Driver * driver, int reserves)
{
if (driver->reserves > 30000) { driver->uncappedReserves += reserves; }
else { driver->reserves += reserves; }
}

void Online_CollidePointWithBucket(struct Thread* th, short* vec3_pos)
{
int rn = octr->serverRoom;
if (!ROOM_IS_ITEMS(rn)) //itemless rooms have no collision.
return;
while (th != 0)
{
DECOMP_PROC_CollidePointWithSelf(th, vec3_pos);
// next
th = th->siblingThread;
}
}
#endif

#ifdef USE_BOOSTBAR
Expand Down
3 changes: 2 additions & 1 deletion decompile/General/AltMods/OnlineCTR/endOfRaceUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ void EndOfRace_Camera()
const char s_switchCam[] = "Press R1 or L1 to change the camera";
DECOMP_DecalFont_DrawLine(s_switchCam, 0x100, 5, FONT_SMALL, JUSTIFY_CENTER | ORANGE);

struct GamepadBuffer * pad = &sdata->gGamepads->gamepad[0];
DECOMP_DecalFont_DrawLine(octr->nameBuffer[currCam], 252, 195, FONT_BIG, JUSTIFY_CENTER | PAPU_YELLOW);
struct GamepadBuffer* pad = &sdata->gGamepads->gamepad[0];
if (pad->buttonsTapped & BTN_R1) { SetNextCamera(true); }
if (pad->buttonsTapped & BTN_L1) { SetNextCamera(false); }
}
Expand Down
38 changes: 33 additions & 5 deletions decompile/General/AltMods/OnlineCTR/global.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef ONLINE_GLOBAL_H
#define ONLINE_GLOBAL_H

#define VERSION 1019
#define VERSION 1020
//#define ONLINE_BETA_MODE

#ifndef WINDOWS_INCLUDE
Expand Down Expand Up @@ -32,6 +32,35 @@
#define IP_ADDRESS_SIZE 16 // assuming IPv4 (which is "xxx.xxx.xxx.xxx" + '\0')
#define PORT_SIZE 6 // the port number as a string (0-65535 + '\0')

//these let you adjust the number of rooms allocated to game types
//"START" is the starting index [0-15]
//"LENGTH" is the length of that game type.

//itemless rooms are 0 1 2 3 4
#define ROOM_ITEMLESSSTART 0
#define ROOM_ITEMLESSLENGTH 5
//item rooms are 5 6 7 8 9
#define ROOM_ITEMSTART 5
#define ROOM_ITEMLENGTH 5
//retro rooms are 10 11 12
#define ROOM_RETROSTART 10
#define ROOM_RETROLENGTH 3
//item + retro rooms are 13 14 15
#define ROOM_ITEMRETROSTART 13
#define ROOM_ITEMRETROLENGTH 3

#define ROOM_IS_ITEMS(rn) ((rn >= ROOM_ITEMSTART && rn < (ROOM_ITEMSTART + ROOM_ITEMLENGTH)) || \
(rn >= ROOM_ITEMRETROSTART && rn < (ROOM_ITEMRETROSTART + ROOM_ITEMRETROLENGTH)))
#define ROOM_IS_RETRO(rn) ((rn >= ROOM_RETROSTART && rn < (ROOM_RETROSTART + ROOM_RETROLENGTH)) || \
(rn >= ROOM_ITEMRETROSTART && rn < (ROOM_ITEMRETROSTART + ROOM_ITEMRETROLENGTH)))

// 2 seconds to be very tolerant on client
#ifdef USE_60FPS
#define DISCONNECT_AT_UNSYNCED_FRAMES 120
#else
#define DISCONNECT_AT_UNSYNCED_FRAMES 60
#endif

enum ClientState
{
LAUNCH_ENTER_PID,
Expand Down Expand Up @@ -61,7 +90,7 @@ typedef struct raceStats
} raceStats;

// This can be 0x400 (1024) bytes max:
// 0x8000C000 at 0x8000C400
// 0x8000C000 to 0x8000C400
struct OnlineCTR
{
// 0x0
Expand Down Expand Up @@ -135,9 +164,8 @@ struct OnlineCTR

char desiredFPS;

#ifdef PINE_DEBUG
int stateChangeCounter;
#endif
// when to start the client.exe loop
int readyToSend;
};

STATIC_ASSERT2(sizeof(struct OnlineCTR) <= 0x400, "Size of OnlineCTR must be lte 1kb");
Expand Down
20 changes: 13 additions & 7 deletions decompile/General/AltMods/OnlineCTR/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,9 @@ void OnlineInit_Drivers(struct GameTracker* gGT)
#endif
}

if (gGT->levelID != 0x26)
if (gGT->levelID != 0x26/*INTRO_RACE_TODAY*/) //was 0x26 (globe level)
{
octr->CurrState = GAME_WAIT_FOR_RACE;
#ifdef PINE_DEBUG
printf("statechange %d GAME_WAIT_FOR_RACE 1: \n", octr->stateChangeCounter++);
#endif
}
}

Expand All @@ -188,16 +185,25 @@ bool HasRaceEnded()

RECT windowText = {0x118, 0x40, 0xD8, 0};

//extern int currCam; //from endOfRaceUI.c

void OnlineEndOfRace()
{
struct Driver * driver = sdata->gGT->drivers[0];
if (((driver->actionsFlagSet & 0x2000000) == 0) ||
(octr->CurrState < GAME_START_RACE)) { return; }

//this is a potential untested fix for the "spectator name bug"
//(i.e.), when first beginning to spectate, the name of the person you're
//spectating at the bottom of the screen can sometimes be incorrect until you
//change the camera for the first time.
//if (octr->CurrState != GAME_END_RACE) //this must be out first frame here.
//{
// currCam = 0;
// sdata->gGT->cameraDC[0].driverToFollow = sdata->gGT->drivers[currCam];
//}

octr->CurrState = GAME_END_RACE;
#ifdef PINE_DEBUG
printf("statechange %d GAME_END_RACE 2: \n", octr->stateChangeCounter++);
#endif

static unsigned frameCounter = 0;
EndOfRace_Camera();
Expand Down
49 changes: 35 additions & 14 deletions decompile/General/AltMods/OnlineCTR/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void NewPage_ServerCountry()
{
int i;

menu.posX_curr = 0x198; // X position
menu.posX_curr = 0x188; // X position
menu.posY_curr = 0x84; // Y position

// override "LAPS" "3/5/7",
Expand Down Expand Up @@ -141,27 +141,48 @@ void NewPage_ServerRoom()
{
int i;

// override "LAPS" "3/5/7"
sdata->lngStrings[0x9a] = "ROOM 1 - x/8";
sdata->lngStrings[0x9b] = "ROOM 2 - x/8";
sdata->lngStrings[0x9c] = "ROOM 3 - x/8";
sdata->lngStrings[0x9d] = "ROOM 4 - x/8";
sdata->lngStrings[0x9e] = "ROOM 5 - x/8";
sdata->lngStrings[0x9f] = "ROOM 6 - x/8";
sdata->lngStrings[0xa0] = "ROOM 7 - x/8";
sdata->lngStrings[0xa1] = "ROOM 8 - x/8";

int pn = octr->PageNumber;

const char* itemless = "ITEMLESS";
const char* items = "ITEMS ";
const char* retro = "RETRO ";
const char* itmretro = "ITEM+RET";

sdata->lngStrings[0x9a] = "ROOM 1 - x/8";
sdata->lngStrings[0x9b] = "ROOM 2 - x/8";
sdata->lngStrings[0x9c] = "ROOM 3 - x/8";
sdata->lngStrings[0x9d] = "ROOM 4 - x/8";
sdata->lngStrings[0x9e] = "ROOM 5 - x/8";
sdata->lngStrings[0x9f] = "ROOM 6 - x/8";
sdata->lngStrings[0xa0] = "ROOM 7 - x/8";
sdata->lngStrings[0xa1] = "ROOM 8 - x/8";
for (i = 0; i < 8; i++)
{
int rn = i + (pn * 8);
const char* type;
if (rn >= ROOM_ITEMLESSSTART && rn < (ROOM_ITEMLESSSTART + ROOM_ITEMLESSLENGTH))
type = itemless;
if (rn >= ROOM_ITEMSTART && rn < (ROOM_ITEMSTART + ROOM_ITEMLENGTH))
type = items;
if (rn >= ROOM_RETROSTART && rn < (ROOM_RETROSTART + ROOM_RETROLENGTH))
type = retro;
if (rn >= ROOM_ITEMRETROSTART && rn < (ROOM_ITEMRETROSTART + ROOM_ITEMRETROLENGTH))
type = itmretro;
for (int name = 0; name < 8; name++)
{
sdata->lngStrings[0x9a+i][name] = type[name]; //replace "ROOM" with the roomtype
}
}

for(i = 0; i < 8; i++)
{
menuRows[i].stringIndex = 0x809a+i;
sdata->lngStrings[0x9a+i][5] = GetRoomChar(8*pn + i+1);
sdata->lngStrings[0x9a+i][9] = '0' + (octr->clientCount[8*pn+i]);
sdata->lngStrings[0x9a+i][9] = GetRoomChar(8*pn + i+1);
sdata->lngStrings[0x9a+i][13] = '0' + (octr->clientCount[8*pn+i]);

// handle locked rows
if(octr->clientCount[8*pn+i] > 8)
sdata->lngStrings[0x9a+i][9] = '0' + (octr->clientCount[8*pn+i]) - 8;
sdata->lngStrings[0x9a+i][13] = '0' + (octr->clientCount[8*pn+i]) - 8;
}

int numRooms = GetNumRoom();
Expand Down
24 changes: 13 additions & 11 deletions decompile/General/AltMods/OnlineCTR/states.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void ResetPsxGlobals()
void StatePS1_Launch_PickRoom()
{
#if 0
DecalFont_DrawLine("Special Events in odd rooms: 1,3,5...",0x100,0x14,FONT_SMALL,JUSTIFY_CENTER|PAPU_YELLOW);
DecalFont_DrawLine("Classic Games in even rooms: 2,4,6...",0x100,0x1c,FONT_SMALL,JUSTIFY_CENTER|PAPU_YELLOW);
DecalFont_DrawLine("Itemless games on first page",0x100,0x14,FONT_SMALL,JUSTIFY_CENTER|PAPU_YELLOW);
DecalFont_DrawLine("Items games on second page",0x100,0x1c,FONT_SMALL,JUSTIFY_CENTER|PAPU_YELLOW);
#endif

MenuWrites_ServerRoom();
Expand Down Expand Up @@ -126,17 +126,11 @@ void StatePS1_Lobby_AssignRole()
if(octr->DriverID == 0)
{
octr->CurrState = LOBBY_HOST_TRACK_PICK;
#ifdef PINE_DEBUG
printf("statechange %d LOBBY_HOST_TRACK_PICK 3: \n", octr->stateChangeCounter++);
#endif
}

else if (octr->DriverID > 0)
{
octr->CurrState = LOBBY_GUEST_TRACK_WAIT;
#ifdef PINE_DEBUG
printf("statechange %d LOBBY_GUEST_TRACK_WAIT 4: \n", octr->stateChangeCounter++);
#endif
}
}

Expand Down Expand Up @@ -349,7 +343,9 @@ void StatePS1_Game_WaitForRace()
}

gGT->trafficLightsTimer = 0xf40;
Ghostify();
int rn = octr->serverRoom;
if (!ROOM_IS_ITEMS(rn)) //itemless only
Ghostify();

if((gGT->gameMode1 & START_OF_RACE) != 0)
return;
Expand Down Expand Up @@ -386,7 +382,10 @@ void StatePS1_Game_WaitForRace()
void StatePS1_Game_StartRace()
{
int i;
Ghostify();

int rn = octr->serverRoom;
if (!ROOM_IS_ITEMS(rn)) //itemless only
Ghostify();

for(i = 1; i < 8; i++)
{
Expand Down Expand Up @@ -426,7 +425,8 @@ void StatePS1_Game_StartRace()

static void OnRaceEnd()
{
struct Driver ** drivers = sdata->gGT->drivers;
struct Driver* before = sdata->gGT->cameraDC[0].driverToFollow;
struct Driver** drivers = sdata->gGT->drivers;
bool foundRacer = false;
for (int driverID = 1; driverID < MAX_NUM_PLAYERS; driverID++)
{
Expand All @@ -439,6 +439,8 @@ static void OnRaceEnd()
foundRacer = true;
}
}
//tbh I don't think this fixes the spectator name bug.
sdata->gGT->cameraDC[0].driverToFollow = before;
}

void StatePS1_Game_EndRace()
Expand Down
68 changes: 19 additions & 49 deletions decompile/General/AltMods/OnlineCTR/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,30 @@ void ThreadFunc(struct Thread* t)
int isIdle = 0;

struct GameTracker* gGT = sdata->gGT;
octr->boolPlanetLEV = gGT->levelID == 0x26;
octr->boolPlanetLEV = gGT->levelID == 0x26; //was 0x26 (globe level)

if(octr->boolPlanetLEV)
{
*(int*)0x800ae54c = 0x3e00008;
*(int*)0x800ae550 = 0;
//this code seems to be causing the LOAD screen crash.

//*(int*)0x800ae54c = 0x3e00008;
//*(int*)0x800ae550 = 0;

// freecam mode
gGT->cameraDC[0].cameraMode = 3;
//// freecam mode
//gGT->cameraDC[0].cameraMode = 3;

// disable all HUD flags
gGT->hudFlags = 0;
//// disable all HUD flags
//gGT->hudFlags = 0;

struct PushBuffer* pb = &gGT->pushBuffer[0];
//struct PushBuffer* pb = &gGT->pushBuffer[0];

pb->pos[0] = 0x3D;
pb->pos[1] = 0xF8;
pb->pos[2] = 0xF879;
//pb->pos[0] = 0x3D;
//pb->pos[1] = 0xF8;
//pb->pos[2] = 0xF879;

pb->rot[0] = 0x841;
pb->rot[1] = 0x77c;
pb->rot[2] = 0xff5;
//pb->rot[0] = 0x841;
//pb->rot[1] = 0x77c;
//pb->rot[2] = 0xff5;
}

// only disable for no$psx testing,
Expand Down Expand Up @@ -84,34 +86,8 @@ void ThreadFunc(struct Thread* t)
octr->frames_unsynced = 0;
}

//this debug info courtesy of ClaudioBo
#ifdef PINE_DEBUG
static unsigned frameCounter = 0;
char frames_unsynced_str[12];
sprintf(frames_unsynced_str, "%d", octr->frames_unsynced);

if (octr->frames_unsynced >= 80) {
int color = frameCounter++ & FPS_DOUBLE(1) ? RED : WHITE;
char final_str[20];
sprintf(final_str, "WTF!!: %s/120", frames_unsynced_str);
DECOMP_DecalFont_DrawLine(final_str, 0x100, 200, FONT_BIG, JUSTIFY_CENTER | color);
}
else if (octr->frames_unsynced >= 60) {
DECOMP_DecalFont_DrawLine(frames_unsynced_str, 0x100, 200, FONT_BIG, JUSTIFY_CENTER | CORTEX_RED);
}
else if (octr->frames_unsynced >= 40) {
DECOMP_DecalFont_DrawLine(frames_unsynced_str, 0x100, 200, FONT_BIG, JUSTIFY_CENTER | ROO_ORANGE);
}
else if (octr->frames_unsynced >= 20) {
DECOMP_DecalFont_DrawLine(frames_unsynced_str, 0x100, 200, FONT_BIG, JUSTIFY_CENTER | PAPU_YELLOW);
}
else {
DECOMP_DecalFont_DrawLine(frames_unsynced_str, 0x100, 200, FONT_BIG, JUSTIFY_CENTER | WHITE);
}
#endif

// close if client didn't update the game in 2 seconds
int boolCloseClient = (octr->frames_unsynced > FPS_DOUBLE(60));
// close if client didn't update the game in DISCONNECT_AT_UNSYNCED_FRAMES
int boolCloseClient = (octr->frames_unsynced > DISCONNECT_AT_UNSYNCED_FRAMES);

// if client closed, or server disconnected
if(boolCloseClient || (octr->CurrState < 0))
Expand All @@ -123,9 +99,6 @@ void ThreadFunc(struct Thread* t)
// if closed==1, go to 0 ("please open client")
// if closed==0, go to 1 (server select)
octr->CurrState = !boolCloseClient;
#ifdef PINE_DEBUG
printf("statechange %d yesno open client/server select 5: \n", octr->stateChangeCounter++);
#endif

octr->serverLockIn1 = 0;
octr->serverLockIn2 = 0;
Expand All @@ -138,9 +111,6 @@ void ThreadFunc(struct Thread* t)
// if closed==1, go to 0 ("please open client")
// if closed==0, go to 1 (server select)
octr->CurrState = !boolCloseClient;
#ifdef PINE_DEBUG
printf("statechange %d yesno open client/server select 6: \n", octr->stateChangeCounter++);
#endif

// stop music,
// stop "most FX", let menu FX ring
Expand All @@ -163,7 +133,7 @@ void ThreadFunc(struct Thread* t)
#endif

// gameplay
if (octr->CurrState >= GAME_WAIT_FOR_RACE)
if (octr->CurrState >= GAME_WAIT_FOR_RACE && octr->CurrState < GAME_END_RACE)
{
void DrawOverheadNames();
DrawOverheadNames();
Expand Down
Loading

0 comments on commit 9601b2b

Please sign in to comment.