Fix being stuck in zoom fov if map motd is changed to -hax (thanks aleksb385)

This commit is contained in:
UnknownShadow200 2019-04-28 18:13:00 +10:00
parent c4ae04b777
commit eb6c50e54c
14 changed files with 116 additions and 114 deletions

View File

@ -23,9 +23,6 @@ static void Camera_LoseFocus(void) {
static void Camera_OnRawMouseMoved(int deltaX, int deltaY) { static void Camera_OnRawMouseMoved(int deltaX, int deltaY) {
cam_delta.X += deltaX; cam_delta.Y += deltaY; cam_delta.X += deltaX; cam_delta.Y += deltaY;
} }
static void Camera_RawMouseMovedHandler(void* obj, int deltaX, int deltaY) {
Camera.Active->OnRawMouseMoved(deltaX, deltaY);
}
/*########################################################################################################################* /*########################################################################################################################*
*--------------------------------------------------Perspective camera-----------------------------------------------------* *--------------------------------------------------Perspective camera-----------------------------------------------------*
@ -224,13 +221,23 @@ static struct Camera cam_ForwardThird = {
/*########################################################################################################################* /*########################################################################################################################*
*-----------------------------------------------------General camera------------------------------------------------------* *-----------------------------------------------------General camera------------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void Camera_RawMouseMovedHandler(void* obj, int deltaX, int deltaY) {
Camera.Active->OnRawMouseMoved(deltaX, deltaY);
}
static void Camera_CheckThirdPerson(void* obj) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
if (!h->CanUseThirdPersonCamera || !h->Enabled) Camera_CycleActive();
}
void Camera_Init(void) { void Camera_Init(void) {
Camera_Register(&cam_FirstPerson); Camera_Register(&cam_FirstPerson);
Camera_Register(&cam_ThirdPerson); Camera_Register(&cam_ThirdPerson);
Camera_Register(&cam_ForwardThird); Camera_Register(&cam_ForwardThird);
Camera.Active = &cam_FirstPerson; Camera.Active = &cam_FirstPerson;
Event_RegisterMouseMove(&MouseEvents.RawMoved, NULL, Camera_RawMouseMovedHandler); Event_RegisterMouseMove(&MouseEvents.RawMoved, NULL, Camera_RawMouseMovedHandler);
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, NULL, Camera_CheckThirdPerson);
Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 30); Camera.Sensitivity = Options_GetInt(OPT_SENSITIVITY, 1, 100, 30);
Camera.Clipping = Options_GetBool(OPT_CAMERA_CLIPPING, true); Camera.Clipping = Options_GetBool(OPT_CAMERA_CLIPPING, true);
@ -242,10 +249,10 @@ void Camera_CycleActive(void) {
if (Game_ClassicMode) return; if (Game_ClassicMode) return;
Camera.Active = Camera.Active->Next; Camera.Active = Camera.Active->Next;
cam_isForwardThird = Camera.Active == &cam_ForwardThird;
if (!p->Hacks.CanUseThirdPersonCamera || !p->Hacks.Enabled) { if (!p->Hacks.CanUseThirdPersonCamera || !p->Hacks.Enabled) {
Camera.Active = &cam_FirstPerson; Camera.Active = &cam_FirstPerson;
} }
cam_isForwardThird = Camera.Active == &cam_ForwardThird;
/* reset rotation offset when changing cameras */ /* reset rotation offset when changing cameras */
cam_rotOffset.X = 0.0f; cam_rotOffset.Y = 0.0f; cam_rotOffset.X = 0.0f; cam_rotOffset.Y = 0.0f;

View File

@ -789,15 +789,7 @@ struct LocalPlayer LocalPlayer_Instance;
static bool hackPermMsgs; static bool hackPermMsgs;
float LocalPlayer_JumpHeight(void) { float LocalPlayer_JumpHeight(void) {
struct LocalPlayer* p = &LocalPlayer_Instance; struct LocalPlayer* p = &LocalPlayer_Instance;
return (float)PhysicsComp_GetMaxHeight(p->Physics.JumpVel); return (float)PhysicsComp_CalcMaxHeight(p->Physics.JumpVel);
}
void LocalPlayer_CheckHacksConsistency(void) {
struct LocalPlayer* p = &LocalPlayer_Instance;
HacksComp_CheckConsistency(&p->Hacks);
if (!HacksComp_CanJumpHigher(&p->Hacks)) {
p->Physics.JumpVel = p->Physics.ServerJumpVel;
}
} }
void LocalPlayer_SetInterpPosition(float t) { void LocalPlayer_SetInterpPosition(float t) {
@ -847,7 +839,7 @@ static void LocalPlayer_Tick(struct Entity* e, double delta) {
Vector3 headingVelocity; Vector3 headingVelocity;
if (!World.Blocks) return; if (!World.Blocks) return;
e->StepSize = hacks->FullBlockStep && hacks->Enabled && hacks->CanAnyHacks && hacks->CanSpeed ? 1.0f : 0.5f; e->StepSize = hacks->FullBlockStep && hacks->Enabled && hacks->CanSpeed ? 1.0f : 0.5f;
p->OldVelocity = e->Velocity; p->OldVelocity = e->Velocity;
wasOnGround = e->OnGround; wasOnGround = e->OnGround;
@ -890,7 +882,14 @@ static void LocalPlayer_RenderName(struct Entity* e) {
Player_DrawName((struct Player*)e); Player_DrawName((struct Player*)e);
} }
struct EntityVTABLE localPlayer_VTABLE = { static void LocalPlayer_CheckJumpVelocity(void* obj) {
struct LocalPlayer* p = &LocalPlayer_Instance;
if (!HacksComp_CanJumpHigher(&p->Hacks)) {
p->Physics.JumpVel = p->Physics.ServerJumpVel;
}
}
static struct EntityVTABLE localPlayer_VTABLE = {
LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetCol, LocalPlayer_Tick, Player_Despawn, LocalPlayer_SetLocation, Entity_GetCol,
LocalPlayer_RenderModel, LocalPlayer_RenderName, Player_ContextLost, Player_ContextRecreated, LocalPlayer_RenderModel, LocalPlayer_RenderName, Player_ContextLost, Player_ContextRecreated,
}; };
@ -900,6 +899,7 @@ static void LocalPlayer_Init(void) {
Player_Init(&p->Base); Player_Init(&p->Base);
Player_SetName((struct Player*)p, &Game_Username, &Game_Username); Player_SetName((struct Player*)p, &Game_Username, &Game_Username);
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, NULL, LocalPlayer_CheckJumpVelocity);
p->Collisions.Entity = &p->Base; p->Collisions.Entity = &p->Base;
HacksComp_Init(hacks); HacksComp_Init(hacks);

View File

@ -198,9 +198,6 @@ struct LocalPlayer {
extern struct LocalPlayer LocalPlayer_Instance; extern struct LocalPlayer LocalPlayer_Instance;
/* Returns how high (in blocks) the player can jump. */ /* Returns how high (in blocks) the player can jump. */
float LocalPlayer_JumpHeight(void); float LocalPlayer_JumpHeight(void);
/* Checks consistency of user's enabled hacks. */
/* (e.g. if Hacks.CanNoclip is false, Hacks.Noclip is set to false) */
void LocalPlayer_CheckHacksConsistency(void);
/* Interpolates current position and orientation between Interp.Prev and Interp.Next */ /* Interpolates current position and orientation between Interp.Prev and Interp.Next */
void LocalPlayer_SetInterpPosition(float t); void LocalPlayer_SetInterpPosition(float t);
/* Returns whether local player handles a key being pressed. */ /* Returns whether local player handles a key being pressed. */

View File

@ -157,6 +157,7 @@ void HacksComp_Init(struct HacksComp* hacks) {
HacksComp_SetAll(hacks, true); HacksComp_SetAll(hacks, true);
hacks->SpeedMultiplier = 10.0f; hacks->SpeedMultiplier = 10.0f;
hacks->Enabled = true; hacks->Enabled = true;
hacks->IsOp = true;
hacks->CanSeeAllNames = true; hacks->CanSeeAllNames = true;
hacks->CanDoubleJump = true; hacks->CanDoubleJump = true;
hacks->BaseHorSpeed = 1.0f; hacks->BaseHorSpeed = 1.0f;
@ -168,7 +169,7 @@ void HacksComp_Init(struct HacksComp* hacks) {
} }
bool HacksComp_CanJumpHigher(struct HacksComp* hacks) { bool HacksComp_CanJumpHigher(struct HacksComp* hacks) {
return hacks->Enabled && hacks->CanAnyHacks && hacks->CanSpeed; return hacks->Enabled && hacks->CanSpeed;
} }
static String HacksComp_UNSAFE_FlagValue(const char* flagRaw, struct HacksComp* hacks) { static String HacksComp_UNSAFE_FlagValue(const char* flagRaw, struct HacksComp* hacks) {
@ -230,8 +231,7 @@ static void HacksComp_ParseAllFlag(struct HacksComp* hacks, const char* incFlag,
void HacksComp_SetUserType(struct HacksComp* hacks, uint8_t value, bool setBlockPerms) { void HacksComp_SetUserType(struct HacksComp* hacks, uint8_t value, bool setBlockPerms) {
bool isOp = value >= 100 && value <= 127; bool isOp = value >= 100 && value <= 127;
hacks->UserType = value; hacks->IsOp = isOp;
hacks->CanSeeAllNames = isOp;
if (!setBlockPerms) return; if (!setBlockPerms) return;
Blocks.CanPlace[BLOCK_BEDROCK] = isOp; Blocks.CanPlace[BLOCK_BEDROCK] = isOp;
@ -242,7 +242,26 @@ void HacksComp_SetUserType(struct HacksComp* hacks, uint8_t value, bool setBlock
Blocks.CanPlace[BLOCK_STILL_LAVA] = isOp; Blocks.CanPlace[BLOCK_STILL_LAVA] = isOp;
} }
void HacksComp_CheckConsistency(struct HacksComp* hacks) { void HacksComp_RecheckFlags(struct HacksComp* hacks) {
const static String noHaxFlag = String_FromConst("-hax");
/* Can use hacks by default (also case with WoM), no need to check +hax */
bool hax = !String_ContainsString(&hacks->HacksFlags, &noHaxFlag);
HacksComp_SetAll(hacks, hax);
hacks->CanBePushed = true;
HacksComp_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly);
HacksComp_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip);
HacksComp_ParseFlag(hacks, "+speed", "-speed", &hacks->CanSpeed);
HacksComp_ParseFlag(hacks, "+respawn", "-respawn", &hacks->CanRespawn);
HacksComp_ParseFlag(hacks, "+push", "-push", &hacks->CanBePushed);
if (hacks->IsOp) HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax");
hacks->BaseHorSpeed = HacksComp_ParseFlagFloat("horspeed=", hacks);
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
HacksComp_Update(hacks);
}
void HacksComp_Update(struct HacksComp* hacks) {
if (!hacks->CanFly || !hacks->Enabled) { if (!hacks->CanFly || !hacks->Enabled) {
hacks->Flying = false; hacks->FlyingDown = false; hacks->FlyingUp = false; hacks->Flying = false; hacks->FlyingDown = false; hacks->FlyingUp = false;
} }
@ -253,40 +272,8 @@ void HacksComp_CheckConsistency(struct HacksComp* hacks) {
hacks->Speeding = false; hacks->HalfSpeeding = false; hacks->Speeding = false; hacks->HalfSpeeding = false;
} }
hacks->CanDoubleJump = hacks->CanAnyHacks && hacks->Enabled && hacks->CanSpeed; hacks->CanDoubleJump = hacks->Enabled && hacks->CanSpeed;
hacks->CanSeeAllNames = hacks->CanAnyHacks && hacks->CanSeeAllNames; hacks->CanSeeAllNames = hacks->CanAnyHacks && hacks->IsOp;
if (!hacks->CanUseThirdPersonCamera || !hacks->Enabled) {
Camera_CycleActive();
}
}
void HacksComp_UpdateState(struct HacksComp* hacks) {
const static String excHacks = String_FromConst("-hax");
HacksComp_SetAll(hacks, true);
hacks->CanBePushed = true;
if (!hacks->HacksFlags.length) return;
/* By default (this is also the case with WoM), we can use hacks */
if (String_ContainsString(&hacks->HacksFlags, &excHacks)) {
HacksComp_SetAll(hacks, false);
}
HacksComp_ParseFlag(hacks, "+fly", "-fly", &hacks->CanFly);
HacksComp_ParseFlag(hacks, "+noclip", "-noclip", &hacks->CanNoclip);
HacksComp_ParseFlag(hacks, "+speed", "-speed", &hacks->CanSpeed);
HacksComp_ParseFlag(hacks, "+respawn", "-respawn", &hacks->CanRespawn);
HacksComp_ParseFlag(hacks, "+push", "-push", &hacks->CanBePushed);
if (hacks->UserType == 0x64) {
HacksComp_ParseAllFlag(hacks, "+ophax", "-ophax");
}
hacks->BaseHorSpeed = HacksComp_ParseFlagFloat("horspeed=", hacks);
hacks->MaxJumps = HacksComp_ParseFlagInt("jumps=", hacks);
HacksComp_CheckConsistency(hacks);
Event_RaiseVoid(&UserEvents.HackPermissionsChanged); Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
} }
@ -1190,7 +1177,7 @@ static double PhysicsComp_YPosAt(int t, float u) {
return a * (-49 * u - 196) - 4 * t + 50 * u + 196; return a * (-49 * u - 196) - 4 * t + 50 * u + 196;
} }
double PhysicsComp_GetMaxHeight(float u) { double PhysicsComp_CalcMaxHeight(float u) {
/* equation below comes from solving diff(x(t, u))= 0 */ /* equation below comes from solving diff(x(t, u))= 0 */
/* We only work in discrete timesteps, so test both rounded up and down */ /* We only work in discrete timesteps, so test both rounded up and down */
double t = 49.49831645 * Math_Log(0.247483075 * u + 0.9899323); double t = 49.49831645 * Math_Log(0.247483075 * u + 0.9899323);
@ -1199,17 +1186,18 @@ double PhysicsComp_GetMaxHeight(float u) {
return max(value_floor, value_ceil); return max(value_floor, value_ceil);
} }
/* Calculates the jump velocity required such that when a client presses /* Calculates the jump velocity required such that when user presses
the jump binding they will be able to jump up to the given height. */ the jump binding they will be able to jump up to the given height. */
void PhysicsComp_CalculateJumpVelocity(struct PhysicsComp* comp, float jumpHeight) { float PhysicsComp_CalcJumpVelocity(float jumpHeight) {
comp->JumpVel = 0.0f; float jumpVel = 0.0f;
if (jumpHeight == 0.0f) return; if (jumpHeight == 0.0f) return jumpVel;
if (jumpHeight >= 256.0f) comp->JumpVel = 10.0f; if (jumpHeight >= 256.0f) jumpVel = 10.0f;
if (jumpHeight >= 512.0f) comp->JumpVel = 16.5f; if (jumpHeight >= 512.0f) jumpVel = 16.5f;
if (jumpHeight >= 768.0f) comp->JumpVel = 22.5f; if (jumpHeight >= 768.0f) jumpVel = 22.5f;
while (PhysicsComp_GetMaxHeight(comp->JumpVel) <= jumpHeight) { comp->JumpVel += 0.001f; } while (PhysicsComp_CalcMaxHeight(jumpVel) <= jumpHeight) { jumpVel += 0.001f; }
return jumpVel;
} }
void PhysicsComp_DoEntityPush(struct Entity* entity) { void PhysicsComp_DoEntityPush(struct Entity* entity) {

View File

@ -36,7 +36,7 @@ void TiltComp_GetCurrent(struct TiltComp* anim, float t);
/* Entity component that performs management of hack states */ /* Entity component that performs management of hack states */
struct HacksComp { struct HacksComp {
uint8_t UserType; bool IsOp;
/* Speed player move at, relative to normal speed, when the 'speeding' key binding is held down */ /* Speed player move at, relative to normal speed, when the 'speeding' key binding is held down */
float SpeedMultiplier; float SpeedMultiplier;
/* Whether blocks that the player places that intersect themselves, should cause the player to /* Whether blocks that the player places that intersect themselves, should cause the player to
@ -44,7 +44,7 @@ struct HacksComp {
bool PushbackPlacing; bool PushbackPlacing;
/* Whether the player should be able to step up whole blocks, instead of just slabs */ /* Whether the player should be able to step up whole blocks, instead of just slabs */
bool FullBlockStep; bool FullBlockStep;
/* Whether the player has allowed hacks usage as an option. Note 'can use X' set by the server override this */ /* Whether user has allowed hacks as an option. Note 'can use X' set by the server override this */
bool Enabled; bool Enabled;
bool CanAnyHacks, CanUseThirdPersonCamera, CanSpeed, CanFly; bool CanAnyHacks, CanUseThirdPersonCamera, CanSpeed, CanFly;
@ -68,8 +68,12 @@ struct HacksComp {
void HacksComp_Init(struct HacksComp* hacks); void HacksComp_Init(struct HacksComp* hacks);
bool HacksComp_CanJumpHigher(struct HacksComp* hacks); bool HacksComp_CanJumpHigher(struct HacksComp* hacks);
void HacksComp_SetUserType(struct HacksComp* hacks, uint8_t value, bool setBlockPerms); void HacksComp_SetUserType(struct HacksComp* hacks, uint8_t value, bool setBlockPerms);
void HacksComp_CheckConsistency(struct HacksComp* hacks); /* Determines hacks permissions based on flags, then calls HacksComp_Update */
void HacksComp_UpdateState(struct HacksComp* hacks); /* e.g. +ophax allows all hacks if op, -push disables entity pushing */
void HacksComp_RecheckFlags(struct HacksComp* hacks);
/* Updates state based on permissions (e.g. Flying set to false if CanFly is false) */
/* Raises UserEvents.HackPermissionsChanged */
void HacksComp_Update(struct HacksComp* hacks);
/* Represents a position and orientation state */ /* Represents a position and orientation state */
struct InterpState { Vector3 Pos; float HeadX, HeadY, RotX, RotZ; }; struct InterpState { Vector3 Pos; float HeadX, HeadY, RotX, RotZ; };
@ -127,8 +131,8 @@ void PhysicsComp_Init(struct PhysicsComp* comp, struct Entity* entity);
void PhysicsComp_UpdateVelocityState(struct PhysicsComp* comp); void PhysicsComp_UpdateVelocityState(struct PhysicsComp* comp);
void PhysicsComp_DoNormalJump(struct PhysicsComp* comp); void PhysicsComp_DoNormalJump(struct PhysicsComp* comp);
void PhysicsComp_PhysicsTick(struct PhysicsComp* comp, Vector3 vel); void PhysicsComp_PhysicsTick(struct PhysicsComp* comp, Vector3 vel);
void PhysicsComp_CalculateJumpVelocity(struct PhysicsComp* comp, float jumpHeight); float PhysicsComp_CalcJumpVelocity(float jumpHeight);
double PhysicsComp_GetMaxHeight(float u); double PhysicsComp_CalcMaxHeight(float u);
void PhysicsComp_DoEntityPush(struct Entity* entity); void PhysicsComp_DoEntityPush(struct Entity* entity);
/* Entity component that plays block step sounds */ /* Entity component that plays block step sounds */

View File

@ -163,10 +163,14 @@ void Game_UserSetViewDistance(int distance) {
Game_SetViewDistance(distance); Game_SetViewDistance(distance);
} }
void Game_UpdateProjection(void) { void Game_SetFov(int fov) {
Game_DefaultFov = Options_GetInt(OPT_FIELD_OF_VIEW, 1, 179, 70); if (Game_Fov == fov) return;
Camera.Active->GetProjection(&Gfx.Projection); Game_Fov = fov;
Game_UpdateProjection();
}
void Game_UpdateProjection(void) {
Camera.Active->GetProjection(&Gfx.Projection);
Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection); Gfx_LoadMatrix(MATRIX_PROJECTION, &Gfx.Projection);
Event_RaiseVoid(&GfxEvents.ProjectionChanged); Event_RaiseVoid(&GfxEvents.ProjectionChanged);
} }
@ -640,7 +644,7 @@ static void Game_RenderFrame(double delta) {
allowZoom = !Gui_Active && !Gui_HUD->HandlesAllInput; allowZoom = !Gui_Active && !Gui_HUD->HandlesAllInput;
if (allowZoom && KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) { if (allowZoom && KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) {
InputHandler_SetFOV(Game_ZoomFov, false); InputHandler_SetFOV(Game_ZoomFov);
} }
Game_DoScheduledTasks(delta); Game_DoScheduledTasks(delta);

View File

@ -66,6 +66,7 @@ void Game_SetDefaultTexturePack(const String* texPack);
bool Game_ChangeTerrainAtlas(Bitmap* atlas); bool Game_ChangeTerrainAtlas(Bitmap* atlas);
void Game_SetViewDistance(int distance); void Game_SetViewDistance(int distance);
void Game_UserSetViewDistance(int distance); void Game_UserSetViewDistance(int distance);
void Game_SetFov(int fov);
void Game_UpdateProjection(void); void Game_UpdateProjection(void);
void Game_Disconnect(const String* title, const String* reason); void Game_Disconnect(const String* title, const String* reason);
void Game_Reset(void); void Game_Reset(void);

View File

@ -195,7 +195,7 @@ void Gui_SetActive(struct Screen* screen) {
} }
void Gui_RefreshHud(void) { Elem_Recreate(Gui_HUD); } void Gui_RefreshHud(void) { Elem_Recreate(Gui_HUD); }
void Gui_ShowOverlay(struct Screen* overlay, bool atFront) { void Gui_ShowOverlay(struct Screen* screen, bool atFront) {
int i; int i;
if (Gui_OverlaysCount == GUI_MAX_OVERLAYS) { if (Gui_OverlaysCount == GUI_MAX_OVERLAYS) {
Logger_Abort("Gui_ShowOverlay - hit max count"); Logger_Abort("Gui_ShowOverlay - hit max count");
@ -206,13 +206,13 @@ void Gui_ShowOverlay(struct Screen* overlay, bool atFront) {
for (i = Gui_OverlaysCount - 1; i > 0; i--) { for (i = Gui_OverlaysCount - 1; i > 0; i--) {
Gui_Overlays[i] = Gui_Overlays[i - 1]; Gui_Overlays[i] = Gui_Overlays[i - 1];
} }
Gui_Overlays[0] = overlay; Gui_Overlays[0] = screen;
} else { } else {
Gui_Overlays[Gui_OverlaysCount] = overlay; Gui_Overlays[Gui_OverlaysCount] = screen;
} }
Gui_OverlaysCount++; Gui_OverlaysCount++;
Elem_Init(overlay); Elem_Init(screen);
Camera_CheckFocus(); Camera_CheckFocus();
} }
@ -226,7 +226,7 @@ int Gui_IndexOverlay(const void* screen) {
return -1; return -1;
} }
void Gui_RemoveOverlay(void* screen) { void Gui_RemoveOverlay(const void* screen) {
struct Screen* s = screen; struct Screen* s = screen;
int i = Gui_IndexOverlay(screen); int i = Gui_IndexOverlay(screen);
if (i == -1) return; if (i == -1) return;

View File

@ -126,7 +126,7 @@ CC_NOINLINE void Gui_CloseActive(void);
CC_NOINLINE void Gui_Close(void* screen); CC_NOINLINE void Gui_Close(void* screen);
void Gui_RefreshHud(void); void Gui_RefreshHud(void);
void Gui_ShowOverlay(struct Screen* overlay, bool atFront); void Gui_ShowOverlay(struct Screen* screen, bool atFront);
/* Returns index of the given screen in the overlays list, -1 if not */ /* Returns index of the given screen in the overlays list, -1 if not */
int Gui_IndexOverlay(const void* screen); int Gui_IndexOverlay(const void* screen);
/* Removes given screen from the overlays list */ /* Removes given screen from the overlays list */

View File

@ -115,16 +115,12 @@ static void InputHandler_CycleDistanceBackwards(const short* viewDists, int coun
Game_UserSetViewDistance(viewDists[count - 1]); Game_UserSetViewDistance(viewDists[count - 1]);
} }
bool InputHandler_SetFOV(int fov, bool setZoom) { bool InputHandler_SetFOV(int fov) {
struct HacksComp* h; struct HacksComp* h = &LocalPlayer_Instance.Hacks;
if (Game_Fov == fov) return true; if (!h->Enabled || !h->CanUseThirdPersonCamera) return false;
h = &LocalPlayer_Instance.Hacks; Game_ZoomFov = fov;
if (!h->Enabled || !h->CanAnyHacks || !h->CanUseThirdPersonCamera) return false; Game_SetFov(fov);
Game_Fov = fov;
if (setZoom) Game_ZoomFov = fov;
Game_UpdateProjection();
return true; return true;
} }
@ -133,13 +129,18 @@ static bool InputHandler_DoFovZoom(float deltaPrecise) {
if (!KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) return false; if (!KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) return false;
h = &LocalPlayer_Instance.Hacks; h = &LocalPlayer_Instance.Hacks;
if (!h->Enabled || !h->CanAnyHacks || !h->CanUseThirdPersonCamera) return false; if (!h->Enabled || !h->CanUseThirdPersonCamera) return false;
if (input_fovIndex == -1.0f) input_fovIndex = (float)Game_ZoomFov; if (input_fovIndex == -1.0f) input_fovIndex = (float)Game_ZoomFov;
input_fovIndex -= deltaPrecise * 5.0f; input_fovIndex -= deltaPrecise * 5.0f;
Math_Clamp(input_fovIndex, 1.0f, Game_DefaultFov); Math_Clamp(input_fovIndex, 1.0f, Game_DefaultFov);
return InputHandler_SetFOV((int)input_fovIndex, true); return InputHandler_SetFOV((int)input_fovIndex);
}
static void InputHandler_CheckZoomFov(void* obj) {
struct HacksComp* h = &LocalPlayer_Instance.Hacks;
if (!h->Enabled || !h->CanUseThirdPersonCamera) Game_SetFov(Game_DefaultFov);
} }
static bool InputHandler_HandleNonClassicKey(Key key) { static bool InputHandler_HandleNonClassicKey(Key key) {
@ -494,7 +495,7 @@ static void InputHandler_KeyUp(void* obj, int key) {
if (InputHandler_SimulateMouse(key, false)) return; if (InputHandler_SimulateMouse(key, false)) return;
if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) { if (key == KeyBinds[KEYBIND_ZOOM_SCROLL]) {
InputHandler_SetFOV(Game_DefaultFov, false); Game_SetFov(Game_DefaultFov);
} }
active = Gui_GetActiveScreen(); active = Gui_GetActiveScreen();
@ -515,6 +516,7 @@ void InputHandler_Init(void) {
Event_RegisterInt(&KeyEvents.Up, NULL, InputHandler_KeyUp); Event_RegisterInt(&KeyEvents.Up, NULL, InputHandler_KeyUp);
Event_RegisterInt(&KeyEvents.Press, NULL, InputHandler_KeyPress); Event_RegisterInt(&KeyEvents.Press, NULL, InputHandler_KeyPress);
Event_RegisterVoid(&UserEvents.HackPermissionsChanged, NULL, InputHandler_CheckZoomFov);
KeyBind_Init(); KeyBind_Init();
Hotkeys_Init(); Hotkeys_Init();
} }

View File

@ -7,7 +7,7 @@
struct Screen; struct Screen;
bool InputHandler_IsMousePressed(MouseButton button); bool InputHandler_IsMousePressed(MouseButton button);
bool InputHandler_SetFOV(int fov, bool setZoom); bool InputHandler_SetFOV(int fov);
void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right); void InputHandler_PickBlocks(bool cooldown, bool left, bool middle, bool right);
void InputHandler_Init(void); void InputHandler_Init(void);
void InputHandler_ScreenChanged(struct Screen* oldScreen, struct Screen* newScreen); void InputHandler_ScreenChanged(struct Screen* oldScreen, struct Screen* newScreen);

View File

@ -2231,7 +2231,7 @@ static void ClassicOptionsScreen_SetViewBob(const String* v) { Game_ViewBobbing
static void ClassicOptionsScreen_GetHacks(String* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); } static void ClassicOptionsScreen_GetHacks(String* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); }
static void ClassicOptionsScreen_SetHacks(const String* v) { static void ClassicOptionsScreen_SetHacks(const String* v) {
LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v, OPT_HACKS_ENABLED); LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v, OPT_HACKS_ENABLED);
LocalPlayer_CheckHacksConsistency(); HacksComp_Update(&LocalPlayer_Instance.Hacks);
} }
static void ClassicOptionsScreen_ContextRecreated(void* screen) { static void ClassicOptionsScreen_ContextRecreated(void* screen) {
@ -2602,7 +2602,7 @@ struct Screen* GuiOptionsScreen_MakeInstance(void) {
static void HacksSettingsScreen_GetHacks(String* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); } static void HacksSettingsScreen_GetHacks(String* v) { Menu_GetBool(v, LocalPlayer_Instance.Hacks.Enabled); }
static void HacksSettingsScreen_SetHacks(const String* v) { static void HacksSettingsScreen_SetHacks(const String* v) {
LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v,OPT_HACKS_ENABLED); LocalPlayer_Instance.Hacks.Enabled = Menu_SetBool(v,OPT_HACKS_ENABLED);
LocalPlayer_CheckHacksConsistency(); HacksComp_Update(&LocalPlayer_Instance.Hacks);
} }
static void HacksSettingsScreen_GetSpeed(String* v) { String_AppendFloat(v, LocalPlayer_Instance.Hacks.SpeedMultiplier, 2); } static void HacksSettingsScreen_GetSpeed(String* v) { String_AppendFloat(v, LocalPlayer_Instance.Hacks.SpeedMultiplier, 2); }
@ -2622,7 +2622,7 @@ static void HacksSettingsScreen_SetJump(const String* v) {
struct PhysicsComp* physics; struct PhysicsComp* physics;
physics = &LocalPlayer_Instance.Physics; physics = &LocalPlayer_Instance.Physics;
PhysicsComp_CalculateJumpVelocity(physics, Menu_Float(v)); physics->JumpVel = PhysicsComp_CalcJumpVelocity(Menu_Float(v));
physics->UserJumpVel = physics->JumpVel; physics->UserJumpVel = physics->JumpVel;
String_InitArray(str, strBuffer); String_InitArray(str, strBuffer);
@ -2657,18 +2657,19 @@ static void HacksSettingsScreen_SetSlide(const String* v) {
static void HacksSettingsScreen_GetFOV(String* v) { String_AppendInt(v, Game_Fov); } static void HacksSettingsScreen_GetFOV(String* v) { String_AppendInt(v, Game_Fov); }
static void HacksSettingsScreen_SetFOV(const String* v) { static void HacksSettingsScreen_SetFOV(const String* v) {
Game_Fov = Menu_Int(v); int fov = Menu_Int(v);
if (Game_ZoomFov > Game_Fov) Game_ZoomFov = Game_Fov; if (Game_ZoomFov > fov) Game_ZoomFov = fov;
Game_DefaultFov = fov;
Options_Set(OPT_FIELD_OF_VIEW, v); Options_Set(OPT_FIELD_OF_VIEW, v);
Game_UpdateProjection(); Game_SetFov(fov);
} }
static void HacksSettingsScreen_CheckHacksAllowed(void* screen) { static void HacksSettingsScreen_CheckHacksAllowed(void* screen) {
struct MenuOptionsScreen* s = screen; struct MenuOptionsScreen* s = screen;
struct Widget** widgets = s->Widgets; struct Widget** widgets = s->Widgets;
struct LocalPlayer* p; struct LocalPlayer* p;
bool noGlobalHacks; bool disabled;
int i; int i;
for (i = 0; i < s->WidgetsCount; i++) { for (i = 0; i < s->WidgetsCount; i++) {
@ -2677,11 +2678,11 @@ static void HacksSettingsScreen_CheckHacksAllowed(void* screen) {
} }
p = &LocalPlayer_Instance; p = &LocalPlayer_Instance;
noGlobalHacks = !p->Hacks.CanAnyHacks || !p->Hacks.Enabled; disabled = !p->Hacks.Enabled;
widgets[3]->Disabled = noGlobalHacks || !p->Hacks.CanSpeed; widgets[3]->Disabled = disabled || !p->Hacks.CanSpeed;
widgets[4]->Disabled = noGlobalHacks || !p->Hacks.CanSpeed; widgets[4]->Disabled = disabled || !p->Hacks.CanSpeed;
widgets[5]->Disabled = noGlobalHacks || !p->Hacks.CanSpeed; widgets[5]->Disabled = disabled || !p->Hacks.CanSpeed;
widgets[7]->Disabled = noGlobalHacks || !p->Hacks.CanPushbackBlocks; widgets[7]->Disabled = disabled || !p->Hacks.CanPushbackBlocks;
} }
static void HacksSettingsScreen_ContextLost(void* screen) { static void HacksSettingsScreen_ContextLost(void* screen) {

View File

@ -15,7 +15,6 @@ extern const char* FpsLimit_Names[FPS_LIMIT_COUNT];
#define OPT_MUSIC_VOLUME "musicvolume" #define OPT_MUSIC_VOLUME "musicvolume"
#define OPT_SOUND_VOLUME "soundsvolume" #define OPT_SOUND_VOLUME "soundsvolume"
#define OPT_FORCE_OPENAL "forceopenal" #define OPT_FORCE_OPENAL "forceopenal"
#define OPT_FORCE_OLD_OPENGL "force-oldgl"
#define OPT_VIEW_DISTANCE "viewdist" #define OPT_VIEW_DISTANCE "viewdist"
#define OPT_BLOCK_PHYSICS "singleplayerphysics" #define OPT_BLOCK_PHYSICS "singleplayerphysics"

View File

@ -380,7 +380,7 @@ static void Classic_Handshake(uint8_t* data) {
String_Copy(&hacks->HacksFlags, &Server.Name); String_Copy(&hacks->HacksFlags, &Server.Name);
String_AppendString(&hacks->HacksFlags, &Server.MOTD); String_AppendString(&hacks->HacksFlags, &Server.MOTD);
HacksComp_UpdateState(hacks); HacksComp_RecheckFlags(hacks);
} }
static void Classic_Ping(uint8_t* data) { } static void Classic_Ping(uint8_t* data) { }
@ -647,7 +647,7 @@ static void Classic_Kick(uint8_t* data) {
static void Classic_SetPermission(uint8_t* data) { static void Classic_SetPermission(uint8_t* data) {
struct HacksComp* hacks = &LocalPlayer_Instance.Hacks; struct HacksComp* hacks = &LocalPlayer_Instance.Hacks;
HacksComp_SetUserType(hacks, *data, !cpe_blockPerms); HacksComp_SetUserType(hacks, *data, !cpe_blockPerms);
HacksComp_UpdateState(hacks); HacksComp_RecheckFlags(hacks);
} }
static void Classic_ReadAbsoluteLocation(uint8_t* data, EntityID id, bool interpolate) { static void Classic_ReadAbsoluteLocation(uint8_t* data, EntityID id, bool interpolate) {
@ -1130,18 +1130,17 @@ static void CPE_HackControl(uint8_t* data) {
p->Hacks.CanSpeed = *data++ != 0; p->Hacks.CanSpeed = *data++ != 0;
p->Hacks.CanRespawn = *data++ != 0; p->Hacks.CanRespawn = *data++ != 0;
p->Hacks.CanUseThirdPersonCamera = *data++ != 0; p->Hacks.CanUseThirdPersonCamera = *data++ != 0;
LocalPlayer_CheckHacksConsistency(); HacksComp_Update(&p->Hacks);
jumpHeight = Stream_GetU16_BE(data); jumpHeight = Stream_GetU16_BE(data);
physics = &p->Physics; physics = &p->Physics;
if (jumpHeight == UInt16_MaxValue) { /* special value of -1 to reset default */ if (jumpHeight == UInt16_MaxValue) { /* special value of -1 to reset default */
physics->JumpVel = HacksComp_CanJumpHigher(&p->Hacks) ? physics->UserJumpVel : 0.42f; physics->JumpVel = HacksComp_CanJumpHigher(&p->Hacks) ? physics->UserJumpVel : 0.42f;
} else { } else {
PhysicsComp_CalculateJumpVelocity(physics, jumpHeight / 32.0f); physics->JumpVel = PhysicsComp_CalcJumpVelocity(jumpHeight / 32.0f);
} }
physics->ServerJumpVel = physics->JumpVel; physics->ServerJumpVel = physics->JumpVel;
Event_RaiseVoid(&UserEvents.HackPermissionsChanged);
} }
static void CPE_ExtAddEntity2(uint8_t* data) { static void CPE_ExtAddEntity2(uint8_t* data) {