Skip to content

Commit

Permalink
the start of the refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hero622 committed Aug 14, 2024
1 parent e8dd65f commit ec9daf0
Show file tree
Hide file tree
Showing 75 changed files with 2,413 additions and 967 deletions.
89 changes: 24 additions & 65 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,71 +1,30 @@
---
AccessModifierOffset: '-1'
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveMacros: 'false'
AlignConsecutiveAssignments: 'false'
AlignConsecutiveDeclarations: 'false'
AlignEscapedNewlines: Left
AlignOperands: 'false'
AlignTrailingComments: 'true'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: WithoutElse
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: 'true'
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: 'true'
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: 'false'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: 'true'
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: 'false'
AccessModifierOffset: -1
AlignConsecutiveAssignments: true
AlignConsecutiveBitFields: true
AlignConsecutiveDeclarations: true
AlignConsecutiveMacros: true
AlignEscapedNewlines: true
AlignOperands: true
AlignTrailingComments: true
AllowShortBlocksOnASingleLine: Always
AllowShortIfStatementsOnASingleLine: Never
BreakTemplateDeclarations: Yes
ColumnLimit: 0
CompactNamespaces: 'false'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '1'
ContinuationIndentWidth: '1'
Cpp11BracedListStyle: 'true'
DerivePointerAlignment: 'false'
ForEachMacros: ['foreach']
Cpp11BracedListStyle: false
IncludeBlocks: Regroup
IncludeIsMainRegex: $
IndentCaseLabels: 'false'
IndentPPDirectives: AfterHash
IndentWidth: '1'
IndentWrappedFunctionNames: 'false'
InsertTrailingCommas: Wrapped
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '2'
IndentWidth: 1
NamespaceIndentation: All
PointerAlignment: Right
ReflowComments: 'true'
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'true'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'true'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCpp11BracedList: 'true'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'true'
SpacesBeforeTrailingComments: '2'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'true'
SpacesInContainerLiterals: 'true'
SpacesInParentheses: 'true'
SpacesInSquareBrackets: 'true'
Standard: Cpp11
TabWidth: '1'
PointerAlignment: Left
SpaceAfterCStyleCast: true
SpaceInEmptyParentheses: true
SpacesBeforeTrailingComments: 2
SpacesInAngles: true
SpacesInConditionalStatement: true
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
TabWidth: 1
UseTab: AlignWithSpaces

...
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CXX=g++-10
SDIR=src
ODIR=obj

SRCS=$(wildcard $(SDIR)/photon-sdk/utils/*.cpp)
SRCS=$(wildcard $(SDIR)/sdk/utils/*.cpp)
SRCS+=$(wildcard $(SDIR)/core/*.cpp)
SRCS+=$(wildcard $(SDIR)/core/convars/*.cpp)
SRCS+=$(wildcard $(SDIR)/core/hooks/*.cpp)
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

## Mods
- Install mods by placing them in the `photon` folder inside the Portal 2 directory.
- Load mods by typing `photon_load <mod name>` in the console.
- Enable mods by typing `photon_enable <mod name>` in the console.
- Enable them from the menu that you can open by pressing <kbd>Insert</kbd>.

## Development
- [SDK](https://github.com/hero622/photon-sdk)
- [Contributing](docs/contributing.md)
4 changes: 2 additions & 2 deletions example-mod/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CXX=g++-10
SDIR=src
ODIR=obj

SRCS=$(wildcard ../$(SDIR)/photon-sdk/utils/*.cpp)
SRCS=$(wildcard ../$(SDIR)/util/*.cpp)
SRCS+=$(wildcard $(SDIR)/*.cpp)
SRCS+=$(wildcard $(SDIR)/convars/*.cpp)
SRCS+=$(wildcard $(SDIR)/hooks/*.cpp)
Expand All @@ -17,7 +17,7 @@ OBJS=$(patsubst $(SDIR)/%.cpp, $(ODIR)/%.o, $(SRCS))
DEPS=$(OBJS:%.o=%.d)

WARNINGS=-Wall -Wno-parentheses -Wno-unknown-pragmas -Wno-delete-non-virtual-dtor
CXXFLAGS=-std=c++17 -m32 $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -I$(SDIR)/deps/photon-sdk
CXXFLAGS=-std=c++17 -m32 $(WARNINGS) -I$(SDIR) -fPIC -D_GNU_SOURCE -I$(SDIR)/sdk # i think this is cooked either way im gonna check later
LDFLAGS=-m32 -shared -lstdc++fs

# Import config.mk, which can be used for optional config
Expand Down
30 changes: 15 additions & 15 deletions example-mod/src/convars/convars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

#include <photon.h>

concmd_cbk( example_command ) {
CONCMD_CBK( example_command ) {
// get multiple types of values of the cvar
const auto cvar = photon->portal2->cvar->find_con_var( "example_convar" );

const auto fl_value = cvar->get_float( );
const auto n_value = cvar->get_int( );
const auto col_value = cvar->get_color( );
const auto b_value = cvar->get_bool( );
const auto str_value = cvar->get_string( );

photon->portal2->console->msg( "the value of example_convar is:\n" );
photon->portal2->console->msg( "float: %f\n", fl_value );
photon->portal2->console->msg( "int: %d\n", n_value );
photon->portal2->console->msg( "color: %d %d %d %d\n", col_value.r, col_value.g, col_value.b, col_value.a );
photon->portal2->console->msg( "bool: %d\n", ( int ) b_value );
photon->portal2->console->msg( "string: %s\n", str_value );
// const auto cvar = interfaces::cvar->find_con_var( "example_convar" );

// const auto fl_value = cvar->get_float( );
// const auto n_value = cvar->get_int( );
// const auto col_value = cvar->get_color( );
// const auto b_value = cvar->get_bool( );
// const auto str_value = cvar->get_string( );

// interfaces::console->msg( "the value of example_convar is:\n" );
// interfaces::console->msg( "float: %f\n", fl_value );
// interfaces::console->msg( "int: %d\n", n_value );
// interfaces::console->msg( "color: %d %d %d %d\n", col_value.r, col_value.g, col_value.b, col_value.a );
// interfaces::console->msg( "bool: %d\n", ( int ) b_value );
// interfaces::console->msg( "string: %s\n", str_value );
}

bool convars::initialize( ) {
Expand Down
6 changes: 3 additions & 3 deletions example-mod/src/hooks/hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include "hooks.h"

bool example_mod::hooks::initialize( ) {
hk_inline( calc_view_model_lag, utils::memory::pattern_scan( module( "client" ), os( "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 83 EC 1C 56 6A 00", "56 53 83 EC 24 8B 74 24 30 8B 5C 24 34 6A 00" ) ) );
// HK_INLINE( calc_view_model_lag, util::pattern_scan( MODULE( "client" ), OS( "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 83 EC 1C 56 6A 00", "56 53 83 EC 24 8B 74 24 30 8B 5C 24 34 6A 00" ) ) );

return true;
}

void example_mod::hooks::uninitialize( ) {
unhk( calc_view_model_lag );
// UNHK( calc_view_model_lag );
}

hk_fn( void, example_mod::hooks::calc_view_model_lag, sdk::vec3_t &origin, sdk::vec3_t &angles, sdk::vec3_t &original_angles ) {
HK_FN( void, example_mod::hooks::calc_view_model_lag, vec3_t& origin, vec3_t& angles, vec3_t& original_angles ) {
return;
}
2 changes: 1 addition & 1 deletion example-mod/src/hooks/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace example_mod {
namespace hooks {
decl_hk( void, calc_view_model_lag, sdk::vec3_t &origin, sdk::vec3_t &angles, sdk::vec3_t &original_angles );
DECL_HK( void, calc_view_model_lag, vec3_t& origin, vec3_t& angles, vec3_t& original_angles );

bool initialize( );
void uninitialize( );
Expand Down
20 changes: 9 additions & 11 deletions example-mod/src/huds/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <photon.h>

c_example_hud *ex_hud;
c_example_thud *ex_thud;
c_example_hud* ex_hud;
c_example_thud* ex_thud;

bool huds::initialize( ) {
photon->hud->reg( ex_hud = new c_example_hud( ) );
Expand All @@ -17,25 +17,23 @@ void huds::uninitialize( ) {
photon->hud->unreg( ex_thud );
}


void c_example_hud::paint( ) {
photon->hud->draw_begin( this );

photon->hud->draw_filled_rect( 0, 0, 20, 20, sdk::color_t( 255, 0, 0, 255 ) );
photon->hud->draw_filled_rect( 20, 20, 20, 20, sdk::color_t( 0, 255, 0, 255 ) );
photon->hud->draw_filled_rect( 40, 40, 20, 20, sdk::color_t( 0, 0, 255, 255 ) );
photon->hud->draw_filled_rect( 0, 60, 80, 20, sdk::color_t( 255, 255, 255, 255 ) );
photon->hud->draw_filled_rect( 0, 0, 20, 20, color_t( 255, 0, 0, 255 ) );
photon->hud->draw_filled_rect( 20, 20, 20, 20, color_t( 0, 255, 0, 255 ) );
photon->hud->draw_filled_rect( 40, 40, 20, 20, color_t( 0, 0, 255, 255 ) );
photon->hud->draw_filled_rect( 0, 60, 80, 20, color_t( 255, 255, 255, 255 ) );

photon->hud->draw_end( );
}
const char *c_example_hud::get_name( ) {
const char* c_example_hud::get_name( ) {
return "example hud";
}


const char *c_example_thud::get_text( ) {
const char* c_example_thud::get_text( ) {
return "0";
}
const char *c_example_thud::get_name( ) {
const char* c_example_thud::get_name( ) {
return "example-thud";
}
8 changes: 4 additions & 4 deletions example-mod/src/huds/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace huds {
} // namespace huds

class c_example_hud : public photon_api::i_hud {
virtual void paint( );
virtual const char *get_name( );
virtual void paint( );
virtual const char* get_name( );
};

class c_example_thud : public photon_api::i_thud {
virtual const char *get_text( );
virtual const char *get_name( );
virtual const char* get_text( );
virtual const char* get_name( );
};
32 changes: 16 additions & 16 deletions example-mod/src/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

c_photon_mod mod;

expose_photon_mod( c_photon_mod, mod );
EXPOSE_PHOTON_MOD( c_photon_mod, mod );

photon_api::c_shared *photon;
photon_api::c_shared* photon;

sdk::h_font font;
h_font font;

bool c_photon_mod::load( photon_api::c_shared *photon ) {
bool c_photon_mod::load( photon_api::c_shared* photon ) {
::photon = photon;

if ( example_mod::hooks::initialize( ) ) {
convars::initialize( );

huds::initialize( );

photon->portal2->console->msg( "example mod loaded.\n" );
// interfaces::console->msg( "example mod loaded.\n" );

// post example event
// this will look like: "example mod:load" for other mods
photon->event->post( &mod, "load" );

photon->render->create_font( font, "Tahoma", 12, false, sdk::fontflag_dropshadow );
photon->render->create_font( font, "Tahoma", 12, false, fontflag_dropshadow );
}

return true;
Expand All @@ -41,21 +41,21 @@ void c_photon_mod::unload( ) {

example_mod::hooks::uninitialize( );

photon->portal2->console->msg( "example mod unloaded.\n" );
// interfaces::console->msg( "example mod unloaded.\n" );
}

void c_photon_mod::on_event( const char *msg ) {
void c_photon_mod::on_event( const char* msg ) {
if ( !strcmp( msg, "paint" ) ) {
photon->render->draw_text( 2, 2, font, { 255, 255, 255, 255 }, false, "example mod loaded." );
}
if ( !strcmp( msg, "on_screen_size_changed" ) ) {
photon->render->create_font( font, "Tahoma", 12, false, sdk::fontflag_dropshadow );
photon->render->create_font( font, "Tahoma", 12, false, fontflag_dropshadow );
}
}

photon_api::mod_info_t c_photon_mod::get_info( ) {
photon_api::mod_info_t info;
info.name = "example mod";
info.name = "example mod";
info.version = "0.0.1";
return info;
}
Expand All @@ -70,11 +70,11 @@ void c_photon_mod::paint_menu( ) {
static float example_sliderf_val;
photon->menu->sliderf( example_sliderf_val, 0.f, 10.f, "example sliderf" );

static std::size_t example_combo_val;
const char *example_combo_items[] = { "value 1", "value 2", "value 3" };
photon->menu->combo( example_combo_val, example_combo_items, array_len( example_combo_items ), "example combo" );
// static std::size_t example_combo_val;
// const char* example_combo_items[] = { "value 1", "value 2", "value 3" };
// photon->menu->combo( example_combo_val, example_combo_items, array_len( example_combo_items ), "example combo" );

static std::size_t example_multicombo_val;
const char *example_multicombo_items[] = { "value 1", "value 2", "value 3" };
photon->menu->multicombo( example_multicombo_val, example_multicombo_items, array_len( example_multicombo_items ), "example multicombo" );
// static std::size_t example_multicombo_val;
// const char* example_multicombo_items[] = { "value 1", "value 2", "value 3" };
// photon->menu->multicombo( example_multicombo_val, example_multicombo_items, array_len( example_multicombo_items ), "example multicombo" );
}
8 changes: 4 additions & 4 deletions example-mod/src/mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

class c_photon_mod : public photon_api::i_photon_mod {
public:
virtual bool load( photon_api::c_shared *photon );
virtual void unload( );
virtual void on_event( const char *msg );
virtual bool load( photon_api::c_shared* photon );
virtual void unload( );
virtual void on_event( const char* msg );
virtual photon_api::mod_info_t get_info( );
virtual void paint_menu( );
virtual void paint_menu( );
};

extern c_photon_mod mod;
Loading

0 comments on commit ec9daf0

Please sign in to comment.