Skip to content

Commit be917a5

Browse files
committed
hi
1 parent 4b07bcc commit be917a5

File tree

6 files changed

+191
-52
lines changed

6 files changed

+191
-52
lines changed

source/Main.hx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import crowplexus.iris.Iris;
2626
import psychlua.HScript.HScriptInfos;
2727
#end
2828

29-
#if linux
29+
#if (linux || mac)
3030
import lime.graphics.Image;
3131
#end
3232

@@ -54,6 +54,7 @@ import backend.Highscore;
5454
@:cppInclude('./external/gamemode_client.h')
5555
@:cppFileCode('#define GAMEMODE_AUTO')
5656
#end
57+
5758
#if windows
5859
@:buildXml('
5960
<target id="haxe">
@@ -71,7 +72,7 @@ extern "C" HRESULT WINAPI SetCurrentProcessExplicitAppUserModelID(PCWSTR AppID);
7172
// // // // // // // // //
7273
class Main extends Sprite
7374
{
74-
var game = {
75+
public static final game = {
7576
width: 1280, // WINDOW width
7677
height: 720, // WINDOW height
7778
initialState: states.FirstCheckState, // initial game state
@@ -99,18 +100,8 @@ class Main extends Sprite
99100
public function new()
100101
{
101102
super();
102-
#if windows
103-
// DPI Scaling fix for windows
104-
// this shouldn't be needed for other systems
105-
// Credit to YoshiCrafter29 for finding this function
106-
untyped __cpp__("SetProcessDPIAware();");
107-
108-
var display = lime.system.System.getDisplay(0);
109-
if (display != null) {
110-
var dpiScale:Float = display.dpi / 96;
111-
Application.current.window.width = Std.int(game.width * dpiScale);
112-
Application.current.window.height = Std.int(game.height * dpiScale);
113-
}
103+
#if (cpp && windows)
104+
backend.window.Native.fixScaling();
114105
#end
115106

116107
// Credits to MAJigsaw77 (he's the og author for this code)
@@ -222,7 +213,7 @@ class Main extends Sprite
222213
}
223214
#end
224215

225-
#if linux
216+
#if (linux || mac) // fix the app icon not showing up on the Linux Panel / Mac Dock
226217
var icon = Image.fromFile("icon.png");
227218
Lib.current.stage.window.setIcon(icon);
228219
#end
@@ -247,6 +238,10 @@ class Main extends Sprite
247238
DiscordClient.prepare();
248239
#end
249240

241+
FlxG.fixedTimestep = false;
242+
FlxG.game.focusLostFramerate = 60;
243+
FlxG.keys.preventDefaultKeys = [TAB];
244+
250245
Lib.current.loaderInfo.addEventListener(NativeProcessExitEvent.EXIT, onClosing); // help-
251246

252247
// try { // WHY THE HELL IS THIS CRASHING???????????????????
@@ -475,8 +470,7 @@ class Main extends Sprite
475470
} else {
476471
Application.current.window.alert("The game encountered a critical error and will now restart.", "Game Bricked");
477472
trace("The game was bricked. Restarting...");
478-
var mainInstance = new Main();
479-
var mainGame = mainInstance.game;
473+
var mainGame = Main.game;
480474
var initialState = Type.getClass(mainGame.initialState);
481475
var restartProcess = new Process("Mixtape.exe", ["GameJoltBug", "restart"]);
482476
FlxG.switchState(new states.ExitState());
@@ -487,8 +481,7 @@ class Main extends Sprite
487481
case "APDisconnectSubstate":
488482
Application.current.window.alert("The game encountered a critical error and will now restart.", "AP Disconnect Error");
489483
trace("AP Disconnect Error. Restarting...");
490-
var mainInstance = new Main();
491-
var mainGame = mainInstance.game;
484+
var mainGame = Main.game;
492485
var initialState = Type.getClass(mainGame.initialState);
493486
var restartProcess = new Process("Mixtape.exe", ["APDisconnectError", "restart"]);
494487
// FlxG.switchState(new states.ExitState());
@@ -507,8 +500,7 @@ class Main extends Sprite
507500
}
508501

509502
if (!handled) {
510-
var mainInstance = new Main();
511-
var mainGame = mainInstance.game;
503+
var mainGame = Main.game;
512504
FlxG.switchState(Type.createInstance(states.TitleState, []));
513505
trace("Unhandled state: " + (Type.getClassName(Type.getClass(FlxG.state))));
514506
trace("Restarting Game...");

source/backend/window/Native.hx

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package backend.window;
2+
3+
import lime.app.Application;
4+
import lime.system.Display;
5+
import lime.system.System;
6+
7+
import flixel.util.FlxColor;
8+
9+
#if (cpp && windows)
10+
@:buildXml('
11+
<target id="haxe">
12+
<lib name="dwmapi.lib" if="windows"/>
13+
<lib name="gdi32.lib" if="windows"/>
14+
</target>
15+
')
16+
@:cppFileCode('
17+
#include <windows.h>
18+
#include <dwmapi.h>
19+
#include <winuser.h>
20+
#include <wingdi.h>
21+
22+
#define attributeDarkMode 20
23+
#define attributeDarkModeFallback 19
24+
25+
#define attributeCaptionColor 34
26+
#define attributeTextColor 35
27+
#define attributeBorderColor 36
28+
29+
struct HandleData {
30+
DWORD pid = 0;
31+
HWND handle = 0;
32+
};
33+
34+
BOOL CALLBACK findByPID(HWND handle, LPARAM lParam) {
35+
DWORD targetPID = ((HandleData*)lParam)->pid;
36+
DWORD curPID = 0;
37+
38+
GetWindowThreadProcessId(handle, &curPID);
39+
if (targetPID != curPID || GetWindow(handle, GW_OWNER) != (HWND)0 || !IsWindowVisible(handle)) {
40+
return TRUE;
41+
}
42+
43+
((HandleData*)lParam)->handle = handle;
44+
return FALSE;
45+
}
46+
47+
HWND curHandle = 0;
48+
void getHandle() {
49+
if (curHandle == (HWND)0) {
50+
HandleData data;
51+
data.pid = GetCurrentProcessId();
52+
EnumWindows(findByPID, (LPARAM)&data);
53+
curHandle = data.handle;
54+
}
55+
}
56+
')
57+
#end
58+
class Native
59+
{
60+
public static function __init__():Void
61+
{
62+
registerDPIAware();
63+
}
64+
65+
public static function registerDPIAware():Void
66+
{
67+
#if (cpp && windows)
68+
// DPI Scaling fix for windows
69+
// this shouldn't be needed for other systems
70+
// Credit to YoshiCrafter29 for finding this function
71+
untyped __cpp__('
72+
SetProcessDPIAware();
73+
#ifdef DPI_AWARENESS_CONTEXT
74+
SetProcessDpiAwarenessContext(
75+
#ifdef DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
76+
DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
77+
#else
78+
DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
79+
#endif
80+
);
81+
#endif
82+
');
83+
#end
84+
}
85+
86+
private static var fixedScaling:Bool = false;
87+
public static function fixScaling():Void
88+
{
89+
if (fixedScaling) return;
90+
fixedScaling = true;
91+
92+
#if (cpp && windows)
93+
final display:Null<Display> = System.getDisplay(0);
94+
if (display != null)
95+
{
96+
final dpiScale:Float = display.dpi / 96;
97+
@:privateAccess Application.current.window.width = Std.int(Main.game.width * dpiScale);
98+
@:privateAccess Application.current.window.height = Std.int(Main.game.height * dpiScale);
99+
100+
Application.current.window.x = Std.int((Application.current.window.display.bounds.width - Application.current.window.width) / 2);
101+
Application.current.window.y = Std.int((Application.current.window.display.bounds.height - Application.current.window.height) / 2);
102+
}
103+
104+
untyped __cpp__('
105+
getHandle();
106+
if (curHandle != (HWND)0) {
107+
HDC curHDC = GetDC(curHandle);
108+
RECT curRect;
109+
GetClientRect(curHandle, &curRect);
110+
FillRect(curHDC, &curRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
111+
ReleaseDC(curHandle, curHDC);
112+
}
113+
');
114+
#end
115+
}
116+
}

source/psychlua/HScript.hx

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import crowplexus.hscript.Expr.Error as IrisError;
1818
import crowplexus.hscript.Printer;
1919
import objects.VideoSprite;
2020

21+
import haxe.ValueException;
22+
2123
typedef HScriptInfos = {
2224
> haxe.PosInfos,
2325
var ?funcName:String;
@@ -526,7 +528,7 @@ class HScript extends Iris
526528
final retVal:IrisCall = funk.hscript.call(funcToRun, funcArgs);
527529
if (retVal != null)
528530
{
529-
return (retVal.returnValue == null || LuaUtils.isOfTypes(retVal.returnValue, [Bool, Int, Float, String, Array])) ? retVal.returnValue : null;
531+
return (LuaUtils.isLuaSupported(retVal.returnValue)) ? retVal.returnValue : null;
530532
}
531533
else if (funk.hscript.returnValue != null)
532534
{
@@ -542,7 +544,7 @@ class HScript extends Iris
542544
final retVal:IrisCall = funk.hscript.call(funcToRun, funcArgs);
543545
if (retVal != null)
544546
{
545-
return (retVal.returnValue == null || LuaUtils.isOfTypes(retVal.returnValue, [Bool, Int, Float, String, Array])) ? retVal.returnValue : null;
547+
return (LuaUtils.isLuaSupported(retVal.returnValue)) ? retVal.returnValue : null;
546548
}
547549
}
548550
else
@@ -600,21 +602,29 @@ class HScript extends Iris
600602
final ret = Reflect.callMethod(null, func, args ?? []);
601603
return {funName: funcToRun, signature: func, returnValue: ret};
602604
}
603-
catch(e:Dynamic) {
604-
if (Std.is(e, IrisError)) {
605-
var pos:HScriptInfos = cast this.interp.posInfos();
606-
pos.funcName = funcToRun;
607-
#if LUA_ALLOWED
608-
if (parentLua != null)
609-
{
610-
pos.isLua = true;
611-
if (parentLua.lastCalledFunction != '') pos.funcName = parentLua.lastCalledFunction;
612-
}
613-
#end
614-
Iris.error(Printer.errorToString(e, false), pos);
615-
} else {
616-
trace(e);
605+
catch(e:IrisError) {
606+
var pos:HScriptInfos = cast this.interp.posInfos();
607+
pos.funcName = funcToRun;
608+
#if LUA_ALLOWED
609+
if (parentLua != null)
610+
{
611+
pos.isLua = true;
612+
if (parentLua.lastCalledFunction != '') pos.funcName = parentLua.lastCalledFunction;
617613
}
614+
#end
615+
Iris.error(Printer.errorToString(e, false), pos);
616+
}
617+
catch (e:ValueException) {
618+
var pos:HScriptInfos = cast this.interp.posInfos();
619+
pos.funcName = funcToRun;
620+
#if LUA_ALLOWED
621+
if (parentLua != null)
622+
{
623+
pos.isLua = true;
624+
if (parentLua.lastCalledFunction != '') pos.funcName = parentLua.lastCalledFunction;
625+
}
626+
#end
627+
Iris.error('$e', pos);
618628
}
619629
return null;
620630
}
@@ -706,6 +716,23 @@ class CustomInterp extends crowplexus.hscript.Interp
706716
super();
707717
}
708718

719+
override function fcall(o:Dynamic, funcToRun:String, args:Array<Dynamic>):Dynamic {
720+
for (_using in usings) {
721+
var v = _using.call(o, funcToRun, args);
722+
if (v != null)
723+
return v;
724+
}
725+
726+
var f = get(o, funcToRun);
727+
728+
if (f == null) {
729+
Iris.error('Tried to call null function $funcToRun', posInfos());
730+
return null;
731+
}
732+
733+
return Reflect.callMethod(o, f, args);
734+
}
735+
709736
override function resolve(id: String): Dynamic {
710737
if (locals.exists(id)) {
711738
var l = locals.get(id);
@@ -752,4 +779,4 @@ class HScript
752779
}
753780
#end
754781
}
755-
#end
782+
#end

source/psychlua/LuaUtils.hx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package psychlua;
22

33
import backend.WeekData;
44
import objects.Character;
5+
import stages.StageData;
56

67
import openfl.display.BlendMode;
78
import Type.ValueType;
@@ -42,11 +43,10 @@ class LuaUtils
4243
// Legacy shit.
4344

4445
inline public static function getTextObject(name:String):FlxText
45-
{
46-
return #if LUA_ALLOWED PlayState.instance.modchartTexts.exists(name) ? PlayState.instance.modchartTexts.get(name) : #end Reflect.getProperty(PlayState.instance, name);
47-
}
46+
{
47+
return #if LUA_ALLOWED PlayState.instance.modchartTexts.exists(name) ? PlayState.instance.modchartTexts.get(name) : #end Reflect.getProperty(PlayState.instance, name);
48+
}
4849

49-
5050
public static function resetTextTag(tag:String) {
5151
#if LUA_ALLOWED
5252
if(!PlayState.instance.modchartTexts.exists(tag)) {
@@ -61,7 +61,6 @@ class LuaUtils
6161
#end
6262
}
6363

64-
6564
public static function setVarInArray(instance:Dynamic, variable:String, value:Dynamic, allowMaps:Bool = false):Any
6665
{
6766
var splitProps:Array<String> = variable.split('[');
@@ -94,7 +93,7 @@ class LuaUtils
9493
return value;
9594
}
9695

97-
if(MusicBeatState.getVariables().exists(variable))
96+
if(instance is MusicBeatState && MusicBeatState.getVariables().exists(variable))
9897
{
9998
MusicBeatState.getVariables().set(variable, value);
10099
return value;
@@ -131,7 +130,7 @@ class LuaUtils
131130
return instance.get(variable);
132131
}
133132

134-
if(MusicBeatState.getVariables().exists(variable))
133+
if(instance is MusicBeatState && MusicBeatState.getVariables().exists(variable))
135134
{
136135
var retVal:Dynamic = MusicBeatState.getVariables().get(variable);
137136
if(retVal != null)
@@ -286,6 +285,9 @@ class LuaUtils
286285
}
287286
return false;
288287
}
288+
public static function isLuaSupported(value:Any):Bool {
289+
return (value == null || isOfTypes(value, [Bool, Int, Float, String, Array]) || Type.typeof(value) == ValueType.TObject);
290+
}
289291

290292
public static function getTargetInstance()
291293
{
@@ -295,7 +297,9 @@ class LuaUtils
295297

296298
public static inline function getLowestCharacterGroup():FlxSpriteGroup
297299
{
298-
var group:FlxSpriteGroup = PlayState.instance.gfGroup;
300+
var stageData:StageFile = StageData.getStageFile(PlayState.SONG.stage);
301+
var group:FlxSpriteGroup = (stageData.hide_girlfriend ? PlayState.instance.boyfriendGroup : PlayState.instance.gfGroup);
302+
299303
var pos:Int = PlayState.instance.members.indexOf(group);
300304

301305
var newPos:Int = PlayState.instance.members.indexOf(PlayState.instance.boyfriendGroup);

source/states/LoadingState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import flixel.FlxState;
1414
import flash.media.Sound;
1515

1616
import backend.Song;
17-
import backend.StageData;
17+
import stages.StageData;
1818
import objects.Character;
1919

2020
import sys.thread.Thread;

0 commit comments

Comments
 (0)