Skip to content

Commit fa63d58

Browse files
committed
Update Desain Sofwere[ Beta ]
1 parent 0094eb3 commit fa63d58

20 files changed

Lines changed: 590 additions & 25 deletions

Bloxstrap/App.xaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Windows.Threading;
66

77
using Microsoft.Win32;
8+
using Bloxstrap.Integrations;
89

910
namespace Bloxstrap
1011
{
@@ -343,6 +344,27 @@ protected override void OnStartup(StartupEventArgs e)
343344
FastFlags.Load();
344345
GlobalSettings.Load();
345346

347+
// Initialize app background on startup
348+
try
349+
{
350+
Logger.WriteLine(LOG_IDENT, "Initializing app background");
351+
352+
// Validate and set random app background if enabled
353+
if (Settings.Prop.EnableWallpaperLauncher)
354+
{
355+
bool isValid = AppBackgroundService.ValidateBackgroundFiles();
356+
357+
if (isValid)
358+
{
359+
Logger.WriteLine(LOG_IDENT, "App background files validated");
360+
}
361+
}
362+
}
363+
catch (Exception ex)
364+
{
365+
Logger.WriteLine(LOG_IDENT, $"App background initialization failed: {ex.Message}");
366+
}
367+
346368
if (Settings.Prop.AllowCookieAccess)
347369
Task.Run(Cookies.LoadCookies);
348370

Bloxstrap/Bloxstrap.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<EmbeddedResource Include="Resources\Mods\Sounds\OldWalk.mp3" />
6161
<EmbeddedResource Include="Resources\Mods\Sounds\Empty.mp3" />
6262
<EmbeddedResource Include="Resources\Mods\OldAvatarBackground.rbxl" />
63+
<None Include="Resources\Wallpapers\wallpapers.jpg" CopyToOutputDirectory="PreserveNewest" />
64+
<None Include="Resources\Wallpapers\wallpapersC.jpg" CopyToOutputDirectory="PreserveNewest" />
65+
<None Include="Resources\Wallpapers\wallpapersQ.jpg" CopyToOutputDirectory="PreserveNewest" />
6366
</ItemGroup>
6467

6568
<ItemGroup>

Bloxstrap/Bloxstrap.ico

-210 KB
Binary file not shown.

Bloxstrap/Bloxstrap.png

-344 KB
Loading
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Windows.Media.Imaging;
6+
7+
namespace Bloxstrap.Integrations
8+
{
9+
/// <summary>
10+
/// Service untuk mengubah background UI aplikasi BoneFish
11+
/// Mendukung 3 pilihan wallpaper sebagai background dari folder Bloxstrap\Resources\Wallpapers\
12+
/// Wallpaper berubah random setiap kali aplikasi dibuka
13+
/// </summary>
14+
public class AppBackgroundService
15+
{
16+
private const string LOG_IDENT = "AppBackgroundService";
17+
18+
public enum BackgroundType
19+
{
20+
Default = 0,
21+
Cool = 1,
22+
Quality = 2
23+
}
24+
25+
/// <summary>
26+
/// Get wallpaper image source berdasarkan tipe
27+
/// </summary>
28+
private static BitmapImage? GetBackgroundImage(BackgroundType type)
29+
{
30+
try
31+
{
32+
string wallpaperPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Wallpapers");
33+
34+
string imagePath = type switch
35+
{
36+
BackgroundType.Default => Path.Combine(wallpaperPath, "wallpapers.jpg"),
37+
BackgroundType.Cool => Path.Combine(wallpaperPath, "wallpapersC.jpg"),
38+
BackgroundType.Quality => Path.Combine(wallpaperPath, "wallpapersQ.jpg"),
39+
_ => Path.Combine(wallpaperPath, "wallpapers.jpg")
40+
};
41+
42+
if (!File.Exists(imagePath))
43+
{
44+
App.Logger.WriteLine(LOG_IDENT, $"Background image not found: {imagePath}");
45+
return null;
46+
}
47+
48+
BitmapImage bitmap = new();
49+
bitmap.BeginInit();
50+
bitmap.UriSource = new Uri(imagePath);
51+
bitmap.CacheOption = BitmapCacheOption.OnLoad;
52+
bitmap.EndInit();
53+
bitmap.Freeze();
54+
55+
return bitmap;
56+
}
57+
catch (Exception ex)
58+
{
59+
App.Logger.WriteLine(LOG_IDENT, $"Error loading background image: {ex.Message}");
60+
return null;
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Get random background image
66+
/// </summary>
67+
public static BitmapImage? GetRandomBackground()
68+
{
69+
try
70+
{
71+
var backgroundTypes = Enum.GetValues(typeof(BackgroundType)).Cast<BackgroundType>().ToList();
72+
var randomType = backgroundTypes[Random.Shared.Next(backgroundTypes.Count)];
73+
74+
App.Logger.WriteLine(LOG_IDENT, $"Selected random background: {randomType}");
75+
return GetBackgroundImage(randomType);
76+
}
77+
catch (Exception ex)
78+
{
79+
App.Logger.WriteLine(LOG_IDENT, $"Error getting random background: {ex.Message}");
80+
return null;
81+
}
82+
}
83+
84+
/// <summary>
85+
/// Get specific background image
86+
/// </summary>
87+
public static BitmapImage? GetBackground(BackgroundType type)
88+
{
89+
return GetBackgroundImage(type);
90+
}
91+
92+
/// <summary>
93+
/// Check if background files exist
94+
/// </summary>
95+
public static bool ValidateBackgroundFiles()
96+
{
97+
try
98+
{
99+
bool allExist = true;
100+
101+
foreach (BackgroundType type in Enum.GetValues(typeof(BackgroundType)))
102+
{
103+
string wallpaperPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources", "Wallpapers");
104+
string imagePath = type switch
105+
{
106+
BackgroundType.Default => Path.Combine(wallpaperPath, "wallpapers.jpg"),
107+
BackgroundType.Cool => Path.Combine(wallpaperPath, "wallpapersC.jpg"),
108+
BackgroundType.Quality => Path.Combine(wallpaperPath, "wallpapersQ.jpg"),
109+
_ => Path.Combine(wallpaperPath, "wallpapers.jpg")
110+
};
111+
112+
if (!File.Exists(imagePath))
113+
{
114+
App.Logger.WriteLine(LOG_IDENT, $"Missing background image: {type} at {imagePath}");
115+
allExist = false;
116+
}
117+
}
118+
119+
if (allExist)
120+
App.Logger.WriteLine(LOG_IDENT, "All background images validated successfully");
121+
122+
return allExist;
123+
}
124+
catch (Exception ex)
125+
{
126+
App.Logger.WriteLine(LOG_IDENT, $"Error validating background files: {ex.Message}");
127+
return false;
128+
}
129+
}
130+
}
131+
}

Bloxstrap/Integrations/FpsMonitorService.cs

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
using System;
12
using System.Windows;
3+
using System.Threading;
4+
using System.Windows.Threading;
25
using Bloxstrap.UI.Elements;
36

47
namespace Bloxstrap.Integrations
58
{
69
/// <summary>
710
/// Service untuk menampilkan FPS Monitor overlay saat game berjalan
11+
/// FPS Monitor tetap aktif bahkan setelah user keluar dari game atau menutup BoneFish
12+
/// Menggunakan separate dispatcher untuk persistence
813
/// </summary>
914
public class FpsMonitorService : IDisposable
1015
{
@@ -13,13 +18,16 @@ public class FpsMonitorService : IDisposable
1318
private readonly ActivityWatcher _activityWatcher;
1419
private FpsMonitorOverlay? _fpsOverlay;
1520
private bool _isRunning = false;
21+
private bool _persistentMode = false;
22+
private Dispatcher? _fpsDispatcher;
23+
private Thread? _fpsThread;
1624

1725
public FpsMonitorService(ActivityWatcher activityWatcher)
1826
{
1927
_activityWatcher = activityWatcher;
2028

2129
_activityWatcher.OnGameJoin += (_, _) => StartMonitoring();
22-
_activityWatcher.OnGameLeave += (_, _) => StopMonitoring();
30+
_activityWatcher.OnGameLeave += (_, _) => ContinueMonitoring();
2331
}
2432

2533
public void StartMonitoring()
@@ -32,15 +40,18 @@ public void StartMonitoring()
3240
App.Logger.WriteLine(LOG_IDENT, "Starting FPS Monitor");
3341

3442
_isRunning = true;
43+
_persistentMode = true;
3544

36-
// Create dan show FPS overlay di main thread
37-
if (Application.Current.Dispatcher != null)
45+
if (_fpsOverlay == null || _fpsDispatcher == null)
3846
{
39-
Application.Current.Dispatcher.Invoke(() =>
47+
CreateFpsWindowOnSeparateThread();
48+
}
49+
else if (_fpsDispatcher != null)
50+
{
51+
_fpsDispatcher.Invoke(() =>
4052
{
41-
if (_fpsOverlay == null || !_fpsOverlay.IsLoaded)
53+
if (_fpsOverlay != null && !_fpsOverlay.IsLoaded)
4254
{
43-
_fpsOverlay = new FpsMonitorOverlay();
4455
_fpsOverlay.Show();
4556
App.Logger.WriteLine(LOG_IDENT, "FPS Monitor overlay shown");
4657
}
@@ -54,6 +65,57 @@ public void StartMonitoring()
5465
}
5566
}
5667

68+
private void CreateFpsWindowOnSeparateThread()
69+
{
70+
_fpsThread = new Thread(() =>
71+
{
72+
try
73+
{
74+
_fpsDispatcher = Dispatcher.CurrentDispatcher;
75+
_fpsOverlay = new FpsMonitorOverlay();
76+
_fpsOverlay.Show();
77+
App.Logger.WriteLine(LOG_IDENT, "FPS Monitor overlay created on separate dispatcher");
78+
Dispatcher.Run();
79+
}
80+
catch (Exception ex)
81+
{
82+
App.Logger.WriteLine(LOG_IDENT, $"Error in FPS thread: {ex.Message}");
83+
}
84+
})
85+
{
86+
IsBackground = false,
87+
Name = "FpsMonitorThread"
88+
};
89+
90+
_fpsThread.SetApartmentState(ApartmentState.STA);
91+
_fpsThread.Start();
92+
}
93+
94+
public void ContinueMonitoring()
95+
{
96+
// FPS Monitor tetap aktif - jangan di-stop
97+
if (_persistentMode && _isRunning && _fpsDispatcher != null)
98+
{
99+
try
100+
{
101+
App.Logger.WriteLine(LOG_IDENT, "Game left but FPS Monitor continues (persistent mode enabled)");
102+
103+
_fpsDispatcher.Invoke(() =>
104+
{
105+
if (_fpsOverlay != null && _fpsOverlay.IsLoaded)
106+
{
107+
_fpsOverlay.SetPersistentMode(true);
108+
App.Logger.WriteLine(LOG_IDENT, "FPS Monitor switched to persistent mode");
109+
}
110+
});
111+
}
112+
catch (Exception ex)
113+
{
114+
App.Logger.WriteLine(LOG_IDENT, $"Error continuing FPS Monitor: {ex.Message}");
115+
}
116+
}
117+
}
118+
57119
public void StopMonitoring()
58120
{
59121
if (!_isRunning)
@@ -64,17 +126,20 @@ public void StopMonitoring()
64126
App.Logger.WriteLine(LOG_IDENT, "Stopping FPS Monitor");
65127

66128
_isRunning = false;
129+
_persistentMode = false;
67130

68-
if (Application.Current.Dispatcher != null)
131+
if (_fpsDispatcher != null && _fpsOverlay != null)
69132
{
70-
Application.Current.Dispatcher.Invoke(() =>
133+
_fpsDispatcher.Invoke(() =>
71134
{
72-
if (_fpsOverlay != null && _fpsOverlay.IsLoaded)
135+
try
73136
{
74-
_fpsOverlay.Close();
75-
_fpsOverlay = null;
76-
App.Logger.WriteLine(LOG_IDENT, "FPS Monitor overlay closed");
137+
if (_fpsOverlay.IsLoaded)
138+
{
139+
_fpsOverlay.Close();
140+
}
77141
}
142+
catch { }
78143
});
79144
}
80145
}
@@ -86,7 +151,27 @@ public void StopMonitoring()
86151

87152
public void Dispose()
88153
{
89-
StopMonitoring();
154+
try
155+
{
156+
if (_fpsDispatcher != null)
157+
{
158+
_fpsDispatcher.InvokeShutdown();
159+
}
160+
161+
if (_fpsThread != null && _fpsThread.IsAlive)
162+
{
163+
_fpsThread.Join(TimeSpan.FromSeconds(2));
164+
}
165+
}
166+
catch (Exception ex)
167+
{
168+
App.Logger.WriteLine(LOG_IDENT, $"Error disposing: {ex.Message}");
169+
}
170+
171+
_fpsOverlay = null;
172+
_fpsDispatcher = null;
173+
_fpsThread = null;
174+
90175
App.Logger.WriteLine(LOG_IDENT, "FPS Monitor service disposed");
91176
}
92177
}

0 commit comments

Comments
 (0)