Skip to content

Commit 2db067f

Browse files
committed
Speed Shard and some other things
1 parent 2ffafd2 commit 2db067f

28 files changed

+612
-38
lines changed

App.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@
363363
</Style>
364364
<ResourceDictionary.MergedDictionaries>
365365
<ResourceDictionary Source="Language/zh-cn.xaml"/>
366+
<ResourceDictionary Source="Language/ru-ru.xaml"/>
366367
<ResourceDictionary Source="Language/en-us.xaml"/>
367368
</ResourceDictionary.MergedDictionaries>
368369
</ResourceDictionary>

DataLoader.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ModShardLauncher
2222
public class DataLoader
2323
{
2424
public static UndertaleData data = null;
25+
public static UndertaleData dataCache = null;
2526
internal static string DataPath = "";
2627
public delegate void FileMessageEventHandler(string message);
2728
public static event FileMessageEventHandler FileMessageEvent;
@@ -90,6 +91,19 @@ public static async Task LoadFile(string filename, bool re = false)
9091
{
9192
FileMessageEvent?.Invoke(message);
9293
});
94+
dataCache = UndertaleIO.Read(stream, warning =>
95+
{
96+
ShowWarning(warning, "Loading warning");
97+
98+
if (warning.Contains("unserializeCountError.txt")
99+
|| warning.Contains("object pool size"))
100+
return;
101+
102+
hadWarnings = true;
103+
}, delegate (string message)
104+
{
105+
FileMessageEvent?.Invoke(message);
106+
});
93107
}
94108

95109
UndertaleEmbeddedTexture.TexData.ClearSharedStream();

FilePacker.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ModShardLauncher.Mods;
55
using System;
66
using System.Collections.Generic;
7+
using System.Collections.ObjectModel;
78
using System.IO;
89
using System.Linq;
910
using System.Reflection;
@@ -20,6 +21,7 @@ public static void Pack(string path)
2021
var dir = new DirectoryInfo(path);
2122
var textures = dir.GetFiles("*.png", SearchOption.AllDirectories).ToList();
2223
var scripts = dir.GetFiles("*.lua", SearchOption.AllDirectories).ToList();
24+
var codes = dir.GetFiles("*.gml", SearchOption.AllDirectories).ToList();
2325
FileStream fs = new FileStream(Path.Join(ModLoader.ModPath, dir.Name + ".sml"), FileMode.Create);
2426
Write(fs, "MSLM");
2527
var version = DataLoader.GetVersion();
@@ -38,6 +40,18 @@ public static void Pack(string path)
3840
}
3941
Write(fs, scripts.Count);
4042
foreach (var scr in scripts)
43+
{
44+
var name = dir.Name + scr.FullName.Replace(path, "");
45+
Write(fs, name.Length);
46+
Write(fs, name);
47+
Write(fs, offset);
48+
var len = CalculateBytesLength(scr);
49+
Write(fs, len);
50+
offset += len;
51+
52+
}
53+
Write(fs, codes.Count);
54+
foreach (var scr in codes)
4155
{
4256
var name = dir.Name + scr.FullName.Replace(path, "");
4357
Write(fs, name.Length);
@@ -51,6 +65,8 @@ public static void Pack(string path)
5165
Write(fs, tex);
5266
foreach (var scr in scripts)
5367
Write(fs, scr);
68+
foreach (var scr in codes)
69+
Write(fs, scr);
5470
var successful = CompileMod(dir.Name, path, out var code, out _, fs);
5571
if (!successful) return;
5672
Write(fs, code.Length);
@@ -109,6 +125,7 @@ public static Diagnostic[] RoslynCompile(string name, string[] files, string[] p
109125
MetadataReference.CreateFromFile(typeof(object).Assembly.Location),//mscorlib.dll
110126
MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location),//System.dll
111127
MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location),
128+
MetadataReference.CreateFromFile(typeof(ObservableCollection<>).Assembly.Location),
112129
MetadataReference.CreateFromFile(refPath("System.Collections.dll")),//System.Core.dll
113130
MetadataReference.CreateFromFile(refPath("ModShardLauncher.dll")),
114131
MetadataReference.CreateFromFile(refPath("UndertaleModLib.dll")),

FileReader.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public byte[] GetFile(string name)
6565
}
6666
else return new byte[0];
6767
}
68+
public string GetCode(string name)
69+
{
70+
var data = GetFile(name);
71+
var text = Encoding.UTF8.GetString(data);
72+
if(text.Length == 0)
73+
{
74+
MessageBox.Show(Application.Current.FindResource("ModLostWarning").ToString() + " : " + name);
75+
return "";
76+
}
77+
text = text.Remove(0,1);
78+
return text;
79+
}
6880
public bool FileExist(string name)
6981
{
7082
return GetFile(name).Length > 0;
@@ -105,6 +117,16 @@ public static ModFile Read(string path)
105117
chunk.length = BitConverter.ToInt32(Read(fs, 4));
106118
file.Files.Add(chunk);
107119
}
120+
count = BitConverter.ToInt32(Read(fs, 4), 0);
121+
for (int i = 0; i < count; i++)
122+
{
123+
var len = BitConverter.ToInt32(Read(fs, 4), 0);
124+
var chunk = new FileChunk();
125+
chunk.name = Encoding.UTF8.GetString(Read(fs, len));
126+
chunk.offset = BitConverter.ToInt32(Read(fs, 4));
127+
chunk.length = BitConverter.ToInt32(Read(fs, 4));
128+
file.Files.Add(chunk);
129+
}
108130
file.FileOffset = (int)fs.Position;
109131

110132
if(file.Files.Count > 0)

Language/ru-ru.xaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:sys="clr-namespace:System;assembly=mscorlib">
4+
<sys:String x:Key="FileHeader">Файл</sys:String>
5+
<sys:String x:Key="SettingHeader">Настройки</sys:String>
6+
<sys:String x:Key="FileHeader_Open">Открыть</sys:String>
7+
<sys:String x:Key="SettingHeader_Lang">Язык</sys:String>
8+
<sys:String x:Key="RefreshButtonText">Обновить</sys:String>
9+
<sys:String x:Key="PatchButtonText">Загрузить</sys:String>
10+
<sys:String x:Key="SearchBoxText">Поиск по названию мода...</sys:String>
11+
<sys:String x:Key="Welcome">Добро пожаловать</sys:String>
12+
<sys:String x:Key="Welcome_Use">Добро пожаловать в ModShardLauncher!</sys:String>
13+
<sys:String x:Key="Welcome_Desc">Если вы хотите обновить моды, просто вставьте их в папку /Mods и нажмите кнопку "Обновить" слева.
14+
Сначала нажмите кнопку "Файл" и откройте исходный файл данных, затем выберите моды, которые вы хотите включить.
15+
Затем нажмите кнопку "Загрузить", чтобы загрузить моды в файл данных.</sys:String>
16+
<sys:String x:Key="ModName">Название мода</sys:String>
17+
<sys:String x:Key="ModAuthor">Автор мода</sys:String>
18+
<sys:String x:Key="ModDescription">Описание мода</sys:String>
19+
<sys:String x:Key="EnableMod">Включить мод</sys:String>
20+
<sys:String x:Key="ModVersion">Версия мода</sys:String>
21+
<sys:String x:Key="GameVersion">Версия игры</sys:String>
22+
<sys:String x:Key="Compile">Компилировать</sys:String>
23+
<sys:String x:Key="LoadDataWarning">Пожалуйста, загрузите файл данных игры сначала!</sys:String>
24+
<sys:String x:Key="VersionDifferentWarningTitle">Версия мода отличается от версии игры</sys:String>
25+
<sys:String x:Key="VersionDifferentWarning">Версия мода отличается от версии игры, возможно, это вызовет сбой. Вы всё равно хотите загрузить его?</sys:String>
26+
<sys:String x:Key="ModLostWarning">Файл мода отсутствует</sys:String>
27+
</ResourceDictionary>

Main.xaml.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public partial class Main : Window
2626
public Main()
2727
{
2828
Instance = this;
29-
Settings.LoadSettings();
3029
MainPage = new MainPage();
3130
ModPage = new ModInfos();
3231
ModSourcePage = new ModSourceInfos();
32+
ModLoader.LoadFiles();
33+
Settings.LoadSettings();
3334
SettingsPage = new Settings();
3435
InitializeComponent();
3536
if (!Directory.Exists(ModLoader.ModPath))
@@ -38,7 +39,7 @@ public Main()
3839
Directory.CreateDirectory(ModLoader.ModSourcesPath);
3940

4041

41-
ModLoader.LoadFiles();
42+
4243
Viewer.Content = MainPage;
4344

4445

@@ -142,6 +143,12 @@ public void ChangeLanguage(int index)
142143
Application.Current.Resources.MergedDictionaries.Add(resDict);
143144
Main.Settings.Language = "English";
144145
break;
146+
case 2:
147+
resDict = Application.Current.Resources.MergedDictionaries.First(t => t.Source.OriginalString == @"Language/ru-ru.xaml");
148+
Application.Current.Resources.MergedDictionaries.Remove(resDict);
149+
Application.Current.Resources.MergedDictionaries.Add(resDict);
150+
Main.Settings.Language = "Русский";
151+
break;
145152
}
146153

147154
}

ModLoader.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ public static UndertaleGameObject AddObject(string name)
5353
}
5454
public static UndertaleGameObject GetObject(string name)
5555
{
56-
return Data.GameObjects.FirstOrDefault(t => t.Name.Content.IndexOf(name) != -1);
56+
return Data.GameObjects.FirstOrDefault(t => t.Name.Content == name);
57+
}
58+
public static UndertaleSprite GetSprite(string name)
59+
{
60+
return Data.Sprites.FirstOrDefault(t => t.Name.Content == name);
5761
}
5862
public static void SetObject(string name, UndertaleGameObject o)
5963
{
@@ -91,6 +95,11 @@ public static List<string> GetTable(string name)
9195
var ret = Regex.Match(text, "return (\\[.*\\])").Groups[1].Value;
9296
return JsonConvert.DeserializeObject<List<string>>(ret);
9397
}
98+
public static UndertaleCode GetCode(string name)
99+
{
100+
var code = Data.Code.First(t => t.Name.Content == name);
101+
return code;
102+
}
94103
public static string GetDecompiledCode(string name)
95104
{
96105
var func = Data.Code.First(t => t.Name.Content.IndexOf(name) != -1);
@@ -110,6 +119,23 @@ public static void SetDecompiledCode(string Code, string name)
110119
var code = Data.Code.First(t => t.Name.Content.IndexOf(name) != -1);
111120
code.ReplaceGML(Code, Data);
112121
}
122+
public static void InsertDecompiledCode(string Code, string name, int pos)
123+
{
124+
var code = GetDecompiledCode(name).Split("\n").ToList();
125+
code.Insert(pos, Code);
126+
SetDecompiledCode(string.Join("\n", code), name);
127+
}
128+
public static void ReplaceDecompiledCode(string Code, string name, int pos)
129+
{
130+
var code = GetDecompiledCode(name).Split("\n").ToList();
131+
code[pos] = Code;
132+
SetDecompiledCode(string.Join("\n", code), name);
133+
}
134+
public static void SetDisassemblyCode(string Code, string name)
135+
{
136+
var code = Data.Code.First(t => t.Name.Content.IndexOf(name) != -1);
137+
code.ReplaceGML(Code, Data);
138+
}
113139
public static void SetTable(List<string> table, string name)
114140
{
115141
var ret = JsonConvert.SerializeObject(table).Replace("\n", "");
@@ -180,6 +206,7 @@ public static void LoadFiles()
180206
var type = assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(Mod))).ToList()[0];
181207
var mod = Activator.CreateInstance(type) as Mod;
182208
mod.LoadAssembly();
209+
mod.ModFiles = f;
183210
f.instance = mod;
184211
var old = mods.FirstOrDefault(t => t.Name == f.Name);
185212
if (old != null) f.isEnabled = old.isEnabled;
@@ -205,7 +232,7 @@ public static void PatchMods()
205232
MessageBox.Show(Application.Current.FindResource("ModLostWarning").ToString() + " : " + mod.Name);
206233
continue;
207234
}
208-
Main.Settings.EnableMods.Add(mod.instance.Name);
235+
Main.Settings.EnableMods.Add(mod.Name);
209236
var version = DataLoader.GetVersion();
210237
var reg = new Regex("0([0-9])");
211238
version = reg.Replace(version, "$1");
@@ -234,18 +261,16 @@ public static void LoadWeapon(Type type)
234261
Weapons.Insert(Weapons.IndexOf("SWORDS - BLADES;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;") + 1, strs.Item1);
235262
WeaponDescriptions.Insert(WeaponDescriptions.IndexOf(";;SWORDS;;;;;;SWORDS;SWORDS;;;;") + 1, weapon.Name + ";" + string.Join(";", weapon.NameList.Values));
236263
WeaponDescriptions.Insert(WeaponDescriptions.IndexOf(";weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;weapon_desc;") + 1,
237-
weapon.Name + ";" + string.Join(";", weapon.Description.Values));
264+
weapon.Name + ";" + string.Join(";", weapon.WeaponDescriptions.Values));
238265
WeaponDescriptions.Insert(WeaponDescriptions.IndexOf(";weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;weapon_pronoun;") + 1,
239266
weapon.Name + ";He;;;It;She;She;She;She;He;;;;");
240267
}
241268
public static async void PatchFile()
242269
{
243-
if (patched) await DataLoader.LoadFile(DataLoader.DataPath);
244270
PatchInnerFile();
245271
PatchMods();
246272
SetTable(Weapons, "gml_GlobalScript_table_weapons");
247273
SetTable(WeaponDescriptions, "gml_GlobalScript_table_weapons_text");
248-
patched = true;
249274
LoadFiles();
250275
}
251276
internal static void PatchInnerFile()

ModShardLauncher.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<None Remove="Resources\enable_button_down.png" />
2727
<None Remove="Resources\enable_button_over.png" />
2828
<None Remove="Resources\icon.gif" />
29+
<None Remove="Resources\icon_default.png" />
2930
<None Remove="Resources\leftPanel.png" />
3031
<None Remove="Resources\menu.png" />
3132
<None Remove="Resources\menu_down.png" />
@@ -71,6 +72,7 @@
7172
</ItemGroup>
7273

7374
<ItemGroup>
75+
<Resource Include="Resources\icon_default.png" />
7476
<Resource Include="Resources\settings_button_over.png" />
7577
</ItemGroup>
7678

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
if (global.gamespeed == global.default_gamespeed)
2+
{
3+
global.gamespeed = global.accelerated_gamespeed
4+
scr_actionsLogUpdate("F1: AccelerateSpeed")
5+
}
6+
else
7+
{
8+
global.gamespeed = global.default_gamespeed
9+
scr_actionsLogUpdate("F1: DefaultSpeed")
10+
}
11+
game_set_speed(global.gamespeed, gamespeed_fps)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ini_open("speedshard.ini")
2+
global.defaut_gamespeed = ini_read_real("globals", "default_gamespeed", 40)
3+
global.accelerated_gamespeed = ini_read_real("globals", "accelerated_gamespeed", 40)
4+
global.reputation_modifier = ini_read_real("globals", "reputation_modifier", 1)
5+
global.water_container_modifier = ini_read_real("globals", "water_container_modifier", 1)
6+
global.campbed_despawn_days = ini_read_real("globals", "campbed_despawn_days", 1)
7+
global.hostile_spawnrate_by_level_modifier = ini_read_real("globals", "hostile_spawnrate_by_level_modifier", 31)
8+
global.neutral_spawnrate_by_level_modifier = ini_read_real("globals", "neutral_spawnrate_by_level_modifier", 31)
9+
global.tiles_by_turn = ini_read_real("globals", "tiles_by_turn", 1)
10+
global.xp_by_level_modifier = ini_read_real("globals", "xp_by_level_modifier", 500)
11+
global.max_level = ini_read_real("globals", "max_level", 30)
12+
global.interval_level_extra_sp = ini_read_real("globals", "interval_level_extra_sp", 31)
13+
global.interval_level_extra_ap = ini_read_real("globals", "interval_level_extra_ap", 31)
14+
global.dungeon_reset_modifier = ini_read_real("globals", "dungeon_reset_modifier", 6)
15+
global.extra_sp_ap_at_creation = ini_read_real("globals", "extra_sp_ap_at_creation", 0)
16+
global.quicksave_enable = ini_read_real("globals", "quicksave_enable", 0)
17+
global.campbed_not_destroyed = ini_read_real("globals", "campbed_not_destroyed", 0)
18+
global.big_backpack = ini_read_real("globals", "big_backpack", 0)
19+
global.secret_room_chance = ini_read_real("globals", "secret_room_chance", 5)
20+
global.contract_money_modifier = ini_read_real("globals", "contract_money_modifier", 1)
21+
global.number_room_max = ini_read_real("globals", "number_room_max", 15)
22+
global.number_room_min = ini_read_real("globals", "number_room_min", 5)
23+
global.number_chest_max = ini_read_real("globals", "number_chest_max", 7)
24+
global.number_chest_min = ini_read_real("globals", "number_chest_min", 5)
25+
global.extra_slotbar = ini_read_real("globals", "extra_slotbar", 0)
26+
global.gold_multiplier = ini_read_real("globals", "gold_multiplier", 1)
27+
ini_close()
28+
global.gamespeed = global.defaut_gamespeed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
if global.quicksave_enable
2+
{
3+
scr_smoothSaveSleep()
4+
with (o_sleepController)
5+
{
6+
sleepType = 3
7+
sleepHours = 0
8+
}
9+
}

0 commit comments

Comments
 (0)