Skip to content

Latest commit

 

History

History
381 lines (276 loc) · 9.64 KB

File metadata and controls

381 lines (276 loc) · 9.64 KB

Developer Setup Guide - The Drifter Accessibility Mod

This guide will help you set up the development environment to build and modify the accessibility mod.


Prerequisites

1. Required Software

  • Visual Studio 2022 or JetBrains Rider or VS Code with C# extension
  • .NET 6.0 SDK or higher (Download)
  • The Drifter Game (Steam or GOG version)
  • MelonLoader installed in the game (Download)
  • Git (optional, for version control)

2. Game Installation

Make sure The Drifter is installed and MelonLoader is set up:

[Game Folder]\
├── TheDrifter.exe
├── TheDrifter_Data\
│   └── Managed\
│       ├── Assembly-CSharp.dll
│       ├── UnityEngine.dll
│       ├── UnityEngine.CoreModule.dll
│       └── [other Unity DLLs]
├── MelonLoader\
│   ├── MelonLoader.dll
│   ├── 0Harmony.dll
│   └── [other MelonLoader files]
└── Mods\
    └── [empty initially]

Project Setup

Step 1: Update Project References

The .csproj file contains hardcoded paths that need to be updated to match your installation:

  1. Open TheDrifterAccessibility.csproj in a text editor

  2. Find all <Reference> tags and update the <HintPath> to point to your game installation

  3. Update these paths (example for Steam installation):

<!-- MelonLoader -->
<Reference Include="MelonLoader">
  <HintPath>C:\Program Files (x86)\Steam\steamapps\common\The Drifter\MelonLoader\MelonLoader.dll</HintPath>
  <Private>False</Private>
</Reference>

<!-- Unity Engine -->
<Reference Include="UnityEngine">
  <HintPath>C:\Program Files (x86)\Steam\steamapps\common\The Drifter\MelonLoader\Managed\UnityEngine.dll</HintPath>
  <Private>False</Private>
</Reference>

<Reference Include="UnityEngine.CoreModule">
  <HintPath>C:\Program Files (x86)\Steam\steamapps\common\The Drifter\TheDrifter_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
  <Private>False</Private>
</Reference>

<!-- Continue for all references... -->

Common Installation Paths:

  • Steam: C:\Program Files (x86)\Steam\steamapps\common\The Drifter\
  • GOG: C:\GOG Games\The Drifter\
  • Epic Games: C:\Program Files\Epic Games\The Drifter\

Step 2: Alternative - Use Environment Variable

Create an environment variable DRIFTER_PATH pointing to your game folder:

setx DRIFTER_PATH "C:\Program Files (x86)\Steam\steamapps\common\The Drifter"

Then update .csproj to use:

<Reference Include="MelonLoader">
  <HintPath>$(DRIFTER_PATH)\MelonLoader\MelonLoader.dll</HintPath>
  <Private>False</Private>
</Reference>

Building the Mod

Option 1: Using Command Line

cd "E:\Game codes\The Drifter\TheDrifterAccessibility"
dotnet restore
dotnet build -c Release

Output will be in: bin\Release\net6.0\TheDrifterAccessibility.dll

Option 2: Using Visual Studio

  1. Open TheDrifterAccessibility.csproj in Visual Studio
  2. Build → Build Solution (F6)
  3. Or right-click project → Build

Option 3: Using the Build Script

After updating paths in build.bat:

cd "E:\Game codes\The Drifter\TheDrifterAccessibility"
build.bat

The script will:

  1. Clean previous builds
  2. Compile the DLL
  3. Copy to game's Mods folder
  4. Copy dependencies to game folder

Project Structure

TheDrifterAccessibility\
├── Core\
│   ├── AccessibilityManager.cs          # Main TTS coordinator
│   └── KeyboardNavigationHandler.cs     # Keyboard input handler
├── ScreenReader\
│   ├── TolkWrapper.cs                   # TOLK library wrapper
│   └── NVDAWrapper.cs                   # NVDA direct wrapper
├── Patches\
│   ├── QuestTextPatches.cs              # Core text display patches
│   ├── DialogPatches.cs                 # Dialog system patches
│   ├── GuiComponentPatches.cs           # UI component patches
│   ├── HotspotPatches.cs                # World object patches
│   ├── InventoryPatches.cs              # Inventory system patches
│   └── MenuPatches.cs                   # Menu system patches
├── Properties\
│   └── AssemblyInfo.cs                  # Assembly metadata
├── TheDrifterAccessibilityMod.cs        # Main mod entry point
├── TheDrifterAccessibility.csproj       # Project file
├── build.bat                            # Build script
├── README.md                            # User documentation
├── INSTALLATION.md                      # Installation guide
├── DEVELOPER_SETUP.md                   # This file
└── CHANGELOG.md                         # Version history

Development Workflow

1. Making Changes

  1. Edit source files in your IDE
  2. Build the project (Ctrl+Shift+B in VS)
  3. The DLL is automatically copied to Mods folder (if build script is used)

2. Testing

  1. Launch The Drifter
  2. MelonLoader console will show mod loading
  3. Check MelonLoader\Latest.log for errors
  4. Test with a screen reader (NVDA recommended)

3. Debugging

Enable MelonLoader Debug Mode:

  1. Open MelonLoader\MelonLoader.cfg
  2. Set Debug = true
  3. Relaunch game

View Logs:

  • Real-time: Watch MelonLoader\Latest.log
  • Use MelonLogger.Msg() for debug output
  • Use MelonLogger.Error() for errors

Attach Debugger:

  1. Visual Studio → Debug → Attach to Process
  2. Find TheDrifter.exe
  3. Set breakpoints in your code
  4. Trigger the code in-game

Understanding the Code

Harmony Patching

The mod uses Harmony to inject code into game methods:

[HarmonyPatch(typeof(Button))]  // Target class
public static class ButtonPatches
{
    [HarmonyPatch(nameof(Button.Click))]  // Target method
    [HarmonyPrefix]  // Run before original
    public static void Click_Prefix(Button __instance)
    {
        // Your code here
        // __instance is the Button being clicked
    }
}

Patch Types:

  • [HarmonyPrefix] - Runs before the original method
  • [HarmonyPostfix] - Runs after the original method
  • [HarmonyTranspiler] - Modifies IL code (advanced)

AccessibilityManager

Central coordinator for all TTS:

var manager = AccessibilityManager.Instance;
manager.Speak("Hello world", interrupt: true);
manager.AnnounceButton("Play Game", enabled: true);
manager.AnnounceDialog("Annie", "How are you?");

Screen Reader Integration

// Initialize
TolkWrapper.Initialize();

// Speak
TolkWrapper.Output("Text to speak", interrupt: false);

// Check status
bool isActive = TolkWrapper.IsActive;

// Shutdown
TolkWrapper.Shutdown();

Adding New Features

Example: Add TTS for a New UI Element

  1. Find the Game Class: Use dnSpy or ILSpy to find the class name

  2. Create a Patch:

[HarmonyPatch(typeof(NewGuiElement))]
public static class NewGuiElementPatches
{
    [HarmonyPatch("OnShow")]
    [HarmonyPostfix]
    public static void OnShow_Postfix(NewGuiElement __instance)
    {
        var manager = AccessibilityManager.Instance;
        if (!manager.IsScreenReaderActive())
            return;

        string text = __instance.GetText();
        manager.Speak(text, true);
    }
}
  1. Register the Patch in TheDrifterAccessibilityMod.cs:
typeof(NewGuiElementPatches),
  1. Build and Test

Common Issues

Issue: "Cannot find reference"

Solution: Update paths in .csproj to match your installation

Issue: "Harmony patches not applying"

Solution:

  • Check class and method names match exactly
  • Verify namespace imports
  • Check MelonLoader log for patch errors

Issue: "Mod loads but doesn't speak"

Solution:

  • Ensure screen reader is running
  • Press F2 to toggle accessibility
  • Check TolkWrapper.Initialize() succeeded

Issue: "Build succeeds but mod doesn't load"

Solution:

  • Verify MelonLoader is installed
  • Check MelonLoader version compatibility
  • Look for errors in MelonLoader\Latest.log

Testing Checklist

  • Main menu buttons announced
  • Dialog text read with character names
  • Hotspots announced on hover
  • Inventory items announced
  • Dialog choices navigable with arrow keys
  • F1-F10 hotkeys work
  • Settings changes announced
  • Scene transitions announced
  • No crashes or errors in log
  • Performance is acceptable

Contributing

Code Style

  • Use C# naming conventions (PascalCase for public, camelCase for private)
  • Add XML documentation to public methods
  • Keep methods focused and small
  • Handle exceptions gracefully
  • Log errors with MelonLogger.Error()

Pull Request Process

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly with a screen reader
  5. Update CHANGELOG.md
  6. Submit pull request with description

Resources

Documentation

Tools

  • dnSpy: Decompile and debug Unity games (Download)
  • ILSpy: View .NET assemblies (Download)
  • UnityExplorer: Runtime Unity inspector for MelonLoader (GitHub)

Community


License

MIT License - See main README.md for full text


Happy modding! 🔧♿