Skip to content

Commit

Permalink
Merge pull request #32 from fyryNy/master
Browse files Browse the repository at this point in the history
Bunch of new stuff and fixes
  • Loading branch information
Franisz authored Apr 11, 2024
2 parents a2fa449 + 16b215c commit 17f0578
Show file tree
Hide file tree
Showing 16 changed files with 398 additions and 196 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ This is a plugin with a set of many quality-of-life and utility features made fo

- Insert all items into inventory with `zutilities giveallitems` command.

- Check currently used plugin version through in game console with `zutilities version` command.
- Check currently used plugin version through in game console with `zutilities version` command.

- Reminds the player to save the game by displaying an icon with a timer after playing without saving the game for too long.
- By default, it reminds the player after 5 minutes since the last save game. It can be changed in `gothic.ini` with `SaveReminder` option.
- It can be turned off by setting `SaveReminder` to `-1`

### Options

Expand Down Expand Up @@ -175,6 +179,10 @@ KeyTimeMultiplier=KEY_Z
TimeMultipliers=1.0|2.5
; ... defines time multipliers

SaveReminder=5
; ... Time in minutes after which the reminder to save the game appears on the screen
; ... set to -1 to disable

RecoveryVisualization=1
; ... enables (1) or disables (0) visualization of healing that hovered in the inventory item gives

Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions zUtilities/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ namespace GOTHIC_ENGINE {
return true;
}

if (w2 == "ShowTriggers") {
Options::ShowTriggers = !Options::ShowTriggers;
zSTRING state = (Options::ShowTriggers) ? "ON" : "OFF";
msg = "zUtilities showing triggers " + state;
return true;
}

return false;
}

Expand All @@ -93,5 +100,6 @@ namespace GOTHIC_ENGINE {
zcon->Register( "zUtilities Version", "Shows version number" );
zcon->Register( "zUtilities Debug", "Toggles debug mode" );
zcon->Register( "zUtilities GiveAllItems", "Gives all items" );
zcon->Register( "zUtilities ShowTriggers", "Toggles the display of invisible triggers in debug mode" );
}
}
2 changes: 1 addition & 1 deletion zUtilities/Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace GOTHIC_ENGINE {
#define PLUGIN_NAME "ZUTILITIES"
#define VERSION_NUMBER "0.36"
#define VERSION_NUMBER "0.37"
#define printWin(a) ogame->GetTextView()->Printwin(a)
#define del(x) { delete x; x = nullptr; }
}
398 changes: 230 additions & 168 deletions zUtilities/DebugHelper.cpp

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions zUtilities/DebugHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@
namespace GOTHIC_ENGINE {
namespace Options {
bool UsingDebugHelper = false;
bool ShowTriggers = false;
}

class DebugHelper {
private:
zCView* mainView;
zCView* textView;
zCView* sideView;
zCView* leftView;
zCView* rightView;

int textLines;
int textLinesLeft;
int textLinesRight;
int textHeight;
int margin;

void InfoNpc( oCNpc* npc );
void InfoItem( oCItem* item );
void InfoMob( oCMOB* mob );
void AddSeparator( zSTRING str = "" );
void AddSeparator( zCView* view, zSTRING str = "" );
void Print( zCView* view, zSTRING name, zSTRING value );
bool TryPrintInfo();
void ShowTriggerBoxes();

public:
void Clear();
Expand Down
20 changes: 8 additions & 12 deletions zUtilities/FocusColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,17 @@ namespace GOTHIC_ENGINE {
}

zSTRING FocusColor::GetName( zCVob* vob ) {
if ( Options::ColorLockables )
if ( oCMobLockable* lockable = vob->CastTo<oCMobLockable>() )
return lockable->GetName();
if ( oCMobLockable* lockable = vob->CastTo<oCMobLockable>() )
return lockable->GetName();

if ( Options::ColorNpcs )
if ( oCNpc* npc = vob->CastTo<oCNpc>() )
return npc->name[0];
if ( oCNpc* npc = vob->CastTo<oCNpc>() )
return npc->name[0];

if ( Options::ColorItems )
if ( oCItem* item = vob->CastTo<oCItem>() )
return item->name;
if ( oCItem* item = vob->CastTo<oCItem>() )
return item->name;

if ( Options::ColorInter )
if ( oCMobInter* inter = vob->CastTo<oCMobInter>() )
return inter->GetName();
if ( oCMobInter* inter = vob->CastTo<oCMobInter>() )
return inter->GetName();

return "";
}
Expand Down
1 change: 1 addition & 0 deletions zUtilities/Headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Add your headers this

// Automatically generated block
#include <chrono>
#pragma region Includes
#include "Const.h"
#include "Colors.h"
Expand Down
7 changes: 7 additions & 0 deletions zUtilities/IconInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace GOTHIC_ENGINE {
if ( quickSave->IsBusy() || !ogame->GetShowPlayerStatus() || !ogame->game_drawall || ogame->IsOnPause() || playerHelper.IsInInfo() || player->attribute[NPC_ATR_HITPOINTS] <= 0 )
return;

RestoreViewport(); //because some plugins don't restore viewport after Blitting, so it messes with prints in other plugins
DrawIcon();
PrintText();
}
Expand Down Expand Up @@ -41,6 +42,12 @@ namespace GOTHIC_ENGINE {
delete view;
}

void IconInfo::RestoreViewport() {
int ScreenX, ScreenY, ScreenSX, ScreenSY;
screen->GetViewport(ScreenX, ScreenY, ScreenSX, ScreenSY);
zrenderer->SetViewport(ScreenX, ScreenY, ScreenSX, ScreenSY);
}

IconInfo::IconInfo( int x, int y, int size, zCOLOR color, zSTRING texName, zSTRING text = "" )
: vx( x ), vy( y ), vsize( size ), color( color ), texName( texName ), text( text ) {
Draw();
Expand Down
1 change: 1 addition & 0 deletions zUtilities/IconInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace GOTHIC_ENGINE {
void Draw();
void DrawIcon();
void PrintText();
void RestoreViewport();

public:
IconInfo( int x, int y, int size, zCOLOR color, zSTRING texName, zSTRING text );
Expand Down
16 changes: 16 additions & 0 deletions zUtilities/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ namespace GOTHIC_ENGINE {
string archivePath = string::Combine( "%s\\%s\\%s\.sav", savesDir, slotDir, sav );
return archivePath;
}

zSTRING GetAttributeName( int att ) {
switch ( att )
{
case NPC_ATR_HITPOINTSMAX:
return "HP";
case NPC_ATR_MANAMAX:
return "MANA";
case NPC_ATR_STRENGTH:
return "STR";
case NPC_ATR_DEXTERITY:
return "DEX";
default:
return "<Unknown>";
}
}
}
2 changes: 2 additions & 0 deletions zUtilities/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace GOTHIC_ENGINE {
zoptions->AddTrivia( PLUGIN_NAME, "ActivateUsedMunition", "... enables (1) or disables (0) highlighting currently used ranged weapon munition in the inventory" );
zoptions->AddTrivia( PLUGIN_NAME, "AlternativeDialogueBoxes", "... enables (1) or disables (0) alternative dialogue boxes style" );
zoptions->AddTrivia( PLUGIN_NAME, "SelectedDialogueColor", "... defines color of selected line in dialogues" + nline + "... use 'R|G|B' or 'R|G|B|A' format" + nline + "... leave empty to use default color" );

zoptions->AddTrivia( PLUGIN_NAME, "SaveReminder", "... Time in minutes after which the reminder to save the game appears on the screen" + nline + "... set to -1 to disable");
}
}
}
105 changes: 95 additions & 10 deletions zUtilities/PlayerStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,50 @@
// Union SOURCE file

namespace GOTHIC_ENGINE {
#if ENGINE >= Engine_G2
std::vector<oCVisualFX*> vfxs;
HOOK Ivk_InitEffect_Union PATCH( &oCVisualFX::InitEffect, &oCVisualFX::InitEffect_Union );
void oCVisualFX::InitEffect_Union() {

if ( visName_S.Search( ".SLW", 1 ) == -1 )
{
THISCALL( Ivk_InitEffect_Union )();
return;
}

vfxs.push_back( this );
playerStatus.ResetTimeMultiplier();

THISCALL( Ivk_InitEffect_Union )();
}

HOOK Ivk_EndEffect_Union PATCH(&oCVisualFX::EndEffect, &oCVisualFX::EndEffect_Union);
void oCVisualFX::EndEffect_Union( const int kill ) {
if ( visName_S.Search( ".SLW", 1 ) == -1 )
{
THISCALL( Ivk_EndEffect_Union )( kill );
return;
}

auto it = std::find( vfxs.begin(), vfxs.end(), this );
if (it != vfxs.end())
{
vfxs.erase( std::remove( vfxs.begin(), vfxs.end(), this ), vfxs.end() );
}

THISCALL( Ivk_EndEffect_Union )( kill );
}
#endif

bool PlayerStatus::CanChangeZtimer()
{
#if ENGINE >= Engine_G2
return vfxs.empty();
#endif
return true;
}


HOOK Ivk_CallOnStateFunc_Union PATCH( &oCMobInter::CallOnStateFunc, &oCMobInter::CallOnStateFunc_Union );
void oCMobInter::CallOnStateFunc_Union( oCNpc* npc, int a1 ) {
THISCALL( Ivk_CallOnStateFunc_Union )(npc, a1);
Expand Down Expand Up @@ -36,17 +80,15 @@ namespace GOTHIC_ENGINE {
list = list->next;

// Whenever the icon will visible or not is based on the npc dialogue including PICKPOCKET word which seems to be used consistently in mods as well.
if ( !info->name.HasWord( "PICKPOCKET" ) )
if ( !info->name.HasWordI( "pickpocket" ) && !info->name.HasWordI( "_steal" ) && !info->name.HasWordI( "pickme" ) )
continue;

if ( info->name.HasWordI( "_DOIT" ) || info->name.HasWordI( "_TRY" ) )
continue;

// To avoid targeting possible dialogues related to pickpocketing quests or teach options.
int idx = parser->GetIndex( info->name + "_DOIT" );
if ( idx == Invalid ) {
// Alternative pickpocket instance name
idx = parser->GetIndex( info->name + "_TRY" );
if ( idx == Invalid )
continue;
}
if ( parser->GetIndex( info->name + "_DOIT" ) == Invalid && parser->GetIndex( info->name + "_TRY" ) == Invalid )
continue;

if ( !pickpocketInfos.IsInList( info ) )
pickpocketInfos.Insert( info );
Expand Down Expand Up @@ -163,7 +205,7 @@ namespace GOTHIC_ENGINE {
#if ENGINE < Engine_G2
HOOK Hook_zCAICamera_CheckKeys PATCH( &zCAICamera::CheckKeys, &zCAICamera::CheckKeys_Union );
void zCAICamera::CheckKeys_Union() {
if ( !Options::UseTimeMultiplier || ztimer->factorMotion == 1.0f ) {
if ( !Options::UseTimeMultiplier || ztimer->factorMotion == 1.0f || !playerStatus.CanChangeZtimer() ) {
THISCALL( Hook_zCAICamera_CheckKeys )();
return;
}
Expand All @@ -179,7 +221,7 @@ namespace GOTHIC_ENGINE {

HOOK Hook_oCAIHuman_PC_Turnings PATCH( &oCAIHuman::PC_Turnings, &oCAIHuman::PC_Turnings_Union );
void oCAIHuman::PC_Turnings_Union( int forceRotation ) {
if ( !Options::UseTimeMultiplier || ztimer->factorMotion == 1.0f || Pressed( GAME_LEFT ) || Pressed( GAME_RIGHT ) ) {
if ( !Options::UseTimeMultiplier || ztimer->factorMotion == 1.0f || Pressed( GAME_LEFT ) || Pressed( GAME_RIGHT ) || !playerStatus.CanChangeZtimer() ) {
THISCALL( Hook_oCAIHuman_PC_Turnings )(forceRotation);
return;
}
Expand All @@ -201,13 +243,25 @@ namespace GOTHIC_ENGINE {
ztimer->factorMotion = 1.0f;
}

void PlayerStatus::ResetSaveReminder() {
if (SaveLoadGameInfo.changeLevel)
{
return;
}

lastSaveTime = std::chrono::high_resolution_clock::now();
}

void PlayerStatus::FactorMotion() {
if ( !Options::UseTimeMultiplier )
return;

if ( !Options::TimeMultipliers.GetNum() || playerHelper.IsConUp() )
return;

if ( !CanChangeZtimer() )
return;

if ( playerHelper.IsDead() || playerHelper.IsInInfo() || ogame->IsOnPause() ) {
if ( ztimer->factorMotion != 1.0f )
ztimer->factorMotion = 1.0f;
Expand Down Expand Up @@ -299,6 +353,36 @@ namespace GOTHIC_ENGINE {
IconInfo icon = IconInfo( screen->FontY(), screen->FontY() * 2.5 * infoIcons, screen->FontY() * 0.9f, color, texture, Z amount );
}

void PlayerStatus::ShowSaveReminder() {
if (
Options::SaveReminder == Invalid
|| !ogame
|| !player
|| playerHelper.IsBusy()
|| quickSave->IsBusy()
|| playerHelper.IsDead()
|| playerHelper.IsConUp()
|| !ogame->GetShowPlayerStatus()
|| !ogame->game_drawall
)
{
return;
}

auto ElapsedTime = std::chrono::high_resolution_clock::now() - lastSaveTime;
auto ElapsedMins = std::chrono::duration_cast<std::chrono::minutes>(ElapsedTime);
auto ElapsedSeconds = std::chrono::duration_cast<std::chrono::seconds>(ElapsedTime - ElapsedMins);
if ( ElapsedTime >= static_cast<std::chrono::minutes>( Options::SaveReminder ) )
{
zSTRING str = ( ElapsedMins.count() < 10 ? "0" : "" ) + Z ElapsedMins.count() + ":" + ( ElapsedSeconds.count() < 10 ? "0" : "" ) + Z static_cast<int>( ElapsedSeconds.count() );

zSTRING texture = "ICON_SAVE"; // https://game-icons.net/1x1/lorc/disc.html

infoIcons++;
IconInfo icon = IconInfo(screen->FontY(), screen->FontY() * 2.5 * infoIcons, screen->FontY() * 0.9f, GFX_RED, texture, str);
}
}

void PlayerStatus::StatusBars() {
if ( !hpBar )
hpBar = new StatusBar( ogame->hpBar );
Expand Down Expand Up @@ -352,6 +436,7 @@ namespace GOTHIC_ENGINE {
FactorMotion();
ShowGameTime();
ShowMunitionAmount();
ShowSaveReminder();
HandleMunitionLoop();
RenderSelectedItem();
}
Expand Down
7 changes: 7 additions & 0 deletions zUtilities/PlayerStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace GOTHIC_ENGINE {
bool ShowGameTime, ShowMunitionAmount, ShowTargetProtection, ShowPickpocketIcon, UseTimeMultiplier;
int KeyTimeMultiplier;
Array<float> TimeMultipliers;
int SaveReminder;

void PlayerStatus() {
ShowGameTime = zoptions->ReadBool( PLUGIN_NAME, "ShowGameTime", false );
Expand All @@ -22,6 +23,8 @@ namespace GOTHIC_ENGINE {
TimeMultipliers.Clear();
for ( int i = 0; i < MulStrings.GetNum(); i++ )
TimeMultipliers.Insert( MulStrings[i].Shrink().ToReal32() );

SaveReminder = zoptions->ReadInt(PLUGIN_NAME, "SaveReminder", 5);
}
}

Expand All @@ -32,9 +35,11 @@ namespace GOTHIC_ENGINE {
StatusBar* swimBar;
int multiplierIndex = 0;
int infoIcons = 0;
std::chrono::high_resolution_clock::time_point lastSaveTime;

void ShowGameTime();
void ShowMunitionAmount();
void ShowSaveReminder();
void StatusBars();
void FactorMotion();

Expand All @@ -47,9 +52,11 @@ namespace GOTHIC_ENGINE {
StatusBar* focusBar;
bool CanPickpocketNpc( oCNpc* npc );
void GetPickpocketInfos();
bool CanChangeZtimer();
bool KnowStateFunc( zCVob* vob );
void TryAddStateFunc( zCVob* vob );
void ResetTimeMultiplier();
void ResetSaveReminder();
void Clear();
void Loop();
void Archive( zCArchiver* ar );
Expand Down
Loading

0 comments on commit 17f0578

Please sign in to comment.