Files
LonaRPG-Online-Games/Data/Scripts/1_CoreSecurity.rb
T
2026-10-29 21:59:06 +04:00

108 lines
2.3 KiB
Ruby

# encoding: UTF-8
module LonaCoreSecurity
SAFE_ARG_ALLOWLIST = ["gamescopemode"] unless const_defined?(:SAFE_ARG_ALLOWLIST)
DEV_UNLOCK_TOKEN = "LONARPG_DEV_CONSOLE_UNLOCK" unless const_defined?(:DEV_UNLOCK_TOKEN)
DEV_UNLOCK_FILES = ["UserData/DevConsole.unlock", "DevConsole.unlock"] unless const_defined?(:DEV_UNLOCK_FILES)
BUILTIN_MOD_IDS = ["NoerHome"] unless const_defined?(:BUILTIN_MOD_IDS)
module_function
def dev_console_unlocked?
return @dev_console_unlocked unless @dev_console_unlocked.nil?
@dev_console_unlocked = false
DEV_UNLOCK_FILES.each do |path|
begin
next unless File.file?(path)
text = File.open(path, "rb") { |f| f.read.to_s }.strip
if text == DEV_UNLOCK_TOKEN
@dev_console_unlocked = true
break
end
rescue
end
end
@dev_console_unlocked
rescue
false
end
def console_allowed?
false
rescue
false
end
def sanitize_argv!
return if dev_console_unlocked?
begin
if defined?(ARGV) && ARGV.respond_to?(:replace)
safe = []
ARGV.each do |arg|
text = arg.to_s.strip
safe << text if SAFE_ARG_ALLOWLIST.include?(text.downcase)
end
ARGV.replace(safe)
end
rescue
end
begin
$TEST = false if defined?($TEST)
$BTEST = false if defined?($BTEST)
rescue
end
end
def blocked_console!
begin
SndLib.sys_buzzer if defined?(SndLib) && SndLib.respond_to?(:sys_buzzer)
rescue
end
begin
prp "SECURITY: F10 console blocked by CoreSecurity", 1 if defined?(prp)
rescue
end
false
rescue
false
end
def restart_game
spawn("Game.exe")
rescue
false
end
def builtin_mod_id?(mod_id)
BUILTIN_MOD_IDS.include?(mod_id.to_s)
rescue
false
end
def enforce_runtime!
sanitize_argv! if respond_to?(:sanitize_argv!)
begin
$DEBUG = false if defined?($DEBUG)
$prp_console_enabled = false if defined?($prp_console_enabled)
rescue
end
rescue SystemExit
raise
rescue
end
def normalize_mod_data(data)
return {} unless data.respond_to?(:each)
result = {}
data.each do |key, value|
next if builtin_mod_id?(key)
result[key] = value
end
result
rescue
{}
end
end
LonaCoreSecurity.sanitize_argv!