Initial commit
This commit is contained in:
commit
ef22d85589
35 changed files with 1454 additions and 0 deletions
BIN
Release/CL.read.1.tlog
Normal file
BIN
Release/CL.read.1.tlog
Normal file
Binary file not shown.
BIN
Release/CL.write.1.tlog
Normal file
BIN
Release/CL.write.1.tlog
Normal file
Binary file not shown.
BIN
Release/cl.command.1.tlog
Normal file
BIN
Release/cl.command.1.tlog
Normal file
Binary file not shown.
21
Release/gmcl_samurai_win32.Build.CppClean.log
Normal file
21
Release/gmcl_samurai_win32.Build.CppClean.log
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
D:\GMHax\gmcl_samurai_win32\Release\cl.command.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\CL.read.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\CL.write.1.tlog
|
||||
D:\GMHAX\GMCL_SAMURAI_WIN32\RELEASE\GMCL_SAMURAI_WIN32.DLL.INTERMEDIATE.MANIFEST
|
||||
D:\GMHax\gmcl_samurai_win32\Release\gmcl_samurai_win32.vcxprojResolveAssemblyReference.cache
|
||||
D:\GMHax\gmcl_samurai_win32\Release\gmcl_samurai_win32.write.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\link.command.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\link.read.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\link.write.1.tlog
|
||||
D:\GMHAX\GMCL_SAMURAI_WIN32\RELEASE\MAIN.OBJ
|
||||
D:\GMHAX\GMCL_SAMURAI_WIN32\RELEASE\MEMOBJ.OBJ
|
||||
D:\GMHax\gmcl_samurai_win32\Release\mt.command.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\mt.read.1.tlog
|
||||
D:\GMHax\gmcl_samurai_win32\Release\mt.write.1.tlog
|
||||
D:\GMHAX\GMCL_SAMURAI_WIN32\RELEASE\STATE.OBJ
|
||||
D:\GMHAX\GMCL_SAMURAI_WIN32\RELEASE\STRUCT.OBJ
|
||||
D:\GMHax\gmcl_samurai_win32\Release\vc100.pdb
|
||||
D:\GMHAX\RELEASE\GMCL_SAMURAI_WIN32.DLL
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHAX\RELEASE\GMCL_SAMURAI_WIN32.PDB
|
||||
10
Release/gmcl_samurai_win32.dll.intermediate.manifest
Normal file
10
Release/gmcl_samurai_win32.dll.intermediate.manifest
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
|
||||
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||
<security>
|
||||
<requestedPrivileges>
|
||||
<requestedExecutionLevel level='asInvoker' uiAccess='false' />
|
||||
</requestedPrivileges>
|
||||
</security>
|
||||
</trustInfo>
|
||||
</assembly>
|
||||
2
Release/gmcl_samurai_win32.lastbuildstate
Normal file
2
Release/gmcl_samurai_win32.lastbuildstate
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#v4.0:v100:false
|
||||
Release|Win32|D:\GMHax\|
|
||||
30
Release/gmcl_samurai_win32.log
Normal file
30
Release/gmcl_samurai_win32.log
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
Build started 13.05.2017 17:50:32.
|
||||
1>Project "D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj" on node 2 (build target(s)).
|
||||
1>InitializeBuildStatus:
|
||||
Creating "Release\gmcl_samurai_win32.unsuccessfulbuild" because "AlwaysCreate" was specified.
|
||||
ClCompile:
|
||||
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D _WINDLL /D _MBCS /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt samurai.cpp
|
||||
samurai.cpp
|
||||
1>samurai.cpp(105): warning C4018: <: несоответствие типов со знаком и без знака
|
||||
1>samurai.cpp(119): warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
|
||||
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\string.h(110): см. объявление "strcat"
|
||||
Link:
|
||||
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\link.exe /ERRORREPORT:PROMPT /OUT:"D:\GMHax\Release\gmcl_samurai_win32.dll" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /ManifestFile:"Release\gmcl_samurai_win32.dll.intermediate.manifest" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"D:\GMHax\Release\gmcl_samurai_win32.pdb" /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"D:\GMHax\Release\gmcl_samurai_win32.lib" /MACHINE:X86 /DLL Release\main.obj
|
||||
Release\memobj.obj
|
||||
Release\samurai.obj
|
||||
Release\state.obj
|
||||
Release\struct.obj
|
||||
Создается библиотека D:\GMHax\Release\gmcl_samurai_win32.lib и объект D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
Создание кода
|
||||
Создание кода завершено
|
||||
gmcl_samurai_win32.vcxproj -> D:\GMHax\Release\gmcl_samurai_win32.dll
|
||||
Manifest:
|
||||
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\mt.exe /nologo /verbose /outputresource:"D:\GMHax\Release\gmcl_samurai_win32.dll;#2" /manifest Release\gmcl_samurai_win32.dll.intermediate.manifest
|
||||
FinalizeBuildStatus:
|
||||
Deleting file "Release\gmcl_samurai_win32.unsuccessfulbuild".
|
||||
Touching "Release\gmcl_samurai_win32.lastbuildstate".
|
||||
1>Done Building Project "D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj" (build target(s)).
|
||||
|
||||
Построение успешно завершено.
|
||||
|
||||
Time Elapsed 00:00:06.66
|
||||
BIN
Release/gmcl_samurai_win32.vcxprojResolveAssemblyReference.cache
Normal file
BIN
Release/gmcl_samurai_win32.vcxprojResolveAssemblyReference.cache
Normal file
Binary file not shown.
55
Release/gmcl_samurai_win32.write.1.tlog
Normal file
55
Release/gmcl_samurai_win32.write.1.tlog
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
^D:\GMHax\gmcl_samurai_win32\gmcl_samurai_win32.vcxproj
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.lib
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
D:\GMHax\Release\gmcl_samurai_win32.exp
|
||||
BIN
Release/link.command.1.tlog
Normal file
BIN
Release/link.command.1.tlog
Normal file
Binary file not shown.
BIN
Release/link.read.1.tlog
Normal file
BIN
Release/link.read.1.tlog
Normal file
Binary file not shown.
BIN
Release/link.write.1.tlog
Normal file
BIN
Release/link.write.1.tlog
Normal file
Binary file not shown.
BIN
Release/main.obj
Normal file
BIN
Release/main.obj
Normal file
Binary file not shown.
BIN
Release/memobj.obj
Normal file
BIN
Release/memobj.obj
Normal file
Binary file not shown.
BIN
Release/mt.command.1.tlog
Normal file
BIN
Release/mt.command.1.tlog
Normal file
Binary file not shown.
BIN
Release/mt.read.1.tlog
Normal file
BIN
Release/mt.read.1.tlog
Normal file
Binary file not shown.
BIN
Release/mt.write.1.tlog
Normal file
BIN
Release/mt.write.1.tlog
Normal file
Binary file not shown.
BIN
Release/samurai.obj
Normal file
BIN
Release/samurai.obj
Normal file
Binary file not shown.
BIN
Release/state.obj
Normal file
BIN
Release/state.obj
Normal file
Binary file not shown.
BIN
Release/struct.obj
Normal file
BIN
Release/struct.obj
Normal file
Binary file not shown.
BIN
Release/vc100.pdb
Normal file
BIN
Release/vc100.pdb
Normal file
Binary file not shown.
80
gmcl_samurai_win32.vcxproj
Normal file
80
gmcl_samurai_win32.vcxproj
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{8CDB4A26-C5A0-4AF8-BA78-BE9022004A3A}</ProjectGuid>
|
||||
<RootNamespace>gmcl_samurai_win32</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="memobj.cpp" />
|
||||
<ClCompile Include="samurai.cpp" />
|
||||
<ClCompile Include="state.cpp" />
|
||||
<ClCompile Include="struct.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="interface.h" />
|
||||
<ClInclude Include="lua.h" />
|
||||
<ClInclude Include="memobj.h" />
|
||||
<ClInclude Include="samurai.h" />
|
||||
<ClInclude Include="state.h" />
|
||||
<ClInclude Include="struct.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
54
gmcl_samurai_win32.vcxproj.filters
Normal file
54
gmcl_samurai_win32.vcxproj.filters
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Файлы исходного кода">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Заголовочные файлы">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Файлы ресурсов">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="state.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="memobj.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="struct.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="samurai.cpp">
|
||||
<Filter>Файлы исходного кода</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="state.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lua.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="interface.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="memobj.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="struct.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="samurai.h">
|
||||
<Filter>Заголовочные файлы</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
3
gmcl_samurai_win32.vcxproj.user
Normal file
3
gmcl_samurai_win32.vcxproj.user
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
||||
37
interface.h
Normal file
37
interface.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef __INTERFACE_H
|
||||
#define __INTERFACE_H
|
||||
|
||||
#include "lua.h"
|
||||
#include "state.h"
|
||||
|
||||
class CLuaInterface;
|
||||
|
||||
class CLuaShared
|
||||
{
|
||||
public:
|
||||
void** vtable;
|
||||
char tmp[88];
|
||||
CLuaInterface* m_pClient;
|
||||
CLuaInterface* m_pServer;
|
||||
CLuaInterface* m_pMenu;
|
||||
};
|
||||
|
||||
class CLuaInterface
|
||||
{
|
||||
public:
|
||||
void** vtable;
|
||||
CLuaState* m_pState;
|
||||
};
|
||||
|
||||
#ifndef DLL_EXPORT
|
||||
#if defined(__GCC__)
|
||||
#define DLL_EXPORT __attribute__((dllexport))
|
||||
#elif defined (_MSC_VER)
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define GMOD_MODULE_OPEN() extern "C" DLL_EXPORT int gmod13_open(CLuaState* L)
|
||||
#define GMOD_MODULE_CLOSE() extern "C" DLL_EXPORT int gmod13_close(CLuaState* L)
|
||||
|
||||
#endif
|
||||
87
lua.h
Normal file
87
lua.h
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
#ifndef __LUA_H
|
||||
#define __LUA_H
|
||||
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define LUA_REGISTRYINDEX (-10000)
|
||||
#define LUA_ENVIRONINDEX (-10001)
|
||||
#define LUA_GLOBALSINDEX (-10002)
|
||||
|
||||
class CLuaState;
|
||||
typedef int (*CLuaFunction)(CLuaState*);
|
||||
|
||||
typedef int (*lua_type) (CLuaState *L, int idx);
|
||||
typedef const char *(*lua_typename) (CLuaState *L, int tp);
|
||||
|
||||
typedef int (*lua_gettop) (CLuaState *L);
|
||||
typedef void (*lua_settop) (CLuaState *L, int idx);
|
||||
typedef void (*lua_pushvalue) (CLuaState *L, int idx);
|
||||
|
||||
typedef double (*lua_tonumber) (CLuaState *L, int idx);
|
||||
typedef int (*lua_toboolean) (CLuaState *L, int idx);
|
||||
typedef const char *(*lua_tolstring) (CLuaState *L, int idx, size_t *len);
|
||||
typedef CLuaFunction (*lua_tocfunction) (CLuaState *L, int idx);
|
||||
typedef void *(*lua_touserdata) (CLuaState *L, int idx);
|
||||
typedef CLuaState *(*lua_tothread) (CLuaState *L, int idx);
|
||||
typedef const void *(*lua_topointer) (CLuaState *L, int idx);
|
||||
|
||||
typedef void (*lua_pushnil) (CLuaState *L);
|
||||
typedef void (*lua_pushnumber) (CLuaState *L, double n);
|
||||
typedef void (*lua_pushlstring) (CLuaState *L, const char *s, size_t l);
|
||||
typedef void (*lua_pushcclosure) (CLuaState *L, CLuaFunction fn, int n);
|
||||
typedef void (*lua_pushboolean) (CLuaState *L, int b);
|
||||
typedef void (*lua_pushlightuserdata) (CLuaState *L, void *p);
|
||||
typedef int (*lua_pushthread) (CLuaState *L);
|
||||
|
||||
typedef void (*lua_gettable) (CLuaState *L, int idx);
|
||||
typedef void (*lua_getfield) (CLuaState *L, int idx, const char *k);
|
||||
typedef void (*lua_rawget) (CLuaState *L, int idx);
|
||||
typedef void (*lua_rawgeti) (CLuaState *L, int idx, int n);
|
||||
typedef void (*lua_createtable) (CLuaState *L, int narr, int nrec);
|
||||
typedef void *(*lua_newuserdata) (CLuaState *L, size_t sz);
|
||||
typedef int (*lua_getmetatable) (CLuaState *L, int objindex);
|
||||
typedef void (*lua_getfenv) (CLuaState *L, int idx);
|
||||
|
||||
typedef void (*lua_settable) (CLuaState *L, int idx);
|
||||
typedef void (*lua_setfield) (CLuaState *L, int idx, const char *k);
|
||||
typedef void (*lua_rawset) (CLuaState *L, int idx);
|
||||
typedef void (*lua_rawseti) (CLuaState *L, int idx, int n);
|
||||
typedef int (*lua_setmetatable) (CLuaState *L, int objindex);
|
||||
typedef int (*lua_setfenv) (CLuaState *L, int idx);
|
||||
|
||||
typedef void (*lua_call) (CLuaState *L, int nargs, int nresults);
|
||||
typedef int (*lua_pcall) (CLuaState *L, int nargs, int nresults, int errfunc);
|
||||
|
||||
typedef int (*luaL_loadbufferx)(CLuaState *L, const char *buff,
|
||||
size_t sz,const char *name,const char* mode);
|
||||
typedef int (*luaL_newmetatable) (CLuaState *L, const char *tname);
|
||||
typedef void (*luaL_checktype) (CLuaState *L, int narg, int t);
|
||||
typedef size_t (*lua_objlen) (CLuaState *L, int idx);
|
||||
typedef void (*lua_pushinteger)(CLuaState *L, int n);
|
||||
typedef int (*lua_tointeger)(CLuaState* L,int idx);
|
||||
|
||||
typedef enum {
|
||||
OK = 0,
|
||||
YIELD,
|
||||
ERRRUN,
|
||||
ERRSYNTAX,
|
||||
ERRMEM,
|
||||
ERRERR
|
||||
} ret_t;
|
||||
|
||||
typedef enum {
|
||||
NONE = -1,
|
||||
NIL,
|
||||
TBOOLEAN,
|
||||
LIGHTUSERDATA,
|
||||
NUMBER,
|
||||
STRING,
|
||||
TABLE,
|
||||
FUNCTION,
|
||||
USERDATA,
|
||||
THREAD,
|
||||
} luatype_t;
|
||||
|
||||
#endif
|
||||
21
main.cpp
Normal file
21
main.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include <Windows.h>
|
||||
#include "interface.h"
|
||||
#include "memobj.h"
|
||||
#include "struct.h"
|
||||
#include "samurai.h"
|
||||
|
||||
GMOD_MODULE_OPEN()
|
||||
{
|
||||
MemObj_Open(L);
|
||||
Struct_Open(L);
|
||||
Samurai_Open(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
GMOD_MODULE_CLOSE()
|
||||
{
|
||||
MemObj_Close(L);
|
||||
Struct_Close(L);
|
||||
Samurai_Close(L);
|
||||
return 0;
|
||||
}
|
||||
121
memobj.cpp
Normal file
121
memobj.cpp
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
#include "memobj.h"
|
||||
#include "struct.h"
|
||||
|
||||
int lMemObj_Create(CLuaState* L)
|
||||
{
|
||||
L->CheckType(1,NUMBER);
|
||||
|
||||
memobj_t* obj = new memobj_t;
|
||||
obj->sz = L->GetInteger(1);
|
||||
obj->mem = (void*)malloc(obj->sz);
|
||||
|
||||
userdata_t* pData = L->NewUserData();
|
||||
pData->data = obj;
|
||||
pData->type = MEMOBJ_TYPE;
|
||||
|
||||
L->GetMetaFromRegistry(MEMOBJ_NAME);
|
||||
L->SetMetaTable(-2);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
memobj_t* MemObj_Check(CLuaState* L,int idx)
|
||||
{
|
||||
userdata_t* pData = L->GetUserData(idx);
|
||||
if(pData->type == MEMOBJ_TYPE)
|
||||
return (memobj_t*)pData->data;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lMemObj_tostr(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
if(!obj)
|
||||
return 0;
|
||||
else
|
||||
L->PushFString("memobj_t mem %p size %d",obj->mem,obj->sz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lMemObj_eq(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj1 = MemObj_Check(L,1),*obj2 = MemObj_Check(L,2);
|
||||
L->PushBool(((obj1->mem == obj2->mem) && (obj1->sz == obj2->sz)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lMemObj_gc(CLuaState *L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
if(obj->mem)
|
||||
free(obj->mem);
|
||||
delete obj;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lMemObj_ToString(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
L->PushString((const char*)obj->mem,obj->sz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lMemObj_ToStruct(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
Struct_Create(L,obj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lMemObj_ToPointer(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
L->PushInteger((int)obj->mem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lMemObj_Free(CLuaState* L)
|
||||
{
|
||||
memobj_t* obj = MemObj_Check(L,1);
|
||||
if(obj->mem)
|
||||
{
|
||||
free(obj->mem);
|
||||
obj->mem = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int MemObj_Open(CLuaState* L)
|
||||
{
|
||||
L->CreateMetaTable(MEMOBJ_NAME);
|
||||
|
||||
L->PushCFunction(lMemObj_tostr);
|
||||
L->SetField(-2,"__tostring");
|
||||
|
||||
L->PushCFunction(lMemObj_eq);
|
||||
L->SetField(-2,"__eq");
|
||||
|
||||
L->PushCFunction(lMemObj_gc);
|
||||
L->SetField(-2,"__gc");
|
||||
|
||||
L->PushCFunction(lMemObj_Free);
|
||||
L->SetField(-2,"Free");
|
||||
|
||||
L->PushCFunction(lMemObj_ToString);
|
||||
L->SetField(-2,"ToString");
|
||||
|
||||
L->PushCFunction(lMemObj_ToStruct);
|
||||
L->SetField(-2,"ToStruct");
|
||||
|
||||
L->PushCFunction(lMemObj_ToPointer);
|
||||
L->SetField(-2,"ToPointer");
|
||||
|
||||
L->Push(-1);
|
||||
L->SetField(-2,"__index");
|
||||
return 0;
|
||||
}
|
||||
int MemObj_Close(CLuaState* L)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
23
memobj.h
Normal file
23
memobj.h
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef __MEMOBJ_H
|
||||
#define __MEMOBJ_H
|
||||
|
||||
#include "interface.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#define MEMOBJ_NAME "luaL_MemObj"
|
||||
#define MEMOBJ_TYPE 195
|
||||
|
||||
typedef struct {
|
||||
void* mem;
|
||||
size_t sz;
|
||||
} memobj_t;
|
||||
|
||||
int lMemObj_Create(CLuaState* L);
|
||||
|
||||
int MemObj_Open(CLuaState* L);
|
||||
int MemObj_Close(CLuaState* L);
|
||||
|
||||
#endif
|
||||
183
samurai.cpp
Normal file
183
samurai.cpp
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
#include "samurai.h"
|
||||
#include "memobj.h"
|
||||
#include "struct.h"
|
||||
|
||||
int lGetModuleHandle(CLuaState* L)
|
||||
{
|
||||
L->CheckType(1,STRING);
|
||||
L->PushInteger((int)GetModuleHandleA(L->GetString(1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lGetProcAddress(CLuaState* L)
|
||||
{
|
||||
L->CheckType(1,NUMBER);
|
||||
L->CheckType(2,STRING);
|
||||
L->PushInteger((int)GetProcAddress((HMODULE)L->GetInteger(1),L->GetString(2)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
__declspec(naked) int VStdCall(int func,int stack) //StdCall
|
||||
{
|
||||
__asm
|
||||
{
|
||||
push ebp
|
||||
mov ebp,esp
|
||||
|
||||
mov eax,[func]
|
||||
mov esp,[stack]
|
||||
call eax
|
||||
mov esp,ebp
|
||||
|
||||
pop ebp
|
||||
retn
|
||||
}
|
||||
}
|
||||
|
||||
int lInvoke(CLuaState* L)
|
||||
{
|
||||
DWORD dwFunc,dwData;
|
||||
int argnum;
|
||||
int* s_ptr;
|
||||
char stack[10240];
|
||||
|
||||
s_ptr = (int*)&stack[10240];
|
||||
memset(stack,'\0',10240);
|
||||
|
||||
L->CheckType(1,NUMBER);
|
||||
|
||||
dwFunc = (DWORD)L->GetInteger(1);
|
||||
argnum = L->GetTop();
|
||||
|
||||
for(int i = argnum; i != 1; i--)
|
||||
{
|
||||
int type = L->Type(i);
|
||||
switch(type)
|
||||
{
|
||||
case NUMBER:
|
||||
dwData = L->GetInteger(i);
|
||||
break;
|
||||
case STRING:
|
||||
dwData = (DWORD)L->GetString(i);
|
||||
break;
|
||||
case TBOOLEAN:
|
||||
dwData = (DWORD)L->GetBool(i);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,"%d invalid type!\n",i);
|
||||
}
|
||||
s_ptr--;
|
||||
*s_ptr = dwData;
|
||||
}
|
||||
|
||||
L->PushInteger(VStdCall(dwFunc,(int)s_ptr));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Export2Table(CLuaState* L,const char* name)
|
||||
{
|
||||
PIMAGE_DOS_HEADER DosHeader;
|
||||
PIMAGE_NT_HEADERS NtHeader;
|
||||
PIMAGE_SECTION_HEADER SecHeader;
|
||||
PIMAGE_EXPORT_DIRECTORY Exports;
|
||||
PIMAGE_DATA_DIRECTORY Data;
|
||||
HMODULE hDll;
|
||||
DWORD dwLocal;
|
||||
char* text,*end,*len;
|
||||
char funcName[MAX_PATH];
|
||||
|
||||
LPVOID lpBase = (LPVOID)GetModuleHandle(name);
|
||||
|
||||
DosHeader = (PIMAGE_DOS_HEADER)lpBase;
|
||||
NtHeader = (PIMAGE_NT_HEADERS)((DWORD)lpBase + DosHeader->e_lfanew);
|
||||
SecHeader = IMAGE_FIRST_SECTION(NtHeader);
|
||||
Data = (PIMAGE_DATA_DIRECTORY)(&NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT]);
|
||||
Exports = (PIMAGE_EXPORT_DIRECTORY)((DWORD)lpBase + Data->VirtualAddress);
|
||||
|
||||
L->CreateTable();
|
||||
|
||||
PDWORD pdwFunctions = (PDWORD)((DWORD)lpBase+Exports->AddressOfFunctions);
|
||||
const char** Names = (const char**)((DWORD)lpBase+Exports->AddressOfNames);
|
||||
unsigned short* ordinal = (unsigned short*)((DWORD)lpBase+Exports->AddressOfNameOrdinals);
|
||||
|
||||
for(int i = 0; i < Exports->NumberOfNames; i++)
|
||||
{
|
||||
const char* name = ((DWORD)lpBase+Names[i]);
|
||||
unsigned short ord = ordinal[i];
|
||||
dwLocal = (DWORD)lpBase+pdwFunctions[ord];
|
||||
DWORD dwNew = (DWORD)GetProcAddress((HMODULE)lpBase,name);
|
||||
if(dwLocal >= (DWORD)Exports && dwLocal <= (DWORD)Exports + Data->Size)
|
||||
{
|
||||
text = (char*)dwLocal;
|
||||
len = (char*)(text+strlen(text));
|
||||
memset(funcName,'\0',MAX_PATH);
|
||||
if(!(end = (char*)strchr(text,'.')))
|
||||
continue;
|
||||
memcpy(funcName,text,(size_t)(end-text));
|
||||
strcat(funcName,".dll");
|
||||
if(!(hDll = GetModuleHandle(funcName)))
|
||||
continue;
|
||||
end++;
|
||||
memcpy(funcName,end,(len-end));
|
||||
dwLocal = (DWORD)GetProcAddress(hDll,funcName);
|
||||
}
|
||||
|
||||
L->PushInteger(dwLocal);
|
||||
L->SetField(-2,name);
|
||||
}
|
||||
}
|
||||
|
||||
int lExport2Table(CLuaState* L)
|
||||
{
|
||||
L->CheckType(1,STRING);
|
||||
Export2Table(L,L->GetString(1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Samurai_Open(CLuaState* L)
|
||||
{
|
||||
L->CreateTable();
|
||||
|
||||
L->PushCFunction(lGetModuleHandle);
|
||||
L->SetField(-2,"GetModuleHandle");
|
||||
|
||||
L->PushCFunction(lGetProcAddress);
|
||||
L->SetField(-2,"GetProcAddress");
|
||||
|
||||
L->PushCFunction(lExport2Table);
|
||||
L->SetField(-2,"ExportTable");
|
||||
|
||||
L->PushCFunction(lMemObj_Create);
|
||||
L->SetField(-2,"Alloc");
|
||||
|
||||
L->PushCFunction(Struct_FromPointer);
|
||||
L->SetField(-2,"StructFromPointer");
|
||||
|
||||
L->SetGlobal("samurai");
|
||||
|
||||
L->PushCFunction(lInvoke);
|
||||
L->SetGlobal("invoke");
|
||||
|
||||
Export2Table(L,"kernel32.dll");
|
||||
L->SetGlobal("kernel32");
|
||||
|
||||
Export2Table(L,"user32.dll");
|
||||
L->SetGlobal("user32");
|
||||
|
||||
L->PushInteger(0);
|
||||
L->SetGlobal("NULL");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Samurai_Close(CLuaState* L)
|
||||
{
|
||||
L->PushNil();
|
||||
L->SetGlobal("samurai");
|
||||
|
||||
L->PushNil();
|
||||
L->SetGlobal("invoke");
|
||||
|
||||
L->PushNil();
|
||||
L->SetGlobal("NULL");
|
||||
return 0;
|
||||
}
|
||||
12
samurai.h
Normal file
12
samurai.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef __SAMURAI_H
|
||||
#define __SAMURAI_H
|
||||
|
||||
#include "interface.h"
|
||||
#include <Windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc.h>
|
||||
|
||||
int Samurai_Open(CLuaState* L);
|
||||
int Samurai_Close(CLuaState* L);
|
||||
|
||||
#endif
|
||||
343
state.cpp
Normal file
343
state.cpp
Normal file
|
|
@ -0,0 +1,343 @@
|
|||
#include "state.h"
|
||||
|
||||
func_t lua_api[] = {
|
||||
{"lua_gettop",NULL}, //0
|
||||
{"lua_settop",NULL}, //1
|
||||
{"lua_pushvalue",NULL}, //2
|
||||
{"lua_tonumber",NULL}, //3
|
||||
{"lua_toboolean",NULL}, //4
|
||||
{"lua_tolstring",NULL}, //5
|
||||
{"lua_tocfunction",NULL}, //6
|
||||
{"lua_touserdata",NULL}, //7
|
||||
{"lua_tothread",NULL}, //8
|
||||
{"lua_topointer",NULL}, //9
|
||||
{"lua_pushnil",NULL}, //10
|
||||
{"lua_pushnumber",NULL}, //11
|
||||
{"lua_pushlstring",NULL}, //12
|
||||
{"lua_pushcclosure",NULL}, //13
|
||||
{"lua_pushboolean",NULL}, //14
|
||||
{"lua_pushlightuserdata",NULL}, //15
|
||||
{"lua_pushthread",NULL}, //16
|
||||
{"lua_gettable",NULL}, //17
|
||||
{"lua_getfield",NULL}, //18
|
||||
{"lua_rawget",NULL}, //19
|
||||
{"lua_rawgeti",NULL}, //20
|
||||
{"lua_createtable",NULL}, //21
|
||||
{"lua_getmetatable",NULL}, //22
|
||||
{"lua_newuserdata",NULL}, //23
|
||||
{"lua_getfenv",NULL}, //24
|
||||
{"lua_settable",NULL}, //25
|
||||
{"lua_setfield",NULL}, //26
|
||||
{"lua_rawset",NULL}, //27
|
||||
{"lua_rawseti",NULL}, //28
|
||||
{"lua_setmetatable",NULL}, //29
|
||||
{"lua_setfenv",NULL}, //30
|
||||
{"lua_call",NULL}, //31
|
||||
{"lua_pcall",NULL}, //32
|
||||
{"luaL_loadbufferx",NULL}, //33
|
||||
{"luaL_newmetatable",NULL}, //34
|
||||
{"lua_type",NULL}, //35
|
||||
{"lua_typename",NULL}, //36
|
||||
{"luaL_checktype",NULL}, //37
|
||||
{"lua_objlen",NULL}, //38
|
||||
{"lua_pushinteger",NULL}, //39
|
||||
{"lua_tointeger",NULL}, //40
|
||||
{NULL,NULL}
|
||||
};
|
||||
|
||||
CLuaState::CLuaState()
|
||||
{
|
||||
}
|
||||
|
||||
CLuaState::~CLuaState()
|
||||
{
|
||||
}
|
||||
|
||||
int CLuaState::GetTop()
|
||||
{
|
||||
return (((lua_gettop)lua_api[0].ptr))(this);
|
||||
}
|
||||
|
||||
void CLuaState::SetTop(int n)
|
||||
{
|
||||
(((lua_settop)lua_api[1].ptr))(this,n);
|
||||
}
|
||||
|
||||
void CLuaState::SetField(int idx,const char* name)
|
||||
{
|
||||
(((lua_setfield)lua_api[26].ptr))(this,idx,name);
|
||||
}
|
||||
|
||||
void CLuaState::GetField(int idx,const char* name)
|
||||
{
|
||||
(((lua_getfield)lua_api[18].ptr))(this,idx,name);
|
||||
}
|
||||
|
||||
void CLuaState::Push(int idx)
|
||||
{
|
||||
(((lua_pushvalue)lua_api[2].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::PushNil()
|
||||
{
|
||||
(((lua_pushnil)lua_api[10].ptr))(this);
|
||||
}
|
||||
|
||||
void CLuaState::PushBool(bool val)
|
||||
{
|
||||
(((lua_pushboolean)lua_api[14].ptr))(this,val);
|
||||
}
|
||||
|
||||
void CLuaState::PushNumber(double num)
|
||||
{
|
||||
(((lua_pushnumber)lua_api[11].ptr))(this,num);
|
||||
}
|
||||
|
||||
void CLuaState::PushInteger(int n)
|
||||
{
|
||||
(((lua_pushinteger)lua_api[39].ptr))(this,n);
|
||||
}
|
||||
|
||||
void CLuaState::PushCClosure(CLuaFunction fn,int n)
|
||||
{
|
||||
(((lua_pushcclosure)lua_api[13].ptr))(this,fn,n);
|
||||
}
|
||||
|
||||
void CLuaState::PushString(const char* str,size_t len)
|
||||
{
|
||||
if(!len)
|
||||
len = strlen(str);
|
||||
(((lua_pushlstring)lua_api[12].ptr))(this,str,len);
|
||||
}
|
||||
|
||||
void CLuaState::PushVString(const char* fmt,va_list ap)
|
||||
{
|
||||
char buf[512];
|
||||
vsnprintf(buf,512,fmt,ap);
|
||||
PushString(buf);
|
||||
}
|
||||
|
||||
void CLuaState::PushFString(const char* fmt,...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap,fmt);
|
||||
PushVString(fmt,ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void CLuaState::PushLightUserData(void* p)
|
||||
{
|
||||
(((lua_pushlightuserdata)lua_api[15].ptr))(this,p);
|
||||
}
|
||||
|
||||
void CLuaState::PushThread(CLuaState* L)
|
||||
{
|
||||
(((lua_pushthread)lua_api[16].ptr))(L);
|
||||
}
|
||||
|
||||
bool CLuaState::GetBool(int idx)
|
||||
{
|
||||
return (((lua_toboolean)lua_api[4].ptr))(this,idx);
|
||||
}
|
||||
|
||||
double CLuaState::GetNumber(int idx)
|
||||
{
|
||||
return (((lua_tonumber)lua_api[3].ptr))(this,idx);
|
||||
}
|
||||
|
||||
int CLuaState::GetInteger(int idx)
|
||||
{
|
||||
return (((lua_tointeger)lua_api[40].ptr))(this,idx);
|
||||
}
|
||||
|
||||
const char* CLuaState::GetString(int idx,size_t* len)
|
||||
{
|
||||
return (((lua_tolstring)lua_api[5].ptr))(this,idx,len);
|
||||
}
|
||||
|
||||
userdata_t* CLuaState::GetUserData(int idx)
|
||||
{
|
||||
return (userdata_t*)(((lua_touserdata)lua_api[7].ptr))(this,idx);
|
||||
}
|
||||
|
||||
CLuaFunction CLuaState::GetCFunction(int idx)
|
||||
{
|
||||
return (((lua_tocfunction)lua_api[6].ptr))(this,idx);
|
||||
}
|
||||
|
||||
CLuaState* CLuaState::GetThread(int idx)
|
||||
{
|
||||
return (((lua_tothread)lua_api[8].ptr))(this,idx);
|
||||
}
|
||||
|
||||
const void* CLuaState::GetPointer(int idx)
|
||||
{
|
||||
return (((lua_topointer)lua_api[9].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::CreateTable()
|
||||
{
|
||||
(((lua_createtable)lua_api[21].ptr))(this,0,0);
|
||||
}
|
||||
|
||||
void CLuaState::GetTable(int idx)
|
||||
{
|
||||
(((lua_gettable)lua_api[17].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::SetTable(int idx)
|
||||
{
|
||||
(((lua_settable)lua_api[25].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::RawGet(int idx)
|
||||
{
|
||||
(((lua_rawget)lua_api[19].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::RawGeti(int idx,int n)
|
||||
{
|
||||
(((lua_rawgeti)lua_api[20].ptr))(this,idx,n);
|
||||
}
|
||||
|
||||
void CLuaState::RawSet(int idx)
|
||||
{
|
||||
(((lua_rawset)lua_api[27].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::RawSeti(int idx,int n)
|
||||
{
|
||||
(((lua_rawseti)lua_api[28].ptr))(this,idx,n);
|
||||
}
|
||||
|
||||
void CLuaState::GetEnvironment(int idx)
|
||||
{
|
||||
(((lua_getfenv)lua_api[24].ptr))(this,idx);
|
||||
}
|
||||
|
||||
void CLuaState::SetEnvironment(int idx)
|
||||
{
|
||||
(((lua_setfenv)lua_api[30].ptr))(this,idx);
|
||||
}
|
||||
|
||||
userdata_t* CLuaState::NewUserData()
|
||||
{
|
||||
return (userdata_t*)(((lua_newuserdata)lua_api[23].ptr))(this,sizeof(userdata_t));
|
||||
}
|
||||
|
||||
void CLuaState::CreateMetaTable(const char* name)
|
||||
{
|
||||
(((luaL_newmetatable)lua_api[34].ptr))(this,name);
|
||||
}
|
||||
|
||||
int CLuaState::GetMetaTable(int idx)
|
||||
{
|
||||
return (((lua_getmetatable)lua_api[22].ptr))(this,idx);
|
||||
}
|
||||
|
||||
int CLuaState::SetMetaTable(int idx)
|
||||
{
|
||||
return (((lua_setmetatable)lua_api[29].ptr))(this,idx);
|
||||
}
|
||||
|
||||
luatype_t CLuaState::Type(int idx)
|
||||
{
|
||||
return (luatype_t)(((lua_type)lua_api[35].ptr))(this,idx);
|
||||
}
|
||||
|
||||
const char* CLuaState::TypeName(int idx)
|
||||
{
|
||||
return (((lua_typename)lua_api[36].ptr))(this,Type(idx));
|
||||
}
|
||||
|
||||
void CLuaState::CheckType(int idx,luatype_t tp)
|
||||
{
|
||||
(((luaL_checktype)lua_api[37].ptr))(this,idx,tp);
|
||||
}
|
||||
|
||||
void CLuaState::Call(int nargs,int nret)
|
||||
{
|
||||
(((lua_call)lua_api[31].ptr))(this,nargs,nret);
|
||||
}
|
||||
|
||||
int CLuaState::PCall(int nargs,int nret,int errfunc)
|
||||
{
|
||||
return (((lua_pcall)lua_api[32].ptr))(this,nargs,nret,errfunc);
|
||||
}
|
||||
|
||||
void CLuaState::Print(const char* msg,...)
|
||||
{
|
||||
GetGlobal("print");
|
||||
va_list ap;
|
||||
va_start(ap,msg);
|
||||
PushVString(msg,ap);
|
||||
va_end(ap);
|
||||
Call(1,0);
|
||||
}
|
||||
|
||||
int CLuaState::ObjLen(int idx)
|
||||
{
|
||||
return (((lua_objlen)lua_api[38].ptr))(this,idx);
|
||||
}
|
||||
|
||||
int CLuaState::ReferenceCreate()
|
||||
{
|
||||
int len = ObjLen(-1);
|
||||
len++;
|
||||
PushInteger(len);
|
||||
Push(-2);
|
||||
SetTable(LUA_REGISTRYINDEX);
|
||||
Pop();
|
||||
return len;
|
||||
}
|
||||
|
||||
void CLuaState::ReferencePush(int refId)
|
||||
{
|
||||
PushInteger(refId);
|
||||
GetTable(LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
void CLuaState::ReferenceFree(int refId)
|
||||
{
|
||||
PushInteger(refId);
|
||||
PushNil();
|
||||
SetTable(LUA_REGISTRYINDEX);
|
||||
}
|
||||
|
||||
const char* CLuaState::RunString(const char* name,const char* buf,size_t len)
|
||||
{
|
||||
const char* err = NULL;
|
||||
if( (((luaL_loadbufferx)lua_api[33].ptr))(this,buf,len,name,NULL) != OK)
|
||||
{
|
||||
err = GetString(-1);
|
||||
Pop();
|
||||
}
|
||||
else
|
||||
PCall(0,0,0);
|
||||
return err;
|
||||
}
|
||||
|
||||
BOOL WINAPI ConnectLuaShared()
|
||||
{
|
||||
HMODULE hLuaShared = NULL;
|
||||
char szDebugInfo[128];
|
||||
if(!(hLuaShared = GetModuleHandle("lua_shared.dll")))
|
||||
return FALSE;
|
||||
for(func_t* i = lua_api; i->name; i++)
|
||||
{
|
||||
if(!(i->ptr = (void*)GetProcAddress(hLuaShared,i->name)))
|
||||
{
|
||||
_snprintf(szDebugInfo,128,"GetProcAddress failed at %s",i->name);
|
||||
MessageBoxA(NULL,szDebugInfo,"ConnectLuaShared",MB_ICONHAND);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL APIENTRY DllMain(HINSTANCE hDll,DWORD fdwReason,LPVOID lpReserved)
|
||||
{
|
||||
if(fdwReason == DLL_PROCESS_ATTACH)
|
||||
return ConnectLuaShared();
|
||||
return TRUE;
|
||||
}
|
||||
102
state.h
Normal file
102
state.h
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#ifndef __STATE_H
|
||||
#define __STATE_H
|
||||
|
||||
#include "lua.h"
|
||||
#include <Windows.h>
|
||||
#include <stdarg.h>
|
||||
#include <varargs.h>
|
||||
|
||||
typedef struct {
|
||||
const char* name;
|
||||
void* ptr;
|
||||
} func_t;
|
||||
|
||||
typedef struct {
|
||||
void* data;
|
||||
unsigned char type;
|
||||
} userdata_t;
|
||||
|
||||
class CLuaState
|
||||
{
|
||||
public:
|
||||
CLuaState();
|
||||
~CLuaState();
|
||||
|
||||
int GetTop();
|
||||
void SetTop(int n);
|
||||
|
||||
void SetField(int idx,const char* name);
|
||||
void GetField(int idx,const char* name);
|
||||
|
||||
inline void GetGlobal(const char* name){GetField(LUA_GLOBALSINDEX,name);}
|
||||
inline void SetGlobal(const char* name){SetField(LUA_GLOBALSINDEX,name);}
|
||||
inline void GetMetaFromRegistry(const char* name){GetField(LUA_REGISTRYINDEX,name);}
|
||||
|
||||
void Push(int idx);
|
||||
void Pop(int amt = 1){SetTop(-(amt)-1);}
|
||||
|
||||
void PushNil();
|
||||
void PushBool(bool val);
|
||||
void PushNumber(double num);
|
||||
void PushInteger(int n);
|
||||
void PushCClosure(CLuaFunction fn,int n);
|
||||
inline void PushCFunction(CLuaFunction fn){PushCClosure(fn,0);}
|
||||
void PushString(const char* str,size_t len = 0);
|
||||
void PushVString(const char* fmt,va_list ap);
|
||||
void PushFString(const char* fmt,...);
|
||||
void PushLightUserData(void* p);
|
||||
void PushThread(CLuaState* L);
|
||||
|
||||
bool GetBool(int idx);
|
||||
double GetNumber(int idx);
|
||||
int GetInteger(int idx);
|
||||
const char* GetString(int idx,size_t* len = NULL);
|
||||
userdata_t* GetUserData(int idx);
|
||||
CLuaFunction GetCFunction(int idx);
|
||||
CLuaState* GetThread(int idx);
|
||||
const void* GetPointer(int idx);
|
||||
|
||||
void CreateTable();
|
||||
void GetTable(int idx);
|
||||
void SetTable(int idx);
|
||||
|
||||
void RawGet(int idx);
|
||||
void RawGeti(int idx,int n);
|
||||
void RawSet(int idx);
|
||||
void RawSeti(int idx,int n);
|
||||
|
||||
void GetEnvironment(int idx);
|
||||
void SetEnvironment(int idx);
|
||||
|
||||
userdata_t* NewUserData();
|
||||
void CreateMetaTable(const char* name);
|
||||
int GetMetaTable(int idx);
|
||||
int SetMetaTable(int idx);
|
||||
|
||||
luatype_t Type(int idx);
|
||||
const char* TypeName(int idx);
|
||||
void CheckType(int idx,luatype_t tp);
|
||||
|
||||
void Call(int nargs,int nret);
|
||||
int PCall(int nargs,int nret,int errfunc);
|
||||
|
||||
int ObjLen(int idx);
|
||||
int ReferenceCreate();
|
||||
void ReferencePush(int refId);
|
||||
void ReferenceFree(int refId);
|
||||
|
||||
void Print(const char*,...);
|
||||
const char* RunString(const char* name,const char* buf,size_t len);
|
||||
|
||||
inline bool IsNil(int idx){return (Type(idx) == NIL);}
|
||||
inline bool IsBool(int idx){return (Type(idx) == TBOOLEAN);}
|
||||
inline bool IsLightUserData(int idx){return (Type(idx) == LIGHTUSERDATA);}
|
||||
inline bool IsNumber(int idx){return (Type(idx) == NUMBER);}
|
||||
inline bool IsString(int idx){return (Type(idx) == STRING);}
|
||||
inline bool IsTable(int idx){return (Type(idx) == TABLE);}
|
||||
inline bool IsFunction(int idx){return (Type(idx) == FUNCTION);}
|
||||
inline bool IsUserData(int idx){return (Type(idx) == USERDATA);}
|
||||
inline bool IsThread(int idx){return (Type(idx) == THREAD);}
|
||||
};
|
||||
|
||||
#endif
|
||||
248
struct.cpp
Normal file
248
struct.cpp
Normal file
|
|
@ -0,0 +1,248 @@
|
|||
#include "struct.h"
|
||||
|
||||
void Struct_Create(CLuaState* L,memobj_t* obj)
|
||||
{
|
||||
struct_t* stc = new struct_t;
|
||||
stc->page = obj;
|
||||
stc->s_ptr = (char*)stc->page->mem;
|
||||
stc->bFree = false;
|
||||
|
||||
userdata_t* pData = L->NewUserData();
|
||||
pData->data = (void*)stc;
|
||||
pData->type = STRUCT_TYPE;
|
||||
|
||||
L->GetMetaFromRegistry(STRUCT_NAME);
|
||||
L->SetMetaTable(-2);
|
||||
}
|
||||
|
||||
int Struct_FromPointer(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = new struct_t;
|
||||
L->CheckType(1,NUMBER);
|
||||
|
||||
stc->page = new memobj_t;
|
||||
stc->s_ptr = (char*)stc->page->mem;
|
||||
stc->bFree = false;
|
||||
|
||||
userdata_t* pData = L->NewUserData();
|
||||
pData->data = (void*)stc;
|
||||
pData->type = STRUCT_TYPE;
|
||||
|
||||
L->GetMetaFromRegistry(STRUCT_NAME);
|
||||
L->SetMetaTable(-2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct_t* Check_Struct(CLuaState* L,int idx)
|
||||
{
|
||||
userdata_t* pData = L->GetUserData(idx);
|
||||
if(pData->type == STRUCT_TYPE)
|
||||
return (struct_t*)pData->data;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int lStruct_tostr(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
L->PushFString("struct mem %p s_ptr %p size %d",stc->page->mem,stc->s_ptr,stc->page->sz);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_eq(CLuaState* L)
|
||||
{
|
||||
struct_t* st1 = Check_Struct(L,1),*st2 = Check_Struct(L,2);
|
||||
L->PushBool(((st1->page == st2->page) && (st1->s_ptr == st2->s_ptr)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_gc(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
if(stc->bFree && stc->page->mem)
|
||||
free(stc->page);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_ResetPtr(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
stc->s_ptr = (char*)stc->page->mem;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_GetOffset(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
L->PushInteger((int)(stc->s_ptr-(char*)stc->page->mem));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_SetOffset(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,NUMBER);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
stc->s_ptr=(char*)L->GetInteger(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_Skip(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,NUMBER);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
stc->s_ptr=(char*)(stc->s_ptr+L->GetInteger(2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_PushString(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,STRING);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
|
||||
const char* str = L->GetString(2);
|
||||
size_t len = strlen(str) + 1;
|
||||
|
||||
memcpy(stc->s_ptr,str,len);
|
||||
stc->s_ptr = (char*)(stc->s_ptr+len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_PushNumber(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,NUMBER);
|
||||
L->CheckType(3,NUMBER);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
|
||||
size_t len = L->GetNumber(3);
|
||||
int data = L->GetInteger(2);
|
||||
|
||||
if(len == 1)
|
||||
*(unsigned char*)stc->s_ptr = (unsigned char)data;
|
||||
else if(len == 2)
|
||||
*(unsigned short*)stc->s_ptr = (unsigned short)data;
|
||||
else if(len == 4)
|
||||
*(unsigned int*)stc->s_ptr = (unsigned int)data;
|
||||
stc->s_ptr = (char*)(stc->s_ptr+len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lStruct_GetStringFixed(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,NUMBER);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
|
||||
size_t len = L->GetInteger(2);
|
||||
L->PushString(stc->s_ptr);
|
||||
stc->s_ptr = (char*)(stc->s_ptr+len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_GetString(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
|
||||
size_t len = strlen(stc->s_ptr)+1;
|
||||
L->PushString(stc->s_ptr);
|
||||
stc->s_ptr = (char*)(stc->s_ptr+len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_GetNumber(CLuaState* L)
|
||||
{
|
||||
L->CheckType(2,NUMBER);
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
|
||||
size_t len = L->GetInteger(2);
|
||||
int data;
|
||||
|
||||
if(len == 1)
|
||||
data = stc->s_ptr[0];
|
||||
else if(len == 2)
|
||||
data = *(unsigned short*)stc->s_ptr;
|
||||
else if(len == 4)
|
||||
data = *(unsigned int*)stc->s_ptr;
|
||||
L->PushInteger(data);
|
||||
stc->s_ptr = (char*)(stc->s_ptr+len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int lStruct_ToPointer(CLuaState* L)
|
||||
{
|
||||
struct_t* stc = Check_Struct(L,1);
|
||||
L->PushInteger((int)stc->page->mem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Struct_Open(CLuaState* L)
|
||||
{
|
||||
L->PushNumber(1);
|
||||
L->SetGlobal("BYTE");
|
||||
|
||||
L->PushNumber(2);
|
||||
L->SetGlobal("WORD");
|
||||
|
||||
L->PushNumber(4);
|
||||
L->SetGlobal("DWORD");
|
||||
|
||||
L->CreateMetaTable(STRUCT_NAME);
|
||||
|
||||
L->PushCFunction(lStruct_eq);
|
||||
L->SetField(-2,"__eq");
|
||||
|
||||
L->PushCFunction(lStruct_gc);
|
||||
L->SetField(-2,"__gc");
|
||||
|
||||
L->PushCFunction(lStruct_tostr);
|
||||
L->SetField(-2,"__tostring");
|
||||
|
||||
L->PushCFunction(lStruct_ResetPtr);
|
||||
L->SetField(-2,"ResetPtr");
|
||||
|
||||
L->PushCFunction(lStruct_GetOffset);
|
||||
L->SetField(-2,"GetOffset");
|
||||
|
||||
L->PushCFunction(lStruct_SetOffset);
|
||||
L->SetField(-2,"SetOffset");
|
||||
|
||||
L->PushCFunction(lStruct_Skip);
|
||||
L->SetField(-2,"Skip");
|
||||
|
||||
L->PushCFunction(lStruct_PushString);
|
||||
L->SetField(-2,"PushString");
|
||||
|
||||
L->PushCFunction(lStruct_PushNumber);
|
||||
L->SetField(-2,"PushNumber");
|
||||
|
||||
L->PushCFunction(lStruct_GetStringFixed);
|
||||
L->SetField(-2,"GetStringFixed");
|
||||
|
||||
L->PushCFunction(lStruct_GetString);
|
||||
L->SetField(-2,"GetString");
|
||||
|
||||
L->PushCFunction(lStruct_GetNumber);
|
||||
L->SetField(-2,"GetNumber");
|
||||
|
||||
L->PushCFunction(lStruct_ToPointer);
|
||||
L->SetField(-2,"ToPointer");
|
||||
|
||||
L->Push(-1);
|
||||
L->SetField(-2,"__index");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Struct_Close(CLuaState* L)
|
||||
{
|
||||
L->PushNil();
|
||||
L->SetGlobal("BYTE");
|
||||
|
||||
L->PushNil();
|
||||
L->SetGlobal("WORD");
|
||||
|
||||
L->PushNil();
|
||||
L->SetGlobal("DWORD");
|
||||
return 0;
|
||||
}
|
||||
22
struct.h
Normal file
22
struct.h
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef __STRUCT_H
|
||||
#define __STRUCT_H
|
||||
|
||||
#define STRUCT_NAME "luaL_Struct"
|
||||
#define STRUCT_TYPE 196
|
||||
|
||||
#include "interface.h"
|
||||
#include "memobj.h"
|
||||
|
||||
typedef struct {
|
||||
memobj_t* page;
|
||||
char* s_ptr;
|
||||
bool bFree;
|
||||
} struct_t;
|
||||
|
||||
void Struct_Create(CLuaState* L,memobj_t* obj);
|
||||
int Struct_FromPointer(CLuaState* L);
|
||||
|
||||
int Struct_Open(CLuaState* L);
|
||||
int Struct_Close(CLuaState* L);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue