Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Fixed crash when replacing event scripts, slight refactor #1174

Merged
merged 2 commits into from
Feb 12, 2023

Conversation

TheAwoo
Copy link

@TheAwoo TheAwoo commented Feb 12, 2023

Description

When trying to replace an event script in a non-undertale title, one is met with an exception:

UndertaleModCli replace data.orig
-c gml_Object_obj_light_controller_Draw_0=./Mods/gml_Object_obj_light_controller_Draw_0.gml
-v -o data.win

System.InvalidCastException: Unable to cast object of type 'UndertaleModLib.Models.EventType' to type 'System.Int32'.
   at UndertaleModCli.Program.ImportCode(String codeName, String gmlCode, Boolean isGML, Boolean doParse, Boolean destroyASM, Boolean checkDecompiler, Boolean throwOnError) in /mnt/nex/projekty/undertale-mod-tool/UndertaleModCli/Program.UMTLibInherited.cs:line 921
   at UndertaleModCli.Program.ImportGMLString(String codeName, String gmlCode, Boolean doParse, Boolean checkDecompiler) in /mnt/nex/projekty/undertale-mod-tool/UndertaleModCli/Program.UMTLibInherited.cs:line 607
   at UndertaleModCli.Program.ReplaceCodeEntryWithFile(String codeEntry, FileInfo fileToReplace) in /mnt/nex/projekty/undertale-mod-tool/UndertaleModCli/Program.cs:line 664
   at UndertaleModCli.Program.Replace(ReplaceOptions options) in /mnt/nex/projekty/undertale-mod-tool/UndertaleModCli/Program.cs:line 416
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)

The following commits fix the issue and introduce enhancements:

  • Plain cast to int has been substituted to a Convert.ToInt32 call which does not fault,
  • Removed needless reflection (which would also fault on call) when trying to obtain a particular value from an enum.

Caveats

Hopefully none, the changes introduced shouldn't change any behaviour, just the value handling.

Notes

Game used: ZERO Sievert
Tested on a Linux box:

awoo@~ $ uname -a
Linux [redacted] 6.1.9-zen1-2-zen #1 ZEN SMP PREEMPT_DYNAMIC Sat, 04 Feb 2023 23:45:10 +0000 x86_64 GNU/Linux

@Grossley Grossley merged commit 88ba165 into UnderminersTeam:master Feb 12, 2023
@TheAwoo TheAwoo deleted the fix/cli-enums branch February 12, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants