Module: Lich

Included in:
DragonRealms, Gemstone
Defined in:
documented/lich.rb,
documented/vars.rb,
documented/games.rb,
documented/stash.rb,
documented/update.rb,
documented/messaging.rb,
documented/util/util.rb,
documented/common/gtk.rb,
documented/common/hmr.rb,
documented/common/log.rb,
documented/magic-info.rb,
documented/common/vars.rb,
documented/gemstone/sk.rb,
documented/common/spell.rb,
documented/common/buffer.rb,
documented/common/script.rb,
documented/gemstone/disk.rb,
documented/gemstone/gift.rb,
documented/gemstone/psms.rb,
documented/common/account.rb,
documented/common/eaccess.rb,
documented/common/gameobj.rb,
documented/gemstone/claim.rb,
documented/gemstone/group.rb,
documented/gemstone/scars.rb,
documented/attributes/char.rb,
documented/common/db_store.rb,
documented/common/settings.rb,
documented/common/uservars.rb,
documented/common/watchfor.rb,
documented/gemstone/bounty.rb,
documented/gemstone/wounds.rb,
documented/attributes/stats.rb,
documented/common/front-end.rb,
documented/common/gui-login.rb,
documented/common/xmlparser.rb,
documented/gemstone/effects.rb,
documented/gemstone/infomon.rb,
documented/gemstone/society.rb,
documented/attributes/skills.rb,
documented/attributes/spells.rb,
documented/common/map/map_dr.rb,
documented/common/map/map_gs.rb,
documented/gemstone/creature.rb,
documented/gemstone/stowlist.rb,
documented/common/game-loader.rb,
documented/gemstone/critranks.rb,
documented/gemstone/psms/cman.rb,
documented/gemstone/psms/feat.rb,
documented/gemstone/readylist.rb,
documented/common/limitedarray.rb,
documented/common/sharedbuffer.rb,
documented/common/upstreamhook.rb,
documented/gemstone/experience.rb,
documented/gemstone/psms/armor.rb,
documented/gemstone/spellranks.rb,
documented/attributes/resources.rb,
documented/attributes/spellsong.rb,
documented/gemstone/bounty/task.rb,
documented/gemstone/infomon/cli.rb,
documented/gemstone/psms/shield.rb,
documented/gemstone/psms/warcry.rb,
documented/gemstone/psms/weapon.rb,
documented/common/downstreamhook.rb,
documented/dragonrealms/drinfomon.rb,
documented/gemstone/bounty/parser.rb,
documented/gemstone/combat/parser.rb,
documented/gemstone/infomon/cache.rb,
documented/gemstone/combat/tracker.rb,
documented/gemstone/infomon/parser.rb,
documented/gemstone/infomon/status.rb,
documented/gemstone/psms/ascension.rb,
documented/gemstone/combat/defs/ucs.rb,
documented/gemstone/combat/processor.rb,
documented/gemstone/infomon/currency.rb,
documented/gemstone/infomon/xmlparser.rb,
documented/dragonrealms/commons/common.rb,
documented/gemstone/combat/defs/damage.rb,
documented/common/class_exts/stringproc.rb,
documented/common/settings/charsettings.rb,
documented/common/settings/gamesettings.rb,
documented/gemstone/combat/defs/attacks.rb,
documented/gemstone/infomon/activespell.rb,
documented/dragonrealms/commons/slackbot.rb,
documented/dragonrealms/drinfomon/drdefs.rb,
documented/dragonrealms/drinfomon/drroom.rb,
documented/dragonrealms/drinfomon/events.rb,
documented/gemstone/combat/defs/statuses.rb,
documented/common/settings/path_navigator.rb,
documented/common/settings/settings_proxy.rb,
documented/dragonrealms/drinfomon/drskill.rb,
documented/dragonrealms/drinfomon/drstats.rb,
documented/dragonrealms/drinfomon/drparser.rb,
documented/dragonrealms/drinfomon/drspells.rb,
documented/gemstone/combat/async_processor.rb,
documented/common/settings/database_adapter.rb,
documented/gemstone/societies/order_of_voln.rb,
documented/dragonrealms/commons/common-items.rb,
documented/dragonrealms/commons/common-money.rb,
documented/dragonrealms/commons/equipmanager.rb,
documented/dragonrealms/commons/common-arcana.rb,
documented/dragonrealms/commons/common-travel.rb,
documented/dragonrealms/drinfomon/drvariables.rb,
documented/dragonrealms/commons/common-healing.rb,
documented/dragonrealms/commons/common-theurgy.rb,
documented/gemstone/societies/council_of_light.rb,
documented/common/class_exts/synchronizedsocket.rb,
documented/dragonrealms/commons/common-crafting.rb,
documented/dragonrealms/commons/common-moonmage.rb,
documented/dragonrealms/commons/common-summoning.rb,
documented/dragonrealms/commons/common-validation.rb,
documented/gemstone/societies/guardians_of_sunfist.rb,
documented/dragonrealms/commons/common-healing-data.rb

Overview

Provides functionality for the Lich project

Examples:

Using the Lich module

Lich::DragonRealms::DRCS.summon_weapon

Defined Under Namespace

Modules: Claim, Common, Currency, DragonRealms, GameBase, 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
@@debug_messaging =

boolean

nil

Class Method Summary collapse

Class Method Details

.break_game_host_port(gamehost, gameport) ⇒ Array

Reverts the game host and port to their original values based on known mappings.

Parameters:

  • gamehost (String)

    The current game host.

  • gameport (Integer)

    The current game port.

Returns:

  • (Array)

    The reverted game host and port.



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
# File 'documented/lich.rb', line 687

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) ⇒ Object



113
# File 'documented/lich.rb', line 113

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

.class_variable_get(*_a) ⇒ Object



111
# File 'documented/lich.rb', line 111

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

.core_updated_with_lich_versionString

Retrieves the version with which the core was last updated.

Returns:

  • (String)

    The version string.



798
799
800
801
802
803
804
805
806
# File 'documented/lich.rb', line 798

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 with which the core was last updated.

Parameters:

  • val (String)

    The new version string.

Returns:

  • (nil)


811
812
813
814
815
816
817
818
819
# File 'documented/lich.rb', line 811

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 and returns the SQLite3 database connection.

Returns:

  • (SQLite3::Database)

    The database connection.



86
87
88
# File 'documented/lich.rb', line 86

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.



26
27
28
# File 'documented/lich.rb', line 26

def self.db_mutex
  @@db_mutex
end

.debug_messagingBoolean

Retrieves the current debug messaging setting.

Returns:

  • (Boolean)

    True if debug messaging is enabled, false otherwise.



708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'documented/lich.rb', line 708

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.

Parameters:

  • val (Boolean)

    The new debug messaging setting.

Returns:

  • (nil)


725
726
727
728
729
730
731
732
733
734
# File 'documented/lich.rb', line 725

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 the use of old objects.

Examples:

Logging a deprecation

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

Parameters:

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

    The deprecated object name.

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

    The recommended replacement object name.

  • 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 send the message to the front-end.

  • limit_log (Boolean) (defaults to: true)

    Whether to limit logging of the same message.

Returns:

  • (nil)


135
136
137
138
139
140
141
# File 'documented/lich.rb', line 135

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 display exits setting.

Returns:

  • (Boolean)

    True if display exits is enabled, false otherwise.



853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'documented/lich.rb', line 853

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.

Parameters:

  • val (Boolean)

    The new display exits setting.

Returns:

  • (nil)


870
871
872
873
874
875
876
877
878
879
# File 'documented/lich.rb', line 870

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 current display Lich ID setting.

Returns:

  • (Boolean)

    True if display Lich ID is enabled, false otherwise.



738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'documented/lich.rb', line 738

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 Lich ID setting.

Parameters:

  • val (Boolean)

    The new display Lich ID setting.

Returns:

  • (nil)


755
756
757
758
759
760
761
762
763
764
# File 'documented/lich.rb', line 755

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 display string procs setting.

Returns:

  • (Boolean)

    True if display string procs is enabled, false otherwise.



883
884
885
886
887
888
889
890
891
892
893
894
895
# File 'documented/lich.rb', line 883

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.

Parameters:

  • val (Boolean)

    The new display string procs setting.

Returns:

  • (nil)


900
901
902
903
904
905
906
907
908
909
# File 'documented/lich.rb', line 900

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 display UID setting.

Returns:

  • (Boolean)

    True if display UID is enabled, false otherwise.



823
824
825
826
827
828
829
830
831
832
833
834
835
# File 'documented/lich.rb', line 823

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.

Parameters:

  • val (Boolean)

    The new display UID setting.

Returns:

  • (nil)


840
841
842
843
844
845
846
847
848
849
# File 'documented/lich.rb', line 840

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_fileObject



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
# File 'documented/lich.rb', line 512

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 known mappings.

Parameters:

  • gamehost (String)

    The original game host.

  • gameport (Integer)

    The original game port.

Returns:

  • (Array)

    The fixed game host and port.



666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'documented/lich.rb', line 666

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 launching the Simutronics game.

Returns:

  • (String, nil)

    The launcher command or nil if not found.



237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'documented/lich.rb', line 237

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 hide UID flag setting.

Returns:

  • (Boolean)

    True if hide UID flag is enabled, false otherwise.



768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'documented/lich.rb', line 768

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 setting.

Parameters:

  • val (Boolean)

    The new hide UID flag setting.

Returns:

  • (nil)


785
786
787
788
789
790
791
792
793
794
# File 'documented/lich.rb', line 785

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

Finds and returns the path to the hosts file used by the system.

Returns:

  • (String, false)

    The path to the hosts file or false if not found.



507
508
509
510
# File 'documented/lich.rb', line 507

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

.init_dbObject

Initializes the database and creates necessary tables if they do not exist.

Examples:

Initializing the database

Lich.init_db

Raises:

  • (SQLite3::BusyException)

    If the database is busy.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'documented/lich.rb', line 94

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 the specified player.

Parameters:

  • player_id (Integer)

    The ID of the player.

Returns:

  • (Boolean)

    True if inventory boxes are enabled, false otherwise.



601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'documented/lich.rb', line 601

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 Lich application to the Simutronics Autolaunch environment.

Returns:

  • (Boolean)

    True if linked successfully, false otherwise.



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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'documented/lich.rb', line 384

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 Lich application to the Simutronics game environment.

Returns:

  • (Boolean)

    True if linked successfully, false otherwise.



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
# File 'documented/lich.rb', line 262

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:

Logging a message

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

Parameters:

  • msg (String)

    The message to log.



121
122
123
# File 'documented/lich.rb', line 121

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

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

Handles calls to undefined methods, providing a warning for deprecated usage.

Examples:

Calling a missing method

Lich.some_missing_method

Parameters:

  • arg1 (Symbol)

    The name of the method being called.

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

    An optional second argument.

Returns:

  • (Object)

    The result of the Vars.method_missing call.



62
63
64
65
66
67
68
# File 'documented/lich.rb', line 62

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 the specified game host.

Parameters:

  • game_host (String)

    The game host to add to the hosts file.

Returns:

  • (Boolean)

    True if modified successfully, false otherwise.



552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'documented/lich.rb', line 552

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) ⇒ Object



115
# File 'documented/lich.rb', line 115

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

.msgbox(args) ⇒ Symbol?

Displays a message box with the specified options.

Examples:

Displaying a message box

response = Lich.msgbox(:message => "Hello, World!", :title => "Greeting")

Parameters:

  • args (Hash)

    Options for the message box.

Options Hash (args):

  • :message (String)

    The message to display.

  • :title (String)

    The title of the message box.

  • :buttons (Symbol)

    The buttons to display (:ok_cancel, :yes_no).

  • :icon (Symbol)

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

Returns:

  • (Symbol, nil)

    The response from the message box (:ok, :cancel, :yes, :no) or nil.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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
# File 'documented/lich.rb', line 162

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:

Locking the mutex

Lich.mutex_lock

Raises:

  • (StandardError)

    If an error occurs while locking the mutex.



34
35
36
37
38
39
40
41
# File 'documented/lich.rb', line 34

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:

Unlocking the mutex

Lich.mutex_unlock

Raises:

  • (StandardError)

    If an error occurs while unlocking the mutex.



47
48
49
50
51
52
53
54
# File 'documented/lich.rb', line 47

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:

Restoring hosts

Lich.restore_hosts

Returns:

  • (nil)


578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
# File 'documented/lich.rb', line 578

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?

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

Examples:

Seeking a front-end location

location = 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 'documented/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

Sets the inventory boxes state for the specified player.

Parameters:

  • player_id (Integer)

    The ID of the player.

  • enabled (Boolean)

    Whether to enable or disable inventory boxes.

Returns:

  • (nil)


619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
# File 'documented/lich.rb', line 619

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:

Showing the deprecated log

Lich.show_deprecated_log

Returns:

  • (nil)


147
148
149
150
151
# File 'documented/lich.rb', line 147

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

.track_autosort_stateBoolean

Retrieves the current track autosort state setting.

Returns:

  • (Boolean)

    True if track autosort state is enabled, false otherwise.



913
914
915
916
917
918
919
920
921
922
923
924
# File 'documented/lich.rb', line 913

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.

Parameters:

  • val (Boolean)

    The new track autosort state setting.

Returns:

  • (nil)


929
930
931
932
933
934
935
936
937
938
# File 'documented/lich.rb', line 929

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 track dark mode setting.

Returns:

  • (Boolean)

    True if track dark mode is enabled, false otherwise.



942
943
944
945
946
947
948
949
950
951
952
953
# File 'documented/lich.rb', line 942

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.

Parameters:

  • val (Boolean)

    The new track dark mode setting.

Returns:

  • (nil)


958
959
960
961
962
963
964
965
966
967
# File 'documented/lich.rb', line 958

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 track layout state setting.

Returns:

  • (Boolean)

    True if track layout state is enabled, false otherwise.



971
972
973
974
975
976
977
978
979
980
981
982
# File 'documented/lich.rb', line 971

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.

Parameters:

  • val (Boolean)

    The new track layout state setting.

Returns:

  • (nil)


987
988
989
990
991
992
993
994
995
996
# File 'documented/lich.rb', line 987

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 Lich application from the Simutronics Autolaunch environment.

Returns:

  • (Boolean)

    True if unlinked successfully, false otherwise.



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
501
502
503
# File 'documented/lich.rb', line 455

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 Lich application from the Simutronics game environment.

Returns:

  • (Boolean)

    True if unlinked successfully, false otherwise.



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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'documented/lich.rb', line 332

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 Windows launch method setting.

Returns:

  • (String)

    The launch method setting.



640
641
642
643
644
645
646
647
648
# File 'documented/lich.rb', line 640

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 Windows launch method setting.

Parameters:

  • val (String)

    The new launch method setting.

Returns:

  • (nil)


653
654
655
656
657
658
659
660
# File 'documented/lich.rb', line 653

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