[XP] Memory Font Loader

Started by ForeverZer0, January 08, 2014, 08:46:25 am

Previous topic - Next topic

ForeverZer0

January 08, 2014, 08:46:25 am Last Edit: December 17, 2014, 07:35:32 am by ForeverZer0
Memory Font Loader
Authors: ForeverZer0
Version: 1.1
Type: Game Utility
Key Term: Game Utility



Introduction

Small script that allows for loading and using fonts into memory at run-time without the need for installing them on the operating system. The advantage of this script over others, such as Wachunga's font-install script, is that it does not require a administrator privileges to use the fonts, nor a restart of the game after running.



Features


  • Automatically load all fonts found in user-defined folder

  • Supports TrueType (*.ttf) and OpenType(*.otf) fonts

  • Does not require Administrator privileges

  • Does not require a game restart

  • Plug & play




Screenshots

None.


Demo

None.


Script

Spoiler: ShowHide

#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Memory Font Loader
# Author: ForeverZer0
# Version: 1.1
# Date: 12.17.2014
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#                             VERSION HISTORY
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# v.1.0   1.8.2014
#   - Original Release
# v.1.1   12.17.2014
#   - Improved compatibility on different systems by adding "AddFontResource"
#     as backup call if "AddFontResourceEx" fails
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#
# Introduction:
#
#   Small script that allows for loading and using fonts into memory at run-time
#   without the need for installing them on the operating system. The advantage
#   of this script over others, such as Wachunga's font-install script, is that
#   it does not require a administrator privileges to use the fonts, nor a
#   restart of the game after running.
#
# Features:
#
#   - Automatically load all fonts found in user-defined folder
#   - Supports TrueType (*.ttf) and OpenType(*.otf) fonts
#   - Does not require Administrator privileges
#   - Does not require a game restart
#
# Instructions:
#   
#   - Place script anywhere above main
#   - Some optional configuration below with explanation
#   - Use the script call "Font.add(PATH_TO_FILE)" to add a font.
#   - If using auto-load, create a folder for the fonts ("Fonts" by default),
#     and place all font files within it. Loading will be done automatically.
#
# Compatibility:
#
#   - No known compatibility issues with any other script.
#
# Credits/Thanks:
#
#   - ForeverZer0, for the script
#   - Duds, for pointing out the "AddFontResource" fix
#
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

#===============================================================================
# ** Font
#-------------------------------------------------------------------------------
# The font class. Font is a property of the Bitmap class.
#===============================================================================
class Font
 
  #-----------------------------------------------------------------------------
  #                            CONFIGURATION
  #-----------------------------------------------------------------------------
 
  # This value (true/false) indicates if all fonts in the specified fonts folder
  # will be automatically loaded when the game is started.
  AUTO_LOAD = true
   
  # Set this to the name of the folder, relative to the game directory, where
  # the font files are contained. This folder will be searched for font files
  # when using the auto-load feature
  FONT_FOLDER = 'Fonts'
 
  #-----------------------------------------------------------------------------
  #                           END CONFIGURATION
  #-----------------------------------------------------------------------------
 
  #-----------------------------------------------------------------------------
  # * Constants
  #-----------------------------------------------------------------------------
  WM_FONTCHANGE = 0x001D
  HWND_BROADCAST = 0xFFFF
  AddFontResource = Win32API.new('gdi32', 'AddFontResource', ['P'], 'L')
  AddFontResourceEx = Win32API.new('gdi32', 'AddFontResourceEx', 'PLL', 'L')
  SendMessage = Win32API.new('user32', 'SendMessage', 'LLLL', 'L')
  SendNotifyMessage = Win32API.new('user32', 'SendNotifyMessage', 'LLLL', 'L')
  #-----------------------------------------------------------------------------
  # * Class Variables
  #-----------------------------------------------------------------------------
  @@memory_fonts = []
  #-----------------------------------------------------------------------------
  # * Load font(s) into memory
  #     filename  : Full path to font file. Accepts multiple filenames.
  #-----------------------------------------------------------------------------
  def self.add(*filenames)
    filenames.each {|f|
      next if @@memory_fonts.include?(f)
      if AddFontResourceEx.call(f, 16, 0) > 0 || AddFontResource.call(f) > 0
        @@memory_fonts.push(f)
      end
    }
    SendNotifyMessage.call(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
    SendMessage.call(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
  end
  #-----------------------------------------------------------------------------
  # * Automatically seach and load all font files found in the font folder.
  #-----------------------------------------------------------------------------
  def self.auto_load
    dir = FONT_FOLDER == '' ? Dir.pwd : File.join(Dir.pwd, FONT_FOLDER)
    return unless File.directory?(dir)
    files = Dir.glob(File.join(dir, '*.{ttf,otf}'))
    self.add(*files)
  end
end

# Load fonts if using auto-load
if Font::AUTO_LOAD
  Font.auto_load
end



Instructions

Place script anywhere above main. Some optional configuration and instructions within the script.


Compatibility

No known compatibility issues, should have been solved with version 1.1.  


Credits and Thanks


  • ForeverZer0, for the script

  • Duds, for pointing out the "AddFontResource" fix




Author's Notes

Please feel free to ask for support, post bugs, or anything else. Enjoy!
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

PhoenixFire

   I currently have absolutely no use for this, but now that this exists, I may just change the fonts in my game so that I can use this  :^_^':
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

Zexion

... Words cannot describe how much I love you right now :P
Nice job F0! I'm sure that there will be tons of use of this script!

Jamal XVI

So i tested and it didn't work.I've just pasted the script and put a code 'Font.default_name = "Font Name"', but it won't work,
What should i do?
Thanks,
Jamal XVI

ForeverZer0

Make sure the name of the font is correct. The name of the font and the filename are not always the same.

Try with this, I have confirmed that this name is the same. Simply use the name "Slant".
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Jamal XVI

The same problem.Something must be wrong.
Look at this code:
module GTBS
  #=============================================================#
  #                       ENGINE SETTINGS                       #
  #=============================================================#
  def self.font
    return "slant"#Fonts::Names[0]
  end
end

and the main
begin
  #intalar_fonts
  $data_configuracoes = Configuracoes.new
  # Prepare for transition
  GMRK::API.disable_sys_key(1)
  Graphics.freeze
  # Make scene object (title screen)
  $scene = Scene_Perfis.new
  Font.default_name = GTBS::font  #############################################Here#################################
  Font.default_size = 22
  Font.default_bold = true
  # Call main method as long as $scene is effective
  while $scene != nil
    $scene.main
  end
  # Fade out
  Graphics.transition(20)
rescue Errno::ENOENT
  # Supplement Errno::ENOENT exception
  # If unable to open file, display message and end
  filename = $!.message.sub("No such file or directory - ", "")
  print("Unable to find file #{filename}.")
end

i wondering why it didn't work.Hope you can help me   :)
Thanks,
Jamal XVI

ForeverZer0

Does it work in a new project, as in a blank new project, without any added scripts?
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

KK20


Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Jamal XVI

Quote from: ForeverZer0 on January 21, 2014, 12:58:34 pm
Does it work in a new project, as in a blank new project, without any added scripts?

A new project main
#==============================================================================
# Main
#------------------------------------------------------------------------------
# Após o final de cada definição de classe o processo principal
# do jogo é iniciado. Esta é a classe principal do jogo.
#==============================================================================

begin
 
 # É definida aqui a fonte usada nas janelas do jogo
 # Você pode usar aqui qualquer fonte disponível em seu computador
 # Porém é recomendável usar fontes padrão do Windows
 # Por exemplo: Arial, Lucida Console, Tahoma, Verdana...
 
 $defaultfonttype = $fontface = $fontname = Font.default_name = "Slant"
 # É definido aqui o tamanho da fonte usada nas janelas de jogo
 # O tamanho padrão é 25. Porém, você pode usar o tamanho que você
 # achar melhor para seu sistema e fonte
 
 $defaultfontsize = $fontsize = Font.default_size = 22
 
 # É preparada uma transição de tela
 
 Graphics.freeze
 
 # Aqui é chamada a tela título do jogo. O script padrão
 # de título é 'Scene_Title'. Você pode mudá-lo, mas isso não é
 # recomendável
 
 $scene = Scene_Title.new
 
 # É definida a limitação efetiva da variável $scene.
 # Se esta é nula, é chamado o método principal
 
 while $scene != nil
   $scene.main
 end
 
 # A transição de tela é executada
 
 Graphics.transition(20)
rescue Errno::ENOENT
 
 # Aqui, definimos a mensagem padrão para Errno::ENOENT
 # Quando não é possível abrir um arquivo, a mensagem é exibida
 
 filename = $!.message.sub("Arquivo não encontrado - ", "")
 print("O Arquivo #{filename} não foi encontrado.")
end

Results: ShowHide
So i put a print in the method self.auto_load and the result was:

so i started the game and...

I can't imagine what problem making this, but it wont work.
Thanks,
Jamal XVI

ForeverZer0

Strange.
I will have to see if maybe there is some issue with WinXP, or perhaps something else I am missing.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Jamal XVI

So i got the problem.
The font name "slant.ttf" has to be the name name of the font "Slant" as the same in RGGS,but the font name is case sensitive to.
Then the file name must be "Slant.ttf" and in RGSS the font name must be "Slant"
Thanks,
Jamal XVI

Zexion

Here's a tip, doesn't always work but will for the most part. In your system fonts folder, double click the font in question and it should say the fonts real name inside. A lot of font files are named one thing but are actually something else. A file like "sans bold" could actually be called "sanserif bold" and rgss won't pick it up.

PrinceEndymion88

I've added the Joystix Monospace.ttf font into Fonts folder and into UMS script I've edited
@font = "Arial"
into
@font = "Joystix Monospace"
but I can't see the font when I play the game... where I'm wrong?

Zexion

I think it might be related to the post I made above you. The font is named Joystix Monospace.ttf  but the real font probably has a different name like joystix mono.
Double click it and read where it says Font Name:

PrinceEndymion88

I had already checked out, the real name is Joystix Monospace.

Nome tipo carattere = Font Name (in italian  :haha:)

Dust

Doesn't work for me too, sadly :/ I tried it with the Slant-font aswell, even renaming it and trying other fonts, but the font won't be loaded. I'm using Windows 8.1 by the way.

ForeverZer0

I think it does have something to do with the new "upgrade" that is Windows 8.
I wrote the script under Windows 7, and now that I have remade a switch back to Windows 8, it is not working for me either.  AddFontResourceEx is executing correctly, but using SendMessage with the broadcast is failing, returning a generic error code of "1", which doesn't explain much other than "I did not work".

I will take a look into it soon when I get a chance. One more reason Windows 8 sucks.
Just out of curiosity, are you running the game in compatibility mode or anything? That shouldn't be a problem, but may help track down the cause of the error.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

orochii

I don't care if this script works (well, actually I do, but...). I love this kind of scripts where I don't get a shit of how does it works. I can imagine, and I could probably, like, write it later from scratch (it's pretty short anyway). Because the idea is pretty simple (though I still don't understand why the SendMessage command is used, something about a protocol?). But as in "thought that it could be done this way", nope. Not without a lot of research, and there is where the beautifulness of this code is. As in, how the hell did you came up with this solution xD.

This is wizardry!

Blizzard

Quote from: orochii on May 24, 2014, 06:23:23 pm
(though I still don't understand why the SendMessage command is used, something about a protocol?).


You need to let the running apps in the OS know "hey, dudes, there's a new kid font on the block". SendMessage() does exactly that.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Dust

Quote from: ForeverZer0 on May 24, 2014, 06:39:32 am
I will take a look into it soon when I get a chance. One more reason Windows 8 sucks.
Just out of curiosity, are you running the game in compatibility mode or anything? That shouldn't be a problem, but may help track down the cause of the error.


It would be reaaally great if you could get this to work c: And no, I'm not running the Game.exe or RPG Maker itself in compatibility mode

Cremno

May 25, 2014, 11:22:37 am #21 Last Edit: May 25, 2014, 12:27:40 pm by Cremno
I don't know exactly why it doesn't work, but it's neither the fault of the (unnecessary) SendMessage call nor Windows 8. Does it work for you or someone else? It doesn't even work for me under the good old Windows XP SP3.

By the way, it works if you write your own Game.exe.

ForeverZer0

Yes, SendMessage should most definitely be used.

http://msdn.microsoft.com/en-us/library/aa911393.aspx

Quote from: MSDNRemarks

An application that adds or removes fonts from the system (for example, by using the AddFontResource or RemoveFontResource function) should send this message to all top-level windows.
To send the WM_FONTCHANGE message to all top-level windows, an application can call the SendMessage function with the hwnd parameter set to HWND_BROADCAST.


I am hardly going to rewrite Game.exe just to load a font from memory, that is ludicrous.

I only think that it could be the fault of Win 8 due to the fact that it worked perfectly for me before making a switch from Win7 to Win8, though it is obviously unconfirmed at this point.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Cremno

May 25, 2014, 01:48:26 pm #23 Last Edit: May 25, 2014, 01:51:01 pm by Cremno
AddFontResource != AddFontResourceEx (especially with FR_PRIVATE)

I think RGSS1 has an internal font list which is initialized at start and that's why calling AddFont* functions don't work afterwards.

Heretic86

Methinks time for Blizz to step in...

I cant get this to work either.  Renaming fonts, case sensitive, spaces, putting ".ttf" in the name, and this box is XP-SP3.  I monkeyed with the scripts, but even after its there, using Font.exist?(name) I get nada.  AddFontResourceEx.call returns 1 so it says the font is loaded into memory.  Fantastic idea, and already implemented into VXA apparently, just can not get it to work.  Only thing I could find that was relevant was this:

https://github.com/Ancurio/mkxp

Way over my head...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Blizzard

Try AddFontResourceExA(), that's probably the reason. Using just AddFontResourceExW() will cause problems because of wide-chars.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Heretic86

Still no luck.  Ex, ExA, ExW, no Ex, my brain just keeps coming up short.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

ForeverZer0

I have yet to find a pattern to what works definitely and what does not. I do believe it has SOMETHING to do with the OS, but I cannot even say that for sure.

@heretic:
Just for a test, run the game as admin and see if has something to do with permissions or not. I have had success and not being an admin, put it could possibly be a combination of OS and UAC.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Heretic86

October 11, 2014, 04:45:57 am #28 Last Edit: October 11, 2014, 05:16:07 am by Heretic86
Still doesnt work as Administrator either.

However, I do use a program for my VPN called PIA (Private Internet Access) and when I set it up and my firewall complained about it, it is also Ruby based, so not sure if that could somehow cause a conflict.  It may not sound like it might, but since RMXP uses system globals (like fonts), I wonder if the two might conflict?  I did exit the VPN program, and still didnt get any results.  Perhaps Adobe Flash?  I messed with some of the geek config settings, namely "DisableDeviceFontEnumeration", and think Flash shouldnt cause a conflict, but perhaps Font Enumeration?  Some sort of other Windows permission?  AVG?  All disabled for testing, and no luck on anything I've tried.  Shortcuts are not set to run in compatability mode, the advanced text services are not turned off.  Just related things, but dont seem to have any impact...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Duds

November 30, 2014, 07:13:57 pm #29 Last Edit: December 01, 2014, 09:38:14 am by Duds
Hi guys, this is my first post here. :haha:
I was very interested in this script so I gave a try on fixing it.
It works with AddFontResource (without Ex).


Spoiler: ShowHide


#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Memory Font Loader
# Author: ForeverZer0
# Version: 1.0
# Date: 1.8.2014
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#                             VERSION HISTORY
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# v.1.0   1.8.2014
#   - Original Release
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#
# Introduction:
#
#   Small script that allows for loading and using fonts into memory at run-time
#   without the need for installing them on the operating system. The advantage
#   of this script over others, such as Wachunga's font-install script, is that
#   it does not require a administrator privileges to use the fonts, nor a
#   restart of the game after running.
#
# Features:
#
#   - Automatically load all fonts found in user-defined folder
#   - Supports TrueType (*.ttf) and OpenType(*.otf) fonts
#   - Does not require Administrator privileges
#   - Does not require a game restart
#
# Instructions:
#  
#   - Place script anywhere above main
#   - Some optional configuration below with explanation
#   - Use the script call "Font.add(PATH_TO_FILE)" to add a font.
#   - If using auto-load, create a folder for the fonts ("Fonts" by default),
#     and place all font files within it. Loading will be done automatically.
#
# Compatibility:
#
#   - No known compatibility issues with any other script.
#
# Credits/Thanks:
#
#   - ForeverZer0, for the script
#
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=

#===============================================================================
# ** Font
#-------------------------------------------------------------------------------
# The font class. Font is a property of the Bitmap class.
#===============================================================================
class Font
 
 #-----------------------------------------------------------------------------
 #                            CONFIGURATION
 #-----------------------------------------------------------------------------
 
 # This value (true/false) indicates if all fonts in the specified fonts folder
 # will be automatically loaded when the game is started.
 AUTO_LOAD = true
   
 # Set this to the name of the folder, relative to the game directory, where
 # the font files are contained. This folder will be searched for font files
 # when using the auto-load feature
 FONT_FOLDER = 'Fonts'
 
 #-----------------------------------------------------------------------------
 #                           END CONFIGURATION
 #-----------------------------------------------------------------------------
 
 #-----------------------------------------------------------------------------
 # * Constants
 #-----------------------------------------------------------------------------

 WM_FONTCHANGE = 0x001D
 HWND_BROADCAST = 0xFFFF

 AddFontResourceEx = Win32API.new('gdi32', 'AddFontResource', ['P'], 'L')
 SendMessage = Win32API.new('user32', 'SendMessage', ['L'] * 4, 'L')
 #-----------------------------------------------------------------------------
 # * Class Variables
 #-----------------------------------------------------------------------------
 @@memory_fonts = []
 #-----------------------------------------------------------------------------
 # * Load font(s) into memory
 #     filename  : Full path to font file. Accepts multiple filenames.
 #-----------------------------------------------------------------------------
 def self.add(*filenames)
   filenames.each {|f|
     next if @@memory_fonts.include?(f)
     if AddFontResourceEx.call(f) > 0
       @@memory_fonts.push(f)
     end
   }
   SendMessage.call(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
 end
 #-----------------------------------------------------------------------------
 # * Automatically seach and load all font files found in the font folder.
 #-----------------------------------------------------------------------------
 def self.auto_load
   dir = FONT_FOLDER == '' ? Dir.pwd : File.join(Dir.pwd, FONT_FOLDER)
   return unless File.directory?(dir)
   files = Dir.glob(File.join(dir, '*.{ttf,otf}'))
   self.add(*files)
 end
 # Load fonts if using auto-load
 auto_load if AUTO_LOAD
end


Heretic86

+Rep

Changing AddFontResourceEx (ExA or ExW also) to just AddFontResource works perfectly!  At least on XP SP3, so Im not sure how that will affect Windows 7 / 8 / 8.1 but feedback on the proposed fix would be appreciated by many...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

ForeverZer0

* Updates script to version 1.1 *

I added the fix that Duds pointed out to the script as a backup if the original method fails. If you were having troubles getting the script to work before, it may be worth your while to check again.

Thank you, Duds.  8)
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Blizzard

I think that I can offer some more insight here after experimenting with this a bit.
The problem seems to be indeed that RMXP keeps a list of available fonts that it creates on load. AddFontResourceEx() can't work, because the fonts are uninstalled again right after it closes. AddFontResource() will work, because it temporarily installs the fonts until the next reboot. So yeah, I don't think this problem can be solved.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Blizzard

*BUMP*

I just had an idea that I shared with Heretic:

Quote from: le meThere MIGHT be one last possible solution. You could reinstall the fonts every time the game runs and copy the file into the fonts directory regardless if it's already there. In that case you would just have to change the code a bit to avoid reporting missing fonts to users.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

F117Landers

I'm rather new to this, so perhaps someone can help:

what is "PATH_TO_FILE"? Is that to add a script from outside the Fonts folder into the game? or is that to actually set the font once it is loaded?

KK20

If you're not using AUTO_LOAD, you'll have to use that script call to add your fonts. Otherwise, just throw all your fonts into whatever Font folder you package your game with; you won't have to worry about making any script calls.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

F117Landers

July 11, 2016, 07:46:14 am #36 Last Edit: July 11, 2016, 08:05:13 am by F117Landers
Thanks KK20. I am using auto load, but the fonts weren't loading (Edit: using Font.default_name = "King's Gambit") and I had checked the font size, name (within the ttf), and capitalization already.

ThallionDarkshine

So I seem to have found a bug with this on Windows 8.1. After the call to
SendMessage
, the game freezes. Have you tried with just
SendNotifyMessage
? From what I can tell in the docs,
SendMessage
blocks until all windows process the notification, whereas
SendNotifyMessage
returns immediately... I tried removing the
SendMessage
call, and the game appears to run fine. Is there a reason you're making both calls?

maathieu

Hi,

I have been asked by a friend developing an RPGMaker XP game to look into this script in order to get it to load a user-defined font at runtime. Reading the forum here, I can't really figure out why it seems to work for some people, and not for others.

I am doing the testing on Wine simulating Windows XP. Ruby properly calls AddFontResource, SendMessage, and SendNotifyMessage; but after that, the font is not made available to the game. I have read that RPGMaker XP maintains an internal "list of fonts", could it be possible that said list is loaded before the script for some verions of RPGMaker XP, and after it for others? I use version 1.03 here.

If the "list" hypothesis is right, is there any way to access the internal list and manually add the font name in it?

Cheers,

Maathieu

Blizzard

I think you're correct about the internal list IIRC. But that's exactly what AddFontResource, SendMessage and SendNotifyMessage are supposed to handle and change. So I'm not sure what's wrong. I assume it's some internal bug in XP. XP's been around since, well, Windows XP and the tighter permission restrictions have only been added in Windows Vista and later and I wouldn't be surprised if permissions are what's causing the issue in the first place. So it's likely that this is an issue that would require an update to XP to reliably fix. But the original developers don't maintain it anymore so there's not much hope that this will be fixed.

You may want to consider using XPA. Ever since I converted my project to XPA, I haven't had any font issues anymore. The VXA engine handles fonts so much better than previous versions of RPG Maker.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

maathieu

I wish I could do that... Unfortunately we developed a lot of custom scripts for the game and hacked around the existing ones. The code is sloppy, the development heavily plays with the limits of RPG XP, and porting is hazardous.

Well, I guess the best solution is to create a Windows Installer that installs the font along with the game... I'll give a go at NSIS.

Blizzard

May 19, 2020, 03:37:49 am #41 Last Edit: May 19, 2020, 03:41:04 am by Blizzard
I have over 30000 lines of code compared to the standard 9000 lines. That's how many custom scripts I had when porting. It took me about 3 work days to do the port and most of it was fixing cutscene timing of music and minigames. And that was because I switched to 60 FPS, not so much because of XPA. Except for some very specific bitmap handling issues and some other minor bugs, it was relatively easy to do. Actually the majority of bugs were either in the new windowing system and with the tilemap implementation. So KK20 fixed the tilemap bugs and I fixed the window system bugs directly in XPA.

Of course, I'm a programmer. If you're not one, you'll likely have a harder time with porting to XPA. In either case it was very worth it for me. This is why I'm suggesting to at least give it a go. Make a backup of your project, switch to XPA and maybe do 1-2h of testing to see how it works. If you run into issues you think you can't solve, you can always just delete it and keep using your normal XP backup.

I tried getting NSIS to install the font myself as well, but it didn't work. I'm not saying that you should give up right away (I used v2.46), but be aware that this will likely not be the solution.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

ctkny

If reverse engineering is permitted for some kind of refinement,this should be way simpler.

Similarily,functionalities such as disabling F12/10s hangup/alt+enter,background running,pausing the movieplay in VA,loading .so that requires native ruby func support,screenshot,... can all be achieved.
Some of these take nothing but one byte's hack.

With no source,the machine code level provides the most freedom.
Sadly though,this violates the EULA.

A lot of what I know about reverse engineering comes from the time when I had fun with RMXP,fixing this or that,digging.I just drifted from scripting ruby.

I'm Chinese so I have never posted here.And I don't really care about EULA for a long time.I don't make /publish games myself and people I helped did not seem that bothered.

I don't know.If it is acceptable,I'll share my way of doing this,detail it.Otherwise,well,thanks for hearing out.

KK20

I don't know why you specifically chose this thread to share it. But feel free to post a new topic under general discussion sharing what you found/know. Just put a disclaimer that it violates EULA and is just for knowledge-sharing purposes.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!