diff --git a/CheatEnabler/CheatEnabler.csproj b/CheatEnabler/CheatEnabler.csproj index 4d58354..44c9339 100644 --- a/CheatEnabler/CheatEnabler.csproj +++ b/CheatEnabler/CheatEnabler.csproj @@ -20,10 +20,6 @@ - - - - ..\AssemblyFromGame\Assembly-CSharp.dll @@ -33,11 +29,16 @@ + + + + - - + + diff --git a/DSP_Mods.sln b/DSP_Mods.sln index ed98e40..d6076aa 100644 --- a/DSP_Mods.sln +++ b/DSP_Mods.sln @@ -19,19 +19,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OverclockEverything", "Over EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MechaDronesTweaks", "MechaDronesTweaks\MechaDronesTweaks.csproj", "{15B8BC2E-93E0-4454-8F8F-BF1FA8DC90F4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabOpt", "LabOpt\LabOpt.csproj", "{DD76B77C-68D8-4A4C-B98E-CBEECEDC49FB}" - ProjectSection(ProjectDependencies) = postProject - {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F} = {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabOptPreloader", "LabOptPreloader\LabOptPreloader.csproj", "{F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DustbinPreloader", "DustbinPreloader\DustbinPreloader.csproj", "{B8EB3D8D-5613-42F0-9040-EAA11A38C6AC}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoolOpt", "PoolOpt\PoolOpt.csproj", "{8BE61246-2C9D-4088-AA33-5AFF22C5046E}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UserCloak", "UserCloak\UserCloak.csproj", "{096D2E4B-D1CE-424D-9954-C36A23E9E279}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaScriptEngine", "LuaScriptEngine\LuaScriptEngine.csproj", "{E9375F0E-26DC-4CEC-80DC-9C48F23340BC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -70,14 +65,6 @@ Global {15B8BC2E-93E0-4454-8F8F-BF1FA8DC90F4}.Debug|Any CPU.Build.0 = Debug|Any CPU {15B8BC2E-93E0-4454-8F8F-BF1FA8DC90F4}.Release|Any CPU.ActiveCfg = Release|Any CPU {15B8BC2E-93E0-4454-8F8F-BF1FA8DC90F4}.Release|Any CPU.Build.0 = Release|Any CPU - {DD76B77C-68D8-4A4C-B98E-CBEECEDC49FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DD76B77C-68D8-4A4C-B98E-CBEECEDC49FB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DD76B77C-68D8-4A4C-B98E-CBEECEDC49FB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DD76B77C-68D8-4A4C-B98E-CBEECEDC49FB}.Release|Any CPU.Build.0 = Release|Any CPU - {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F2D5EBE8-7D9D-4572-9A3E-4DD1114FD99F}.Release|Any CPU.Build.0 = Release|Any CPU {B8EB3D8D-5613-42F0-9040-EAA11A38C6AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B8EB3D8D-5613-42F0-9040-EAA11A38C6AC}.Debug|Any CPU.Build.0 = Debug|Any CPU {B8EB3D8D-5613-42F0-9040-EAA11A38C6AC}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -90,5 +77,9 @@ Global {096D2E4B-D1CE-424D-9954-C36A23E9E279}.Debug|Any CPU.Build.0 = Debug|Any CPU {096D2E4B-D1CE-424D-9954-C36A23E9E279}.Release|Any CPU.ActiveCfg = Release|Any CPU {096D2E4B-D1CE-424D-9954-C36A23E9E279}.Release|Any CPU.Build.0 = Release|Any CPU + {E9375F0E-26DC-4CEC-80DC-9C48F23340BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9375F0E-26DC-4CEC-80DC-9C48F23340BC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9375F0E-26DC-4CEC-80DC-9C48F23340BC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9375F0E-26DC-4CEC-80DC-9C48F23340BC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Dustbin/Dustbin.csproj b/Dustbin/Dustbin.csproj index 442f55f..5fdd80f 100644 --- a/Dustbin/Dustbin.csproj +++ b/Dustbin/Dustbin.csproj @@ -16,11 +16,21 @@ - + - + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + + + @@ -29,13 +39,8 @@ - - - GameAssembly\Assembly-CSharp.dll - - - - + diff --git a/DustbinPreloader/DustbinPreloader.csproj b/DustbinPreloader/DustbinPreloader.csproj index fe8bc71..649fbaf 100644 --- a/DustbinPreloader/DustbinPreloader.csproj +++ b/DustbinPreloader/DustbinPreloader.csproj @@ -14,8 +14,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + diff --git a/HideTips/HideTips.csproj b/HideTips/HideTips.csproj index aba9158..8f2b1e1 100644 --- a/HideTips/HideTips.csproj +++ b/HideTips/HideTips.csproj @@ -15,8 +15,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -24,6 +33,6 @@ - + diff --git a/LabOpt/LabOpt.csproj b/LabOpt/LabOpt.csproj index 196ecb7..e9a22aa 100644 --- a/LabOpt/LabOpt.csproj +++ b/LabOpt/LabOpt.csproj @@ -15,8 +15,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -24,6 +33,6 @@ - + diff --git a/LabOptPreloader/LabOptPreloader.csproj b/LabOptPreloader/LabOptPreloader.csproj index f3969ef..b33bce6 100644 --- a/LabOptPreloader/LabOptPreloader.csproj +++ b/LabOptPreloader/LabOptPreloader.csproj @@ -14,8 +14,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + diff --git a/LogisticMiner/LogisticMiner.csproj b/LogisticMiner/LogisticMiner.csproj index 2397e84..13e64b1 100644 --- a/LogisticMiner/LogisticMiner.csproj +++ b/LogisticMiner/LogisticMiner.csproj @@ -16,7 +16,7 @@ - + diff --git a/LuaScriptEngine/CHANGELOG.md b/LuaScriptEngine/CHANGELOG.md new file mode 100644 index 0000000..83aadba --- /dev/null +++ b/LuaScriptEngine/CHANGELOG.md @@ -0,0 +1,7 @@ +## Changlog +* 1.0.0 + + Initial release + +## 更新日志 +* 1.0.0 + + 初始版本 diff --git a/LuaScriptEngine/LuaScriptEngine.cs b/LuaScriptEngine/LuaScriptEngine.cs new file mode 100644 index 0000000..50b3aee --- /dev/null +++ b/LuaScriptEngine/LuaScriptEngine.cs @@ -0,0 +1,223 @@ +using System; +using System.Collections.Generic; +using System.Text; +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; +using NLua; + +namespace LuaScriptEngine; + +[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] +public class LuaScriptEngine : BaseUnityPlugin +{ + private class Timer(LuaFunction func, long startInterval, long repeatInterval = 0L) + { + public bool Check(long gameTick) + { + if (gameTick < _nextTick) return false; + try + { + _func.Call(); + } + catch (Exception e) + { + Logger.LogError($"Error in Lua script: {e}"); + } + + if (_repeatInterval <= 0L) return true; + _nextTick += _repeatInterval; + if (_nextTick < gameTick) + _nextTick = gameTick + 1; + return false; + } + + public bool Reset(long gameTick) + { + if (_repeatInterval <= 0L) return true; + _nextTick = gameTick + _repeatInterval; + return false; + } + + private readonly LuaFunction _func = func; + private readonly long _repeatInterval = repeatInterval; + private long _nextTick = GameMain.gameTick + startInterval; + } + public new static readonly ManualLogSource Logger = + BepInEx.Logging.Logger.CreateLogSource(PluginInfo.PLUGIN_NAME); + + private Harmony _harmony; + + private static readonly Lua LuaState = new(); + private static readonly List PostDataLoadedFuncs = []; + private static readonly List PreUpdateFuncs = []; + private static readonly List PostUpdateFuncs = []; + private static readonly List PreGameBeginFuncs = []; + private static readonly List PostGameBeginFuncs = []; + private static readonly List PreGameEndFuncs = []; + private static readonly List PostGameEndFuncs = []; + private static readonly HashSet Timers = []; + private static readonly List TimersToRemove = []; + + private void Awake() + { + LuaState.State.Encoding = Encoding.UTF8; + LuaState.LoadCLRPackage(); + LuaState.DoString("import('Assembly-CSharp')"); + LuaState["register_callback"] = (string tp, bool pre, LuaFunction action) => + { + switch (tp) + { + case "data_loaded": + PostDataLoadedFuncs.Add(action); + break; + case "update": + (pre ? PreUpdateFuncs : PostUpdateFuncs).Add(action); + break; + case "game_begin": + (pre ? PreGameBeginFuncs : PostGameBeginFuncs).Add(action); + break; + case "game_end": + (pre ? PreGameEndFuncs : PostGameEndFuncs).Add(action); + break; + } + }; + LuaState["add_timer"] = Timer(LuaFunction func, long firstInterval, long repeatInterval) => + { + var timer = new Timer(func, firstInterval, repeatInterval); + Timers.Add(timer); + return timer; + }; + LuaState["remove_timer"] = void (Timer timer) => + { + Timers.Remove(timer); + }; + var assemblyPath = System.IO.Path.Combine( + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)!, + "scripts" + ); + LuaState.DoString($"package.path = '{assemblyPath.Replace('\\', '/')}/?.lua'"); + + foreach (var file in System.IO.Directory.GetFiles(assemblyPath, "*.lua")) + { + Logger.LogInfo($"Loading Lua script: {file}"); + LuaState.DoFile(file); + } + _harmony = Harmony.CreateAndPatchAll(typeof(Patches)); + } + + private void OnDestroy() + { + Timers.Clear(); + PreUpdateFuncs.Clear(); + PostUpdateFuncs.Clear(); + PreGameBeginFuncs.Clear(); + PostGameBeginFuncs.Clear(); + PreGameEndFuncs.Clear(); + PostGameEndFuncs.Clear(); + + _harmony?.UnpatchSelf(); + LuaState.Dispose(); + } + + private static class Patches + { + private static void LoopCall(List funcs) + { + foreach (var func in funcs) + { + try + { + func.Call(); + } + catch (Exception e) + { + Logger.LogError($"Error in Lua script: {e}"); + } + } + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(VFPreload), nameof(VFPreload.InvokeOnLoadWorkEnded))] + private static void VFPreload_InvokeOnLoadWorkEnded_Postfix() + { + LoopCall(PostDataLoadedFuncs); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.FixedUpdate))] + private static void GameMain_FixedUpdate_Prefix() + { + if (Timers.Count > 0) + { + var gameTick = GameMain.gameTick; + foreach (var timer in Timers) + { + if (timer == null || !timer.Check(gameTick)) continue; + TimersToRemove.Add(timer); + } + if (TimersToRemove.Count > 0) + { + foreach (var timer in TimersToRemove) + { + Timers.Remove(timer); + } + TimersToRemove.Clear(); + } + } + + LoopCall(PreUpdateFuncs); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.FixedUpdate))] + private static void GameMain_FixedUpdate_Postfix() + { + LoopCall(PostUpdateFuncs); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))] + private static void GameMain_Begin_Prefix() + { + var tick = GameMain.gameTick; + foreach (var timer in Timers) + { + if (timer.Reset(tick)) + { + TimersToRemove.Add(timer); + } + } + if (TimersToRemove.Count > 0) + { + foreach (var timer in TimersToRemove) + { + Timers.Remove(timer); + } + TimersToRemove.Clear(); + } + LoopCall(PreGameBeginFuncs); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.Begin))] + private static void GameMain_Begin_Postfix() + { + LoopCall(PostGameBeginFuncs); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.End))] + private static void GameMain_End_Prefix() + { + LoopCall(PreGameEndFuncs); + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(GameMain), nameof(GameMain.End))] + private static void GameMain_End_Postfix() + { + LoopCall(PostGameEndFuncs); + } + } +} \ No newline at end of file diff --git a/LuaScriptEngine/LuaScriptEngine.csproj b/LuaScriptEngine/LuaScriptEngine.csproj new file mode 100644 index 0000000..b495cf7 --- /dev/null +++ b/LuaScriptEngine/LuaScriptEngine.csproj @@ -0,0 +1,40 @@ + + + + + net472 + LuaScriptEngine + org.soardev.luascriptengine + DSP MOD - LuaScriptEngine + 1.0.0 + true + latest + https://nuget.bepinex.dev/v3/index.json + + + + + + + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + + + + + + + + + + + diff --git a/LuaScriptEngine/README.md b/LuaScriptEngine/README.md new file mode 100644 index 0000000..a7a1119 --- /dev/null +++ b/LuaScriptEngine/README.md @@ -0,0 +1,8 @@ +# LuaScriptEngine + +#### Write mod functions in lua scripts +#### 用lua脚本编写mod功能 + +## Usage + +## 使用说明 diff --git a/LuaScriptEngine/package/icon.png b/LuaScriptEngine/package/icon.png new file mode 100644 index 0000000..84fa77d Binary files /dev/null and b/LuaScriptEngine/package/icon.png differ diff --git a/LuaScriptEngine/package/manifest.json b/LuaScriptEngine/package/manifest.json new file mode 100644 index 0000000..27ea4d4 --- /dev/null +++ b/LuaScriptEngine/package/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "LuaScriptEngine", + "version_number": "1.0.0", + "website_url": "https://github.com/soarqin/DSP_Mods/tree/master/LuaScriptEngine", + "description": "Write mod functions in lua scripts / 用lua脚本编写mod功能", + "dependencies": [ + "xiaoye97-BepInEx-5.4.17" + ] +} diff --git a/MechaDronesTweaks/MechaDronesTweaks.csproj b/MechaDronesTweaks/MechaDronesTweaks.csproj index 461ae7f..172d4fa 100644 --- a/MechaDronesTweaks/MechaDronesTweaks.csproj +++ b/MechaDronesTweaks/MechaDronesTweaks.csproj @@ -15,8 +15,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -24,6 +33,6 @@ - + diff --git a/OverclockEverything/OverclockEverything.csproj b/OverclockEverything/OverclockEverything.csproj index 9899d31..bda2d83 100644 --- a/OverclockEverything/OverclockEverything.csproj +++ b/OverclockEverything/OverclockEverything.csproj @@ -16,9 +16,18 @@ - + - + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -26,6 +35,6 @@ - + diff --git a/PoolOpt/PoolOpt.csproj b/PoolOpt/PoolOpt.csproj index 03e8a69..3b41e75 100644 --- a/PoolOpt/PoolOpt.csproj +++ b/PoolOpt/PoolOpt.csproj @@ -15,8 +15,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -24,6 +33,6 @@ - + diff --git a/README.md b/README.md index 775d90a..b0895b4 100644 --- a/README.md +++ b/README.md @@ -9,35 +9,15 @@ Add various cheat functions while disabling abnormal determinants Moved [to another repo](https://github.com/soarqin/DSP_Mods_TO/tree/master/CompressSave) -## [LogisticMiner](LogisticMiner) - -Logistic Storages can mine all ores/water on current planet -物流塔可以采集当前星球的全部矿产(以及水) - -## [HideTips](HideTips) - -Hide/Disable various tutorial tips/messages -隐藏/屏蔽各种引导提示/消息 - ## [Dustbin](Dustbin) Can turn Storages and Tanks into Dustbin(Destroy incoming items) 储物仓和储液罐可以转变为垃圾桶(销毁送进的物品) -## [OverclockEverything](OverclockEverything) +## [HideTips](HideTips) -Boost nearly all structures -加速几乎所有建筑功能 - -## [UniverseGenTweaks](UniverseGenTweaks) - -Universe Generator Tweak -宇宙生成参数调节 - -## [MechaDronesTweaks](MechaDronesTweaks) - -Some tweaks for mecha drones and build functions(Successor to FastDrones MOD) -机甲建设机和建设功能调整(FastDrones MOD的后继者) +Hide/Disable various tutorial tips/messages +隐藏/屏蔽各种引导提示/消息 ## [LabOpt](LabOpt) @@ -46,11 +26,35 @@ Marked as obsoleted temporarily, needs more investigation about LabComponent's m 优化研究站性能 暂时标识为过期,需要更多关于LabComponent机制的研究 +## [LogisticMiner](LogisticMiner) + +Logistic Storages can mine all ores/water on current planet +物流塔可以采集当前星球的全部矿产(以及水) + +## [LuaScriptEngine](LuaScriptEngine) +Write mod functions in lua scripts +用lua脚本编写mod功能 + +## [MechaDronesTweaks](MechaDronesTweaks) + +Some tweaks for mecha drones and build functions(Successor to FastDrones MOD) +机甲建设机和建设功能调整(FastDrones MOD的后继者) + +## [OverclockEverything](OverclockEverything) + +Boost nearly all structures +加速几乎所有建筑功能 + ## [PoolOpt](PoolOpt) Optimize memory pools on loading gamesaves 加载游戏存档时优化内存池的使用 +## [UniverseGenTweaks](UniverseGenTweaks) + +Universe Generator Tweak +宇宙生成参数调节 + ## [UserCloak](UserCloak) Cloak(Fake) user account info diff --git a/UXAssist/UXAssist.csproj b/UXAssist/UXAssist.csproj index 38565e9..251816c 100644 --- a/UXAssist/UXAssist.csproj +++ b/UXAssist/UXAssist.csproj @@ -61,7 +61,8 @@ - - + + diff --git a/UniverseGenTweaks/UniverseGenTweaks.csproj b/UniverseGenTweaks/UniverseGenTweaks.csproj index cce291a..b907c8c 100644 --- a/UniverseGenTweaks/UniverseGenTweaks.csproj +++ b/UniverseGenTweaks/UniverseGenTweaks.csproj @@ -20,10 +20,6 @@ - - - - ..\AssemblyFromGame\Assembly-CSharp.dll @@ -33,11 +29,15 @@ + + + + - + diff --git a/UserCloak/UserCloak.csproj b/UserCloak/UserCloak.csproj index ef948ce..209b80e 100644 --- a/UserCloak/UserCloak.csproj +++ b/UserCloak/UserCloak.csproj @@ -15,8 +15,17 @@ - - + + + + + + + ..\AssemblyFromGame\Assembly-CSharp.dll + + + ..\AssemblyFromGame\UnityEngine.UI.dll + @@ -24,6 +33,6 @@ - +