From 83f71ae533ef0d3e34ce37bfde5a8d8c152f2532 Mon Sep 17 00:00:00 2001 From: Paul Sladen Date: Fri, 31 Jul 2009 14:18:08 +0100 Subject: [PATCH] AtsPluginProxy: patch to chdir() to train directory before loading real plugin.so --- AtsPluginProxy/AtsPluginProxy.cpp | 13 +++++++++++++ debian/changelog | 2 ++ 2 files changed, 15 insertions(+), 0 deletions(-) diff --git a/AtsPluginProxy/AtsPluginProxy.cpp b/AtsPluginProxy/AtsPluginProxy.cpp index 6ddb527..153d5d5 100644 --- a/AtsPluginProxy/AtsPluginProxy.cpp +++ b/AtsPluginProxy/AtsPluginProxy.cpp @@ -4,9 +4,12 @@ extern "C" { #ifdef __WIN32__ #include "stdafx.h" #else +#include #include #include // wchar #include +#include // get_current_dir_name() +#include // strdup() #define _stdcall #define __stdcall #define FARPROC void * @@ -82,8 +85,11 @@ typedef ATS_API void (__stdcall *DOORCLOSE) (); static DOORCLOSE doorclose = NUL typedef ATS_API void (__stdcall *SETSIGNAL) (int signal); static SETSIGNAL setsignal = NULL; typedef ATS_API void (__stdcall *SETBEACONDATA) (ATS_BEACONDATA beaconData); static SETBEACONDATA setbeacondata = NULL; +static char *plugin_path; + // --- load the plugin --- int _stdcall LoadDLL(LPCWSTR fileUnicode, LPCSTR fileAnsi) { + plugin_path = strdup(fileAnsi); fprintf(stderr, "LoadDLL(\"%s\") called\n", fileAnsi); dllhandle = LoadLibraryW(fileUnicode); if (dllhandle == NULL) { @@ -234,6 +240,13 @@ int _stdcall UnloadDLL () { // --- Load --- void _stdcall Load () { fprintf(stderr, "AtsPluginProxy: Load()\n"); +#ifndef __WIN32__ + // Strip the directory and change to it so that the + // plugin has some hope of finding its config file + // If it fails, it's no worse than before + *rindex(plugin_path, '/') = '\0'; + chdir(plugin_path); +#endif if (load != NULL) load(); fprintf(stderr, "AtsPluginProxy: Load() returned\n"); } diff --git a/debian/changelog b/debian/changelog index 627ac2f..2b34f54 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ openbve (1.2.0.0-0ubuntu1) unreleased; urgency=low + debian/openbve-atspluginproxy.* + debian/rules: combine common dh_* methods to binary + install OpenBve.exe.config Dll import mapping + + patch to chdir() to train directory before loading real plugin.so + (allow plugin to find its configuration file as no GetModuleName()) -- Paul Sladen Sun, 26 Jul 2009 11:07:00 +0000 -- 1.6.0.4