Skip to content

Commit

Permalink
implemented configurator (using multiple configs per identifier), now…
Browse files Browse the repository at this point in the history
… using json as configuration save format
  • Loading branch information
loonsies committed Oct 23, 2023
1 parent 2279fe7 commit 350f0bb
Show file tree
Hide file tree
Showing 18 changed files with 9,442 additions and 200 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
"sstream": "cpp",
"stop_token": "cpp",
"thread": "cpp",
"map": "cpp"
"map": "cpp",
"cstring": "cpp",
"set": "cpp",
"iomanip": "cpp",
"codecvt": "cpp",
"list": "cpp",
"condition_variable": "cpp"
}
}
49 changes: 34 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
NAME = MemSubLoader
CC = g++
CFLAGS = -Wall
LINKS = -lstdc++ -lcomdlg32 -lshlwapi -lgdi32 -lgdiplus bin/Release/OutlineText.dll
LIBLINKS = -I./includes -I./resources -I./lib/OutlineText
LINKS = -lstdc++ -lcomdlg32 -lshlwapi -lgdi32 -lgdiplus bin/Release/OutlineText.dll bin/Release/JsonCpp.dll
LIBLINKS = -I./includes -I./resources -I./lib -I./lib/json -I./lib/OutlineText
SRC_PATH = srcs/
OBJ_PATH = bin/
OUT_PATH = bin/Release/
Expand All @@ -11,49 +11,68 @@ C_EXTENSION = .cpp
# 눈_눈 SOURCES 눈_눈

MAIN_PATH =
MAIN_FILES = main game mainWindow settingsWindow subtitlesWindow utils
MAIN_FILES = main game mainWindow settingsWindow subtitlesWindow configuratorWindow utils Win32InputBox
SRCS_FILES += $(addprefix $(MAIN_PATH), $(MAIN_FILES))

SRCS_FILES_EXT += $(addsuffix $(C_EXTENSION), $(SRCS_FILES))
SRCS += $(addprefix $(SRC_PATH), $(SRCS_FILES_EXT))
OBJS = $(addprefix $(OBJ_PATH), $(SRCS_FILES_EXT:cpp=o))

OUTLINETEXT_PATH = lib/OutlineText/
OUTLINETEXT_FILES = BmpOutlineText CanvasHelper DiffusedShadowStrategy DrawGradient ExtrudeStrategy\
LIB_OUTLINE_TEXT_PATH = lib/OutlineText/
LIB_OUTLINE_TEXT_FILES = BmpOutlineText CanvasHelper DiffusedShadowStrategy DrawGradient ExtrudeStrategy\
GDIPath IOutlineText ITextStrategy MaskColor NonSystemFontLoader OutlineText PngOutlineText stdafx TextDblGlowStrategy\
TextDblOutlineStrategy TextGlowStrategy TextGradOutlineLastStrategy TextGradOutlineStrategy TextImplGetHeight TextNoOutlineStrategy\
TextOnlyOutlineStrategy TextOutlineStrategy
OUTLINETEXT_SRCS_FILES = $(addprefix $(OUTLINETEXT_PATH), $(OUTLINETEXT_FILES))
LIB_OUTLINE_TEXT_SRCS_FILES = $(addprefix $(LIB_OUTLINE_TEXT_PATH), $(LIB_OUTLINE_TEXT_FILES))

OUTLINETEXT_SRCS_FILES_EXT += $(addsuffix $(C_EXTENSION), $(OUTLINETEXT_SRCS_FILES))
OUTLINETEXT_SRCS += $(addprefix $(OUTLINETEXT_PATH), $(OUTLINETEXT_SRCS_FILES_EXT))
OUTLINETEXT_OBJS = $(addprefix $(OBJ_PATH), $(OUTLINETEXT_SRCS_FILES_EXT:cpp=o))
LIB_OUTLINE_TEXT_SRCS_FILES_EXT += $(addsuffix $(C_EXTENSION), $(LIB_OUTLINE_TEXT_SRCS_FILES))
LIB_OUTLINE_TEXT_SRCS += $(addprefix $(LIB_OUTLINE_TEXT_PATH), $(LIB_OUTLINE_TEXT_SRCS_FILES_EXT))
LIB_OUTLINE_TEXT_OBJS = $(addprefix $(OBJ_PATH), $(LIB_OUTLINE_TEXT_SRCS_FILES_EXT:cpp=o))

LIB_JSON_CPP_PATH = lib/json/
LIB_JSON_CPP_FILES = jsoncpp
LIB_JSON_CPP_SRCS_FILES = $(addprefix $(LIB_JSON_CPP_PATH), $(LIB_JSON_CPP_FILES))

LIB_JSON_CPP_SRCS_FILES_EXT += $(addsuffix $(C_EXTENSION), $(LIB_JSON_CPP_SRCS_FILES))
LIB_JSON_CPP_SRCS += $(addprefix $(LIB_JSON_CPP_PATH), $(LIB_JSON_CPP_SRCS_FILES_EXT))
LIB_JSON_CPP_OBJS = $(addprefix $(OBJ_PATH), $(LIB_JSON_CPP_SRCS_FILES_EXT:cpp=o))

# (҂◡_◡) UTILS (҂◡_◡)

RM = rm -rf

# ( ಠ ʖ̯ ಠ) RULES ( ಠ ʖ̯ ಠ)

all: folders lib $(NAME)
all: folders libOutlineText libJsonCpp $(NAME)

$(NAME): $(OBJS)
$(CC) $(CFLAGS) -o $(OUT_PATH)$(NAME) $(OBJS) $(LINKS)

folders:
@mkdir -p $(dir $(OBJ_PATH)$(OUTLINETEXT_PATH))
@mkdir -p $(dir $(OBJ_PATH)$(LIB_OUTLINE_TEXT_PATH))
@mkdir -p $(dir $(OBJ_PATH)$(LIB_JSON_CPP_PATH))
@mkdir -p $(dir $(OBJ_PATH)$(LIB_INPUT_BOX_PATH))
@mkdir -p $(dir ${OUT_PATH})

lib: $(OUTLINETEXT_OBJS)
$(CC) ${CFLAGS} -shared $(OUTLINETEXT_OBJS) -lgdiplus -lgdi32 -Wl,--export-all-symbols -o $(OUT_PATH)OutlineText.dll
libOutlineText: $(LIB_OUTLINE_TEXT_OBJS)
$(CC) ${CFLAGS} -shared $(LIB_OUTLINE_TEXT_OBJS) -lgdiplus -lgdi32 -Wl,--export-all-symbols -o $(OUT_PATH)OutlineText.dll

libJsonCpp: $(LIB_JSON_CPP_OBJS)
$(CC) ${CFLAGS} -shared $(LIB_JSON_CPP_OBJS) -Wl,--export-all-symbols -o $(OUT_PATH)JsonCpp.dll

.c.o:
@$(CC) $(FLAGS) -c ${LIBLINKS} $< -o ${<:.cpp=.o}

$(OBJ_PATH)%.o: $(SRC_PATH)%.cpp
${CC} ${CFLAGS} $(LIBLINKS) -c $< -o $@

$(OBJ_PATH)$(OUTLINETEXT_PATH)%.o: $(OUTLINETEXT_PATH)%.cpp
$(OBJ_PATH)$(LIB_OUTLINE_TEXT_PATH)%.o: $(LIB_OUTLINE_TEXT_PATH)%.cpp
${CC} ${CFLAGS} $(LIBLINKS) -c $< -o $@

$(OBJ_PATH)$(LIB_JSON_CPP_PATH)%.o: $(LIB_JSON_CPP_PATH)%.cpp
${CC} ${CFLAGS} $(LIBLINKS) -c $< -o $@

$(OBJ_PATH)$(LIB_INPUT_BOX_PATH)%.o: $(LIB_INPUT_BOX_PATH)%.cpp
${CC} ${CFLAGS} $(LIBLINKS) -c $< -o $@

clean:
Expand All @@ -64,4 +83,4 @@ fclean: clean

re: fclean all

.phony: all clean fclean re lib folders
.phony: all clean fclean re libOutlineText libJsonCpp folders
6 changes: 6 additions & 0 deletions MemSubLoader.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<Add option="-Wall" />
<Add directory="includes" />
<Add directory="resources" />
<Add directory="lib" />
<Add directory="lib/json" />
<Add directory="lib/OutlineText" />
</Compiler>
<Linker>
Expand All @@ -43,12 +45,16 @@
<Add library="Comdlg32" />
<Add library="gdiplus" />
<Add library="bin/Release/OutlineText.dll" />
<Add library="bin/Release/JsonCpp.dll" />
</Linker>
<Unit filename="includes/MemSubLoader.hpp" />
<Unit filename="includes/Win32InputBox.h" />
<Unit filename="resources/MemSubLoader.rc">
<Option compilerVar="WINDRES" />
</Unit>
<Unit filename="resources/resource.h" />
<Unit filename="srcs/Win32InputBox.cpp" />
<Unit filename="srcs/configuratorWindow.cpp" />
<Unit filename="srcs/game.cpp" />
<Unit filename="srcs/main.cpp" />
<Unit filename="srcs/mainWindow.cpp" />
Expand Down
81 changes: 55 additions & 26 deletions includes/MemSubLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
# define UNICODE
#endif
# define _WIN32_WINNT 0x0501
# define _WIN32_IE 0x0300
# include <windows.h>
# include <commctrl.h>
# include <iostream>
# include <shlwapi.h>
# include <fstream>
Expand All @@ -17,6 +19,8 @@
# include <sstream>
# include <gdiplus.h>
# include "OutlineText.h"
# include "json.h"
# include "Win32InputBox.h"
# include "resource.h"

// Main controls
Expand Down Expand Up @@ -64,6 +68,11 @@
# define AREA_HEIGHT_EDIT 38
# define AREA_HEIGHT_UPDOWN 39
# define AREA_PREVIEW_CHECKBOX 40
# define CONFIGURATOR_EDIT_BUTTON 41
# define CONFIGURATOR_NEW_BUTTON 42
# define CONFIGURATOR_DELETE_BUTTON 43
# define CONFIGURATOR_DUPLICATE_BUTTON 44
# define CONFIGURATOR_TODEFAULT_BUTTON 45

// Save & Cancel controls
# define SAVE_BUTTON 41
Expand Down Expand Up @@ -104,9 +113,8 @@ enum TextAlignment {
};

struct Config {
wchar_t gamePath[MAX_PATH];
wchar_t subtitlesPath[MAX_PATH];

wchar_t *identifier;

// Font
COLORREF fontColor;
LOGFONT subtitlesFont;
Expand Down Expand Up @@ -137,17 +145,29 @@ struct Config {
bool areaPreview;
};

struct WStringCompare
{
bool operator()(const wchar_t* str1, const wchar_t* str2) const
{
return wcscmp(str1, str2) < 0;
}
};

// Global variables definition

// Global resources
extern Config config;
extern std::map<std::wstring, Config> configs;
extern std::map<wchar_t *, Config, WStringCompare> configs;
extern std::wstring textToDraw;
extern Config tmpConfig;
extern wchar_t gamePath[MAX_PATH];
extern wchar_t subtitlesPath[MAX_PATH];
extern HINSTANCE hInst;

// Windows
extern HWND mainHWND;
extern HWND subtitlesHWND;
extern HWND settingsHWND;
extern HWND configuratorHWND;

// Main window handles
extern HWND gamePathValueLabel;
Expand All @@ -160,6 +180,9 @@ extern HWND fontStyleValueLabel;
extern HWND alignmentHorizontalComboBox;
extern HWND alignmentVerticalComboBox;

// Configurator window handles
extern HWND configList;

// Resources
extern HFONT hFont;
extern HFONT titleFont;
Expand Down Expand Up @@ -194,25 +217,25 @@ extern int oldAreaHeight;
class Subtitles
{
private:
uintptr_t bAddress_audio;
std::vector <int> offset_audio;
uintptr_t bAddress_play;
std::vector <int> offset_play;
void findAddress(uintptr_t &address, int offset, HANDLE hProcess);
uintptr_t bAddress_audio;
std::vector <int> offset_audio;
uintptr_t bAddress_play;
std::vector <int> offset_play;
void findAddress(uintptr_t &address, int offset, HANDLE hProcess);

public:
uintptr_t address_audio;
uintptr_t address_play;
int AudioID;
int lastAudioID;
bool is_playing;
std::vector <int> ID;
std::vector <std::wstring> Text;

void search_memory(HANDLE hProcess);
bool check_audio(HANDLE hProcess);
void file_memory(std::wifstream& file);
void file_text(std::wifstream& file);
uintptr_t address_audio;
uintptr_t address_play;
int AudioID;
int lastAudioID;
bool is_playing;
std::vector <int> ID;
std::vector <std::wstring> Text;

void search_memory(HANDLE hProcess);
bool check_audio(HANDLE hProcess);
void file_memory(std::wifstream& file);
void file_text(std::wifstream& file);
};

// Main
Expand All @@ -224,29 +247,35 @@ void updateMainAttributes(HWND hwnd);
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int createSettingsWindow(HWND parent);
void updateSubtitlesSettingsAttributes(HWND hwnd, LOGFONT &lf);
void updateSettingsWindowAttributes(HWND hwnd);
LRESULT CALLBACK SettingsWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

int createSubtitlesWindow(void);
LRESULT CALLBACK subtitlesWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void handleUpdown(HWND hwnd, int &value, int &oldValue, const wchar_t *name, int id, int min, int max, LPARAM lParam);
void handleEdit(HWND hwnd, int &value, int &oldValue, const wchar_t *name, int id, int min, int max, WPARAM wParam);

int createConfiguratorWindow(HWND parent);
void updateConfiguratorWindowAttributes();
LRESULT CALLBACK ConfiguratorWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

// Utilities
void findAddress(uintptr_t &address, int offset, HANDLE hProcess);

bool openFileExplorer(HWND hwnd, wchar_t *filePath, int filePathSize, int button);
bool openFontDialog(HWND hwnd, LOGFONT &lf, HFONT &subtitlesFont);
bool openFontDialog(HWND hwnd, LOGFONT &lf, HFONT &subtitlesFont, COLORREF &subtitlesColor);
bool openColorDialog(HWND hwnd, COLORREF &subtitlesColor);

void ShowBalloonTooltip(HWND hwnd, const std::wstring& description, int durationMilliseconds);

bool saveConfig(const Config &config, wchar_t *filename);
bool loadConfig(Config &config, const wchar_t *filename);
bool saveConfig(wchar_t *filename);
bool loadConfig(const wchar_t *filename);
bool setAutoloadConfigPath(const wchar_t *path);
bool getAutoloadConfigPath(wchar_t *path);
bool getAutoloadPath(wchar_t *executablePath);
Gdiplus::StringAlignment getConfigAlignment(TextAlignment alignment);
std::map<wchar_t *, Config, WStringCompare>::iterator getConfig(wchar_t * identifier);
wchar_t *getSelectedIdentifier(void);

void cleanup(void);

Expand Down
Loading

0 comments on commit 350f0bb

Please sign in to comment.