Module: Lich

Included in:
DragonRealms, Gemstone
Defined in:
lib/games.rb,
lib/lich.rb,
lib/stash.rb,
lib/update.rb,
lib/messaging.rb,
lib/util/util.rb,
lib/common/hmr.rb,
lib/common/log.rb,
lib/magic-info.rb,
lib/common/vars.rb,
lib/gemstone/sk.rb,
lib/common/spell.rb,
lib/common/buffer.rb,
lib/common/script.rb,
lib/gemstone/disk.rb,
lib/gemstone/gift.rb,
lib/gemstone/psms.rb,
lib/common/account.rb,
lib/common/eaccess.rb,
lib/common/gameobj.rb,
lib/gemstone/claim.rb,
lib/gemstone/group.rb,
lib/gemstone/scars.rb,
lib/attributes/char.rb,
lib/common/db_store.rb,
lib/common/settings.rb,
lib/common/uservars.rb,
lib/common/watchfor.rb,
lib/gemstone/bounty.rb,
lib/gemstone/wounds.rb,
lib/attributes/stats.rb,
lib/common/front-end.rb,
lib/common/gui-login.rb,
lib/common/xmlparser.rb,
lib/gemstone/effects.rb,
lib/gemstone/infomon.rb,
lib/attributes/skills.rb,
lib/attributes/spells.rb,
lib/common/map/map_dr.rb,
lib/common/map/map_gs.rb,
lib/gemstone/stowlist.rb,
lib/attributes/society.rb,
lib/common/game-loader.rb,
lib/gemstone/critranks.rb,
lib/gemstone/psms/cman.rb,
lib/gemstone/psms/feat.rb,
lib/gemstone/readylist.rb,
lib/common/limitedarray.rb,
lib/common/sharedbuffer.rb,
lib/common/upstreamhook.rb,
lib/gemstone/experience.rb,
lib/gemstone/psms/armor.rb,
lib/gemstone/spellranks.rb,
lib/attributes/resources.rb,
lib/attributes/spellsong.rb,
lib/gemstone/bounty/task.rb,
lib/gemstone/infomon/cli.rb,
lib/gemstone/psms/shield.rb,
lib/gemstone/psms/warcry.rb,
lib/gemstone/psms/weapon.rb,
lib/common/downstreamhook.rb,
lib/gemstone/bounty/parser.rb,
lib/gemstone/infomon/cache.rb,
lib/gemstone/infomon/parser.rb,
lib/gemstone/infomon/status.rb,
lib/gemstone/psms/ascension.rb,
lib/gemstone/infomon/currency.rb,
lib/gemstone/infomon/xmlparser.rb,
lib/common/class_exts/stringproc.rb,
lib/common/settings/charsettings.rb,
lib/common/settings/gamesettings.rb,
lib/gemstone/infomon/activespell.rb,
lib/common/settings/path_navigator.rb,
lib/common/settings/settings_proxy.rb,
lib/common/settings/database_adapter.rb,
lib/common/class_exts/synchronizedsocket.rb,
lib/gemstone/critranks/generic_critical_table.rb

Overview

requireds template for a crit GENERIC: <<– the ‘crit table name’

UNSPECIFIED:                                         <<-- the 'location'
  0:                                                 <<-- the 'crit rank'
    :type: GENERIC                                   <<-- this must match the crit table name
    :location: UNSPECIFIED                           <<-- this must match the location
    :rank: 0                                         <<-- this must match the crit rank
    :damage: 0                                       <<-- additional damage per crit table
    :position:                                       <<-- if the crit causing KNEEL, SITTING or PRONE
    :fatal: false                                    <<-- if the crit is fatal
    :stunned: 999                                    <<-- rounds of stun caused by the crit - use 999 for unknown
    :amputated: false                                <<-- if the crit causes the LOCATION to be severed
    :crippled: false                                 <<-- if the crit causes the location to be useless
    :sleeping: false                                 <<-- if the crit causes an unconcious / sleeping state
    :dazed: false                                    <<-- UAC can caused dazed effect (possible PSMs too?)
    :limb_favored:                                   <<-- limb favored (true false or location tbd)
    :roundtime: 0                                    <<-- if the crit causes additional roundtime
    :silenced: false                                 <<-- if the crit prevents speaking / casting
    :slowed: false                                   <<-- if the crit causes slower actions
    :wound_rank: 0                                   <<-- rank of wound caused at LOCATION
    :secondary_wound:                                <<-- second wound caused at different LOCATIONI
    :regex: !ruby/regexp /.*? is stunned!/       <<-- the regex that denotes the crit text for capture

Defined Under Namespace

Modules: Claim, Common, Currency, DragonRealms, Gemstone, Messaging, Resources, Stash, Unknown, Util

Constant Summary collapse

@@hosts_file =
nil
@@lich_db =
nil
@@last_warn_deprecated =
0
@@deprecated_log =
[]
@@display_lichid =

settings

nil
@@display_uid =

boolean

nil
@@display_exits =

boolean

nil
@@display_stringprocs =

boolean

nil
@@hide_uid_flag =

boolean

nil
@@track_autosort_state =

boolean

nil
@@track_dark_mode =

boolean

nil
@@track_layout_state =

boolean

nil

Class Method Summary collapse

Class Method Details

.break_game_host_port(gamehost, gameport) ⇒ Array

Reverts the game host and port based on predefined mappings.

Examples:

reverted_host, reverted_port = Lich.break_game_host_port('storm.gs4.game.play.net', 10324)

Parameters:

  • gamehost (String)

    The original game host.

  • gameport (Integer)

    The original game port.

Returns:

  • (Array)

    An array containing the reverted game host and port.



780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
# File 'lib/lich.rb', line 780

def Lich.break_game_host_port(gamehost, gameport)
  if (gamehost == 'storm.gs4.game.play.net') and (gameport.to_i == 10324)
    gamehost = 'gs4.simutronics.net'
    gameport = 10321
  elsif (gamehost == 'storm.gs4.game.play.net') and (gameport.to_i == 10124)
    gamehost = 'gs-plat.simutronics.net'
    gameport = 10121
  elsif (gamehost == 'storm.gs4.game.play.net') and (gameport.to_i == 10024)
    gamehost = 'gs3.simutronics.net'
    gameport = 4900
  elsif (gamehost == 'dr.simutronics.net') and (gameport.to_i == 11024)
    gamehost = 'prime.dr.game.play.net'
    gameport = 4901
  end
  [gamehost, gameport]
end

.class_eval(*_a) ⇒ nil

Returns nil for class evaluation.

Parameters:

  • _a (Array)

    ignored parameters.

Returns:

  • (nil)

    always returns nil.



126
# File 'lib/lich.rb', line 126

def Lich.class_eval(*_a);         nil; end

.class_variable_get(*_a) ⇒ nil

Returns nil for class variable access.

Parameters:

  • _a (Array)

    ignored parameters.

Returns:

  • (nil)

    always returns nil.



120
# File 'lib/lich.rb', line 120

def Lich.class_variable_get(*_a); nil; end

.core_updated_with_lich_versionString

Retrieves the version of the core that was updated with the lich version.

Examples:

version = Lich.core_updated_with_lich_version

Returns:

  • (String)

    The version of the core.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



915
916
917
918
919
920
921
922
923
# File 'lib/lich.rb', line 915

def Lich.core_updated_with_lich_version
  begin
    val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='core_updated_with_lich_version';")
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return val.to_s
end

.core_updated_with_lich_version=(val) ⇒ nil

Sets the version of the core that was updated with the lich version.

Examples:

Lich.core_updated_with_lich_version = "1.0.0"

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



932
933
934
935
936
937
938
939
940
# File 'lib/lich.rb', line 932

def Lich.core_updated_with_lich_version=(val)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('core_updated_with_lich_version',?);", [val.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.dbSQLite3::Database

Initializes the database connection and creates necessary tables.

Examples:

Lich.init_db

Returns:

  • (SQLite3::Database)

    the database connection.

Raises:

  • (SQLite3::BusyException)

    if the database is busy.



90
91
92
# File 'lib/lich.rb', line 90

def Lich.db
  @@lich_db ||= SQLite3::Database.new("#{DATA_DIR}/lich.db3")
end

.db_mutexMutex

Returns the database mutex for thread safety.

Returns:

  • (Mutex)

    the mutex used for database operations.



22
23
24
# File 'lib/lich.rb', line 22

def self.db_mutex
  @@db_mutex
end

.debug_messagingBoolean

Retrieves the debug messaging setting from the database.

Examples:

is_debug_enabled = Lich.debug_messaging

Returns:

  • (Boolean)

    True if debug messaging is enabled, otherwise false.



802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'lib/lich.rb', line 802

def Lich.debug_messaging
  if @@debug_messaging.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='debug_messaging';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    @@debug_messaging = (val.to_s =~ /on|true|yes/ ? true : false)
    Lich.debug_messaging = @@debug_messaging
  end
  return @@debug_messaging
end

.debug_messaging=(val) ⇒ nil

Sets the debug messaging setting in the database.

Examples:

Lich.debug_messaging = true

Parameters:

  • val (Boolean)

    True to enable debug messaging, false to disable.

Returns:

  • (nil)

    Returns nil after executing the operation.

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



823
824
825
826
827
828
829
830
831
832
# File 'lib/lich.rb', line 823

def Lich.debug_messaging=(val)
  @@debug_messaging = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('debug_messaging',?);", [@@debug_messaging.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.deprecated(old_object = '', new_object = '', script_location = "#{Script.current.name || 'unknown'}", debug_log: true, fe_log: false, limit_log: true) ⇒ nil

Logs a deprecation warning for a method or variable.

Examples:

Lich.deprecated('old_method', 'new_method')

Parameters:

  • old_object (String) (defaults to: '')

    the deprecated object name.

  • new_object (String) (defaults to: '')

    the new object name to use.

  • script_location (String) (defaults to: "#{Script.current.name || 'unknown'}")

    the location of the script using the deprecated object.

  • debug_log (Boolean) (defaults to: true)

    whether to log the message for debugging.

  • fe_log (Boolean) (defaults to: false)

    whether to log the message to the front-end.

  • limit_log (Boolean) (defaults to: true)

    whether to limit logging of the same message.

Returns:

  • (nil)

    returns nothing.



154
155
156
157
158
159
160
# File 'lib/lich.rb', line 154

def Lich.deprecated(old_object = '', new_object = '', script_location = "#{Script.current.name || 'unknown'}", debug_log: true, fe_log: false, limit_log: true)
  msg = "Deprecated call to #{old_object} used in #{script_location}. Please change to #{new_object} instead!"
  return if limit_log && @@deprecated_log.include?(msg)
  Lich.log(msg) if debug_log
  Lich::Messaging.msg("bold", msg) if fe_log
  @@deprecated_log.push(msg) unless @@deprecated_log.include?(msg)
end

.display_exitsBoolean

Retrieves the current state of the display exits setting.

Examples:

display_exits = Lich.display_exits

Returns:

  • (Boolean)

    The current state of the display exits setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



986
987
988
989
990
991
992
993
994
995
996
997
998
# File 'lib/lich.rb', line 986

def Lich.display_exits
  if @@display_exits.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='display_exits';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    val = false if val.nil? and XMLData.game != ""; # default false
    @@display_exits = (val.to_s =~ /on|true|yes/ ? true : false) if !val.nil?;
  end
  return @@display_exits
end

.display_exits=(val) ⇒ nil

Sets the display exits setting.

Examples:

Lich.display_exits = true

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'lib/lich.rb', line 1007

def Lich.display_exits=(val)
  @@display_exits = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('display_exits',?);", [@@display_exits.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.display_lichidBoolean

Retrieves the display Lich ID setting from the database.

Examples:

is_display_enabled = Lich.display_lichid

Returns:

  • (Boolean)

    True if display Lich ID is enabled, otherwise false.



839
840
841
842
843
844
845
846
847
848
849
850
851
# File 'lib/lich.rb', line 839

def Lich.display_lichid
  if @@display_lichid.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='display_lichid';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    val = (XMLData.game =~ /^GS/ ? true : false) if val.nil? and XMLData.game != ""; # default false if DR, otherwise default true
    @@display_lichid = (val.to_s =~ /on|true|yes/ ? true : false) if !val.nil?;
  end
  return @@display_lichid
end

.display_lichid=(val) ⇒ nil

Sets the display state of the lich ID.

Examples:

Lich.display_lichid = true

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



860
861
862
863
864
865
866
867
868
869
# File 'lib/lich.rb', line 860

def Lich.display_lichid=(val)
  @@display_lichid = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('display_lichid',?);", [@@display_lichid.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.display_stringprocsBoolean

Retrieves the current state of the display string procs setting.

Examples:

display_stringprocs = Lich.display_stringprocs

Returns:

  • (Boolean)

    The current state of the display string procs setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# File 'lib/lich.rb', line 1024

def Lich.display_stringprocs
  if @@display_stringprocs.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='display_stringprocs';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    val = false if val.nil? and XMLData.game != ""; # default false
    @@display_stringprocs = (val.to_s =~ /on|true|yes/ ? true : false) if !val.nil?;
  end
  return @@display_stringprocs
end

.display_stringprocs=(val) ⇒ nil

Sets the display string procs setting.

Examples:

Lich.display_stringprocs = false

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
# File 'lib/lich.rb', line 1045

def Lich.display_stringprocs=(val)
  @@display_stringprocs = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('display_stringprocs',?);", [@@display_stringprocs.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.display_uidBoolean

Retrieves the current state of the display UID setting.

Examples:

display_uid = Lich.display_uid

Returns:

  • (Boolean)

    The current state of the display UID setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'lib/lich.rb', line 948

def Lich.display_uid
  if @@display_uid.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='display_uid';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    val = (XMLData.game =~ /^GS/ ? true : false) if val.nil? and XMLData.game != ""; # default false if DR, otherwise default true
    @@display_uid = (val.to_s =~ /on|true|yes/ ? true : false) if !val.nil?;
  end
  return @@display_uid
end

.display_uid=(val) ⇒ nil

Sets the display UID setting.

Examples:

Lich.display_uid = true

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



969
970
971
972
973
974
975
976
977
978
# File 'lib/lich.rb', line 969

def Lich.display_uid=(val)
  @@display_uid = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('display_uid',?);", [@@display_uid.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.find_hosts_fileString, false

Searches for the hosts file based on the operating system.

Examples:

hosts_file_path = Lich.find_hosts_file

Returns:

  • (String, false)

    The path to the hosts file if found, otherwise false.

Raises:

  • (StandardError)

    If there is an error accessing the registry or file system.



578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/lich.rb', line 578

def Lich.find_hosts_file
  if defined?(Win32)
    begin
      key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'System\\CurrentControlSet\\Services\\Tcpip\\Parameters', :samDesired => Win32::KEY_READ)[:phkResult]
      hosts_path = Win32.RegQueryValueEx(:hKey => key, :lpValueName => 'DataBasePath')[:lpData]
    ensure
      Win32.RegCloseKey(:hKey => key) rescue nil
    end
    if hosts_path
      windir = (ENV['windir'] || ENV['SYSTEMROOT'] || 'c:\windows')
      hosts_path.gsub!('%SystemRoot%', windir)
      hosts_file = "#{hosts_path}\\hosts"
      if File.exist?(hosts_file)
        return (@@hosts_file = hosts_file)
      end
    end
    if (windir = (ENV['windir'] || ENV['SYSTEMROOT'])) and File.exist?("#{windir}\\system32\\drivers\\etc\\hosts")
      return (@@hosts_file = "#{windir}\\system32\\drivers\\etc\\hosts")
    end

    for drive in ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
      for windir in ['winnt', 'windows']
        if File.exist?("#{drive}:\\#{windir}\\system32\\drivers\\etc\\hosts")
          return (@@hosts_file = "#{drive}:\\#{windir}\\system32\\drivers\\etc\\hosts")
        end
      end
    end
  else # Linux/Mac
    if File.exist?('/etc/hosts')
      return (@@hosts_file = '/etc/hosts')
    elsif File.exist?('/private/etc/hosts')
      return (@@hosts_file = '/private/etc/hosts')
    end
  end
  return (@@hosts_file = false)
end

.fix_game_host_port(gamehost, gameport) ⇒ Array

Fixes the game host and port based on predefined mappings.

Examples:

fixed_host, fixed_port = Lich.fix_game_host_port('gs-plat.simutronics.net', 10121)

Parameters:

  • gamehost (String)

    The original game host.

  • gameport (Integer)

    The original game port.

Returns:

  • (Array)

    An array containing the fixed game host and port.



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/lich.rb', line 756

def Lich.fix_game_host_port(gamehost, gameport)
  if (gamehost == 'gs-plat.simutronics.net') and (gameport.to_i == 10121)
    gamehost = 'storm.gs4.game.play.net'
    gameport = 10124
  elsif (gamehost == 'gs3.simutronics.net') and (gameport.to_i == 4900)
    gamehost = 'storm.gs4.game.play.net'
    gameport = 10024
  elsif (gamehost == 'gs4.simutronics.net') and (gameport.to_i == 10321)
    gamehost = 'storm.gs4.game.play.net'
    gameport = 10324
  elsif (gamehost == 'prime.dr.game.play.net') and (gameport.to_i == 4901)
    gamehost = 'dr.simutronics.net'
    gameport = 11024
  end
  [gamehost, gameport]
end

.get_simu_launcherString?

Retrieves the command for the Simutronics launcher from the registry.

Examples:

Lich.get_simu_launcher

Returns:

  • (String, nil)

    the command for the launcher or nil if not found.

Raises:

  • (StandardError)

    if an error occurs while accessing the registry.



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/lich.rb', line 262

def Lich.get_simu_launcher
  if defined?(Win32)
    begin
      launcher_key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command', :samDesired => (Win32::KEY_ALL_ACCESS | Win32::KEY_WOW64_32KEY))[:phkResult]
      launcher_cmd = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'RealCommand')[:lpData]
      if launcher_cmd.nil? or launcher_cmd.empty?
        launcher_cmd = Win32.RegQueryValueEx(:hKey => launcher_key)[:lpData]
      end
      return launcher_cmd
    ensure
      Win32.RegCloseKey(:hKey => launcher_key) rescue nil
    end
  elsif defined?(Wine)
    launcher_cmd = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\RealCommand')
    unless launcher_cmd and not launcher_cmd.empty?
      launcher_cmd = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\')
    end
    return launcher_cmd
  else
    return nil
  end
end

.hide_uid_flagBoolean

Retrieves the current state of the hide UID flag.

Examples:

current_flag = Lich.hide_uid_flag

Returns:

  • (Boolean)

    The current state of the hide UID flag.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



877
878
879
880
881
882
883
884
885
886
887
888
889
# File 'lib/lich.rb', line 877

def Lich.hide_uid_flag
  if @@hide_uid_flag.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='hide_uid_flag';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    val = false if val.nil? and XMLData.game != ""; # default false
    @@hide_uid_flag = (val.to_s =~ /on|true|yes/ ? true : false) if !val.nil?;
  end
  return @@hide_uid_flag
end

.hide_uid_flag=(val) ⇒ nil

Sets the hide UID flag.

Examples:

Lich.hide_uid_flag = false

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



898
899
900
901
902
903
904
905
906
907
# File 'lib/lich.rb', line 898

def Lich.hide_uid_flag=(val)
  @@hide_uid_flag = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('hide_uid_flag',?);", [@@hide_uid_flag.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.hosts_fileString, false

Retrieves the path to the hosts file. If the path is not already cached, it will search for it.

Examples:

hosts_file_path = Lich.hosts_file

Returns:

  • (String, false)

    The path to the hosts file if found, otherwise false.



567
568
569
570
# File 'lib/lich.rb', line 567

def Lich.hosts_file
  Lich.find_hosts_file if @@hosts_file.nil?
  return @@hosts_file
end

.init_dbObject

Creates necessary tables in the database if they do not exist.

Examples:

Lich.init_db

Raises:

  • (SQLite3::BusyException)

    if the database is busy.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/lich.rb', line 99

def Lich.init_db
  begin
    Lich.db.execute("CREATE TABLE IF NOT EXISTS script_setting (script TEXT NOT NULL, name TEXT NOT NULL, value BLOB, PRIMARY KEY(script, name));")
    Lich.db.execute("CREATE TABLE IF NOT EXISTS script_auto_settings (script TEXT NOT NULL, scope TEXT, hash BLOB, PRIMARY KEY(script, scope));")
    Lich.db.execute("CREATE TABLE IF NOT EXISTS lich_settings (name TEXT NOT NULL, value TEXT, PRIMARY KEY(name));")
    Lich.db.execute("CREATE TABLE IF NOT EXISTS uservars (scope TEXT NOT NULL, hash BLOB, PRIMARY KEY(scope));")
    if (RUBY_VERSION =~ /^2\.[012]\./)
      Lich.db.execute("CREATE TABLE IF NOT EXISTS trusted_scripts (name TEXT NOT NULL);")
    end
    Lich.db.execute("CREATE TABLE IF NOT EXISTS simu_game_entry (character TEXT NOT NULL, game_code TEXT NOT NULL, data BLOB, PRIMARY KEY(character, game_code));")
    Lich.db.execute("CREATE TABLE IF NOT EXISTS enable_inventory_boxes (player_id INTEGER NOT NULL, PRIMARY KEY(player_id));")
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
end

.inventory_boxes(player_id) ⇒ Boolean

Checks if inventory boxes are enabled for a specific player.

Examples:

is_enabled = Lich.inventory_boxes(12345)

Parameters:

  • player_id (Integer)

    The ID of the player to check.

Returns:

  • (Boolean)

    True if inventory boxes are enabled, otherwise false.

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



676
677
678
679
680
681
682
683
684
685
686
687
688
# File 'lib/lich.rb', line 676

def Lich.inventory_boxes(player_id)
  begin
    v = Lich.db.get_first_value('SELECT player_id FROM enable_inventory_boxes WHERE player_id=?;', [player_id.to_i])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  if v
    true
  else
    false
  end
end

Links the application to the Simutronics Auto-launch command on Windows or Wine.

This method checks if the application is already linked to the Auto-launch command. If not, it attempts to link it by modifying the Windows registry or using Wine’s registry functions.

Examples:

Lich.link_to_sal

Returns:

  • (Boolean)

    true if already linked or successfully linked, false otherwise.

Raises:

  • (StandardError)

    if there is an issue accessing the registry or executing commands.



433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/lich.rb', line 433

def Lich.link_to_sal
  if defined?(Win32)
    if Win32.admin?
      begin
        # fixme: 64 bit browsers?
        launcher_key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command', :samDesired => (Win32::KEY_ALL_ACCESS | Win32::KEY_WOW64_32KEY))[:phkResult]
        r = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'RealCommand')
        if (r[:return] == 0) and not r[:lpData].empty?
          # already linked
          return true
        end

        r = Win32.GetModuleFileName
        unless r[:return] > 0
          # fixme
          return false
        end

        new_launcher_cmd = "\"#{r[:lpFilename]}\" \"#{File.expand_path($PROGRAM_NAME)}\" %1"
        r = Win32.RegQueryValueEx(:hKey => launcher_key)
        launcher_cmd = r[:lpData]
        r = Win32.RegSetValueEx(:hKey => launcher_key, :lpValueName => 'RealCommand', :dwType => Win32::REG_SZ, :lpData => launcher_cmd)
        return false unless (r == 0)

        r = Win32.RegSetValueEx(:hKey => launcher_key, :dwType => Win32::REG_SZ, :lpData => new_launcher_cmd)
        return (r == 0)
      ensure
        Win32.RegCloseKey(:hKey => launcher_key) rescue nil
      end
    else
      begin
        r = Win32.GetModuleFileName
        file = ((r[:return] > 0) ? r[:lpFilename] : 'rubyw.exe')
        params = "#{$PROGRAM_NAME.split(/\/|\\/).last} --link-to-sal"
        r = Win32.ShellExecuteEx(:lpVerb => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params, :fMask => Win32::SEE_MASK_NOCLOSEPROCESS)
        if r[:return] > 0
          process_id = r[:hProcess]
          sleep 0.2 while Win32.GetExitCodeProcess(:hProcess => process_id)[:lpExitCode] == Win32::STILL_ACTIVE
          sleep 3
        else
          Win32.ShellExecute(:lpOperation => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params)
          sleep 6
        end
      rescue
        Lich.msgbox(:message => $!)
      end
    end
  elsif defined?(Wine)
    launch_cmd = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\')
    return false unless launch_cmd

    new_launch_cmd = "#{File.expand_path($PROGRAM_NAME)} --wine=#{Wine::BIN} --wine-prefix=#{Wine::PREFIX} %1"
    result = true
    if launch_cmd
      if launch_cmd =~ /lich/i
        $stdout.puts "--- warning: Lich appears to already be installed to the registry"
        Lich.log "warning: Lich appears to already be installed to the registry"
        Lich.log 'info: launch_cmd: ' + launch_cmd
      else
        result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\RealCommand', launch_cmd)
        result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\', new_launch_cmd)
      end
    end
    return result
  else
    return false
  end
end

Links the application to the Simutronics Game Engine (SGE) on Windows or Wine.

This method checks if the application is already linked to SGE. If not, it attempts to link it by modifying the Windows registry or using Wine’s registry functions.

Examples:

Lich.link_to_sge

Returns:

  • (Boolean)

    true if already linked or successfully linked, false otherwise.

Raises:

  • (StandardError)

    if there is an issue accessing the registry or executing commands.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/lich.rb', line 295

def Lich.link_to_sge
  if defined?(Win32)
    if Win32.admin?
      begin
        launcher_key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'Software\\Simutronics\\Launcher', :samDesired => (Win32::KEY_ALL_ACCESS | Win32::KEY_WOW64_32KEY))[:phkResult]
        r = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'RealDirectory')
        if (r[:return] == 0) and not r[:lpData].empty?
          # already linked
          return true
        end

        r = Win32.GetModuleFileName
        unless r[:return] > 0
          # fixme
          return false
        end

        new_launcher_dir = "\"#{r[:lpFilename]}\" \"#{File.expand_path($PROGRAM_NAME)}\" "
        r = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'Directory')
        launcher_dir = r[:lpData]
        r = Win32.RegSetValueEx(:hKey => launcher_key, :lpValueName => 'RealDirectory', :dwType => Win32::REG_SZ, :lpData => launcher_dir)
        return false unless (r == 0)

        r = Win32.RegSetValueEx(:hKey => launcher_key, :lpValueName => 'Directory', :dwType => Win32::REG_SZ, :lpData => new_launcher_dir)
        return (r == 0)
      ensure
        Win32.RegCloseKey(:hKey => launcher_key) rescue nil
      end
    else
      begin
        r = Win32.GetModuleFileName
        file = ((r[:return] > 0) ? r[:lpFilename] : 'rubyw.exe')
        params = "#{$PROGRAM_NAME.split(/\/|\\/).last} --link-to-sge"
        r = Win32.ShellExecuteEx(:lpVerb => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params, :fMask => Win32::SEE_MASK_NOCLOSEPROCESS)
        if r[:return] > 0
          process_id = r[:hProcess]
          sleep 0.2 while Win32.GetExitCodeProcess(:hProcess => process_id)[:lpExitCode] == Win32::STILL_ACTIVE
          sleep 3
        else
          Win32.ShellExecute(:lpOperation => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params)
          sleep 6
        end
      rescue
        Lich.msgbox(:message => $!)
      end
    end
  elsif defined?(Wine)
    launch_dir = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\Directory')
    return false unless launch_dir

    lich_launch_dir = "#{File.expand_path($PROGRAM_NAME)} --wine=#{Wine::BIN} --wine-prefix=#{Wine::PREFIX}  "
    result = true
    if launch_dir
      if launch_dir =~ /lich/i
        $stdout.puts "--- warning: Lich appears to already be installed to the registry"
        Lich.log "warning: Lich appears to already be installed to the registry"
        Lich.log 'info: launch_dir: ' + launch_dir
      else
        result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\RealDirectory', launch_dir)
        result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\Directory', lich_launch_dir)
      end
    end
    return result
  else
    return false
  end
end

.log(msg) ⇒ Object

Logs a message to standard error with a timestamp.

Examples:

Lich.log("This is a log message.")

Parameters:

  • msg (String)

    the message to log.



139
140
141
# File 'lib/lich.rb', line 139

def Lich.log(msg)
  $stderr.puts "#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}: #{msg}"
end

.method_missing(arg1, arg2 = '') ⇒ Object

Handles missing methods for Lich, providing a warning for deprecated usage.

Examples:

Lich.method_missing(:some_method)

Parameters:

  • arg1 (Symbol)

    the name of the missing method.

  • arg2 (String) (defaults to: '')

    optional, additional argument for the method.

Returns:

  • (Object)

    the result of Vars.method_missing if called.



61
62
63
64
65
66
67
# File 'lib/lich.rb', line 61

def Lich.method_missing(arg1, arg2 = '')
  if (Time.now.to_i - @@last_warn_deprecated) > 300
    respond "--- warning: Lich.* variables will stop working in a future version of Lich.  Use Vars.* (offending script: #{Script.current.name || 'unknown'})"
    @@last_warn_deprecated = Time.now.to_i
  end
  Vars.method_missing(arg1, arg2)
end

.modify_hosts(game_host) ⇒ Boolean

Modifies the hosts file to include a new game host.

Examples:

success = Lich.modify_hosts('example.game.host')

Parameters:

  • game_host (String)

    The game host to add to the hosts file.

Returns:

  • (Boolean)

    True if the modification was successful, otherwise false.



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/lich.rb', line 621

def Lich.modify_hosts(game_host)
  if Lich.hosts_file and File.exist?(Lich.hosts_file)
    at_exit { Lich.restore_hosts }
    Lich.restore_hosts
    if File.exist?("#{Lich.hosts_file}.bak")
      return false
    end

    begin
      # copy hosts to hosts.bak
      File.open("#{Lich.hosts_file}.bak", 'w') { |hb| File.open(Lich.hosts_file) { |h| hb.write(h.read) } }
    rescue
      File.unlink("#{Lich.hosts_file}.bak") if File.exist?("#{Lich.hosts_file}.bak")
      return false
    end
    File.open(Lich.hosts_file, 'a') { |f| f.write "\r\n127.0.0.1\t\t#{game_host}" }
    return true
  else
    return false
  end
end

.module_eval(*_a) ⇒ nil

Returns nil for module evaluation.

Parameters:

  • _a (Array)

    ignored parameters.

Returns:

  • (nil)

    always returns nil.



132
# File 'lib/lich.rb', line 132

def Lich.module_eval(*_a);        nil; end

.msgbox(args) ⇒ Symbol?

Displays a message box with specified options.

Examples:

Lich.msgbox(message: "Are you sure?", buttons: :yes_no, icon: :question)

Parameters:

  • args (Hash)

    options for the message box.

Options Hash (args):

  • :message (String)

    the message to display.

  • :buttons (Symbol)

    the type of buttons to display (:ok_cancel, :yes_no).

  • :icon (Symbol)

    the icon to display (:error, :question, :warning).

  • :title (String)

    the title of the message box.

Returns:

  • (Symbol, nil)

    returns :ok, :cancel, :yes, :no, or nil based on user response.



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/lich.rb', line 183

def Lich.msgbox(args)
  if defined?(Win32)
    if args[:buttons] == :ok_cancel
      buttons = Win32::MB_OKCANCEL
    elsif args[:buttons] == :yes_no
      buttons = Win32::MB_YESNO
    else
      buttons = Win32::MB_OK
    end
    if args[:icon] == :error
      icon = Win32::MB_ICONERROR
    elsif args[:icon] == :question
      icon = Win32::MB_ICONQUESTION
    elsif args[:icon] == :warning
      icon = Win32::MB_ICONWARNING
    else
      icon = 0
    end
    args[:title] ||= "Lich v#{LICH_VERSION}"
    r = Win32.MessageBox(:lpText => args[:message], :lpCaption => args[:title], :uType => (buttons | icon))
    if r == Win32::IDIOK
      return :ok
    elsif r == Win32::IDICANCEL
      return :cancel
    elsif r == Win32::IDIYES
      return :yes
    elsif r == Win32::IDINO
      return :no
    else
      return nil
    end
  elsif defined?(Gtk)
    if args[:buttons] == :ok_cancel
      buttons = Gtk::MessageDialog::BUTTONS_OK_CANCEL
    elsif args[:buttons] == :yes_no
      buttons = Gtk::MessageDialog::BUTTONS_YES_NO
    else
      buttons = Gtk::MessageDialog::BUTTONS_OK
    end
    if args[:icon] == :error
      type = Gtk::MessageDialog::ERROR
    elsif args[:icon] == :question
      type = Gtk::MessageDialog::QUESTION
    elsif args[:icon] == :warning
      type = Gtk::MessageDialog::WARNING
    else
      type = Gtk::MessageDialog::INFO
    end
    dialog = Gtk::MessageDialog.new(nil, Gtk::Dialog::MODAL, type, buttons, args[:message])
    args[:title] ||= "Lich v#{LICH_VERSION}"
    dialog.title = args[:title]
    response = nil
    dialog.run { |d_r|
      response = d_r
      dialog.destroy
    }
    if response == Gtk::Dialog::RESPONSE_OK
      return :ok
    elsif response == Gtk::Dialog::RESPONSE_CANCEL
      return :cancel
    elsif response == Gtk::Dialog::RESPONSE_YES
      return :yes
    elsif response == Gtk::Dialog::RESPONSE_NO
      return :no
    else
      return nil
    end
  elsif $stdout.isatty
    $stdout.puts(args[:message])
    return nil
  end
end

.mutex_lockObject

Locks the database mutex to ensure thread safety during operations.

Examples:

Lich.mutex_lock

Raises:

  • (StandardError)

    if an error occurs while locking the mutex.



31
32
33
34
35
36
37
38
# File 'lib/lich.rb', line 31

def self.mutex_lock
  begin
    self.db_mutex.lock unless self.db_mutex.owned?
  rescue StandardError
    respond "--- Lich: error: Lich.mutex_lock: #{$!}"
    Lich.log "error: Lich.mutex_lock: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
  end
end

.mutex_unlockObject

Unlocks the database mutex after operations are complete.

Examples:

Lich.mutex_unlock

Raises:

  • (StandardError)

    if an error occurs while unlocking the mutex.



45
46
47
48
49
50
51
52
# File 'lib/lich.rb', line 45

def self.mutex_unlock
  begin
    self.db_mutex.unlock if self.db_mutex.owned?
  rescue StandardError
    respond "--- Lich: error: Lich.mutex_unlock: #{$!}"
    Lich.log "error: Lich.mutex_unlock: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
  end
end

.restore_hostsnil

Restores the original hosts file from the backup.

Examples:

Lich.restore_hosts

Returns:

  • (nil)

    Returns nil after attempting to restore the hosts file.

Raises:

  • (StandardError)

    If there is an error during the restore process.



649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
# File 'lib/lich.rb', line 649

def Lich.restore_hosts
  if Lich.hosts_file and File.exist?(Lich.hosts_file)
    begin
      # fixme: use rename instead?  test rename on windows
      if File.exist?("#{Lich.hosts_file}.bak")
        File.open("#{Lich.hosts_file}.bak") { |infile|
          File.open(Lich.hosts_file, 'w') { |outfile|
            outfile.write(infile.read)
          }
        }
        File.unlink "#{Lich.hosts_file}.bak"
      end
    rescue
      $stdout.puts "--- error: restore_hosts: #{$!}"
      Lich.log "error: restore_hosts: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
      exit(1)
    end
  end
end

.seek(fe) ⇒ String?

Retrieves the location of the front-end based on the provided identifier.

Examples:

Lich.seek('wizard')

Parameters:

  • fe (String)

    the front-end identifier (e.g., ‘wizard’, ‘stormfront’).

Returns:

  • (String, nil)

    the location of the front-end or nil if not found.



75
76
77
78
79
80
81
82
# File 'lib/lich.rb', line 75

def Lich.seek(fe)
  if fe =~ /wizard/
    return $wiz_fe_loc
  elsif fe =~ /stormfront/
    return $sf_fe_loc
  end
  pp "Landed in get_simu_launcher method"
end

.set_inventory_boxes(player_id, enabled) ⇒ nil

Enables or disables inventory boxes for a specific player.

Examples:

Lich.set_inventory_boxes(12345, true)

Parameters:

  • player_id (Integer)

    The ID of the player to modify.

  • enabled (Boolean)

    True to enable, false to disable.

Returns:

  • (nil)

    Returns nil after executing the operation.

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/lich.rb', line 698

def Lich.set_inventory_boxes(player_id, enabled)
  if enabled
    begin
      Lich.db.execute('INSERT OR REPLACE INTO enable_inventory_boxes values(?);', [player_id.to_i])
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
  else
    begin
      Lich.db.execute('DELETE FROM enable_inventory_boxes where player_id=?;', [player_id.to_i])
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
  end
  nil
end

.show_deprecated_lognil

Displays the log of deprecated messages.

Examples:

Lich.show_deprecated_log

Returns:

  • (nil)

    returns nothing.



167
168
169
170
171
# File 'lib/lich.rb', line 167

def Lich.show_deprecated_log
  @@deprecated_log.each do |msg|
    respond(msg)
  end
end

.track_autosort_stateBoolean

Retrieves the current state of the track autosort state setting.

Examples:

track_autosort_state = Lich.track_autosort_state

Returns:

  • (Boolean)

    The current state of the track autosort state setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
# File 'lib/lich.rb', line 1062

def Lich.track_autosort_state
  if @@track_autosort_state.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='track_autosort_state';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    @@track_autosort_state = (val.to_s =~ /on|true|yes/ ? true : false)
  end
  return @@track_autosort_state
end

.track_autosort_state=(val) ⇒ nil

Sets the track autosort state setting.

Examples:

Lich.track_autosort_state = true

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
# File 'lib/lich.rb', line 1082

def Lich.track_autosort_state=(val)
  @@track_autosort_state = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('track_autosort_state',?);", [@@track_autosort_state.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.track_dark_modeBoolean

Retrieves the current state of the track dark mode setting.

Examples:

track_dark_mode = Lich.track_dark_mode

Returns:

  • (Boolean)

    The current state of the track dark mode setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'lib/lich.rb', line 1099

def Lich.track_dark_mode
  if @@track_dark_mode.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='track_dark_mode';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    @@track_dark_mode = (val.to_s =~ /on|true|yes/ ? true : false)
  end
  return @@track_dark_mode
end

.track_dark_mode=(val) ⇒ nil

Sets the track dark mode setting.

Examples:

Lich.track_dark_mode = false

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/lich.rb', line 1119

def Lich.track_dark_mode=(val)
  @@track_dark_mode = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('track_dark_mode',?);", [@@track_dark_mode.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

.track_layout_stateBoolean

Retrieves the current state of the track layout state setting.

Examples:

track_layout_state = Lich.track_layout_state

Returns:

  • (Boolean)

    The current state of the track layout state setting.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
# File 'lib/lich.rb', line 1136

def Lich.track_layout_state
  if @@track_layout_state.nil?
    begin
      val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='track_layout_state';")
    rescue SQLite3::BusyException
      sleep 0.1
      retry
    end
    @@track_layout_state = (val.to_s =~ /on|true|yes/ ? true : false)
  end
  return @@track_layout_state
end

.track_layout_state=(val) ⇒ nil

Sets the track layout state setting.

Examples:

Lich.track_layout_state = true

Parameters:

  • val (Object)

    The value to set, can be any object that responds to ‘to_s`.

Returns:

  • (nil)

    Always returns nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy, the method will retry after a short sleep.



1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
# File 'lib/lich.rb', line 1156

def Lich.track_layout_state=(val)
  @@track_layout_state = (val.to_s =~ /on|true|yes/ ? true : false)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('track_layout_state',?);", [@@track_layout_state.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  return nil
end

Unlinks the application from the Simutronics Auto-launch command on Windows or Wine.

This method checks if the application is linked to the Auto-launch command. If it is, it attempts to unlink it by modifying the Windows registry or using Wine’s registry functions.

Examples:

Lich.unlink_from_sal

Returns:

  • (Boolean)

    true if not linked or successfully unlinked, false otherwise.

Raises:

  • (StandardError)

    if there is an issue accessing the registry or executing commands.



512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'lib/lich.rb', line 512

def Lich.unlink_from_sal
  if defined?(Win32)
    if Win32.admin?
      begin
        launcher_key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command', :samDesired => (Win32::KEY_ALL_ACCESS | Win32::KEY_WOW64_32KEY))[:phkResult]
        real_directory = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'RealCommand')[:lpData]
        if real_directory.nil? or real_directory.empty?
          # not linked
          return true
        end

        r = Win32.RegSetValueEx(:hKey => launcher_key, :dwType => Win32::REG_SZ, :lpData => real_directory)
        return false unless (r == 0)

        r = Win32.RegDeleteValue(:hKey => launcher_key, :lpValueName => 'RealCommand')
        return (r == 0)
      ensure
        Win32.RegCloseKey(:hKey => launcher_key) rescue nil
      end
    else
      begin
        r = Win32.GetModuleFileName
        file = ((r[:return] > 0) ? r[:lpFilename] : 'rubyw.exe')
        params = "#{$PROGRAM_NAME.split(/\/|\\/).last} --unlink-from-sal"
        r = Win32.ShellExecuteEx(:lpVerb => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params, :fMask => Win32::SEE_MASK_NOCLOSEPROCESS)
        if r[:return] > 0
          process_id = r[:hProcess]
          sleep 0.2 while Win32.GetExitCodeProcess(:hProcess => process_id)[:lpExitCode] == Win32::STILL_ACTIVE
          sleep 3
        else
          Win32.ShellExecute(:lpOperation => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params)
          sleep 6
        end
      rescue
        Lich.msgbox(:message => $!)
      end
    end
  elsif defined?(Wine)
    real_launch_cmd = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\RealCommand')
    result = true
    if real_launch_cmd and not real_launch_cmd.empty?
      result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\', real_launch_cmd)
      result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Classes\\Simutronics.Autolaunch\\Shell\\Open\\command\\RealCommand', '')
    end
    return result
  else
    return false
  end
end

Unlinks the application from the Simutronics Game Engine (SGE) on Windows or Wine.

This method checks if the application is linked to SGE. If it is, it attempts to unlink it by modifying the Windows registry or using Wine’s registry functions.

Examples:

Lich.unlink_from_sge

Returns:

  • (Boolean)

    true if not linked or successfully unlinked, false otherwise.

Raises:

  • (StandardError)

    if there is an issue accessing the registry or executing commands.



373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
# File 'lib/lich.rb', line 373

def Lich.unlink_from_sge
  if defined?(Win32)
    if Win32.admin?
      begin
        launcher_key = Win32.RegOpenKeyEx(:hKey => Win32::HKEY_LOCAL_MACHINE, :lpSubKey => 'Software\\Simutronics\\Launcher', :samDesired => (Win32::KEY_ALL_ACCESS | Win32::KEY_WOW64_32KEY))[:phkResult]
        real_directory = Win32.RegQueryValueEx(:hKey => launcher_key, :lpValueName => 'RealDirectory')[:lpData]
        if real_directory.nil? or real_directory.empty?
          # not linked
          return true
        end

        r = Win32.RegSetValueEx(:hKey => launcher_key, :lpValueName => 'Directory', :dwType => Win32::REG_SZ, :lpData => real_directory)
        return false unless (r == 0)

        r = Win32.RegDeleteValue(:hKey => launcher_key, :lpValueName => 'RealDirectory')
        return (r == 0)
      ensure
        Win32.RegCloseKey(:hKey => launcher_key) rescue nil
      end
    else
      begin
        r = Win32.GetModuleFileName
        file = ((r[:return] > 0) ? r[:lpFilename] : 'rubyw.exe')
        params = "#{$PROGRAM_NAME.split(/\/|\\/).last} --unlink-from-sge"
        r = Win32.ShellExecuteEx(:lpVerb => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params, :fMask => Win32::SEE_MASK_NOCLOSEPROCESS)
        if r[:return] > 0
          process_id = r[:hProcess]
          sleep 0.2 while Win32.GetExitCodeProcess(:hProcess => process_id)[:lpExitCode] == Win32::STILL_ACTIVE
          sleep 3
        else
          Win32.ShellExecute(:lpOperation => 'runas', :lpFile => file, :lpDirectory => LICH_DIR.tr("/", "\\"), :lpParameters => params)
          sleep 6
        end
      rescue
        Lich.msgbox(:message => $!)
      end
    end
  elsif defined?(Wine)
    real_launch_dir = Wine.registry_gets('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\RealDirectory')
    result = true
    if real_launch_dir and not real_launch_dir.empty?
      result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\Directory', real_launch_dir)
      result = result && Wine.registry_puts('HKEY_LOCAL_MACHINE\\Software\\Simutronics\\Launcher\\RealDirectory', '')
    end
    return result
  else
    return false
  end
end

.win32_launch_methodString?

Retrieves the current win32 launch method from the database.

Examples:

launch_method = Lich.win32_launch_method

Returns:

  • (String, nil)

    The win32 launch method if found, otherwise nil.

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



723
724
725
726
727
728
729
730
731
# File 'lib/lich.rb', line 723

def Lich.win32_launch_method
  begin
    val = Lich.db.get_first_value("SELECT value FROM lich_settings WHERE name='win32_launch_method';")
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
  val
end

.win32_launch_method=(val) ⇒ nil

Sets the win32 launch method in the database.

Examples:

Lich.win32_launch_method = 'new_method'

Parameters:

  • val (String)

    The win32 launch method to set.

Returns:

  • (nil)

    Returns nil after executing the operation.

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



740
741
742
743
744
745
746
747
# File 'lib/lich.rb', line 740

def Lich.win32_launch_method=(val)
  begin
    Lich.db.execute("INSERT OR REPLACE INTO lich_settings(name,value) values('win32_launch_method',?);", [val.to_s.encode('UTF-8')])
  rescue SQLite3::BusyException
    sleep 0.1
    retry
  end
end