Some more work on new ScriptEngine.

afrisby
Tedd Hansen 2007-10-05 19:56:44 +00:00
parent 29aa41daa0
commit 6dd923b01d
35 changed files with 8174 additions and 7 deletions

View File

@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Runtime.Remoting.Lifetime;
namespace OpenSim.Grid.ScriptEngine.Common
{
public class Executor : MarshalByRefObject
{
// Private instance for each script
private IScript m_Script;
private Dictionary<string, MethodInfo> Events = new Dictionary<string, MethodInfo>();
private bool m_Running = true;
//private List<IScript> Scripts = new List<IScript>();
public Executor(IScript Script)
{
m_Script = Script;
}
// Object never expires
public override Object InitializeLifetimeService()
{
//Console.WriteLine("Executor: InitializeLifetimeService()");
// return null;
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
// lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
// lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return lease;
}
public AppDomain GetAppDomain()
{
return AppDomain.CurrentDomain;
}
public void ExecuteEvent(string FunctionName, object[] args)
{
// IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
// Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
//try
//{
if (m_Running == false)
{
// Script is inactive, do not execute!
return;
}
string EventName = m_Script.State() + "_event_" + FunctionName;
//type.InvokeMember(EventName, BindingFlags.InvokeMethod, null, m_Script, args);
//Console.WriteLine("ScriptEngine Executor.ExecuteEvent: \"" + EventName + "\"");
if (Events.ContainsKey(EventName) == false)
{
// Not found, create
Type type = m_Script.GetType();
try
{
MethodInfo mi = type.GetMethod(EventName);
Events.Add(EventName, mi);
}
catch
{
// Event name not found, cache it as not found
Events.Add(EventName, null);
}
}
// Get event
MethodInfo ev = null;
Events.TryGetValue(EventName, out ev);
if (ev == null) // No event by that name!
{
//Console.WriteLine("ScriptEngine Can not find any event named: \"" + EventName + "\"");
return;
}
// Found
//try
//{
// Invoke it
ev.Invoke(m_Script, args);
//}
//catch (Exception e)
//{
// // TODO: Send to correct place
// Console.WriteLine("ScriptEngine Exception attempting to executing script function: " + e.ToString());
//}
//}
//catch { }
}
public void StopScript()
{
m_Running = false;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.Common
{
public interface IScript
{
string State();
Executor Exec { get; }
}
}

View File

@ -0,0 +1,635 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.Common
{
public interface LSL_BuiltIn_Commands_Interface
{
string State();
double llSin(double f);
double llCos(double f);
double llTan(double f);
double llAtan2(double x, double y);
double llSqrt(double f);
double llPow(double fbase, double fexponent);
int llAbs(int i);
double llFabs(double f);
double llFrand(double mag);
int llFloor(double f);
int llCeil(double f);
int llRound(double f);
double llVecMag(LSL_Types.Vector3 v);
LSL_Types.Vector3 llVecNorm(LSL_Types.Vector3 v);
double llVecDist(LSL_Types.Vector3 a, LSL_Types.Vector3 b);
LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r);
LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v);
LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up);
LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r);
LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r);
LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r);
LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 start, LSL_Types.Vector3 end);
void llWhisper(int channelID, string text);
//void llSay(int channelID, string text);
void llSay(int channelID, string text);
void llShout(int channelID, string text);
int llListen(int channelID, string name, string ID, string msg);
void llListenControl(int number, int active);
void llListenRemove(int number);
void llSensor(string name, string id, int type, double range, double arc);
void llSensorRepeat(string name, string id, int type, double range, double arc, double rate);
void llSensorRemove();
string llDetectedName(int number);
string llDetectedKey(int number);
string llDetectedOwner(int number);
int llDetectedType(int number);
LSL_Types.Vector3 llDetectedPos(int number);
LSL_Types.Vector3 llDetectedVel(int number);
LSL_Types.Vector3 llDetectedGrab(int number);
LSL_Types.Quaternion llDetectedRot(int number);
int llDetectedGroup(int number);
int llDetectedLinkNumber(int number);
void llDie();
double llGround(LSL_Types.Vector3 offset);
double llCloud(LSL_Types.Vector3 offset);
LSL_Types.Vector3 llWind(LSL_Types.Vector3 offset);
void llSetStatus(int status, int value);
int llGetStatus(int status);
void llSetScale(LSL_Types.Vector3 scale);
LSL_Types.Vector3 llGetScale();
void llSetColor(LSL_Types.Vector3 color, int face);
double llGetAlpha(int face);
void llSetAlpha(double alpha, int face);
LSL_Types.Vector3 llGetColor(int face);
void llSetTexture(string texture, int face);
void llScaleTexture(double u, double v, int face);
void llOffsetTexture(double u, double v, int face);
void llRotateTexture(double rotation, int face);
string llGetTexture(int face);
void llSetPos(LSL_Types.Vector3 pos);
//wiki: vector llGetPos()
LSL_Types.Vector3 llGetPos();
//wiki: vector llGetLocalPos()
LSL_Types.Vector3 llGetLocalPos();
//wiki: llSetRot(rotation rot)
void llSetRot(LSL_Types.Quaternion rot);
//wiki: rotation llGetRot()
LSL_Types.Quaternion llGetRot();
//wiki: rotation llGetLocalRot()
LSL_Types.Quaternion llGetLocalRot();
//wiki: llSetForce(vector force, integer local)
void llSetForce(LSL_Types.Vector3 force, int local);
//wiki: vector llGetForce()
LSL_Types.Vector3 llGetForce();
//wiki: integer llTarget(vector position, double range)
int llTarget(LSL_Types.Vector3 position, double range);
//wiki: llTargetRemove(integer number)
void llTargetRemove(int number);
//wiki: integer llRotTarget(rotation rot, double error)
int llRotTarget(LSL_Types.Quaternion rot, double error);
//wiki: integer llRotTargetRemove(integer number)
void llRotTargetRemove(int number);
//wiki: llMoveToTarget(vector target, double tau)
void llMoveToTarget(LSL_Types.Vector3 target, double tau);
//wiki: llStopMoveToTarget()
void llStopMoveToTarget();
//wiki: llApplyImpulse(vector force, integer local)
void llApplyImpulse(LSL_Types.Vector3 force, int local);
//wiki: llapplyRotationalImpulse(vector force, integer local)
void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local);
//wiki: llSetTorque(vector torque, integer local)
void llSetTorque(LSL_Types.Vector3 torque, int local);
//wiki: vector llGetTorque()
LSL_Types.Vector3 llGetTorque();
//wiki: llSeForceAndTorque(vector force, vector torque, integer local)
void llSetForceAndTorque(LSL_Types.Vector3 force, LSL_Types.Vector3 torque, int local);
//wiki: vector llGetVel()
LSL_Types.Vector3 llGetVel();
//wiki: vector llGetAccel()
LSL_Types.Vector3 llGetAccel();
//wiki: vector llGetOmega()
LSL_Types.Vector3 llGetOmega();
//wiki: double llGetTimeOfDay()
double llGetTimeOfDay();
//wiki: double llGetWallclock()
double llGetWallclock();
//wiki: double llGetTime()
double llGetTime();
//wiki: llResetTime()
void llResetTime();
//wiki: double llGetAndResetTime()
double llGetAndResetTime();
//wiki (deprecated) llSound(string sound, double volume, integer queue, integer loop)
void llSound();
//wiki: llPlaySound(string sound, double volume)
void llPlaySound(string sound, double volume);
//wiki: llLoopSound(string sound, double volume)
void llLoopSound(string sound, double volume);
//wiki: llLoopSoundMaster(string sound, double volume)
void llLoopSoundMaster(string sound, double volume);
//wiki: llLoopSoundSlave(string sound, double volume)
void llLoopSoundSlave(string sound, double volume);
//wiki llPlaySoundSlave(string sound, double volume)
void llPlaySoundSlave(string sound, double volume);
//wiki: llTriggerSound(string sound, double volume)
void llTriggerSound(string sound, double volume);
//wiki: llStopSound()
void llStopSound();
//wiki: llPreloadSound(string sound)
void llPreloadSound(string sound);
//wiki: string llGetSubString(string src, integer start, integer end)
string llGetSubString(string src, int start, int end);
//wiki: string llDeleteSubString(string src, integer start, integer end)
string llDeleteSubString(string src, int start, int end);
//wiki string llInsertString(string dst, integer position, string src)
string llInsertString(string dst, int position, string src);
//wiki: string llToUpper(string source)
string llToUpper(string source);
//wiki: string llToLower(string source)
string llToLower(string source);
//wiki: integer llGiveMoney(key destination, integer amount)
int llGiveMoney(string destination, int amount);
//wiki: (deprecated)
void llMakeExplosion();
//wiki: (deprecated)
void llMakeFountain();
//wiki: (deprecated)
void llMakeSmoke();
//wiki: (deprecated)
void llMakeFire();
//wiki: llRezObject(string inventory, vector pos, vector rel, rotation rot, integer param)
void llRezObject(string inventory, LSL_Types.Vector3 pos, LSL_Types.Quaternion rot, int param);
//wiki: llLookAt(vector target, double strength, double damping)
void llLookAt(LSL_Types.Vector3 target, double strength, double damping);
//wiki: llStopLookAt()
void llStopLookAt();
//wiki: llSetTimerEvent(double sec)
void llSetTimerEvent(double sec);
//wiki: llSleep(double sec)
void llSleep(double sec);
//wiki: double llGetMass()
double llGetMass();
//wiki: llCollisionFilter(string name, key id, integer accept)
void llCollisionFilter(string name, string id, int accept);
//wiki: llTakeControls(integer controls, integer accept, integer pass_on)
void llTakeControls(int controls, int accept, int pass_on);
//wiki: llReleaseControls()
void llReleaseControls();
//wiki: llAttachToAvatar(integer attachment)
void llAttachToAvatar(int attachment);
//wiki: llDetachFromAvatar()
void llDetachFromAvatar();
//wiki: (deprecated) llTakeCamera()
void llTakeCamera();
//wiki: (deprecated) llReleaseCamera()
void llReleaseCamera();
//wiki: key llGetOwner()
string llGetOwner();
//wiki: llInstantMessage(key user, string message)
void llInstantMessage(string user, string message);
//wiki: llEmail(string address, string subject, string message)
void llEmail(string address, string subject, string message);
//wiki: llGetNextEmail(string address, string subject)
void llGetNextEmail(string address, string subject);
//wiki: key llGetKey()
string llGetKey();
//wiki: llSetBuoyancy(double buoyancy)
void llSetBuoyancy(double buoyancy);
//wiki: llSetHoverHeight(double height, integer water, double tau)
void llSetHoverHeight(double height, int water, double tau);
//wiki: llStopHover
void llStopHover();
//wiki: llMinEventDelay(double delay)
void llMinEventDelay(double delay);
//wiki: (deprecated) llSoundPreload()
void llSoundPreload();
//wiki: llRotLookAt(rotation target, double strength, double damping)
void llRotLookAt(LSL_Types.Quaternion target, double strength, double damping);
//wiki: integer llStringLength(string str)
int llStringLength(string str);
//wiki: llStartAnimation(string anim)
void llStartAnimation(string anim);
//wiki: llStopAnimation(string anim)
void llStopAnimation(string anim);
//wiki: (deprecated) llPointAt
void llPointAt();
//wiki: (deprecated) llStopPointAt
void llStopPointAt();
//wiki: llTargetOmega(vector axis, double spinrate, double gain)
void llTargetOmega(LSL_Types.Vector3 axis, double spinrate, double gain);
//wiki: integer llGetStartParameter()
int llGetStartParameter();
//wiki: llGodLikeRezObject(key inventory, vector pos)
void llGodLikeRezObject(string inventory, LSL_Types.Vector3 pos);
//wiki: llRequestPermissions(key agent, integer perm)
void llRequestPermissions(string agent, int perm);
//wiki: key llGetPermissionsKey()
string llGetPermissionsKey();
//wiki: integer llGetPermissions()
int llGetPermissions();
//wiki integer llGetLinkNumber()
int llGetLinkNumber();
//wiki: llSetLinkColor(integer linknumber, vector color, integer face)
void llSetLinkColor(int linknumber, LSL_Types.Vector3 color, int face);
//wiki: llCreateLink(key target, integer parent)
void llCreateLink(string target, int parent);
//wiki: llBreakLink(integer linknum)
void llBreakLink(int linknum);
//wiki: llBreakAllLinks()
void llBreakAllLinks();
//wiki: key llGetLinkKey(integer linknum)
string llGetLinkKey(int linknum);
//wiki: llGetLinkName(integer linknum)
void llGetLinkName(int linknum);
//wiki: integer llGetInventoryNumber(integer type)
int llGetInventoryNumber(int type);
//wiki: string llGetInventoryName(integer type, integer number)
string llGetInventoryName(int type, int number);
//wiki: llSetScriptState(string name, integer run)
void llSetScriptState(string name, int run);
//wiki: double llGetEnergy()
double llGetEnergy();
//wiki: llGiveInventory(key destination, string inventory)
void llGiveInventory(string destination, string inventory);
//wiki: llRemoveInventory(string item)
void llRemoveInventory(string item);
//wiki: llSetText(string text, vector color, double alpha)
void llSetText(string text, LSL_Types.Vector3 color, double alpha);
//wiki: double llWater(vector offset)
double llWater(LSL_Types.Vector3 offset);
//wiki: llPassTouches(integer pass)
void llPassTouches(int pass);
//wiki: key llRequestAgentData(key id, integer data)
string llRequestAgentData(string id, int data);
//wiki: key llRequestInventoryData(string name)
string llRequestInventoryData(string name);
//wiki: llSetDamage(double damage)
void llSetDamage(double damage);
//wiki: llTeleportAgentHome(key agent)
void llTeleportAgentHome(string agent);
//wiki: llModifyLand(integer action, integer brush)
void llModifyLand(int action, int brush);
//wiki: llCollisionSound(string impact_sound, double impact_volume)
void llCollisionSound(string impact_sound, double impact_volume);
//wiki: llCollisionSprite(string impact_sprite)
void llCollisionSprite(string impact_sprite);
//wiki: string llGetAnimation(key id)
string llGetAnimation(string id);
//wiki: llResetScript()
void llResetScript();
//wiki: llMessageLinked(integer linknum, integer num, string str, key id)
void llMessageLinked(int linknum, int num, string str, string id);
//wiki: llPushObject(key target, vector impulse, vector ang_impulse, integer local)
void llPushObject(string target, LSL_Types.Vector3 impulse, LSL_Types.Vector3 ang_impulse, int local);
//wiki: llPassCollisions(integer pass)
void llPassCollisions(int pass);
//wiki: string llGetScriptName()
string llGetScriptName();
//wiki: integer llGetNumberOfSides()
int llGetNumberOfSides();
//wiki: rotation llAxisAngle2Rot(vector axis, double angle)
LSL_Types.Quaternion llAxisAngle2Rot(LSL_Types.Vector3 axis, double angle);
//wiki: vector llRot2Axis(rotation rot)
LSL_Types.Vector3 llRot2Axis(LSL_Types.Quaternion rot);
void llRot2Angle();
//wiki: double llAcos(double val)
double llAcos(double val);
//wiki: double llAsin(double val)
double llAsin(double val);
//wiki: double llAngleBetween(rotation a, rotation b)
double llAngleBetween(LSL_Types.Quaternion a, LSL_Types.Quaternion b);
//wiki: string llGetInventoryKey(string name)
string llGetInventoryKey(string name);
//wiki: llAllowInventoryDrop(integer add)
void llAllowInventoryDrop(int add);
//wiki: vector llGetSunDirection()
LSL_Types.Vector3 llGetSunDirection();
//wiki: vector llGetTextureOffset(integer face)
LSL_Types.Vector3 llGetTextureOffset(int face);
//wiki: vector llGetTextureScale(integer side)
LSL_Types.Vector3 llGetTextureScale(int side);
//wiki: double llGetTextureRot(integer side)
double llGetTextureRot(int side);
//wiki: integer llSubStringIndex(string source, string pattern)
int llSubStringIndex(string source, string pattern);
//wiki: key llGetOwnerKey(key id)
string llGetOwnerKey(string id);
//wiki: vector llGetCenterOfMass()
LSL_Types.Vector3 llGetCenterOfMass();
//wiki: list llListSort(list src, integer stride, integer ascending)
List<string> llListSort(List<string> src, int stride, int ascending);
//integer llGetListLength(list src)
int llGetListLength(List<string> src);
//wiki: integer llList2Integer(list src, integer index)
int llList2Integer(List<string> src, int index);
//wiki: double llList2double(list src, integer index)
double llList2double(List<string> src, int index);
//wiki: string llList2String(list src, integer index)
string llList2String(List<string> src, int index);
//wiki: key llList2Key(list src, integer index)
string llList2Key(List<string> src, int index);
//wiki: vector llList2Vector(list src, integer index)
LSL_Types.Vector3 llList2Vector(List<string> src, int index);
//wiki rotation llList2Rot(list src, integer index)
LSL_Types.Quaternion llList2Rot(List<string> src, int index);
//wiki: list llList2List(list src, integer start, integer end)
List<string> llList2List(List<string> src, int start, int end);
//wiki: llDeleteSubList(list src, integer start, integer end)
List<string> llDeleteSubList(List<string> src, int start, int end);
//wiki: integer llGetListEntryType( list src, integer index )
int llGetListEntryType(List<string> src, int index);
//wiki: string llList2CSV( list src )
string llList2CSV(List<string> src);
//wiki: list llCSV2List( string src )
List<string> llCSV2List(string src);
//wiki: list llListRandomize( list src, integer stride )
List<string> llListRandomize(List<string> src, int stride);
//wiki: list llList2ListStrided( list src, integer start, integer end, integer stride )
List<string> llList2ListStrided(List<string> src, int start, int end, int stride);
//wiki: vector llGetRegionCorner( )
LSL_Types.Vector3 llGetRegionCorner();
//wiki: list llListInsertList( list dest, list src, integer start )
List<string> llListInsertList(List<string> dest, List<string> src, int start);
//wiki: integer llListFindList( list src, list test )
int llListFindList(List<string> src, List<string> test);
//wiki: string llGetObjectName()
string llGetObjectName();
//wiki: llSetObjectName(string name)
void llSetObjectName(string name);
//wiki: string llGetDate()
string llGetDate();
//wiki: integer llEdgeOfWorld(vector pos, vector dir)
int llEdgeOfWorld(LSL_Types.Vector3 pos, LSL_Types.Vector3 dir);
//wiki: integer llGetAgentInfo(key id)
int llGetAgentInfo(string id);
//wiki: llAdjustSoundVolume(double volume)
void llAdjustSoundVolume(double volume);
//wiki: llSetSoundQueueing(integer queue)
void llSetSoundQueueing(int queue);
//wiki: llSetSoundRadius(double radius)
void llSetSoundRadius(double radius);
//wiki: string llKey2Name(key id)
string llKey2Name(string id);
//wiki: llSetTextureAnim(integer mode, integer face, integer sizex, integer sizey, double start, double length, double rate)
void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate);
//wiki: llTriggerSoundLimited(string sound, double volume, vector top_north_east, vector bottom_south_west)
void llTriggerSoundLimited(string sound, double volume, LSL_Types.Vector3 top_north_east, LSL_Types.Vector3 bottom_south_west);
//wiki: llEjectFromLand(key pest)
void llEjectFromLand(string pest);
void llParseString2List();
//wiki: integer llOverMyLand(key id)
int llOverMyLand(string id);
//wiki: key llGetLandOwnerAt(vector pos)
string llGetLandOwnerAt(LSL_Types.Vector3 pos);
//wiki: key llGetNotecardLine(string name, integer line)
string llGetNotecardLine(string name, int line);
//wiki: vector llGetAgentSize(key id)
LSL_Types.Vector3 llGetAgentSize(string id);
//wiki: integer llSameGroup(key agent)
int llSameGroup(string agent);
//wiki: llUnSit(key id)
void llUnSit(string id);
//wiki: vector llGroundSlope(vector offset)
LSL_Types.Vector3 llGroundSlope(LSL_Types.Vector3 offset);
//wiki: vector llGroundNormal(vector offset)
LSL_Types.Vector3 llGroundNormal(LSL_Types.Vector3 offset);
//wiki: vector llGroundContour(vector offset)
LSL_Types.Vector3 llGroundContour(LSL_Types.Vector3 offset);
//wiki: integer llGetAttached()
int llGetAttached();
//wiki: integer llGetFreeMemory()
int llGetFreeMemory();
//wiki: string llGetRegionName()
string llGetRegionName();
//wiki: double llGetRegionTimeDilation()
double llGetRegionTimeDilation();
//wiki: double llGetRegionFPS()
double llGetRegionFPS();
//wiki: llParticleSystem(List<Object> rules
void llParticleSystem(List<Object> rules);
//wiki: llGroundRepel(double height, integer water, double tau)
void llGroundRepel(double height, int water, double tau);
void llGiveInventoryList();
//wiki: llSetVehicleType(integer type)
void llSetVehicleType(int type);
//wiki: llSetVehicledoubleParam(integer param, double value)
void llSetVehicledoubleParam(int param, double value);
//wiki: llSetVehicleVectorParam(integer param, vector vec)
void llSetVehicleVectorParam(int param, LSL_Types.Vector3 vec);
//wiki: llSetVehicleRotationParam(integer param, rotation rot)
void llSetVehicleRotationParam(int param, LSL_Types.Quaternion rot);
//wiki: llSetVehicleFlags(integer flags)
void llSetVehicleFlags(int flags);
//wiki: llRemoveVehicleFlags(integer flags)
void llRemoveVehicleFlags(int flags);
//wiki: llSitTarget(vector offset, rotation rot)
void llSitTarget(LSL_Types.Vector3 offset, LSL_Types.Quaternion rot);
//wiki key llAvatarOnSitTarget()
string llAvatarOnSitTarget();
//wiki: llAddToLandPassList(key avatar, double hours)
void llAddToLandPassList(string avatar, double hours);
//wiki: llSetTouchText(string text)
void llSetTouchText(string text);
//wiki: llSetSitText(string text)
void llSetSitText(string text);
//wiki: llSetCameraEyeOffset(vector offset)
void llSetCameraEyeOffset(LSL_Types.Vector3 offset);
//wiki: llSeteCameraAtOffset(vector offset)
void llSetCameraAtOffset(LSL_Types.Vector3 offset);
void llDumpList2String();
//wiki: integer llScriptDanger(vector pos)
void llScriptDanger(LSL_Types.Vector3 pos);
//wiki: llDialog( key avatar, string message, list buttons, integer chat_channel )
void llDialog(string avatar, string message, List<string> buttons, int chat_channel);
//wiki: llVolumeDetect(integer detect)
void llVolumeDetect(int detect);
//wiki: llResetOtherScript(string name)
void llResetOtherScript(string name);
//wiki: integer llGetScriptState(string name)
int llGetScriptState(string name);
//wiki: (deprecated)
void llRemoteLoadScript();
//wiki: llSetRemoteScriptAccessPin(integer pin)
void llSetRemoteScriptAccessPin(int pin);
//wiki: llRemoteLoadScriptPin(key target, string name, integer pin, integer running, integer start_param)
void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param);
//wiki: llOpenRemoteDataChannel()
void llOpenRemoteDataChannel();
//wiki: key llSendRemoteData(key channel, string dest, integer idata, string sdata)
string llSendRemoteData(string channel, string dest, int idata, string sdata);
//wiki: llRemoteDataReply(key channel, key message_id, string sdata, integer idata)
void llRemoteDataReply(string channel, string message_id, string sdata, int idata);
//wiki: llCloseRemoteDataChannel(key channel)
void llCloseRemoteDataChannel(string channel);
//wiki: string llMD5String(string src, integer nonce)
string llMD5String(string src, int nonce);
//wiki: llSetPrimitiveParams( list rules )
void llSetPrimitiveParams(List<string> rules);
//wiki: string llStringToBase64(string str)
string llStringToBase64(string str);
//wiki: string llBase64ToString(string str)
string llBase64ToString(string str);
//wiki: (deprecated)
void llXorBase64Strings();
//wiki: llRemoteDataSetRegion()
void llRemoteDataSetRegion();
//wiki: double llLog10(double val)
double llLog10(double val);
//wiki: double llLog(double val)
double llLog(double val);
//wiki: list llGetAnimationList( key id )
List<string> llGetAnimationList(string id);
//wiki: llSetParcelMusicURL(string url)
void llSetParcelMusicURL(string url);
//wiki: vector llGetRootPosition()
LSL_Types.Vector3 llGetRootPosition();
//wiki: rotation llGetRootRotation()
LSL_Types.Quaternion llGetRootRotation();
//wiki: string llGetObjectDesc()
string llGetObjectDesc();
//wiki: llSetObjectDesc(string desc)
void llSetObjectDesc(string desc);
//wiki: key llGetCreator()
string llGetCreator();
//wiki: string llGetTimestamp()
string llGetTimestamp();
//wiki: llSetLinkAlpha(integer linknumber, double alpha, integer face)
void llSetLinkAlpha(int linknumber, double alpha, int face);
//wiki: integer llGetNumberOfPrims()
int llGetNumberOfPrims();
//wiki: key llGetNumberOfNotecardLines(string name)
string llGetNumberOfNotecardLines(string name);
//wiki: list llGetBoundingBox( key object )
List<string> llGetBoundingBox(string obj);
//wiki: vector llGetGeometricCenter()
LSL_Types.Vector3 llGetGeometricCenter();
void llGetPrimitiveParams();
//wiki: string llIntegerToBase64(integer number)
string llIntegerToBase64(int number);
//wiki integer llBase64ToInteger(string str)
int llBase64ToInteger(string str);
//wiki: double llGetGMTclock()
double llGetGMTclock();
//wiki: string llGetSimulatorHostname()
string llGetSimulatorHostname();
//llSetLocalRot(rotation rot)
void llSetLocalRot(LSL_Types.Quaternion rot);
//wiki: list llParseStringKeepNulls( string src, list separators, list spacers )
List<string> llParseStringKeepNulls(string src, List<string> seperators, List<string> spacers);
//wiki: llRezAtRoot(string inventory, vector position, vector velocity, rotation rot, integer param)
void llRezAtRoot(string inventory, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity, LSL_Types.Quaternion rot, int param);
//wiki: integer llGetObjectPermMask(integer mask)
int llGetObjectPermMask(int mask);
//wiki: llSetObjectPermMask(integer mask, integer value)
void llSetObjectPermMask(int mask, int value);
//wiki integer llGetInventoryPermMask(string item, integer mask)
void llGetInventoryPermMask(string item, int mask);
//wiki: llSetInventoryPermMask(string item, integer mask, integer value)
void llSetInventoryPermMask(string item, int mask, int value);
//wiki: key llGetInventoryCreator(string item)
string llGetInventoryCreator(string item);
//wiki: llOwnerSay(string msg)
void llOwnerSay(string msg);
//wiki: key llRequestSimulatorData(string simulator, integer data)
void llRequestSimulatorData(string simulator, int data);
//wiki: llForceMouselook(integer mouselook)
void llForceMouselook(int mouselook);
//wiki: double llGetObjectMass(key id)
double llGetObjectMass(string id);
void llListReplaceList();
//wiki: llLoadURL(key avatar_id, string message, string url)
void llLoadURL(string avatar_id, string message, string url);
//wiki: llParcelMediaCommandList( list commandList )
void llParcelMediaCommandList(List<string> commandList);
void llParcelMediaQuery();
//wiki integer llModPow(integer a, integer b, integer c)
int llModPow(int a, int b, int c);
//wiki: integer llGetInventoryType(string name)
int llGetInventoryType(string name);
//wiki: llSetPayPrice( integer price, list quick_pay_buttons )
void llSetPayPrice(int price, List<string> quick_pay_buttons);
//wiki: vector llGetCameraPos()
LSL_Types.Vector3 llGetCameraPos();
//wiki rotation llGetCameraRot()
LSL_Types.Quaternion llGetCameraRot();
//wiki: (deprecated)
void llSetPrimURL();
//wiki: (deprecated)
void llRefreshPrimURL();
//wiki: string llEscapeURL(string url)
string llEscapeURL(string url);
//wiki: string llUnescapeURL(string url)
string llUnescapeURL(string url);
//wiki: llMapDestination(string simname, vector pos, vector look_at)
void llMapDestination(string simname, LSL_Types.Vector3 pos, LSL_Types.Vector3 look_at);
//wiki: llAddToLandBanList(key avatar, double hours)
void llAddToLandBanList(string avatar, double hours);
//wiki: llRemoveFromLandPassList(key avatar)
void llRemoveFromLandPassList(string avatar);
//wiki: llRemoveFromLandBanList(key avatar)
void llRemoveFromLandBanList(string avatar);
//wiki: llSetCameraParams( list rules )
void llSetCameraParams(List<string> rules);
//wiki: llClearCameraParams()
void llClearCameraParams();
//wiki: double llListStatistics( integer operation, list src )
double llListStatistics(int operation, List<string> src);
//wiki: integer llGetUnixTime()
int llGetUnixTime();
//wiki: integer llGetParcelFlags(vector pos)
int llGetParcelFlags(LSL_Types.Vector3 pos);
//wiki: integer llGetRegionFlags()
int llGetRegionFlags();
//wiki: string llXorBase64StringsCorrect(string str1, string str2)
string llXorBase64StringsCorrect(string str1, string str2);
void llHTTPRequest(string url, List<string> parameters, string body);
//wiki: llResetLandBanList()
void llResetLandBanList();
//wiki: llResetLandPassList()
void llResetLandPassList();
//wiki integer llGetParcelPrimCount(vector pos, integer category, integer sim_wide)
int llGetParcelPrimCount(LSL_Types.Vector3 pos, int category, int sim_wide);
//wiki: list llGetParcelPrimOwners( vector pos )
List<string> llGetParcelPrimOwners(LSL_Types.Vector3 pos);
//wiki: integer llGetObjectPrimCount(key object_id)
int llGetObjectPrimCount(string object_id);
//wiki: integer llGetParcelMaxPrims( vector pos, integer sim_wide )
int llGetParcelMaxPrims(LSL_Types.Vector3 pos, int sim_wide);
//wiki list llGetParcelDetails(vector pos, list params)
List<string> llGetParcelDetails(LSL_Types.Vector3 pos, List<string> param);
//OpenSim functions
string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams, int timer);
}
}

View File

@ -0,0 +1,53 @@
using System;
namespace OpenSim.Grid.ScriptEngine.Common
{
[Serializable]
public class LSL_Types
{
[Serializable]
public struct Vector3
{
public double X;
public double Y;
public double Z;
public Vector3(Vector3 vector)
{
X = (float)vector.X;
Y = (float)vector.Y;
Z = (float)vector.Z;
}
public Vector3(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
}
[Serializable]
public struct Quaternion
{
public double X;
public double Y;
public double Z;
public double R;
public Quaternion(Quaternion Quat)
{
X = (float)Quat.X;
Y = (float)Quat.Y;
Z = (float)Quat.Z;
R = (float)Quat.R;
}
public Quaternion(double x, double y, double z, double r)
{
X = x;
Y = y;
Z = z;
R = r;
}
}
}
}

View File

@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenSim.Grid.ScriptEngine.Common")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenSim.Grid.ScriptEngine.Common")]
[assembly: AssemblyCopyright("Copyright © 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0bf07c53-ae51-487f-a907-e9b30c251602")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,200 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Threading;
using System.Runtime.Remoting;
using System.IO;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Scenes.Scripting;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL;
using OpenSim.Region.ScriptEngine.Common;
using libsecondlife;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
public class AppDomainManager
{
private int maxScriptsPerAppDomain = 1;
/// <summary>
/// Internal list of all AppDomains
/// </summary>
private List<AppDomainStructure> appDomains = new List<AppDomainStructure>();
/// <summary>
/// Structure to keep track of data around AppDomain
/// </summary>
private class AppDomainStructure
{
/// <summary>
/// The AppDomain itself
/// </summary>
public AppDomain CurrentAppDomain;
/// <summary>
/// Number of scripts loaded into AppDomain
/// </summary>
public int ScriptsLoaded;
/// <summary>
/// Number of dead scripts
/// </summary>
public int ScriptsWaitingUnload;
}
/// <summary>
/// Current AppDomain
/// </summary>
private AppDomainStructure currentAD;
private object getLock = new object(); // Mutex
private object freeLock = new object(); // Mutex
//private ScriptEngine m_scriptEngine;
//public AppDomainManager(ScriptEngine scriptEngine)
public AppDomainManager()
{
//m_scriptEngine = scriptEngine;
}
/// <summary>
/// Find a free AppDomain, creating one if necessary
/// </summary>
/// <returns>Free AppDomain</returns>
private AppDomainStructure GetFreeAppDomain()
{
Console.WriteLine("Finding free AppDomain");
lock (getLock)
{
// Current full?
if (currentAD != null && currentAD.ScriptsLoaded >= maxScriptsPerAppDomain)
{
// Add it to AppDomains list and empty current
appDomains.Add(currentAD);
currentAD = null;
}
// No current
if (currentAD == null)
{
// Create a new current AppDomain
currentAD = new AppDomainStructure();
currentAD.CurrentAppDomain = PrepareNewAppDomain();
}
Console.WriteLine("Scripts loaded in this Appdomain: " + currentAD.ScriptsLoaded);
return currentAD;
} // lock
}
private int AppDomainNameCount;
/// <summary>
/// Create and prepare a new AppDomain for scripts
/// </summary>
/// <returns>The new AppDomain</returns>
private AppDomain PrepareNewAppDomain()
{
// Create and prepare a new AppDomain
AppDomainNameCount++;
// TODO: Currently security match current appdomain
// Construct and initialize settings for a second AppDomain.
AppDomainSetup ads = new AppDomainSetup();
ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
ads.DisallowBindingRedirects = false;
ads.DisallowCodeDownload = true;
ads.LoaderOptimization = LoaderOptimization.MultiDomain; // Sounds good ;)
ads.ShadowCopyFiles = "true"; // Enabled shadowing
ads.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + AppDomainNameCount, null, ads);
Console.WriteLine("Loading: " + AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll").ToString());
AD.Load(AssemblyName.GetAssemblyName("OpenSim.Region.ScriptEngine.Common.dll"));
// Return the new AppDomain
return AD;
}
/// <summary>
/// Unload appdomains that are full and have only dead scripts
/// </summary>
private void UnloadAppDomains()
{
lock (freeLock)
{
// Go through all
foreach (AppDomainStructure ads in new System.Collections.ArrayList(appDomains))
{
// Don't process current AppDomain
if (ads.CurrentAppDomain != currentAD.CurrentAppDomain)
{
// Not current AppDomain
// Is number of unloaded bigger or equal to number of loaded?
if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload)
{
Console.WriteLine("Found empty AppDomain, unloading");
// Remove from internal list
appDomains.Remove(ads);
#if DEBUG
long m = GC.GetTotalMemory(true);
#endif
// Unload
AppDomain.Unload(ads.CurrentAppDomain);
#if DEBUG
Console.WriteLine("AppDomain unload freed " + (m - GC.GetTotalMemory(true)) + " bytes of memory");
#endif
}
}
} // foreach
} // lock
}
public OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass LoadScript(string FileName)
{
// Find next available AppDomain to put it in
AppDomainStructure FreeAppDomain = GetFreeAppDomain();
Console.WriteLine("Loading into AppDomain: " + FileName);
LSL_BaseClass mbrt = (LSL_BaseClass)FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap(FileName, "SecondLife.Script");
//Console.WriteLine("ScriptEngine AppDomainManager: is proxy={0}", RemotingServices.IsTransparentProxy(mbrt));
FreeAppDomain.ScriptsLoaded++;
return mbrt;
}
/// <summary>
/// Increase "dead script" counter for an AppDomain
/// </summary>
/// <param name="ad"></param>
//[Obsolete("Needs fixing, needs a real purpose in life!!!")]
public void StopScript(AppDomain ad)
{
lock (freeLock)
{
Console.WriteLine("Stopping script in AppDomain");
// Check if it is current AppDomain
if (currentAD.CurrentAppDomain == ad)
{
// Yes - increase
currentAD.ScriptsWaitingUnload++;
return;
}
// Lopp through all AppDomains
foreach (AppDomainStructure ads in new System.Collections.ArrayList(appDomains))
{
if (ads.CurrentAppDomain == ad)
{
// Found it
ads.ScriptsWaitingUnload++;
break;
}
} // foreach
} // lock
UnloadAppDomains(); // Outsite lock, has its own GetLock
}
}
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
public static class Common
{
static public bool debug = true;
static public ScriptEngine mySE;
//public delegate void SendToDebugEventDelegate(string Message);
//public delegate void SendToLogEventDelegate(string Message);
//static public event SendToDebugEventDelegate SendToDebugEvent;
//static public event SendToLogEventDelegate SendToLogEvent;
static public void SendToDebug(string Message)
{
//if (Debug == true)
mySE.Log.Verbose("ScriptEngine", "Debug: " + Message);
//SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
}
static public void SendToLog(string Message)
{
//if (Debug == true)
mySE.Log.Verbose("ScriptEngine", "LOG: " + Message);
//SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
}
}
}

View File

@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL
{
public class Compiler
{
private LSL2CSConverter LSL_Converter = new LSL2CSConverter();
private CSharpCodeProvider codeProvider = new CSharpCodeProvider();
private static UInt64 scriptCompileCounter = 0;
//private ICodeCompiler icc = codeProvider.CreateCompiler();
public string CompileFromFile(string LSOFileName)
{
switch (System.IO.Path.GetExtension(LSOFileName).ToLower())
{
case ".txt":
case ".lsl":
Common.SendToDebug("Source code is LSL, converting to CS");
return CompileFromLSLText(File.ReadAllText(LSOFileName));
case ".cs":
Common.SendToDebug("Source code is CS");
return CompileFromCSText(File.ReadAllText(LSOFileName));
default:
throw new Exception("Unknown script type.");
}
}
/// <summary>
/// Converts script from LSL to CS and calls CompileFromCSText
/// </summary>
/// <param name="Script">LSL script</param>
/// <returns>Filename to .dll assembly</returns>
public string CompileFromLSLText(string Script)
{
if (Script.Substring(0, 4).ToLower() == "//c#")
{
return CompileFromCSText( Script );
}
else
{
return CompileFromCSText(LSL_Converter.Convert(Script));
}
}
/// <summary>
/// Compile CS script to .Net assembly (.dll)
/// </summary>
/// <param name="Script">CS script</param>
/// <returns>Filename to .dll assembly</returns>
public string CompileFromCSText(string Script)
{
// Output assembly name
scriptCompileCounter++;
string OutFile = Path.Combine("ScriptEngines", "Script_" + scriptCompileCounter + ".dll");
try
{
System.IO.File.Delete(OutFile);
}
catch (Exception e)
{
Console.WriteLine("Exception attempting to delete old compiled script: " + e.ToString());
}
//string OutFile = Path.Combine("ScriptEngines", "SecondLife.Script.dll");
// DEBUG - write source to disk
try
{
File.WriteAllText(Path.Combine("ScriptEngines", "debug_" + Path.GetFileNameWithoutExtension(OutFile) + ".cs"), Script);
}
catch { }
// Do actual compile
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.IncludeDebugInformation = true;
// Add all available assemblies
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
//Console.WriteLine("Adding assembly: " + asm.Location);
//parameters.ReferencedAssemblies.Add(asm.Location);
}
string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
string rootPathSE = Path.GetDirectoryName(this.GetType().Assembly.Location);
//Console.WriteLine("Assembly location: " + rootPath);
parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, "OpenSim.Region.ScriptEngine.Common.dll"));
parameters.ReferencedAssemblies.Add(Path.Combine(rootPathSE, "OpenSim.Grid.ScriptEngine.DotNetEngine.dll"));
//parameters.ReferencedAssemblies.Add("OpenSim.Region.Environment");
parameters.GenerateExecutable = false;
parameters.OutputAssembly = OutFile;
parameters.IncludeDebugInformation = false;
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Script);
// Go through errors
// TODO: Return errors to user somehow
if (results.Errors.Count > 0)
{
string errtext = "";
foreach (CompilerError CompErr in results.Errors)
{
errtext += "Line number " + (CompErr.Line - 1) +
", Error Number: " + CompErr.ErrorNumber +
", '" + CompErr.ErrorText + "'\r\n";
}
throw new Exception(errtext);
}
return OutFile;
}
}
}

View File

@ -0,0 +1,266 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL
{
public class LSL2CSConverter
{
//private Regex rnw = new Regex(@"[a-zA-Z0-9_\-]", RegexOptions.Compiled);
private Dictionary<string, string> dataTypes = new Dictionary<string, string>();
private Dictionary<string, string> quotes = new Dictionary<string, string>();
public LSL2CSConverter()
{
// Only the types we need to convert
dataTypes.Add("void", "void");
dataTypes.Add("integer", "int");
dataTypes.Add("float", "double");
dataTypes.Add("string", "string");
dataTypes.Add("key", "string");
dataTypes.Add("vector", "LSL_Types.Vector3");
dataTypes.Add("rotation", "LSL_Types.Quaternion");
dataTypes.Add("list", "list");
dataTypes.Add("null", "null");
}
public string Convert(string Script)
{
string Return = "";
Script = " \r\n" + Script;
//
// Prepare script for processing
//
// Clean up linebreaks
Script = Regex.Replace(Script, @"\r\n", "\n");
Script = Regex.Replace(Script, @"\n", "\r\n");
// QUOTE REPLACEMENT
// temporarily replace quotes so we can work our magic on the script without
// always considering if we are inside our outside ""'s
string _Script = "";
string C;
bool in_quote = false;
bool quote_replaced = false;
string quote_replacement_string = "Q_U_O_T_E_REPLACEMENT_";
string quote = "";
bool last_was_escape = false;
int quote_replaced_count = 0;
for (int p = 0; p < Script.Length; p++)
{
C = Script.Substring(p, 1);
while (true)
{
// found " and last was not \ so this is not an escaped \"
if (C == "\"" && last_was_escape == false)
{
// Toggle inside/outside quote
in_quote = !in_quote;
if (in_quote)
{
quote_replaced_count++;
}
else
{
if (quote == "")
{
// We didn't replace quote, probably because of empty string?
_Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]);
}
// We just left a quote
quotes.Add(quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]), quote);
quote = "";
}
break;
}
if (!in_quote)
{
// We are not inside a quote
quote_replaced = false;
}
else
{
// We are inside a quote
if (!quote_replaced)
{
// Replace quote
_Script += quote_replacement_string + quote_replaced_count.ToString().PadLeft(5, "0".ToCharArray()[0]);
quote_replaced = true;
}
quote += C;
break;
}
_Script += C;
break;
}
last_was_escape = false;
if (C == @"\")
{
last_was_escape = true;
}
}
Script = _Script;
//
// END OF QUOTE REPLACEMENT
//
//
// PROCESS STATES
// Remove state definitions and add state names to start of each event within state
//
int ilevel = 0;
int lastlevel = 0;
string ret = "";
string cache = "";
bool in_state = false;
string current_statename = "";
for (int p = 0; p < Script.Length; p++)
{
C = Script.Substring(p, 1);
while (true)
{
// inc / dec level
if (C == @"{")
ilevel++;
if (C == @"}")
ilevel--;
if (ilevel < 0)
ilevel = 0;
cache += C;
// if level == 0, add to return
if (ilevel == 1 && lastlevel == 0)
{
// 0 => 1: Get last
Match m = Regex.Match(cache, @"(?![a-zA-Z_]+)\s*([a-zA-Z_]+)[^a-zA-Z_\(\)]*{", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
in_state = false;
if (m.Success)
{
// Go back to level 0, this is not a state
in_state = true;
current_statename = m.Groups[1].Captures[0].Value;
//Console.WriteLine("Current statename: " + current_statename);
cache = Regex.Replace(cache, @"(?<s1>(?![a-zA-Z_]+)\s*)" + @"([a-zA-Z_]+)(?<s2>[^a-zA-Z_\(\)]*){", "${s1}${s2}", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
}
ret += cache;
cache = "";
}
if (ilevel == 0 && lastlevel == 1)
{
// 1 => 0: Remove last }
if (in_state == true)
{
cache = cache.Remove(cache.Length - 1, 1);
//cache = Regex.Replace(cache, "}$", "", RegexOptions.Multiline | RegexOptions.Singleline);
//Replace function names
// void dataserver(key query_id, string data) {
//cache = Regex.Replace(cache, @"([^a-zA-Z_]\s*)((?!if|switch|for)[a-zA-Z_]+\s*\([^\)]*\)[^{]*{)", "$1" + "<STATE>" + "$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
//Console.WriteLine("Replacing using statename: " + current_statename);
cache = Regex.Replace(cache, @"^(\s*)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1public " + current_statename + "_event_$2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
}
ret += cache;
cache = "";
in_state = true;
current_statename = "";
}
break;
}
lastlevel = ilevel;
}
ret += cache;
cache = "";
Script = ret;
ret = "";
foreach (string key in dataTypes.Keys)
{
string val;
dataTypes.TryGetValue(key, out val);
// Replace CAST - (integer) with (int)
Script = Regex.Replace(Script, @"\(" + key + @"\)", @"(" + val + ")", RegexOptions.Compiled | RegexOptions.Multiline);
// Replace return types and function variables - integer a() and f(integer a, integer a)
Script = Regex.Replace(Script, @"(^|;|}|[\(,])(\s*)" + key + @"(\s*)", @"$1$2" + val + "$3", RegexOptions.Compiled | RegexOptions.Multiline);
}
// Add "void" in front of functions that needs it
Script = Regex.Replace(Script, @"^(\s*public\s+)((?!(if|switch|for)[^a-zA-Z0-9_])[a-zA-Z0-9_]*\s*\([^\)]*\)[^;]*\{)", @"$1void $2", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace <x,y,z> and <x,y,z,r>
Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Quaternion($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
Script = Regex.Replace(Script, @"<([^,>]*,[^,>]*,[^,>]*)>", @"new LSL_Types.Vector3($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace List []'s
Script = Regex.Replace(Script, @"\[([^\]]*)\]", @"List.Parse($1)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// Replace (string) to .ToString() //
Script = Regex.Replace(Script, @"\(string\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.ToString()", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
Script = Regex.Replace(Script, @"\((float|int)\)\s*([a-zA-Z0-9_]+(\s*\([^\)]*\))?)", @"$1.Parse($2)", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);
// REPLACE BACK QUOTES
foreach (string key in quotes.Keys)
{
string val;
quotes.TryGetValue(key, out val);
Script = Script.Replace(key, "\"" + val + "\"");
}
// Add namespace, class name and inheritance
Return = "" +
"using OpenSim.Region.ScriptEngine.Common;";
//"using System; " +
//"using System.Collections.Generic; " +
//"using System.Text; " +
//"using OpenSim.Region.ScriptEngine.Common; " +
//"using integer = System.Int32; " +
//"using key = System.String; ";
//// Make a Using out of DataTypes
//// Using integer = System.Int32;
//string _val;
//foreach (string key in DataTypes.Keys)
//{
// DataTypes.TryGetValue(key, out _val);
// if (key != _val)
// {
// Return += "using " + key + " = " + _val + "; ";
// }
//}
Return += "" +
"namespace SecondLife { ";
Return += "" +
//"[Serializable] " +
"public class Script : OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass { ";
Return += @"public Script() { } ";
Return += Script;
Return += "} }\r\n";
return Return;
}
}
}

View File

@ -0,0 +1,784 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler;
using OpenSim.Region.ScriptEngine.Common;
using System.Threading;
using System.Reflection;
using System.Runtime.Remoting.Lifetime;
using integer = System.Int32;
using key = System.String;
using vector = OpenSim.Region.ScriptEngine.Common.LSL_Types.Vector3;
using rotation = OpenSim.Region.ScriptEngine.Common.LSL_Types.Quaternion;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL
{
//[Serializable]
public class LSL_BaseClass : MarshalByRefObject, LSL_BuiltIn_Commands_Interface, IScript
{
// Object never expires
public override Object InitializeLifetimeService()
{
//Console.WriteLine("LSL_BaseClass: InitializeLifetimeService()");
// return null;
ILease lease = (ILease)base.InitializeLifetimeService();
if (lease.CurrentState == LeaseState.Initial)
{
lease.InitialLeaseTime = TimeSpan.Zero; // TimeSpan.FromMinutes(1);
//lease.SponsorshipTimeout = TimeSpan.FromMinutes(2);
//lease.RenewOnCallTime = TimeSpan.FromSeconds(2);
}
return lease;
}
private Executor m_Exec;
public Executor Exec
{
get
{
if (m_Exec == null)
m_Exec = new Executor(this);
return m_Exec;
}
}
public LSL_BuiltIn_Commands_Interface m_LSL_Functions;
public string SourceCode = "";
public LSL_BaseClass()
{
}
public string State()
{
return m_LSL_Functions.State();
}
public void Start(LSL_BuiltIn_Commands_Interface LSL_Functions)
{
m_LSL_Functions = LSL_Functions;
//MainLog.Instance.Notice("ScriptEngine", "LSL_BaseClass.Start() called.");
// Get this AppDomain's settings and display some of them.
AppDomainSetup ads = AppDomain.CurrentDomain.SetupInformation;
Console.WriteLine("AppName={0}, AppBase={1}, ConfigFile={2}",
ads.ApplicationName,
ads.ApplicationBase,
ads.ConfigurationFile
);
// Display the name of the calling AppDomain and the name
// of the second domain.
// NOTE: The application's thread has transitioned between
// AppDomains.
Console.WriteLine("Calling to '{0}'.",
Thread.GetDomain().FriendlyName
);
return;
}
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
// They are only forwarders to LSL_BuiltIn_Commands.cs
//
public double llSin(double f) { return m_LSL_Functions.llSin(f); }
public double llCos(double f) { return m_LSL_Functions.llCos(f); }
public double llTan(double f) { return m_LSL_Functions.llTan(f); }
public double llAtan2(double x, double y) { return m_LSL_Functions.llAtan2(x, y); }
public double llSqrt(double f) { return m_LSL_Functions.llSqrt(f); }
public double llPow(double fbase, double fexponent) { return m_LSL_Functions.llPow(fbase, fexponent); }
public int llAbs(int i) { return m_LSL_Functions.llAbs(i); }
public double llFabs(double f) { return m_LSL_Functions.llFabs(f); }
public double llFrand(double mag) { return m_LSL_Functions.llFrand(mag); }
public int llFloor(double f) { return m_LSL_Functions.llFloor(f); }
public int llCeil(double f) { return m_LSL_Functions.llCeil(f); }
public int llRound(double f) { return m_LSL_Functions.llRound(f); }
public double llVecMag(LSL_Types.Vector3 v) { return m_LSL_Functions.llVecMag(v); }
public LSL_Types.Vector3 llVecNorm(LSL_Types.Vector3 v) { return m_LSL_Functions.llVecNorm(v); }
public double llVecDist(LSL_Types.Vector3 a, LSL_Types.Vector3 b) { return m_LSL_Functions.llVecDist(a, b); }
public LSL_Types.Vector3 llRot2Euler(LSL_Types.Quaternion r) { return m_LSL_Functions.llRot2Euler(r); }
public LSL_Types.Quaternion llEuler2Rot(LSL_Types.Vector3 v) { return m_LSL_Functions.llEuler2Rot(v); }
public LSL_Types.Quaternion llAxes2Rot(LSL_Types.Vector3 fwd, LSL_Types.Vector3 left, LSL_Types.Vector3 up) { return m_LSL_Functions.llAxes2Rot(fwd, left, up); }
public LSL_Types.Vector3 llRot2Fwd(LSL_Types.Quaternion r) { return m_LSL_Functions.llRot2Fwd(r); }
public LSL_Types.Vector3 llRot2Left(LSL_Types.Quaternion r) { return m_LSL_Functions.llRot2Left(r); }
public LSL_Types.Vector3 llRot2Up(LSL_Types.Quaternion r) { return m_LSL_Functions.llRot2Up(r); }
public LSL_Types.Quaternion llRotBetween(LSL_Types.Vector3 start, LSL_Types.Vector3 end) { return m_LSL_Functions.llRotBetween(start, end); }
public void llWhisper(int channelID, string text) { m_LSL_Functions.llWhisper(channelID, text); }
public void llSay(int channelID, string text) { m_LSL_Functions.llSay(channelID, text); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llShout(int channelID, string text) { m_LSL_Functions.llShout(channelID, text); }
public int llListen(int channelID, string name, string ID, string msg) { return m_LSL_Functions.llListen(channelID, name, ID, msg); }
public void llListenControl(int number, int active) { m_LSL_Functions.llListenControl(number, active); }
public void llListenRemove(int number) { m_LSL_Functions.llListenRemove(number); }
public void llSensor(string name, string id, int type, double range, double arc) { m_LSL_Functions.llSensor(name, id, type, range, arc); }
public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) { m_LSL_Functions.llSensorRepeat(name, id, type, range, arc, rate); }
public void llSensorRemove() { m_LSL_Functions.llSensorRemove(); }
public string llDetectedName(int number) { return m_LSL_Functions.llDetectedName(number); }
public string llDetectedKey(int number) { return m_LSL_Functions.llDetectedKey(number); }
public string llDetectedOwner(int number) { return m_LSL_Functions.llDetectedOwner(number); }
public int llDetectedType(int number) { return m_LSL_Functions.llDetectedType(number); }
public LSL_Types.Vector3 llDetectedPos(int number) { return m_LSL_Functions.llDetectedPos(number); }
public LSL_Types.Vector3 llDetectedVel(int number) { return m_LSL_Functions.llDetectedVel(number); }
public LSL_Types.Vector3 llDetectedGrab(int number) { return m_LSL_Functions.llDetectedGrab(number); }
public LSL_Types.Quaternion llDetectedRot(int number) { return m_LSL_Functions.llDetectedRot(number); }
public int llDetectedGroup(int number) { return m_LSL_Functions.llDetectedGroup(number); }
public int llDetectedLinkNumber(int number) { return m_LSL_Functions.llDetectedLinkNumber(number); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llDie() { m_LSL_Functions.llDie(); }
public double llGround(LSL_Types.Vector3 offset) { return m_LSL_Functions.llGround(offset); }
public double llCloud(LSL_Types.Vector3 offset) { return m_LSL_Functions.llCloud(offset); }
public LSL_Types.Vector3 llWind(LSL_Types.Vector3 offset) { return m_LSL_Functions.llWind(offset); }
public void llSetStatus(int status, int value) { m_LSL_Functions.llSetStatus(status, value); }
public int llGetStatus(int status) { return m_LSL_Functions.llGetStatus(status); }
public void llSetScale(LSL_Types.Vector3 scale) { m_LSL_Functions.llSetScale(scale); }
public LSL_Types.Vector3 llGetScale() { return m_LSL_Functions.llGetScale(); }
public void llSetColor(LSL_Types.Vector3 color, int face) { m_LSL_Functions.llSetColor(color, face); }
public double llGetAlpha(int face) { return m_LSL_Functions.llGetAlpha(face); }
public void llSetAlpha(double alpha, int face) { m_LSL_Functions.llSetAlpha(alpha, face); }
public LSL_Types.Vector3 llGetColor(int face) { return m_LSL_Functions.llGetColor(face); }
public void llSetTexture(string texture, int face) { m_LSL_Functions.llSetTexture(texture, face); }
public void llScaleTexture(double u, double v, int face) { m_LSL_Functions.llScaleTexture(u, v, face); }
public void llOffsetTexture(double u, double v, int face) { m_LSL_Functions.llOffsetTexture(u, v, face); }
public void llRotateTexture(double rotation, int face) { m_LSL_Functions.llRotateTexture(rotation, face); }
public string llGetTexture(int face) { return m_LSL_Functions.llGetTexture(face); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llSetPos(LSL_Types.Vector3 pos) { m_LSL_Functions.llSetPos(pos); }
public LSL_Types.Vector3 llGetPos() { return m_LSL_Functions.llGetPos(); }
public LSL_Types.Vector3 llGetLocalPos() { return m_LSL_Functions.llGetLocalPos(); }
public void llSetRot(LSL_Types.Quaternion rot) { m_LSL_Functions.llSetRot(rot); }
public LSL_Types.Quaternion llGetRot() { return m_LSL_Functions.llGetRot(); }
public LSL_Types.Quaternion llGetLocalRot() { return m_LSL_Functions.llGetLocalRot(); }
public void llSetForce(LSL_Types.Vector3 force, int local) { m_LSL_Functions.llSetForce(force, local); }
public LSL_Types.Vector3 llGetForce() { return m_LSL_Functions.llGetForce(); }
public int llTarget(LSL_Types.Vector3 position, double range) { return m_LSL_Functions.llTarget(position, range); }
public void llTargetRemove(int number) { m_LSL_Functions.llTargetRemove(number); }
public int llRotTarget(LSL_Types.Quaternion rot, double error) { return m_LSL_Functions.llRotTarget(rot, error); }
public void llRotTargetRemove(int number) { m_LSL_Functions.llRotTargetRemove(number); }
public void llMoveToTarget(LSL_Types.Vector3 target, double tau) { m_LSL_Functions.llMoveToTarget(target, tau); }
public void llStopMoveToTarget() { m_LSL_Functions.llStopMoveToTarget(); }
public void llApplyImpulse(LSL_Types.Vector3 force, int local) { m_LSL_Functions.llApplyImpulse(force, local); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llApplyRotationalImpulse(LSL_Types.Vector3 force, int local) { m_LSL_Functions.llApplyRotationalImpulse(force, local); }
public void llSetTorque(LSL_Types.Vector3 torque, int local) { m_LSL_Functions.llSetTorque(torque, local); }
public LSL_Types.Vector3 llGetTorque() { return m_LSL_Functions.llGetTorque(); }
public void llSetForceAndTorque(LSL_Types.Vector3 force, LSL_Types.Vector3 torque, int local) { m_LSL_Functions.llSetForceAndTorque(force, torque, local); }
public LSL_Types.Vector3 llGetVel() { return m_LSL_Functions.llGetVel(); }
public LSL_Types.Vector3 llGetAccel() { return m_LSL_Functions.llGetAccel(); }
public LSL_Types.Vector3 llGetOmega() { return m_LSL_Functions.llGetOmega(); }
public double llGetTimeOfDay() { return m_LSL_Functions.llGetTimeOfDay(); }
public double llGetWallclock() { return m_LSL_Functions.llGetWallclock(); }
public double llGetTime() { return m_LSL_Functions.llGetTime(); }
public void llResetTime() { m_LSL_Functions.llResetTime(); }
public double llGetAndResetTime() { return m_LSL_Functions.llGetAndResetTime(); }
public void llSound() { m_LSL_Functions.llSound(); }
public void llPlaySound(string sound, double volume) { m_LSL_Functions.llPlaySound(sound, volume); }
public void llLoopSound(string sound, double volume) { m_LSL_Functions.llLoopSound(sound, volume); }
public void llLoopSoundMaster(string sound, double volume) { m_LSL_Functions.llLoopSoundMaster(sound, volume); }
public void llLoopSoundSlave(string sound, double volume) { m_LSL_Functions.llLoopSoundSlave(sound, volume); }
public void llPlaySoundSlave(string sound, double volume) { m_LSL_Functions.llPlaySoundSlave(sound, volume); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llTriggerSound(string sound, double volume) { m_LSL_Functions.llTriggerSound(sound, volume); }
public void llStopSound() { m_LSL_Functions.llStopSound(); }
public void llPreloadSound(string sound) { m_LSL_Functions.llPreloadSound(sound); }
public string llGetSubString(string src, int start, int end) { return m_LSL_Functions.llGetSubString(src, start, end); }
public string llDeleteSubString(string src, int start, int end) { return m_LSL_Functions.llDeleteSubString(src, start, end); }
public string llInsertString(string dst, int position, string src) { return m_LSL_Functions.llInsertString(dst, position, src); }
public string llToUpper(string source) { return m_LSL_Functions.llToUpper(source); }
public string llToLower(string source) { return m_LSL_Functions.llToLower(source); }
public int llGiveMoney(string destination, int amount) { return m_LSL_Functions.llGiveMoney(destination, amount); }
public void llMakeExplosion() { m_LSL_Functions.llMakeExplosion(); }
public void llMakeFountain() { m_LSL_Functions.llMakeFountain(); }
public void llMakeSmoke() { m_LSL_Functions.llMakeSmoke(); }
public void llMakeFire() { m_LSL_Functions.llMakeFire(); }
public void llRezObject(string inventory, LSL_Types.Vector3 pos, LSL_Types.Quaternion rot, int param) { m_LSL_Functions.llRezObject(inventory, pos, rot, param); }
public void llLookAt(LSL_Types.Vector3 target, double strength, double damping) { m_LSL_Functions.llLookAt(target, strength, damping); }
public void llStopLookAt() { m_LSL_Functions.llStopLookAt(); }
public void llSetTimerEvent(double sec) { m_LSL_Functions.llSetTimerEvent(sec); }
public void llSleep(double sec) { m_LSL_Functions.llSleep(sec); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public double llGetMass() { return m_LSL_Functions.llGetMass(); }
public void llCollisionFilter(string name, string id, int accept) { m_LSL_Functions.llCollisionFilter(name, id, accept); }
public void llTakeControls(int controls, int accept, int pass_on) { m_LSL_Functions.llTakeControls(controls, accept, pass_on); }
public void llReleaseControls() { m_LSL_Functions.llReleaseControls(); }
public void llAttachToAvatar(int attachment) { m_LSL_Functions.llAttachToAvatar(attachment); }
public void llDetachFromAvatar() { m_LSL_Functions.llDetachFromAvatar(); }
public void llTakeCamera() { m_LSL_Functions.llTakeCamera(); }
public void llReleaseCamera() { m_LSL_Functions.llReleaseCamera(); }
public string llGetOwner() { return m_LSL_Functions.llGetOwner(); }
public void llInstantMessage(string user, string message) { m_LSL_Functions.llInstantMessage(user, message); }
public void llEmail(string address, string subject, string message) { m_LSL_Functions.llEmail(address, subject, message); }
public void llGetNextEmail(string address, string subject) { m_LSL_Functions.llGetNextEmail(address, subject); }
public string llGetKey() { return m_LSL_Functions.llGetKey(); }
public void llSetBuoyancy(double buoyancy) { m_LSL_Functions.llSetBuoyancy(buoyancy); }
public void llSetHoverHeight(double height, int water, double tau) { m_LSL_Functions.llSetHoverHeight(height, water, tau); }
public void llStopHover() { m_LSL_Functions.llStopHover(); }
public void llMinEventDelay(double delay) { m_LSL_Functions.llMinEventDelay(delay); }
public void llSoundPreload() { m_LSL_Functions.llSoundPreload(); }
public void llRotLookAt(LSL_Types.Quaternion target, double strength, double damping) { m_LSL_Functions.llRotLookAt(target, strength, damping); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public int llStringLength(string str) { return m_LSL_Functions.llStringLength(str); }
public void llStartAnimation(string anim) { m_LSL_Functions.llStartAnimation(anim); }
public void llStopAnimation(string anim) { m_LSL_Functions.llStopAnimation(anim); }
public void llPointAt() { m_LSL_Functions.llPointAt(); }
public void llStopPointAt() { m_LSL_Functions.llStopPointAt(); }
public void llTargetOmega(LSL_Types.Vector3 axis, double spinrate, double gain) { m_LSL_Functions.llTargetOmega(axis, spinrate, gain); }
public int llGetStartParameter() { return m_LSL_Functions.llGetStartParameter(); }
public void llGodLikeRezObject(string inventory, LSL_Types.Vector3 pos) { m_LSL_Functions.llGodLikeRezObject(inventory, pos); }
public void llRequestPermissions(string agent, int perm) { m_LSL_Functions.llRequestPermissions(agent, perm); }
public string llGetPermissionsKey() { return m_LSL_Functions.llGetPermissionsKey(); }
public int llGetPermissions() { return m_LSL_Functions.llGetPermissions(); }
public int llGetLinkNumber() { return m_LSL_Functions.llGetLinkNumber(); }
public void llSetLinkColor(int linknumber, LSL_Types.Vector3 color, int face) { m_LSL_Functions.llSetLinkColor(linknumber, color, face); }
public void llCreateLink(string target, int parent) { m_LSL_Functions.llCreateLink(target, parent); }
public void llBreakLink(int linknum) { m_LSL_Functions.llBreakLink(linknum); }
public void llBreakAllLinks() { m_LSL_Functions.llBreakAllLinks(); }
public string llGetLinkKey(int linknum) { return m_LSL_Functions.llGetLinkKey(linknum); }
public void llGetLinkName(int linknum) { m_LSL_Functions.llGetLinkName(linknum); }
public int llGetInventoryNumber(int type) { return m_LSL_Functions.llGetInventoryNumber(type); }
public string llGetInventoryName(int type, int number) { return m_LSL_Functions.llGetInventoryName(type, number); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llSetScriptState(string name, int run) { m_LSL_Functions.llSetScriptState(name, run); }
public double llGetEnergy() { return m_LSL_Functions.llGetEnergy(); }
public void llGiveInventory(string destination, string inventory) { m_LSL_Functions.llGiveInventory(destination, inventory); }
public void llRemoveInventory(string item) { m_LSL_Functions.llRemoveInventory(item); }
public void llSetText(string text, LSL_Types.Vector3 color, double alpha) { m_LSL_Functions.llSetText(text, color, alpha); }
public double llWater(LSL_Types.Vector3 offset) { return m_LSL_Functions.llWater(offset); }
public void llPassTouches(int pass) { m_LSL_Functions.llPassTouches(pass); }
public string llRequestAgentData(string id, int data) { return m_LSL_Functions.llRequestAgentData(id, data); }
public string llRequestInventoryData(string name) { return m_LSL_Functions.llRequestInventoryData(name); }
public void llSetDamage(double damage) { m_LSL_Functions.llSetDamage(damage); }
public void llTeleportAgentHome(string agent) { m_LSL_Functions.llTeleportAgentHome(agent); }
public void llModifyLand(int action, int brush) { m_LSL_Functions.llModifyLand(action, brush); }
public void llCollisionSound(string impact_sound, double impact_volume) { m_LSL_Functions.llCollisionSound(impact_sound, impact_volume); }
public void llCollisionSprite(string impact_sprite) { m_LSL_Functions.llCollisionSprite(impact_sprite); }
public string llGetAnimation(string id) { return m_LSL_Functions.llGetAnimation(id); }
public void llResetScript() { m_LSL_Functions.llResetScript(); }
public void llMessageLinked(int linknum, int num, string str, string id) { m_LSL_Functions.llMessageLinked(linknum, num, str, id); }
public void llPushObject(string target, LSL_Types.Vector3 impulse, LSL_Types.Vector3 ang_impulse, int local) { m_LSL_Functions.llPushObject(target, impulse, ang_impulse, local); }
public void llPassCollisions(int pass) { m_LSL_Functions.llPassCollisions(pass); }
public string llGetScriptName() { return m_LSL_Functions.llGetScriptName(); }
public int llGetNumberOfSides() { return m_LSL_Functions.llGetNumberOfSides(); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public LSL_Types.Quaternion llAxisAngle2Rot(LSL_Types.Vector3 axis, double angle) { return m_LSL_Functions.llAxisAngle2Rot(axis, angle); }
public LSL_Types.Vector3 llRot2Axis(LSL_Types.Quaternion rot) { return m_LSL_Functions.llRot2Axis(rot); }
public void llRot2Angle() { m_LSL_Functions.llRot2Angle(); }
public double llAcos(double val) { return m_LSL_Functions.llAcos(val); }
public double llAsin(double val) { return m_LSL_Functions.llAsin(val); }
public double llAngleBetween(LSL_Types.Quaternion a, LSL_Types.Quaternion b) { return m_LSL_Functions.llAngleBetween(a, b); }
public string llGetInventoryKey(string name) { return m_LSL_Functions.llGetInventoryKey(name); }
public void llAllowInventoryDrop(int add) { m_LSL_Functions.llAllowInventoryDrop(add); }
public LSL_Types.Vector3 llGetSunDirection() { return m_LSL_Functions.llGetSunDirection(); }
public LSL_Types.Vector3 llGetTextureOffset(int face) { return m_LSL_Functions.llGetTextureOffset(face); }
public LSL_Types.Vector3 llGetTextureScale(int side) { return m_LSL_Functions.llGetTextureScale(side); }
public double llGetTextureRot(int side) { return m_LSL_Functions.llGetTextureRot(side); }
public int llSubStringIndex(string source, string pattern) { return m_LSL_Functions.llSubStringIndex(source, pattern); }
public string llGetOwnerKey(string id) { return m_LSL_Functions.llGetOwnerKey(id); }
public LSL_Types.Vector3 llGetCenterOfMass() { return m_LSL_Functions.llGetCenterOfMass(); }
public List<string> llListSort(List<string> src, int stride, int ascending) { return m_LSL_Functions.llListSort(src, stride, ascending); }
public int llGetListLength(List<string> src) { return m_LSL_Functions.llGetListLength(src); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public int llList2Integer(List<string> src, int index) { return m_LSL_Functions.llList2Integer(src, index); }
public double llList2double(List<string> src, int index) { return m_LSL_Functions.llList2double(src, index); }
public string llList2String(List<string> src, int index) { return m_LSL_Functions.llList2String(src, index); }
public string llList2Key(List<string> src, int index) { return m_LSL_Functions.llList2Key(src, index); }
public LSL_Types.Vector3 llList2Vector(List<string> src, int index) { return m_LSL_Functions.llList2Vector(src, index); }
public LSL_Types.Quaternion llList2Rot(List<string> src, int index) { return m_LSL_Functions.llList2Rot(src, index); }
public List<string> llList2List(List<string> src, int start, int end) { return m_LSL_Functions.llList2List(src, start, end); }
public List<string> llDeleteSubList(List<string> src, int start, int end) { return m_LSL_Functions.llDeleteSubList(src, start, end); }
public int llGetListEntryType(List<string> src, int index) { return m_LSL_Functions.llGetListEntryType(src, index); }
public string llList2CSV(List<string> src) { return m_LSL_Functions.llList2CSV(src); }
public List<string> llCSV2List(string src) { return m_LSL_Functions.llCSV2List(src); }
public List<string> llListRandomize(List<string> src, int stride) { return m_LSL_Functions.llListRandomize(src, stride); }
public List<string> llList2ListStrided(List<string> src, int start, int end, int stride) { return m_LSL_Functions.llList2ListStrided(src, start, end, stride); }
public LSL_Types.Vector3 llGetRegionCorner() { return m_LSL_Functions.llGetRegionCorner(); }
public List<string> llListInsertList(List<string> dest, List<string> src, int start) { return m_LSL_Functions.llListInsertList(dest, src, start); }
public int llListFindList(List<string> src, List<string> test) { return m_LSL_Functions.llListFindList(src, test); }
public string llGetObjectName() { return m_LSL_Functions.llGetObjectName(); }
public void llSetObjectName(string name) { m_LSL_Functions.llSetObjectName(name); }
public string llGetDate() { return m_LSL_Functions.llGetDate(); }
public int llEdgeOfWorld(LSL_Types.Vector3 pos, LSL_Types.Vector3 dir) { return m_LSL_Functions.llEdgeOfWorld(pos, dir); }
public int llGetAgentInfo(string id) { return m_LSL_Functions.llGetAgentInfo(id); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llAdjustSoundVolume(double volume) { m_LSL_Functions.llAdjustSoundVolume(volume); }
public void llSetSoundQueueing(int queue) { m_LSL_Functions.llSetSoundQueueing(queue); }
public void llSetSoundRadius(double radius) { m_LSL_Functions.llSetSoundRadius(radius); }
public string llKey2Name(string id) { return m_LSL_Functions.llKey2Name(id); }
public void llSetTextureAnim(int mode, int face, int sizex, int sizey, double start, double length, double rate) { m_LSL_Functions.llSetTextureAnim(mode, face, sizex, sizey, start, length, rate); }
public void llTriggerSoundLimited(string sound, double volume, LSL_Types.Vector3 top_north_east, LSL_Types.Vector3 bottom_south_west) { m_LSL_Functions.llTriggerSoundLimited(sound, volume, top_north_east, bottom_south_west); }
public void llEjectFromLand(string pest) { m_LSL_Functions.llEjectFromLand(pest); }
public void llParseString2List() { m_LSL_Functions.llParseString2List(); }
public int llOverMyLand(string id) { return m_LSL_Functions.llOverMyLand(id); }
public string llGetLandOwnerAt(LSL_Types.Vector3 pos) { return m_LSL_Functions.llGetLandOwnerAt(pos); }
public string llGetNotecardLine(string name, int line) { return m_LSL_Functions.llGetNotecardLine(name, line); }
public LSL_Types.Vector3 llGetAgentSize(string id) { return m_LSL_Functions.llGetAgentSize(id); }
public int llSameGroup(string agent) { return m_LSL_Functions.llSameGroup(agent); }
public void llUnSit(string id) { m_LSL_Functions.llUnSit(id); }
public LSL_Types.Vector3 llGroundSlope(LSL_Types.Vector3 offset) { return m_LSL_Functions.llGroundSlope(offset); }
public LSL_Types.Vector3 llGroundNormal(LSL_Types.Vector3 offset) { return m_LSL_Functions.llGroundNormal(offset); }
public LSL_Types.Vector3 llGroundContour(LSL_Types.Vector3 offset) { return m_LSL_Functions.llGroundContour(offset); }
public int llGetAttached() { return m_LSL_Functions.llGetAttached(); }
public int llGetFreeMemory() { return m_LSL_Functions.llGetFreeMemory(); }
public string llGetRegionName() { return m_LSL_Functions.llGetRegionName(); }
public double llGetRegionTimeDilation() { return m_LSL_Functions.llGetRegionTimeDilation(); }
public double llGetRegionFPS() { return m_LSL_Functions.llGetRegionFPS(); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llParticleSystem(List<Object> rules) { m_LSL_Functions.llParticleSystem(rules); }
public void llGroundRepel(double height, int water, double tau) { m_LSL_Functions.llGroundRepel(height, water, tau); }
public void llGiveInventoryList() { m_LSL_Functions.llGiveInventoryList(); }
public void llSetVehicleType(int type) { m_LSL_Functions.llSetVehicleType(type); }
public void llSetVehicledoubleParam(int param, double value) { m_LSL_Functions.llSetVehicledoubleParam(param, value); }
public void llSetVehicleVectorParam(int param, LSL_Types.Vector3 vec) { m_LSL_Functions.llSetVehicleVectorParam(param, vec); }
public void llSetVehicleRotationParam(int param, LSL_Types.Quaternion rot) { m_LSL_Functions.llSetVehicleRotationParam(param, rot); }
public void llSetVehicleFlags(int flags) { m_LSL_Functions.llSetVehicleFlags(flags); }
public void llRemoveVehicleFlags(int flags) { m_LSL_Functions.llRemoveVehicleFlags(flags); }
public void llSitTarget(LSL_Types.Vector3 offset, LSL_Types.Quaternion rot) { m_LSL_Functions.llSitTarget(offset, rot); }
public string llAvatarOnSitTarget() { return m_LSL_Functions.llAvatarOnSitTarget(); }
public void llAddToLandPassList(string avatar, double hours) { m_LSL_Functions.llAddToLandPassList(avatar, hours); }
public void llSetTouchText(string text) { m_LSL_Functions.llSetTouchText(text); }
public void llSetSitText(string text) { m_LSL_Functions.llSetSitText(text); }
public void llSetCameraEyeOffset(LSL_Types.Vector3 offset) { m_LSL_Functions.llSetCameraEyeOffset(offset); }
public void llSetCameraAtOffset(LSL_Types.Vector3 offset) { m_LSL_Functions.llSetCameraAtOffset(offset); }
public void llDumpList2String() { m_LSL_Functions.llDumpList2String(); }
public void llScriptDanger(LSL_Types.Vector3 pos) { m_LSL_Functions.llScriptDanger(pos); }
public void llDialog(string avatar, string message, List<string> buttons, int chat_channel) { m_LSL_Functions.llDialog(avatar, message, buttons, chat_channel); }
public void llVolumeDetect(int detect) { m_LSL_Functions.llVolumeDetect(detect); }
public void llResetOtherScript(string name) { m_LSL_Functions.llResetOtherScript(name); }
public int llGetScriptState(string name) { return m_LSL_Functions.llGetScriptState(name); }
public void llRemoteLoadScript() { m_LSL_Functions.llRemoteLoadScript(); }
public void llSetRemoteScriptAccessPin(int pin) { m_LSL_Functions.llSetRemoteScriptAccessPin(pin); }
public void llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param) { m_LSL_Functions.llRemoteLoadScriptPin(target, name, pin, running, start_param); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public void llOpenRemoteDataChannel() { m_LSL_Functions.llOpenRemoteDataChannel(); }
public string llSendRemoteData(string channel, string dest, int idata, string sdata) { return m_LSL_Functions.llSendRemoteData(channel, dest, idata, sdata); }
public void llRemoteDataReply(string channel, string message_id, string sdata, int idata) { m_LSL_Functions.llRemoteDataReply(channel, message_id, sdata, idata); }
public void llCloseRemoteDataChannel(string channel) { m_LSL_Functions.llCloseRemoteDataChannel(channel); }
public string llMD5String(string src, int nonce) { return m_LSL_Functions.llMD5String(src, nonce); }
public void llSetPrimitiveParams(List<string> rules) { m_LSL_Functions.llSetPrimitiveParams(rules); }
public string llStringToBase64(string str) { return m_LSL_Functions.llStringToBase64(str); }
public string llBase64ToString(string str) { return m_LSL_Functions.llBase64ToString(str); }
public void llXorBase64Strings() { m_LSL_Functions.llXorBase64Strings(); }
public void llRemoteDataSetRegion() { m_LSL_Functions.llRemoteDataSetRegion(); }
public double llLog10(double val) { return m_LSL_Functions.llLog10(val); }
public double llLog(double val) { return m_LSL_Functions.llLog(val); }
public List<string> llGetAnimationList(string id) { return m_LSL_Functions.llGetAnimationList(id); }
public void llSetParcelMusicURL(string url) { m_LSL_Functions.llSetParcelMusicURL(url); }
public LSL_Types.Vector3 llGetRootPosition() { return m_LSL_Functions.llGetRootPosition(); }
public LSL_Types.Quaternion llGetRootRotation() { return m_LSL_Functions.llGetRootRotation(); }
public string llGetObjectDesc() { return m_LSL_Functions.llGetObjectDesc(); }
public void llSetObjectDesc(string desc) { m_LSL_Functions.llSetObjectDesc(desc); }
public string llGetCreator() { return m_LSL_Functions.llGetCreator(); }
public string llGetTimestamp() { return m_LSL_Functions.llGetTimestamp(); }
public void llSetLinkAlpha(int linknumber, double alpha, int face) { m_LSL_Functions.llSetLinkAlpha(linknumber, alpha, face); }
public int llGetNumberOfPrims() { return m_LSL_Functions.llGetNumberOfPrims(); }
public string llGetNumberOfNotecardLines(string name) { return m_LSL_Functions.llGetNumberOfNotecardLines(name); }
public List<string> llGetBoundingBox(string obj) { return m_LSL_Functions.llGetBoundingBox(obj); }
public LSL_Types.Vector3 llGetGeometricCenter() { return m_LSL_Functions.llGetGeometricCenter(); }
public void llGetPrimitiveParams() { m_LSL_Functions.llGetPrimitiveParams(); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public string llIntegerToBase64(int number) { return m_LSL_Functions.llIntegerToBase64(number); }
public int llBase64ToInteger(string str) { return m_LSL_Functions.llBase64ToInteger(str); }
public double llGetGMTclock() { return m_LSL_Functions.llGetGMTclock(); }
public string llGetSimulatorHostname() { return m_LSL_Functions.llGetSimulatorHostname(); }
public void llSetLocalRot(LSL_Types.Quaternion rot) { m_LSL_Functions.llSetLocalRot(rot); }
public List<string> llParseStringKeepNulls(string src, List<string> seperators, List<string> spacers) { return m_LSL_Functions.llParseStringKeepNulls(src, seperators, spacers); }
public void llRezAtRoot(string inventory, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity, LSL_Types.Quaternion rot, int param) { m_LSL_Functions.llRezAtRoot(inventory, position, velocity, rot, param); }
public int llGetObjectPermMask(int mask) { return m_LSL_Functions.llGetObjectPermMask(mask); }
public void llSetObjectPermMask(int mask, int value) { m_LSL_Functions.llSetObjectPermMask(mask, value); }
public void llGetInventoryPermMask(string item, int mask) { m_LSL_Functions.llGetInventoryPermMask(item, mask); }
public void llSetInventoryPermMask(string item, int mask, int value) { m_LSL_Functions.llSetInventoryPermMask(item, mask, value); }
public string llGetInventoryCreator(string item) { return m_LSL_Functions.llGetInventoryCreator(item); }
public void llOwnerSay(string msg) { m_LSL_Functions.llOwnerSay(msg); }
public void llRequestSimulatorData(string simulator, int data) { m_LSL_Functions.llRequestSimulatorData(simulator, data); }
public void llForceMouselook(int mouselook) { m_LSL_Functions.llForceMouselook(mouselook); }
public double llGetObjectMass(string id) { return m_LSL_Functions.llGetObjectMass(id); }
public void llListReplaceList() { m_LSL_Functions.llListReplaceList(); }
public void llLoadURL(string avatar_id, string message, string url) { m_LSL_Functions.llLoadURL(avatar_id, message, url); }
public void llParcelMediaCommandList(List<string> commandList) { m_LSL_Functions.llParcelMediaCommandList(commandList); }
public void llParcelMediaQuery() { m_LSL_Functions.llParcelMediaQuery(); }
public int llModPow(int a, int b, int c) { return m_LSL_Functions.llModPow(a, b, c); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public int llGetInventoryType(string name) { return m_LSL_Functions.llGetInventoryType(name); }
public void llSetPayPrice(int price, List<string> quick_pay_buttons) { m_LSL_Functions.llSetPayPrice(price, quick_pay_buttons); }
public LSL_Types.Vector3 llGetCameraPos() { return m_LSL_Functions.llGetCameraPos(); }
public LSL_Types.Quaternion llGetCameraRot() { return m_LSL_Functions.llGetCameraRot(); }
public void llSetPrimURL() { m_LSL_Functions.llSetPrimURL(); }
public void llRefreshPrimURL() { m_LSL_Functions.llRefreshPrimURL(); }
public string llEscapeURL(string url) { return m_LSL_Functions.llEscapeURL(url); }
public string llUnescapeURL(string url) { return m_LSL_Functions.llUnescapeURL(url); }
public void llMapDestination(string simname, LSL_Types.Vector3 pos, LSL_Types.Vector3 look_at) { m_LSL_Functions.llMapDestination(simname, pos, look_at); }
public void llAddToLandBanList(string avatar, double hours) { m_LSL_Functions.llAddToLandBanList(avatar, hours); }
public void llRemoveFromLandPassList(string avatar) { m_LSL_Functions.llRemoveFromLandPassList(avatar); }
public void llRemoveFromLandBanList(string avatar) { m_LSL_Functions.llRemoveFromLandBanList(avatar); }
public void llSetCameraParams(List<string> rules) { m_LSL_Functions.llSetCameraParams(rules); }
public void llClearCameraParams() { m_LSL_Functions.llClearCameraParams(); }
public double llListStatistics(int operation, List<string> src) { return m_LSL_Functions.llListStatistics(operation, src); }
public int llGetUnixTime() { return m_LSL_Functions.llGetUnixTime(); }
public int llGetParcelFlags(LSL_Types.Vector3 pos) { return m_LSL_Functions.llGetParcelFlags(pos); }
public int llGetRegionFlags() { return m_LSL_Functions.llGetRegionFlags(); }
public string llXorBase64StringsCorrect(string str1, string str2) { return m_LSL_Functions.llXorBase64StringsCorrect(str1, str2); }
public void llHTTPRequest(string url, List<string> parameters, string body) { m_LSL_Functions.llHTTPRequest(url, parameters, body); }
public void llResetLandBanList() { m_LSL_Functions.llResetLandBanList(); }
public void llResetLandPassList() { m_LSL_Functions.llResetLandPassList(); }
public int llGetParcelPrimCount(LSL_Types.Vector3 pos, int category, int sim_wide) { return m_LSL_Functions.llGetParcelPrimCount(pos, category, sim_wide); }
public List<string> llGetParcelPrimOwners(LSL_Types.Vector3 pos) { return m_LSL_Functions.llGetParcelPrimOwners(pos); }
public int llGetObjectPrimCount(string object_id) { return m_LSL_Functions.llGetObjectPrimCount(object_id); }
//
// DO NOT MODIFY HERE: MODIFY IN LSL_BuiltIn_Commands.cs
//
public int llGetParcelMaxPrims(LSL_Types.Vector3 pos, int sim_wide) { return m_LSL_Functions.llGetParcelMaxPrims(pos, sim_wide); }
public List<string> llGetParcelDetails(LSL_Types.Vector3 pos, List<string> param) { return m_LSL_Functions.llGetParcelDetails(pos, param); }
//
// OpenSim Functions
//
public string osSetDynamicTextureURL(string dynamicID, string contentType, string url, string extraParams, int timer) { return m_LSL_Functions.osSetDynamicTextureURL(dynamicID, contentType, url, extraParams, timer); }
// LSL CONSTANTS
public const int TRUE = 1;
public const int FALSE = 0;
public const int STATUS_PHYSICS = 1;
public const int STATUS_ROTATE_X = 2;
public const int STATUS_ROTATE_Y = 4;
public const int STATUS_ROTATE_Z = 8;
public const int STATUS_PHANTOM = 16;
public const int STATUS_SANDBOX = 32;
public const int STATUS_BLOCK_GRAB = 64;
public const int STATUS_DIE_AT_EDGE = 128;
public const int STATUS_RETURN_AT_EDGE = 256;
public const int AGENT = 1;
public const int ACTIVE = 2;
public const int PASSIVE = 4;
public const int SCRIPTED = 8;
public const int CONTROL_FWD = 1;
public const int CONTROL_BACK = 2;
public const int CONTROL_LEFT = 4;
public const int CONTROL_RIGHT = 8;
public const int CONTROL_UP = 16;
public const int CONTROL_DOWN = 32;
public const int CONTROL_ROT_LEFT = 256;
public const int CONTROL_ROT_RIGHT = 512;
public const int CONTROL_LBUTTON = 268435456;
public const int CONTROL_ML_LBUTTON = 1073741824;
public const int PERMISSION_DEBIT = 2;
public const int PERMISSION_TAKE_CONTROLS = 4;
public const int PERMISSION_REMAP_CONTROLS = 8;
public const int PERMISSION_TRIGGER_ANIMATION = 16;
public const int PERMISSION_ATTACH = 32;
public const int PERMISSION_RELEASE_OWNERSHIP = 64;
public const int PERMISSION_CHANGE_LINKS = 128;
public const int PERMISSION_CHANGE_JOINTS = 256;
public const int PERMISSION_CHANGE_PERMISSIONS = 512;
public const int PERMISSION_TRACK_CAMERA = 1024;
public const int AGENT_FLYING = 1;
public const int AGENT_ATTACHMENTS = 2;
public const int AGENT_SCRIPTED = 4;
public const int AGENT_MOUSELOOK = 8;
public const int AGENT_SITTING = 16;
public const int AGENT_ON_OBJECT = 32;
public const int AGENT_AWAY = 64;
public const int AGENT_WALKING = 128;
public const int AGENT_IN_AIR = 256;
public const int AGENT_TYPING = 512;
public const int AGENT_CROUCHING = 1024;
public const int AGENT_BUSY = 2048;
public const int AGENT_ALWAYS_RUN = 4096;
public const int PSYS_PART_INTERP_COLOR_MASK = 1;
public const int PSYS_PART_INTERP_SCALE_MASK = 2;
public const int PSYS_PART_BOUNCE_MASK = 4;
public const int PSYS_PART_WIND_MASK = 8;
public const int PSYS_PART_FOLLOW_SRC_MASK = 16;
public const int PSYS_PART_FOLLOW_VELOCITY_MASK = 32;
public const int PSYS_PART_TARGET_POS_MASK = 64;
public const int PSYS_PART_TARGET_LINEAR_MASK = 128;
public const int PSYS_PART_EMISSIVE_MASK = 256;
public const int PSYS_PART_FLAGS = 0;
public const int PSYS_PART_START_COLOR = 1;
public const int PSYS_PART_START_ALPHA = 2;
public const int PSYS_PART_END_COLOR = 3;
public const int PSYS_PART_END_ALPHA = 4;
public const int PSYS_PART_START_SCALE = 5;
public const int PSYS_PART_END_SCALE = 6;
public const int PSYS_PART_MAX_AGE = 7;
public const int PSYS_SRC_ACCEL = 8;
public const int PSYS_SRC_PATTERN = 9;
public const int PSYS_SRC_INNERANGLE = 10;
public const int PSYS_SRC_OUTERANGLE = 11;
public const int PSYS_SRC_TEXTURE = 12;
public const int PSYS_SRC_BURST_RATE = 13;
public const int PSYS_SRC_BURST_PART_COUNT = 15;
public const int PSYS_SRC_BURST_RADIUS = 16;
public const int PSYS_SRC_BURST_SPEED_MIN = 17;
public const int PSYS_SRC_BURST_SPEED_MAX = 18;
public const int PSYS_SRC_MAX_AGE = 19;
public const int PSYS_SRC_TARGET_KEY = 20;
public const int PSYS_SRC_OMEGA = 21;
public const int PSYS_SRC_ANGLE_BEGIN = 22;
public const int PSYS_SRC_ANGLE_END = 23;
public const int PSYS_SRC_PATTERN_DROP = 1;
public const int PSYS_SRC_PATTERN_EXPLODE = 2;
public const int PSYS_SRC_PATTERN_ANGLE = 4;
public const int PSYS_SRC_PATTERN_ANGLE_CONE = 8;
public const int PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY = 16;
public const int VEHICLE_TYPE_NONE = 0;
public const int VEHICLE_TYPE_SLED = 1;
public const int VEHICLE_TYPE_CAR = 2;
public const int VEHICLE_TYPE_BOAT = 3;
public const int VEHICLE_TYPE_AIRPLANE = 4;
public const int VEHICLE_TYPE_BALLOON = 5;
public const int VEHICLE_LINEAR_FRICTION_TIMESCALE = 16;
public const int VEHICLE_ANGULAR_FRICTION_TIMESCALE = 17;
public const int VEHICLE_LINEAR_MOTOR_DIRECTION = 18;
public const int VEHICLE_LINEAR_MOTOR_OFFSET = 20;
public const int VEHICLE_ANGULAR_MOTOR_DIRECTION = 19;
public const int VEHICLE_HOVER_HEIGHT = 24;
public const int VEHICLE_HOVER_EFFICIENCY = 25;
public const int VEHICLE_HOVER_TIMESCALE = 26;
public const int VEHICLE_BUOYANCY = 27;
public const int VEHICLE_LINEAR_DEFLECTION_EFFICIENCY = 28;
public const int VEHICLE_LINEAR_DEFLECTION_TIMESCALE = 29;
public const int VEHICLE_LINEAR_MOTOR_TIMESCALE = 30;
public const int VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE = 31;
public const int VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY = 32;
public const int VEHICLE_ANGULAR_DEFLECTION_TIMESCALE = 33;
public const int VEHICLE_ANGULAR_MOTOR_TIMESCALE = 34;
public const int VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE = 35;
public const int VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY = 36;
public const int VEHICLE_VERTICAL_ATTRACTION_TIMESCALE = 37;
public const int VEHICLE_BANKING_EFFICIENCY = 38;
public const int VEHICLE_BANKING_MIX = 39;
public const int VEHICLE_BANKING_TIMESCALE = 40;
public const int VEHICLE_REFERENCE_FRAME = 44;
public const int VEHICLE_FLAG_NO_DEFLECTION_UP = 1;
public const int VEHICLE_FLAG_LIMIT_ROLL_ONLY = 2;
public const int VEHICLE_FLAG_HOVER_WATER_ONLY = 4;
public const int VEHICLE_FLAG_HOVER_TERRAIN_ONLY = 8;
public const int VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT = 16;
public const int VEHICLE_FLAG_HOVER_UP_ONLY = 32;
public const int VEHICLE_FLAG_LIMIT_MOTOR_UP = 64;
public const int VEHICLE_FLAG_MOUSELOOK_STEER = 128;
public const int VEHICLE_FLAG_MOUSELOOK_BANK = 256;
public const int VEHICLE_FLAG_CAMERA_DECOUPLED = 512;
public const int INVENTORY_ALL = -1;
public const int INVENTORY_NONE = -1;
public const int INVENTORY_TEXTURE = 0;
public const int INVENTORY_SOUND = 1;
public const int INVENTORY_LANDMARK = 3;
public const int INVENTORY_CLOTHING = 5;
public const int INVENTORY_OBJECT = 6;
public const int INVENTORY_NOTECARD = 7;
public const int INVENTORY_SCRIPT = 10;
public const int INVENTORY_BODYPART = 13;
public const int INVENTORY_ANIMATION = 20;
public const int INVENTORY_GESTURE = 21;
public const int ATTACH_CHEST = 1;
public const int ATTACH_HEAD = 2;
public const int ATTACH_LSHOULDER = 3;
public const int ATTACH_RSHOULDER = 4;
public const int ATTACH_LHAND = 5;
public const int ATTACH_RHAND = 6;
public const int ATTACH_LFOOT = 7;
public const int ATTACH_RFOOT = 8;
public const int ATTACH_BACK = 9;
public const int ATTACH_PELVIS = 10;
public const int ATTACH_MOUTH = 11;
public const int ATTACH_CHIN = 12;
public const int ATTACH_LEAR = 13;
public const int ATTACH_REAR = 14;
public const int ATTACH_LEYE = 15;
public const int ATTACH_REYE = 16;
public const int ATTACH_NOSE = 17;
public const int ATTACH_RUARM = 18;
public const int ATTACH_RLARM = 19;
public const int ATTACH_LUARM = 20;
public const int ATTACH_LLARM = 21;
public const int ATTACH_RHIP = 22;
public const int ATTACH_RULEG = 23;
public const int ATTACH_RLLEG = 24;
public const int ATTACH_LHIP = 25;
public const int ATTACH_LULEG = 26;
public const int ATTACH_LLLEG = 27;
public const int ATTACH_BELLY = 28;
public const int ATTACH_RPEC = 29;
public const int ATTACH_LPEC = 30;
public const int LAND_LEVEL = 0;
public const int LAND_RAISE = 1;
public const int LAND_LOWER = 2;
public const int LAND_SMOOTH = 3;
public const int LAND_NOISE = 4;
public const int LAND_REVERT = 5;
public const int LAND_SMALL_BRUSH = 1;
public const int LAND_MEDIUM_BRUSH = 2;
public const int LAND_LARGE_BRUSH = 3;
public const int DATA_ONLINE = 1;
public const int DATA_NAME = 2;
public const int DATA_BORN = 3;
public const int DATA_RATING = 4;
public const int DATA_SIM_POS = 5;
public const int DATA_SIM_STATUS = 6;
public const int DATA_SIM_RATING = 7;
public const int ANIM_ON = 1;
public const int LOOP = 2;
public const int REVERSE = 4;
public const int PING_PONG = 8;
public const int SMOOTH = 16;
public const int ROTATE = 32;
public const int SCALE = 64;
public const int ALL_SIDES = -1;
public const int LINK_SET = -1;
public const int LINK_ROOT = 1;
public const int LINK_ALL_OTHERS = -2;
public const int LINK_ALL_CHILDREN = -3;
public const int LINK_THIS = -4;
public const int CHANGED_INVENTORY = 1;
public const int CHANGED_COLOR = 2;
public const int CHANGED_SHAPE = 4;
public const int CHANGED_SCALE = 8;
public const int CHANGED_TEXTURE = 16;
public const int CHANGED_LINK = 32;
public const int CHANGED_ALLOWED_DROP = 64;
public const int CHANGED_OWNER = 128;
public const int TYPE_INVALID = 0;
public const int TYPE_INTEGER = 1;
public const int TYPE_double = 2;
public const int TYPE_STRING = 3;
public const int TYPE_KEY = 4;
public const int TYPE_VECTOR = 5;
public const int TYPE_ROTATION = 6;
public const int REMOTE_DATA_CHANNEL = 1;
public const int REMOTE_DATA_REQUEST = 2;
public const int REMOTE_DATA_REPLY = 3;
//public const int PRIM_TYPE = 1;
public const int PRIM_MATERIAL = 2;
public const int PRIM_PHYSICS = 3;
public const int PRIM_TEMP_ON_REZ = 4;
public const int PRIM_PHANTOM = 5;
public const int PRIM_POSITION = 6;
public const int PRIM_SIZE = 7;
public const int PRIM_ROTATION = 8;
public const int PRIM_TYPE = 9;
public const int PRIM_TEXTURE = 17;
public const int PRIM_COLOR = 18;
public const int PRIM_BUMP_SHINY = 19;
public const int PRIM_FULLBRIGHT = 20;
public const int PRIM_FLEXIBLE = 21;
public const int PRIM_TEXGEN = 22;
public const int PRIM_TEXGEN_DEFAULT = 0;
public const int PRIM_TEXGEN_PLANAR = 1;
public const int PRIM_TYPE_BOX = 0;
public const int PRIM_TYPE_CYLINDER = 1;
public const int PRIM_TYPE_PRISM = 2;
public const int PRIM_TYPE_SPHERE = 3;
public const int PRIM_TYPE_TORUS = 4;
public const int PRIM_TYPE_TUBE = 5;
public const int PRIM_TYPE_RING = 6;
public const int PRIM_HOLE_DEFAULT = 0;
public const int PRIM_HOLE_CIRCLE = 16;
public const int PRIM_HOLE_SQUARE = 32;
public const int PRIM_HOLE_TRIANGLE = 48;
public const int PRIM_MATERIAL_STONE = 0;
public const int PRIM_MATERIAL_METAL = 1;
public const int PRIM_MATERIAL_GLASS = 2;
public const int PRIM_MATERIAL_WOOD = 3;
public const int PRIM_MATERIAL_FLESH = 4;
public const int PRIM_MATERIAL_PLASTIC = 5;
public const int PRIM_MATERIAL_RUBBER = 6;
public const int PRIM_MATERIAL_LIGHT = 7;
public const int PRIM_SHINY_NONE = 0;
public const int PRIM_SHINY_LOW = 1;
public const int PRIM_SHINY_MEDIUM = 2;
public const int PRIM_SHINY_HIGH = 3;
public const int PRIM_BUMP_NONE = 0;
public const int PRIM_BUMP_BRIGHT = 1;
public const int PRIM_BUMP_DARK = 2;
public const int PRIM_BUMP_WOOD = 3;
public const int PRIM_BUMP_BARK = 4;
public const int PRIM_BUMP_BRICKS = 5;
public const int PRIM_BUMP_CHECKER = 6;
public const int PRIM_BUMP_CONCRETE = 7;
public const int PRIM_BUMP_TILE = 8;
public const int PRIM_BUMP_STONE = 9;
public const int PRIM_BUMP_DISKS = 10;
public const int PRIM_BUMP_GRAVEL = 11;
public const int PRIM_BUMP_BLOBS = 12;
public const int PRIM_BUMP_SIDING = 13;
public const int PRIM_BUMP_LARGETILE = 14;
public const int PRIM_BUMP_STUCCO = 15;
public const int PRIM_BUMP_SUCTION = 16;
public const int PRIM_BUMP_WEAVE = 17;
public const int MASK_BASE = 0;
public const int MASK_OWNER = 1;
public const int MASK_GROUP = 2;
public const int MASK_EVERYONE = 3;
public const int MASK_NEXT = 4;
public const int PERM_TRANSFER = 8192;
public const int PERM_MODIFY = 16384;
public const int PERM_COPY = 32768;
public const int PERM_MOVE = 524288;
public const int PERM_ALL = 2147483647;
public const int PARCEL_MEDIA_COMMAND_STOP = 0;
public const int PARCEL_MEDIA_COMMAND_PAUSE = 1;
public const int PARCEL_MEDIA_COMMAND_PLAY = 2;
public const int PARCEL_MEDIA_COMMAND_LOOP = 3;
public const int PARCEL_MEDIA_COMMAND_TEXTURE = 4;
public const int PARCEL_MEDIA_COMMAND_URL = 5;
public const int PARCEL_MEDIA_COMMAND_TIME = 6;
public const int PARCEL_MEDIA_COMMAND_AGENT = 7;
public const int PARCEL_MEDIA_COMMAND_UNLOAD = 8;
public const int PARCEL_MEDIA_COMMAND_AUTO_ALIGN = 9;
public const int PAY_HIDE = -1;
public const int PAY_DEFAULT = -2;
public const string NULL_KEY = "00000000-0000-0000-0000-000000000000";
public const string EOF = "\n\n\n";
public const double PI = 3.14159274f;
public const double TWO_PI = 6.28318548f;
public const double PI_BY_TWO = 1.57079637f;
public const double DEG_TO_RAD = 0.01745329238f;
public const double RAD_TO_DEG = 57.29578f;
public const double SQRT2 = 1.414213538f;
// Can not be public const?
public LSL_Types.Vector3 ZERO_VECTOR = new LSL_Types.Vector3(0, 0, 0);
public LSL_Types.Quaternion ZERO_ROTATION = new LSL_Types.Quaternion(0, 0, 0, 0);
}
}

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public static class Common
{
static public bool Debug = true;
static public bool IL_UseTryCatch = true;
static public bool IL_CreateConstructor = true;
static public bool IL_CreateFunctionList = true;
static public bool IL_ProcessCodeChunks = true;
public delegate void SendToDebugEventDelegate(string Message);
public delegate void SendToLogEventDelegate(string Message);
static public event SendToDebugEventDelegate SendToDebugEvent;
static public event SendToLogEventDelegate SendToLogEvent;
static public void SendToDebug(string Message)
{
//if (Debug == true)
Console.WriteLine("COMPILER:Debug: " + Message);
SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
}
static public void SendToLog(string Message)
{
//if (Debug == true)
Console.WriteLine("COMPILER:LOG: " + Message);
SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
}
}
// TEMPORARY TEST THINGIES
public static class IL_Helper
{
public static string ReverseFormatString(string text1, string format)
{
Common.SendToDebug("ReverseFormatString text1: " + text1);
Common.SendToDebug("ReverseFormatString format: " + format);
return string.Format(format, text1);
}
public static string ReverseFormatString(string text1, UInt32 text2, string format)
{
Common.SendToDebug("ReverseFormatString text1: " + text1);
Common.SendToDebug("ReverseFormatString text2: " + text2.ToString());
Common.SendToDebug("ReverseFormatString format: " + format);
return string.Format(format, text1, text2.ToString());
}
public static string Cast_ToString(object obj)
{
Common.SendToDebug("OBJECT TO BE CASTED: " + obj.GetType().ToString());
return "ABCDEFGIHJKLMNOPQ123";
}
}
}

View File

@ -0,0 +1,300 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Reflection;
using System.Reflection.Emit;
using System.Threading;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public class Engine
{
//private string LSO_FileName = @"LSO\AdditionTest.lso";
private string LSO_FileName;// = @"LSO\CloseToDefault.lso";
AppDomain appDomain;
public string Compile(string LSOFileName)
{
LSO_FileName = LSOFileName;
//appDomain = AppDomain.CreateDomain("AlternateAppDomain");
appDomain = Thread.GetDomain();
// Create Assembly Name
AssemblyName asmName = new AssemblyName();
asmName.Name = System.IO.Path.GetFileNameWithoutExtension(LSO_FileName);
//asmName.Name = "TestAssembly";
string DLL_FileName = asmName.Name + ".dll";
string DLL_FileName_WithPath = System.IO.Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName;
Common.SendToLog("LSO File Name: " + System.IO.Path.GetFileName(LSO_FileName));
Common.SendToLog("Assembly name: " + asmName.Name);
Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll");
Common.SendToLog("Starting processing of LSL ByteCode...");
Common.SendToLog("");
// Create Assembly
AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(
asmName,
AssemblyBuilderAccess.RunAndSave
);
//// Create Assembly
//AssemblyBuilder asmBuilder =
// Thread.GetDomain().DefineDynamicAssembly
//(asmName, AssemblyBuilderAccess.RunAndSave);
// Create a module (and save to disk)
ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
(asmName.Name,
DLL_FileName);
//Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\"");
// Create a Class (/Type)
TypeBuilder typeBuilder = modBuilder.DefineType(
"LSL_ScriptObject",
TypeAttributes.Public | TypeAttributes.BeforeFieldInit,
typeof(OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass));
//,
// typeof());
//, typeof(LSL_BuiltIn_Commands_Interface));
//,
// typeof(object),
// new Type[] { typeof(LSL_CLRInterface.LSLScript) });
/*
* Generate the IL itself
*/
LSO_Parser LSOP = new LSO_Parser(LSO_FileName, typeBuilder);
LSOP.OpenFile();
LSOP.Parse();
// Constructor has to be created AFTER LSO_Parser because of accumulated variables
if (Common.IL_CreateConstructor)
IL_CREATE_CONSTRUCTOR(typeBuilder, LSOP);
LSOP.CloseFile();
/*
* Done generating. Create a type and run it.
*/
Common.SendToLog("Attempting to compile assembly...");
// Compile it
Type type = typeBuilder.CreateType();
Common.SendToLog("Compilation successful!");
Common.SendToLog("Saving assembly: " + DLL_FileName);
asmBuilder.Save(DLL_FileName);
Common.SendToLog("Returning assembly filename: " + DLL_FileName);
return DLL_FileName;
//Common.SendToLog("Creating an instance of new assembly...");
//// Create an instance we can play with
////LSLScript hello = (LSLScript)Activator.CreateInstance(type);
////LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
//object MyScript = (object)Activator.CreateInstance(type);
//System.Reflection.MemberInfo[] Members = type.GetMembers();
//Common.SendToLog("Members of assembly " + type.ToString() + ":");
//foreach (MemberInfo member in Members)
// Common.SendToLog(member.ToString());
//// Play with it
////MyScript.event_state_entry("Test");
//object[] args = { null };
////System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
//string[] ret = { };
//if (Common.IL_CreateFunctionList)
// ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
//foreach (string s in ret)
//{
// Common.SendToLog("");
// Common.SendToLog("*** Executing LSL Server Event: " + s);
// //object test = type.GetMember(s);
// //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args);
// //runner();
// //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null);
// type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" });
//}
}
private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP)
{
Common.SendToDebug("IL_CREATE_CONSTRUCTOR()");
//ConstructorBuilder constructor = typeBuilder.DefineConstructor(
// MethodAttributes.Public,
// CallingConventions.Standard,
// new Type[0]);
ConstructorBuilder constructor = typeBuilder.DefineConstructor(
MethodAttributes.Public |
MethodAttributes.SpecialName |
MethodAttributes.RTSpecialName,
CallingConventions.Standard,
new Type[0]);
//Define the reflection ConstructorInfor for System.Object
ConstructorInfo conObj = typeof(LSL_BaseClass).GetConstructor(new Type[0]);
//call constructor of base object
ILGenerator il = constructor.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, conObj);
//Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;");
//string FieldName;
//// Create state object
//FieldName = "State";
//FieldBuilder State_fb = typeBuilder.DefineField(
// FieldName,
// typeof(UInt32),
// FieldAttributes.Public);
//il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Ldc_I4, 0);
//il.Emit(OpCodes.Stfld, State_fb);
//Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();");
////Type objType1 = typeof(object);
//Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation);
//FieldName = "LSL_BuiltIns";
//FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField(
// FieldName,
// objType1,
// FieldAttributes.Public);
////LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation();
//il.Emit(OpCodes.Ldarg_0);
////il.Emit(OpCodes.Ldstr, "Test 123");
//il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { }));
//il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb);
foreach (UInt32 pos in LSOP.StaticBlocks.Keys)
{
LSO_Struct.StaticBlock sb;
LSOP.StaticBlocks.TryGetValue(pos, out sb);
if (sb.ObjectType > 0 && sb.ObjectType < 8) { // We don't want void or null's
il.Emit(OpCodes.Ldarg_0);
// Push position to stack
il.Emit(OpCodes.Ldc_I4, pos);
//il.Emit(OpCodes.Box, typeof(UInt32));
Type datatype = null;
// Push data to stack
Common.SendToDebug("Adding to static (" + pos + ") type: " + ((LSO_Enums.Variable_Type_Codes)sb.ObjectType).ToString() + " (" + sb.ObjectType + ")");
switch ((LSO_Enums.Variable_Type_Codes)sb.ObjectType)
{
case LSO_Enums.Variable_Type_Codes.Float:
case LSO_Enums.Variable_Type_Codes.Integer:
//UInt32
il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0));
datatype = typeof(UInt32);
il.Emit(OpCodes.Box, datatype);
break;
case LSO_Enums.Variable_Type_Codes.String:
case LSO_Enums.Variable_Type_Codes.Key:
//String
LSO_Struct.HeapBlock hb = LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1);
il.Emit(OpCodes.Ldstr, System.Text.Encoding.UTF8.GetString(hb.Data));
datatype = typeof(string);
break;
case LSO_Enums.Variable_Type_Codes.Vector:
datatype = typeof(LSO_Enums.Vector);
//TODO: Not implemented
break;
case LSO_Enums.Variable_Type_Codes.Rotation:
//Object
//TODO: Not implemented
datatype = typeof(LSO_Enums.Rotation);
break;
default:
datatype = typeof(object);
break;
}
// Make call
il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddToStatic", new Type[] { typeof(UInt32), datatype }));
}
}
////il.Emit(OpCodes.Newobj, typeof(UInt32));
//il.Emit(OpCodes.Starg_0);
//// Create LSL function library
//FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public);
//il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface));
//il.Emit(OpCodes.Stloc_1);
il.Emit(OpCodes.Ret);
}
// End of class
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
partial class LSO_Parser
{
private static TypeBuilder CreateType(ModuleBuilder modBuilder, string typeName)
{
TypeBuilder typeBuilder = modBuilder.DefineType(typeName,
TypeAttributes.Public |
TypeAttributes.Class |
TypeAttributes.AutoClass |
TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout,
typeof(object),
new Type[] { typeof(object) });
return typeBuilder;
}
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler;
using OpenSim.Region.ScriptEngine.Common;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public partial class LSL_BaseClass
{
//public MemoryStream LSLStack = new MemoryStream();
public Stack<object> LSLStack = new Stack<object>();
public Dictionary<UInt32, object> StaticVariables = new Dictionary<UInt32, object>();
public Dictionary<UInt32, object> GlobalVariables = new Dictionary<UInt32, object>();
public Dictionary<UInt32, object> LocalVariables = new Dictionary<UInt32, object>();
//public System.Collections.Generic.List<string> FunctionList = new System.Collections.Generic.List<string>();
//public void AddFunction(String x) {
// FunctionList.Add(x);
//}
//public Stack<StackItemStruct> LSLStack = new Stack<StackItemStruct>;
//public struct StackItemStruct
//{
// public LSO_Enums.Variable_Type_Codes ItemType;
// public object Data;
//}
public UInt32 State = 0;
public LSL_BuiltIn_Commands_Interface LSL_Builtins;
public LSL_BuiltIn_Commands_Interface GetLSL_BuiltIn()
{
return LSL_Builtins;
}
public LSL_BaseClass() { }
public virtual int OverrideMe()
{
return 0;
}
public void Start(LSL_BuiltIn_Commands_Interface LSLBuiltins)
{
LSL_Builtins = LSLBuiltins;
Common.SendToLog("OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO.LSL_BaseClass.Start() called");
//LSL_Builtins.llSay(0, "Test");
return;
}
public void AddToStatic(UInt32 index, object obj)
{
Common.SendToDebug("AddToStatic: " + index + " type: " + obj.GetType());
StaticVariables.Add(index, obj);
}
}
}

View File

@ -0,0 +1,373 @@
//using System;
//using System.Collections.Generic;
//using System.Text;
//namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
//{
// public partial class LSL_BaseClass
// {
// public float llSin() {
// float f = (float)LSLStack.Pop();
// return LSL_Builtins.llSin(f);
// }
// public float llCos() {
// float f = (float)LSLStack.Pop();
// return LSL_Builtins.llCos(f);
// }
// public float llTan() {
// float f = (float)LSLStack.Pop();
// return LSL_Builtins.llTan(f);
// }
// public float llAtan2() {
// float x = (float)LSLStack.Pop();
// float y = (float)LSLStack.Pop();
// return LSL_Builtins.llAtan2(x, y);
// }
// public float llSqrt() {
// float f = (float)LSLStack.Pop();
// return LSL_Builtins.llSqrt(f);
// }
// float llPow()
// {
// float fexponent = (float)LSLStack.Pop();
// float fbase = (float)LSLStack.Pop();
// return LSL_Builtins.llPow(fbase, fexponent);
// }
// //UInt32 llAbs(UInt32 i){ return; }
// //float llFabs(float f){ return; }
// //float llFrand(float mag){ return; }
// //UInt32 llFloor(float f){ return; }
// //UInt32 llCeil(float f){ return; }
// //UInt32 llRound(float f){ return; }
// //float llVecMag(LSO_Enums.Vector v){ return; }
// //LSO_Enums.Vector llVecNorm(LSO_Enums.Vector v){ return; }
// //float llVecDist(LSO_Enums.Vector a, LSO_Enums.Vector b){ return; }
// //LSO_Enums.Vector llRot2Euler(LSO_Enums.Rotation r){ return; }
// //LSO_Enums.Rotation llEuler2Rot(LSO_Enums.Vector v){ return; }
// //LSO_Enums.Rotation llAxes2Rot(LSO_Enums.Vector fwd, LSO_Enums.Vector left, LSO_Enums.Vector up){ return; }
// //LSO_Enums.Vector llRot2Fwd(LSO_Enums.Rotation r){ return; }
// //LSO_Enums.Vector llRot2Left(LSO_Enums.Rotation r){ return; }
// //LSO_Enums.Vector llRot2Up(LSO_Enums.Rotation r){ return; }
// //LSO_Enums.Rotation llRotBetween(LSO_Enums.Vector start, LSO_Enums.Vector end){ return; }
// public void llWhisper()
// {
// UInt16 i = (UInt16)LSLStack.Pop();
// string s = (string)LSLStack.Pop();
// LSL_Builtins.llWhisper(i, s);
// }
// public void llSay()
// {
// UInt16 i = (UInt16)LSLStack.Pop();
// string s = (string)LSLStack.Pop();
// LSL_Builtins.llSay(i, s);
// }
// //void llShout(UInt16 channelID, string text);
// //UInt32 llListen(UInt16 channelID, string name, LSO_Enums.Key ID, string msg);
// //void llListenControl(UInt32 number, UInt32 active);
// //void llListenRemove(UInt32 number);
// //void llSensor(string name, LSO_Enums.Key id, UInt32 type, float range, float arc);
// //void llSensorRepeat(string name, LSO_Enums.Key id, UInt32 type, float range, float arc, float rate);
// //void llSensorRemove();
// //string llDetectedName(UInt32 number);
// //LSO_Enums.Key llDetectedKey(UInt32 number);
// //LSO_Enums.Key llDetectedOwner(UInt32 number);
// //UInt32 llDetectedType(UInt32 number);
// //LSO_Enums.Vector llDetectedPos(UInt32 number);
// //LSO_Enums.Vector llDetectedVel(UInt32 number);
// //LSO_Enums.Vector llDetectedGrab(UInt32 number);
// //LSO_Enums.Rotation llDetectedRot(UInt32 number);
// //UInt32 llDetectedGroup(UInt32 number);
// //UInt32 llDetectedLinkNumber(UInt32 number);
// //void llDie();
// //float llGround(LSO_Enums.Vector offset);
// //float llCloud(LSO_Enums.Vector offset);
// //LSO_Enums.Vector llWind(LSO_Enums.Vector offset);
// //void llSetStatus(UInt32 status, UInt32 value);
// //UInt32 llGetStatus(UInt32 status);
// //void llSetScale(LSO_Enums.Vector scale);
// //LSO_Enums.Vector llGetScale();
// //void llSetColor();
// //float llGetAlpha();
// //void llSetAlpha();
// //LSO_Enums.Vector llGetColor();
// //void llSetTexture();
// //void llScaleTexture();
// //void llOffsetTexture();
// //void llRotateTexture();
// //string llGetTexture();
// //void llSetPos();
// public void llGetPos() { }
// public void llGetLocalPos() { }
// public void llSetRot() { }
// public void llGetRot() { }
// public void llGetLocalRot() { }
// public void llSetForce() { }
// public void llGetForce() { }
// public void llTarget() { }
// public void llTargetRemove() { }
// public void llRotTarget() { }
// public void llRotTargetRemove() { }
// public void llMoveToTarget() { }
// public void llStopMoveToTarget() { }
// public void llApplyImpulse() { }
// public void llApplyRotationalImpulse() { }
// public void llSetTorque() { }
// public void llGetTorque() { }
// public void llSetForceAndTorque() { }
// public void llGetVel() { }
// public void llGetAccel() { }
// public void llGetOmega() { }
// public void llGetTimeOfDay() { }
// public void llGetWallclock() { }
// public void llGetTime() { }
// public void llResetTime() { }
// public void llGetAndResetTime() { }
// public void llSound() { }
// public void llPlaySound() { }
// public void llLoopSound() { }
// public void llLoopSoundMaster() { }
// public void llLoopSoundSlave() { }
// public void llPlaySoundSlave() { }
// public void llTriggerSound() { }
// public void llStopSound() { }
// public void llPreloadSound() { }
// public void llGetSubString() { }
// public void llDeleteSubString() { }
// public void llInsertString() { }
// public void llToUpper() { }
// public void llToLower() { }
// public void llGiveMoney() { }
// public void llMakeExplosion() { }
// public void llMakeFountain() { }
// public void llMakeSmoke() { }
// public void llMakeFire() { }
// public void llRezObject() { }
// public void llLookAt() { }
// public void llStopLookAt() { }
// public void llSetTimerEvent() { }
// public void llSleep() { }
// public void llGetMass() { }
// public void llCollisionFilter() { }
// public void llTakeControls() { }
// public void llReleaseControls() { }
// public void llAttachToAvatar() { }
// public void llDetachFromAvatar() { }
// public void llTakeCamera() { }
// public void llReleaseCamera() { }
// public void llGetOwner() { }
// public void llInstantMessage() { }
// public void llEmail() { }
// public void llGetNextEmail() { }
// public void llGetKey() { }
// public void llSetBuoyancy() { }
// public void llSetHoverHeight() { }
// public void llStopHover() { }
// public void llMinEventDelay() { }
// public void llSoundPreload() { }
// public void llRotLookAt() { }
// public void llStringLength() { }
// public void llStartAnimation() { }
// public void llStopAnimation() { }
// public void llPointAt() { }
// public void llStopPointAt() { }
// public void llTargetOmega() { }
// public void llGetStartParameter() { }
// public void llGodLikeRezObject() { }
// public void llRequestPermissions() { }
// public void llGetPermissionsKey() { }
// public void llGetPermissions() { }
// public void llGetLinkNumber() { }
// public void llSetLinkColor() { }
// public void llCreateLink() { }
// public void llBreakLink() { }
// public void llBreakAllLinks() { }
// public void llGetLinkKey() { }
// public void llGetLinkName() { }
// public void llGetInventoryNumber() { }
// public void llGetInventoryName() { }
// public void llSetScriptState() { }
// public void llGetEnergy() { }
// public void llGiveInventory() { }
// public void llRemoveInventory() { }
// public void llSetText() { }
// public void llWater() { }
// public void llPassTouches() { }
// public void llRequestAgentData() { }
// public void llRequestInventoryData() { }
// public void llSetDamage() { }
// public void llTeleportAgentHome() { }
// public void llModifyLand() { }
// public void llCollisionSound() { }
// public void llCollisionSprite() { }
// public void llGetAnimation() { }
// public void llResetScript() { }
// public void llMessageLinked() { }
// public void llPushObject() { }
// public void llPassCollisions() { }
// public void llGetScriptName() { }
// public void llGetNumberOfSides() { }
// public void llAxisAngle2Rot() { }
// public void llRot2Axis() { }
// public void llRot2Angle() { }
// public void llAcos() { }
// public void llAsin() { }
// public void llAngleBetween() { }
// public void llGetInventoryKey() { }
// public void llAllowInventoryDrop() { }
// public void llGetSunDirection() { }
// public void llGetTextureOffset() { }
// public void llGetTextureScale() { }
// public void llGetTextureRot() { }
// public void llSubStringIndex() { }
// public void llGetOwnerKey() { }
// public void llGetCenterOfMass() { }
// public void llListSort() { }
// public void llGetListLength() { }
// public void llList2Integer() { }
// public void llList2Float() { }
// public void llList2String() { }
// public void llList2Key() { }
// public void llList2Vector() { }
// public void llList2Rot() { }
// public void llList2List() { }
// public void llDeleteSubList() { }
// public void llGetListEntryType() { }
// public void llList2CSV() { }
// public void llCSV2List() { }
// public void llListRandomize() { }
// public void llList2ListStrided() { }
// public void llGetRegionCorner() { }
// public void llListInsertList() { }
// public void llListFindList() { }
// public void llGetObjectName() { }
// public void llSetObjectName() { }
// public void llGetDate() { }
// public void llEdgeOfWorld() { }
// public void llGetAgentInfo() { }
// public void llAdjustSoundVolume() { }
// public void llSetSoundQueueing() { }
// public void llSetSoundRadius() { }
// public void llKey2Name() { }
// public void llSetTextureAnim() { }
// public void llTriggerSoundLimited() { }
// public void llEjectFromLand() { }
// public void llParseString2List() { }
// public void llOverMyLand() { }
// public void llGetLandOwnerAt() { }
// public void llGetNotecardLine() { }
// public void llGetAgentSize() { }
// public void llSameGroup() { }
// public void llUnSit() { }
// public void llGroundSlope() { }
// public void llGroundNormal() { }
// public void llGroundContour() { }
// public void llGetAttached() { }
// public void llGetFreeMemory() { }
// public void llGetRegionName() { }
// public void llGetRegionTimeDilation() { }
// public void llGetRegionFPS() { }
// public void llParticleSystem() { }
// public void llGroundRepel() { }
// public void llGiveInventoryList() { }
// public void llSetVehicleType() { }
// public void llSetVehicleFloatParam() { }
// public void llSetVehicleVectorParam() { }
// public void llSetVehicleRotationParam() { }
// public void llSetVehicleFlags() { }
// public void llRemoveVehicleFlags() { }
// public void llSitTarget() { }
// public void llAvatarOnSitTarget() { }
// public void llAddToLandPassList() { }
// public void llSetTouchText() { }
// public void llSetSitText() { }
// public void llSetCameraEyeOffset() { }
// public void llSetCameraAtOffset() { }
// public void llDumpList2String() { }
// public void llScriptDanger() { }
// public void llDialog() { }
// public void llVolumeDetect() { }
// public void llResetOtherScript() { }
// public void llGetScriptState() { }
// public void llRemoteLoadScript() { }
// public void llSetRemoteScriptAccessPin() { }
// public void llRemoteLoadScriptPin() { }
// public void llOpenRemoteDataChannel() { }
// public void llSendRemoteData() { }
// public void llRemoteDataReply() { }
// public void llCloseRemoteDataChannel() { }
// public void llMD5String() { }
// public void llSetPrimitiveParams() { }
// public void llStringToBase64() { }
// public void llBase64ToString() { }
// public void llXorBase64Strings() { }
// public void llRemoteDataSetRegion() { }
// public void llLog10() { }
// public void llLog() { }
// public void llGetAnimationList() { }
// public void llSetParcelMusicURL() { }
// public void llGetRootPosition() { }
// public void llGetRootRotation() { }
// public void llGetObjectDesc() { }
// public void llSetObjectDesc() { }
// public void llGetCreator() { }
// public void llGetTimestamp() { }
// public void llSetLinkAlpha() { }
// public void llGetNumberOfPrims() { }
// public void llGetNumberOfNotecardLines() { }
// public void llGetBoundingBox() { }
// public void llGetGeometricCenter() { }
// public void llGetPrimitiveParams() { }
// public void llIntegerToBase64() { }
// public void llBase64ToInteger() { }
// public void llGetGMTclock() { }
// public void llGetSimulatorHostname() { }
// public void llSetLocalRot() { }
// public void llParseStringKeepNulls() { }
// public void llRezAtRoot() { }
// public void llGetObjectPermMask() { }
// public void llSetObjectPermMask() { }
// public void llGetInventoryPermMask() { }
// public void llSetInventoryPermMask() { }
// public void llGetInventoryCreator() { }
// public void llOwnerSay() { }
// public void llRequestSimulatorData() { }
// public void llForceMouselook() { }
// public void llGetObjectMass() { }
// public void llListReplaceList() { }
// public void llLoadURL() { }
// public void llParcelMediaCommandList() { }
// public void llParcelMediaQuery() { }
// public void llModPow() { }
// public void llGetInventoryType() { }
// public void llSetPayPrice() { }
// public void llGetCameraPos() { }
// public void llGetCameraRot() { }
// public void llSetPrimURL() { }
// public void llRefreshPrimURL() { }
// public void llEscapeURL() { }
// public void llUnescapeURL() { }
// public void llMapDestination() { }
// public void llAddToLandBanList() { }
// public void llRemoveFromLandPassList() { }
// public void llRemoveFromLandBanList() { }
// public void llSetCameraParams() { }
// public void llClearCameraParams() { }
// public void llListStatistics() { }
// public void llGetUnixTime() { }
// public void llGetParcelFlags() { }
// public void llGetRegionFlags() { }
// public void llXorBase64StringsCorrect() { }
// public void llHTTPRequest() { }
// public void llResetLandBanList() { }
// public void llResetLandPassList() { }
// public void llGetParcelPrimCount() { }
// public void llGetParcelPrimOwners() { }
// public void llGetObjectPrimCount() { }
// public void llGetParcelMaxPrims() { }
// public void llGetParcelDetails() { }
// }
//}

View File

@ -0,0 +1,350 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public partial class LSL_BaseClass
{
/*
* OPCODES
*
* These are internal "assembly" commands,
* basic operators like "ADD", "PUSH" and "POP"
*
* It also contains managed stack and keeps track of internal variables, etc.
*
*/
public void StoreToLocal(UInt32 index)
{
// TODO: How to determine local?
Common.SendToDebug("::StoreToLocal " + index);
if (LocalVariables.ContainsKey(index))
LocalVariables.Remove(index);
LocalVariables.Add(index, LSLStack.Peek());
}
public void StoreToGlobal(UInt32 index)
{
Common.SendToDebug("::StoreToGlobal " + index);
if (GlobalVariables.ContainsKey(index))
GlobalVariables.Remove(index);
GlobalVariables.Add(index, LSLStack.Peek());
}
public void StoreToStatic(UInt32 index)
{
Common.SendToDebug("::StoreToStatic " + index);
//if (StaticVariables.ContainsKey(index))
// StaticVariables.Remove(index);
StaticVariables.Add(index, LSLStack.Peek());
}
public void GetFromLocal(UInt32 index)
{
// TODO: How to determine local?
Common.SendToDebug("::GetFromLocal " + index);
object ret;
LocalVariables.TryGetValue(index, out ret);
LSLStack.Push(ret);
//return ret;
}
public void GetFromGlobal(UInt32 index)
{
Common.SendToDebug("::GetFromGlobal " + index);
object ret;
GlobalVariables.TryGetValue(index, out ret);
LSLStack.Push(ret);
//return ret;
}
public void GetFromStatic(UInt32 index)
{
Common.SendToDebug("::GetFromStatic " + index);
object ret;
StaticVariables.TryGetValue(index, out ret);
Common.SendToDebug("::GetFromStatic - ObjectType: " + ret.GetType().ToString());
LSLStack.Push(ret);
//return ret;
}
public object POPToStack()
{
Common.SendToDebug("::POPToStack");
//return LSLStack.Pop();
object p = LSLStack.Pop();
if (p.GetType() == typeof(UInt32))
return (UInt32)p;
if (p.GetType() == typeof(string))
return (string)p;
if (p.GetType() == typeof(Int32))
return (Int32)p;
if (p.GetType() == typeof(UInt16))
return (UInt16)p;
if (p.GetType() == typeof(float))
return (float)p;
if (p.GetType() == typeof(LSO_Enums.Vector))
return (LSO_Enums.Vector)p;
if (p.GetType() == typeof(LSO_Enums.Rotation))
return (LSO_Enums.Rotation)p;
if (p.GetType() == typeof(LSO_Enums.Key))
return (LSO_Enums.Key)p;
return p;
}
//public object POPToStack(UInt32 count)
//{
// // POP NUMBER FROM TOP OF STACK
// //LSLStack.SetLength(LSLStack.Length - 4);
// Common.SendToDebug("::POPToStack " + count);
// if (count < 2)
// return LSLStack.Pop();
// Stack<object> s = new Stack<object>();
// for (int i = 0; i < count; i++)
// {
// s.Push(LSLStack.Pop);
// }
//}
public void POP()
{
// POP NUMBER FROM TOP OF STACK
//LSLStack.SetLength(LSLStack.Length - 4);
Common.SendToDebug("::POP");
if (LSLStack.Count < 1)
{
//TODO: Temporary fix
Common.SendToDebug("ERROR: TRYING TO POP EMPTY STACK!");
}
else
{
LSLStack.Pop();
}
}
public void PUSH(object Param)
{
if (Param == null)
{
Common.SendToDebug("::PUSH: <null>");
}
else
{
//Common.SendToDebug("::PUSH: " + Param.GetType());
}
LSLStack.Push(Param);
}
public void ADD(UInt32 Param)
{
Common.SendToDebug("::ADD: " + Param);
object o2 = LSLStack.Pop();
object o1 = LSLStack.Pop();
Common.SendToDebug("::ADD: Debug: o1: " + o1.GetType() + " (" + o1.ToString() + "), o2: " + o2.GetType() + " (" + o2.ToString() + ")");
if (o2.GetType() == typeof(string))
{
LSLStack.Push((string)o1 + (string)o2);
return;
}
if (o2.GetType() == typeof(UInt32))
{
LSLStack.Push((UInt32)o1 + (UInt32)o2);
return;
}
}
public void SUB(UInt32 Param)
{
Common.SendToDebug("::SUB: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 - i2));
}
public void MUL(UInt32 Param)
{
Common.SendToDebug("::SUB: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 * i2));
}
public void DIV(UInt32 Param)
{
Common.SendToDebug("::DIV: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 / i2));
}
public void MOD(UInt32 Param)
{
Common.SendToDebug("::MOD: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 % i2));
}
public void EQ(UInt32 Param)
{
Common.SendToDebug("::EQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 == i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void NEQ(UInt32 Param)
{
Common.SendToDebug("::NEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 != i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void LEQ(UInt32 Param)
{
Common.SendToDebug("::LEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 <= i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void GEQ(UInt32 Param)
{
Common.SendToDebug("::GEQ: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 >= i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void LESS(UInt32 Param)
{
Common.SendToDebug("::LESS: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 < i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void GREATER(UInt32 Param)
{
Common.SendToDebug("::GREATER: " + Param);
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
if (i1 > i2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void BITAND()
{
Common.SendToDebug("::BITAND");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 & i2));
}
public void BITOR()
{
Common.SendToDebug("::BITOR");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 | i2));
}
public void BITXOR()
{
Common.SendToDebug("::BITXOR");
UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 ^ i2));
}
public void BOOLAND()
{
Common.SendToDebug("::BOOLAND");
bool b2 = bool.Parse((string)LSLStack.Pop());
bool b1 = bool.Parse((string)LSLStack.Pop());
if (b1 && b2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void BOOLOR()
{
Common.SendToDebug("::BOOLOR");
bool b2 = bool.Parse((string)LSLStack.Pop());
bool b1 = bool.Parse((string)LSLStack.Pop());
if (b1 || b2)
{
LSLStack.Push((UInt32)1);
}
else
{
LSLStack.Push((UInt32)0);
}
}
public void NEG(UInt32 Param)
{
Common.SendToDebug("::NEG: " + Param);
//UInt32 i2 = (UInt32)LSLStack.Pop();
UInt32 i1 = (UInt32)LSLStack.Pop();
LSLStack.Push((UInt32)(i1 * -1));
}
public void BITNOT()
{
//Common.SendToDebug("::BITNOT");
//UInt32 i2 = (UInt32)LSLStack.Pop();
//UInt32 i1 = (UInt32)LSLStack.Pop();
//LSLStack.Push((UInt32)(i1 / i2));
}
public void BOOLNOT()
{
//Common.SendToDebug("::BOOLNOT");
////UInt32 i2 = (UInt32)LSLStack.Pop();
//UInt32 i1 = (UInt32)LSLStack.Pop();
//LSLStack.Push((UInt32)(i1));
}
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public class LSL_CLRInterface
{
public interface LSLScript
{
//public virtual void Run(object arg)
//{
//}
//void Run(object arg);
//void event_state_entry(object arg);
//void event_state_exit();
//void event_touch_start(object arg);
//void event_touch();
//void event_touch_end();
//void event_collision_start();
//void event_collision();
//void event_collision_end();
//void event_land_collision_start();
//void event_land_collision();
//void event_land_collision_end();
//void event_timer();
//void event_listen();
//void event_on_rez();
//void event_sensor();
//void event_no_sensor();
//void event_control();
//void event_money();
//void event_email();
//void event_at_target();
//void event_not_at_target();
//void event_at_rot_target();
//void event_not_at_rot_target();
//void event_run_time_permissions();
//void event_changed();
//void event_attach();
//void event_dataserver();
//void event_link_message();
//void event_moving_start();
//void event_moving_end();
//void event_object_rez();
//void event_remote_data();
//void event_http_response();
}
}
}

View File

@ -0,0 +1,436 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using OpenSim.Region.ScriptEngine.Common;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
partial class LSO_Parser
{
//internal Stack<Type> ILStack = new Stack<Type>();
//LSO_Enums MyLSO_Enums = new LSO_Enums();
internal bool LSL_PROCESS_OPCODE(ILGenerator il)
{
byte bp1;
UInt32 u32p1;
float fp1;
UInt16 opcode = br_read(1)[0];
Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString());
string idesc = ((LSO_Enums.Operation_Table)opcode).ToString();
switch ((LSO_Enums.Operation_Table)opcode)
{
/***************
* IMPLEMENTED *
***************/
case LSO_Enums.Operation_Table.NOOP:
break;
case LSO_Enums.Operation_Table.PUSHSP:
// Push Stack Top (Memory Address) to stack
Common.SendToDebug("Instruction " + idesc);
Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack");
IL_Push(il, (UInt32)myHeader.SP);
break;
// BYTE
case LSO_Enums.Operation_Table.PUSHARGB:
Common.SendToDebug("Param1: " + br_read(1)[0]);
break;
// INTEGER
case LSO_Enums.Operation_Table.PUSHARGI:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1);
IL_Push(il, u32p1);
break;
// FLOAT
case LSO_Enums.Operation_Table.PUSHARGF:
fp1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1);
IL_Push(il, fp1);
break;
// STRING
case LSO_Enums.Operation_Table.PUSHARGS:
string s = Read_String();
Common.SendToDebug("Instruction " + idesc + ", Param1: " + s);
IL_Debug(il, "OPCODE: " + idesc + ":" + s);
IL_Push(il, s);
break;
// VECTOR z,y,x
case LSO_Enums.Operation_Table.PUSHARGV:
LSO_Enums.Vector v = new LSO_Enums.Vector();
v.Z = BitConverter.ToUInt32(br_read(4), 0);
v.Y = BitConverter.ToUInt32(br_read(4), 0);
v.X = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1 Z: " + v.Z);
Common.SendToDebug("Param1 Y: " + v.Y);
Common.SendToDebug("Param1 X: " + v.X);
IL_Push(il, v);
break;
// ROTATION s,z,y,x
case LSO_Enums.Operation_Table.PUSHARGQ:
LSO_Enums.Rotation r = new LSO_Enums.Rotation();
r.S = BitConverter.ToUInt32(br_read(4), 0);
r.Z = BitConverter.ToUInt32(br_read(4), 0);
r.Y = BitConverter.ToUInt32(br_read(4), 0);
r.X = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1 S: " + r.S);
Common.SendToDebug("Param1 Z: " + r.Z);
Common.SendToDebug("Param1 Y: " + r.Y);
Common.SendToDebug("Param1 X: " + r.X);
IL_Push(il, r);
break;
case LSO_Enums.Operation_Table.PUSHE:
IL_Push(il, (UInt32)0);
break;
case LSO_Enums.Operation_Table.PUSHARGE:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1);
//IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1)));
IL_Push(il, u32p1);
break;
// BYTE
case LSO_Enums.Operation_Table.ADD:
case LSO_Enums.Operation_Table.SUB:
case LSO_Enums.Operation_Table.MUL:
case LSO_Enums.Operation_Table.DIV:
case LSO_Enums.Operation_Table.EQ:
case LSO_Enums.Operation_Table.NEQ:
case LSO_Enums.Operation_Table.LEQ:
case LSO_Enums.Operation_Table.GEQ:
case LSO_Enums.Operation_Table.LESS:
case LSO_Enums.Operation_Table.GREATER:
case LSO_Enums.Operation_Table.NEG:
case LSO_Enums.Operation_Table.MOD:
bp1 = br_read(1)[0];
Common.SendToDebug("Param1: " + bp1);
IL_CallBaseFunction(il, idesc, (UInt32)bp1);
break;
// NO ARGUMENTS
case LSO_Enums.Operation_Table.BITAND:
case LSO_Enums.Operation_Table.BITOR:
case LSO_Enums.Operation_Table.BITXOR:
case LSO_Enums.Operation_Table.BOOLAND:
case LSO_Enums.Operation_Table.BOOLOR:
case LSO_Enums.Operation_Table.BITNOT:
case LSO_Enums.Operation_Table.BOOLNOT:
IL_CallBaseFunction(il, idesc);
break;
// SHORT
case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
// TODO: What is size of short?
UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0);
Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString());
//Common.SendToDebug("Param1: " + U16p1);
string fname = ((LSO_Enums.BuiltIn_Functions)U16p1).ToString();
bool cmdFound = false;
foreach (MethodInfo mi in typeof(LSL_BuiltIn_Commands_Interface).GetMethods())
{
// Found command
if (mi.Name == fname)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] { }));
// Pop required number of items from my stack to .Net stack
IL_PopToStack(il, mi.GetParameters().Length);
il.Emit(OpCodes.Callvirt, mi);
cmdFound = true;
break;
}
}
if (cmdFound == false)
{
Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS");
}
break;
// RETURN
case LSO_Enums.Operation_Table.RETURN:
Common.SendToDebug("OPCODE: RETURN");
return true;
case LSO_Enums.Operation_Table.POP:
case LSO_Enums.Operation_Table.POPS:
case LSO_Enums.Operation_Table.POPL:
case LSO_Enums.Operation_Table.POPV:
case LSO_Enums.Operation_Table.POPQ:
// Pops a specific datatype from the stack
// We just ignore the datatype for now
IL_Pop(il);
break;
// LONG
case LSO_Enums.Operation_Table.STORE:
case LSO_Enums.Operation_Table.STORES:
case LSO_Enums.Operation_Table.STOREL:
case LSO_Enums.Operation_Table.STOREV:
case LSO_Enums.Operation_Table.STOREQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToLocal", u32p1);
break;
case LSO_Enums.Operation_Table.STOREG:
case LSO_Enums.Operation_Table.STOREGS:
case LSO_Enums.Operation_Table.STOREGL:
case LSO_Enums.Operation_Table.STOREGV:
case LSO_Enums.Operation_Table.STOREGQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToGlobal", u32p1);
break;
case LSO_Enums.Operation_Table.LOADP:
case LSO_Enums.Operation_Table.LOADSP:
case LSO_Enums.Operation_Table.LOADLP:
case LSO_Enums.Operation_Table.LOADVP:
case LSO_Enums.Operation_Table.LOADQP:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToLocal", u32p1);
IL_Pop(il);
break;
case LSO_Enums.Operation_Table.LOADGP:
case LSO_Enums.Operation_Table.LOADGSP:
case LSO_Enums.Operation_Table.LOADGLP:
case LSO_Enums.Operation_Table.LOADGVP:
case LSO_Enums.Operation_Table.LOADGQP:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR);
IL_Pop(il);
break;
// PUSH FROM LOCAL FRAME
case LSO_Enums.Operation_Table.PUSH:
case LSO_Enums.Operation_Table.PUSHS:
case LSO_Enums.Operation_Table.PUSHL:
case LSO_Enums.Operation_Table.PUSHV:
case LSO_Enums.Operation_Table.PUSHQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "GetFromLocal", u32p1);
break;
// PUSH FROM STATIC FRAME
case LSO_Enums.Operation_Table.PUSHG:
case LSO_Enums.Operation_Table.PUSHGS:
case LSO_Enums.Operation_Table.PUSHGL:
case LSO_Enums.Operation_Table.PUSHGV:
case LSO_Enums.Operation_Table.PUSHGQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR);
break;
/***********************
* NOT IMPLEMENTED YET *
***********************/
case LSO_Enums.Operation_Table.POPIP:
case LSO_Enums.Operation_Table.POPSP:
case LSO_Enums.Operation_Table.POPSLR:
case LSO_Enums.Operation_Table.POPARG:
case LSO_Enums.Operation_Table.POPBP:
//Common.SendToDebug("Instruction " + idesc + ": Ignored");
Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack (TODO: Only popping 1)");
//Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
IL_Pop(il);
break;
// None
case LSO_Enums.Operation_Table.PUSHIP:
// PUSH INSTRUCTION POINTER
break;
case LSO_Enums.Operation_Table.PUSHBP:
case LSO_Enums.Operation_Table.PUSHEV:
break;
case LSO_Enums.Operation_Table.PUSHEQ:
break;
// LONG
case LSO_Enums.Operation_Table.JUMP:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
break;
// BYTE, LONG
case LSO_Enums.Operation_Table.JUMPIF:
case LSO_Enums.Operation_Table.JUMPNIF:
Common.SendToDebug("Param1: " + br_read(1)[0]);
Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0));
break;
// LONG
case LSO_Enums.Operation_Table.STATE:
bp1 = br_read(1)[0];
//il.Emit(OpCodes.Ld); // Load local variable 0 onto stack
//il.Emit(OpCodes.Ldc_I4, 0); // Push index position
//il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value
//il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
break;
case LSO_Enums.Operation_Table.CALL:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
Common.SendToDebug("ERROR: Function CALL not implemented yet.");
break;
// BYTE
case LSO_Enums.Operation_Table.CAST:
bp1 = br_read(1)[0];
Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1));
Common.SendToDebug("Param1: " + bp1);
switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)
{
case LSO_Enums.OpCode_Cast_TypeDefs.String:
Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());");
break;
default:
Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!");
break;
}
break;
// LONG
case LSO_Enums.Operation_Table.STACKTOS:
case LSO_Enums.Operation_Table.STACKTOL:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
break;
// BYTE
case LSO_Enums.Operation_Table.PRINT:
case LSO_Enums.Operation_Table.CALLLIB:
Common.SendToDebug("Param1: " + br_read(1)[0]);
break;
}
return false;
}
private void IL_PopToStack(ILGenerator il)
{
IL_PopToStack(il, 1);
}
private void IL_PopToStack(ILGenerator il, int count)
{
Common.SendToDebug("IL_PopToStack();");
for (int i = 0; i < count; i++)
{
IL_CallBaseFunction(il, "POPToStack");
//il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Call,
// typeof(LSL_BaseClass).GetMethod("POPToStack",
// new Type[] { }));
}
}
private void IL_Pop(ILGenerator il)
{
Common.SendToDebug("IL_Pop();");
IL_CallBaseFunction(il, "POP");
}
private void IL_Debug(ILGenerator il, string text)
{
il.Emit(OpCodes.Ldstr, text);
il.Emit(OpCodes.Call, typeof(Common).GetMethod("SendToDebug",
new Type[] { typeof(string) }
));
}
private void IL_CallBaseFunction(ILGenerator il, string methodname)
{
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod(methodname, new Type[] { }));
}
private void IL_CallBaseFunction(ILGenerator il, string methodname, object data)
{
il.Emit(OpCodes.Ldarg_0);
if (data.GetType() == typeof(string))
il.Emit(OpCodes.Ldstr, (string)data);
if (data.GetType() == typeof(UInt32))
il.Emit(OpCodes.Ldc_I4, (UInt32)data);
il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod(methodname, new Type[] { data.GetType() }));
}
private void IL_Push(ILGenerator il, object data)
{
il.Emit(OpCodes.Ldarg_0);
Common.SendToDebug("PUSH datatype: " + data.GetType());
IL_PushDataTypeToILStack(il, data);
il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("PUSH", new Type[] { data.GetType() }));
}
private void IL_PushDataTypeToILStack(ILGenerator il, object data)
{
if (data.GetType() == typeof(UInt16))
{
il.Emit(OpCodes.Ldc_I4, (UInt16)data);
il.Emit(OpCodes.Box, data.GetType());
}
if (data.GetType() == typeof(UInt32))
{
il.Emit(OpCodes.Ldc_I4, (UInt32)data);
il.Emit(OpCodes.Box, data.GetType());
}
if (data.GetType() == typeof(Int32))
{
il.Emit(OpCodes.Ldc_I4, (Int32)data);
il.Emit(OpCodes.Box, data.GetType());
}
if (data.GetType() == typeof(float))
{
il.Emit(OpCodes.Ldc_I4, (float)data);
il.Emit(OpCodes.Box, data.GetType());
}
if (data.GetType() == typeof(string))
il.Emit(OpCodes.Ldstr, (string)data);
//if (data.GetType() == typeof(LSO_Enums.Rotation))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data);
//if (data.GetType() == typeof(LSO_Enums.Vector))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data);
//if (data.GetType() == typeof(LSO_Enums.Key))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data);
}
}
}

View File

@ -0,0 +1,557 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
public static class LSO_Enums
{
//public System.Collections.Generic.Dictionary<Byte, Type> OpCode_Add_Types;
//LSO_Enums() {
// OpCode_Add_Types.Add(51, typeof(String));
// OpCode_Add_Types.Add(17, typeof(UInt32));
//}
[Serializable]
public enum OpCode_Add_TypeDefs
{
String = 51,
UInt32 = 17
}
[Serializable]
public enum OpCode_Cast_TypeDefs
{
String = 19
}
[Serializable]
public struct Key
{
public string KeyString;
}
[Serializable]
public struct Vector
{
public UInt32 Z;
public UInt32 Y;
public UInt32 X;
}
[Serializable]
public struct Rotation
{
public UInt32 S;
public UInt32 Z;
public UInt32 Y;
public UInt32 X;
}
[Serializable]
public enum Variable_Type_Codes
{
Void = 0,
Integer = 1,
Float = 2,
String = 3,
Key = 4,
Vector = 5,
Rotation = 6,
List = 7,
Null = 8
}
[Serializable]
public enum Event_Mask_Values
{
state_entry = 0,
state_exit = 1,
touch_start = 2,
touch = 3,
touch_end = 4,
collision_start = 5,
collision = 6,
collision_end = 7,
land_collision_start = 8,
land_collision = 9,
land_collision_end = 10,
timer = 11,
listen = 12,
on_rez = 13,
sensor = 14,
no_sensor = 15,
control = 16,
money = 17,
email = 18,
at_target = 19,
not_at_target = 20,
at_rot_target = 21,
not_at_rot_target = 22,
run_time_permissions = 23,
changed = 24,
attach = 25,
dataserver = 26,
link_message = 27,
moving_start = 28,
moving_end = 29,
object_rez = 30,
remote_data = 31,
http_response = 32
}
[Serializable]
public enum Operation_Table
{
NOOP = 0x0,
POP = 0x1,
POPS = 0x2,
POPL = 0x3,
POPV = 0x4,
POPQ = 0x5,
POPARG = 0x6,
POPIP = 0x7,
POPBP = 0x8,
POPSP = 0x9,
POPSLR = 0xa,
DUP = 0x20,
DUPS = 0x21,
DUPL = 0x22,
DUPV = 0x23,
DUPQ = 0x24,
STORE = 0x30,
STORES = 0x31,
STOREL = 0x32,
STOREV = 0x33,
STOREQ = 0x34,
STOREG = 0x35,
STOREGS = 0x36,
STOREGL = 0x37,
STOREGV = 0x38,
STOREGQ = 0x39,
LOADP = 0x3a,
LOADSP = 0x3b,
LOADLP = 0x3c,
LOADVP = 0x3d,
LOADQP = 0x3e,
LOADGP = 0x3f,
LOADGSP = 0x40,
LOADGLP = 0x41,
LOADGVP = 0x42,
LOADGQP = 0x43,
PUSH = 0x50,
PUSHS = 0x51,
PUSHL = 0x52,
PUSHV = 0x53,
PUSHQ = 0x54,
PUSHG = 0x55,
PUSHGS = 0x56,
PUSHGL = 0x57,
PUSHGV = 0x58,
PUSHGQ = 0x59,
PUSHIP = 0x5a,
PUSHBP = 0x5b,
PUSHSP = 0x5c,
PUSHARGB = 0x5d,
PUSHARGI = 0x5e,
PUSHARGF = 0x5f,
PUSHARGS = 0x60,
PUSHARGV = 0x61,
PUSHARGQ = 0x62,
PUSHE = 0x63,
PUSHEV = 0x64,
PUSHEQ = 0x65,
PUSHARGE = 0x66,
ADD = 0x70,
SUB = 0x71,
MUL = 0x72,
DIV = 0x73,
MOD = 0x74,
EQ = 0x75,
NEQ = 0x76,
LEQ = 0x77,
GEQ = 0x78,
LESS = 0x79,
GREATER = 0x7a,
BITAND = 0x7b,
BITOR = 0x7c,
BITXOR = 0x7d,
BOOLAND = 0x7e,
BOOLOR = 0x7f,
NEG = 0x80,
BITNOT = 0x81,
BOOLNOT = 0x82,
JUMP = 0x90,
JUMPIF = 0x91,
JUMPNIF = 0x92,
STATE = 0x93,
CALL = 0x94,
RETURN = 0x95,
CAST = 0xa0,
STACKTOS = 0xb0,
STACKTOL = 0xb1,
PRINT = 0xc0,
CALLLIB = 0xd0,
CALLLIB_TWO_BYTE = 0xd1,
SHL = 0xe0,
SHR = 0xe1
}
[Serializable]
public enum BuiltIn_Functions
{
llSin = 0,
llCos = 1,
llTan = 2,
llAtan2 = 3,
llSqrt = 4,
llPow = 5,
llAbs = 6,
llFabs = 7,
llFrand = 8,
llFloor = 9,
llCeil = 10,
llRound = 11,
llVecMag = 12,
llVecNorm = 13,
llVecDist = 14,
llRot2Euler = 15,
llEuler2Rot = 16,
llAxes2Rot = 17,
llRot2Fwd = 18,
llRot2Left = 19,
llRot2Up = 20,
llRotBetween = 21,
llWhisper = 22,
llSay = 23,
llShout = 24,
llListen = 25,
llListenControl = 26,
llListenRemove = 27,
llSensor = 28,
llSensorRepeat = 29,
llSensorRemove = 30,
llDetectedName = 31,
llDetectedKey = 32,
llDetectedOwner = 33,
llDetectedType = 34,
llDetectedPos = 35,
llDetectedVel = 36,
llDetectedGrab = 37,
llDetectedRot = 38,
llDetectedGroup = 39,
llDetectedLinkNumber = 40,
llDie = 41,
llGround = 42,
llCloud = 43,
llWind = 44,
llSetStatus = 45,
llGetStatus = 46,
llSetScale = 47,
llGetScale = 48,
llSetColor = 49,
llGetAlpha = 50,
llSetAlpha = 51,
llGetColor = 52,
llSetTexture = 53,
llScaleTexture = 54,
llOffsetTexture = 55,
llRotateTexture = 56,
llGetTexture = 57,
llSetPos = 58,
llGetPos = 59,
llGetLocalPos = 60,
llSetRot = 61,
llGetRot = 62,
llGetLocalRot = 63,
llSetForce = 64,
llGetForce = 65,
llTarget = 66,
llTargetRemove = 67,
llRotTarget = 68,
llRotTargetRemove = 69,
llMoveToTarget = 70,
llStopMoveToTarget = 71,
llApplyImpulse = 72,
llApplyRotationalImpulse = 73,
llSetTorque = 74,
llGetTorque = 75,
llSetForceAndTorque = 76,
llGetVel = 77,
llGetAccel = 78,
llGetOmega = 79,
llGetTimeOfDay = 80,
llGetWallclock = 81,
llGetTime = 82,
llResetTime = 83,
llGetAndResetTime = 84,
llSound = 85,
llPlaySound = 86,
llLoopSound = 87,
llLoopSoundMaster = 88,
llLoopSoundSlave = 89,
llPlaySoundSlave = 90,
llTriggerSound = 91,
llStopSound = 92,
llPreloadSound = 93,
llGetSubString = 94,
llDeleteSubString = 95,
llInsertString = 96,
llToUpper = 97,
llToLower = 98,
llGiveMoney = 99,
llMakeExplosion = 100,
llMakeFountain = 101,
llMakeSmoke = 102,
llMakeFire = 103,
llRezObject = 104,
llLookAt = 105,
llStopLookAt = 106,
llSetTimerEvent = 107,
llSleep = 108,
llGetMass = 109,
llCollisionFilter = 110,
llTakeControls = 111,
llReleaseControls = 112,
llAttachToAvatar = 113,
llDetachFromAvatar = 114,
llTakeCamera = 115,
llReleaseCamera = 116,
llGetOwner = 117,
llInstantMessage = 118,
llEmail = 119,
llGetNextEmail = 120,
llGetKey = 121,
llSetBuoyancy = 122,
llSetHoverHeight = 123,
llStopHover = 124,
llMinEventDelay = 125,
llSoundPreload = 126,
llRotLookAt = 127,
llStringLength = 128,
llStartAnimation = 129,
llStopAnimation = 130,
llPointAt = 131,
llStopPointAt = 132,
llTargetOmega = 133,
llGetStartParameter = 134,
llGodLikeRezObject = 135,
llRequestPermissions = 136,
llGetPermissionsKey = 137,
llGetPermissions = 138,
llGetLinkNumber = 139,
llSetLinkColor = 140,
llCreateLink = 141,
llBreakLink = 142,
llBreakAllLinks = 143,
llGetLinkKey = 144,
llGetLinkName = 145,
llGetInventoryNumber = 146,
llGetInventoryName = 147,
llSetScriptState = 148,
llGetEnergy = 149,
llGiveInventory = 150,
llRemoveInventory = 151,
llSetText = 152,
llWater = 153,
llPassTouches = 154,
llRequestAgentData = 155,
llRequestInventoryData = 156,
llSetDamage = 157,
llTeleportAgentHome = 158,
llModifyLand = 159,
llCollisionSound = 160,
llCollisionSprite = 161,
llGetAnimation = 162,
llResetScript = 163,
llMessageLinked = 164,
llPushObject = 165,
llPassCollisions = 166,
llGetScriptName = 167,
llGetNumberOfSides = 168,
llAxisAngle2Rot = 169,
llRot2Axis = 170,
llRot2Angle = 171,
llAcos = 172,
llAsin = 173,
llAngleBetween = 174,
llGetInventoryKey = 175,
llAllowInventoryDrop = 176,
llGetSunDirection = 177,
llGetTextureOffset = 178,
llGetTextureScale = 179,
llGetTextureRot = 180,
llSubStringIndex = 181,
llGetOwnerKey = 182,
llGetCenterOfMass = 183,
llListSort = 184,
llGetListLength = 185,
llList2Integer = 186,
llList2Float = 187,
llList2String = 188,
llList2Key = 189,
llList2Vector = 190,
llList2Rot = 191,
llList2List = 192,
llDeleteSubList = 193,
llGetListEntryType = 194,
llList2CSV = 195,
llCSV2List = 196,
llListRandomize = 197,
llList2ListStrided = 198,
llGetRegionCorner = 199,
llListInsertList = 200,
llListFindList = 201,
llGetObjectName = 202,
llSetObjectName = 203,
llGetDate = 204,
llEdgeOfWorld = 205,
llGetAgentInfo = 206,
llAdjustSoundVolume = 207,
llSetSoundQueueing = 208,
llSetSoundRadius = 209,
llKey2Name = 210,
llSetTextureAnim = 211,
llTriggerSoundLimited = 212,
llEjectFromLand = 213,
llParseString2List = 214,
llOverMyLand = 215,
llGetLandOwnerAt = 216,
llGetNotecardLine = 217,
llGetAgentSize = 218,
llSameGroup = 219,
llUnSit = 220,
llGroundSlope = 221,
llGroundNormal = 222,
llGroundContour = 223,
llGetAttached = 224,
llGetFreeMemory = 225,
llGetRegionName = 226,
llGetRegionTimeDilation = 227,
llGetRegionFPS = 228,
llParticleSystem = 229,
llGroundRepel = 230,
llGiveInventoryList = 231,
llSetVehicleType = 232,
llSetVehicleFloatParam = 233,
llSetVehicleVectorParam = 234,
llSetVehicleRotationParam = 235,
llSetVehicleFlags = 236,
llRemoveVehicleFlags = 237,
llSitTarget = 238,
llAvatarOnSitTarget = 239,
llAddToLandPassList = 240,
llSetTouchText = 241,
llSetSitText = 242,
llSetCameraEyeOffset = 243,
llSetCameraAtOffset = 244,
llDumpList2String = 245,
llScriptDanger = 246,
llDialog = 247,
llVolumeDetect = 248,
llResetOtherScript = 249,
llGetScriptState = 250,
llRemoteLoadScript = 251,
llSetRemoteScriptAccessPin = 252,
llRemoteLoadScriptPin = 253,
llOpenRemoteDataChannel = 254,
llSendRemoteData = 255,
llRemoteDataReply = 256,
llCloseRemoteDataChannel = 257,
llMD5String = 258,
llSetPrimitiveParams = 259,
llStringToBase64 = 260,
llBase64ToString = 261,
llXorBase64Strings = 262,
llRemoteDataSetRegion = 263,
llLog10 = 264,
llLog = 265,
llGetAnimationList = 266,
llSetParcelMusicURL = 267,
llGetRootPosition = 268,
llGetRootRotation = 269,
llGetObjectDesc = 270,
llSetObjectDesc = 271,
llGetCreator = 272,
llGetTimestamp = 273,
llSetLinkAlpha = 274,
llGetNumberOfPrims = 275,
llGetNumberOfNotecardLines = 276,
llGetBoundingBox = 277,
llGetGeometricCenter = 278,
llGetPrimitiveParams = 279,
llIntegerToBase64 = 280,
llBase64ToInteger = 281,
llGetGMTclock = 282,
llGetSimulatorHostname = 283,
llSetLocalRot = 284,
llParseStringKeepNulls = 285,
llRezAtRoot = 286,
llGetObjectPermMask = 287,
llSetObjectPermMask = 288,
llGetInventoryPermMask = 289,
llSetInventoryPermMask = 290,
llGetInventoryCreator = 291,
llOwnerSay = 292,
llRequestSimulatorData = 293,
llForceMouselook = 294,
llGetObjectMass = 295,
llListReplaceList = 296,
llLoadURL = 297,
llParcelMediaCommandList = 298,
llParcelMediaQuery = 299,
llModPow = 300,
llGetInventoryType = 301,
llSetPayPrice = 302,
llGetCameraPos = 303,
llGetCameraRot = 304,
llSetPrimURL = 305,
llRefreshPrimURL = 306,
llEscapeURL = 307,
llUnescapeURL = 308,
llMapDestination = 309,
llAddToLandBanList = 310,
llRemoveFromLandPassList = 311,
llRemoveFromLandBanList = 312,
llSetCameraParams = 313,
llClearCameraParams = 314,
llListStatistics = 315,
llGetUnixTime = 316,
llGetParcelFlags = 317,
llGetRegionFlags = 318,
llXorBase64StringsCorrect = 319,
llHTTPRequest = 320,
llResetLandBanList = 321,
llResetLandPassList = 322,
llGetParcelPrimCount = 323,
llGetParcelPrimOwners = 324,
llGetObjectPrimCount = 325,
llGetParcelMaxPrims = 326,
llGetParcelDetails = 327
}
}
}

View File

@ -0,0 +1,722 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
partial class LSO_Parser
{
private string FileName;
private FileStream fs;
private BinaryReader br;
internal LSO_Struct.Header myHeader;
internal Dictionary<long, LSO_Struct.StaticBlock> StaticBlocks = new Dictionary<long, LSO_Struct.StaticBlock>();
//private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable();
private TypeBuilder typeBuilder;
private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>();
public LSO_Parser(string _FileName, TypeBuilder _typeBuilder)
{
FileName = _FileName;
typeBuilder = _typeBuilder;
}
internal void OpenFile()
{
// Open
Common.SendToDebug("Opening filename: " + FileName);
fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
br = new BinaryReader(fs, Encoding.BigEndianUnicode);
}
internal void CloseFile()
{
// Close
br.Close();
fs.Close();
}
/// <summary>
/// Parse LSO file.
/// </summary>
public void Parse()
{
// The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack.
// HEADER BLOCK
Common.SendToDebug("Reading HEADER BLOCK at: 0");
fs.Seek(0, SeekOrigin.Begin);
myHeader = new LSO_Struct.Header();
myHeader.TM = BitConverter.ToUInt32(br_read(4), 0);
myHeader.IP = BitConverter.ToUInt32(br_read(4), 0);
myHeader.VN = BitConverter.ToUInt32(br_read(4), 0);
myHeader.BP = BitConverter.ToUInt32(br_read(4), 0);
myHeader.SP = BitConverter.ToUInt32(br_read(4), 0);
myHeader.HR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.HP = BitConverter.ToUInt32(br_read(4), 0);
myHeader.CS = BitConverter.ToUInt32(br_read(4), 0);
myHeader.NS = BitConverter.ToUInt32(br_read(4), 0);
myHeader.CE = BitConverter.ToUInt32(br_read(4), 0);
myHeader.IE = BitConverter.ToUInt32(br_read(4), 0);
myHeader.ER = BitConverter.ToUInt32(br_read(4), 0);
myHeader.FR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.PR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.SR = BitConverter.ToUInt32(br_read(4), 0);
myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0);
myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0);
myHeader.NER = BitConverter.ToUInt64(br_read(8), 0);
// Print Header Block to debug
Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM);
Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP);
Common.SendToDebug("VN - Version number: " + myHeader.VN);
Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP);
Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP);
Common.SendToDebug("HR - Heap Register: " + myHeader.HR);
Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP);
Common.SendToDebug("CS - Current State: " + myHeader.CS);
Common.SendToDebug("NS - Next State: " + myHeader.NS);
Common.SendToDebug("CE - Current Events: " + myHeader.CE);
Common.SendToDebug("IE - In Event: " + myHeader.IE);
Common.SendToDebug("ER - Event Register: " + myHeader.ER);
Common.SendToDebug("FR - Fault Register: " + myHeader.FR);
Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR);
Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR);
Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR);
Common.SendToDebug("PR - Parameter Register: " + myHeader.PR);
Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR);
Common.SendToDebug("SR - State Register: " + myHeader.SR);
Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE);
Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE);
Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER);
Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position);
// STATIC BLOCK
Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR);
fs.Seek(myHeader.GVR, SeekOrigin.Begin);
int StaticBlockCount = 0;
// Read function blocks until we hit GFR
while (fs.Position < myHeader.GFR)
{
StaticBlockCount++;
long startReadPos = fs.Position;
Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + startReadPos);
//fs.Seek(myHeader.GVR, SeekOrigin.Begin);
LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock();
myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0);
myStaticBlock.ObjectType = br_read(1)[0];
Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString());
myStaticBlock.Unknown = br_read(1)[0];
// Size of datatype varies -- what about strings?
if (myStaticBlock.ObjectType != 0)
myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType));
StaticBlocks.Add((UInt32)startReadPos, myStaticBlock);
}
Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount);
// FUNCTION BLOCK
// Always right after STATIC BLOCK
LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock();
if (myHeader.GFR == myHeader.SR)
{
// If GFR and SR are at same position then there is no fuction block
Common.SendToDebug("No FUNCTION BLOCK found");
}
else
{
Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR);
fs.Seek(myHeader.GFR, SeekOrigin.Begin);
myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount);
if (myFunctionBlock.FunctionCount > 0)
{
myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount];
for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
{
Common.SendToDebug("Reading function " + i + " at: " + fs.Position);
// TODO: ADD TO FUNCTION LIST (How do we identify it later?)
// Note! Absolute position
myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR;
Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]);
}
}
}
// STATE FRAME BLOCK
// Always right after FUNCTION BLOCK
Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR);
fs.Seek(myHeader.SR, SeekOrigin.Begin);
LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock();
myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0);
if (myStateFrameBlock.StateCount > 0)
{
// Initialize array
myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount];
for (int i = 0; i < myStateFrameBlock.StateCount; i++)
{
Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position);
// Position is relative to state frame
myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0);
myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8));
Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location);
Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count);
//// Read STATE BLOCK
//long CurPos = fs.Position;
//fs.Seek(CurPos, SeekOrigin.Begin);
}
}
// STATE BLOCK
// For each StateFrameBlock there is one StateBlock with multiple event handlers
if (myStateFrameBlock.StateCount > 0)
{
// Go through all State Frame Pointers found
for (int i = 0; i < myStateFrameBlock.StateCount; i++)
{
fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin);
Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position);
// READ: STATE BLOCK HEADER
myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock();
myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note
myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0);
myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0];
myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note
Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos);
Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize);
Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos);
// We need to count number of bits flagged in EventMask?
// for each bit in myStateFrameBlock.StatePointer[i].EventMask
// ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE
//TODO: Create event hooks
myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1];
for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
{
if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true)
{
// We got an event
// READ: STATE BLOCK HANDLER
Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position);
myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0);
myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer);
Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize);
}
}
}
}
//// READ FUNCTION CODE CHUNKS
//// Functions + Function start pos (GFR)
//// TODO: Somehow be able to identify and reference this
//LSO_Struct.CodeChunk[] myFunctionCodeChunk;
//if (myFunctionBlock.FunctionCount > 0)
//{
// myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount];
// for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
// {
// Common.SendToDebug("Reading Function Code Chunk " + i);
// myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]);
// }
//}
// READ EVENT CODE CHUNKS
LSO_Struct.CodeChunk[] myEventCodeChunk;
if (myStateFrameBlock.StateCount > 0)
{
myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount];
for (int i = 0; i < myStateFrameBlock.StateCount; i++)
{
// TODO: Somehow organize events and functions so they can be found again,
// two level search ain't no good
for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
{
if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0)
{
Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii);
// Override a Method / Function
string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii;
Common.SendToDebug("Event Name: " + eventname);
if (Common.IL_ProcessCodeChunks)
{
EventList.Add(eventname);
// JUMP TO CODE PROCESSOR
ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname);
}
}
}
}
}
if (Common.IL_CreateFunctionList)
IL_INSERT_FUNCTIONLIST();
}
internal LSO_Struct.HeapBlock GetHeap(UInt32 pos)
{
// HEAP BLOCK
// TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries)
Common.SendToDebug("Reading HEAP BLOCK at: " + pos);
fs.Seek(pos, SeekOrigin.Begin);
LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock();
myHeapBlock.DataBlockSize = BitConverter.ToInt32(br_read(4), 0);
myHeapBlock.ObjectType = br_read(1)[0];
myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0);
//myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType));
// Don't read it reversed
myHeapBlock.Data = new byte[myHeapBlock.DataBlockSize - 1];
br.Read(myHeapBlock.Data, 0, myHeapBlock.DataBlockSize - 1);
Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize);
Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString());
Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount);
return myHeapBlock;
}
private byte[] br_read(int len)
{
if (len <= 0)
return null;
try
{
byte[] bytes = new byte[len];
for (int i = len - 1; i > -1; i--)
bytes[i] = br.ReadByte();
return bytes;
}
catch (Exception e)
{
Common.SendToDebug("Exception: " + e.ToString());
throw (e);
}
}
//private byte[] br_read_smallendian(int len)
//{
// byte[] bytes = new byte[len];
// br.Read(bytes,0, len);
// return bytes;
//}
private Type getLLObjectType(byte objectCode)
{
switch ((LSO_Enums.Variable_Type_Codes)objectCode)
{
case LSO_Enums.Variable_Type_Codes.Void: return typeof(void);
case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32);
case LSO_Enums.Variable_Type_Codes.Float: return typeof(float);
case LSO_Enums.Variable_Type_Codes.String: return typeof(string);
case LSO_Enums.Variable_Type_Codes.Key: return typeof(string);
case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector);
case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation);
case LSO_Enums.Variable_Type_Codes.List:
Common.SendToDebug("TODO: List datatype not implemented yet!");
return typeof(System.Collections.ArrayList);
case LSO_Enums.Variable_Type_Codes.Null:
Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!");
return typeof(string);
default:
Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object.");
return typeof(object);
}
}
private int getObjectSize(byte ObjectType)
{
switch ((LSO_Enums.Variable_Type_Codes)ObjectType)
{
case LSO_Enums.Variable_Type_Codes.Integer:
case LSO_Enums.Variable_Type_Codes.Float:
case LSO_Enums.Variable_Type_Codes.String:
case LSO_Enums.Variable_Type_Codes.Key:
case LSO_Enums.Variable_Type_Codes.List:
return 4;
case LSO_Enums.Variable_Type_Codes.Vector:
return 12;
case LSO_Enums.Variable_Type_Codes.Rotation:
return 16;
default:
return 0;
}
}
private string Read_String()
{
string ret = "";
byte reader = br_read(1)[0];
while (reader != 0x000)
{
ret += (char)reader;
reader = br_read(1)[0];
}
return ret;
}
/// <summary>
/// Reads a code chunk and creates IL
/// </summary>
/// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param>
/// <param name="typeBuilder">TypeBuilder for assembly</param>
/// <param name="eventname">Name of event (function) to generate</param>
private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname)
{
LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk();
Common.SendToDebug("Reading Function Code Chunk at: " + pos);
fs.Seek(pos, SeekOrigin.Begin);
myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize);
// Read until null
myCodeChunk.Comment = Read_String();
Common.SendToDebug("Function comment: " + myCodeChunk.Comment);
myCodeChunk.ReturnTypePos = br_read(1)[0];
myCodeChunk.ReturnType = GetStaticBlock((long)myCodeChunk.ReturnTypePos + (long)myHeader.GVR);
Common.SendToDebug("Return type #" + myCodeChunk.ReturnType.ObjectType + ": " + ((LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType.ObjectType).ToString());
// TODO: How to determine number of codechunks -- does this method work?
myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>();
byte reader = br_read(1)[0];
reader = br_read(1)[0];
// NOTE ON CODE CHUNK ARGUMENTS
// This determins type definition
int ccount = 0;
while (reader != 0x000)
{
ccount++;
Common.SendToDebug("Reading Code Chunk Argument " + ccount);
LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument();
CCA.FunctionReturnTypePos = reader;
reader = br_read(1)[0];
CCA.NullString = reader;
CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR);
myCodeChunk.CodeChunkArguments.Add(CCA);
Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + ": " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType.ObjectType);
}
// Create string array
Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count];
for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++)
{
MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType);
Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType).ToString());
}
// End marker is 0x000
myCodeChunk.EndMarker = reader;
//
// Emit: START OF METHOD (FUNCTION)
//
Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod...");
MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
MethodAttributes.Public,
typeof(void),
new Type[] { typeof(object) });
//MethodArgs);
//typeof(void), //getLLObjectType(myCodeChunk.ReturnType),
// new Type[] { typeof(object) }, //);
//Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder...");
//typeBuilder.DefineMethodOverride(methodBuilder,
// typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
// Create the IL generator
Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();");
ILGenerator il = methodBuilder.GetILGenerator();
if (Common.IL_UseTryCatch)
IL_INSERT_TRY(il, eventname);
// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
//Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
//il.Emit(OpCodes.Call, typeof(Console).GetMethod
// ("WriteLine", new Type[] { typeof(string) }));
//Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);");
//il.Emit(OpCodes.Ldc_I4_S, 0);
for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++)
{
Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");");
il.Emit(OpCodes.Ldarg, _ic);
}
//
// CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL
//
bool FoundRet = false;
while (FoundRet == false)
{
FoundRet = LSL_PROCESS_OPCODE(il);
}
if (Common.IL_UseTryCatch)
IL_INSERT_END_TRY(il, eventname);
// Emit: RETURN FROM METHOD
il.Emit(OpCodes.Ret);
return;
}
private void IL_INSERT_FUNCTIONLIST()
{
Common.SendToDebug("Creating function list");
string eventname = "GetFunctions";
Common.SendToDebug("Creating IL " + eventname);
// Define a private String field.
//FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public);
//FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private);
MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
MethodAttributes.Public,
typeof(string[]),
null);
//typeBuilder.DefineMethodOverride(methodBuilder,
// typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
ILGenerator il = methodBuilder.GetILGenerator();
// IL_INSERT_TRY(il, eventname);
// // Push string to stack
// il.Emit(OpCodes.Ldstr, "Inside " + eventname);
//// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
//il.Emit(OpCodes.Call, typeof(Console).GetMethod
// ("WriteLine", new Type[] { typeof(string) }));
//initIL.Emit(OpCodes.Newobj, typeof(string[]));
//string[] MyArray = new string[2] { "TestItem1" , "TestItem2" };
////il.Emit(OpCodes.Ldarg_0);
il.DeclareLocal(typeof(string[]));
////il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length
il.Emit(OpCodes.Newarr, typeof(String)); // create new string array
il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack
////SetFunctionList
for (int lv = 0; lv < EventList.Count; lv++)
{
il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack
il.Emit(OpCodes.Ldc_I4, lv); // Push index position
il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value
il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
//il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value
//il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) }));
}
// IL_INSERT_END_TRY(il, eventname);
il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack
// il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("SetFunctionList", new Type[] { typeof(Array) }));
il.Emit(OpCodes.Ret); // Return
}
private void IL_INSERT_TRY(ILGenerator il, string eventname)
{
/*
* CLR TRY
*/
//Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()");
il.BeginExceptionBlock();
// Push "Hello World!" string to stack
//Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
//il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname);
}
private void IL_INSERT_END_TRY(ILGenerator il, string eventname)
{
/*
* CATCH
*/
Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));");
il.BeginCatchBlock(typeof(Exception));
// Push "Hello World!" string to stack
Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": ");
//call void [mscorlib]System.Console::WriteLine(string)
Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
il.Emit(OpCodes.Call, typeof(Console).GetMethod
("Write", new Type[] { typeof(string) }));
//callvirt instance string [mscorlib]System.Exception::get_Message()
Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt...");
il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
("get_Message"));
//call void [mscorlib]System.Console::WriteLine(string)
Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
il.Emit(OpCodes.Call, typeof(Console).GetMethod
("WriteLine", new Type[] { typeof(string) }));
/*
* CLR END TRY
*/
//Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();");
il.EndExceptionBlock();
}
private LSO_Struct.StaticBlock GetStaticBlock(long pos)
{
long FirstPos = fs.Position;
try
{
UInt32 position = (UInt32)pos;
// STATIC BLOCK
Common.SendToDebug("Reading STATIC BLOCK at: " + position);
fs.Seek(position, SeekOrigin.Begin);
if (StaticBlocks.ContainsKey(position) == true)
{
Common.SendToDebug("Found cached STATIC BLOCK");
return StaticBlocks[pos];
}
//int StaticBlockCount = 0;
// Read function blocks until we hit GFR
//while (fs.Position < myHeader.GFR)
//{
//StaticBlockCount++;
//Common.SendToDebug("Reading Static Block at: " + position);
//fs.Seek(myHeader.GVR, SeekOrigin.Begin);
LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock();
myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0);
myStaticBlock.ObjectType = br_read(1)[0];
Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString());
myStaticBlock.Unknown = br_read(1)[0];
// Size of datatype varies
if (myStaticBlock.ObjectType != 0)
myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType));
StaticBlocks.Add(position, myStaticBlock);
//}
Common.SendToDebug("Done reading Static Block.");
return myStaticBlock;
}
finally
{
// Go back to original read pos
fs.Seek(FirstPos, SeekOrigin.Begin);
}
}
}
}

View File

@ -0,0 +1,135 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSO
{
static class LSO_Struct
{
public struct Header
{
public UInt32 TM;
public UInt32 IP;
public UInt32 VN;
public UInt32 BP;
public UInt32 SP;
public UInt32 HR;
public UInt32 HP;
public UInt32 CS;
public UInt32 NS;
public UInt32 CE;
public UInt32 IE;
public UInt32 ER;
public UInt32 FR;
public UInt32 SLR;
public UInt32 GVR;
public UInt32 GFR;
public UInt32 PR;
public UInt32 ESR;
public UInt32 SR;
public UInt64 NCE;
public UInt64 NIE;
public UInt64 NER;
}
public struct StaticBlock
{
public UInt32 Static_Chunk_Header_Size;
public byte ObjectType;
public byte Unknown;
public byte[] BlockVariable;
}
/* Not actually a structure
public struct StaticBlockVariable
{
public UInt32 Integer1;
public UInt32 Float1;
public UInt32 HeapPointer_String;
public UInt32 HeapPointer_Key;
public byte[] Vector_12;
public byte[] Rotation_16;
public UInt32 Pointer_List_Structure;
} */
public struct HeapBlock
{
public Int32 DataBlockSize;
public byte ObjectType;
public UInt16 ReferenceCount;
public byte[] Data;
}
public struct StateFrameBlock
{
public UInt32 StateCount;
public StatePointerBlock[] StatePointer;
}
public struct StatePointerBlock
{
public UInt32 Location;
public System.Collections.BitArray EventMask;
public StateBlock StateBlock;
}
public struct StateBlock
{
public UInt32 StartPos;
public UInt32 EndPos;
public UInt32 HeaderSize;
public byte Unknown;
public StateBlockHandler[] StateBlockHandlers;
}
public struct StateBlockHandler
{
public UInt32 CodeChunkPointer;
public UInt32 CallFrameSize;
}
public struct FunctionBlock
{
public UInt32 FunctionCount;
public UInt32[] CodeChunkPointer;
}
public struct CodeChunk
{
public UInt32 CodeChunkHeaderSize;
public string Comment;
public System.Collections.Generic.List<CodeChunkArgument> CodeChunkArguments;
public byte EndMarker;
public byte ReturnTypePos;
public StaticBlock ReturnType;
}
public struct CodeChunkArgument
{
public byte FunctionReturnTypePos;
public byte NullString;
public StaticBlock FunctionReturnType;
}
}
}

View File

@ -0,0 +1,12 @@
//c#
namespace SecondLife {
public class Script : OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSL.LSL_BaseClass
{
public Script() { }
public void default_event_state_entry( )
{
llSay(0, "testing, I've been touched");
}
}}

View File

@ -0,0 +1,131 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;
using OpenSim.Framework.Interfaces;
using OpenSim.Region.Environment.Scenes.Scripting;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
/// <summary>
/// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
/// </summary>
[Serializable]
class EventManager
{
private ScriptEngine myScriptEngine;
//public IScriptHost TEMP_OBJECT_ID;
public EventManager(ScriptEngine _ScriptEngine)
{
myScriptEngine = _ScriptEngine;
// TODO: HOOK EVENTS UP TO SERVER!
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventManager Start");
// TODO: ADD SERVER HOOK TO LOAD A SCRIPT THROUGH myScriptEngine.ScriptManager
// Hook up a test event to our test form
myScriptEngine.Log.Verbose("ScriptEngine", "Hooking up to server events");
myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
myScriptEngine.World.EventManager.OnRezScript += OnRezScript;
myScriptEngine.World.EventManager.OnRemoveScript += OnRemoveScript;
}
public void touch_start(uint localID, LLVector3 offsetPos, IClientAPI remoteClient)
{
// Add to queue for all scripts in ObjectID object
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventManager Event: touch_start");
//Console.WriteLine("touch_start localID: " + localID);
myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_start", new object[] { (int)1 });
}
public void OnRezScript(uint localID, LLUUID itemID, string script)
{
//myScriptEngine.myScriptManager.StartScript(
// Path.Combine("ScriptEngines", "Default.lsl"),
// new OpenSim.Region.Environment.Scenes.Scripting.NullScriptHost()
//);
Console.WriteLine("OnRezScript localID: " + localID + " LLUID: " + itemID.ToString() + " Size: " + script.Length);
myScriptEngine.m_ScriptManager.StartScript(localID, itemID, script);
}
public void OnRemoveScript(uint localID, LLUUID itemID)
{
//myScriptEngine.myScriptManager.StartScript(
// Path.Combine("ScriptEngines", "Default.lsl"),
// new OpenSim.Region.Environment.Scenes.Scripting.NullScriptHost()
//);
Console.WriteLine("OnRemoveScript localID: " + localID + " LLUID: " + itemID.ToString());
myScriptEngine.m_ScriptManager.StopScript(
localID,
itemID
);
}
// TODO: Replace placeholders below
// These needs to be hooked up to OpenSim during init of this class
// then queued in EventQueueManager.
// When queued in EventQueueManager they need to be LSL compatible (name and params)
//public void state_entry() { } //
public void state_exit() { }
//public void touch_start() { }
public void touch() { }
public void touch_end() { }
public void collision_start() { }
public void collision() { }
public void collision_end() { }
public void land_collision_start() { }
public void land_collision() { }
public void land_collision_end() { }
public void timer() { }
public void listen() { }
public void on_rez() { }
public void sensor() { }
public void no_sensor() { }
public void control() { }
public void money() { }
public void email() { }
public void at_target() { }
public void not_at_target() { }
public void at_rot_target() { }
public void not_at_rot_target() { }
public void run_time_permissions() { }
public void changed() { }
public void attach() { }
public void dataserver() { }
public void link_message() { }
public void moving_start() { }
public void moving_end() { }
public void object_rez() { }
public void remote_data() { }
public void http_response() { }
}
}

View File

@ -0,0 +1,321 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using OpenSim.Region.Environment.Scenes.Scripting;
using libsecondlife;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
/// <summary>
/// EventQueueManager handles event queues
/// Events are queued and executed in separate thread
/// </summary>
[Serializable]
class EventQueueManager
{
/// <summary>
/// List of threads processing event queue
/// </summary>
private List<Thread> eventQueueThreads = new List<Thread>();
private object queueLock = new object(); // Mutex lock object
/// <summary>
/// How many ms to sleep if queue is empty
/// </summary>
private int nothingToDoSleepms = 50;
/// <summary>
/// How many threads to process queue with
/// </summary>
private int numberOfThreads = 2;
/// <summary>
/// Queue containing events waiting to be executed
/// </summary>
private Queue<QueueItemStruct> eventQueue = new Queue<QueueItemStruct>();
/// <summary>
/// Queue item structure
/// </summary>
private struct QueueItemStruct
{
public uint localID;
public LLUUID itemID;
public string functionName;
public object[] param;
}
/// <summary>
/// List of localID locks for mutex processing of script events
/// </summary>
private List<uint> objectLocks = new List<uint>();
private object tryLockLock = new object(); // Mutex lock object
private ScriptEngine m_ScriptEngine;
public EventQueueManager(ScriptEngine _ScriptEngine)
{
m_ScriptEngine = _ScriptEngine;
//
// Start event queue processing threads (worker threads)
//
for (int ThreadCount = 0; ThreadCount <= numberOfThreads; ThreadCount++)
{
Thread EventQueueThread = new Thread(EventQueueThreadLoop);
eventQueueThreads.Add(EventQueueThread);
EventQueueThread.IsBackground = true;
EventQueueThread.Priority = ThreadPriority.BelowNormal;
EventQueueThread.Name = "EventQueueManagerThread_" + ThreadCount;
EventQueueThread.Start();
}
}
~EventQueueManager()
{
// Kill worker threads
foreach (Thread EventQueueThread in new System.Collections.ArrayList(eventQueueThreads))
{
if (EventQueueThread != null && EventQueueThread.IsAlive == true)
{
try
{
EventQueueThread.Abort();
EventQueueThread.Join();
}
catch (Exception)
{
//myScriptEngine.Log.Verbose("ScriptEngine", "EventQueueManager Exception killing worker thread: " + e.ToString());
}
}
}
eventQueueThreads.Clear();
// Todo: Clean up our queues
eventQueue.Clear();
}
/// <summary>
/// Queue processing thread loop
/// </summary>
private void EventQueueThreadLoop()
{
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Worker thread spawned");
try
{
QueueItemStruct BlankQIS = new QueueItemStruct();
while (true)
{
try
{
QueueItemStruct QIS = BlankQIS;
bool GotItem = false;
if (eventQueue.Count == 0)
{
// Nothing to do? Sleep a bit waiting for something to do
Thread.Sleep(nothingToDoSleepms);
}
else
{
// Something in queue, process
//myScriptEngine.m_logger.Verbose("ScriptEngine", "Processing event for localID: " + QIS.localID + ", itemID: " + QIS.itemID + ", FunctionName: " + QIS.FunctionName);
// OBJECT BASED LOCK - TWO THREADS WORKING ON SAME OBJECT IS NOT GOOD
lock (queueLock)
{
GotItem = false;
for (int qc = 0; qc < eventQueue.Count; qc++)
{
// Get queue item
QIS = eventQueue.Dequeue();
// Check if object is being processed by someone else
if (TryLock(QIS.localID) == false)
{
// Object is already being processed, requeue it
eventQueue.Enqueue(QIS);
}
else
{
// We have lock on an object and can process it
GotItem = true;
break;
}
} // go through queue
} // lock
if (GotItem == true)
{
// Execute function
try
{
m_ScriptEngine.m_ScriptManager.ExecuteEvent(QIS.localID, QIS.itemID, QIS.functionName, QIS.param);
}
catch (Exception e)
{
// DISPLAY ERROR INWORLD
string text = "Error executing script function \"" + QIS.functionName + "\":\r\n";
if (e.InnerException != null)
{ // Send inner exception
text += e.InnerException.Message.ToString();
}
else
{ // Send normal
text += e.Message.ToString();
}
try
{
if (text.Length > 1500)
text = text.Substring(0, 1500);
IScriptHost m_host = m_ScriptEngine.World.GetSceneObjectPart(QIS.localID);
//if (m_host != null)
//{
m_ScriptEngine.World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
} catch {
//}
//else
//{
// T oconsole
Console.WriteLine("Unable to send text in-world:\r\n" + text);
}
}
finally
{
ReleaseLock(QIS.localID);
}
}
} // Something in queue
} catch (ThreadAbortException tae) {
throw tae;
} catch (Exception e) {
Console.WriteLine("Exception in EventQueueThreadLoop: " + e.ToString());
}
} // while
} // try
catch (ThreadAbortException)
{
//myScriptEngine.Log.Verbose("ScriptEngine", "EventQueueManager Worker thread killed: " + tae.Message);
}
}
/// <summary>
/// Try to get a mutex lock on localID
/// </summary>
/// <param name="localID"></param>
/// <returns></returns>
private bool TryLock(uint localID)
{
lock (tryLockLock)
{
if (objectLocks.Contains(localID) == true)
{
return false;
}
else
{
objectLocks.Add(localID);
return true;
}
}
}
/// <summary>
/// Release mutex lock on localID
/// </summary>
/// <param name="localID"></param>
private void ReleaseLock(uint localID)
{
lock (tryLockLock)
{
if (objectLocks.Contains(localID) == true)
{
objectLocks.Remove(localID);
}
}
}
/// <summary>
/// Add event to event execution queue
/// </summary>
/// <param name="localID"></param>
/// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
/// <param name="param">Array of parameters to match event mask</param>
public void AddToObjectQueue(uint localID, string FunctionName, object[] param)
{
// Determine all scripts in Object and add to their queue
//myScriptEngine.m_logger.Verbose("ScriptEngine", "EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName);
// Do we have any scripts in this object at all? If not, return
if (m_ScriptEngine.m_ScriptManager.Scripts.ContainsKey(localID) == false)
{
//Console.WriteLine("Event \"" + FunctionName + "\" for localID: " + localID + ". No scripts found on this localID.");
return;
}
Dictionary<LLUUID, LSL_BaseClass>.KeyCollection scriptKeys = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID);
foreach ( LLUUID itemID in scriptKeys )
{
// Add to each script in that object
// TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter?
AddToScriptQueue(localID, itemID, FunctionName, param);
}
}
/// <summary>
/// Add event to event execution queue
/// </summary>
/// <param name="localID"></param>
/// <param name="itemID"></param>
/// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
/// <param name="param">Array of parameters to match event mask</param>
public void AddToScriptQueue(uint localID, LLUUID itemID, string FunctionName, object[] param)
{
lock (queueLock)
{
// Create a structure and add data
QueueItemStruct QIS = new QueueItemStruct();
QIS.localID = localID;
QIS.itemID = itemID;
QIS.functionName = FunctionName;
QIS.param = param;
// Add it to queue
eventQueue.Enqueue(QIS);
}
}
}
}

View File

@ -0,0 +1,321 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using libsecondlife;
using OpenSim.Region.ScriptEngine.Common;
using OpenSim.Region.Environment.Modules;
using OpenSim.Region.Environment.Interfaces;
namespace OpenSim.Region.ScriptEngine.DotNetEngine
{
/// <summary>
/// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
/// </summary>
class LSLLongCmdHandler
{
private Thread cmdHandlerThread;
private int cmdHandlerThreadCycleSleepms = 100;
private ScriptEngine m_ScriptEngine;
public LSLLongCmdHandler(ScriptEngine _ScriptEngine)
{
m_ScriptEngine = _ScriptEngine;
// Start the thread that will be doing the work
cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
cmdHandlerThread.Name = "CmdHandlerThread";
cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
cmdHandlerThread.IsBackground = true;
cmdHandlerThread.Start();
}
~LSLLongCmdHandler()
{
// Shut down thread
try
{
if (cmdHandlerThread != null)
{
if (cmdHandlerThread.IsAlive == true)
{
cmdHandlerThread.Abort();
cmdHandlerThread.Join();
}
}
}
catch { }
}
private void CmdHandlerThreadLoop()
{
while (true)
{
// Check timers
CheckTimerEvents();
Thread.Sleep(25);
// Check HttpRequests
CheckHttpRequests();
Thread.Sleep(25);
// Check XMLRPCRequests
CheckXMLRPCRequests();
Thread.Sleep(25);
// Check Listeners
CheckListeners();
Thread.Sleep(25);
// Sleep before next cycle
//Thread.Sleep(cmdHandlerThreadCycleSleepms);
}
}
/// <summary>
/// Remove a specific script (and all its pending commands)
/// </summary>
/// <param name="m_localID"></param>
/// <param name="m_itemID"></param>
public void RemoveScript(uint localID, LLUUID itemID)
{
// Remove a specific script
// Remove from: Timers
UnSetTimerEvents(localID, itemID);
// Remove from: HttpRequest
StopHttpRequest(localID, itemID);
}
#region TIMER
//
// TIMER
//
private class TimerClass
{
public uint localID;
public LLUUID itemID;
public double interval;
public DateTime next;
}
private List<TimerClass> Timers = new List<TimerClass>();
private object TimerListLock = new object();
public void SetTimerEvent(uint m_localID, LLUUID m_itemID, double sec)
{
Console.WriteLine("SetTimerEvent");
// Always remove first, in case this is a re-set
UnSetTimerEvents(m_localID, m_itemID);
if (sec == 0) // Disabling timer
return;
// Add to timer
TimerClass ts = new TimerClass();
ts.localID = m_localID;
ts.itemID = m_itemID;
ts.interval = sec;
ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
lock (TimerListLock)
{
Timers.Add(ts);
}
}
public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
{
// Remove from timer
lock (TimerListLock)
{
List<TimerClass> NewTimers = new List<TimerClass>();
foreach (TimerClass ts in Timers)
{
if (ts.localID != m_localID && ts.itemID != m_itemID)
{
NewTimers.Add(ts);
}
}
Timers.Clear();
Timers = NewTimers;
}
}
public void CheckTimerEvents()
{
// Nothing to do here?
if (Timers.Count == 0)
return;
lock (TimerListLock)
{
// Go through all timers
foreach (TimerClass ts in Timers)
{
// Time has passed?
if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
{
// Add it to queue
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", new object[] { });
// set next interval
ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
}
}
} // lock
}
#endregion
#region HTTP REQUEST
//
// HTTP REAQUEST
//
private class HttpClass
{
public uint localID;
public LLUUID itemID;
public string url;
public List<string> parameters;
public string body;
public DateTime next;
public string response_request_id;
public int response_status;
public List<string> response_metadata;
public string response_body;
public void SendRequest()
{
// TODO: SEND REQUEST!!!
}
public void Stop()
{
// TODO: Cancel any ongoing request
}
public bool CheckResponse()
{
// TODO: Check if we got a response yet, return true if so -- false if not
return true;
// TODO: If we got a response, set the following then return true
//response_request_id
//response_status
//response_metadata
//response_body
}
}
private List<HttpClass> HttpRequests = new List<HttpClass>();
private object HttpListLock = new object();
public void StartHttpRequest(uint localID, LLUUID itemID, string url, List<string> parameters, string body)
{
Console.WriteLine("StartHttpRequest");
HttpClass htc = new HttpClass();
htc.localID = localID;
htc.itemID = itemID;
htc.url = url;
htc.parameters = parameters;
htc.body = body;
lock (HttpListLock)
{
//ADD REQUEST
HttpRequests.Add(htc);
}
}
public void StopHttpRequest(uint m_localID, LLUUID m_itemID)
{
// Remove from list
lock (HttpListLock)
{
List<HttpClass> NewHttpList = new List<HttpClass>();
foreach (HttpClass ts in HttpRequests)
{
if (ts.localID != m_localID && ts.itemID != m_itemID)
{
// Keeping this one
NewHttpList.Add(ts);
}
else
{
// Shutting this one down
ts.Stop();
}
}
HttpRequests.Clear();
HttpRequests = NewHttpList;
}
}
public void CheckHttpRequests()
{
// Nothing to do here?
if (HttpRequests.Count == 0)
return;
lock (HttpListLock)
{
foreach (HttpClass ts in HttpRequests)
{
if (ts.CheckResponse() == true)
{
// Add it to event queue
//key request_id, integer status, list metadata, string body
object[] resobj = new object[] { ts.response_request_id, ts.response_status, ts.response_metadata, ts.response_body };
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "http_response", resobj);
// Now stop it
StopHttpRequest(ts.localID, ts.itemID);
}
}
} // lock
}
#endregion
public void CheckXMLRPCRequests()
{
IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
while (xmlrpc.hasRequests())
{
RPCRequestInfo rInfo = xmlrpc.GetNextRequest();
System.Console.WriteLine("PICKED REQUEST");
//Deliver data to prim's remote_data handler
object[] resobj = new object[] {
2, rInfo.GetChannelKey().ToString(), rInfo.GetMessageID().ToString(), "", rInfo.GetIntValue(), rInfo.GetStrVal()
};
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", resobj
);
}
}
public void CheckListeners()
{
IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
while (comms.HasMessages())
{
ListenerInfo lInfo = comms.GetNextMessage();
System.Console.WriteLine("PICKED LISTENER");
//Deliver data to prim's listen handler
object[] resobj = new object[] {
lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage()
};
m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
lInfo.GetLocalID(), lInfo.GetItemID(), "listen", resobj
);
}
}
}
}

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OpenSim.Grid.ScriptEngine.DotNetEngine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OpenSim.Grid.ScriptEngine.DotNetEngine")]
[assembly: AssemblyCopyright("Copyright © 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2842257e-6fde-4460-9368-4cde57fa9cc4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,132 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework.Console;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Scenes.Scripting;
using OpenSim.Region.Environment.Interfaces;
using libsecondlife;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
/// <summary>
/// This is the root object for ScriptEngine
/// </summary>
[Serializable]
public class ScriptEngine :IRegionModule
{
internal OpenSim.Region.Environment.Scenes.Scene World;
internal EventManager m_EventManager; // Handles and queues incoming events from OpenSim
internal EventQueueManager m_EventQueueManager; // Executes events
internal ScriptManager m_ScriptManager; // Load, unload and execute scripts
internal AppDomainManager m_AppDomainManager;
internal LSLLongCmdHandler m_LSLLongCmdHandler;
private OpenSim.Framework.Console.LogBase m_log;
public ScriptEngine()
{
//Common.SendToDebug("ScriptEngine Object Initialized");
Common.mySE = this;
}
public LogBase Log
{
get { return m_log; }
}
public void InitializeEngine(OpenSim.Region.Environment.Scenes.Scene Sceneworld, OpenSim.Framework.Console.LogBase logger)
{
World = Sceneworld;
m_log = logger;
Log.Verbose("ScriptEngine", "DotNet & LSL ScriptEngine initializing");
//m_logger.Status("ScriptEngine", "InitializeEngine");
// Create all objects we'll be using
m_EventQueueManager = new EventQueueManager(this);
m_EventManager = new EventManager(this);
m_ScriptManager = new ScriptManager(this);
m_AppDomainManager = new AppDomainManager();
m_LSLLongCmdHandler = new LSLLongCmdHandler(this);
// Should we iterate the region for scripts that needs starting?
// Or can we assume we are loaded before anything else so we can use proper events?
}
public void Shutdown()
{
// We are shutting down
}
//// !!!FOR DEBUGGING ONLY!!! (for executing script directly from test app)
//[Obsolete("!!!FOR DEBUGGING ONLY!!!")]
//public void StartScript(string ScriptID, IScriptHost ObjectID)
//{
// this.myEventManager.TEMP_OBJECT_ID = ObjectID;
// Log.Status("ScriptEngine", "DEBUG FUNCTION: StartScript: " + ScriptID);
// myScriptManager.StartScript(ScriptID, ObjectID);
//}
#region IRegionModule
public void Initialise(Scene scene)
{
this.InitializeEngine(scene, MainLog.Instance);
}
public void PostInitialise()
{
}
public void CloseDown()
{
}
public string GetName()
{
return "LSLScriptingModule";
}
public bool IsSharedModule()
{
return false;
}
#endregion
}
}

View File

@ -0,0 +1,417 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Original code: Tedd Hansen */
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.Environment.Scenes.Scripting;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler;
using OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL;
using OpenSim.Region.ScriptEngine.Common;
using libsecondlife;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
/// <summary>
/// Loads scripts
/// Compiles them if necessary
/// Execute functions for EventQueueManager (Sends them to script on other AppDomain for execution)
/// </summary>
[Serializable]
public class ScriptManager
{
#region Declares
private Thread scriptLoadUnloadThread;
private int scriptLoadUnloadThread_IdleSleepms = 100;
private Queue<LoadStruct> loadQueue = new Queue<LoadStruct>();
private Queue<UnloadStruct> unloadQueue = new Queue<UnloadStruct>();
private struct LoadStruct
{
public uint localID;
public LLUUID itemID;
public string script;
}
private struct UnloadStruct
{
public uint localID;
public LLUUID itemID;
}
// Object<string, Script<string, script>>
// IMPORTANT: Types and MemberInfo-derived objects require a LOT of memory.
// Instead use RuntimeTypeHandle, RuntimeFieldHandle and RunTimeHandle (IntPtr) instead!
internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
public Scene World
{
get
{
return m_scriptEngine.World;
}
}
#endregion
#region Object init/shutdown
private ScriptEngine m_scriptEngine;
public ScriptManager(ScriptEngine scriptEngine)
{
m_scriptEngine = scriptEngine;
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
scriptLoadUnloadThread = new Thread(ScriptLoadUnloadThreadLoop);
scriptLoadUnloadThread.Name = "ScriptLoadUnloadThread";
scriptLoadUnloadThread.IsBackground = true;
scriptLoadUnloadThread.Priority = ThreadPriority.BelowNormal;
scriptLoadUnloadThread.Start();
}
~ScriptManager ()
{
// Abort load/unload thread
try
{
if (scriptLoadUnloadThread != null)
{
if (scriptLoadUnloadThread.IsAlive == true)
{
scriptLoadUnloadThread.Abort();
scriptLoadUnloadThread.Join();
}
}
}
catch
{
}
}
#endregion
#region Load / Unload scripts (Thread loop)
private void ScriptLoadUnloadThreadLoop()
{
try
{
while (true)
{
if (loadQueue.Count == 0 && unloadQueue.Count == 0)
Thread.Sleep(scriptLoadUnloadThread_IdleSleepms);
if (loadQueue.Count > 0)
{
LoadStruct item = loadQueue.Dequeue();
_StartScript(item.localID, item.itemID, item.script);
}
if (unloadQueue.Count > 0)
{
UnloadStruct item = unloadQueue.Dequeue();
_StopScript(item.localID, item.itemID);
}
}
}
catch (ThreadAbortException tae)
{
string a = tae.ToString();
a = "";
// Expected
}
}
#endregion
#region Helper functions
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
//Console.WriteLine("ScriptManager.CurrentDomain_AssemblyResolve: " + args.Name);
return Assembly.GetExecutingAssembly().FullName == args.Name ? Assembly.GetExecutingAssembly() : null;
}
#endregion
#region Internal functions to keep track of script
internal Dictionary<LLUUID, LSL_BaseClass>.KeyCollection GetScriptKeys(uint localID)
{
if (Scripts.ContainsKey(localID) == false)
return null;
Dictionary<LLUUID, LSL_BaseClass> Obj;
Scripts.TryGetValue(localID, out Obj);
return Obj.Keys;
}
internal LSL_BaseClass GetScript(uint localID, LLUUID itemID)
{
if (Scripts.ContainsKey(localID) == false)
return null;
Dictionary<LLUUID, LSL_BaseClass> Obj;
Scripts.TryGetValue(localID, out Obj);
if (Obj.ContainsKey(itemID) == false)
return null;
// Get script
LSL_BaseClass Script;
Obj.TryGetValue(itemID, out Script);
return Script;
}
internal void SetScript(uint localID, LLUUID itemID, LSL_BaseClass Script)
{
// Create object if it doesn't exist
if (Scripts.ContainsKey(localID) == false)
{
Scripts.Add(localID, new Dictionary<LLUUID, LSL_BaseClass>());
}
// Delete script if it exists
Dictionary<LLUUID, LSL_BaseClass> Obj;
Scripts.TryGetValue(localID, out Obj);
if (Obj.ContainsKey(itemID) == true)
Obj.Remove(itemID);
// Add to object
Obj.Add(itemID, Script);
}
internal void RemoveScript(uint localID, LLUUID itemID)
{
// Don't have that object?
if (Scripts.ContainsKey(localID) == false)
return;
// Delete script if it exists
Dictionary<LLUUID, LSL_BaseClass> Obj;
Scripts.TryGetValue(localID, out Obj);
if (Obj.ContainsKey(itemID) == true)
Obj.Remove(itemID);
}
#endregion
#region Start/Stop/Reset script
/// <summary>
/// Fetches, loads and hooks up a script to an objects events
/// </summary>
/// <param name="itemID"></param>
/// <param name="localID"></param>
public void StartScript(uint localID, LLUUID itemID, string Script)
{
LoadStruct ls = new LoadStruct();
ls.localID = localID;
ls.itemID = itemID;
ls.script = Script;
loadQueue.Enqueue(ls);
}
/// <summary>
/// Disables and unloads a script
/// </summary>
/// <param name="localID"></param>
/// <param name="itemID"></param>
public void StopScript(uint localID, LLUUID itemID)
{
UnloadStruct ls = new UnloadStruct();
ls.localID = localID;
ls.itemID = itemID;
unloadQueue.Enqueue(ls);
}
public void ResetScript(uint localID, LLUUID itemID)
{
string script = GetScript(localID, itemID).SourceCode;
StopScript(localID, itemID);
StartScript(localID, itemID, script);
}
private void _StartScript(uint localID, LLUUID itemID, string Script)
{
//IScriptHost root = host.GetRoot();
Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID);
// We will initialize and start the script.
// It will be up to the script itself to hook up the correct events.
string ScriptSource = "";
SceneObjectPart m_host = World.GetSceneObjectPart(localID);
try
{
// Create a new instance of the compiler (currently we don't want reuse)
OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler LSLCompiler = new OpenSim.Grid.ScriptEngine.DotNetEngine.Compiler.LSL.Compiler();
// Compile (We assume LSL)
ScriptSource = LSLCompiler.CompileFromLSLText(Script);
//Console.WriteLine("Compilation of " + FileName + " done");
// * Insert yield into code
ScriptSource = ProcessYield(ScriptSource);
#if DEBUG
long before;
before = GC.GetTotalMemory(true);
#endif
LSL_BaseClass CompiledScript;
CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource);
#if DEBUG
Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before);
#endif
CompiledScript.SourceCode = ScriptSource;
// Add it to our script memstruct
SetScript(localID, itemID, CompiledScript);
// We need to give (untrusted) assembly a private instance of BuiltIns
// this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed.
LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID);
// Start the script - giving it BuiltIns
CompiledScript.Start(LSLB);
// Fire the first start-event
m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { });
}
catch (Exception e)
{
//m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString());
try
{
// DISPLAY ERROR INWORLD
string text = "Error compiling script:\r\n" + e.Message.ToString();
if (text.Length > 1500)
text = text.Substring(0, 1500);
World.SimChat(Helpers.StringToField(text), 1, 0, m_host.AbsolutePosition, m_host.Name, m_host.UUID);
}
catch (Exception e2)
{
m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString());
}
}
}
private void _StopScript(uint localID, LLUUID itemID)
{
// Stop script
Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString());
// Stop long command on script
m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID);
LSL_BaseClass LSLBC = GetScript(localID, itemID);
if (LSLBC == null)
return;
// TEMP: First serialize it
//GetSerializedScript(localID, itemID);
try
{
// Get AppDomain
AppDomain ad = LSLBC.Exec.GetAppDomain();
// Tell script not to accept new requests
GetScript(localID, itemID).Exec.StopScript();
// Remove from internal structure
RemoveScript(localID, itemID);
// Tell AppDomain that we have stopped script
m_scriptEngine.m_AppDomainManager.StopScript(ad);
}
catch(Exception e)
{
Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + ": " + e.ToString());
}
}
private string ProcessYield(string FileName)
{
// TODO: Create a new assembly and copy old but insert Yield Code
//return TempDotNetMicroThreadingCodeInjector.TestFix(FileName);
return FileName;
}
#endregion
#region Perform event execution in script
/// <summary>
/// Execute a LL-event-function in Script
/// </summary>
/// <param name="localID">Object the script is located in</param>
/// <param name="itemID">Script ID</param>
/// <param name="FunctionName">Name of function</param>
/// <param name="args">Arguments to pass to function</param>
internal void ExecuteEvent(uint localID, LLUUID itemID, string FunctionName, object[] args)
{
// Execute a function in the script
//m_scriptEngine.Log.Verbose("ScriptEngine", "Executing Function localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName);
LSL_BaseClass Script = m_scriptEngine.m_ScriptManager.GetScript(localID, itemID);
if (Script == null)
return;
// Must be done in correct AppDomain, so leaving it up to the script itself
Script.Exec.ExecuteEvent(FunctionName, args);
}
#endregion
#region Script serialization/deserialization
public void GetSerializedScript(uint localID, LLUUID itemID)
{
// Serialize the script and return it
// Should not be a problem
System.IO.FileStream fs = System.IO.File.Create("SERIALIZED_SCRIPT_" + itemID);
BinaryFormatter b = new BinaryFormatter();
b.Serialize(fs, GetScript(localID,itemID));
fs.Close();
}
public void PutSerializedScript(uint localID, LLUUID itemID)
{
// Deserialize the script and inject it into an AppDomain
// How to inject into an AppDomain?
}
#endregion
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
using Rail.Transformation;
using Rail.Reflect;
using Rail.Exceptions;
using Rail.MSIL;
namespace OpenSim.Grid.ScriptEngine.DotNetEngine
{
/// <summary>
/// Tedds Sandbox for RAIL/microtrheading. This class is only for testing purposes!
/// Its offspring will be the actual implementation.
/// </summary>
class TempDotNetMicroThreadingCodeInjector
{
public static string TestFix(string FileName)
{
string ret = System.IO.Path.GetFileNameWithoutExtension(FileName + "_fixed.dll");
Console.WriteLine("Loading: \"" + FileName + "\"");
RAssemblyDef rAssembly = RAssemblyDef.LoadAssembly(FileName);
//Get the type of the method to copy from assembly Teste2.exe to assembly Teste.exe
RTypeDef type = (RTypeDef)rAssembly.RModuleDef.GetType("SecondLife.Script");
//Get the methods in the type
RMethod[] m = type.GetMethods();
//Create a MethodPrologueAdder visitor object with the method to add
//and with the flag that enables local variable creation set to true
MethodPrologueAdder mpa = new MethodPrologueAdder((RMethodDef)m[0], true);
//Apply the changes to the assembly
rAssembly.Accept(mpa);
//Save the new assembly
rAssembly.SaveAssembly(ret);
return ret;
}
}
}

View File

@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Grid.ScriptServer
{
public abstract class RegionBase
{
// These are events that the region needs to have
// TEMP: Using System.Delegate -- needs replacing with a real delegate
public delegate void DefaultDelegate();
public event DefaultDelegate onScriptRez;
public event DefaultDelegate onstate_entry;
public event DefaultDelegate onstate_exit;
public event DefaultDelegate ontouch_start;
public event DefaultDelegate ontouch;
public event DefaultDelegate ontouch_end;
public event DefaultDelegate oncollision_start;
public event DefaultDelegate oncollision;
public event DefaultDelegate oncollision_end;
public event DefaultDelegate onland_collision_start;
public event DefaultDelegate onland_collision;
public event DefaultDelegate onland_collision_end;
public event DefaultDelegate ontimer;
public event DefaultDelegate onlisten;
public event DefaultDelegate onon_rez;
public event DefaultDelegate onsensor;
public event DefaultDelegate onno_sensor;
public event DefaultDelegate oncontrol;
public event DefaultDelegate onmoney;
public event DefaultDelegate onemail;
public event DefaultDelegate onat_target;
public event DefaultDelegate onnot_at_target;
public event DefaultDelegate onat_rot_target;
public event DefaultDelegate onnot_at_rot_target;
public event DefaultDelegate onrun_time_permissions;
public event DefaultDelegate onchanged;
public event DefaultDelegate onattach;
public event DefaultDelegate ondataserver;
public event DefaultDelegate onlink_message;
public event DefaultDelegate onmoving_start;
public event DefaultDelegate onmoving_end;
public event DefaultDelegate onobject_rez;
public event DefaultDelegate onremote_data;
public event DefaultDelegate onhttp_response;
public void ScriptRez() { onScriptRez(); }
public void state_entry() { onstate_entry(); }
public void state_exit() { onstate_exit(); }
public void touch_start() { ontouch_start(); }
public void touch() { ontouch(); }
public void touch_end() { ontouch_end(); }
public void collision_start() { oncollision_start(); }
public void collision() { oncollision(); }
public void collision_end() { oncollision_end(); }
public void land_collision_start() { onland_collision_start(); }
public void land_collision() { onland_collision(); }
public void land_collision_end() { onland_collision_end(); }
public void timer() { ontimer(); }
public void listen() { onlisten(); }
public void on_rez() { onon_rez(); }
public void sensor() { onsensor(); }
public void no_sensor() { onno_sensor(); }
public void control() { oncontrol(); }
public void money() { onmoney(); }
public void email() { onemail(); }
public void at_target() { onat_target(); }
public void not_at_target() { onnot_at_target(); }
public void at_rot_target() { onat_rot_target(); }
public void not_at_rot_target() { onnot_at_rot_target(); }
public void run_time_permissions() { onrun_time_permissions(); }
public void changed() { onchanged(); }
public void attach() { onattach(); }
public void dataserver() { ondataserver(); }
public void link_message() { onlink_message(); }
public void moving_start() { onmoving_start(); }
public void moving_end() { onmoving_end(); }
public void object_rez() { onobject_rez(); }
public void remote_data() { onremote_data(); }
public void http_response() { onhttp_response(); }
}
}

View File

@ -1,15 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Framework.Console;
namespace OpenSim.Grid.ScriptServer
{
// Maintains connection and communication to a region
internal class RegionConnectionManager
public class RegionConnectionManager: RegionBase
{
public RegionConnectionManager()
private LogBase m_log;
private ScriptServerMain m_ScriptServerMain;
private object m_Connection;
public RegionConnectionManager(ScriptServerMain scm, LogBase logger, object Connection)
{
m_ScriptServerMain = scm;
m_log = logger;
m_Connection = Connection;
}
private void DataReceived(object objectID, object scriptID)
{
// TODO: HOW DO WE RECEIVE DATA? ASYNC?
// ANYHOW WE END UP HERE?
// NEW SCRIPT? ASK SCRIPTENGINE TO INITIALIZE IT
ScriptRez();
// EVENT? DELIVER EVENT DIRECTLY TO SCRIPTENGINE
touch_start();
}
}

View File

@ -93,6 +93,9 @@ namespace OpenSim.Grid.ScriptServer
// ~ ask scriptengines if they will accept script?
// - Add script to shared communication channel towards that region
// TODO: FAKING A CONNECTION
Regions.Add(new RegionConnectionManager(m_ScriptServerMain, m_log, null));
}
}

View File

@ -31,7 +31,7 @@ namespace OpenSim.Grid.ScriptServer
{
public interface ScriptEngineInterface
{
//void InitializeEngine(Scene Sceneworld, LogBase logger);
void InitializeEngine(RegionConnectionManager Region, LogBase logger);
void Shutdown();
// void StartScript(string ScriptID, IScriptHost ObjectID);
}

View File

@ -931,6 +931,61 @@
</Project>
<Project name="OpenSim.Grid.ScriptEngine.Common" path="OpenSim/Grid/ScriptEngine/Common" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../../bin/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../../bin/</ReferencePath>
<ReferencePath>../../../../bin/ScriptEngines/</ReferencePath>
<Reference name="System" localCopy="false"/>
<Reference name="System.Data" localCopy="false"/>
<Reference name="System.Xml" localCopy="false"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
<Project name="OpenSim.Grid.ScriptEngine.DotNetEngine" path="OpenSim/Grid/ScriptEngine/DotNetEngine" type="Library">
<Configuration name="Debug">
<Options>
<OutputPath>../../../../bin/ScriptEngines/</OutputPath>
</Options>
</Configuration>
<Configuration name="Release">
<Options>
<OutputPath>../../../../bin/ScriptEngines/</OutputPath>
</Options>
</Configuration>
<ReferencePath>../../../../bin/</ReferencePath>
<ReferencePath>../../../../bin/ScriptEngines/</ReferencePath>
<Reference name="System" localCopy="false"/>
<Reference name="System.Data" localCopy="false"/>
<Reference name="System.Xml" localCopy="false"/>
<Reference name="System.Runtime.Remoting" localCopy="false"/>
<Reference name="OpenSim.Region.Environment" />
<Reference name="libsecondlife.dll"/>
<Reference name="RAIL.dll"/>
<Reference name="OpenSim.Framework"/>
<Reference name="OpenSim.Framework.Console"/>
<Reference name="OpenSim.Region.ScriptEngine.Common"/>
<Reference name="Axiom.MathLib.dll" localCopy="false"/>
<Files>
<Match pattern="*.cs" recurse="true"/>
</Files>
</Project>
</Solution>