Skip to content

Commit

Permalink
細かい改良
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Jun 6, 2013
1 parent 255d9f7 commit bb3c6a2
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 30 deletions.
10 changes: 5 additions & 5 deletions DynamicPatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dpAPI bool dpInitialize(const dpConfig &conf)
}
dpEach(cf.loads, [](const std::string &v){ dpLoad(v.c_str()); });
dpEach(cf.source_paths, [](const std::string &v){ dpAddSourcePath(v.c_str()); });
dpEach(cf.load_paths, [](const std::string &v){ dpAddLoadPath(v.c_str()); });
dpEach(cf.module_paths, [](const std::string &v){ dpAddModulePath(v.c_str()); });
dpEach(cf.msbuild_commands, [](const std::string &v){ dpAddMSBuildCommand(v.c_str()); });
dpEach(cf.build_commands, [](const std::string &v){ dpAddBuildCommand(v.c_str()); });
if(!cf.source_paths.empty() && (!cf.msbuild_commands.empty() || !cf.build_commands.empty())) {
Expand Down Expand Up @@ -142,9 +142,9 @@ dpAPI void* dpGetUnpatched(void *target_or_hook_addr)
}


dpAPI void dpAddLoadPath(const char *path)
dpAPI void dpAddModulePath(const char *path)
{
dpGetCurrentContext()->getBuilder()->addLoadPath(path);
dpGetCurrentContext()->getBuilder()->addModulePath(path);
}

dpAPI void dpAddSourcePath(const char *path)
Expand Down Expand Up @@ -180,7 +180,7 @@ dpAPI void dpUpdate()
dpGetCurrentContext()->getBuilder()->update();
}

dpAPI const char* dpGetVCVars()
dpAPI const char* dpGetVCVarsPath()
{
return dpGetCurrentContext()->getBuilder()->getVCVars();
return dpGetCurrentContext()->getBuilder()->getVCVarsPath();
}
16 changes: 7 additions & 9 deletions DynamicPatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@

#ifdef _M_X64
# define dpLibArch "64"
# define dpSymPrefix
#else // _M_X64
# define dpLibArch
# define dpSymPrefix "_"
#endif //_M_X64
#ifdef _DEBUG
# define dpLibConfig "d"
Expand All @@ -27,12 +25,12 @@

#if defined(dpDLLImpl)
# define dpAPI dpDLLExport
#elif defined(dpLinkDynamic)
# define dpAPI dpDLLImport
# pragma comment(lib,"DynamicPatcher" dpLibArch ".lib")
#elif defined(dpLinkStatic)
# define dpAPI
# pragma comment(lib,"DynamicPatchers" dpLibConfig dpLibArch ".lib")
#elif !defined(dpNoLib)
# define dpAPI dpDLLImport
# pragma comment(lib,"DynamicPatcher" dpLibArch ".lib")
#else
# define dpAPI
#endif // dpDLL_Impl
Expand Down Expand Up @@ -139,7 +137,7 @@ dpAPI bool dpPatchByAddress(void *hook_addr); // patches the host symbol that
dpAPI bool dpUnpatchByAddress(void *target_or_hook_addr);
dpAPI void* dpGetUnpatched(void *target_or_hook_addr);

dpAPI void dpAddLoadPath(const char *path); // accepts wildcard. affects auto build and dpReload()
dpAPI void dpAddModulePath(const char *path); // accepts wildcard. affects auto build and dpReload()
dpAPI void dpAddSourcePath(const char *path); //
dpAPI void dpAddMSBuildCommand(const char *msbuild_option); // add msbuild command that will be called by auto build thread
dpAPI void dpAddCLBuildCommand(const char *cl_option); // add cl command that will be called by auto build thread
Expand All @@ -150,7 +148,7 @@ dpAPI void dpUpdate(); // reloads and links modified modules.

dpAPI void dpPrint(const char* fmt, ...);
dpAPI bool dpDemangle(const char *mangled, char *demangled, size_t buflen);
dpAPI const char* dpGetVCVars();
dpAPI const char* dpGetVCVarsPath();

#else // dpDisable

Expand Down Expand Up @@ -183,7 +181,7 @@ dpAPI const char* dpGetVCVars();
#define dpUnpatchByAddress(...)
#define dpGetUnpatched(...)

#define dpAddLoadPath(...)
#define dpAddModulePath(...)
#define dpAddSourcePath(...)
#define dpAddMSBuildCommand(...)
#define dpAddCLBuildCommand(...)
Expand All @@ -194,7 +192,7 @@ dpAPI const char* dpGetVCVars();

#define dpPrint(...)
#define dpDemangle(...)
#define dpGetVCVars(...)
#define dpGetVCVarsPath(...)

#endif // dpDisable

Expand Down
4 changes: 4 additions & 0 deletions DynamicPatcherInjector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FloatingPointModel>Fast</FloatingPointModel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -127,6 +128,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<FloatingPointModel>Fast</FloatingPointModel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -145,6 +147,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand All @@ -162,6 +165,7 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<BufferSecurityCheck>false</BufferSecurityCheck>
<FloatingPointModel>Fast</FloatingPointModel>
<PreprocessorDefinitions>dpNoLib;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
2 changes: 1 addition & 1 deletion Test/Test_Inject/Test_Inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dpNoInline void Test_ThisMaybeOverridden()
dpOnLoad(
dpPrint("loaded: Test_Inject.cpp\n");

dpAddLoadPath(dpObjDir"/*.obj");
dpAddModulePath(dpObjDir"/*.obj");
dpAddSourcePath("Test_Inject");
dpAddMSBuildCommand("Test_Inject.vcxproj /target:ClCompile /m /p:Configuration="dpConfiguration";Platform="dpPlatform);
dpStartAutoBuild();
Expand Down
4 changes: 2 additions & 2 deletions Test/Test_LibDll/Test_UseLibDll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int main(int argc, char *argv[])
dpScope(g_dp_context=dpCreateContext());
dpSetCurrentContext(g_dp_context);

dpAddLoadPath("Test_Dll.dll");
dpAddLoadPath("Test_Lib.lib");
dpAddModulePath("Test_Dll.dll");
dpAddModulePath("Test_Lib.lib");
dpAddSourcePath("Test_LibDll");
dpAddMSBuildCommand("Test_Lib.vcxproj /target:Build /m /p:Configuration="dpConfiguration";Platform="dpPlatform);
dpAddMSBuildCommand("Test_Dll.vcxproj /target:Build /m /p:Configuration="dpConfiguration";Platform="dpPlatform);
Expand Down
1 change: 0 additions & 1 deletion Test/Test_LibDll/dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// https://github.com/i-saint/DynamicObjLoader

#include <windows.h>
#define dpLinkDynamic
#include "DynamicPatcher.h"

dpPatch void OverriddenByDll()
Expand Down
2 changes: 1 addition & 1 deletion Test/Test_Particles/Test_Particles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ void Render()
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPWSTR /*lpCmdLine*/, int nCmdShow )
{
dpInitialize(dpConfig(dpE_LogAll, dpE_SysDefault|dpE_SysOpenConsole));
dpAddLoadPath(dpObjDir"/Test_ParticlesObj.obj");
dpAddModulePath(dpObjDir"/Test_ParticlesObj.obj");
dpAddSourcePath("Test_Particles");
dpAddMSBuildCommand("Test_Particles.vcxproj /target:ClCompile /m /p:Configuration="dpConfiguration";Platform="dpPlatform);
dpStartAutoBuild();
Expand Down
1 change: 0 additions & 1 deletion Test/Test_Particles/Test_Particles.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <d3dcompiler.h>
#include <xnamath.h>
#include <cstdio>
#define dpLinkDynamic
#include "DynamicPatcher.h"

#define MAX_PARTICLES 6144
Expand Down
3 changes: 1 addition & 2 deletions Test/Test_Simple/Test_Simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

//#define dpDisable
//#define dpLinkStatic
#define dpLinkDynamic
#include "DynamicPatcher.h"

#ifdef _M_X64
Expand Down Expand Up @@ -71,7 +70,7 @@ dpNoInline void Test_ThisMaybeOverridden()
int main(int argc, char *argv[])
{
dpInitialize(dpE_LogAll);
dpAddLoadPath(dpObjDir"/*.obj");
dpAddModulePath(dpObjDir"/*.obj");
dpAddSourcePath("Test_Simple");
dpAddMSBuildCommand("Test_Simple.vcxproj /target:ClCompile /m /p:Configuration="dpConfiguration";Platform="dpPlatform);
dpStartAutoBuild();
Expand Down
5 changes: 5 additions & 0 deletions dpBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "dpInternal.h"
#include <regex>

#ifdef _M_X64
# define dpSymPrefix
#else // _M_X64
# define dpSymPrefix "_"
#endif //_M_X64

typedef unsigned long long QWORD;
const char g_symname_onload[] = dpSymPrefix "dpOnLoadHandler";
Expand Down
4 changes: 2 additions & 2 deletions dpBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dpBuilder::~dpBuilder()
stopAutoBuild();
}

void dpBuilder::addLoadPath(const char *path)
void dpBuilder::addModulePath(const char *path)
{
std::string tmp = path;
auto p = dpFind(m_loadpathes, [&](const std::string &s){return s==tmp;});
Expand Down Expand Up @@ -222,7 +222,7 @@ size_t dpBuilder::reload()
return n;
}

const char* dpBuilder::getVCVars() const
const char* dpBuilder::getVCVarsPath() const
{
return m_vcvars.c_str();
}
2 changes: 1 addition & 1 deletion dpConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool dpConfigFile::load(const char *path)
else if(sscanf(line, "vc ver: %d", &iv)) { vc_ver=iv; }
else if(sscanf(line, "load: \"%[^\"]\"", opt)) { loads.push_back(opt); }
else if(sscanf(line, "source path: \"%[^\"]\"", opt)) { source_paths.push_back(opt); }
else if(sscanf(line, "load path: \"%[^\"]\"", opt)) { load_paths.push_back(opt); }
else if(sscanf(line, "module path: \"%[^\"]\"", opt)) { module_paths.push_back(opt); }
else if(sscanf(line, "msbuild command: \"%[^\"]\"", opt)) { msbuild_commands.push_back(opt); }
else if(sscanf(line, "build command: \"%[^\"]\"", opt)) { build_commands.push_back(opt); }
}
Expand Down
4 changes: 2 additions & 2 deletions dpFoundation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,13 @@ size_t dpGetCurrentModulePath(char *buf, size_t buflen)
{
HMODULE mod = 0;
::GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)&dpGetCurrentModulePath, &mod);
return ::GetModuleFileNameA(mod, buf, buflen);
return ::GetModuleFileNameA(mod, buf, (DWORD)buflen);
}

size_t dpGetMainModulePath(char *buf, size_t buflen)
{
HMODULE mod = ::GetModuleHandleA(nullptr);
return ::GetModuleFileNameA(mod, buf, buflen);
return ::GetModuleFileNameA(mod, buf, (DWORD)buflen);
}

void dpSanitizePath(std::string &path)
Expand Down
6 changes: 3 additions & 3 deletions dpInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct dpConfigFile
int vc_ver;
std::vector<std::string> loads;
std::vector<std::string> source_paths;
std::vector<std::string> load_paths;
std::vector<std::string> module_paths;
std::vector<std::string> msbuild_commands;
std::vector<std::string> build_commands;
std::string target_process;
Expand Down Expand Up @@ -441,7 +441,7 @@ class dpBuilder
public:
dpBuilder(dpContext *ctx);
~dpBuilder();
void addLoadPath(const char *path);
void addModulePath(const char *path);
void addSourcePath(const char *path);
void addMSBuildCommand(const char *msbuild_options);
void addCLBuildCommand(const char *cl_options);
Expand All @@ -454,7 +454,7 @@ class dpBuilder
void watchFiles();
bool build();

const char* getVCVars() const;
const char* getVCVarsPath() const;

private:
struct SourcePath
Expand Down

0 comments on commit bb3c6a2

Please sign in to comment.