Skip to content

Commit

Permalink
BRO
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackx2 committed Jun 29, 2024
1 parent fe0198e commit 7dcddf8
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 79 deletions.
2 changes: 1 addition & 1 deletion source/funkin/backend/Highscore.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/backend/client/Discord.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class DiscordClient
var requestPtr:cpp.Star<DiscordUser> = 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();
}
Expand Down
2 changes: 1 addition & 1 deletion source/funkin/backend/funkinLua/FunkinLua.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
58 changes: 58 additions & 0 deletions source/funkin/backend/handlers/CrashHandler.hx
Original file line number Diff line number Diff line change
@@ -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<StackItem> = 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
}
4 changes: 3 additions & 1 deletion source/funkin/backend/utils/native/WindowUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 9 additions & 3 deletions source/funkin/game/Init.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand Down
55 changes: 3 additions & 52 deletions source/funkin/game/Main.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package funkin.game;

import funkin.backend.handlers.CrashHandler;
import flixel.graphics.FlxGraphic;
import flixel.FlxG;
import flixel.FlxGame;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<StackItem> = 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
}
12 changes: 2 additions & 10 deletions source/funkin/game/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -3349,9 +3343,7 @@ class PlayState extends MusicBeatState
}

if (startedCountdown)
{
Conductor.songPosition += FlxG.elapsed * 1000 * playbackRate;
}

if (startingSong)
{
Expand Down
10 changes: 1 addition & 9 deletions source/funkin/game/states/TitleState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 7dcddf8

Please sign in to comment.