diff --git a/source/funkin/backend/Highscore.hx b/source/funkin/backend/Highscore.hx index f2d58a1..a4eb5ac 100644 --- a/source/funkin/backend/Highscore.hx +++ b/source/funkin/backend/Highscore.hx @@ -133,7 +133,7 @@ class Highscore return weekScores.get(daWeek); } - public static function load():Void + public static function init():Void { if (FlxG.save.data.weekScores != null) { diff --git a/source/funkin/backend/client/Discord.hx b/source/funkin/backend/client/Discord.hx index 8c7fce9..8e91063 100644 --- a/source/funkin/backend/client/Discord.hx +++ b/source/funkin/backend/client/Discord.hx @@ -51,9 +51,9 @@ class DiscordClient var requestPtr:cpp.Star = cpp.ConstPointer.fromRaw(request).ptr; if (Std.parseInt(cast(requestPtr.discriminator, String)) != 0) // New Discord IDs/Discriminator system - traceFr('Connected to User (${cast (requestPtr.username, String)}#${cast (requestPtr.discriminator, String)})'); + traceFr('Connected to User [${cast (requestPtr.username, String)}#${cast (requestPtr.discriminator, String)}]'); else // Old discriminators - traceFr('Connected to User (${cast (requestPtr.username, String)})'); + traceFr('Connected to User [${cast (requestPtr.username, String)}]'); changePresence(); } diff --git a/source/funkin/backend/funkinLua/FunkinLua.hx b/source/funkin/backend/funkinLua/FunkinLua.hx index 11c985e..10175ce 100644 --- a/source/funkin/backend/funkinLua/FunkinLua.hx +++ b/source/funkin/backend/funkinLua/FunkinLua.hx @@ -227,7 +227,7 @@ class FunkinLua { set('scriptName', scriptName); set('currentModDirectory', Paths.currentModDirectory); set('scoreBarType', ClientPrefs.data.scoreBarType); - #if windows set('darkmode', funkin.backend.utils.native.WindowUtil.darkMode); #end + #if windows set('darkMode', funkin.backend.utils.native.WindowUtil.darkMode); #end set('buildTarget', LuaUtils.getBuildTarget()); diff --git a/source/funkin/backend/handlers/CrashHandler.hx b/source/funkin/backend/handlers/CrashHandler.hx new file mode 100644 index 0000000..3e1cf88 --- /dev/null +++ b/source/funkin/backend/handlers/CrashHandler.hx @@ -0,0 +1,58 @@ +package funkin.backend.handlers; + +#if CRASH_HANDLER +import lime.app.Application; +import openfl.events.UncaughtErrorEvent; +import haxe.CallStack; +import haxe.io.Path; +import sys.FileSystem; +import sys.io.File; +import sys.io.Process; +#end + +class CrashHandler +{ + #if CRASH_HANDLER + public static function onCrash(e:UncaughtErrorEvent):Void + { + var errMsg:String = ""; + var path:String; + final callStack:Array = CallStack.exceptionStack(true); + final dateNow:String = Date.now().toString().replace(" ", "_").replace(":", "'"); + + path = './crash/${Application.current.meta.get('file')}_$dateNow.txt'; + trace(path); + + for (stackItem in callStack) + { + switch (stackItem) + { + case FilePos(s, file, line, column): + errMsg += file + " (line " + line + ")\n"; + default: + Sys.println(stackItem); + } + } + + errMsg += "\nUncaught Error: " + + e.error + + "\nPlease report this error to the GitHub page:" + + EngineData.engineData.repository + + "\n\n---------------------------------------------------------\n> Crash Handler written by: sqirra-rng"; + + if (!FileSystem.exists("./crash/")) + FileSystem.createDirectory("./crash/"); + + File.saveContent(path, errMsg + "\n"); + + Sys.println(errMsg); + Sys.println("Crash dump saved in " + Path.normalize(path)); + + Application.current.window.alert(errMsg, "Error!"); + #if DISCORD_ALLOWED + DiscordClient.shutdown(); + #end + Sys.exit(1); + } + #end +} \ No newline at end of file diff --git a/source/funkin/backend/utils/native/WindowUtil.hx b/source/funkin/backend/utils/native/WindowUtil.hx index 20f63cf..bac96e5 100644 --- a/source/funkin/backend/utils/native/WindowUtil.hx +++ b/source/funkin/backend/utils/native/WindowUtil.hx @@ -19,7 +19,9 @@ class WindowUtil if (S_OK != DwmSetWindowAttribute(window, 19, &darkMode, sizeof(darkMode))) DwmSetWindowAttribute(window, 20, &darkMode, sizeof(darkMode)); ') - public static function darkMode(enable:Bool){} + public static function darkMode(enable:Bool){ + trace('Darkmode ${enable ? 'Enabled' : 'Disabled'}'); + } public static function setTitle(?s:String, ?normal:Bool = true) { diff --git a/source/funkin/game/Init.hx b/source/funkin/game/Init.hx index bd221f5..a48caa7 100644 --- a/source/funkin/game/Init.hx +++ b/source/funkin/game/Init.hx @@ -19,9 +19,10 @@ class Init extends flixel.FlxState Logs.init(); Volume.init(); - funkin.backend.Highscore.load(); + funkin.backend.Highscore.init(); funkin.backend.utils.ClientPrefs.init(); MusicBeatState.init(); + init(); #if DISCORD_ALLOWED DiscordClient.prepare(); @@ -30,11 +31,16 @@ class Init extends flixel.FlxState super.create(); // Extra stuff goes here :3 - if (FlxG.save.data != null && FlxG.save.data.fullscreen) - FlxG.fullscreen = FlxG.save.data.fullscreen; FlxG.switchState(new TitleState()); } + + private inline function init():Void { + if (FlxG.save.data != null && FlxG.save.data.fullscreen) + FlxG.fullscreen = FlxG.save.data.fullscreen; + if (FlxG.save.data.weekCompleted != null) + funkin.game.states.StoryMenuState.weekCompleted = FlxG.save.data.weekCompleted; + } } class Volume diff --git a/source/funkin/game/Main.hx b/source/funkin/game/Main.hx index 04d4092..1c43299 100644 --- a/source/funkin/game/Main.hx +++ b/source/funkin/game/Main.hx @@ -1,5 +1,6 @@ package funkin.game; +import funkin.backend.handlers.CrashHandler; import flixel.graphics.FlxGraphic; import flixel.FlxG; import flixel.FlxGame; @@ -15,14 +16,8 @@ import funkin.backend.utils.ClientPrefs; #if DISCORD_ALLOWED import funkin.backend.client.Discord.DiscordClient; #end -// crash handler stuff #if CRASH_HANDLER import openfl.events.UncaughtErrorEvent; -import haxe.CallStack; -import haxe.io.Path; -import sys.FileSystem; -import sys.io.File; -import sys.io.Process; #end import funkin.backend.data.*; import funkin.game.FPS; @@ -56,7 +51,7 @@ class Main extends Sprite public static function exitOn(?type:Int = 0, ?traceE:Bool = false) { if (traceE) - trace("Exit at " + Date.now().toString()); + trace('Exited at ${Date.now().toString()}'); Sys.exit(type); } @@ -118,54 +113,10 @@ class Main extends Sprite #end #if CRASH_HANDLER - Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, onCrash); + Lib.current.loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, CrashHandler.onCrash); #end } // Code was entirely made by sqirra-rng for their fnf engine named "Izzy Engine", big props to them!!! // very cool person for real they don't get enough credit for their work - #if CRASH_HANDLER - function onCrash(e:UncaughtErrorEvent):Void - { - var errMsg:String = ""; - var path:String; - final callStack:Array = CallStack.exceptionStack(true); - final dateNow:String = Date.now().toString().replace(" ", "_").replace(":", "'"); - final currentName = Application.current.meta.get('file'); - - path = './crash/${currentName}_$dateNow.txt'; - trace(path); - - for (stackItem in callStack) - { - switch (stackItem) - { - case FilePos(s, file, line, column): - errMsg += file + " (line " + line + ")\n"; - default: - Sys.println(stackItem); - } - } - - errMsg += "\nUncaught Error: " - + e.error - + "\nPlease report this error to the GitHub page:" - + EngineData.engineData.repository - + "\n\n---------------------------------------------------------\n> Crash Handler written by: sqirra-rng"; - - if (!FileSystem.exists("./crash/")) - FileSystem.createDirectory("./crash/"); - - File.saveContent(path, errMsg + "\n"); - - Sys.println(errMsg); - Sys.println("Crash dump saved in " + Path.normalize(path)); - - Application.current.window.alert(errMsg, "Error!"); - #if DISCORD_ALLOWED - DiscordClient.shutdown(); - #end - Sys.exit(1); - } - #end } diff --git a/source/funkin/game/states/PlayState.hx b/source/funkin/game/states/PlayState.hx index 4b412d8..9a28c67 100644 --- a/source/funkin/game/states/PlayState.hx +++ b/source/funkin/game/states/PlayState.hx @@ -3307,12 +3307,7 @@ class PlayState extends MusicBeatState } if (FlxG.keys.anyJustPressed(debugKeysChart) && !endingSong && !inCutscene) - { openChartEditor(); - } - - // FlxG.watch.addQuick('VOL', vocals.amplitudeLeft); - // FlxG.watch.addQuick('VOLRight', vocals.amplitudeRight); var mult:Float = FlxMath.lerp(1, iconP1.scale.x, CoolUtil.boundTo(1 - (elapsed * 9 * playbackRate), 0, 1)); iconP1.scale.set(mult, mult); @@ -3335,10 +3330,9 @@ class PlayState extends MusicBeatState else iconP1.animation.curAnim.curFrame = 0; - if (healthBar.percent > 80){ + if (healthBar.percent > 80) iconP2.animation.curAnim.curFrame = 1; - iconP1.animation.curAnim.curFrame = 2; - } else + else iconP2.animation.curAnim.curFrame = 0; if (FlxG.keys.anyJustPressed(debugKeysCharacter) && !endingSong && !inCutscene) { @@ -3349,9 +3343,7 @@ class PlayState extends MusicBeatState } if (startedCountdown) - { Conductor.songPosition += FlxG.elapsed * 1000 * playbackRate; - } if (startingSong) { diff --git a/source/funkin/game/states/TitleState.hx b/source/funkin/game/states/TitleState.hx index 2a3d965..04e3149 100644 --- a/source/funkin/game/states/TitleState.hx +++ b/source/funkin/game/states/TitleState.hx @@ -136,15 +136,7 @@ class TitleState extends MusicBeatState titleJSON = Json.parse(Paths.getTextFromFile('data/titleJson.json')); if (!initialized) - { - persistentUpdate = true; - persistentDraw = true; - } - - if (FlxG.save.data.weekCompleted != null) - { - funkin.game.states.StoryMenuState.weekCompleted = FlxG.save.data.weekCompleted; - } + persistentUpdate = persistentDraw = true; #if FREEPLAY MusicBeatState.switchState(new game.states.FreeplayState());