Skip to content

Commit

Permalink
Merge pull request #15 from xoxor4d/feature/reflections
Browse files Browse the repository at this point in the history
merge reflections
  • Loading branch information
xoxor4d authored Jun 2, 2022
2 parents 6364460 + 382907c commit 652020b
Show file tree
Hide file tree
Showing 23 changed files with 1,155 additions and 76 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ https://discord.gg/t5jRGbj
- [X Labs](https://github.com/XLabsProject) (especially [Snake](https://github.com/momo5502))
- [The Plutonium Project Team](https://plutonium.pw/) (especially [Rektinator](https://github.com/RektInator))
- [Nukem9 - LinkerMod](https://github.com/Nukem9/LinkerMod) & [detours](https://github.com/Nukem9/detours)
- [JTAG - NootNoot](https://twitter.com/imjtagmodz)
- [ocornut - Dear ImGui](https://github.com/ocornut/imgui)
- [CedricGuillemet - ImGuizmo](https://github.com/CedricGuillemet/ImGuizmo)
- [nlohmann - fifo_map](https://github.com/nlohmann/fifo_map)
- [David Gallardo - imgui_color_gradient](https://gist.github.com/galloscript/8a5d179e432e062550972afcd1ecf112)
- [nem0 - ImGui CurveEditor](https://github.com/nem0/LumixEngine/blob/39e46c18a58111cc3c8c10a4d5ebbb614f19b1b8/external/imgui/imgui_user.inl#L505-L930)
- [zfedoran - ImGui Spinner](https://github.com/ocornut/imgui/issues/1901)
- [maluoi - tga writer](https://gist.github.com/maluoi/ade07688e741ab188841223b8ffeed22)
- [Infinity Ward - OG. Radiant and Effects Framework](https://www.infinityward.com)
- [id-Software - OG. Radiant](https://github.com/id-Software/Quake-III-Arena/tree/master/q3radiant)

Expand Down
31 changes: 31 additions & 0 deletions readme/licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
MIT License

https://github.com/Nukem9/detours
Copyright (c) 2019 Nukem <[email protected]>

https://github.com/ocornut/imgui
Copyright (c) 2014-2022 Omar Cornut

https://github.com/nlohmann/fifo_map
Copyright (c) 2015-2017 Niels Lohmann

https://gist.github.com/maluoi/ade07688e741ab188841223b8ffeed22
Copyright (c) 2019 Nick Klingensmith (@koujaku)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions src/components/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace components
loader::_register(new main_module());
loader::_register(new pmesh());
loader::_register(new process());
loader::_register(new reflectionprobes());
loader::_register(new renderer());
loader::_register(new remote_net());

Expand Down
1 change: 1 addition & 0 deletions src/components/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ namespace components
#include "modules/main_module.hpp"
#include "modules/pmesh.hpp"
#include "modules/process.hpp"
#include "modules/reflectionprobes.hpp"
#include "modules/renderer.hpp"
#include "modules/remote_net.hpp"
88 changes: 84 additions & 4 deletions src/components/modules/d3dbsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,76 @@ namespace components
return false;
}

#pragma warning(push)
#pragma warning(disable: 4146)
void d3dbsp::Com_SaveLump(LumpType type, const void* newLump, unsigned int size)
{
const void* chunkData[100];

BspHeader new_header = {};
new_header.ident = 1347633737;
new_header.version = 22;
new_header.chunkCount = 0;

bool isNewChunk = true;
unsigned int offset = 8 * comBspGlob.header->chunkCount + 12;

for (auto chunkIter = 0u; chunkIter < comBspGlob.header->chunkCount; ++chunkIter)
{
const BspChunk* chunk = &comBspGlob.header->chunks[chunkIter];
if (chunk->type == type)
{
isNewChunk = false;
if (size)
{
new_header.chunks[new_header.chunkCount].type = type;
new_header.chunks[new_header.chunkCount].length = size;
chunkData[new_header.chunkCount++] = newLump;
}
}
else
{
new_header.chunks[new_header.chunkCount].type = chunk->type;
new_header.chunks[new_header.chunkCount].length = chunk->length;
chunkData[new_header.chunkCount++] = (char*)comBspGlob.header + offset;
}

offset += (chunk->length + 3) & 0xFFFFFFFC;
}
if (isNewChunk && size)
{
new_header.chunks[new_header.chunkCount].type = type;
new_header.chunks[new_header.chunkCount].length = size;
chunkData[new_header.chunkCount++] = newLump;
}

const auto h = game::FS_OpenFileOverwrite(comBspGlob.name);
if (h)
{
game::FS_Write(&new_header, 8 * new_header.chunkCount + 12, h);
for (auto chunkIter = 0u; chunkIter < new_header.chunkCount; ++chunkIter)
{
game::FS_Write(chunkData[chunkIter], new_header.chunks[chunkIter].length, h);
const unsigned int zeroCount = -new_header.chunks[chunkIter].length & 3;

if (zeroCount)
{
unsigned int zero;
game::FS_Write(&zero, zeroCount, h);
}

}

game::FS_FCloseFile(h);
d3dbsp::radiant_load_bsp(d3dbsp::loaded_bsp_path.c_str(), true);
}
else
{
game::Com_Error("Failed to open file %s for writing", comBspGlob.name);
}
}
#pragma warning(pop)

const void* d3dbsp::Com_GetBspLump(LumpType type, unsigned int elemSize, unsigned int* count)
{
const void* result = nullptr;
Expand Down Expand Up @@ -472,7 +542,7 @@ namespace components

if (bytesRead != comBspGlob.fileSize)
{
free(comBspGlob.header);
game::Z_Free(comBspGlob.header);
game::printf_to_console("[ERR][BSP] bytesRead != comBspGlob.fileSize");
return false;
}
Expand All @@ -489,9 +559,8 @@ namespace components
d3dbsp::dobj_clear_list();

comBspGlob.loadedLumpData = nullptr;

// free(comBspGlob.header);
utils::hook::call<void(__cdecl)(void*)>(0x4AC2A0)(comBspGlob.header);

game::Z_Free(comBspGlob.header);

comBspGlob.header = nullptr;
comBspGlob.name[0] = 0;
Expand Down Expand Up @@ -715,6 +784,11 @@ namespace components
process::pthis->set_callback([bsp_path]
{
d3dbsp::radiant_load_bsp(bsp_path.c_str(), true);

if(dvars::bsp_gen_reflections_on_compile->current.enabled)
{
dvars::set_bool(dvars::r_reflectionprobe_generate, true);
}
});

process::pthis->create_process();
Expand Down Expand Up @@ -798,6 +872,12 @@ namespace components
/* flags */ game::dvar_flags::saved,
/* desc */ "enable to load entities when loading a bsp (static_models only)");

dvars::bsp_gen_reflections_on_compile = dvars::register_bool(
/* name */ "bsp_gen_reflections_on_compile",
/* default */ true,
/* flags */ game::dvar_flags::saved,
/* desc */ "automatically build reflections when compiling the bsp");

dvars::r_draw_bsp = dvars::register_bool(
/* name */ "r_draw_bsp",
/* default */ false,
Expand Down
4 changes: 4 additions & 0 deletions src/components/modules/d3dbsp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ namespace components
static bool Com_IsBspLoaded();
static std::uint32_t Com_GetBspVersion();
static char* Com_ValidateBspLumpData(LumpType type, unsigned int offset, unsigned int length, unsigned int elemSize, unsigned int* count);

static void Com_SaveLump(LumpType type, const void* newLump, unsigned int size);
static void Com_SaveLump_t5(LumpType type, const void* newLump, unsigned int size);

static const void* Com_GetBspLump(LumpType type, unsigned int elemSize, unsigned int* count);
static bool Com_GetBspLumpBool(LumpType type);
static bool Com_LoadBsp(const char* filename);
Expand Down
58 changes: 51 additions & 7 deletions src/components/modules/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ namespace components
// main rendering loop (d3d9ex::d3d9device::EndScene())
void gui::render_loop()
{
if(dvars::r_reflectionprobe_generate->current.enabled)
{
return;
}

exec::on_gui_execute();

/* - radiant draws multiple windows using d3d
Expand Down Expand Up @@ -378,21 +383,60 @@ namespace components
ShowWindow(con, SW_HIDE);
}

// debug
#if 0
if (game::s_world->reflectionProbes && game::s_world->reflectionProbes->reflectionImage
&& game::s_world->reflectionProbes->reflectionImage->texture.data)
{
ImGui::Begin("Reflection Probes Debug", nullptr);

ImGui::Image(game::s_world->reflectionProbes[0].reflectionImage->texture.data, ImVec2(300, 300));
ImGui::SameLine();
ImGui::Image(game::s_world->reflectionProbes[1].reflectionImage->texture.data, ImVec2(300, 300));


if (reflectionprobes::imgui_cube_surfaces[0])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[0], ImVec2(300, 300));


ImGui::SameLine();
if (reflectionprobes::imgui_cube_surfaces[1])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[1], ImVec2(300, 300));


ImGui::SameLine();
if (reflectionprobes::imgui_cube_surfaces[2])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[2], ImVec2(300, 300));


if (reflectionprobes::imgui_cube_surfaces[3])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[3], ImVec2(300, 300));

ImGui::SameLine();
if (reflectionprobes::imgui_cube_surfaces[4])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[4], ImVec2(300, 300));

ImGui::SameLine();
if (reflectionprobes::imgui_cube_surfaces[5])
ImGui::Image(reflectionprobes::imgui_cube_surfaces[5], ImVec2(300, 300));

ImGui::End();
}
#endif

// debug
//game::GfxRenderTarget* targets = reinterpret_cast<game::GfxRenderTarget*>(0x174F4A8);
//game::GfxRenderTarget* depth = &targets[game::R_RENDERTARGET_FLOAT_Z];

/*ImGui::Begin("Debug", nullptr);
ImGui::Image(postSun->image->texture.data, ImVec2(game::dx->windows[ggui::e_gfxwindow::CCAMERAWND].width, game::dx->windows[ggui::e_gfxwindow::CCAMERAWND].height));
ImGui::End();*/

//if(depth && depth->image && depth->image->texture.data)
//{
// ImGui::Begin("Depthbuffer", nullptr);
// ImGui::Image(depth->image->texture.data, ImVec2(ggui::get_rtt_camerawnd()->scene_size_imgui.x, ggui::get_rtt_camerawnd()->scene_size_imgui.y));
// ImGui::End();
//}
/*if(depth && depth->image && depth->image->texture.data)
{
ImGui::Begin("Depthbuffer", nullptr);
ImGui::Image(depth->image->texture.data, ImVec2(300, 300));
ImGui::End();
}*/

// end the current context frame
goto END_FRAME;
Expand Down
Loading

0 comments on commit 652020b

Please sign in to comment.