Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxor4d committed May 1, 2022
2 parents 1ccabee + f5dbe84 commit a0919df
Show file tree
Hide file tree
Showing 19 changed files with 979 additions and 113 deletions.
29 changes: 29 additions & 0 deletions src/common/camwnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,31 @@ void __declspec(naked) move_selection_stub()
}
}

void __declspec(naked) drag_setup_stub()
{
const static uint32_t cmp_addr = 0x47E45A;
const static uint32_t retn_pt = 0x47E448;
__asm
{
shr eax, 0xF; // og
test al, 1; // og
jz JZ_ADDR;
jmp retn_pt;

JZ_ADDR:
pushad; // new
call should_move_selection;
test al, al;
popad; // new

je SKIP_ADDR;
jmp cmp_addr;

SKIP_ADDR:
jmp retn_pt;
}
}

// *
// *

Expand Down Expand Up @@ -392,6 +417,10 @@ void ccamwnd::hooks()
//utils::hook::set<BYTE>(0x40539D, 0xEB);
utils::hook(0x480238, move_selection_stub, HOOK_JUMP).install()->quick();

// disable selection box when using the guizmo to translate vertices -> fixes deselection of vertices after translation
utils::hook::nop(0x47E441, 5);
utils::hook(0x47E441, drag_setup_stub, HOOK_JUMP).install()->quick();

// disable original context menu ~ handled in czwnd
//utils::hook::nop(0x403340, 5);

Expand Down
12 changes: 12 additions & 0 deletions src/components/modules/main_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ namespace components
}
}


// ----------------------------------


Expand Down Expand Up @@ -402,6 +403,17 @@ namespace components

// * ---------------------------

/*command::register_command("rope"s, [](const std::vector<std::string>& args)
{
if (args.size() != 4)
{
game::printf_to_console("Usage: rope <int: thickness> <int: slack in percent (0-100)> <bool: delete nulls>");
return;
}
generate_rope(utils::try_stoi(args[1], false), utils::try_stoi(args[2], false), utils::try_stoi(args[3], false));
});*/


// creates a brush that encupsules all selected brushes/patches and uses texture info of the first selected brush
// then deletes the original selection
Expand Down
81 changes: 70 additions & 11 deletions src/components/modules/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2174,14 +2174,20 @@ namespace components
}

//#ifdef DEBUG
// // Add a debug line
// game::vec3_t start = { 0.0f, 0.0f, 0.0f };
// game::vec3_t end = { 0.0f, 0.0f, 20000.0f };
// game::vec4_t color = { 1.0f, 0.0f, 0.0f, 1.0f };
//
// // R_AddDebugLine(frontEndDataOut->debugGlobals, &v10, &v13, v9);
// utils::hook::call<void(__cdecl)(game::DebugGlobals*, const float* start, const float* end, const float* color)>(0x528680)
// (game::get_frontenddata()->debugGlobals, start, end, color);
// Add a debug line
//game::vec3_t start = { 0.0f, 0.0f, 0.0f };
//game::vec3_t fwd = {};
//utils::vector::angle_vectors(game::glob::track_worldspawn.sundirection, fwd, nullptr, nullptr);

//utils::vector::scale(fwd, 500.0f, fwd);

////game::vec3_t end = { 0.0f, 0.0f, 20000.0f };
//game::vec4_t color = { 1.0f, 0.5f, 0.0f, 1.0f };

//// R_AddDebugLine(frontEndDataOut->debugGlobals, &v10, &v13, v9);
//utils::hook::call<void(__cdecl)(game::DebugGlobals*, const float* start, const float* end, const float* color)>(0x528680)
// (game::get_frontenddata()->debugGlobals, start, fwd, color);

//#endif

RB_EndSceneRendering(game::gfxCmdBufSourceState, game::gfxCmdBufState, &viewInfo->input, viewInfo);
Expand Down Expand Up @@ -2517,6 +2523,55 @@ namespace components
}
}

void debug_sundirection()
{
if(game::glob::debug_sundir)
{
if (const auto world_ent = game::g_world_entity();
world_ent && world_ent->firstActive)
{
for (auto epair = world_ent->firstActive->epairs; epair; epair = epair->next)
{
if (utils::string_equals(epair->key, "sundirection"))
{
const std::vector<std::string> value_str = utils::explode(epair->value, ' ');

if (value_str.size() != 3)
{
break;
}

game::vec3_t sun_dir = {};
sun_dir[0] = utils::try_stof(value_str[0], true);
sun_dir[1] = utils::try_stof(value_str[1], true);
sun_dir[2] = utils::try_stof(value_str[0], true);

game::vec3_t end_pt = {};
utils::vector::angle_vectors(sun_dir, end_pt, nullptr, nullptr);
utils::vector::scale(end_pt, game::glob::debug_sundir_length, end_pt);

game::vec4_t color_start = { 1.0f, 0.4f, 0.1f, 1.0f };
game::vec4_t color_end = { 0.85f, 0.75f, 0.25f, 1.0f };

game::GfxPointVertex pts[2] = {};

game::Byte4PackPixelColor(color_start, &pts[0].color);
pts[0].xyz[0] = game::glob::debug_sundir_startpos[0];
pts[0].xyz[1] = game::glob::debug_sundir_startpos[1];
pts[0].xyz[2] = game::glob::debug_sundir_startpos[2];

game::Byte4PackPixelColor(color_end, &pts[1].color);
pts[1].xyz[0] = end_pt[0];
pts[1].xyz[1] = end_pt[1];
pts[1].xyz[2] = end_pt[2];

renderer::R_AddLineCmd(1, 4, 3, pts);
}
}
}
}
}

void __declspec(naked) disable_line_depth_testing2()
{
// enable depth testing for connection lines
Expand All @@ -2528,6 +2583,7 @@ namespace components

pushad;
call draw_target_connection_lines_func;
call debug_sundirection;
popad;

jmp retn_addr;
Expand All @@ -2547,7 +2603,7 @@ namespace components
};

// rewrite to add depth_test functionality
void R_AddLineCmd(const std::uint16_t count, const char width, const char dimension, const game::GfxPointVertex* verts)
void renderer::R_AddLineCmd(const std::uint16_t count, const char width, const char dimension, const game::GfxPointVertex* verts)
{
if (count <= 0)
{
Expand Down Expand Up @@ -2898,12 +2954,15 @@ namespace components

// ^ nop call that adds connection lines (target->targetname) (after disabled depth testing) and call it before disabling depth testing
//utils::hook::nop(0x408645, 5);
utils::hook(0x40CC21, disable_line_depth_testing2, HOOK_JUMP).install()->quick(); // disable depth testing for lines (same result as clearing the depthbuffer)

// disable depth testing for lines (same result as clearing the depthbuffer)
// + stub that draws the sundirection debug line
utils::hook(0x40CC21, disable_line_depth_testing2, HOOK_JUMP).install()->quick();

// * ------

// rewrite R_AddLineCmd to add depth_test functionality
utils::hook::detour(0x4FD0A0, R_AddLineCmd, HK_JUMP);
utils::hook::detour(0x4FD0A0, renderer::R_AddLineCmd, HK_JUMP);

// make RB_DrawLinesCmd use the cmd's depth_test var
utils::hook::nop(0x5336AF, 6);
Expand Down
1 change: 1 addition & 0 deletions src/components/modules/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace components
static void R_ConvertColorToBytes(float* from, game::GfxColor* gfx_col);
static void R_AddCmdDrawTextAtPosition(const char* text, game::Font_s* font, float* origin, float* pixel_step_x, float* pixel_step_y, float* color);
static void copy_scene_to_texture(ggui::e_gfxwindow wnd, IDirect3DTexture9*& dest, bool no_release = false);
static void R_AddLineCmd(const std::uint16_t count, const char width, const char dimension, const game::GfxPointVertex* verts);

static inline int effect_drawsurf_count_ = 0;

Expand Down
Loading

0 comments on commit a0919df

Please sign in to comment.