I know about the old scripting way but I’ve been trying to get a neater solution recently using PowerShell.
I wrote a module and placed it before the main class in the scripts list:
Then I called this at the top of the Main Class:
This part seemed to work fine calling the PowerShell script:
Now the PowerShell script appears to be running fine but the game just stopes after this script finishes. If I put a read-host at the end it shows this getting through the script without error.
But the game itself just seems to close then. I'm not really sure why as the script is running outwith the game.
I know it isn't the:
lines after I call the script code as these were already tested before trying to add the script.
The idea is that if I can load a font into Windows temporarily in the current session from within the game it should be usable by the game then get dropped when the game ends.
Has anybody else tried this, can it work and I'm just doing something wrong?
I wrote a module and placed it before the main class in the scripts list:
Ruby:
module FontLoaderPS
def self.load_font(font_filename)
font_path = File.expand_path("Font/#{font_filename}")
ps_script = "powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File \"PowerShell\\LoadFont.ps1\" -FontPath \"#{font_path}\""
system_output = `#{ps_script}`
end
end
Then I called this at the top of the Main Class:
Ruby:
begin
#First set the Font
FontLoaderPS.load_font("Mordred.ttf")
$defaultfonttype = $fontface = $fontname = Font.default_name = "Mordred"
$defaultfontsize = $fontsize = Font.default_size = 18
This part seemed to work fine calling the PowerShell script:
Code:
#PowerShell
param(
[Parameter(Mandatory=$true)]
[string]$FontPath
)
# --- FONT LOADING LOGIC ---
function Load-TemporaryFont {
$AbsoluteFontPath = (Resolve-Path $FontPath).Path
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class FontLoader {
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr AddFontResource(string lpszFilename);
[DllImport("gdi32.dll", CharSet = CharSet.Auto)]
public static extern int RemoveFontResource(string lpszFilename);
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
// Constants for broadcasting the font change to the system
public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
public static readonly int WM_FONTCHANGE = 0x001d;
}
"@
[FontLoader]::AddFontResource($AbsoluteFontPath)
[FontLoader]::SendMessage([FontLoader]::HWND_BROADCAST, [FontLoader]::WM_FONTCHANGE, 0, 0)
Write-Output "Font successfully loaded for session: $AbsoluteFontPath"
}
# Load the font immediately when the script runs
Load-TemporaryFont
Now the PowerShell script appears to be running fine but the game just stopes after this script finishes. If I put a read-host at the end it shows this getting through the script without error.
But the game itself just seems to close then. I'm not really sure why as the script is running outwith the game.
I know it isn't the:
Ruby:
$defaultfonttype = $fontface = $fontname = Font.default_name = "Mordred"
$defaultfontsize = $fontsize = Font.default_size = 18 commands.
The idea is that if I can load a font into Windows temporarily in the current session from within the game it should be usable by the game then get dropped when the game ends.
Has anybody else tried this, can it work and I'm just doing something wrong?