fixed support of progs.dat files with important global and field names removed, such...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 19 Feb 2007 01:15:58 +0000 (01:15 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 19 Feb 2007 01:15:58 +0000 (01:15 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6860 d7cf8633-e32d-0410-b094-e92efae38249

csprogs.c
menu.c
progsvm.h
prvm_edict.c
sv_main.c

index 28fc973..343f8a1 100644 (file)
--- a/csprogs.c
+++ b/csprogs.c
@@ -645,9 +645,7 @@ void CL_VM_Init (void)
 
        PRVM_LoadProgs(csqc_progname.string, cl_numrequiredfunc, cl_required_func, 0, NULL, 0, NULL);
 
-       if(prog->loaded)
-               Con_Printf("CSQC ^5loaded (crc=%i, size=%i)\n", csprogsdatacrc, (int)csprogsdatasize);
-       else
+       if (!prog->loaded)
        {
                CL_VM_Error("CSQC ^2failed to load\n");
                if(!sv.active)
@@ -655,6 +653,12 @@ void CL_VM_Init (void)
                return;
        }
 
+       Con_Printf("CSQC ^5loaded (crc=%i, size=%i)\n", csprogsdatacrc, (int)csprogsdatasize);
+
+       // check if OP_STATE animation is possible in this dat file
+       if (prog->fieldoffsets.nextthink >= 0 && prog->fieldoffsets.frame >= 0 && prog->fieldoffsets.think >= 0 && prog->globaloffsets.self >= 0)
+               prog->flag |= PRVM_OP_STATE;
+
        //[515]: optional fields & funcs
        if(prog->funcoffsets.CSQC_Parse_Print)
        {
diff --git a/menu.c b/menu.c
index 405a72b..e28b04c 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -4960,6 +4960,9 @@ void MP_Init (void)
 
        PRVM_LoadProgs(M_PROG_FILENAME, m_numrequiredfunc, m_required_func, 0, NULL, 0, NULL);
 
+       // note: OP_STATE is not supported by menu qc, we don't even try to detect
+       // it here
+
 #ifdef NG_MENU
        m_displayed = false;
 #endif
index 17cf736..cb46759 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -461,6 +461,8 @@ mfunction_t *PRVM_ED_FindFunction(const char *name);
 int PRVM_ED_FindFieldOffset(const char *name);
 int PRVM_ED_FindGlobalOffset(const char *name);
 func_t PRVM_ED_FindFunctionOffset(const char *name);
+#define PRVM_ED_FindFieldOffset_FromStruct(st, field) prog->fieldoffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
+#define PRVM_ED_FindGlobalOffset_FromStruct(st, field) prog->globaloffsets . field = ((int *)(&((st *)NULL)-> field ) - ((int *)NULL))
 
 void PRVM_MEM_IncreaseEdicts(void);
 
index 700dd8e..f9db9de 100644 (file)
@@ -1684,10 +1684,6 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
 
        PRVM_FindOffsets();
 
-       // check if OP_STATE animation is possible in this dat file
-       if (prog->fieldoffsets.nextthink >= 0 && prog->fieldoffsets.frame >= 0 && prog->fieldoffsets.think >= 0 && prog->globaloffsets.self >= 0)
-               prog->flag |= PRVM_OP_STATE;
-
        PRVM_GCALL(init_cmd)();
 
        // init mempools
index d330329..0f3eb57 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -2448,6 +2448,35 @@ void SV_VM_Setup(void)
        // TODO: add a requiredfuncs list (ask LH if this is necessary at all)
        PRVM_LoadProgs( sv_progs.string, 0, NULL, REQFIELDS, reqfields, 0, NULL );
 
+       // some mods compiled with scrambling compilers lack certain critical
+       // global names and field names such as "self" and "time" and "nextthink"
+       // so we have to set these offsets manually, matching the entvars_t
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, angles);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, chain);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, classname);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, frame);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, groundentity);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, ideal_yaw);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, nextthink);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, think);
+       PRVM_ED_FindFieldOffset_FromStruct(entvars_t, yaw_speed);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, self);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, time);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, v_forward);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, v_right);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, v_up);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_allsolid);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_startsolid);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_fraction);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_inwater);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_inopen);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_endpos);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_plane_normal);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_plane_dist);
+       PRVM_ED_FindGlobalOffset_FromStruct(globalvars_t, trace_ent);
+       // OP_STATE is always supported on server (due to entvars_t)
+       prog->flag |= PRVM_OP_STATE;
+
        VM_AutoSentStats_Clear();//[515]: csqc
        EntityFrameCSQC_ClearVersions();//[515]: csqc