Skip to content

Commit

Permalink
Add Script_FontScale
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeto committed Oct 24, 2020
1 parent d6e403d commit 29e0f82
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 0 deletions.
10 changes: 10 additions & 0 deletions source/Scripts/Script_FontScale/Readme_DE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- Script_FontScale ---

0. Description
Verhindert, dass sich die Größe der Fokusnamen in Abhängigkeit von der Auflösung
des Spiels ändert, indem die Schriftgröße des Fokusnamens entsprechend der
Rendering-Auflösung skaliert wird.

1. Installation
Der Ordner 'scripts' muss ins Gothic 3 Installationverzeichnis kopiert werden.
Es ist nicht notwendig ein neues Spiel zu beginnen.
9 changes: 9 additions & 0 deletions source/Scripts/Script_FontScale/Readme_EN.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--- Script_FontScale ---

0. Description
Prevents the size of focus names from changing depending on the resolution of
the game, by scaling the focus name font size according to the rendering resolution.

1. Installation
The 'scripts' folder has to be copied into the Gothic 3 install folder.
There is no need to start a new game.
92 changes: 92 additions & 0 deletions source/Scripts/Script_FontScale/Script_FontScale.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#include "Script_FontScale.h"

#include "util/Memory.h"
#include "util/Hook.h"
#include "util/Util.h"

namespace
{
const GEFloat FOCUS_NAME_FONT_SCALE_FACTOR = 1 / 1080.0f;
const GEInt DEFAULT_FONT_HEIGHT = 24;

void GE_STDCALL DrawFocusNames_UpdateFont(gCGUIEntityRenderer & a_FocusNameRenderer)
{
static GEU32 s_LastViewportHeight = 1080;

eCGfxShared::eSGfxViewport Viewport {};
if (eCGfxAdmin * pGfxAdmin = FindModule<eCGfxAdmin>())
pGfxAdmin->GetAccessToMixer().GetViewport(Viewport);

GEU32 ViewportHeight = Viewport.Height - Viewport.Y;
if(s_LastViewportHeight != ViewportHeight)
{
s_LastViewportHeight = ViewportHeight;

// GUI scaling has changed, recalculate the font size
GEFloat FontScaleHeight = ViewportHeight * FOCUS_NAME_FONT_SCALE_FACTOR;
GEInt FontHeight = RoundFloat(DEFAULT_FONT_HEIGHT * FontScaleHeight);

eSSetupEngine const & Setup = eCApplication::GetInstance().GetSetupEngineDesc();

// Create font
SFFGUIFont FontConfig;
FontConfig.FaceName = Setup.m_DefaultFont;
FontConfig.Height = FontHeight;
FontConfig.Width = 0;
FontConfig.Weight = Setup.m_bDefaultFontBold ? 800 : 400;
FontConfig.CharSet = 1;
FontConfig.OutPrecision = 0;
FontConfig.Quality = 0;
FontConfig.PitchAndFamily = 0;
FontConfig.Italic = 0;

a_FocusNameRenderer.m_FontIndex = eCGUIModule::GetInstance().GetAdmin().CreateFontA(FontConfig);
}
}
}

void ApplyHooks()
{
// The focus name is rendered with a constant pixel size.
// Therefore when in fullscreen mode, the focus name looks larger in lower resolutions,
// and smaller in higher resolutions.

// Update font used for focus name rendering
static mCCallHook Hook_DrawFocusNames_UpdateFont;
Hook_DrawFocusNames_UpdateFont
.Prepare(RVA_Game(0x7981C), &DrawFocusNames_UpdateFont)
.AddRegArg(mCRegisterBase::mERegisterType_Edi) // gCGUIEntityRenderer &
.InsertCall().Hook();
}


gSScriptInit & GetScriptInit()
{
static gSScriptInit s_ScriptInit;
return s_ScriptInit;
}

extern "C" __declspec( dllexport )
gSScriptInit const * GE_STDCALL ScriptInit( void )
{
ApplyHooks();

return &GetScriptInit();
}

//
// Entry Point
//

BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
::DisableThreadLibraryCalls( hModule );
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
8 changes: 8 additions & 0 deletions source/Scripts/Script_FontScale/Script_FontScale.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef SCRIPT_MOUSE_DRAG_H_INCLUDED
#define SCRIPT_MOUSE_DRAG_H_INCLUDED

#include "Script.h"

gSScriptInit & GetScriptInit();

#endif
63 changes: 63 additions & 0 deletions source/Scripts/Script_FontScale/Script_FontScale.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Script_FontScale", "Script_FontScale.vcxproj", "{01579160-3197-46CB-9663-9EB62EFDF62A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Script", "..\..\Script.vcxproj", "{DF45B4AC-7FD2-4C19-9E70-6EE4DC96B604}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Engine", "..\..\Engine.vcxproj", "{F385328B-69B2-4E58-B520-9562EFD53AD8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Game", "..\..\Game.vcxproj", "{F74F8EFB-8610-40F4-BFEC-03FB5D4190D7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GFC", "..\..\GFC.vcxproj", "{84E2573C-0D33-417F-A740-B42636728ABC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedBase", "..\..\SharedBase.vcxproj", "{7823C28A-70F8-484E-A6DC-CCEFEBC34C03}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Importer", "..\..\Importer.vcxproj", "{23213CDA-14E6-4EE1-B018-995D09AE753D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Asmjit", "..\..\Shared\Asmjit\Asmjit.vcxproj", "{32A1BE07-45F2-4B54-9CF0-992DFFC8D06A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{01579160-3197-46CB-9663-9EB62EFDF62A}.Debug|Win32.ActiveCfg = Debug|Win32
{01579160-3197-46CB-9663-9EB62EFDF62A}.Debug|Win32.Build.0 = Debug|Win32
{01579160-3197-46CB-9663-9EB62EFDF62A}.Release|Win32.ActiveCfg = Release|Win32
{01579160-3197-46CB-9663-9EB62EFDF62A}.Release|Win32.Build.0 = Release|Win32
{DF45B4AC-7FD2-4C19-9E70-6EE4DC96B604}.Debug|Win32.ActiveCfg = Debug|Win32
{DF45B4AC-7FD2-4C19-9E70-6EE4DC96B604}.Debug|Win32.Build.0 = Debug|Win32
{DF45B4AC-7FD2-4C19-9E70-6EE4DC96B604}.Release|Win32.ActiveCfg = Release|Win32
{DF45B4AC-7FD2-4C19-9E70-6EE4DC96B604}.Release|Win32.Build.0 = Release|Win32
{F385328B-69B2-4E58-B520-9562EFD53AD8}.Debug|Win32.ActiveCfg = Debug|Win32
{F385328B-69B2-4E58-B520-9562EFD53AD8}.Debug|Win32.Build.0 = Debug|Win32
{F385328B-69B2-4E58-B520-9562EFD53AD8}.Release|Win32.ActiveCfg = Release|Win32
{F385328B-69B2-4E58-B520-9562EFD53AD8}.Release|Win32.Build.0 = Release|Win32
{F74F8EFB-8610-40F4-BFEC-03FB5D4190D7}.Debug|Win32.ActiveCfg = Debug|Win32
{F74F8EFB-8610-40F4-BFEC-03FB5D4190D7}.Debug|Win32.Build.0 = Debug|Win32
{F74F8EFB-8610-40F4-BFEC-03FB5D4190D7}.Release|Win32.ActiveCfg = Release|Win32
{F74F8EFB-8610-40F4-BFEC-03FB5D4190D7}.Release|Win32.Build.0 = Release|Win32
{84E2573C-0D33-417F-A740-B42636728ABC}.Debug|Win32.ActiveCfg = Debug|Win32
{84E2573C-0D33-417F-A740-B42636728ABC}.Debug|Win32.Build.0 = Debug|Win32
{84E2573C-0D33-417F-A740-B42636728ABC}.Release|Win32.ActiveCfg = Release|Win32
{84E2573C-0D33-417F-A740-B42636728ABC}.Release|Win32.Build.0 = Release|Win32
{7823C28A-70F8-484E-A6DC-CCEFEBC34C03}.Debug|Win32.ActiveCfg = Debug|Win32
{7823C28A-70F8-484E-A6DC-CCEFEBC34C03}.Debug|Win32.Build.0 = Debug|Win32
{7823C28A-70F8-484E-A6DC-CCEFEBC34C03}.Release|Win32.ActiveCfg = Release|Win32
{7823C28A-70F8-484E-A6DC-CCEFEBC34C03}.Release|Win32.Build.0 = Release|Win32
{23213CDA-14E6-4EE1-B018-995D09AE753D}.Debug|Win32.ActiveCfg = Debug|Win32
{23213CDA-14E6-4EE1-B018-995D09AE753D}.Debug|Win32.Build.0 = Debug|Win32
{23213CDA-14E6-4EE1-B018-995D09AE753D}.Release|Win32.ActiveCfg = Release|Win32
{23213CDA-14E6-4EE1-B018-995D09AE753D}.Release|Win32.Build.0 = Release|Win32
{32A1BE07-45F2-4B54-9CF0-992DFFC8D06A}.Debug|Win32.ActiveCfg = Debug|Win32
{32A1BE07-45F2-4B54-9CF0-992DFFC8D06A}.Debug|Win32.Build.0 = Debug|Win32
{32A1BE07-45F2-4B54-9CF0-992DFFC8D06A}.Release|Win32.ActiveCfg = Release|Win32
{32A1BE07-45F2-4B54-9CF0-992DFFC8D06A}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
109 changes: 109 additions & 0 deletions source/Scripts/Script_FontScale/Script_FontScale.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{01579160-3197-46CB-9663-9EB62EFDF62A}</ProjectGuid>
<RootNamespace>Script_FontScale</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\GothicScriptsRelease.props" />
<Import Project="..\..\Shared\Asmjit\Asmjit.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\GothicScriptsDebug.props" />
<Import Project="..\..\Shared\Asmjit\Asmjit.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>12.0.30501.0</_ProjectFileVersion>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>.\;..\..\Shared\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling />
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<AdditionalIncludeDirectories>.\;..\..\Shared\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ExceptionHandling />
</ClCompile>
<Link />
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\Shared\util\AsmjitUtil.cpp" />
<ClCompile Include="..\..\Shared\util\Debug.cpp" />
<ClCompile Include="..\..\Shared\util\Hook.cpp" />
<ClCompile Include="..\..\Shared\util\Logging.cpp" />
<ClCompile Include="..\..\Shared\util\Memory.cpp" />
<ClCompile Include="..\..\Shared\util\Util.cpp" />
<ClCompile Include="Script_FontScale.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Shared\util\AsmjitUtil.h" />
<ClInclude Include="..\..\Shared\util\Debug.h" />
<ClInclude Include="..\..\Shared\util\Hook.h" />
<ClInclude Include="..\..\Shared\util\Logging.h" />
<ClInclude Include="..\..\Shared\util\Memory.h" />
<ClInclude Include="..\..\Shared\util\Util.h" />
<ClInclude Include="Script_FontScale.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Shared\util\Logging.inl" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Engine.vcxproj">
<Project>{f385328b-69b2-4e58-b520-9562efd53ad8}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Game.vcxproj">
<Project>{f74f8efb-8610-40f4-bfec-03fb5d4190d7}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\GFC.vcxproj">
<Project>{84e2573c-0d33-417f-a740-b42636728abc}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Importer.vcxproj">
<Project>{23213cda-14e6-4ee1-b018-995d09ae753d}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Script.vcxproj">
<Project>{df45b4ac-7fd2-4c19-9e70-6ee4dc96b604}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\SharedBase.vcxproj">
<Project>{7823c28a-70f8-484e-a6dc-ccefebc34c03}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\..\Shared\Asmjit\Asmjit.vcxproj">
<Project>{32a1be07-45f2-4b54-9cf0-992dffc8d06a}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
55 changes: 55 additions & 0 deletions source/Scripts/Script_FontScale/Script_FontScale.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="util">
<UniqueIdentifier>{a473925b-9924-47ad-b92f-dc6fbaf970cb}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\Shared\util\AsmjitUtil.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="..\..\Shared\util\Debug.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="..\..\Shared\util\Hook.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="..\..\Shared\util\Logging.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="..\..\Shared\util\Memory.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="..\..\Shared\util\Util.cpp">
<Filter>util</Filter>
</ClCompile>
<ClCompile Include="Script_FontScale.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\Shared\util\AsmjitUtil.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="..\..\Shared\util\Debug.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="..\..\Shared\util\Hook.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="..\..\Shared\util\Logging.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="..\..\Shared\util\Memory.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="..\..\Shared\util\Util.h">
<Filter>util</Filter>
</ClInclude>
<ClInclude Include="Script_FontScale.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\Shared\util\Logging.inl">
<Filter>util</Filter>
</None>
</ItemGroup>
</Project>

0 comments on commit 29e0f82

Please sign in to comment.