Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ziqian zhang
Grasscutter
Commits
8c860308
Commit
8c860308
authored
May 19, 2022
by
Melledy
Browse files
Fix bad casting exceptions with scene garbages objects
parent
0dac404f
Changes
5
Show whitespace changes
Inline
Side-by-side
src/main/java/emu/grasscutter/game/world/Scene.java
View file @
8c860308
...
@@ -599,6 +599,7 @@ public class Scene {
...
@@ -599,6 +599,7 @@ public class Scene {
.
map
(
g
->
scriptManager
.
createGadget
(
group
.
id
,
group
.
block_id
,
g
)).
toList
());
.
map
(
g
->
scriptManager
.
createGadget
(
group
.
id
,
group
.
block_id
,
g
)).
toList
());
entities
.
addAll
(
suiteData
.
sceneMonsters
.
stream
()
entities
.
addAll
(
suiteData
.
sceneMonsters
.
stream
()
.
map
(
mob
->
scriptManager
.
createMonster
(
group
.
id
,
group
.
block_id
,
mob
)).
toList
());
.
map
(
mob
->
scriptManager
.
createMonster
(
group
.
id
,
group
.
block_id
,
mob
)).
toList
());
suite
++;
suite
++;
}
while
(
suite
<
group
.
init_config
.
end_suite
);
}
while
(
suite
<
group
.
init_config
.
end_suite
);
}
}
...
...
src/main/java/emu/grasscutter/scripts/SceneScriptManager.java
View file @
8c860308
...
@@ -164,7 +164,10 @@ public class SceneScriptManager {
...
@@ -164,7 +164,10 @@ public class SceneScriptManager {
public
void
loadGroupFromScript
(
SceneGroup
group
)
{
public
void
loadGroupFromScript
(
SceneGroup
group
)
{
group
.
load
(
getScene
().
getId
());
group
.
load
(
getScene
().
getId
());
if
(
group
.
variables
!=
null
)
{
group
.
variables
.
forEach
(
var
->
this
.
getVariables
().
put
(
var
.
name
,
var
.
value
));
group
.
variables
.
forEach
(
var
->
this
.
getVariables
().
put
(
var
.
name
,
var
.
value
));
}
this
.
sceneGroups
.
put
(
group
.
id
,
group
);
this
.
sceneGroups
.
put
(
group
.
id
,
group
);
if
(
group
.
regions
!=
null
){
if
(
group
.
regions
!=
null
){
...
...
src/main/java/emu/grasscutter/scripts/ScriptUtils.java
0 → 100644
View file @
8c860308
package
emu.grasscutter.scripts
;
import
java.util.HashMap
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaValue
;
import
emu.grasscutter.Grasscutter
;
public
class
ScriptUtils
{
public
static
HashMap
<
Object
,
Object
>
toMap
(
LuaTable
table
)
{
HashMap
<
Object
,
Object
>
map
=
new
HashMap
<>();
LuaValue
[]
rootKeys
=
table
.
keys
();
for
(
LuaValue
k
:
rootKeys
)
{
if
(
table
.
get
(
k
).
istable
())
{
map
.
put
(
k
,
toMap
(
table
.
get
(
k
).
checktable
()));
}
else
{
map
.
put
(
k
,
table
.
get
(
k
));
}
}
return
map
;
}
public
static
void
print
(
LuaTable
table
)
{
Grasscutter
.
getLogger
().
info
(
toMap
(
table
).
toString
());
}
}
src/main/java/emu/grasscutter/scripts/data/SceneGroup.java
View file @
8c860308
...
@@ -9,6 +9,10 @@ import lombok.ToString;
...
@@ -9,6 +9,10 @@ import lombok.ToString;
import
javax.script.Bindings
;
import
javax.script.Bindings
;
import
javax.script.CompiledScript
;
import
javax.script.CompiledScript
;
import
javax.script.ScriptException
;
import
javax.script.ScriptException
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaValue
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -106,9 +110,17 @@ public class SceneGroup {
...
@@ -106,9 +110,17 @@ public class SceneGroup {
suites
=
ScriptLoader
.
getSerializer
().
toList
(
SceneSuite
.
class
,
bindings
.
get
(
"suites"
));
suites
=
ScriptLoader
.
getSerializer
().
toList
(
SceneSuite
.
class
,
bindings
.
get
(
"suites"
));
regions
=
ScriptLoader
.
getSerializer
().
toList
(
SceneRegion
.
class
,
bindings
.
get
(
"regions"
));
regions
=
ScriptLoader
.
getSerializer
().
toList
(
SceneRegion
.
class
,
bindings
.
get
(
"regions"
));
garbages
=
ScriptLoader
.
getSerializer
().
toObject
(
SceneGarbage
.
class
,
bindings
.
get
(
"garbages"
));
init_config
=
ScriptLoader
.
getSerializer
().
toObject
(
SceneInitConfig
.
class
,
bindings
.
get
(
"init_config"
));
init_config
=
ScriptLoader
.
getSerializer
().
toObject
(
SceneInitConfig
.
class
,
bindings
.
get
(
"init_config"
));
// Garbages TODO fix properly later
Object
garbagesValue
=
bindings
.
get
(
"garbages"
);
if
(
garbagesValue
!=
null
&&
garbagesValue
instanceof
LuaValue
garbagesTable
)
{
garbages
=
new
SceneGarbage
();
if
(
garbagesTable
.
checktable
().
get
(
"gadgets"
)
!=
LuaValue
.
NIL
)
{
garbages
.
gadgets
=
ScriptLoader
.
getSerializer
().
toList
(
SceneGadget
.
class
,
garbagesTable
.
checktable
().
get
(
"gadgets"
).
checktable
());
}
}
// Add variables to suite
// Add variables to suite
variables
=
ScriptLoader
.
getSerializer
().
toList
(
SceneVar
.
class
,
bindings
.
get
(
"variables"
));
variables
=
ScriptLoader
.
getSerializer
().
toList
(
SceneVar
.
class
,
bindings
.
get
(
"variables"
));
...
...
src/main/java/emu/grasscutter/scripts/serializer/LuaSerializer.java
View file @
8c860308
...
@@ -2,6 +2,9 @@ package emu.grasscutter.scripts.serializer;
...
@@ -2,6 +2,9 @@ package emu.grasscutter.scripts.serializer;
import
com.esotericsoftware.reflectasm.ConstructorAccess
;
import
com.esotericsoftware.reflectasm.ConstructorAccess
;
import
com.esotericsoftware.reflectasm.MethodAccess
;
import
com.esotericsoftware.reflectasm.MethodAccess
;
import
emu.grasscutter.Grasscutter
;
import
emu.grasscutter.scripts.ScriptUtils
;
import
lombok.AccessLevel
;
import
lombok.AccessLevel
;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
...
@@ -9,6 +12,8 @@ import lombok.experimental.FieldDefaults;
...
@@ -9,6 +12,8 @@ import lombok.experimental.FieldDefaults;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaTable
;
import
org.luaj.vm2.LuaValue
;
import
org.luaj.vm2.LuaValue
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.ConcurrentHashMap
;
...
@@ -31,6 +36,10 @@ public class LuaSerializer implements Serializer {
...
@@ -31,6 +36,10 @@ public class LuaSerializer implements Serializer {
public
<
T
>
List
<
T
>
serializeList
(
Class
<
T
>
type
,
LuaTable
table
)
{
public
<
T
>
List
<
T
>
serializeList
(
Class
<
T
>
type
,
LuaTable
table
)
{
List
<
T
>
list
=
new
ArrayList
<>();
List
<
T
>
list
=
new
ArrayList
<>();
if
(
table
==
null
)
{
return
list
;
}
try
{
try
{
LuaValue
[]
keys
=
table
.
keys
();
LuaValue
[]
keys
=
table
.
keys
();
for
(
LuaValue
k
:
keys
)
{
for
(
LuaValue
k
:
keys
)
{
...
@@ -79,7 +88,7 @@ public class LuaSerializer implements Serializer {
...
@@ -79,7 +88,7 @@ public class LuaSerializer implements Serializer {
}
}
try
{
try
{
if
(!
methodAccessCache
.
containsKey
(
type
)){
if
(!
methodAccessCache
.
containsKey
(
type
))
{
cacheType
(
type
);
cacheType
(
type
);
}
}
var
methodAccess
=
methodAccessCache
.
get
(
type
);
var
methodAccess
=
methodAccessCache
.
get
(
type
);
...
@@ -87,9 +96,10 @@ public class LuaSerializer implements Serializer {
...
@@ -87,9 +96,10 @@ public class LuaSerializer implements Serializer {
object
=
(
T
)
constructorCache
.
get
(
type
).
newInstance
();
object
=
(
T
)
constructorCache
.
get
(
type
).
newInstance
();
if
(
table
==
null
){
if
(
table
==
null
)
{
return
object
;
return
object
;
}
}
LuaValue
[]
keys
=
table
.
keys
();
LuaValue
[]
keys
=
table
.
keys
();
for
(
LuaValue
k
:
keys
)
{
for
(
LuaValue
k
:
keys
)
{
try
{
try
{
...
@@ -117,6 +127,7 @@ public class LuaSerializer implements Serializer {
...
@@ -117,6 +127,7 @@ public class LuaSerializer implements Serializer {
}
}
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Grasscutter
.
getLogger
().
info
(
ScriptUtils
.
toMap
(
table
).
toString
());
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment