Skip to content

Commit

Permalink
Very early shader mod support
Browse files Browse the repository at this point in the history
  • Loading branch information
andon authored and andon committed Feb 14, 2017
1 parent a596271 commit 3cf65a4
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 129 deletions.
4 changes: 2 additions & 2 deletions include/DLL_VERSION.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#define TBF_MAJOR 0
#define TBF_MINOR 9
#define TBF_BUILD 6
#define TBF_REV 6
#define TBF_BUILD 7
#define TBF_REV 0



Expand Down
7 changes: 7 additions & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ struct tbf_config_t
bool highlight_debug_tex = true;
} textures;

struct {
bool hollow_eye_mode = false;
uint32_t hollow_eye_vs_crc32 = 0xf063a9f3;
bool disable_smoke = false;
uint32_t smoke_ps_crc32 = 0x868bd533;
} fun_stuff;

struct {
struct {
std::wstring texture_set = L"XboxOne";
Expand Down
12 changes: 10 additions & 2 deletions include/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,21 @@ namespace tbf

struct render_target_tracking_s
{
IDirect3DBaseTexture9* tracking_tex;
IDirect3DBaseTexture9* tracking_tex = nullptr;

std::unordered_set <uint32_t> pixel_shaders;
std::unordered_set <uint32_t> vertex_shaders;

bool active;
bool active = false;
} extern tracked_rt;

struct shader_tracking_s
{
uint32_t crc32 = 0x00;
bool cancel_draws = false;
bool active = false;
int num_draws = 0;
} extern tracked_vs, tracked_ps;
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/ImGui/control_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,21 @@ TBFix_DrawConfigUI (void)
ImGui::TreePop ();
}

if (ImGui::CollapsingHeader ("Fun Stuff"))
{
ImGui::TreePush ("");

ImGui::Checkbox ("Hollow Eye Mode", &config.fun_stuff.hollow_eye_mode);
if (ImGui::IsItemHovered ())
ImGui::SetTooltip ("The stuff nightmares are made from.");

ImGui::Checkbox ("Disable Smoke", &config.fun_stuff.disable_smoke);
if (ImGui::IsItemHovered ())
ImGui::SetTooltip ("Does not disable all smoke... just the super obnoxious concentric ring (banding from hell) variety that makes you want to gouge your eyes out in dungeons.");

ImGui::TreePop ();
}

ImGui::PopItemWidth ();

ImGui::Separator ( );
Expand Down
191 changes: 120 additions & 71 deletions src/ImGui/mod_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,13 +812,13 @@ TBFix_TextureModDlg (void)
ImGui::Columns (2);

for ( auto it : tbf::RenderFix::tracked_rt.vertex_shaders ) {
ImGui::Text ("Vertex Shader: %x", it);
ImGui::Text ("Vertex Shader: %08x", it);
}

ImGui::NextColumn ();

for ( auto it : tbf::RenderFix::tracked_rt.pixel_shaders ) {
ImGui::Text ("Pixel Shader: %x", it);
ImGui::Text ("Pixel Shader: %08x", it);
}

ImGui::Columns (1);
Expand All @@ -834,22 +834,26 @@ TBFix_TextureModDlg (void)

if (ImGui::CollapsingHeader ("Live Shader View"))
{
ImGui::BeginGroup ();

static float last_ht = 256.0f;
static float last_width = 256.0f;

static std::vector <std::string> list_contents;
static bool list_dirty = true;
static uint32_t last_sel = 0;
static int sel = -1;
struct {
std::vector <std::string> list_contents;
bool list_dirty = true;
uint32_t last_sel = 0;
int sel = -1;
} static ps, vs;

std::vector <uint32_t> pixel_shaders ( tbf::RenderFix::last_frame.pixel_shaders.begin (),
tbf::RenderFix::last_frame.pixel_shaders.end () );

if (list_dirty)
if (ps.list_dirty)
{
sel = -1;
int idx = 0;
list_contents.clear ();
ps.sel = -1;
int idx = 0;
ps.list_contents.clear ();

// The underlying list is unsorted for speed, but that's not at all
// intuitive to humans, so sort the thing when we have the RT view open.
Expand All @@ -862,13 +866,13 @@ TBFix_TextureModDlg (void)
{
char szDesc [16] = { };

sprintf (szDesc, "%llx", (uintptr_t)it);
sprintf (szDesc, "%08llx", (uintptr_t)it);

list_contents.emplace_back (szDesc);
ps.list_contents.emplace_back (szDesc);

if ((uint32_t)it == last_sel)
if ((uint32_t)it == ps.last_sel)
{
sel = idx;
ps.sel = idx;
//tbf::RenderFix::tracked_rt.tracking_tex = render_textures [sel];
}

Expand All @@ -880,66 +884,86 @@ TBFix_TextureModDlg (void)
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Pixel Shaders",
ImVec2 ( font_size * 10.0f, std::max (font_size * 15.0f, last_ht)),
ImVec2 ( font_size * 7.0f, std::max (font_size * 15.0f, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );

if (pixel_shaders.size ())
{
static int last_sel = 0;
static bool sel_changed = false;
if (ImGui::IsWindowHovered ())
{
ImGui::BeginTooltip ();
ImGui::TextColored (ImVec4 (0.9f, 0.6f, 0.2f, 1.0f), "You can cancel all render passes using the selected pixel shader to disable an effect");
ImGui::Separator ();
ImGui::BulletText ("Press [ while the mouse is hovering this list to select the previous shader");
ImGui::BulletText ("Press ] while the mouse is hovering this list to select the next shader");
ImGui::EndTooltip ();

if (ImGui::GetIO ().KeysDownDuration [VK_OEM_4] == 0.0f) ps.sel--;
else if (ImGui::GetIO ().KeysDownDuration [VK_OEM_6] == 0.0f) ps.sel++;
}

if (sel != last_sel)
sel_changed = true;
if (pixel_shaders.size ())
{
static int last_sel = 0;
static bool sel_changed = false;

last_sel = sel;
if (ps.sel != last_sel)
sel_changed = true;

for ( int line = 0; line < pixel_shaders.size (); line++ )
{
if (line == sel)
{
bool selected = true;
ImGui::Selectable (list_contents [line].c_str (), &selected);
last_sel = ps.sel;

if (sel_changed)
{
ImGui::SetScrollHere (0.5f); // 0.0f:top, 0.5f:center, 1.0f:bottom
sel_changed = false;
}
}
for ( int line = 0; line < pixel_shaders.size (); line++ )
{
if (line == ps.sel)
{
bool selected = true;
ImGui::Selectable (ps.list_contents [line].c_str (), &selected);

else
{
bool selected = false;
if (sel_changed)
{
ImGui::SetScrollHere (0.5f); // 0.0f:top, 0.5f:center, 1.0f:bottom
sel_changed = false;
ps.last_sel = (uint32_t)pixel_shaders [ps.sel];
tbf::RenderFix::tracked_ps.crc32 = (uint32_t)pixel_shaders [ps.sel];
}
}

if (ImGui::Selectable (list_contents [line].c_str (), &selected))
{
sel_changed = true;
sel = line;
last_sel = (uint32_t)pixel_shaders [sel];
//tbf::RenderFix::tracked_rt.tracking_tex = render_textures [sel];
}
}
}
}
else
{
bool selected = false;

if (ImGui::Selectable (ps.list_contents [line].c_str (), &selected))
{
sel_changed = true;
ps.sel = line;
ps.last_sel = (uint32_t)pixel_shaders [ps.sel];
tbf::RenderFix::tracked_ps.crc32 = (uint32_t)pixel_shaders [ps.sel];
}
}
}
}

ImGui::EndChild ();

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

if (tbf::RenderFix::tracked_ps.crc32 != 0x00)
ImGui::Checkbox ("Cancel Draws Using Selected Pixel Shader", &tbf::RenderFix::tracked_ps.cancel_draws);
else
tbf::RenderFix::tracked_ps.cancel_draws = false;

ImGui::EndGroup ();

ImGui::PopStyleColor ();
ImGui::PopStyleVar ();

ImGui::EndGroup ();


std::vector <uint32_t> vertex_shaders ( tbf::RenderFix::last_frame.vertex_shaders.begin (),
tbf::RenderFix::last_frame.vertex_shaders.end () );

if (list_dirty)
if (vs.list_dirty)
{
sel = -1;
int idx = 0;
list_contents.clear ();
vs.sel = -1;
int idx = 0;
vs.list_contents.clear ();

// The underlying list is unsorted for speed, but that's not at all
// intuitive to humans, so sort the thing when we have the RT view open.
Expand All @@ -950,63 +974,78 @@ TBFix_TextureModDlg (void)
{
char szDesc [16] = { };

sprintf (szDesc, "%llx", (uintptr_t)it);
sprintf (szDesc, "%08llx", (uintptr_t)it);

list_contents.emplace_back (szDesc);
vs.list_contents.emplace_back (szDesc);

if ((uint32_t)it == last_sel)
if ((uint32_t)it == vs.last_sel)
{
sel = idx;
vs.sel = idx;
//tbf::RenderFix::tracked_rt.tracking_tex = render_textures [sel];
}

++idx;
}
}

ImGui::BeginGroup ();

ImGui::PushStyleVar (ImGuiStyleVar_ChildWindowRounding, 0.0f);
ImGui::PushStyleColor (ImGuiCol_Border, ImVec4 (0.9f, 0.7f, 0.5f, 1.0f));

ImGui::BeginChild ( "Vertex Shaders",
ImVec2 ( font_size * 10.0f, std::max (font_size * 15.0f, last_ht)),
ImVec2 ( font_size * 7.0f, std::max (font_size * 15.0f, last_ht)),
true, ImGuiWindowFlags_AlwaysAutoResize );


if (ImGui::IsWindowHovered ())
{
ImGui::BeginTooltip ();
ImGui::TextColored (ImVec4 (0.9f, 0.6f, 0.2f, 1.0f), "You can cancel all render passes using the selected vertex shader to disable an effect");
ImGui::Separator ();
ImGui::BulletText ("Press [ while the mouse is hovering this list to select the previous shader");
ImGui::BulletText ("Press ] while the mouse is hovering this list to select the next shader");
ImGui::EndTooltip ();

if (ImGui::GetIO ().KeysDownDuration [VK_OEM_4] == 0.0f) vs.sel--;
else if (ImGui::GetIO ().KeysDownDuration [VK_OEM_6] == 0.0f) vs.sel++;
}

if (vertex_shaders.size ())
{
static int last_sel = 0;
static bool sel_changed = false;
static int last_sel = 0;
static bool sel_changed = false;

if (sel != last_sel)
if (vs.sel != last_sel)
sel_changed = true;

last_sel = sel;
last_sel = vs.sel;

for ( int line = 0; line < vertex_shaders.size (); line++ )
{
if (line == sel)
if (line == vs.sel)
{
bool selected = true;
ImGui::Selectable (list_contents [line].c_str (), &selected);
ImGui::Selectable (vs.list_contents [line].c_str (), &selected);

if (sel_changed)
{
ImGui::SetScrollHere (0.5f); // 0.0f:top, 0.5f:center, 1.0f:bottom
sel_changed = false;
vs.last_sel = (uint32_t)vertex_shaders [vs.sel];
tbf::RenderFix::tracked_vs.crc32 = (uint32_t)vertex_shaders [vs.sel];
}
}

else
{
bool selected = false;

if (ImGui::Selectable (list_contents [line].c_str (), &selected))
if (ImGui::Selectable (vs.list_contents [line].c_str (), &selected))
{
sel_changed = true;
sel = line;
last_sel = (uint32_t)vertex_shaders [sel];
//tbf::RenderFix::tracked_rt.tracking_tex = render_textures [sel];
vs.sel = line;
vs.last_sel = (uint32_t)vertex_shaders [vs.sel];
tbf::RenderFix::tracked_vs.crc32 = (uint32_t)vertex_shaders [vs.sel];
}
}
}
Expand All @@ -1015,12 +1054,22 @@ TBFix_TextureModDlg (void)
ImGui::EndChild ();
ImGui::PopStyleVar ();
ImGui::PopStyleColor ();

ImGui::SameLine ();

if (tbf::RenderFix::tracked_vs.crc32 != 0x00)
ImGui::Checkbox ("Cancel Draws Using Selected Vertex Shader", &tbf::RenderFix::tracked_vs.cancel_draws);
else
tbf::RenderFix::tracked_vs.cancel_draws = false;

ImGui::EndGroup ();
}

if (ImGui::CollapsingHeader ("Misc. Settings"))
{
ImGui::TreePush ("");
if (ImGui::Checkbox ("Dump ALL Textures (TBFix_Res\\dump\\textures\\<format>\\*.dds)", &config.textures.dump)) tbf::RenderFix::need_reset.graphics = true;
if (ImGui::Checkbox ("Dump ALL Shaders (TBFix_Res\\dump\\shaders\\<ps|vs>_<checksum>.html", &config.render.dump_shaders)) tbf::RenderFix::need_reset.graphics = true;
if (ImGui::Checkbox ("Dump ALL Textures (TBFix_Res\\dump\\textures\\<format>\\*.dds)", &config.textures.dump)) tbf::RenderFix::need_reset.graphics = true;

if (ImGui::IsItemHovered ())
{
Expand Down
Loading

0 comments on commit 3cf65a4

Please sign in to comment.