66 Commits

Author SHA1 Message Date
a284edd130 Add debug logs about environment and fonts. 2023-11-01 01:02:55 +08:00
b57959b4bf Update Cryville.Audio. 2023-11-01 01:01:13 +08:00
724cb10bc1 Import Cryville.Interop.Java. 2023-11-01 00:59:09 +08:00
97e759f57d Adjust the progress report from prehandler. 2023-10-08 01:00:12 +08:00
3ce8ad72ed Add dialogs for audio engine initialization error. 2023-10-08 00:58:43 +08:00
c23d79e3f5 Emits a warning on text frame not found. 2023-10-08 00:53:12 +08:00
71294db3c1 Optimize GC and performance for MonoPInvokeCallback. 2023-09-25 17:09:27 +08:00
825818679c Rearrange platform specific plugins. 2023-09-25 10:52:16 +08:00
84acb2c12d Add suppressions for plugins. 2023-09-25 09:33:10 +08:00
9c034c0f7b Code cleanup for font table. 2023-09-17 20:26:31 +08:00
aa7452aead Draft virtual player strategy. (Amend) 2023-08-24 23:45:57 +08:00
f86562b2f2 Draft virtual player strategy. 2023-08-24 23:44:13 +08:00
8fa2bd1e81 Code structure cleanup. (2) 2023-08-24 16:18:16 +08:00
1f58390298 Code structure cleanup. 2023-08-24 15:47:34 +08:00
e40c98ae1b Update project version. 2023-08-15 21:01:19 +08:00
642a9563ba Fix conditional compilation for Android. 2023-08-15 21:01:00 +08:00
4a1fa48352 Fix incomplete ruleset config displayed on config initialization. 2023-08-15 19:16:16 +08:00
4dc0767e91 Typo fix. 2023-08-11 01:24:01 +08:00
9e82c04898 Fix event priority. 2023-08-07 13:56:17 +08:00
0776eca49d Implement custom ruleset config. (Amend) 2023-08-07 13:55:57 +08:00
af01fb2119 Fix the handle of the slider disappearing permanently after an abnormal range is assigned. 2023-08-02 17:30:20 +08:00
9044631fe7 Implement custom ruleset config. (2) 2023-08-02 17:28:55 +08:00
3b22d4fce3 Fix potential constant flag toggled off incorrectly while optimizing. 2023-08-02 17:25:49 +08:00
5393ff1451 Code cleanup with the implementation of property store. 2023-08-02 17:20:45 +08:00
e34a9cc868 Implement custom ruleset config. 2023-07-31 15:15:07 +08:00
440581261e Add contextual function precision. 2023-07-31 15:14:06 +08:00
b78e99c59c Reconstruct property sources and operators to generic types. 2023-07-31 15:12:41 +08:00
3db8f61e3b Decouple the usage of PDT evaluator of chart player. 2023-07-28 14:13:49 +08:00
8b64165fb7 Fix incorrect layout of popup in camera canvas mode. 2023-07-28 14:10:03 +08:00
799b1e12da Code cleanup. 2023-07-28 13:33:23 +08:00
957270c41a Code cleanup. 2023-07-28 12:17:03 +08:00
bc51a45df8 Rewrite property panel to adapt to ruleset config. 2023-07-27 22:07:20 +08:00
9b091a0084 Rename constraint types to avoid ambiguity. 2023-07-27 22:06:15 +08:00
98e35fc6f6 Distinguish stepped sliders by applying a tint to them. 2023-07-27 16:22:22 +08:00
d83f447e82 Fix number slider not working in camera canvas mode. 2023-07-27 16:21:27 +08:00
898885b116 Scene cleanup. 2023-07-27 16:04:42 +08:00
fd05f6c1dd Add contextual function range. 2023-07-27 16:00:22 +08:00
86da71f2cb Draft config definition. 2023-07-27 15:59:56 +08:00
ba2f1d4858 Fix attempt to save config when failed to load. 2023-07-27 15:31:47 +08:00
3687a70aec Import Android Apk Patch. 2023-07-25 22:12:17 +08:00
8da54093aa Code cleanup. 2023-07-14 23:49:27 +08:00
b057ea8074 Fix the game hanging on close. 2023-07-14 23:48:13 +08:00
e7bc9d0294 Code cleanup. 2023-07-12 23:26:36 +08:00
08de91b04d Implement updater for Windows. 2023-07-12 23:26:26 +08:00
ea70fbb051 Improve exception handling for update checker. 2023-07-12 23:25:15 +08:00
cee6a08240 Refactor some judge variables to hit variables. (Amend) 2023-07-12 23:12:55 +08:00
f04b9cfb75 Refactor some judge variables to hit variables. 2023-07-12 23:08:29 +08:00
1dcbc03829 Code cleanup. 2023-07-11 00:03:47 +08:00
d89423caf5 Code cleanup for network module. 2023-07-11 00:02:14 +08:00
c9b348dd4f Fix Discord timestamp not reset on pause and resume. 2023-07-11 00:01:15 +08:00
636f45f03f Fix dialog layout. 2023-07-04 11:13:46 +08:00
7fce9591a9 Fix crash on opening a URL on Android. 2023-07-04 11:13:28 +08:00
f65e4f1900 Cleanup network module. 2023-07-04 11:12:27 +08:00
a4d0e3867a Code cleanup. 2023-07-03 01:11:04 +08:00
83b9c27e94 Implement opening external package link. 2023-07-03 01:10:45 +08:00
864ea91be0 Implement update checker. 2023-06-22 13:23:24 +08:00
ea02fc22bd Pull down UnityNetworkTask. 2023-06-22 13:23:03 +08:00
60cc763cd0 Fix the active network task not re-enqueued when suspended. 2023-06-22 13:22:23 +08:00
8955b69cdf Fix active inputs not cleaned up while batching. 2023-06-22 13:21:01 +08:00
a7aff4d625 Code cleanup. 2023-06-22 13:18:34 +08:00
22cb8f0cb4 Implement dialog. 2023-06-22 13:15:25 +08:00
db07ace927 Code cleanup. 2023-06-13 18:13:23 +08:00
094c3fe2a3 Add contextual variable judge_delta_time. 2023-06-13 18:13:09 +08:00
cc156e0d81 Fix certain non-interactable UI blocking interaction. 2023-06-06 21:28:17 +08:00
9833052849 Improve the ordering logic for applicable input handlers in input config. 2023-06-06 21:27:33 +08:00
a6a0ac3f9e Fix memory leak during collapsing in PDT. 2023-06-06 21:13:36 +08:00
319 changed files with 7999 additions and 2727 deletions

View File

@@ -3,12 +3,12 @@ using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class RangeAttribute : Attribute {
public RangeAttribute(float min, float max) {
public RangeAttribute(double min, double max) {
Min = min;
Max = max;
}
public float Min { get; set; }
public float Max { get; set; }
public double Min { get; set; }
public double Max { get; set; }
}
}

View File

@@ -3,9 +3,9 @@ using System;
namespace Cryville.Common.ComponentModel {
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class StepAttribute : Attribute {
public StepAttribute(float step) {
public StepAttribute(double step) {
Step = step;
}
public float Step { get; set; }
public double Step { get; set; }
}
}

View File

@@ -6,295 +6,295 @@ using System.Linq;
namespace Cryville.Common.Font {
public abstract class FontMatcher {
protected FontManager Manager { get; private set; }
public FontMatcher(FontManager manafer) { Manager = manafer; }
public FontMatcher(FontManager manager) { Manager = manager; }
public abstract IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false);
}
public class FallbackListFontMatcher : FontMatcher {
public Dictionary<string, List<string>> MapScriptToTypefaces = new Dictionary<string, List<string>>();
public void LoadDefaultWindowsFallbackList() {
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return;
MapScriptToTypefaces.Clear();
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
public static Dictionary<string, List<string>> GetDefaultWindowsFallbackMap() {
var map = new Dictionary<string, List<string>>();
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
// Reference: https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/platform/fonts/win/font_fallback_win.cc
MapScriptToTypefaces["zyyy"].Insert(0, "SimSun"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
MapScriptToTypefaces["zyyy"].Insert(0, "Arial");
MapScriptToTypefaces["zyyy"].Insert(0, "Times New Roman");
MapScriptToTypefaces["zyyy"].Insert(0, "Segoe UI"); // Custom
MapScriptToTypefaces["arab"].Insert(0, "Tahoma");
MapScriptToTypefaces["cyrl"].Insert(0, "Times New Roman");
MapScriptToTypefaces["grek"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hebr"].Insert(0, "David");
MapScriptToTypefaces["jpan"].Insert(0, "MS PGothic");
MapScriptToTypefaces["latn"].Insert(0, "Times New Roman");
MapScriptToTypefaces["hans"].Insert(0, "SimSun");
MapScriptToTypefaces["hans"].Insert(0, "SimHei"); // Custom
MapScriptToTypefaces["thai"].Insert(0, "Tahoma");
MapScriptToTypefaces["hans"].Insert(0, "PMingLiU");
map["zyyy"].Insert(0, "SimSun"); // Custom
map["zyyy"].Insert(0, "SimHei"); // Custom
map["zyyy"].Insert(0, "Microsoft YaHei"); // Custom
map["zyyy"].Insert(0, "Arial");
map["zyyy"].Insert(0, "Times New Roman");
map["zyyy"].Insert(0, "Segoe UI"); // Custom
map["arab"].Insert(0, "Tahoma");
map["cyrl"].Insert(0, "Times New Roman");
map["grek"].Insert(0, "Times New Roman");
map["hebr"].Insert(0, "David");
map["jpan"].Insert(0, "MS PGothic");
map["latn"].Insert(0, "Times New Roman");
map["hans"].Insert(0, "SimSun");
map["hans"].Insert(0, "SimHei"); // Custom
map["thai"].Insert(0, "Tahoma");
map["hans"].Insert(0, "PMingLiU");
// Reference: https://learn.microsoft.com/en-us/globalization/input/font-support
var ver = Environment.OSVersion.Version;
if (ver >= new Version(5, 0)) { // Windows 2000
MapScriptToTypefaces["armn"].Insert(0, "Sylfaen");
MapScriptToTypefaces["deva"].Insert(0, "Mangal");
MapScriptToTypefaces["geor"].Insert(0, "Sylfaen");
MapScriptToTypefaces["taml"].Insert(0, "Latha");
map["armn"].Insert(0, "Sylfaen");
map["deva"].Insert(0, "Mangal");
map["geor"].Insert(0, "Sylfaen");
map["taml"].Insert(0, "Latha");
}
if (ver >= new Version(5, 1)) { // Windows XP
MapScriptToTypefaces["gujr"].Insert(0, "Shruti");
MapScriptToTypefaces["guru"].Insert(0, "Raavi");
MapScriptToTypefaces["knda"].Insert(0, "Tunga");
MapScriptToTypefaces["syrc"].Insert(0, "Estrangelo Edessa");
MapScriptToTypefaces["telu"].Insert(0, "Gautami");
MapScriptToTypefaces["thaa"].Insert(0, "MV Boli");
map["gujr"].Insert(0, "Shruti");
map["guru"].Insert(0, "Raavi");
map["knda"].Insert(0, "Tunga");
map["syrc"].Insert(0, "Estrangelo Edessa");
map["telu"].Insert(0, "Gautami");
map["thaa"].Insert(0, "MV Boli");
// SP2
MapScriptToTypefaces["beng"].Insert(0, "Vrinda");
MapScriptToTypefaces["mlym"].Insert(0, "Kartika");
map["beng"].Insert(0, "Vrinda");
map["mlym"].Insert(0, "Kartika");
}
if (ver >= new Version(6, 0)) { // Windows Vista
MapScriptToTypefaces["cans"].Insert(0, "Euphemia");
MapScriptToTypefaces["cher"].Insert(0, "Plantagenet");
MapScriptToTypefaces["ethi"].Insert(0, "Nyala");
MapScriptToTypefaces["khmr"].Insert(0, "DaunPenh MoolBoran");
MapScriptToTypefaces["laoo"].Insert(0, "DokChampa");
MapScriptToTypefaces["mong"].Insert(0, "Mongolian Baiti");
MapScriptToTypefaces["orya"].Insert(0, "Kalinga");
MapScriptToTypefaces["sinh"].Insert(0, "Iskoola Pota");
MapScriptToTypefaces["tibt"].Insert(0, "Microsoft Himalaya");
MapScriptToTypefaces["yiii"].Insert(0, "Microsoft Yi Baiti");
MapScriptToTypefaces["arab"].Insert(0, "Segoe UI");
MapScriptToTypefaces["cyrl"].Insert(0, "Segoe UI");
MapScriptToTypefaces["grek"].Insert(0, "Segoe UI");
MapScriptToTypefaces["latn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hans"].Add("SimSun-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU-ExtB");
MapScriptToTypefaces["hant"].Add("MingLiU_HKSCS-ExtB");
MapScriptToTypefaces["arab"].Add("Microsoft Uighur");
MapScriptToTypefaces["zmth"].Insert(0, "Cambria Math");
map["cans"].Insert(0, "Euphemia");
map["cher"].Insert(0, "Plantagenet");
map["ethi"].Insert(0, "Nyala");
map["khmr"].Insert(0, "DaunPenh MoolBoran");
map["laoo"].Insert(0, "DokChampa");
map["mong"].Insert(0, "Mongolian Baiti");
map["orya"].Insert(0, "Kalinga");
map["sinh"].Insert(0, "Iskoola Pota");
map["tibt"].Insert(0, "Microsoft Himalaya");
map["yiii"].Insert(0, "Microsoft Yi Baiti");
map["arab"].Insert(0, "Segoe UI");
map["cyrl"].Insert(0, "Segoe UI");
map["grek"].Insert(0, "Segoe UI");
map["latn"].Insert(0, "Segoe UI");
map["hans"].Add("SimSun-ExtB");
map["hant"].Add("MingLiU-ExtB");
map["hant"].Add("MingLiU_HKSCS-ExtB");
map["arab"].Add("Microsoft Uighur");
map["zmth"].Insert(0, "Cambria Math");
// Reference: https://en.wikipedia.org/wiki/List_of_CJK_fonts
MapScriptToTypefaces["jpan"].Insert(0, "Meiryo");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei");
map["jpan"].Insert(0, "Meiryo");
map["hans"].Insert(0, "Microsoft YaHei");
}
if (ver >= new Version(6, 1)) { // Windows 7
MapScriptToTypefaces["brai"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["dsrt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["talu"].Insert(0, "Microsoft New Tai Lue");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["osma"].Insert(0, "Ebrima");
MapScriptToTypefaces["phag"].Insert(0, "Microsoft PhagsPa");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["zsym"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["tale"].Insert(0, "Microsoft Tai Le");
MapScriptToTypefaces["tfng"].Insert(0, "Ebrima");
MapScriptToTypefaces["vaii"].Insert(0, "Ebrima");
map["brai"].Insert(0, "Segoe UI Symbol");
map["dsrt"].Insert(0, "Segoe UI Symbol");
map["talu"].Insert(0, "Microsoft New Tai Lue");
map["ogam"].Insert(0, "Segoe UI Symbol");
map["osma"].Insert(0, "Ebrima");
map["phag"].Insert(0, "Microsoft PhagsPa");
map["runr"].Insert(0, "Segoe UI Symbol");
map["zsym"].Insert(0, "Segoe UI Symbol");
map["tale"].Insert(0, "Microsoft Tai Le");
map["tfng"].Insert(0, "Ebrima");
map["vaii"].Insert(0, "Ebrima");
}
if (ver >= new Version(6, 2)) { // Windows 8
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["hang"].Add("Malgun Gothic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["lisu"].Insert(0, "Segoe UI");
MapScriptToTypefaces["mymr"].Insert(0, "Myanmar Text");
MapScriptToTypefaces["nkoo"].Insert(0, "Ebrima");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["ethi"].Insert(0, "Ebrima");
MapScriptToTypefaces["cans"].Insert(0, "Gadugi");
MapScriptToTypefaces["hant"].Insert(0, "Microsoft JhengHei UI");
MapScriptToTypefaces["hans"].Insert(0, "Microsoft YaHei UI");
MapScriptToTypefaces["beng"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["deva"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["gujr"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["mlym"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["orya"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
MapScriptToTypefaces["telu"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["armn"].Insert(0, "Segoe UI");
MapScriptToTypefaces["geor"].Insert(0, "Segoe UI");
MapScriptToTypefaces["hebr"].Insert(0, "Segoe UI");
map["glag"].Insert(0, "Segoe UI Symbol");
map["goth"].Insert(0, "Segoe UI Symbol");
map["hang"].Add("Malgun Gothic");
map["ital"].Insert(0, "Segoe UI Symbol");
map["lisu"].Insert(0, "Segoe UI");
map["mymr"].Insert(0, "Myanmar Text");
map["nkoo"].Insert(0, "Ebrima");
map["orkh"].Insert(0, "Segoe UI Symbol");
map["ethi"].Insert(0, "Ebrima");
map["cans"].Insert(0, "Gadugi");
map["hant"].Insert(0, "Microsoft JhengHei UI");
map["hans"].Insert(0, "Microsoft YaHei UI");
map["beng"].Insert(0, "Nirmala UI");
map["deva"].Insert(0, "Nirmala UI");
map["gujr"].Insert(0, "Nirmala UI");
map["guru"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["knda"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["mlym"].Insert(0, "Nirmala UI");
map["orya"].Insert(0, "Nirmala UI");
map["sinh"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["taml"].Insert(0, "Nirmala UI"); // NOT DOCUMENTED, UNVERIFIED
map["telu"].Insert(0, "Nirmala UI");
map["armn"].Insert(0, "Segoe UI");
map["geor"].Insert(0, "Segoe UI");
map["hebr"].Insert(0, "Segoe UI");
}
if (ver >= new Version(6, 3)) { // Windows 8.1
MapScriptToTypefaces["bugi"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["copt"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["java"].Insert(0, "Javanese Text");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Symbol");
MapScriptToTypefaces["olck"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["sora"].Insert(0, "Nirmala UI");
MapScriptToTypefaces["khmr"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["laoo"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["thai"].Insert(0, "Leelawadee UI");
MapScriptToTypefaces["zsye"].Insert(0, "Segoe UI Emoji");
map["bugi"].Insert(0, "Leelawadee UI");
map["copt"].Insert(0, "Segoe UI Symbol");
map["java"].Insert(0, "Javanese Text");
map["merc"].Insert(0, "Segoe UI Symbol");
map["olck"].Insert(0, "Nirmala UI");
map["sora"].Insert(0, "Nirmala UI");
map["khmr"].Insert(0, "Leelawadee UI");
map["laoo"].Insert(0, "Leelawadee UI");
map["thai"].Insert(0, "Leelawadee UI");
map["zsye"].Insert(0, "Segoe UI Emoji");
}
if (ver >= new Version(10, 0)) { // Windows 10
MapScriptToTypefaces["brah"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cari"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["cprt"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["egyp"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["armi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phli"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["prti"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["khar"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lyci"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["lydi"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["phnx"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xpeo"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["sarb"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["shaw"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["xsux"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ugar"].Insert(0, "Segoe UI Historic");
map["brah"].Insert(0, "Segoe UI Historic");
map["cari"].Insert(0, "Segoe UI Historic");
map["cprt"].Insert(0, "Segoe UI Historic");
map["egyp"].Insert(0, "Segoe UI Historic");
map["armi"].Insert(0, "Segoe UI Historic");
map["phli"].Insert(0, "Segoe UI Historic");
map["prti"].Insert(0, "Segoe UI Historic");
map["khar"].Insert(0, "Segoe UI Historic");
map["lyci"].Insert(0, "Segoe UI Historic");
map["lydi"].Insert(0, "Segoe UI Historic");
map["phnx"].Insert(0, "Segoe UI Historic");
map["xpeo"].Insert(0, "Segoe UI Historic");
map["sarb"].Insert(0, "Segoe UI Historic");
map["shaw"].Insert(0, "Segoe UI Historic");
map["xsux"].Insert(0, "Segoe UI Historic");
map["ugar"].Insert(0, "Segoe UI Historic");
// Segoe UI Symbol -> Segoe UI Historic
MapScriptToTypefaces["glag"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["goth"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["merc"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ogam"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["ital"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["orkh"].Insert(0, "Segoe UI Historic");
MapScriptToTypefaces["runr"].Insert(0, "Segoe UI Historic");
map["glag"].Insert(0, "Segoe UI Historic");
map["goth"].Insert(0, "Segoe UI Historic");
map["merc"].Insert(0, "Segoe UI Historic");
map["ogam"].Insert(0, "Segoe UI Historic");
map["ital"].Insert(0, "Segoe UI Historic");
map["orkh"].Insert(0, "Segoe UI Historic");
map["runr"].Insert(0, "Segoe UI Historic");
//
MapScriptToTypefaces["jpan"].Insert(0, "Yu Gothic UI");
MapScriptToTypefaces["zsym"].Add("Segoe MDL2 Assets");
map["jpan"].Insert(0, "Yu Gothic UI");
map["zsym"].Add("Segoe MDL2 Assets");
}
return map;
}
public void LoadDefaultAndroidFallbackList() {
if (Environment.OSVersion.Platform != PlatformID.Unix) return;
MapScriptToTypefaces.Clear();
ScriptUtils.FillKeysWithScripts(MapScriptToTypefaces, () => new List<string>());
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK JP");
MapScriptToTypefaces["zyyy"].Insert(0, "Noto Sans CJK SC");
MapScriptToTypefaces["zyyy"].Insert(0, "Roboto");
MapScriptToTypefaces["zsye"].Insert(0, "Noto Color Emoji");
MapScriptToTypefaces["zsye"].Add("Noto Color Emoji Flags");
MapScriptToTypefaces["arab"].Insert(0, "Noto Naskh Arabic");
MapScriptToTypefaces["adlm"].Insert(0, "Noto Sans Adlam");
MapScriptToTypefaces["ahom"].Insert(0, "Noto Sans Ahom");
MapScriptToTypefaces["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
MapScriptToTypefaces["armn"].Insert(0, "Noto Sans Armenian");
MapScriptToTypefaces["avst"].Insert(0, "Noto Sans Avestan");
MapScriptToTypefaces["bali"].Insert(0, "Noto Sans Balinese");
MapScriptToTypefaces["bamu"].Insert(0, "Noto Sans Bamum");
MapScriptToTypefaces["bass"].Insert(0, "Noto Sans Bassa Vah");
MapScriptToTypefaces["batk"].Insert(0, "Noto Sans Batak");
MapScriptToTypefaces["beng"].Insert(0, "Noto Sans Bengali");
MapScriptToTypefaces["bhks"].Insert(0, "Noto Sans Bhaiksuki");
MapScriptToTypefaces["brah"].Insert(0, "Noto Sans Brahmi");
MapScriptToTypefaces["bugi"].Insert(0, "Noto Sans Buginese");
MapScriptToTypefaces["buhd"].Insert(0, "Noto Sans Buhid");
MapScriptToTypefaces["jpan"].Insert(0, "Noto Sans CJK JP");
MapScriptToTypefaces["kore"].Insert(0, "Noto Sans CJK KR");
MapScriptToTypefaces["hans"].Insert(0, "Noto Sans CJK SC");
MapScriptToTypefaces["hant"].Insert(0, "Noto Sans CJK TC");
MapScriptToTypefaces["hant"].Add("Noto Sans CJK HK");
MapScriptToTypefaces["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
MapScriptToTypefaces["cari"].Insert(0, "Noto Sans Carian");
MapScriptToTypefaces["cakm"].Insert(0, "Noto Sans Chakma");
MapScriptToTypefaces["cham"].Insert(0, "Noto Sans Cham");
MapScriptToTypefaces["cher"].Insert(0, "Noto Sans Cherokee");
MapScriptToTypefaces["copt"].Insert(0, "Noto Sans Coptic");
MapScriptToTypefaces["xsux"].Insert(0, "Noto Sans Cuneiform");
MapScriptToTypefaces["cprt"].Insert(0, "Noto Sans Cypriot");
MapScriptToTypefaces["dsrt"].Insert(0, "Noto Sans Deseret");
MapScriptToTypefaces["deva"].Insert(0, "Noto Sans Devanagari");
MapScriptToTypefaces["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
MapScriptToTypefaces["elba"].Insert(0, "Noto Sans Elbasan");
MapScriptToTypefaces["ethi"].Insert(0, "Noto Sans Ethiopic");
MapScriptToTypefaces["geor"].Insert(0, "Noto Sans Georgian");
MapScriptToTypefaces["glag"].Insert(0, "Noto Sans Glagolitic");
MapScriptToTypefaces["goth"].Insert(0, "Noto Sans Gothic");
MapScriptToTypefaces["gran"].Insert(0, "Noto Sans Grantha");
MapScriptToTypefaces["gujr"].Insert(0, "Noto Sans Gujarati");
MapScriptToTypefaces["gong"].Insert(0, "Noto Sans Gunjala Gondi");
MapScriptToTypefaces["guru"].Insert(0, "Noto Sans Gurmukhi");
MapScriptToTypefaces["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
MapScriptToTypefaces["hano"].Insert(0, "Noto Sans Hanunoo");
MapScriptToTypefaces["hatr"].Insert(0, "Noto Sans Hatran");
MapScriptToTypefaces["hebr"].Insert(0, "Noto Sans Hebrew");
MapScriptToTypefaces["armi"].Insert(0, "Noto Sans Imperial Aramaic");
MapScriptToTypefaces["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
MapScriptToTypefaces["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
MapScriptToTypefaces["java"].Insert(0, "Noto Sans Javanese");
MapScriptToTypefaces["kthi"].Insert(0, "Noto Sans Kaithi");
MapScriptToTypefaces["knda"].Insert(0, "Noto Sans Kannada");
MapScriptToTypefaces["kali"].Insert(0, "Noto Sans KayahLi");
MapScriptToTypefaces["khar"].Insert(0, "Noto Sans Kharoshthi");
MapScriptToTypefaces["khmr"].Insert(0, "Noto Sans Khmer");
MapScriptToTypefaces["khoj"].Insert(0, "Noto Sans Khojki");
MapScriptToTypefaces["laoo"].Insert(0, "Noto Sans Lao");
MapScriptToTypefaces["lepc"].Insert(0, "Noto Sans Lepcha");
MapScriptToTypefaces["limb"].Insert(0, "Noto Sans Limbu");
MapScriptToTypefaces["lina"].Insert(0, "Noto Sans Linear A");
MapScriptToTypefaces["linb"].Insert(0, "Noto Sans Linear B");
MapScriptToTypefaces["lisu"].Insert(0, "Noto Sans Lisu");
MapScriptToTypefaces["lyci"].Insert(0, "Noto Sans Lycian");
MapScriptToTypefaces["lydi"].Insert(0, "Noto Sans Lydian");
MapScriptToTypefaces["mlym"].Insert(0, "Noto Sans Malayalam");
MapScriptToTypefaces["mand"].Insert(0, "Noto Sans Mandiac");
MapScriptToTypefaces["mani"].Insert(0, "Noto Sans Manichaean");
MapScriptToTypefaces["marc"].Insert(0, "Noto Sans Marchen");
MapScriptToTypefaces["gonm"].Insert(0, "Noto Sans Masaram Gondi");
MapScriptToTypefaces["medf"].Insert(0, "Noto Sans Medefaidrin");
MapScriptToTypefaces["mtei"].Insert(0, "Noto Sans Meetei Mayek");
MapScriptToTypefaces["merc"].Insert(0, "Noto Sans Meroitic");
MapScriptToTypefaces["mero"].Insert(0, "Noto Sans Meroitic");
MapScriptToTypefaces["plrd"].Insert(0, "Noto Sans Miao");
MapScriptToTypefaces["modi"].Insert(0, "Noto Sans Modi");
MapScriptToTypefaces["mong"].Insert(0, "Noto Sans Mongolian");
MapScriptToTypefaces["mroo"].Insert(0, "Noto Sans Mro");
MapScriptToTypefaces["mult"].Insert(0, "Noto Sans Multani");
MapScriptToTypefaces["mymr"].Insert(0, "Noto Sans Myanmar");
MapScriptToTypefaces["nkoo"].Insert(0, "Noto Sans Nko");
MapScriptToTypefaces["nbat"].Insert(0, "Noto Sans Nabataean");
MapScriptToTypefaces["talu"].Insert(0, "Noto Sans New Tai Lue");
MapScriptToTypefaces["newa"].Insert(0, "Noto Sans Newa");
MapScriptToTypefaces["ogam"].Insert(0, "Noto Sans Ogham");
MapScriptToTypefaces["olck"].Insert(0, "Noto Sans Ol Chiki");
MapScriptToTypefaces["ital"].Insert(0, "Noto Sans Old Italian");
MapScriptToTypefaces["narb"].Insert(0, "Noto Sans Old North Arabian");
MapScriptToTypefaces["perm"].Insert(0, "Noto Sans Old Permic");
MapScriptToTypefaces["xpeo"].Insert(0, "Noto Sans Old Persian");
MapScriptToTypefaces["sarb"].Insert(0, "Noto Sans Old South Arabian");
MapScriptToTypefaces["orkh"].Insert(0, "Noto Sans Old Turkic");
MapScriptToTypefaces["orya"].Insert(0, "Noto Sans Oriya");
MapScriptToTypefaces["osge"].Insert(0, "Noto Sans Osage");
MapScriptToTypefaces["osma"].Insert(0, "Noto Sans Osmanya");
MapScriptToTypefaces["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
MapScriptToTypefaces["palm"].Insert(0, "Noto Sans Palmyrene");
MapScriptToTypefaces["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
MapScriptToTypefaces["phag"].Insert(0, "Noto Sans Phags Pa");
MapScriptToTypefaces["phnx"].Insert(0, "Noto Sans Phoenician");
MapScriptToTypefaces["rjng"].Insert(0, "Noto Sans Rejang");
MapScriptToTypefaces["runr"].Insert(0, "Noto Sans Runic");
MapScriptToTypefaces["samr"].Insert(0, "Noto Sans Samaritan");
MapScriptToTypefaces["saur"].Insert(0, "Noto Sans Saurashtra");
MapScriptToTypefaces["shrd"].Insert(0, "Noto Sans Sharada");
MapScriptToTypefaces["shaw"].Insert(0, "Noto Sans Shavian");
MapScriptToTypefaces["sinh"].Insert(0, "Noto Sans Sinhala");
MapScriptToTypefaces["sora"].Insert(0, "Noto Sans Sora Sompeng");
MapScriptToTypefaces["soyo"].Insert(0, "Noto Sans Soyombo");
MapScriptToTypefaces["sund"].Insert(0, "Noto Sans Sundanese");
MapScriptToTypefaces["sylo"].Insert(0, "Noto Sans Syloti Nagri");
MapScriptToTypefaces["zsym"].Insert(0, "Noto Sans Symbols");
MapScriptToTypefaces["syrn"].Insert(0, "Noto Sans Syriac Eastern");
MapScriptToTypefaces["syre"].Insert(0, "Noto Sans Syriac Estrangela");
MapScriptToTypefaces["syrj"].Insert(0, "Noto Sans Syriac Western");
MapScriptToTypefaces["tglg"].Insert(0, "Noto Sans Tagalog");
MapScriptToTypefaces["tagb"].Insert(0, "Noto Sans Tagbanwa");
MapScriptToTypefaces["tale"].Insert(0, "Noto Sans Tai Le");
MapScriptToTypefaces["lana"].Insert(0, "Noto Sans Tai Tham");
MapScriptToTypefaces["tavt"].Insert(0, "Noto Sans Tai Viet");
MapScriptToTypefaces["takr"].Insert(0, "Noto Sans Takri");
MapScriptToTypefaces["taml"].Insert(0, "Noto Sans Tamil");
MapScriptToTypefaces["telu"].Insert(0, "Noto Sans Telugu");
MapScriptToTypefaces["thaa"].Insert(0, "Noto Sans Thaana");
MapScriptToTypefaces["thai"].Insert(0, "Noto Sans Thai");
MapScriptToTypefaces["tfng"].Insert(0, "Noto Sans Tifinagh");
MapScriptToTypefaces["ugar"].Insert(0, "Noto Sans Ugaritic");
MapScriptToTypefaces["vaii"].Insert(0, "Noto Sans Vai");
MapScriptToTypefaces["wcho"].Insert(0, "Noto Sans Wancho");
MapScriptToTypefaces["wara"].Insert(0, "Noto Sans Warang Citi");
MapScriptToTypefaces["yiii"].Insert(0, "Noto Sans Yi");
public static Dictionary<string, List<string>> GetDefaultAndroidFallbackMap() {
var map = new Dictionary<string, List<string>>();
ScriptUtils.FillKeysWithScripts(map, () => new List<string>());
map["zyyy"].Insert(0, "Noto Sans CJK TC"); // TODO Modify default fallback
map["zyyy"].Insert(0, "Noto Sans CJK JP");
map["zyyy"].Insert(0, "Noto Sans CJK SC");
map["zyyy"].Insert(0, "Roboto");
map["zsye"].Insert(0, "Noto Color Emoji");
map["zsye"].Add("Noto Color Emoji Flags");
map["arab"].Insert(0, "Noto Naskh Arabic");
map["adlm"].Insert(0, "Noto Sans Adlam");
map["ahom"].Insert(0, "Noto Sans Ahom");
map["hluw"].Insert(0, "Noto Sans Anatolian Hieroglyphs");
map["armn"].Insert(0, "Noto Sans Armenian");
map["avst"].Insert(0, "Noto Sans Avestan");
map["bali"].Insert(0, "Noto Sans Balinese");
map["bamu"].Insert(0, "Noto Sans Bamum");
map["bass"].Insert(0, "Noto Sans Bassa Vah");
map["batk"].Insert(0, "Noto Sans Batak");
map["beng"].Insert(0, "Noto Sans Bengali");
map["bhks"].Insert(0, "Noto Sans Bhaiksuki");
map["brah"].Insert(0, "Noto Sans Brahmi");
map["bugi"].Insert(0, "Noto Sans Buginese");
map["buhd"].Insert(0, "Noto Sans Buhid");
map["jpan"].Insert(0, "Noto Sans CJK JP");
map["kore"].Insert(0, "Noto Sans CJK KR");
map["hans"].Insert(0, "Noto Sans CJK SC");
map["hant"].Insert(0, "Noto Sans CJK TC");
map["hant"].Add("Noto Sans CJK HK");
map["cans"].Insert(0, "Noto Sans Canadian Aboriginal");
map["cari"].Insert(0, "Noto Sans Carian");
map["cakm"].Insert(0, "Noto Sans Chakma");
map["cham"].Insert(0, "Noto Sans Cham");
map["cher"].Insert(0, "Noto Sans Cherokee");
map["copt"].Insert(0, "Noto Sans Coptic");
map["xsux"].Insert(0, "Noto Sans Cuneiform");
map["cprt"].Insert(0, "Noto Sans Cypriot");
map["dsrt"].Insert(0, "Noto Sans Deseret");
map["deva"].Insert(0, "Noto Sans Devanagari");
map["egyp"].Insert(0, "Noto Sans Egyptian Hieroglyphs");
map["elba"].Insert(0, "Noto Sans Elbasan");
map["ethi"].Insert(0, "Noto Sans Ethiopic");
map["geor"].Insert(0, "Noto Sans Georgian");
map["glag"].Insert(0, "Noto Sans Glagolitic");
map["goth"].Insert(0, "Noto Sans Gothic");
map["gran"].Insert(0, "Noto Sans Grantha");
map["gujr"].Insert(0, "Noto Sans Gujarati");
map["gong"].Insert(0, "Noto Sans Gunjala Gondi");
map["guru"].Insert(0, "Noto Sans Gurmukhi");
map["rohg"].Insert(0, "Noto Sans Hanifi Rohingya");
map["hano"].Insert(0, "Noto Sans Hanunoo");
map["hatr"].Insert(0, "Noto Sans Hatran");
map["hebr"].Insert(0, "Noto Sans Hebrew");
map["armi"].Insert(0, "Noto Sans Imperial Aramaic");
map["phli"].Insert(0, "Noto Sans Inscriptional Pahlavi");
map["prti"].Insert(0, "Noto Sans Inscriptional Parthian");
map["java"].Insert(0, "Noto Sans Javanese");
map["kthi"].Insert(0, "Noto Sans Kaithi");
map["knda"].Insert(0, "Noto Sans Kannada");
map["kali"].Insert(0, "Noto Sans KayahLi");
map["khar"].Insert(0, "Noto Sans Kharoshthi");
map["khmr"].Insert(0, "Noto Sans Khmer");
map["khoj"].Insert(0, "Noto Sans Khojki");
map["laoo"].Insert(0, "Noto Sans Lao");
map["lepc"].Insert(0, "Noto Sans Lepcha");
map["limb"].Insert(0, "Noto Sans Limbu");
map["lina"].Insert(0, "Noto Sans Linear A");
map["linb"].Insert(0, "Noto Sans Linear B");
map["lisu"].Insert(0, "Noto Sans Lisu");
map["lyci"].Insert(0, "Noto Sans Lycian");
map["lydi"].Insert(0, "Noto Sans Lydian");
map["mlym"].Insert(0, "Noto Sans Malayalam");
map["mand"].Insert(0, "Noto Sans Mandiac");
map["mani"].Insert(0, "Noto Sans Manichaean");
map["marc"].Insert(0, "Noto Sans Marchen");
map["gonm"].Insert(0, "Noto Sans Masaram Gondi");
map["medf"].Insert(0, "Noto Sans Medefaidrin");
map["mtei"].Insert(0, "Noto Sans Meetei Mayek");
map["merc"].Insert(0, "Noto Sans Meroitic");
map["mero"].Insert(0, "Noto Sans Meroitic");
map["plrd"].Insert(0, "Noto Sans Miao");
map["modi"].Insert(0, "Noto Sans Modi");
map["mong"].Insert(0, "Noto Sans Mongolian");
map["mroo"].Insert(0, "Noto Sans Mro");
map["mult"].Insert(0, "Noto Sans Multani");
map["mymr"].Insert(0, "Noto Sans Myanmar");
map["nkoo"].Insert(0, "Noto Sans Nko");
map["nbat"].Insert(0, "Noto Sans Nabataean");
map["talu"].Insert(0, "Noto Sans New Tai Lue");
map["newa"].Insert(0, "Noto Sans Newa");
map["ogam"].Insert(0, "Noto Sans Ogham");
map["olck"].Insert(0, "Noto Sans Ol Chiki");
map["ital"].Insert(0, "Noto Sans Old Italian");
map["narb"].Insert(0, "Noto Sans Old North Arabian");
map["perm"].Insert(0, "Noto Sans Old Permic");
map["xpeo"].Insert(0, "Noto Sans Old Persian");
map["sarb"].Insert(0, "Noto Sans Old South Arabian");
map["orkh"].Insert(0, "Noto Sans Old Turkic");
map["orya"].Insert(0, "Noto Sans Oriya");
map["osge"].Insert(0, "Noto Sans Osage");
map["osma"].Insert(0, "Noto Sans Osmanya");
map["hmng"].Insert(0, "Noto Sans Pahawh Hmong");
map["palm"].Insert(0, "Noto Sans Palmyrene");
map["pauc"].Insert(0, "Noto Sans Pau Cin Hau");
map["phag"].Insert(0, "Noto Sans Phags Pa");
map["phnx"].Insert(0, "Noto Sans Phoenician");
map["rjng"].Insert(0, "Noto Sans Rejang");
map["runr"].Insert(0, "Noto Sans Runic");
map["samr"].Insert(0, "Noto Sans Samaritan");
map["saur"].Insert(0, "Noto Sans Saurashtra");
map["shrd"].Insert(0, "Noto Sans Sharada");
map["shaw"].Insert(0, "Noto Sans Shavian");
map["sinh"].Insert(0, "Noto Sans Sinhala");
map["sora"].Insert(0, "Noto Sans Sora Sompeng");
map["soyo"].Insert(0, "Noto Sans Soyombo");
map["sund"].Insert(0, "Noto Sans Sundanese");
map["sylo"].Insert(0, "Noto Sans Syloti Nagri");
map["zsym"].Insert(0, "Noto Sans Symbols");
map["syrn"].Insert(0, "Noto Sans Syriac Eastern");
map["syre"].Insert(0, "Noto Sans Syriac Estrangela");
map["syrj"].Insert(0, "Noto Sans Syriac Western");
map["tglg"].Insert(0, "Noto Sans Tagalog");
map["tagb"].Insert(0, "Noto Sans Tagbanwa");
map["tale"].Insert(0, "Noto Sans Tai Le");
map["lana"].Insert(0, "Noto Sans Tai Tham");
map["tavt"].Insert(0, "Noto Sans Tai Viet");
map["takr"].Insert(0, "Noto Sans Takri");
map["taml"].Insert(0, "Noto Sans Tamil");
map["telu"].Insert(0, "Noto Sans Telugu");
map["thaa"].Insert(0, "Noto Sans Thaana");
map["thai"].Insert(0, "Noto Sans Thai");
map["tfng"].Insert(0, "Noto Sans Tifinagh");
map["ugar"].Insert(0, "Noto Sans Ugaritic");
map["vaii"].Insert(0, "Noto Sans Vai");
map["wcho"].Insert(0, "Noto Sans Wancho");
map["wara"].Insert(0, "Noto Sans Warang Citi");
map["yiii"].Insert(0, "Noto Sans Yi");
return map;
}
public FallbackListFontMatcher(FontManager manager) : base(manager) { }
public override IEnumerable<Typeface> MatchScript(string script = null, bool distinctFamily = false) {

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
#pragma warning disable IDE0049
namespace Cryville.Common.Font {
public abstract class FontTable<T> {
protected UInt32 Offset { get; private set; }
@@ -25,14 +26,17 @@ namespace Cryville.Common.Font {
readonly UInt16 minorVersion;
readonly UInt32 numFonts;
readonly List<UInt32> tableDirectoryOffsets = new List<UInt32>();
#pragma warning disable IDE0052 // Reserved
readonly String dsigTag;
readonly UInt32 dsigLength;
readonly UInt32 dsigOffset;
#pragma warning restore IDE0052 // Reserved
public TTCHeader(BinaryReader reader, UInt32 offset) : base(reader, offset) {
ttcTag = reader.ReadTag();
if (ttcTag != "ttcf") throw new NotImplementedException();
if (ttcTag != "ttcf") throw new NotSupportedException();
majorVersion = reader.ReadUInt16();
minorVersion = reader.ReadUInt16();
if (minorVersion != 0) throw new NotSupportedException();
numFonts = reader.ReadUInt32();
for (UInt32 i = 0; i < numFonts; i++) tableDirectoryOffsets.Add(reader.ReadUInt32());
if (majorVersion == 2) {
@@ -52,12 +56,16 @@ namespace Cryville.Common.Font {
public sealed class TableDirectory : FontTable<TableRecord, object> {
readonly UInt32 sfntVersion;
readonly UInt16 numTables;
#pragma warning disable IDE0052 // Reserved
readonly UInt16 searchRange;
readonly UInt16 entrySelector;
readonly UInt16 rangeShift;
#pragma warning restore IDE0052 // Reserved
readonly List<TableRecord> tableRecords = new List<TableRecord>();
public TableDirectory(BinaryReader reader, UInt32 offset) : base(reader, offset) {
sfntVersion = reader.ReadUInt32();
if (sfntVersion != 0x00010000 && sfntVersion != 0x4F54544F &&
sfntVersion != 0x74727565 && sfntVersion != 0x74797031) throw new NotSupportedException();
numTables = reader.ReadUInt16();
searchRange = reader.ReadUInt16();
entrySelector = reader.ReadUInt16();
@@ -99,48 +107,63 @@ namespace Cryville.Common.Font {
count = reader.ReadUInt16();
storageOffset = reader.ReadUInt16();
for (UInt16 i = 0; i < count; i++)
nameRecord.Add(new NameRecord {
platformID = reader.ReadUInt16(),
encodingID = reader.ReadUInt16(),
languageID = reader.ReadUInt16(),
nameID = (NameID)reader.ReadUInt16(),
length = reader.ReadUInt16(),
stringOffset = reader.ReadUInt16(),
});
nameRecord.Add(new NameRecord(
reader.ReadUInt16(),
reader.ReadUInt16(),
reader.ReadUInt16(),
(NameID)reader.ReadUInt16(),
reader.ReadUInt16(),
reader.ReadUInt16()
));
if (version == 1) {
langTagCount = reader.ReadUInt16();
for (UInt16 i = 0; i < langTagCount; i++)
langTagRecord.Add(new LangTagRecord {
length = reader.ReadUInt16(),
langTagOffset = reader.ReadUInt16(),
});
langTagRecord.Add(new LangTagRecord(
reader.ReadUInt16(),
reader.ReadUInt16()
));
}
foreach (var i in nameRecord)
i.Load(reader, offset + storageOffset);
if (version == 1) {
foreach (var i in langTagRecord)
i.Load(reader, offset + storageOffset);
}
UInt32 origin = (UInt32)reader.BaseStream.Position;
for (int i = 0; i < nameRecord.Count; i++) nameRecord[i] = nameRecord[i].Load(reader, origin);
for (int i = 0; i < langTagRecord.Count; i++) langTagRecord[i] = langTagRecord[i].Load(reader, origin);
}
public sealed override IReadOnlyList<NameRecord> GetItems() {
return nameRecord;
}
}
public struct NameRecord {
public UInt16 platformID;
public UInt16 encodingID;
public UInt16 languageID;
public NameID nameID;
public UInt16 length;
public UInt16 stringOffset;
public String value { get; private set; }
public NameRecord Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + stringOffset;
public class NameRecord {
public UInt16 PlatformID { get; private set; }
public UInt16 EncodingID { get; private set; }
public UInt16 LanguageID { get; private set; }
public NameID NameID { get; private set; }
public UInt16 Length { get; private set; }
public UInt16 StringOffset { get; private set; }
public String Value { get; private set; }
public NameRecord(UInt16 platformID, UInt16 encodingID, UInt16 languageID, NameID nameID, UInt16 length, UInt16 stringOffset) {
PlatformID = platformID;
EncodingID = encodingID;
LanguageID = languageID;
NameID = nameID;
Length = length;
StringOffset = stringOffset;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + StringOffset;
Encoding encoding;
switch (platformID) {
case 0: encoding = Encoding.BigEndianUnicode; break;
case 3: encoding = Encoding.BigEndianUnicode; break;
default: return this;
try {
switch (PlatformID) {
case 0: encoding = Encoding.BigEndianUnicode; break;
case 1: encoding = Encoding.GetEncoding(10000 + EncodingID); break;
case 3: encoding = Encoding.BigEndianUnicode; break;
default: return;
}
}
value = encoding.GetString(reader.ReadBytes(length));
return this;
catch (NotSupportedException) { return; }
catch (ArgumentException) { return; }
Value = encoding.GetString(reader.ReadBytes(Length));
}
}
public enum NameID : UInt16 {
@@ -171,47 +194,58 @@ namespace Cryville.Common.Font {
DarkBackgroundPalette = 24,
VariationsPostScriptNamePrefix = 25,
}
public struct LangTagRecord {
public UInt16 length;
public UInt16 langTagOffset;
public String value { get; private set; }
public LangTagRecord Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + langTagOffset;
value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(length));
return this;
public class LangTagRecord {
public UInt16 Length { get; private set; }
public UInt16 LangTagOffset { get; private set; }
public String Value { get; private set; }
public LangTagRecord(UInt16 length, UInt16 langTagOffset) {
Length = length;
LangTagOffset = langTagOffset;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + LangTagOffset;
Value = Encoding.BigEndianUnicode.GetString(reader.ReadBytes(Length));
}
}
public sealed class MetaTable : FontTable<DataMap> {
readonly UInt32 version;
#pragma warning disable IDE0052 // Reserved
readonly UInt32 flags;
#pragma warning restore IDE0052 // Reserved
readonly UInt32 dataMapCount;
readonly List<DataMap> dataMaps = new List<DataMap>();
public MetaTable(BinaryReader reader, UInt32 offset) : base(reader, offset) {
version = reader.ReadUInt32();
if (version != 1) throw new NotSupportedException();
flags = reader.ReadUInt32();
reader.ReadUInt32();
dataMapCount = reader.ReadUInt32();
for (UInt32 i = 0; i < dataMapCount; i++)
dataMaps.Add(new DataMap {
tag = reader.ReadTag(),
dataOffset = reader.ReadUInt32(),
dataLength = reader.ReadUInt32(),
});
for (int i = 0; i < dataMaps.Count; i++) dataMaps[i] = dataMaps[i].Load(reader, offset);
dataMaps.Add(new DataMap (
reader.ReadTag(),
reader.ReadUInt32(),
reader.ReadUInt32()
));
foreach (var i in dataMaps)
i.Load(reader, offset);
}
public sealed override IReadOnlyList<DataMap> GetItems() {
return dataMaps;
}
}
public struct DataMap {
public String tag;
public UInt32 dataOffset;
public UInt32 dataLength;
public String value { get; private set; }
public DataMap Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + dataOffset;
value = Encoding.ASCII.GetString(reader.ReadBytes((int)dataLength));
return this;
public class DataMap {
public String Tag { get; private set; }
public UInt32 DataOffset { get; private set; }
public UInt32 DataLength { get; private set; }
public String Value { get; private set; }
public DataMap(String tag, UInt32 dataOffset, UInt32 dataLength) {
Tag = tag;
DataOffset = dataOffset;
DataLength = dataLength;
}
public void Load(BinaryReader reader, UInt32 origin) {
reader.BaseStream.Position = origin + DataOffset;
Value = Encoding.ASCII.GetString(reader.ReadBytes((int)DataLength));
}
}
public static class BinaryReaderExtensions {

View File

@@ -23,9 +23,9 @@ namespace Cryville.Common.Font {
protected override void GetName(BinaryReader reader) {
var dir = new TableDirectory(reader, (uint)reader.BaseStream.Position);
var nameTable = (NameTable)dir.GetSubTable((from i in dir.GetItems() where i.tableTag == "name" select i).Single());
FamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontFamilyName && i.value != null select i.value).First();
SubfamilyName = (from i in nameTable.GetItems() where i.nameID == NameID.FontSubfamilyName && i.value != null select i.value).First();
FullName = (from i in nameTable.GetItems() where i.nameID == NameID.FullFontName && i.value != null select i.value).First();
FamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontFamilyName && i.Value != null select i.Value).First();
SubfamilyName = (from i in nameTable.GetItems() where i.NameID == NameID.FontSubfamilyName && i.Value != null select i.Value).First();
FullName = (from i in nameTable.GetItems() where i.NameID == NameID.FullFontName && i.Value != null select i.Value).First();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1a624371d4108614b9cdc4acca1499e2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,12 +4,11 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
namespace Cryville.Common.Network {
public class HttpClient {
namespace Cryville.Common.Network.Http11 {
public class Http11Client : IDisposable {
private readonly string _directHost;
protected string DirectHost { get { return _directHost; } }
@@ -19,29 +18,17 @@ namespace Cryville.Common.Network {
readonly Uri _baseUri;
readonly int origPort;
protected string Version = "HTTP/1.1";
protected const string Version = "HTTP/1.1";
protected TcpClient TcpClient { get; private set; }
protected Stream RawTcpStream {
get {
return TcpClient.GetStream();
}
}
protected virtual Stream Stream {
get {
return TcpClient.GetStream();
}
}
protected virtual string WindowsProxyProtocolName {
get {
return "http";
}
}
protected Stream RawTcpStream { get { return TcpClient.GetStream(); } }
protected virtual Stream Stream { get { return TcpClient.GetStream(); } }
protected virtual string WindowsProxyProtocolName { get { return "http"; } }
private readonly bool _proxied = false;
public Dictionary<string, string> Headers { get; set; }
public HttpClient(Uri baseUri, int port = 80) {
public Http11Client(Uri baseUri, int port = 80) {
_directHost = baseUri.Host;
_directPort = port;
_baseUri = baseUri;
@@ -61,18 +48,29 @@ namespace Cryville.Common.Network {
public virtual void Close() {
TcpClient.Close();
}
public HttpResponse Request(string method, Uri uri, string body = null, Encoding encoding = null) {
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
public Http11Response Request(string method, Uri uri, string body = null, Encoding encoding = null) {
string struri = GetUri(uri).PathAndQuery;
return Request(Stream, method, struri, body, encoding);
}
public HttpResponse Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
var headers = new Dictionary<string, string>();
Http11Response Request(Stream stream, string method, string uri, string body = null, Encoding encoding = null) {
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
foreach (var h in Headers)
headers.Add(h.Key, h.Value);
headers["Host"] = _baseUri.Host;
byte[] payload = new byte[0];
byte[] payload = null;
if (body != null) {
if (encoding == null)
encoding = Encoding.UTF8;
@@ -80,22 +78,24 @@ namespace Cryville.Common.Network {
headers.Add("Content-Encoding", encoding.EncodingName);
headers.Add("Content-Length", payload.Length.ToString(CultureInfo.InvariantCulture));
}
string request_line = string.Format(
"{0} {1} {2}\r\n", method, uri, Version
);
string header_fields = string.Concat((
from h in headers select h.Key + ":" + h.Value + "\r\n"
).ToArray());
byte[] buffer0 = Encoding.ASCII.GetBytes(string.Format(
"{0}{1}\r\n", request_line, header_fields
));
byte[] buffer1 = new byte[buffer0.Length + payload.Length];
Array.Copy(buffer0, buffer1, buffer0.Length);
Array.Copy(payload, 0, buffer1, buffer0.Length, payload.Length);
Logger.Log("main", 0, "Network", Encoding.UTF8.GetString(buffer1));
stream.Write(buffer1, 0, buffer1.Length);
stream.Flush();
var response = new HttpResponse(stream);
using (var writer = new StreamWriter(stream, Encoding.ASCII, 1024, true)) {
writer.Write(method);
writer.Write(' ');
writer.Write(uri);
writer.Write(' ');
writer.Write(Version);
writer.Write("\r\n");
foreach (var header in headers) {
writer.Write(header.Key);
writer.Write(':');
writer.Write(header.Value);
writer.Write("\r\n");
}
writer.Write("\r\n");
if (payload != null) writer.Write(payload);
writer.Flush();
}
var response = new Http11Response(stream);
Logger.Log("main", 0, "Network", "{0}", response);
return response;
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 9653d5e145f2866439a0fcd1b27f49c4
guid: 5a795e416e54c69418de1a3c27a88932
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,31 +1,41 @@
using Cryville.Common.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Cryville.Common.Network {
public class HttpResponse {
namespace Cryville.Common.Network.Http11 {
public class Http11Response : IDisposable {
static readonly char[] spchar = new char[]{ ' ' };
public string HttpVersion { get; private set; }
public string StatusCode { get; private set; }
public string ReasonPhase { get; private set; }
public Dictionary<string, string> Headers { get; private set; }
public HttpResponseStream MessageBody { get; private set; }
internal HttpResponse(Stream stream) {
public Http11ResponseStream MessageBody { get; private set; }
internal Http11Response(Stream stream) {
var reader = new BinaryReader(stream, Encoding.ASCII);
var statu_line = ReadLine(reader).Split(spchar, 3);
HttpVersion = statu_line[0];
StatusCode = statu_line[1];
ReasonPhase = statu_line[2];
Logger.Log("main", 0, "Network", "Receive Response: {0} {1} {2}", HttpVersion, StatusCode, ReasonPhase);
Headers = new Dictionary<string, string>();
Headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
while (ParseHeader(reader, Headers)) ;
if (Headers.ContainsKey("content-length")) {
int length = int.Parse(Headers["content-length"]);
MessageBody = new HttpResponseBlockStream(reader, length);
MessageBody = new Http11ResponseBlockStream(reader, length);
}
else if (Headers.ContainsKey("transfer-encoding") && Headers["transfer-encoding"] == "chunked") {
MessageBody = new HttpResponseChunkedStream(reader);
MessageBody = new Http11ResponseChunkedStream(reader);
}
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
MessageBody.Dispose();
}
}
@@ -37,12 +47,11 @@ namespace Cryville.Common.Network {
// TODO Multiline header
var header = ReadLine(reader);
if (header == "") return false;
var s = header.Split(':');
var s = header.Split(':', 2);
string field_name = s[0].Trim().ToLower();
string field_value = s[1].Trim();
if (headers.ContainsKey(field_name)) headers[field_name] += "," + field_value;
else headers.Add(field_name, field_value);
Logger.Log("main", 0, "Network", "Receive Header {0}: {1}", field_name, field_value);
return true;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71234dd1c93d47b4893750686b2333a3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +1,11 @@
using Cryville.Common.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
namespace Cryville.Common.Network {
public abstract class HttpResponseStream : Stream {
namespace Cryville.Common.Network.Http11 {
public abstract class Http11ResponseStream : Stream {
public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } }
@@ -37,11 +36,11 @@ namespace Cryville.Common.Network {
}
}
internal sealed class HttpResponseBlockStream : HttpResponseStream {
internal sealed class Http11ResponseBlockStream : Http11ResponseStream {
readonly BinaryReader _reader;
readonly int _length;
int _pos = 0;
internal HttpResponseBlockStream(BinaryReader reader, int length) {
internal Http11ResponseBlockStream(BinaryReader reader, int length) {
_reader = reader;
_length = length;
}
@@ -51,7 +50,6 @@ namespace Cryville.Common.Network {
if (recv_len == 0) return 0;
while (recv < recv_len) {
recv += _reader.Read(buffer, offset + recv, count - recv);
Logger.Log("main", 0, "Network", "Message body received: {0}/{1}/{2}", recv, recv_len, _length);
}
_pos += recv_len;
return recv_len;
@@ -63,36 +61,34 @@ namespace Cryville.Common.Network {
}
}
internal sealed class HttpResponseChunkedStream : HttpResponseStream {
internal sealed class Http11ResponseChunkedStream : Http11ResponseStream {
readonly BinaryReader _reader;
byte[] _chunk = null;
int _pos = 0;
internal HttpResponseChunkedStream(BinaryReader reader) {
internal Http11ResponseChunkedStream(BinaryReader reader) {
_reader = reader;
ReadChunk();
}
public void ReadChunk() {
if (_chunk != null && _chunk.Length == 0) return;
string[] chunkHeader = HttpResponse.ReadLine(_reader).Split(';');
// int chunkSize = Array.IndexOf(LEN, chunkHeader[0].ToLower()[0]);
int chunkSize = int.Parse(chunkHeader[0], NumberStyles.HexNumber);
if (chunkSize == -1)
string[] chunkHeader = Http11Response.ReadLine(_reader).Split(';');
int chunkSize;
if (!int.TryParse(chunkHeader[0], NumberStyles.HexNumber, CultureInfo.InvariantCulture, out chunkSize))
throw new IOException("Corrupted chunk received");
if (chunkSize == 0) {
_chunk = new byte[0];
// TODO TE Header, now just discard
var headers = new Dictionary<string, string>();
while (HttpResponse.ParseHeader(_reader, headers)) ;
while (Http11Response.ParseHeader(_reader, headers)) ;
return;
}
_chunk = new byte[chunkSize];
int recv = 0;
while (recv < chunkSize) {
recv += _reader.Read(_chunk, recv, chunkSize - recv);
Logger.Log("main", 0, "Network", "Message chunk received: {0}/{1}", recv, chunkSize);
}
_pos = 0;
if (HttpResponse.ReadLine(_reader) != "")
if (Http11Response.ReadLine(_reader) != "")
throw new IOException("Corrupted chunk received");
}
public override int Read(byte[] buffer, int offset, int count) {

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49a8d5b9869e5bb42bafbe71f84fecc5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,8 @@
using System;
using System.IO;
namespace Cryville.Common.Network {
public class HttpsClient : HttpClient {
namespace Cryville.Common.Network.Http11 {
public class Https11Client : Http11Client {
readonly TlsClient _tlsClient;
protected override Stream Stream {
@@ -16,7 +16,7 @@ namespace Cryville.Common.Network {
}
}
public HttpsClient(Uri baseUri) : base(baseUri, 443) {
public Https11Client(Uri baseUri) : base(baseUri, 443) {
_tlsClient = new TlsClient(RawTcpStream, baseUri.Host);
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5c233e6228ce204fa1a9724c48ac8fe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 5ea931bf5488011468f3d1243a038874
timeCreated: 1622589817
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 07e8215a93e3eb1418685009f0c58dcd
timeCreated: 1622596274
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: f191de447a708da4f9d230e6545ce0a6
timeCreated: 1635470462
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 9b35290e0e147a342acc29a20c8fceaf
timeCreated: 1622503538
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,8 +1,8 @@
using Cryville.Common.Logging;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Tls;
using Org.BouncyCastle.Tls.Crypto;
using Org.BouncyCastle.Tls.Crypto.Impl.BC;
using System;
using System.Collections;
using System.IO;
using System.Linq;
@@ -10,7 +10,7 @@ using System.Text;
using BcTlsClient = Org.BouncyCastle.Tls.TlsClient;
namespace Cryville.Common.Network {
public class TlsClient {
public class TlsClient : IDisposable {
readonly TlsClientProtocol _protocol;
readonly BcTlsClient _tlsClient;
public Stream Stream { get; private set; }
@@ -28,6 +28,17 @@ namespace Cryville.Common.Network {
_protocol.Close();
}
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public virtual void Dispose(bool disposing) {
if (disposing) {
Close();
}
}
private class InternalTlsClient : DefaultTlsClient {
readonly string _host;
@@ -72,20 +83,6 @@ namespace Cryville.Common.Network {
public override TlsAuthentication GetAuthentication() {
return new NullTlsAuthentication();
}
public override void NotifyAlertReceived(short alertLevel, short alertDescription) {
Logger.Log("main", 0, "Network/TLS", "TLS Alert {0} {1}", alertLevel, alertDescription);
}
public override void NotifyServerVersion(ProtocolVersion serverVersion) {
base.NotifyServerVersion(serverVersion);
Logger.Log("main", 0, "Network/TLS", "NotifyServerVersion {0}", serverVersion);
}
public override void NotifySelectedCipherSuite(int selectedCipherSuite) {
base.NotifySelectedCipherSuite(selectedCipherSuite);
Logger.Log("main", 0, "Network/TLS", "NotifySelectedCipherSuite {0}", selectedCipherSuite);
}
}
private class NullTlsAuthentication : TlsAuthentication {

View File

@@ -24,8 +24,8 @@ namespace Cryville.Common.Pdt {
/// <param name="exp">The expression to evaluate.</param>
/// <returns>Whether the evaluaton succeeded.</returns>
public bool Evaluate(PdtOperator target, PdtExpression exp) {
var prevFrameCount = _framecount;
try {
var prevFrameCount = _framecount;
_revokepttconst = false;
for (var ip = exp.Instructions.First; ip != null; ip = ip.Next)
ip.Value.Execute(this, ref ip);
@@ -33,12 +33,14 @@ namespace Cryville.Common.Pdt {
exp.IsConstant = exp.IsPotentialConstant = !_revokepttconst;
}
var ret = Operate(target, _framecount - prevFrameCount, true);
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
return ret;
}
catch (Exception ex) {
throw new EvaluationFailureException(exp, ex);
}
finally {
for (var i = prevFrameCount; i < _framecount; i++) DiscardStack();
}
}
/// <summary>
/// Optimizes an expression by merging its instructions.
@@ -133,10 +135,7 @@ namespace Cryville.Common.Pdt {
for (var ins = il.First; ins != null; ins = ins.Next) {
if (!(ins.Value is PdtInstruction.PushConstant)) {
exp.IsConstant = false;
}
else if (!(ins.Value is PdtInstruction.PushVariable)) {
exp.IsPotentialConstant = false;
return;
break;
}
}
}
@@ -205,7 +204,7 @@ namespace Cryville.Common.Pdt {
var frame = _stack[--_framecount];
if (frame.Type == PdtInternalType.Error) {
_framecount -= pc - i - 1;
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
return false;
}
op.LoadOperand(new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length));
@@ -218,13 +217,15 @@ namespace Cryville.Common.Pdt {
internal unsafe void Collapse(int name, ref LinkedListNode<PdtInstruction> self, LinkedListNode<PdtInstruction> target) {
fixed (byte* pmem = _mem) {
var frame = _stack[--_framecount];
_goffset -= frame.Length;
if (frame.Type == PdtInternalType.Error) {
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = _goffset, Length = 0 };
_stack[_framecount++] = new StackFrame { Type = PdtInternalType.Error, Offset = -1, Length = 0 };
self = target;
return;
}
if (Collapse(name, new PdtVariableMemory(frame.Type, pmem + frame.Offset, frame.Length))) {
_framecount++;
_goffset += frame.Length;
self = target;
}
}

View File

@@ -57,6 +57,7 @@ namespace Cryville.Common.Unity {
suspended = true;
if (currentNetworkTask != null) {
currentNetworkTask.Cancel();
networkTasks.Enqueue(currentNetworkTask);
currentNetworkTask = null;
}
}
@@ -91,15 +92,6 @@ namespace Cryville.Common.Unity {
/// A network task.
/// </summary>
public abstract class NetworkTask {
protected NetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
/// <summary>
/// Whether the task is cancelled.
/// </summary>
@@ -108,40 +100,56 @@ namespace Cryville.Common.Unity {
/// <summary>
/// Cancels the task.
/// </summary>
public virtual void Cancel() {
public void Cancel() {
Cancelled = true;
OnCancel();
}
protected virtual void OnCancel() { }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <summary>
/// Starts the task.
/// </summary>
public virtual void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
public abstract void Start();
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
public virtual bool Done() {
public abstract bool Done();
}
/// <summary>
/// A Unity network task.
/// </summary>
public abstract class UnityNetworkTask : NetworkTask {
protected UnityNetworkTask(string uri) {
Uri = uri;
}
/// <summary>
/// The URI of the resource.
/// </summary>
public string Uri { get; private set; }
#if UNITY_5_4_OR_NEWER
protected UnityWebRequest www;
/// <inheritdoc />
public override void Start() {
www = new UnityWebRequest(Uri);
www.SendWebRequest();
}
/// <inheritdoc />
public override bool Done() {
if (!www.isDone) return false;
return true;
}
#else
protected WWW www;
/// <summary>
/// Starts the task.
/// </summary>
/// <inheritdoc />
public virtual void Start() {
www = new WWW(Uri);
}
/// <summary>
/// Gets whether the task is done.
/// </summary>
/// <returns>Whether the task is done.</returns>
/// <inheritdoc />
public virtual bool Done() {
if (!www.isDone) return false;
return true;
@@ -149,9 +157,9 @@ namespace Cryville.Common.Unity {
#endif
}
/// <summary>
/// A <see cref="NetworkTask" /> that loads a texture.
/// A <see cref="UnityNetworkTask" /> that loads a texture.
/// </summary>
public class LoadTextureTask : NetworkTask {
public class LoadTextureTask : UnityNetworkTask {
/// <summary>
/// Creates an instance of the <see cref="LoadTextureTask" /> class.
/// </summary>

View File

@@ -0,0 +1,50 @@
#if UNITY_EDITOR
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
namespace Cryville.Common.Unity {
[InitializeOnLoad]
public class ScopedThreadAttacherInjector {
static readonly Encoding _encoding = new UTF8Encoding(false, true);
static string _filePath;
static string _oldSrc;
static ScopedThreadAttacherInjector() {
BuildPlayerWindow.RegisterBuildPlayerHandler(opt => HandlePlayerBuild(opt));
}
static void HandlePlayerBuild(BuildPlayerOptions opt) {
try {
OnPreprocessBuild();
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(opt);
}
finally {
OnPostprocessBuild();
}
}
static void OnPreprocessBuild() {
var il2cppRoot = Environment.GetEnvironmentVariable("UNITY_IL2CPP_PATH");
if (string.IsNullOrEmpty(il2cppRoot)) {
_filePath = string.Empty;
return;
}
_filePath = Path.Combine(il2cppRoot, "libil2cpp", "vm", "ScopedThreadAttacher.cpp");
if (!File.Exists(_filePath)) {
_filePath = string.Empty;
return;
}
_oldSrc = File.ReadAllText(_filePath, _encoding);
File.WriteAllText(_filePath, Regex.Replace(_oldSrc, @"~\s*?ScopedThreadAttacher\s*?\(\s*?\)\s*?\{.*\}", "~ScopedThreadAttacher(){}", RegexOptions.Singleline), _encoding);
}
static void OnPostprocessBuild() {
if (string.IsNullOrEmpty(_filePath)) return;
File.WriteAllText(_filePath, _oldSrc, _encoding);
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2322d8e9250e9e6469826361223dfdda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -6,6 +6,7 @@ using TMPro;
using UnityEngine;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.TextCore.Text;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Common.Unity.UI {
[RequireComponent(typeof(TextMeshProUGUI))]
@@ -29,12 +30,14 @@ namespace Cryville.Common.Unity.UI {
else if (DefaultShader) ifont.material.shader = DefaultShader;
if (_font == null) {
_font = ifont;
Logger.Log("main", 1, "UI", "Using main font: {0}", typeface.FullName);
if (MaxFallbackCount <= 0) break;
}
else {
if (_font.fallbackFontAssetTable == null)
_font.fallbackFontAssetTable = new List<FontAsset>();
_font.fallbackFontAssetTable.Add(ifont);
Logger.Log("main", 1, "UI", "Using fallback font #{0}: {1}", _font.fallbackFontAssetTable.Count, typeface.FullName);
if (_font.fallbackFontAssetTable.Count >= MaxFallbackCount) break;
}
}

View File

@@ -0,0 +1,26 @@
namespace Cryville.Common.Unity {
public static class UrlOpener {
public static void Open(string url) {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
System.Diagnostics.Process.Start(url);
#elif UNITY_ANDROID
using (var clazz = new UnityEngine.AndroidJavaClass("world.cryville.common.unity.UrlOpener")) {
clazz.CallStatic("open", url);
}
#else
#error Unknown platform.
#endif
}
public static void OpenThreaded(string url) {
#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
Open(url);
#elif UNITY_ANDROID
UnityEngine.AndroidJNI.AttachCurrentThread();
Open(url);
UnityEngine.AndroidJNI.DetachCurrentThread();
#else
#error Unknown platform.
#endif
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c827ee181de8c51499777e5a822981b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,17 @@
package world.cryville.common.unity;
import android.content.Intent;
import android.net.Uri;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
public final class UrlOpener {
private UrlOpener() { }
static UnityPlayerActivity activity;
public static void open(String url) {
if (activity == null) activity = (UnityPlayerActivity)UnityPlayer.currentActivity;
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
}

View File

@@ -0,0 +1,32 @@
fileFormatVersion: 2
guid: e2d08ba79acb0564b9802b57dbc2f8d3
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Android: Android
second:
enabled: 1
settings: {}
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,4 +1,5 @@
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Skin;
using UnityEngine;
namespace Cryville.Crtr {

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: cfa7de3f6f944914d9999fcfda245f97
timeCreated: 1637552994
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: b38d66b3e6e5d94438c72f855c4efff9
timeCreated: 1637554149
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using Cryville.Common;
using Cryville.Crtr.Extension;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
public struct ChartDetail {
public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f9870328bccefa4d8d4f6d5e3cef591
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 477e04b1ed5b60e48886fb76081245c5
timeCreated: 1637722157
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,6 +3,7 @@ using Cryville.Common.Unity;
using Cryville.Crtr.Extension;
using Cryville.Crtr.Extensions;
using Cryville.Crtr.Extensions.Umg;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -66,7 +67,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}
@@ -93,7 +94,7 @@ namespace Cryville.Crtr.Browsing {
var coverFile = item.GetFiles(meta.cover);
if (coverFile.Length > 0) {
cover = new AsyncDelivery<Texture2D>();
var task = new LoadTextureTask(Game.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
var task = new LoadTextureTask(PlatformConfig.FileProtocolPrefix + coverFile[0].FullName, cover.Deliver);
cover.CancelSource = task.Cancel;
Game.NetworkTaskWorker.SubmitNetworkTask(task);
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 5d443a346e9a19d4eabbb0fa9ec7016f
timeCreated: 1637566071
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 3a13b7ea14b96e54ea8a7e6ba1275281
timeCreated: 1638435211
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,76 +0,0 @@
using Cryville.Common.ComponentModel;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
using RangeAttribute = Cryville.Common.ComponentModel.RangeAttribute;
namespace Cryville.Crtr.Browsing {
public class PropertyPanel : MonoBehaviour {
[SerializeField]
GameObject m_bool;
[SerializeField]
GameObject m_number;
[SerializeField]
GameObject m_string;
PropertyInfo _property;
object _target;
Text _key;
Transform _valueContainer;
PropertyValuePanel _value;
#pragma warning disable IDE0051
void Awake() {
_key = transform.Find("Key").GetComponent<Text>();
_valueContainer = transform.Find("Value");
}
#pragma warning restore IDE0051
public void Load(PropertyInfo prop, object target) {
_target = target;
_property = prop;
_key.text = prop.Name;
GameObject vp;
if (prop.PropertyType == typeof(bool)) vp = m_bool;
else if (prop.PropertyType == typeof(float) || prop.PropertyType == typeof(int)) vp = m_number;
else if (prop.PropertyType == typeof(string)) vp = m_string;
else return;
_value = GameObject.Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
if (_value is PVPNumber) {
var t = (PVPNumber)_value;
t.IntegerMode = prop.PropertyType == typeof(int);
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) {
var u = (RangeAttribute)attr[0];
t.Range = new Vector2(u.Min, u.Max);
}
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
if (attr.Length > 0) {
var u = (PrecisionAttribute)attr[0];
t.Precision = u.Precision;
}
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
if (attr.Length > 0) {
var u = (StepAttribute)attr[0];
t.MaxStep = u.Step;
}
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
if (attr.Length > 0) {
t.LogarithmicMode = true;
}
}
_value.Callback = SetValueToObject;
GetValueFromObject();
}
void GetValueFromObject() {
_value.Value = _property.GetValue(_target, null);
}
void SetValueToObject(object value) {
_property.SetValue(_target, value, null);
GetValueFromObject();
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: bcca29fea992ac24698a213f0e2baedc
timeCreated: 1638435590
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,9 +0,0 @@
using System;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
public abstract class PropertyValuePanel : MonoBehaviour {
public Action<object> Callback { protected get; set; }
public abstract object Value { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: c6b4df13dea0e4a469d7e54e7e8fb428
timeCreated: 1637234060
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 256d7d3efda1f9b4c882eb42e608cc8e
timeCreated: 1638414803
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: a69c80e5f3e7bd04485bc3afc5826584
timeCreated: 1638415083
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,15 +2,6 @@ using Cryville.Common;
using UnityEngine;
namespace Cryville.Crtr.Browsing {
internal abstract class BrowserItem : MonoBehaviour {
public int? Id { get; private set; }
protected ResourceItemMeta meta;
internal virtual void Load(int id, ResourceItemMeta item) {
Id = id;
meta = item;
}
}
public struct ResourceItemMeta {
public bool IsDirectory { get; set; }
public AsyncDelivery<Texture2D> Icon { get; set; }

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f535064222dd08c4f8e52d6e9144079a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba8a8b6df16a9714f9785aba6adc0427
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
using UnityEngine;
namespace Cryville.Crtr.Browsing.UI {
internal abstract class BrowserItem : MonoBehaviour {
public int? Id { get; private set; }
protected ResourceItemMeta meta;
internal virtual void Load(int id, ResourceItemMeta item) {
Id = id;
meta = item;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3cee963751f1ee4c9792c8c8983f51d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -2,7 +2,7 @@ using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
internal class BrowserItemTile : BrowserItem {
#pragma warning disable IDE0044
[SerializeField]
@@ -45,7 +45,7 @@ namespace Cryville.Crtr.Browsing {
}
public void OnClick() {
if (Id == null) return;
ResourceBrowser resourceBrowser = GetComponentInParent<ResourceBrowser>();
var resourceBrowser = GetComponentInParent<ResourceBrowser>();
if (_dir) resourceBrowser.OnDirectoryItemClicked(Id.Value);
else resourceBrowser.OnObjectItemClicked(Id.Value);
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18dcb7d928c649f46bda005527fb6a17
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,7 +4,7 @@ using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
public class DetailPanel : ResourceBrowserUnit {
#pragma warning disable IDE0044
[SerializeField]

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9bdcc04cb1961dd4e9483dbf6c6d6f8b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
internal class PathPart : MonoBehaviour {
private int _id;
private Text _exp;

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 961fa71cc64cc2a4b88adfc5a1aad216
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,10 +1,11 @@
using Cryville.Common.Unity;
using Cryville.Common.Unity.UI;
using Cryville.Crtr.UI;
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
public class ResourceBrowser : ResourceBrowserUnit {
public IResourceManager<ChartDetail> ResourceManager;
public ScrollableItemGrid PathContainer;

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d8141a90dc49f741b382e7abbf0a9c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,13 +1,12 @@
using Cryville.Common;
using Cryville.Common.Unity.UI;
using Cryville.Crtr.Config;
using Cryville.Crtr.Extension;
using Cryville.Crtr.Config.UI;
using Cryville.Crtr.UI;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
public class ResourceBrowserMaster : MonoBehaviour {
[SerializeField]
private Button m_playButton;
@@ -89,9 +88,4 @@ namespace Cryville.Crtr.Browsing {
Settings.Default.LoadChart = MainBrowser.ResourceManager.GetItemPath(id);
}
}
public struct ChartDetail {
public AsyncDelivery<Texture2D> Cover { get; set; }
public ChartMeta Meta { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1c6c8bc301408004a904079721302722
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +1,6 @@
using UnityEngine;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Browsing.UI {
public abstract class ResourceBrowserUnit : MonoBehaviour {
protected ResourceBrowserMaster Master { get; private set; }
protected virtual void Awake() {

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8d98fa73d49ab94cb1a16c5ef09db6c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,10 +1,10 @@
using Cryville.Crtr.Components;
using Cryville.Crtr.Skin.Components;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr {
public static class GenericResources {
public static class BuiltinResources {
public static Dictionary<string, Type> Components
= new Dictionary<string, Type>();
public static Dictionary<string, Shader> Shaders

View File

@@ -1,6 +1,7 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -215,11 +216,11 @@ namespace Cryville.Crtr {
default: return base.GetEventsOfType(type);
}
}
public override int Priority { get { return 10; } }
public override int Priority { get { return 12; } }
}
public class Track : EventContainer {
public override int Priority { get { return 10; } }
public override int Priority { get { return 14; } }
}
public class Motion : ChartEvent {

View File

@@ -66,7 +66,7 @@ namespace Cryville.Crtr {
if (comps[i] == "") comps[i] = "0";
}
_itor.SetSource(string.Format("({0});", string.Join(',', comps)));
ChartPlayer.etor.Evaluate(_vecop, _itor.GetExp());
PdtEvaluator.Instance.Evaluate(_vecop, _itor.GetExp());
return _vecbuf;
}
}
@@ -99,18 +99,18 @@ namespace Cryville.Crtr {
var exp = _itor.GetExp();
switch (c) {
case '@':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.Time = new Vec1(_vecbuf);
break;
case '~':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.EndTime = new Vec1(_vecbuf);
break;
case '^':
node.Transition = exp;
break;
case ':':
ChartPlayer.etor.Evaluate(_vecop, exp);
PdtEvaluator.Instance.Evaluate(_vecop, exp);
node.Value = Vector.Construct(ChartPlayer.motionRegistry[name].Type, _vecbuf);
break;
default:

View File

@@ -1,9 +1,10 @@
#define BUILD
using Cryville.Common;
using Cryville.Common.Buffers;
using Cryville.Crtr.Config;
using Cryville.Crtr.Event;
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.Skin;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -24,9 +25,9 @@ namespace Cryville.Crtr {
public class ChartPlayer : MonoBehaviour {
#region Fields
Chart chart;
Skin skin;
SkinDefinition skin;
public static PdtSkin pskin;
Ruleset ruleset;
RulesetDefinition ruleset;
PdtRuleset pruleset;
Dictionary<string, Texture2D> texs;
public static Dictionary<string, SpriteFrame> frames;
@@ -62,8 +63,6 @@ namespace Cryville.Crtr {
public static float sv = 16f;
public static Dictionary<Identifier, MotionRegistry> motionRegistry;
public static PdtEvaluator etor;
#endregion
#region MonoBehaviour
@@ -75,14 +74,13 @@ namespace Cryville.Crtr {
logs = logobj.GetComponent<TextMeshProUGUI>();
if (!initialized) {
Game.Init();
GenericResources.LoadDefault();
BuiltinResources.LoadDefault();
initialized = true;
}
OnSettingsUpdate();
status = GameObject.Find("Status").GetComponent<TextMeshProUGUI>();
#if BUILD
try {
Play();
}
@@ -91,7 +89,6 @@ namespace Cryville.Crtr {
Popup.CreateException(ex);
ReturnToMenu();
}
#endif
// Camera.main.RenderToCubemap();
}
@@ -186,9 +183,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 4, "Load/MainThread", "Load failed");
loadThread = null;
Popup.CreateException(threadException);
#if BUILD
ReturnToMenu();
#endif
}
else if (texloaddone) {
if (texLoader == null) Stop();
@@ -273,12 +268,12 @@ namespace Cryville.Crtr {
"\nStates: c{0} / b{1}",
cbus.ActiveStateCount, bbus.ActiveStateCount
);
var aTime = Game.AudioClient.Position;
var aTime = Game.AudioClient.Position - atime0;
var iTime = inputProxy.GetTimestampAverage();
statusbuf.AppendFormat(
"\nSTime: {0:G9}s {5} {6}\nATime: {1:G9}s ({3:+0.0ms;-0.0ms;0}) {5} {6}\nITime: {2:G9}s ({4:+0.0ms;-0.0ms;0}) {5} {7}",
cbus.Time, aTime, iTime,
(aTime - atime0 - cbus.Time) * 1e3,
(aTime - cbus.Time) * 1e3,
(iTime - cbus.Time) * 1e3,
forceSyncFrames != 0 ? "(force sync)" : "",
paused ? "(paused)" : "",
@@ -355,13 +350,19 @@ namespace Cryville.Crtr {
forceSyncFrames = Settings.Default.ForceSyncFrames;
Game.AudioClient.Start();
inputProxy.UnlockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetResume(cbus.Time);
#endif
}
else {
Game.AudioClient.Pause();
inputProxy.LockTime();
#if !UNITY_ANDROID || UNITY_EDITOR
DiscordController.Instance.SetPaused();
#endif
}
}
#endregion
#endregion
#region Load
void Play() {
@@ -377,7 +378,7 @@ namespace Cryville.Crtr {
areaJudgePrecision = 1 << Settings.Default.AreaJudgePrecision;
forceSyncFrames = Settings.Default.ForceSyncFrames;
texloaddone = false;
Game.NetworkTaskWorker.SuspendBackgroundTasks();
Game.SuspendBackgroundTasks();
Game.AudioSession = Game.AudioSequencer.NewSession();
var hitPlane = new Plane(Vector3.forward, Vector3.zero);
@@ -419,10 +420,10 @@ namespace Cryville.Crtr {
);
if (!skinFile.Exists) throw new FileNotFoundException("Skin not found\nPlease specify an available skin in the config");
using (StreamReader reader = new StreamReader(skinFile.FullName, Encoding.UTF8)) {
skin = JsonConvert.DeserializeObject<Skin>(reader.ReadToEnd(), new JsonSerializerSettings() {
skin = JsonConvert.DeserializeObject<SkinDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (skin.format != Skin.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
if (skin.format != SkinDefinition.CURRENT_FORMAT) throw new FormatException("Invalid skin file version");
}
loadThread = new Thread(new ParameterizedThreadStart(Load));
@@ -455,7 +456,7 @@ namespace Cryville.Crtr {
for (int i = 0; i < queue.Count; i++) {
#if UNITY_5_4_OR_NEWER
texHandler = new DownloadHandlerTexture();
texLoader = new UnityWebRequest(Game.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader = new UnityWebRequest(PlatformConfig.FileProtocolPrefix + queue[i], "GET", texHandler, null);
texLoader.SendWebRequest();
#else
texLoader = new WWW(Game.FileProtocolPrefix + queue[i]);
@@ -499,22 +500,22 @@ namespace Cryville.Crtr {
IEnumerator<float> Prehandle() {
Stopwatch timer = new Stopwatch();
timer.Reset(); timer.Start();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return .00f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 2)"); yield return 0;
cbus.BroadcastPreInit();
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return .05f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 3)"); yield return 0;
using (var pbus = cbus.Clone(17)) {
while (pbus.Time != double.PositiveInfinity) {
pbus.ForwardOnce();
yield return (float)pbus.EventId / pbus.EventCount * .80f + .05f;
yield return (float)pbus.EventId / pbus.EventCount;
}
}
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return .85f;
Logger.Log("main", 0, "Load/Prehandle", "Prehandling (iteration 4)"); yield return 1;
cbus.BroadcastPostInit();
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return .90f;
Logger.Log("main", 0, "Load/Prehandle", "Seeking to start offset"); yield return 1;
cbus.ForwardByTime(startOffset);
bbus.ForwardByTime(startOffset);
Game.AudioSequencer.SeekTime(startOffset, SeekOrigin.Current);
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return .95f;
Logger.Log("main", 0, "Load/Prehandle", "Cleaning up"); yield return 1;
if (logEnabled && Settings.Default.HideLogOnPlay) ToggleLogs();
Camera.main.cullingMask |= 1;
GC.Collect();
@@ -528,7 +529,7 @@ namespace Cryville.Crtr {
logs.text = "";
}
Game.AudioSequencer.Playing = true;
atime0 = Game.AudioClient.Position - startOffset;
atime0 = Game.AudioClient.BufferPosition - startOffset;
inputProxy.SyncTime(cbus.Time);
inputProxy.Activate();
}
@@ -552,7 +553,7 @@ namespace Cryville.Crtr {
effectManager.Dispose();
effectManager = null;
}
etor = null;
PdtEvaluator.Instance.Reset();
motionRegistry = null;
Logger.Log("main", 1, "Game", "Stopped");
}
@@ -568,10 +569,8 @@ namespace Cryville.Crtr {
started = false;
}
}
Game.NetworkTaskWorker.ResumeBackgroundTasks();
#if BUILD
Game.ResumeBackgroundTasks();
ReturnToMenu();
#endif
}
void OnSettingsUpdate() {
@@ -588,11 +587,9 @@ namespace Cryville.Crtr {
}
Exception threadException;
#if !NO_THREAD
Thread loadThread = null;
volatile float loadPregress;
Stopwatch workerTimer;
#endif
void Load(object _info) {
var info = (LoadInfo)_info;
try {
@@ -622,7 +619,7 @@ namespace Cryville.Crtr {
};
using (StreamReader reader = new StreamReader(info.chartFile.FullName, Encoding.UTF8)) {
etor = new PdtEvaluator();
PdtEvaluator.Instance.Reset();
LoadRuleset(info.rulesetFile); loadPregress = .05f;
@@ -642,7 +639,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/WorkerThread", "Initializing judge and input"); loadPregress = .35f;
judge = new Judge(this, pruleset);
etor.ContextJudge = judge;
PdtEvaluator.Instance.ContextJudge = judge;
inputProxy = new InputProxy(pruleset, judge, screenSize);
inputProxy.LoadFrom(_rscfg.inputs);
@@ -688,14 +685,15 @@ namespace Cryville.Crtr {
DirectoryInfo dir = file.Directory;
Logger.Log("main", 0, "Load/WorkerThread", "Loading ruleset: {0}", file);
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
pruleset = ruleset.Root;
pruleset.Optimize(etor);
pruleset.Optimize(PdtEvaluator.Instance);
}
PdtEvaluator.Instance.ContextRulesetConfig = new RulesetConfigStore(pruleset.configs, _rscfg.configs);
RMVPool.Shared = new RMVPool();
MotionCachePool.Shared = new MotionCachePool();
MotionNodePool.Shared = new MotionNodePool();
@@ -706,7 +704,7 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/WorkerThread", "Loading skin: {0}", file);
skin.LoadPdt(dir);
pskin = skin.Root;
pskin.Optimize(etor);
pskin.Optimize(PdtEvaluator.Instance);
effectManager = new EffectManager(pskin);
}
#endregion

View File

@@ -0,0 +1,101 @@
using Cryville.Common.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
namespace Cryville.Crtr.Config {
public interface IPropertyAdapter {
string Category { get; }
string Name { get; }
PropertyType Type { get; }
object[] Range { get; }
object GetValue();
void SetValue(object value);
event Action ValueChanged;
object MapValue(object value);
bool SetMapped { get; }
object MapValueInverse(object value);
}
public enum PropertyType {
Unknown,
Number,
NumberStepped,
Boolean,
String,
}
public class DefaultPropertyAdapter : IPropertyAdapter {
readonly object _target;
readonly PropertyInfo _prop;
public string Category { get; private set; }
public string Name { get; private set; }
public PropertyType Type { get; private set; }
public object[] Range { get; private set; }
public object GetValue() { return _prop.GetValue(_target, null); }
public void SetValue(object value) { _prop.SetValue(_target, value, null); }
public event Action ValueChanged { add { } remove { } }
readonly double _precision;
readonly double _step;
readonly bool _logarithmic;
public object MapValue(object value) {
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
var result = (double)value;
if (_step != 0) result *= _step;
if (_logarithmic) result = Math.Pow(Math.E, result);
if (_precision != 0) result = Math.Round(result / _precision) * _precision;
return Convert.ChangeType(result, _prop.PropertyType);
}
return value;
}
public bool SetMapped { get { return true; } }
public object MapValueInverse(object value) {
if (Type == PropertyType.Number || Type == PropertyType.NumberStepped) {
var result = Convert.ToDouble(value);
if (_logarithmic) result = Math.Log(result);
if (_step != 0) result /= _step;
return result;
}
return value;
}
public DefaultPropertyAdapter(object target, PropertyInfo prop) {
_target = target;
_prop = prop;
var attrs = prop.GetCustomAttributes(typeof(CategoryAttribute), true);
if (attrs.Length > 0) Category = ((CategoryAttribute)attrs.Single()).Category;
Name = prop.Name;
if (prop.PropertyType == typeof(bool)) Type = PropertyType.Boolean;
else if (prop.PropertyType == typeof(char)) throw new NotSupportedException();
else if (prop.PropertyType.IsPrimitive) {
Type = prop.GetCustomAttributes(typeof(StepAttribute), true).Length > 0
? PropertyType.NumberStepped
: PropertyType.Number;
var attr = prop.GetCustomAttributes(typeof(RangeAttribute), true);
if (attr.Length > 0) {
var u = (RangeAttribute)attr.Single();
Range = new object[] { u.Min, u.Max };
}
attr = prop.GetCustomAttributes(typeof(PrecisionAttribute), true);
if (attr.Length > 0) {
var u = (PrecisionAttribute)attr.Single();
_precision = u.Precision;
}
attr = prop.GetCustomAttributes(typeof(StepAttribute), true);
if (attr.Length > 0) {
var u = (StepAttribute)attr.Single();
_step = u.Step;
}
attr = prop.GetCustomAttributes(typeof(LogarithmicScaleAttribute), true);
if (attr.Length > 0) {
_logarithmic = true;
}
}
else if (prop.PropertyType == typeof(string)) Type = PropertyType.String;
else return;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9b3e9219783719544bcbceade34a1090
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace Cryville.Crtr.Config {
public interface IPropertyMasterAdapter {
string DefaultCategory { get; }
IEnumerable<IPropertyAdapter> GetProperties();
}
public class DefaultPropertyMasterAdapter : IPropertyMasterAdapter {
readonly object _target;
public DefaultPropertyMasterAdapter(object target) {
if (target == null) throw new ArgumentNullException("target");
_target = target;
}
public string DefaultCategory { get { return "miscellaneous"; } }
public IEnumerable<IPropertyAdapter> GetProperties() {
return _target.GetType().GetProperties().Where(p => {
var attrs = p.GetCustomAttributes(typeof(BrowsableAttribute), true);
if (attrs.Length == 0) return true;
else return ((BrowsableAttribute)attrs.Single()).Browsable;
}).Select(p => new DefaultPropertyAdapter(_target, p));
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4e0b160d43716cf4d8ba20b5a7eafd13
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,13 +14,13 @@ namespace Cryville.Crtr.Config {
[Category("gameplay")]
[JsonProperty("sound_offset")]
[Step(0.04f)]
[Step(0.04)]
[Precision(1e-3)]
public float SoundOffset { get; set; }
[Category("deprecated")][Obsolete]
[JsonProperty("scroll_velocity")][DefaultValue(1)]
[LogarithmicScale][Step(0.5f)][Precision(1e-1)]
[LogarithmicScale][Step(0.5)][Precision(1e-1)]
public float ScrollVelocity { get; set; }
public Generic() {
@@ -29,6 +29,8 @@ namespace Cryville.Crtr.Config {
ScrollVelocity = 1;
}
}
public Dictionary<string, object> configs
= new Dictionary<string, object>();
public Dictionary<string, InputEntry> inputs
= new Dictionary<string, InputEntry>();
public class InputEntry {

View File

@@ -0,0 +1,100 @@
using Cryville.Common;
using Cryville.Common.Pdt;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;
namespace Cryville.Crtr.Config {
internal class RulesetConfigPropertyMasterAdapter : IPropertyMasterAdapter {
readonly List<RulesetConfigPropertyAdapter> _props = new List<RulesetConfigPropertyAdapter>();
readonly RulesetConfigStore _store;
public RulesetConfigPropertyMasterAdapter(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
_store = new RulesetConfigStore(defs, values);
PdtEvaluator.Instance.ContextRulesetConfig = _store;
if (defs == null) return;
foreach (var def in defs) {
_props.Add(new RulesetConfigPropertyAdapter(def.Key, def.Value, this));
}
}
public string DefaultCategory { get { return "miscellaneous"; } }
public IEnumerable<IPropertyAdapter> GetProperties() { return _props; }
public object GetValue(string key) {
return _store[key];
}
public void SetValue(string key, object value) {
_store[key] = value;
foreach (var prop in _props) {
prop.OnValueChanged();
}
}
}
internal class RulesetConfigPropertyAdapter : IPropertyAdapter {
readonly RulesetConfigPropertyMasterAdapter _master;
readonly ConfigDefinition _def;
public RulesetConfigPropertyAdapter(Identifier key, ConfigDefinition def, RulesetConfigPropertyMasterAdapter master) {
_master = master;
_def = def;
Name = (string)key.Name;
switch (_def.type) {
case ConfigType.number: Type = PropertyType.Number; break;
case ConfigType.number_stepped: Type = PropertyType.NumberStepped; break;
default: Type = PropertyType.Unknown; break;
}
_rangeOp = new PropOp.Clip(v => {
m_range[0] = (double)v.Behind;
m_range[1] = (double)v.Ahead;
});
}
public string Category { get { return _def.category; } }
public string Name { get; private set; }
public PropertyType Type { get; private set; }
readonly PdtOperator _rangeOp;
readonly object[] m_range = new object[] { double.NegativeInfinity, double.PositiveInfinity };
public object[] Range {
get {
if (_def.range != null)
PdtEvaluator.Instance.Evaluate(_rangeOp, _def.range);
return m_range;
}
}
public object GetValue() {
return _master.GetValue(Name);
}
public void SetValue(object value) {
_master.SetValue(Name, value);
}
public event Action ValueChanged;
public void OnValueChanged() {
var ev = ValueChanged;
if (ev != null) ev();
}
public bool SetMapped { get { return false; } }
readonly PropStores.Float _numst = new PropStores.Float();
public object MapValue(object value) {
_numst.Value = (float)(double)value;
if (_def.value == null) return _numst.Value;
PdtEvaluator.Instance.ContextSelfValue = _numst.Source;
PdtEvaluator.Instance.Evaluate(_numst.Target, _def.value);
PdtEvaluator.Instance.ContextSelfValue = null;
return _numst.Value;
}
public object MapValueInverse(object value) { throw new NotSupportedException(); }
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c8b12ed5f582bb24fbc508f74f8ef79e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using Cryville.Common;
using Cryville.Common.Collections.Specialized;
using Cryville.Crtr.Ruleset;
using System;
using System.Collections.Generic;
namespace Cryville.Crtr.Config {
public class RulesetConfigStore {
readonly IntKeyedDictionary<PropSrc> _srcs = new IntKeyedDictionary<PropSrc>();
readonly Dictionary<string, int> _revMap = new Dictionary<string, int>();
readonly Dictionary<string, object> _values;
public RulesetConfigStore(Dictionary<Identifier, ConfigDefinition> defs, Dictionary<string, object> values) {
_values = values;
if (defs == null) return;
foreach (var def in defs) {
var key = def.Key.Key;
var name = (string)def.Key.Name;
if (!_values.ContainsKey(name)) {
double value = 0;
PdtEvaluator.Instance.Evaluate(new PropOp.Float(v => value = v), def.Value.@default);
_values.Add(name, value);
}
_revMap.Add(name, key);
_srcs.Add(key, new PropSrc.Float(() => {
float result = 0;
PdtEvaluator.Instance.ContextSelfValue = new PropSrc.Float(() => Convert.ToSingle(_values[name]));
PdtEvaluator.Instance.Evaluate(new PropOp.Float(v => result = v), def.Value.value);
PdtEvaluator.Instance.ContextSelfValue = null;
return result;
}));
}
}
public object this[string key] {
get { return _values[key]; }
set {
_values[key] = value;
_srcs[_revMap[key]].Invalidate();
}
}
public bool TryGetMappedSource(int key, out PropSrc result) {
return _srcs.TryGetValue(key, out result);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d346b4bc0a3d4a44f90a924d01c0d2f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 26842cf5cfcceb14a9dbb07adbdf4da0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,3 +1,5 @@
using Cryville.Crtr.Ruleset;
using Cryville.Crtr.UI;
using Newtonsoft.Json;
using System;
using System.IO;
@@ -5,7 +7,7 @@ using System.Text;
using UnityEngine;
using Logger = Cryville.Common.Logging.Logger;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class ConfigPanelMaster : MonoBehaviour {
[SerializeField]
Menu m_menu;
@@ -14,17 +16,22 @@ namespace Cryville.Crtr.Config {
Transform m_content;
[SerializeField]
SettingsPanel m_genericConfigPanel;
PropertyMasterPanel m_genericConfigPanel;
[SerializeField]
PropertyMasterPanel m_rulesetConfigPanel;
[SerializeField]
InputConfigPanel m_inputConfigPanel;
public Ruleset ruleset;
public RulesetDefinition ruleset;
RulesetConfig _rscfg;
bool _loaded;
void OnEnable() {
try {
ChartPlayer.etor = new PdtEvaluator();
PdtEvaluator.Instance.Reset();
FileInfo file = new FileInfo(
Game.GameDataPath + "/rulesets/" + Settings.Default.LoadRuleset
);
@@ -33,10 +40,10 @@ namespace Cryville.Crtr.Config {
}
DirectoryInfo dir = file.Directory;
using (StreamReader reader = new StreamReader(file.FullName, Encoding.UTF8)) {
ruleset = JsonConvert.DeserializeObject<Ruleset>(reader.ReadToEnd(), new JsonSerializerSettings() {
ruleset = JsonConvert.DeserializeObject<RulesetDefinition>(reader.ReadToEnd(), new JsonSerializerSettings() {
MissingMemberHandling = MissingMemberHandling.Error
});
if (ruleset.format != Ruleset.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
if (ruleset.format != RulesetDefinition.CURRENT_FORMAT) throw new FormatException("Invalid ruleset file version");
ruleset.LoadPdt(dir);
}
FileInfo cfgfile = new FileInfo(
@@ -54,13 +61,16 @@ namespace Cryville.Crtr.Config {
}
}
m_genericConfigPanel.Target = _rscfg.generic;
m_genericConfigPanel.Adapter = new DefaultPropertyMasterAdapter(_rscfg.generic);
m_rulesetConfigPanel.Adapter = new RulesetConfigPropertyMasterAdapter(ruleset.Root.configs, _rscfg.configs);
var proxy = new InputProxy(ruleset.Root, null, new Vector2(Screen.width, Screen.height));
proxy.LoadFrom(_rscfg.inputs);
m_inputConfigPanel.proxy = proxy;
m_inputConfigPanel.OnConfigEnable();
_loaded = true;
}
catch (Exception ex) {
Popup.CreateException(ex);
@@ -77,15 +87,18 @@ namespace Cryville.Crtr.Config {
}
void OnDisable() {
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
m_inputConfigPanel.proxy.Dispose();
FileInfo cfgfile = new FileInfo(
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
);
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
if (_loaded) {
_loaded = false;
m_inputConfigPanel.proxy.SaveTo(_rscfg.inputs);
m_inputConfigPanel.proxy.Dispose();
FileInfo cfgfile = new FileInfo(
Game.GameDataPath + "/config/rulesets/" + Settings.Default.LoadRulesetConfig
);
using (StreamWriter cfgwriter = new StreamWriter(cfgfile.FullName, false, Encoding.UTF8)) {
cfgwriter.Write(JsonConvert.SerializeObject(_rscfg, Game.GlobalJsonSerializerSettings));
}
m_inputConfigPanel.OnConfigDisable();
}
m_inputConfigPanel.OnConfigDisable();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 54c06a15adfb41548acca0d73f391fe7
guid: bad1f43573d4f1143a94fddddd30fb81
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,12 +1,13 @@
using Cryville.Common;
using Cryville.Common.Unity;
using Cryville.Crtr.Ruleset;
using Cryville.Input;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanel : MonoBehaviour {
[SerializeField]
ConfigPanelMaster m_configScene;
@@ -30,6 +31,7 @@ namespace Cryville.Crtr.Config {
public InputProxy proxy;
readonly Dictionary<Identifier, InputConfigPanelEntry> _entries = new Dictionary<Identifier, InputConfigPanelEntry>();
int _applicableEntries;
Identifier _sel;
int _targetDim;
PhysicalDimension? _targetPDim;
@@ -45,6 +47,7 @@ namespace Cryville.Crtr.Config {
CallHelper.Purge(m_deviceList);
_consumer.EnumerateEvents(ev => { });
_recvsrcs.Clear();
_applicableEntries = 1;
AddSourceItem(null);
}
@@ -143,7 +146,7 @@ namespace Cryville.Crtr.Config {
}
else flag = true;
btn.interactable = flag;
obj.transform.SetSiblingIndex(flag ? 1 : m_deviceList.childCount - 1);
obj.transform.SetSiblingIndex(flag ? _applicableEntries++ : m_deviceList.childCount - 1);
}
else {
obj.transform.SetSiblingIndex(0);

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: d27589834da67984d98c6147c8b6b5bb
guid: 279d2404a312e5543813d8aca02800b8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,9 +1,10 @@
using Cryville.Common;
using Cryville.Crtr.Ruleset;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Config {
namespace Cryville.Crtr.Config.UI {
public class InputConfigPanelEntry : MonoBehaviour {
[SerializeField]
Text m_key;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 8661f4d4934e11040a0c65729d4ba47a
guid: 9741a0ed8c1c5e0468ea89f2cf33f36c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,14 +1,8 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Config.UI {
public class PVPBool : PropertyValuePanel, IPointerClickHandler {
bool _value;
public override object Value {
get { return _value; }
set { _value = (bool)value; }
}
[SerializeField]
RectTransform m_on;
[SerializeField]
@@ -16,21 +10,22 @@ namespace Cryville.Crtr.Browsing {
[SerializeField]
RectTransform m_handle;
protected override void OnValueUpdated() { }
public void Toggle() {
_value = !_value;
Callback(Value);
RawValue = !(bool)RawValue;
}
const float SPEED = 8;
float _ratio;
#pragma warning disable IDE0051
void Update() {
if (_value && _ratio != 1) {
if ((bool)RawValue && _ratio != 1) {
_ratio += SPEED * Time.deltaTime;
if (_ratio > 1) _ratio = 1;
UpdateGraphics();
}
else if (!_value && _ratio != 0) {
else if (!(bool)RawValue && _ratio != 0) {
_ratio -= SPEED * Time.deltaTime;
if (_ratio < 0) _ratio = 0;
UpdateGraphics();

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b281561aca5d19f43ba8af035de8ec98
guid: 9cb1bc40304ff174f891239c8f450c1c
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,27 @@
using System;
namespace Cryville.Crtr.Config.UI {
public class PVPNumber : PVPNumberBase {
protected override void OnValueUpdated() {
base.OnValueUpdated();
if (Range != null && Range.Length == 2) {
var min = (double)Range[0];
var max = (double)Range[1];
var value = Convert.ToDouble(RawValue);
if (value < min) {
value = min;
RawValue = value;
}
else if (value > max) {
value = max;
RawValue = value;
}
SetRatio((float)((value - min) / (max - min)));
}
}
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
// if (LogarithmicMode) throw new NotImplementedException();
return (1 - ratio) * min + ratio * max;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 1eb74ffd69f934d4a8eca80aa3077b6c
guid: 94cb9dad5ac3eb04ca16d58a7bae0cb5
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,52 +1,19 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
public class PVPNumber : PropertyValuePanel {
double m_value;
public override object Value {
get {
float s_value = GetDisplayValue();
return IntegerMode ? (int)s_value : (object)s_value;
}
set {
if (value is double) m_value = (double)value;
else m_value = IntegerMode ? (int)value : (double)(float)value;
float s_value = GetDisplayValue();
m_text.text = s_value.ToString();
if (Range != null && MaxStep == 0) {
SetRatio((float)(m_value - Range.Value.x) / (Range.Value.y - Range.Value.x));
}
}
}
float GetDisplayValue() {
double s_value = m_value;
if (Precision > 0)
s_value = Math.Round(s_value / Precision) * Precision;
if (IntegerMode)
s_value = Math.Round(s_value);
return (float)s_value;
}
public bool IntegerMode { get; set; }
public bool LogarithmicMode { get; set; }
public float MaxStep { get; set; }
public double Precision { get; set; }
public Vector2? Range { get; set; }
namespace Cryville.Crtr.Config.UI {
public abstract class PVPNumberBase : PropertyValuePanel {
[SerializeField]
EventTrigger m_ctn;
[SerializeField]
RectTransform m_handleArea;
[SerializeField]
RectTransform m_handle;
Image m_handle;
[SerializeField]
Text m_text;
#pragma warning disable IDE0051
void Start() {
protected void Start() {
var ev = new EventTrigger.Entry { eventID = EventTriggerType.InitializePotentialDrag };
ev.callback.AddListener(e => OnInitializePotentialDrag((PointerEventData)e));
m_ctn.triggers.Add(ev);
@@ -59,22 +26,28 @@ namespace Cryville.Crtr.Browsing {
ev = new EventTrigger.Entry { eventID = EventTriggerType.PointerClick };
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
m_ctn.triggers.Add(ev);
if (MaxStep != 0) SetRatio(0.5f);
OnIdle();
}
protected override void OnValueUpdated() {
m_text.text = MappedValue.ToString();
}
protected virtual void OnIdle() { }
void Update() {
if (use && MaxStep != 0) {
if (use) {
SetRatio(GetRatioFromPos(pp));
SetValueFromPos(pp);
}
}
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
m_handleArea.sizeDelta = new Vector2(m_handle.rectTransform.rect.height - m_handle.rectTransform.rect.width, 0);
}
#pragma warning restore IDE0051
Camera cam;
Vector2 pp;
bool use, nouse;
public void OnInitializePotentialDrag(PointerEventData eventData) {
@@ -84,6 +57,7 @@ namespace Cryville.Crtr.Browsing {
public void OnDrag(PointerEventData eventData) {
if (nouse) return;
cam = eventData.pressEventCamera;
if (!use) {
var delta = eventData.position - pp;
float dx = Mathf.Abs(delta.x), dy = Mathf.Abs(delta.y);
@@ -92,7 +66,6 @@ namespace Cryville.Crtr.Browsing {
}
if (use) {
pp = eventData.position;
if (MaxStep == 0) SetValueFromPos(eventData.position);
eventData.Use();
}
}
@@ -100,8 +73,7 @@ namespace Cryville.Crtr.Browsing {
public void OnEndDrag(PointerEventData eventData) {
if (!nouse) {
SetValueFromPos(eventData.position);
Callback(Value);
if (MaxStep != 0) SetRatio(0.5f);
OnIdle();
eventData.Use();
use = false;
}
@@ -110,13 +82,12 @@ namespace Cryville.Crtr.Browsing {
public void OnPointerClick(PointerEventData eventData) {
SetValueFromPos(eventData.position);
Callback(Value);
eventData.Use();
}
float GetRatioFromPos(Vector2 pos) {
Vector2 lp;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_handleArea, pos, null, out lp)) {
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_handleArea, pos, cam, out lp)) {
lp -= m_handleArea.rect.position;
return Mathf.Clamp01(lp.x / m_handleArea.rect.width);
}
@@ -124,27 +95,24 @@ namespace Cryville.Crtr.Browsing {
}
void SetValueFromPos(Vector2 pos) {
double min = double.NegativeInfinity, max = double.PositiveInfinity;
if (Range != null && Range.Length == 2) {
min = (double)Range[0];
max = (double)Range[1];
}
double ratio = GetRatioFromPos(pos);
double result;
if (MaxStep == 0) {
if (LogarithmicMode) throw new NotImplementedException();
else result = (1 - ratio) * Range.Value.x + ratio * Range.Value.y;
}
else {
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * MaxStep * Time.deltaTime;
if (LogarithmicMode) result = Math.Pow(Math.E, Math.Log(m_value) + delta);
else result = m_value + delta;
}
if (Range != null) {
if (result < Range.Value.x) result = Range.Value.x;
else if (result > Range.Value.y) result = Range.Value.y;
}
Value = result;
double result = GetValue(ratio, Time.deltaTime, min, max);
if (result < min) result = min;
else if (result > max) result = max;
RawValue = result;
}
void SetRatio(float ratio) {
m_handle.anchorMin = new Vector2(ratio, m_handle.anchorMin.y);
m_handle.anchorMax = new Vector2(ratio, m_handle.anchorMax.y);
protected abstract double GetValue(double ratio, float deltaTime, double min, double max);
protected void SetRatio(float ratio) {
m_handle.rectTransform.anchorMin = new Vector2(ratio, m_handle.rectTransform.anchorMin.y);
m_handle.rectTransform.anchorMax = new Vector2(ratio, m_handle.rectTransform.anchorMax.y);
m_handle.rectTransform.anchoredPosition = Vector2.zero;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c928ece9c4b30f04cb33f66eb9f050b3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
using System;
namespace Cryville.Crtr.Config.UI {
public class PVPNumberStepped : PVPNumberBase {
protected override void OnIdle() {
SetRatio(0.5f);
}
protected override double GetValue(double ratio, float deltaTime, double min, double max) {
double delta = (ratio > 0.5 ? 1 : -1) * Math.Pow((ratio - 0.5f) * 2, 2) * deltaTime;
// if (LogarithmicMode) return Math.Pow(Math.E, Math.Log(m_value) + delta);
return Convert.ToDouble(RawValue) + delta;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c309650ed758ea34ba64e765f59bb043
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,17 +1,8 @@
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Config.UI {
public class PVPString : PropertyValuePanel {
string m_value;
public override object Value {
get {
return m_value;
}
set {
m_value = (string)value;
_inputField.text = m_value;
}
}
protected override void OnValueUpdated() { _inputField.text = (string)MappedValue; }
InputField _inputField;
@@ -21,8 +12,7 @@ namespace Cryville.Crtr.Browsing {
}
void OnValueChanged(string value) {
m_value = value;
Callback(Value);
RawValue = value;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: aadf11739189bc94e9cb4f702eb7ccd3
guid: f81596a59a59fce48854b6753fe8cfc6
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,9 +1,8 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Browsing {
namespace Cryville.Crtr.Config.UI {
public class PropertyCategoryPanel : MonoBehaviour {
[SerializeField]
private GameObject m_propertyPrefab;
@@ -29,11 +28,11 @@ namespace Cryville.Crtr.Browsing {
}
#pragma warning restore IDE0051
public void Load(string name, IEnumerable<PropertyInfo> props, object target) {
public void Load(string name, IEnumerable<IPropertyAdapter> props) {
Name = name.ToUpper();
foreach (var prop in props) {
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab, transform, false);
obj.GetComponent<PropertyPanel>().Load(prop, target);
var obj = Instantiate(m_propertyPrefab, transform, false);
obj.GetComponent<PropertyPanel>().Load(prop);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 11c5451aac09cbd4a8e94c82d5c568e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,51 @@
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Config.UI {
public class PropertyMasterPanel : MonoBehaviour {
[SerializeField]
GameObject m_categoryPrefab;
[SerializeField]
Transform m_container;
bool _invalidated = true;
public void Invalidate() {
_invalidated = true;
}
private IPropertyMasterAdapter m_adapter;
public IPropertyMasterAdapter Adapter {
get { return m_adapter; }
set {
m_adapter = value;
Invalidate();
}
}
public void Update() {
if (!_invalidated) return;
LoadProperties();
foreach (Transform c in m_container) Destroy(c.gameObject);
foreach (var c in _categories) {
var obj = Instantiate(m_categoryPrefab, m_container, false);
obj.GetComponent<PropertyCategoryPanel>().Load(c.Key, c.Value);
}
}
readonly Dictionary<string, List<IPropertyAdapter>> _categories = new Dictionary<string, List<IPropertyAdapter>>();
public void LoadProperties() {
_categories.Clear();
_invalidated = false;
if (Adapter == null) return;
foreach (var p in Adapter.GetProperties()) {
string category = p.Category;
if (category == null) category = Adapter.DefaultCategory;
if (!_categories.ContainsKey(category))
_categories.Add(category, new List<IPropertyAdapter>());
_categories[category].Add(p);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8d04667a373e4648a83440b496c8127
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Crtr.Config.UI {
public class PropertyPanel : MonoBehaviour {
[SerializeField]
GameObject m_bool;
[SerializeField]
GameObject m_number;
[SerializeField]
GameObject m_numberStepped;
[SerializeField]
GameObject m_string;
Text _key;
Transform _valueContainer;
PropertyValuePanel _value;
#pragma warning disable IDE0051
void Awake() {
_key = transform.Find("Key").GetComponent<Text>();
_valueContainer = transform.Find("Value");
}
#pragma warning restore IDE0051
public void Load(IPropertyAdapter prop) {
_key.text = prop.Name;
GameObject vp;
switch (prop.Type) {
case PropertyType.Number: vp = m_number; break;
case PropertyType.NumberStepped: vp = m_numberStepped; break;
case PropertyType.Boolean: vp = m_bool; break;
case PropertyType.String: vp = m_string; break;
default: return;
}
_value = Instantiate(vp, _valueContainer, false).GetComponent<PropertyValuePanel>();
_value.Init(prop);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a812a9e54dd057459b501c0881b0f68
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using UnityEngine;
namespace Cryville.Crtr.Config.UI {
public abstract class PropertyValuePanel : MonoBehaviour {
IPropertyAdapter _property;
public void Init(IPropertyAdapter property) {
_property = property;
_property.ValueChanged += GetValue;
GetValue();
}
protected object[] Range { get { return _property.Range; } }
public object MappedValue { get; private set; }
private object m_rawValue;
public object RawValue {
get { return m_rawValue; }
set {
m_rawValue = value;
SetValue();
}
}
protected abstract void OnValueUpdated();
void GetValue() {
if (_property.SetMapped) {
MappedValue = _property.GetValue();
m_rawValue = _property.MapValueInverse(MappedValue);
}
else {
m_rawValue = _property.GetValue();
MappedValue = _property.MapValue(m_rawValue);
}
OnValueUpdated();
}
void SetValue() {
var outRaw = RawValue;
MappedValue = _property.MapValue(outRaw);
_property.SetValue(_property.SetMapped ? MappedValue : outRaw);
OnValueUpdated();
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fca3da10a8b0677439885f6732ac3b6e
guid: aa6b204c7a1fd1d4c95d912196fc7566
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,4 +1,4 @@
using Cryville.Common.Network;
using Cryville.Common.Network.Http11;
using System;
using System.Collections.Generic;
using System.Threading;
@@ -123,13 +123,13 @@ namespace Cryville.Crtr {
try {
switch (p[0]) {
case "!http":
var httpcl = new HttpClient(new Uri(p[1]));
var httpcl = new Http11Client(new Uri(p[1]));
httpcl.Connect();
httpcl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
httpcl.Close();
break;
case "!https":
var httpscl = new HttpsClient(new Uri(p[1]));
var httpscl = new Https11Client(new Uri(p[1]));
httpscl.Connect();
httpscl.Request("GET", new Uri(p[1])).MessageBody.ReadToEnd();
httpscl.Close();

Some files were not shown because too many files have changed in this diff Show More