Skip to content

Commit

Permalink
try fixing sw mode "false positives"
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokko committed Jun 24, 2022
1 parent f2f9879 commit 60bca4a
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 1,089 deletions.
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.0)

project(csldr)

set(OUTDIR CACHE STRING "Directory to output library to")

if (MSVC)
add_compile_options(/W4 /WX /wd4244)
else()
Expand Down Expand Up @@ -32,5 +34,17 @@ if (MSVC)
set_source_files_properties(${SRCDIR}/csldr/pch.c PROPERTIES COMPILE_FLAGS "/Ycpch.h")
endif()

if (WIN32)
target_link_libraries(csldr PRIVATE opengl32)
endif()

set_target_properties(csldr PROPERTIES OUTPUT_NAME "client")
set_target_properties(csldr PROPERTIES PREFIX "")

# from csgo-lite
if (OUTDIR)
add_custom_command(TARGET csldr POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
$<TARGET_FILE:csldr>
${OUTDIR}/$<TARGET_FILE_NAME:csldr>)
endif()
20 changes: 9 additions & 11 deletions csldr/cdll_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ cldll_func_t cl_funcs;
void *(*pCreateInterface)(const char *, int *);

bool isCzero;
bool isSoftware;

float clientTime;

Expand Down Expand Up @@ -73,16 +72,6 @@ void Hk_HudInit(void)

cl_funcs.pHudInitFunc();

/* we have to know if software mode is enabled so we can disable all of the cool features */
#if defined(_WIN32)
isSoftware = !GetModuleHandleA("hw.dll");
#else
isSoftware = false;
#endif

if (!isSoftware)
GL_Load(); /* bad place for this */

ViewInit();
HudInit();
InspectInit();
Expand Down Expand Up @@ -115,6 +104,15 @@ void Hk_HudShutdown(void)

void Hk_HudFrame(double time)
{
static bool bitched;

if (!bitched)
{
if (isSoftware)
gEngfuncs.Con_Printf("Running in software mode. Some features of csldr will not work.\n");
bitched = true;
}

clientTime = gEngfuncs.GetClientTime();
cl_funcs.pHudFrame(time);
}
Expand Down
1 change: 0 additions & 1 deletion csldr/cl_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ extern cldll_func_t cl_funcs;
extern void *(*pCreateInterface)(const char *, int *);

extern bool isCzero;
extern bool isSoftware;

extern float clientTime;

Expand Down
695 changes: 0 additions & 695 deletions csldr/gl_load.c

This file was deleted.

338 changes: 0 additions & 338 deletions csldr/gl_load.h

This file was deleted.

29 changes: 11 additions & 18 deletions csldr/hud_crosshair.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ cvar_t *cl_crosshair_translucent;

void HudInit(void)
{
if (isSoftware)
{
/* crosshair relies on opengl */
can_xhair = false;
return;
}

CVAR_ARHCIVE_FAST(xhair_enable, 0);

CVAR_ARHCIVE_FAST(xhair_gap, 4);
Expand Down Expand Up @@ -57,20 +50,20 @@ int ScaleForRes(int value, int height)

void DrawQuad(int x0, int y0, int x1, int y1, float r, float g, float b)
{
GL_Disable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_2D);

GL_Color3f(r, b, g);
glColor3f(r, b, g);

GL_Begin(GL_QUADS);
GL_Vertex2i(x0, y0);
GL_Vertex2i(x1, y0);
GL_Vertex2i(x1, y1);
GL_Vertex2i(x0, y1);
GL_End();
glBegin(GL_QUADS);
glVertex2i(x0, y0);
glVertex2i(x1, y0);
glVertex2i(x1, y1);
glVertex2i(x0, y1);
glEnd();

GL_Color3f(1.0f, 1.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);

GL_Enable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_2D);
}

void DrawCrosshairSection(int x0, int y0, int x1, int y1)
Expand Down Expand Up @@ -160,7 +153,7 @@ int Hk_HudRedraw(float time, int intermission)
float old_trans;
char old_color[2];

if (!can_xhair || !xhair_enable->value)
if (isSoftware || !can_xhair || !xhair_enable->value)
return cl_funcs.pHudRedrawFunc(time, intermission);

/* stupid hack, the memory is always writable though */
Expand Down
1 change: 0 additions & 1 deletion csldr/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ typedef struct
#include "camera.h"
#include "cl_dll.h"
#include "fov.h"
#include "gl_load.h"
#include "inspect.h"
#include "passthrough.h"
#include "platform.h"
Expand Down
14 changes: 4 additions & 10 deletions csldr/shell.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "pch.h"

bool can_shell;
cvar_t *mirror_shell;
cvar_t *cl_righthand;

Expand All @@ -11,20 +10,15 @@ vec3_t shellVelocity;

void ShellInit(void)
{
can_shell = !isSoftware;

if (can_shell)
{
cl_righthand = gEngfuncs.pfnGetCvarPointer("cl_righthand");
mirror_shell = gEngfuncs.pfnRegisterVariable("mirror_shell", "1", FCVAR_ARCHIVE);
}
cl_righthand = gEngfuncs.pfnGetCvarPointer("cl_righthand");
mirror_shell = gEngfuncs.pfnRegisterVariable("mirror_shell", "1", FCVAR_ARCHIVE);
}

int (*Og_MsgFunc_Brass)(const char *pszName, int iSize, void *pbuf);

int Hk_MsgFunc_Brass(const char *pszName, int iSize, void *pbuf)
{
if (can_shell && mirror_shell->value)
if (!isSoftware && mirror_shell->value)
{
/* save origin and velocity, we'll flip them later in R_TempModel */
BEGIN_READ(pbuf, iSize);
Expand Down Expand Up @@ -116,7 +110,7 @@ TEMPENTITY *Hk_TempModel(float *pos,
void Hk_ ## name(event_args_t * args) \
{ \
float value; \
if (!can_shell || !mirror_shell->value) \
if (isSoftware || !mirror_shell->value) \
{ \
Og_ ## name(args); \
return; \
Expand Down
29 changes: 21 additions & 8 deletions csldr/studiorenderer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"

bool isSoftware;

engine_studio_api_t IEngineStudio;
r_studio_interface_t studio;

Expand Down Expand Up @@ -71,6 +73,9 @@ void RestoreModelOrigin(studiohdr_t *hdr)
int i;
mstudiobone_t *bone;

if (!hdr)
return;

bone = (mstudiobone_t *)((byte *)hdr + hdr->boneindex);

for (i = 0; i < hdr->numbones; i++, bone++)
Expand Down Expand Up @@ -129,19 +134,19 @@ int Hk_StudioDrawModel(int flags)
/* viewmodel fov only supported on hardware */
if (!isSoftware)
{
GL_MatrixMode(GL_PROJECTION);
GL_PushMatrix();
GL_LoadIdentity();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

fov1 = viewmodel_fov->value * fovDifference;
fov2 = CLAMP(fov1, 1.0f, 170.0f);
fov = CalcVerticalFov(fov2);

top = tan(RAD(fov) / 2.0f) * Z_NEAR;

GL_Frustum(-top * aspect, top * aspect, -top, top, Z_NEAR, Z_FAR);
glFrustum(-top * aspect, top * aspect, -top, top, Z_NEAR, Z_FAR);

GL_MatrixMode(GL_MODELVIEW);
glMatrixMode(GL_MODELVIEW);
}

/* think about inspecting now since we're about to draw the vm */
Expand All @@ -163,9 +168,9 @@ int Hk_StudioDrawModel(int flags)
/* viewmodel fov only supported on hardware */
if (!isSoftware)
{
GL_MatrixMode(GL_PROJECTION);
GL_PopMatrix();
GL_MatrixMode(GL_MODELVIEW);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

return result;
Expand All @@ -192,6 +197,12 @@ void Hk_StudioSetupModel(int bodypart, void **ppbodypart, void **ppsubmodel)

/* check if bodypart is right */
studiohdr = (studiohdr_t *)entity->model->cache.data;
if (!studiohdr) /* what the fuck */
{
IEngineStudio.StudioSetupModel(bodypart, ppbodypart, ppsubmodel);
return;
}

body = (mstudiobodyparts_t *)((byte *)studiohdr + studiohdr->bodypartindex) + bodypart;

/* check if the names matches and that there's enough submodels */
Expand Down Expand Up @@ -236,5 +247,7 @@ int Hk_GetStudioModelInterface(int version,
memcpy(&studio, (*ppinterface), sizeof(studio));
(*ppinterface)->StudioDrawModel = Hk_StudioDrawModel;

isSoftware = !pstudio->IsHardware();

return result;
}
2 changes: 2 additions & 0 deletions csldr/studiorenderer.h
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
extern bool isSoftware;

int Hk_GetStudioModelInterface(int version, r_studio_interface_t **ppinterface, engine_studio_api_t *pstudio);
10 changes: 3 additions & 7 deletions csldr/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ cvar_t *cl_mirror_knife;

void ViewInit(void)
{
if (!isSoftware)
CVAR_ARHCIVE_FAST(viewmodel_fov, 68);
CVAR_ARHCIVE_FAST(viewmodel_fov, 68);

CVAR_ARHCIVE_FAST(viewmodel_shift, 0);
CVAR_ARHCIVE_FAST(viewmodel_offset_x, 0);
Expand All @@ -60,13 +59,10 @@ void ViewInit(void)
CVAR_ARHCIVE_FAST(viewmodel_lag_scale, 1.0);
CVAR_ARHCIVE_FAST(viewmodel_lag_speed, 8.0);

if (!isSoftware)
CVAR_ARHCIVE_FAST(fov_horplus, 1);

CVAR_ARHCIVE_FAST(fov_horplus, 1);
CVAR_ARHCIVE_FAST(fov_lerp, 0.1);

if (!isSoftware)
CVAR_ARHCIVE_FAST(cl_mirror_knife, 1);
CVAR_ARHCIVE_FAST(cl_mirror_knife, 1);
}

struct
Expand Down

0 comments on commit 60bca4a

Please sign in to comment.