Skip to content

Commit

Permalink
Added support for Framerate Limiter Bypass
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Jan 17, 2017
1 parent 202530b commit 539da13
Show file tree
Hide file tree
Showing 17 changed files with 357 additions and 994 deletions.
4 changes: 2 additions & 2 deletions include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


#define TBF_MAJOR 0
#define TBF_MINOR 1
#define TBF_BUILD 7
#define TBF_MINOR 2
#define TBF_BUILD 0
#define TBF_REV 0


Expand Down
45 changes: 16 additions & 29 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,41 +31,26 @@ extern std::wstring DEFAULT_BK2;
struct tbf_config_t
{
struct {
uint32_t sample_hz = 48000;
uint32_t channels = 6; // OBSOLETE
bool compatibility = false;
bool enable_fix = true;
uint32_t sample_hz = -1;
uint32_t channels = 6;
bool compatibility = false;
bool enable_fix = true;
} audio;

struct {
bool yield_processor = true;
bool allow_fake_sleep = false;
bool minimize_latency = false;
DWORD speedresetcode_addr = 0x0046C0F9; //0x0046C529;
DWORD speedresetcode2_addr = 0x0056EB41; //0x0056E441; 0x217B464
DWORD speedresetcode3_addr = 0x0056E03F; //0x0056D93F;
DWORD limiter_branch_addr = 0x00990F53; //0x00990873;
bool disable_limiter = true;
bool auto_adjust = false;
int target = 60;
int battle_target = 60;
bool battle_adaptive = false;
int cutscene_target = 30;
bool reshade_fix = false;
bool replace_limiter = true;
int target = 60;
bool reshade_fix = false;
} framerate;

struct {
bool capture = false;
bool capture = false;
} file_io;

struct {
bool allow_broadcasts = false;
bool allow_broadcasts = false;
} steam;

struct {
bool fix_priest = true;
} lua;

struct {
float fovy = 0.785398f;
float aspect_ratio = 1.777778f;
Expand All @@ -81,11 +66,13 @@ struct tbf_config_t
} render;

struct {
bool dump = false;
bool remaster = true;
bool cache = true;
int32_t max_cache_in_mib = 2048L;
int32_t worker_threads = 6;
bool dump = false;
bool remaster = true;
bool cache = true;
bool uncompressed = false;
float lod_bias = -0.2666f;
int32_t max_cache_in_mib = 2048L;
int32_t worker_threads = 6;
} textures;

struct {
Expand Down
33 changes: 10 additions & 23 deletions include/framerate.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
/**
* This file is part of Tales of Zestiria "Fix".
* This file is part of Tales of Berseria "Fix".
*
* Tales of Zestiria "Fix" is free software : you can redistribute it
* Tales of Berseria "Fix" is free software : you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by The Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Tales of Zestiria "Fix" is distributed in the hope that it will be
* Tales of Berseria "Fix" is distributed in the hope that it will be
* useful,
*
* But WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Tales of Zestiria "Fix".
* along with Tales of Berseria "Fix".
*
* If not, see <http://www.gnu.org/licenses/>.
*
**/
#ifndef __TZF__FRAMERATE_H__
#define __TZF__FRAMERATE_H__
#ifndef __TBF__FRAMERATE_H__
#define __TBF__FRAMERATE_H__

#include <stdint.h>
#include <Windows.h>

#include "command.h"

namespace tzf
namespace tbf
{
namespace FrameRateFix
{
Expand All @@ -39,10 +39,7 @@ namespace tzf
void RenderTick (void);


// Determine the appropriate value for TickScale
long CalcTickScale (double elapsed_ms);


#if 0
//
// At key points during the game, we need to disable the code that
// cuts timing in half. These places will be wrapped by calls to
Expand All @@ -52,6 +49,7 @@ namespace tzf
void End30FPSEvent (void);

void SetFPS (int fps);
#endif

class CommandProcessor : public SK_IVariableListener {
public:
Expand All @@ -74,23 +72,12 @@ namespace tzf
static CommandProcessor* pCommProc;
};


// True if the game is running in fullscreen
extern bool fullscreen;

// True if the game is being framerate limited by the DRIVER
extern bool driver_limit_setup;

// True if the executable has been modified (at run-time) to allow 60 FPS
extern bool variable_speed_installed;

// This is actually setup in the SK DLL that loads this one
extern uint32_t target_fps;

// Store the original unmodifed game instructions
extern uint8_t old_speed_reset_code2 [7];
extern uint8_t old_limiter_instruction [6];

// Cache the game's tick scale for timing -- this can be changed without
// our knowledge, so this is more or less a hint rather than a rule
extern int32_t tick_scale;
Expand All @@ -104,4 +91,4 @@ namespace tzf
}
}

#endif /* __TZF__FRAMERATE_H__ */
#endif /* __TBF__FRAMERATE_H__ */
10 changes: 9 additions & 1 deletion include/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,16 @@ class ParameterBool : public Parameter <bool>

bool load (bool& ref);

enum boolean_term_t {
TrueFalse = 0,
OnOff = 1,
YesNo = 2,
ZeroNonZero = 3
};

protected:
bool value;
bool value;
boolean_term_t type = TrueFalse;
};

class ParameterFloat : public Parameter <float>
Expand Down
9 changes: 5 additions & 4 deletions include/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
*
**/

#ifndef __TZF__SCANNER_H__
#define __TZF__SCANNER_H__
#ifndef __TBF__SCANNER_H__
#define __TBF__SCANNER_H__

#include <stdint.h>

void* TBF_Scan (uint8_t* pattern, size_t len, uint8_t* mask = nullptr);
void* TBF_Scan (uint8_t* pattern, size_t len, uint8_t* mask = nullptr);
uintptr_t TBF_GetBaseAddr (void);

#endif /* __TZF__SCANNER_H__ */
#endif /* __TBF__SCANNER_H__ */
58 changes: 41 additions & 17 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,7 @@ struct {
} audio;

struct {
tbf::ParameterBool* allow_fake_sleep;
tbf::ParameterBool* yield_processor;
tbf::ParameterBool* minimize_latency;
tbf::ParameterInt* speedresetcode_addr;
tbf::ParameterInt* speedresetcode2_addr;
tbf::ParameterInt* speedresetcode3_addr;
tbf::ParameterInt* limiter_branch_addr;
tbf::ParameterBool* disable_limiter;
tbf::ParameterBool* auto_adjust;
tbf::ParameterInt* target;
tbf::ParameterInt* battle_target;
tbf::ParameterBool* battle_adaptive;
tbf::ParameterInt* cutscene_target;
tbf::ParameterBool* replace_limiter;
} framerate;

struct {
Expand All @@ -84,6 +72,8 @@ struct {

struct {
tbf::ParameterBool* remaster;
tbf::ParameterBool* uncompressed;
tbf::ParameterFloat* lod_bias;
tbf::ParameterBool* cache;
tbf::ParameterBool* dump;
tbf::ParameterInt* cache_size;
Expand All @@ -101,10 +91,6 @@ struct {
} keyboard;


struct {
tbf::ParameterBool* fix_priest;
} lua;

struct {
struct {
tbf::ParameterStringW* texture_set;
Expand Down Expand Up @@ -225,6 +211,26 @@ TBF_LoadConfig (std::wstring name)
L"Texture.System",
L"Remaster" );

textures.uncompressed =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool> (
L"Do Not Re-Compress Remastered Textures")
);
textures.uncompressed->register_to_ini (
render_ini,
L"Texture.System",
L"UncompressedRemasters" );

textures.lod_bias =
static_cast <tbf::ParameterFloat *>
(g_ParameterFactory.create_parameter <float> (
L"Texture LOD Bias")
);
textures.lod_bias->register_to_ini (
render_ini,
L"Texture.System",
L"LODBias" );

textures.cache_size =
static_cast <tbf::ParameterInt *>
(g_ParameterFactory.create_parameter <int> (
Expand Down Expand Up @@ -277,6 +283,16 @@ TBF_LoadConfig (std::wstring name)
L"Shadow.Quality",
L"RescaleEnvShadows" );

framerate.replace_limiter =
static_cast <tbf::ParameterBool *>
(g_ParameterFactory.create_parameter <bool> (
L"Replace Namco's Framerate Limiter")
);
framerate.replace_limiter->register_to_ini (
render_ini,
L"Framerate.Fix",
L"ReplaceLimiter" );


input.gamepad.texture_set =
static_cast <tbf::ParameterStringW *>
Expand Down Expand Up @@ -345,7 +361,11 @@ TBF_LoadConfig (std::wstring name)

render.dump_shaders->load (config.render.dump_shaders);

framerate.replace_limiter->load (config.framerate.replace_limiter);

textures.remaster->load (config.textures.remaster);
textures.uncompressed->load (config.textures.uncompressed);
textures.lod_bias->load (config.textures.lod_bias);
textures.cache->load (config.textures.cache);
textures.dump->load (config.textures.dump);
textures.cache_size->load (config.textures.max_cache_in_mib);
Expand All @@ -365,12 +385,16 @@ TBF_SaveConfig (std::wstring name, bool close_config)
audio.compatibility->store (config.audio.compatibility);
audio.enable_fix->store (config.audio.enable_fix);

framerate.replace_limiter->store (config.framerate.replace_limiter);

render.dump_shaders->store (config.render.dump_shaders);

render.rescale_shadows->store (config.render.shadow_rescale);
render.rescale_env_shadows->store (config.render.env_shadow_rescale);

textures.remaster->store (config.textures.remaster);
textures.uncompressed->store (config.textures.uncompressed);
textures.lod_bias->store (config.textures.lod_bias);
textures.cache->store (config.textures.cache);
textures.dump->store (config.textures.dump);
textures.cache_size->store (config.textures.max_cache_in_mib);
Expand Down
14 changes: 9 additions & 5 deletions src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "command.h"
#include "hook.h"

#include "scanner.h"

#pragma comment (lib, "kernel32.lib")

typedef HRESULT (__stdcall *SK_UpdateSoftware_pfn) (const wchar_t* wszProduct);
Expand Down Expand Up @@ -74,15 +76,17 @@ SKPlugIn_Init (HMODULE hModSpecialK)
TBF_VER_STR.c_str () );

if (! TBF_LoadConfig ()) {
config.audio.channels = 6;
config.audio.sample_hz = 48000;
config.audio.channels = 6;
config.audio.sample_hz = -1;
config.audio.compatibility = false;
config.audio.enable_fix = true;

config.file_io.capture = false;

config.steam.allow_broadcasts = false;
config.lua.fix_priest = true;

config.framerate.replace_limiter = true;
config.framerate.target = 20;

config.render.aspect_ratio = 1.777778f;
config.render.fovy = 0.785398f;
Expand Down Expand Up @@ -123,7 +127,7 @@ SKPlugIn_Init (HMODULE hModSpecialK)
//tbf::FileIO::Init ();
//tbf::SteamFix::Init ();
tbf::RenderFix::Init ();
//tbf::FrameRateFix::Init ();
tbf::FrameRateFix::Init ();
//tbf::KeyboardFix::Init ();

// Uncomment this when spawning a thread
Expand Down Expand Up @@ -176,7 +180,7 @@ DllMain (HMODULE hModule,
//tbf::FileIO::Shutdown ();
//tbf::SteamFix::Shutdown ();
tbf::RenderFix::Shutdown ();
//tbf::FrameRateFix::Shutdown ();
tbf::FrameRateFix::Shutdown ();
//tbf::KeyboardFix::Shutdown ();

TBF_UnInit_MinHook ();
Expand Down
Loading

0 comments on commit 539da13

Please sign in to comment.