Skip to content

Make integration of custom opcodes easier #74

Closed

Description

@x87

CLEO and its successors add many new custom opcodes (see #71 for example). Currently in order to compile the script you have to alter the original *SCM.INI and add new definitions manually. This is error-prone and unfriendly to new users. During Sanny updates those changes could be lost so you need to update the INI again.

Need to come up with a flexible solution that make Sanny aware of custom opcodes without (ideally) touching its files. This affects the compiler, the disassembler, and IDE (Opcode Search).

Activity

  1. added
    discussion
    on Sep 23, 2020
  2. MatiDragon-YT commented on Sep 23, 2020

    @MatiDragon-YT
    Member

    These are some of the solutions that I would give you if I could

    1. In the same way that modes.xml works, you could do something similar to load new opcodes.txt and SASCM.INI with other names, such as opcodeOfCLEO.txt or newOpc.txt from the mode folder.
      • Personally, I don't like XML because of its novice-unfriendly syntax.
    2. Write two new files e.g. XXX and ZZZ, for custom opcodes if they don't exist, but incase that these files if they exist, only read files XXX and ZZZ existing.
    3. Could add a tool with an interface similar to "User Tools" and thus make it a little more pleasant.
      image of "User Tools"
  3. OrionSR commented on Sep 24, 2020

    @OrionSR

    Oh wow! Good idea. And is an appropriate issue for the question I had in mind.

    Are Restored Opcodes currently supported by Sanny?

    Closer to the point, changes to the SCM.ini definitions would influence all of the "command" files, which I've been grouping to include:

    • classes.db
    • keywords.txt
    • opcode.txt (examples.txt)
    • scm.ini (opcodes.ini)
    • templates.txt
      (I've been considering renaming some files to be more consistent with the XML definitions, and between all games.)
      See: Mobile Modes for GTA3 and Vice City #6 - A little feedback would be appreciated.

    For keywords in particular, but also CustomVariables.ini, it would nice to be able to have secondary files with duplicate entries that worked in the compiler, but consistently disassembled to the primary example. #20

    Thinking ahead to enumerations; I have found it difficult to maintain a long list in constants.txt built around sheets for each group. I would much prefer to manage these groups as individual files. #40

    I agree with @MatiDragon-YT 's assessment of the awkwardness of managing the XML mode files. I have given serious consideration to creating a Modes Manager as a learn-to-GUI project with my son, but that's not going to happen any time soon. Neither of us has done this before and, well... he agreed but has shown no interest in starting. I think a better strategy is to allow the user, or ToolPacks, to update files in a manner that doesn't need to modify the XML file.

    <opcodes>@sb:\data\vc\opcodes.ini</opcodes>
    <opcodes>@sb:\data\vc\plugins\*.opcodes.ini</opcodes>
    <enums>@sb:\data\vc\enum\*.enum.txt</enums>
    

    Goal: To update the edit mode the user would only need to place a file with the appropriate naming convention into the proper folder.

  4. MatiDragon-YT commented on Sep 26, 2020

    @MatiDragon-YT
    Member

    Well.. it would not be bad to start like this.
    in the future, maybe I can generate a simple console program that does that job, that of installing new extensions to XML.

  5. x87 commented on Sep 26, 2020

    @x87
    CollaboratorAuthor

    A GUI tool that allows to add/remove new entries to modes.xml by just dropping a new file onto the tool window and/or unticking a checkbox to temporarily exclude the file would be really handy.

    I agree XML is not the most human-friendly format, yet it's much easier comparing to awkward custom syntax of the classes.db.

  6. OrionSR commented on Sep 26, 2020

    @OrionSR

    Before I forget again... I was not able to find an error case for the same keyword text being assigned to different opcode numbers.

    I think an Edit Mode Manager tool is an awesome idea worthy of it's own discussion, but doesn't solve the stated goal of:

    Need to come up with a flexible solution that make Sanny aware of custom opcodes without (ideally) touching its files.

    Suggestion for a Mode Manager progression:

    • V1 - A tool for switching the current modes.xml file. User Tools appear to be limited to 9 entries. I'm already using 5 just for this purpose. This version would not need to modify xml files.
    • V2 - Ability to copy, paste, disable. delete and sort entire mode definitions. For example. copy a PS2 edit mode from a custom root mode to Sanny's default root mode. Or, duplicate a standard edit mode and update the the title and IDs to support different game paths needed for multiple installations of the same game.
      -V3 - A full featured Mode Editor. I figure that mode editing will always be an advanced skill. Ideally, a novice would never need to use the editing features.
  7. x87 commented on Nov 8, 2020

    @x87
    CollaboratorAuthor

    While working on adding CLEO library and its plugins definitions in different edit modes I realized that providing all possible opcodes by default could be misleading and unintentionally make a scripter assume they use an instruction that is available with vanilla game but in fact this is something that requires an extra piece of software. While it's obvious in context of {$CLEO} scripts that you might want to use CLEO opcodes , it's not like that in main.scm or when you use opcodes introduced with some exotic plugins. You should be aware of such dependency on third-party software and explicitly signal Sanny Builder you want to use it.

    Hence comes something new in edit modes - the extensions.

    What is an extension? It's a named set of files that define new instructions and related language constructs (keywords, classes).
    Each edit mode could have multiple extensions but it must have at least one which would be used with any script. In other words this is what edit modes currently define using <opcodes>, <keywords> , <examples>, etc. So, say, GTA SA v1.0 mode could now look like:

    <mode id="sa" title="GTA SA v1.0" game="sa" type="default">
            <data>@sb:\data\sa\</data>
    
            <extension name="default">
                <opcodes>@sb:\data\sa\SASCM.ini</opcodes>
                <classes>@sb:\data\sa\classes.db</classes>
                <enums>@sb:\data\sa\enums.txt</enums>
                <keywords>@sb:\data\sa\keywords.txt</keywords>
                <constants>@sb:\data\sa\constants.txt</constants>
                <templates>@sb:\data\sa\templates.txt</templates>
                <examples>@sb:\data\sa\opcodes.txt</examples>
            </extension>
            
            <variables>@sb:\data\sa\CustomVariables.ini</variables>
            <labels>@sb:\data\sa\CustomLabels.ini</labels>
            <arrays>@sb:\data\sa\CustomArrays.ini</arrays>
            <missions>@sb:\data\sa\missions.txt</missions>
            <text format="sa">@game:\text\american.gxt</text>
            <ide base="@game:\">@game:\data\default.dat</ide>
            <ide>@game:\data\maps\veh_mods\veh_mods.ide</ide>
        </mode>

    In addition to the default extension the mode could define custom extensions, e.g. one for standard CLEO opcodes:

    <mode id="sa" title="GTA SA v1.0" game="sa" type="default">
            <data>@sb:\data\sa\</data>
    
            <extension name="default">
                <opcodes>@sb:\data\sa\SASCM.ini</opcodes>
                <classes>@sb:\data\sa\classes.db</classes>
                <enums>@sb:\data\sa\enums.txt</enums>
                <keywords>@sb:\data\sa\keywords.txt</keywords>
                <constants>@sb:\data\sa\constants.txt</constants>
                <templates>@sb:\data\sa\templates.txt</templates>
                <examples>@sb:\data\sa\opcodes.txt</examples>
            </extension>
    
            <extension name="cleo">
                <opcodes>@sb:\data\sa\cleo4.ini</opcodes>
                <examples>@sb:\data\sa\cleo4.opcodes.txt</examples>
            </extension>
    
            <variables>@sb:\data\sa\CustomVariables.ini</variables>
            <labels>@sb:\data\sa\CustomLabels.ini</labels>
            <arrays>@sb:\data\sa\CustomArrays.ini</arrays>
            <missions>@sb:\data\sa\missions.txt</missions>
            <text format="sa">@game:\text\american.gxt</text>
            <ide base="@game:\">@game:\data\default.dat</ide>
            <ide>@game:\data\maps\veh_mods\veh_mods.ide</ide>
        </mode>

    or any other CLEO plugin:

    <mode id="sa" title="GTA SA v1.0" game="sa" type="default">
            <data>@sb:\data\sa\</data>
    
            <extension name="default">
                <opcodes>@sb:\data\sa\SASCM.ini</opcodes>
                <classes>@sb:\data\sa\classes.db</classes>
                <enums>@sb:\data\sa\enums.txt</enums>
                <keywords>@sb:\data\sa\keywords.txt</keywords>
                <constants>@sb:\data\sa\constants.txt</constants>
                <templates>@sb:\data\sa\templates.txt</templates>
                <examples>@sb:\data\sa\opcodes.txt</examples>
            </extension>
    
            <extension name="cleo">
                <opcodes>@sb:\data\sa\cleo4.ini</opcodes>
                <examples>@sb:\data\sa\cleo4.opcodes.txt</examples>
            </extension>
    
            <extension name="cleo+">
                <opcodes>@sb:\data\sa\cleo+.ini</opcodes>
                <examples>@sb:\data\sa\cleo+.opcodes.txt</examples>
            </extension>
    
            <variables>@sb:\data\sa\CustomVariables.ini</variables>
            <labels>@sb:\data\sa\CustomLabels.ini</labels>
            <arrays>@sb:\data\sa\CustomArrays.ini</arrays>
            <missions>@sb:\data\sa\missions.txt</missions>
            <text format="sa">@game:\text\american.gxt</text>
            <ide base="@game:\">@game:\data\default.dat</ide>
            <ide>@game:\data\maps\veh_mods\veh_mods.ide</ide>
        </mode>

    Now the interesting part. By default the IDE and compiler will only use the default extension. This is something that belong to the game opcodes and is always available for the given game. But if you want to use something extra you should add a new line on top of your script: {$use extension_name}. E.g.:

    {$use cleo+}
    {$use newOpcodes}
    

    Now both the IDE and compiler know your intention and will provide necessary support (autocomplete, highlighting, compiling). The disassembler will be smart enough to restore list of extensions based on which opcodes are actually used in the file.

    Using {$CLEO} directive implies {$use cleo} so no changes needed for existing scripts.

    The above is only necessary for the scripter. A compiled script will continue depend on the presence of CLEO plugins on user's machine so it's a responsibility of the script author to announce them. However in the future we could integrate some kind of dependency check in the CLEO itself, so it reject scripts if required plugins are missing, to avoid game crashes.

    Please let me know your thoughts on this feature.

  8. x87 commented on Nov 8, 2020

    @x87
    CollaboratorAuthor

    We could also agree on some implicit way of adding extensions, for example, have a subfolder inside edit mode directory named extensions where you create a new folder, say, cleo+ and add new files here:

    - Sanny Builder\
    -- data\
    --- sa\
    ---- extensions\
    ----- cleo+\
           |- opcodes.txt
           |- templates.txt
           |- keywords.txt
           |- opcodes.ini
    

    Sanny would automatically register a new extension as if it was defined explicitly in the modes.xml

  9. added
    priority:p1
    on Nov 8, 2020
  10. added this to the v3.7.0 milestone on Nov 8, 2020
  11. x87 commented on Nov 9, 2020

    @x87
    CollaboratorAuthor

    Also have to support conflicting extensions when one opcode number belongs to multiple extensions. Example: clipboard operations plugin & cleo+. The compiler should suggest all possible choices. The disassembler should somehow resolve the correct extension, possibly by analyzing the rest of opcodes used if they belong to the same extension.

  12. XMDS commented on Nov 13, 2020

    @XMDS
    Member

    @x87 The function of extended commands is really great.
    Just as I replied to you in the forum a few hours ago. I suggest to distinguish between the original OP and the non-original OP. Just as the default original OP uses {$CLEO}, the OP added by the standard CLEO library should be {$CLEO4} and {$CLEO2.0}. This is actually better. In fact, with regard to the OP search bar, whether there is a switch hotkey, switch the search bar of the corresponding type OP according to the extension of the OP.

    About the default "keywords",I noticed that this file is still messy. In fact, the original keyword "if jf wait." and so on appeared for abbreviation, but some OPs about CLEO4 and CLEO+ added in the 3.6.0 keywords are very messy. I mean actually maybe now we are not creating it for shorthand? Then it is necessary to distinguish between several types of OP keywords. As you said, we should create multiple files separately. I also noticed a problem:

    In OP.ini and OP.txt:
    0A96: $ActorStruct = ped $PLAYER_ACTOR struct
    0A97: $CarStruct = vehicle $MyCar struct
    0A98: $ObjectStruct = object 0@ struct

    Keyword file:
    0A96=get_ped_pointer
    0A97=get_vehicle_pointer
    0A98=get_object_pointer

    They are not the same. I think it should be standardized as one kind, just like GTA3sc:
    0A96: 0@ = get_ped_pointer 1@
    0A97: 0@ =get_vehicle_pointer 1@
    0A98: 0@ =get_object_pointer 1@

    I think the keyword is not necessarily a shorthand for OP, so it can be more standardized. Not only these three OPs, other OPs also have problems.

  13. 24 remaining items

  14. x87 commented on Dec 11, 2020

    @x87
    CollaboratorAuthor

    But are you planning on adding FYP's SAMPFUNCS extension to your defined sets of extension?

    I don't have such plans. The goal is to make the process of adding new extensions as easy as just copying a folder into Sanny Builder data directory. If anyone is interested to convert SAMPFUNCS into a proposed format they could do so and distribute as a prepared package.

    I don't want to bear a burden of maintaining all known opcode plugins.

  15. Aldrin-John-Olaer-Manalansan commented on Dec 11, 2020

    @Aldrin-John-Olaer-Manalansan

    If anyone is interested to convert SAMPFUNCS into a proposed format they could do so and distribute as a prepared package.

    I can create all definitions of SAMPFUNCS Extension for the upcoming Sanny Builder version.

    For the mean time, I will wait for the final proposed format.

  16. x87 commented on Dec 11, 2020

    @x87
    CollaboratorAuthor

    @Aldrin-John-Olaer-Manalansan Ok. Can you please open a new ticket for this request similar to #71?

  17. Aldrin-John-Olaer-Manalansan commented on Dec 11, 2020

    @Aldrin-John-Olaer-Manalansan

    @Aldrin-John-Olaer-Manalansan Ok. Can you please open a new ticket for this request similar to #71?

    Requested ticket #112

  18. x87 commented on Jan 12, 2021

    @x87
    CollaboratorAuthor

    Moving this ticket out of v3.7 as I need more time to come up with a solution to some cases.

    • handle opcode clashes during disassembling
    • split results of make_opcodes Split result of make_opcodes by extensions make_opcodes#3
    • make Language service to collect information on used extensions and update autocomplete (opcodes list, keywords, classes)
    • have an option in Opcode Search tool to search across all extensions/only currently used ones
    • provide a compiler prompt to add a particular extension to the file when it finds an unknown opcode
  19. removed this from the v3.7.0 milestone on Jan 12, 2021
  20. added
    priority:p2
    and removed
    priority:p1
    on Jan 12, 2021
  21. x87 commented on Jan 15, 2021

    @x87
    CollaboratorAuthor
  22. x87 commented on Jun 7, 2023

    @x87
    CollaboratorAuthor

    I'd like to push this idea forward and start off of a conservative approach. Given a number of challenges we could limit the proposal to the following:

    1. allow multiple <opcodes> definitions.
    <opcodes>@sb:\data\vc\opcodes.ini</opcodes>
    <opcodes>@sb:\data\vc\plugins\*.opcodes.ini</opcodes> // not sure about wildcard support
    
    • Each file overwrites previous definitions in case of id clashes. To resolve the clash differently, reorder the <opcodes>.
    1. allow self-declarative mode folders. Instead of defining each mode in modes.xml, a user could create a new folder under SB\data, place a file called mode.xml (same format as <mode> in modes.xml), and select it from SB's list of modes.
    • Each mode could still extend an existing mode with <extends>. In addition to the mode id, an argument could be a path to mode.xml of the mode to extend (i.e. extends="../sa/mode.xml")
    • Users can delete modes they are not interested in (another solution to Edit Mode list customisation #184), either by deleting the folder or renaming mode.xml file
    • modes.xml won't be present in the future versions
  23. OrionSR commented on Jun 7, 2023

    @OrionSR

    Users can delete modes they are not interested in (another solution to #184), either by deleting the folder or renaming mode.xml file.

    My thought was to add a data\disabled folder for edit modes I don't intend to use regularly.

    A user could quickly get into trouble by disabling modes that are extended. And renaming mode.xml seems likely to cause similar issues.

    Still, I like the basic idea of making custom edit modes easier to implement. I've been putting off customizing my edit modes since it tends to lead to conflicts when sharing scripts. Perhaps it's time to revisit the idea to provide examples for the new feature.

    Got any thoughts on implementing original variable names for SA?

  24. x87 commented on Jun 7, 2023

    @x87
    CollaboratorAuthor

    Got any thoughts on implementing original variable names for SA?

    you mean #195? Haven't looked closely yet, sorry.

  25. added this to the v3.9.0 milestone on Sep 9, 2023
  26. x87 commented on Sep 9, 2023

    @x87
    CollaboratorAuthor

    closing as the limited proposal has been implemented in 3.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionpriority:p2scope:edit modesstatus:user feedback requestedtype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions