|
|
by hzqst
- #define R_STUDIOLIGHTING_SIG "\x51\xDB\x05\x2A\x2A\x2A\x2A\x8A\x4C\x24\x10\xB8\x01\x00\x00\x00\x84\xC8\xD9\x5C\x24\x00"
- #define R_STUDIOLIGHTING_SIG_NEW "\x55\x8B\xEC\x51\xDB\x05\x2A\x2A\x2A\x2A\x8A\x4D\x10\xB8\x01\x00\x00\x00\x84\xC8\xD9\x5D\xFC"
- #define STUDIO_NF_FULLBRIGHT 0x0004
- typedef struct
- {
- void (*R_StudioLighting)(float *lv, int bone, int flags, vec3_t normal);
- void (*R_StudioSetupLighting)(alight_t *plighting);
- }studiofuncs_t;
- studiofuncs_t gStudioFuncs;
- void InstallHook(void)
- {
- if(g_dwEngineBuildnum >= 5953)
- gStudioFuncs.R_StudioLighting = (void (*)(float *, int, int, vec3_t))g_pMetaHookAPI->SearchPattern((void *)g_dwEngineBase, g_dwEngineSize, R_STUDIOLIGHTING_SIG_NEW, sizeof(R_STUDIOLIGHTING_SIG_NEW)-1);
- else
- gStudioFuncs.R_StudioLighting = (void (*)(float *, int, int, vec3_t))g_pMetaHookAPI->SearchPattern((void *)g_dwEngineBase, g_dwEngineSize, R_STUDIOLIGHTING_SIG, sizeof(R_STUDIOLIGHTING_SIG)-1);
- g_pMetaHookAPI->InlineHook(gStudioFuncs.R_StudioLighting, R_StudioLighting, (void *&)gStudioFuncs.R_StudioLighting);
- g_pMetaHookAPI->InlineHook(gStudioFuncs.R_StudioSetupLighting, R_StudioSetupLighting, (void *&)gStudioFuncs.R_StudioSetupLighting);
- }
- int HUD_GetStudioModelInterface(int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio)
- {
- gStudioFuncs.R_StudioSetupLighting = pstudio->StudioSetupLighting;
- InstallHook();
- return gExportFuncs.HUD_GetStudioModelInterface(version, ppinterface, pstudio);
- }
- alight_t g_savedLighting;
- void R_StudioSetupLighting(alight_t *plighting)
- {
- memcpy(&g_savedLighting, plighting, sizeof(alight_t));
- gStudioFuncs.R_StudioSetupLighting(plighting);
- }
- void R_StudioLighting(float *lv, int bone, int flags, vec3_t normal)
- {
- if(flags & STUDIO_NF_FULLBRIGHT)
- {
- //save the lighting strength at first.
- int r_ambientlight = g_savedLighting.ambientlight;
- float r_shadelight = g_savedLighting.shadelight;
- //changed to whatever you want
- g_savedLighting.ambientlight = 192;
- g_savedLighting.shadelight = 128.0f;
- //then call the original StudioSetupLighting to modify engine's r_ambientlight & r_shadelight.
- gStudioFuncs.studioapi_StudioSetupLighting(&g_savedLighting);
- //then call the original func the calculate the lighting value (lv)
- gHookFuncs.R_StudioLighting(lv, bone, flags, normal);
- //or you can just set *lv = 1 if you want it fullbright, if you do this way, there is no need to save or change the global lighting strength.
- //*lv = 1;
- //then set the lighting value back;
- g_savedLighting.ambientlight = r_ambientlight;
- g_savedLighting.shadelight = r_shadelight;
- //then call the original StudioSetupLighting to set engine's r_ambientlight & r_shadelight back.
- gStudioFuncs.studioapi_StudioSetupLighting(&g_savedLighting);
- return;
- }
- //nothing to do, just do the original way.
- gHookFuncs.R_StudioLighting(lv, bone, flags, normal);
- }
复制代码 |
|