Skip to content

Commit

Permalink
Implements IsMultiplayerOnly for ViniferaCommandClass.
Browse files Browse the repository at this point in the history
  • Loading branch information
CCHyper committed May 10, 2022
1 parent 68c2bde commit 249c2d7
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/extensions/command/commandext.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,24 @@ class HouseClass;
class ViniferaCommandClass : public CommandClass
{
public:
ViniferaCommandClass() : CommandClass(), IsDeveloper(false) {}
ViniferaCommandClass() : CommandClass(), IsDeveloper(false), IsMultiplayerOnly(false) {}
virtual ~ViniferaCommandClass() {}

virtual KeyNumType Default_Key() const = 0;

bool Developer_Only() const { return IsDeveloper; }
bool Multiplayer_Only() const { return IsMultiplayerOnly; }

public:
/**
* Is this command only available in developer mode?
*/
bool IsDeveloper;

/**
* Is this command only available in multiplayer games?
*/
bool IsMultiplayerOnly;
};


Expand All @@ -60,7 +68,7 @@ class ViniferaCommandClass : public CommandClass
class PNGScreenCaptureCommandClass : public ViniferaCommandClass
{
public:
PNGScreenCaptureCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
PNGScreenCaptureCommandClass() : ViniferaCommandClass() {}
virtual ~PNGScreenCaptureCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -80,7 +88,7 @@ class PNGScreenCaptureCommandClass : public ViniferaCommandClass
class ManualPlaceCommandClass : public ViniferaCommandClass
{
public:
ManualPlaceCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ManualPlaceCommandClass() : ViniferaCommandClass() {}
virtual ~ManualPlaceCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -99,7 +107,7 @@ class ManualPlaceCommandClass : public ViniferaCommandClass
class PrevThemeCommandClass : public ViniferaCommandClass
{
public:
PrevThemeCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
PrevThemeCommandClass() : ViniferaCommandClass() {}
virtual ~PrevThemeCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -118,7 +126,7 @@ class PrevThemeCommandClass : public ViniferaCommandClass
class NextThemeCommandClass : public ViniferaCommandClass
{
public:
NextThemeCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
NextThemeCommandClass() : ViniferaCommandClass() {}
virtual ~NextThemeCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -137,7 +145,7 @@ class NextThemeCommandClass : public ViniferaCommandClass
class ScrollNECommandClass : public ViniferaCommandClass
{
public:
ScrollNECommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ScrollNECommandClass() : ViniferaCommandClass() {}
virtual ~ScrollNECommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -156,7 +164,7 @@ class ScrollNECommandClass : public ViniferaCommandClass
class ScrollSECommandClass : public ViniferaCommandClass
{
public:
ScrollSECommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ScrollSECommandClass() : ViniferaCommandClass() {}
virtual ~ScrollSECommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -175,7 +183,7 @@ class ScrollSECommandClass : public ViniferaCommandClass
class ScrollSWCommandClass : public ViniferaCommandClass
{
public:
ScrollSWCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ScrollSWCommandClass() : ViniferaCommandClass() {}
virtual ~ScrollSWCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -194,7 +202,7 @@ class ScrollSWCommandClass : public ViniferaCommandClass
class ScrollNWCommandClass : public ViniferaCommandClass
{
public:
ScrollNWCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ScrollNWCommandClass() : ViniferaCommandClass() {}
virtual ~ScrollNWCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -213,7 +221,7 @@ class ScrollNWCommandClass : public ViniferaCommandClass
class JumpCameraWestCommandClass : public ViniferaCommandClass
{
public:
JumpCameraWestCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
JumpCameraWestCommandClass() : ViniferaCommandClass() {}
virtual ~JumpCameraWestCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -232,7 +240,7 @@ class JumpCameraWestCommandClass : public ViniferaCommandClass
class JumpCameraEastCommandClass : public ViniferaCommandClass
{
public:
JumpCameraEastCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
JumpCameraEastCommandClass() : ViniferaCommandClass() {}
virtual ~JumpCameraEastCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -251,7 +259,7 @@ class JumpCameraEastCommandClass : public ViniferaCommandClass
class JumpCameraNorthCommandClass : public ViniferaCommandClass
{
public:
JumpCameraNorthCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
JumpCameraNorthCommandClass() : ViniferaCommandClass() {}
virtual ~JumpCameraNorthCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -270,7 +278,7 @@ class JumpCameraNorthCommandClass : public ViniferaCommandClass
class JumpCameraSouthCommandClass : public ViniferaCommandClass
{
public:
JumpCameraSouthCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
JumpCameraSouthCommandClass() : ViniferaCommandClass() {}
virtual ~JumpCameraSouthCommandClass() {}

virtual const char *Get_Name() const override;
Expand All @@ -289,7 +297,7 @@ class JumpCameraSouthCommandClass : public ViniferaCommandClass
class ToggleSuperTimersCommandClass : public ViniferaCommandClass
{
public:
ToggleSuperTimersCommandClass() : ViniferaCommandClass() { IsDeveloper = false; }
ToggleSuperTimersCommandClass() : ViniferaCommandClass() {}
virtual ~ToggleSuperTimersCommandClass() {}

virtual const char *Get_Name() const override;
Expand Down
74 changes: 74 additions & 0 deletions src/extensions/command/commandext_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "commandext.h"
#include "vinifera_globals.h"
#include "tibsun_functions.h"
#include "tibsun_globals.h"
#include "session.h"
#include "ccfile.h"
#include "ccini.h"
#include "object.h"
Expand All @@ -37,6 +39,76 @@
#include "debughandler.h"


// This can not be in client compatabile builds currently as the additional
// commands added do not have runtime type information.
#if !defined(TS_CLIENT)
/**
* This function reimplements the chunk of code that populates the keyboard
* command list box. This allows us to enforce limits on what commands
* to show depending on the current game mode.
*
* @author: CCHyper
*/
static void Populate_Command_Categories(HWND hWnd, const char *category)
{
for (int i = 0; i < Commands.Count(); ++i) {
CommandClass *cmd = Commands[i];
if (!cmd) {
continue;
}

/**
* Any Vinifera commands are subject to game mode checks. We only need
* to check these if are actually "in game".
*/
if (bool_007E4040 || bool_007E48FC) {

ViniferaCommandClass *vcmd = dynamic_cast<ViniferaCommandClass *>(cmd);
if (vcmd) {
if (vcmd->Multiplayer_Only() && (Session.Type == GAME_NORMAL || Session.Type == GAME_SKIRMISH || Session.Type == GAME_WDT)) {
continue;
}
if (vcmd->Developer_Only() && !Vinifera_DeveloperMode) {
continue;
}
}

}

if (strcmpi(cmd->Get_Category(), category) != 0) {
continue;
}

/**
* Add the string and data pair to the list box.
*/
LRESULT result = SendMessage(hWnd, LB_ADDSTRING, 0, (LPARAM)cmd->Get_UI_Name());
if (result != LB_ERR && result != LB_ERRSPACE) {
UINT index = (UINT)result;
SendMessage(hWnd, LB_SETITEMDATA, index, (LPARAM)cmd);
}

}
}
#endif


/**
* Patch to intercept the populating of the keyboard command list box.
*
* @author: CCHyper
*/
DECLARE_PATCH(_OptionsClass_Keyboard_Options_Dialog_Populate_Intercept_Patch)
{
GET_REGISTER_STATIC(HWND, hWnd, ebp);
LEA_STACK_STATIC(const char *, category, esp, 0x0A4);

Populate_Command_Categories(hWnd, category);

JMP(0x0058A79C);
}


/**
* #issue-#53
*
Expand Down Expand Up @@ -463,4 +535,6 @@ void CommandExtension_Hooks()
Hook_Virtual(0x004EAB00, PNGScreenCaptureCommandClass::Process);

Patch_Jump(0x004E95C2, &_GuardCommandClass_Process_Harvesters_Set_Mission_Patch);

Patch_Jump(0x0058A72E, &_OptionsClass_Keyboard_Options_Dialog_Populate_Intercept_Patch);
}

0 comments on commit 249c2d7

Please sign in to comment.