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

op2ext for Outpost 2 v1.4.x #303

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
BSD 3-Clause License

Copyright (c) 2021, The Outpost Universe
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

THIS MATERIAL IS NOT MADE OR SUPPORTED BY ACTIVISION.

Outpost 2 is (c) 1997, Activision Publishing, Inc. and its affiliates ("Activision").
8 changes: 7 additions & 1 deletion ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ Order of vol file precedence is below:
Change Log
------------------------------------------

Version 3.1.0
* Check if the base module is Outpost2.exe and that the game version is valid before attempting to activate patches
* Look for Outpost2.ini and other OPU modded game files under the "Outpost2\OPU" directory instead of "Outpost2"
* Removed Earthworker Proximity Tasking as a Built in Module
* Add external API functions GetModuleDirectoryCount and GetModuleDirectory to get loaded module directories
* Changed how multiple console mods can be loaded - you should now specify "/loadmod" multiple times

Version 3.0.0

* Remove public functions IsConsoleModuleLoaded & IsIniModuleLoaded
Expand Down Expand Up @@ -159,7 +166,6 @@ LoadAddons = "NetFix, NetHelper"
Add the following sections to the ini file:

[BuiltInModules]
EarthworkerProximityTasking = yes
IPDropDown = yes

[ExternalModules]
Expand Down
17 changes: 13 additions & 4 deletions srcDLL/DllMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "OP2Memory.h"
#include "FileSystemHelper.h"
#include "FsInclude.h"
#include "ConsoleArgumentParser.h"
#include "Log.h"
#include "Log/LoggerFile.h"
#include "Log/LoggerMessageBox.h"
Expand Down Expand Up @@ -40,7 +41,7 @@ AppEvents appEvents;
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*reserved*/)
{
// This will be called once the program is unpacked and running
if (dwReason == DLL_PROCESS_ATTACH) {
if ((dwReason == DLL_PROCESS_ATTACH) && CommandOptionExists("OPU")) {
// Setup logging
SetLoggerError(&loggerDistributor);
SetLoggerMessage(&loggerFile);
Expand Down Expand Up @@ -69,9 +70,6 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*reserved*/)
// Set active events
appEvents.Activate();
}

// Disable any more thread attach calls
DisableThreadLibraryCalls(hInstance);
}

return TRUE;
Expand Down Expand Up @@ -104,11 +102,22 @@ bool InstallDepPatch()
}


// Redirects Outpost2.ini to be accessed from the OPU directory.
void RedirectIniFile()
{
// Overwrite gConfigFile.iniPath
CopyStringViewIntoCharBuffer(GetOutpost2IniPath(), static_cast<char*>(Op2RelocatePointer(0x00547090)), MAX_PATH);
}


void OnInit()
{
// Install DEP patch so newer versions of Windows don't terminate the game
InstallDepPatch();

// Set the game to look for Outpost2.ini under the OPU directory
RedirectIniFile();

// Order of precedence for loading vol files is:
// ART_PATH (from console module), Console Module, Ini Modules, Addon directory, Game directory

Expand Down
17 changes: 15 additions & 2 deletions srcDLL/op2ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "StringConversion.h"
#include "OP2Memory.h"
#include "FileSystemHelper.h"
#include "ResourceSearchPath.h"
#include "Log.h"
#include "WindowsModule.h"
#define WIN32_LEAN_AND_MEAN
Expand All @@ -13,8 +14,8 @@
#include <cstdint>


// Dummy export for linking requirements from Outpost2.exe and OP2Shell.dll.
// Outpost2.exe and OP2Shell.dll reference this dummy entry, causing op2ext.dll to load.
// Dummy export for linking requirements from winmm.dll injector shim loaded by Outpost2.exe.
// The winmm.dll shim references this dummy entry, causing op2ext.dll to load.
// It is not used in any way, but must exist to prevent Windows loader errors.
extern "C" OP2EXT_API int StubExt;
int StubExt = 0;
Expand Down Expand Up @@ -164,3 +165,15 @@ OP2EXT_API size_t GetLoadedModuleName(size_t moduleIndex, char* buffer, size_t b

return CopyStringViewIntoCharBuffer(moduleName, buffer, bufferSize);
}

OP2EXT_API size_t GetModuleDirectoryCount()
{
return ResourceSearchPath::GetSearchPaths().size();
}

OP2EXT_API size_t GetModuleDirectory(size_t moduleIndex, char* buffer, size_t bufferSize)
{
const auto& searchPaths = ResourceSearchPath::GetSearchPaths();
const std::string moduleName = (moduleIndex < searchPaths.size()) ? searchPaths[moduleIndex] : "";
return CopyStringViewIntoCharBuffer(moduleName, buffer, bufferSize);
}
11 changes: 10 additions & 1 deletion srcDLL/op2ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,20 @@ OP2EXT_API size_t GetLoadedModuleCount();
// Use function GetLoadedModuleCount to determine how many module names exist.
// If an index is beyond the loaded module count, returns 0 and clears the buffer.
// A console module's name is the directory name parameter passed in via the /loadmod command.
// The directory name is relative to the executable's folder, with no trailing slash
// The directory name is relative to the OPU folder, with no trailing slash
// An ini module name is the module's [section name] within the ini file.
// Returns 0 on success. Returns the required minimum size of the buffer on failure.
OP2EXT_API size_t GetLoadedModuleName(size_t moduleIndex, char* buffer, size_t bufferSize);

// Returns the number of module directories.
OP2EXT_API size_t GetModuleDirectoryCount();

// Retrieves the module directory path at the specified index.
// Use function GetModuleDirectoryCount() to determine how many module directories exist.
// If an index is beyond the loaded module count, returns 0 and clears the buffer.
// Returns 0 on success. Returns the required minimum size of the buffer on failure.
OP2EXT_API size_t GetModuleDirectory(size_t moduleIndex, char* buffer, size_t bufferSize);

#ifdef __cplusplus
} // extern "C"
#endif
Loading