Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions docs/MODDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ Let's begin by finding where the time is updated. Thankfully in the save editor
So this tells us that `gSaveContext.dayTime` is what we're looking for. Let's now do a global search for this to see if we can find where it is updated. We find the following in `soh/src/code/z_kankyo.c` around line 925:

```cpp
if (IS_DAY || gTimeIncrement >= 0x190) {
gSaveContext.dayTime += gTimeIncrement;
if (IS_DAY || gTimeSpeed >= 0x190) {
gSaveContext.dayTime += gTimeSpeed;
} else {
gSaveContext.dayTime += gTimeIncrement * 2; // time moves twice as fast at night
gSaveContext.dayTime += gTimeSpeed * 2; // time moves twice as fast at night
}
```

We can make a quick change to this code to verify this is indeed what we are looking for, lets multiply the gTimeIncrement by 10:
We can make a quick change to this code to verify this is indeed what we are looking for, lets multiply the gTimeSpeed by 10:

```diff
if (IS_DAY || gTimeIncrement >= 0x190) {
- gSaveContext.dayTime += gTimeIncrement;
+ gSaveContext.dayTime += gTimeIncrement * 10;
if (IS_DAY || gTimeSpeed >= 0x190) {
- gSaveContext.dayTime += gTimeSpeed;
+ gSaveContext.dayTime += gTimeSpeed * 10;
} else {
- gSaveContext.dayTime += gTimeIncrement * 2; // time moves twice as fast at night
+ gSaveContext.dayTime += gTimeIncrement * 2 * 10; // time moves twice as fast at night
- gSaveContext.dayTime += gTimeSpeed * 2; // time moves twice as fast at night
+ gSaveContext.dayTime += gTimeSpeed * 2 * 10; // time moves twice as fast at night
}
```

Expand All @@ -102,12 +102,12 @@ This adds a `Widget` which sets a CVar, which then sets the options of the slide
Now we need to replace our hard coded values with the new variable. We can do this by replacing the `10` with a cvar call

```diff
if (IS_DAY || gTimeIncrement >= 0x190) {
- gSaveContext.dayTime += gTimeIncrement * 10;
+ gSaveContext.dayTime += gTimeIncrement * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f);
if (IS_DAY || gTimeSpeed >= 0x190) {
- gSaveContext.dayTime += gTimeSpeed * 10;
+ gSaveContext.dayTime += gTimeSpeed * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f);
} else {
- gSaveContext.dayTime += gTimeIncrement * 2 * 10;
+ gSaveContext.dayTime += gTimeIncrement * 2 * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f);
- gSaveContext.dayTime += gTimeSpeed * 2 * 10;
+ gSaveContext.dayTime += gTimeSpeed * 2 * CVarGetFloat(CVAR_CHEAT("TimeOfDayMultiplier"),1.0f);
}
```

Expand Down
3 changes: 3 additions & 0 deletions soh/include/alignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
#define ALIGN64(val) (((val) + 0x3F) & ~0x3F)
#define ALIGN256(val) (((val) + 0xFF) & ~0xFF)

// TODO: Update these
#ifdef __GNUC__
#define ALIGNED4 __attribute__ ((aligned (4)))
#define ALIGNED8 __attribute__ ((aligned (8)))
#else
#define ALIGNED4
#define ALIGNED8
#endif

Expand Down
28 changes: 28 additions & 0 deletions soh/include/debug_display.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef DEBUG_DISPLAY_H
#define DEBUG_DISPLAY_H

#include <libultraship/libultra.h>
#include "z64math.h"
#include <libultraship/color.h>

#include "extern_c_helper.h"

struct GraphicsContext;
struct PlayState;

typedef struct DebugDispObject {
/* 0x00 */ Vec3f pos;
/* 0x0C */ Vec3s rot;
/* 0x14 */ Vec3f scale;
/* 0x20 */ Color_RGBA8 color;
/* 0x24 */ s16 type;
/* 0x28 */ struct DebugDispObject* next;
} DebugDispObject; // size = 0x2C

EXTERN_C void DebugDisplay_Init(void);
EXTERN_C DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX,
f32 scaleY, f32 scaleZ, u8 red, u8 green, u8 blue, u8 alpha, s16 type,
struct GraphicsContext* gfxCtx);
EXTERN_C void DebugDisplay_DrawObjects(struct PlayState* play);

#endif
244 changes: 244 additions & 0 deletions soh/include/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
#ifndef ENVIRONMENT_H_
#define ENVIRONMENT_H_

#include "z64math.h"
#include "z64light.h"
#include "z64dma.h"

#include "extern_c_helper.h"

struct GameOverContext;
struct MessageContext;
struct PauseContext;
struct PlayState;
struct SkyboxContext;
struct View;

#define FILL_SCREEN_OPA (1 << 0)
#define FILL_SCREEN_XLU (1 << 1)

// TODO: NEXT_TIME macros

// TODO: LIGHT_SETTING macros

// TODO: LIGHT_BLEND macros

// TODO: LightMode enum

Comment thread
serprex marked this conversation as resolved.
typedef enum SkyboxDmaState {
/* 0 */ SKYBOX_DMA_INACTIVE,
/* 1 */ SKYBOX_DMA_FILE1_START,
/* 2 */ SKYBOX_DMA_FILE1_DONE,
/* 3 */ SKYBOX_DMA_PAL1_START,
/* 11 */ SKYBOX_DMA_FILE2_START = 11,
/* 12 */ SKYBOX_DMA_FILE2_DONE,
/* 13 */ SKYBOX_DMA_PAL2_START
} SkyboxDmaState;

typedef enum LightningMode {
/* 0 */ LIGHTNING_MODE_OFF, // no lightning
/* 1 */ LIGHTNING_MODE_ON, // request ligtning strikes at random intervals
/* 2 */ LIGHTNING_MODE_LAST // request one lightning strike before turning off
} LightningMode;

typedef enum LightningStrikeState {
/* 0 */ LIGHTNING_STRIKE_WAIT, // wait between lightning strikes. request bolts when timer hits 0
/* 1 */ LIGHTNING_STRIKE_START, // fade in the flash. note: bolts are requested in the previous state
/* 2 */ LIGHTNING_STRIKE_END // fade out the flash and go back to wait
} LightningStrikeState;

// TODO: WeatherMode enum

// TODO: ChangeSkyboxState enum

// TODO: PrecipitationData enum

// TODO: StormRequest enum

// TODO: StormState enum

// TODO: TimeBasedSeqState enum

typedef enum SandstormState {
/* 0 */ SANDSTORM_OFF,
/* 1 */ SANDSTORM_FILL,
/* 2 */ SANDSTORM_UNFILL,
/* 3 */ SANDSTORM_ACTIVE,
/* 4 */ SANDSTORM_DISSIPATE
} SandstormState;

typedef struct LightningStrike {
/* 0x00 */ u8 state;
/* 0x01 */ u8 flashRed;
/* 0x02 */ u8 flashGreen;
/* 0x03 */ u8 flashBlue;
/* 0x04 */ u8 flashAlphaTarget;
/* 0x08 */ f32 delayTimer;
} LightningStrike; // size = 0xC

// TODO: Update the type to upstream (TimeBasedSkyboxEntry)
// describes what skybox files and blending modes to use depending on time of day
typedef struct struct_8011FC1C {
/* 0x00 */ u16 startTime;
/* 0x02 */ u16 endTime;
/* 0x04 */ u8 blend; // if true, blend between.. skyboxes? palettes?
/* 0x05 */ u8 skybox1Index; // whats the difference between _pal and non _pal files?
/* 0x06 */ u8 skybox2Index;
} struct_8011FC1C; // size = 0x8

// TODO: CurrentEnvLightSettings struct

// `EnvLightSettings` is very similar to `CurrentEnvLightSettings` with one key difference.
// The light settings data in the scene packs blend rate information with the fog near value.
// The blendRate determines how fast the current light settings fade to the next one
// (under LIGHT_MODE_SETTINGS, otherwise unused).

// TODO: BLEND_RATE macro

// TODO: ENV_LIGHT macros

// TODO: Update the type to upstream
typedef struct EnvLightSettings {
/* 0x00 */ u8 ambientColor[3];
/* 0x03 */ s8 light1Dir[3];
/* 0x06 */ u8 light1Color[3];
/* 0x09 */ s8 light2Dir[3];
/* 0x0C */ u8 light2Color[3];
/* 0x0F */ u8 fogColor[3];
/* 0x12 */ s16 fogNear;
/* 0x14 */ s16 fogFar;
} EnvLightSettings; // size = 0x16

// TODO: Update the type to upstream
typedef struct EnvironmentContext {
/* 0x00 */ char unk_00[0x02];
/* 0x02 */ u16 timeIncrement; // how many units of time that pass every update
/* 0x04 */ Vec3f sunPos; // moon position can be found by negating the sun position
/* 0x10 */ u8 skybox1Index;
/* 0x11 */ u8 skybox2Index;
/* 0x12 */ char unk_12[0x01];
/* 0x13 */ u8 skyboxBlend;
/* 0x14 */ char unk_14[0x01];
/* 0x15 */ u8 skyboxDisabled;
/* 0x16 */ u8 sunMoonDisabled;
/* 0x17 */ u8 unk_17; // currentWeatherMode for skybox? (prev called gloomySky)
/* 0x18 */ u8 unk_18; // nextWeatherMode for skybox?
/* 0x19 */ u8 unk_19;
/* 0x1A */ u16 unk_1A;
/* 0x1C */ char unk_1C[0x02];
/* 0x1E */ u8 indoors; // when set, day time has no effect on lighting
/* 0x1F */ u8 unk_1F; // outdoor light index
/* 0x20 */ u8 unk_20; // prev outdoor light index?
/* 0x21 */ u8 unk_21;
/* 0x22 */ u16 unk_22;
/* 0x24 */ u16 unk_24;
/* 0x26 */ char unk_26[0x02];
/* 0x28 */ LightInfo dirLight1; // used for sunlight outdoors
/* 0x36 */ LightInfo dirLight2; // used for moonlight outdoors
/* 0x44 */ s8 skyboxDmaState;
/* 0x48 */ DmaRequest dmaRequest;
/* 0x68 */ OSMesgQueue loadQueue;
/* 0x80 */ OSMesg loadMsg;
/* 0x84 */ f32 unk_84;
/* 0x88 */ f32 unk_88;
/* 0x8C */ s16 adjAmbientColor[3];
/* 0x92 */ s16 adjLight1Color[3];
/* 0x98 */ s16 adjFogColor[3];
/* 0x9E */ s16 adjFogNear;
/* 0xA0 */ s16 adjFogFar;
/* 0xA2 */ char unk_A2[0x06];
/* 0xA8 */ Vec3s windDirection;
/* 0xB0 */ f32 windSpeed;
/* 0xB4 */ u8 numLightSettings;
/* 0xB8 */ EnvLightSettings* lightSettingsList; // list of light settings from the scene file
/* 0xBC */ u8 blendIndoorLights; // when true, blend between indoor light settings when switching
/* 0xBD */ u8 unk_BD; // indoor light index
/* 0xBE */ u8 unk_BE; // prev indoor light index?
/* 0xBF */ u8 unk_BF;
/* 0xC0 */ EnvLightSettings lightSettings;
/* 0xD6 */ u16 unk_D6;
/* 0xD8 */ f32 unk_D8; // indoor light blend weight?
/* 0xDC */ u8 unk_DC;
/* 0xDD */ u8 gloomySkyMode;
/* 0xDE */ u8 unk_DE; // gloomy sky state
/* 0xDF */ u8 lightningMode;
/* 0xE0 */ u8 unk_E0; // env sounds state
/* 0xE1 */ u8 fillScreen;
/* 0xE2 */ u8 screenFillColor[4];
/* 0xE6 */ u8 sandstormState;
/* 0xE7 */ u8 sandstormPrimA;
/* 0xE8 */ u8 sandstormEnvA;
/* 0xE9 */ u8 customSkyboxFilter;
/* 0xEA */ u8 skyboxFilterColor[4];
/* 0xEE */ u8 unk_EE[4];
/* 0xF2 */ u8 unk_F2[4];
/* 0xF6 */ char unk_F6[0x06];
} EnvironmentContext; // size = 0xFC

// TODO: Rename variables
EXTERN_C u8 gSkyboxBlendingEnabled;
EXTERN_C struct_8011FC1C D_8011FC1C[][9];

EXTERN_C u8 gWeatherMode;
EXTERN_C u8 D_8011FB34;
EXTERN_C u8 D_8011FB38;
EXTERN_C u16 gTimeSpeed;

EXTERN_C LightningStrike gLightningStrike;

// TODO: These variables are here for BSS ordering but ideally they should not
// be extern. This could be fixed by putting more stuff (e.g. struct definitions)
// between gLightningStrike and gCustomLensFlareOn.
// TODO: Missing variables
EXTERN_C u8 gCustomLensFlareOn;
EXTERN_C Vec3f gCustomLensFlarePos;
EXTERN_C s16 gLensFlareScale;
EXTERN_C f32 gLensFlareColorIntensity;
EXTERN_C s16 gLensFlareScreenFillAlpha;

// Environment_UpdateSkybox was updated during porting to add a PlayState* argument?
EXTERN_C void Environment_UpdateSkybox(struct PlayState* play, u8 skyboxId, EnvironmentContext* envCtx, struct SkyboxContext* skyboxCtx);
EXTERN_C void Environment_DrawSkyboxFilters(struct PlayState* play);

// TODO: Rename to Environment_ZBufValToFixedPoint
EXTERN_C s32 func_8006F0A0(s32 arg0);
EXTERN_C u16 Environment_GetPixelDepth(s32 x, s32 y);
EXTERN_C void Environment_GraphCallback(struct GraphicsContext* gfxCtx, void* param);
EXTERN_C void Environment_Init(struct PlayState* play2, EnvironmentContext* envCtx, s32 unused);
EXTERN_C u8 Environment_SmoothStepToU8(u8* pvalue, u8 target, u8 scale, u8 step, u8 minStep);
EXTERN_C u8 Environment_SmoothStepToS8(s8* pvalue, s8 target, u8 scale, u8 step, u8 minStep);
EXTERN_C f32 Environment_LerpWeight(u16 max, u16 min, u16 val);
EXTERN_C f32 Environment_LerpWeightAccelDecel(u16 endFrame, u16 startFrame, u16 curFrame, u16 accelDuration, u16 decelDuration);
EXTERN_C void Environment_EnableUnderwaterLights(struct PlayState* play, s32 waterLightsIndex);
EXTERN_C void Environment_DisableUnderwaterLights(struct PlayState* play);
EXTERN_C void Environment_Update(struct PlayState* play, EnvironmentContext* envCtx, LightContext* lightCtx,
struct PauseContext* pauseCtx, struct MessageContext* msgCtx,
struct GameOverContext* gameOverCtx, struct GraphicsContext* gfxCtx);
EXTERN_C void Environment_DrawSunAndMoon(struct PlayState* play);
EXTERN_C void Environment_DrawSunLensFlare(struct PlayState* play, EnvironmentContext* envCtx, struct View* view,
struct GraphicsContext* gfxCtx, Vec3f pos, s32 unused);
EXTERN_C void Environment_DrawLensFlare(struct PlayState* play, EnvironmentContext* envCtx, struct View* view,
struct GraphicsContext* gfxCtx, Vec3f pos, s32 unused, s16 arg6, f32 arg7, s16 arg8, u8 arg9);
EXTERN_C void Environment_DrawRain(struct PlayState* play, struct View* view, struct GraphicsContext* gfxCtx);
// TODO: Rename to Environment_ChangeLightSetting
EXTERN_C void func_80074CE8(struct PlayState* play, u32 arg1);
EXTERN_C void Environment_UpdateLightningStrike(struct PlayState* play);
EXTERN_C void Environment_AddLightningBolts(struct PlayState* play, u8 num);
EXTERN_C void Environment_DrawLightning(struct PlayState* play, s32 unused);
EXTERN_C void Environment_PlaySceneSequence(struct PlayState* play);
EXTERN_C void Environment_DrawCustomLensFlare(struct PlayState* play);
EXTERN_C void Environment_InitGameOverLights(struct PlayState* play);
EXTERN_C void Environment_FadeInGameOverLights(struct PlayState* play);
EXTERN_C void Environment_FadeOutGameOverLights(struct PlayState* play);
EXTERN_C void Environment_FillScreen(struct GraphicsContext* gfxCtx, u8 red, u8 green, u8 blue, u8 alpha, u8 drawFlags);
EXTERN_C void Environment_DrawSandstorm(struct PlayState* play, u8 sandstormState);
EXTERN_C void Environment_AdjustLights(struct PlayState* play, f32 arg1, f32 arg2, f32 arg3, f32 arg4);
EXTERN_C s32 Environment_GetBgsDayCount(void);
EXTERN_C void Environment_ClearBgsDayCount(void);
EXTERN_C s32 Environment_GetTotalDays(void);
EXTERN_C void Environment_ForcePlaySequence(u16 seqId);
EXTERN_C s32 Environment_IsForcedSequenceDisabled(void);
EXTERN_C void Environment_PlayStormNatureAmbience(struct PlayState* play);
EXTERN_C void Environment_StopStormNatureAmbience(struct PlayState* play);
EXTERN_C void Environment_WarpSongLeave(struct PlayState* play);
#endif
9 changes: 9 additions & 0 deletions soh/include/extern_c_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

// SoH: Helper for headers which can be included in both C & C++

#if __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C extern
#endif
39 changes: 39 additions & 0 deletions soh/include/font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef FONT_H
#define FONT_H

#include <libultraship/libultra.h>

#include "extern_c_helper.h"

// #region SoH [Port]: Increased char buffer because texture paths could be bigger than (16 * 16 / 2)
#define FONT_CHAR_MULTIPLIER 256
// #endregion

// TODO get these properties from the textures themselves
#define FONT_CHAR_TEX_WIDTH 16
#define FONT_CHAR_TEX_HEIGHT 16
#define FONT_CHAR_TEX_SIZE ((FONT_CHAR_TEX_WIDTH * FONT_CHAR_TEX_HEIGHT) / 2) // 16x16 I4 texture

// TODO: Update the type to upstream
typedef struct Font {
/* 0x0000 */ uintptr_t msgOffset;
/* 0x0004 */ u32 msgLength;
/* 0x0008 */ u8 charTexBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER];
/* 0x3C08 */ u8 iconBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER];
/* 0x3C88 */ u8 fontBuf[FONT_CHAR_TEX_SIZE * FONT_CHAR_MULTIPLIER];
union {
/* 0xDC88 */ char msgBuf[1280];
/* 0xDC88 */ u16 msgBufWide[640];
};
} Font; // size = 0xE188

// TODO: PLATFORM macros
#if false//PLATFORM_IQUE
EXTERN_C void Font_LoadCharCHN(Font* font, u16 character, u16 codePointIndex);
#endif
EXTERN_C void Font_LoadCharWide(Font* font, u16 character, u16 codePointIndex);
EXTERN_C void Font_LoadChar(Font* font, u8 character, u16 codePointIndex);
EXTERN_C void Font_LoadMessageBoxIcon(Font* font, u16 icon);
EXTERN_C void Font_LoadOrderedFont(Font* font);

#endif
Loading
Loading