Skip to content

Commit 16335cc

Browse files
committed
awesome flxsave
1 parent 400ef63 commit 16335cc

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

source/funkin/modding/PolymodHandler.hx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class PolymodHandler
256256
// NOTE: Scripted classes are automatically aliased to their parent class.
257257
Polymod.addImportAlias('flixel.math.FlxPoint', flixel.math.FlxPoint.FlxBasePoint);
258258

259+
// flixel.util.FlxSave has a `resolveFlixelClasses` function
260+
Polymod.addImportAlias('flixel.util.FlxSave', funkin.save.FlxSaveSandboxed);
261+
259262
Polymod.addImportAlias('funkin.data.event.SongEventSchema', funkin.data.event.SongEventSchema.SongEventSchemaRaw);
260263

261264
// `lime.utils.Assets` literally just has a private `resolveClass` function for some reason? so we replace it with our own.
@@ -315,10 +318,6 @@ class PolymodHandler
315318
// Unserializer.DEFAULT_RESOLVER.resolveClass() can access blacklisted packages
316319
Polymod.blacklistImport('haxe.Unserializer');
317320

318-
// `flixel.util.FlxSave`
319-
// FlxSave.resolveFlixelClasses() can access blacklisted packages
320-
Polymod.blacklistImport('flixel.util.FlxSave');
321-
322321
// Disable access to AdMob Util
323322
Polymod.blacklistImport('funkin.mobile.util.AdMobUtil');
324323

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package funkin.save;
2+
3+
import flixel.util.FlxSave;
4+
import haxe.Exception;
5+
6+
/**
7+
* Wrapper for `FlxSave`
8+
* Prevents the use of `resolveFlixelClasses` function
9+
* Also locks down saves to only save inside the `FunkinCrew` folder
10+
*/
11+
@:nullSafety
12+
class FlxSaveSandboxed extends FlxSave
13+
{
14+
static final SAVE_PATH:String = 'FunkinCrew';
15+
static final SAVE_NAME:String = 'Funkin';
16+
static final BASE_SAVE_SLOT:Int = 1;
17+
18+
public function new()
19+
{
20+
super();
21+
}
22+
23+
override public function bind(name:String, ?path:String, ?backupParser:(String, Exception)->Null<Any>):Bool
24+
{
25+
if (name == '$SAVE_NAME${BASE_SAVE_SLOT}' && path == null) throw 'Unable to bind to $name. Use funkin.save.Save instead.';
26+
return super.bind(name, '$SAVE_PATH${path != null ? '/$path' : ''}', backupParser);
27+
}
28+
29+
override public function mergeDataFrom(name:String, ?path:String, overwrite = false, eraseSave = true, minFileSize = 0):Bool
30+
{
31+
if (name == '$SAVE_NAME${BASE_SAVE_SLOT}' && path == null) throw 'Unable to merge save. Requested save data cannot be a Funkin save.';
32+
return super.mergeDataFrom(name, '$SAVE_PATH${path != null ? '/$path' : ''}', overwrite, false, minFileSize);
33+
}
34+
35+
@:unreflective
36+
override public function erase():Bool
37+
{
38+
if (this.name == '$SAVE_NAME${BASE_SAVE_SLOT}' && this.path == SAVE_PATH) throw 'Unable to delete ${this.name} because it\'s a Funkin save.';
39+
return super.erase();
40+
}
41+
}

0 commit comments

Comments
 (0)