Brought up to date with the newest T2BoL I've located

This commit is contained in:
Robert MacGregor 2015-08-30 02:30:29 -04:00
parent 8c96cba3e1
commit accd31895e
287 changed files with 108557 additions and 107608 deletions

View file

@ -0,0 +1,83 @@
//------------------------------------------------------------------------------
// Array.cs
// Array object you can pass around.
// Copyright (c) 2012 Robert MacGregor
//==============================================================================
function ArrayFactory::create(%this, %name)
{
if (isObject(%name))
%name = "";
%object = new ScriptObject(%name) { class = "ArrayObject"; };
%object.elementCount = 0;
return %object;
}
function ArrayObject::setElement(%this, %index, %object)
{
%replaced = false;
if (%this.Element[%index] != "")
%replaced = true;
else
{
%this.elementIndex[%index] = %this.elementCount;
%this.elementIndices[%this.elementCount] = %index;
%this.elementCount++;
}
%this.Element[%index] = %object;
return %replaced;
}
function ArrayObject::list(%this)
{
%list = Array.create();
for (%i = 0; %i < %this.elementCount; %i++)
%list.setElement(%i, %this.Element[%this.elementIndices[%i]]);
return %list;
}
function ArrayObject::removeElement(%this, %index)
{
if (%this.Element[%index] != "")
{
%this.Element[%index] = "";
for (%i = %this.elementIndex[%index]; %i < %this.elementCount; %i++)
%this.elementIndices[%i] = %this.elementIndices[%i+1];
%this.elementCount--;
return true;
}
else
return false;
return false;
}
function ArrayObject::hasElementValue(%this, %value)
{
for (%i = 0; %i < %this.elementCount; %i++)
if (%this.Element[%i] == %value)
return true;
return false;
}
function ArrayObject::isElement(%this, %index)
{
if (%this.Element[%index] == "")
return false;
else
return true;
return false;
}
function ArrayObject::element(%this, %index)
{
return %this.Element[%index];
}
function ArrayObject::count(%this)
{
return %this.elementCount;
}
if (!IsObject(Array))
new ScriptObject(Array) { class = "ArrayFactory"; };

View file

@ -0,0 +1,276 @@
//------------------------------------------------------------------------------
// basicDataStorage.cs
// Originally written for T2BoL mod back in the day, now is being rewritten
// for the original implementation was pretty crappy.
// Requires: Array.cs
// Copyright (c) 2012 Robert MacGregor
//==============================================================================
//------------------------------------------------------------------------------
// Name: BasicDataParser.load
// Argument %file: The file to parse and load into memory.
// Description: This function is the main function of everything; it loads
// %file into memory.
// Return: True if the function succeeded, false if otherwise failed.
//==============================================================================
function BasicDataParser::load(%this, %file)
{
// Make sure we have our values initialised (math doesn't work right on nonexistent variables!)
if (%this.filesLoaded == "")
%this.filesLoaded = 0;
if (%this.blockEntryCount == "")
%this.blockEntryCount = 0;
if (%this.blockInstances == "")
%this.blockInstances = 0;
%currentSeconds = formatTimeString("ss");
// Check to see if the data is valid (returns false if we tried to load a nonexistent file)
if (!isFile(%file))
{
error("basicDataStorage.cs: Attempted to load non-existent file " @ %file @ "!");
return false;
}
// Check to see if this file is already loaded
if (%this.isLoaded(%file))
{
error("basicDataStorage.cs: Attempted to reload data file " @ %file SPC "while it's already in memory! (try unloading or emptying)");
return false;
}
// Add the file entry to memory (for the file check above)
%this.files[%this.filesLoaded] = %file;
%this.fileIndex[%file] = %this.filesLoaded;
%this.filesLoaded++;
// Load the file into memory (function is from fileProcessing.cs)
%fileData = strReplace(stripChars(getFileBuffer(%file),"\t"),"\n","\t");
%lineCount = getFieldCount(%fileData);
%isProcessingBlock = false; // Used to set processing mode
%currentBlock = 0;
%hadError = false;
// Iterate through all lines
for (%i = 0; %i < %lineCount; %i++)
{
%currentLine = getField(%fileData,%i);
// Check to see if this line contains a block definition or not
%openingBlock = strStr(%currentLine, "[");
%closingBlock = strStr(%currentLine, "]");
// If we have a block definition, it should be against left margin
if (%openingBlock == 0 && %closingBlock > 0 && !%isProcessingBlock)
{
%isProcessingBlock = true;
%blockName = getSubStr(%currentLine,%openingBlock+1,%closingBlock-1);
if (%this.blockInstances[%blockName] == "")
{
%this.blockInstances[%blockName] = 0;
%this.blockEntry[%this.blockEntryCount] = %blockName;
%this.blockEntryCount++;
}
// Create the array to store our block data
%currentBlock = Array.create();
%currentBlock.Name = %blockName;
%currentBlock.File = %file;
%this.blocks[%blockName,%this.blockInstances] = %currentBlock;
%this.blockInstances[%blockName]++;
%this.blockInstances++;
continue;
}
// Results in an error
else if (%openingBlock == 0 && %closingBlock > 0 && %isProcessingBlock)
{
error("basicDataStorage.cs: Error loading file "@ %file @ ", block spacing error.");
return false;
}
// If we're processing the actual block
if (%isProcessingBlock)
{
if (%currentLine $="" || %i == %lineCount)
{
%isProcessingBlock = false;
continue;
}
else
{
%eqPos = strStr(%currentLine,"="); // This is safe since the equals sign should be first.
if (%eqPos == -1)
{
error("basicDataStorage.cs: Unable to read entry for block" SPC %currentBlock.Name @ " in file" SPC %file @ "!");
%isProcessingBlock = false;
%hadError = true;
continue;
}
// Note: I got lazy here, just don't have semicolons in your data entries..
%semiPos = strStr(%currentLine,";");
if (%semiPos == -1 || getSubStrOccurance(%currentLine,";") > 1)
{
error("basicDataStorage.cs: Unable to read entry for block" SPC %currentBlock.Name @ " in file" SPC %file @ "!");
%isProcessingBlock = false;
%hadError = true;
continue;
}
%entryName = trim(getSubStr(%currentLine,0,%eqPos-1));
%entryValue = trim(getSubStr(%currentLine,%eqPos+1, mAbs(%eqPos-%semiPos)-1 ));
%currentBlock.setElement(%entryName,%entryValue);
}
}
}
if (!%hadError)
warn("basicDataStorage.cs: Successfully loaded file" SPC %file SPC "in " @ formatTimeString("ss") - %currentSeconds SPC "seconds.");
return !%hadError;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.unload
// Argument %file: The file of who's entries should be unloaded.
// Description: This function is used to unload data by filename -- useful for
// reloading data from specific files.
// Return: True if the function was successful, false if otherwise failed.
//==============================================================================
function BasicDataParser::unload(%this, %file)
{
if (!%this.isLoaded(%file))
{
error("basicDataStorage.cs: Attempted to unload non-loaded data file " @ %file @ "!");
return false;
}
// Unload any data associated with this file now
%removed = "";
for (%i = 0; %i < %this.blockEntryCount; %i++)
{
%name = %this.blockEntry[%i];
for (%h = 0; %h < %this.blockInstances[%name]; %h++)
if (%this.blocks[%name, %h].File $= %file)
{
%this.blocks[%name, %h].delete();
%this.blocks[%name, %h] = "";
%this.blockEntry[%i] = "";
%removed = trim(%removed SPC %i);
if (%this.blockInstances[%name] == 1)
%this.blockInstances[%name] = "";
else
%this.blockInstances[%name]--;
}
}
// Iterate through our block entries and correct the imbalance
for (%i = 0; %i < getWordCount(%removed); %i++)
{
for (%h = i; %h < %this.blockEntryCount; %h++)
%this.blockEntry[%h-%i] = %this.blockEntry[%h+1];
%this.blockEntryCount--;
}
// Now remove the file entry
for (%i = %this.fileIndex[%file]; %i < %this.filesLoaded; %i++)
if (%i != %this.filesLoaded-1)
{
%this.files[%i] = %this.files[%i+1];
%this.fileIndex[%this.files[%i+1]] = %i;
}
else
{
%this.fileIndex[%file] = "";
%this.files[%i] = "";
}
// Decrement the files loaded count and return true
%this.filesLoaded--;
return true;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.count
// Argument %block: The bloick entry to count the occurances of
// Return: The occurances of %block in this parser object. If there is no
// such entry of %block anywhere, false (0) is returned.
//==============================================================================
function BasicDataParser::count(%this, %block)
{
// Return zero if the block has no entries even registered
if (%this.blockInstances[%block] == "")
return false;
else
// Return the block Instances otherwise
return %this.blockInstances[%block];
return false; // Shouldn't happen
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.empty
// Description: Empties the entire object of any information it may have
// loaded anytime.
// Return: True is always returned from this function.
//==============================================================================
function BasicDataParser::empty(%this)
{
// Iterate through our block entries and destroy them
for (%i = 0; %i < %this.blockEntryCount; %i++)
{
%name = %this.blockEntry[%i];
for (%h = 0; %h < %this.blockInstances[%name]; %h++)
{
%this.blocks[%name, %h].delete();
%this.blocks[%name, %h] = "";
}
%this.blockInstances[%name] = "";
%this.blockEntry[%i] = "";
}
// Remove the files loaded entries now
for (%i = 0; %i < %this.filesLoaded; %i++)
{
%this.fileIndex[%this.files[%i]] = "";
%this.files[%i] = "";
}
// Reset some variables to 0 and return true
%this.filesLoaded = 0;
%this.blockInstances = 0;
%this.blockEntryCount = 0;
return true;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.isLoaded
// Argument %file: The file to check the loaded status of.
// Description: Returns if %file is loaded into memory of this object or not.
// Return: A boolean representing the loaded status.
//==============================================================================
function BasicDataParser::isLoaded(%this, %file)
{
// Check to see if this file is already loaded
for (%i = 0; %i < %this.filesLoaded; %i++)
if (%this.files[%i] $= %file)
return true;
return false;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.get
// Argument %block: The name of the block to return.
// Argument %occurance: The block index we need to return -- if there's
// multiple entries of %block.
// Description: This function is used to retrieve block entries loaded from
// within any of the files this object has parsed.
// Return: An Array (array.cs) containing relevent information to the requested
// block. If there is no such entry of %block, false is returned.
//==============================================================================
function BasicDataParser::get(%this, %block, %occurance)
{
// Check ti see uf thus block has only once entry -- in which case %occurance is ignored
if (%this.count(%block) == 1) return %this.blocks[%block, 0];
// Otherwise we use %occurance to return the specific index
else if (%occurance >= 0 && %occurance <= %this.count(%block)) return %this.blocks[%block, %occurance];
return false;
}

View file

@ -0,0 +1,80 @@
// -----------------------------------------------------
// FileFunctions.cs
// Basic file functions
// Copyright (c) 2012 Robert MacGregor
// -----------------------------------------------------
function getFileBuffer(%file)
{
if (!IsFile(%file))
return -1;
new FileObject(FileBuffer);
FileBuffer.openForRead(%file);
while (!FileBuffer.isEOF())
%buffer = %buffer @ FileBuffer.readLine() @ "\n";
FileBuffer.detach();
return %buffer; //Long string. >.>
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return -1;
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return -1;
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
// Returns an unsorted list of the contents of %dir (including folders)
function getDirectory(%dir)
{
%array = Array.create();
%fileCount = 0;
for( %file = findFirstFile( %dir @ "*.*" ); %file !$= ""; %file = findNextFile( %dir @ "*.*" ) )
{
%file = strReplace(%file, %socket.request, "");
if (strStr(%file, "/") != -1)
{
%dir = getSubStr(%file, 0, strStr(%file, "/")) @ "/";
if (!%dirAdded[%dir])
{
%data = %data @ "<a href=\"" @ strReplace(%dir, " ","%20") @ "\">" @ %dir @ "</a><br>\n";
%dirAdded[%dir] = true;
}
}
else
%data = %data @ "<a href=\"" @ strReplace(%file, " ", "%20") @ "\">" @ %file @ "</a><br>\n";
}
return %array;
}
// -----------------------------------------------------
// Bound Functions
// -----------------------------------------------------
function fileObject::Detach(%this) //Detaches fileObject from file & deletes
{
%this.close();
%this.delete();
return %this;
}

View file

@ -0,0 +1,196 @@
//------------------------------------------------------------------------------
// StringFunctions.cs
// String functions
// Copyright (c) 2012 Robert MacGregor
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function textToHash(%text)
{
new fileObject(TextToHash);
TextToHash.openForWrite("Hash.txt");
TextToHash.writeLine(%text);
TextToHash.detach();
%hash = getFileCRC("Hash.txt");
deleteFile("Hash.txt");
return %hash;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strReverse(%string)
{
%len = StrLen(%string);
%rstring = "";
for (%i = 0; %i < %len; %i++)
%rstring = getSubStr(%string,%i,1) @ %rstring;
return %rstring;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrInsert(%string,%insert,%slot)
{
%seg = getSubStr(%string,0,%slot);
%seg = %seg @ %insert;
%string = %seg @ getSubStr(%string,%slot,strLen(%string));
return %string;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrRemove(%string,%slot)//Minimum: 1
{
%half2 = getSubStr(%string,%slot,strLen(%string));
%half1 = getSubStr(%string,0,%slot-1);
return %half1 @ %half2;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strMove(%string,%factor)
{
%len = GetWordCount(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getWord(%string,%i);
%move = subStrInsert(%move,%sub,%i);
}
return %move;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrMove(%string,%factor)
{
%len = strLen(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
%move = subStrInsert(%move,%sub,%factor);
}
return %move;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function subStrScramble(%string)
{
%len = strLen(%string);
for (%i = 0; %i < %len; %i++)
{
%sub = getSubStr(%string,%i,1);
%scramble = subStrInsert(%scramble,%sub,getRandom(0,%len));
}
return %scramble;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strSplit(%string)
{
%count = strLen(%string);
%div = %count / 2;
return getSubStr(%string,0,%div) @ " | " @ getSubStr(%string,%div,%count);
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function stripSpaces(%string)
{
return strReplace(%string," ","");
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function stripNonNumericCharacters(%string)
{
%string = strLwr(%string);
return stripChars(%string,"abcdefghijklmnopqrstuvwxyz`~!@#$%^&*()-_=+\|}]{[/?.>,<;:");
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function getSubStrOccurances(%string,%search)
{
%len = strLen(%string);
%srLen = strLen(%search);
%count = 0;
for (%i = 0; %i < %len; %i++)
{
%strSearch = strStr(%string,%search);
if (%strSearch != -1) //It exists somewhere in the string
{
%count++;
%string = getSubStr(%string,%strSearch+%srLen,%len);
}
else
return %count;
}
return %count;
}
function getSubStrPos(%string,%str,%num)
{
%len = strLen(%string);
%subC = 0;
for (%i = 0; %i < %len; %i++)
{
%curPos = %i;
%sub = getSubStr(%string,%i,1);
if (%sub $= %str)
{
if (%subC == %num)
return %i;
%subC++;
}
}
return false;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function strWhite(%string, %whiteList, %char)
{
%charLen = strLen(%char);
for (%i = 0; %i < strLen(%whiteList); %i++)
for (%h = 0; %h < %charLen; %h++)
{
%whiteSeg = getSubStr(%whiteList, %i, %charLen);
}
return false;
}
//------------------------------------------------------------------------------
function getFileNameFromString(%string)
{
if (strStr(%string, "/") == -1)
return %string;
else
return getSubStr(%string,getSubStrPos(%string, "/", getSubStrOccurances(%string, "/")-1)+1,strLen(%string));
}
//-------------------------------------------------------------------------------
function getFileExtensionFromString(%string)
{
%file = getFileNameFromString(%string);
%period = strStr(%file,".");
if (%period == -1)
return false;
else
return getSubStr(%file,strStr(%file,".")+1, strLen(%file));
}
//------------------------------------------------------------------------------

View file

@ -0,0 +1,276 @@
//------------------------------------------------------------------------------
// basicDataStorage.cs
// Originally written for T2BoL mod back in the day, now is being rewritten
// for the original implementation was pretty crappy.
// Requires: Array.cs
// Copyright (c) 2012 The DarkDragonDX
//==============================================================================
//------------------------------------------------------------------------------
// Name: BasicDataParser.load
// Argument %file: The file to parse and load into memory.
// Description: This function is the main function of everything; it loads
// %file into memory.
// Return: True if the function succeeded, false if otherwise failed.
//==============================================================================
function BasicDataParser::load(%this, %file)
{
// Make sure we have our values initialised (math doesn't work right on nonexistent variables!)
if (%this.filesLoaded == "")
%this.filesLoaded = 0;
if (%this.blockEntryCount == "")
%this.blockEntryCount = 0;
if (%this.blockInstances == "")
%this.blockInstances = 0;
%currentSeconds = formatTimeString("ss");
// Check to see if the data is valid (returns false if we tried to load a nonexistent file)
if (!isFile(%file))
{
error("basicDataStorage.cs: Attempted to load non-existent file " @ %file @ "!");
return false;
}
// Check to see if this file is already loaded
if (%this.isLoaded(%file))
{
error("basicDataStorage.cs: Attempted to reload data file " @ %file SPC "while it's already in memory! (try unloading or emptying)");
return false;
}
// Add the file entry to memory (for the file check above)
%this.files[%this.filesLoaded] = %file;
%this.fileIndex[%file] = %this.filesLoaded;
%this.filesLoaded++;
// Load the file into memory (function is from fileProcessing.cs)
%fileData = strReplace(stripChars(getFileBuffer(%file),"\t"),"\n","\t");
%lineCount = getFieldCount(%fileData);
%isProcessingBlock = false; // Used to set processing mode
%currentBlock = 0;
%hadError = false;
// Iterate through all lines
for (%i = 0; %i < %lineCount; %i++)
{
%currentLine = getField(%fileData,%i);
// Check to see if this line contains a block definition or not
%openingBlock = strStr(%currentLine, "[");
%closingBlock = strStr(%currentLine, "]");
// If we have a block definition, it should be against left margin
if (%openingBlock == 0 && %closingBlock > 0 && !%isProcessingBlock)
{
%isProcessingBlock = true;
%blockName = getSubStr(%currentLine,%openingBlock+1,%closingBlock-1);
if (%this.blockInstances[%blockName] == "")
{
%this.blockInstances[%blockName] = 0;
%this.blockEntry[%this.blockEntryCount] = %blockName;
%this.blockEntryCount++;
}
// Create the array to store our block data
%currentBlock = Array.create();
%currentBlock.Name = %blockName;
%currentBlock.File = %file;
%this.blocks[%blockName,%this.blockInstances] = %currentBlock;
%this.blockInstances[%blockName]++;
%this.blockInstances++;
continue;
}
// Results in an error
else if (%openingBlock == 0 && %closingBlock > 0 && %isProcessingBlock)
{
error("basicDataStorage.cs: Error loading file "@ %file @ ", block spacing error.");
return false;
}
// If we're processing the actual block
if (%isProcessingBlock)
{
if (%currentLine $="" || %i == %lineCount)
{
%isProcessingBlock = false;
continue;
}
else
{
%eqPos = strStr(%currentLine,"="); // This is safe since the equals sign should be first.
if (%eqPos == -1)
{
error("basicDataStorage.cs: Unable to read entry for block" SPC %currentBlock.Name @ " in file" SPC %file @ "!");
%isProcessingBlock = false;
%hadError = true;
continue;
}
// Note: I got lazy here, just don't have semicolons in your data entries..
%semiPos = strStr(%currentLine,";");
if (%semiPos == -1 || getSubStrOccurance(%currentLine,";") > 1)
{
error("basicDataStorage.cs: Unable to read entry for block" SPC %currentBlock.Name @ " in file" SPC %file @ "!");
%isProcessingBlock = false;
%hadError = true;
continue;
}
%entryName = trim(getSubStr(%currentLine,0,%eqPos-1));
%entryValue = trim(getSubStr(%currentLine,%eqPos+1, mAbs(%eqPos-%semiPos)-1 ));
%currentBlock.setElement(%entryName,%entryValue);
}
}
}
if (!%hadError)
warn("basicDataStorage.cs: Successfully loaded file" SPC %file SPC "in " @ formatTimeString("ss") - %currentSeconds SPC "seconds.");
return !%hadError;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.unload
// Argument %file: The file of who's entries should be unloaded.
// Description: This function is used to unload data by filename -- useful for
// reloading data from specific files.
// Return: True if the function was successful, false if otherwise failed.
//==============================================================================
function BasicDataParser::unload(%this, %file)
{
if (!%this.isLoaded(%file))
{
error("basicDataStorage.cs: Attempted to unload non-loaded data file " @ %file @ "!");
return false;
}
// Unload any data associated with this file now
%removed = "";
for (%i = 0; %i < %this.blockEntryCount; %i++)
{
%name = %this.blockEntry[%i];
for (%h = 0; %h < %this.blockInstances[%name]; %h++)
if (%this.blocks[%name, %h].File $= %file)
{
%this.blocks[%name, %h].delete();
%this.blocks[%name, %h] = "";
%this.blockEntry[%i] = "";
%removed = trim(%removed SPC %i);
if (%this.blockInstances[%name] == 1)
%this.blockInstances[%name] = "";
else
%this.blockInstances[%name]--;
}
}
// Iterate through our block entries and correct the imbalance
for (%i = 0; %i < getWordCount(%removed); %i++)
{
for (%h = i; %h < %this.blockEntryCount; %h++)
%this.blockEntry[%h-%i] = %this.blockEntry[%h+1];
%this.blockEntryCount--;
}
// Now remove the file entry
for (%i = %this.fileIndex[%file]; %i < %this.filesLoaded; %i++)
if (%i != %this.filesLoaded-1)
{
%this.files[%i] = %this.files[%i+1];
%this.fileIndex[%this.files[%i+1]] = %i;
}
else
{
%this.fileIndex[%file] = "";
%this.files[%i] = "";
}
// Decrement the files loaded count and return true
%this.filesLoaded--;
return true;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.count
// Argument %block: The bloick entry to count the occurances of
// Return: The occurances of %block in this parser object. If there is no
// such entry of %block anywhere, false (0) is returned.
//==============================================================================
function BasicDataParser::count(%this, %block)
{
// Return zero if the block has no entries even registered
if (%this.blockInstances[%block] == "")
return false;
else
// Return the block Instances otherwise
return %this.blockInstances[%block];
return false; // Shouldn't happen
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.empty
// Description: Empties the entire object of any information it may have
// loaded anytime.
// Return: True is always returned from this function.
//==============================================================================
function BasicDataParser::empty(%this)
{
// Iterate through our block entries and destroy them
for (%i = 0; %i < %this.blockEntryCount; %i++)
{
%name = %this.blockEntry[%i];
for (%h = 0; %h < %this.blockInstances[%name]; %h++)
{
%this.blocks[%name, %h].delete();
%this.blocks[%name, %h] = "";
}
%this.blockInstances[%name] = "";
%this.blockEntry[%i] = "";
}
// Remove the files loaded entries now
for (%i = 0; %i < %this.filesLoaded; %i++)
{
%this.fileIndex[%this.files[%i]] = "";
%this.files[%i] = "";
}
// Reset some variables to 0 and return true
%this.filesLoaded = 0;
%this.blockInstances = 0;
%this.blockEntryCount = 0;
return true;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.isLoaded
// Argument %file: The file to check the loaded status of.
// Description: Returns if %file is loaded into memory of this object or not.
// Return: A boolean representing the loaded status.
//==============================================================================
function BasicDataParser::isLoaded(%this, %file)
{
// Check to see if this file is already loaded
for (%i = 0; %i < %this.filesLoaded; %i++)
if (%this.files[%i] $= %file)
return true;
return false;
}
//------------------------------------------------------------------------------
// Name: BasicDataParser.get
// Argument %block: The name of the block to return.
// Argument %occurance: The block index we need to return -- if there's
// multiple entries of %block.
// Description: This function is used to retrieve block entries loaded from
// within any of the files this object has parsed.
// Return: An Array (array.cs) containing relevent information to the requested
// block. If there is no such entry of %block, false is returned.
//==============================================================================
function BasicDataParser::get(%this, %block, %occurance)
{
// Check ti see uf thus block has only once entry -- in which case %occurance is ignored
if (%this.count(%block) == 1) return %this.blocks[%block, 0];
// Otherwise we use %occurance to return the specific index
else if (%occurance >= 0 && %occurance <= %this.count(%block)) return %this.blocks[%block, %occurance];
return false;
}

View file

@ -0,0 +1,80 @@
// -----------------------------------------------------
// fileProcessing.cs
// Basic file functions
// Copyright (c) 2012 The DarkDragonDX
// -----------------------------------------------------
function getFileBuffer(%file)
{
if (!IsFile(%file))
return -1;
new FileObject(FileBuffer);
FileBuffer.openForRead(%file);
while (!FileBuffer.isEOF())
%buffer = %buffer @ FileBuffer.readLine() @ "\n";
FileBuffer.detach();
return %buffer; //Long string. >.>
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return -1;
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
function getLine(%file, %line)
{
if (!IsFile(%file))
return -1;
new FileObject(FileLine);
FileLine.openForRead(%file);
for (%i = 0; %i < %line; %i++)
%line = FileLine.readLine();
FileLine.detach();
return %line;
}
// Returns an unsorted list of the contents of %dir (including folders)
function getDirectory(%dir)
{
%array = Array.create();
%fileCount = 0;
for( %file = findFirstFile( %dir @ "*.*" ); %file !$= ""; %file = findNextFile( %dir @ "*.*" ) )
{
%file = strReplace(%file, %socket.request, "");
if (strStr(%file, "/") != -1)
{
%dir = getSubStr(%file, 0, strStr(%file, "/")) @ "/";
if (!%dirAdded[%dir])
{
%data = %data @ "<a href=\"" @ strReplace(%dir, " ","%20") @ "\">" @ %dir @ "</a><br>\n";
%dirAdded[%dir] = true;
}
}
else
%data = %data @ "<a href=\"" @ strReplace(%file, " ", "%20") @ "\">" @ %file @ "</a><br>\n";
}
return %array;
}
// -----------------------------------------------------
// Bound Functions
// -----------------------------------------------------
function fileObject::Detach(%this) //Detaches fileObject from file & deletes
{
%this.close();
%this.delete();
return %this;
}

View file

@ -0,0 +1,10 @@
//------------------------------------------------------------------------------
// initialise.cs
// Shared Functions for T2Bol
// Copyright (c) 2012 The DarkDragonDX
//==============================================================================
exec("scripts/modScripts/shared/StringFunctions.cs");
exec("scripts/modScripts/shared/fileProcessing.cs");
exec("scripts/modScripts/shared/basicDataStorage.cs");

View file

@ -0,0 +1,201 @@
// -----------------------------------------------------
// Block Processing
// -----------------------------------------------------
function getBlockCount(%file,%blockName) //Searches a data file for all occurances of 'blockName'
{
if (!IsFile(%file))
return false;
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%blockSearch);
if (%search != -1)
%count++;
}
%fileP.detach();
return %count;
}
function getBlockData(%file,%blockName,%num,%data) //Gets values out of a block. Note that 1 is the first block in a file for %num
{
if (!IsFile(%file))
return false;
%blockCount = getBlockCount(%file,%blockName);
if (!%blockCount || %num > %blockCount) //None of 'typeName' exist here
return -1;
%blockSearch = strLwr("[" @ %blockName @ "]");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
%lineCount = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineCount++;
if (getSubStr(stripSpaces(%line),0,1) !$= ";") //If the beginning of the line is "commented", skip it.
{
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%blockSearch);
if (%Search != -1 && %Count != %num)
%count++;
else if (%count == %num) //We found it, stop incrementing the count and find our data.
{
%Search = strStr(strLwr(%line),strLwr(%data));
%lineTest = strLwr(strReplace(%line," ","")); //See if we exited our block
if (GetSubStr(%lineTest, 0, 1) $= "[") //The beginning of a new block
return -1;
if (%search != -1) //We found it,
{
%fileP.detach();
//Since our line might have some sort of commenting after it, we better return to just the "end" symbol..
%semiS =strStr(%line, ";");
if (%semiS == -1)
return -1;
%line = getSubStr(%line, 0, %semiS);
//Now find where "equals" is..
%equalS = strStr(%line, "=");
if (%equalS == -1)
return -1;
%line = getSubStr(%line, %equalS+1, strLen(%line));
//Is our data in single quotations? If so, convert it to a tagged string.
if (strStr(%line,"\x27") != -1) //It is.
%line = addTaggedString(stripChars(%line,"\x27"));
//Now return our string without quotations.
%line = stripChars(stripTrailingSpaces(strReplace(%line,%data,"")),"\x22");
return getSubStr(%line,1,strLen(%line));
}
}
}
}
%fileP.detach();
return false;
}
//function getBlockLength(%file,%blockName,%num) Won't work until I figure out a way to signal the end of a block without adding any extra characters,
//{
//if (!IsFile(%file))
//return "Not existant.";
//%blockSearch = "[" @ %blockName @ "]";
//%blockSearch = strLwr(%blockSearch); //Convert to lowerCase
//new FileObject(GetBlockCount);
//GetBlockCount.openForRead(%file);
//%count = 0;
//%len = 0;
// while (!GetBlockCount.isEOF())
// {
// %line = GetBlockCount.readLine();
// %lineTest = strLwr(%line);
// %Search = strStr(%lineTest,%blockSearch);
//if (%search != -1)
// %count++;
// else if (%search != -1 && %count == %num) //We found our wanted block, count it.
//{
// if (strStr(%lineTest,%blockSearch) == -1)
// %len++;
// else
// break;
// }
//}
//GetBlockCount.detach();
//return %len;
//}
// -----------------------------------------------------
// Array Processing
// -----------------------------------------------------
function getArrayCount(%file,%array)
{
if (!IsFile(%file))
return false;
%arraySearch = strLwr("\x22" @ %array @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%count = 0;
while (!%fileP.isEOF())
{
%line = %fileP.readLine();
%lineTest = strLwr(%line);
%Search = strStr(%lineTest,%typeSearch);
if (%search != -1)
%count++;
}
%fileP.detach();
return %count;
}
function getArrayData(%file,%arrayName,%num)
{
if (!IsFile(%file))
return false;
%arrayCount = getArrayCount(%file,%arrayName);
if (!%arrayCount)
return false;
%arraySearch = strLwr("\x22" @ %arrayName @ "\x22");
%fileP = new FileObject();
%fileP.openForRead(%file);
%lineCount = 0;
while (!%fileP.isEOF())
{
%line = stripSpaces(%fileP.readline());
%lineCount++;
if (getSubStr(%line,0,1) !$= ";") //Is this line a comment?
{
%search = strStr(strLwr(%line),%arraySearch);
if (%search !$= -1) //Found it.
break; //Break the loop, we know the array exists
if (%fileP.IsEOF() && %search == -1) //Didn't find it, return the error.
return false;
}
}
//Check where the array actually starts..
%line = %fileP.readLine();
if (%line $= "{") //Data starts on next line..
{
%line = %fileP.readLine(); //Drop it down one
for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data
%line = %fileP.readLine();
}
else //The line we just grabbed is part of the data
{
if (%num == 0) //The wanted data was on line zero..
return %line;
for (%i = 0; %i < %num; %i++) //Keep going untill we hit the wanted data
%line = %fileP.readLine();
}
%fileP.detach();
return %line;
}