Initial attempt at using ISXEq2 from c++

This commit is contained in:
Malcolm Roberts 2023-12-20 15:36:09 -06:00
commit 2ba27dd921
78 changed files with 9184 additions and 0 deletions

34
.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
# Ignore build folders
cmake-*/
# Ignore generated headers
scripts/*.h
# Ignore common C++ and CMake build artifacts
*.o
*.lo
*.la
*.so
*.so.*
*.dylib
*.dll
*.exe
*.out
*.app
# CMake specific files
CMakeFiles/
CMakeCache.txt
cmake_install.cmake
Makefile
# Ignore editor and IDE specific files
.vscode/
.idea/
*.swp
*.swo
*~
# Miscellaneous
.DS_Store
Thumbs.db

77
CMakeLists.txt Normal file
View File

@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.27)
project(ISXMr VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Set the project source directory
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Set the project include directory
include_directories(${SOURCE_DIR})
file(GLOB_RECURSE SCRIPT_FILES "scripts/*")
foreach(FILE ${SCRIPT_FILES})
get_filename_component(FILE_NAME ${FILE} NAME)
string(REGEX REPLACE "[^a-zA-Z0-9]" "_" FILE_IDENTIFIER ${FILE_NAME})
set(HEADER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${FILE_NAME}.h")
add_custom_command(
OUTPUT ${HEADER_FILE}
COMMAND xxd -i -n ${FILE_IDENTIFIER} ${FILE} ${HEADER_FILE}
COMMENT "Generating ${HEADER_FILE} from ${FILE_PATH}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${FILE}
)
list(APPEND GENERATED_HEADERS ${HEADER_FILE})
endforeach()
add_custom_target(GenerateHeaders ALL DEPENDS ${GENERATED_HEADERS})
add_library(ISXMr SHARED ${SOURCE_DIR}/ISXMr.cpp
${SOURCE_DIR}/Commands.cpp
${SOURCE_DIR}/DataTypes.cpp
${SOURCE_DIR}/LGUIMrFrame.cpp
${SOURCE_DIR}/Services.cpp
${SOURCE_DIR}/TopLevelObjects.cpp
${SOURCE_DIR}/Commands.h
${SOURCE_DIR}/DataTypeList.h
${SOURCE_DIR}/DataTypes.h
${SOURCE_DIR}/ISXMr.h
${SOURCE_DIR}/ISXMrServices.h
${SOURCE_DIR}/LGUIMrFrame.h
${SOURCE_DIR}/Services.h
${SOURCE_DIR}/TopLevelObjects.h
src/isxeq2/Character.cpp
src/isxeq2/Character.h
src/isxeq2/Actor.cpp
src/isxeq2/Actor.h
src/isxeq2/LSObject.cpp
src/isxeq2/LSObject.h)
# Set the path to additional libraries
set(LIBS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/)
# Find isxdk library
find_library(ISXDK_LIBRARY ISXDK HINTS ${LIBS_DIR}/isxdk/lib64/vs16)
if(NOT ISXDK_LIBRARY)
message(FATAL_ERROR "isxdk library not found")
endif()
find_library(ISUI_LIBRARY ISUI HINTS ${LIBS_DIR}/isxdk/lib64/vs16)
if(NOT ISUI_LIBRARY)
message(FATAL_ERROR "isxui library not found")
endif()
# Set include directories for isxdk
include_directories(${LIBS_DIR}/isxdk/include)
# Link ISXMr with isxdk library
target_link_libraries(ISXMr PRIVATE ${ISUI_LIBRARY} ${ISXDK_LIBRARY})
# Set the output directory for the shared library
set_target_properties(ISXMr PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
)
set_property(TARGET ISXMr PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

View File

@ -0,0 +1,153 @@
#pragma once
class CColumnRenderer;
#ifndef __CColumnRenderer_h__
#define __CColumnRenderer_h__
struct _ColumnRendererItem
{
char *Text;
size_t Length;
};
class CColumnRenderer
{
public:
CColumnRenderer()
{
LongestItem=0;
ItemCount=0;
}
~CColumnRenderer()
{
foreach(_ColumnRendererItem* pItem,i,Items)
{
free(pItem->Text);
}
}
void AddItem(const char *Text)
{
if (!Text || !Text[0])
return;
_ColumnRendererItem *pItem = new _ColumnRendererItem;
pItem->Text=strdup(Text);
size_t NewLength=strlen(Text);
if (const char *pColor=(const char *)strchr(Text,'\a'))
{
do
{
if (pColor[1]=='-')
NewLength--;
NewLength-=2;
}
while(pColor=strchr(&pColor[1],'\a'));
}
pItem->Length=NewLength;
if (NewLength>LongestItem)
LongestItem=NewLength;
Items+=pItem;
ItemCount++;
}
void Render(class ISInterface *pISInterface)
{
if (!LongestItem)
return; // wtf.
size_t Width = pISInterface->GetTerminalWidth();
size_t Columns = (Width - LongestItem) / LongestItem;
size_t ColumnWidth;
if (Columns<1)
{
Columns=1;
ColumnWidth=Width;
}
else if (Columns>10)
{
Columns=10;
ColumnWidth=Width/10;
}
else
ColumnWidth=Width/Columns;
char Row[1024];
char *pColumn=Row;
size_t Rows = (ItemCount / Columns) + 1;
size_t ItemNumber = 0;
//pISInterface->Printf("Items: %d. Rows: %d. Columns: %d.",ItemCount,Rows,Columns);
for (size_t i = 0; i < Rows; i++)
{
ItemNumber=i;
for (size_t Column = 0; Column < Columns; Column++)
{
if (ItemNumber<ItemCount)
{
if (_ColumnRendererItem* pItem=Items[ItemNumber])
{
pColumn+=sprintf(pColumn,"%-*s",(int)ColumnWidth,pItem->Text);
}
}
ItemNumber+=Rows;
}
pISInterface->Printf("%s",Row);
pColumn=Row;
Row[0]=0;
}
}
void RenderLeftToRight(class ISInterface *pISInterface)
{
if (!LongestItem)
return; // wtf.
size_t Width = pISInterface->GetTerminalWidth();
char Row[1024];
size_t Columns = (Width - LongestItem) / LongestItem;
size_t ColumnWidth;
//pISInterface->Printf("Longest Item: %d. Width: %d. ColWidth: %d. Columns: %d.",LongestItem,Width,ColumnWidth,Columns);
if (Columns<1)
{
Columns=1;
ColumnWidth=Width;
}
else if (Columns>10)
{
Columns=10;
ColumnWidth=Width/10;
}
else
ColumnWidth=Width/Columns;
size_t Column = 0;
char *pColumn=Row;
foreach(_ColumnRendererItem* pItem,i,Items)
{
pColumn+=sprintf(pColumn,"%-*s",(int)ColumnWidth,pItem->Text);
Column++;
if (Column>=Columns)
{
pISInterface->Printf("%s",Row);
Column=0;
pColumn=Row;
Row[0]=0;
}
}
if (Row[0])
pISInterface->Printf("%s",Row);
}
protected:
unsigned int ItemCount;
size_t LongestItem;
CIndex<_ColumnRendererItem *> Items;
size_t Widest;
};
#endif

View File

@ -0,0 +1,236 @@
#pragma once
struct _FileListEntry
{
char Filename[512];
char FilenameOnly[128];
FILETIME ftCreationTime;
FILETIME ftLastWriteTime;
FILETIME ftLastAccessTime;
unsigned int FileSize;
};
class CFileList
{
public:
CFileList()
{
nFiles=0;
}
~CFileList()
{
List.Cleanup();
}
void AddFile(LPWIN32_FIND_DATA pFile, char *Path)
{
_FileListEntry *pNew = new _FileListEntry;
sprintf(pNew->Filename,"%s%s",Path,pFile->cFileName);
strcpy(pNew->FilenameOnly,pFile->cFileName);
pNew->ftCreationTime=pFile->ftCreationTime;
pNew->ftLastAccessTime=pFile->ftLastAccessTime;
pNew->ftLastWriteTime=pFile->ftLastWriteTime;
pNew->FileSize=pFile->nFileSizeLow;
List+=pNew;
nFiles++;
}
char *GetPath(char *Wildcard)
{
static char Path[512];
if (char *pSlash=strrchr(Wildcard,'\\'))
{
strcpy(Path,Wildcard);
Path[(pSlash-Wildcard)+1]=0;
}
else
Path[0]=0;
return Path;
}
unsigned int EnumDirectories(char *Wildcard)
{
WIN32_FIND_DATA file;
HANDLE hSearch=FindFirstFile(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
char *Path=GetPath(Wildcard);
do
{
if (_stricmp(file.cFileName,".") && _stricmp(file.cFileName,".."))
if (file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
AddFile(&file,Path);
} while (FindNextFile(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int EnumFiles(char *Wildcard)
{
WIN32_FIND_DATA file;
HANDLE hSearch=FindFirstFile(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
char *Path=GetPath(Wildcard);
do
{
if (!(file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
AddFile(&file,Path);
} while (FindNextFile(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int EnumFilesAfter(FILETIME &filetime, char *Wildcard)
{
WIN32_FIND_DATA file;
HANDLE hSearch=FindFirstFile(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
char *Path=GetPath(Wildcard);
do
{
if (!(file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) &&
CompareFileTime(&file.ftLastWriteTime,&filetime)>0)
{
AddFile(&file,Path);
}
} while (FindNextFile(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int nFiles;
CIndex <_FileListEntry *> List;
};
struct _FileListEntryW
{
wchar_t Filename[512];
wchar_t FilenameOnly[128];
FILETIME ftCreationTime;
FILETIME ftLastWriteTime;
FILETIME ftLastAccessTime;
unsigned int FileSize;
};
class CFileListW
{
public:
CFileListW()
{
nFiles=0;
}
~CFileListW()
{
List.Cleanup();
}
void Clear()
{
List.Cleanup();
nFiles=0;
}
void AddFile(PWIN32_FIND_DATAW pFile, wchar_t *Path)
{
_FileListEntryW *pNew = new _FileListEntryW;
_snwprintf(pNew->Filename,512,L"%ls%ls",Path,pFile->cFileName);
wcsncpy(pNew->FilenameOnly,pFile->cFileName,sizeof(pNew->FilenameOnly)/sizeof(pNew->FilenameOnly[0]));
pNew->ftCreationTime=pFile->ftCreationTime;
pNew->ftLastAccessTime=pFile->ftLastAccessTime;
pNew->ftLastWriteTime=pFile->ftLastWriteTime;
pNew->FileSize=pFile->nFileSizeLow;
List+=pNew;
nFiles++;
}
inline wchar_t *ConvertSlashes(wchar_t *text)
{
wchar_t *temp=text;
while(wchar_t *pSlash=wcschr(temp,'\\'))
{
*pSlash='/';
temp=&pSlash[1];
}
return text;
}
wchar_t *GetPath(const wchar_t *Wildcard)
{
static wchar_t Path[512];
wchar_t temp[512];
wcsncpy(temp,Wildcard,512);
temp[511]=0;
wchar_t *pLastSlash=wcsrchr(temp,'\\');
if (pLastSlash)
{
wchar_t *pOtherSlash=wcsrchr(pLastSlash,'/');
if (pOtherSlash && pOtherSlash>pLastSlash)
pLastSlash=pOtherSlash;
}
else
pLastSlash=wcsrchr(temp,'/');
if (wchar_t *pSlash=pLastSlash)
{
wcsncpy(Path,temp,sizeof(Path)/sizeof(Path[0]));
Path[(pSlash-temp)+1]=0;
ConvertSlashes(Path);
}
else
Path[0]=0;
return Path;
}
unsigned int EnumDirectories(const wchar_t *Wildcard)
{
WIN32_FIND_DATAW file;
HANDLE hSearch=FindFirstFileW(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
wchar_t *Path=GetPath(Wildcard);
do
{
if (wcsicmp(file.cFileName,L".") && wcsicmp(file.cFileName,L".."))
if (file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
AddFile(&file,Path);
} while (FindNextFileW(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int EnumFiles(const wchar_t *Wildcard)
{
WIN32_FIND_DATAW file;
HANDLE hSearch=FindFirstFileW(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
wchar_t *Path=GetPath(Wildcard);
do
{
if (!(file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
AddFile(&file,Path);
} while (FindNextFileW(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int EnumFilesAfter(FILETIME &filetime, const wchar_t *Wildcard)
{
WIN32_FIND_DATAW file;
HANDLE hSearch=FindFirstFileW(Wildcard,&file);
if (hSearch==INVALID_HANDLE_VALUE)
return 0;
wchar_t *Path=GetPath(Wildcard);
do
{
if (!(file.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) &&
CompareFileTime(&file.ftLastWriteTime,&filetime)>0)
{
AddFile(&file,Path);
}
} while (FindNextFileW(hSearch,&file));
FindClose(hSearch);
return nFiles;
}
unsigned int nFiles;
CIndex <_FileListEntryW *> List;
};

View File

@ -0,0 +1,464 @@
#pragma once
class ISLavishScriptInterface
{
public:
// paths
virtual char *GetCWD(char *buffer, size_t buflen)=0;
virtual char *SetRoot(const char *Filename, char *Dest)=0;
virtual bool AddCommand(const char *Command, fLSCommand Function, bool Parse=true, bool Hidden=false)=0;
virtual bool RemoveCommand(const char *Command)=0;
virtual bool AddAlias(const char *Replace, const char *With)=0;
virtual bool RemoveAlias(const char *Replace)=0;
virtual char *GetArgs(int BeginInclusive, int EndExclusive, char *argv[], char *buf, size_t buflen)=0;
virtual char *GetArgsQuoted(int BeginInclusive, int EndExclusive, char *argv[], char *buf, size_t buflen)=0;
virtual char *GetArgsQuotedNF(int BeginInclusive, int EndExclusive, char *argv[], char *buf, size_t buflen)=0;
virtual void ExecuteTimedCommand(unsigned int DelayMS, const char *Command)=0;
virtual int ExecuteCommand(const char *Text)=0;
virtual int DataParse(const char *ToParse, char *buf, size_t buflen)=0;
virtual bool DataParse(const char *Text, LSOBJECT &Object)=0;
virtual bool RunScript(const char *Filename)=0;
virtual bool EndScript(const char *Filename)=0;
virtual bool RunCommandFile(const char *Filename)=0;
virtual bool AddTopLevelObject(const char *Name, fLSTopLevelObject Function)=0;
virtual bool RemoveTopLevelObject(const char *Name)=0;
virtual bool AddLSTypeDefinition(class LSTypeDefinition &Type)=0;
virtual bool RemoveLSTypeDefinition(class LSTypeDefinition &Type)=0;
virtual LSTypeDefinition *FindLSTypeDefinition(const char *Name, char *subtypebuf=0, size_t subtypebuflen=0)=0;
virtual fLSCommand IsCommand(const char *Name)=0;
virtual bool IsAlias(const char *Name)=0;
virtual fLSTopLevelObject IsTopLevelObject(const char *Name)=0;
virtual bool IsLSTypeDefinition(const char *Name)=0;
virtual bool ResolveCommand(const char *Text, char *buf,size_t buflen)=0;
virtual void *GetTempBuffer(unsigned int Size, void *CopyFrom=0)=0;
virtual void AddTempObject(CTempObject *pObject)=0;
virtual bool RunScriptFromBuffer(const char *Name, const char *Buffer, size_t buflen, int argc=0, char *argv[]=0, const char *CWD=0)=0;
// pre-compiled scripts
// compiled text and data sequences (improve performance of reused text)
virtual unsigned int PreParseText(const char *Text, bool bDataSequence=false)=0;
virtual bool RetrieveOriginalText(unsigned int ID, char *buf, size_t buflen)=0;
virtual bool RetrieveProcessedText(unsigned int ID, char *buf, size_t buflen)=0;
virtual bool RetrieveProcessedResult(unsigned int ID, LSOBJECT &Result)=0; // data sequence only
virtual bool FreePreParsed(unsigned int ID)=0;
// object persistence
virtual unsigned int RegisterPersistentClass(const char *Name)=0;
virtual void InvalidatePersistentClass(unsigned int Class)=0;
virtual void InvalidatePersistentObject(unsigned int Class, unsigned __int64 Value)=0;
virtual void SetPersistentClass(LSTypeDefinition *pType,unsigned int Class)=0;
// object queries
virtual unsigned int CreateQuery(const char *Text)=0;
virtual bool RetrieveQueryExpression(unsigned int ID,char *buf, size_t buflen)=0;
virtual bool QueryEvaluate(unsigned int ID,LSOBJECT &Object, bool &bResult)=0;
virtual bool FreeQuery(unsigned int ID)=0;
virtual unsigned int PersistObject(LSOBJECT &object)=0;
virtual bool GetPersistedObject(unsigned int key, LSOBJECT &out_object)=0;
virtual void ISLavishScriptInterface_06_Reserved() {}
virtual void ISLavishScriptInterface_07_Reserved() {}
virtual void ISLavishScriptInterface_08_Reserved() {}
virtual void ISLavishScriptInterface_09_Reserved() {}
virtual void ISLavishScriptInterface_10_Reserved() {}
virtual void ISLavishScriptInterface_11_Reserved() {}
virtual void ISLavishScriptInterface_12_Reserved() {}
virtual void ISLavishScriptInterface_13_Reserved() {}
virtual void ISLavishScriptInterface_14_Reserved() {}
virtual void ISLavishScriptInterface_15_Reserved() {}
virtual unsigned int AddGlobalAtom(const char *Buffer, size_t buflen)=0;
virtual bool RemoveAtom(unsigned int AtomID)=0;
virtual int ExecuteAtom(unsigned int AtomID,int argc=0, char *argv[]=0, PLSOBJECT pThisLSObject=0, PLSOBJECT pContext=0, char *ReturnBuffer=0, size_t buflen=0)=0;
virtual int ExecuteAtom(const char *Name,int argc=0, char *argv[]=0, PLSOBJECT pContext=0, char *ReturnBuffer=0, size_t buflen=0)=0;
virtual int ExecuteAtom(const char *ScriptName, const char *Name,int argc=0, char *argv[]=0, PLSOBJECT pContext=0, char *ReturnBuffer=0, size_t buflen=0)=0;
virtual unsigned int ResolveAtom(const char *Name)=0;
// enumerations
virtual unsigned int EnumAliases(fLSGenericEnumCallback Callback, void *pData)=0;
virtual unsigned int EnumCommands(fLSGenericEnumCallback Callback, void *pData)=0;
virtual unsigned int EnumLSTypeDefinitions(fLSGenericEnumCallback Callback, void *pData)=0;
virtual unsigned int EnumTopLevelObjects(fLSGenericEnumCallback Callback, void *pData)=0;
virtual unsigned int EnumScripts(fLSGenericEnumCallback Callback, void *pData)=0;
// scripts
virtual bool GetCurrentScript(char *buffer, size_t buflen)=0;
virtual bool GetScriptCWD(const char *ScriptName, char *buffer, size_t buflen)=0;
virtual bool QueueCommand(const char *ScriptName, const char *Command)=0;
virtual unsigned int GetScriptRuntime(const char *ScriptName)=0;
virtual unsigned int PauseScripts()=0;
virtual unsigned int ResumeScripts()=0;
virtual unsigned int AddAtom(const char *ScriptName, const char *Buffer, size_t buflen)=0;
virtual bool ScriptEngineActive()=0;
virtual void LavishScriptPulse()=0;
// events
virtual unsigned int RegisterEvent(const char *Name)=0;
virtual void UnregisterEvent(unsigned int EventID)=0;
virtual bool ExecuteEvent(unsigned int EventID,int BeginInclusive=0, int EndExclusive=0, char *argv[]=0, PLSOBJECT pThisLSObject=0)=0;
virtual bool AttachEventTarget(unsigned int EventID,unsigned int AtomID)=0;
virtual bool AttachEventTarget(unsigned int EventID,fLSEventTarget fCallback)=0;
virtual bool DetachEventTarget(unsigned int EventID,unsigned int AtomID)=0;
virtual bool DetachEventTarget(unsigned int EventID,fLSEventTarget fCallback)=0;
// misc
virtual unsigned int GetRuntime()=0;
virtual char *Escape(const char *text, char *buf, size_t buflen)=0;
virtual char *EscapeQuotes(const char *text, char *buf, size_t buflen) = 0;
virtual bool CalculateResult(const char *Formula, double &Result)=0;
virtual bool CalculateResult(const char *Formula, __int64 &Result)=0;
virtual void Printf(const char *Format, ...)=0;
virtual void Print(const char *Text)=0;
virtual unsigned int GetTerminalWidth()=0;
// inline functions
inline bool AddLSType(class LSTypeDefinition &Type) { return AddLSTypeDefinition(Type); }
inline bool RemoveLSType(class LSTypeDefinition &Type) { return RemoveLSTypeDefinition(Type); }
inline LSTypeDefinition *FindLSType(char *Name) { return FindLSTypeDefinition(Name); }
inline bool IsLSType(char *Name) { return IsLSTypeDefinition(Name); }
};
class ISServiceMasterInterface
{
public:
// service master
virtual HISXSERVICE RegisterService(ISXInterface *pMaster, const char *Name, fISServiceRequest RequestCallback=0)=0;
virtual bool ServiceBroadcast(ISXInterface *pMaster, HISXSERVICE hService, unsigned int MSG, void *lpData)=0;
virtual bool ServiceNotify(ISXInterface *pMaster, HISXSERVICE hService, ISXInterface *pTarget, unsigned int MSG, void *lpData)=0;
virtual bool ShutdownService(ISXInterface *pMaster, HISXSERVICE hService)=0;
};
class ISServiceClientInterface
{
public:
// service client
virtual HISXSERVICE ConnectService(ISXInterface *pClient, const char *ServiceName, fISService NotifyCallback)=0;
virtual bool ServiceRequest(ISXInterface *pClient, HISXSERVICE hService, unsigned int MSG, void *lpData)=0;
virtual void DisconnectService(ISXInterface *pClient, HISXSERVICE hService)=0;
};
class ISInputInterface
{
public:
// input
virtual bool AddHotkey(const char *Name, const char *Combo, const char *Command, bool Press=false)=0;
virtual bool IsHotkey(const char *Name)=0;
virtual bool RemoveHotkey(const char *Name)=0;
virtual bool MouseTo(int X, int Y)=0;
virtual bool GetMousePos(int &X, int &Y)=0;
virtual bool EmulateKeyPress(const char *Combo, bool Hold)=0;
virtual bool EmulateKeyRelease(const char *Combo)=0;
virtual bool EmulateTyping(const char *Text)=0;
virtual bool EmulateMousePress(unsigned int Button, bool Hold)=0;
virtual bool EmulateMouseRelease(unsigned int Button)=0;
// disable binds
virtual unsigned int SetPrintableBindsAllowed(bool bEnable)=0;
virtual unsigned int GetPrintableBindsAllowedCount()=0;
virtual void ISInputInterface_00_Reserved() {}
virtual void ISInputInterface_01_Reserved() {}
virtual void ISInputInterface_02_Reserved() {}
virtual void ISInputInterface_03_Reserved() {}
virtual void ISInputInterface_04_Reserved() {}
virtual void ISInputInterface_05_Reserved() {}
};
class ISLavishSettingsInterface
{
public:
/* DEPRECATED, TO BE REMOVED IN NEAR FUTURE ISXDK */
virtual __declspec(deprecated) bool GetSetting(char *Filename, char *Set, char *Setting, char *buf, size_t buflen)=0;
virtual __declspec(deprecated) bool SetSetting(char *Filename, char *Set, char *Setting, char *Value)=0;
virtual __declspec(deprecated) bool GetSettingb(char *Filename, char *Set, char *Setting, bool &bValue)=0;
virtual __declspec(deprecated) bool GetSettingi(char *Filename, char *Set, char *Setting, int &iValue)=0;
virtual __declspec(deprecated) bool SetSettingi(char *Filename, char *Set, char *Setting, int iValue)=0;
virtual __declspec(deprecated) bool GetSettingf(char *Filename, char *Set, char *Setting, float &fValue)=0;
virtual __declspec(deprecated) bool SetSettingf(char *Filename, char *Set, char *Setting, float fValue)=0;
virtual __declspec(deprecated) bool IsSet(char *Filename, char *Set)=0;
virtual __declspec(deprecated) bool CreateSet(char *Filename, char *Set)=0;
virtual __declspec(deprecated) bool RemoveSet(char *Filename, char *Set)=0;
virtual __declspec(deprecated) bool RemoveSetting(char *Filename, char *Set, char *Setting)=0;
virtual __declspec(deprecated) unsigned int EnumSets(char *Filename, fSetEnumCallback Callback, void *pData)=0;
virtual __declspec(deprecated) unsigned int EnumSettings(char *Filename, char *Set, fSettingEnumCallback Callback, void *pData)=0;
virtual __declspec(deprecated) bool UnloadSettings(char *Filename)=0; // Use UnloadSet
virtual __declspec(deprecated) bool SaveSettings(char *Filename)=0; // Use ExportSet
/* NEW AND IMPROVED! */
virtual unsigned int OpenSettings(const char *Filename)=0;
virtual unsigned int FindFileSet(const char *Filename)=0;
virtual unsigned int FindSet(unsigned int &ParentSetGUID, const char *Name)=0;
virtual bool SaveFileSet(const char *Filename)=0;
virtual bool ExportSet(unsigned int &SetGUID, const char *Filename)=0;
virtual bool ImportToSet(unsigned int &SetGUID, const char *Filename)=0;
virtual bool CopySet(unsigned int &ToSetGUID, unsigned int FromSetGUID)=0;
virtual bool UnloadSet(unsigned int &SetGUID)=0;
virtual bool ClearSet(unsigned int &SetGUID)=0;
virtual bool SortSet(unsigned int &SetGUID)=0;
virtual unsigned int CreateSet(unsigned int &SetGUID, const char *Name)=0;
virtual bool GetSetName(unsigned int &SetGUID, char *buf, size_t buflen)=0;
virtual bool GetSetParent(unsigned int &SetGUID, unsigned int &ParentSetGUID)=0;
virtual bool RenameSetting(unsigned int &SetGUID, const char *Setting, const char *NewName)=0;
virtual bool RemoveSetting(unsigned int &SetGUID, const char *Setting)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, const char *Value)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, bool &bValue)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, int iValue)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, float &fValue)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, unsigned int &ulValue)=0;
virtual bool AssertSetting(unsigned int &SetGUID, const char *Setting, __int64 &Value)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, char *buf, size_t buflen)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, bool &bValue)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, int &iValue)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, float &fValue)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, unsigned int &ulValue)=0;
virtual bool GetSetting(unsigned int &SetGUID, const char *Setting, __int64 &Value)=0;
virtual bool SetSetting(unsigned int &SetGUID, const char *Setting, const char *Value)=0;
virtual bool SetSetting(unsigned int &SetGUID, const char *Setting, int iValue)=0;
virtual bool SetSetting(unsigned int &SetGUID, const char *Setting, unsigned int &ulValue)=0;
virtual bool SetSetting(unsigned int &SetGUID, const char *Setting, float &fValue)=0;
virtual bool SetSetting(unsigned int &SetGUID, const char *Setting, __int64 &Value)=0;
virtual bool CreateComment(unsigned int &SetGUID, const char *Text)=0;
virtual unsigned int EnumSets(unsigned int &SetGUID, fSetEnumCallback Callback, void *pData)=0;
virtual unsigned int EnumSettings(unsigned int &SetGUID, fSettingEnumCallback Callback, void *pData)=0;
virtual void ISLavishSettingsInterface_00_Reserved() {}
virtual void ISLavishSettingsInterface_01_Reserved() {}
virtual void ISLavishSettingsInterface_02_Reserved() {}
virtual void ISLavishSettingsInterface_03_Reserved() {}
virtual void ISLavishSettingsInterface_04_Reserved() {}
virtual void ISLavishSettingsInterface_05_Reserved() {}
virtual void ISLavishSettingsInterface_06_Reserved() {}
virtual void ISLavishSettingsInterface_07_Reserved() {}
virtual void ISLavishSettingsInterface_08_Reserved() {}
virtual void ISLavishSettingsInterface_09_Reserved() {}
virtual void ISLavishSettingsInterface_10_Reserved() {}
virtual void ISLavishSettingsInterface_11_Reserved() {}
virtual void ISLavishSettingsInterface_12_Reserved() {}
virtual void ISLavishSettingsInterface_13_Reserved() {}
virtual void ISLavishSettingsInterface_14_Reserved() {}
virtual void ISLavishSettingsInterface_15_Reserved() {}
virtual void ISLavishSettingsInterface_16_Reserved() {}
virtual void ISLavishSettingsInterface_17_Reserved() {}
virtual void ISLavishSettingsInterface_18_Reserved() {}
virtual void ISLavishSettingsInterface_19_Reserved() {}
virtual void ISLavishSettingsInterface_20_Reserved() {}
};
class ISIPCInterface
{
public:
// inter-process
virtual void Relay(const char *Session, const char *Command)=0;
virtual unsigned int GetSessionCount()=0;
virtual bool GetSessionName(unsigned int nSession, char *buf, size_t buflen) = 0;
virtual void ISIPCInterface_00_Reserved() {}
virtual void ISIPCInterface_01_Reserved() {}
virtual void ISIPCInterface_02_Reserved() {}
virtual void ISIPCInterface_03_Reserved() {}
virtual void ISIPCInterface_04_Reserved() {}
virtual void ISIPCInterface_05_Reserved() {}
};
class ISNavigationInterface
{
public:
virtual unsigned int LNavAddRegion(unsigned int ParentGUID, const char *Type, const char *Name, int BeginInclusive, int EndExclusive, char *argv[])=0;
virtual bool LNavRemoveRegion(unsigned int RegionGUID)=0;
virtual unsigned int LNavAddConnection(unsigned int FromGUID, unsigned int ToGUID, int BeginInclusive, int EndExclusive, char *argv[])=0;
virtual bool LNavRemoveConnection(unsigned int ConnectionGUID)=0;
virtual unsigned int LNavResolveFQN(const char *FQN, unsigned int FromGUID=0)=0;
virtual bool LNavImportXML(unsigned int ParentGUID, const char *Filename)=0;
virtual bool LNavExportXML(unsigned int RegionGUID, const char *Filename, bool OnlyChildren)=0;
virtual void ISNavigationInterface_00_Reserved() {}
virtual void ISNavigationInterface_01_Reserved() {}
virtual void ISNavigationInterface_02_Reserved() {}
virtual void ISNavigationInterface_03_Reserved() {}
virtual void ISNavigationInterface_04_Reserved() {}
virtual void ISNavigationInterface_05_Reserved() {}
virtual void ISNavigationInterface_06_Reserved() {}
virtual void ISNavigationInterface_07_Reserved() {}
virtual void ISNavigationInterface_08_Reserved() {}
virtual void ISNavigationInterface_09_Reserved() {}
virtual void ISNavigationInterface_10_Reserved() {}
virtual void ISNavigationInterface_11_Reserved() {}
virtual void ISNavigationInterface_12_Reserved() {}
virtual void ISNavigationInterface_13_Reserved() {}
virtual void ISNavigationInterface_14_Reserved() {}
virtual void ISNavigationInterface_15_Reserved() {}
virtual void ISNavigationInterface_16_Reserved() {}
virtual void ISNavigationInterface_17_Reserved() {}
virtual void ISNavigationInterface_18_Reserved() {}
virtual void ISNavigationInterface_19_Reserved() {}
virtual void ISNavigationInterface_20_Reserved() {}
};
class ISDisplayInterface
{
public:
// display
virtual bool GetDisplaySize(unsigned int &Height, unsigned int &Width)=0;
virtual bool GetPixel(int X, int Y, RGBCOLOR &Color)=0;
virtual bool GetPixels(int X, int Y, unsigned int nRows, unsigned int nColumns, RGBCOLOR **Rows)=0;
virtual bool GetDisplayRect(enum _D3DXIMAGE_FILEFORMAT format, bool front_buffer, RECT *optional_area, struct ID3DXBuffer **ppScreenshot)=0;
virtual void ISDisplayInterface_01_Reserved() {}
virtual void ISDisplayInterface_02_Reserved() {}
virtual void ISDisplayInterface_03_Reserved() {}
virtual void ISDisplayInterface_04_Reserved() {}
virtual void ISDisplayInterface_05_Reserved() {}
virtual void ISDisplayInterface_06_Reserved() {}
virtual void ISDisplayInterface_07_Reserved() {}
virtual void ISDisplayInterface_08_Reserved() {}
virtual void ISDisplayInterface_09_Reserved() {}
virtual void ISDisplayInterface_10_Reserved() {}
virtual void ISDisplayInterface_11_Reserved() {}
virtual void ISDisplayInterface_12_Reserved() {}
virtual void ISDisplayInterface_13_Reserved() {}
virtual void ISDisplayInterface_14_Reserved() {}
virtual void ISDisplayInterface_15_Reserved() {}
virtual void ISDisplayInterface_16_Reserved() {}
virtual void ISDisplayInterface_17_Reserved() {}
virtual void ISDisplayInterface_18_Reserved() {}
virtual void ISDisplayInterface_19_Reserved() {}
virtual void ISDisplayInterface_20_Reserved() {}
};
class ISLavishVMInterface
{
public:
/* LavishVM */
virtual bool IsAvailable()=0;
virtual bool TryInitialize()=0;
virtual bool RegisterLibrary(const char *Name,fGetAPI)=0;
virtual bool UnregisterLibrary(const char *Name)=0;
virtual bool Execute(const char *Domain, const char *AssemblyName, int argc=0, const char *argv[]=0)=0;
virtual bool UnloadDomain(const char *Name)=0;
virtual unsigned int EnumDomains(fDomainEnumCallback, void *pData)=0;
virtual bool IsDomainActive(const char *Name)=0;
/* Threading (including LavishVM) */
virtual void FrameLock()=0;
virtual void FrameUnlock()=0;
virtual bool FrameTryLock()=0;
virtual void FrameWait(bool bLock)=0;
};
class ISInterface : public ISLavishScriptInterface,
public ISServiceMasterInterface,
public ISServiceClientInterface,
public ISInputInterface,
public ISLavishSettingsInterface,
public ISIPCInterface,
public ISNavigationInterface,
public ISDisplayInterface,
public ISLavishVMInterface
{
public:
virtual unsigned int GetVersion()=0;
virtual unsigned int GetBuildNumber()=0;
virtual unsigned int GetExtensionSetGUID(const char *Extension)=0;
virtual unsigned int GetScriptSetGUID(const char *Script)=0;
virtual unsigned int CreateExtensionSet(const char *Extension)=0;
virtual unsigned int CreateScriptSet(const char *Script)=0;
virtual unsigned int GetGameSetGUID()=0;
virtual unsigned int GetProfileSetGUID()=0;
virtual bool LoadExtension(const char *Filename)=0;
virtual bool UnloadExtension(const char *Filename, bool &denied_by_extension)=0;
virtual bool IsExtensionLoaded(const char *Filename)=0;
// High Stealth is intended for temporarily increasing stealth while an application
// performs scanning and detection methods
virtual bool HighStealthEnabled()=0;
virtual void EnableHighStealth()=0;
virtual void DisableHighStealth()=0;
// paths
virtual char *GetInnerSpacePath(char *buffer, size_t buflen)=0;
virtual char *GetLogsPath(const char *extension_subdir, char *buffer, size_t buflen) = 0;
virtual char *GetSettingsPath(char *buffer, size_t buflen) = 0;
virtual char *GetNETProgramsPath(char *buffer, size_t buflen) = 0;
virtual char *GetExtensionsPath(char *buffer, size_t buflen) = 0;
virtual char *GetInterfacePath(char *buffer, size_t buflen) = 0;
virtual char *GetLavishScriptModulesPath(char *buffer, size_t buflen) = 0;
virtual char *GetScreenshotsPath(char *buffer, size_t buflen) = 0;
virtual char *GetScriptsPath(char *buffer, size_t buflen) = 0;
// hud
virtual bool AddElement(const char *Name, const char *Data, int X, int Y, unsigned int Color, const char *Group="Default")=0;
virtual bool RemoveElement(const char *Name)=0;
// console
virtual void ClearConsole()=0;
virtual void EnableStealth()=0;
virtual bool StealthEnabled()=0;
virtual void StoreInnerSpaceSettings() {};
virtual bool GetLavishScript2Environment_(unsigned int LS2MODULE_SDK_VERSION, void **ppEnvironment)=0;
bool GetLavishScript2Environment(unsigned int LS2MODULE_SDK_VERSION, void **ppEnvironment)
{
if (GetBuildNumber()>=5671)
return GetLavishScript2Environment_(LS2MODULE_SDK_VERSION,ppEnvironment);
return false;
}
virtual void ISInterface_01_Reserved() {}
virtual void ISInterface_02_Reserved() {}
virtual void ISInterface_03_Reserved() {}
virtual void ISInterface_04_Reserved() {}
virtual void ISInterface_05_Reserved() {}
virtual void ISInterface_06_Reserved() {}
virtual void ISInterface_07_Reserved() {}
virtual void ISInterface_08_Reserved() {}
virtual void ISInterface_09_Reserved() {}
virtual void ISInterface_10_Reserved() {}
virtual void ISInterface_11_Reserved() {}
virtual void ISInterface_12_Reserved() {}
virtual void ISInterface_13_Reserved() {}
virtual void ISInterface_14_Reserved() {}
virtual void ISInterface_15_Reserved() {}
virtual void ISInterface_16_Reserved() {}
virtual void ISInterface_17_Reserved() {}
virtual void ISInterface_18_Reserved() {}
virtual void ISInterface_19_Reserved() {}
virtual void ISInterface_20_Reserved() {}
};

View File

@ -0,0 +1,100 @@
#pragma once
#ifdef LGUI_LIBRARY
#define LGUI_API
#else
#ifdef LGUI_EXPORTS
#define LGUI_API __declspec(dllexport)
#else
#define LGUI_API __declspec(dllimport)
#endif
#endif
#include <map>
//#include <string>
#include <set>
using namespace std;
#define LGUI_VERSION 0x12
#define LGUI_VERSIONSTRING "0.73"
class LGUIPreParse
{
public:
LGUI_API LGUIPreParse(const char *Text);
LGUI_API LGUIPreParse();
LGUI_API ~LGUIPreParse();
LGUI_API void Clear();
LGUI_API void PreParse(const char *Text);
LGUI_API bool RetrieveProcessedText(char *buf, unsigned int buflen);
inline const char *GetOriginalText()
{
return OriginalText;
}
inline unsigned int GetID()
{
return ID;
}
protected:
const char *OriginalText;
unsigned int ID;
};
class LGUIDataSequence
{
public:
LGUI_API LGUIDataSequence();
LGUI_API LGUIDataSequence(const char *DataSequence);
LGUI_API ~LGUIDataSequence();
LGUI_API void Clear();
LGUI_API void PreParse(const char *DataSequence);
LGUI_API bool RetrieveOriginalText(char *buf, unsigned int buflen);
LGUI_API bool RetrieveProcessedText(char *buf, unsigned int buflen);
LGUI_API bool RetrieveProcessedResult(LSOBJECT &Result);
inline unsigned int GetID()
{
return ID;
}
protected:
unsigned int ID;
};
#include "LGUIEmbeddedScript.h"
#include "LGUITexture.h"
#include "LGUIFont.h"
#include "LGUIElement.h"
#include "LGUIFrame.h"
#include "LGUIContextMenu.h"
#include "LGUIWindow.h"
#include "LGUIText.h"
#include "LGUITextEntry.h"
#include "LGUITextEdit.h"
#include "LGUICommandEntry.h"
#include "LGUIConsole.h"
#include "LGUIHudElement.h"
#include "LGUIScreen.h"
#include "LGUIButton.h"
#include "LGUICommandButton.h"
#include "LGUICheckBox.h"
#include "LGUICommandCheckBox.h"
#include "LGUISlider.h"
#include "LGUIVariableSlider.h"
#include "LGUIScrollBar.h"
#include "LGUIMessageBox.h"
#include "LGUIGauge.h"
#include "LGUIVariableGauge.h"
#include "LGUIListBox.h"
#include "LGUIComboBox.h"
#include "LGUITabControl.h"
#include "LGUITooltip.h"
#include "LGUITable.h"
#include "LGUIMap.h"
#include "LGUITree.h"
#include "LGUIManager.h"
#define SELECT(possiblevalue,defaultvalue) ((possiblevalue)?(possiblevalue):(defaultvalue))

View File

@ -0,0 +1,55 @@
#pragma once
#include "LGUIelement.h"
struct _CreateButton : public _CreateElement
{
char *Text; // may be 0 for no text
// char *Font;
// unsigned int FontSize; // may be 0 to use default
// unsigned int TextColor; // may be 0 to use default (use 0xFF000000 for solid black)
_CreateFont Font;
unsigned int BackgroundColor; // may be 0 to use default (0xFF000000 for solid black)
bool DefaultTextures; // // You may create textures directly if you do not use default textures flag
unsigned int Border;
unsigned int BorderColor; // may be 0 to use default (use 0xFF000000 for solid black)
};
class LGUIButton :
public LGUIElement
{
public:
LGUI_API LGUIButton(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIButton(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateButton &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
// -- XML Properties --
LGUIPreParse Text;
LGUIFont *pFont;
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
LGUITexture *pTexture;
LGUITexture *pTexturePressed;
LGUITexture *pTextureHover;
// --------------------
bool bDown;
};

View File

@ -0,0 +1,34 @@
#pragma once
#include "LGUIelement.h"
class LGUICheckBox :
public LGUIElement
{
public:
LGUI_API LGUICheckBox(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUICheckBox(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
// -- XML Properties --
LGUIPreParse Text;
LGUIFont *pFont;
LGUITexture *pTexture;
LGUITexture *pTexturePressed;
LGUITexture *pTextureHover;
LGUITexture *pTextureChecked;
LGUITexture *pTextureCheckedPressed;
LGUITexture *pTextureCheckedHover;
// --------------------
bool bDown;
bool bChecked;
};

View File

@ -0,0 +1,40 @@
#pragma once
class LGUIComboBox :
public LGUIElement
{
public:
LGUI_API LGUIComboBox(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIComboBox(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void RecalculateSize(bool RecalculateChildren);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API void OnLMouseDownOther(LGUIElement *pOther);
// -- XML Properties --
LGUITexture *pTexture;
LGUITexture *pButtonTexture;
LGUIFont *pFont;
unsigned int Border;
unsigned int FullHeight;
unsigned int ButtonWidth;
LGUIEmbeddedScript *pOnSelect;
// ----------------------
LGUIListBox *pListBox;
bool bDown;
unsigned int NormalHeight;
int Selection;
};

View File

@ -0,0 +1,23 @@
#pragma once
#include "LGUIelement.h"
class LGUICommandButton :
public LGUIButton
{
public:
LGUI_API LGUICommandButton(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUICommandButton(void);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseUp(POINT2I &pt);
// -- XML Properties --
char *Command;
char *Console;
// --------------------
};

View File

@ -0,0 +1,27 @@
#pragma once
#include "LGUIelement.h"
class LGUICommandCheckBox :
public LGUICheckBox
{
public:
LGUI_API LGUICommandCheckBox(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUICommandCheckBox(void);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API void Render();
// -- XML Properties --
LGUIPreParse Data;
char *Command;
char *CommandChecked;
char *Console;
// --------------------
};

View File

@ -0,0 +1,33 @@
#pragma once
#include "LGUItextentry.h"
class LGUICommandEntry :
public LGUITextEntry
{
public:
LGUI_API LGUICommandEntry(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUICommandEntry(void);
LGUI_API bool IsTypeOf(char *TestFactory);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API virtual bool OnKeyDown(unsigned int VKey);
LGUI_API virtual void HandleEnter();
LGUI_API virtual void PasteClipboard();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void OnCommand(char *Text);
//
char *Console;
//
unsigned int CmdHistorySize;
char **CmdHistory;
int HistoryLine;
int HistoryView;
int HistoryLines;
void InsertCmdHistory(char *Text);
LGUIEmbeddedScript *pOnCommand;
};

View File

@ -0,0 +1,80 @@
#pragma once
#include "LGUIelement.h"
class LGUIConsoleSelector
{
public:
LGUI_API LGUIConsoleSelector(class LGUIConsole *pConsole);
LGUI_API LGUIConsoleSelector(const char *FullyQualifiedName);
LGUI_API ~LGUIConsoleSelector();
protected:
char PreviousConsole[1024];
};
class LGUIConsole :
public LGUIElement
{
public:
LGUI_API LGUIConsole(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIConsole(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void SizeRecalculated(bool Changed);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API virtual void HandlePageUp();
LGUI_API virtual void HandlePageDown();
LGUI_API virtual void HandleUp();
LGUI_API virtual void HandleDown();
LGUI_API void SetFontSize(unsigned int NewHeight);
LGUI_API void SnapToGrid(POINT2I &pt);
LGUI_API void CopySelection();
LGUI_API void SplitFixed(char *in, size_t MaxWidth);
LGUI_API void Clear();
LGUI_API void Printf(const char *szFormat, ...);
LGUI_API void Print(const char *Text);
// -- XML PROPERTIES --
LGUIFixedFont *pFont;
unsigned int Border;
unsigned int BorderColor;
unsigned int ScrollbackColor;
unsigned int BackgroundColor;
unsigned int SelectionColor;
LGUITexture *pTexture;
LGUITexture *pTextureScrollback;
// ----------------------
unsigned int BackBufferSize;
char **BackBuffer;
int LastLine;
class LGUIScrollBar *pVerticalBar;
int ScrollBack;
int VisibleLines;
bool bSelect;
RECT Selection;
protected:
LGUI_API virtual void AddLineInternal(char *Line);
};

View File

@ -0,0 +1,170 @@
#pragma once
enum ContextMenuType
{
CMT_ITEM=1,
CMT_SUBMENU=2,
CMT_SEPARATOR=3,
};
class LGUIContextMenuNode
{
public:
LGUIContextMenuNode(class LGUIContextMenu *p_pParent, ContextMenuType p_Type, unsigned int p_ID=0);
LGUIContextMenuNode(class LGUIContextMenu *p_pParent, LGUIContextMenuNode *pInsertAfter, ContextMenuType p_Type, unsigned int ID=0);
virtual ~LGUIContextMenuNode();
RECT r;
virtual size_t Render()=0;
virtual void OnLMouseUp()=0;
class LGUIContextMenu *pMenu;
LGUIContextMenuNode *pPrev;
LGUIContextMenuNode *pNext;
ContextMenuType Type;
unsigned int ID;
};
class LGUIContextMenuItem : public LGUIContextMenuNode
{
public:
LGUIContextMenuItem(class LGUIContextMenu *p_pParent, char *p_Text, unsigned int p_ID=0);
~LGUIContextMenuItem();
size_t Render();
void OnLMouseUp();
char *Text;
bool bChecked;
};
class LGUIContextMenuSubmenu : public LGUIContextMenuNode
{
public:
LGUIContextMenuSubmenu(class LGUIContextMenu *p_pParent, char *Text, class CContextMenuHandler *p_pHandler, unsigned int p_ID=0);
~LGUIContextMenuSubmenu();
size_t Render();
void OnLMouseUp();
char *Text;
class CContextMenuHandler *pHandler;
};
class LGUIContextMenuSeparator : public LGUIContextMenuNode
{
public:
LGUIContextMenuSeparator(class LGUIContextMenu *p_pParent);
~LGUIContextMenuSeparator();
size_t Render();
void OnLMouseUp()
{
}
};
class LGUIContextMenu :
public LGUIFrame
{
public:
LGUIContextMenu(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
~LGUIContextMenu(void);
bool IsTypeOf(char *TestFactory);
// class LSTypeDefinition *GetLSType();
bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
bool Create(class CContextMenuHandler *p_pMenuHandler, class XMLNode *pTemplate=0);
void Render();
bool OnLMouseUp(POINT2I &pt);
bool OnLMouseDown(POINT2I &pt);
bool OnMouseMove(POINT2I &pt);
unsigned int AddItem(char *Text, unsigned int ID=0);
unsigned int AddSubmenu(char *Text, CContextMenuHandler *pHandler, unsigned int ID=0);
unsigned int AddSeparator();
bool GetItemCheck(unsigned int ID, bool &bChecked);
void SetItemCheck(unsigned int ID, bool bChecked);
void OnKeyboardExit(LGUIElement *pNewFocus);
void OnLMouseDownOther(LGUIElement *pOther);
// -- From XML --
LGUIFont *pFont;
unsigned int HighlightColor;
LGUITexture *pItemTexture;
LGUITexture *pSubmenuTexture;
LGUITexture *pSeparatorTexture;
LGUITexture *pHighlightItemTexture;
LGUITexture *pHighlightSubmenuTexture;
LGUITexture *pItemCheckTexture;
// --------------------------------
unsigned int ParentMenuID;
unsigned int ChildMenuID;
unsigned int NextID;
LGUIContextMenuNode *pItems;
unsigned int nItems;
LGUIContextMenuNode *pMouseOver;
class CContextMenuHandler *pMenuHandler;
};
class CContextMenuHandler
{
public:
LGUI_API CContextMenuHandler()
{
pMenu=0;
pTemplate=0;
pChildMenu=0;
pParentMenu=0;
}
LGUI_API virtual ~CContextMenuHandler()
{
DestroyMenu();
}
inline bool IsMenu()
{
return pMenu!=0;
}
inline void SetTemplate(class XMLNode *pNewTemplate)
{
pTemplate=pNewTemplate;
}
bool Create(CContextMenuHandler *p_pParentMenu, unsigned int ParentItemID, int X, int Y);
LGUI_API bool Create(int X, int Y);
LGUI_API unsigned int AddItem(char *Text, unsigned int ID=0);
LGUI_API unsigned int AddSubMenu(char *Text, CContextMenuHandler *pHandler, unsigned int ID=0);
LGUI_API unsigned int AddSeparator();
LGUI_API bool GetItemCheck(unsigned int ID, bool &bChecked);
LGUI_API void SetItemCheck(unsigned int ID, bool bChecked);
LGUI_API virtual void OnCreate(unsigned int ParentItemID) {}
virtual void OnClick(unsigned int ItemID)=0;
LGUI_API void DestroyMenu(bool bParentsToo=false);
LGUI_API virtual void OnMenuDestroyed()
{
pMenu=0;
}
private:
class XMLNode *pTemplate;
class LGUIContextMenu *pMenu;
class CContextMenuHandler *pChildMenu;
class CContextMenuHandler *pParentMenu;
};

View File

@ -0,0 +1,687 @@
#pragma once
#include "LGUIManager.h"
#define NOTIFICATION_USER (0x10000000)
#define NOTIFICATION_NULL 0
#define NOTIFICATION_CLICKED 1
//#define NOTIFICATION_CLOSE 2
#define NOTIFICATION_CHANGETEXT 3
#define NOTIFICATION_CHANGENUMBER 4
#define NOTIFICATION_ENTER 5
#define NOTIFICATION_LMOUSEDOWN 6
#define NOTIFICATION_LMOUSEUP NOTIFICATION_CLICKED
#define NOTIFICATION_RMOUSEDOWN 7
#define NOTIFICATION_RMOUSEUP 8
#define NOTIFICATION_CHANGESELECTION 9
#define NOTIFICATION_LMOUSEDOUBLECLICK 10
#define NOTIFICATION_RMOUSEDOUBLECLICK 11
#define NOTIFICATION_DOUBLECLICKSELECTION 12
#define NOTIFICATION_CHANGEORDER 13
#define NOTIFICATION_MOUSEMOVE 14
#define NOTIFICATION_MOUSEWHEEL 15
#define NOTIFICATION_FONTCHANGED 50
#define NOTIFICATION_DELETING 51
enum eElementPositionType
{
EPT_FIXED=0,
EPT_VARIABLE=1,
EPT_PERCENT=2,
EPT_REVERSE_FIXED=3,
};
enum eElementFadeState
{
EFS_NORMAL=0,
EFS_DELAYING=1,
EFS_FADING=2,
EFS_FADED=3,
EFS_IN_DELAYING=4,
EFS_IN_FADING=5,
EFS_IN_FADED=6,
};
struct ElementPosition
{
eElementPositionType Type;
union
{
unsigned int Size;
float fSize;
};
};
class XMLHelper
{
public:
LGUI_API static bool GetToggle(class XMLNode *pXML, const char *Name, bool Default=0);
LGUI_API static unsigned int GetIntValue(class XMLNode *pXML, const char *Name, unsigned int Default=0);
LGUI_API static float GetFloatValue(class XMLNode *pXML, const char *Name, float Default=0.0f);
LGUI_API static unsigned int GetHexValue(class XMLNode *pXML, const char *Name, unsigned int Default=0);
LGUI_API static unsigned int GetFactorValue(class XMLNode *pXML, const char *Name, float &FactorResult, unsigned int Default=0);
LGUI_API static unsigned int GetElementPositionValue(class XMLNode *pXML, const char *Name, ElementPosition &EPResult, unsigned int Default=0);
LGUI_API static bool GetElementPositionValueEx(class XMLNode *pXML, const char *Name, ElementPosition &EPResult, unsigned int &ulResult);
LGUI_API static const char *GetStringValue(class XMLNode *pXML, const char *Name, const char *Default = "");
LGUI_API static class XMLNode *GetChild(class XMLNode *pXML, const char *Name);
LGUI_API static const char *GetText(class XMLNode *pXML);
LGUI_API static class XMLNode *GetPrev(class XMLNode *pXML);
LGUI_API static class XMLNode *GetParent(class XMLNode *pXML);
LGUI_API static class XMLNode *GetNext(class XMLNode *pXML);
LGUI_API static class XMLNode *GetFirstChild(class XMLNode *pXML);
LGUI_API static unsigned int GetIntAttribute(class XMLNode *pXML, const char *Name, unsigned int Default=0);
LGUI_API static float GetFloatAttribute(class XMLNode *pXML, const char *Name, float Default=0.0f);
LGUI_API static unsigned int GetHexAttribute(class XMLNode *pXML, const char *Name, unsigned int Default=0);
LGUI_API static unsigned int GetFactorAttribute(class XMLNode *pXML, const char *Name, float &FactorResult, unsigned int Default=0);
LGUI_API static unsigned int GetElementPositionAttribute(class XMLNode *pXML, const char *Name, ElementPosition &EPResult, unsigned int Default=0);
LGUI_API static const char *GetStringAttribute(class XMLNode *pXML, const char *Name, const char *Default="");
static inline bool GetTemplateToggle(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, bool Default=0)
{
Default=GetToggle(pTemplate,Name,Default);
return GetToggle(pXML,Name,Default);
}
static inline unsigned int GetTemplateIntValue(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, unsigned int Default=0)
{
Default=GetIntValue(pTemplate,Name,Default);
return GetIntValue(pXML,Name,Default);
}
static inline float GetTemplateFloatValue(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, float Default=0)
{
Default=GetFloatValue(pTemplate,Name,Default);
return GetFloatValue(pXML,Name,Default);
}
static inline unsigned int GetTemplateHexValue(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, unsigned int Default=0)
{
Default=GetHexValue(pTemplate,Name,Default);
return GetHexValue(pXML,Name,Default);
}
static inline unsigned int GetTemplateFactorValue(class XMLNode *pXML, const char *Name, float &FactorResult, class XMLNode *pTemplate)
{
float TempFactorResult;
unsigned int Default=GetFactorValue(pTemplate,Name,TempFactorResult,0);
unsigned int Ret=GetFactorValue(pXML,Name,FactorResult,0);
if (!Ret && !FactorResult)
{
FactorResult=TempFactorResult;
return Default;
}
return Ret;
}
static inline unsigned int GetTemplateElementPositionValue(class XMLNode *pXML, const char *Name, ElementPosition &EPResult, class XMLNode *pTemplate)
{
unsigned int Ret=0;
if (GetElementPositionValueEx(pXML,Name,EPResult,Ret))
return Ret;
return GetElementPositionValue(pTemplate,Name,EPResult,0);
}
static inline const char *GetTemplateStringValue(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, const char *Default="")
{
Default=GetStringValue(pTemplate,Name,Default);
return GetStringValue(pXML,Name,Default);
}
static inline class XMLNode *GetTemplateChild(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate)
{
class XMLNode *pNode=GetChild(pXML,Name);
if (pNode)
return pNode;
return GetChild(pTemplate,Name);
}
static inline unsigned int GetTemplateIntAttribute(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, unsigned int Default=0)
{
Default=GetIntAttribute(pTemplate,Name,Default);
return GetIntAttribute(pXML,Name,Default);
}
static inline float GetTemplateFloatAttribute(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, float Default=0)
{
Default=GetFloatAttribute(pTemplate,Name,Default);
return GetFloatAttribute(pXML,Name,Default);
}
static inline unsigned int GetTemplateHexAttribute(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate,unsigned int Default=0)
{
Default=GetHexAttribute(pTemplate,Name,Default);
return GetHexAttribute(pXML,Name,Default);
}
static inline unsigned int GetTemplateFactorAttribute(class XMLNode *pXML, const char *Name, float &FactorResult, class XMLNode *pTemplate)
{
float TempFactorResult;
unsigned int Default=GetFactorAttribute(pTemplate,Name,TempFactorResult,0);
unsigned int Ret=GetFactorAttribute(pXML,Name,FactorResult,0);
if (!Ret && !FactorResult)
{
FactorResult=TempFactorResult;
return Default;
}
return Ret;
}
static inline const char *GetTemplateStringAttribute(class XMLNode *pXML, const char *Name, class XMLNode *pTemplate, const char *Default = "")
{
Default=GetStringAttribute(pTemplate,Name,Default);
return GetStringAttribute(pXML,Name,Default);
}
};
struct _Line
{
POINT2I A;
POINT2I B;
};
/*
struct _TexturedPoint
{
POINT2I pt;
LGUITexture *pTexture;
unsigned int Weight;
};
/**/
struct _CreateElement
{
int X;
int Y;
unsigned int Width;
unsigned int Height;
ElementPosition XFactor;
ElementPosition YFactor;
ElementPosition HeightFactor;
ElementPosition WidthFactor;
bool bVisible;
char bAlwaysOnTop;
};
struct FullElementPosition
{
int X;
ElementPosition XFactor;
int Y;
ElementPosition YFactor;
unsigned int Height;
ElementPosition HeightFactor;
unsigned int Width;
ElementPosition WidthFactor;
};
class LGUIElement
{
public:
LGUI_API LGUIElement(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API virtual ~LGUIElement();
LGUI_API void Delete(); // dont call this. use Destroy() instead.
LGUI_API bool TextureFromArgs(int argc, char *argv[], LGUITexture **ppTexture);
LGUI_API virtual bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API virtual LGUITexture *TextureFromXML(class XMLNode *pXML, const char *ValueName, class XMLNode *pTemplate = 0);
LGUI_API virtual LGUIFont *FontFromXML(class XMLNode *pXML, const char *ValueName, class XMLNode *pTemplate = 0);
LGUI_API virtual LGUIFixedFont *FixedFontFromXML(class XMLNode *pXML, const char *ValueName, class XMLNode *pTemplate = 0);
LGUI_API virtual LGUIEmbeddedScript *EmbeddedScriptFromXML(class XMLNode *pXML, const char *ValueName, class XMLNode *pTemplate = 0, const char *Parameters = "");
LGUI_API virtual bool IsTypeOf(char *TestFactory);
LGUI_API virtual void RecalculateSize(bool RecalculateChildren);
LGUI_API virtual void RecalculateChildrenSize();
LGUI_API virtual void SizeRecalculated(bool Changed) {};
LGUI_API virtual void Render();
LGUI_API virtual void RenderChildren();
LGUI_API virtual void Show(bool bShow) {bVisible=bShow;}
LGUI_API virtual void Center();
LGUI_API virtual bool OnLMouseUp(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnLMouseDown(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnRMouseUp(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnRMouseDown(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnLMouseDoubleClick(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnRMouseDoubleClick(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnMouseMove(POINT2I &pt);// {return false;}
LGUI_API virtual bool OnMouseWheel(int Offset);// {return false;};
LGUI_API virtual bool OnKeyUp(unsigned int VKey);// {return false;}
LGUI_API virtual bool OnKeyDown(unsigned int VKey);// {return false;}
LGUI_API virtual void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value) {if (pParent) pParent->OnNotify(pElement,Notification,Value);};
LGUI_API virtual void OnMouseEnter(POINT2I &pt);// {}
LGUI_API virtual void OnMouseExit(LGUIElement *pNewFocus);// {}
LGUI_API virtual void OnKeyboardEnter();// {}
LGUI_API virtual void OnKeyboardExit(LGUIElement *pNewFocus);// {}
LGUI_API virtual void OnLMouseDownOther(LGUIElement *pOther) {}
LGUI_API virtual void OnCreate() {}
LGUI_API virtual void OnDestroy() {}
LGUI_API virtual class LSTypeDefinition *GetLSType();
LGUI_API virtual bool GetStoragePosition(int &StoreX, int &StoreY, unsigned int &StoreWidth, unsigned int &StoreHeight);
inline LGUIElement *GetParent() {return pParent;}
inline LGUIElement *GetFirstChild() {return pFirstChild;}
inline LGUIElement *GetLastChild() {return pLastChild;}
inline LGUIElement *GetPrev() {return pPrev;}
inline LGUIElement *GetNext() {return pNext;}
LGUI_API LGUIElement *Walk(bool bRequireVisible, LGUIElement *pStopAtParent);
LGUI_API LGUIElement *WalkReverse(bool bRequireVisible, LGUIElement *pStopAtParent);
inline void SetNext(LGUIElement *pElement) {pNext=pElement;}
inline void SetPrev(LGUIElement *pElement) {pPrev=pElement;}
inline void SetLastChild(LGUIElement *pElement) {pLastChild=pElement;}
inline void SetFirstChild(LGUIElement *pElement) {pFirstChild=pElement;}
inline bool IsDescendentOf(LGUIElement *pElement)
{
LGUIElement *pTest=pParent;
while(pTest)
{
if (pElement==pTest)
return true;
pTest=pTest->pParent;
}
return false;
}
inline char *GetName() {return Name;}
inline char *GetFullName() {return FullName;}
inline char *GetFactory() {return Factory;}
LGUI_API void AddChild(LGUIElement *pElement);
LGUI_API void DeleteChild(LGUIElement *pElement);
LGUI_API virtual LGUIElement *FindChild(const char *Name);
LGUI_API LGUIElement *FindUsableChild(const char *Name, const char *Type);
inline void SetLeft(int NewValue) {X=NewValue;}
inline void SetTop(int NewValue) {Y=NewValue;}
inline void GetXFactor(ElementPosition &EP) {EP=XFactor;}
inline void GetYFactor(ElementPosition &EP) {EP=YFactor;}
inline void GetHeightFactor(ElementPosition &EP) {EP=HeightFactor;}
inline void GetWidthFactor(ElementPosition &EP) {EP=WidthFactor;}
inline void SetWidth(unsigned int NewValue) {Width=NewValue;}
inline void SetHeight(unsigned int NewValue) {Height=NewValue;}
inline int GetRight() {return X+Width;}
inline int GetBottom() {return Y+Height;}
inline int GetTop() {return Y;}
inline int GetLeft() {return X;}
inline unsigned int GetHeight() {return Height;}
inline unsigned int GetWidth() {return Width;}
inline unsigned int GetID() {return ID;}
inline bool IsVisible() {return bVisible;}
LGUI_API bool IsReallyVisible();
inline unsigned char GetAlwaysOnTop() {return bAlwaysOnTop;}
inline void SetAlwaysOnTop(unsigned char NewValue) { bAlwaysOnTop = NewValue; }
inline bool GetStorePosition() {return bStorePosition;}
inline void Destroy() {pParent->DeleteChild(this);}
inline void GetOriginalPosition(FullElementPosition &Dest) {Dest=OriginalPosition;}
inline void ResetPosition()
{
X=OriginalPosition.X;
Y=OriginalPosition.Y;
Height=OriginalPosition.Height;
Width=OriginalPosition.Width;
XFactor=OriginalPosition.XFactor;
YFactor=OriginalPosition.YFactor;
HeightFactor=OriginalPosition.HeightFactor;
WidthFactor=OriginalPosition.WidthFactor;
RecalculateSize(true);
}
LGUI_API virtual bool SetFocus();
LGUI_API virtual bool SetMouseOver();
LGUI_API bool IsMouseOver();
LGUI_API bool IsFocus();
LGUI_API bool FillRect(RECT &r,unsigned int Color);
LGUI_API bool FillRectBordered(RECT &r,unsigned int Color,unsigned int BorderSize,unsigned int BorderColor);
LGUI_API bool DrawBorder(RECT &r,unsigned int BorderSize,unsigned int BorderColor);
LGUI_API bool TexturedRect(RECT &r,LGUITexture *pTexture);
LGUI_API bool TexturedRectBordered(RECT &r,LGUITexture *pTexture, unsigned int BorderSize);
LGUI_API bool TexturedRects(unsigned int nRects, LGUITexturedRect *pRects);
LGUI_API bool FillTriangle(LGUITriangle &t,unsigned int Color);
LGUI_API bool TexturedTriangle(LGUITriangle &t,LGUITexture *pTexture);
LGUI_API bool TexturedTriangles(unsigned int nTriangles, LGUITexturedTriangle *pTriangles);
LGUI_API bool DrawLine(_Line &Line, LGUITexture *pTexture, unsigned int Weight=1);
LGUI_API bool DrawLines(_Line *Lines, unsigned int nLines, LGUITexture *pTexture, unsigned int Weight=1);
LGUI_API bool DrawLine(_Line &Line, unsigned int Color, unsigned int Weight=1);
LGUI_API bool DrawLines(_Line *Lines, unsigned int nLines, unsigned int Color, unsigned int Weight=1);
// LGUI_API bool DrawPoint(_ColoredPoint &pt);
// LGUI_API bool DrawPoints(_ColoredPoint *Points, unsigned int nPoints);
LGUI_API size_t DrawText(LGUIFont *pFont,const char *Text,int X, int Y);
LGUI_API size_t DrawTextClipped(LGUIFont *pFont,const char *Text,int X, int Y);
LGUI_API size_t DrawTextCenter(LGUIFont *pFont,const char *Text,int X, int Y);
LGUI_API size_t DrawTextRight(LGUIFont *pFont,const char *Text,int X, int Y);
LGUI_API size_t DrawTextClipped(LGUIFont *pFont,const char *Text,int X, int Y, int RightX);
LGUI_API size_t DrawTextCenter(LGUIFont *pFont,const char *Text,int X, int Y, int RightX);
LGUI_API size_t DrawTextRight(LGUIFont *pFont,const char *Text,int X, int Y, int RightX);
LGUI_API size_t DrawColoredText(LGUIFont *pFont,const char *buffer, int X, int Y);
LGUI_API size_t DrawColoredTextClipped(LGUIFont *pFont,const char *buffer, int X, int Y, int RightX);
static LGUI_API void StripColor(const char *In, char *Out);
static LGUI_API size_t ColorStrlen(const char *Text);
LGUI_API virtual LGUIElement *FindMouseOver(POINT2I &pt, LGUIElement *pStart);
LGUI_API bool HitTest(POINT2I &pt);
inline void SetAbsolute(POINT2I &pt) {Absolute=pt;}
inline void GetAbsolute(POINT2I &pt) {pt=Absolute;}
inline bool GetLeftClickThru() {return bLeftClickThru;}
inline bool GetRightClickThru() {return bRightClickThru;}
inline void SetLeftClickThru(bool Value) {bLeftClickThru=Value;}
inline void SetRightClickThru(bool Value) {bRightClickThru=Value;}
inline void SetAbsoluteAlpha(float Value) {AbsoluteAlpha=Value;}
inline float GetAbsoluteAlpha() {return AbsoluteAlpha;}
inline void SetAlpha(float Value) {AlphaLevel=Value;}
inline float GetAlpha() {return AlphaLevel;}
inline void SetFadeAlpha(float Value) {FadeAlphaLevel=Value;}
inline float GetFadeAlpha() {return FadeAlphaLevel;}
inline unsigned int GetFadeDelay() {return FadeDelay;}
inline void SetFadeDelay(unsigned int Value) {FadeDelay=Value;}
inline unsigned int GetFadeDuration() {return FadeDuration;}
inline void SetFadeDuration(unsigned int Value) {FadeDuration=Value;}
inline void BeginFade() {FadeState=EFS_DELAYING;FadeBegan=g_UIManager.RenderTime;}
inline void InstantFade() {FadeState=EFS_FADED;} // FadeDelay must be non-zero to fade normally.
inline void ResetFade() {FadeState=EFS_NORMAL;}
inline eElementFadeState GetFadeState() {return FadeState;}
inline void UpdateFadeState()
{
if (!FadeDelay)
return;
if (FadeState==EFS_NORMAL)
{
if (!HitTest(g_UIManager.MousePos))
{
BeginFade();
}
}
else
{
if (HitTest(g_UIManager.MousePos))
{
ResetFade();
}
}
}
LGUI_API float GetCurrentAlpha();
inline unsigned char ApplyAlpha(unsigned char Value)
{
float fValue=((((float)Value/255.0f)*AbsoluteAlpha)*255.0f);
if (fValue>255)
return 255;
return (unsigned char)fValue;
}
inline unsigned int ApplyAlpha(unsigned int &Value)
{
RGBCOLOR Color;
Color.ARGB=Value;
Color.A=ApplyAlpha(Color.A);
return Color.ARGB;
}
inline float ApplyAlpha(float Value)
{
return Value*AbsoluteAlpha;
}
inline void ExecuteOnLoad() {if (pOnLoad) pOnLoad->Execute();}
inline void ExecuteOnRender() {if (pOnRender) pOnRender->Execute();}
LGUI_API virtual void MoveZUp();
LGUI_API virtual void MoveZDown();
LGUI_API virtual void MoveZTop(bool bAncestorsToo=true);
LGUI_API virtual void MoveZBottom();
void MoveContainerZTop();
static void StripSlashes(char *Text);
// void GetAbsolute();
protected:
char *Factory;
unsigned int ID; // globally unique
char *Name;
char *FullName;
LGUIElement *pParent;
LGUIElement *pPrev;
LGUIElement *pNext;
LGUIElement *pFirstChild;
LGUIElement *pLastChild; // top of Z order
LGUIEmbeddedScript *pOnLoad;
LGUIEmbeddedScript *pOnUnload;
LGUIEmbeddedScript *pOnLeftClick;
LGUIEmbeddedScript *pOnRightClick;
LGUIEmbeddedScript *pOnDoubleLeftClick;
LGUIEmbeddedScript *pOnDoubleRightClick;
LGUIEmbeddedScript *pOnMouseEnter;
LGUIEmbeddedScript *pOnMouseExit;
LGUIEmbeddedScript *pOnMouseMove;
LGUIEmbeddedScript *pOnMouseWheel;
LGUIEmbeddedScript *pOnKeyboardEnter;
LGUIEmbeddedScript *pOnKeyboardExit;
LGUIEmbeddedScript *pOnKeyUp;
LGUIEmbeddedScript *pOnKeyDown;
LGUIEmbeddedScript *pOnLeftDown;
LGUIEmbeddedScript *pOnRightDown;
LGUIEmbeddedScript *pOnRender;
int X;
ElementPosition XFactor;
int Y;
ElementPosition YFactor;
unsigned int Height;
ElementPosition HeightFactor;
unsigned int Width;
ElementPosition WidthFactor;
FullElementPosition OriginalPosition;
bool bStorePosition;
bool bVisible;
char bAlwaysOnTop;
bool bLeftClickThru;
bool bRightClickThru;
float AlphaLevel;
unsigned int FadeBegan;
unsigned int FadeDelay;
unsigned int FadeDuration;
float FadeAlphaLevel;
eElementFadeState FadeState;
unsigned int FadeInDelay;
unsigned int FadeInDuration;
char *AutoTooltip;
inline void Create(_CreateElement &CreateInfo)
{
X=CreateInfo.X;
Y=CreateInfo.Y;
Width=CreateInfo.Width;
Height=CreateInfo.Height;
bVisible=CreateInfo.bVisible;
XFactor=CreateInfo.XFactor;
YFactor=CreateInfo.YFactor;
WidthFactor=CreateInfo.WidthFactor;
HeightFactor=CreateInfo.HeightFactor;
bAlwaysOnTop=CreateInfo.bAlwaysOnTop;
MoveZTop();
}
float AbsoluteAlpha;
POINT2I Absolute;
};
class LGUIElementDeleter
{
public:
virtual void Delete(LGUIElement *pElement)
{
pElement->OnDestroy();
delete pElement;
}
};
class LGUIElementFactory
{
public:
LGUIElementFactory(const char *p_Type, unsigned int LGUIVersion)
{
Register(p_Type,LGUIVersion);
pDeleter = new LGUIElementDeleter;
}
~LGUIElementFactory()
{
if (Type)
{
map<LGUIElement*,unsigned int>::iterator i=Elements.begin();
while(i!=Elements.end())
{
map<LGUIElement*,unsigned int>::iterator cur=i;
i++;
if (cur->second)
{
cur->first->OnDestroy();
if (cur->first->GetParent())
cur->first->GetParent()->DeleteChild(cur->first);
else
{
// delete i->first; // fuck it, avoid crashing
}
}
}
}
Unregister();
delete pDeleter;
}
LGUI_API void Register(const char *p_Type, unsigned int LGUIVersion);
LGUI_API void Unregister();
LGUI_API virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name, class XMLNode *pXML, const char *Template = 0) = 0;
LGUI_API virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name) = 0;
virtual void UnregisterUIElement(LGUIElement *pElement)
{
Elements.erase(pElement);
}
inline const char *GetTypeName()
{
return Type;
}
map<LGUIElement*,unsigned int> Elements;
void DeleteUIElement(LGUIElement *pElement)
{
//pElement->OnDestroy();
pDeleter->Delete(pElement);
}
protected:
LGUIElementDeleter *pDeleter;
const char *Type;
};
template<class T>
class LGUIFactory : public LGUIElementFactory
{
public:
LGUIFactory(const char *p_Type) :LGUIElementFactory(p_Type, LGUI_VERSION)
{
}
~LGUIFactory()
{
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name, class XMLNode *pXML, const char *Template = 0)
{
T *pElement = new T((char*)Type,pParent,(char*)Name);
if (!pElement->FromXML(pXML,g_UIManager.FindTemplate(Template)))
{
if (pParent)
pParent->DeleteChild(pElement);
else
delete pElement;
return 0;
}
Elements[pElement]=1;
return pElement;
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name)
{
T *pElement = new T((char*)Type,pParent,(char*)Name);
Elements[pElement]=1;
return pElement;
}
};
template<class T>
class DelayedLGUIFactory
{
public:
DelayedLGUIFactory(const char *p_Type)
{
Type=strdup(p_Type);
pFactory=0;
}
~DelayedLGUIFactory()
{
Shutdown();
free((void*)Type);
}
void Initialize()
{
if (pFactory)
return;
pFactory = new LGUIFactory<T>(Type);
}
void Shutdown()
{
if (!pFactory)
return;
delete pFactory;
pFactory=0;
}
const char *Type;
LGUIFactory<T> *pFactory;
};

View File

@ -0,0 +1,20 @@
#pragma once
class LGUIEmbeddedScript
{
public:
LGUIEmbeddedScript(unsigned int AtomID, class LGUIElement *pThis);
virtual ~LGUIEmbeddedScript();
LGUI_API static LGUIEmbeddedScript *New(class LGUIElement *pThis, const char *Buffer, const char *Parameters);
LGUI_API virtual void Delete();
LGUI_API virtual int Execute(int argc=0, char *argv[]=0);
LGUI_API virtual int Execute(class LGUIElement *pThis, int argc=0, char *argv[]=0);
protected:
unsigned int AtomID;
class LGUIElement *pThis;
unsigned int RefCount;
};

View File

@ -0,0 +1,84 @@
#pragma once
struct _CreateFont
{
char *Name;
unsigned char Height;
unsigned int Color;
bool Bold;
bool Fixed;
};
class LGUIFont
{
public:
LGUIFont(LGUIElement *pParent, const char *Face, unsigned char Height, bool Fixed, bool Bold);
LGUIFont(LGUIElement *pParent, const LGUIFont&);
LGUIFont(LGUIElement *pParent, _CreateFont &CreateFont, XMLNode *pTemplate);
virtual ~LGUIFont();
// LGUI_API virtual bool FromXML(class XMLNode *pXML, char *Template="");
LGUI_API static LGUIFont *New(LGUIElement *pParent,const char *Face, unsigned char Height, bool Fixed, bool Bold);
LGUI_API static LGUIFont *New(LGUIElement *pParent,_CreateFont &CreateFont, class XMLNode *pTemplate=0);
LGUI_API static LGUIFont *New(LGUIElement *pParent,const LGUIFont&);
LGUI_API virtual void Delete();
LGUI_API virtual bool Prepare();
LGUI_API void Release();
LGUI_API bool IsFixedFont();
// LGUI_API float GetBaseHeight();
LGUI_API size_t Draw(const char *Text, int X, int Y, size_t ClipLength = 0);
LGUI_API size_t DrawCenter(const char *Text, int X, int Y, size_t ClipLength);
LGUI_API size_t DrawRight(const char *Text, int X, int Y, size_t ClipLength);
LGUI_API size_t GetTextWidth(const char *Text);
LGUI_API size_t GetTextWidth(const char *Text, size_t Length);
// LGUI_API unsigned int GetCharWidth(unsigned int c);
LGUI_API unsigned int GetCharByOffset(const char *Text, size_t Offset);
LGUI_API void SetName(const char *p_Name);
LGUI_API void SetBold(bool Bold);
inline char *GetName() {return Name;}
inline unsigned int GetColor() {return Color;}
inline unsigned char GetHeight() {return Height;}
inline bool GetBold() {return Bold;}
LGUI_API void SetHeight(unsigned char NewHeight);
inline void SetColor(unsigned int NewColor) {Color=NewColor;}
protected:
unsigned int FontID;
char *Name;
unsigned char Height;
unsigned int Color;
bool Bold;
bool Fixed;
LGUIElement *pParent;
};
class LGUIFixedFont : public LGUIFont
{
public:
LGUIFixedFont(LGUIElement *pParent, const char *Face, unsigned char Height, bool Bold);
LGUIFixedFont(LGUIElement *pParent,const LGUIFixedFont&);
LGUIFixedFont(LGUIElement *pParent,_CreateFont &CreateFont, class XMLNode *pTemplate);
~LGUIFixedFont();
LGUI_API static LGUIFixedFont *New(LGUIElement *pParent, const char *Face, unsigned char Height, bool Bold);
LGUI_API static LGUIFixedFont *New(LGUIElement *pParent,const LGUIFixedFont&);
LGUI_API static LGUIFixedFont *New(LGUIElement *pParent,_CreateFont &CreateFont, class XMLNode *pTemplate=0);
LGUI_API virtual void Delete();
LGUI_API virtual bool Prepare();
LGUI_API size_t GetCharWidth();
/*
protected:
inline class CLavishFontFixed *GetFixedFont()
{
return (class CLavishFontFixed *)pFont;
}
/**/
};

View File

@ -0,0 +1,41 @@
#pragma once
struct _CreateFrame : public _CreateElement
{
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
};
class LGUIFrame :
public LGUIElement
{
public:
LGUI_API LGUIFrame(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIFrame(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void Create(_CreateFrame &CreateInfo);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnLMouseDoubleClick(POINT2I &pt);
LGUI_API bool OnRMouseDoubleClick(POINT2I &pt);
LGUI_API bool OnRMouseUp(POINT2I &pt);
LGUI_API bool OnRMouseDown(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
// -- XML Properties --
LGUITexture *pTexture;
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
// ----------------------
};

View File

@ -0,0 +1,93 @@
#pragma once
class LGUIGauge :
public LGUIFrame
{
public:
LGUI_API LGUIGauge(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIGauge(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API virtual void SetValue(float NewValue);
// -- XML Properties --
LGUITexture *pTopTexture;
bool bVertical;
float fRange;
// --------------------
bool Mod;
class LGUIGaugeFiller* pFiller;
float fValue;
};
class LGUIGaugeFiller:
public LGUIElement
{
public:
LGUIGaugeFiller(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
~LGUIGaugeFiller(void);
// LGUI_API class LSTypeDefinition *GetLSType();
void Render();
bool FromXML(class XMLNode *pXML);
bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate);
bool IsTypeOf(char *TestFactory);
// void Default();
virtual void SetValue(float NewValue);
void RecalculateSize(bool RecalculateChildren);
// -- XML Properties --
LGUITexture *pTexture;
// --------------------
float fRange;
float fValue;
bool bVertical;
unsigned int Repeat;
class LGUIGauge *pGauge;
};
class LGUIGaugeFactory : public LGUIElementFactory
{
public:
LGUIGaugeFactory():LGUIElementFactory("gauge",LGUI_VERSION)
{
}
~LGUIGaugeFactory()
{
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name, class XMLNode *pXML, const char *Template = 0)
{
LGUIGauge *pElement = new LGUIGauge(Type,pParent,Name);
if (!pElement->FromXML(pXML,g_UIManager.FindTemplate(Template)))
{
delete pElement;
return 0;
}
Elements[pElement]=1;
if (pElement->pFiller)
return pElement->pFiller;
return pElement;
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name)
{
LGUIGauge *pElement = new LGUIGauge(Type,pParent,Name);
Elements[pElement]=1;
return pElement;
}
virtual LSType *GetLSType();
};

View File

@ -0,0 +1,37 @@
#pragma once
#include "LGUIelement.h"
class LGUIHudElement :
public LGUIElement
{
public:
LGUIHudElement(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
~LGUIHudElement(void);
bool IsTypeOf(char *TestFactory);
class LSTypeDefinition *GetLSType();
bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
bool OnLMouseUp(POINT2I &pt);
bool OnLMouseDown(POINT2I &pt);
bool OnMouseMove(POINT2I &pt);
void Render();
virtual void UpdateElement();
virtual void SetText(char *NewValue);
// -- From XML --
//char *Text;
LGUIPreParse PreParsed;
char *Group;
LGUIFont *pFont;
unsigned int UpdateInterval;
// --------------------------------
char *CurrentValue;
unsigned int CurrentInterval;
bool bMoving;
POINT2I MovingOffset;
};

View File

@ -0,0 +1,145 @@
#pragma once
enum eListBoxSort
{
LBSORT_NONE=0,
LBSORT_USER=1,
LBSORT_TEXT=2,
LBSORT_VALUE=3,
LBSORT_CUSTOM=4,
LBSORT_TEXTREVERSE=5,
LBSORT_VALUEREVERSE=6,
};
class ListBoxItem
{
public:
ListBoxItem(class LGUIListBox *p_pListBox, const char *p_Text, unsigned int p_Color, const char *p_Value, unsigned int p_ID)
{
pListBox=p_pListBox;
Text=strdup(p_Text);
Color=p_Color;
if (p_Value)
Value=p_Value;
ID=p_ID;
Order=0;
}
~ListBoxItem()
{
free(Text);
Text="Error";
}
unsigned int ID;
char *Text;
unsigned int Color;
std::string Value;
unsigned int Order;
class LGUIListBox *pListBox;
};
struct _CreateListBox : public _CreateElement
{
// unsigned int FontSize;
// unsigned int TextColor;
_CreateFont Font;
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
unsigned int SelectionColor;
eListBoxSort SortType;
bool bSelectMultiple;
char *ScrollBarTemplate;
};
class LGUIListBox :
public LGUIElement
{
public:
LGUI_API LGUIListBox(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIListBox(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateListBox &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void RecalculateSize(bool RecalculateChildren);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDoubleClick(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
LGUI_API virtual void DeselectItem(unsigned int ID);
LGUI_API virtual void SelectItem(unsigned int ID);
LGUI_API virtual void ItemToggleSelect(unsigned int ID);
LGUI_API virtual void ClearSelection();
LGUI_API virtual unsigned int AddItem(const char *Text, const char *Value, unsigned int Color=0);
LGUI_API virtual void RemoveItem(unsigned int ID);
LGUI_API virtual void ClearItems();
LGUI_API virtual bool GetItemValue(unsigned int ID, unsigned int &Value);
LGUI_API virtual void SetItemText(unsigned int ID, const char *Text);
LGUI_API virtual void SetItemColor(unsigned int ID, unsigned int Color);
LGUI_API virtual unsigned int FindItemByText(const char *Text, unsigned int BeginInclusive=1);
LGUI_API virtual unsigned int FindItemByValue(const char *Value, unsigned int BeginInclusive=1);
LGUI_API virtual unsigned int GetItemFromPoint(POINT2I &pt);
LGUI_API virtual unsigned int GetOrderFromPoint(POINT2I &pt);
LGUI_API virtual void ApplySort();
LGUI_API ListBoxItem *RetrieveItem(unsigned int ID);
void Sort(int (__cdecl* customCompare)(const void *,const void *));
// -- XML Properties --
LGUIFont *pFont;
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
unsigned int SelectionColor;
eListBoxSort SortType;
bool bSelectMultiple;
LGUITexture *pTexture;
LGUIEmbeddedScript *pOnSelect;
LGUIEmbeddedScript *pOnDeSelect;
// --------------------
unsigned int TextColor;
LGUIScrollBar *pVerticalBar;
bool bAutoSort;
int (__cdecl* fCustomCompare)(const void *,const void *);
unsigned int VisiblePos;
set<ListBoxItem *> Selection;
CIndex<ListBoxItem *> Items;
CIndex<ListBoxItem *> OrderedItems;
unsigned int nItems;
unsigned int DraggingID;
bool Reordered;
};

View File

@ -0,0 +1,175 @@
#pragma once
#include "LGUI.h"
struct _UISettings
{
unsigned int AutoTooltipTime;
unsigned int DoubleClickTime;
unsigned int TypematicRate;
unsigned int TypematicDelay;
};
class LGUISkin
{
public:
LGUISkin(const char *p_Name);
~LGUISkin();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void AddTemplate(const char *BaseTemplate, const char *SkinTemplate);
LGUI_API void RemoveTemplate(const char *BaseTemplate);
char *Name;
map<utf8stringnocase,char *> Templates;
};
class MetadataStore
{
public:
const char *Get(const char *key);
bool Set(const char *key, const char *value);
bool Unset(const char *key);
map<utf8stringnocase,std::string> m_Metadata;
};
class CUIManager
{
public:
CUIManager(void);
~CUIManager(void);
virtual void Initialize();
virtual void Shutdown();
virtual unsigned int GetVersion();
virtual void DisableMouse();
LGUI_API void Reset();
LGUI_API bool LoadInterfaceXML(const char *Filename, bool Reload = false, LGUISkin *pSkin = 0);
LGUI_API bool LoadInterfaceXML(const char *Filename, const char *Element, const char *NewName, bool Reload = false, LGUISkin *pSkin = 0);
LGUI_API bool LoadInterfaceXML(LGUIElement *pParent, const char *Filename, bool Reload = false, LGUISkin *pSkin = 0);
LGUI_API bool LoadInterfaceXML(LGUIElement *pParent, const char *Filename, const char *Element, const char *NewName, bool Reload = false, LGUISkin *pSkin = 0);
LGUI_API bool UnloadInterfaceXML(const char *Filename);
LGUI_API bool OnLMouseUp();
LGUI_API bool OnLMouseDown();
LGUI_API bool OnRMouseUp();
LGUI_API bool OnRMouseDown();
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
LGUI_API bool OnKeyUp(unsigned int VKey);
LGUI_API bool OnKeyDown(unsigned int VKey);
LGUI_API void SetFocusElement(class LGUIElement *pElement);
inline class LGUIElement *GetElementByID(unsigned int ID)
{
map<unsigned int,class LGUIElement *>::iterator i=AllElements.find(ID);
if (i==AllElements.end())
return 0;
return i->second;
}
LGUI_API class LGUIElement *GetFocusElement();
LGUI_API class LGUIElement *SetFocusElement();
LGUI_API class LGUIElement *GetMouseOverElement();
LGUI_API class LGUIElement *SetMouseOverElement();
LGUI_API bool ShowElement(const char *Name, bool Show);
LGUI_API bool ToggleElement(const char *Name);
LGUI_API void Render();
LGUI_API class LGUIElementFactory *FindFactory(const char *Type);
LGUI_API class LGUIElement *FindElement(const char *Name);
unsigned int LoadTexture(const char *Filename, unsigned int ColorKey);
LGUI_API bool GetTextureSize(unsigned int ID, POINT2I &pt);
void ReleaseTexture(unsigned int ID);
unsigned int LoadFont(const char *Face, unsigned char Height, bool Fixed, bool Bold=0);
void ReleaseFont(unsigned int ID);
// LGUI_API unsigned int DrawText(const char *Text,int p_X, int p_Y,unsigned int Color,unsigned int FontHeight);
unsigned int FocusID;
unsigned int MouseOverID;
unsigned int LockMouseOverIDLeft;
unsigned int LockMouseOverIDRight;
unsigned int MousePriorityID;
unsigned int CurrentFontID;
bool bShift;
bool bAlt;
bool bCtrl;
char LeftMouse;
char RightMouse;
POINT2I MousePos;
unsigned char KeyboardState[256];
map<utf8stringnocase,class LGUIElement *> AllElementsByName;
map<unsigned int,class LGUIElement *> AllElements;
class LGUIElement *pScreen;
map<utf8stringnocase,class LGUIElementFactory *> ElementFactories;
unsigned int NextID;
CSemaphore S;
LGUI_API class XMLNode *AddTemplate(const char *Name, const char *XML);
LGUI_API class XMLNode *AddTemplate(const char *Name, class XMLNode *pXML);
LGUI_API void RemoveTemplate(const char *Name);
LGUI_API class XMLNode *FindTemplate(const char *Name);
LGUI_API void ClearTemplates();
map<utf8stringnocase,class XMLNode *> Templates;
map<utf8stringnocase,LGUISkin *> Skins;
LGUI_API LGUISkin *NewSkin(const char *Name);
LGUI_API LGUISkin *FindSkin(const char *Name);
LGUI_API void RemoveSkin(const char *Name);
LGUISkin *pCurrentSkin;
char OuterTag[64];
char CurrentXMLFile[512];
bool bShutdown;
unsigned int MouseOverTime;
unsigned int LastActionTime;
POINT2I LastClickPos;
unsigned int LastLeftClickTime;
unsigned int LastLeftClickID;
unsigned int LastRightClickTime;
unsigned int LastRightClickID;
unsigned int RenderTime;
unsigned int AutoTooltipShownID;
_UISettings Settings;
bool bZOrderChanged;
map<unsigned int,unsigned char> KeyboardStateEx;
unsigned int PersistentClass;
void OnDeleteElement(class LGUIElement *pElement);
const char *GetMetadata(unsigned int elementid, const char *key);
bool SetMetadata(unsigned int elementid, const char *key, const char *value);
bool UnsetMetadata(unsigned int elementid, const char *key);
map<unsigned int,MetadataStore *> m_MetadataStores;
//protected:
LGUI_API LGUIElement *LoadElement(class LGUIElement *pParent, const char *Type, const char *Name, class XMLNode *pXML, const char *Template = 0);
LGUI_API LGUIElement *LoadElement(class LGUIElement *pParent, const char *Type, const char *Name);
};
extern LGUI_API CUIManager g_UIManager;

View File

@ -0,0 +1,150 @@
#pragma once
class LGUIMapBlip :
public LGUIFrame
{
public:
LGUI_API LGUIMapBlip(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIMapBlip(void);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void OnMouseEnter(POINT2I &pt);
LGUI_API void OnMouseExit(LGUIElement *pNewFocus);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool SetTooltip(LGUITooltip *pTooltip);
LGUIFont *pFont;
LGUIEmbeddedScript *pSetTooltip;
POINT3F Point;
char *Custom;
char *Label;
};
class LGUIMapBlipView :
public LGUIFrame
{
public:
LGUI_API LGUIMapBlipView(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIMapBlipView(void);
LGUI_API bool IsTypeOf(char *TestFactory);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void OnMouseEnter(POINT2I &pt);
LGUI_API void OnMouseExit(LGUIElement *pNewFocus);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void UpdateSize();
LGUI_API void Render();
LGUI_API bool SetTooltip(LGUITooltip *pTooltip);
LGUIMapBlip *pBlip;
};
class LGUIMapView;
class LGUIMap :
public LGUIElement
{
public:
LGUI_API LGUIMap(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIMap(void);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void OnCreate();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void Render();
char BlipFactory[64];
char *BlipTemplate;
POINT3F Origin; // center of Map (player location?)
float Rotation; // rotation of Map (player heading?)
float MapSizeX; // size of Map box in game units (east-west) - MapSizeY not used if ClipRadius is set.
float MapSizeY; // size of Map box in game units (north-south)
bool bClipRadius; // use radius clipping instead of box clipping
bool bClipZ; // height clipping
bool bShowLabels; // show labels?
bool bRotation; // Rotate Map around origin?
bool bClipText; // Clip text to Map edge?
POINT2F ZClipping; // min/max height difference from origin. X = min, Y = max
LGUI_API virtual void BlipHover(LGUIMapBlip *pBlip, POINT2I &Pos);
LGUI_API virtual void BlipHoverStop(LGUIMapBlip *pBlip);
// Blip Manipulation
LGUI_API virtual unsigned int AddBlip(char *Name, POINT3F &Point, unsigned int Size, char *Label=0, char *BlipTemplate=0, char *BlipFactory=0);
LGUI_API virtual void RemoveBlip(unsigned int ID);
LGUI_API virtual void ClearBlips();
LGUI_API virtual void UpdateBlip(unsigned int ID, POINT3F &Point);
LGUI_API virtual void UpdateBlipLabel(unsigned int ID, char *Label);
LGUI_API virtual void UpdateBlipSize(unsigned int ID, unsigned int Size);
LGUI_API virtual LGUIMapBlip *NewBlip(char *Name, char *BlipTemplate=0, char *BlipFactory=0);
LGUI_API virtual LGUIMapBlip *FindBlip(char *Name);
LGUI_API virtual void UpdateRadius();
LGUI_API virtual void UpdateBox();
map<unsigned int, LGUIMapBlip *> Blips;
map<utf8string, LGUIMapBlip *> BlipsByName;
map<unsigned int, LGUIMapView *> Views;
unsigned int HoverID;
unsigned int nBlips;
LGUITooltip *pTooltip;
};
class LGUIMapView :
public LGUIElement
{
public:
LGUI_API LGUIMapView(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIMapView(void);
LGUI_API bool IsTypeOf(char *TestFactory);
// LGUI_API class LSTypeDefinition *GetLSType();
// LGUI_API void ClearBlips();
LGUI_API void OnCreate();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void Render();
POINT3F Origin; // center of Map (player location?)
float Rotation; // rotation of Map (player heading?)
float MapSizeX; // size of Map box in game units (east-west) - MapSizeY not used if ClipRadius is set.
float MapSizeY; // size of Map box in game units (north-south)
bool bClipRadius; // use radius clipping instead of box clipping
bool bClipZ; // height clipping
bool bShowLabels; // show labels?
bool bRotation; // Rotate Map around origin?
bool bClipText; // Clip text to Map edge?
POINT2F ZClipping; // min/max height difference from origin. X = min, Y = max
LGUI_API virtual void BlipHover(LGUIMapBlipView *pBlip, POINT2I &Pos);
LGUI_API virtual void BlipHoverStop(LGUIMapBlipView *pBlip);
LGUI_API virtual void UpdateRadius();
LGUI_API virtual void UpdateBox();
// LGUI_API virtual void AddBlipView(LGUIMapBlip *pBlip);
// LGUI_API virtual void RemoveBlipView(LGUIMapBlip *pBlip);
map<LGUIMapBlip *, LGUIMapBlipView *> BlipViews;
LGUIMap *pMap;
unsigned int HoverID;
LGUITooltip *pTooltip;
};

View File

@ -0,0 +1,36 @@
#pragma once
enum eMessageBoxType
{
MSGBOX_OK=1,
MSGBOX_OKCANCEL=2,
MSGBOX_YESNO=3,
};
class LGUIMessageBox : public LGUIWindow
{
public:
LGUI_API LGUIMessageBox(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIMessageBox(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(char *p_Title, char *p_Text, eMessageBoxType p_Type, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
// Text
LGUIFont *pFont;
eMessageBoxType MessageBoxType;
// --------------------
LGUIButton *pOK;
LGUIButton *pCancel;
LGUIButton *pYes;
LGUIButton *pNo;
};

View File

@ -0,0 +1,20 @@
#pragma once
#include "LGUIelement.h"
class LGUIScreen :
public LGUIElement
{
public:
LGUIScreen(void);
~LGUIScreen(void);
bool IsTypeOf(char *TestFactory);
//void Render();
void RecalculateSize(bool RecalculateChildren);
void MoveZTop(bool bAncestorsToo);
void MoveZUp();
void MoveZDown();
void MoveZBottom();
bool OnLMouseDown(POINT2I &pt);
};

View File

@ -0,0 +1,41 @@
#pragma once
struct _CreateScrollBar : public _CreateElement
{
unsigned int Range;
bool bVertical;
bool DefaultTextures;
};
class LGUIScrollBar :
public LGUIElement
{
public:
LGUI_API LGUIScrollBar(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIScrollBar(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateScrollBar &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void SizeRecalculated(bool Changed);
// LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
// LGUI_API void RecalculateSize();
LGUI_API virtual void SetRange(unsigned int NewRange);
LGUI_API virtual void SetValue(unsigned int NewValue);
LGUI_API virtual void RaiseValue(unsigned int Offset);
LGUI_API virtual void LowerValue(unsigned int Offset);
LGUI_API virtual unsigned int GetValue();
unsigned int Range;
bool bVertical;
LGUIButton *pUp;
LGUIButton *pDown;
LGUISlider *pSlider;
};

View File

@ -0,0 +1,53 @@
#pragma once
#include "LGUIelement.h"
struct _CreateSlider : public _CreateElement
{
unsigned int Border;
unsigned int Range;
bool bVertical;
bool DefaultTextures;
};
class LGUISlider :
public LGUIElement
{
public:
LGUI_API LGUISlider(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUISlider(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateSlider &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API virtual void SetValue(unsigned int NewValue);
LGUI_API virtual void SetPosition(unsigned int NewPosition);
LGUI_API void RecalculateSize(bool RecalculateChildren);
// -- XML Properties --
LGUITexture *pTexture;
LGUITexture *pHandleTexture;
unsigned int Border;
bool bVertical;
unsigned int Range;
LGUIEmbeddedScript *pOnChange;
// --------------------
unsigned int HandleWidth;
unsigned int HandleHeight;
unsigned int Value;
unsigned int Position;
bool bSliding;
};

View File

@ -0,0 +1,93 @@
#pragma once
class CLGUITab
{
public:
CLGUITab(class LGUITabControl *p_Control,const char *p_Name, unsigned int p_ID)
{
Name=strdup(p_Name);
ID=p_ID;
Order=0;
pFrame=0;
pTabControl=p_Control;
// Length=strlen(Name);
}
~CLGUITab()
{
free(Name);
}
LGUI_API void Rename(const char *NewName);
char *Name;
// unsigned int Length;
unsigned int FullWidth;
unsigned int ID;
unsigned int Order;
LGUIFrame *pFrame;
class LGUITabControl *pTabControl;
};
class LGUITabControl :
public LGUIElement
{
public:
LGUI_API LGUITabControl(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITabControl(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API void RecalculateSize(bool RecalculateChildren);
LGUI_API void SizeRecalculated(bool Changed);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API virtual unsigned int AddTab(const char *Text,XMLNode *pXML, const char *ChildName, const char *Template);
LGUI_API virtual void RemoveTab(unsigned int ID);
LGUI_API virtual unsigned int GetTabFromPoint(POINT2I &pt);
LGUI_API virtual unsigned int GetOrderFromPoint(POINT2I &pt);
LGUI_API void MoveTab(CLGUITab *pTab, unsigned int Order);
LGUI_API virtual void SelectTab(unsigned int ID);
LGUI_API virtual void ClearSelection();
LGUI_API CLGUITab *GetTabFromName(const char *Name);
// -- XML Properties --
LGUIFont *pFont;
LGUITexture *pTabTexture;
LGUITexture *pTabSelectedTexture;
LGUITexture *pFrameTexture;
unsigned int FrameBackgroundColor;
unsigned int FrameBorder;
unsigned int FrameBorderColor;
unsigned int TabHeight;
unsigned int TabBorder;
unsigned int SelectedTextColor;
bool bDraggable;
LGUIEmbeddedScript *pOnSelect;
// ----------------------
LGUIButton *pLeft;
LGUIButton *pRight;
unsigned int VisiblePos;
unsigned int Selection;
CIndex<CLGUITab *> Tabs;
CIndex<CLGUITab *> OrderedTabs;
unsigned int nTabs;
unsigned int DraggingID;
};

View File

@ -0,0 +1,54 @@
#pragma once
class LGUITableCell :
public LGUIFrame
{
public:
LGUI_API LGUITableCell(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITableCell(void);
// LGUI_API class LSTypeDefinition *GetLSType();
// LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
// -- XML Properties --
unsigned int RowSpan;
unsigned int ColSpan;
// ----------------------
unsigned int Row;
unsigned int Column;
};
class LGUITable :
public LGUIFrame
{
public:
LGUI_API LGUITable(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITable(void);
// LGUI_API class LSTypeDefinition *GetLSType();
// LGUI_API void Render();
LGUI_API virtual void RecalculateSize(bool RecalculateChildren);
LGUI_API virtual void SizeRecalculated(bool Changed);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
// -- XML Properties --
char *CellTemplate;
//unsigned int CellSpacing; // TODO
// ----------------------
LGUITableCell **Cell;
ElementPosition *ColumnWidth;
ElementPosition *RowHeight;
unsigned int nRows;
unsigned int nColumns;
};

View File

@ -0,0 +1,69 @@
#pragma once
#include "LGUIelement.h"
enum eTextAlign
{
ALIGN_LEFT=0,
ALIGN_CENTER=1,
ALIGN_RIGHT=2,
VALIGN_TOP=3,
VALIGN_CENTER=4,
VALIGN_BOTTOM=5,
};
struct _CreateText : public _CreateElement
{
char *Text;
_CreateFont Font;
// char *Font;
// unsigned int FontSize;
// unsigned int Color;
bool bWrap;
eTextAlign Alignment;
eTextAlign VerticalAlignment;
};
class LGUIText : public LGUIElement
{
public:
LGUI_API LGUIText(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIText(void);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API static size_t SplitFixed(char *Value, size_t MaxChars, size_t &Width);
LGUI_API static size_t Split(char *Value, size_t MaxWidth, LGUIFont *pFont, size_t &Width);
LGUI_API size_t Split(char *Value);
LGUI_API void Render();
LGUI_API bool RenderCustom();
LGUI_API void Create(_CreateText &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void RenderLeft(char *Value);
LGUI_API void RenderCenter(char *Value);
LGUI_API void RenderRight(char *Value);
LGUI_API void RecalculateSize(bool RecalculateChildren);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void SetText(char *NewText);
LGUI_API void SetHorizontalAlignment(eTextAlign value);
LGUI_API void SetVerticalAlignment(eTextAlign value);
LGUI_API void SetWrap(bool value);
// -- XML Properties --
char *Text;
LGUIFont *pFont;
bool bWrap;
eTextAlign Alignment;
eTextAlign VerticalAlignment;
// --------------------
char *NonVariable;
size_t nLines;
};

View File

@ -0,0 +1,260 @@
#pragma once
#include "LGUIelement.h"
class CTextEditLine
{
public:
CTextEditLine(const char *p_Text, size_t p_nLine)
{
nLine=p_nLine;
pPrev=0;
pNext=0;
if (p_Text)
{
Used=strlen(p_Text);
Allocated=Used+1;
Text=(char*)malloc(Allocated);
memcpy(Text,p_Text,Allocated);
}
else
{
Text=_strdup("");
Used=0;
Allocated=1;
}
}
~CTextEditLine()
{
free(Text);
}
bool InsertText(size_t Position, const char *Insert, size_t InsertSize)
{
if (!InsertSize)
return true;
if (Position>Used)
return false;
if (Used+InsertSize>Allocated)
{
Text=(char*)realloc(Text,Used+InsertSize+7);
}
if (Position!=Used+1)
{
// shift to the right
memmove(&Text[Position+InsertSize],&Text[Position],(Used+1-Position)+InsertSize);
}
else
Text[Position+Used+1]=0;
Used+=InsertSize;
memcpy(&Text[Position],Insert,InsertSize);
return true;
}
bool InsertCharacter(size_t Position, char C)
{
if (Position>Used)
return false;
if (Used+2>=Allocated)
{
Text=(char*)realloc(Text,Used+7);
}
if (Position!=Used+1)
{
// shift to the right
memmove(&Text[Position+1],&Text[Position],(Used+1-Position)+1);
}
else
Text[Position+1]=0;
Used++;
Text[Position]=C;
return true;
}
bool OverwriteCharacter(size_t Position, char C)
{
if (Position>Used)
return false;
if (Position==Used)
{
if (Used+1>=Allocated)
{
Text=(char*)realloc(Text,Used+7);
}
Used++;
Text[Position+1]=0;
}
Text[Position]=C;
}
inline bool DeleteCharacter(size_t Position)
{
if (Position>=Used)
return false;
memmove(&Text[Position],&Text[Position+1],(Used+1-Position));
Used--;
return true;
}
inline bool Truncate(size_t Position)
{
if (Position>Used)
return false;
Text[Position]=0;
Used=Position;
return true;
}
char *Text;
size_t Allocated;
size_t Used;
size_t nLine;
CTextEditLine *pPrev;
CTextEditLine *pNext;
};
struct TextEditPos
{
CTextEditLine *pLine;
size_t Position;
bool operator==(const TextEditPos& other ) const
{
return pLine==other.pLine && Position==other.Position;
}
bool operator!=(const TextEditPos& other ) const
{
return pLine!=other.pLine || Position!=other.Position;
}
bool operator<(const TextEditPos& other ) const
{
if (pLine==other.pLine)
return Position<other.Position;
else
return pLine->nLine<other.pLine->nLine;
}
bool operator>(const TextEditPos& other ) const
{
if (pLine==other.pLine)
return Position>other.Position;
else
return pLine->nLine>other.pLine->nLine;
}
bool operator<=(const TextEditPos& other ) const
{
if (pLine==other.pLine)
return Position<=other.Position;
else
return pLine->nLine<=other.pLine->nLine;
}
bool operator>=(const TextEditPos& other ) const
{
if (pLine==other.pLine)
return Position>=other.Position;
else
return pLine->nLine>=other.pLine->nLine;
}
};
class LGUITextEdit :
public LGUIFrame
{
public:
LGUI_API LGUITextEdit(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITextEdit(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API virtual void SetText(const char *NewValue);
LGUI_API virtual void AddText(const char *Text);
LGUI_API virtual void AddLine(const char *Text);
LGUI_API virtual void InsertText(TextEditPos &Pos, const char *Text);
LGUI_API virtual CTextEditLine *InsertLineAfter(CTextEditLine *pLine, const char *Text);
LGUI_API virtual void RemoveLine(CTextEditLine *pLine, bool bReverseCursor=false);
LGUI_API virtual bool OnKeyUp(unsigned int VKey);
LGUI_API virtual bool OnKeyDown(unsigned int VKey);
LGUI_API virtual bool OnLMouseDown(POINT2I &pt);
LGUI_API virtual bool OnLMouseUp(POINT2I &pt);
LGUI_API virtual bool OnMouseMove(POINT2I &pt);
LGUI_API virtual void InsertCharacter(char C);
LGUI_API virtual void HandleBackspace();
LGUI_API virtual void HandleDelete();
LGUI_API virtual void HandleEnter();
LGUI_API virtual void HandleUp(unsigned int Count=1);
LGUI_API virtual void HandleDown(unsigned int Count=1);
LGUI_API virtual void HandleLeft();
LGUI_API virtual void HandleRight();
LGUI_API virtual void HandlePageUp();
LGUI_API virtual void HandlePageDown();
LGUI_API virtual void HandleHome();
LGUI_API virtual void HandleEnd();
LGUI_API virtual void HandleCtrlHome();
LGUI_API virtual void HandleCtrlEnd();
LGUI_API virtual void PasteClipboard();
LGUI_API virtual void CopySelection();
LGUI_API virtual void GetPositionFromPoint(POINT2I &pt, TextEditPos &Position);
LGUI_API virtual bool OnMouseWheel(int Offset);
LGUI_API virtual void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API virtual void OnKeyboardExit(LGUIElement *pNewFocus);
bool IsSelected(CTextEditLine *pLine, POINT2I &Selected);
void ClearSelection();
void UpdateSelection();
// -- XML PROPERTIES --
LGUIFixedFont *pFont;
unsigned int SelectionColor;
unsigned int CaretOuterColor;
unsigned int CaretInnerColor;
LGUITexture *pTextureCaret;
LGUITexture *pTextureCaretOverwrite;
//---------------------
CTextEditLine *pFirstLine;
CTextEditLine *pLastLine;
bool InsertMode;
size_t MaxLines;
size_t CharactersWide;
TextEditPos SelectionBegin;
TextEditPos SelectionEnd;
TextEditPos Position;
TextEditPos UpperLeft;
TextEditPos LowerLeft;
unsigned int LastVKey;
unsigned int LastVKeyTimer;
size_t VisibleLines;
class LGUIScrollBar *pVerticalScrollbar;
class LGUIScrollBar *pHorizontalScrollbar;
size_t nLines;
bool bDragging;
protected:
LGUI_API virtual void Clear();
};

View File

@ -0,0 +1,83 @@
#pragma once
#include "LGUIelement.h"
struct _CreateTextEntry : public _CreateElement
{
char *Text;
_CreateFont Font;
// char *Font;
// unsigned int FontHeight;
// unsigned int TextColor;
unsigned int BackgroundColor;
unsigned int SelectionColor;
unsigned int MaxLength;
unsigned int BorderColor;
unsigned int Border;
unsigned int CaretOuterColor;
unsigned int CaretInnerColor;
char PasswordChar;
};
class LGUITextEntry :
public LGUIElement
{
public:
LGUI_API LGUITextEntry(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITextEntry(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateTextEntry &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API void Render();
LGUI_API void RenderCustom();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API virtual void SetText(char *NewValue);
LGUI_API virtual void SetFontSize(unsigned int NewHeight);
LGUI_API virtual bool OnKeyUp(unsigned int VKey);
LGUI_API virtual bool OnKeyDown(unsigned int VKey);
LGUI_API virtual bool OnLMouseDown(POINT2I &pt);
LGUI_API virtual void InsertCharacter(char C);
LGUI_API virtual void HandleBackspace();
LGUI_API virtual void HandleDelete();
LGUI_API virtual void HandleEnter();
LGUI_API virtual void HandleEscape();
LGUI_API virtual void PasteClipboard();
LGUI_API unsigned int GetPositionFromPoint(POINT2I &pt);
LGUI_API virtual void OnKeyboardExit(LGUIElement *pNewFocus);
// -- XML PROPERTIES --
char *Text;
LGUIFont *pFont;
unsigned int BackgroundColor;
unsigned int SelectionColor;
unsigned int MaxLength;
unsigned int BorderColor;
unsigned int Border;
unsigned int CaretOuterColor;
unsigned int CaretInnerColor;
LGUITexture *pTexture;
LGUITexture *pTextureFocused;
LGUITexture *pTextureCaret;
LGUITexture *pTextureCaretOverwrite;
LGUIEmbeddedScript *pOnChange;
char PasswordChar;
//---------------------
// unsigned int FontWidth;
bool InsertMode;
size_t Position;
unsigned int LastVKey;
size_t TextEnd;
unsigned int LastVKeyTimer;
size_t VisiblePos;
};

View File

@ -0,0 +1,75 @@
#pragma once
#define TR_TEXTURERECT 1
#define TR_ALPHA 2
#define TR_COLORMASK 4
#define TR_NOSIZE 8
#define TR_TEXTURETRIANGLE 16
struct LGUITexturedRect
{
public:
class LGUITexture *pTexture;
RECT Rect;
DWORD Flags;
RECT TextureRect;
unsigned char Alpha;
unsigned int ColorMask;
unsigned char Orientation;
};
struct LGUITriangle
{
POINT2F Point[3];
};
struct LGUITexturedTriangle
{
public:
class LGUITexture *pTexture;
LGUITriangle Triangle;
DWORD Flags;
LGUITriangle TextureTriangle;
unsigned char Alpha;
unsigned int ColorMask;
unsigned char Orientation;
};
class LGUITexture
{
public:
LGUITexture(const char *p_Name);
LGUITexture(const LGUITexture&);
~LGUITexture();
void CopyFrom(const LGUITexture &other);
LGUI_API static LGUITexture *New(const char *p_Name);
LGUI_API static LGUITexture *New(const LGUITexture&);
LGUI_API void Delete();
LGUI_API bool Prepare();
LGUI_API bool GetSize();
LGUI_API bool FromXML(class XMLNode *pXML);
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate);
LGUI_API void Set(const char *Filename, unsigned int ColorKey=0);
LGUI_API void SetFrom(const LGUITexture& other);
char *Name;
unsigned int TextureID;
unsigned int ColorKey;
DWORD Flags;
RECT TextureRect;
LGUITriangle TextureTriangle;
float Alpha;
unsigned int ColorMask;
unsigned int Border;
unsigned char Orientation;
};

View File

@ -0,0 +1,58 @@
#pragma once
struct _CreateTooltip : public _CreateElement
{
unsigned int BackgroundColor;
unsigned int Border;
unsigned int BorderColor;
_CreateFont Font;
// unsigned int TextColor;
// unsigned int FontSize;
bool DefaultTextures;
};
class LGUITooltipLine
{
public:
LGUI_API LGUITooltipLine(const char *p_Text);
LGUI_API ~LGUITooltipLine();
LGUI_API char *Parse();
LGUI_API void Set(const char *p_Text);
char *Text;
bool bVariable;
};
class LGUITooltip :
public LGUIFrame
{
public:
LGUI_API LGUITooltip(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITooltip(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
// LGUI_API void Create(_CreateTooltip &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API void Reset();
LGUI_API void Printf(const char *Format, ...);
LGUI_API void Print(const char *Text);
// -- XML Properties --
LGUIFont *pFont;
// ----------------------
CIndex<LGUITooltipLine*> Lines;
unsigned int nLines;
protected:
LGUI_API void AddLine(const char *Text);
};

View File

@ -0,0 +1,99 @@
#pragma once
class LGUITreeNode
{
public:
LGUI_API LGUITreeNode(class LGUITree *p_pTree, LGUITreeNode *p_pParent, const char *p_Text, unsigned int p_Color);
LGUI_API ~LGUITreeNode();
bool Render(RECT &bounds, unsigned int height, int &Skip);
bool RenderChildren(RECT &bounds, unsigned int height, int &Skip);
void ClearChildren();
void ToggleExpand();
void Expand(bool bExpand);
void Remove();
void SetText(const char *text);
LGUITreeNode *ParseNode(int argc, char *argv[]);
LGUITreeNode *AddChild(int argc, char *argv[]);
LGUITreeNode *InsertSiblingBefore(int argc, char *argv[]);
LGUITreeNode *InsertSiblingAfter(int argc, char *argv[]);
LGUITreeNode *m_pParent;
LGUITreeNode *m_pChildren;
LGUITreeNode *m_pPrevious;
LGUITreeNode *m_pNext;
LGUITreeNode *WalkTree(bool bIncludeCollapsed);
class LGUITexture *m_pImage;
class LGUITexture *m_pImageCollapsible;
class LGUITexture *m_pImageCollapsed;
const char *m_Text;
bool m_bExpanded;
unsigned int m_Color;
class LGUITree *m_pTree;
MetadataStore *m_pMetadataStore;
const char *GetMetadata(const char *key);
bool SetMetadata(const char *key, const char *value);
bool UnsetMetadata(const char *key);
};
class LGUITree :
public LGUIFrame
{
public:
LGUI_API LGUITree(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUITree(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDoubleClick(POINT2I &pt);
LGUI_API bool OnRMouseUp(POINT2I &pt);
LGUI_API bool OnRMouseDown(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
LGUITreeNode *GetNodeByHandle(UINT_PTR handle);
LGUITreeNode *GetNodeByQuery(const char *query);
LGUITreeNode *GetNodeByPosition(int X, int Y, bool &bOnImage);
void SetSelected(LGUITreeNode *node);
LGUIFont *pFont;
class LGUITexture *m_pImage;
class LGUITexture *m_pImageCollapsible;
class LGUITexture *m_pImageCollapsed;
unsigned int VisiblePos;
unsigned int IndentPerDepth;
unsigned int ImageSize;
unsigned int ImageBorder;
unsigned int TextMargin;
unsigned int TextColor;
unsigned int ItemHeight;
unsigned int SelectionBackgroundColor;
unsigned int SelectionTextColor;
LGUITreeNode *pRoot;
LGUIScrollBar *pVerticalBar;
LGUIEmbeddedScript *pOnSelect;
LGUIEmbeddedScript *pOnDeSelect;
LGUITreeNode *pSelectedNode;
std::set<LGUITreeNode *> m_AllNodes;
};

View File

@ -0,0 +1,55 @@
#pragma once
class LGUIVariableGauge :
public LGUIGauge
{
public:
LGUI_API LGUIVariableGauge(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIVariableGauge(void);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
// -- XML Properties --
LGUIDataSequence Data;
float Offset;
// --------------------
};
class LGUIVariableGaugeFactory : public LGUIElementFactory
{
public:
LGUIVariableGaugeFactory():LGUIElementFactory("variablegauge",LGUI_VERSION)
{
}
~LGUIVariableGaugeFactory()
{
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name, class XMLNode *pXML, const char *Template = 0)
{
LGUIVariableGauge *pElement = new LGUIVariableGauge(Type,pParent,Name);
if (!pElement->FromXML(pXML,g_UIManager.FindTemplate(Template)))
{
delete pElement;
return 0;
}
Elements[pElement]=1;
if (pElement->pFiller)
return pElement->pFiller;
return pElement;
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name)
{
LGUIVariableGauge *pElement = new LGUIVariableGauge(Type,pParent,Name);
Elements[pElement]=1;
return pElement;
}
};

View File

@ -0,0 +1,29 @@
#pragma once
class LGUIVariableSlider :
public LGUISlider
{
public:
LGUI_API LGUIVariableSlider(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIVariableSlider(void);
// LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Render();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
// LGUI_API bool OnLMouseUp(POINT2I &pt);
// LGUI_API bool OnLMouseDown(POINT2I &pt);
// LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API void SetValue(unsigned int NewValue);
// -- XML Properties --
LGUIDataSequence Data;
const char *OriginalData;
float Offset;
float VariableRange;
// --------------------
bool InitialValue;
};

View File

@ -0,0 +1,168 @@
#pragma once
#include "LGUIElement.h"
#define ISW_CLOSE 1
#define ISW_MINIMIZE 2
//#define ISW_TITLEBAR 4
#define ISW_RESIZEWIDTH 8
#define ISW_RESIZEHEIGHT 16
#define ISW_RESIZE (ISW_RESIZEWIDTH|ISW_RESIZEHEIGHT)
#define ISW_OFFSETTITLEBARWIDTH 32
#define ISW_OFFSETTITLEBARHEIGHT 64
#define SIZING_LEFT 1
#define SIZING_RIGHT 2
#define SIZING_TOP 4
#define SIZING_BOTTOM 8
struct _CreateWindow : public _CreateFrame
{
unsigned int Flags;
char *Title;
char *ClickFocus;
};
class CWindowContextMenu : public CContextMenuHandler
{
public:
LGUI_API CWindowContextMenu();
LGUI_API ~CWindowContextMenu();
LGUI_API virtual void OnCreate(unsigned int ParentItemID);
LGUI_API virtual void OnClick(unsigned int ItemID);
class LGUIWindow *pWindow;
};
class LGUIWindow : public LGUIFrame
{
public:
LGUI_API LGUIWindow(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
LGUI_API ~LGUIWindow(void);
LGUI_API class LSTypeDefinition *GetLSType();
LGUI_API void Create(_CreateWindow &CreateInfo, class XMLNode *pTemplate=0);
LGUI_API bool IsTypeOf(char *TestFactory);
LGUI_API void Render();
LGUI_API void RenderChildren();
LGUI_API void OnCreate();
LGUI_API bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
LGUI_API void RecalculateSize(bool RecalculateChildren);
LGUI_API bool OnLMouseUp(POINT2I &pt);
LGUI_API bool OnLMouseDown(POINT2I &pt);
LGUI_API bool OnLMouseDoubleClick(POINT2I &pt);
LGUI_API bool OnRMouseUp(POINT2I &pt);
LGUI_API bool OnRMouseDown(POINT2I &pt);
LGUI_API bool OnMouseMove(POINT2I &pt);
LGUI_API bool OnMouseWheel(int Offset);
LGUI_API void Show(bool bShow);
LGUI_API void OnNotify(LGUIElement *pElement, unsigned int Notification, UINT_PTR Value);
LGUI_API virtual void OnResize();
LGUI_API LGUIElement *FindChild(const char *Name);
LGUI_API void Minimize(bool bMinimize);
LGUI_API void ResetWindowPosition();
LGUI_API bool GetStoragePosition(int &StoreX, int &StoreY, unsigned int &StoreWidth, unsigned int &StoreHeight);
LGUI_API void SetTitle(const char *title);
// -- XML Properties --
unsigned int Flags;
char *Title;
char *ClickFocus;
unsigned int MinHeight;
unsigned int MinWidth;
LGUIEmbeddedScript *pOnMove;
LGUIEmbeddedScript *pOnSize;
LGUIEmbeddedScript *pOnReset;
// ---
unsigned int PreMinimizeHeight;
unsigned int PreMinimizeWidth;
int PreMinimizeTitleBarX;
int PreMinimizeTitleBarY;
bool bMinimized;
bool bMoving;
bool bLocked;
unsigned int Sizing;
POINT2I SizingOffset;
POINT2I MovingOffset;
class LGUIWindowClient *pClient;
class LGUIFrame *pTitleBar;
class LGUIText *pTitle;
class LGUIButton *pMinimize;
class LGUIButton *pMaximize;
class LGUIButton *pClose;
CWindowContextMenu ContextMenu;
// CWindowSubmenu SubMenu;
};
class LGUIWindowClient : public LGUIFrame
{
public:
LGUIWindowClient(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
~LGUIWindowClient(void);
bool IsTypeOf(char *TestFactory);
void OnCreate()
{
pWindow->OnCreate();
}
void OnNotify(LGUIElement *pElement, unsigned int Notification, unsigned int Value)
{
pWindow->OnNotify(pElement,Notification,Value);
}
class LGUIWindow *pWindow;
};
template<class T,LSTypeDefinition **Q=0>
class LGUIWindowFactory : public LGUIElementFactory
{
public:
LGUIWindowFactory(const char *p_Type):LGUIElementFactory(p_Type,LGUI_VERSION)
{
}
~LGUIWindowFactory()
{
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name, class XMLNode *pXML, const char *Template = 0)
{
T *pElement = new T(Type,pParent,Name);
if (!pElement->FromXML(pXML,g_UIManager.FindTemplate(Template)))
{
if (pParent)
pParent->DeleteChild(pElement);
else
delete pElement;
return 0;
}
Elements[pElement]=1;
pElement->OnCreate();
pElement->ExecuteOnLoad();
return pElement->pClient;
}
virtual LGUIElement *CreateUIElement(LGUIElement *pParent, const char *Name)
{
T *pElement = new T(Type,pParent,Name);
Elements[pElement]=1;
return pElement;
}
virtual LSTypeDefinition *GetLSType() {if (!Q) return 0; return *Q;}
};
/**/

527
libs/isxdk/include/ISXDK.h Normal file
View File

@ -0,0 +1,527 @@
#pragma once
#pragma pack(push)
#pragma pack(8)
//
// Inner Space Extension Library
// (c) 2004-2016 Lavish Software, LLC
//
#define ISXDK_VERSION 0x0035
#pragma warning( push )
#pragma warning( disable : 4996 )
//#include <tchar.h>
#include <windows.h>
#include <map>
#include <string>
#include "utf8string.h"
#include <algorithm>
#include <math.h>
#include "WinThreading.h"
#include "Index.h"
#include "Queue.h"
#include "FileList.h"
#ifndef ISXDK_NOLAVISHSCRIPT
#include "LavishScript/LavishScript.h"
#else
#define LSType unsigned int
#define fLSCommand unsigned int
#define fLSTopLevelObject unsigned int
#define PLSOBJECT unsigned int
#define CTempObject unsigned int
#define CNavPath unsigned int
#define RGBCOLOR unsigned int
//#define fLSEventTarget unsigned int
struct POINT2I
{
int X;
int Y;
};
struct POINT2F
{
float X;
float Y;
};
struct POINT3F : public POINT2F
{
float Z;
};
#endif
#ifndef ISXDK_NOLAVISHSCRIPT
typedef void (__cdecl *fLSEventTarget)(int argc, char *argv[], PLSOBJECT);
#else
typedef void (__cdecl *fLSEventTarget)(int argc, char *argv[], void *);
typedef void (__cdecl *fLSGenericEnumCallback)(const char *Name, void *pData);
#ifdef RGBCOLOR
#undef RGBCOLOR
#endif
typedef struct _RGBColor
{
union {
unsigned int ulColor;
struct {
unsigned char Red;
unsigned char Green;
unsigned char Blue;
unsigned char Reserved;
};
struct {
unsigned char B;
unsigned char G;
unsigned char R;
unsigned char A;
};
unsigned int ARGB;
};
} RGBCOLOR, *PRGBCOLOR;
#endif
#ifndef ISXDK_NOISUI
#pragma comment(lib,"ISUI.lib")
#include "ISUI/LGUI.h"
#endif
using namespace std;
#define MakeLower(yourstring) transform (yourstring.begin(),yourstring.end(), yourstring.begin(), tolower);
// from Blech.h
#ifndef BLECHVERSION
typedef struct _BLECHVALUE {
char *Name;
char *Value;
struct _BLECHVALUE *pNext;
} BLECHVALUE, *PBLECHVALUE;
typedef unsigned int (__stdcall *fBlechVariableValue)(char *VarName, char *Value);
typedef void (__stdcall *fBlechCallback)(unsigned int ID, void *pData, PBLECHVALUE pValues);
#endif
#ifndef FUNCTION_AT_ADDRESS
#define FUNCTION_AT_ADDRESS(function,offset) __declspec(naked) function\
{\
__asm{mov eax, offset};\
__asm{jmp eax};\
}
#endif
#ifndef FUNCTION_AT_VARIABLE_ADDRESS
#define FUNCTION_AT_VARIABLE_ADDRESS(function,variable) __declspec(naked) function\
{\
__asm{mov eax, [variable]};\
__asm{jmp eax};\
}
#endif
#ifndef FUNCTION_AT_VIRTUAL_ADDRESS
#define FUNCTION_AT_VIRTUAL_ADDRESS(function,virtualoffset) __declspec(naked) function\
{\
__asm{mov eax, [ecx]};\
__asm{lea eax, [eax+virtualoffset]};\
__asm{mov eax, [eax]};\
__asm{jmp eax};\
}
#endif
#ifndef DETOUR_TRAMPOLINE_EMPTY
#define DETOUR_TRAMPOLINE_EMPTY(trampoline) \
__declspec(naked) trampoline \
{ \
__asm { nop };\
__asm { nop };\
__asm { xor eax, eax };\
__asm { mov eax, [eax] };\
__asm { ret };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
__asm { nop };\
}
#endif
#ifndef ISXDK_NOLAVISHSCRIPT
struct NamedPoint
{
char Name[128];
POINT3F pt;
};
class CNavPath
{
public:
CNavPath()
{
nPoints=0;
}
~CNavPath()
{
Reset();
}
void Reset()
{
Points.Cleanup();
nPoints=0;
}
void RemoveLast()
{
if (nPoints)
{
nPoints--;
delete Points[nPoints];
Points[nPoints]=0;
}
}
void AddPoint(POINT3F &pt, char *Name=0)
{
NamedPoint *pPoint=new NamedPoint;
pPoint->pt=pt;
if (Name)
{
strncpy(pPoint->Name,Name,128);
pPoint->Name[127]=0;
}
else
pPoint->Name[0]=0;
Points+=pPoint;
nPoints++;
}
void Reverse()
{
if (nPoints)
{
CLock L(&Points.CS,1);
unsigned int Mid=nPoints/2;
unsigned int nPointsLess1=nPoints-1;
for (unsigned int i = 0 ; i < Mid ; i++)
{
unsigned int Second=nPointsLess1-i;
NamedPoint* Temp=Points[i];
Points[i]=Points[Second];
Points[Second]=Temp;
}
}
}
unsigned int nPoints;
CIndex<NamedPoint*> Points;
};
class CPixelMap
{
public:
CPixelMap(unsigned int nRows, unsigned int nColumns)
{
Rows=(RGBCOLOR**)malloc(nRows*sizeof(RGBCOLOR**));
unsigned int BufferSize=nRows*nColumns*sizeof(RGBCOLOR);
Buffer=(RGBCOLOR*)malloc(BufferSize);
ZeroMemory(Buffer,BufferSize);
for (unsigned int i = 0 ; i < nRows ; i++)
{
Rows[i]=&Buffer[nColumns*i];
}
}
~CPixelMap()
{
free(Rows);
free(Buffer);
};
RGBCOLOR **Rows;
private:
RGBCOLOR *Buffer;
};
static inline bool IsNumber(const char *String)
{
if (*String==0)
return false;
if (*String=='-')
String++;
while(*String)
{
if (!((*String>='0' && *String<='9') || *String=='.'))
return false;
++String;
}
return true;
}
static inline bool IsHex(const char *String)
{
if (*String==0)
return false;
while(*String)
{
if ((*String<'0' || *String>'9') &&
(*String<'a' || *String>'f') &&
(*String<'A' || *String>'F')
)
return false;
++String;
}
return true;
}
#endif
static inline bool IsAbsolutePath(const char *String)
{
if (!String)
return false;
if (String[0]=='\\' || String[0]=='/')
return true;
if (strchr(String,':'))
return true;
return false;
}
static inline bool IsAbsolutePath(const wchar_t *String)
{
if (!String)
return false;
if (String[0]=='\\' || String[0]=='/')
return true;
if (wcschr(String,':'))
return true;
return false;
}
#ifndef FOPEN_UTF8
#define FOPEN_UTF8
static inline FILE *fopen_utf8(const char *filename, const char *mode)
{
WCHAR wFilename[512];
wFilename[0]=0;
MultiByteToWideChar(CP_UTF8,0,filename,-1,wFilename,512);
wFilename[511]=0;
WCHAR wMode[512];
#pragma warning( push )
#pragma warning( disable : 4996 )
swprintf(wMode,L"%S",mode);
return _wfopen(wFilename,wMode);
#pragma warning( pop )
}
#endif
#ifndef FEXISTS_UTF8
#define FEXISTS_UTF8
static inline bool fexists_utf8(const char *filename)
{
WCHAR wFilename[512];
wFilename[0]=0;
MultiByteToWideChar(CP_UTF8,0,filename,-1,wFilename,512);
wFilename[511]=0;
return (_waccess( wFilename, 0 )) != -1;
}
#endif
#ifndef WFEXISTS
#define WFEXISTS
static inline bool _wfexists(const wchar_t *wFilename)
{
return (_waccess( wFilename, 0 )) != -1;
}
#endif
typedef unsigned int HISXSERVICE;
class ISXInterface;
#ifndef LVM_TYPEDEFS
#define LVM_TYPEDEFS
typedef void (__stdcall *fDomainEnumCallback)(const char *Name, void *pData);
typedef void * (__stdcall *fGetAPI)(const char *Name, unsigned int Version);
#endif
typedef void (__cdecl *fISService)(bool Broadcast, unsigned int MSG, void *lpData);
typedef void (__cdecl *fISServiceRequest)(ISXInterface *pClient, unsigned int MSG, void *lpData);
typedef ISXInterface *(__cdecl *fCreateISXInterface)(unsigned int);
typedef void (__cdecl *fSetEnumCallback)(const char *Name, void *pData);
typedef void (__cdecl *fNavWorldEnumCallback)(const char *Name, void *pData);
typedef void (__cdecl *fSettingEnumCallback)(const char *Name, const char *Value, void *pData);
#include "ISInterface.h"
#include "ISXInterface.h"
#include "ColumnRenderer.h"
#include "Services.h"
class ISXPreParse
{
public:
inline ISXPreParse(class ISInterface *pInterface, const char *Text)
{
ID=pInterface->PreParseText(Text);
}
inline ~ISXPreParse()
{
pInterface->FreePreParsed(ID);
}
inline bool RetrieveOriginalText(char *buf, size_t buflen)
{
return pInterface->RetrieveOriginalText(ID,buf,buflen);
}
inline bool RetrieveProcessedText(char *buf, size_t buflen)
{
return pInterface->RetrieveProcessedText(ID,buf,buflen);
}
unsigned int ID;
ISInterface *pInterface;
};
class ISXDataSequence
{
public:
inline ISXDataSequence(class ISInterface *pInterface, const char *DataSequence)
{
ID=pInterface->PreParseText(DataSequence,true);
}
inline ~ISXDataSequence()
{
pInterface->FreePreParsed(ID);
}
inline bool RetrieveOriginalText(char *buf, unsigned int buflen)
{
return pInterface->RetrieveOriginalText(ID,buf,buflen);
}
inline bool RetrieveProcessedText(char *buf, unsigned int buflen)
{
return pInterface->RetrieveProcessedText(ID,buf,buflen);
}
inline bool RetrieveProcessedResult(LSOBJECT &Result)
{
return pInterface->RetrieveProcessedResult(ID,Result);
}
unsigned int ID;
ISInterface *pInterface;
};
#define ISXDllMain(_name_,_class_) \
BOOL APIENTRY DllMain(HANDLE hModule, \
DWORD ul_reason_for_call, \
LPVOID lpReserved \
) \
{ \
if (ul_reason_for_call == DLL_PROCESS_ATTACH) \
{ \
g_hModule = (HMODULE)hModule; \
DWORD ResultLen = GetModuleFileName((HMODULE)hModule, ModulePath, sizeof(ModulePath)); \
memcpy(ActualModulePath, ModulePath, ResultLen + 1); \
if (char *pSlash = strrchr(ModulePath, '\\')) \
{ \
*pSlash = 0; \
ModuleFileName = &pSlash[1]; \
}\
else \
{\
ModuleFileName = ActualModulePath; \
ModulePath[0] = '.'; \
ModulePath[1] = 0; \
}\
sprintf_s(INIFileName, "%s\\%s.ini", ModulePath, _name_); \
sprintf_s(XMLFileName, "%s.xml", _name_); \
sprintf_s(PluginLog, "%s\\%s.log", ModulePath, _name_); \
}\
else if (ul_reason_for_call == DLL_PROCESS_DETACH)\
{\
if (pExtension)\
{\
delete pExtension; \
pExtension = 0; \
}\
}\
return TRUE; \
}
#define ISXDKDependencies(_name_,_class_) \
class LSTypeDefinition * FindLSTypeDefinition(const char *Name)\
{\
return pISInterface->FindLSTypeDefinition(Name); \
}\
void *GetTempBuffer(size_t Size, const void *Copy)\
{\
return pISInterface->GetTempBuffer((unsigned int)Size, (void*)Copy); \
}\
void RegisterTemporaryObject(class CTempObject *pObject)\
{\
pISInterface->AddTempObject(pObject); \
}\
void InvalidatePersistentObject(unsigned int persistentClass, unsigned __int64 persistedValue)\
{\
pISInterface->InvalidatePersistentObject(persistentClass, persistedValue); \
}\
unsigned int RegisterPersistentClass(const char *name)\
{\
return pISInterface->RegisterPersistentClass(name); \
}
#define ISXExports(_name_,_class_) \
extern "C" __declspec(dllexport) ISXInterface * __cdecl CreateISXInterface(unsigned int ISInterfaceVersion) \
{\
if (pExtension || ISInterfaceVersion != ISXDK_VERSION) \
return 0; \
pExtension = new _class_; \
return pExtension; \
}\
extern void __cdecl InitializeISXDK(void *); \
extern "C" __declspec(dllexport) ISXInterface * __cdecl CreateISXInterfaceEx(void *p) \
{\
if (pExtension)\
return 0; \
InitializeISXDK(p); \
pExtension = new _class_; \
return pExtension; \
}\
extern "C" __declspec(dllexport) unsigned int ISXDK_Version = ISXDK_VERSION; \
extern "C" __declspec(dllexport) unsigned int LGUI_Version = LGUI_VERSION;
#define ISXVariables(_name_,_class_) \
char ActualModulePath[MAX_PATH] = { 0 }; \
char ModulePath[MAX_PATH] = { 0 }; \
char PluginLog[MAX_PATH] = { 0 }; \
char INIFileName[MAX_PATH] = { 0 }; \
char XMLFileName[MAX_PATH] = { 0 }; \
const char *ModuleFileName = 0; \
_class_ *pExtension = 0; \
HMODULE g_hModule = 0;
#define ISXPreSetup(_name_,_class_) \
ISXVariables(_name_, _class_) \
ISXDllMain(_name_, _class_); \
ISXExports(_name_, _class_); \
ISXDKDependencies(_name_, _class_);
#pragma warning(pop)
#pragma pack(pop)

View File

@ -0,0 +1,54 @@
#pragma once
typedef struct _ISXSCRIPTENGINECAPS
{
unsigned int Sizeof; // set by the caller before calling GetCaps, to sizeof(ISXSCRIPTENGINECAPS)
// use Sizeof to fill in the caps structure only up to the correct size
bool bPreprocessor; // engine has a preprocessor (e.g. #define, #include, etc)
bool bPersistent; // can run persistent scripts
bool bMultipleScripts; // can run multiple scripts
} ISXSCRIPTENGINECAPS, *PISXSCRIPTENGINECAPS;
class ISXScriptEngine
{
public:
virtual const char *GetName()=0; // unix name if possible, e.g. #!/usr/bin/perl would be "perl"
virtual const char *GetVersion()=0; // used by extensions. implement however you want
virtual bool GetCaps(ISXSCRIPTENGINECAPS &Dest)=0; // used by extensions to retrieve engine capabilities
virtual void Pulse()=0; // for persistent scripts, use this to process microthreads, etc.
virtual bool ExecuteScript(const char *FullFilename, int argc, char *argv[])=0; // used by RunScript command
virtual bool EndScript(const char *Name)=0; // used by EndScript
virtual bool IsScript(const char *FullFilename) {return true;}
};
class ISXSoftwareCursorInterface
{
public:
virtual bool CursorEnabled()=0;
virtual bool GetPosition(int &X, int &Y)=0;
virtual bool SetPosition(int X, int Y)=0;
virtual bool DrawCursor() {return false;}
};
class ISXInterface
{
public:
virtual unsigned int GetVersion();
virtual bool Initialize(ISInterface *pISInterface)=0;
virtual void Shutdown()=0;
virtual bool RequestShutdown()
{
// return false if you must handle asynchronous shutdown behaviors first
// doing so will require an additional unload request.
return true;
}
};

131
libs/isxdk/include/Index.h Normal file
View File

@ -0,0 +1,131 @@
#pragma once
#ifndef __INDEX_H__
#define __INDEX_H__
#include <malloc.h>
//#include <afxmt.h>
#define foreach(variable,counter,index) for (size_t counter=0 ; counter < index.Size ; counter++) if (variable=index[counter])
#define foreachp(variable,counter,index) for (size_t counter=0 ; counter < index->Size ; counter++) if (variable=(*index)[counter])
template <class Any>
class CIndex
{
public:
CIndex()
{
Size=0;
List=0;
}
CIndex(size_t InitialSize)
{
Size=0;
List=0;
Resize(InitialSize);
}
~CIndex()
{// user is responsible for managing elements
CLock(&CS,true);
if (List)
Free(List);
List=0;
Size=0;
}
void Clear()
{
CLock(&CS,true);
for (size_t i = 0 ; i < Size ; i++)
{
if (List[i])
{
List[i]=0;
}
}
}
void Cleanup()
{
CLock(&CS,true);
for (size_t i = 0 ; i < Size ; i++)
{
if (List[i])
{
delete List[i];
List[i]=0;
}
}
}
void Resize(size_t NewSize)
{
CLock(&CS,true);
if (List)
{
if (NewSize>Size)
{
// because we want to zero out the unused portions, we wont use realloc
Any *NewList=(Any*)Malloc(NewSize*sizeof(Any));
memset(NewList,0,NewSize*sizeof(Any));
memcpy(NewList,List,Size*sizeof(Any));
Free(List);
List=NewList;
Size=NewSize;
}
}
else
{
List=(Any*)Malloc(NewSize*sizeof(Any));
memset(List,0,NewSize*sizeof(Any));
Size=NewSize;
}
}
// gets the next unused index, resizing if necessary
inline size_t GetUnused()
{
CLock(&CS,true);
size_t i;
for ( i = 0 ; i < Size ; i++)
{
if (!List[i])
return i;
}
Resize(Size+10);
return i;
}
size_t Count()
{
CLock(&CS,true);
size_t ret=0;
for (size_t i = 0 ; i < Size ; i++)
{
if (List[i])
ret++;
}
return ret;
}
virtual void *Malloc(size_t _Size)
{
return malloc(_Size);
}
virtual void Free(const void *mem)
{
free((void*)mem);
}
size_t Size;
Any *List;
inline Any& operator+=(Any& Value){return List[GetUnused()]=Value;}
inline Any& operator[](size_t Index){return List[Index];}
CSemaphore CS;
};
#endif

View File

@ -0,0 +1,844 @@
#pragma once
#include <map>
#include <set>
using namespace std;
#include <utf8string.h>
extern void InvalidatePersistentObject(unsigned int persistentClass, unsigned __int64 persistedValue);
extern unsigned int RegisterPersistentClass(const char *name);
// Symbiotic base class (e.g. iterator <-> iterator target)
class LSSym
{
public:
virtual void RegisterSym(LSSym*)=0;
virtual void UnregisterSym(LSSym*)=0;
};
class LSIterator : public LSSym
{
public:
LSIterator(class LSIteratable *p_pIteratable, bool b_Reversible, bool b_Const, bool b_RandomAccess);
virtual ~LSIterator();
virtual void RegisterSym(LSSym*) {};
virtual void UnregisterSym(LSSym*) {pIteratable=0;};
virtual bool IsValid()=0;
virtual bool First()=0;
virtual bool Last()=0;
virtual bool GetKey(LSOBJECT &Object)=0;
virtual bool GetValue(LSOBJECT &Object)=0;
virtual bool SetValue(int argc, char *argv[])=0;
virtual bool Jump(int argc, char *argv[])=0;
virtual bool Next()=0;
virtual bool Previous()=0;
virtual void Delete();
virtual class LSIteratable *GetIteratable() {return (class LSIteratable *)pIteratable;}
inline bool IsReversible() {return bReversible;}
inline bool IsConstant() {return bConst;}
inline bool IsRandomAccess() {return bRandomAccess;}
protected:
LSSym *pIteratable;
bool bReversible;
bool bConst;
bool bRandomAccess;
};
class LSIteratable : public LSSym
{
public:
LSIteratable(const char *p_IteratableType);
virtual ~LSIteratable();
virtual void RegisterSym(LSSym* pSym)
{
Iterators.insert((LSIterator*)pSym);
}
virtual void UnregisterSym(LSSym* pSym)
{
Iterators.erase((LSIterator*)pSym);
}
virtual LSIterator *NewIterator(void *PassAlong)=0;
bool NewIterator(LSOBJECT &Dest);
inline const char *GetIteratableType() {return IteratableType;}
protected:
set<LSIterator*> Iterators;
const char *IteratableType;
};
class LSContainer : public LSIteratable
{
public:
LSContainer(const char *p_IteratableType):LSIteratable(p_IteratableType)
{
RegisterContainer();
}
~LSContainer()
{
UnregisterContainer();
InvalidatePersistentObject(RegisterPersistentClass("internal_pointer"), (unsigned __int64)this);
}
virtual bool Clear()=0;
virtual size_t GetContainerSize() = 0;
virtual size_t GetContainerUsed() = 0;
virtual void OnRemoveType(class LSTypeDefinition *pType)=0;
void RegisterContainer();
void UnregisterContainer();
};
/* QUEUE */
struct LSQueueNode
{
LSOBJECT Object;
LSQueueNode *pNext;
};
class LSQueueIterator : public LSIterator
{
public:
LSQueueIterator(class LSQueue *p_pQueue);
virtual bool First();
virtual bool Last();
virtual bool IsValid();
virtual bool GetKey(LSOBJECT &Object);
virtual bool GetValue(LSOBJECT &Object);
virtual bool SetValue(int argc, char *argv[]);
virtual bool Jump(int argc, char *argv[]) {return false;}
virtual bool Next();
virtual bool Previous();
LSQueueNode *pNode;
};
class LSQueue : public LSContainer
{
public:
LSQueue(LSTypeDefinition *p_pType, const char *p_SubType) : LSContainer("queue")
{
Count=0;
pHead=0;
pTail=0;
pType=p_pType;
SubType=strdup(p_SubType);
}
virtual ~LSQueue()
{
Clear();
free((void*)SubType);
}
virtual bool Clear()
{
CLock L(&S,1);
Count=0;
for (set<LSIterator*>::iterator i = Iterators.begin() ; i!=Iterators.end() ; i++)
{
LSQueueIterator *pIterator=(LSQueueIterator *)(*i);
pIterator->pNode=0;
}
while(pHead)
{
LSQueueNode *pNext=pHead->pNext;
pType->FreeVariable(pHead->Object.GetObjectData());
delete pHead;
pHead=pNext;
}
pTail=0;
return true;
}
virtual bool Queue(int argc, char *argv[])
{
CLock L(&S,1);
LSOBJECTDATA Val;
if (!pType->InitVariable(Val,SubType))
return false;
if (!pType->FromText(Val,argc,argv))
{
pType->FreeVariable(Val);
return false;
}
LSQueueNode *pNode=new LSQueueNode;
pNode->pNext=0;
pNode->Object.SetObjectData(Val);
pNode->Object.Type=pType;
if (pTail)
{
pTail->pNext=pNode;
pTail=pNode;
}
else
{
pHead=pTail=pNode;
}
Count++;
return true;
}
virtual bool Dequeue()
{
CLock L(&S,1);
if (!pHead)
return false;
for (set<LSIterator*>::iterator i = Iterators.begin() ; i!=Iterators.end() ; i++)
{
LSQueueIterator *pIterator=(LSQueueIterator *)(*i);
if (pIterator->pNode==pHead)
pIterator->pNode=0;
}
LSQueueNode *pNext=pHead->pNext;
pType->FreeVariable(pHead->Object.GetObjectData());
delete pHead;
pHead=pNext;
if (!pHead)
pTail=0;
Count--;
return true;
}
virtual bool Peek(LSOBJECT &Object)
{
CLock L(&S,1);
if (!pHead)
return 0;
Object.Ptr=&pHead->Object;
Object.Type=GetLSVariableType();
return true;
}
LSTypeDefinition *GetLSVariableType();
inline size_t GetCount() { return Count; }
virtual LSIterator *NewIterator(void *PassAlong);
inline LSQueueNode *GetHead() { return pHead; }
inline LSQueueNode *GetTail() {return pTail; }
inline LSType *GetType() {return pType; }
inline const char *GetSubType() {return SubType; }
virtual size_t GetContainerSize() { return Count; }
virtual size_t GetContainerUsed() { return Count; }
virtual void OnRemoveType(class LSTypeDefinition *pType);
protected:
LSType *pType;
const char *SubType;
LSQueueNode *pHead;
LSQueueNode *pTail;
size_t Count;
CSemaphore S;
};
/* STACK */
struct LSStackNode
{
LSOBJECT Object;
LSStackNode *pNext;
};
class LSStackIterator : public LSIterator
{
public:
LSStackIterator(class LSStack *p_pStack);
virtual bool First();
virtual bool Last();
virtual bool IsValid();
virtual bool GetKey(LSOBJECT &Object);
virtual bool GetValue(LSOBJECT &Object);
virtual bool SetValue(int argc, char *argv[]);
virtual bool Jump(int argc, char *argv[]) {return false;}
virtual bool Next();
virtual bool Previous();
LSStackNode *pNode;
};
class LSStack : public LSContainer
{
public:
LSStack(LSTypeDefinition *p_pType, const char *p_SubType) : LSContainer("stack")
{
Count=0;
pTop=0;
pType=p_pType;
SubType=strdup(p_SubType);
}
virtual ~LSStack()
{
Clear();
free((void*)SubType);
}
virtual bool Clear()
{
CLock L(&S,1);
Count=0;
for (set<LSIterator*>::iterator i = Iterators.begin() ; i!=Iterators.end() ; i++)
{
LSStackIterator *pIterator=(LSStackIterator *)(*i);
pIterator->pNode=0;
}
while(pTop)
{
LSStackNode *pNext=pTop->pNext;
pType->FreeVariable(pTop->Object.GetObjectData());
delete pTop;
pTop=pNext;
}
return true;
}
virtual bool Push(int argc, char *argv[])
{
CLock L(&S,1);
LSOBJECTDATA Val;
if (!pType->InitVariable(Val,SubType))
return false;
if (!pType->FromText(Val,argc,argv))
{
pType->FreeVariable(Val);
return false;
}
LSStackNode *pNode=new LSStackNode;
pNode->pNext=pTop;
pNode->Object.SetObjectData(Val);
pNode->Object.Type=pType;
pTop=pNode;
Count++;
return true;
}
virtual bool Pop()
{
CLock L(&S,1);
if (!pTop)
return false;
for (set<LSIterator*>::iterator i = Iterators.begin() ; i!=Iterators.end() ; i++)
{
LSStackIterator *pIterator=(LSStackIterator *)(*i);
if (pIterator->pNode==pTop)
pIterator->pNode=0;
}
LSStackNode *pNext=pTop->pNext;
pType->FreeVariable(pTop->Object.GetObjectData());
delete pTop;
pTop=pNext;
Count--;
return true;
}
virtual bool Top(LSOBJECT &Object)
{
CLock L(&S,1);
if (!pTop)
return 0;
Object.Ptr=&pTop->Object;
Object.Type=GetLSVariableType();
return true;
}
LSTypeDefinition *GetLSVariableType();
inline size_t GetCount() { return Count; }
virtual LSIterator *NewIterator(void *PassAlong);
inline LSStackNode *GetTop() { return pTop; }
inline LSType *GetType() {return pType; }
inline const char *GetSubType() {return SubType; }
virtual size_t GetContainerSize() { return Count; }
virtual size_t GetContainerUsed() { return Count; }
virtual void OnRemoveType(class LSTypeDefinition *pType);
protected:
LSType *pType;
const char *SubType;
LSStackNode *pTop;
size_t Count;
CSemaphore S;
};
class LSObjectCollectionIterator;
/* COLLECTION (map) */
class LSObjectCollection : public LSContainer
{
public:
LSObjectCollection(LSTypeDefinition *p_pType, const char *p_SubType): LSContainer("collection")
{
pType=p_pType;
SubType=strdup(p_SubType);
}
virtual ~LSObjectCollection()
{
CLock L(&S,1);
free((void*)SubType);
map<utf8stringnocase,PLSOBJECT>::iterator i;
for (i = Map.begin() ; i!=Map.end() ; i++)
{
pType->FreeVariable(i->second->GetObjectData());
delete i->second;
}
}
virtual bool Clear()
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i;
for (i = Map.begin() ; i!=Map.end() ; i++)
{
pType->FreeVariable(i->second->GetObjectData());
delete i->second;
}
Map.clear();
Iterator=Map.end();
return true;
}
virtual bool GetFirstItem(LSOBJECT &Dest)
{
CLock L(&S,1);
Iterator=Map.begin();
if (Iterator!=Map.end())
{
Dest.Type=GetLSVariableType();
Dest.Ptr=Iterator->second;
return true;
}
return false;
}
virtual bool GetCurrentItem(LSOBJECT &Dest)
{
CLock L(&S,1);
if (Iterator!=Map.end())
{
Dest.Type=GetLSVariableType();
Dest.Ptr=Iterator->second;
return true;
}
return false;
}
virtual bool GetNextItem(LSOBJECT &Dest)
{
CLock L(&S,1);
Iterator++;
if (Iterator!=Map.end())
{
Dest.Type=GetLSVariableType();
Dest.Ptr=Iterator->second;
return true;
}
return false;
}
virtual const char *GetFirstKey()
{
CLock L(&S,1);
Iterator=Map.begin();
if (Iterator!=Map.end())
{
return Iterator->first.c_str();
}
return false;
}
virtual const char * GetCurrentKey()
{
CLock L(&S,1);
if (Iterator!=Map.end())
{
return Iterator->first.c_str();
}
return false;
}
virtual const char *GetNextKey()
{
CLock L(&S,1);
Iterator++;
if (Iterator!=Map.end())
{
return Iterator->first.c_str();
}
return false;
}
virtual bool GetItem(const char *Key, LSOBJECT &Dest)
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i=Map.find(Key);
if (i==Map.end())
return false;
Dest.Type=GetLSVariableType();
Dest.Ptr=i->second;
return true;
}
/*
bool CreateItem(const char *Key)
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i=Map.find(Key);
if (i==Map.end())
{
LSOBJECTDATA Val;
if (pType->InitVariable(Val,SubType))
{
PLSOBJECT pObject=new LSOBJECT;
pObject->VarPtr=Val;
pObject->Type=pType;
Map[Key]=pObject;
return true;
}
}
return false;
}
/**/
virtual void SetItem(const char *Key, LSOBJECTDATA &ObjectData)
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i=Map.find(Key);
if (i!=Map.end())
{
// existing
PLSOBJECTDATA pVal = &i->second->GetObjectData();
pType->FreeVariable(*pVal);
i->second->SetObjectData(ObjectData);
}
else
{
PLSOBJECT pObject=new LSOBJECT;
pObject->SetObjectData(ObjectData);
pObject->Type=pType;
Map[Key]=pObject;
}
}
virtual void SetItem(const char *Key, int argc, char *argv[])
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i=Map.find(Key);
if (i!=Map.end())
{
// existing
PLSOBJECTDATA pVal = &i->second->GetObjectData();
pType->FreeVariable(*pVal);
if (!pType->InitVariable(*pVal,SubType))
{
delete i->second;
Map.erase(Key);
return;
}
if (!pType->FromText(*pVal,argc,argv))
{
pType->FreeVariable(*pVal);
delete i->second;
Map.erase(Key);
return;
}
}
else
{
LSOBJECTDATA Val;
if (!pType->InitVariable(Val,SubType))
return;
if (!pType->FromText(Val,argc,argv))
{
pType->FreeVariable(Val);
return;
}
PLSOBJECT pObject=new LSOBJECT;
pObject->SetObjectData(Val);
pObject->Type=pType;
Map[Key]=pObject;
}
}
virtual void RemoveItem(const char *Key)
{
CLock L(&S,1);
map<utf8stringnocase,PLSOBJECT>::iterator i=Map.find(Key);
if (i!=Map.end())
{
InvalidateIterators(i);
// delete existing
pType->FreeVariable(i->second->GetObjectData());
delete i->second;
Map.erase(Key);
Iterator=Map.end();
}
}
LSTypeDefinition *GetLSVariableType();
inline size_t GetCount() {return Map.size();}
inline LSType *GetType() {return pType;}
inline const char *GetSubType() {return SubType;}
virtual LSIterator *NewIterator(void *PassAlong);
void InvalidateIterators(map<utf8stringnocase,PLSOBJECT>::iterator &erasing);
inline map<utf8stringnocase,PLSOBJECT> *GetMap() {return &Map;}
virtual size_t GetContainerSize() {return GetCount();}
virtual size_t GetContainerUsed() { return GetCount(); }
virtual void OnRemoveType(class LSTypeDefinition *pType);
unsigned int RemoveItemsByQuery(unsigned int ID, bool remove_MATCHES);// false removes NON-MATCHES
protected:
LSType *pType;
const char *SubType;
map<utf8stringnocase,PLSOBJECT> Map;
map<utf8stringnocase,PLSOBJECT>::iterator Iterator;
CSemaphore S;
};
class LSObjectCollectionIterator : public LSIterator
{
public:
LSObjectCollectionIterator(class LSObjectCollection *p_pCollection);
virtual bool First();
virtual bool Last();
virtual bool IsValid();
virtual bool GetKey(LSOBJECT &Object);
virtual bool GetValue(LSOBJECT &Object);
virtual bool SetValue(int argc, char *argv[]);
virtual bool Jump(int argc, char *argv[]);
virtual bool Next();
virtual bool Previous();
map<utf8stringnocase,PLSOBJECT>::iterator Iterator;
};
class LSSetIterator : public LSIterator
{
public:
LSSetIterator(class LSSet *p_pCollection);
virtual bool First();
virtual bool Last();
virtual bool IsValid();
virtual bool GetKey(LSOBJECT &Object);
virtual bool GetValue(LSOBJECT &Object);
virtual bool SetValue(int argc, char *argv[]);
virtual bool Jump(int argc, char *argv[]);
virtual bool Next();
virtual bool Previous();
set<utf8stringnocase>::iterator Iterator;
};
/* SET */
class LSSet : public LSContainer
{
public:
LSSet(): LSContainer("set")
{
}
virtual ~LSSet()
{
CLock L(&S,1);
}
virtual bool Clear()
{
CLock L(&S,1);
Set.clear();
return true;
}
virtual bool Contains(const char *Key)
{
CLock L(&S,1);
set<utf8stringnocase>::iterator i=Set.find(Key);
return i!=Set.end();
}
virtual bool GetFirstKey(utf8string &Dest)
{
CLock L(&S,1);
Iterator=Set.begin();
if (Iterator!=Set.end())
{
Dest=*Iterator;
return true;
}
return false;
}
virtual bool GetCurrentKey(utf8string &Dest)
{
CLock L(&S,1);
if (Iterator!=Set.end())
{
Dest=*Iterator;
return true;
}
return false;
}
virtual bool GetNextKey(utf8string &Dest)
{
CLock L(&S,1);
Iterator++;
if (Iterator!=Set.end())
{
Dest=*Iterator;
return true;
}
return false;
}
virtual void AddItem(const char *Key)
{
CLock L(&S,1);
Set.insert(Key);
}
virtual void RemoveItem(const char *Key)
{
CLock L(&S,1);
Set.erase(Key);
}
inline size_t GetCount() {return Set.size();}
virtual LSIterator *NewIterator(void *PassAlong);
virtual size_t GetContainerSize() { return GetCount(); }
virtual size_t GetContainerUsed() { return GetCount(); }
virtual void OnRemoveType(class LSTypeDefinition *pType);
inline set<utf8stringnocase> *GetSet() {return &Set;}
protected:
set<utf8stringnocase> Set;
set<utf8stringnocase>::iterator Iterator;
CSemaphore S;
};
class LSIndexIterator : public LSIterator
{
public:
LSIndexIterator(class LSIndex *p_pIndex);
bool AdvanceToValid();
bool ReverseToValid();
virtual bool First();
virtual bool Last();
virtual bool IsValid();
virtual bool GetKey(LSOBJECT &Object);
virtual bool GetValue(LSOBJECT &Object);
virtual bool SetValue(int argc, char *argv[]);
virtual bool Jump(int argc, char *argv[]);
virtual bool Next();
virtual bool Previous();
size_t N;
};
class LSIndex : public LSContainer
{
public:
LSIndex(class LSTypeDefinition *p_pType, const char *p_SubType);
virtual ~LSIndex();
virtual unsigned int AddItem(int argc, char *argv[]);
virtual bool SetItem(size_t N, int argc, char *argv[]);
virtual bool DeleteItem(size_t N);
virtual unsigned int GetNextItem(size_t N);
virtual bool Resize(size_t NewSize);
virtual bool Swap(size_t A, size_t B);
virtual bool Move(size_t From, size_t To);
virtual bool Clear();
virtual void Collapse();
bool ShiftUp(size_t From, size_t count);
virtual PLSOBJECT GetItem(size_t N);
inline class LSTypeDefinition *GetType()
{
return pType;
}
inline const char *GetSubType()
{
return SubType;
}
inline unsigned int AddItem(const char *value)
{
char *argv[]={(char*)value};
return AddItem(1,argv);
}
unsigned int AddItem(LSOBJECTDATA &value);// to be used only for types that do not require allocation of memory (e.g. int)
inline size_t GetUsed()
{
return Count;
}
inline size_t GetAllocated()
{
return Index.Size;
}
inline bool IsConstant()
{
return bConstant;
}
inline void SetConstant(bool p_bConstant) {bConstant=p_bConstant;}
virtual size_t GetContainerSize() { return GetAllocated(); }
virtual size_t GetContainerUsed() { return GetUsed(); }
virtual LSIterator *NewIterator(void *PassAlong);
virtual void OnRemoveType(class LSTypeDefinition *pType);
unsigned int DeleteItemsByQuery(unsigned int ID, bool remove_MATCHES);// false removes NON-MATCHES
CIndex<PLSOBJECT> *GetIndex() {return &Index;}
protected:
CIndex<PLSOBJECT> Index;
class LSTypeDefinition *pType;
const char *SubType;
size_t Count;
bool bConstant;
};
extern bool InitializeIterator(LSIteratable *pIteratable,void *PassAlong,LSOBJECT &Object);

View File

@ -0,0 +1,560 @@
#pragma once
#pragma warning( push )
#pragma warning( disable : 4505 )
#ifndef __LSTYPE_H__
#define __LSTYPE_H__
#define TypeMember(name) AddMember((DWORD)name,""#name)
#define TypeMethod(name) AddMethod((DWORD)name,""#name)
#include <math.h>
#include <map>
#include <string>
using namespace std;
typedef struct _RGBColor
{
union {
unsigned int ulColor;
struct {
unsigned char Red;
unsigned char Green;
unsigned char Blue;
unsigned char Reserved;
};
struct {
BYTE B;
BYTE G;
BYTE R;
BYTE A;
};
DWORD ARGB;
};
} RGBCOLOR, *PRGBCOLOR;
typedef struct _LSVarPtr
{
_LSVarPtr()
{
Int64 = 0;
}
union
{
__int64 Int64;
double Float64;
unsigned char Array64[8];
struct
{
union
{
void *Ptr;
float Float;
unsigned int DWord;
unsigned int *DWordPtr;
int Int;
unsigned char Array[4];
char *CharPtr;
wchar_t *WCharPtr;
__int64 *Int64Ptr;
double *Float64Ptr;
const void *ConstPtr;
const char *ConstCharPtr;
const wchar_t *ConstWCharPtr;
RGBCOLOR RGB;
};
unsigned int HighDWord;
};
};
} LSOBJECTDATA, *PLSOBJECTDATA, LSVARPTR, *PLSVARPTR;
typedef struct _LSTypeVar
{
_LSTypeVar()
{
Type = 0;
Int64 = 0;
}
__inline LSOBJECTDATA &GetObjectData()
{
return *(LSOBJECTDATA*)&Int64;
}
__inline void SetObjectData(const LSOBJECTDATA &new_data)
{
Int64 = new_data.Int64;
}
union {
class LSTypeDefinition *Type;
class LSTypeDefinition *ObjectType;
};
union {
// LSOBJECTDATA VarPtr;
// LSOBJECTDATA ObjectData;
__int64 Int64;
double Float64;
unsigned char Array64[8];
struct
{
union
{
void *Ptr;
float Float;
unsigned int DWord;
unsigned int *DWordPtr;
int Int;
unsigned char Array[4];
char *CharPtr;
wchar_t *WCharPtr;
__int64 *Int64Ptr;
double *Float64Ptr;
const void *ConstPtr;
const char *ConstCharPtr;
const wchar_t *ConstWCharPtr;
RGBCOLOR RGB;
};
unsigned int HighDWord;
};
};
} LSOBJECT, *PLSOBJECT, LSTYPEVAR, *PLSTYPEVAR;
typedef bool(__cdecl *fLSTypeMember)(LSTypeDefinition *pType, LSOBJECTDATA, int argc, char *argv[], LSOBJECT &);
typedef bool(__cdecl *fLSTypeMethod)(LSTypeDefinition *pType, LSOBJECTDATA &, int argc, char *argv[]);
typedef void (__cdecl *fLSGenericEnumCallback)(const char *Name, void *pData);
typedef struct _LSTypeMember
{
unsigned int ID;
char *Name;
union {
fLSTypeMember MemberCallback;
fLSTypeMethod MethodCallback;
};
_LSTypeMember *pPrev;
_LSTypeMember *pNext;
} LSTYPEMEMBER, *PLSTYPEMEMBER, LSTYPEMETHOD, *PLSTYPEMETHOD;
typedef struct _Point1f
{
float X;
} POINT1F, *PPOINT1F;
typedef struct _Point2f : public _Point1f
{
float Y;
} POINT2F, *PPOINT2F;
typedef struct _Point3f : public _Point2f
{
float Z;
} POINT3F, *PPOINT3F;
typedef struct _Point1i
{
int X;
} POINT1I, *PPOINT1I;
typedef struct _Point2i : public _Point1i
{
int Y;
} POINT2I, *PPOINT2I;
typedef struct _Point3i : public _Point2i
{
int Z;
} POINT3I, *PPOINT3I;
static inline FLOAT GetDistance3D(_Point3f &P1,_Point3f &P2)
{
FLOAT dX = P1.X - P2.X;
FLOAT dY = P1.Y - P2.Y;
FLOAT dZ = P1.Z - P2.Z;
return sqrtf(dX*dX + dY*dY + dZ*dZ);
}
static inline FLOAT GetDistance3DNoSqrt(_Point3f &P1,_Point3f &P2)
{
FLOAT dX = P1.X - P2.X;
FLOAT dY = P1.Y - P2.Y;
FLOAT dZ = P1.Z - P2.Z;
return (dX*dX + dY*dY + dZ*dZ);
}
static inline FLOAT GetDistance2D(_Point2f &P1,_Point2f &P2)
{
FLOAT dX = P1.X - P2.X;
FLOAT dY = P1.Y - P2.Y;
return sqrtf(dX*dX + dY*dY);
}
static inline FLOAT GetDistance2DNoSqrt(_Point2f &P1,_Point2f &P2)
{
FLOAT dX = P1.X - P2.X;
FLOAT dY = P1.Y - P2.Y;
return (dX*dX + dY*dY);
}
static inline FLOAT GetDistance2D(_Point2i &P1,_Point2i &P2)
{
FLOAT dX = (FLOAT)(P1.X - P2.X);
FLOAT dY = (FLOAT)(P1.Y - P2.Y);
return sqrtf(dX*dX + dY*dY);
}
static inline FLOAT GetDistance2DNoSqrt(_Point2i &P1,_Point2i &P2)
{
FLOAT dX = (FLOAT)(P1.X - P2.X);
FLOAT dY = (FLOAT)(P1.Y - P2.Y);
return (dX*dX + dY*dY);
}
static bool DistancePointLine(POINT2F &Point,POINT2F &SegmentStart,POINT2F &SegmentEnd,float &Result)
{
float SegmentLength= GetDistance2D(SegmentStart,SegmentEnd);
float U= (((Point.X-SegmentStart.X) * (SegmentEnd.X-SegmentStart.X))+
((Point.Y-SegmentStart.Y) * (SegmentEnd.Y-SegmentStart.Y)))/
(SegmentLength*SegmentLength);
if (U<0.0f || U>1.0f)
{
// no intersection
return false;
}
// calculate intersection point
POINT2F Intersection;
Intersection.X = SegmentStart.X + U * ( SegmentEnd.X - SegmentStart.X );
Intersection.Y = SegmentStart.Y + U * ( SegmentEnd.Y - SegmentStart.Y );
// and now the distance from the point to the start of the segment
Result = GetDistance2D( Point, Intersection );
return true;
}
extern void RegisterTemporaryObject(class CTempObject *);
class CTempObject
{
public:
CTempObject()
{
RegisterTemporaryObject(this);
}
virtual ~CTempObject()
{
}
virtual void Delete()
{
delete this;
}
};
template<typename T>
class CTemporaryObject : public CTempObject
{
public:
T Object;
};
class LSBinary
{
public:
LSBinary(size_t InitialSize = 64);
LSBinary(void *buf, size_t buflen);
~LSBinary();
bool Copy(void *buf, size_t buflen);
size_t Resize(size_t NewSize);
bool Reset(unsigned char Value);
bool Reset(unsigned int Begin, size_t Length, unsigned char Value);
bool Copy(unsigned int Begin, void *buf, size_t buflen);
inline void *GetBuffer()
{
return pBuffer;
}
inline size_t GetSize() { return Size; }
inline size_t GetUsed() { return Used; }
inline void SetUsed(size_t NewUsed) { Used = NewUsed; }
protected:
void *pBuffer;
size_t Size;
size_t Used;
};
#define INHERITDIRECT(_inherit_) \
virtual int GetInheritedMember(LSOBJECTDATA ObjectData, char *Member, int argc, char *argv[], LSOBJECT &Dest)\
{\
return _inherit_->GetMemberEx(ObjectData,Member,argc,argv,Dest);\
}\
virtual int GetInheritedMethod(LSOBJECTDATA &ObjectData, char *Method, int argc, char *argv[])\
{\
return _inherit_->GetMethodEx(ObjectData,Method,argc,argv);\
}\
virtual int GetInheritedIndex(LSOBJECTDATA &ObjectData, int argc, char *argv[], LSOBJECT &Dest)\
{\
return _inherit_->GetIndex(ObjectData,argc,argv,Dest);\
}
#define INHERITINDIRECT(_inherit_,_convertto_,_convertfrom_) \
virtual int GetInheritedMember(LSOBJECTDATA ObjectData, char *Member, int argc, char *argv[], LSOBJECT &Dest)\
{\
LSOBJECTDATA Temp;\
_convertto_;\
return _inherit_->GetMemberEx(Temp,Member,argc,argv,Dest);\
}\
virtual int GetInheritedIndex(LSOBJECTDATA ObjectData, int argc, char *argv[], LSOBJECT &Dest)\
{\
LSOBJECTDATA Temp;\
_convertto_;\
return _inherit_->GetIndex(Temp,argc,argv,Dest);\
}\
virtual int GetInheritedMethod(LSOBJECTDATA &ObjectData, char *Method, int argc, char *argv[])\
{\
LSOBJECTDATA Temp;\
_convertto_;\
int Ret=_inherit_->GetMethodEx(Temp,Method,argc,argv);\
if (Ret>0)\
{\
_convertfrom_;\
}\
return Ret;\
}
class LSTypeDefinition
{
public:
LSTypeDefinition(char *NewName);
inline void InitializeMembers(PLSTYPEMEMBER MemberArray)
{
for (unsigned int i = 0 ; MemberArray[i].ID ; i++)
{
AddMember(MemberArray[i].ID,MemberArray[i].Name);
}
}
virtual ~LSTypeDefinition();
virtual bool __declspec(deprecated) FromString(LSOBJECTDATA &ObjectData, char *Source) {return false;}
virtual bool FromText(LSOBJECTDATA &ObjectData, int argc, char *argv[]);// calls the other FromText by default.
virtual bool FromText(LSOBJECTDATA &ObjectData, char *Source)
{
#pragma warning( push )
#pragma warning( disable : 4996 )
return FromString(ObjectData,Source);
#pragma warning( pop )
}
virtual void InitVariable(LSOBJECTDATA &ObjectData) {ObjectData.Int64=0;}
virtual bool InitVariable(LSOBJECTDATA &ObjectData, const char *SubType) {if (SubType && SubType[0]) return false; InitVariable(ObjectData); return true;}
virtual void FreeVariable(LSOBJECTDATA &ObjectData) {}
virtual bool __declspec(deprecated) GetMember(LSOBJECTDATA ObjectData, char *Member, int argc, char *argv[], LSOBJECT &Dest)
{
return false;
}
virtual bool __declspec(deprecated) GetMethod(LSOBJECTDATA &ObjectData, char *Method, int argc, char *argv[])
{
return false;
}
virtual bool GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER pMember, int argc, char *argv[], LSOBJECT &Dest)
{
#pragma warning( push )
#pragma warning( disable : 4996 )
return GetMember(ObjectData,pMember->Name,argc,argv,Dest);
#pragma warning( pop )
}
virtual bool GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[])
{
#pragma warning( push )
#pragma warning( disable : 4996 )
return GetMethod(ObjectData,pMethod->Name,argc,argv);
#pragma warning( pop )
}
virtual int GetIndex(LSOBJECTDATA ObjectData, int argc, char *argv[], LSOBJECT &Dest)
{
return GetInheritedIndex(ObjectData,argc,argv,Dest);
/* // SAMPLE
// This will let the index automatically access a member called GetIndex
return GetMemberEx(ObjectData,"GetIndex",argc,argv,Dest);
/**/
}
virtual int GetMemberEx(LSOBJECTDATA ObjectData, char *Member, int argc, char *argv[], LSOBJECT &Dest);
virtual int GetMethodEx(LSOBJECTDATA &ObjectData, char *Method, int argc, char *argv[]);
virtual int GetInheritedIndex(LSOBJECTDATA ObjectData, int argc, char *argv[], LSOBJECT &Dest)
{
return -1;
/* // SAMPLE
// convert ObjectData to inherited type
ObjectData.Ptr=((string*)ObjectData.Ptr)->c_str();
// try inherited type
return pStringType->GetIndex(ObjectData,argc,argv,Dest);
/**/
}
virtual int GetInheritedMember(LSOBJECTDATA ObjectData, char *Member, int argc, char *argv[], LSOBJECT &Dest)
{
return -1;
/* // SAMPLE
// convert ObjectData to inherited type
ObjectData.Ptr=((string*)ObjectData.Ptr)->c_str();
// try inherited type
return pStringType->GetMemberEx(ObjectData,Member,argc,argv,Dest);
/**/
}
virtual int GetInheritedMethod(LSOBJECTDATA &ObjectData, char *Method, int argc, char *argv[])
{
return -1;
/*
// SAMPLE: Direct conversion
return pStringType->GetMethodEx(ObjectData,argc,argv);
// SAMPLE: Special conversion required
// make temporary ObjectData for inherited type
LSOBJECTDATA Temp;
Temp.Ptr=((string*)ObjectData.Ptr)->c_str();
// try inherited type
int Ret=pStringType->GetMethodEx(Temp,Method,argc,argv);
if (Ret>0)
{
// string changed, replace old string
((string*)ObjectData.Ptr)->assign(Temp.CharPtr);
}
return Ret;
/**/
}
virtual bool ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int buflen)
{
#pragma warning( push )
#pragma warning( disable : 4996 )
return ToText(ObjectData,buf);
#pragma warning( pop )
}
virtual bool __declspec(deprecated) ToText(LSOBJECTDATA ObjectData, char *Destination)
{
#pragma warning( push )
#pragma warning( disable : 4996 )
return ToString(ObjectData,Destination);
#pragma warning( pop )
}
virtual bool __declspec(deprecated) ToString(LSOBJECTDATA ObjectData, char *Destination)
{
return false;
}
inline char *GetName() {return &TypeName[0];}
inline LSTypeDefinition *GetInheritance() {return pInherits;}
char *GetMemberName(unsigned int ID);
bool GetMemberID(char *Name, unsigned int &Result);
PLSTYPEMEMBER FindMember(char *Name);
virtual bool InheritedMember(char *Name);
char *GetMethodName(unsigned int ID);
bool GetMethodID(char *Name, unsigned int &Result);
PLSTYPEMETHOD FindMethod(char *Name);
virtual bool InheritedMethod(char *Name);
virtual LSTypeDefinition *GetVariableType()
{
return this;
}
void SetInheritance(LSTypeDefinition *pNewInherit);
unsigned int RegisterVariable(struct _LSTypeVariable *);
inline struct _LSTypeVariable *GetVariableByID(unsigned int ID)
{
map<unsigned int,struct _LSTypeVariable *>::iterator i=Variables.find(ID);
if (i!=Variables.end())
return i->second;
return 0;
}
void UnregisterVariable(unsigned int ID);
virtual bool AddMember(unsigned int ID, char *Name, fLSTypeMember Callback=0);
virtual bool AddMember(char *Name, fLSTypeMember Callback=0);
virtual bool RemoveMember(char *Name, fLSTypeMember Callback=0);
virtual bool AddMethod(unsigned int ID, char *Name, fLSTypeMethod Callback=0);
virtual bool AddMethod(char *Name, fLSTypeMethod Callback=0);
virtual bool RemoveMethod(char *Name, fLSTypeMethod Callback=0);
unsigned int EnumMembers(fLSGenericEnumCallback Callback, void *pData);
unsigned int EnumMethods(fLSGenericEnumCallback Callback, void *pData);
protected:
char TypeName[32];
CIndex<PLSTYPEMEMBER> Members;
map<string,unsigned int> MemberMap;
CIndex<PLSTYPEMETHOD> Methods;
map<string,unsigned int> MethodMap;
LSTypeDefinition *pInherits;
unsigned int NextMethodID;
unsigned int NextMemberID;
unsigned int NextVariableID;
map<unsigned int,struct _LSTypeVariable *> Variables;
bool bShutdown;
};
class CLSObject : public LSOBJECT
{
public:
CLSObject()
{
Int64=0;
Type=0;
}
~CLSObject()
{
Reset();
}
inline void Reset()
{
if (Type)
{
Type->FreeVariable(GetObjectData());
Type=0;
}
}
bool Initialize(LSTypeDefinition *pType, const char *SubType, int argc=0, char *argv[]=0)
{
if (Type)
Reset();
if (!pType)
return false;
pType=pType->GetVariableType();
if (!pType)
return false;
if (!pType->InitVariable(GetObjectData(), SubType))
return false;
if (!pType->FromText(GetObjectData(), argc, argv))
{
pType->FreeVariable(GetObjectData());
return false;
}
Type=pType;
return true;
}
};
#define LSType LSTypeDefinition
#endif
#pragma warning( pop )

View File

@ -0,0 +1,8 @@
#define MAX_VARSTRING 4096
#include "LSType.h"
#include "LSSTLTypes.h"
typedef bool (__cdecl *fLSTopLevelObject)(int argc, char *argv[], LSTYPEVAR &);
typedef int (__cdecl *fLSCommand)(int argc, char *argv[]);
typedef void (__cdecl *fLSGenericEnumCallback)(const char *Name, void *pData);

221
libs/isxdk/include/Queue.h Normal file
View File

@ -0,0 +1,221 @@
/*****************************************************************************
EQIMBase, the Base C++ classes for handling EQIM
Copyright (C) 2003-2004 Lax
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2,
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Usage of these EQIM clients and derivatives subject you to the rules of
the EQIM network. Access to the network is restricted to paying
subscribers of the online game EverQuest. This software and the EQIM
protocol is provided in good faith to the EverQuest community, and not
intended for malicious purposes. Usage of this software for malicious
purposes is prohibited and any distribution, usage, or mention of
malicious activity can and will be reported to the administrators of the
EQIM network.
******************************************************************************/
// Queue.hpp
//
//////////////////////////////////////////////////////////////////////
#ifndef __QUEUE_HPP__
#define __QUEUE_HPP__
template <class QT>
class Queue
{
public:
Queue();
virtual ~Queue();
bool Empty() const;
QT Pop();
void Push(const QT&);
void Remove(const QT&);
QT& Peek();
void Clear();
private:
struct QueueNode
{
QT data;
QueueNode* prev;
};
//CCriticalSection S;
CSemaphore S;
QueueNode* head;
QueueNode* tail;
};
template <class QT>
Queue<QT>::Queue(void)
{
head=NULL;
tail=NULL;
}
template <class QT>
Queue<QT>::~Queue(void)
{
Clear();
}
template <class QT>
bool Queue<QT>::Empty(void) const
{
if(tail)
return false;
else
return true;
}
template <class QT>
QT Queue<QT>::Pop(void)
{
//CSingleLock L(&S);
//L.Lock();
CLock L(&S,true);
QT TempData;
if(tail)
{
QueueNode* Temp;
Temp = tail;
TempData = tail->data;
tail = tail->prev;
if (!tail)
head=0;
delete Temp;
}
//L.Unlock();
return TempData;
}
template <class QT>
void Queue<QT>::Push(const QT& iData)
{
// CSingleLock L(&S);
// L.Lock();
CLock L(&S,true);
QueueNode* Temp = new QueueNode;//(iData, 0);
Temp->prev=NULL;
Temp->data=iData;
if (head)
{
//head->Prev(Temp);
head->prev=Temp;
head=head->prev;
}
else
{
head=Temp;
tail=head;
}
//L.Unlock();
}
template <class QT>
QT& Queue<QT>::Peek(void)
{
// CSingleLock L(&S);
// L.Lock();
CLock L(&S,true);
//L.Unlock();
return tail->data;
}
template <class QT>
void Queue<QT>::Remove(const QT& iRemove)
{
// CSingleLock L(&S);
// L.Lock();
CLock L(&S,true);
QueueNode* iQueueNode = tail;
QueueNode* Last=0;
while (iQueueNode)
{
if (iQueueNode->data==iRemove)
{
if (head==tail)
{
head=0;
tail=0;
//L.Unlock();
return;
}
else if (iQueueNode==tail)
{
// ack! gotta go through the whole list :(
iQueueNode=head;
while(iQueueNode)
{
Last=iQueueNode;
iQueueNode=iQueueNode->prev;
}
tail=Last;
//L.Unlock();
return;
}
if (iQueueNode->prev)
iQueueNode->prev=iQueueNode->prev->prev;
//L.Unlock();
return;
}
Last=iQueueNode;
iQueueNode=iQueueNode->prev;
}
//L.Unlock();
}
template <class QT>
void Queue<QT>::Clear(void)
{
// CSingleLock L(&S);
// L.Lock();
CLock L(&S,true);
if(head)
{
QueueNode* Temp;
QueueNode* Index;
Temp = tail;
Index = tail;
do
{
Index = Temp->prev;
delete Temp;
} while(Temp = Index);
tail = 0;
head = 0;
}
//L.Unlock();
}
#endif

View File

@ -0,0 +1,462 @@
#pragma once
#pragma warning( push )
#pragma warning( disable : 4505 )
#define ISXSERVICE_MSG (1000)
// Services Messages - General (used for all services)
#define ISXSERVICE_CLIENTADDED 1
#define ISXSERVICE_CLIENTREMOVED 2
#define ISXSERVICE_DISCONNECTED 3
// Service Messages - Service-specific (will be reused for other services)
// System Service "Pulse"
#define PULSE_PULSE (ISXSERVICE_MSG+1)
#define PULSE_PREFRAME (ISXSERVICE_MSG+2)
// System Service "Console"
#define CONSOLE_OUTPUT (ISXSERVICE_MSG+1)
#define CONSOLE_OUTPUT_WITHCODES (ISXSERVICE_MSG+2)
// System Service "Memory"
#define MEM_DETOUR ((ISXSERVICE_MSG)+1)
#define MEM_MODIFY ((ISXSERVICE_MSG)+2)
#define MEM_RELEASEDETOUR ((ISXSERVICE_MSG)+3)
#define MEM_RELEASEMODIFY ((ISXSERVICE_MSG)+4)
#define MEM_ISDETOURED ((ISXSERVICE_MSG)+5)
#define MEM_ISMODIFIED ((ISXSERVICE_MSG)+6)
#define MEM_ENABLEPROTECTION ((ISXSERVICE_MSG)+7)
#define MEM_DISABLEPROTECTION ((ISXSERVICE_MSG)+8)
#define MEM_DETOURAPI ((ISXSERVICE_MSG)+9)
#define MEM_RELEASEAPIDETOUR ((ISXSERVICE_MSG)+10)
#define MEM_ISAPIDETOURED ((ISXSERVICE_MSG)+11)
// Custom Service for memory protection
#define MEMPROTECT_PROTECT ((ISXSERVICE_MSG)+1)
#define MEMPROTECT_UNPROTECT ((ISXSERVICE_MSG)+2)
// System Service "HTTP"
#define HTTPSERVICE_REQUEST ((ISXSERVICE_MSG)+1)
#define HTTPSERVICE_FAILURE ((ISXSERVICE_MSG)+2)
#define HTTPSERVICE_SUCCESS ((ISXSERVICE_MSG)+3)
// System Service "Services"
#define SERVICES_ADDED ((ISXSERVICE_MSG)+1)
#define SERVICES_REMOVED ((ISXSERVICE_MSG)+2)
// System Service "Extensions"
#define EXTENSIONS_ADDED ((ISXSERVICE_MSG)+1)
#define EXTENSIONS_REMOVED ((ISXSERVICE_MSG)+2)
// System Service "Triggers"
#define TRIGGERS_ADD ((ISXSERVICE_MSG)+1)
#define TRIGGERS_REMOVE ((ISXSERVICE_MSG)+2)
#define TRIGGERS_PROCESS ((ISXSERVICE_MSG)+3)
#define TRIGGERS_GETLINE ((ISXSERVICE_MSG)+4)
// System Service "Files"
#define FILES_OPEN ((ISXSERVICE_MSG)+1)
#define FILES_TRACKEDREAD ((ISXSERVICE_MSG)+2)
#define FILES_TRACKEDWRITE ((ISXSERVICE_MSG)+3)
#define FILES_TRACKEDCLOSE ((ISXSERVICE_MSG)+4)
#define FILES_OVERLAPPEDREAD ((ISXSERVICE_MSG)+5)
#define FILES_OVERLAPPEDWRITE ((ISXSERVICE_MSG)+6)
// System Service "Scripts"
#define SCRIPTS_ADDED ((ISXSERVICE_MSG)+1)
#define SCRIPTS_REMOVED ((ISXSERVICE_MSG)+2)
// System Service "Software Cursor"
#define SOFTWARECURSOR_ENABLE ((ISXSERVICE_MSG)+1)
#define SOFTWARECURSOR_DISABLE ((ISXSERVICE_MSG)+2)
// System Service "Script Engines"
#define SCRIPTENGINE_ADD ((ISXSERVICE_MSG)+1)
#define SCRIPTENGINE_REMOVE ((ISXSERVICE_MSG)+2)
#define SCRIPTENGINE_ADDFILEEXT ((ISXSERVICE_MSG)+3)
#define SCRIPTENGINE_REMOVEFILEEXT ((ISXSERVICE_MSG)+4)
#define SCRIPTENGINE_SCRIPTBEGINS ((ISXSERVICE_MSG)+5)
#define SCRIPTENGINE_SCRIPTENDS ((ISXSERVICE_MSG)+6)
#define SCRIPTENGINE_ADDED ((ISXSERVICE_MSG)+7)
#define SCRIPTENGINE_REMOVED ((ISXSERVICE_MSG)+8)
// System Service "Modules"
#define MODULESERVICE_LOADLIBRARY ((ISXSERVICE_MSG)+1)
#define MODULESERVICE_FREELIBRARY ((ISXSERVICE_MSG)+2)
// System Service "System"
#define SYSTEMSERVICE_DIAGNOSTICS ((ISXSERVICE_MSG)+1)
#define SYSTEMSERVICE_CRASHLOG ((ISXSERVICE_MSG)+2)
struct _SystemCrashLog
{
_EXCEPTION_POINTERS *pExceptionInfo;
const char *Identifier;
};
static bool IS_SystemCrashLog(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hSystemService, _EXCEPTION_POINTERS *pExceptionInfo, const char *CrashIdentifier)
{
_SystemCrashLog Data;
Data.pExceptionInfo=pExceptionInfo;
Data.Identifier=CrashIdentifier;
return pISInterface->ServiceRequest(pClient,hSystemService,SYSTEMSERVICE_CRASHLOG,&Data);
}
struct _ModuleServiceLibrary
{
const char *Library;
HMODULE hModule;
};
struct _ScriptEngineScriptBegins
{
class ISXScriptEngine *pInterface;
const char *ScriptName;
};
struct _ScriptEngineScriptEnds
{
class ISXScriptEngine *pInterface;
const char *ScriptName;
};
struct _ScriptEngineFileExt
{
class ISXScriptEngine *pInterface;
const char *Extension;
};
static bool IS_ScriptEngineAdd(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface)
{
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_ADD,pInterface);
}
static bool IS_ScriptEngineRemove(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface)
{
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_REMOVE,pInterface);
}
static bool IS_ScriptEngineScriptBegins(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface, const char *Name)
{
_ScriptEngineScriptBegins Data;
Data.pInterface=pInterface;
Data.ScriptName=Name;
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_SCRIPTBEGINS,&Data);
}
static bool IS_ScriptEngineScriptEnds(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface, const char *Name)
{
_ScriptEngineScriptBegins Data;
Data.pInterface=pInterface;
Data.ScriptName=Name;
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_SCRIPTENDS,&Data);
}
static bool IS_ScriptEngineAddFileExt(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface, const char *Ext)
{
_ScriptEngineFileExt Data;
Data.pInterface=pInterface;
Data.Extension=Ext;
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_ADDFILEEXT,&Data);
}
static bool IS_ScriptEngineRemoveFileExt(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hScriptEngineService, class ISXScriptEngine *pInterface, const char *Ext)
{
_ScriptEngineFileExt Data;
Data.pInterface=pInterface;
Data.Extension=Ext;
return pISInterface->ServiceRequest(pClient,hScriptEngineService,SCRIPTENGINE_REMOVEFILEEXT,&Data);
}
static bool IS_SoftwareCursorEnable(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hSoftwareCursorService, class ISXSoftwareCursorInterface *pInterface)
{
return pISInterface->ServiceRequest(pClient,hSoftwareCursorService,SOFTWARECURSOR_ENABLE,pInterface);
}
static bool IS_SoftwareCursorDisable(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hSoftwareCursorService)
{
return pISInterface->ServiceRequest(pClient,hSoftwareCursorService,SOFTWARECURSOR_DISABLE,0);
}
struct _FileOpen
{
// out
const char *FileName;
// in
bool bTrack;
};
struct _FileIO
{
// out
const char *FileName;
const void *Buffer;
unsigned int Length;
unsigned int Position;
};
struct _FileOverlappedIO
{
// out
HANDLE hFile;
const void *Buffer;
DWORD nLength;
DWORD *nActualTransfer;
LPOVERLAPPED lpOverlapped;
};
struct _EventSet
{
char *Name;
char *Command; // may be NULL
};
struct _TriggerAdd
{
// in
const char *Text;
fBlechCallback Callback;
void *pUserData;
// out
unsigned int ID;
};
struct _TriggerGetLine
{
// out
const char *Text;
};
struct HttpRequest
{
const char *URL;
void *pData;
};
struct HttpFile
{
const char *URL;
char *pBuffer;
size_t Size;
void *pData;
};
static bool IS_HttpRequest(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hHttpService, const char *URL, void *pData)
{
HttpRequest Temp;
Temp.URL=URL;
Temp.pData=pData;
return pISInterface->ServiceRequest(pClient,hHttpService,HTTPSERVICE_REQUEST,&Temp);
}
struct MemIs
{
UINT_PTR Address;
bool Is;
};
struct MemProtect
{// this struct is used only by memory protection extensions, and only for MEMPROTECT_PROTECT
UINT_PTR Address; // in
size_t Length; // in
bool Success; // out
const void *OriginalData; // in
};
struct MemDetour
{
UINT_PTR Address; // in
void *Detour; // in
void *Trampoline; // in
bool Success; // out
};
struct MemDetourAPI
{
void *Detour; // in
const char *DLLName; // in
const char *FunctionName; // in
unsigned int FunctionOrdinal; // in
bool Success; // out
};
struct MemModify
{
UINT_PTR Address; // in
void *NewData; // in
size_t Length; // in
bool Reverse; // in
bool Success; // out
};
#define ISDetourAPI(_hMemoryService_,_Detour_,_DLLName_,_FunctionName_,_FunctionOrdinal_) IS_DetourAPI(this,pISInterface,_hMemoryService_,_Detour_,_DLLName_,_FunctionName_,_FunctionOrdinal_)
static bool IS_DetourAPI(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, ...)
{
va_list ap;
int nArgs = 0;
int i = 0;
UINT_PTR Args[5];
va_start(ap, hMemoryService);
while (i != -1)
{
if (nArgs < 5)
{
Args[nArgs] = i;
nArgs++;
}
i = va_arg(ap, int);
}
va_end(ap);
void *Detour;
char *DLLName;
char *FunctionName;
unsigned int FunctionOrdinal;
if (nArgs == 5)
{
Detour = (PBYTE)Args[1];
DLLName = (char *)Args[2];
FunctionName = (char *)Args[3];
FunctionOrdinal = (unsigned int)Args[4];
}
else
{
return false;
}
MemDetourAPI data;
data.Detour=Detour;
data.DLLName=DLLName;
data.FunctionName=FunctionName;
data.FunctionOrdinal=FunctionOrdinal;
data.Success=false;
return pISInterface->ServiceRequest(pClient,hMemoryService,MEM_DETOURAPI,&data) && data.Success;
}
#define ISUnDetourAPI(_hMemoryService_,Address) IS_UnDetourAPI(this,pISInterface,_hMemoryService_,(UINT_PTR)Address)
static inline void IS_UnDetourAPI(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, UINT_PTR Address)
{
pISInterface->ServiceRequest(pClient,hMemoryService,MEM_RELEASEAPIDETOUR,(void*)Address);
}
#define ISDetour(_hMemoryService_, Address, Detour, Trampoline) IS_Detour(this,pISInterface,_hMemoryService_,(UINT_PTR)Address,Detour,Trampoline)
static bool IS_Detour(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, UINT_PTR Address,...)
{
va_list ap;
int nArgs = 0;
int i = 0;
UINT_PTR Args[3];
va_start(ap, Address);
while (i != -1)
{
if (nArgs < 3)
{
Args[nArgs] = i;
nArgs++;
}
i = va_arg(ap, int);
}
va_end(ap);
void *Detour;
void *Trampoline;
if (nArgs == 3)
{
Detour = (PBYTE)Args[1];
Trampoline = (PBYTE)Args[2];
}
else
{
return false;
}
MemDetour data;
data.Address=Address;
data.Detour=Detour;
data.Trampoline=Trampoline;
data.Success=false;
return pISInterface->ServiceRequest(pClient,hMemoryService,MEM_DETOUR,&data) && data.Success;
}
#define MemoryModify(_hMemoryService_,Address,NewData,Length,Reverse) Memory_Modify(this,pISInterface,_hMemoryService_,(UINT_PTR)Address,NewData,Length,Reverse)
static inline bool Memory_Modify(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, UINT_PTR Address, void *NewData, size_t Length, bool Reverse)
{
MemModify data;
data.Address=Address;
data.NewData=NewData;
data.Length=Length;
data.Reverse=Reverse;
data.Success=false;
return pISInterface->ServiceRequest(pClient,hMemoryService,MEM_MODIFY,&data) && data.Success;
}
#define ISUnDetour(_hMemoryService_,Address) IS_UnDetour(this,pISInterface,_hMemoryService_,(UINT_PTR)Address)
static inline void IS_UnDetour(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, UINT_PTR Address)
{
pISInterface->ServiceRequest(pClient,hMemoryService,MEM_RELEASEDETOUR,(void*)Address);
}
#define MemoryUnModify(_hMemoryService_,Address) Memory_UnModify(this,pISInterface,_hMemoryService_,(UINT_PTR)Address)
static inline void Memory_UnModify(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMemoryService, UINT_PTR Address)
{
pISInterface->ServiceRequest(pClient,hMemoryService,MEM_RELEASEMODIFY,(void*)Address);
}
#define ISAddTrigger(_hTriggerService_,Text,Callback,pUserData) IS_AddTrigger(this,pISInterface,_hTriggerService_,Text,Callback,pUserData)
static inline unsigned int IS_AddTrigger(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hTriggerService, const char *Text, fBlechCallback Callback, void *pUserData=0)
{
_TriggerAdd data;
data.Callback=Callback;
data.ID=0;
data.pUserData=pUserData;
data.Text=Text;
pISInterface->ServiceRequest(pClient,hTriggerService,TRIGGERS_ADD,&data);
return data.ID;
}
#define ISRemoveTrigger(_hTriggerService_,ID) IS_RemoveTrigger(this,pISInterface,_hTriggerService_,ID)
static inline void IS_RemoveTrigger(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hTriggerService, unsigned int ID)
{
pISInterface->ServiceRequest(pClient,hTriggerService,TRIGGERS_REMOVE,(void*)(UINT_PTR)ID);
}
#define ISCheckTriggers(_hTriggerService_,Text) IS_CheckTriggers(this,pISInterface,_hTriggerService_,Text)
static inline void IS_CheckTriggers(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hTriggerService, const char *Text)
{
pISInterface->ServiceRequest(pClient,hTriggerService,TRIGGERS_PROCESS,(void*)Text);
}
#define ISGetTriggerLine(_hTriggerService_) IS_GetTriggerLine(this,pISInterface,_hTriggerService_)
static inline const char *IS_GetTriggerLine(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hTriggerService)
{
_TriggerGetLine data;
data.Text=0;
if (!pISInterface->ServiceRequest(pClient,hTriggerService,TRIGGERS_GETLINE,&data))
return "";
return data.Text;
}
/*
#define ISSetEvent(_hEventService_,Name,Command) IS_SetEvent(this,pISInterface,_hEventService_,Name,Command)
static inline void IS_SetEvent(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hEventService, char *Name, char *Command)
{
_EventSet data;
data.Command=Command;
data.Name=Name;
pISInterface->ServiceRequest(pClient,hEventService,EVENTS_SET,&data);
}
#define ISRemoveEvent(_hEventService_,Name) IS_RemoveEvent(this,pISInterface,_hEventService_,Name)
static inline void IS_RemoveEvent(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hEventService, char *Name)
{
pISInterface->ServiceRequest(pClient,hEventService,EVENTS_REMOVE,(void*)Name);
}
#define ISExecuteEvent(_hEventService_,Name) IS_ExecuteEvent(this,pISInterface,_hEventService_,Name)
static inline void IS_ExecuteEvent(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hEventService, char *Name)
{
pISInterface->ServiceRequest(pClient,hEventService,EVENTS_EXECUTE,(void*)Name);
}
/**/
#pragma warning( pop )

View File

@ -0,0 +1,49 @@
#pragma once
#ifndef __THREADING_H__
#define __THREADING_H__
//#ifdef WIN32
#define THREAD DWORD
//typedef DWORD (*PTHREAD_START_ROUTINE)(LPVOID);
//#else
//#define THREAD void*
//typedef void* (*PTHREAD_START_ROUTINE)(void*);
//#endif
class CPortableSemaphore
{
//virtual void Initialize()=0;
};
class CPortableLock
{
public:
virtual void SetSemaphore(CPortableSemaphore*)=0;
virtual void Lock()=0;
virtual void Unlock()=0;
virtual bool IsLocked()=0;
};
class CPortableThread
{
public:
virtual bool BeginThread(LPTHREAD_START_ROUTINE function, void* pInfo, bool bWait)=0;
virtual void EndThread()=0;
virtual void AbortThread()=0;
bool bThreading;
bool CloseThread;
bool ThreadReady;
void *Info;
};
class CPortableSignal
{
public:
virtual void Wait(unsigned int Timeout, CPortableLock* unlockme=0)=0;
virtual void Wait(CPortableLock* unlockme=0)=0;
virtual void Release()=0;
virtual void Signal(bool*)=0;
};
#endif

View File

@ -0,0 +1,238 @@
#pragma once
#ifndef __WINTHREADING_H__
#define __WINTHREADING_H__
#include <windows.h>
#include <time.h>
#include "Threading.h"
#define CLock CWinLock
#define CSemaphore CWinSemaphore
#define CThread CWindowsThread
#define CSignal CWinSignal
class CWinSemaphore : public CPortableSemaphore
{
public:
CRITICAL_SECTION s;
CWinSemaphore()
{
InitializeCriticalSection(&s);
}
~CWinSemaphore()
{
// if (s.LockCount>=0)
// {
// DeleteCriticalSection(&s);
// }
DeleteCriticalSection(&s);
};
};
class CWinLock : public CPortableLock
{
public:
CWinLock()
{
s=NULL;
Locked=false;
};
CWinLock(CWinSemaphore* sem,bool bLocked=true)
{
s=&sem->s;
if (bLocked && s)
{
EnterCriticalSection(s);
Locked=true;
}
else
Locked=false;
};
~CWinLock()
{
Unlock();
};
void Lock()
{
if (s)
{
EnterCriticalSection(s);
Locked=true;
}
};
void Unlock()
{
if (Locked)
{
LeaveCriticalSection(s);
Locked=false;
}
};
bool IsLocked()
{
return Locked;
};
void SetSemaphore(CPortableSemaphore* sem)
{
s=&((CWinSemaphore*)sem)->s;
};
private:
CRITICAL_SECTION *s;
bool Locked;
};
class CWinSignal : public CPortableSignal
{
public:
CWinSignal(void)
{
InitializeCriticalSection(&waiting);
InitializeCriticalSection(&signaling);
}
~CWinSignal(void)
{
DeleteCriticalSection(&waiting);
DeleteCriticalSection(&signaling);
}
void Wait(unsigned int Timeout, CPortableLock* unlockme=NULL)
{
EnterCriticalSection(&waiting);
if (unlockme)
((CWinLock*)unlockme)->Unlock();
time_t start=time(0);
int scount=0;
{
while(signaling.OwningThread==0)
{
if ((unsigned int)(time(0)-start)>Timeout)
{
LeaveCriticalSection(&waiting);
return;
}
if (scount++>5)
{
scount=0;
Sleep(1);
}
}
}
}
void Wait(CPortableLock* unlockme=NULL)
{
EnterCriticalSection(&waiting);
if (unlockme)
((CWinLock*)unlockme)->Unlock();
time_t start=time(0);
int scount=0;
{
while(signaling.OwningThread==0)
{
/*
if (time(0)-start>Timeout)
{
LeaveCriticalSection(&waiting);
return;
}
*/
if (scount++>5)
{
scount=0;
Sleep(1);
}
}
}
}
void Release()
{
LeaveCriticalSection(&waiting);
}
void Signal(bool* WhileTrue=0)
{
EnterCriticalSection(&signaling);
int scount=0;
while(waiting.OwningThread==0 && (!WhileTrue || *WhileTrue))
{
if (scount++>5)
{
scount=0;
Sleep(1);
}
}
EnterCriticalSection(&waiting);
LeaveCriticalSection(&signaling);
LeaveCriticalSection(&waiting);
}
private:
CRITICAL_SECTION waiting;
CRITICAL_SECTION signaling;
bool bWaiting;
};
static DWORD CWindowsThreadFunction(void *ThreadInstance);
class CWindowsThread : public CPortableThread
{
public:
CWinSemaphore Threading;
DWORD ThreadID;
HANDLE hThread;
CWindowsThread()
{
ThreadReady = false;
bThreading = false;
CloseThread=false;
ThreadID=0;
};
~CWindowsThread()
{
if (bThreading)
EndThread();
};
bool BeginThread(PTHREAD_START_ROUTINE function, void* pInfo,bool bWait)
{
if (bThreading)
return true;
Info=pInfo;
ThreadReady=false;
CloseThread=false;
hThread=CreateThread(NULL,0,(PTHREAD_START_ROUTINE)function,this,0,&ThreadID);
if (hThread==0)
return false;
if (!bWait)
return true;
while(!ThreadReady)
{
Sleep(0);
}
return true;
};
void AbortThread()
{
TerminateThread(hThread,0);
bThreading=false;
}
void EndThread()
{
CloseThread=true;
CWinLock L(&Threading,true);
ThreadID=0;
};
};
#endif

View File

@ -0,0 +1,621 @@
//////////////////////////////////////////////////////////////////////////////////////////////
// utf8string is designed for Win32. Under POSIX, this will simply be an ascii string, but still
// otherwise work.
//
//////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2005 Lavish Software, LLC
// www.lavishsoft.com
//
// LICENSE INFORMATION
// This source file may be used and distributed, commercially or non-commercially, as long as
// this original copyright and license information is left in tact in this source file.
///////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#ifndef __LAVISH_UTF8STRING__
#define __LAVISH_UTF8STRING__
#ifdef ISXDK_VERSION
#ifndef WIN32
#define WIN32
#endif
#endif
#ifdef WIN32
//#include <mbstring.h>
//#include <tchar.h>
#include <malloc.h>
#else
#define strdup strdup
#define strcpy strcpy
#define strncpy strncpy
#define _vstprintf vsprintf
#define _stprintf sprintf
#define strcmp strcmp
#define stricmp strcasecmp
#define strrchr strrchr
#define strlwr strlwr
#define strchr strchr
#endif
#ifdef __MINGW32_VERSION
#define MINGW_SUCKS
#undef strnbcnt
#define strnbcnt(x,y) _mbsnbcnt((const unsigned char *)x,y)
#undef strnccnt
#define strnccnt(x,y) _mbsnccnt((const unsigned char *)x,y)
#else
#endif
//#define strlen(utf8) strnbcnt(utf8,0x7fffffff)
#define strbytes strlen
#define UTF8STRING_INLINE inline
//#define UTF8STRING_INLINE
#ifdef UTF8STRING_POLYMORPH
#define UTF8STRING_VIRTUAL virtual
#define UTF8STRING_INHERIT : public utf8stringbase
#else
#define UTF8STRING_VIRTUAL UTF8STRING_INLINE
#define UTF8STRING_INHERITBASE
#endif
#ifdef UTF8STRING_FAST
#error Fast utf8string not yet implemented
#else
#ifdef UTF8STRING_POLYMORPH
class utf8stringbase
{
public:
virtual unsigned int Bytes()=0;
virtual unsigned int Characters()=0;
virtual int Compare(const char *utf8)=0;
virtual int CompareNoCase(const char *utf8)=0;
virtual const char *Copy(const char *utf8)=0;
virtual const char *GetString()=0;
UTF8STRING_INLINE const char *c_str()
{
return GetString();
}
UTF8STRING_INLINE char *unsafe_str()
{
return (char*)GetString();
}
};
#endif
class utf8stringcharholder UTF8STRING_INHERITBASE
{
public:
UTF8STRING_INLINE char *GetProtectedText() const
{
return Text;
}
protected:
char *Text;
};
class constutf8string UTF8STRING_INHERITBASE
{
public:
static size_t ByteCount(const char *utf8)
{
return strlen(utf8);
}
UTF8STRING_INLINE constutf8string(const char *utf8)
{
Initialize(utf8);
}
UTF8STRING_INLINE constutf8string(const constutf8string &utf8)
{
Initialize(utf8.GetString());
}
/* utf8stringbase */
UTF8STRING_VIRTUAL size_t Bytes()
{
if (!nBytes)
nBytes=strlen(Text);
return nBytes;
}
UTF8STRING_VIRTUAL size_t Characters()
{
if (!nCharacters)
nCharacters=strlen(Text);
return nCharacters;
}
UTF8STRING_VIRTUAL int Compare(const char *utf8)
{
return strcmp(Text,utf8);
}
UTF8STRING_VIRTUAL int CompareNoCase(const char *utf8)
{
return _stricmp(Text,utf8);
}
UTF8STRING_VIRTUAL const char *Copy(const char *utf8)
{
Initialize(utf8);
return utf8;
}
UTF8STRING_VIRTUAL const char *GetString() const
{
return Text;
}
/* operators */
constutf8string& operator=(const constutf8string& utf8)
{
Text=utf8.GetText();
nBytes=utf8.GetBytes();
nCharacters=utf8.GetCharacters();
return *this;
}
constutf8string& operator=(const char* utf8)
{
Initialize(utf8);
return *this;
}
bool operator!( ) const
{
return false;
}
bool operator==(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())==0;
}
bool operator!=(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())!=0;
}
bool operator<(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())<0;
}
bool operator>(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())>0;
}
bool operator<=(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())<=0;
}
bool operator>=(const utf8stringcharholder& str ) const
{
return _stricmp(Text,str.GetProtectedText())>=0;
}
bool operator==(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())==0;
}
bool operator!=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())!=0;
}
bool operator<(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())<0;
}
bool operator>(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())>0;
}
bool operator<=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())<=0;
}
bool operator>=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())>=0;
}
UTF8STRING_INLINE const char *c_str() const
{
return GetString();
}
UTF8STRING_INLINE char *unsafe_str() const
{
return (char*)GetString();
}
protected:
UTF8STRING_INLINE void Initialize(const char *utf8)
{
Text=utf8;
nBytes=0;
nCharacters=0;
}
UTF8STRING_INLINE const char *GetText() const
{
return Text;
}
UTF8STRING_INLINE size_t GetBytes() const
{
return nBytes;
}
UTF8STRING_INLINE size_t GetCharacters() const
{
return nCharacters;
}
const char *Text;
size_t nBytes;
size_t nCharacters;
};
class utf8string : public utf8stringcharholder
{
public:
virtual void *Realloc(void *Block, size_t Size)
{
return realloc(Block,Size);
}
virtual void *Malloc(size_t Size)
{
return malloc(Size);
}
virtual void Free(void *Block)
{
free(Block);
}
static size_t ByteCount(const char *utf8)
{
return strlen(utf8);
}
UTF8STRING_INLINE utf8string()
{
InitializeEmpty();
}
UTF8STRING_INLINE utf8string(const char *utf8)
{
Initialize(utf8);
}
UTF8STRING_INLINE utf8string(const utf8string &utf8)
{
Initialize(utf8.GetString());
}
virtual ~utf8string()
{
ClearText();
}
/* utf8stringbase */
UTF8STRING_VIRTUAL size_t Bytes() const
{
return nBytes;
}
UTF8STRING_VIRTUAL size_t Characters() const
{
return nCharacters;
}
UTF8STRING_VIRTUAL int Compare(const char *utf8)
{
return strcmp(Text,utf8);
}
UTF8STRING_VIRTUAL int CompareNoCase(const char *utf8)
{
return _stricmp(Text,utf8);
}
UTF8STRING_VIRTUAL const char *Copy(const char *utf8)
{
ClearText();
Initialize(utf8);
return Text;
}
UTF8STRING_VIRTUAL const char *GetString() const
{
return Text;
}
/* operators */
utf8string& operator=(const utf8string& utf8)
{
Set(utf8);
return *this;
}
utf8string& operator=(const char* utf8)
{
Set(utf8);
return *this;
}
utf8string& operator+=(const char *utf8)
{
Append(utf8);
return *this;
}
UTF8STRING_INLINE void Set(const utf8string& utf8)
{
size_t NewSize=utf8.nBytes+1;
if (nAllocated<NewSize)
{
Resize(NewSize*2);
}
memcpy(Text,utf8.Text,NewSize);
nBytes=utf8.nBytes;
nCharacters=utf8.nCharacters;
}
UTF8STRING_INLINE void Set(const char *utf8)
{
nBytes=strlen(utf8);
size_t NewSize=nBytes+1;
if (nAllocated<NewSize)
{
Resize(NewSize*2);
}
nCharacters=nBytes;//strnccnt(utf8,0x7fffffff);
memcpy(Text,utf8,NewSize);
}
UTF8STRING_INLINE void SetFromACP(const char *local)
{
int wclen=MultiByteToWideChar(CP_ACP,0,local,-1,0,0);
if (wclen<=0)
{
Set("");
return;
}
wchar_t *Temp=(wchar_t*)alloca(wclen*sizeof(wchar_t));
MultiByteToWideChar(CP_ACP,0,local,-1,Temp,wclen);
size_t NewSize=WideCharToMultiByte(CP_UTF8,0,Temp,-1,0,0,0,0);
nBytes=NewSize-1;
if (nAllocated<NewSize)
{
Resize(NewSize*2);
}
nCharacters=nBytes;
WideCharToMultiByte(CP_UTF8,0,Temp,-1,Text,(int)nAllocated,0,0);
}
UTF8STRING_INLINE void Append(const utf8string& utf8)
{
size_t NewSize=nBytes+utf8.nBytes+1;
if (nAllocated<NewSize)
{
Resize(NewSize*2);
}
memcpy(&Text[nBytes],utf8.Text,utf8.nBytes+1);
nCharacters+=utf8.nCharacters;
nBytes+=utf8.nBytes;
}
UTF8STRING_INLINE void Append(const char *utf8)
{
size_t AddBytes=strlen(utf8);
size_t NewSize=nBytes+AddBytes+1;
if (nAllocated<NewSize)
{
Resize(NewSize*2);
}
memcpy(&Text[nBytes],utf8,AddBytes+1);
nCharacters+=strlen(utf8);
nBytes+=AddBytes;
}
bool operator!( ) const
{
return false;
}
bool operator==(const utf8string& str ) const
{
return strcmp(Text,str.GetString())==0;
}
bool operator!=(const utf8string& str ) const
{
return strcmp(Text,str.GetString())!=0;
}
bool operator<(const utf8string& str ) const
{
return strcmp(Text,str.GetString())<0;
}
bool operator>(const utf8string& str ) const
{
return strcmp(Text,str.GetString())>0;
}
bool operator<=(const utf8string& str ) const
{
return strcmp(Text,str.GetString())<=0;
}
bool operator>=(const utf8string& str ) const
{
return strcmp(Text,str.GetString())>=0;
}
bool operator==(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())==0;
}
bool operator!=(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())!=0;
}
bool operator<(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())<0;
}
bool operator>(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())>0;
}
bool operator<=(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())<=0;
}
bool operator>=(const constutf8string& str ) const
{
return strcmp(Text,str.GetString())>=0;
}
UTF8STRING_INLINE const char *c_str() const
{
return GetString();
}
UTF8STRING_INLINE char *unsafe_str() const
{
return (char*)GetString();
}
protected:
UTF8STRING_INLINE void ClearText()
{
Free(Text);
}
UTF8STRING_INLINE void Clear()
{
ClearText();
nAllocated=0;
nBytes=0;
nCharacters=0;
}
UTF8STRING_INLINE void InitializeEmpty()
{
Text=(char*)Malloc(10);
*(unsigned int*)Text=0;
// Text[0]=0;
// Text[1]=0;
nAllocated=10;
nBytes=0;
nCharacters=0;
}
UTF8STRING_INLINE void Initialize(const char *utf8)
{
if (!utf8)
utf8="";
nCharacters=strlen(utf8);
nBytes=nCharacters;
//nBytes=strlen(utf8);
nAllocated=nBytes+1;
Text=(char*)Malloc(nAllocated);
memcpy(Text,utf8,nAllocated);
}
UTF8STRING_INLINE void Resize(size_t newsize)
{
if (newsize>nAllocated)
{
Text=(char*)Realloc(Text,newsize);
nAllocated=newsize;
}
}
UTF8STRING_INLINE const char *GetText() const
{
return Text;
}
UTF8STRING_INLINE size_t GetAllocated() const
{
return nAllocated;
}
UTF8STRING_INLINE size_t GetBytes() const
{
return nBytes;
}
UTF8STRING_INLINE size_t GetCharacters() const
{
return nCharacters;
}
size_t nAllocated;
size_t nBytes;
size_t nCharacters;
};
class utf8stringnocase : public utf8string
{
public:
UTF8STRING_INLINE utf8stringnocase():utf8string()
{
}
UTF8STRING_INLINE utf8stringnocase(const char *utf8):utf8string(utf8)
{
}
UTF8STRING_INLINE utf8stringnocase(const utf8stringnocase &utf8):utf8string(utf8.GetString())
{
}
bool operator!( ) const
{
return false;
}
bool operator==(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())==0;
}
bool operator!=(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())!=0;
}
bool operator<(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())<0;
}
bool operator>(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())>0;
}
bool operator<=(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())<=0;
}
bool operator>=(const utf8string& str ) const
{
return _stricmp(Text,str.GetString())>=0;
}
bool operator==(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())==0;
}
bool operator!=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())!=0;
}
bool operator<(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())<0;
}
bool operator>(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())>0;
}
bool operator<=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())<=0;
}
bool operator>=(const constutf8string& str ) const
{
return _stricmp(Text,str.GetString())>=0;
}
/*
UTF8STRING_INLINE const char *c_str() const
{
return GetString();
}
UTF8STRING_INLINE char *unsafe_str() const
{
return (char*)GetString();
}
/**/
};
#endif
#endif /* __LAVISH_UTF8STRING__ */

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
scripts/controller.iss Normal file
View File

@ -0,0 +1 @@
test

6
src/Commands.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "ISXMr.h"
int CMD_Mr(int argc, char *argv[])
{
return 0;
}

20
src/Commands.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef COMMAND
#define COMMAND_SELF
#define COMMAND(name,cmd,parse,hide) extern int cmd(int argc, char *argv[])
#endif
// ----------------------------------------------------
// commands
// sample
COMMAND("Mr",CMD_Mr,true,false);
// ----------------------------------------------------
#ifdef COMMAND_SELF
#undef COMMAND_SELF
#undef COMMAND
#endif

27
src/DataTypeList.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef DATATYPE
#define DATATYPE_SELF
#define DATATYPE(_class_,_variable_,_inherits_) extern class _class_ *_variable_
#endif
// ----------------------------------------------------
// data types
// sample data type is the MrType class, and we're making a variable called pMrType.
// this type does not inherit from another type, so we use 0. If it did inherit from another single type,
// we would use the pointer to the definition of that type, such as pStringType
DATATYPE(MrType,pMrType,0);
// ----------------------------------------------------
#ifdef DATATYPE_SELF
#undef DATATYPE_SELF
#undef DATATYPE
#endif

91
src/DataTypes.cpp Normal file
View File

@ -0,0 +1,91 @@
#include "ISXMr.h"
#define DATATYPE(_class_,_variable_,_inherits_) class _class_ *_variable_=0
#include "DataTypeList.h"
#undef DATATYPE
// A LavishScript data type is much like a C++ class. It has data members and methods, and can use
// inheritance. A data type describes the view of a type of object; it is not the object itself.
// The sample data type does NOT allow variables to be created of its type. That is slightly more
// advanced, and unnecessary for most purposes. If you need help with that, please get in touch with
// Lax for an example.
bool MrType::ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int buflen)
{
// The ToString function is used when a data sequence ends with an object of this type. Its job is
// to fill the Destination with the default value of this object. For example, the "int" type simply
// performs itoa (integer to ascii conversion).
// ObjectData is the object, or a pointer to the object. Validate the object here.
if (!ObjectData.Ptr)
return false;
strcpy_s(buf,buflen,"ISXMr");
return true;
}
bool MrType::GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER pMember, int argc, char *argv[], LSOBJECT &Object)
{
// The GetMember function is used when a data sequence accesses a member of an object of this type.
// Its job is to take the member name (such as RetrieveData), retrieve the requested data, and place
// it in Dest, to be used as the next object in the data sequence. argc and argv are used if the member
// access uses an index, such as RetrieveData[1] or RetrieveData[my coat,1,seventeen]. argc is the
// number of parameters (or dimensions) separated by commas, and does NOT include the name of the member.
// As a general rule, members should NOT make changes to the object, or perform actions -- that is what
// methods are for :)
// LSOBJECT, used for Dest, is ObjectData with a Type. Type should be set to a pointer to a data type,
// such as Dest.Type=pIntType for integers. Do not set the Type or return true if the data retrieval
// fails (there is no object). For example, if the requested data is a string, and the string does
// not exist, return false and do not set the type.
// ObjectData is the object, or a pointer to the object. Validate the object here.
if (!ObjectData.Ptr)
return false;
// Based on the member ID, retrieve the desired member
switch((MrTypeMembers)pMember->ID)
{
case RetrieveData:
// Handle the "RetrieveData" member
{
// use argc and argv if you need to process parameters
// return true if you set Dest to a new, valid object. otherwise, return false.
return false;
}
}
return false;
}
bool MrType::GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[])
{
// The GetMethod function is used when a data sequence access a method of an object of this type.
// Its job is to take the method name (such as PerformAction), and perform the requested action.
// Unlike members, methods do not result in a new object -- they may make changes to the original
// object, but always result in the same object (return true), or no object if the object was deleted
// (return false).
// ObjectData here is passed by reference, so that you may modify the value stored if necessary. 32-bit
// (or less) integer types, for example, use a value directly in the ObjectData, rather than a pointer
// to an object.
// ObjectData is the object, or a pointer to the object. Validate the object here.
if (!ObjectData.Ptr)
return false;
// Based on the method ID, execute the desired method
switch((MrTypeMethods)pMethod->ID)
{
case PerformAction:
// Handle the "PerformAction" member
{
// use argc and argv if you need to process parameters
// return true if the object is still valid. return false if not.
return true;
}
}
return false;
}

32
src/DataTypes.h Normal file
View File

@ -0,0 +1,32 @@
#pragma once
#include "DataTypeList.h"
// custom data type declarations
class MrType : public LSTypeDefinition
{
public:
// All data members (retrieving data) should be listed in this enumeration
enum MrTypeMembers
{
RetrieveData,
};
// All data methods (performing actions on or with the object) should be listed in this enumeration
enum MrTypeMethods
{
PerformAction,
};
MrType() : LSType("mr")
{
// Use the TypeMember macro to activate each member, or use AddMember
TypeMember(RetrieveData);
// Use the TypeMethod macro to activate each member, or use AddMethod
TypeMethod(PerformAction);
}
virtual bool GetMember(LSOBJECTDATA ObjectData, PLSTYPEMEMBER Member, int argc, char *argv[], LSOBJECT &Object);
virtual bool GetMethod(LSOBJECTDATA &ObjectData, PLSTYPEMETHOD pMethod, int argc, char *argv[]);
virtual bool ToText(LSOBJECTDATA ObjectData, char *buf, unsigned int buflen);
};

417
src/ISXMr.cpp Normal file
View File

@ -0,0 +1,417 @@
//
// ISXMr
//
// Version guideline: YYYYMMDD
// Add lettering to the end to indicate a new version on the same date, such as 20060305a, 20060305b, etc
// You can also use a standard version numbering system such as 1.00, 1.01, etc.
// Be aware that for the versioning system, this text is simply compared to another version text from the
// same extension to check for new versions -- if this version text comes before the compared text (in a
// dictionary), then an update is available. Equal text means the version is up to date. After means this
// is newer than the compared version. With that said, use whatever version numbering system you'd like.
#define EXTENSION_VERSION "20060617"
#include "ISXMr.h"
#include "isxeq2/Character.h"
#pragma comment(lib,"isxdk.lib")
// The mandatory pre-setup function. Our name is "ISXMr", and the class is ISXMr.
// This sets up a "ModulePath" variable which contains the path to this module in case we want it,
// and a "PluginLog" variable, which contains the path and filename of what we should use for our
// debug logging if we need it. It also sets up a variable "pExtension" which is the pointer to
// our instanced class.
ISXPreSetup("ISXMr",ISXMr);
// Basic LavishScript datatypes, these get retrieved on startup by our initialize function, so we can
// use them in our Top-Level Objects or custom datatypes
LSType *pStringType=0;
LSType *pIntType=0;
LSType *pUintType=0;
LSType *pBoolType=0;
LSType *pFloatType=0;
LSType *pTimeType=0;
LSType *pByteType=0;
LSType *pIntPtrType=0;
LSType *pBoolPtrType=0;
LSType *pFloatPtrType=0;
LSType *pBytePtrType=0;
ISInterface *pISInterface=0;
HISXSERVICE hPulseService;
HISXSERVICE hMemoryService;
HISXSERVICE hHTTPService;
HISXSERVICE hTriggerService;
HISXSERVICE hSystemService;
char Mr_Version[]=EXTENSION_VERSION;
// Forward declarations of callbacks
void __cdecl PulseService(bool Broadcast, unsigned int MSG, void *lpData);
void __cdecl MemoryService(bool Broadcast, unsigned int MSG, void *lpData);
void __cdecl TriggerService(bool Broadcast, unsigned int MSG, void *lpData);
void __cdecl HTTPService(bool Broadcast, unsigned int MSG, void *lpData);
void __cdecl SystemService(bool Broadcast, unsigned int MSG, void *lpData);
// The constructor of our class. General initialization cannot be done yet, because we're not given
// the pointer to the Inner Space interface until it is ready for us to initialize. Just set the
// pointer we have to the interface to 0. Initialize data members, too.
ISXMr::ISXMr(void)
{
}
// Free any remaining resources in the destructor. This is called when the DLL is unloaded, but
// Inner Space calls the "Shutdown" function first. Most if not all of the shutdown process should
// be done in Shutdown.
ISXMr::~ISXMr(void)
{
}
// Initialize is called by Inner Space when the extension should initialize.
bool ISXMr::Initialize(ISInterface *p_ISInterface)
{
/*
* Most of the functionality in Initialize is completely optional and could be removed or
* changed if so desired. The defaults are simply a suggestion that can be easily followed.
*/
__try // exception handling. See __except below.
{
// Keep a global copy of the ISInterface pointer, which is for calling Inner Space API
pISInterface=p_ISInterface;
// Register the extension to make launching and updating the extension easy
RegisterExtension();
// retrieve basic LavishScript data types for use in ISXMr data types
pStringType=pISInterface->FindLSType("string");
pIntType=pISInterface->FindLSType("int");
pUintType=pISInterface->FindLSType("uint");
pBoolType=pISInterface->FindLSType("bool");
pFloatType=pISInterface->FindLSType("float");
pTimeType=pISInterface->FindLSType("time");
pByteType=pISInterface->FindLSType("byte");
pIntPtrType=pISInterface->FindLSType("intptr");
pBoolPtrType=pISInterface->FindLSType("boolptr");
pFloatPtrType=pISInterface->FindLSType("floatptr");
pBytePtrType=pISInterface->FindLSType("byteptr");
// Connect to commonly used Inner Space services
ConnectServices();
// Register LavishScript extensions (commands, aliases, data types, objects)
RegisterCommands();
RegisterAliases();
RegisterDataTypes();
RegisterTopLevelObjects();
// Register (create) our own services
RegisterServices();
// Register any text triggers built into ISXMr
RegisterTriggers();
printf("ISXMr version %s Loaded",Mr_Version);
return true;
}
// Exception handling sample. Exception handling should at LEAST be used in functions that
// are suspected of causing user crashes. This will help users report the crash and hopefully
// enable the extension developer to locate and fix the crash condition.
__except(EzCrashFilter(GetExceptionInformation(),"Crash in initialize routine"))
{
TerminateProcess(GetCurrentProcess(),0);
return 0;
}
/*
* EzCrashFilter takes printf-style formatting after the first parameter. The above
* could look something like this:
__except(EzCrashFilter(GetExceptionInformation(),"Crash in initialize routine (%s:%d)",__FILE__,__LINE__))
{
TerminateProcess(GetCurrentProcess(),0);
return 0;
}
* of course, the FILE and LINE macros would be the location of the exception handler, not the
* actual crash, but you should get the idea that extra parameters can be used as if EzCrashFilter
* was printf.
*
* EzCrashFilter will automatically produce a crash log (CrashLog.txt) and open it in notepad for
* non-breakpoint exceptions (and hopefully the user will report the crash to the extension developer).
* Your exception handler (the part within the {} under __except) should simply terminate the process
* and return from the function as in the sample. The return will not be hit, but the compiler will
* whine without it because it doesn't automatically know that the function will not return.
*/
}
// shutdown sequence
void ISXMr::Shutdown()
{
// Disconnect from services we connected to
DisconnectServices();
// Unregister (destroy) services we created
UnRegisterServices();
// Remove LavishScript extensions (commands, aliases, data types, objects)
UnRegisterTopLevelObjects();
UnRegisterDataTypes();
UnRegisterAliases();
UnRegisterCommands();
}
/*
* Note that Initialize and Shutdown are the only two REQUIRED functions in your ISXInterface class.
* All others are for suggested breakdown of routines, and for example purposes.
*/
void ISXMr::RegisterExtension()
{
// add this extension to, or update this extension's info in, InnerSpace.xml.
// This accomplishes a few things. A) The extension can be loaded by name (ISXMr)
// no matter where it resides on the system. B) A script or extension can
// check a repository to determine if there is an update available (and update
// if necessary)
unsigned int ExtensionSetGUID=pISInterface->GetExtensionSetGUID("ISXMr");
if (!ExtensionSetGUID)
{
ExtensionSetGUID=pISInterface->CreateExtensionSet("ISXMr");
if (!ExtensionSetGUID)
return;
}
pISInterface->SetSetting(ExtensionSetGUID,"Filename",ModuleFileName);
pISInterface->SetSetting(ExtensionSetGUID,"Path",ModulePath);
pISInterface->SetSetting(ExtensionSetGUID,"Version",Mr_Version);
}
void ISXMr::ConnectServices()
{
// connect to any services. Here we connect to "Pulse" which receives a
// message every frame (after the frame is displayed) and "Memory" which
// wraps "detours" and memory modifications
hPulseService=pISInterface->ConnectService(this,"Pulse",PulseService);
hMemoryService=pISInterface->ConnectService(this,"Memory",MemoryService);
// The HTTP service handles URL retrieval
hHTTPService=pISInterface->ConnectService(this,"HTTP",HTTPService);
// The Triggers service handles trigger-related functions, including the
// ability to pass text TO the trigger parser, as well as the ability to
// add triggers.
hTriggerService=pISInterface->ConnectService(this,"Triggers",TriggerService);
// The System service provides general system-related services, including
// a diagnostics message that allows the extension to insert diagnostic
// information for the "diagnostics" command, and extension crash logs.
hSystemService=pISInterface->ConnectService(this,"System",SystemService);
}
void ISXMr::RegisterCommands()
{
// add any commands
// pISInterface->AddCommand("ISXMr",CMD_ISXMr,true,false);
#define COMMAND(name,cmd,parse,hide) pISInterface->AddCommand(name,cmd,parse,hide);
#include "Commands.h"
#undef COMMAND
}
void ISXMr::RegisterAliases()
{
// add any aliases
}
void ISXMr::RegisterDataTypes()
{
// add any datatypes
// pMyType = new MyType;
// pISInterface->AddLSType(*pMyType);
#define DATATYPE(_class_,_variable_,_inherits_) _variable_ = new _class_; pISInterface->AddLSType(*_variable_); _variable_->SetInheritance(_inherits_);
#include "DataTypeList.h"
#undef DATATYPE
}
void ISXMr::RegisterTopLevelObjects()
{
// add any Top-Level Objects
//pISInterface->AddTopLevelObject("ISXMr",TLO_ISXMr);
#define TOPLEVELOBJECT(name,funcname) pISInterface->AddTopLevelObject(name,funcname);
#include "TopLevelObjects.h"
#undef TOPLEVELOBJECT
}
void ISXMr::RegisterServices()
{
// register any services. Here we demonstrate a service that does not use a
// callback
// set up a 1-way service (broadcast only)
// hISXMrService=pISInterface->RegisterService(this,"ISXMr Service",0);
// broadcast a message, which is worthless at this point because nobody will receive it
// (nobody has had a chance to connect)
// pISInterface->ServiceBroadcast(this,hISXMrService,ISXSERVICE_MSG+1,0);
#define SERVICE(_name_,_callback_,_variable_) _variable_=pISInterface->RegisterService(this,_name_,_callback_);
#include "Services.h"
#undef SERVICE
}
void ISXMr::RegisterTriggers()
{
// add any Triggers
}
void ISXMr::DisconnectServices()
{
// gracefully disconnect from services
if (hPulseService)
pISInterface->DisconnectService(this,hPulseService);
if (hMemoryService)
{
pISInterface->DisconnectService(this,hMemoryService);
// memory modifications are automatically undone when disconnecting
// also, since this service accepts messages from clients we should reset our handle to
// 0 to make sure we dont try to continue using it
hMemoryService=0;
}
if (hHTTPService)
{
pISInterface->DisconnectService(this,hHTTPService);
}
if (hTriggerService)
{
pISInterface->DisconnectService(this,hTriggerService);
}
if (hSystemService)
{
pISInterface->DisconnectService(this,hSystemService);
}
}
void ISXMr::UnRegisterCommands()
{
// remove commands
// pISInterface->RemoveCommand("ISXMr");
#define COMMAND(name,cmd,parse,hide) pISInterface->RemoveCommand(name);
#include "Commands.h"
#undef COMMAND
}
void ISXMr::UnRegisterAliases()
{
// remove aliases
}
void ISXMr::UnRegisterDataTypes()
{
// remove data types
#define DATATYPE(_class_,_variable_,_inherits_) pISInterface->RemoveLSType(*_variable_); delete _variable_;
#include "DataTypeList.h"
#undef DATATYPE
}
void ISXMr::UnRegisterTopLevelObjects()
{
// remove Top-Level Objects
// pISInterface->RemoveTopLevelObject("ISXMr");
#define TOPLEVELOBJECT(name,funcname) pISInterface->RemoveTopLevelObject(name);
#include "TopLevelObjects.h"
#undef TOPLEVELOBJECT
}
void ISXMr::UnRegisterServices()
{
// shutdown our own services
// if (hISXMrService)
// pISInterface->ShutdownService(this,hISXMrService);
#define SERVICE(_name_,_callback_,_variable_) _variable_=pISInterface->ShutdownService(this,_variable_);
#include "Services.h"
#undef SERVICE
}
int frameCount = 0;
void __cdecl PulseService(bool Broadcast, unsigned int MSG, void *lpData)
{
if (MSG==PULSE_PULSE)
{
/*
* "OnPulse"
* This message is received by the extension before each frame is
* displayed by the game. This is the place to put any repeating
* tasks.
*/
if(frameCount++ > 80) {
frameCount = 0;
const auto me = pISInterface->IsTopLevelObject("Me");
if(me != nullptr) {
LSOBJECT response;
me(0, nullptr, response);
Character c(response);
printf("------------------------------------");
printf("ID: %u", c.GetId());
printf("Name: %s", c.GetName());
printf("Race: %s", c.GetRace());
printf("Archetype: %s", c.GetArchetype());
printf("Class: %s", c.GetClass());
printf("SubClass: %s", c.GetSubClass());
printf("TSArchetype: %s", c.GetTradeskillArchtype());
printf("TSClass: %s", c.GetTradeskillClass());
printf("TSSubClass: %s", c.GetTradeskillSubClass());
printf("Gender: %s", c.GetGender());
printf("------------------------------------");
}
// if(pISInterface->IsExtensionLoaded("ISXEq2")) {
// printf("Loaded");
// } else {
// printf("Not loaded");
// }
}
}
}
void __cdecl MemoryService(bool Broadcast, unsigned int MSG, void *lpData)
{
// no messages are currently associated with this service (other than
// system messages such as client disconnect), so do nothing.
}
void __cdecl TriggerService(bool Broadcast, unsigned int MSG, void *lpData)
{
// no messages are currently associated with this service (other than
// system messages such as client disconnect), so do nothing.
}
void __cdecl SystemService(bool Broadcast, unsigned int MSG, void *lpData)
{
if (MSG==SYSTEMSERVICE_DIAGNOSTICS)
{
// Diagnostics sample
/*
FILE *file=(FILE*)lpData;
fprintf(file,"ISXMr version %s\n",EXTENSION_VERSION);
fprintf(file,"------------------------------------\n",EXTENSION_VERSION);
fprintf(file,"Any ISXMr diagnostic information here\n");
fprintf(file,"\n");// extra spacing for making the crash log look nice
/**/
}
}
void __cdecl HTTPService(bool Broadcast, unsigned int MSG, void *lpData)
{
switch(MSG)
{
#define pReq ((HttpFile*)lpData)
case HTTPSERVICE_FAILURE:
// HTTP request failed to retrieve document
printf("ISXMr URL %s failed",pReq->URL);
break;
case HTTPSERVICE_SUCCESS:
// HTTP request successfully retrieved document
printf("ISXMr URL %s -- %d bytes",pReq->URL,pReq->Size);
// Retrieved data buffer is pReq->pBuffer and is null-terminated
break;
#undef pReq
}
}

96
src/ISXMr.h Normal file
View File

@ -0,0 +1,96 @@
#pragma once
#include <ISXDK.h>
#include <windows.h>
class ISXMr :
public ISXInterface
{
public:
ISXMr(void);
~ISXMr(void);
virtual bool Initialize(ISInterface *p_ISInterface);
virtual void Shutdown();
void RegisterExtension();
void ConnectServices();
void RegisterCommands();
void RegisterAliases();
void RegisterDataTypes();
void RegisterTopLevelObjects();
void RegisterServices();
void RegisterTriggers();
void DisconnectServices();
void UnRegisterCommands();
void UnRegisterAliases();
void UnRegisterDataTypes();
void UnRegisterTopLevelObjects();
void UnRegisterServices();
};
extern ISInterface *pISInterface;
extern HISXSERVICE hPulseService;
extern HISXSERVICE hMemoryService;
extern HISXSERVICE hHTTPService;
extern HISXSERVICE hTriggerService;
extern HISXSERVICE hSystemService;
extern ISXMr *pExtension;
#define printf pISInterface->Printf
#define EzDetour(Address, Detour, Trampoline) IS_Detour(pExtension,pISInterface,hMemoryService,(unsigned int)Address,Detour,Trampoline)
#define EzUnDetour(Address) IS_UnDetour(pExtension,pISInterface,hMemoryService,(unsigned int)Address)
#define EzDetourAPI(_Detour_,_DLLName_,_FunctionName_,_FunctionOrdinal_) IS_DetourAPI(pExtension,pISInterface,hMemoryService,_Detour_,_DLLName_,_FunctionName_,_FunctionOrdinal_)
#define EzUnDetourAPI(Address) IS_UnDetourAPI(pExtension,pISInterface,hMemoryService,(unsigned int)Address)
#define EzModify(Address,NewData,Length,Reverse) Memory_Modify(pExtension,pISInterface,hMemoryService,(unsigned int)Address,NewData,Length,Reverse)
#define EzUnModify(Address) Memory_UnModify(pExtension,pISInterface,hMemoryService,(unsigned int)Address)
#define EzHttpRequest(_URL_,_pData_) IS_HttpRequest(pExtension,pISInterface,hHTTPService,_URL_,_pData_)
#define EzAddTrigger(Text,Callback,pUserData) IS_AddTrigger(pExtension,pISInterface,hTriggerService,Text,Callback,pUserData)
#define EzRemoveTrigger(ID) IS_RemoveTrigger(pExtension,pISInterface,hTriggerService,ID)
#define EzCheckTriggers(Text) IS_CheckTriggers(pExtension,pISInterface,hTriggerService,Text)
static LONG EzCrashFilter(_EXCEPTION_POINTERS *pExceptionInfo,const char *szIdentifier,...)
{
unsigned int Code=pExceptionInfo->ExceptionRecord->ExceptionCode;
if (Code==EXCEPTION_BREAKPOINT || Code==EXCEPTION_SINGLE_STEP)
return EXCEPTION_CONTINUE_SEARCH;
char szOutput[4096];
szOutput[0]=0;
va_list vaList;
va_start( vaList, szIdentifier );
vsprintf_s(szOutput,szIdentifier, vaList);
IS_SystemCrashLog(pExtension,pISInterface,hSystemService,pExceptionInfo,szOutput);
return EXCEPTION_EXECUTE_HANDLER;
}
extern LSType *pStringType;
extern LSType *pIntType;
extern LSType *pUintType;
extern LSType *pBoolType;
extern LSType *pFloatType;
extern LSType *pTimeType;
extern LSType *pByteType;
extern LSType *pIntPtrType;
extern LSType *pBoolPtrType;
extern LSType *pFloatPtrType;
extern LSType *pBytePtrType;
extern char Mr_Version[];
#include "Commands.h"
#include "DataTypes.h"
#include "TopLevelObjects.h"
#include "Services.h"

91
src/ISXMrServices.h Normal file
View File

@ -0,0 +1,91 @@
#pragma once
/**********************************************************************
ISXMrServices.h is a redistributable file that can be used
by other extensions to access the services provided by ISXMr.
It should contain all information for any message that can be sent to
clients from the master (individually or broadcast), or to the master
from clients.
All "in/out" information is relative to the client. If it says "in"
it means the client feeds information in. If it says "out" it means
the client pulls information out.
**********************************************************************/
// ----- "Mr Service" messages ------------------------------
// Note: ISXSERVICE_MSG defines the starting point for service-specific
// message numbers. Numbers below ISXSERVICE_MSG are reserved for
// future system use.
// These message numbers are PER SERVICE, so you can and should
// reuse numbers for different services
/* in (requests) */
#define Mr_FOO (ISXSERVICE_MSG+1)
// add all requests
/* out (notifications) */
#define Mr_BAR (ISXSERVICE_MSG+2)
// add all notifications
// ----- "Mr Service" request structures ---------------------
// These structures are sent as the "lpData" in requests or notifications.
/*
* All structures are essentially used to build a function call. Our first
* example handles a call to this function:
bool MrFooFunction(const char *Name, unsigned int Age,float Height);
* This function has 3 parameters, and 1 return value. The structure used will
* reflect exactly this.
*
* Note that because services are all executed in-process, data does not need to
* be serialized, as it would with using network sockets and such -- in other words,
* it is safe to pass original pointers.
*/
// Mr_FOO
struct MrRequest_Foo
{
/* in */ const char *Name; // Parameter 1
/* in */ unsigned int Age; // Parameter 2
/* int */ float Height; // Parameter 3
/* out */ bool Success; // Return value
};
// ----- "Mr Service" Helper Functions -----------------------
// Put any helper functions for REQUESTS here. Notifications (in contrast) are done by
// the service master, and do not need redistributable helper functions.
/*
* This function sets up the actual service request. It follows the same form as the function we
* are calling, but takes additional parameters to set up the remote service request. This will
* be used by our EzFoo macro, which will hide the service portion from developers wishing to use
* the remote function.
*/
static inline bool MrFoo(ISXInterface *pClient, ISInterface *pISInterface, HISXSERVICE hMrService, const char *Name, unsigned int Age, float Height)
{
// set up lpData
MrRequest_Foo RemoteFunctionCall;
RemoteFunctionCall.Name=Name;
RemoteFunctionCall.Age=Age;
RemoteFunctionCall.Height=Height;
RemoteFunctionCall.Success=false;
// return true if a) the service request was sent correctly and b) the service set Success to true, indicating
// that the Foo operation was successfully completed
return pISInterface->ServiceRequest(pClient,hMrService,Mr_FOO,&RemoteFunctionCall) && RemoteFunctionCall.Success;
}
// Most extensions will opt to use the default naming conventions, with a global pISInterface and pExtension,
// and your service handle name. This means you can make an "easy" macro to call MrFoo for them,
// and they can just use EzFoo as if they were calling the actual remote function:
#define EzFoo(_name_,_age_,_height_) MrFoo(pExtension,pISInterface,hMrService,_name_,_age_,_height_)
// Note that EzFoo is now used exactly the same as bool MrFooFunction(const char *Name, unsigned int Age,float Height)
// ----- "Mr Service" notification structures ---------------------
// The following structures are for use in Mr Service notification handlers
// Mr_BAR
// NOTE: For structures that have only one data item, we dont really need a structure. But to make things
// easy to use and understand, it's perfectly fine and compiles to the same machine code anyway.
struct MrNotification_Bar
{
/* out */ const char *Text;
};

50
src/LGUIMrFrame.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "ISXMr.h"
#include "LGUIMrFrame.h"
LGUIFactory<LGUIMrFrame> MrFrameFactory("mrframe");
LGUIMrFrame::LGUIMrFrame(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name):LGUIFrame(p_Factory,p_pParent,p_Name)
{
pText=0;
Count=0;
}
LGUIMrFrame::~LGUIMrFrame(void)
{
}
bool LGUIMrFrame::IsTypeOf(char *TestFactory)
{
return (!_stricmp(TestFactory,"mrframe")) || LGUIFrame::IsTypeOf(TestFactory);
}
bool LGUIMrFrame::FromXML(class XMLNode *pXML, class XMLNode *pTemplate)
{
if (!pTemplate)
pTemplate=g_UIManager.FindTemplate(XMLHelper::GetStringAttribute(pXML,"Template"));
if (!pTemplate)
pTemplate=g_UIManager.FindTemplate("mrframe");
if (!LGUIFrame::FromXML(pXML,pTemplate))
return false;
// custom xml properties
return true;
}
void LGUIMrFrame::OnCreate()
{
// All children of this element are guaranteed to have been created now.
pText = (LGUIText*)FindUsableChild("Output","text");
}
void LGUIMrFrame::Render()
{
Count++;
if (pText)
{
char Temp[256];
sprintf_s(Temp,"This frame has been rendered %d times.",Count);
pText->SetText(Temp);
}
LGUIFrame::Render();
}

19
src/LGUIMrFrame.h Normal file
View File

@ -0,0 +1,19 @@
#pragma once
class LGUIMrFrame :
public LGUIFrame
{
public:
LGUIMrFrame(const char *p_Factory, LGUIElement *p_pParent, const char *p_Name);
~LGUIMrFrame(void);
bool IsTypeOf(char *TestFactory);
bool FromXML(class XMLNode *pXML, class XMLNode *pTemplate=0);
void OnCreate();
void Render();
LGUIText *pText;
unsigned int Count;
};
extern LGUIFactory<LGUIMrFrame> MrFrameFactory;

76
src/Services.cpp Normal file
View File

@ -0,0 +1,76 @@
#include "ISXMr.h"
#include "ISXMrServices.h"
#define SERVICE(_name_,_callback_,_variable_) HISXSERVICE _variable_=0;
#include "Services.h"
#undef SERVICE
bool MrFooFunction(const char *Name, unsigned int Age,float Height)
{
printf("Foo: %s. Age %d. Height: %fcm",Name,Age,Height);
return true;
}
void __cdecl MrService(ISXInterface *pClient, unsigned int MSG, void *lpData)
{
switch(MSG)
{
case ISXSERVICE_CLIENTADDED:
// This message indicates that a new client has been added to the service
// pClient is 0, because this message is a system message from Inner Space
// lpData is an ISXInterface* that is the pointer to the new client
{
// use lpData as the actual type, not as void *. We can make a new
// variable to do this:
ISXInterface *pNewClient=(ISXInterface *)lpData;
printf("MrService client added: %X",pNewClient);
// You may use the client pointer (pNewClient here) as an ID to track client-specific
// information. Some services such as the memory service do this to automatically
// remove memory modifications made by an extension when that extension is unloaded.
}
break;
case ISXSERVICE_CLIENTREMOVED:
// This message indicates that a client has been removed from the service
// pClient is 0, because this message is a system message from Inner Space
// lpData is an ISXInterface* that is the pointer to the removed client
{
// use lpData as the actual type, not as void *. We can make a new
// variable to do this:
ISXInterface *pRemovedClient=(ISXInterface *)lpData;
printf("MrService client removed: %X",pRemovedClient);
}
break;
case Mr_FOO:
// This is a custom service request defined in ISXMrServices.h
// pClient is a valid pointer to the client that sent this request
// lpData is a MrRequest_Foo* as sent by the client
{
MrRequest_Foo *pFoo=(MrRequest_Foo*)lpData;
/*
* As described in ISXMrServices.h, pFoo is simply a remote call
* to MrFooFunction, and has all of the parameters and the outgoing
* return value ready to go.
*/
pFoo->Success=MrFooFunction(pFoo->Name,pFoo->Age,pFoo->Height);
/*
* That's it! In many cases, the functionality provided by the service will
* be something that should be per-client to automatically handle cleanup.
* In such cases, it would be prudent to pass the pClient to the function call
* for proper handling.
*/
}
break;
}
}
/*
* How to broadcast an outgoing service message (called a notification):
MrNotification_Bar Bar;
Bar.Text="Some text to pass as part of the notification";
pFoo->Success=pISInterface->ServiceBroadcast(pExtension,hMrService,Mr_BAR,&Bar);
*/

25
src/Services.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef SERVICE
#define SERVICE_SELF
#define SERVICE(_name_,_callback_,_variable_) extern HISXSERVICE _variable_;extern void __cdecl _callback_(ISXInterface *pClient, unsigned int MSG, void *lpData);
#endif
// ----------------------------------------------------
// services
SERVICE("Mr Service",MrService,hMrService);
// ----------------------------------------------------
#ifdef SERVICE_SELF
#undef SERVICE_SELF
#undef SERVICE
#endif

22
src/TopLevelObjects.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "ISXMr.h"
// A LavishScript Top-Level Object is similar to a global C++ object. The main difference is that
// a TLO can give ANY data type it wants; it is not limited to a single type. You may wish to give
// a different type depending on the index (parameters, dimensions, etc) for example. Usually, though,
// you simply give one specific type.
bool __cdecl TLO_Mr(int argc, char *argv[], LSTYPEVAR &Dest)
{
// argc and argv are used if the object access uses an index, such as Mr[1] or
// Mr[my coat,1,seventeen]. argc is the number of parameters (or dimensions) separated
// by commas, and does NOT include the name of the object.
// LSTYPEVAR, used for Dest, is a VarPtr with a Type. Type should be set to a pointer to a data type,
// such as Dest.Type=pIntType for integers. Do not set the Type or return true if the data retrieval
// fails (there is no object). For example, if the requested data is a string, and the string does
// not exist, return false and do not set the type.
Dest.DWord=1;
Dest.Type=pMrType;
return true;
}

31
src/TopLevelObjects.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef TOPLEVELOBJECT
#define TOPLEVELOBJECT_SELF
#define TOPLEVELOBJECT(name,funcname) extern bool funcname(int argc, char *argv[], LSTYPEVAR &Ret);
#endif
// ----------------------------------------------------
// Top-Level Objects
TOPLEVELOBJECT("Mr",TLO_Mr);
// ----------------------------------------------------
#ifdef TOPLEVELOBJECT_SELF
#undef TOPLEVELOBJECT_SELF
#undef TOPLEVELOBJECT
#endif

139
src/isxeq2/Actor.cpp Normal file
View File

@ -0,0 +1,139 @@
//
// Created by marob on 12/20/2023.
//
#include "Actor.h"
u_long Actor::GetId() {
return {static_cast<u_long>(this->GetMemberResponse("ID").Int64)};
}
std::string Actor::GetName() {
return {this->GetMemberResponse("Name").CharPtr};
}
std::string Actor::GetLastName() {
return { this->GetMemberResponse("LastName").CharPtr };
}
int Actor::GetHealthPercentage() {
return this->GetMemberResponse("Health").Int;
}
int Actor::GetPowerPercentage() {
return this->GetMemberResponse("Power").Int;
}
int Actor::GetLevel() {
return this->GetMemberResponse("Level").Int;
}
int Actor::GetEffectiveLevel() {
return this->GetMemberResponse("EffectiveLevel").Int;
}
u_int Actor::GetTintFlags() {
return this->GetMemberResponse("TintFlags").Int;
}
std::string Actor::GetVisualVariant() {
return { this->GetMemberResponse("VisualVariant").CharPtr };
}
std::string Actor::GetMood() {
return { this->GetMemberResponse("Mood").CharPtr };
}
std::string Actor::GetCurrentAnimation() {
return { this->GetMemberResponse("CurrentAnimation").CharPtr };
}
std::string Actor::GetOverlay() {
return { this->GetMemberResponse("Overlay").CharPtr };
}
std::string Actor::GetAura() {
return { this->GetMemberResponse("Aura").CharPtr };
}
std::string Actor::GetGuild() {
return { this->GetMemberResponse("Guild").CharPtr };
}
std::string Actor::GetType() {
return { this->GetMemberResponse("Type").CharPtr };
}
std::string Actor::GetSuffixTitle() {
return { this->GetMemberResponse("SuffixTitle").CharPtr };
}
std::string Actor::GetConColor() {
return { this->GetMemberResponse("ConColor").CharPtr };
}
std::string Actor::GetRawConColor() {
// TODO: Modify to accept a parameter & pass in the string 'raw'
return { this->GetMemberResponse("RawConColor").CharPtr };
}
std::string Actor::GetFactionStanding() {
return { this->GetMemberResponse("FactionStanding").CharPtr };
}
int Actor::GetFaction() {
return this->GetMemberResponse("Faction").Int;
}
Actor Actor::GetTarget() {
return Actor(this->GetMemberResponse("Target"));
}
Actor Actor::GetPet() {
return Actor(this->GetMemberResponse("Pet"));
}
int Actor::GetThreatToPet() {
return this->GetMemberResponse("ThreatToPet").Int;
}
int Actor::GetThreatToMe() {
return this->GetMemberResponse("GetThreatToMe").Int;
}
int Actor::GetThreatToNext() {
return this->GetMemberResponse("GetThreatToNext").Int;
}
float Actor::GetDistance() {
return this->GetMemberResponse("Distance").Float;
}
float Actor::GetDistance2d() {
return this->GetMemberResponse("Distance2D").Float;
}
float Actor::GetX() {
return this->GetMemberResponse("X").Float;
}
float Actor::GetY() {
return this->GetMemberResponse("Y").Float;
}
float Actor::GetZ() {
return this->GetMemberResponse("Z").Float;
}
std::string Actor::GetRace() {
return {this->GetMemberResponse("Race").CharPtr};
}
std::string Actor::GetClass() {
return {this->GetMemberResponse("Class").CharPtr};
}
std::string Actor::GetGender() {
return {this->GetMemberResponse("Gender").CharPtr};
}

65
src/isxeq2/Actor.h Normal file
View File

@ -0,0 +1,65 @@
//
// Created by marob on 12/20/2023.
//
#ifndef ACTOR_H
#define ACTOR_H
#include <ISXDK.h>
#include "LSObject.h"
class Actor : public LSObject {
public:
explicit Actor(const LSOBJECT &obj) : LSObject(obj), lsObject(obj) {
}
// General
u_long GetId();
std::string GetName();
std::string GetLastName();
int GetHealthPercentage();
int GetPowerPercentage();
int GetLevel();
int GetEffectiveLevel();
u_int GetTintFlags();
std::string GetVisualVariant();
std::string GetMood();
std::string GetCurrentAnimation();
std::string GetOverlay();
std::string GetAura();
std::string GetGender();
std::string GetRace();
std::string GetClass();
std::string GetGuild();
std::string GetType();
std::string GetSuffixTitle();
std::string GetConColor();
std::string GetRawConColor();
std::string GetFactionStanding();
int GetFaction();
Actor GetTarget();
Actor GetPet();
// Threat
int GetThreatToPet();
int GetThreatToMe();
int GetThreatToNext();
// Location
float GetDistance(); // Note: This is the distance using three dimensions, which is what the EQ2 client primarily uses for determining ability ranges, etc.
float GetDistance2d();
float GetX();
float GetY();
float GetZ();
private:
LSOBJECT lsObject;
};
#endif //ACTOR_H

39
src/isxeq2/Character.cpp Normal file
View File

@ -0,0 +1,39 @@
//
// Created by marob on 12/20/2023.
//
#include "Character.h"
std::string Character::GetArchetype() {
const auto response = this->GetMemberResponse("Archetype");
return {response.CharPtr};
}
std::string Character::GetSubClass() {
const auto response = this->GetMemberResponse("SubClass");
return {response.CharPtr};
}
std::string Character::GetTradeskillArchtype() {
const auto response = this->GetMemberResponse("TSArchetype");
return {response.CharPtr};
}
std::string Character::GetTradeskillClass() {
const auto response = this->GetMemberResponse("TSClass");
return {response.CharPtr};
}
std::string Character::GetTradeskillSubClass() {
const auto response = this->GetMemberResponse("TSSubClass");
return {response.CharPtr};
}

31
src/isxeq2/Character.h Normal file
View File

@ -0,0 +1,31 @@
//
// Created by marob on 12/20/2023.
//
#ifndef CHARACTER_H
#define CHARACTER_H
#include <string>
#include <ISXDK.h>
#include "Actor.h"
class Character : public Actor {
public:
explicit Character(const LSOBJECT &obj) : Actor(obj), lsObject(obj) { }
std::string GetArchetype();
std::string GetSubClass();
std::string GetTradeskillArchtype();
std::string GetTradeskillClass();
std::string GetTradeskillSubClass();
private:
LSOBJECT lsObject;
};
#endif //CHARACTER_H

19
src/isxeq2/LSObject.cpp Normal file
View File

@ -0,0 +1,19 @@
//
// Created by marob on 12/20/2023.
//
#include "LSObject.h"
LSOBJECT LSObject::GetMemberResponse(const std::string &memberName) {
LSOBJECT response;
this->lsObject.Type->GetMemberEx(
this->lsObject.GetObjectData(),
const_cast<char*>(memberName.c_str()),
0,
nullptr,
response
);
return response;
}

21
src/isxeq2/LSObject.h Normal file
View File

@ -0,0 +1,21 @@
//
// Created by marob on 12/20/2023.
//
#ifndef LSOBJECT_H
#define LSOBJECT_H
#include <ISXDK.h>
class LSObject {
public:
explicit LSObject (const LSOBJECT &obj) : lsObject(obj) {}
protected:
LSOBJECT GetMemberResponse(const std::string &memberName);
private:
LSOBJECT lsObject;
};
#endif //LSOBJECT_H