/*
* Search all or given vobs by base class
*//*
* Retrieve class definition address by string
*/
func int GetClassDefByString(var string classDefName) {
const int zCClassDef__GetClassDef_G1 = 5809264; //0x58A470
const int zCClassDef__GetClassDef_G2 = 5939168; //0x5A9FE0
var int classDefNamePtr; classDefNamePtr = _@s(classDefName);
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam(_@(classDefNamePtr));
CALL__cdecl(MEMINT_SwitchG1G2(zCClassDef__GetClassDef_G1, zCClassDef__GetClassDef_G2));
call = CALL_End();
};
return CALL_RetValAsPtr();
};
func int SearchVobsByClass(var string className, var int vobListPtr) {
const int zCWorld__SearchVobListByBaseClass_G1 = 6250016; //0x5F5E20
const int zCWorld__SearchVobListByBaseClass_G2 = 6439712; //0x624320
var zCArray vobList; vobList = _^(vobListPtr);
if (!vobList.numInArray) {
var int vobTreePtr; vobTreePtr = _@(MEM_Vobtree);
var int worldPtr; worldPtr = _@(MEM_World);
var int classDef; classDef = GetClassDefByString(className);
const int call = 0;
if (CALL_Begin(call)) {
CALL_PtrParam(_@(vobTreePtr));
CALL_PtrParam(_@(vobListPtr));
CALL_PtrParam(_@(classDef));
CALL__thiscall(_@(worldPtr), MEMINT_SwitchG1G2(zCWorld__SearchVobListByBaseClass_G1,
zCWorld__SearchVobListByBaseClass_G2));
call = CALL_End();
};
} else {
// Iterate over all vobs and remove the ones not matching the criteria
var int i; i = 0;
while(i < vobList.numInArray);
var int vobPtr; vobPtr = MEM_ArrayRead(vobListPtr, i);
if (objCheckInheritance(vobPtr, classDef)) {
// Keep vob
i += 1;
} else {
// Otherwise remove vob from array
MEM_ArrayRemoveIndex(vobListPtr, i);
};
end;
};
return vobList.numInArray;
};
/*
* Search all or given vobs by visual
*/
func int SearchVobsByVisual(var string visual, var int vobListPtr) {
// Create vob list if empty
var zCArray vobList; vobList = _^(vobListPtr);
if (!vobList.numInArray) {
if (!SearchVobsByClass("zCVob", vobListPtr)) {
return 0;
};
};
// Iterate over all vobs and remove the ones not matching the criteria
var int i; i = 0;
while(i < vobList.numInArray);
var int vobPtr; vobPtr = MEM_ArrayRead(vobListPtr, i);
if (vobPtr) {
// Check for visual
var zCVob vob; vob = _^(vobPtr);
if (vob.visual) {
// Compare visual
var zCObject visualObj; visualObj = _^(vob.visual);
if (Hlp_StrCmp(visualObj.objectname, visual)) {
// Keep vob
i += 1;
continue;
};
};
};
// Otherwise remove vob from array
MEM_ArrayRemoveIndex(vobListPtr, i);
end;
return vobList.numInArray;
};
/*
* Search all or given vobs by proximity
*/
func int SearchVobsByProximity(var int posPtr, var int maxDist, var int vobListPtr) {
// Create vob list if empty
var zCArray vobList; vobList = _^(vobListPtr);
if (!vobList.numInArray) {
if (!SearchVobsByClass("zCVob", vobListPtr)) {
return 0;
};
};
var int pos[3];
MEM_CopyWords(posPtr, _@(pos), 3);
// Iterate over all vobs and remove the ones not matching the criteria
var int i; i = 0;
while(i < vobList.numInArray);
var int vobPtr; vobPtr = MEM_ArrayRead(vobListPtr, i);
if (vobPtr) {
// Check distance
var zCVob vob; vob = _^(vobPtr);
// Compute distance between vob and position
var int dist[3];
dist[0] = subf(vob.trafoObjToWorld[ 3], pos[0]);
dist[1] = subf(vob.trafoObjToWorld[ 7], pos[1]);
dist[2] = subf(vob.trafoObjToWorld[11], pos[2]);
var int distance;
distance = sqrtf(addf(addf(sqrf(dist[0]), sqrf(dist[1])), sqrf(dist[2])));
// Check if distance is with in maxDist
if (lef(distance, maxDist)) {
// Keep vob
i += 1;
continue;
};
};
// Otherwise remove vob from array
MEM_ArrayRemoveIndex(vobListPtr, i);
end;
return vobList.numInArray;
};
/*
* Search all or given vobs by remoteness
*/
func int SearchVobsByRemoteness(var int posPtr, var int minDist, var int vobListPtr) {
// Create vob list if empty
var zCArray vobList; vobList = _^(vobListPtr);
if (!vobList.numInArray) {
if (!SearchVobsByClass("zCVob", vobListPtr)) {
return 0;
};
};
var int pos[3];
MEM_CopyWords(posPtr, _@(pos), 3);
// Iterate over all vobs and remove the ones not matching the criteria
var int i; i = 0;
while(i < vobList.numInArray);
var int vobPtr; vobPtr = MEM_ArrayRead(vobListPtr, i);
if (vobPtr) {
// Check distance
var zCVob vob; vob = _^(vobPtr);
// Compute distance between vob and position
var int dist[3];
dist[0] = subf(vob.trafoObjToWorld[ 3], pos[0]);
dist[1] = subf(vob.trafoObjToWorld[ 7], pos[1]);
dist[2] = subf(vob.trafoObjToWorld[11], pos[2]);
var int distance;
distance = sqrtf(addf(addf(sqrf(dist[0]), sqrf(dist[1])), sqrf(dist[2])));
// Check if distance is beyond minDist
if (gf(distance, minDist)) {
// Keep vob
i += 1;
continue;
};
};
// Otherwise remove vob from array
MEM_ArrayRemoveIndex(vobListPtr, i);
end;
return vobList.numInArray;
};
var int Grass_Dist;
func void FixMobSwitches_Restore_Sub(var int vobArrayPtr)
{
var zCArray vobList;
vobList = _^(vobArrayPtr);
repeat(i, vobList.numInArray);
var int i;
var int vobPtr; vobPtr = MEM_ArrayRead(vobArrayPtr, i);
var oCMobInter mob;
mob = _^ (vobPtr);
if(Grass_Dist == 0)
{
mob._zCVob_m_fVobFarClipZScale = 1036831949;
}
else if(Grass_Dist == 1)
{
mob._zCVob_m_fVobFarClipZScale = 1045220557;
}
else if(Grass_Dist == 2)
{
mob._zCVob_m_fVobFarClipZScale = 1050253722;
}
else if(Grass_Dist == 3)
{
mob._zCVob_m_fVobFarClipZScale = 1053609165;
}
else if(Grass_Dist == 4)
{
mob._zCVob_m_fVobFarClipZScale = 1056964608;
}
else if(Grass_Dist == 5)
{
mob._zCVob_m_fVobFarClipZScale = 1058642330;
}
else if(Grass_Dist == 6)
{
mob._zCVob_m_fVobFarClipZScale = 1060320051;
}
else if(Grass_Dist == 7)
{
mob._zCVob_m_fVobFarClipZScale = 1061997773;
}
else if(Grass_Dist == 8)
{
mob._zCVob_m_fVobFarClipZScale = 1063675494;
}
else if(Grass_Dist == 9)
{
mob._zCVob_m_fVobFarClipZScale = 1065353216;
}
else if(Grass_Dist == 10)
{
mob._zCVob_m_fVobFarClipZScale = 0;
};
end;
};
func void FixMobSwitches_Restore()
{
var int vobArrayPtr;
vobArrayPtr = MEM_ArrayCreate();
if(SearchVobsByVisual("GRAS1X1.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
if(SearchVobsByVisual("GRAS1X1_G.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
if(SearchVobsByVisual("GRAS1X0.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
if(SearchVobsByVisual("GRAS1X0_G.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
if(SearchVobsByVisual("GRAS2X2.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
if(SearchVobsByVisual("OW_NATURE_BUSH_02_01.3DS", vobArrayPtr))
{
FixMobSwitches_Restore_Sub(vobArrayPtr);
};
MEM_ArrayClear(vobArrayPtr);
MEM_ArrayFree(vobArrayPtr);
};