GithubHelp home page GithubHelp logo

herrnamenlos123 / genomescript Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 177 KB

A modkit for Gothic 3, implementing Hooks and Lua scripting

License: GNU General Public License v3.0

CMake 1.33% C++ 96.78% C 1.84% Batchfile 0.04%

genomescript's Introduction

GenomeScript

A modkit for Gothic 3, implementing Hooks and Lua scripting

This is just an experiment and not for public use yet!

Build:

cmake . -B build
cmake --build build --config=release --target=GenomeScript

Once the project is built and installed into the Gothic installation directory (hard-coded in CMakeLists.txt), you must inject the DLL:
Copy setdll.exe, GenomeScriptInstall.bat and GenomeScriptUninstall.bat to the Gothic directory and double-click GenomeScriptInstall.bat. It injects the GenomeScript DLL to NxCooking.dll, because it is sufficient and probably nobody else does this, hence making it compatible with any other mod.

When installed, GenomeScript will load all mods installed in ./GenomeScript/*/.

Take a look at the examples folder. The folders in examples must be copied to ./GenomeScript/. Then they are automatically loaded on startup, in alphabetical order.

There are following conventions:

  • Hooked functions contain the class and function name. E.g. to override Music::TriggerFight(), define
function Music_TriggerFight(this)
   log.info("hi")
end
  • If it is a member function, add this as the first parameter.
  • For static functions, omit it.
  • You can call original member functions with this:TriggerFight(). : is equivalent to C++ .
  • You can call static member functions everywhere with Class.StaticMember(). . is equivalent to C++ ::
  • Use PreventDefault*() to change the default behaviour of a hook (see examples)
  • Return values of hooks are ignored
  • Loops and arrays start at index 1 (!!!)

Example: The function is Music::TriggerFight().

function Music_TriggerFight(this)   -- Simply define this to get the call ('this' is the 'Music' object)
    PreventDefaultSuccess()         -- Call this to return early after the script, without calling the original
    PreventDefaultFailure()         -- The last call across all scripts defines what is done
                                    -- To keep mods as compatible as possible, prevent as little defaults as possible and only add hooks
    result = this:TriggerVictory()  -- We call another function instead of the default, and return the return value instead
    PreventDefaultWithValue(result) -- Return early, but with the return value from this hook
end

This function would replace the combat music with the victory music.

You can add more hooks by modifying hooks.cpp. The goal is to eventually support all hooks someone would possibly want, so that any mod could at least in theory be written in Lua. Do not forget to call ::detour() AND ::defineLuaTypes() at the bottom of the file!!!

To add a hook you will need the full function signature. You can get them directly from Ghidra or another decompiler, or alternatively here: (https://github.com/HerrNamenlos123/G3SDK/tree/main/extra-resources)

genomescript's People

Contributors

herrnamenlos123 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.