825 lines
23 KiB
C++
825 lines
23 KiB
C++
#include "SCENE.H"
|
||
#include "Script_Help_Xsl.h"
|
||
#ifdef ONLINE_MODE
|
||
#include "account.h"
|
||
extern CCamCamAccount Account;
|
||
#endif
|
||
|
||
HANDLE PackFileMutex;
|
||
|
||
typedef enum COMMAND
|
||
{
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) COM_##scriptName,
|
||
#define DEFINE_SCRIPT(a,params,Help,b) COM_##a,
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) COM_##n, COM_##a,
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) COM_##a,
|
||
#include "Script_Commands.h"
|
||
MAX_COMMAND
|
||
};
|
||
|
||
BOOL GetDrawWindowRect(RECT *winRect, int XSize, int YSize, HWND hWnd)
|
||
{
|
||
HWND curWin;
|
||
float RatioSrc;
|
||
float RatioDst;
|
||
|
||
if (hWnd == NULL)
|
||
curWin = GetForegroundWindow();
|
||
else
|
||
curWin = hWnd;
|
||
GetClientRect(curWin, winRect);
|
||
|
||
winRect->right = winRect->right - winRect->left;
|
||
winRect->bottom = winRect->bottom - winRect->top;
|
||
winRect->left = 0;
|
||
winRect->top = 0;
|
||
|
||
RatioSrc = (float)YSize / (float)XSize;
|
||
RatioDst = (float)winRect->bottom / (float)winRect->right;
|
||
if (RatioSrc > RatioDst)
|
||
{
|
||
s32 NewW;
|
||
NewW = winRect->bottom / RatioSrc;
|
||
winRect->left = (winRect->right - NewW) >> 1;
|
||
winRect->right = NewW + winRect->left;
|
||
} else
|
||
{
|
||
s32 NewH;
|
||
NewH = winRect->right * RatioSrc;
|
||
winRect->top = (winRect->bottom - NewH) >> 1;
|
||
winRect->bottom = NewH + winRect->top;
|
||
}
|
||
|
||
return (winRect->left != winRect->right) && (winRect->top != winRect->bottom);
|
||
}
|
||
|
||
BOOL GetDrawWindowRect(RECT *winRect, int XSize, int YSize)
|
||
{
|
||
return GetDrawWindowRect(winRect, XSize, YSize, NULL);
|
||
}
|
||
|
||
POINT GetMouse(int Mode, int MouseX, int MouseY, int XSize, int YSize, MAP *MediaPtr, int X, int Y, int SX, int SY)
|
||
{
|
||
POINT MouseXY;
|
||
RECT winRect;
|
||
HWND hWnd = GetForegroundWindow();;
|
||
|
||
MouseXY.x = MouseXY.y = -1;
|
||
if(!GetDrawWindowRect(&winRect, XSize, YSize, hWnd))
|
||
return MouseXY;
|
||
|
||
switch (Mode)
|
||
{
|
||
case 0:
|
||
MouseXY.x = MouseX;
|
||
MouseXY.y = MouseY;
|
||
break;
|
||
case 1:
|
||
if (X!=-1 && Y!=-1 && SX!=-1 && SY!=-1)
|
||
{
|
||
X = winRect.left + X*(winRect.right - winRect.left)/XSize;
|
||
SX = SX*(winRect.right - winRect.left)/XSize;
|
||
Y = winRect.top + Y*(winRect.bottom - winRect.top)/YSize;
|
||
SY = SY*(winRect.bottom - winRect.top)/YSize;
|
||
|
||
if (MediaPtr && MediaPtr->GetBase() &&
|
||
MouseX >= X && MouseX < X + SX &&
|
||
MouseY >= Y && MouseY < Y + SY)
|
||
{
|
||
MouseXY.x = (MouseX - X)* MediaPtr->SX/SX;
|
||
MouseXY.y = (MouseY - Y)* MediaPtr->SY/SY;
|
||
}
|
||
}
|
||
break;
|
||
case 2:
|
||
case 3:
|
||
if(MediaPtr)
|
||
{
|
||
u32 zColor;
|
||
if (Mode == 2)
|
||
{
|
||
if (winRect.right > winRect.left && winRect.bottom > winRect.top)
|
||
{
|
||
MouseXY.x = (MouseX - winRect.left) * MediaPtr->SX / (winRect.right - winRect.left);
|
||
MouseXY.y = (MouseY - winRect.top) * MediaPtr->SY / (winRect.bottom - winRect.top);
|
||
}
|
||
} else if (X != -1 && Y != -1)
|
||
{
|
||
MouseXY.x = X;
|
||
MouseXY.y = Y;
|
||
}
|
||
|
||
if (MouseXY.x >= 0 && MouseXY.x < MediaPtr->SX &&
|
||
MouseXY.y >= 0 && MouseXY.y < MediaPtr->SY)
|
||
{
|
||
|
||
zColor= MediaPtr->GetValue(MouseXY.x + (MediaPtr->SY-MouseXY.y-1)*MediaPtr->PITCH);
|
||
if ((zColor & 0x00FF00) > 0x00F000)
|
||
{
|
||
MouseXY.x = (zColor & 0xFF0000) >> 16;
|
||
MouseXY.y = (zColor & 0x0000FF);
|
||
} else
|
||
MouseXY.x = MouseXY.y = -1;
|
||
} else
|
||
MouseXY.x = MouseXY.y = -1;
|
||
}
|
||
break;
|
||
case 4:
|
||
if (winRect.right > winRect.left && winRect.bottom > winRect.top)
|
||
{
|
||
MouseXY.x = (MouseX - winRect.left)* XSize / (winRect.right - winRect.left);
|
||
MouseXY.y = (MouseY - winRect.top)* YSize / (winRect.bottom - winRect.top);
|
||
}
|
||
break;
|
||
case 5:
|
||
MouseXY.x = MouseX;
|
||
MouseXY.y = MouseY;
|
||
ClientToScreen(hWnd, &MouseXY);
|
||
break;
|
||
}
|
||
return MouseXY;
|
||
}
|
||
|
||
|
||
void GenXMLCommand(FILE *F, char *command, char *params, char *help, char *infunction, int type)
|
||
{
|
||
char bufferType[512];
|
||
char bufferName[512];
|
||
char bufferReturn[1024];
|
||
char *bufferPtr;
|
||
char *bufferStrPtr;
|
||
BOOL optional;
|
||
int len;
|
||
char *optionalStr[2] = {"false", "true"};
|
||
|
||
fprintf(F,"\n\t<Command name=\"%s\" ", command);
|
||
bufferPtr = strstr(params, "CATEGORY(");
|
||
if (bufferPtr != NULL)
|
||
{
|
||
bufferPtr += strlen("CATEGORY(");
|
||
bufferStrPtr = strchr(bufferPtr, ')');
|
||
strncpy(bufferType, bufferPtr, bufferStrPtr - bufferPtr);
|
||
bufferType[bufferStrPtr - bufferPtr] = 0;
|
||
fprintf(F,"category=\"%s\" ", bufferType);
|
||
}
|
||
else fprintf(F,"category=\"Unclassified\" ");
|
||
|
||
switch (type)
|
||
{
|
||
case 1:
|
||
fprintf(F, "type=\"Fou\" >");
|
||
break;
|
||
case 2:
|
||
fprintf(F, "type=\"Lua\" >");
|
||
break;
|
||
case 3:
|
||
fprintf(F, "type=\"Both\" >");
|
||
break;
|
||
default:
|
||
fprintf(F, " >");
|
||
}
|
||
|
||
bufferPtr = params;
|
||
while ((bufferStrPtr = strstr(bufferPtr, "PARAM_")) != NULL)
|
||
{
|
||
memset(bufferType, 0, sizeof(bufferType));
|
||
memset(bufferName, 0, sizeof(bufferName));
|
||
|
||
bufferPtr = bufferStrPtr+strlen("PARAM_");
|
||
bufferStrPtr = strchr(bufferPtr, '(');
|
||
strncpy(bufferType, bufferPtr, bufferStrPtr - bufferPtr);
|
||
bufferPtr = strstr(bufferType, "_OPT");
|
||
if (bufferPtr)
|
||
{
|
||
optional = true;
|
||
*bufferPtr = 0;
|
||
} else
|
||
{
|
||
optional = false;
|
||
}
|
||
bufferPtr = bufferStrPtr+1;
|
||
bufferStrPtr = strchr(bufferPtr, ')');
|
||
strncpy(bufferName, bufferPtr, bufferStrPtr - bufferPtr);
|
||
bufferStrPtr = bufferName;
|
||
if (strstr(bufferType, "TAB"))
|
||
bufferStrPtr= strchr(bufferStrPtr, ',') + 1;
|
||
if (optional)
|
||
{
|
||
bufferStrPtr = strchr(bufferStrPtr, ',');
|
||
if (bufferStrPtr)
|
||
*bufferStrPtr = 0;
|
||
}
|
||
fprintf(F, "\n\t\t<param name=\"%s\" type=\"%s\" opt=\"%s\" />", bufferName, bufferType, optionalStr[optional]);
|
||
}
|
||
|
||
bufferPtr = infunction;
|
||
memset(bufferReturn, 0, sizeof(bufferReturn));
|
||
bool returnValuePresent = false;
|
||
while ((bufferStrPtr = strstr(bufferPtr, "RETURN_")) != NULL)
|
||
{
|
||
memset(bufferType, 0, sizeof(bufferType));
|
||
|
||
bufferPtr = bufferStrPtr+strlen("RETURN_");
|
||
bufferStrPtr = strchr(bufferPtr, '(');
|
||
strncpy(bufferType, bufferPtr, bufferStrPtr - bufferPtr);
|
||
if (!strstr(bufferReturn, bufferType))
|
||
{
|
||
sprintf(bufferReturn+strlen(bufferReturn), "\n\t\t<return type=\"%s\" />", bufferType);
|
||
returnValuePresent = true;
|
||
}
|
||
}
|
||
if(returnValuePresent==false)
|
||
{
|
||
sprintf(bufferReturn+strlen(bufferReturn), "\n\t\t<return type=\"-\" />");
|
||
}
|
||
fprintf(F, bufferReturn);
|
||
char tmpHelp[2048];
|
||
strcpy(tmpHelp, "<br>");
|
||
int end = strlen(help)+4-5;
|
||
int lastBr = 0;
|
||
for(int i=0; i<end; i++)
|
||
{
|
||
if(strncmp(help+i, "<br/>", strlen("<br/>"))==0)
|
||
{
|
||
|
||
strncat(tmpHelp, help+lastBr, i-lastBr); //copie de ce qu'il y a entre le br/ pr<70>c<EFBFBD>dent et le nouveau
|
||
strcat(tmpHelp, "</br><br>"); //copie de ce qu'il y a a roujout<75> a la place du br/
|
||
lastBr = i+strlen("<br/>");
|
||
}
|
||
}
|
||
strcat(tmpHelp, help+lastBr);
|
||
strcat(tmpHelp, "</br>");
|
||
fprintf(F, "\n\t\t<help>%s</help>\n\t</Command>", tmpHelp);
|
||
}
|
||
|
||
/* This function copies the useful files for notepad++ */
|
||
#define NOTEPAD_PATH "C:\\Program Files\\Notepad++"
|
||
#define NOTEPAD_EXE_PATH "C:\\Program Files\\Notepad++\\notepad++.exe"
|
||
u32 FILEIO_IsModePackedEXE();
|
||
|
||
void LuaSupportForNotepadPP()
|
||
{
|
||
//cr<63>ation du chemin d'acc<63>s au fichier "stylers.xml"
|
||
char appDataPath[2048] = "";
|
||
GetModuleFileName(NULL, appDataPath, 2048);
|
||
SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appDataPath);
|
||
char stylerPath[2048] = "";
|
||
strcat(stylerPath, appDataPath);
|
||
strcat(stylerPath, "\\Notepad++\\stylers.xml");
|
||
|
||
|
||
//cr<63>ation d'un backup du fichier "stylers.xml" avant toute modification
|
||
#ifndef NO_DIR_CREATE
|
||
CreateDirectory("Backup0", NULL);
|
||
CreateDirectory("Backup0/Miscellaneous", NULL);
|
||
if(lengthOfFile("Backup0/Miscellaneous/stylers.xml")==-1)
|
||
{
|
||
CopyFile(stylerPath, "Backup0/Miscellaneous/stylers.xml", true);
|
||
}
|
||
#endif
|
||
//modification du fichier "stylers.xml" pour la coloration syntaxique des fonctions Lua
|
||
long int luaPos = findText(stylerPath, 0, "desc=\"Lua\"");
|
||
if(luaPos!=-1)
|
||
{
|
||
long int funcPos = findText(stylerPath, luaPos, "keywordClass=\"type2\"");
|
||
if(funcPos!=-1)
|
||
{
|
||
funcPos += strlen("keywordClass=\"type2\"");
|
||
long int funcPos2 = findText(stylerPath, funcPos, "/");
|
||
if(funcPos2!=-1)
|
||
{
|
||
funcPos2++;
|
||
long int funcEndPos = findText(stylerPath, funcPos2, ">");
|
||
if(funcEndPos!=-1)
|
||
{
|
||
funcEndPos++;
|
||
deleteText(stylerPath, funcPos, funcEndPos);
|
||
insertText(stylerPath, funcPos, ">");
|
||
long int nameLength = 0;
|
||
|
||
//calcul de la taille des noms des fonctions script Lua mis bout <20> bout
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) nameLength+=strlen(#scriptName)+1;
|
||
#define DEFINE_SCRIPT(a,params,Help,b) nameLength+=strlen(#a)+1;
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) nameLength+=strlen(#n)+1;
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) nameLength+=strlen(#a)+1;
|
||
#include "Script_Commands.h"
|
||
|
||
char* toAdd = (char*)ZeroAlloc(nameLength*sizeof(char)+1);
|
||
long int currentPos = 0;
|
||
|
||
//ajout des noms des fonctions lua dans un tableau
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) \
|
||
strcpy(toAdd+currentPos, #scriptName); \
|
||
currentPos+=strlen(#scriptName)+1; \
|
||
toAdd[currentPos-1] = ' ';
|
||
#define DEFINE_SCRIPT(a,params,Help,b) \
|
||
strcpy(toAdd+currentPos, #a); \
|
||
currentPos+=strlen(#a)+1; \
|
||
toAdd[currentPos-1] = ' ';
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) \
|
||
strcpy(toAdd+currentPos, #n); \
|
||
currentPos+=strlen(#n)+1; \
|
||
toAdd[currentPos-1] = ' ';
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) \
|
||
strcpy(toAdd+currentPos, #a); \
|
||
currentPos+=strlen(#a)+1; \
|
||
toAdd[currentPos-1] = ' ';
|
||
#include "Script_Commands.h"
|
||
|
||
//ajout du contenu du tableau au fichier "styler.xml"
|
||
insertText(stylerPath, funcPos+1, toAdd);
|
||
CC_free(toAdd);
|
||
|
||
insertText(stylerPath, funcPos+1+nameLength, "</WordsStyle>");
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//copie du fichier "lua.xml" pour l'auto-compl<70>tion des fonctions Lua
|
||
FILE* apifile = CC_fopen("camcam_script_LUA.api","rt");
|
||
if(apifile)
|
||
{
|
||
CC_fclose(apifile);
|
||
char dest[2048] = "";
|
||
char dest2[2048] = "";
|
||
FILE* file = CC_fopen(NOTEPAD_EXE_PATH,"rt");
|
||
if(file)
|
||
{
|
||
CC_fclose(file);
|
||
strcpy(dest, NOTEPAD_PATH);
|
||
}
|
||
else
|
||
{
|
||
file = CC_fopen(NOTEPAD_EXE_PATH,"rt");
|
||
if(file)
|
||
{
|
||
CC_fclose(file);
|
||
strcpy(dest, NOTEPAD_PATH);
|
||
}
|
||
}
|
||
if(*dest)
|
||
{
|
||
if(dest[strlen(dest)-1]!='\\')
|
||
strcat(dest, "\\");
|
||
|
||
strcpy(dest2, dest);
|
||
strcat(dest, "plugins\\APIs\\lua.api");
|
||
SetFileAttributes(dest, GetFileAttributes(dest) & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile(dest);
|
||
CopyFile("camcam_script_LUA.api", dest, 0);
|
||
|
||
SetFileAttributes("camcam_script_LUA.api", GetFileAttributes("camcam_script_LUA.api") & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile("camcam_script_LUA.api");
|
||
|
||
|
||
strcat(dest2, "plugins\\APIs\\lua.xml");
|
||
SetFileAttributes(dest2, GetFileAttributes(dest2) & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile(dest2);
|
||
CopyFile("camcam_script_LUA.xml", dest2, 0);
|
||
|
||
SetFileAttributes("camcam_script_LUA.xml", GetFileAttributes("camcam_script_LUA.api") & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile("camcam_script_LUA.xml");
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
void GenApiFile(FILE *apiF, char *command, char * params, char *help, int type, bool apiXml)
|
||
{
|
||
char bufferType[512];
|
||
char bufferName[512];
|
||
char bufferReturn[1024];
|
||
char *bufferPtr;
|
||
char *bufferStrPtr;
|
||
BOOL isFirst;
|
||
BOOL optional;
|
||
|
||
if (apiF == NULL) return;
|
||
|
||
if (apiXml)
|
||
{
|
||
fprintf(apiF, "\t\t<KeyWord name=\"");
|
||
}
|
||
|
||
bufferPtr = params;
|
||
if (type == 1)
|
||
fprintf(apiF, "%s ", command);
|
||
else
|
||
fprintf(apiF, "%s(", command);
|
||
|
||
isFirst = true;
|
||
while ((bufferStrPtr = strstr(bufferPtr, "PARAM_")) != NULL)
|
||
{
|
||
memset(bufferType, 0, sizeof(bufferType));
|
||
memset(bufferName, 0, sizeof(bufferName));
|
||
|
||
bufferPtr = bufferStrPtr+strlen("PARAM_");
|
||
bufferStrPtr = strchr(bufferPtr, '(');
|
||
strncpy(bufferType, bufferPtr, bufferStrPtr - bufferPtr);
|
||
bufferPtr = strstr(bufferType, "_OPT");
|
||
if (bufferPtr)
|
||
{
|
||
optional = true;
|
||
*bufferPtr = 0;
|
||
} else
|
||
{
|
||
optional = false;
|
||
}
|
||
bufferPtr = bufferStrPtr+1;
|
||
bufferStrPtr = strchr(bufferPtr, ')');
|
||
strncpy(bufferName, bufferPtr, bufferStrPtr - bufferPtr);
|
||
bufferStrPtr = bufferName;
|
||
if (strstr(bufferType, "TAB"))
|
||
bufferStrPtr= strchr(bufferStrPtr, ',') + 1;
|
||
if (optional)
|
||
{
|
||
bufferStrPtr = strchr(bufferStrPtr, ',');
|
||
if (bufferStrPtr)
|
||
*bufferStrPtr = 0;
|
||
}
|
||
bufferStrPtr = bufferName;
|
||
if (isFirst) isFirst = false;
|
||
else
|
||
{
|
||
if (type == 1) fprintf(apiF, " ");
|
||
else fprintf(apiF, ",");
|
||
}
|
||
if (optional)
|
||
fprintf(apiF, "[");
|
||
fprintf(apiF, "%s", bufferName);
|
||
if (optional)
|
||
fprintf(apiF, "]");
|
||
}
|
||
|
||
if (apiXml)
|
||
{
|
||
if (type == 1) fprintf(apiF, "\" />\n");
|
||
else fprintf(apiF, ")\" />\n");
|
||
}
|
||
else
|
||
{
|
||
if (type == 1) fprintf(apiF, "\n");
|
||
else fprintf(apiF, ")\n");
|
||
}
|
||
}
|
||
|
||
int strcmpupr(const char *str1, const char *str2)
|
||
{
|
||
char buffer1[2048];
|
||
char buffer2[2048];
|
||
|
||
strcpy(buffer1, str1);
|
||
strcpy(buffer2, str2);
|
||
|
||
//strlwr(buffer1);
|
||
//strlwr(buffer2);
|
||
strupr(buffer1);
|
||
strupr(buffer2);
|
||
|
||
return strcmp(buffer1, buffer2);
|
||
}
|
||
|
||
|
||
u32 WORLD::SceneScript_INIT()
|
||
{
|
||
ScriptAccesMutex = CreateMutex(NULL, FALSE, "ScriptMutex");
|
||
PackFileMutex = CreateMutex(NULL, FALSE, "ZCCMutex");
|
||
if (FILEIO_IsModePackedEXE()) return 0;
|
||
|
||
#ifndef USER_MODE
|
||
FILE *F, *FAPILUA, *FAPIXMLLUA, *FAPIXSL;
|
||
|
||
SetFileAttributes("camcam_script_LUA.api", GetFileAttributes("camcam_script_LUA.api") & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile("camcam_script_LUA.api");
|
||
|
||
SetFileAttributes("camcam_script_LUA.xml", GetFileAttributes("camcam_script_LUA.api") & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile("camcam_script_LUA.xml");
|
||
|
||
SetFileAttributes("Script_Help.xml", GetFileAttributes("Script_Help.xml") & ~FILE_ATTRIBUTE_READONLY);
|
||
DeleteFile("Script_Help.xml");
|
||
|
||
F = CC_fopen("Script_Help.xml","wt");
|
||
FAPILUA = CC_fopen("camcam_script_LUA.api","wt");
|
||
FAPIXMLLUA = CC_fopen("camcam_script_LUA.xml","wt");
|
||
|
||
if (FAPIXMLLUA)
|
||
{
|
||
fprintf(FAPIXMLLUA,"<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>\n<NotepadPlus>\n\t<AutoComplete>\n");
|
||
}
|
||
|
||
FAPIXSL = CC_fopen("Script_Help.xsl","wt");
|
||
if (FAPIXSL)
|
||
{
|
||
fprintf(FAPIXSL, XSL_CONTENTS);
|
||
CC_fclose(FAPIXSL);
|
||
}
|
||
|
||
if (F)
|
||
{
|
||
/* Alphabetic order modif */
|
||
char Smallest[2048];
|
||
char SmallestLoop[2048];
|
||
char NameLower[2048];
|
||
memset(SmallestLoop,0,sizeof(Smallest));
|
||
|
||
u32 Sup = MAX_COMMAND;
|
||
while (Sup--)
|
||
{
|
||
memset(Smallest,0,sizeof(Smallest));
|
||
memset(Smallest,0xff,sizeof(Smallest) >> 2);
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) \
|
||
if ((strcmpupr(SmallestLoop, #scriptName)<0) && (strcmpupr(Smallest,#scriptName)>0)) strcpy(Smallest,#scriptName);
|
||
#define DEFINE_SCRIPT(a,params,Help,b) \
|
||
if ((strcmpupr(SmallestLoop, #a)<0) && (strcmpupr(Smallest,#a)>0)) strcpy(Smallest,#a);
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) \
|
||
if ((strcmpupr(SmallestLoop, #n)<0) && (strcmpupr(Smallest,#n)>0)) strcpy(Smallest,#n);
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) \
|
||
if ((strcmpupr(SmallestLoop, #a)<0) && (strcmpupr(Smallest,#a)>0)) strcpy(Smallest,#a);
|
||
|
||
#include "Script_Commands.h"
|
||
strcpy(SmallestLoop,Smallest);
|
||
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) \
|
||
if (strcmp(SmallestLoop,#scriptName)==0) \
|
||
{\
|
||
GenApiFile(FAPILUA, #scriptName, #parameters, helpString, 2, false);\
|
||
GenApiFile(FAPIXMLLUA, #scriptName, #parameters, helpString, 2, true);\
|
||
}
|
||
#define DEFINE_SCRIPT(a,params,Help,b) \
|
||
if (strcmp(SmallestLoop,#a)==0) \
|
||
{\
|
||
GenApiFile(FAPILUA, #a, #params, Help, 2, false);\
|
||
GenApiFile(FAPIXMLLUA, #a, #params, Help, 2, true);\
|
||
}
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) \
|
||
if (strcmp(SmallestLoop,#n)==0) \
|
||
{\
|
||
GenApiFile(FAPILUA, #n, #params, Help, 2, false);\
|
||
GenApiFile(FAPIXMLLUA, #n, #params, Help, 2, true);\
|
||
}
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) \
|
||
if (strcmp(SmallestLoop,#a)==0) \
|
||
{\
|
||
GenApiFile(FAPILUA, #a, #params, Help, 2, false);\
|
||
GenApiFile(FAPIXMLLUA, #a, #params, Help, 2, true);\
|
||
}
|
||
#include "Script_Commands.h"
|
||
}
|
||
|
||
if (FAPILUA)
|
||
CC_fclose(FAPILUA);
|
||
|
||
fprintf(F,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"Script_Help.xsl\"?>\n<Functions>");
|
||
#define DEFINE_SCRIPT_SPECIAL(scriptName, functionName, parameters, helpString) \
|
||
GenXMLCommand(F, #scriptName, #parameters, helpString, "", 2);
|
||
#define DEFINE_SCRIPT(a,params,Help,b) \
|
||
GenXMLCommand(F, #a, #params, Help, #b, 3);
|
||
#define DEFINE_SCRIPT_REN(n,a,params,Help,b) \
|
||
GenXMLCommand(F, #n, #params, Help, #b, 3);
|
||
#ifdef ONLINE_MODE
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) \
|
||
GenXMLCommand(F, #a, #params, Help, #b, 3);
|
||
#else
|
||
#define DEFINE_SCRIPT_ONLINE(a,params,Help,b,c) \
|
||
GenXMLCommand(F, #a, #params, Help, #c, 3);
|
||
#endif
|
||
|
||
#define SP_PARAMS
|
||
|
||
#include "Script_Commands.h"
|
||
|
||
if (FAPIXMLLUA)
|
||
{
|
||
fprintf(FAPIXMLLUA,"\t</AutoComplete>\n</NotepadPlus>\n");
|
||
CC_fclose(FAPIXMLLUA);
|
||
}
|
||
|
||
fprintf(F,"</Functions>");
|
||
|
||
CC_fclose(F);
|
||
}
|
||
#endif //USER_MODE
|
||
return 0;
|
||
}
|
||
|
||
|
||
|
||
u32 WORLD::SceneScript_DESTROY(CommandBatch *SceneScript,u32 Index )
|
||
{
|
||
if (SceneScript->ulNumberOfCommands)
|
||
{
|
||
if (Index != -1)
|
||
{
|
||
if (Index < 2048)
|
||
{
|
||
CC_free(SceneScript->BatchExec[Index].String);
|
||
SceneScript->BatchExec[Index].String = NULL;
|
||
}
|
||
} else
|
||
{
|
||
for (int i = 0 ; i < SceneScript->ulNumberOfCommands ; i ++)
|
||
{
|
||
CC_free(SceneScript->BatchExec[i].String);
|
||
SceneScript->BatchExec[i].String = NULL;
|
||
}
|
||
SceneScript->ulNumberOfCommands = 0;
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
u32 WORLD::SceneScript_EXECUTE()
|
||
{
|
||
char ScriptReturnValue[2048];
|
||
|
||
if (WAIT_OBJECT_0 != WaitForSingleObject(ScriptAccesMutex, INFINITE))
|
||
return 0;
|
||
|
||
for (int i = 0 ; i < SceneScript_Ecluse.ulNumberOfCommands ; i ++)
|
||
{
|
||
if (SceneScript_Ecluse.BatchExec[i].String)
|
||
{
|
||
if (!strncmp(SceneScript_Ecluse.BatchExec[i].String,
|
||
"LUA_Load", strlen("LUA_Load")))
|
||
{
|
||
if (!strcmp(SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1, "exit"))
|
||
{
|
||
void API_EXIT();
|
||
API_EXIT();
|
||
return 0;
|
||
}
|
||
// Called from an external browser?
|
||
else if (!strncmp(SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1, "camcam://", 9))
|
||
{
|
||
#ifdef ONLINE_MODE
|
||
Account.onBrowserEvent(SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1 + 9, NULL);
|
||
#endif
|
||
strcpy(ScriptReturnValue, "0");
|
||
FlashCom_Send(ScriptReturnValue);
|
||
}
|
||
else
|
||
{
|
||
// very special USE !! even the syntax is special ;)
|
||
currentScript = 0;
|
||
char *scriptToLoad = SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1;
|
||
if (!strcmp(ScriptNameStack[currentScript], scriptToLoad) || strstr(ScriptNameStack[currentScript], scriptToLoad))
|
||
{
|
||
SetActiveWindow(OwnerHwnd);
|
||
continue;
|
||
}
|
||
#ifdef USER_MODE
|
||
// Verify file
|
||
BOOL IsFileAllowed(char *filename, bool fromLua);
|
||
if (IsFileAllowed(SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1, 0))
|
||
{
|
||
sprintf(ScriptNameStack[currentScript],"%s", SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1);
|
||
LoadLua(ScriptNameStack[currentScript], 1);
|
||
}
|
||
}
|
||
}
|
||
#else
|
||
extern char CamcamCCM[];
|
||
|
||
sprintf(ScriptNameStack[currentScript],"%s", SceneScript_Ecluse.BatchExec[i].String + strlen("LUA_Load") + 1);
|
||
SetIniValue(CamcamCCM, "lastScriptPath", ScriptNameStack[currentScript]);
|
||
SaveIniFile(CamcamCCM);
|
||
LoadLua(ScriptNameStack[currentScript], 1);
|
||
|
||
strcpy(ScriptReturnValue, "0");
|
||
FlashCom_Send(ScriptReturnValue);
|
||
}
|
||
} else if (!strncmp(SceneScript_Ecluse.BatchExec[i].String,
|
||
"ZCC_Load", strlen("ZCC_Load")))
|
||
{
|
||
// very special USE !! even the syntax is special ;)
|
||
UNPACK(SceneScript_Ecluse.BatchExec[i].String + strlen("ZCC_Load "),1,0);
|
||
} else if (!strncmp(SceneScript_Ecluse.BatchExec[i].String,
|
||
"LUA_ExecScript", strlen("LUA_ExecScript")))
|
||
{
|
||
char ExecCommand[2048 + 64];
|
||
strcpy(ScriptReturnValue, "0");
|
||
if (luaScriptTable[currentScript])
|
||
{
|
||
if (strchr(SceneScript_Ecluse.BatchExec[i].String, '='))
|
||
{
|
||
if (luaL_dostring(luaScriptTable[currentScript], SceneScript_Ecluse.BatchExec[i].String) != 0)
|
||
{
|
||
char * strPtr = (char *)lua_tostring(luaScriptTable[currentScript],-1);
|
||
if (strPtr)
|
||
strcpy(ScriptReturnValue, strPtr);
|
||
}
|
||
} else
|
||
{
|
||
sprintf(ExecCommand, "return %s", SceneScript_Ecluse.BatchExec[i].String);
|
||
luaL_dostring(luaScriptTable[currentScript], ExecCommand);
|
||
if(lua_istable(luaScriptTable[currentScript], -1))
|
||
{
|
||
extern int mainThread;
|
||
if (mainThread != GetCurrentThreadId()) MessageBox(NULL, "Bad Threard Access 5!", "YouUp", MB_OK | MB_ICONERROR);
|
||
lua_getglobal(luaScriptTable[currentScript], "TableToString");
|
||
lua_pushvalue(luaScriptTable[currentScript], -2);
|
||
lua_pushnumber(luaScriptTable[currentScript], 2);
|
||
lua_pcall(luaScriptTable[currentScript], 2, 1,0);
|
||
}
|
||
if (!lua_isnil(luaScriptTable[currentScript],-1))
|
||
{
|
||
if (lua_isboolean(luaScriptTable[currentScript],-1))
|
||
{
|
||
if (lua_toboolean(luaScriptTable[currentScript],-1))
|
||
strcpy(ScriptReturnValue, "1");
|
||
} else
|
||
{
|
||
char * strPtr = (char *)lua_tostring(luaScriptTable[currentScript],-1);
|
||
if (strPtr)
|
||
strcpy(ScriptReturnValue, strPtr);
|
||
}
|
||
}
|
||
lua_pop(luaScriptTable[currentScript], 1);
|
||
}
|
||
if (ScriptReturnValue[0] == 0)
|
||
strcpy(ScriptReturnValue, "0");
|
||
}
|
||
FlashCom_Send(ScriptReturnValue);
|
||
}
|
||
#endif //USER_MODE
|
||
}
|
||
}
|
||
SceneScript_DESTROY(&SceneScript_Ecluse);
|
||
ReleaseMutex(ScriptAccesMutex);
|
||
return 0;
|
||
}
|
||
|
||
u32 WORLD::SceneScript_SetText(CommandLine *CL, char *Line)
|
||
{
|
||
if (CL->String) CC_free(CL->String);
|
||
CL->String = NULL;
|
||
if (Line)
|
||
{
|
||
CL->String = (s8 *)CC_malloc(strlen(Line) + 2);
|
||
strcpy(CL->String,Line);
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
u32 WORLD::SceneScript_ADD(CommandBatch *SceneScript, char *Line, u32 Index)
|
||
{
|
||
if (WAIT_OBJECT_0 == WaitForSingleObject(ScriptAccesMutex, 100))
|
||
{
|
||
if (Index == -1) Index = SceneScript->ulNumberOfCommands;
|
||
if (Index > 2047) Index = 2047;
|
||
|
||
SceneScript_SetText(&SceneScript->BatchExec[Index], Line);
|
||
if (Index >= SceneScript->ulNumberOfCommands) SceneScript->ulNumberOfCommands = Index + 1;
|
||
|
||
ReleaseMutex(ScriptAccesMutex);
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
/************************************************************************************************************************/
|
||
/* Console Execution */
|
||
/************************************************************************************************************************/
|
||
#define ConsoleNumberOfdLines 150
|
||
#define ConsoleLineW 256
|
||
static char Console[ConsoleNumberOfdLines*ConsoleLineW];
|
||
|
||
WORLD *ThtrashWorldPlace = NULL;
|
||
void WORLD::OutputConsole(char *String)
|
||
{
|
||
ThtrashWorldPlace = this;
|
||
u32 localCW = XSize / 8;
|
||
if (localCW > ConsoleLineW) localCW = ConsoleLineW;
|
||
|
||
while (strlen(String) > localCW)
|
||
{
|
||
char Save;
|
||
Save = String[localCW];
|
||
String[localCW] = 0;
|
||
memmove(Console + ConsoleLineW,Console,(ConsoleNumberOfdLines-1)*ConsoleLineW);
|
||
sprintf(Console,"%s",String);
|
||
String[localCW] = Save;
|
||
String += localCW;
|
||
}
|
||
memmove(Console + ConsoleLineW,Console,(ConsoleNumberOfdLines-1)*ConsoleLineW);
|
||
sprintf(Console,"%s",String);
|
||
}
|
||
|
||
void _Extern_OutputConsole(char *String)
|
||
{
|
||
if (ThtrashWorldPlace) ThtrashWorldPlace->OutputConsole(String);
|
||
}
|
||
void WORLD::DrawConsole()
|
||
{
|
||
for ( u32 Counter = 0 ; Counter < ConsoleNumberOfdLines ; Counter++)
|
||
{
|
||
DI->DrawText((unsigned char *)(Console + ConsoleLineW * Counter),10, Counter * 17, 1.0,1.0,0xff00ffff);
|
||
}
|
||
}
|
||
|
||
void WORLD::ClearConsole()
|
||
{
|
||
for ( u32 Counter = 0 ; Counter < ConsoleNumberOfdLines ; Counter++)
|
||
{
|
||
*(char *)(Console + ConsoleLineW * Counter) = 0;
|
||
}
|
||
}
|