Skip to content

Commit

Permalink
Improved aspect ratio support
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Mar 1, 2017
1 parent 27f6b68 commit 46c1905
Show file tree
Hide file tree
Showing 10 changed files with 349 additions and 60 deletions.
2 changes: 1 addition & 1 deletion include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define TBF_MAJOR 0
#define TBF_MINOR 10
#define TBF_BUILD 0
#define TBF_BUILD 1
#define TBF_REV 0


Expand Down
14 changes: 9 additions & 5 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern std::wstring DEFAULT_BK2;

struct keybind_s
{
const char* bind_name;
std::wstring human_readable;

struct {
Expand Down Expand Up @@ -74,7 +75,7 @@ struct tbf_config_t
float aspect_ratio = 1.777778f;
uintptr_t aspect_addr = 0x00D56494ULL;//0x00D52398;
uintptr_t fovy_addr = 0x00D56498ULL;//0x00D5239C;
bool blackbar_videos = false; // OBSOLETE
bool blackbar_videos = false;
bool aspect_correction = false;
float postproc_ratio = 0.5f;
bool clear_blackbars = false;
Expand Down Expand Up @@ -167,10 +168,13 @@ struct tbf_config_t
std::wstring swap_keys = L"";
bool swap_wasd = false;

keybind_s hudless { L"Ctrl+Shift+F10", { true, true, false }, VK_F10 },
screenshot { L"F10", { false, false, false }, VK_F10 },
config_menu { L"Ctrl+Shift+Backspace", { true, true, false }, VK_BACK },
aspect_ratio { L"Ctrl+Alt+Shift+.", { true, true, true }, VK_OEM_PERIOD };
keybind_s hudless { "Hudless", L"Ctrl+Shift+F10", { true, true, false }, VK_F10 },
screenshot { "Screenshot", L"F10", { false, false, false }, VK_F10 },
config_menu { "CfgMenu", L"Ctrl+Shift+Backspace", { true, true, false }, VK_BACK },
aspect_ratio { "AspectRatio", L"Ctrl+Alt+Shift+.", { true, true, true }, VK_OEM_PERIOD },
clear_enemies { "ClearEnemies", L"Ctrl+Shift+F1", { true, true, false }, VK_F1 },
respawn_enemies { "RespawnEnemies", L"Ctrl+Shift+F2", { true, true, false }, VK_F2 },
battle_timestop { "BattleTimestop", L"Ctrl+Shift+/", { true, true, false }, 0 };

} keyboard;

Expand Down
47 changes: 44 additions & 3 deletions include/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ namespace tbf
{
extern uint32_t current_tex [256];

for ( int i = 0; i < num_elems; i++ )
for ( UINT i = 0; i < num_elems; i++ )
{
if (elem_decl [i].Usage == D3DDECLUSAGE_TEXCOORD)
textures.emplace (current_tex [elem_decl [i].UsageIndex]);
Expand Down Expand Up @@ -589,10 +589,51 @@ namespace tbf
}
}

const uint32_t START_FLAG = 0xF1D19C;
const int MAX_FLAGS = 40;

extern uintptr_t
TBF_GetBaseAddr (void);

__forceinline
uintptr_t
TBF_GetFlagBase (void)
{
return TBF_GetBaseAddr () + START_FLAG;
}

__forceinline
uint8_t*
TBF_GetFlagFromIdx (int idx)
{
return (uint8_t *)TBF_GetFlagBase () + idx;
}

struct game_state_t {
BYTE* base_addr = (BYTE *)0x2130309;
BYTE* base_addr = (BYTE *)0xF1D19C;
bool in_skit = false;

struct {
bool want = false;
uint64_t frame = 0;

void set (void) {
want = true;
frame = 0;
}

void clear (void) {
want = false;
frame = 0;
}

bool test (void) {
return want;
}
} clear_enemies, respawn_enemies;

// Applies to Tales of Zestiria only, flags have been
// shifted around in Berseria
struct data_t {
/* 0 */ BYTE Title;
/* 1 */ BYTE OpeningMovie;
Expand Down Expand Up @@ -680,7 +721,7 @@ struct game_state_t {
//((data_t *)base_addr)->BattlePause ||
//((data_t *)base_addr)->Title);
}
} static game_state;
} extern game_state;

typedef HRESULT (STDMETHODCALLTYPE *BeginScene_pfn)(
IDirect3DDevice9 *This
Expand Down
98 changes: 89 additions & 9 deletions src/ImGui/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ TBFix_KeybindDialog (keybind_s* keybind)

ImGui::SetNextWindowSizeConstraints ( ImVec2 (font_size * 9, font_size * 3), ImVec2 (font_size * 30, font_size * 6));

if (ImGui::BeginPopupModal ("Keyboard Binding", NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_ShowBorders))
if (ImGui::BeginPopupModal (keybind->bind_name, NULL, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_ShowBorders))
{
ImGui::GetIO ().WantCaptureKeyboard = false;

Expand Down Expand Up @@ -1130,12 +1130,6 @@ TBFix_DrawConfigUI (void)
ImGui::EndTooltip ();
}

tbf::RenderFix::need_reset.graphics |=
ImGui::Checkbox ("Enable Debug Validation Layer", &config.render.validation);

ImGui::SameLine ();
ImGui::Checkbox ("Marshall UI Draws Through Hook", &hook_marshall);

ImGui::TreePop ();
}

Expand Down Expand Up @@ -1242,7 +1236,7 @@ TBFix_DrawConfigUI (void)
}

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup ("Keyboard Binding");
ImGui::OpenPopup (config.keyboard.aspect_ratio.bind_name);
}

TBFix_KeybindDialog (&config.keyboard.aspect_ratio);
Expand Down Expand Up @@ -1295,7 +1289,7 @@ TBFix_DrawConfigUI (void)
}

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup ("Keyboard Binding");
ImGui::OpenPopup (config.keyboard.hudless.bind_name);
}

TBFix_KeybindDialog (&config.keyboard.hudless);
Expand Down Expand Up @@ -1538,6 +1532,92 @@ TBFix_DrawConfigUI (void)
ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Debug"))
{
ImGui::TreePush ("");

ImGui::BeginGroup ();
ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 15.0f);
ImGui::BeginChild ("Debug Flags", ImVec2 ( font_size * 35,
font_size_multiline * ( 1.3f + ( (MAX_FLAGS / 4) +
(MAX_FLAGS % 4 > 0 ? 1 : 0) ) ) ),
true );
for (int i = 0; i < MAX_FLAGS; i++)
{
char szDesc [32] = { '\0' };
if (i == 0)
sprintf (szDesc, "Base %06x", (uint32_t)START_FLAG + i);
else
sprintf (szDesc, "Flag [%#4lu]", i);

extern uintptr_t
TBF_GetBaseAddr (void);

uint8_t* flag = (uint8_t *)(TBF_GetBaseAddr () + START_FLAG + i);

bool bFlag = *flag != 0;

if (ImGui::Checkbox (szDesc, &bFlag))
*flag = (bFlag ? 1 : 0);

if (((i + 1) % 4) != 0 && i != (MAX_FLAGS - 1))
ImGui::SameLine ();
}

ImGui::EndChild ();
ImGui::EndGroup ();

ImGui::SameLine ();
ImGui::BeginGroup ();

tbf::RenderFix::need_reset.graphics |=
ImGui::Checkbox ("Enable D3D9 Debug Validation Layer", &config.render.validation);

ImGui::Checkbox ("Marshall UI Draws Through Hooked Procedures", &hook_marshall);

ImGui::Separator ();

ImGui::Text (" Clear Enemies Keybinding: %ws", config.keyboard.clear_enemies.human_readable.c_str ());

if (ImGui::IsItemHovered ()) {
ImGui::SetTooltip ("Click here to change.");
}

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup (config.keyboard.clear_enemies.bind_name);
}

TBFix_KeybindDialog (&config.keyboard.clear_enemies);

ImGui::Text ("Respawn Enemies Keybinding: %ws", config.keyboard.respawn_enemies.human_readable.c_str ());

if (ImGui::IsItemHovered ()) {
ImGui::SetTooltip ("Click here to change.");
}

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup (config.keyboard.respawn_enemies.bind_name);
}

TBFix_KeybindDialog (&config.keyboard.respawn_enemies);

ImGui::Text ("Battle Timestop Keybinding: %ws", config.keyboard.battle_timestop.human_readable.c_str ());

if (ImGui::IsItemHovered ()) {
ImGui::SetTooltip ("Click here to change.");
}

if (ImGui::IsItemClicked ()) {
ImGui::OpenPopup (config.keyboard.battle_timestop.bind_name);
}

TBFix_KeybindDialog (&config.keyboard.battle_timestop);

ImGui::EndGroup ();

ImGui::TreePop ();
}

ImGui::PopItemWidth ();

ImGui::Separator ( );
Expand Down
2 changes: 1 addition & 1 deletion src/ImGui/mod_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ TBF_LiveVertexStreamView (bool& can_scroll)
{
ImGui::Separator ();

for (int i = 0; i < num_elems; i++)
for (UINT i = 0; i < num_elems; i++)
{
if (elem_decl [i].Type != D3DDECLTYPE_UNUSED)
{
Expand Down
55 changes: 51 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ struct {
struct {
tbf::ParameterStringW* swap_keys;
tbf::ParameterBool* swap_wasd;

tbf::ParameterStringW* clear_enemies;
tbf::ParameterStringW* respawn_enemies;
tbf::ParameterStringW* battle_timestop;
} keyboard;


Expand Down Expand Up @@ -804,6 +808,37 @@ TBF_LoadConfig (std::wstring name)
L"Keyboard.Remap",
L"SwapKeys" );

keyboard.clear_enemies =
static_cast <tbf::ParameterStringW *>
(g_ParameterFactory.create_parameter <std::wstring>(
L"Clear Enemies On Screen")
);
keyboard.clear_enemies->register_to_ini (
keyboard_ini,
L"Keyboard.Debug",
L"ClearEnemies" );

keyboard.respawn_enemies =
static_cast <tbf::ParameterStringW *>
(g_ParameterFactory.create_parameter <std::wstring>(
L"Respawn Enemies On Screen")
);
keyboard.respawn_enemies->register_to_ini (
keyboard_ini,
L"Keyboard.Debug",
L"RespawnEnemies" );

keyboard.battle_timestop =
static_cast <tbf::ParameterStringW *>
(g_ParameterFactory.create_parameter <std::wstring> (
L"Pause Battle")
);
keyboard.battle_timestop->register_to_ini (
keyboard_ini,
L"Keyboard.Debug",
L"BattleTimestop" );



sys.version =
static_cast <tbf::ParameterStringW *>
Expand Down Expand Up @@ -926,9 +961,15 @@ TBF_LoadConfig (std::wstring name)
screenshots.keep->load (config.screenshots.keep);
screenshots.hudless_keybind->load (config.keyboard.hudless.human_readable);
render.aspect_ratio_keybind->load (config.keyboard.aspect_ratio.human_readable);
keyboard.clear_enemies->load (config.keyboard.clear_enemies.human_readable);
keyboard.respawn_enemies->load (config.keyboard.respawn_enemies.human_readable);
keyboard.battle_timestop->load (config.keyboard.battle_timestop.human_readable);

config.keyboard.hudless.parse ();
config.keyboard.aspect_ratio.parse ();
config.keyboard.hudless.parse ();
config.keyboard.aspect_ratio.parse ();
config.keyboard.clear_enemies.parse ();
config.keyboard.respawn_enemies.parse ();
config.keyboard.battle_timestop.parse ();

textures.remaster->load (config.textures.remaster);
textures.uncompressed->load (config.textures.uncompressed);
Expand Down Expand Up @@ -1023,8 +1064,11 @@ TBF_SaveConfig (std::wstring name, bool close_config)
input.gamepad.texture_set->store (config.input.gamepad.texture_set);
input.gamepad.virtual_controllers->store (config.input.gamepad.virtual_controllers);

config.keyboard.hudless.update ();
config.keyboard.aspect_ratio.update ();
config.keyboard.hudless.update ();
config.keyboard.aspect_ratio.update ();
config.keyboard.clear_enemies.update ();
config.keyboard.respawn_enemies.update ();
config.keyboard.battle_timestop.update ();

screenshots.add_to_steam->store (config.screenshots.import_to_steam);
screenshots.keep->store (config.screenshots.keep);
Expand All @@ -1033,6 +1077,9 @@ TBF_SaveConfig (std::wstring name, bool close_config)

keyboard.swap_wasd->store (config.keyboard.swap_wasd);
keyboard.swap_keys->store (config.keyboard.swap_keys);
keyboard.clear_enemies->store (config.keyboard.clear_enemies.human_readable);
keyboard.respawn_enemies->store (config.keyboard.respawn_enemies.human_readable);
keyboard.battle_timestop->store (config.keyboard.battle_timestop.human_readable);

sys.version->store (TBF_VER_STR);
//sys.intro_video->store (config.system.intro_video);
Expand Down
Loading

0 comments on commit 46c1905

Please sign in to comment.