This repository has been archived on 2024-04-19. You can view files and clone it, but cannot push or open issues or pull requests.
Jessist/Scripts/CrashHandler.gd
2022-06-18 13:05:48 +02:00

117 lines
6 KiB
GDScript

######################
### Jessist Script ###
######################
# This script is part of Jessist
# Jessist is licensed under GNU GPLv3
#
# This script is part of the CrashHandler scene and animates the CrashHandler and collects debugging information
extends Node2D
export (Array) var debuggingInformation = ["script", "function", "debuginformation"]
var collectedMessage = null
var collectedLog = null
var waitTime = 0.0002
var debuggingMessages = ["500 Internal Game Error","Oh no!","Oops! Something has gone wrong!","A wild error appeared!","A wild MissingNo appeared!","Never gonna give you up, never gonna let you down","Did this get written in Java?","Code one, debug everywhere - Motto of Java","yes yes very bad","Oopsie dasy!","Did system-oomd on Ubuntu 22.4 LTS kill more than it should?","oUt oF mEmOrY!1!!!11","Uhh, is this a crash?","You are running Jessist v0.0.0.0.0.1.25.2.5.1 alpha release candidate build 2342","this was developed by a java dev","This was coded in BASIC","Kernel panic - not syncing: VFS: Unable to mount root fs","*** STOP: 0x00000050 (0xFCCBFFFF,0x00000000,0x00000000)","root@localhost:~# strace jessist","exited with code 255","why am i here","im a fallen text","*sans incoming*","NANI?!","help me","HTTP/1.1 GET /crash","^C","You hacked my game!","wot da fck"]
var crashMessageTemplate = "%rdm%\n====================================\nError encountered in script %script%, running function %func%\nUTC Time and date: %time% | %date%\nUnix time: %unixtime%\nLocale: %locale%\nDebug build: %dbgbuild%\nA memory dump can be found at %memdump% (please send with report)\n\nDebugging information provided by the reporting function:\n%dbginfo%\n\nComplete log file:\n%logloc%\n\nThis crash can also be found at %crashreport%"
#%rdm%
#====================================
#Error encountered in script %script%, running function %func%
#UTC Time and date: %time% | %date%
#Unix time: %unixtime%
#Locale: %locale%
#Debug build: %dbgbuild%
#A memory dump can be found at %memdump% (please send with report)
#
#Debugging information provided by the reporting function:
#%dbginfo%
#
#Complete log file:
#%logloc%
#
#This crash can also be found at %crashreport%
func _ready():
gameController.logCall("CrashHandler","_ready",null)
$Sound.play(0)
animationTitle()
animationDescription()
Thread.new().start(self,"setCrashDescription")
#animationCrashDescription()
func animationTitle():
gameController.logCall("CrashHandler","animationTitle",null)
var node = get_node("Background/Title")
var text = node.text
var textWritten = ""
node.bbcode_text = ""
for c in text:
textWritten = textWritten + c
node.bbcode_text = "[center]" + textWritten + "[/center]"
yield(get_tree().create_timer(waitTime*750),"timeout")
node.bbcode_text = "[center][shake rate=20 level=40]" + text + "[/shake][/center]"
func animationDescription():
gameController.logCall("CrashHandler","animationDescription",null)
var node = get_node("Background/Description")
node.visible_characters = 0
for c in node.text:
node.visible_characters += 2
yield(get_tree().create_timer(waitTime),"timeout")
func animationCrashDescription():
gameController.logCall("CrashHandler","animationCrashDescription",null)
var node = get_node("Background/CrashInformation")
if not (debuggingInformation == null or debuggingInformation == ""):
node.text = debuggingInformation
node.visible_characters = 0
for c in node.text:
node.visible_characters += 2
yield(get_tree().create_timer(waitTime),"timeout")
func setCrashDescription():
gameController.logCall("CrashHandler","setCrashDescription",null)
$Background/CrashInformation.text = "Please wait while Jessist retrieves and collects debug information (this may take a LONG time)"
gameController.logInfo("CrashHandler","setCrashDescription","Setting RDM")
var rng = RandomNumberGenerator.new()
rng.randomize()
var randomDebugMessage = debuggingMessages[rng.randi_range(0,int(debuggingMessages.size()))]
gameController.logInfo("CrashHandler","setCrashDescription","Creating memory dump")
OS.dump_memory_to_file(OS.get_user_data_dir() + "/crash.dump")
gameController.logInfo("CrashHandler","setCrashDescription","Collecting log (last 5000 lines)")
var fullLog = gameController.getLog(5000)
gameController.logInfo("CrashHandler","setCrashDescription","Creating crash message")
var message = crashMessageTemplate
message = message.replace("%rdm%",randomDebugMessage)
message = message.replace("%script%",debuggingInformation[0])
message = message.replace("%func%",debuggingInformation[1])
message = message.replace("%time%",OS.get_time(true))
message = message.replace("%date%",OS.get_date(true))
message = message.replace("%unixtime%",OS.get_unix_time())
message = message.replace("%locale%",OS.get_locale())
message = message.replace("%dbgbuild%",OS.is_debug_build())
message = message.replace("%memdump%",OS.get_user_data_dir() + "/crash.dump")
message = message.replace("%dbginfo%",debuggingInformation[2])
message = message.replace("%logloc%",OS.get_user_data_dir() + "/crash.log")
message = message.replace("%log%",fullLog)
message = message.replace("%crashreport%",OS.get_user_data_dir() + "/crash.txt")
gameController.logInfo("CrashHandler","setCrashDescription","Saving crash report")
var crashreport = File.new()
crashreport.open(OS.get_user_data_dir() + "/crash.txt",File.WRITE)
crashreport.store_string(message)
crashreport.close()
crashreport.open(OS.get_user_data_dir() + "/crash.log",File.WRITE)
crashreport.store_string(fullLog)
crashreport.close()
gameController.logInfo("CrashHandler","setCrashDescription","Displaying crash report")
$Background/CrashInformation.text = message
gameController.logInfo("CrashHandler","setCrashDescription","Making crash report information available")
collectedLog = fullLog
collectedMessage = message
func quitButtonPressed():
gameController.logInfo("CrashHandler","setCrashDescription","Quitting Jessist...")
get_tree().quit(25)
func copyButtonPressed():
OS.clipboard = "-- JESSIST CRASHREPORT --\n\n" + collectedMessage + "\n\n-- JESSIST LOGFILE --\n\n" + collectedLog