Skip to content

Commit

Permalink
Fix some FBO related issues, fix Nightvision crash, updated GTA HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedSnark committed Nov 13, 2024
1 parent 4868780 commit d111147
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 33 deletions.
7 changes: 5 additions & 2 deletions GSChaos/CFeatureCreepypasta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const char* CFeatureCreepypasta::GetFeatureName()

void CFeatureCreepypasta::SwapBuffers()
{
int width = ImGui::GetIO().DisplaySize.x;
int height = ImGui::GetIO().DisplaySize.y;
int width = gImGui.m_vecRealDisplaySize.x;
int height = gImGui.m_vecRealDisplaySize.y;

glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
glEnable(GL_BLEND);
Expand All @@ -49,6 +49,8 @@ void CFeatureCreepypasta::SwapBuffers()

glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_COPY_INVERTED);

glViewport(0, 0, gImGui.m_vecRealDisplaySize.x, gImGui.m_vecRealDisplaySize.y);

glBegin(GL_QUADS);
glTexCoord2f(0, 0);
Expand Down Expand Up @@ -79,6 +81,7 @@ void CFeatureCreepypasta::SwapBuffers()
glEnd();

// Restore OpenGL states

glMatrixMode(GL_PROJECTION);
glPopMatrix();

Expand Down
81 changes: 58 additions & 23 deletions GSChaos/CFeatureGTA3HUD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ void HOOKED_S_StartDynamicSound(int entnum, int entchannel, sfx_t* sfx, vec_t* o
return;
}

if (strstr(sfx->name, "items/9mmclip1.wav"))
{
ChaosLoud::EmitSound(SND_GTA_AMMO);
return;
}

if (strstr(sfx->name, "items/smallmedkit1.wav"))
{
ChaosLoud::EmitSound(g_bActivatedGTA3HUD ? SND_GTA3_ITEM_PICKUP : SND_GTAVC_ITEM_PICKUP);
Expand Down Expand Up @@ -328,6 +334,8 @@ void CFeatureGTA3HUD::ActivateFeature()

m_bActivated = true;

m_flFlashHealthTime = 0.0f;

g_bActivatedGTAVCHUD = false;
g_bActivatedGTA3HUD = false;

Expand Down Expand Up @@ -361,6 +369,8 @@ void CFeatureGTA3HUD::Draw()
if (CLWrapper::GetPausedState())
return;

static int oldHealth;

DrawNotify();

ImVec4 armorColor = g_bActivatedGTA3HUD ? ImVec4(GTA3_HUD_ARMOR_COLOR, 255.0f / 255.0f) : ImVec4(GTAVC_HUD_ARMOR_COLOR, 255.0f / 255.0f);
Expand Down Expand Up @@ -408,32 +418,40 @@ void CFeatureGTA3HUD::Draw()

GLuint textureID = g_bActivatedGTA3HUD ? g_ActiveWeapon->iiiTextureID : g_ActiveWeapon->vcTextureID;

if ((gChaos.GetFrameCount() & 16) && (*sv_player)->v.health < 10.0f)
int health = (int)(*sv_player)->v.health;
int armor = (int)(*sv_player)->v.armorvalue;

if (oldHealth > health)
m_flFlashHealthTime = pEngfuncs->GetAbsoluteTime() + 0.25f;

if ((ImGui::GetFrameCount() & 8) && (health < 10.0f || m_flFlashHealthTime > pEngfuncs->GetAbsoluteTime()))
m_bFlashHealth = true;
else
m_bFlashHealth = false;

oldHealth = health;

ImVec2 screenPos = ImVec2(ImGui::GetIO().DisplaySize.x - 384, ImGui::GetIO().DisplaySize.y - (ImGui::GetIO().DisplaySize.y / 1.05f));

ImGui::SetNextWindowPos(screenPos, ImGuiCond_Always);
ImGui::SetNextWindowSize(ImVec2(ImGui::GetIO().DisplaySize.x - screenPos.x, ImGui::GetIO().DisplaySize.y - screenPos.y), ImGuiCond_Always);
if (ImGui::Begin("#GTAHUD", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoSavedSettings))
{
ImVec2 previousPos, curPos;
static ImVec2 iconPos = ImVec2(0.0f,0.0f);
static ImVec2 iconPos = ImVec2(0.0f, 0.0f);

ImGui::Spacing();
ImGui::Spacing();

//==========================

// DRAW ARMOR (FOR POSITION)
ImGui::Image((void*)nullptr, ImVec2(56.0f / 1.75f, 51.0f / 1.75f));

ImGui::SameLine();
ImGui::PushFont(gChaos.m_pPricedown);

ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", (int)(*sv_player)->v.armorvalue);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", armor);

ImGui::PopFont();

Expand All @@ -445,7 +463,7 @@ void CFeatureGTA3HUD::Draw()
ImGui::SameLine();
ImGui::PushFont(gChaos.m_pPricedown);

ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", (int)(*sv_player)->v.health);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", health);
ImGui::PopFont();

curPos = ImGui::GetCursorPos();
Expand All @@ -455,7 +473,7 @@ void CFeatureGTA3HUD::Draw()
// DRAW WEAPON ICON

ImGui::SameLine();

ImVec2 weaponIconPos = ImGui::GetCursorPos();
ImGui::Image((void*)textureID, ImVec2(128, 128));

Expand All @@ -464,7 +482,7 @@ void CFeatureGTA3HUD::Draw()
// DRAW ARMOR
ImGui::SetCursorPosY(curPos.y + 24.0f);

if ((*sv_player)->v.armorvalue > 0.0f)
if (armor > 0.0f)
{
ImVec2 armorIconPos = ImGui::GetCursorPos();
// SHADOW
Expand All @@ -481,21 +499,21 @@ void CFeatureGTA3HUD::Draw()
ImGui::SameLine();
ImGui::PushFont(gChaos.m_pPricedown);

if ((*sv_player)->v.armorvalue > 0.0f)
if (armor > 0)
{
ImVec2 armorPos = ImGui::GetCursorPos();

// SHADOW
ImGui::SetCursorPos(ImVec2(armorPos.x + 2, armorPos.y + 2));
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 255.0f / 255.0f), "%03d", (int)(*sv_player)->v.armorvalue);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 255.0f / 255.0f), "%03d", armor);

// REAL
ImGui::SetCursorPos(armorPos);

ImGui::TextColored(armorColor, "%03d", (int)(*sv_player)->v.armorvalue);
ImGui::TextColored(armorColor, "%03d", armor);
}
else
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", (int)(*sv_player)->v.armorvalue);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", armor);

ImGui::PopFont();

Expand All @@ -522,31 +540,48 @@ void CFeatureGTA3HUD::Draw()

if (m_bFlashHealth)
{
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", (int)(*sv_player)->v.health);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 0.0f), "%03d", health);
}
else
{
ImVec2 healthPos = ImGui::GetCursorPos();
ImGui::SetCursorPos(ImVec2(healthPos.x + 2, healthPos.y + 2));
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 1.0f), "%03d", (int)(*sv_player)->v.health);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 1.0f), "%03d", health);

ImGui::SetCursorPos(healthPos);
ImGui::TextColored(healthColor, "%03d", (int)(*sv_player)->v.health);
ImGui::TextColored(healthColor, "%03d", health);
}

ImGui::PopFont();

// DRAW WEAPON AMMO
/*
ImGui::SetCursorPos(ImVec2(weaponIconPos.x + 64, weaponIconPos.y + 96));
ImGui::PushFont(m_pArialBlack);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 1.0f), "%i/%i", g_ActiveWeapon->iClip, g_ActiveWeapon->iAmmo);
ImGui::PopFont();
ImGui::GetForegroundDrawList()->AddText(m_pArialBlack, 24.0f, weaponIconPos, ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f)), UTIL_VarArgs("%i/%i", g_ActiveWeapon->iClip, g_ActiveWeapon->iAmmo));
*/

// TODO: FINALLY GET PROPER AMMO/CLIP INFORMATION
if (g_bActivatedGTAVCHUD)
{
char buffer[16];
//sprintf_s(buffer, "%d/%d", g_ActiveWeapon->iClip, g_ActiveWeapon->iAmmo);
sprintf_s(buffer, "69/420");

ImVec2 ammoTextSize = gChaos.m_pArborcrest->CalcTextSizeA(22.0f, FLT_MAX, 0.0f, buffer);

ImVec2 centeredPos = ImVec2(
(weaponIconPos.x + 64) - (ammoTextSize.x / 2.0f),
(weaponIconPos.y + 144) - (ammoTextSize.y / 2.0f)
);

ImGui::SetCursorPos(ImVec2(centeredPos.x + 2.0f, centeredPos.y + 2.0f));
ImGui::PushFont(gChaos.m_pArborcrest);
ImGui::TextColored(ImVec4(0.0f, 0.0f, 0.0f, 1.0f), "%s", buffer);
ImGui::PopFont();

ImGui::SetCursorPos(centeredPos);
ImGui::PushFont(gChaos.m_pArborcrest);
ImGui::TextColored(ImVec4(GTAVC_HUD_HEALTH_COLOR, 1.0f), "%s", buffer);
ImGui::PopFont();
}

ImGui::End();
//ImGui::GetWindowDrawList()->AddImage((void*)g_ActiveWeapon->textureID, ImVec2(0.0f, 0.0f), ImVec2(ImGui::GetIO().DisplaySize.x, ImGui::GetIO().DisplaySize.y), ImVec2(0, 0), ImVec2(1, 1));
}
}

Expand Down
1 change: 1 addition & 0 deletions GSChaos/CFeatureGTA3HUD.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CFeatureGTA3HUD : public CChaosFeature
bool m_bFlashHealth;
bool m_bNotificationActive;
double m_notifyStartTime;
float m_flFlashHealthTime;
const char* m_notifyMessage;
};

Expand Down
6 changes: 4 additions & 2 deletions GSChaos/CFeatureMirrorScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ bool CFeatureMirrorScreen::UseCustomDuration()

void CFeatureMirrorScreen::SwapBuffers()
{
int width = ImGui::GetIO().DisplaySize.x;
int height = ImGui::GetIO().DisplaySize.y;
int width = gImGui.m_vecRealDisplaySize.x;
int height = gImGui.m_vecRealDisplaySize.y;

glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
glEnable(GL_BLEND);
Expand All @@ -64,6 +64,8 @@ void CFeatureMirrorScreen::SwapBuffers()

glColor4f(1, 1, 1, 1);

glViewport(0, 0, gImGui.m_vecRealDisplaySize.x, gImGui.m_vecRealDisplaySize.y);

glBegin(GL_QUADS);

glTexCoord2f(width, 0);
Expand Down
6 changes: 6 additions & 0 deletions GSChaos/CFeatureNightvision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ void CFeatureNightvision::Draw()
if (!IsActive())
return;

if (m_nvSprite == NULL)
{
m_nvSprite = LoadSprite("../chaos/of_nv_b.spr");
return;
}

// Top left of the screen.
int x, y;
x = y = 0;
Expand Down
1 change: 1 addition & 0 deletions GSChaos/ChaosLoudManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace ChaosLoud
g_wBank[SND_BEAMSTART5].load("chaos/beamstart5.wav");
g_wBank[SND_PAIN].load("chaos/pl_pain2.wav");
g_wBank[SND_XBOW_HIT].load("chaos/xbow_hit.wav");
g_wBank[SND_GTA_AMMO].load("chaos/gta_ammo.wav");
}

void EmitSound(int idx)
Expand Down
1 change: 1 addition & 0 deletions GSChaos/ChaosLoudManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum
SND_BEAMSTART5,
SND_PAIN,
SND_XBOW_HIT,
SND_GTA_AMMO,
SOUNDBANK_SIZE
};

Expand Down
7 changes: 5 additions & 2 deletions GSChaos/GSChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int __stdcall HOOKED_wglSwapBuffers(HDC a1)
// -------------------------

glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);

ImGui::Render();
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
}
Expand Down Expand Up @@ -303,9 +304,11 @@ void HOOKED_HUD_Frame(double time)
{
gChaos.Init();

ImVec2 realDisplaySize = gImGui.m_vecRealDisplaySize;

// create a load of blank pixels to create textures with
unsigned char* pBlankTex = new unsigned char[ImGui::GetIO().DisplaySize.x * ImGui::GetIO().DisplaySize.y * 3];
memset(pBlankTex, 0, ImGui::GetIO().DisplaySize.x * ImGui::GetIO().DisplaySize.y * 3);
unsigned char* pBlankTex = new unsigned char[realDisplaySize.x * realDisplaySize.y * 3];
memset(pBlankTex, 0, realDisplaySize.x * realDisplaySize.y * 3);

// Create the SCREEN-HOLDING TEXTURE
glBindTexture(GL_TEXTURE_RECTANGLE_NV, 32767);
Expand Down
6 changes: 6 additions & 0 deletions GSChaos/GSChaos.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@
<ClCompile Include="CFeatureInvertMovementInputs.cpp">
<Filter>Effects</Filter>
</ClCompile>
<ClCompile Include="CFeatureOHKO.cpp">
<Filter>Effects</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="includes.h" />
Expand Down Expand Up @@ -1276,6 +1279,9 @@
<ClInclude Include="CFeatureInvertMovementInputs.h">
<Filter>Effects</Filter>
</ClInclude>
<ClInclude Include="CFeatureOHKO.h">
<Filter>Effects</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Hooking">
Expand Down
6 changes: 4 additions & 2 deletions GSChaos/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ bool CImGuiManager::CanUseEngineResolution()
return (ScreenWidth > 0 && ScreenHeight > 0);
}

void CImGuiManager::UpdateResolution(ImVec2& displaySize, ImVec2& frameBufferScale)
void CImGuiManager::UpdateResolution(ImVec2& displaySize, ImVec2& frameBufferScale, ImVec2 realDisplaySize)
{
m_vecRealDisplaySize = realDisplaySize;
displaySize = ImVec2(ScreenWidth, ScreenHeight);
//frameBufferScale = ImVec2(1, 1);
}
Expand All @@ -62,7 +63,8 @@ void CImGuiManager::Draw()

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

glViewport(0, 0, ScreenWidth, ScreenHeight);
glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);

ImGui::Render();
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
}
4 changes: 3 additions & 1 deletion GSChaos/imgui_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class CImGuiManager
void Init();
void InitBackends(void* hwnd);
bool CanUseEngineResolution();
void UpdateResolution(ImVec2& displaySize, ImVec2& frameBufferScale);
void UpdateResolution(ImVec2& displaySize, ImVec2& frameBufferScale, ImVec2 realDisplaySize);
void Draw();

ImVec2 m_vecRealDisplaySize;
};

#endif //IMGUI_MANAGER_HPP_GUARD
Expand Down
2 changes: 2 additions & 0 deletions GSChaos/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
#include "CLWrapper.h"
#include "in_camera.h"

extern CImGuiManager gImGui;

extern void* g_lpClient;
extern void* g_lpOpenGL32;
extern void* g_lpHW;
Expand Down
2 changes: 1 addition & 1 deletion external/imgui/backends/imgui_impl_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void ImGui_ImplWin32_NewFrame()
::GetClientRect(bd->hWnd, &rect);
if (gImGui.CanUseEngineResolution())
{
gImGui.UpdateResolution(io.DisplaySize, io.DisplayFramebufferScale);
gImGui.UpdateResolution(io.DisplaySize, io.DisplayFramebufferScale, ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top)));
}
else
io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
Expand Down

0 comments on commit d111147

Please sign in to comment.