Update app.py
Browse files
app.py
CHANGED
|
@@ -12,15 +12,29 @@ from fastapi.responses import FileResponse, JSONResponse
|
|
| 12 |
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
|
| 14 |
# ==========================================
|
| 15 |
-
# C# SCRIPT FABRİKASI (
|
| 16 |
# ==========================================
|
| 17 |
def generate_csx_scripts():
|
| 18 |
extract_code = """using System.IO;
|
| 19 |
using System.Text.Json;
|
| 20 |
using System.Collections.Generic;
|
| 21 |
using System.Linq;
|
|
|
|
| 22 |
using UndertaleModLib;
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
var dict = new Dictionary<string, string>();
|
| 25 |
foreach (var str in Data.Strings) {
|
| 26 |
if (!string.IsNullOrWhiteSpace(str.Content)) {
|
|
@@ -38,10 +52,12 @@ foreach (var font in Data.Fonts) {
|
|
| 38 |
string texName = font.Texture.TexturePage.Name.Content;
|
| 39 |
string texPath = "Fonts/" + texName + ".png";
|
| 40 |
if (!File.Exists(texPath)) {
|
| 41 |
-
// HATA ÇÖZÜMÜ: Textures yerine EmbeddedTextures kullanıldı
|
| 42 |
var tex = Data.EmbeddedTextures.FirstOrDefault(t => t.Name.Content == texName);
|
| 43 |
-
if (tex != null && tex.TextureData != null
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
}
|
| 47 |
var glyphs = new Dictionary<string, object>();
|
|
@@ -62,6 +78,18 @@ using System.Linq;
|
|
| 62 |
using System.Reflection;
|
| 63 |
using UndertaleModLib;
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
string json = File.ReadAllText("strings.json");
|
| 66 |
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
| 67 |
|
|
@@ -75,10 +103,9 @@ foreach (var str in Data.Strings) {
|
|
| 75 |
if (Directory.Exists("Fonts")) {
|
| 76 |
foreach (var texFile in Directory.GetFiles("Fonts", "*.png")) {
|
| 77 |
string texName = Path.GetFileNameWithoutExtension(texFile);
|
| 78 |
-
// HATA ÇÖZÜMÜ: Textures yerine EmbeddedTextures kullanıldı
|
| 79 |
var tex = Data.EmbeddedTextures.FirstOrDefault(t => t.Name.Content == texName);
|
| 80 |
-
if (tex != null) {
|
| 81 |
-
tex.TextureData
|
| 82 |
}
|
| 83 |
}
|
| 84 |
string fontJsonPath = "Fonts/font_data.json";
|
|
|
|
| 12 |
from fastapi.middleware.cors import CORSMiddleware
|
| 13 |
|
| 14 |
# ==========================================
|
| 15 |
+
# C# SCRIPT FABRİKASI (X-RAY YANSIMA İLE YENİLMEZ SÜRÜM)
|
| 16 |
# ==========================================
|
| 17 |
def generate_csx_scripts():
|
| 18 |
extract_code = """using System.IO;
|
| 19 |
using System.Text.Json;
|
| 20 |
using System.Collections.Generic;
|
| 21 |
using System.Linq;
|
| 22 |
+
using System.Reflection;
|
| 23 |
using UndertaleModLib;
|
| 24 |
|
| 25 |
+
// X-RAY ALGORİTMASI: Değişken ismi ne olursa olsun PNG verisini (byte array) bulur
|
| 26 |
+
byte[] GetImg(object td) {
|
| 27 |
+
if (td == null) return null;
|
| 28 |
+
var t = td.GetType();
|
| 29 |
+
var p = t.GetProperty("TextureBlob") ?? t.GetProperty("TextureBuffer") ?? t.GetProperty("Data");
|
| 30 |
+
if (p != null) return p.GetValue(td) as byte[];
|
| 31 |
+
var fp = t.GetProperties().FirstOrDefault(x => x.PropertyType == typeof(byte[]));
|
| 32 |
+
if (fp != null) return fp.GetValue(td) as byte[];
|
| 33 |
+
var ff = t.GetFields().FirstOrDefault(x => x.FieldType == typeof(byte[]));
|
| 34 |
+
if (ff != null) return ff.GetValue(td) as byte[];
|
| 35 |
+
return null;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
var dict = new Dictionary<string, string>();
|
| 39 |
foreach (var str in Data.Strings) {
|
| 40 |
if (!string.IsNullOrWhiteSpace(str.Content)) {
|
|
|
|
| 52 |
string texName = font.Texture.TexturePage.Name.Content;
|
| 53 |
string texPath = "Fonts/" + texName + ".png";
|
| 54 |
if (!File.Exists(texPath)) {
|
|
|
|
| 55 |
var tex = Data.EmbeddedTextures.FirstOrDefault(t => t.Name.Content == texName);
|
| 56 |
+
if (tex != null && tex.TextureData != null) {
|
| 57 |
+
byte[] img = GetImg(tex.TextureData);
|
| 58 |
+
if (img != null) {
|
| 59 |
+
File.WriteAllBytes(texPath, img);
|
| 60 |
+
}
|
| 61 |
}
|
| 62 |
}
|
| 63 |
var glyphs = new Dictionary<string, object>();
|
|
|
|
| 78 |
using System.Reflection;
|
| 79 |
using UndertaleModLib;
|
| 80 |
|
| 81 |
+
// X-RAY ALGORİTMASI: Düzenlenmiş PNG resmini isme bakmaksızın motora geri zorlar
|
| 82 |
+
void SetImg(object td, byte[] d) {
|
| 83 |
+
if (td == null) return;
|
| 84 |
+
var t = td.GetType();
|
| 85 |
+
var p = t.GetProperty("TextureBlob") ?? t.GetProperty("TextureBuffer") ?? t.GetProperty("Data");
|
| 86 |
+
if (p != null && p.CanWrite) { p.SetValue(td, d); return; }
|
| 87 |
+
var fp = t.GetProperties().FirstOrDefault(x => x.PropertyType == typeof(byte[]) && x.CanWrite);
|
| 88 |
+
if (fp != null) { fp.SetValue(td, d); return; }
|
| 89 |
+
var ff = t.GetFields().FirstOrDefault(x => x.FieldType == typeof(byte[]));
|
| 90 |
+
if (ff != null) { ff.SetValue(td, d); return; }
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
string json = File.ReadAllText("strings.json");
|
| 94 |
var dict = JsonSerializer.Deserialize<Dictionary<string, string>>(json);
|
| 95 |
|
|
|
|
| 103 |
if (Directory.Exists("Fonts")) {
|
| 104 |
foreach (var texFile in Directory.GetFiles("Fonts", "*.png")) {
|
| 105 |
string texName = Path.GetFileNameWithoutExtension(texFile);
|
|
|
|
| 106 |
var tex = Data.EmbeddedTextures.FirstOrDefault(t => t.Name.Content == texName);
|
| 107 |
+
if (tex != null && tex.TextureData != null) {
|
| 108 |
+
SetImg(tex.TextureData, File.ReadAllBytes(texFile));
|
| 109 |
}
|
| 110 |
}
|
| 111 |
string fontJsonPath = "Fonts/font_data.json";
|